當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。