Skip to content

Commit

Permalink
Moving the instantiation of a controller into the Dispatch objects
Browse files Browse the repository at this point in the history
dispatch() method.

This meens that isDispatchable() now uses reflection to run it's tests.

Fixes proem#126
  • Loading branch information
trq committed Aug 30, 2012
1 parent a530239 commit 2bf3437
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Proem/Dispatch/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ public function isDispatchable()
$map
);

if (class_exists($this->class)) {
$this->class = new $this->class($this->assets);
if ($this->class instanceof \Proem\Controller\Template) {
if (is_callable([$this->class, $this->action . 'Action'])) {
try {
$class = new \ReflectionClass($this->class);
if ($class->implementsInterface('\Proem\Controller\Template')) {
$method = $class->getMethod($this->action . 'Action');
if ($method->isPublic()) {
return true;
}
}
} catch (\ReflectionException $e) {
return false;
}
}

Expand All @@ -187,6 +190,8 @@ public function dispatch()
if ($this->assets->has('request')) {
$this->assets->get('request')->injectPayload($this->payload->prepare());
}

$this->class = new $this->class($this->assets);
$this->class->dispatch($this->action);
return $this;
}
Expand Down

0 comments on commit 2bf3437

Please sign in to comment.