Zephir\Stubs\DocBlock::__construct PHP Method

__construct() public method

public __construct ( string $source, string $indent = ' ' )
$source string Raw doc-block
$indent string Indent, 4 spaces by default
    public function __construct($source, $indent = '    ')
    {
        $this->indent = $indent;
        $lines = explode("\n", trim($source));
        $count = count($lines);
        foreach ($lines as $i => $line) {
            $line = preg_replace('#^([\\s\\t]+)?/?([*]+)([\\s\\t]+)?$#im', '', rtrim($line));
            $line = preg_replace('#^([\\s\\t]+)?([*]+)([\\s\\t]+)?/?$#im', '', rtrim($line));
            if (($i === 0 || $i === $count - 1) && empty($line)) {
                continue;
            }
            $cleaned = trim($line, "\t* ");
            if (strpos($cleaned, '@') === 0) {
                $this->lines[] = $line = $cleaned;
            } else {
                $line = preg_replace('#([\\s\\t]+)?[*]#', '', $line);
                $line = preg_replace('#([\\s\\t]+)?[*]([\\s\\t]){1,2}#', '$1* ', ' * ' . $line);
                $line = preg_replace('#[*]([\\s\\t]){1,}$#', '*', $line);
                $line = preg_replace('#\\t#', $indent, $line);
                $this->lines[] = array_pop($this->lines) . "\n{$this->indent}" . $line;
            }
        }
        if (!empty($this->lines) && strpos(trim($this->lines[0], "\t* "), '@') !== 0) {
            $description = array_shift($this->lines);
            $description = explode("\n", $description);
            $cleaned = [];
            $empty = 0;
            foreach ($description as $i => $line) {
                if (preg_match('#^([\\s\\t]+)?[*]([\\s\\t]+)?$#', $line)) {
                    $empty++;
                } else {
                    $empty = 0;
                }
                if ($empty > 1) {
                    continue;
                }
                $cleaned[] = $line;
            }
            $reversed = array_reverse($cleaned);
            if (empty($reversed[0]) || trim($reversed[0], "\t* ") === '') {
                unset($reversed[0]);
            }
            $this->description = implode("\n", array_reverse($reversed));
        }
    }

Usage Example

コード例 #1
0
ファイル: MethodDocBlock.php プロジェクト: phalcon/zephir
 public function __construct(ClassMethod $method, AliasManager $aliasManager, $indent = '    ')
 {
     parent::__construct($method->getDocBlock(), $indent);
     $this->deprecated = $method->isDeprecated();
     $this->aliasManager = $aliasManager;
     $this->shortcutName = $method->isShortcut() ? $method->getShortcutName() : '';
     $this->parseMethodParameters($method);
     $this->parseLines();
     $this->parseMethodReturnType($method);
     $this->appendParametersLines();
     if (!empty($this->return)) {
         $this->appendReturnLine();
     }
 }
All Usage Examples Of Zephir\Stubs\DocBlock::__construct