AbstractYamlPatternsDeriver.php in UI Patterns 8
File
src/Plugin/Deriver/AbstractYamlPatternsDeriver.php
View source
<?php
namespace Drupal\ui_patterns\Plugin\Deriver;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\TypedData\TypedDataManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class AbstractYamlPatternsDeriver extends AbstractPatternsDeriver implements YamlPatternsDeriverInterface {
protected $fileSystem;
public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, MessengerInterface $messenger, FileSystemInterface $file_system) {
parent::__construct($base_plugin_id, $typed_data_manager, $messenger);
$this->fileSystem = $file_system;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('typed_data_manager'), $container
->get('messenger'), $container
->get('file_system'));
}
public function fileScanDirectory($directory) {
if (!is_dir($directory)) {
return [];
}
$options = [
'nomask' => $this
->getNoMask(),
];
$extensions = $this
->getFileExtensions();
$extensions = array_map('preg_quote', $extensions);
$extensions = implode('|', $extensions);
$files = $this->fileSystem
->scanDirectory($directory, "/{$extensions}\$/", $options);
ksort($files);
return $files;
}
protected function getNoMask() {
$ignore = Settings::get('file_scan_ignore_directories', []);
$ignore[] = 'tests';
array_walk($ignore, function (&$value) {
$value = preg_quote($value, '/');
});
return '/^' . implode('|', $ignore) . '$/';
}
}