本文整理汇总了PHP中Parser::parseSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::parseSource方法的具体用法?PHP Parser::parseSource怎么用?PHP Parser::parseSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::parseSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNSHelpers
public function testNSHelpers()
{
$doc = RootNode::create('Pharborist');
$this->assertTrue($doc->hasNamespace('Pharborist'));
$this->assertFalse($doc->hasNamespace('\\Drupal'));
$this->assertContains('Pharborist', $doc->getNamespaceNames());
$this->assertContains('\\Pharborist', $doc->getNamespaceNames(TRUE));
$namespaces = $doc->getNamespaces();
$this->assertInstanceOf('\\Pharborist\\NodeCollection', $namespaces);
$this->assertCount(1, $namespaces);
$this->assertNull($doc->getNamespace('Drupal'));
$ns = $doc->getNamespace('Pharborist');
$this->assertInstanceOf('\\Pharborist\\Namespaces\\NamespaceNode', $ns);
$this->assertSame($ns, $namespaces[0]);
$code = <<<'END'
<?php
namespace RoundTable\
Knights\
MontyPython;
class Foo {}
END;
$doc = Parser::parseSource($code);
$this->assertTrue($doc->hasNamespace('RoundTable\\Knights\\MontyPython'));
$this->assertContains('\\RoundTable\\Knights\\MontyPython', $doc->getNamespaceNames(TRUE));
}
示例2: formatSource
protected function formatSource($source)
{
/** @var ParentNode $node */
$node = Parser::parseSource($source);
$formatter = FormatterFactory::getDrupalFormatter();
$formatter->format($node);
return $node->getText();
}
示例3: testRootNode
public function testRootNode()
{
$snippet = <<<'END'
<?php
namespace Foo\Baz; class Blorg { public function __construct() {}}
END;
$expected = <<<'END'
<?php
namespace Foo\Baz;
class Blorg
{
public function __construct()
{
}
}
END;
$doc = Parser::parseSource($snippet);
$this->formatter->format($doc);
$this->assertEquals($expected, $doc->getText());
}
示例4: testIsClassMethodCall
public function testIsClassMethodCall()
{
$source = <<<'END'
<?php
use MyNamespace\Test;
A::test();
MyNamespace\Test::method();
Test::method();
END;
/** @var \Pharborist\Objects\ClassMethodCallNode[] $method_calls */
$method_calls = Parser::parseSource($source)->find(Filter::isClassMethodCall('\\A', 'test'));
$this->assertCount(1, $method_calls);
$method_call = $method_calls[0];
$this->assertInstanceOf('\\Pharborist\\Objects\\ClassMethodCallNode', $method_call);
$this->assertEquals('\\A', $method_call->getClassName()->getAbsolutePath());
$this->assertEquals('test', $method_call->getMethodName()->getText());
$method_calls = Parser::parseSource($source)->find(Filter::isClassMethodCall('\\MyNamespace\\Test', 'method'));
$this->assertCount(2, $method_calls);
$method_call = $method_calls[0];
$this->assertInstanceOf('\\Pharborist\\Objects\\ClassMethodCallNode', $method_call);
$this->assertEquals('\\MyNamespace\\Test', $method_call->getClassName()->getAbsolutePath());
$this->assertEquals('method', $method_call->getMethodName()->getText());
}