当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser::parseSource方法代码示例

本文整理汇总了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));
    }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:26,代码来源:RootNodeTest.php

示例2: formatSource

 protected function formatSource($source)
 {
     /** @var ParentNode $node */
     $node = Parser::parseSource($source);
     $formatter = FormatterFactory::getDrupalFormatter();
     $formatter->format($node);
     return $node->getText();
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:8,代码来源:DrupalFormatterTest.php

示例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());
    }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:21,代码来源:Psr2FormatterTest.php

示例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());
    }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:24,代码来源:FilterTest.php


注:本文中的Parser::parseSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。