本文整理汇总了PHP中ReflectionMethod::getEndLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getEndLine方法的具体用法?PHP ReflectionMethod::getEndLine怎么用?PHP ReflectionMethod::getEndLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getEndLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseMethod
private function parseMethod($class, $method)
{
$refl = new \ReflectionMethod($class, $method);
// 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;
}
示例2: getMethod
public function getMethod($filePath, $ext = '')
{
$fileName = dirname($filePath);
$className = basename(dirname(dirname($filePath)));
if (!class_exists($className)) {
helper::import($fileName);
}
$methodName = basename($filePath);
$method = new ReflectionMethod($className . $ext, $methodName);
$data = new stdClass();
$data->startLine = $method->getStartLine();
$data->endLine = $method->getEndLine();
$data->comment = $method->getDocComment();
$data->parameters = $method->getParameters();
$data->className = $className;
$data->methodName = $methodName;
$data->fileName = $fileName;
$data->post = false;
$file = file($fileName);
for ($i = $data->startLine - 1; $i <= $data->endLine; $i++) {
if (strpos($file[$i], '$this->post') or strpos($file[$i], 'fixer::input') or strpos($file[$i], '$_POST')) {
$data->post = true;
}
}
return $data;
}
示例3: getTrace
/**
* Process the exception. Calls the Exception::getTrace() method to
* get the backtrace. Gets the relevant lines of code for each step
* in the backtrace.
*/
public function getTrace($e)
{
$trace = $e->getTrace();
foreach ($trace as $i => &$entry) {
if (isset($entry['class'])) {
try {
$refl = new ReflectionMethod($entry['class'], $entry['function']);
if (isset($trace[$i - 1]) && isset($trace[$i - 1]['line'])) {
$entry['caller'] = (int) $trace[$i - 1]['line'] - 1;
} else {
if ($i === 0) {
$entry['caller'] = (int) $e->getLine() - 1;
}
}
$start = $entry['caller'] - self::BACKTRACE_CONTEXT;
if ($start < $refl->getStartLine()) {
$start = $refl->getStartLine() - 1;
}
$end = $entry['caller'] + self::BACKTRACE_CONTEXT;
if ($end > $refl->getEndLine()) {
$end = $refl->getEndLine();
}
$entry['source'] = $this->getSourceFromFile($refl->getFileName(), $start, $end);
} catch (Exception $e) {
$entry['caller'] = null;
$entry['source'] = '';
}
}
if (isset($entry['args'])) {
// Duplicate so we don't overwrite by-reference variables
$args = array();
foreach ($entry['args'] as $i => $arg) {
$args[$i] = gettype($arg);
}
$entry['args'] = $args;
}
}
$exceptionParams = array();
if (method_exists($e, 'getParams')) {
$exceptionParams = $e->getParams();
}
$d = array('backtrace' => $trace, 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'name' => api_helpers_class::getBaseName($e), 'params' => $exceptionParams);
if (!empty($e->userInfo)) {
$d['userInfo'] = $e->userInfo;
}
return $d;
}
示例4: getCodeBody
/**
* @param \ReflectionMethod $reflectionMethod
*
* @return string
*/
private function getCodeBody(\ReflectionMethod $reflectionMethod)
{
$reflectionClass = $reflectionMethod->getDeclaringClass();
$length = $reflectionMethod->getEndLine() - $reflectionMethod->getStartLine();
$lines = file($reflectionClass->getFileName());
$code = join(PHP_EOL, array_slice($lines, $reflectionMethod->getStartLine() - 1, $length + 1));
return preg_replace('/.*function[^{]+{/s', '', $code);
}
示例5: getEndLine
/**
* Returns the line this method's declaration ends at
*
* @return integer Line this methods's declaration ends at
*/
public function getEndLine()
{
if ($this->reflectionSource instanceof ReflectionMethod) {
return $this->reflectionSource->getEndLine();
} else {
return parent::getEndLine();
}
}
示例6: getMethodBodyAndDocComment
public static function getMethodBodyAndDocComment($cls, $mtd)
{
$func = new \ReflectionMethod($cls, $mtd);
$start_line = $func->getStartLine() + 1;
$length = $func->getEndLine() - $start_line - 1;
$lines = array_slice(file($func->getFileName()), $start_line, $length);
return array(implode('', $lines), $func->getDocComment());
}
示例7: getRawBody
public function getRawBody()
{
$method = new \ReflectionMethod($this->testClassInstance, $this->testMethod);
$start_line = $method->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $method->getEndLine();
$source = file($method->getFileName());
return implode("", array_slice($source, $start_line, $end_line - $start_line));
}
示例8: getMethodSource
static function getMethodSource(ReflectionMethod $method)
{
$path = $method->getFileName();
$lines = @file($path);
$from = $method->getStartLine();
$to = $method->getEndLine();
$len = $to - $from + 1;
return implode(array_slice($lines, $from - 1, $len));
}
示例9: _getCode
/**
* Get the source code for the method
*
* @param \ReflectionMethod $method
*
* @return string
*/
protected function _getCode(\ReflectionMethod $method)
{
$filename = $method->getFileName();
$start_line = $method->getStartLine() + 1;
$end_line = $method->getEndLine() - 1;
$length = $end_line - $start_line;
$source = file($filename);
return preg_replace('/^\\s{4}/m', '', implode("", array_slice($source, $start_line, $length)));
}
示例10: getCodeBody
/**
* @param \ReflectionMethod $reflectionMethod
*
* @return string
*/
private function getCodeBody(\ReflectionMethod $reflectionMethod)
{
$endLine = $reflectionMethod->getEndLine();
$startLine = $reflectionMethod->getStartLine();
$reflectionClass = $this->getMethodOwner($reflectionMethod, $startLine, $endLine);
$length = $endLine - $startLine;
$lines = file(StreamWrapper::wrapPath($reflectionClass->getFileName()));
$code = join(PHP_EOL, array_slice($lines, $startLine - 1, $length + 1));
return preg_replace('/.*function[^{]+{/s', '', $code);
}
示例11: getCodeBody
/**
* @param ReflectionMethod $reflectionMethod
*
* @return string
*/
private function getCodeBody(\ReflectionMethod $reflectionMethod)
{
$reflectionClass = $reflectionMethod->getDeclaringClass();
$length = $reflectionMethod->getEndLine() - $reflectionMethod->getStartLine();
$lines = file($reflectionClass->getFileName());
if ($length == 0) {
return preg_replace('/.*function.*{/', '', $lines[$reflectionMethod->getStartLine() - 1]);
}
return join("\n", array_slice($lines, $reflectionMethod->getStartLine(), $length));
}
示例12: sourceMethod
function sourceMethod(\ReflectionMethod $method)
{
$filename = $method->getFileName();
$start_line = $method->getStartLine() - 1;
// it's actually - 1, otherwise you wont get the function() block
$end_line = $method->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$body = implode("", array_slice($source, $start_line, $length));
return $method->getDocComment() . PHP_EOL . $body;
}
示例13: testImplementationsAreSynchronized
public function testImplementationsAreSynchronized()
{
$adapterReflector = new ReflectionMethod('ehough_finder_adapter_PhpAdapter', 'searchInDirectory');
$finderReflector = new ReflectionMethod('ehough_finder_Finder', 'searchInDirectory');
$adapterSource = array_slice(file($adapterReflector->getFileName()), $adapterReflector->getStartLine() + 1, $adapterReflector->getEndLine() - $adapterReflector->getStartLine() - 1);
$adapterSource = implode('', $adapterSource);
$adapterSource = str_replace(array('$this->minDepth', '$this->maxDepth'), array('$minDepth', '$maxDepth'), $adapterSource);
$finderSource = array_slice(file($finderReflector->getFileName()), $finderReflector->getStartLine() + 1, $finderReflector->getEndLine() - $finderReflector->getStartLine() - 1);
$finderSource = implode('', $finderSource);
$this->assertStringEndsWith($adapterSource, $finderSource);
}
示例14: generateMethodArguments
/**
* @param ReflectionMethod $method
* @return string
*/
function generateMethodArguments(ReflectionMethod $method)
{
if ($method->isInternal()) {
// This code can`t handle constants, it replaces its with value
return implode(', ', array_map(array($this, 'generateMethodArgument'), $method->getParameters()));
} else {
$lines = $this->getFileLines($method->getFileName());
$start_line = $method->getStartLine() - 1;
$function_lines = array_slice($lines, $start_line, $method->getEndLine() - $start_line);
// todo: use code beautifier?
return $this->parseFunctionArgs(implode(PHP_EOL, $function_lines));
}
}
示例15: collect
/**
* Called by the DebugBar when data needs to be collected
* @return array Collected data
*/
function collect()
{
$dispatcher = $this->di['dispatcher'];
$router = $this->di['router'];
$route = $router->getMatchedRoute();
if (!$route) {
return array();
}
$uri = $route->getPattern();
$paths = $route->getPaths();
$result['uri'] = $uri ?: '-';
$result['paths'] = $this->formatVar($paths);
if ($params = $router->getParams()) {
$result['params'] = $this->formatVar($params);
}
$result['HttpMethods'] = $route->getHttpMethods();
$result['RouteName'] = $route->getName();
$result['hostname'] = $route->getHostname();
if ($this->di->has('app') && ($app = $this->di['app']) instanceof Micro) {
if (($handler = $app->getActiveHandler()) instanceof \Closure || is_string($handler)) {
$reflector = new \ReflectionFunction($handler);
} elseif (is_array($handler)) {
$reflector = new \ReflectionMethod($handler[0], $handler[1]);
}
} else {
$result['Moudle'] = $router->getModuleName();
$result['Controller'] = get_class($controller_instance = $dispatcher->getActiveController());
$result['Action'] = $dispatcher->getActiveMethod();
$reflector = new \ReflectionMethod($controller_instance, $result['Action']);
}
if (isset($reflector)) {
$start = $reflector->getStartLine() - 1;
$stop = $reflector->getEndLine();
$filename = substr($reflector->getFileName(), mb_strlen(realpath(dirname($_SERVER['DOCUMENT_ROOT']))));
$code = array_slice(file($reflector->getFileName()), $start, $stop - $start);
$result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine() . " [CODE]: \n" . implode("", $code);
}
return array_filter($result);
}