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


PHP ReflectionMethod::getClosure方法代码示例

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


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

示例1: closure

 /**
  * @param  mixed   class, object, callable
  * @param  string  method
  * @return \Closure
  */
 public static function closure($callable, $m = NULL)
 {
     if ($m !== NULL) {
         $callable = array($callable, $m);
     } elseif (is_string($callable) && count($tmp = explode('::', $callable)) === 2) {
         $callable = $tmp;
     } elseif ($callable instanceof \Closure) {
         return $callable;
     } elseif (is_object($callable)) {
         $callable = array($callable, '__invoke');
     }
     if (PHP_VERSION_ID >= 50400) {
         if (is_string($callable) && function_exists($callable)) {
             $r = new \ReflectionFunction($callable);
             return $r->getClosure();
         } elseif (is_array($callable) && method_exists($callable[0], $callable[1])) {
             $r = new \ReflectionMethod($callable[0], $callable[1]);
             return $r->getClosure($callable[0]);
         }
     }
     self::check($callable);
     $_callable_ = $callable;
     return function () use($_callable_) {
         return call_user_func_array($_callable_, func_get_args());
     };
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:31,代码来源:Callback.php

示例2: exec

 /**
  * Execute command
  *
  * @return int|mixed
  * @throws \Exception
  */
 public function exec()
 {
     $args = func_get_args();
     if (!$this->cmd) {
         throw new FWException('no cmd provided', 1);
     }
     $build = new ProcessBuilder();
     $pro = $build->setPrefix($this->cmd)->setArguments($args)->getProcess();
     $pro->setTimeout($this->timeout);
     $rm = new \ReflectionMethod($this, 'output');
     $func = $rm->getClosure($this);
     $re = 0;
     if ($this->async) {
         $pro->start($func);
     } else {
         try {
             $pro->mustRun($func);
             $this->out = $pro->getOutput();
             $re = $this->out;
         } catch (ProcessFailedException $e) {
             getLog()->error($e->getMessage());
             $re = 1;
         }
     }
     return $re;
 }
开发者ID:wwtg99,项目名称:flight2wwu,代码行数:32,代码来源:CommandPlugin.php

示例3: __construct

 public function __construct(LoggerInterface $logger)
 {
     $build = new \ReflectionMethod($this, 'buildCallback');
     $run = new \ReflectionMethod($this, 'runCallback');
     $this->buildCallback = $build->getClosure($this);
     $this->runCallback = $run->getClosure($this);
     $this->logger = $logger;
 }
开发者ID:Chris7,项目名称:JoliCi,代码行数:8,代码来源:LoggerCallback.php

示例4: method

 public function method($controller_root, $method)
 {
     $controller = $this->controller;
     $class = $this->class;
     $controller_model_name = $controller_root . '\\' . $class;
     $func = new \ReflectionMethod($controller_model_name, $method);
     $Closure = $func->getClosure(new $controller_model_name());
     $controller->{$class}()->Methods[$method] = $Closure->bindTo($controller->{$class}(), $controller->{$class}());
     return $controller->{$class}()->Methods[$method];
 }
开发者ID:Ermile,项目名称:Saloos,代码行数:10,代码来源:load.php

示例5: execute

function execute($class_name, $method_name, $instance)
{
    try {
        $ref = new ReflectionMethod($class_name, $method_name);
        $method = $ref->getClosure($instance);
        var_dump($method());
    } catch (Exception $e) {
        $c = get_class($e);
        echo "{$c}: {$e->getMessage()}\n";
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:get_closure_instance.php

示例6: __construct

 public function __construct()
 {
     if (PHP_VERSION_ID >= 50400) {
         if (is_int($code = http_response_code())) {
             $this->code = $code;
         }
     }
     if (PHP_VERSION_ID >= 50401) {
         // PHP bug #61106
         $rm = new \ReflectionMethod('Nette\\Http\\Helpers::removeDuplicateCookies');
         header_register_callback($rm->getClosure());
         // requires closure due PHP bug #66375
     }
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:14,代码来源:Response.php

示例7: addMethod

 /**
  * Extracts the named method from the supplied object and attaches
  * it to the skeleton instance
  * 
  * @param object $object
  * @param string $methodName
  * @param string $newMethodName - optional: attach the method under a new name
  * @throws InvalidObjectException When the $object param isn't actually an object
  * @throws InvalidMethodException When the named method is not callable
  * @return \Vanqard\Frankenbuilder\Builder fluent interface
  */
 public function addMethod($object, $methodName, $newMethodName = null)
 {
     if (!is_object($object)) {
         throw new InvalidObjectException('First parameter must be an object instance');
     }
     if (!is_callable(array($object, $methodName))) {
         throw new InvalidMethodException('The named method must be callable on the supplied object');
     }
     $methodInstance = new \ReflectionMethod($object, $methodName);
     $limb = $methodInstance->getClosure($object);
     $limbName = !is_null($newMethodName) ? $newMethodName : $methodName;
     $this->addToSkeleton($limbName, $limb);
     return $this;
 }
开发者ID:vanqard,项目名称:frankenbuilder,代码行数:25,代码来源:Builder.php

示例8: call

 /**
  * Call a action of controller
  * 
  * @access public
  * @param MVC $mvc         MVC Application object
  * @param string $method   Method or Function of the Class Controller
  * @param string $fileView String of the view file
  * @return array           Response array
  * @throws \LogicException
  */
 public final function call(MVC $mvc, $method, $fileView = null)
 {
     if (!method_exists($this, $method)) {
         throw new \LogicException(sprintf('Method "s" don\'t exists.', $method));
     }
     # Replace the view object
     $this->view = $mvc->view();
     # Arguments of method
     $arguments = array();
     # Create a reflection method
     $reflectionMethod = new \ReflectionMethod(get_class($this), $method);
     $reflectionParams = $reflectionMethod->getParameters();
     foreach ($reflectionParams as $param) {
         if ($paramClass = $param->getClass()) {
             $className = $paramClass->name;
             if ($className === 'MVC\\MVC' || $className === '\\MVC\\MVC') {
                 $arguments[] = $mvc;
             } elseif ($className === 'MVC\\Server\\HttpRequest' || $className === '\\MVC\\Server\\HttpRequest') {
                 $arguments[] = $mvc->request();
             }
         } else {
             foreach ($mvc->request()->params as $keyReqParam => $valueReqParam) {
                 if ($param->name === $keyReqParam) {
                     $arguments[] = $valueReqParam;
                     break;
                 }
             }
         }
     }
     $response = call_user_func_array($reflectionMethod->getClosure($this), $arguments);
     if (empty($response)) {
         throw new \LogicException('Response null returned.');
     }
     if (is_string($response)) {
         $this->response['body'] = $response;
     } elseif ($mvc->request()->isAjax()) {
         $this->response['body'] = $this->renderJson($response);
     } elseif (is_array($response)) {
         if (!$fileView) {
             throw new \LogicException('File view is null.');
         }
         $class = explode("\\", get_called_class());
         $classname = end($class);
         // Class without Controller
         $classname = str_replace('Controller', '', $classname);
         $file = $classname . "/{$fileView}";
         $this->response['body'] = $this->renderHtml($file, $response);
     }
     return $this->response;
 }
开发者ID:simple-php-mvc,项目名称:simple-php-mvc,代码行数:60,代码来源:Controller.php

示例9: loadTable

 public static function loadTable($name, $db_name = db_name)
 {
     if (isset(self::$tables[$db_name][$name])) {
         return self::$tables[$db_name][$name];
     }
     $blackList = array("index", "foreign", "unique");
     $sName = "\\database\\{$db_name}\\{$name}";
     if (class_exists($sName)) {
         $table_load = new $sName();
         foreach ($table_load as $key => $value) {
             if (!preg_grep("/^{$key}\$/", $blackList)) {
                 $keys = array_keys($value);
                 $values = array_values($value);
                 $array = array();
                 foreach ($keys as $k => $v) {
                     if (is_int($v)) {
                         $keys[$k] = $values[$k];
                         $values[$k] = true;
                     }
                 }
                 if (method_exists($table_load, $key)) {
                     $options = new \lib\sql\options();
                     $func = new \ReflectionMethod($sName, $key);
                     $Closure = $func->getClosure($table_load);
                     $options->{$key} = \Closure::bind($Closure, $options);
                     $options->table = $table_load;
                     $options->tableName = $table_load;
                     $options->fieldName = $key;
                     $values[] = $options;
                     $keys[] = 'closure';
                 }
                 $array = array_combine($keys, $values);
                 $table_load->{$key} = (object) $array;
             }
         }
         foreach ($table_load as $key => $value) {
             if (method_exists($table_load, $key)) {
                 if (isset($table_load->{$key}->closure)) {
                     $closure = $table_load->{$key}->closure;
                     call_user_func($closure->{$key});
                 }
             }
         }
         self::$tables[$db_name][$name] = $table_load;
         return $table_load;
     }
     return null;
 }
开发者ID:Ermile,项目名称:Saloos,代码行数:48,代码来源:table.php

示例10: testExpandClasses

 public function testExpandClasses()
 {
     $r = new \ReflectionClass(AddClassesToCachePass::class);
     $pass = $r->newInstanceWithoutConstructor();
     $r = new \ReflectionMethod(AddClassesToCachePass::class, 'expandClasses');
     $expand = $r->getClosure($pass);
     $this->assertSame('Foo', $expand(array('Foo'), array())[0]);
     $this->assertSame('Foo', $expand(array('\\Foo'), array())[0]);
     $this->assertSame('Foo', $expand(array('Foo'), array('\\Foo'))[0]);
     $this->assertSame('Foo', $expand(array('Foo'), array('Foo'))[0]);
     $this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar'))[0]);
     $this->assertSame('Foo', $expand(array('Foo'), array('\\Foo\\Bar'))[0]);
     $this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar\\Acme'))[0]);
     $this->assertSame('Foo\\Bar', $expand(array('Foo\\'), array('\\Foo\\Bar'))[0]);
     $this->assertSame('Foo\\Bar\\Acme', $expand(array('Foo\\'), array('\\Foo\\Bar\\Acme'))[0]);
     $this->assertEmpty($expand(array('Foo\\'), array('\\Foo')));
     $this->assertSame('Acme\\Foo\\Bar', $expand(array('**\\Foo\\'), array('\\Acme\\Foo\\Bar'))[0]);
     $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo\\Bar')));
     $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Acme\\Foo')));
     $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo')));
     $this->assertSame('Acme\\Foo', $expand(array('**\\Foo'), array('\\Acme\\Foo'))[0]);
     $this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\Foo\\AcmeBundle')));
     $this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\FooBar\\AcmeBundle')));
     $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
     $this->assertEmpty($expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar')));
     $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
     $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
     $this->assertSame('Acme\\Bar', $expand(array('*\\Bar'), array('\\Acme\\Bar'))[0]);
     $this->assertEmpty($expand(array('*\\Bar'), array('\\Bar')));
     $this->assertEmpty($expand(array('*\\Bar'), array('\\Foo\\Acme\\Bar')));
     $this->assertSame('Foo\\Acme\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
     $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
     $this->assertEmpty($expand(array('**\\Bar'), array('\\Bar')));
     $this->assertSame('Foo\\Bar', $expand(array('Foo\\*'), array('\\Foo\\Bar'))[0]);
     $this->assertEmpty($expand(array('Foo\\*'), array('\\Foo\\Acme\\Bar')));
     $this->assertSame('Foo\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Bar'))[0]);
     $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
     $this->assertSame(array('Foo\\Bar'), $expand(array('Foo\\*'), array('Foo\\Bar', 'Foo\\BarTest')));
     $this->assertSame(array('Foo\\Bar', 'Foo\\BarTest'), $expand(array('Foo\\*', 'Foo\\*Test'), array('Foo\\Bar', 'Foo\\BarTest')));
     $this->assertSame('Acme\\FooBundle\\Controller\\DefaultController', $expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\DefaultController'))[0]);
     $this->assertSame('FooBundle\\Controller\\DefaultController', $expand(array('**Bundle\\Controller\\'), array('\\FooBundle\\Controller\\DefaultController'))[0]);
     $this->assertSame('Acme\\FooBundle\\Controller\\Bar\\DefaultController', $expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'))[0]);
     $this->assertSame('Bundle\\Controller\\Bar\\DefaultController', $expand(array('**Bundle\\Controller\\'), array('\\Bundle\\Controller\\Bar\\DefaultController'))[0]);
     $this->assertSame('Acme\\Bundle\\Controller\\Bar\\DefaultController', $expand(array('**Bundle\\Controller\\'), array('\\Acme\\Bundle\\Controller\\Bar\\DefaultController'))[0]);
     $this->assertSame('Foo\\Bar', $expand(array('Foo\\Bar'), array())[0]);
     $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
 }
开发者ID:ayoah,项目名称:symfony,代码行数:47,代码来源:AddClassesToCachePassTest.php

示例11: load

 /**
  * Add routes to an App from this class by inferring details from PHPDoc @url and @method properties
  * @param App $app
  */
 public function load(App $app)
 {
     $class = get_called_class();
     $methods = get_class_methods($class);
     foreach ($methods as $class_method) {
         $method_props = [];
         $rm = new \ReflectionMethod($this, $class_method);
         $phpdoc = preg_split('/\\r\\n|\\n|\\r/', preg_replace('%^\\s*/?\\*+((?<=\\*)/|[ \\t]*)%m', '', $rm->getDocComment()));
         foreach ($phpdoc as $docline) {
             if (preg_match('#^@(url|method)\\s+(\\S+)$#', $docline, $matches)) {
                 $method_props[$matches[1]] = $matches[2];
             }
         }
         if (isset($method_props['url'])) {
             $route = $app->route($class . '::' . $class_method, $method_props['url'], $rm->getClosure($this));
             if (isset($method_props['method'])) {
                 $route->via($method_props['method']);
             }
         }
     }
 }
开发者ID:ringmaster,项目名称:microsite2,代码行数:25,代码来源:Handler.php

示例12: castToClosure

 /**
  * Casts the given callable to Closure
  * @param callable $callable
  * @return \Closure
  * @throws \InvalidArgumentException
  */
 protected function castToClosure($callable)
 {
     if (!is_callable($callable)) {
         throw new \InvalidArgumentException('Argument 1 must be callable, ' . gettype($callable) . ' given.');
     }
     $result = null;
     if (is_object($callable)) {
         if ($callable instanceof \Closure) {
             $result = $callable;
         } else {
             if (method_exists($callable, '__invoke')) {
                 $r = new \ReflectionObject($callable);
                 $result = $r->getMethod('__invoke')->getClosure($callable);
             }
         }
     } else {
         try {
             $r = new \ReflectionMethod($callable);
             $result = $r->getClosure();
         } catch (\Exception $e) {
             try {
                 $r = new \ReflectionFunction($callable);
                 $result = $r->getClosure();
             } catch (\Exception $e) {
                 if (is_array($callable)) {
                     $r = new \ReflectionObject($callable[0]);
                     $result = $r->getMethod($callable[1])->getClosure($callable[0]);
                 }
             }
         }
     }
     if ($result === null) {
         throw new \InvalidArgumentException('Unsupported callable given.');
     }
     return $result;
 }
开发者ID:Webapper,项目名称:d3i,代码行数:42,代码来源:Provider.php

示例13: getClosure

 /**
  * Returns the function/method as closure.
  *
  * @param object $object Object
  *
  * @return \Closure
  */
 public function getClosure($object)
 {
     if (PHP_VERSION >= 50400) {
         return parent::getClosure();
     } else {
         $that = $this;
         return function () use($object, $that) {
             return $that->invokeArgs($object, func_get_args());
         };
     }
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:18,代码来源:ReflectionMethod.php

示例14: getClosure

 /**
  * @return	Closure
  */
 public function getClosure()
 {
     if ($this->closure instanceof \Closure) {
         return $this->closure;
     }
     $reflect = new \ReflectionMethod($this->closure);
     return $reflect->getClosure();
 }
开发者ID:huxtable,项目名称:cli,代码行数:11,代码来源:Command.php

示例15: yolisp

function yolisp($swag, array &$env = [])
{
    static $OP_CACHE = [];
    // HAH! Take that Zend!
    if (!$swag instanceof cons) {
        // implicitly quote non-strings
        if (!is_string($swag)) {
            return $swag;
        }
        // lookup in environment
        if (array_key_exists($swag, $env)) {
            return $env[$swag];
        } else {
            if (isset($OP_CACHE[$swag])) {
                return $OP_CACHE[$swag];
            } else {
                if (array_key_exists($swag, DEFAULT_ENV)) {
                    $callable = DEFAULT_ENV[$swag];
                    if (is_array($callable)) {
                        return $OP_CACHE[$swag] = (new \ReflectionMethod(...$callable))->getClosure();
                    } else {
                        if (is_string($callable)) {
                            return $OP_CACHE[$swag] = (new \ReflectionFunction($callable))->getClosure();
                        } else {
                            return $callable;
                        }
                    }
                } else {
                    if (function_exists($swag)) {
                        return $OP_CACHE[$swag] = (new \ReflectionFunction($swag))->getClosure();
                        // we do class lookup after function lookup because everyone knows functional programming is superior
                        // what did you expect? this is yolisp, not yojava
                    } else {
                        if (class_exists($swag)) {
                            return $swag;
                        } else {
                            if (array_key_exists($swag, OPS)) {
                                $format = OPS[$swag];
                                $ops = substr_count($format, '$');
                                $ops += $optional_ops = substr_count($format, '?');
                                if ($ops === 0) {
                                    throw new \Exception("Invalid operator format string: \"{$format}\"");
                                }
                                $param_names = [];
                                for ($i = 0; $i < $ops; $i++) {
                                    $param_names[] = '$op' . $i;
                                }
                                $param_list = '';
                                for ($i = 0; $i < $ops; $i++) {
                                    if ($i !== 0) {
                                        $param_list .= ', ';
                                    }
                                    $param_list .= $param_names[$i];
                                    if ($i >= $ops - $optional_ops) {
                                        $param_list .= ' = NULL';
                                    }
                                }
                                $parts = explode(' ', $format);
                                if ($optional_ops) {
                                    $optionless_expr = '';
                                    $i = 0;
                                    foreach ($parts as $part) {
                                        if ($part === '?') {
                                            $optionless_expr .= ' ';
                                        } else {
                                            if ($part === '$') {
                                                $optionless_expr .= ' ' . $param_names[$i];
                                                $i++;
                                            } else {
                                                $optionless_expr .= ' ' . $part;
                                            }
                                        }
                                    }
                                }
                                $expr = '';
                                $i = 0;
                                foreach ($parts as $part) {
                                    if ($part === '?' || $part === '$') {
                                        $expr .= ' ' . $param_names[$i];
                                        $i++;
                                    } else {
                                        $expr .= ' ' . $part;
                                    }
                                }
                                if ($optional_ops) {
                                    $body = "if (func_num_args() < {$ops}) { return {$optionless_expr}; } else { return {$expr}; }";
                                } else {
                                    $body = "return {$expr};";
                                }
                                // And people said eval() and create_function() were evil!
                                return $OP_CACHE[$swag] = create_function($param_list, $body);
                            } else {
                                throw new \Exception("Could not find {$swag} in environment");
                            }
                        }
                    }
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:TazeTSchnitzel,项目名称:yolo,代码行数:101,代码来源:yolisp.php


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