Skip to content

Commit

Permalink
Fix logic to list and load blueprints by using streams (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Aug 20, 2015
1 parent c3f2ddf commit 4a59b8a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions system/src/Grav/Common/Data/Blueprints.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Grav\Common\File\CompiledYamlFile;
use Grav\Common\GravTrait;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;

/**
* Blueprints class keeps track on blueprint instances.
Expand All @@ -23,11 +24,7 @@ class Blueprints
*/
public function __construct($search)
{
if (!is_string($search)) {
$this->search = $search;
} else {
$this->search = rtrim($search, '\\/') . '/';
}
$this->search = $search;
}

/**
Expand All @@ -42,6 +39,14 @@ public function get($type)
if (!isset($this->instances[$type])) {
if (is_string($this->search)) {
$filename = $this->search . $type . YAML_EXT;

// Check if search is a stream and resolve the path.
if (strpos($filename, '://')) {
$grav = static::getGrav();
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$filename = $locator($filename);
}
} else {
$filename = isset($this->search[$type]) ? $this->search[$type] : '';
}
Expand Down Expand Up @@ -91,7 +96,18 @@ public function types()
if ($this->types === null) {
$this->types = array();

$iterator = new \DirectoryIterator($this->search);
// Check if search is a stream.
if (strpos($this->search, '://')) {
// Stream: use UniformResourceIterator.
$grav = static::getGrav();
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$iterator = $locator->getIterator($this->search, null);
} else {
// Not a stream: use DirectoryIterator.
$iterator = new \DirectoryIterator($this->search);
}

/** @var \DirectoryIterator $file */
foreach ($iterator as $file) {
if (!$file->isFile() || '.' . $file->getExtension() != YAML_EXT) {
Expand Down

0 comments on commit 4a59b8a

Please sign in to comment.