isSupported example


    private MarshallerInterface $marshaller;
    private array $decryptionKeys;

    /** * @param string[] $decryptionKeys The key at index "0" is required and is used to decrypt and encrypt values; * more rotating keys can be provided to decrypt values; * each key must be generated using sodium_crypto_box_keypair() */
    public function __construct(array $decryptionKeys, MarshallerInterface $marshaller = null)
    {
        if (!self::isSupported()) {
            throw new CacheException('The "sodium" PHP extension is not loaded.');
        }

        if (!isset($decryptionKeys[0])) {
            throw new InvalidArgumentException('At least one decryption key must be provided at index "0".');
        }

        $this->marshaller = $marshaller ?? new DefaultMarshaller();
        $this->decryptionKeys = $decryptionKeys;
    }

    
/** * Creates the APCu adapter if applicable. * * @throws \LogicException When the Cache Component isn't available */
    public static function createCache(string $namespace, int $defaultLifetime, string $version, LoggerInterface $logger = null): AdapterInterface
    {
        if (!class_exists(ApcuAdapter::class)) {
            throw new \LogicException(sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
        }

        if (!ApcuAdapter::isSupported()) {
            return new NullAdapter();
        }

        $apcu = new ApcuAdapter($namespace$defaultLifetime / 5, $version);
        if ('cli' === \PHP_SAPI && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
            $apcu->setLogger(new NullLogger());
        } elseif (null !== $logger) {
            $apcu->setLogger($logger);
        }

        return $apcu;
    }

    private function lock(string $name = null, bool $blocking = false): bool
    {
        if (!class_exists(SemaphoreStore::class)) {
            throw new LogicException('To enable the locking feature you must install the symfony/lock component. Try running "composer require symfony/lock".');
        }

        if (null !== $this->lock) {
            throw new LogicException('A lock is already in place.');
        }

        if (SemaphoreStore::isSupported()) {
            $store = new SemaphoreStore();
        } else {
            $store = new FlockStore();
        }

        $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName());
        if (!$this->lock->acquire($blocking)) {
            $this->lock = null;

            return false;
        }

        

    public static function isSupported()
    {
        return \extension_loaded('memcached');
    }

    /** * @param int $initialTtl the expiration delay of locks in seconds */
    public function __construct(\Memcached $memcached, int $initialTtl = 300)
    {
        if (!static::isSupported()) {
            throw new InvalidArgumentException('Memcached extension is required.');
        }

        if ($initialTtl < 1) {
            throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
        }

        $this->memcached = $memcached;
        $this->initialTtl = $initialTtl;
    }

    

    public static function isSupported(): bool
    {
        return \extension_loaded('sysvsem');
    }

    public function __construct()
    {
        if (!static::isSupported()) {
            throw new InvalidArgumentException('Semaphore extension (sysvsem) is required.');
        }
    }

    /** * @return void */
    public function save(Key $key)
    {
        $this->lock($key, false);
    }

    
'iterations' => 5000,
                'cost' => null,
                'memory_cost' => null,
                'time_cost' => null,
                'migrate_from' => [],
            ],
        ]]$container->getDefinition('security.password_hasher_factory')->getArguments());
    }

    public function testHashersWithLibsodium()
    {
        if (!SodiumPasswordHasher::isSupported()) {
            $this->markTestSkipped('Libsodium is not available.');
        }

        $container = $this->getContainer('sodium_hasher');

        $this->assertEquals([[
            'JMS\FooBundle\Entity\User1' => [
                'class' => PlaintextPasswordHasher::class,
                'arguments' => [false],
            ],
            'JMS\FooBundle\Entity\User2' => [
                

    public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null): AdapterInterface
    {
        $opcache = new PhpFilesAdapter($namespace$defaultLifetime$directory, true);
        if (null !== $logger) {
            $opcache->setLogger($logger);
        }

        if (!self::$apcuSupported ??= ApcuAdapter::isSupported()) {
            return $opcache;
        }

        if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
            return $opcache;
        }

        $apcu = new ApcuAdapter($namespaceintdiv($defaultLifetime, 5)$version);
        if (null !== $logger) {
            $apcu->setLogger($logger);
        }

        
public function isSupported($entity_type_id) {
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip'));
  }

  /** * {@inheritdoc} */
  public function getSupportedEntityTypes() {
    $supported_types = [];
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if ($this->isSupported($entity_type_id)) {
        $supported_types[$entity_type_id] = $entity_type;
      }
    }
    return $supported_types;
  }

  /** * {@inheritdoc} */
  public function setEnabled($entity_type_id$bundle$value) {
    $config = $this->loadContentLanguageSettings($entity_type_id$bundle);
    

    private function lock(string $name = null, bool $blocking = false): bool
    {
        if (!class_exists(SemaphoreStore::class)) {
            throw new LogicException('To enable the locking feature you must install the symfony/lock component. Try running "composer require symfony/lock".');
        }

        if (null !== $this->lock) {
            throw new LogicException('A lock is already in place.');
        }

        if (SemaphoreStore::isSupported()) {
            $store = new SemaphoreStore();
        } else {
            $store = new FlockStore();
        }

        $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName());
        if (!$this->lock->acquire($blocking)) {
            $this->lock = null;

            return false;
        }

        


        $handler = ! empty($handler) ? $handler : $config->handler;
        $backup  = ! empty($backup) ? $backup : $config->backupHandler;

        if (array_key_exists($handler$config->validHandlers) || ! array_key_exists($backup$config->validHandlers)) {
            throw CacheException::forHandlerNotFound();
        }

        $adapter = new $config->validHandlers[$handler]($config);

        if ($adapter->isSupported()) {
            $adapter = new $config->validHandlers[$backup]($config);

            if ($adapter->isSupported()) {
                // Fall back to the dummy adapter.                 $adapter = new $config->validHandlers['dummy']();
            }
        }

        // If $adapter->initialization throws a CriticalError exception, we will attempt to         // use the $backup handler, if that also fails, we resort to the dummy handler.         try {
            

class ApcuAdapter extends AbstractAdapter
{
    private ?MarshallerInterface $marshaller;

    /** * @throws CacheException if APCu is not enabled */
    public function __construct(string $namespace = '', int $defaultLifetime = 0, string $version = null, MarshallerInterface $marshaller = null)
    {
        if (!static::isSupported()) {
            throw new CacheException('APCu is not enabled.');
        }
        if ('cli' === \PHP_SAPI) {
            ini_set('apc.use_request_time', 0);
        }
        parent::__construct($namespace$defaultLifetime);

        if (null !== $version) {
            CacheItem::validateKey($version);

            if (!apcu_exists($version.'@'.$namespace)) {
                

    protected $skippedTests = [
        'testHasItemReturnsFalseWhenDeferredItemIsExpired' => 'Testing expiration slows down the test suite',
        'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
        'testClearPrefix' => 'Memcached cannot clear by prefix',
    ];

    protected static \Memcached $client;

    public static function setUpBeforeClass(): void
    {
        if (!MemcachedAdapter::isSupported()) {
            throw new SkippedTestSuiteError('Extension memcached > 3.1.5 required.');
        }
        self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')['binary_protocol' => false]);
        self::$client->get('foo');
        $code = self::$client->getResultCode();

        if (\Memcached::RES_SUCCESS !== $code && \Memcached::RES_NOTFOUND !== $code) {
            throw new SkippedTestSuiteError('Memcached error: '.strtolower(self::$client->getResultMessage()));
        }
    }

    

class CouchbaseBucketAdapterTest extends AdapterTestCase
{
    protected $skippedTests = [
        'testClearPrefix' => 'Couchbase cannot clear by prefix',
    ];

    protected static \CouchbaseBucket $client;

    public static function setupBeforeClass(): void
    {
        if (!CouchbaseBucketAdapter::isSupported()) {
            throw new SkippedTestSuiteError('Couchbase >= 2.6.0 < 3.0.0 is required.');
        }

        self::$client = AbstractAdapter::createConnection('couchbase://'.getenv('COUCHBASE_HOST').'/cache',
            ['username' => getenv('COUCHBASE_USER'), 'password' => getenv('COUCHBASE_PASS')]
        );
    }

    public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
    {
        $client = $defaultLifetime
            ?
$command = new \FooLockCommand();

        $tester = new CommandTester($command);
        $this->assertSame(2, $tester->execute([]));
        $this->assertSame(2, $tester->execute([]));
    }

    public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
    {
        $command = new \FooLockCommand();

        if (SemaphoreStore::isSupported()) {
            $store = new SemaphoreStore();
        } else {
            $store = new FlockStore();
        }

        $lock = (new LockFactory($store))->createLock($command->getName());
        $lock->acquire();

        $tester = new CommandTester($command);
        $this->assertSame(1, $tester->execute([]));

        

  public function updateLocaleStorage(StorableConfigBase $config$langcode, array $reference_config = []) {
    $name = $config->getName();
    if ($this->localeConfigManager->isSupported($name) && locale_is_translatable($langcode)) {
      $translatables = $this->localeConfigManager->getTranslatableDefaultConfig($name);
      $this->processTranslatableData($name$config->get()$translatables$langcode$reference_config);
    }
  }

  /** * Process the translatable data array with a given language. * * @param string $name * The configuration name. * @param array $config * The active configuration data or override data. * @param array|\Drupal\Core\StringTranslation\TranslatableMarkup[] $translatable * The translatable array structure. * @see \Drupal\locale\LocaleConfigManager::getTranslatableData() * @param string $langcode * The language code to process the array with. * @param array $reference_config * (Optional) Reference configuration to check against if $config was an * override. This allows us to update locale keys for data not in the * override but still in the active configuration. */
Home | Imprint | This part of the site doesn't use cookies.