本文整理汇总了PHP中ReflectionClass::getStartLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getStartLine方法的具体用法?PHP ReflectionClass::getStartLine怎么用?PHP ReflectionClass::getStartLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getStartLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStartLine
/**
* Gets the line where the class definition starts
* @return Integer
*/
public function getStartLine()
{
$s = $this->reflection->getStartLine();
if (!$s || !$this->getFileName()) {
return NULL;
}
return $s;
}
示例2: getClassBody
/**
* Возвращает тело класса/интерфейса
*/
public function getClassBody()
{
$lines = $this->di->getFileLines(true, true);
$firstLine = $this->rc->getStartLine();
$endLine = $this->rc->getEndLine();
if ($endLine <= $firstLine + 1) {
return '';
}
return trim(implode('', array_slice($lines, $firstLine, $endLine - $firstLine - 1)));
}
示例3: createMockClass
private function createMockClass($className, $mockData = [])
{
$shortName = $this->reflection->getShortName();
$classStart = self::reflectionContent($this->reflection, 1, $this->reflection->getStartLine() - 1);
$classStart .= PHP_EOL . "class {$className} extends {$shortName}" . PHP_EOL;
$this->body = self::reflectionBody($this->reflection, false);
foreach ($mockData as $attribute => $value) {
if (is_callable($value)) {
$this->insertMethod($attribute, $value);
} else {
$this->insertAttribute($attribute, $value);
}
}
eval($classStart . $this->body);
}
示例4: reflect
public function reflect()
{
$this->load->library('calendar');
$reflect = new ReflectionClass('CI_Calendar');
echo $reflect->getStartLine();
$path = $reflect->getFileName();
$temp = @file($path);
echo $reflect->getEndLine();
$len = $reflect->getEndLine() - $reflect->getStartLine() + 1;
echo implode(array_slice($temp, $reflect->getStartLine() - 1, $len));
// foreach ($func->getParameters() as $param)
// {
// echo $param,'<br>';
// }
}
示例5: applyTable
/**
*
* @return type
*/
public static function applyTable()
{
//
if (static::isAdamantTable()) {
return;
}
//
$attribute = 'ApplyTableExecuted';
// avoid re-update by check the cache
if (!static::hasClassAttribute($attribute)) {
// retrieve database
$database = static::getDatabase();
// if model is not connectect to any db return
if (!$database) {
static::error('Database not found', debug_backtrace(), 2);
}
// retrieve class model schema
$schema = static::getSchema();
//
if (!$schema) {
//
$reflector = new \ReflectionClass(static::getClass());
//
static::error('Model class without attributes', [['file' => $reflector->getFileName(), 'line' => $reflector->getStartLine()]]);
}
// get table name
$table = static::getTable();
// have a valid schema update db table
$database->applyTable($table, $schema, false);
// cache last update avoid multiple call
static::setClassAttribute($attribute, time());
}
}
示例6: handleRequestExit
public function handleRequestExit($context, &$storage)
{
$request = $context['functionArgs'][0];
if (empty($request)) {
return;
}
$ctrl = $request->get('_controller');
if (empty($ctrl)) {
return;
}
if (empty($ctrl) || !(is_array($ctrl) || is_string($ctrl))) {
return;
} elseif (is_string($ctrl)) {
$ctrl = explode(':', $ctrl);
}
$controller = $ctrl[0];
if (!empty($ctrl[2])) {
$action = $ctrl[2];
} else {
$action = $ctrl[1];
}
try {
$refclass = new \ReflectionClass($controller);
$filename = $refclass->getFileName();
$lineno = $refclass->getStartLine();
} catch (\Exception $e) {
$filename = $lineno = '';
}
$storage['request'][] = @array('Controller' => $controller, 'Action' => $action, 'Filename' => $filename, 'Line Number' => $lineno, 'Route' => array('Name' => $request->get('_route'), 'Params' => $request->get('_routeparams')), 'Session' => $request->getSession() ? 'yes' : 'no', 'Locale' => $request->getLocale());
}
示例7: __construct
/**
* Constructor.
*
* @param string A PHP identifier, e.g. a class, method, interface, etc. name
* @param callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier
*/
public function __construct($identifier, $callable = null)
{
$this->value = $identifier;
if (0 < ($i = strrpos($identifier, '\\'))) {
$this->attr['ellipsis'] = strlen($identifier) - $i;
}
if (null !== $callable) {
if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
} elseif (is_object($callable)) {
$r = new \ReflectionMethod($callable, '__invoke');
} elseif (is_array($callable)) {
$r = new \ReflectionMethod($callable[0], $callable[1]);
} elseif (false !== ($i = strpos($callable, '::'))) {
$r = new \ReflectionMethod(substr($callable, 0, $i), substr($callable, 2 + $i));
} else {
$r = new \ReflectionFunction($callable);
}
} elseif (false !== ($i = strpos($identifier, '::'))) {
$r = new \ReflectionMethod(substr($identifier, 0, $i), substr($identifier, 2 + $i));
} else {
$r = new \ReflectionClass($identifier);
}
if ($f = $r->getFileName()) {
$this->attr['file'] = $f;
$this->attr['line'] = $r->getStartLine() - substr_count($r->getDocComment(), "\n");
}
}
示例8: getUseStatements
public static function getUseStatements(\ReflectionClass $class)
{
$content = '';
$file = file($class->getFileName());
for ($i = 0; $i < $class->getStartLine(); $i++) {
$content .= $file[$i];
}
$tokenizer = new PhpTokenizer();
$tokens = $tokenizer->tokenize($content);
$tokens = $tokens->filter(function ($token) {
return $token->type !== T_WHITESPACE && $token->type !== T_COMMENT && $token->type !== T_DOC_COMMENT;
});
$statements = [];
while ($token = $tokens->next()) {
if ($token->type === T_USE) {
$explicitAlias = false;
$alias = '';
$class = '';
while ($token = $tokens->next()) {
$isNameToken = $token->type === T_STRING || $token->type === T_NS_SEPARATOR;
if (!$explicitAlias && $isNameToken) {
$class .= $token->contents;
} else {
if ($explicitAlias && $isNameToken) {
$alias .= $token->contents;
} else {
if ($token->type === T_AS) {
$explicitAlias = true;
$alias = '';
} else {
if ($token->contents === ',') {
if ($explicitAlias) {
$statements[$alias] = $class;
} else {
$statements[] = $class;
}
$class = '';
$alias = '';
$explicitAlias = false;
} else {
if ($token->contents === ';') {
if ($explicitAlias) {
$statements[$alias] = $class;
} else {
$statements[] = $class;
}
break;
} else {
break;
}
}
}
}
}
}
}
}
return $statements;
}
示例9: getClassSource
static function getClassSource(ReflectionClass $class)
{
$path = $class->getFileName();
$lines = @file($path);
$from = $class->getStartLine();
$to = $class->getEndLine();
$len = $to - $from + 1;
return implode(array_slice($lines, $from - 1, $len));
}
示例10: getStartLine
/**
* Return the start line of the class
*
* @param bool $includeDocComment
* @return int
*/
public function getStartLine($includeDocComment = false)
{
if ($includeDocComment) {
if ($this->getDocComment() != '') {
return $this->getDocblock()->getStartLine();
}
}
return parent::getStartLine();
}
示例11: 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())));
}
示例12: getCodeInClass
public function getCodeInClass($className)
{
$class = new \ReflectionClass($className);
$startLine = $class->getStartLine() - 1;
// getStartLine() seems to start after the {, we want to include the signature
$endLine = $class->getEndLine();
$numLines = $endLine - $startLine;
$namespace = $this->getNamespaceOfClass($className);
$classCode = "namespace {$namespace};\n\n" . implode("\n", array_slice(explode("\n", $this->fileContent), $startLine, $numLines)) . "\n";
return $classCode;
}
示例13: parse
/**
* Parse the class file and extract the use statements.
*
* @param string $fileName The name of the file to parse.
* @return array A list with use statements or an empty array if no use statements exists.
*/
private function parse($fileName)
{
if (!$fileName) {
return array();
}
$content = $this->getFileContent($fileName, $this->class->getStartLine());
$namespace = str_replace('\\', '\\\\', $this->class->getNamespaceName());
$content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;|{].*)$/s', '\\1', $content);
$this->tokens = token_get_all('<?php ' . $content);
$this->numTokens = count($this->tokens);
$statements = $this->parseUseStatements();
return $statements;
}
示例14: parseClass
/**
* Parses a class.
*
* @param \ReflectionClass $class A <code>ReflectionClass</code> object.
* @return array A list with use statements in the form (Alias => FQN).
*/
public function parseClass(\ReflectionClass $class)
{
if (false === ($filename = $class->getFilename())) {
return array();
}
$content = $this->getFileContent($filename, $class->getStartLine());
$namespace = str_replace('\\', '\\\\', $class->getNamespaceName());
$content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
$this->tokens = token_get_all('<?php ' . $content);
$this->numTokens = count($this->tokens);
$this->pointer = 0;
$statements = $this->parseUseStatements($class->getNamespaceName());
return $statements;
}
示例15: parseUseStatements
/**
* @return array A list with use statements in the form (Alias => FQN).
*/
public function parseUseStatements(\ReflectionClass $class)
{
if (false === ($filename = $class->getFilename())) {
return array();
}
$content = $this->getFileContent($filename, $class->getStartLine());
if (null === $content) {
return array();
}
$namespace = preg_quote($class->getNamespaceName());
$content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
$tokenizer = new TokenParser('<?php ' . $content);
$statements = $tokenizer->parseUseStatements($class->getNamespaceName());
return $statements;
}