class YamlCacheCollectorDiscovery
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Discovery/YamlCacheCollectorDiscovery.php \Drupal\Core\Discovery\YamlCacheCollectorDiscovery
Provides discovery for YAML files within a given set of directories.
This overrides the Component file decoding with the Core YAML implementation.
Hierarchy
- class \Drupal\Component\Discovery\YamlDiscovery implements \Drupal\Component\Discovery\DiscoverableInterface
- class \Drupal\Core\Discovery\YamlDiscovery extends \Drupal\Component\Discovery\YamlDiscovery
- class \Drupal\Core\Discovery\YamlCacheCollectorDiscovery extends \Drupal\Core\Discovery\YamlDiscovery
- class \Drupal\Core\Discovery\YamlDiscovery extends \Drupal\Component\Discovery\YamlDiscovery
Expanded class hierarchy of YamlCacheCollectorDiscovery
1 file declares its use of YamlCacheCollectorDiscovery
- YamlRouteDiscovery.php in core/
lib/ Drupal/ Core/ Routing/ YamlRouteDiscovery.php
File
-
core/
lib/ Drupal/ Core/ Discovery/ YamlCacheCollectorDiscovery.php, line 15
Namespace
Drupal\Core\DiscoveryView source
class YamlCacheCollectorDiscovery extends YamlDiscovery {
/**
* Constructs a YamlDiscovery object.
*
* @param string $name
* The base filename to look for in each directory. The format will be
* $provider.$name.yml.
* @param array $directories
* An array of directories to scan, keyed by the provider.
* @param Drupal\Core\Cache\CacheCollectorInterface $yamlCacheCollector
* An instance of YamlCacheCollector.
*/
public function __construct(string $name, array $directories, protected CacheCollectorInterface $yamlCacheCollector) {
parent::__construct($name, $directories);
}
/**
* {@inheritdoc}
*/
public function findAll() : array {
$all = [];
$files = $this->findFiles();
foreach ($files as $provider => $file) {
$all[$provider] = $this->yamlCacheCollector
->get($file);
}
// Once discovery is complete, call ::destruct() on the cache collector to
// free up memory.
$this->yamlCacheCollector
->destruct();
return $all;
}
/**
* {@inheritdoc}
*/
protected function decode($file) : array {
try {
return $this->yamlCacheCollector
->get($file);
} catch (InvalidDataTypeException $e) {
throw new InvalidDataTypeException($file . ': ' . $e->getMessage(), $e->getCode(), $e);
}
}
/**
* Calls cache collector ::destruct() method when this goes out of scope.
*/
public function __destruct() {
$this->yamlCacheCollector
->destruct();
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| YamlCacheCollectorDiscovery::decode | protected | function | Decode a YAML file. | Overrides YamlDiscovery::decode |
| YamlCacheCollectorDiscovery::findAll | public | function | Returns an array of discoverable items. | Overrides YamlDiscovery::findAll |
| YamlCacheCollectorDiscovery::__construct | public | function | Constructs a YamlDiscovery object. | Overrides YamlDiscovery::__construct |
| YamlCacheCollectorDiscovery::__destruct | public | function | Calls cache collector ::destruct() method when this goes out of scope. | |
| YamlDiscovery::$directories | protected | property | An array of directories to scan, keyed by the provider. | |
| YamlDiscovery::$name | protected | property | The base filename to look for in each directory. | |
| YamlDiscovery::findFiles | protected | function | Returns an array of file paths, keyed by provider. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.