Skip to content

Commit

Permalink
Updated PHP-DI version
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 12, 2014
1 parent b3e9a49 commit 7d1b11d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
14 changes: 6 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 4 additions & 30 deletions core/Container/IniConfigDefinitionSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
namespace Piwik\Container;

use DI\Definition\Exception\DefinitionException;
use DI\Definition\MergeableDefinition;
use DI\Definition\Source\ChainableDefinitionSource;
use DI\Definition\Source\DefinitionSource;
use DI\Definition\ValueDefinition;
use Piwik\Config;

/**
* Import the old INI config into PHP-DI.
*/
class IniConfigDefinitionSource implements DefinitionSource, ChainableDefinitionSource
class IniConfigDefinitionSource extends ChainableDefinitionSource
{
/**
* @var Config
Expand All @@ -30,11 +28,6 @@ class IniConfigDefinitionSource implements DefinitionSource, ChainableDefinition
*/
private $prefix;

/**
* @var DefinitionSource
*/
private $chainedSource;

/**
* @param Config $config
* @param string $prefix Prefix for the container entries.
Expand All @@ -45,15 +38,10 @@ public function __construct(Config $config, $prefix = 'old_config.')
$this->prefix = $prefix;
}

public function getDefinition($name, MergeableDefinition $parentDefinition = null)
protected function findDefinition($name)
{
// INI only contains values, so no definition merging here
if ($parentDefinition) {
return $this->notFound($name, $parentDefinition);
}

if (strpos($name, $this->prefix) !== 0) {
return $this->notFound($name, $parentDefinition);
return null;
}

list($sectionName, $configKey) = $this->parseEntryName($name);
Expand All @@ -65,17 +53,12 @@ public function getDefinition($name, MergeableDefinition $parentDefinition = nul
}

if (! array_key_exists($configKey, $section)) {
return $this->notFound($name, $parentDefinition);
return null;
}

return new ValueDefinition($name, $section[$configKey]);
}

public function chain(DefinitionSource $source)
{
$this->chainedSource = $source;
}

private function parseEntryName($name)
{
$parts = explode('.', $name, 3);
Expand All @@ -102,13 +85,4 @@ private function getSection($sectionName)

return $section;
}

private function notFound($name, $parentDefinition)
{
if ($this->chainedSource) {
return $this->chainedSource->getDefinition($name, $parentDefinition);
}

return null;
}
}

0 comments on commit 7d1b11d

Please sign in to comment.