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


PHP Parser::parseSnippet方法代码示例

本文整理汇总了PHP中Parser::parseSnippet方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::parseSnippet方法的具体用法?PHP Parser::parseSnippet怎么用?PHP Parser::parseSnippet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser::parseSnippet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testInvalidCommentAbove

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testInvalidCommentAbove()
 {
     $original = '$value = variable_get("my_variable", NULL);';
     /** @var StatementNode $statement_node */
     $statement_node = Parser::parseSnippet($original);
     $statement_node->addCommentAbove(NULL);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:10,代码来源:StatementNodeTest.php

示例2: testCatches

 public function testCatches()
 {
     /** @var \Pharborist\Exceptions\TryCatchNode $tryCatch */
     $tryCatch = Parser::parseSnippet('try { foo(); } catch (\\InvalidArgumentException $e) {}');
     $this->assertTrue($tryCatch->catches('\\InvalidArgumentException'));
     $this->assertFalse($tryCatch->catches('\\DomainException'));
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:7,代码来源:TryCatchNodeTest.php

示例3: formatSnippet

 protected function formatSnippet($snippet)
 {
     /** @var ParentNode $node */
     $node = Parser::parseSnippet($snippet);
     $this->formatter->format($node);
     return $node->getText();
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:7,代码来源:Psr2FormatterTest.php

示例4: formatSnippet

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

示例5: testGetPreviousCall

 public function testGetPreviousCall()
 {
     $call = Parser::parseSnippet('\\Drupal::database()->insert("razmatazz");')->firstChild();
     $this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call);
     $this->assertInstanceOf('\\Pharborist\\Objects\\ClassMethodCallNode', $call->getPreviousCall());
     $call = Parser::parseSnippet('$raz->matazz();')->firstChild();
     $this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call);
     $this->assertNull($call->getPreviousCall());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:9,代码来源:ObjectMethodCallNodeTest.php

示例6: testSetName

 public function testSetName()
 {
     /** @var \Pharborist\Objects\ClassNode $class */
     $class = Parser::parseSnippet('class Foo { public function baz() {} }');
     /** @var \Pharborist\Objects\ClassMethodNode $method */
     $method = $class->getMethod('baz');
     $method->setName('bar');
     $this->assertEquals('bar', $method->getName()->getText());
     $this->assertEquals('public function bar() {}', $method->getText());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:10,代码来源:ClassMethodNodeTest.php

示例7: testAppendStatement

 public function testAppendStatement()
 {
     /** @var \Pharborist\ControlStructures\IfNode $ifNode */
     $ifNode = Parser::parseSnippet('if (TRUE) { hello(); }');
     /** @var StatementBlockNode $statementBlock */
     $statementBlock = $ifNode->getThen();
     $this->assertInstanceOf('\\Pharborist\\StatementBlockNode', $statementBlock);
     $this->assertEquals('{ hello(); }', $statementBlock->getText());
     $statementBlock->appendStatement(Parser::parseSnippet('world();'));
     $this->assertEquals('{ hello(); world();}', $statementBlock->getText());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:11,代码来源:StatementBlockNodeTest.php

示例8: testGetConstants

 public function testGetConstants()
 {
     /** @var \Pharborist\Objects\InterfaceNode $interface */
     $interface = Parser::parseSnippet('interface Foo { const ANSWER = 42; }');
     $constants = $interface->getConstants();
     $this->assertCount(1, $constants);
     /** @var \Pharborist\Constants\ConstantDeclarationNode $constant */
     $constant = $constants[0];
     $this->assertInstanceOf('\\Pharborist\\Constants\\ConstantDeclarationNode', $constant);
     $this->assertEquals('ANSWER', $constant->getName());
     $this->assertEquals('42', $constant->getValue()->getText());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:12,代码来源:InterfaceNodeTest.php

示例9: testInvalid

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testInvalid()
    {
        $snippet = <<<'EOF'
namespace Test {
  function hello_world() {
    echo 'hello world!', PHP_EOL;
  }
}
EOF;
        /** @var \Pharborist\Namespaces\NamespaceNode $namespace_node */
        $namespace_node = Parser::parseSnippet($snippet);
        /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
        $function = $namespace_node->getBody()->children(Filter::isFunction('hello_world'))[0];
        $this->assertTrue($function->inNamespace(new \stdClass()));
    }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:18,代码来源:IdentifierNameTraitTest.php

示例10: uncomment

 /**
  * Uncomments the contents of this comment.
  *
  * @return Node
  */
 public function uncomment()
 {
     /** @var CommentNode|LineCommentBlockNode $this */
     return Parser::parseSnippet($this->getCommentText());
 }
开发者ID:kidaa30,项目名称:redcat,代码行数:10,代码来源:UncommentTrait.php

示例11: testSetImplementsStringArray

 public function testSetImplementsStringArray()
 {
     /** @var \Pharborist\Objects\ClassNode $class */
     $class = Parser::parseSnippet('class Foo {}');
     $class->setImplements(['\\IteratorAggregate', '\\ArrayAccess']);
     $implements = $class->getImplementList();
     $this->assertInstanceOf('\\Pharborist\\CommaListNode', $implements);
     $items = $implements->getItems();
     $this->assertCount(2, $items);
     $this->assertEquals('\\IteratorAggregate, \\ArrayAccess', $implements->getText());
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:11,代码来源:SingleInheritanceNodeTest.php


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