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


PHP ReflectionFunction::getStartLine方法代码示例

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


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

示例1: enterNode

 public function enterNode(\PHPParser_Node $node)
 {
     // Determine info about the closure's location
     if (!$this->closureNode) {
         if ($node instanceof \PHPParser_Node_Stmt_Namespace) {
             $this->location->namespace = is_array($node->name->parts) ? implode('\\', $node->name->parts) : null;
         }
         if ($node instanceof \PHPParser_Node_Stmt_Trait) {
             $this->location->trait = $this->location->namespace . '\\' . $node->name;
             $this->location->class = null;
         } elseif ($node instanceof \PHPParser_Node_Stmt_Class) {
             $this->location->class = $this->location->namespace . '\\' . $node->name;
             $this->location->trait = null;
         }
     }
     // Locate the node of the closure
     if ($node instanceof \PHPParser_Node_Expr_Closure) {
         if ($node->getAttribute('startLine') == $this->reflection->getStartLine()) {
             if ($this->closureNode) {
                 throw new \RuntimeException('Two closures were declared on the same line of code. Cannot determine ' . 'which closure was the intended target.');
             } else {
                 $this->closureNode = $node;
             }
         }
     }
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:26,代码来源:ClosureFinderVisitor.php

示例2: serialize

 /**
  * @link http://php.net/manual/en/serializable.serialize.php
  */
 public function serialize()
 {
     // prepare code
     $file = new SplFileObject($this->reflection->getFileName());
     $file->seek($this->reflection->getStartLine() - 1);
     $code = '';
     while ($file->key() < $this->reflection->getEndLine()) {
         $code .= $file->current();
         $file->next();
     }
     $start = strpos($code, 'function');
     $code = substr($code, $start, strpos($code, '}') - $start + 1);
     // prepare variables
     $variables = [];
     $index = stripos($code, 'use');
     // if 'use' keyword found
     if (false !== $index) {
         // get the names of the variables inside the use statement
         $start = strpos($code, '(', $index) + 1;
         $end = strpos($code, ')', $start);
         $use_variables = explode(',', substr($code, $start, $end - $start));
         $static_variables = $this->reflection->getStaticVariables();
         // keep only the variables that appeared in both scopes
         foreach ($use_variables as $variable) {
             $variable = trim($variable, '$&');
             $variables[$variable] = $static_variables[$variable];
         }
     }
     return serialize(['code' => $code, 'variables' => $variables]);
 }
开发者ID:acfatah,项目名称:serializable-closure,代码行数:33,代码来源:SerializableClosure.php

示例3: ReflectionFunction

 /**
  * get Closure info
  * @param Closure $c
  * @return array
  */
 function closure_dump(Closure $c)
 {
     $str = 'function (';
     $r = new ReflectionFunction($c);
     $params = array();
     foreach ($r->getParameters() as $p) {
         $s = '';
         if ($p->isArray()) {
             $s .= 'array ';
         } else {
             if ($p->getClass()) {
                 $s .= $p->getClass()->name . ' ';
             }
         }
         if ($p->isPassedByReference()) {
             $s .= '&';
         }
         $s .= '$' . $p->name;
         if ($p->isOptional()) {
             $s .= ' = ' . var_export($p->getDefaultValue(), TRUE);
         }
         $params[] = $s;
     }
     $str .= implode(', ', $params);
     $str .= '){' . PHP_EOL;
     $lines = file($r->getFileName());
     for ($l = $r->getStartLine(); $l < $r->getEndLine(); $l++) {
         $str .= $lines[$l];
     }
     $arr = ['file' => $r->getFileName(), 'line' => $r->getStartLine() . '-' . $r->getEndLine(), 'source' => $str];
     return $arr;
 }
开发者ID:Vr80s,项目名称:laravel-rbac,代码行数:37,代码来源:helpers.php

示例4: parseClosure

 private function parseClosure(\Closure $callback)
 {
     $refl = new \ReflectionFunction($callback);
     //        var_dump($refl->getFileName());
     //        var_dump($refl->getStartLine());
     //        var_dump($refl->getEndLine());
     $body = trim(implode(array_slice(file($refl->getFileName()), $refl->getStartLine(), $refl->getEndLine() - $refl->getStartLine() - 1)));
     $spec = $this->createSpecification($body, $refl->getFileName(), $refl->getStartLine(), $refl->getEndLine());
     return $spec;
 }
开发者ID:ribozz,项目名称:PhpSpock,代码行数:10,代码来源:SpecificationParser.php

示例5: getRouteInformation

 /**
  * Get the route information for a given route.
  *
  * @param  \Illuminate\Routing\Route $route
  * @return array
  */
 protected function getRouteInformation($route)
 {
     if (!is_a($route, 'Illuminate\\Routing\\Route')) {
         return array();
     }
     $uri = head($route->methods()) . ' ' . $route->uri();
     $action = $route->getAction();
     $result = array('uri' => $uri ?: '-');
     $result = array_merge($result, $action);
     if (isset($action['controller']) && strpos($action['controller'], '@') !== false) {
         list($controller, $method) = explode('@', $action['controller']);
         if (class_exists($controller) && method_exists($controller, $method)) {
             $reflector = new \ReflectionMethod($controller, $method);
         }
         unset($result['uses']);
     } elseif (isset($action['uses']) && $action['uses'] instanceof \Closure) {
         $reflector = new \ReflectionFunction($action['uses']);
         $result['uses'] = $this->formatVar($result['uses']);
     }
     if (isset($reflector)) {
         $filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
         $result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine();
     }
     if ($before = $this->getBeforeFilters($route)) {
         $result['before'] = $before;
     }
     if ($after = $this->getAfterFilters($route)) {
         $result['after'] = $after;
     }
     return $result;
 }
开发者ID:michaeljhopkins,项目名称:laravel-debugbar,代码行数:37,代码来源:IlluminateRouteCollector.php

示例6: filterResponse

 public function filterResponse($response)
 {
     if (!$response->getStatusCode()) {
         /*
         keep in mind: 
         self::$statusCode refers to the value declared in this file (500)
         get_called_class()::$statusCode  would be the value declared in the class that extends this exception
         */
         $className = get_called_class();
         $response->status($className::$statusCode, get_class($this->originalException));
     }
     if ($this->callback) {
         $closure = $this->callback->getCallable();
         if (is_array($closure)) {
             $reflection = new \ReflectionMethod($closure[0], $closure[1]);
         } else {
             $reflection = new \ReflectionFunction($closure);
         }
         $response->header("X-Phidias-Exception-Filename", $reflection->getFilename() . ' Line: ' . $reflection->getStartLine());
     }
     if ($message = $this->originalException->getMessage()) {
         $response->header("X-Phidias-Exception-Message", $message);
     }
     return $response;
 }
开发者ID:phidias-sas,项目名称:api,代码行数:25,代码来源:Exception.php

示例7: testConfigure

 public function testConfigure()
 {
     $prevDumper = $this->getDumpHandler();
     $container = new ContainerBuilder();
     $container->setDefinition('var_dumper.cloner', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockCloner'));
     $container->setDefinition('mock_dumper', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockDumper'));
     ob_start();
     $exception = null;
     $listener = new DumpListener($container, 'mock_dumper');
     try {
         $listener->configure();
         $lazyDumper = $this->getDumpHandler();
         VarDumper::dump('foo');
         $loadedDumper = $this->getDumpHandler();
         VarDumper::dump('bar');
         $this->assertSame('+foo-+bar-', ob_get_clean());
         $listenerReflector = new \ReflectionClass($listener);
         $lazyReflector = new \ReflectionFunction($lazyDumper);
         $loadedReflector = new \ReflectionFunction($loadedDumper);
         $this->assertSame($listenerReflector->getFilename(), $lazyReflector->getFilename());
         $this->assertSame($listenerReflector->getFilename(), $loadedReflector->getFilename());
         $this->assertGreaterThan($lazyReflector->getStartLine(), $loadedReflector->getStartLine());
     } catch (\Exception $exception) {
     }
     VarDumper::setHandler($prevDumper);
     if (null !== $exception) {
         throw $exception;
     }
 }
开发者ID:vomasmic,项目名称:symfony,代码行数:29,代码来源:DumpListenerTest.php

示例8: castClosure

 static function castClosure($c)
 {
     $a = array();
     if (!class_exists('ReflectionFunction', false)) {
         return $a;
     }
     $c = new \ReflectionFunction($c);
     foreach ($c->getParameters() as $p) {
         $n = ($p->isPassedByReference() ? '&$' : '$') . $p->getName();
         if ($p->isDefaultValueAvailable()) {
             $a[$n] = $p->getDefaultValue();
         } else {
             $a[] = $n;
         }
     }
     $m = self::META_PREFIX;
     $a = array($m . 'returnsRef' => true, $m . 'args' => $a);
     if (!$c->returnsReference()) {
         unset($a[$m . 'returnsRef']);
     }
     $a[$m . 'use'] = array();
     if (false === ($a[$m . 'file'] = $c->getFileName())) {
         unset($a[$m . 'file']);
     } else {
         $a[$m . 'lines'] = $c->getStartLine() . '-' . $c->getEndLine();
     }
     if (!($c = $c->getStaticVariables())) {
         unset($a[$m . 'use']);
     } else {
         foreach ($c as $p => &$c) {
             $a[$m . 'use']['$' . $p] =& $c;
         }
     }
     return $a;
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-sandbox,代码行数:35,代码来源:Caster.php

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

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

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

示例12: onWildcardEvent

 public function onWildcardEvent()
 {
     $name = $this->events->firing();
     $time = microtime(true);
     // Get the arguments passed to the event
     $params = $this->prepareParams(func_get_args());
     // Find all listeners for the current event
     foreach ($this->events->getListeners($name) as $i => $listener) {
         // Check if it's an object + method name
         if (is_array($listener) && count($listener) > 1 && is_object($listener[0])) {
             list($class, $method) = $listener;
             // Skip this class itself
             if ($class instanceof static) {
                 continue;
             }
             // Format the listener to readable format
             $listener = get_class($class) . '@' . $method;
             // Handle closures
         } elseif ($listener instanceof \Closure) {
             $reflector = new \ReflectionFunction($listener);
             // Skip our own listeners
             if ($reflector->getNamespaceName() == 'Barryvdh\\Debugbar') {
                 continue;
             }
             // Format the closure to a readable format
             $filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
             $listener = $reflector->getName() . ' (' . $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine() . ')';
         } else {
             // Not sure if this is possible, but to prevent edge cases
             $listener = $this->formatVar($listener);
         }
         $params['listeners.' . $i] = $listener;
     }
     $this->addMeasure($name, $time, $time, $params);
 }
开发者ID:sethathay,项目名称:PPBakery,代码行数:35,代码来源:EventCollector.php

示例13: 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 ($val = $reflection->getClosureThis()) {
         $ret['Uses']['$this'] = $val;
     }
     if ($val = $reflection->getFileName()) {
         $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
     }
     return $ret;
 }
开发者ID:Tacit007,项目名称:Calenda,代码行数:25,代码来源:closure.php

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

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


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