Skip to content

Commit

Permalink
move single parsing of a import into own private method
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikbjorn committed Jul 29, 2014
1 parent 45f6b54 commit 3563c7a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
24 changes: 24 additions & 0 deletions spec/Tacker/LoaderBuilderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace spec\Tacker;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class LoaderBuilderSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith([]);
}

function it_is_initializable()
{
$this->shouldHaveType('Tacker\LoaderBuilder');
}

function it_builds_loader()
{
$this->build()->shouldHaveType('Tacker\Loader\CacheLoader');
}
}
15 changes: 10 additions & 5 deletions src/Loader/AbstractLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function load($resource, $type = null)
return $this->parse($this->read($resource), $resource);
}

protected function parse(array $parameters, $resource)
abstract protected function read($resource);

private function parse(array $parameters, $resource)
{
if (!isset($parameters['@import'])) {
return $parameters;
Expand All @@ -44,13 +46,16 @@ protected function parse(array $parameters, $resource)
unset($parameters['@import']);

foreach ($imports as $import) {
$this->setCurrentDir(dirname($import));

$inherited = array_replace($inherited, $this->import($import, null, false, $resource));
$inherited = $this->parseImport($import, $resource, $inherited);
}

return array_replace($inherited, $parameters);
}

abstract protected function read($resource);
private function parseImport($import, $resource, $inherited)
{
$this->setCurrentDir(dirname($import));

return array_replace($inherited, $this->import($import, null, false, $resource));
}
}

0 comments on commit 3563c7a

Please sign in to comment.