本文整理汇总了PHP中lithium\analysis\Inspector::lines方法的典型用法代码示例。如果您正苦于以下问题:PHP Inspector::lines方法的具体用法?PHP Inspector::lines怎么用?PHP Inspector::lines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\analysis\Inspector
的用法示例。
在下文中一共展示了Inspector::lines方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _method
protected static function _method(array $object, array $data, array $options = array())
{
if (!$data) {
return array();
}
$lines = Inspector::lines($data['file'], range($data['start'], $data['end']));
$object = array('source' => join("\n", $lines)) + $object;
$object += array('tags' => isset($data['tags']) ? $data['tags'] : array());
if (isset($object['tags']['return'])) {
list($type, $text) = explode(' ', $object['tags']['return'], 2) + array('', '');
$object['return'] = compact('type', 'text');
}
return $object;
}
示例2: apply
/**
* Takes an instance of an object (usually a Collection object) containing test
* instances. Introspects the test subject classes to extract cyclomatic complexity data.
*
* @param object $report Instance of Report which is calling apply.
* @param array $tests The test to apply this filter on
* @param array $options Not used.
* @return object|void Returns the instance of `$tests`.
*/
public static function apply($report, $tests, array $options = array())
{
$results = array();
foreach ($tests->invoke('subject') as $class) {
$results[$class] = array();
if (!($methods = Inspector::methods($class, 'ranges', array('public' => false)))) {
continue;
}
foreach ($methods as $method => $lines) {
$lines = Inspector::lines($class, $lines);
$branches = Parser::tokenize(join("\n", (array) $lines), array('include' => static::$_include));
$results[$class][$method] = count($branches) + 1;
$report->collect(__CLASS__, $results);
}
}
return $tests;
}
示例3: range
<h3 id="source">Source</h3>
<div id="sourceCode"></div>
<h3>Stack Trace</h3>
<div class="lithium-stack-trace">
<ol>
<?php
foreach ($stack as $id => $frame) {
?>
<?php
$location = "{$frame['file']}: {$frame['line']}";
$lines = range($frame['line'] - $context, $frame['line'] + $context);
$code = Inspector::lines($frame['file'], $lines);
?>
<li>
<tt><a href="#source" id="<?php
echo $id;
?>
" class="display-source-excerpt">
<?php
echo $frame['functionRef'];
?>
</a></tt>
<div id="sourceCode<?php
echo $id;
?>
" style="display: none;">
示例4: _definition
/**
* Locates original location of closures.
*
* @param mixed $reference File or class name to inspect.
* @param integer $callLine Line number of class reference.
* @return mixed Returns the line number where the method called is defined.
*/
protected static function _definition($reference, $callLine)
{
if (file_exists($reference)) {
foreach (array_reverse(token_get_all(file_get_contents($reference))) as $token) {
if (!is_array($token) || $token[2] > $callLine) {
continue;
}
if ($token[0] === T_FUNCTION) {
return $token[2];
}
}
return;
}
list($class, ) = explode('::', $reference);
if (!class_exists($class)) {
return;
}
$classRef = new ReflectionClass($class);
$methodInfo = Inspector::info($reference);
$methodDef = join("\n", Inspector::lines($classRef->getFileName(), range($methodInfo['start'] + 1, $methodInfo['end'] - 1)));
foreach (array_reverse(token_get_all("<?php {$methodDef} ?>")) as $token) {
if (!is_array($token) || $token[2] > $callLine) {
continue;
}
if ($token[0] === T_FUNCTION) {
return $token[2] + $methodInfo['start'];
}
}
}
示例5: lines
public function lines($data, $start, $end)
{
return Inspector::lines($data, range($start, $end));
}
示例6: testLineIntrospectionWithCRLFLineEndings
/**
* Tests reading specific line numbers of a file that has CRLF line endings.
*/
public function testLineIntrospectionWithCRLFLineEndings()
{
$tmpPath = Libraries::get(true, 'resources') . '/tmp/tests/inspector_crlf';
$contents = implode("\r\n", array('one', 'two', 'three', 'four', 'five'));
file_put_contents($tmpPath, $contents);
$result = Inspector::lines($tmpPath, array(2));
$expected = array(2 => 'two');
$this->assertEqual($expected, $result);
$result = Inspector::lines($tmpPath, array(1, 5));
$expected = array(1 => 'one', 5 => 'five');
$this->assertEqual($expected, $result);
$this->_cleanUp();
}
示例7: testLineIntrospection
/**
* Tests reading specific line numbers of a file.
*
* @return void
*/
public function testLineIntrospection()
{
$result = Inspector::lines(__FILE__, array(__LINE__ - 1));
$expected = array(__LINE__ - 2 => "\tpublic function testLineIntrospection() {");
$this->assertEqual($expected, $result);
$result = Inspector::lines(__CLASS__, array(14));
$expected = array(14 => 'class InspectorTest extends \\lithium\\test\\Unit {');
$this->assertEqual($expected, $result);
$this->expectException('/Missing argument 2/');
$this->assertNull(Inspector::lines('\\lithium\\core\\Foo'));
$this->assertNull(Inspector::lines(__CLASS__, array()));
}
示例8: _extractFileCode
protected static function _extractFileCode($ref, $options)
{
$library = Libraries::get($options['library']);
$file = $ref['file'];
if (!($path = realpath("{$library['path']}/{$file}"))) {
return;
}
list($start, $end) = array_map('intval', explode('-', $ref['lines']));
$lines = Inspector::lines(file_get_contents($path), range($start, $end));
return array("{$ref['file']}::{$ref['lines']}", "\t" . join("\n\t", $lines));
}