public function __construct($paths, $flags = null, UniformResourceLocator $locator = null)
 {
     if (!$locator) {
         throw new \BadMethodCallException('Use $locator->getIterator() instead');
     }
     $this->setFlags($flags);
     foreach ($locator->findResources($paths) as $path) {
         $this->iterators[] = new FilesystemIterator($path, $this->flags);
     }
 }
Ejemplo n.º 2
0
 protected static function getImage(UniformResourceLocator $locator, $details, $image)
 {
     $image = $details["details.images.{$image}"];
     if (!strpos($image, '://')) {
         $name = $details['name'];
         $image = "gantry-themes-{$name}://{$image}";
     }
     try {
         $image = $locator->findResource($image, false);
     } catch (\Exception $e) {
         $image = false;
     }
     return $image;
 }
Ejemplo n.º 3
0
 protected static function getImage(UniformResourceLocator $locator, $details, $image)
 {
     $image = $details["details.images.{$image}"];
     if (!strpos($image, '://')) {
         $name = $details['name'];
         // Stream needs to be valid URL.
         $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $name);
         $image = "{$streamName}://{$image}";
     }
     try {
         $image = $locator->findResource($image, false);
     } catch (\Exception $e) {
         $image = false;
     }
     return $image;
 }
Ejemplo n.º 4
0
 public function add(array $schemes)
 {
     foreach ($schemes as $scheme => $config) {
         if (isset($config['paths'])) {
             $this->locator->addPath($scheme, '', $config['paths']);
         }
         if (isset($config['prefixes'])) {
             foreach ($config['prefixes'] as $prefix => $paths) {
                 $this->locator->addPath($scheme, $prefix, $paths);
             }
         }
         $type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
         if ($type[0] != '\\') {
             $type = '\\Rockettheme\\Toolbox\\StreamWrapper\\' . $type;
         }
         $this->schemes[$scheme] = $type;
     }
 }
Ejemplo n.º 5
0
 protected function init(Container $container, UniformResourceLocator $locator)
 {
     /** @var Config $config */
     $config = $container['config'];
     $schemes = (array) $config->get('streams.schemes', []);
     foreach ($schemes as $scheme => $config) {
         if (isset($config['paths'])) {
             $locator->addPath($scheme, '', $config['paths']);
         }
         if (isset($config['prefixes'])) {
             foreach ($config['prefixes'] as $prefix => $paths) {
                 $locator->addPath($scheme, $prefix, $paths);
             }
         }
         $type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
         if ($type[0] != '\\') {
             $type = '\\RocketTheme\\Toolbox\\StreamWrapper\\' . $type;
         }
         $this->schemes[$scheme] = $type;
     }
 }
Ejemplo n.º 6
0
 /**
  * Initialize resource locator by using the configuration.
  *
  * @param UniformResourceLocator $locator
  */
 public function initializeLocator(UniformResourceLocator $locator)
 {
     $locator->reset();
     $schemes = (array) $this->get('streams.schemes', []);
     foreach ($schemes as $scheme => $config) {
         if (isset($config['paths'])) {
             $locator->addPath($scheme, '', $config['paths']);
         }
         if (isset($config['prefixes'])) {
             foreach ($config['prefixes'] as $prefix => $paths) {
                 $locator->addPath($scheme, $prefix, $paths);
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * @param UniformResourceLocator $locator
  * @throws \InvalidArgumentException
  */
 protected function check(UniformResourceLocator $locator)
 {
     $streams = isset($this->items['streams']['schemes']) ? $this->items['streams']['schemes'] : null;
     if (!is_array($streams)) {
         throw new \InvalidArgumentException('Configuration is missing streams.schemes!');
     }
     $diff = array_keys(array_diff_key($this->streams, $streams));
     if ($diff) {
         throw new \InvalidArgumentException(sprintf('Configuration is missing keys %s from streams.schemes!', implode(', ', $diff)));
     }
     if (!$locator->findResource('environment://config', true)) {
         // If environment does not have its own directory, remove it from the lookup.
         $this->set('streams.schemes.environment.prefixes', ['config' => []]);
         $this->initializeLocator($locator);
     }
     // Create security.yaml if it doesn't exist.
     $filename = $locator->findResource('config://security.yaml', true, true);
     $file = YamlFile::instance($filename);
     if (!$file->exists()) {
         $file->save(['salt' => Utils::generateRandomString(14)]);
         $file->free();
     }
 }
Ejemplo n.º 8
0
 /**
  * @depends testAddPath
  */
 public function testGetSchemes()
 {
     $this->assertEquals(['base', 'local', 'override', 'all'], self::$locator->getSchemes());
 }
Ejemplo n.º 9
0
 public function rewind()
 {
     $this->found = [];
     $this->stack = $this->locator->findResources($this->path);
     $this->next();
 }