Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FeatureSet.php

class FeatureSet

FeatureSet detects and exposes available features in the current environment

A feature set is used by UuidFactory to determine the available features and capabilities of the environment.

Hierarchy

  • class \Ramsey\Uuid\FeatureSet

Expanded class hierarchy of FeatureSet

File

vendor/ramsey/uuid/src/FeatureSet.php, line 63

Namespace

Ramsey\Uuid
View source
class FeatureSet {
    private ?TimeProviderInterface $timeProvider = null;
    private CalculatorInterface $calculator;
    private CodecInterface $codec;
    private DceSecurityGeneratorInterface $dceSecurityGenerator;
    private NameGeneratorInterface $nameGenerator;
    private NodeProviderInterface $nodeProvider;
    private NumberConverterInterface $numberConverter;
    private RandomGeneratorInterface $randomGenerator;
    private TimeConverterInterface $timeConverter;
    private TimeGeneratorInterface $timeGenerator;
    private TimeGeneratorInterface $unixTimeGenerator;
    private UuidBuilderInterface $builder;
    private ValidatorInterface $validator;
    
    /**
     * @param bool $useGuids True build UUIDs using the GuidStringCodec
     * @param bool $force32Bit True to force the use of 32-bit functionality
     *     (primarily for testing purposes)
     * @param bool $forceNoBigNumber (obsolete)
     * @param bool $ignoreSystemNode True to disable attempts to check for the
     *     system node ID (primarily for testing purposes)
     * @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator
     *     to generate version 1 UUIDs
     */
    public function __construct(bool $useGuids = false, bool $force32Bit = false, bool $forceNoBigNumber = false, bool $ignoreSystemNode = false, bool $enablePecl = false) {
        $this->randomGenerator = $this->buildRandomGenerator();
        $this->setCalculator(new BrickMathCalculator());
        $this->builder = $this->buildUuidBuilder($useGuids);
        $this->codec = $this->buildCodec($useGuids);
        $this->nodeProvider = $this->buildNodeProvider();
        $this->nameGenerator = $this->buildNameGenerator();
        $this->setTimeProvider(new SystemTimeProvider());
        $this->setDceSecurityProvider(new SystemDceSecurityProvider());
        $this->validator = new GenericValidator();
        assert($this->timeProvider !== null);
        $this->unixTimeGenerator = $this->buildUnixTimeGenerator();
    }
    
    /**
     * Returns the builder configured for this environment
     */
    public function getBuilder() : UuidBuilderInterface {
        return $this->builder;
    }
    
    /**
     * Returns the calculator configured for this environment
     */
    public function getCalculator() : CalculatorInterface {
        return $this->calculator;
    }
    
    /**
     * Returns the codec configured for this environment
     */
    public function getCodec() : CodecInterface {
        return $this->codec;
    }
    
    /**
     * Returns the DCE Security generator configured for this environment
     */
    public function getDceSecurityGenerator() : DceSecurityGeneratorInterface {
        return $this->dceSecurityGenerator;
    }
    
    /**
     * Returns the name generator configured for this environment
     */
    public function getNameGenerator() : NameGeneratorInterface {
        return $this->nameGenerator;
    }
    
    /**
     * Returns the node provider configured for this environment
     */
    public function getNodeProvider() : NodeProviderInterface {
        return $this->nodeProvider;
    }
    
    /**
     * Returns the number converter configured for this environment
     */
    public function getNumberConverter() : NumberConverterInterface {
        return $this->numberConverter;
    }
    
    /**
     * Returns the random generator configured for this environment
     */
    public function getRandomGenerator() : RandomGeneratorInterface {
        return $this->randomGenerator;
    }
    
    /**
     * Returns the time converter configured for this environment
     */
    public function getTimeConverter() : TimeConverterInterface {
        return $this->timeConverter;
    }
    
    /**
     * Returns the time generator configured for this environment
     */
    public function getTimeGenerator() : TimeGeneratorInterface {
        return $this->timeGenerator;
    }
    
    /**
     * Returns the Unix Epoch time generator configured for this environment
     */
    public function getUnixTimeGenerator() : TimeGeneratorInterface {
        return $this->unixTimeGenerator;
    }
    
    /**
     * Returns the validator configured for this environment
     */
    public function getValidator() : ValidatorInterface {
        return $this->validator;
    }
    
    /**
     * Sets the calculator to use in this environment
     */
    public function setCalculator(CalculatorInterface $calculator) : void {
        $this->calculator = $calculator;
        $this->numberConverter = $this->buildNumberConverter($calculator);
        $this->timeConverter = $this->buildTimeConverter($calculator);
        
        /** @psalm-suppress RedundantPropertyInitializationCheck */
        if (isset($this->timeProvider)) {
            $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider);
        }
    }
    
    /**
     * Sets the DCE Security provider to use in this environment
     */
    public function setDceSecurityProvider(DceSecurityProviderInterface $dceSecurityProvider) : void {
        $this->dceSecurityGenerator = $this->buildDceSecurityGenerator($dceSecurityProvider);
    }
    
    /**
     * Sets the node provider to use in this environment
     */
    public function setNodeProvider(NodeProviderInterface $nodeProvider) : void {
        $this->nodeProvider = $nodeProvider;
        if (isset($this->timeProvider)) {
            $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider);
        }
    }
    
    /**
     * Sets the time provider to use in this environment
     */
    public function setTimeProvider(TimeProviderInterface $timeProvider) : void {
        $this->timeProvider = $timeProvider;
        $this->timeGenerator = $this->buildTimeGenerator($timeProvider);
    }
    
    /**
     * Set the validator to use in this environment
     */
    public function setValidator(ValidatorInterface $validator) : void {
        $this->validator = $validator;
    }
    
    /**
     * Returns a codec configured for this environment
     *
     * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec
     */
    private function buildCodec(bool $useGuids = false) : CodecInterface {
        if ($useGuids) {
            return new GuidStringCodec($this->builder);
        }
        return new StringCodec($this->builder);
    }
    
    /**
     * Returns a DCE Security generator configured for this environment
     */
    private function buildDceSecurityGenerator(DceSecurityProviderInterface $dceSecurityProvider) : DceSecurityGeneratorInterface {
        return new DceSecurityGenerator($this->numberConverter, $this->timeGenerator, $dceSecurityProvider);
    }
    
    /**
     * Returns a node provider configured for this environment
     */
    private function buildNodeProvider() : NodeProviderInterface {
        if ($this->ignoreSystemNode) {
            return new RandomNodeProvider();
        }
        return new FallbackNodeProvider([
            new SystemNodeProvider(),
            new RandomNodeProvider(),
        ]);
    }
    
    /**
     * Returns a number converter configured for this environment
     */
    private function buildNumberConverter(CalculatorInterface $calculator) : NumberConverterInterface {
        return new GenericNumberConverter($calculator);
    }
    
    /**
     * Returns a random generator configured for this environment
     */
    private function buildRandomGenerator() : RandomGeneratorInterface {
        if ($this->enablePecl) {
            return new PeclUuidRandomGenerator();
        }
        return (new RandomGeneratorFactory())->getGenerator();
    }
    
    /**
     * Returns a time generator configured for this environment
     *
     * @param TimeProviderInterface $timeProvider The time provider to use with
     *     the time generator
     */
    private function buildTimeGenerator(TimeProviderInterface $timeProvider) : TimeGeneratorInterface {
        if ($this->enablePecl) {
            return new PeclUuidTimeGenerator();
        }
        return (new TimeGeneratorFactory($this->nodeProvider, $this->timeConverter, $timeProvider))
            ->getGenerator();
    }
    
    /**
     * Returns a Unix Epoch time generator configured for this environment
     */
    private function buildUnixTimeGenerator() : TimeGeneratorInterface {
        return new UnixTimeGenerator($this->randomGenerator);
    }
    
    /**
     * Returns a name generator configured for this environment
     */
    private function buildNameGenerator() : NameGeneratorInterface {
        if ($this->enablePecl) {
            return new PeclUuidNameGenerator();
        }
        return (new NameGeneratorFactory())->getGenerator();
    }
    
    /**
     * Returns a time converter configured for this environment
     */
    private function buildTimeConverter(CalculatorInterface $calculator) : TimeConverterInterface {
        $genericConverter = new GenericTimeConverter($calculator);
        if ($this->is64BitSystem()) {
            return new PhpTimeConverter($calculator, $genericConverter);
        }
        return $genericConverter;
    }
    
    /**
     * Returns a UUID builder configured for this environment
     *
     * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec
     */
    private function buildUuidBuilder(bool $useGuids = false) : UuidBuilderInterface {
        if ($useGuids) {
            return new GuidBuilder($this->numberConverter, $this->timeConverter);
        }
        return new FallbackBuilder([
            new Rfc4122UuidBuilder($this->numberConverter, $this->timeConverter),
            new NonstandardUuidBuilder($this->numberConverter, $this->timeConverter),
        ]);
    }
    
    /**
     * Returns true if the PHP build is 64-bit
     */
    private function is64BitSystem() : bool {
        return PHP_INT_SIZE === 8 && !$this->force32Bit;
    }

}

Members

Title Sort descending Modifiers Object type Summary
FeatureSet::$builder private property
FeatureSet::$calculator private property
FeatureSet::$codec private property
FeatureSet::$dceSecurityGenerator private property
FeatureSet::$nameGenerator private property
FeatureSet::$nodeProvider private property
FeatureSet::$numberConverter private property
FeatureSet::$randomGenerator private property
FeatureSet::$timeConverter private property
FeatureSet::$timeGenerator private property
FeatureSet::$timeProvider private property
FeatureSet::$unixTimeGenerator private property
FeatureSet::$validator private property
FeatureSet::buildCodec private function Returns a codec configured for this environment
FeatureSet::buildDceSecurityGenerator private function Returns a DCE Security generator configured for this environment
FeatureSet::buildNameGenerator private function Returns a name generator configured for this environment
FeatureSet::buildNodeProvider private function Returns a node provider configured for this environment
FeatureSet::buildNumberConverter private function Returns a number converter configured for this environment
FeatureSet::buildRandomGenerator private function Returns a random generator configured for this environment
FeatureSet::buildTimeConverter private function Returns a time converter configured for this environment
FeatureSet::buildTimeGenerator private function Returns a time generator configured for this environment
FeatureSet::buildUnixTimeGenerator private function Returns a Unix Epoch time generator configured for this environment
FeatureSet::buildUuidBuilder private function Returns a UUID builder configured for this environment
FeatureSet::getBuilder public function Returns the builder configured for this environment
FeatureSet::getCalculator public function Returns the calculator configured for this environment
FeatureSet::getCodec public function Returns the codec configured for this environment
FeatureSet::getDceSecurityGenerator public function Returns the DCE Security generator configured for this environment
FeatureSet::getNameGenerator public function Returns the name generator configured for this environment
FeatureSet::getNodeProvider public function Returns the node provider configured for this environment
FeatureSet::getNumberConverter public function Returns the number converter configured for this environment
FeatureSet::getRandomGenerator public function Returns the random generator configured for this environment
FeatureSet::getTimeConverter public function Returns the time converter configured for this environment
FeatureSet::getTimeGenerator public function Returns the time generator configured for this environment
FeatureSet::getUnixTimeGenerator public function Returns the Unix Epoch time generator configured for this environment
FeatureSet::getValidator public function Returns the validator configured for this environment
FeatureSet::is64BitSystem private function Returns true if the PHP build is 64-bit
FeatureSet::setCalculator public function Sets the calculator to use in this environment
FeatureSet::setDceSecurityProvider public function Sets the DCE Security provider to use in this environment
FeatureSet::setNodeProvider public function Sets the node provider to use in this environment
FeatureSet::setTimeProvider public function Sets the time provider to use in this environment
FeatureSet::setValidator public function Set the validator to use in this environment
FeatureSet::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal