本文整理汇总了PHP中Nette\ObjectMixin::getExtensionMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectMixin::getExtensionMethod方法的具体用法?PHP ObjectMixin::getExtensionMethod怎么用?PHP ObjectMixin::getExtensionMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\ObjectMixin
的用法示例。
在下文中一共展示了ObjectMixin::getExtensionMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Call to undefined method.
* @param string method name
* @param array arguments
* @return mixed
* @throws MemberAccessException
*/
public function __call($name, $args)
{
$class = new Nette\Reflection\ClassType($this);
if ($name === '') {
throw new Nette\MemberAccessException("Call to class '{$class->name}' method without name.");
}
// event functionality
if ($class->hasProperty($name)) {
if (!$this->_eventSetupCalled) {
$this->_eventSetupCalled = true;
$this->eventSetup();
$this->onEventSetup($this);
}
if (is_array($list = $this->{$name}) || $list instanceof \Traversable) {
foreach ($list as $handler) {
callback($handler)->invokeArgs($args);
}
}
return NULL;
}
// extension methods
if ($cb = Nette\ObjectMixin::getExtensionMethod(get_class($this), $name)) {
array_unshift($args, $this);
return $cb->invokeArgs($args);
}
throw new Nette\MemberAccessException("Call to undefined method {$class->name}::{$name}().");
}
示例2: extensionMethod
/**
* Adding method to class.
* @param string method name
* @param callable
* @return mixed
*/
public static function extensionMethod($name, $callback = NULL)
{
if (strpos($name, '::') === FALSE) {
$class = get_called_class();
} else {
list($class, $name) = explode('::', $name);
$rc = new \ReflectionClass($class);
$class = $rc->getName();
}
if ($callback === NULL) {
return ObjectMixin::getExtensionMethod($class, $name);
} else {
ObjectMixin::setExtensionMethod($class, $name, $callback);
}
}