Skip to content

Commit

Permalink
made explicit factory checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Regeda committed Mar 30, 2014
1 parent 7051da8 commit b6bd751
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Castel.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public function extend($id, Closure $callable)
}
$parent = $this->values[$id];
$this->values[$id] = function ($c) use ($callable, $parent) {
if (is_callable($parent)) {
$parent = $parent($c);
}
return $callable($parent, $c);
$isFactory = is_object($parent) && method_exists($parent, '__invoke');
return $callable($isFactory ? $parent($c) : $parent, $c);
};
if (property_exists($this, $id)) {
$this->$id = $callable($this->$id, $this);
Expand All @@ -98,9 +96,7 @@ public function __get($id)
throw new InvalidArgumentException(sprintf('Identifier "%s" is undefined.', $id));
}
$value = $this->values[$id];
if (is_callable($value)) {
$value = $value($this);
}
return $this->$id = $value;
$isFactory = is_object($value) && method_exists($value, '__invoke');
return $this->$id = $isFactory ? $value($this) : $value;
}
}

0 comments on commit b6bd751

Please sign in to comment.