Пример #1
0
 /**
  * Get Symfony validator contraints
  * @return string
  */
 private function getSymfonyValidatorConstraints()
 {
     $constraints = array();
     $this->loadUnsettableProperties();
     foreach ($this->dataTypes as $column => $type) {
         // skip inherited columns
         if ($type->isInherited()) {
             continue;
         }
         // Skip Columns designated unsetable.
         if (in_array($column, $this->unsetableProperties)) {
             continue;
         }
         // Check if column is nullable.
         if (!$type->isNullable() and !$type->hasDefault()) {
             $constraints[] = $this->getSymfonyConstraint($column, 'NotNull');
         }
         // Normality entity type constraints.
         if ($type->getEntity() === 'normality') {
             $dataType = $this->options['entityPlaceholder'] . "\\{$type->getNormality()}";
             $constraints[] = $this->getSymfonyTypeConstraint($column, $dataType);
         } elseif ($type->getEntity()) {
             $dataType = "Bond\\Entity\\Types\\{$type->getEntity()}";
             $constraints[] = $this->getSymfonyTypeConstraint($column, $dataType);
         } elseif ($type->isEnum($enumName)) {
             $constraints[] = $this->getSymfonyChoiceConstraint($column, $this->pgClass->getCatalog()->enum->getValues($enumName));
         } else {
             switch ($type->getType()) {
                 case 'int':
                     $constraints[] = $this->getSymfonyConstraint($column, 'RealInt', null, false);
                     $this->class->addUses('Bond\\Bridge\\Normality\\Constraint\\RealInt');
                     break;
                 case 'citext':
                 case 'text':
                     $constraints[] = $this->getSymfonyTypeConstraint($column, 'string');
                     if (is_numeric($type->getLength())) {
                         $constraints[] = $this->getSymfonyConstraint($column, 'MaxLength', $type->getLength());
                     }
                     break;
                 case 'bool':
                     $constraints[] = $this->getSymfonyTypeConstraint($column, 'bool');
                     break;
             }
         }
         $constraints[] = '';
     }
     return implode("\n", $constraints);
 }
Пример #2
0
 /**
  * Generate a array of DataTypes from a Bond\Pg\Catalog\PgClass object
  * @param Bond\Pg\Catalog\PgRelation $relation
  * @return array
  */
 public static function makeFromRelation(PgClass $relation)
 {
     $output = array();
     foreach ($relation->getAttributes() as $attribute) {
         $dataType = static::makeFromAttribute($attribute);
         $output[$dataType->name] = $dataType;
     }
     return $output;
 }
Пример #3
0
 public function buildRelation(PgClass $relation)
 {
     $name = $relation->getEntityName();
     /// logging
     $this->callbacks['log']("{$name} ", false);
     $this->profiler->log($name);
     // construct generators
     if ($relation->isInherited()) {
         $entityBuilderClass = EntityChild::class;
     } else {
         $entityBuilderClass = Entity::class;
     }
     $entityG = new $entityBuilderClass($relation, $this->options->namespaces, $this->options->getPath('entityFileStore'));
     $entityPlaceholderG = new EntityPlaceholder($entityG, $this->options->getNamespace('entityPlaceholder'));
     $repositoryG = new RepositoryG($entityG, $this->options->getNamespace('repository'));
     $repositoryPlaceholderG = new RepositoryPlaceholder($repositoryG, $this->options->getNamespace('repositoryPlaceholder'));
     $this->generate($entityG, true);
     $this->generate($entityPlaceholderG, $this->options->regenerateEntityPlaceholders);
     $this->generate($repositoryG, true);
     $this->generate($repositoryPlaceholderG, $this->options->regenerateRepositoryPlaceholders);
     // register freshly generated entity with Repository
     $namespaces = $this->options->namespaces;
     if ($this->entityManager) {
         $this->entityManager->register($entityPlaceholderG->class->class, $repositoryPlaceholderG->class->class);
     }
     $this->callbacks['log']('');
     return $name;
 }
Пример #4
0
 /**
  * Does the passed relation pass our test
  */
 public function __invoke(PgClass $relation)
 {
     $tags = $relation->getTags();
     $match = isset($tags['match']) ? $tags['match'] : $relation->name;
     return (bool) preg_match($this->regex, $match);
 }