Example #1
0
    /**
     * @param PartInterface$part
     */
    public function preRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        /**
         * @var $table \Model\Cluster\Schema\Table
         */
        $table = $part->getTable();
        $tableNameAsCamelCase = $table->getNameAsCamelCase();
        $tags = array(array('name' => 'see', 'description' => 'parent::setupDefaultEntityType()'));
        $docblock = new \Zend\Code\Generator\DocBlockGenerator('Устанавливаем тип entity по-умолчанию');
        $docblock->setTags($tags);
        $method = new \Zend\Code\Generator\MethodGenerator();
        $method->setName('setupDefaultEntityType');
        $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PROTECTED);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
\$this->defaultEntityType = '\\Model\\Entity\\{$tableNameAsCamelCase}Entity';
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #2
0
 public function postRun(PartInterface $part)
 {
     /** @var $part \Model\Generator\Part\Model */
     $file = $part->getFile();
     $this->generateEnumConstantList($part);
     return $file;
 }
Example #3
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $tableName = $part->getTable()->getName();
        $tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
        $tags = array(array('name' => 'return', 'description' => 'void'));
        $docblock = new \Zend\Code\Generator\DocBlockGenerator('Настраиваем текущую сущность');
        $docblock->setTags($tags);
        $method = new \Zend\Code\Generator\MethodGenerator();
        $method->setName('setupEntity');
        $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
\$this->setName('{$tableName}');
\$this->setEntityName('{$tableName}');
\$this->setEntityClassName('\\Model\\Entity\\{$tableNameAsCamelCase}Entity');
\$this->setCollectionClassName('\\Model\\Collection\\{$tableNameAsCamelCase}Collection');
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #4
0
File: Add.php Project: meniam/model
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
        $tableNameAsVar = $part->getTable()->getNameAsVar();
        //$tableComment = $part->getTable()->getComment();
        $tags = array(array('name' => 'param', 'description' => 'array|' . $tableNameAsCamelCase . 'Model $' . $tableNameAsVar), array('name' => 'return', 'description' => '\\Model\\Entity\\' . $tableNameAsCamelCase));
        $docblock = new \Zend\Code\Generator\DocBlockGenerator('Добавить ' . $tableNameAsCamelCase);
        $docblock->setTags($tags);
        $method = new \Zend\Code\Generator\MethodGenerator();
        $method->setName('add' . $tableNameAsCamelCase);
        $method->setParameter(new \Zend\Code\Generator\ParameterGenerator($tableNameAsVar, 'mixed'));
        $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
\${$tableNameAsVar}Id = null;
\$result = ModelResult();
\${$tableNameAsVar} = new \${$tableNameAsVar}Entity(\${$tableNameAsVar});
\${$tableNameAsVar}Data = \${$tableNameAsVar}->toArray();

// Фильтруем входные данные
\${$tableNameAsVar}Data = \$this->addFilter(\${$tableNameAsVar}Data);

// Валидируем данные
\$validator = \$this->addValidate(\${$tableNameAsVar}Data);
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #5
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $columnCollection = $part->getTable()->getColumn();
        $template = '';
        /** @var $column Column */
        foreach ($columnCollection as $column) {
            $name = $column->getName();
            $requiredFlag = !($column->isNullable() || $column->getName() == 'id');
            if ($columnConfig = $part->getColumntConfig($column)) {
                if ($columnConfig && isset($columnConfig['validators'])) {
                    foreach ($columnConfig['validators'] as $validator) {
                        if (isset($validator['params'])) {
                            $validatorParams = $this->prepareValidatorParams($validator['params'], $column);
                            $validatorParams = $this->varExportMin($validatorParams, true);
                        } else {
                            $validatorParams = null;
                        }
                        if ($validatorParams && $validatorParams != 'NULL') {
                            $template .= "\$this->addValidatorRule('{$name}', Model::getValidatorAdapter()->getValidatorInstance('{$validator['name']}', {$validatorParams}), " . ($requiredFlag ? 'true' : 'false') . ");\n";
                        } else {
                            $template .= "\$this->addValidatorRule('{$name}', Model::getValidatorAdapter()->getValidatorInstance('{$validator['name']}'), " . ($requiredFlag ? 'true' : 'false') . ");\n";
                        }
                    }
                }
            }
        }
        $template = rtrim($template, "\r\n, ");
        //$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
        $tags = array(array('name' => 'return', 'description' => 'array Model массив с фильтрами по полям'));
        $docblock = new DocBlockGenerator('Получить правила для фильтрации ');
        $docblock->setTags($tags);
        $method = new MethodGenerator();
        $method->setName('initValidatorRules');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setStatic(false);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
{$template}
\$this->setupValidatorRules();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #6
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Entity
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $table = $part->getTable();
     if (!$table->isTree()) {
         return;
     }
 }
Example #7
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tags = array(array('name' => 'return', 'description' => 'array'));
        $docblock = new DocBlockGenerator('Initialize indexes');
        $docblock->setTags($tags);
        $resultIndexList = array();
        $indexList = $table->getIndex();
        foreach ($indexList as $index) {
            $resIndex = $index->toArray();
            $resIndex['column_list'] = array();
            switch ($index->getType()) {
                case AbstractIndex::TYPE_PRIMARY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_PRIMARY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_KEY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_KEY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_UNIQUE:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_UNIQUE', ValueGenerator::TYPE_CONSTANT);
                    break;
            }
            foreach ($resIndex['columns'] as $col) {
                $resIndex['column_list'][] = $col['column_name'];
            }
            unset($resIndex['columns']);
            $resultIndexList[$index->getName()] = $resIndex;
        }
        $property = new PropertyGenerator('indexList', $resultIndexList, PropertyGenerator::FLAG_PROTECTED);
        $body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
        $method = new MethodGenerator();
        $method->setName('initIndexList');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
{$body}
\$this->indexList = \$indexList;
\$this->setupIndexList();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #8
0
    /**
     * @param \Model\Generator\Part\PartInterface $part
     */
    public function preRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        /**
         * @var $table \Model\Cluster\Schema\Table
         */
        $table = $part->getTable();
        $maxColNameLen = $table->getMaxColumnNameLength();
        $columnList = $table->getColumn();
        $docblock = new DocBlockGenerator('Настраиваем типы данных');
        $method = new \Zend\Code\Generator\MethodGenerator();
        $method->setName('setupDataTypes');
        $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PROTECTED);
        $method->setDocBlock($docblock);
        $dataTypesText = '';
        foreach ($columnList as $column) {
            $columnName = str_pad('\'' . $column->getName() . '\'', $maxColNameLen + 2, ' ', STR_PAD_RIGHT);
            $columnType = $column->getTypeAsDataTypeConstant();
            $dataTypesText .= "    {$columnName} => {$columnType},\n";
        }
        $linkList = $table->getLink();
        foreach ($linkList as $link) {
            $foreignName = $link->getForeignTable()->getName();
            $columnComment = $link->getForeignColumn()->getComment();
            switch ($link->getLinkType()) {
                case AbstractLink::LINK_TYPE_ONE_TO_MANY:
                case AbstractLink::LINK_TYPE_MANY_TO_MANY:
                    $columnName = str_pad('\'_' . $foreignName . '_collection' . '\'', $maxColNameLen + 2, ' ', STR_PAD_RIGHT);
                    $dataTypesText .= "    {$columnName} => 'Model\\\\Collection\\\\" . $link->getForeignColumn()->getTable()->getNameAsCamelCase() . "Collection',\n";
                case AbstractLink::LINK_TYPE_ONE_TO_ONE:
                case AbstractLink::LINK_TYPE_MANY_TO_ONE:
                    $columnName = str_pad('\'_' . $foreignName . '\'', $maxColNameLen + 2, ' ', STR_PAD_RIGHT);
                    $dataTypesText .= "    {$columnName} => 'Model\\\\Entity\\\\" . $link->getForeignColumn()->getTable()->getNameAsCamelCase() . "Entity',\n";
            }
        }
        $dataTypesText = rtrim($dataTypesText, "\r\n ,");
        $method->setBody(<<<EOS
\$this->dataTypes = array(
{$dataTypesText});
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #9
0
 /**
  * @param \Model\Generator\Part\Model|\Model\Generator\Part\PartInterface $part
  */
 public function postRun(PartInterface $part)
 {
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     /** @var Table $table */
     $table = $part->getTable();
     /** @var string $tableName */
     $tableName = $table->getName();
     if (isset(self::$_data[$tableName])) {
         foreach (self::$_data[$tableName] as $property) {
             $file->getClass()->addPropertyFromGenerator($property);
         }
     }
 }
Example #10
0
 /**
  * @param \Model\Generator\Part\Model|\Model\Generator\Part\PartInterface $part
  */
 public function postRun(PartInterface $part)
 {
     /**
      * @var FileGenerator $file
      */
     $file = $part->getFile();
     /**
      * @var Table $table
      */
     $table = $part->getTable();
     if (isset($this->_data[$table->getName()])) {
         foreach ($this->_data[$table->getName()] as $property) {
             $file->getClass()->addPropertyFromGenerator($property);
         }
     }
 }
Example #11
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tags = array(array('name' => 'var', 'description' => 'array значения по-умолчанию для полей'));
        $docblock = new \Zend\Code\Generator\DocBlockGenerator('Значения по-умолчанию для полей');
        $docblock->setTags($tags);
        $columnCollection = $table->getColumn();
        if (!$columnCollection) {
            return;
        }
        $defaults = '';
        /** @var $column Column */
        foreach ($columnCollection as $column) {
            $columnName = $column->getName();
            $defaultValue = $column->getColumnDefault();
            if (substr($columnName, -5) == '_date') {
                $defaults .= "\$this->setDefaultRule('" . $columnName . "', date('Y-m-d H:i:s'));\n    ";
            } elseif ($defaultValue == 'CURRENT_TIMESTAMP') {
                $defaults .= "\$this->setDefaultRule('" . $columnName . "', date('Y-m-d H:i:s'));\n    ";
            } elseif (!empty($defaultValue)) {
                $defaults .= '$this->setDefaultRule(\'' . $columnName . '\', \'' . (string) $defaultValue . '\');' . "\n    ";
            } elseif (is_null($defaultValue) && $column->isNullable()) {
                $defaults .= '$this->setDefaultRule(\'' . $columnName . '\', null);' . "\n    ";
            }
        }
        $tags = array(array('name' => 'return', 'description' => 'void'));
        $docblock = new DocBlockGenerator('Инициализация значений по-умолчанию');
        $docblock->setTags($tags);
        $method = new MethodGenerator();
        $method->setName('initDefaultsRules');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
    {$defaults}
\$this->setupDefaultsRules();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #12
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Entity
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
     $tags = array(array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'license', 'description' => 'MIT'), array('name' => 'author', 'description' => 'Model_Generator'), array('name' => 'author', 'description' => 'Eugene Myazin <*****@*****.**>'), array('name' => 'author', 'description' => 'Mikhail Rybalka <*****@*****.**>'), array('name' => 'author', 'description' => 'Vadim Slutsky <*****@*****.**>'), array('name' => 'author', 'description' => 'Anton Sedyshev <*****@*****.**>'));
     if ($file->getClass()->getDocblock()) {
         $file->getClass()->getDocblock()->setTags($tags);
     } else {
         $docblock = new DocBlockGenerator('Entity ' . $tableNameAsCamelCase);
         $docblock->setTags($tags);
         $file->getClass()->setDocblock($docblock);
     }
 }
Example #13
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Model
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $table = $part->getTable();
     $tableNameAsCamelCase = $table->getNameAsCamelCase();
     $file->addUse('Model\\Cond\\' . $tableNameAsCamelCase . 'Cond', 'Cond');
     $file->addUse('Model\\Entity\\' . $tableNameAsCamelCase . 'Entity');
     $file->addUse('Model\\Collection\\' . $tableNameAsCamelCase . 'Collection');
     $file->addUse('Model\\Result\\Result');
     $this->defaultStub($file);
     $this->setupCascadeRulesStub($file);
     $this->setupFilterRulesStub($file);
     $this->validatorStub($file);
     $this->prepareStub($file);
     $this->viewStub($part);
     return $file;
 }
Example #14
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Model
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $linkList = $part->getTable()->getLink();
     foreach ($linkList as $link) {
         if ($link->getLinkTable()) {
             $method = $this->getLinkMethodUsedLinkTable($link);
             $file->getClass()->addMethodFromGenerator($method);
             $method = $this->getDeleteLinkMethodUsedLinkTable($link);
             $file->getClass()->addMethodFromGenerator($method);
         } else {
             $method = $this->getLinkMethodWithoutLinkTable($link);
             $file->getClass()->addMethodFromGenerator($method);
             $method = $this->getDeleteLinkMethodWithoutLinkTable($link);
             $file->getClass()->addMethodFromGenerator($method);
         }
     }
 }
Example #15
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $tableName = $part->getTable()->getName();
        $schema = $part->getTable()->getSchema()->getName();
        $docblock = new DocBlockGenerator('Конструктор');
        $method = new MethodGenerator();
        $method->setName('__construct');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
\$this->setName('{$tableName}');
\$this->setDbAdapterName('{$schema}_db');
parent::__construct();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #16
0
    /**
     * @param PartInterface $part
     */
    public function preRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        /**
         * @var $table \Model\Cluster\Schema\Table
         */
        $table = $part->getTable();
        /** @var $columnList Column[]  */
        $columnList = $table->getColumn();
        foreach ($columnList as $column) {
            $columnName = $column->getName();
            $columnComment = $column->getComment();
            if ($columnComment) {
                $shortDescription = "Get " . mb_strtolower($columnComment, 'UTF-8') . ' (' . $column->getTable()->getName() . '.' . $columnName . ')';
            } else {
                $shortDescription = 'Get ' . $column->getTable()->getName() . '.' . $columnName;
            }
            $docBlock = new DocBlockGenerator($shortDescription);
            $docBlock->setTags(array(array('name' => 'return', 'description' => $column->getTypeAsPhp())));
            $method = new MethodGenerator();
            $method->setName('get' . $column->getNameAsCamelCase());
            $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
            $method->setDocBlock($docBlock);
            $method->setBody(<<<EOS
return \$this->get('{$columnName}');
EOS
);
            $part->getFile()->getClass()->addMethodFromGenerator($method);
        }
    }
Example #17
0
 /**
  * @param \Model\Generator\Part\Model|\Model\Generator\Part\PartInterface $part
  */
 public function preRun(PartInterface $part)
 {
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     /** @var Table $table */
     $table = $part->getTable();
     /** @var string $tableName */
     //$tableName = $table->getName();
     /** @var $linkList|Link[] \Model\Cluster\Schema\Table\Column */
     //$linkList = $table->getLink();
     if ($table->isTree()) {
         $names = array('WITH_CHILD', 'WITH_CHILD_COLLECTION', 'WITH_ALL_CHILD', 'WITH_ALL_CHILD_COLLECTION');
         foreach ($names as $name) {
             $property = new PropertyGenerator($name, strtolower($name), PropertyGenerator::FLAG_CONSTANT);
             $tags = array(array('name' => 'const'), array('name' => 'var', 'description' => 'string'));
             $docblock = new DocBlockGenerator('WITH entity for child list');
             $docblock->setTags($tags);
             $property->setDocBlock($docblock);
             $file->getClass()->addPropertyFromGenerator($property);
         }
     }
 }
Example #18
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
        $tags = array(array('name' => 'return', 'description' => '\\Model\\' . $tableNameAsCamelCase . 'Model экземпляр модели'));
        $docblock = new DocBlockGenerator('Получить экземпляр модели ' . $tableNameAsCamelCase);
        $docblock->setTags($tags);
        $method = new MethodGenerator();
        $method->setName('getInstance');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setStatic(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
return parent::getInstance();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #19
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Model
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $table = $part->getTable();
     $tableName = $table->getName();
     $tableNameAsCamelCase = $table->getNameAsCamelCase();
     $file->addUse('Model\\Cond\\' . $tableNameAsCamelCase . 'Cond');
     $indexList = $part->getTable()->getIndex();
     /*$methods = $this->generateMethodsByLink($part);
     
             foreach ($methods as $method) {
                 $file->getClass()->addMethodFromGenerator($method);
             }*/
     $this->generateMethodsByRelated($part);
     $this->generateMethodsByIndex($part);
     $this->generateDocBlock($part);
     return $file;
 }
Example #20
0
 /**
  * @param \Model\Generator\Part\PartInterface $part
  */
 public function preRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Entity
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     /**
      * @var $table \Model\Cluster\Schema\Table
      */
     $table = $part->getTable();
     if ($file->getClass()->getDocblock()) {
         $docBlock = $file->getClass()->getDocblock();
     } else {
         $docBlock = new DocBlockGenerator('Сущность ' . $table->getNameAsCamelCase());
         $file->getClass()->setDocblock($docBlock);
     }
     $columnList = $table->getColumn();
     $config = $part->getOption('config');
     $configFields = isset($config['fields']) ? $config['fields'] : array();
     $usedMethods = array();
     /** @var $columnList \Model\Cluster\Schema\Table\Column[]  */
     foreach ($columnList as $column) {
         foreach ($configFields as $configField) {
             if (isset($configField['match']) && ($columnConfig = $part->getColumntConfig($column))) {
                 /*foreach ($configField['match'] as $match) {
                                         $isMatched = false;
                                         if (isset($match['type'])) {
                                             $matchTypes = is_array($match['type']) ? $match['type'] : array($match['type']);
                                             $isMatched = in_array($column->getColumnType(), $matchTypes);
                                         }
                 
                                         $isMatched = $isMatched && preg_match($match['regexp'], $column->getFullName());
                 
                                         $columnLength = $column->getCharacterMaximumLength() ? $column->getCharacterMaximumLength() : $column->getNumericPrecision();
                 
                                         if ($isMatched && isset($match['length'])) {
                                             foreach ($match['length'] as $operation => $lengthMatch) {
                                                 $operation = preg_replace('#\s+#', '', $operation);
                                                 switch ($operation) {
                                                     case '<':
                                                         $isMatched = ($columnLength < $lengthMatch);
                                                         break;
                                                     case '>':
                                                         $isMatched = ($columnLength > $lengthMatch);
                                                         break;
                                                     case '>=':
                                                         $isMatched = ($columnLength >= $lengthMatch);
                                                         break;
                                                     case '<=':
                                                         $isMatched = ($columnLength <= $lengthMatch);
                                                         break;
                                                     case '==':
                                                         $isMatched = ($columnLength == $lengthMatch);
                                                         break;
                                                     case '=':
                                                         $isMatched = ($columnLength == $lengthMatch);
                                                         break;
                                                     default:
                                                         $isMatched = false;
                                                 }
                                             }
                                         }
                 
                                         if ($isMatched) {
                                             break;
                                         }
                                     }*/
                 if ($columnConfig && isset($configField['decorators'])) {
                     foreach ($configField['decorators'] as $decorator) {
                         $methodName = 'get' . $column->getNameAsCamelCase() . 'As' . $decorator['name'] . 'Decorator';
                         if (!isset($usedMethods[$methodName])) {
                             $file->addUse('\\Model\\Entity\\Decorator\\' . "{$decorator['name']}Decorator");
                             $docBlock->setTag(array('name' => 'method', 'description' => "{$decorator['name']}Decorator {$methodName}() {$methodName}() Декорируем данные как {$decorator['name']}"));
                             $usedMethods[$methodName] = 1;
                         }
                     }
                 }
             }
         }
         $decoratorArray = $column->getDecorator();
         foreach ($decoratorArray as $decorator) {
             $methodName = 'get' . $column->getNameAsCamelCase() . 'As' . $decorator['name'] . 'Decorator';
             if (!isset($usedMethods[$methodName])) {
                 $file->addUse('\\Model\\Entity\\Decorator\\' . "{$decorator['name']}Decorator");
                 $docBlock->setTag(array('name' => 'method', 'description' => "{$decorator['name']}Decorator {$methodName}() {$methodName}() Декорируем данные как {$decorator['name']}"));
                 $usedMethods[$methodName] = 1;
             }
         }
     }
 }
Example #21
0
 public function postRun(PartInterface $part)
 {
     /**
      * @var $part \Model\Generator\Part\Entity
      */
     /**
      * @var $file \Model\Code\Generator\FileGenerator
      */
     $file = $part->getFile();
     $table = $part->getTable();
     $tags = array(array('name' => 'var', 'description' => ' array связи'));
     $docblock = new \Zend\Code\Generator\DocBlockGenerator('Связи');
     $docblock->setTags($tags);
     $linkList = $table->getLink();
     /*if ($table->getColumn('parent_id')) {
                 echo $table->getName();
     
                 print_r($linkList);
                 die;
             }*/
     $relation = array();
     foreach ($linkList as $link) {
         $linkLocalColumnName = $link->getLocalColumn()->getName();
         if ($link->getForeignTable() == $link->getLocalTable() && $link->getLocalColumn() == $link->getForeignColumn()) {
             continue;
         }
         $foreignAliasName = $link->getForeignEntity();
         $rel = $link->toArray();
         unset($rel['name']);
         switch ($link->getLinkType()) {
             case AbstractLink::LINK_TYPE_ONE_TO_ONE:
                 $rel['type'] = new ValueGenerator('AbstractModel::ONE_TO_ONE', ValueGenerator::TYPE_CONSTANT);
                 break;
             case AbstractLink::LINK_TYPE_ONE_TO_MANY:
                 $rel['type'] = new ValueGenerator('AbstractModel::ONE_TO_MANY', ValueGenerator::TYPE_CONSTANT);
                 break;
             case AbstractLink::LINK_TYPE_MANY_TO_ONE:
                 $rel['type'] = new ValueGenerator('AbstractModel::MANY_TO_ONE', ValueGenerator::TYPE_CONSTANT);
                 break;
             case AbstractLink::LINK_TYPE_MANY_TO_MANY:
                 $rel['type'] = new ValueGenerator('AbstractModel::MANY_TO_MANY', ValueGenerator::TYPE_CONSTANT);
                 break;
         }
         if ($link->getLocalColumn()->getName() != 'id' && !$link->getLinkTable() || $link->getLocalColumn()->getName() == 'id' && !$link->getLinkTable() && !$link->getLocalColumn()->isAutoincrement()) {
             $rel['required_link'] = !$link->getLocalColumn()->isNullable();
             $rel['link_method'] = 'link' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
             $rel['unlink_method'] = 'deleteLink' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
         } else {
             if ($table->getName() == 'tag') {
                 if ($link->getLocalEntityAlias() != $link->getLocalTable()->getName()) {
                     $foreignAliasName .= '_as_' . $link->getLocalEntityAlias();
                 }
             }
             $rel['required_link'] = false;
             $rel['link_method'] = 'link' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
             $rel['unlink_method'] = 'deleteLink' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
         }
         $rel['local_entity'] = $link->getLocalEntity();
         $rel['foreign_entity'] = $link->getForeignEntity();
         $relation[$foreignAliasName] = $rel;
         $relation[$foreignAliasName]['foreign_model'] = '\\Model\\' . $link->getForeignTable()->getNameAsCamelCase() . 'Model';
     }
     $property = new PropertyGenerator('relation', $relation, PropertyGenerator::FLAG_PROTECTED);
     //$property->setDocBlock($docblock);
     $method = new MethodGenerator();
     $method->setName('initRelation');
     $method->setFinal(true);
     $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PROTECTED);
     $body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
     $body .= "\$this->setRelation(\$relation); \n";
     $body .= "\$this->setupRelation();";
     $docblock = new DocBlockGenerator('Настройка связей');
     $method->setDocBlock($docblock);
     $method->setBody($body);
     //$file->getClass()->addPropertyFromGenerator($property);
     $file->getClass()->addMethodFromGenerator($method);
 }
Example #22
0
    /**
     * @param PartInterface $part
     */
    public function preRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        /**
         * @var $table \Model\Cluster\Schema\Table
         */
        $table = $part->getTable();
        //        $tableNameAsCamelCase = $table->getNameAsCamelCase();
        /** @var $columnList Column[]  */
        $columnList = $table->getColumn();
        foreach ($columnList as $column) {
            if ($column->getColumnType() != 'enum' || substr($column->getName(), 0, 3) == 'is_' || count($column->getEnumValuesAsArray()) < 1) {
                continue;
            }
            $columnName = $column->getName();
            foreach ($column->getEnumValuesAsArray() as $enumValue) {
                $shortDescr = 'Проверить на соответствие ' . $column->getTable()->getName() . '.' . $columnName . ' значению ' . $enumValue;
                $docblock = new \Zend\Code\Generator\DocBlockGenerator($shortDescr);
                $docblock->setTags(array(array('name' => 'return', 'description' => 'bool')));
                $method = new \Zend\Code\Generator\MethodGenerator();
                $method->setName('is' . $column->getNameAsCamelCase() . implode('', array_map('ucfirst', explode('_', $enumValue))));
                $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
                $method->setDocBlock($docblock);
                if ($part->hasPlugin('ConstantList', AbstractPart::PART_MODEL)) {
                    $modelName = $table->getNameAsCamelCase() . 'Model';
                    $file->addUse("\\Model\\{$modelName}");
                    $enumValue = $modelName . '::' . strtoupper($column->getName() . '_' . $enumValue);
                } else {
                    $enumValue = "'{$enumValue}'";
                }
                $method->setBody(<<<EOS
return \$this->get('{$columnName}') == {$enumValue};
EOS
);
                $part->getFile()->getClass()->addMethodFromGenerator($method);
            }
        }
        foreach ($columnList as $column) {
            if ($column->getColumnType() != 'enum' || substr($column->getName(), 0, 3) != 'is_' || count($column->getEnumValuesAsArray()) != 2) {
                continue;
            }
            $inc = 0;
            foreach ($column->getEnumValuesAsArray() as $enumValue) {
                if (in_array($enumValue, array('y', 'n'))) {
                    $inc++;
                }
            }
            if ($inc != 2) {
                continue;
            }
            $columnName = $column->getName();
            $shortDescr = 'Проверить флаг ' . $column->getTable()->getName() . '.' . $columnName;
            $docblock = new \Zend\Code\Generator\DocBlockGenerator($shortDescr);
            $docblock->setTags(array(array('name' => 'return', 'description' => 'bool')));
            $method = new \Zend\Code\Generator\MethodGenerator();
            $method->setName('is' . substr($column->getNameAsCamelCase(), 2));
            $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
            $method->setDocBlock($docblock);
            $method->setBody(<<<EOS
return \$this->get('{$columnName}') == 'y';
EOS
);
            $part->getFile()->getClass()->addMethodFromGenerator($method);
        }
    }
Example #23
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $file->addUse('Model\\Filter\\Filter');
        $columnCollection = $part->getTable()->getColumn();
        $template = '';
        /** @var $column Column */
        foreach ($columnCollection as $column) {
            $name = $column->getName();
            if ($columnConfig = $part->getColumntConfig($column)) {
                if ($columnConfig && isset($columnConfig['filters'])) {
                    foreach ($columnConfig['filters'] as $filter) {
                        $filterParams = isset($validator['params']) ? $this->varExportMin($validator['params'], true) : null;
                        if ($filterParams && $filterParams != 'NULL') {
                            $template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('{$filter['name']}', {$filterParams}));\n";
                        } else {
                            $template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('{$filter['name']}'));\n";
                        }
                    }
                }
            }
            /*
                        $filterArray = $column->getFilter();
            
                        foreach ($filterArray as $filter) {
                            if (empty($filter['params'])) {
                                $template .= "\$this->addFilterRule('$name', Filter::getFilterInstance('{$filter['name']}'));\n";
                            } else {
                                $filterParams = $this->varExportMin($filter['params'], true);
                                $template .= "\$this->addFilterRule('$name', Filter::getFilterInstance('{$filter['name']}', {$filterParams}));\n";
                            }
                        }
            */
            if ($column->isNullable()) {
                $template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('\\Model\\Filter\\Null'));\n";
            }
        }
        //$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
        $tags = array(array('name' => 'return', 'description' => 'array Model массив с фильтрами по полям'));
        $docblock = new DocBlockGenerator('Получить правила для фильтрации ');
        $docblock->setTags($tags);
        $method = new MethodGenerator();
        $method->setName('initFilterRules');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setStatic(false);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
{$template}
\$this->setupFilterRules();
return \$this->getFilterRules();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
Example #24
0
    /**
     * @param PartInterface $part
     */
    public function preRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        /**
         * @var $table \Model\Cluster\Schema\Table
         */
        $table = $part->getTable();
        $linkList = $table->getLink();
        foreach ($linkList as $link) {
            $foreignEntity = $link->getForeignEntity();
            $columnName = $link->getForeignColumn()->getName();
            $columnComment = $link->getForeignColumn()->getComment();
            switch ($link->getLinkType()) {
                case AbstractLink::LINK_TYPE_ONE_TO_MANY:
                case AbstractLink::LINK_TYPE_MANY_TO_MANY:
                    if ($columnComment) {
                        $shortDescr = "Получить список " . mb_strtolower($columnComment, 'UTF-8') . ' (' . $table->getName() . '.' . $columnName . ')';
                    } else {
                        $shortDescr = 'Получить список ' . $link->getForeignEntity();
                    }
                    $docblock = new \Zend\Code\Generator\DocBlockGenerator($shortDescr);
                    $docblock->setTags(array(array('name' => 'return', 'description' => '\\Model\\Collection\\' . $link->getForeignColumn()->getTable()->getNameAsCamelCase() . 'Collection')));
                    $method = new \Zend\Code\Generator\MethodGenerator();
                    $method->setName('get' . $link->getForeignEntityAsCamelCase() . 'Collection');
                    $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
                    $method->setDocBlock($docblock);
                    $method->setBody(<<<EOS
return \$this->get('_{$foreignEntity}_collection');
EOS
);
                    try {
                        $part->getFile()->getClass()->addMethodFromGenerator($method);
                    } catch (\Exception $e) {
                    }
                case AbstractLink::LINK_TYPE_ONE_TO_ONE:
                case AbstractLink::LINK_TYPE_MANY_TO_ONE:
                    if ($columnComment) {
                        $shortDescr = "Получить связанную сущность" . mb_strtolower($columnComment, 'UTF-8') . ' (' . $table->getName() . '.' . $columnName . ')';
                    } else {
                        $shortDescr = 'Получить связанную сущность ' . $link->getForeignEntity();
                    }
                    $docblock = new \Zend\Code\Generator\DocBlockGenerator($shortDescr);
                    $docblock->setTags(array(array('name' => 'return', 'description' => '\\Model\\Entity\\' . $link->getForeignColumn()->getTable()->getNameAsCamelCase() . 'Entity')));
                    $method = new \Zend\Code\Generator\MethodGenerator();
                    $method->setName('get' . $link->getForeignEntityAsCamelCase());
                    $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
                    $method->setDocBlock($docblock);
                    $method->setBody(<<<EOS
return \$this->get('_{$foreignEntity}');
EOS
);
                    try {
                        $part->getFile()->getClass()->addMethodFromGenerator($method);
                    } catch (\Exception $e) {
                    }
            }
        }
    }