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


PHP DocBlock::getText方法代码示例

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


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

示例1: createPhpDocs

 /**
  * @param string $class
  * @return string
  */
 protected function createPhpDocs($class)
 {
     $reflection = new \ReflectionClass($class);
     $namespace = $reflection->getNamespaceName();
     $classname = $reflection->getShortName();
     $originalDoc = $reflection->getDocComment();
     if ($this->reset) {
         $phpdoc = new DocBlock('', new Context($namespace));
     } else {
         $phpdoc = new DocBlock($reflection, new Context($namespace));
     }
     if (!$phpdoc->getText()) {
         $phpdoc->setText($class);
     }
     $properties = array();
     $methods = array();
     foreach ($phpdoc->getTags() as $tag) {
         $name = $tag->getName();
         if ($name == "property" || $name == "property-read" || $name == "property-write") {
             $properties[] = $tag->getVariableName();
         } elseif ($name == "method") {
             $methods[] = $tag->getMethodName();
         }
     }
     foreach ($this->properties as $name => $property) {
         $name = "\${$name}";
         if (in_array($name, $properties)) {
             continue;
         }
         if ($property['read'] && $property['write']) {
             $attr = 'property';
         } elseif ($property['write']) {
             $attr = 'property-write';
         } else {
             $attr = 'property-read';
         }
         $tag = Tag::createInstance("@{$attr} {$property['type']} {$name} {$property['comment']}", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     foreach ($this->methods as $name => $method) {
         if (in_array($name, $methods)) {
             continue;
         }
         $arguments = implode(', ', $method['arguments']);
         $tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     $serializer = new DocBlockSerializer();
     $serializer->getDocComment($phpdoc);
     $docComment = $serializer->getDocComment($phpdoc);
     if ($this->write) {
         $filename = $reflection->getFileName();
         $contents = \File::get($filename);
         if ($originalDoc) {
             $contents = str_replace($originalDoc, $docComment, $contents);
         } else {
             $needle = "class {$classname}";
             $replace = "{$docComment}\nclass {$classname}";
             $pos = strpos($contents, $needle);
             if ($pos !== false) {
                 $contents = substr_replace($contents, $replace, $pos, strlen($needle));
             }
         }
         if (\File::put($filename, $contents)) {
             $this->info('Written new phpDocBlock to ' . $filename);
         }
     }
     $output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} {}\n}\n\n";
     return $output;
 }
开发者ID:pacho104,项目名称:redbpim,代码行数:74,代码来源:ModelsCommand.php

示例2: getDocComment

 /**
  * Generate a DocBlock comment.
  *
  * @param DocBlock The DocBlock to serialize.
  *
  * @return string The serialized doc block.
  */
 public function getDocComment(DocBlock $docblock)
 {
     $indent = str_repeat($this->indentString, $this->indent);
     $firstIndent = $this->isFirstLineIndented ? $indent : '';
     $text = $docblock->getText();
     if ($this->lineLength) {
         //3 === strlen(' * ')
         $wrapLength = $this->lineLength - strlen($indent) - 3;
         $text = wordwrap($text, $wrapLength);
     }
     $text = str_replace("\n", "\n{$indent} * ", $text);
     $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
     /** @var Tag $tag */
     foreach ($docblock->getTags() as $tag) {
         $tagText = (string) $tag;
         if ($this->lineLength) {
             $tagText = wordwrap($tagText, $wrapLength);
         }
         $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
         $comment .= "{$indent} * {$tagText}\n";
     }
     $comment .= $indent . ' */';
     return $comment;
 }
开发者ID:cruni505,项目名称:prestomed,代码行数:31,代码来源:Serializer.php

示例3: getInheritDoc

 protected function getInheritDoc($reflectionMethod)
 {
     $parentClass = $reflectionMethod->getDeclaringClass()->getParentClass();
     //Get either a parent or the interface
     if ($parentClass) {
         $method = $parentClass->getMethod($reflectionMethod->getName());
     } else {
         $method = $reflectionMethod->getPrototype();
     }
     if ($method) {
         $phpdoc = new DocBlock($method);
         if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
             //Not at the end yet, try another parent/interface..
             return $this->getInheritDoc($method);
         } else {
             return $phpdoc;
         }
     }
 }
开发者ID:gsaulmon,项目名称:laravel-facade-dump,代码行数:19,代码来源:GeneratorCommand.php

示例4: getClassHeader

    protected function getClassHeader($ReflectionEntity, &$params, $class_path, $class_name, $hlevel_extra)
    {
        $ns = $ReflectionEntity->getNamespaceName();
        $name = $ReflectionEntity->getName();
        if ($ns) {
            $name = substr($ReflectionEntity->getName(), strlen($ns) + 1);
        }
        $PHPDoc = new DocBlock($ReflectionEntity->getDocComment());
        $desc = $PHPDoc->getText();
        if ($desc) {
            $desc .= "\n\n";
        }
        $parent = $ReflectionEntity->getParentClass();
        $extra_parent = '';
        if ($parent instanceof ReflectionClass) {
            $parent_ns = $parent->getNamespaceName();
            $parent_name = '\\' . $parent->getName();
            $extra_parent = ' extends ' . $parent_name;
        }
        $altname = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $name));
        $type = 'Class';
        if ($ReflectionEntity->isTrait()) {
            $type = 'Trait';
        }
        $typeLower = strtolower($type);
        // var_dump('level: '.$params['level']);
        if (!$params['level']) {
            // var_dump('2: '.$hlevel_extra);
            $params['level'] = 3;
        }
        $params['level'] += $hlevel_extra;
        $level = $this->getHeaderLevel($params['level'], 1);
        $result = <<<TPL
{$level} {$altname} # {$name} {tpl-git {$class_path}}

```php
namespace {$ns};
{$typeLower} {$name}{$extra_parent};
```

{$desc}
TPL;
        return $result;
    }
开发者ID:bscheshirwork,项目名称:daemon.io,代码行数:44,代码来源:PHPDocImporter.php

示例5: parseMdPropertieFromPHPDoc

 /**
  * Парсит описание свойства из phpdoc в стандартизованный вид для дальнейшей обработки
  * @param  string $text
  * @return string
  */
 protected function parseMdPropertieFromPHPDoc($text)
 {
     $lines = $this->getTextLines($text, '/\\n/', false);
     $phpdoc = [];
     while (true) {
         $line = array_shift($lines);
         if (is_null($line)) {
             break;
         }
         $phpdoc[] = $line;
         if (preg_match('/^[ \\t]*\\*\\//', $line)) {
             break;
         }
     }
     $code = implode("\n", $lines);
     $comment = implode("\n", $phpdoc);
     $PHPDoc = new DocBlock($comment);
     $doc_var = $PHPDoc->getTagsByName('var');
     if (empty($doc_var)) {
         return $code . "\n" . $PHPDoc->getText();
     }
     $tag = $doc_var[0];
     $type = $tag->getType();
     $deftype = $this->getDocDefaultType($type);
     $desc = $tag->getDescription();
     if (!$desc) {
         $desc = $PHPDoc->getText();
     }
     return $deftype . ' ' . $code . "\n" . $desc;
 }
开发者ID:bscheshirwork,项目名称:daemon.io,代码行数:35,代码来源:DocBuilder.php

示例6: parseMethod

 /**
  * @param string $method
  *
  * @return array
  */
 public function parseMethod($method)
 {
     $methodReflector = $this->reflector->getMethod($method);
     // Creating docblock for parsing the docs
     $docblock = new DocBlock($methodReflector);
     // Parsing params
     $params = [];
     foreach ($docblock->getTagsByName('apiParam') as $param) {
         // Removing $ sign from name
         $name = $param->getVariableName();
         if (substr($name, 0, 1) == '$') {
             $name = substr($name, 1);
         }
         $params[] = ['type' => $param->getType(), 'name' => $name];
     }
     // Parse for return value
     $return = [];
     if (!is_null($this->statements)) {
         $return = @$this->methodStatementsReturns[$method] ?: [];
     }
     return ['description' => $docblock->getText(), 'params' => $params, 'return' => $return];
 }
开发者ID:mohaiminul-sust,项目名称:laravel-apidocs,代码行数:27,代码来源:ControllerParser.php

示例7: examples

 /**
  * Parse examples from a DocBlock object.
  *
  * Example:
  * ```
  * // Yeah, this example is pretty useless.
  * $examples = $parser->examples($docBlock);
  * ```
  *
  * @param DocBlock $docBlock The DocBlock to parse
  * @param string $file The filename the docblock is in
  * @param int $line The line where the tested method or class is declared.
  * @return array
  */
 public function examples(DocBlock $docBlock, $fullyQualifiedName, $file, $line, array $magicMethods = [])
 {
     $text = $docBlock->getText();
     // $return = $docBlock->getTagsByName('return');
     // if (!empty($return)) {
     //     print_r($return[0]->getTypes());exit;
     // }
     $parts = explode('Example:', $text);
     if (strpos($text, 'Example:') === false) {
         return [];
     }
     $converter = new Parsedown();
     $document = new DOMDocument();
     $parsedText = $converter->text($parts[1]);
     $document->loadHTML($parsedText);
     $examples = $document->getElementsByTagName('code');
     $index = 0;
     $res = [];
     foreach ($examples as $example) {
         $name = $this->extractSnippetName($example->textContent);
         $indexOrName = $name;
         if (!$name) {
             $indexOrName = $index;
         }
         $identifier = $this->createIdentifier($fullyQualifiedName, $indexOrName);
         $snippet = new Snippet($identifier, ['content' => $example->textContent, 'fqn' => $fullyQualifiedName, 'index' => $index, 'name' => $name, 'file' => $file, 'line' => $line]);
         $res[$identifier] = $snippet;
         $index++;
     }
     $res = array_merge($res, $magicMethods);
     return $res;
 }
开发者ID:GoogleCloudPlatform,项目名称:gcloud-php,代码行数:46,代码来源:Parser.php

示例8: mergeGeneratedTagsIntoDocBlock

 /**
  * @param string $existingDocBlock
  * @return string
  */
 protected function mergeGeneratedTagsIntoDocBlock($existingDocBlock)
 {
     $docBlock = new DocBlock($this->removeExistingSupportedTags($existingDocBlock));
     if (!$docBlock->getText()) {
         $docBlock->setText('Class ' . $this->className);
     }
     foreach ($this->getGeneratedTags() as $tag) {
         $docBlock->appendTag($tag);
     }
     $serializer = new DocBlockSerializer();
     $docBlock = $serializer->getDocComment($docBlock);
     return $docBlock;
 }
开发者ID:axyr,项目名称:silverstripe-ideannotator,代码行数:17,代码来源:DocBlockGenerator.php


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