Skip to content

Commit

Permalink
Fixed shareInstances rule syntax to be inline with the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TRPB committed Jun 12, 2014
1 parent 1d4f559 commit 027d879
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions dice.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public function create($component, array $args = [], $forceNewInstance = false)
}

private function expandParams(array $params, array $share = []) {
for ($i = 0; $i < count($params); $i++) {
if ($params[$i] instanceof Instance) $params[$i] = $this->create($params[$i], $share);
else if (is_callable($params[$i])) $params[$i] = $params[$i]($this);
foreach ($params as &$param) {
if ($param instanceof Instance) $param = $this->create($param, $share);
else if (is_callable($param)) $param = $param($this);
}
return $params;
}

private function getParams(\ReflectionMethod $method, array $args, Rule $rule) {
$subs = array_change_key_case($rule->substitutions);
$share = $this->expandParams($rule->shareInstances);
$share = array_map([$this, 'create'], $rule->shareInstances);
$args = array_merge($args, $this->expandParams($rule->constructParams, $share), $share);
$parameters = [];

Expand Down
4 changes: 2 additions & 2 deletions tests/dicetest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function testBestMatch() {

public function testShareInstances() {
$rule = new \Dice\Rule();
$rule->shareInstances = array(new \Dice\Instance('Shared'));
$rule->shareInstances = ['Shared'];
$this->dice->addRule('TestSharedInstancesTop', $rule);


Expand All @@ -521,7 +521,7 @@ public function testShareInstances() {

public function testShareInstancesMultiple() {
$rule = new \Dice\Rule();
$rule->shareInstances = array(new \Dice\Instance('Shared'));
$rule->shareInstances = ['Shared'];
$this->dice->addRule('TestSharedInstancesTop', $rule);


Expand Down

0 comments on commit 027d879

Please sign in to comment.