<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\Metadata\Parser;

/**
 * Attribute and annotation information is static within a single PHP process.
 * It is therefore okay to use a Singleton registry here.
 *
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
 */
final class Registry
{
    private static ?CachingParser $instance = null;

    public static function parser(): CachingParser
    {
        return self::$instance ?? self::$instance = self::build();
    }

    private function __construct()
    {
    }

    private static function build(): CachingParser
    {
        return new CachingParser(
            new ParserChain(
                new AttributeParser,
                new AnnotationParser
            )
        );
    }
}
