• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ReflectionFunction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: export

 protected function export($var, $return = false)
 {
     if ($var instanceof Closure) {
         /* dump anonymous function in to plain code.*/
         $ref = new ReflectionFunction($var);
         $file = new SplFileObject($ref->getFileName());
         $file->seek($ref->getStartLine() - 1);
         $result = '';
         while ($file->key() < $ref->getEndLine()) {
             $result .= $file->current();
             $file->next();
         }
         $begin = strpos($result, 'function');
         $end = strrpos($result, '}');
         $result = substr($result, $begin, $end - $begin + 1);
     } elseif (is_object($var)) {
         /* dump object with construct function. */
         $result = 'new ' . get_class($var) . '(' . $this->export(get_object_vars($var), true) . ')';
     } elseif (is_array($var)) {
         /* dump array in plain array.*/
         $array = array();
         foreach ($var as $k => $v) {
             $array[] = var_export($k, true) . ' => ' . $this->export($v, true);
         }
         $result = 'array(' . implode(', ', $array) . ')';
     } else {
         $result = var_export($var, true);
     }
     if (!$return) {
         print $result;
     }
     return $result;
 }
开发者ID:schigh,项目名称:router,代码行数:33,代码来源:crouter.php


示例2: wrapClosures

 /**
  * Recursively traverses and wraps all Closure objects within the value.
  *
  * NOTE: THIS MAY NOT WORK IN ALL USE CASES, SO USE AT YOUR OWN RISK.
  *
  * @param mixed $data Any variable that contains closures.
  * @param SerializerInterface $serializer The serializer to use.
  */
 public static function wrapClosures(&$data, SerializerInterface $serializer)
 {
     if ($data instanceof \Closure) {
         // Handle and wrap closure objects.
         $reflection = new \ReflectionFunction($data);
         if ($binding = $reflection->getClosureThis()) {
             self::wrapClosures($binding, $serializer);
             $scope = $reflection->getClosureScopeClass();
             $scope = $scope ? $scope->getName() : 'static';
             $data = $data->bindTo($binding, $scope);
         }
         $data = new SerializableClosure($data, $serializer);
     } elseif (is_array($data) || $data instanceof \stdClass || $data instanceof \Traversable) {
         // Handle members of traversable values.
         foreach ($data as &$value) {
             self::wrapClosures($value, $serializer);
         }
     } elseif (is_object($data) && !$data instanceof \Serializable) {
         // Handle objects that are not already explicitly serializable.
         $reflection = new \ReflectionObject($data);
         if (!$reflection->hasMethod('__sleep')) {
             foreach ($reflection->getProperties() as $property) {
                 if ($property->isPrivate() || $property->isProtected()) {
                     $property->setAccessible(true);
                 }
                 $value = $property->getValue($data);
                 self::wrapClosures($value, $serializer);
                 $property->setValue($data, $value);
             }
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:40,代码来源:Serializer.php


示例3: getReflectedMinimumParams

 function getReflectedMinimumParams($name)
 {
     // Reflection gets this one wrong.
     if (strcasecmp($name, 'define') == 0) {
         return 2;
     }
     if (strcasecmp($name, 'strtok') == 0) {
         return 1;
     }
     if (strcasecmp($name, 'implode') == 0) {
         return 1;
     }
     if (strcasecmp($name, "sprintf") == 0) {
         return 1;
     }
     if (strcasecmp($name, "array_merge") == 0) {
         return 1;
     }
     if (strcasecmp($name, "stream_set_timeout") == 0) {
         return 2;
     }
     try {
         $func = new \ReflectionFunction($name);
         return $func->getNumberOfRequiredParameters();
     } catch (\ReflectionException $e) {
         return -1;
     }
 }
开发者ID:jongardiner,项目名称:StaticAnalysis,代码行数:28,代码来源:FunctionCallCheck.php


示例4: strategyFactory

/**
 * @param array $defaultStrategies
 * @param array $strategyMap
 * @param \FusePump\Cli\Inputs $inputs
 * @param array $arguments
 * @return callable
 */
function strategyFactory($defaultStrategies, $strategyMap = array(), $inputs = null, $arguments = array())
{
    $strategyList = array(function () {
        return false;
    });
    $addStrategy = function ($strategy) use(&$strategyList, $arguments) {
        $args = array();
        $reflection = new \ReflectionFunction($strategy);
        foreach ($reflection->getParameters() as $param) {
            if ($param->getName() === 'patchFile') {
                continue;
            } elseif ($param->getName() === 'superStrategy') {
                $args[] = end($strategyList);
            } elseif (array_key_exists($param->getName(), $arguments)) {
                $args[] = $arguments[$param->getName()];
            } else {
                $args[] = null;
            }
        }
        $strategyList[] = function ($patchFile) use($strategy, $args) {
            return call_user_func_array($strategy, array_merge(array($patchFile), $args));
        };
    };
    foreach ($strategyMap as $option => $strategy) {
        if ($inputs->get($option)) {
            $addStrategy($strategy);
        }
    }
    if (count($strategyList) < 2) {
        foreach ($defaultStrategies as $strategy) {
            $addStrategy($strategy);
        }
    }
    return end($strategyList);
}
开发者ID:jamayka,项目名称:db-patcher,代码行数:42,代码来源:functions.php


示例5: call_closure

 /**
  * Call closure.
  *
  * @param mixed $closure
  * @param array $parameters
  *
  * @return Closure
  */
 protected function call_closure($closure, array $parameters = [])
 {
     if ($closure instanceof Closure) {
         $rc = new ReflectionFunction($closure);
         $args = $rc->getParameters();
         $params = $parameters;
         $classes = [$this->get_class_prefix(get_class($this)), get_class($this), get_parent_class($this)];
         foreach ($args as $index => $arg) {
             if ($arg->getClass() === null) {
                 continue;
             }
             if (in_array($arg->getClass()->name, $classes)) {
                 $parameters[$index] = $this;
             } else {
                 if ($this->exists($arg->getClass()->name)) {
                     $parameters[$index] = $this->make($arg->getClass()->name);
                 }
             }
         }
         if (!empty($args) && empty($parameters)) {
             $parameters[0] = $this;
         }
         if (count($args) > count($parameters)) {
             $parameters = array_merge($parameters, $params);
         }
         return $this->call_closure(call_user_func_array($closure, $parameters), $parameters);
     }
     return $closure;
 }
开发者ID:ekandreas,项目名称:papi,代码行数:37,代码来源:class-papi-container.php


示例6: import

 public function import(\ReflectionFunction $function)
 {
     $this->name = $function->name;
     $this->function = $function->getShortName();
     $this->namespace = $function->getNamespaceName();
     $this->_importFromReflection($function);
 }
开发者ID:bzick,项目名称:koda,代码行数:7,代码来源:FunctionInfo.php


示例7: shouldRun

 private function shouldRun($callback, $controllerResult)
 {
     if (is_array($callback)) {
         $callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
     } elseif (is_object($callback) && !$callback instanceof \Closure) {
         $callbackReflection = new \ReflectionObject($callback);
         $callbackReflection = $callbackReflection->getMethod('__invoke');
     } else {
         $callbackReflection = new \ReflectionFunction($callback);
     }
     if ($callbackReflection->getNumberOfParameters() > 0) {
         $parameters = $callbackReflection->getParameters();
         $expectedControllerResult = $parameters[0];
         if ($expectedControllerResult->getClass() && (!is_object($controllerResult) || !$expectedControllerResult->getClass()->isInstance($controllerResult))) {
             return false;
         }
         if ($expectedControllerResult->isArray() && !is_array($controllerResult)) {
             return false;
         }
         if (method_exists($expectedControllerResult, 'isCallable') && $expectedControllerResult->isCallable() && !is_callable($controllerResult)) {
             return false;
         }
     }
     return true;
 }
开发者ID:shomimn,项目名称:builder,代码行数:25,代码来源:ViewListenerWrapper.php


示例8: execute

 /**
  * Execute handler
  * @param Client $client
  * @param $data
  * @return mixed|null
  */
 public function execute(Client $client, $data)
 {
     $this->_client = $client;
     $this->_data = $data;
     // Execute handler object
     if (!empty($this->_object)) {
         $class = new ReflectionClass(get_class($this->_object));
         $method = $class->getMethod($this->_method);
         $parameters = $this->prepareParameters($method->getParameters());
         if (empty($parameters)) {
             $parameters[] = $data;
         }
         return call_user_func_array([$this->_object, $this->_method], $parameters);
     }
     // Execute closure handler
     if (!empty($this->_closure)) {
         $function = new \ReflectionFunction($this->_closure);
         $parameters = $this->prepareParameters($function->getParameters());
         if (empty($parameters)) {
             $parameters[] = $data;
         }
         return call_user_func_array($this->_closure, $parameters);
     }
     return null;
 }
开发者ID:alexboo,项目名称:websocket-handler,代码行数:31,代码来源:Handler.php


示例9: run

 /**
  * 
  * @param Model_Job $job
  * @return void
  */
 public function run(Model_Job $job)
 {
     if (Kohana::$profiling === TRUE) {
         $benchmark = Profiler::start('Rub job', $job->name);
     }
     $this->values(array('job_id' => $job->id))->create();
     $this->set_status(Model_Job::STATUS_RUNNING);
     try {
         $job = $job->job;
         $minion_task = Minion_Task::convert_task_to_class_name($job);
         if (is_array($job)) {
             $passed = call_user_func($job);
         } elseif (class_exists($minion_task)) {
             Minion_Task::factory(array($job))->execute();
             $passed = TRUE;
         } elseif (strpos($job, '::') === FALSE) {
             $function = new ReflectionFunction($job);
             $passed = $function->invoke();
         } else {
             list($class, $method) = explode('::', $job, 2);
             $method = new ReflectionMethod($class, $method);
             $passed = $method->invoke(NULL);
         }
     } catch (Exception $e) {
         $this->failed();
         return;
     }
     $this->complete();
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:37,代码来源:log.php


示例10: params2MethodArgs

function params2MethodArgs($method, $params)
{
    $funcInfo = new ReflectionFunction($method);
    $args = array();
    foreach ($funcInfo->getParameters() as $paramInfo) {
        $nm = $paramInfo->getName();
        $val = null;
        if (!array_key_exists($nm, $params)) {
            if ($paramInfo->isDefaultValueAvailable()) {
                $val = $paramInfo->getDefaultValue();
            }
            if (is_null($val) && !$paramInfo->isOptional()) {
                throw new Exception("Parameter [{$nm}] of [{$method}] can not be null");
            }
        } else {
            $val = $params[$nm];
        }
        $classInfo = $paramInfo->getClass();
        if ($classInfo) {
            $val = eval("return new " . $classInfo->getName() . "('{$val}');");
        }
        $args[] = $val;
    }
    return $args;
}
开发者ID:sd-studio,项目名称:or,代码行数:25,代码来源:call.php


示例11: parse

 public function parse(&$var, Kint_Object &$o)
 {
     if (!$var instanceof Closure || !$o instanceof Kint_Object_Instance || !$this->parseChildren($o)) {
         return;
     }
     $o = $o->transplant(new Kint_Object_Closure());
     $o->removeRepresentation('properties');
     $closure = new ReflectionFunction($var);
     $o->filename = $closure->getFileName();
     $o->startline = $closure->getStartLine();
     foreach ($closure->getParameters() as $param) {
         $o->parameters[] = new Kint_Object_Parameter($param);
     }
     $p = new Kint_Object_Representation('Parameters');
     $p->contents =& $o->parameters;
     $o->addRepresentation($p, 0);
     $statics = array();
     if (method_exists($closure, 'getClosureThis') && ($v = $closure->getClosureThis())) {
         $statics = array('this' => $v);
     }
     if (count($statics = $statics + $closure->getStaticVariables())) {
         foreach ($statics as $name => &$static) {
             $obj = Kint_Object::blank('$' . $name);
             $obj->depth = $o->depth + 1;
             $static = $this->parser->parse($static, $obj);
             if ($static->value === null) {
                 $static->access_path = null;
             }
         }
         $r = new Kint_Object_Representation('Uses');
         $r->contents = $statics;
         $o->addRepresentation($r, 0);
     }
 }
开发者ID:jnvsor,项目名称:kint,代码行数:34,代码来源:Closure.php


示例12: debugBacktrace

 /**
  * 代码执行过程回溯信息
  *
  * @static
  * @access public
  */
 public static function debugBacktrace()
 {
     $skipFunc[] = 'Error->debugBacktrace';
     $show = $log = '';
     $debugBacktrace = debug_backtrace();
     ksort($debugBacktrace);
     foreach ($debugBacktrace as $k => $error) {
         if (!isset($error['file'])) {
             try {
                 if (isset($error['class'])) {
                     $reflection = new \ReflectionMethod($error['class'], $error['function']);
                 } else {
                     $reflection = new \ReflectionFunction($error['function']);
                 }
                 $error['file'] = $reflection->getFileName();
                 $error['line'] = $reflection->getStartLine();
             } catch (Exception $e) {
                 continue;
             }
         }
         $file = str_replace(rootPath(), '', $error['file']);
         $func = isset($error['class']) ? $error['class'] : '';
         $func .= isset($error['type']) ? $error['type'] : '';
         $func .= isset($error['function']) ? $error['function'] : '';
         if (in_array($func, $skipFunc)) {
             break;
         }
         $error['line'] = sprintf('%04d', $error['line']);
         $show .= '<li>[Line: ' . $error['line'] . ']' . $file . '(' . $func . ')</li>';
         $log .= !empty($log) ? ' -> ' : '';
         $log .= $file . ':' . $error['line'];
     }
     return array($show, $log);
 }
开发者ID:h1soft,项目名称:h,代码行数:40,代码来源:StackTrace.php


示例13: test

function test()
{
    $x = new ReflectionFunction('array_filter');
    $params = $x->getParameters();
    $p1 = $params[1];
    var_dump($p1->getDefaultValueText());
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:hhas_defaults.php


示例14: 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


示例15: updateClassMethodHash

 public static function updateClassMethodHash($className, $methodName, $closure)
 {
     $methodName = strtolower($methodName);
     if (isset(self::$specialMethods[$methodName]) && self::$specialMethods[$methodName] == 1) {
         $methodName = "phlexmock_" . $methodName;
     }
     $closureRF = new \ReflectionFunction($closure);
     $paramStr = "()";
     $params = [];
     $closureParams = $closureRF->getParameters();
     if (count($closureParams) > 0) {
         foreach ($closureParams as $closureParam) {
             $params[] = '$' . $closureParam->getName();
         }
         $paramStr = "(" . implode(",", $params) . ")";
     }
     $sl = $closureRF->getStartLine();
     $el = $closureRF->getEndLine();
     $closureContainerScript = $closureRF->getFileName();
     if (!isset(self::$closureContainerScriptLines[$closureContainerScript])) {
         self::$closureContainerScriptLines[$closureContainerScript] = explode("\n", file_get_contents($closureRF->getFileName()));
     }
     $lines = self::$closureContainerScriptLines[$closureContainerScript];
     $code = '$func = function' . $paramStr . ' { ' . implode("\n", array_slice($lines, $sl, $el - $sl - 1)) . ' };';
     self::$classMethodHash[$className][$methodName] = $code;
 }
开发者ID:jimthunderbird,项目名称:phlexmock,代码行数:26,代码来源:PhlexMock.php


示例16: ipExecuteController_70

 public static function ipExecuteController_70($info)
 {
     if (!is_callable($info['action'])) {
         $controllerClass = $info['controllerClass'];
         $controller = new $controllerClass();
         $callableAction = array($controller, $info['action']);
         $reflection = new \ReflectionMethod($controller, $info['action']);
     } else {
         $callableAction = $info['action'];
         $reflection = new \ReflectionFunction($callableAction);
     }
     $parameters = $reflection->getParameters();
     $arguments = array();
     $routeParameters = array();
     foreach ($parameters as $parameter) {
         $name = $parameter->getName();
         if (isset($info[$name])) {
             $arguments[] = $info[$name];
         } elseif ($parameter->isOptional()) {
             $arguments[] = $parameter->getDefaultValue();
         } else {
             throw new \Ip\Exception("Controller action requires " . esc($name) . " parameter", array('route' => $info, 'requiredParameter' => $name));
         }
         $routeParameters[$parameter->getName()] = end($arguments);
     }
     iproute()->setParameters($routeParameters);
     return call_user_func_array($callableAction, $arguments);
 }
开发者ID:Umz,项目名称:ImpressPages,代码行数:28,代码来源:Job.php


示例17: parse

 public function parse(&$variable)
 {
     if (!$variable instanceof Closure) {
         return false;
     }
     $this->name = 'Closure';
     $reflection = new ReflectionFunction($variable);
     $ret = array('Parameters' => array());
     if ($val = $reflection->getParameters()) {
         foreach ($val as $parameter) {
             // todo http://php.net/manual/en/class.reflectionparameter.php
             $ret['Parameters'][] = $parameter->name;
         }
     }
     if ($val = $reflection->getStaticVariables()) {
         $ret['Uses'] = $val;
     }
     if (method_exists($reflection, 'getClousureThis') && ($val = $reflection->getClosureThis())) {
         $ret['Uses']['$this'] = $val;
     }
     if ($val = $reflection->getFileName()) {
         $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
     }
     return $ret;
 }
开发者ID:DeRossi,项目名称:Training_CI,代码行数:25,代码来源:closure.php


示例18: generate

 function generate($path)
 {
     $filepath = GENERATE_MODULE . "module_" . $path;
     $modulepath = _SYSTEM_DIR_ . "module/" . $path;
     if (file_exists($filepath) && filemtime($filepath) >= filemtime($modulepath)) {
         return;
     }
     $classname = "module_" . substr(basename($path), 0, strpos(basename($path), "."));
     $tmp = array();
     $tmp[] = "<?php /* auto generate module class " . date("Y-m-d H:i:s") . "*/";
     $tmp[] = "/* original file:" . $modulepath . " */";
     $tmp[] = "class " . $classname . " {";
     foreach ($this->_binds as $method => $func) {
         $ref = new \ReflectionFunction($func);
         $params = $ref->getParameters();
         $method_params = array();
         foreach ($params as $a) {
             /* @var $a ReflectionParameter */
             $line = '$' . $a->getName() . ($a->isDefaultValueAvailable() ? '=\'' . $a->getDefaultValue() . '\'' : '');
             try {
                 $class = $a->getClass();
                 if ($class) {
                     $line = $class->getName() . " " . $line;
                 }
             } catch (Exception $e) {
             }
             $method_params[] = $line;
         }
         $tmp[] = "public function " . $method . "(" . implode(", ", $method_params) . "){}";
     }
     $tmp[] = "}";
     file_put_contents($filepath, implode("\n", $tmp));
 }
开发者ID:ryosukemiyazawa,项目名称:lasa,代码行数:33,代码来源:Module.php


示例19: runMiddlewares

 /**
  * Runs all the middlewares of given type.
  */
 public static function runMiddlewares($type = self::BEFORE_REQUEST)
 {
     $apricot = static::getInstance();
     $middlewares = $apricot->middlewares;
     /** @var \Exception */
     $error = null;
     foreach ($middlewares as $key => $middleware) {
         $hasNextMiddleware = array_key_exists($key + 1, $middlewares);
         if ($type !== $middleware['type']) {
             continue;
         }
         $r = new \ReflectionFunction($middleware['callback']);
         $parameters = $r->getParameters();
         $next = $hasNextMiddleware ? $middlewares[$key + 1] : function () {
         };
         try {
             $r->invokeArgs(array($error, $next));
         } catch (\Exception $e) {
             // If there is no more middleware to run, throw the exception.
             if (!$hasNextMiddleware) {
                 throw $e;
             }
             $error = $e;
         }
     }
 }
开发者ID:djom20,项目名称:Apricot,代码行数:29,代码来源:Middleware.php


示例20: executeInSubprocess

 function executeInSubprocess($includeStderr = false)
 {
     // Get the path to the ErrorControlChain class
     $classpath = SS_ClassLoader::instance()->getItemPath('ErrorControlChain');
     $suppression = $this->suppression ? 'true' : 'false';
     // Start building a PHP file that will execute the chain
     $src = '<' . "?php\nrequire_once '{$classpath}';\n\n\$chain = new ErrorControlChain();\n\n\$chain->setSuppression({$suppression});\n\n\$chain\n";
     // For each step, use reflection to pull out the call, stick in the the PHP source we're building
     foreach ($this->steps as $step) {
         $func = new ReflectionFunction($step['callback']);
         $source = file($func->getFileName());
         $start_line = $func->getStartLine() - 1;
         $end_line = $func->getEndLine();
         $length = $end_line - $start_line;
         $src .= implode("", array_slice($source, $start_line, $length)) . "\n";
     }
     // Finally add a line to execute the chain
     $src .= "->execute();";
     // Now stick it in a temporary file & run it
     $codepath = TEMP_FOLDER . '/ErrorControlChainTest_' . sha1($src) . '.php';
     if ($includeStderr) {
         $null = '&1';
     } else {
         $null = is_writeable('/dev/null') ? '/dev/null' : 'NUL';
     }
     file_put_contents($codepath, $src);
     exec("php {$codepath} 2>{$null}", $stdout, $errcode);
     unlink($codepath);
     return array(implode("\n", $stdout), $errcode);
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:30,代码来源:ErrorControlChainTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ReflectionFunctionAbstract类代码示例发布时间:2022-05-23
下一篇:
PHP ReflectionExtension类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap