public function testFieldIsNullable()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     // Explicit Nullable
     $cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50));
     $this->assertTrue($cm->isNullable('status'));
     // Explicit Not Nullable
     $cm->mapField(array('fieldName' => 'username', 'nullable' => false, 'type' => 'string', 'length' => 50));
     $this->assertFalse($cm->isNullable('username'));
     // Implicit Not Nullable
     $cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50));
     $this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable.");
 }
 public function testFieldIsNullable()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     // Explicit Nullable
     $cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50));
     $this->assertTrue($cm->isNullable('status'));
     // Explicit Not Nullable
     $cm->mapField(array('fieldName' => 'username', 'nullable' => false, 'type' => 'string', 'length' => 50));
     $this->assertFalse($cm->isNullable('username'));
     // Implicit Not Nullable
     $cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50));
     $this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable.");
 }
Beispiel #3
0
 public function __construct(\Symforce\AdminBundle\Compiler\Generator\AnnotationCache $cache, $bundle_name, ClassMetadata $meta, Generator $gen)
 {
     $this->cache = $cache;
     $this->bundle_name = $bundle_name;
     $this->class_name = $cache->class_name;
     $this->reflection = $meta->getReflectionClass();
     $this->generator = $gen;
     $this->orm_metadata = $meta;
     if ($meta->isIdentifierComposite) {
         // @TODO add Composite route handle
     } else {
         $this->property_id_name = $meta->getSingleIdentifierFieldName();
     }
     $this->setMyPropertie($cache->class_annotations['Symforce\\AdminBundle\\Compiler\\Annotation\\Entity']);
     if (!$this->name) {
         $this->name = strtolower(preg_replace('/\\W/', '_', $this->class_name));
     }
     $this->template = $this->name . '.admin.html.twig';
     $this->_template_path = $this->generator->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template;
     if (null === $this->_final_template) {
         $tempalte = $this->bundle_name . ':' . basename(str_replace('\\', '\\/', $this->class_name)) . ':admin.macro.html.twig';
         try {
             $this->generator->loadTwigTemplatePath($tempalte);
             $this->_final_template = $tempalte;
         } catch (\InvalidArgumentException $e) {
         }
     }
     $compile_class_name = ucfirst($this->camelize($this->name));
     $this->_compile_class_name = 'Symforce\\AdminCache\\' . $compile_class_name . '\\Admin' . $compile_class_name;
     if (null === $this->tr_domain) {
         $this->tr_domain = $this->bundle_name;
     }
     $this->sf_domain = $gen->getSymforceDomain();
     if (isset($cache->class_annotations[self::ANNOT_TREE_CLASS])) {
         // not work for yml/xml,  because the private stof_doctrine_extensions.listener.tree service
         $tree_annot_len = strlen(self::ANNOT_TREE_CLASS);
         $this->tree = array();
         foreach ($cache->propertie_annotations as $property_name => $as) {
             foreach ($as as $annot_class => &$value) {
                 if (0 === strpos($annot_class, self::ANNOT_TREE_CLASS)) {
                     $tree_config_key = strtolower(substr($annot_class, $tree_annot_len));
                     $this->tree[$tree_config_key] = $property_name;
                 }
             }
         }
         if (!isset($this->tree['parent'])) {
             $this->throwError("missing @%sParent", self::ANNOT_TREE_CLASS);
         }
         if (!isset($this->tree['root'])) {
             $this->throwError("missing @%sRoot", self::ANNOT_TREE_CLASS);
         }
     }
     if (isset($cache->class_annotations[self::ANNOT_TOSTR_CLASS])) {
         \Dev::dump($cache->class_annotations[self::ANNOT_TOSTR_CLASS]);
         exit;
     }
     if (isset($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS])) {
         \Dev::dump($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS]);
         exit;
     }
     foreach ($cache->propertie_annotations as $property_name => $as) {
         if (isset($as[self::ANNOT_SLUG_CLASS])) {
             if ($this->property_slug_name) {
                 $this->throwError("slug property duplicate(%s, %s)", $this->property_slug_name, $property_name);
             }
             $this->property_slug_name = $property_name;
             $this->property_slug_unique = $meta->isUniqueField($property_name);
             $this->property_slug_nullable = $meta->isNullable($property_name);
         }
         if (isset($as[self::ANNOT_TOSTR_CLASS])) {
             if ($this->property_value_name) {
                 $this->throwError("@ToString(%s) is conflict with @ToString(%s)", $property_name, $this->property_value_name);
             }
             $this->property_value_name = $property_name;
         }
         if (isset($as[self::ANNOT_TREE_LEAF_CLASS])) {
             if (!$this->tree) {
                 $this->throwError("use @%s(%s) without @%s", self::ANNOT_TREE_LEAF_CLASS, $property_name, self::ANNOT_TREE_CLASS);
             }
             if (isset($this->tree['leaf'])) {
                 $this->throwError("@ToString(%s) is conflict with %s", self::ANNOT_TREE_LEAF_CLASS, $property_name, $this->tree['leaf']);
             }
             $this->tree['leaf'] = $property_name;
         }
         if (isset($as[Page::PAGE_ANNOT_CLASS])) {
             if ($this->page) {
                 $this->throwError("page property duplicate(%s, %s)", $this->page->pege_property, $property_name);
             }
             $this->page = new Page($this, $property_name, $as[Page::PAGE_ANNOT_CLASS]);
         }
         if (isset($as[Owner::OWNER_ANNOT_CLASS])) {
             if ($this->owner) {
                 $this->throwError("owner property duplicate(%s, %s)", $this->owner->owner_property, $property_name);
             }
             $this->owner = new Owner($this, $property_name, $as[Owner::OWNER_ANNOT_CLASS]);
         }
     }
     if (isset($cache->class_annotations[self::ANNOT_WORKFLOW_CLASS])) {
         $this->workflow = new Workflow($this, $cache->class_annotations[self::ANNOT_WORKFLOW_CLASS]);
     }
     if (!$this->form) {
         $this->form = new Form($this);
     }
     $this->form->bootstrap();
     $this->action_collection = new ActionCollection($this);
     $this->_route_assoc = new RouteAssoc($this);
     if (null !== $this->position) {
         if ($this->dashboard && null === $this->dashboard->position) {
             $this->dashboard->position = $this->position;
         }
         if ($this->menu && null === $this->menu->position) {
             $this->menu->position = $this->position;
         }
     }
 }
Beispiel #4
0
 private function determineFromColumns(ClassMetadata $classMetadata)
 {
     $out = [];
     /** @var Column $column */
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = [];
         try {
             $fieldMapping = $classMetadata->getFieldMapping($fieldName);
         } catch (MappingException $e) {
             $fieldMapping['type'] = 'undefined';
         }
         $columnName = $classMetadata->getColumnName($fieldName);
         $type = $classMetadata->getTypeOfField($fieldName);
         $isNullable = $classMetadata->isNullable($fieldName);
         if (strtolower($type) === 'enum') {
             $out[$columnName] = ['type' => IColumnStructure::ENUM];
             $enum = $fieldMapping['columnDefinition'];
             $options = str_getcsv(str_replace('enum(', '', substr($enum, 0, strlen($enum) - 1)), ',', "'");
             $out[$columnName]['values'] = [];
             foreach ($options as $option) {
                 $out[$columnName]['values'][] = $option;
             }
         } else {
             switch ($type) {
                 case Type::STRING:
                 case Type::TEXT:
                     $out[$columnName] = ['type' => IColumnStructure::TEXT];
                     break;
                 case Type::INTEGER:
                 case Type::FLOAT:
                 case Type::SMALLINT:
                 case Type::BIGINT:
                 case Type::DECIMAL:
                     $out[$columnName] = ['type' => IColumnStructure::NUMBER];
                     break;
                 case Type::DATETIME:
                 case Type::DATETIMETZ:
                 case Type::DATE:
                 case Type::TIME:
                     $out[$columnName] = ['type' => IColumnStructure::DATE];
                     break;
                 case Type::BOOLEAN:
                     $out[$columnName] = ['type' => IColumnStructure::BOOL];
                     break;
             }
         }
         if (isset($out[$columnName])) {
             $out[$columnName]['nullable'] = $isNullable;
         }
     }
     return $out;
 }