本文整理汇总了PHP中ReflectionMethod::getStartLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getStartLine方法的具体用法?PHP ReflectionMethod::getStartLine怎么用?PHP ReflectionMethod::getStartLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getStartLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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));
}
示例4: provideControllerCallables
public function provideControllerCallables()
{
// make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
$r3 = new \ReflectionClass($this);
// test name, callable, expected
return array(array('"Regular" callable', array($this, 'testControllerInspection'), array('class' => __NAMESPACE__ . '\\RequestDataCollectorTest', 'method' => 'testControllerInspection', 'file' => __FILE__, 'line' => $r1->getStartLine())), array('Closure', function () {
return 'foo';
}, array('class' => __NAMESPACE__ . '\\{closure}', 'method' => null, 'file' => __FILE__, 'line' => __LINE__ - 5)), array('Static callback as string', __NAMESPACE__ . '\\RequestDataCollectorTest::staticControllerMethod', array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'staticControllerMethod', 'file' => __FILE__, 'line' => $r2->getStartLine())), array('Static callable with instance', array($this, 'staticControllerMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'staticControllerMethod', 'file' => __FILE__, 'line' => $r2->getStartLine())), array('Static callable with class name', array('Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'staticControllerMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'staticControllerMethod', 'file' => __FILE__, 'line' => $r2->getStartLine())), array('Callable with instance depending on __call()', array($this, 'magicMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a')), array('Callable with class name depending on __callStatic()', array('Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'magicMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a')), array('Invokable controller', $this, array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => null, 'file' => __FILE__, 'line' => $r3->getStartLine())));
}
示例5: 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);
}
示例6: isValid
public static function isValid()
{
if (!assert_options(ASSERT_ACTIVE)) {
return true;
}
$bt = self::debugBacktrace(null, 1);
extract($bt);
//to $file, $line, $function, $class, $object, $type, $args
if (!$args) {
return true;
}
#speed improve
$r = new ReflectionMethod($class, $function);
$doc = $r->getDocComment();
$cache_id = $class . $type . $function;
preg_match_all('~ [\\r\\n]++ [\\x20\\t]++ \\* [\\x20\\t]++
@param
[\\x20\\t]++
\\K #memory reduce
( [_a-z]++[_a-z\\d]*+
(?>[|/,][_a-z]+[_a-z\\d]*)*+
) #1 types
[\\x20\\t]++
&?+\\$([_a-z]++[_a-z\\d]*+) #2 name
~sixSX', $doc, $params, PREG_SET_ORDER);
$parameters = $r->getParameters();
//d($args, $params, $parameters);
if (count($parameters) > count($params)) {
$message = 'phpDoc %d piece(s) @param description expected in %s%s%s(), %s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, count($parameters), $class, $type, $function, count($params), $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_NOTICE);
}
foreach ($args as $i => $value) {
if (!isset($params[$i])) {
return true;
}
if ($parameters[$i]->name !== $params[$i][2]) {
$param_num = $i + 1;
$message = 'phpDoc @param %d in %s%s%s() must be named as $%s, $%s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, $param_num, $class, $type, $function, $parameters[$i]->name, $params[$i][2], $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_NOTICE);
}
$hints = preg_split('~[|/,]~sSX', $params[$i][1]);
if (!self::checkValueTypes($hints, $value)) {
$param_num = $i + 1;
$message = 'Argument %d passed to %s%s%s() must be an %s, %s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, $param_num, $class, $type, $function, implode('|', $hints), (is_object($value) ? get_class($value) . ' ' : '') . gettype($value), $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_WARNING);
return false;
}
}
return true;
}
示例7: getOriginalBody
protected function getOriginalBody(\ReflectionMethod $originalMethod)
{
$lines = array_slice(file($originalMethod->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), $originalMethod->getStartLine(), $originalMethod->getEndLine() - $originalMethod->getStartLine(), true);
$firstLine = array_shift($lines);
if (trim($firstLine) !== '{') {
array_unshift($lines, $firstLine);
}
$lastLine = array_pop($lines);
if (trim($lastLine) !== '}') {
array_push($lines, $lastLine);
}
$body = rtrim(ltrim(implode("\n", $lines), '{'), '}');
return $body;
}
示例8: AjaxobserversAction
/**
* Gets Observers for specified Event.
*
* @return $this|array
*/
public function AjaxobserversAction()
{
$eventName = $this->getRequest()->getPost('event', false);
// If no event name provided,
if (!$eventName) {
return array();
}
// Ensure Event Name is all lowercase
$eventName = strtolower($eventName);
// Set up $areas array and $observers array
$areas = array('global', 'adminhtml', 'frontend');
$observers = array();
// Cycle Through Areas and get config information
foreach ($areas as $area) {
$eventConfig = Mage::app()->getConfig()->getEventConfig($area, $eventName);
if (!$eventConfig) {
$this->_events[$area][$eventName] = false;
continue;
}
try {
foreach ($eventConfig->observers->children() as $obsName => $obsConfig) {
$methodReflection = new ReflectionMethod($obsConfig->getClassName(), $obsConfig->method);
$observers[$obsName] = array('area' => $area, 'type' => (string) $obsConfig->type, 'model' => $obsConfig->class ? (string) $obsConfig->class : $obsConfig->getClassName(), 'class' => $obsConfig->getClassName(), 'method' => (string) $obsConfig->method, 'line' => $methodReflection->getStartLine(), 'path' => $this->getClassPath($obsConfig->getClassName()));
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
// Create Block to Display Results
$block = Mage::app()->getLayout()->createBlock('bronto_verify/adminhtml_system_config_advanced_observersearch');
$block->setObservers($observers);
// Set Response Body
$this->getResponse()->setBody($block->toHtml());
return $this;
}
示例9: testControllerInspection
/**
* Test various types of controller callables.
*
* @dataProvider provider
*/
public function testControllerInspection(Request $request, Response $response)
{
// make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
// test name, callable, expected
$controllerTests = array(array('"Regular" callable', array($this, 'testControllerInspection'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'testControllerInspection', 'file' => __FILE__, 'line' => $r1->getStartLine())), array('Closure', function () {
return 'foo';
}, array('class' => __NAMESPACE__ . '\\{closure}', 'method' => null, 'file' => __FILE__, 'line' => __LINE__ - 5)), array('Static callback as string', 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest::staticControllerMethod', 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest::staticControllerMethod'), array('Static callable with instance', array($this, 'staticControllerMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'staticControllerMethod', 'file' => __FILE__, 'line' => $r2->getStartLine())), array('Static callable with class name', array('Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'staticControllerMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'staticControllerMethod', 'file' => __FILE__, 'line' => $r2->getStartLine())), array('Callable with instance depending on __call()', array($this, 'magicMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a')), array('Callable with class name depending on __callStatic()', array('Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'magicMethod'), array('class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest', 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a')));
$c = new RequestDataCollector();
foreach ($controllerTests as $controllerTest) {
$this->injectController($c, $controllerTest[1], $request);
$c->collect($request, $response);
$this->assertEquals($controllerTest[2], $c->getController(), sprintf('Testing: %s', $controllerTest[0]));
}
}
示例10: 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;
}
示例11: 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;
}
示例12: getStartLine
/**
* Returns the line this method's declaration starts at
*
* @return integer Line this methods's declaration starts at
*/
public function getStartLine()
{
if ($this->reflectionSource instanceof ReflectionMethod) {
return $this->reflectionSource->getStartLine();
} else {
return parent::getStartLine();
}
}
示例13: 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());
}
示例14: 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));
}
示例15: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if ('_route' == $key && is_object($value)) {
$value = $value->getPattern();
}
$attributes[$key] = $this->varToString($value);
}
$content = null;
try {
$content = $request->getContent();
} catch (\LogicException $e) {
// the user already got the request content as a resource
$content = false;
}
$sessionMetadata = array();
$sessionAttributes = array();
$flashes = array();
if ($request->hasSession()) {
$session = $request->getSession();
if ($session->isStarted()) {
$sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated());
$sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed());
$sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime();
$sessionAttributes = $session->all();
$flashes = $session->getFlashBag()->peekAll();
}
}
$this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', 'locale' => $request->getLocale());
if (isset($this->controllers[$request])) {
$controller = $this->controllers[$request];
if (is_array($controller)) {
try {
$r = new \ReflectionMethod($controller[0], $controller[1]);
$this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getStartLine());
} catch (\ReflectionException $re) {
if (is_callable($controller)) {
// using __call or __callStatic
$this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => 'n/a', 'line' => 'n/a');
}
}
} elseif ($controller instanceof \Closure) {
$this->data['controller'] = 'Closure';
} else {
$this->data['controller'] = (string) $controller ?: 'n/a';
}
unset($this->controllers[$request]);
}
}