/**
  * {@inheritdoc}
  */
 public function findAll()
 {
     $all = array();
     $files = $this->findFiles();
     $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->fileCacheKeySuffix);
     // Try to load from the file cache first.
     foreach ($file_cache->getMultiple(array_keys($files)) as $file => $data) {
         $all[$files[$file]][$this->getIdentifier($file, $data)] = $data;
         unset($files[$file]);
     }
     // If there are files left that were not returned from the cache, load and
     // parse them now. This list was flipped above and is keyed by filename.
     if ($files) {
         foreach ($files as $file => $provider) {
             // If a file is empty or its contents are commented out, return an empty
             // array instead of NULL for type consistency.
             try {
                 $data = Yaml::decode(file_get_contents($file)) ?: [];
             } catch (InvalidDataTypeException $e) {
                 throw new DiscoveryException("The {$file} contains invalid YAML", 0, $e);
             }
             $data[static::FILE_KEY] = $file;
             $all[$provider][$this->getIdentifier($file, $data)] = $data;
             $file_cache->set($file, $data);
         }
     }
     return $all;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     FileCacheFactory::setPrefix($this->randomString(4));
     parent::setUp();
     $this->controller = $this->container->get('entity.manager')->getStorage('entity_browser');
     $this->widgetUUID = $this->container->get('uuid')->generate();
     $this->routeProvider = $this->container->get('router.route_provider');
 }
예제 #3
0
 /**
  * Constructs a new FileStorage.
  *
  * @param string $directory
  *   A directory path to use for reading and writing of configuration files.
  * @param string $collection
  *   (optional) The collection to store configuration in. Defaults to the
  *   default collection.
  */
 public function __construct($directory, $collection = StorageInterface::DEFAULT_COLLECTION)
 {
     $this->directory = $directory;
     $this->collection = $collection;
     // Use a NULL File Cache backend by default. This will ensure only the
     // internal statc caching of FileCache is used and thus avoids blowing up
     // the APCu cache.
     $this->fileCache = FileCacheFactory::get('config', ['cache_backend_class' => NULL]);
 }
 /**
  * Constructs a new instance.
  *
  * @param string[] $plugin_namespaces
  *   (optional) An array of namespace that may contain plugin implementations.
  *   Defaults to an empty array.
  * @param string $plugin_definition_annotation_name
  *   (optional) The name of the annotation that contains the plugin definition.
  *   Defaults to 'Drupal\Component\Annotation\Plugin'.
  * @param string[] $annotation_namespaces
  *   (optional) Additional namespaces to be scanned for annotation classes.
  */
 function __construct($plugin_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\\Component\\Annotation\\Plugin', array $annotation_namespaces = [])
 {
     $this->pluginNamespaces = $plugin_namespaces;
     $this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name;
     $this->annotationNamespaces = $annotation_namespaces;
     $file_cache_suffix = str_replace('\\', '_', $plugin_definition_annotation_name);
     $file_cache_suffix .= ':' . hash('crc32b', serialize($annotation_namespaces));
     $this->fileCache = FileCacheFactory::get('annotation_discovery:' . $file_cache_suffix);
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Ensure that an instantiated container in the global state of \Drupal from
     // a previous test does not leak into this test.
     \Drupal::unsetContainer();
     // Ensure that the NullFileCache implementation is used for the FileCache as
     // unit tests should not be relying on caches implicitly.
     FileCacheFactory::setConfiguration(['default' => ['class' => '\\Drupal\\Component\\FileCache\\NullFileCache']]);
     $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Ensure that an instantiated container in the global state of \Drupal from
     // a previous test does not leak into this test.
     \Drupal::unsetContainer();
     // Ensure that the NullFileCache implementation is used for the FileCache as
     // unit tests should not be relying on caches implicitly.
     FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]);
     // Ensure that FileCacheFactory has a prefix.
     FileCacheFactory::setPrefix('prefix');
     $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
 }
예제 #7
0
  /**
   * Returns a \Drupal\composer_manager\PackageManager instance.
   */
  public static function getPackageManager() {
    $root = getcwd();
    require $root . '/autoload.php';
    // The module classes aren't in the autoloader at this point.
    require __DIR__ . '/../ExtensionDiscovery.php';
    require __DIR__ . '/../JsonFile.php';
    require __DIR__ . '/../PackageManagerInterface.php';
    require __DIR__ . '/../PackageManager.php';
    // YAML discovery in core uses FileCache which is not available.
    FileCacheFactory::setConfiguration(['default' => ['class' => '\Drupal\Component\FileCache\NullFileCache']]);

    return new PackageManager($root);
  }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     // @todo Extra hack to avoid test fails, remove this once
     // https://www.drupal.org/node/2553661 is fixed.
     FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
     parent::setUp();
     $this->logger = $this->container->get('logger.channel.rules');
     // Clear the log from any stale entries that are bleeding over from previous
     // tests.
     $this->logger->clearLogs();
     $this->expressionManager = $this->container->get('plugin.manager.rules_expression');
     $this->conditionManager = $this->container->get('plugin.manager.condition');
     $this->typedDataManager = $this->container->get('typed_data_manager');
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Ensure that an instantiated container in the global state of \Drupal from
     // a previous test does not leak into this test.
     \Drupal::unsetContainer();
     // Ensure that the NullFileCache implementation is used for the FileCache as
     // unit tests should not be relying on caches implicitly.
     FileCacheFactory::setConfiguration(['default' => ['class' => '\\Drupal\\Component\\FileCache\\NullFileCache']]);
     $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
     // Reset the static list of SafeStrings to prevent bleeding between tests.
     $reflected_class = new \ReflectionClass('\\Drupal\\Component\\Utility\\SafeMarkup');
     $reflected_property = $reflected_class->getProperty('safeStrings');
     $reflected_property->setAccessible(true);
     $reflected_property->setValue([]);
 }
 /**
  * {@inheritdoc}
  */
 public function getContainerDefinition()
 {
     FileCacheFactory::setConfiguration(array('default' => array('class' => '\\Drupal\\Component\\FileCache\\NullFileCache')));
     $container_builder = new ContainerBuilder();
     $yaml_loader = new YamlFileLoader($container_builder);
     foreach (module_list() as $module) {
         $filename = drupal_get_filename('module', $module);
         $services = dirname($filename) . "/{$module}.services.yml";
         if (file_exists($services)) {
             $yaml_loader->load($services);
         }
     }
     // Disabled for now.
     // $container_builder->compile();
     $dumper = new PhpArrayDumper($container_builder);
     return $dumper->getArray();
 }
예제 #11
0
파일: Command.php 프로젝트: jeyram/camp-gdl
 /**
  * Returns a \Drupal\composer_manager\PackageManager instance.
  */
 public static function getPackageManager()
 {
     // The command is running inside Composer, which gives the autoloader
     // access to Drupal's classes but not the module classes.
     require __DIR__ . '/../ExtensionDiscovery.php';
     require __DIR__ . '/../JsonFile.php';
     require __DIR__ . '/../PackageManagerInterface.php';
     require __DIR__ . '/../PackageManager.php';
     require __DIR__ . '/../RootPackageBuilderInterface.php';
     require __DIR__ . '/../RootPackageBuilder.php';
     // YAML discovery in core uses FileCache which is not available.
     FileCacheFactory::setConfiguration(['default' => ['class' => '\\Drupal\\Component\\FileCache\\NullFileCache']]);
     // Composer runs in core/, so the root is one directory above.
     $root = realpath(getcwd() . '/../');
     $root_package_builder = new \Drupal\composer_manager\RootPackageBuilder($root);
     $package_manager = new \Drupal\composer_manager\PackageManager($root, $root_package_builder);
     return $package_manager;
 }
예제 #12
0
 /**
  * @covers ::setUp
  */
 public function testSetUp()
 {
     $this->assertTrue($this->container->has('request_stack'));
     $this->assertTrue($this->container->initialized('request_stack'));
     $request = $this->container->get('request_stack')->getCurrentRequest();
     $this->assertNotEmpty($request);
     $this->assertEquals('/', $request->getPathInfo());
     $this->assertSame($request, \Drupal::request());
     $this->assertEquals($this, $GLOBALS['conf']['container_service_providers']['test']);
     $GLOBALS['destroy-me'] = TRUE;
     $this->assertArrayHasKey('destroy-me', $GLOBALS);
     $database = $this->container->get('database');
     $database->schema()->createTable('foo', array('fields' => array('number' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE))));
     $this->assertTrue($database->schema()->tableExists('foo'));
     // Ensure that the database tasks have been run during set up. Neither MySQL
     // nor SQLite make changes that are testable.
     if ($database->driver() == 'pgsql') {
         $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField());
         $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField());
     }
     $this->assertNotNull(FileCacheFactory::getPrefix());
 }
 /**
  * {@inheritdoc}
  */
 public function findAll()
 {
     $all = array();
     $files = $this->findFiles();
     $provider_by_files = array_flip($files);
     $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->name);
     // Try to load from the file cache first.
     foreach ($file_cache->getMultiple($files) as $file => $data) {
         $all[$provider_by_files[$file]] = $data;
         unset($provider_by_files[$file]);
     }
     // If there are files left that were not returned from the cache, load and
     // parse them now. This list was flipped above and is keyed by filename.
     if ($provider_by_files) {
         foreach ($provider_by_files as $file => $provider) {
             // If a file is empty or its contents are commented out, return an empty
             // array instead of NULL for type consistency.
             $all[$provider] = Yaml::decode(file_get_contents($file)) ?: [];
             $file_cache->set($file, $all[$provider]);
         }
     }
     return $all;
 }
 public function setUp()
 {
     FileCacheFactory::setPrefix($this->randomMachineName());
     $plugin_type_id_a = $this->randomMachineName();
     $this->pluginTypeDefinitions[$plugin_type_id_a] = ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'provider' => $this->randomMachineName(), 'plugin_manager_service_id' => $this->randomMachineName()];
     $plugin_type_id_b = $this->randomMachineName();
     $this->pluginTypeDefinitions[$plugin_type_id_b] = ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'provider' => $this->randomMachineName(), 'plugin_manager_service_id' => $this->randomMachineName()];
     $this->pluginManagers = [$plugin_type_id_a => $this->getMock(PluginManagerInterface::class), $plugin_type_id_b => $this->getMock(PluginManagerInterface::class)];
     vfsStreamWrapper::register();
     $root = new vfsStreamDirectory('modules');
     vfsStreamWrapper::setRoot($root);
     $this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
     $this->moduleHandler->expects($this->any())->method('getModuleDirectories')->willReturn(array('module_a' => vfsStream::url('modules/module_a'), 'module_b' => vfsStream::url('modules/module_b')));
     $class_resolver = $this->getMock(ClassResolverInterface::class);
     $this->container = $this->getMock(ContainerInterface::class);
     $map = [['class_resolver', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $class_resolver], ['string_translation', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->getStringTranslationStub()], [$this->pluginTypeDefinitions[$plugin_type_id_a]['plugin_manager_service_id'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->pluginManagers[$plugin_type_id_a]], [$this->pluginTypeDefinitions[$plugin_type_id_b]['plugin_manager_service_id'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->pluginManagers[$plugin_type_id_b]]];
     $this->container->expects($this->any())->method('get')->willReturnMap($map);
     $url = vfsStream::url('modules');
     mkdir($url . '/module_a');
     file_put_contents($url . '/module_a/module_a.plugin_type.yml', $this->buildPluginDefinitionYaml($plugin_type_id_a, $this->pluginTypeDefinitions[$plugin_type_id_a]['label'], $this->pluginTypeDefinitions[$plugin_type_id_a]['description'], $this->pluginTypeDefinitions[$plugin_type_id_a]['provider'], $this->pluginTypeDefinitions[$plugin_type_id_a]['plugin_manager_service_id']));
     mkdir($url . '/module_b');
     file_put_contents($url . '/module_b/module_b.plugin_type.yml', $this->buildPluginDefinitionYaml($plugin_type_id_b, $this->pluginTypeDefinitions[$plugin_type_id_b]['label'], $this->pluginTypeDefinitions[$plugin_type_id_b]['description'], $this->pluginTypeDefinitions[$plugin_type_id_b]['provider'], $this->pluginTypeDefinitions[$plugin_type_id_b]['plugin_manager_service_id']));
     $this->sut = new PluginTypeManager($this->container, $this->moduleHandler);
 }
예제 #15
0
파일: WebTestBase.php 프로젝트: Wylbur/gj
 /**
  * Changes parameters in the services.yml file.
  *
  * @param $name
  *   The name of the parameter.
  * @param $value
  *   The value of the parameter.
  */
 protected function setContainerParameter($name, $value)
 {
     $filename = $this->siteDirectory . '/services.yml';
     chmod($filename, 0666);
     $services = Yaml::decode(file_get_contents($filename));
     $services['parameters'][$name] = $value;
     file_put_contents($filename, Yaml::encode($services));
     // Ensure that the cache is deleted for the yaml file loader.
     $file_cache = FileCacheFactory::get('container_yaml_loader');
     $file_cache->delete($filename);
 }
예제 #16
0
 /**
  * Constructs a new ExtensionDiscovery object.
  *
  * @param string $root
  *   The app root.
  * @param bool $use_file_cache
  *   Whether file cache should be used.
  * @param string[] $profile_directories
  *   The available profile directories
  * @param string $site_path
  *   The path to the site.
  */
 public function __construct($root, $use_file_cache = TRUE, $profile_directories = NULL, $site_path = NULL)
 {
     $this->root = $root;
     $this->fileCache = $use_file_cache ? FileCacheFactory::get('extension_discovery') : NULL;
     $this->profileDirectories = $profile_directories;
     $this->sitePath = $site_path;
 }
예제 #17
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     FileCacheFactory::setPrefix('example');
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     if ($this->booted) {
         return $this;
     }
     // Ensure that findSitePath is set.
     if (!$this->sitePath) {
         throw new \Exception('Kernel does not have site path set before calling boot()');
     }
     // Initialize the FileCacheFactory component. We have to do it here instead
     // of in \Drupal\Component\FileCache\FileCacheFactory because we can not use
     // the Settings object in a component.
     $configuration = Settings::get('file_cache');
     // Provide a default configuration, if not set.
     if (!isset($configuration['default'])) {
         $configuration['default'] = ['class' => '\\Drupal\\Component\\FileCache\\FileCache', 'cache_backend_class' => NULL, 'cache_backend_configuration' => []];
         // @todo Use extension_loaded('apcu') for non-testbot
         //  https://www.drupal.org/node/2447753.
         if (function_exists('apcu_fetch')) {
             $configuration['default']['cache_backend_class'] = '\\Drupal\\Component\\FileCache\\ApcuFileCacheBackend';
         }
     }
     FileCacheFactory::setConfiguration($configuration);
     FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
     $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition));
     // Initialize the container.
     $this->initializeContainer();
     $this->booted = TRUE;
     return $this;
 }
예제 #19
0
 /**
  * Initializes the FileCache component.
  *
  * We can not use the Settings object in a component, that's why we have to do
  * it here instead of \Drupal\Component\FileCache\FileCacheFactory.
  */
 protected function initFileCache()
 {
     $configuration = Settings::get('file_cache');
     // Provide a default configuration, if not set.
     if (!isset($configuration['default'])) {
         $configuration['default'] = ['class' => FileCache::class, 'cache_backend_class' => NULL, 'cache_backend_configuration' => []];
         // @todo Use extension_loaded('apcu') for non-testbot
         //  https://www.drupal.org/node/2447753.
         if (function_exists('apcu_fetch')) {
             $configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class;
         }
     }
     FileCacheFactory::setConfiguration($configuration);
     FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
 }
예제 #20
0
 /**
  * Constructs a new ExtensionDiscovery object.
  *
  * @param string $root
  *   The app root.
  */
 public function __construct($root)
 {
     $this->root = $root;
     $this->fileCache = FileCacheFactory::get('extension_discovery');
 }
 /**
  * Creates the discovery object.
  *
  * @param string|bool $subdir
  *   The plugin's subdirectory, for example Plugin/views/filter.
  * @param \Traversable $namespaces
  *   An object that implements \Traversable which contains the root paths
  *   keyed by the corresponding namespace to look for plugin implementations.
  * @param string|null $plugin_interface
  *   (optional) The interface each plugin should implement.
  * @param string $plugin_definition_annotation_name
  *   (optional) The name of the annotation that contains the plugin definition.
  *   Defaults to 'Drupal\Component\Annotation\Plugin'.
  */
 public function __construct($subdir, \Traversable $namespaces, $plugin_interface = NULL, $plugin_definition_annotation_name = 'Drupal\\Component\\Annotation\\Plugin')
 {
     $this->subdir = $subdir;
     $this->namespaces = $namespaces;
     $this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name;
     $this->pluginInterface = $plugin_interface;
     // Add the file cache prefix.
     $configuration['default'] = ['class' => '\\Drupal\\Component\\FileCache\\FileCache', 'cache_backend_class' => NULL, 'cache_backend_configuration' => []];
     // @todo Use extension_loaded('apcu') for non-testbot
     //  https://www.drupal.org/node/2447753.
     if (function_exists('apc_fetch')) {
         $configuration['default']['cache_backend_class'] = '\\Drupal\\Component\\FileCache\\ApcuFileCacheBackend';
     }
     FileCacheFactory::setConfiguration($configuration);
     $identifier = 'file_cache';
     FileCacheFactory::setPrefix('drupal.' . $identifier . '.' . hash_hmac('sha256', $identifier, drupal_get_hash_salt()));
 }
예제 #22
0
 public function __construct(ContainerBuilder $container)
 {
     $this->container = $container;
     $this->fileCache = FileCacheFactory::get('container_yaml_loader');
 }
예제 #23
0
 /**
  * @covers ::getPrefix
  * @covers ::setPrefix
  */
 public function testGetSetPrefix()
 {
     $prefix = $this->randomMachineName();
     FileCacheFactory::setPrefix($prefix);
     $this->assertEquals($prefix, FileCacheFactory::getPrefix());
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     if ($this->booted) {
         return $this;
     }
     // Ensure that findSitePath is set.
     if (!$this->sitePath) {
         throw new \Exception('Kernel does not have site path set before calling boot()');
     }
     // Initialize the FileCacheFactory component. We have to do it here instead
     // of in \Drupal\Component\FileCache\FileCacheFactory because we can not use
     // the Settings object in a component.
     $configuration = Settings::get('file_cache');
     // Provide a default configuration, if not set.
     if (!isset($configuration['default'])) {
         $configuration['default'] = ['class' => '\\Drupal\\Component\\FileCache\\FileCache', 'cache_backend_class' => NULL, 'cache_backend_configuration' => []];
         // @todo Use extension_loaded('apcu') for non-testbot
         //  https://www.drupal.org/node/2447753.
         if (function_exists('apc_fetch')) {
             $configuration['default']['cache_backend_class'] = '\\Drupal\\Component\\FileCache\\ApcuFileCacheBackend';
         }
     }
     FileCacheFactory::setConfiguration($configuration);
     FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
     // Initialize the container.
     $this->initializeContainer();
     // Ensure mt_rand() is reseeded to prevent random values from one page load
     // being exploited to predict random values in subsequent page loads.
     $seed = unpack("L", Crypt::randomBytes(4));
     mt_srand($seed[1]);
     $this->booted = TRUE;
     return $this;
 }