Skip to content

Commit

Permalink
Sets a request for Requestable instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
romeOz committed Nov 4, 2015
1 parent 6205b9e commit 720b5d8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/ComponentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,23 @@ public function ensureBehaviors()
*/
private function _attachBehaviorInternal($name, $behavior)
{
if (!($behavior instanceof Behavior)) {
$behavior = Instance::ensure($behavior);
}
if ($behavior instanceof FilterInterface && $this instanceof Responseble) {
if (is_array($behavior)) {
if (isset($behavior['class'])) {
if (is_subclass_of($behavior['class'], '\rock\filters\FilterInterface')
&& $this instanceof Responseble) {
$behavior['response'] = $this->response;
} elseif (is_subclass_of($behavior['class'], '\rock\request\Requestable') && $this instanceof \rock\request\Requestable) {
$behavior['request'] = $this->request;
}
}
} elseif ($behavior instanceof FilterInterface && $this instanceof Responseble) {
$behavior->response = $this->response;
} elseif ($behavior instanceof \rock\request\Requestable && $this instanceof \rock\request\Requestable) {
$behavior->request = $this->request;
}
/** @var Behavior $behavior */
$behavior = Instance::ensure($behavior);

/** @var ComponentsInterface|static $this */
if (is_int($name)) {
$behavior->attach($this);
Expand Down

0 comments on commit 720b5d8

Please sign in to comment.