Created
June 29, 2012 06:18
-
-
Save co3k/3016197 to your computer and use it in GitHub Desktop.
symfony 1.4.x は *.method_not_found というイベントを用意する時点でこういうのをフレームワークとして用意して欲しかったニャー (ああでもこの手の奴は PHP 5.3.x 前提だから無理ってことですねはい)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 想像を形にしてみただけなので動かないかもよ | |
class sfInjectedMethod | |
{ | |
protected $method, $callable; | |
public __construct($method, $callable) | |
{ | |
$this->method = $method; | |
$this->callable = $callable; | |
} | |
public function __invoke(sfEvent $event) | |
{ | |
if ($this->method !== $event['method']) | |
{ | |
return false; | |
} | |
try | |
{ | |
$result = $this->callable($event); | |
} | |
catch (BadMethodCallException $e) | |
{ | |
return false; | |
} | |
$event->setReturnValue($result); | |
return true; | |
} | |
} | |
// Usage: | |
$dispatcher->connect('request.method_not_found', new sfInjectedMethod('getSpecialInformation', function(sfEvent $event) { | |
return $event->getSubject()->getHttpHeader('X-Co3k'); | |
}); | |
var_dump($request->getSpecialInformation()); // is now available method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment