Make registering page types to remember previous additions

This commit is contained in:
Matias Griese 2016-05-12 21:38:35 +03:00
parent b25eeb9586
commit 0e08f97f46

View File

@ -19,14 +19,18 @@ class Types implements \ArrayAccess, \Iterator, \Countable
public function register($type, $blueprint = null)
{
if (!$blueprint && $this->systemBlueprints && isset($this->systemBlueprints[$type])) {
$useBlueprint = $this->systemBlueprints[$type];
} else {
$useBlueprint = $blueprint;
if (!isset($this->items[$type])) {
$this->items[$type] = [];
} elseif (!$blueprint) {
return;
}
if ($blueprint || empty($this->items[$type])) {
$this->items[$type] = $useBlueprint;
if (!$blueprint && $this->systemBlueprints) {
$blueprint = isset($this->systemBlueprints[$type]) ? $this->systemBlueprints[$type] : $this->systemBlueprints['default'];
}
if ($blueprint) {
array_unshift($this->items[$type], $blueprint);
}
}
@ -36,7 +40,16 @@ class Types implements \ArrayAccess, \Iterator, \Countable
throw new \InvalidArgumentException('First parameter must be URI');
}
$this->items = $this->findBlueprints($uri) + $this->items;
if (!$this->systemBlueprints) {
$this->systemBlueprints = $this->findBlueprints('blueprints://pages');
// Register default by default.
$this->register('default');
}
foreach ($this->findBlueprints($uri) as $type => $blueprint) {
$this->register($type, $blueprint);
}
}
public function scanTemplates($uri)
@ -55,13 +68,6 @@ class Types implements \ArrayAccess, \Iterator, \Countable
'recursive' => false
];
if (!$this->systemBlueprints) {
$this->systemBlueprints = $this->findBlueprints('blueprints://pages');
}
// register default by default
$this->register('default');
foreach (Folder::all($uri, $options) as $type) {
$this->register($type);
}