FOF30\Utils\ModelTypeHints::getHints PHP Метод

getHints() публичный Метод

Returns the docblock with the magic field hints for the model class
public getHints ( ) : string
Результат string
    public function getHints()
    {
        $modelName = $this->className;
        $text = "/**\n * Model {$modelName}\n *\n";
        $hints = $this->getRawHints();
        if (!empty($hints['property'])) {
            $text .= " * Fields:\n *\n";
            $colWidth = 0;
            foreach ($hints['property'] as $hintLine) {
                $colWidth = max($colWidth, strlen($hintLine[0]));
            }
            $colWidth += 2;
            foreach ($hints['property'] as $hintLine) {
                $text .= " * @property  " . str_pad($hintLine[0], $colWidth, ' ') . $hintLine[1] . "\n";
            }
            $text .= " *\n";
        }
        if (!empty($hints['method'])) {
            $text .= " * Filters:\n *\n";
            $colWidth = 0;
            $col2Width = 0;
            foreach ($hints['method'] as $hintLine) {
                $colWidth = max($colWidth, strlen($hintLine[0]));
                $col2Width = max($col2Width, strlen($hintLine[1]));
            }
            $colWidth += 2;
            $col2Width += 2;
            foreach ($hints['method'] as $hintLine) {
                $text .= " * @method  " . str_pad($hintLine[0], $colWidth, ' ') . str_pad($hintLine[1], $col2Width, ' ') . $hintLine[2] . "\n";
            }
            $text .= " *\n";
        }
        if (!empty($hints['property-read'])) {
            $text .= " * Relations:\n *\n";
            $colWidth = 0;
            foreach ($hints['property-read'] as $hintLine) {
                $colWidth = max($colWidth, strlen($hintLine[0]));
            }
            $colWidth += 2;
            foreach ($hints['property-read'] as $hintLine) {
                $text .= " * @property  " . str_pad($hintLine[0], $colWidth, ' ') . $hintLine[1] . "\n";
            }
            $text .= " *\n";
        }
        $text .= "**/\n";
        return $text;
    }

Usage Example

Пример #1
0
 public function build()
 {
     $container = $this->builder->getContainer();
     $fullPath = $container->getNamespacePrefix($this->getSection()) . 'Model\\' . ucfirst($container->inflector->pluralize($this->viewName));
     // Let's remove the last part and use it to create the class name
     $parts = explode('\\', trim($fullPath, '\\'));
     $className = array_pop($parts);
     // Now glue everything together
     $namespace = implode('\\', $parts);
     // Let's be sure that the parent class extends with a backslash
     $baseClass = '\\' . trim(get_class($this->model), '\\');
     $code = '<?php' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= 'namespace ' . $namespace . ';' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= "defined('_JEXEC') or die;" . PHP_EOL;
     $code .= PHP_EOL;
     // Let's create some type-hints for the model class
     $typeHints = new ModelTypeHints($this->model);
     $typeHints->setClassName($fullPath);
     $docBlock = $typeHints->getHints();
     $code .= $docBlock;
     $code .= 'class ' . $className . ' extends ' . $baseClass . PHP_EOL;
     $code .= '{' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= '}' . PHP_EOL;
     $path = $container->backEndPath;
     if (in_array('Site', $parts)) {
         $path = $container->frontEndPath;
     }
     $path .= '/Model/' . $className . '.php';
     $filesystem = $container->filesystem;
     $filesystem->fileWrite($path, $code);
     return $path;
 }