当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionFunction::isClosure方法代码示例

本文整理汇总了PHP中ReflectionFunction::isClosure方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::isClosure方法的具体用法?PHP ReflectionFunction::isClosure怎么用?PHP ReflectionFunction::isClosure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionFunction的用法示例。


在下文中一共展示了ReflectionFunction::isClosure方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: call

 public function call($group, $hook, $parameters = null, $action = null)
 {
     if (!isset($action)) {
         $action = 'execute';
     }
     if (!isset($this->hooks[$this->site][$group][$hook][$action])) {
         $this->register($group, $hook, $action);
     }
     $calls = [];
     if (isset($this->hooks[$this->site][$group][$hook][$action])) {
         $calls = $this->hooks[$this->site][$group][$hook][$action];
     }
     if (isset($this->watches[$this->site][$group][$hook][$action])) {
         $calls = array_merge($calls, $this->watches[$this->site][$group][$hook][$action]);
     }
     $result = [];
     foreach ($calls as $code) {
         $bait = null;
         if (is_string($code)) {
             $class = Apps::getModuleClass($code, 'Hooks');
             $obj = new $class();
             $bait = $obj->{$action}($parameters);
         } else {
             $ref = new \ReflectionFunction($code);
             if ($ref->isClosure()) {
                 $bait = $code($parameters);
             }
         }
         if (!empty($bait)) {
             $result[] = $bait;
         }
     }
     return $result;
 }
开发者ID:haraldpdl,项目名称:oscommerce2,代码行数:34,代码来源:Hooks.php

示例2: from

 /**
  * @return self
  */
 public static function from($from) : self
 {
     if (is_string($from) && strpos($from, '::')) {
         $from = new \ReflectionMethod($from);
     } elseif (is_array($from)) {
         $from = new \ReflectionMethod($from[0], $from[1]);
     } elseif (!$from instanceof \ReflectionFunctionAbstract) {
         $from = new \ReflectionFunction($from);
     }
     $method = new static();
     $method->name = $from->isClosure() ? NULL : $from->getName();
     foreach ($from->getParameters() as $param) {
         $method->parameters[$param->getName()] = Parameter::from($param);
     }
     if ($from instanceof \ReflectionMethod) {
         $method->static = $from->isStatic();
         $method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
         $method->final = $from->isFinal();
         $method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
         $method->body = $from->isAbstract() ? FALSE : '';
     }
     $method->returnReference = $from->returnsReference();
     $method->variadic = PHP_VERSION_ID >= 50600 && $from->isVariadic();
     $method->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
     if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
         $returnType = $from->getReturnType();
         $method->returnType = $returnType->isBuiltin() ? (string) $returnType : '\\' . $returnType;
     }
     return $method;
 }
开发者ID:kukulich,项目名称:php-generator,代码行数:33,代码来源:Method.php

示例3: __construct

 /**
  * @param \ReflectionFunction $reflection
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(\ReflectionFunction $reflection)
 {
     if (!$reflection->isClosure()) {
         throw new \InvalidArgumentException('You must provide the reflection of a closure.');
     }
     $this->reflection = $reflection;
 }
开发者ID:ningcaichen,项目名称:laravel-4.1-quick-start-cn,代码行数:12,代码来源:ClosureParser.php

示例4: invokeClosure

 protected function invokeClosure($targetValue)
 {
     if (is_callable($this->condition)) {
         $reflection = new \ReflectionFunction($this->condition);
         if (!$reflection->isClosure()) {
             throw new Exceptions\NotCallable("Specified condition is not closure, can't proceed");
         }
         return $reflection->invokeArgs(array($targetValue));
     }
     return false;
 }
开发者ID:non3x,项目名称:validus,代码行数:11,代码来源:Closure.php

示例5: checkIfIsClosureOrCode

 private function checkIfIsClosureOrCode($function)
 {
     if (is_string($function)) {
         return;
     }
     if (!is_callable($function) || !is_object($function)) {
         throw new RegisteringInvalidClosureException();
     }
     $rf = new \ReflectionFunction($function);
     if (!$rf->isClosure()) {
         throw new RegisteringInvalidClosureException();
     }
 }
开发者ID:conpago,项目名称:conpago-di,代码行数:13,代码来源:ClosureRegisterer.php

示例6: addHook

 /**
  * @param array|\Closure  $function
  * @param string          $column
  *
  * @return $this|bool
  * @throws \BadFunctionCallException
  * @throws \InvalidArgumentException
  * @throws \LengthException
  */
 public function addHook($function, $column)
 {
     //check for closure
     if (false === is_array($function)) {
         $functionReflected = new \ReflectionFunction($function);
         if ($functionReflected->isClosure()) {
             $this->hooks[$column] = $function;
             return true;
         }
     } else {
         if (2 !== count($function)) {
             throw new \LengthException('Exactly two parameters required!');
         }
         if (false === is_callable($function)) {
             throw new \BadFunctionCallException(sprintf('Function %s in class %s is non callable!', $function[1], $function[0]));
         }
         $this->hooks[$column] = [$function[0], $function[1]];
     }
     return $this;
 }
开发者ID:antqa,项目名称:DataExporterBundle,代码行数:29,代码来源:DataExporter.php

示例7: method

<?php

class MyClass
{
    public function method()
    {
    }
}
$object = new MyClass();
$reflector = new \ReflectionMethod($object, 'method');
$closure = $reflector->getClosure($object);
$closureReflector = new \ReflectionFunction($closure);
var_dump($closureReflector->isClosure());
开发者ID:gleamingthecube,项目名称:php,代码行数:13,代码来源:ext_reflection_tests_bug67068.php

示例8: renderFooter

 /**
  * Renders the footer row.
  *
  * @param string $html 	The string to which it footer should be appended.
  * 						This should of course be the already (almost finished) table.
  *
  * @return string 		The $html argument with the table appended.
  */
 protected function renderFooter($html)
 {
     $hasFooter = false;
     $footer = '<tr>';
     $emptyCount = 1;
     foreach ($this->columns as $column) {
         // Do only something if we have a footer.
         if (isset($column['footerData'])) {
             $hasFooter = true;
             // Render the empty cells before.
             if ($emptyCount > 0) {
                 $footer .= '<td colspan="' . $emptyCount . '"></td>';
                 $emptyCount = 0;
             }
             $dataContainer = $column['footerData'];
             if (is_string($dataContainer)) {
                 // Just show the static string
                 $footer .= '<td>' . $dataContainer . "</td>";
             } else {
                 $rf = new \ReflectionFunction($dataContainer);
                 if ($rf->isClosure()) {
                     // Call the closure and get the result
                     $value = $dataContainer($this->getData(), $this);
                     $footer .= "<td>" . $value . "</td>";
                 }
             }
         } else {
             // Let's remember how many empty cell there was.
             $emptyCount++;
         }
     }
     // Render empty cells (if we have)
     if ($emptyCount > 0) {
         $footer .= '<td colspan="' . $emptyCount . '"></td>';
     }
     $footer .= "</tr>";
     if ($hasFooter) {
         $html .= $footer;
     }
     return $html;
 }
开发者ID:jogli5er,项目名称:telegames,代码行数:49,代码来源:Table.php

示例9: parseUrl

 public function parseUrl(Url $url = null)
 {
     if ($url) {
         $this->url = $url;
         // override existing
     }
     if (!$this->url instanceof Url) {
         throw new ConfigException('No Url instance supplied for parser.');
     }
     $pathComponents = $this->url->pathComponents;
     // Iterate through each and convert to class or method name
     foreach ($pathComponents as &$pathComponent) {
         $pathComponent = str_replace('-', '_', ucfirst($pathComponent));
     }
     $projectControllers = $this->project->ns . '\\Controllers\\';
     // Attempt 1: Look for Routes class in project and call routeResolver method
     $method = self::ROUTE_RESOLVER;
     $controller = $this->project->ns . '\\Routes';
     if (method_exists($controller, $method)) {
         // Call the project routeResolver method
         $route = call_user_func(array(new $controller($this->project), $method), $this->url);
         // If we get a class name back, look for another routeResolver method within
         if (is_string($route) && strpos($route, '::') === false && class_exists($projectControllers . $route) && method_exists($projectControllers . $route, $method)) {
             $savedRoute = $route;
             $routeController = $projectControllers . $route;
             $controllerClass = new $routeController($this->project);
             // Call routeResolver in the controller class
             $route = call_user_func(array($controllerClass, $method), $this->url);
             // If I get a partial string result, assume it's a method response, otherwise prepare for fallback
             if (is_string($route) && strpos($route, '::') === false && is_callable(array($controllerClass, $route))) {
                 return $this->invokeClassMethod($controllerClass, $route);
             } else {
                 $pathComponents[0] = $savedRoute;
             }
         }
         // If we get a string back in format $controller::$method, look for the method
         // If the return class method starts with "\" char, look outside the project controller tree
         if (is_string($route) && strpos($route, '::') !== false) {
             list($controller, $method) = explode('::', ($route[0] != '\\' ? $projectControllers : '') . $route);
             if (class_exists($controller) && is_callable($controller . '::' . $method, true)) {
                 return $this->invokeClassMethod(new $controller($this->project), $method);
             }
         }
         // Otherwise, if we get a closure back, call it
         if (is_callable($route)) {
             if (is_array($route) && count($route) == 2) {
                 return $this->invokeClassMethod($route[0], $route[1]);
             } else {
                 $reflection = new \ReflectionFunction($route);
                 if ($reflection->isClosure()) {
                     return $this->invokeFunction($route);
                 }
             }
         }
     }
     // Attempt 2: pointing to a controller with a routeResolver method
     $path = $pathComponents;
     $method = self::ROUTE_RESOLVER;
     $controller = $projectControllers . (empty($path) ? 'Index' : $path[0]);
     $controllerClass = class_exists($controller) ? new $controller($this->project) : null;
     if ($controllerClass && method_exists($controllerClass, $method)) {
         // Call routeResolver in the controller class
         $route = call_user_func(array($controllerClass, $method), $this->url);
         // If we get a string back in format $controller::$method, look for the method
         // If the return class method starts with "\" char, look outside the project controller tree
         if (is_string($route) && strpos($route, '::') !== false) {
             list($controller, $method) = explode('::', ($route[0] != '\\' ? $projectControllers : '') . $route);
             if (class_exists($controller) && is_callable($controller . '::' . $method, true)) {
                 return $this->invokeClassMethod(new $controller($this->project), $method);
             }
         }
         // If we get a partial string result, assume it's a method response
         if (is_string($route) && strpos($route, '::') === false && is_callable(array($controllerClass, $route))) {
             return $this->invokeClassMethod($controllerClass, $route);
         }
         // Otherwise, if we get a closure back, call it
         if (is_callable($route)) {
             if (is_array($route) && count($route) == 2) {
                 return $this->invokeClassMethod($route[0], $route[1]);
             } else {
                 $reflection = new \ReflectionFunction($route);
                 if ($reflection->isClosure()) {
                     return $this->invokeFunction($route);
                 }
             }
         }
     }
     // Attempt 3: pointing to a specific route* method within the controller
     if (count($pathComponents) > 1) {
         $path = $pathComponents;
         $controllerClass = array_shift($path);
         $methodName = array_shift($path);
         $method = $methodName != null ? 'route' . $methodName : self::ROUTE_DEFAULT;
         $controller = $this->findController($controllerClass);
         if ($controller) {
             $methodFound = $this->findMethod($controller, $method);
             if ($methodFound) {
                 return $methodFound;
             }
         }
//.........这里部分代码省略.........
开发者ID:shaggy8871,项目名称:frame,代码行数:101,代码来源:Router.php

示例10: addHook

 /**
  * @param $function
  * @param $column
  * @return $this|bool
  * @throws \BadFunctionCallException
  * @throws \InvalidArgumentException
  * @throws \LengthException
  */
 public function addHook($function, $column)
 {
     //check for closure
     if (false === is_array($function)) {
         $f = new \ReflectionFunction($function);
         if ($f->isClosure()) {
             $this->hooks[$column] = $function;
             return true;
         }
     } else {
         if (2 !== count($function)) {
             throw new \LengthException('Exactly two parameters required!');
         }
         if (!in_array($column, $this->columns)) {
             throw new \InvalidArgumentException(sprintf("Parameter column must be someone defined in setColumns function!\nRecived: %s\n Expected one of: %s", $function[1], implode(', ', $this->columns)));
         }
         if (!is_callable($function)) {
             throw new \BadFunctionCallException(sprintf('Function %s in class %s non exist!', $function[1], $function[0]));
         }
         $this->hooks[$column] = array($function[0], $function[1]);
     }
     return $this;
 }
开发者ID:linagora,项目名称:DataExporter,代码行数:31,代码来源:DataExporter.php

示例11: validate

 public function validate($validationClosure)
 {
     try {
         $reflection = new \ReflectionFunction($validationClosure);
     } catch (\Exception $e) {
         throw new \Exception('Validate not called with Closure');
     }
     if (!$reflection->isClosure()) {
         throw new \Exception('Validate not called with Closure');
     }
     $this->validationClosure = $validationClosure;
     if (!$this->sessionCheck()) {
         throw new \Exception('NOT_LOGGED_IN');
     }
 }
开发者ID:ajurgensen,项目名称:phpMagic,代码行数:15,代码来源:pageMagic.php

示例12: function

<?php

$closure = function ($param) {
    return "this is a closure";
};
$rc = new ReflectionFunction($closure);
var_dump($rc->isClosure());
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:ReflectionFunction_isClosure_basic.php

示例13: isClosure

 protected function isClosure($value)
 {
     if (!is_callable($value)) {
         return false;
     }
     $reflection = new \ReflectionFunction($value);
     return (bool) $reflection->isClosure();
 }
开发者ID:lucatume,项目名称:wp-browser,代码行数:8,代码来源:WPBootstrapper.php

示例14: not_a_closure

<?php

function not_a_closure()
{
    return 1;
}
$rf = new ReflectionFunction('not_a_closure');
var_dump($rf->isClosure());
var_dump($rf->isGenerator());
function is_a_generator()
{
    (yield 1);
    (yield 2);
}
$rf = new ReflectionFunction('is_a_generator');
var_dump($rf->isClosure());
var_dump($rf->isGenerator());
$cl = function () {
    return 1;
};
$rf = new ReflectionFunction($cl);
var_dump($rf->isClosure());
var_dump($rf->isGenerator());
$cl = function () {
    (yield 1);
    (yield 2);
};
$rf = new ReflectionFunction($cl);
var_dump($rf->isClosure());
var_dump($rf->isGenerator());
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:1365.php


注:本文中的ReflectionFunction::isClosure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。