本文整理匯總了PHP中Nette\Reflection\ClassType::getExtensionMethod方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassType::getExtensionMethod方法的具體用法?PHP ClassType::getExtensionMethod怎麽用?PHP ClassType::getExtensionMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Reflection\ClassType
的用法示例。
在下文中一共展示了ClassType::getExtensionMethod方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: call
/**
* Call to undefined method.
* @param object
* @param string method name
* @param array arguments
* @return mixed
* @throws MemberAccessException
*/
public static function call($_this, $name, $args)
{
$class = new Reflection\ClassType($_this);
if ($name === '') {
throw new MemberAccessException("Call to class '$class->name' method without name.");
}
// event functionality
if ($class->hasEventProperty($name)) {
if (is_array($list = $_this->$name) || $list instanceof \Traversable) {
foreach ($list as $handler) {
callback($handler)->invokeArgs($args);
}
}
return NULL;
}
// extension methods
if ($cb = $class->getExtensionMethod($name)) {
array_unshift($args, $_this);
return $cb->invokeArgs($args);
}
throw new MemberAccessException("Call to undefined method $class->name::$name().");
}
示例2: extensionMethod
/**
* Adding method to class.
* @param string method name
* @param mixed callback or closure
* @return mixed
*/
public static function extensionMethod($name, $callback = NULL)
{
if (strpos($name, '::') === FALSE) {
$class = get_called_class();
} else {
list($class, $name) = explode('::', $name);
}
$class = new Reflection\ClassType($class);
if ($callback === NULL) {
return $class->getExtensionMethod($name);
} else {
$class->setExtensionMethod($name, $callback);
}
}
示例3: call
static function call($_this, $name, $args)
{
$class = new Reflection\ClassType($_this);
if ($name === '') {
throw new MemberAccessException("Call to class '{$class->name}' method without name.");
}
if ($class->hasEventProperty($name)) {
if (is_array($list = $_this->{$name}) || $list instanceof \Traversable) {
foreach ($list as $handler) {
callback($handler)->invokeArgs($args);
}
} elseif ($list !== NULL) {
throw new UnexpectedValueException("Property {$class->name}::\${$name} must be array or NULL, " . gettype($list) . " given.");
}
return NULL;
}
if ($cb = $class->getExtensionMethod($name)) {
array_unshift($args, $_this);
return $cb->invokeArgs($args);
}
throw new MemberAccessException("Call to undefined method {$class->name}::{$name}().");
}