示例#1
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     AnnotationRegistry::registerFile(dirname($this->getRoot()->getRootPath()) . '/vendor/pop-code/framework/src/Form/FormType.php');
     $ann = new IndexedReader(new SimpleAnnotationReader());
     $ann->addNamespace('PopCode\\Framework\\Form');
     $this->set('services.annotation_reader', $ann);
     FormFactory::setAnnotationReader($this->get('services.annotation_reader'));
     FormFactory::registerMapping('form', 'PopCode\\Framework\\Form\\Form');
     FormFactory::registerMapping('text', 'PopCode\\Framework\\Form\\TextForm');
     FormFactory::registerMapping('hidden', 'PopCode\\Framework\\Form\\HiddenForm');
     FormFactory::registerMapping('textarea', 'PopCode\\Framework\\Form\\TextareaForm');
     FormFactory::registerMapping('select', 'PopCode\\Framework\\Form\\SelectForm');
     FormFactory::registerMapping('radio', 'PopCode\\Framework\\Form\\SelectForm');
     FormFactory::registerMapping('checkbox', 'PopCode\\Framework\\Form\\SelectForm');
 }
示例#2
0
 /**
  * 
  * @param string $className
  * @param ReflectionProperty|string $property
  * @return \PopCode\Framework\Form\FormType
  */
 public static function getFormType($className, $property)
 {
     if (!$property instanceof ReflectionProperty) {
         $property = new ReflectionProperty($className, $property);
     }
     //read the form type from annotation
     $formType = static::$annotationReader->getPropertyAnnotation($property, 'PopCode\\Framework\\Form\\FormType');
     //override formType from model method
     $reflection = new ReflectionClass($className);
     if ($reflection->implementsInterface('PopCode\\Framework\\Model\\FormConfigInterface')) {
         $reflection->getMethod('getFormType')->invoke(new $className(), $property->getName(), $formType);
     }
     if (!$formType) {
         return;
     }
     //Auto group ?
     if ($formType->getGroup() !== false) {
         $formType->setGroup(true);
     }
     //Auto label ?
     if ($formType->getLabel() === null) {
         //translate label here ?
         $formType->setLabel(Helper::stringToLabel($property->getName()));
     }
     //themings @todo moove this part with template render
     $formType->setLabelAttrs(array('class' => 'control-label'));
     //merge the attrs with predefined data to get the form-control class
     if ($formType->getType() !== 'radio' && $formType->getType() !== 'checkbox') {
         $attrs = $formType->getAttrs();
         $formType->setAttrs(array_merge(array('class' => 'form-control'), $attrs));
     }
     if ($formType->getType() != 'radio' && $formType->getType() != 'checkbox') {
         $attrs = $formType->getAttrs();
         $formType->setAttrs(array_merge(array('class' => 'form-control'), $attrs));
     }
     //set the classes on container to form-group
     $classes = $formType->getClasses();
     $classes = trim(preg_replace('/form-group/', '', $classes) . ' form-group');
     $formType->setClasses($classes);
     return $formType;
 }
 /**
  * @group DCOM-4
  */
 public function testNamespaceAliasAnnotationWithSeparator()
 {
     $reader = new IndexedReader(new AnnotationReader(new \Doctrine\Common\Cache\ArrayCache()));
     $reader->setAnnotationNamespaceAlias('Doctrine\\Tests\\Common\\', 'alias');
     $reflClass = new ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\Regression\\AliasNamespace');
     $result = $reader->getPropertyAnnotations($reflClass->getProperty('foo'));
     $this->assertEquals(1, count($result));
     $annot = $result['Doctrine\\Tests\\Common\\Annotations\\Name'];
     $this->assertTrue($annot instanceof \Doctrine\Tests\Common\Annotations\Name);
     // no use!
     $this->assertEquals('bar', $annot->foo);
 }
示例#4
0
 /**
  * Função genérica que lerá as annotations da classe e verificará
  * coisas como tipo do dado, comprimento, qtd de itens na collection, etc
  *
  * @ORM\PreFlush()
  */
 public function isValid()
 {
     $reflx = new \ReflectionClass($this);
     $reader = new IndexedReader(new AnnotationReader());
     $props = $reflx->getProperties();
     //$annotations = $reader->getClassAnnotation($reflx);
     foreach ($props as $prop) {
         $annons = $reader->getPropertyAnnotations($prop);
         //var_dump($annons);
         $attr = $prop->getName();
         $method = 'get' . ucfirst($attr);
         if (!strstr($attr, '__') && $attr != 'lazyPropertiesDefaults' && $attr != 'id' && (method_exists($this, $method) && is_object($this->{$method}()) && $this->{$method}() instanceof \SanSIS\BizlayBundle\Entity\AbstractEntity && is_object($this->__parent) && $this->{$method}() !== $this->__parent)) {
             if ((isset($annons['Doctrine\\ORM\\Mapping\\ManyToOne']) || isset($annons['Doctrine\\ORM\\Mapping\\OneToOne'])) && is_object($this->{$method}())) {
                 $this->{$method}()->setParent($this);
                 $this->{$method}()->isValid($this);
             } else {
                 if (isset($annons['Doctrine\\ORM\\Mapping\\ManyToMany']) || isset($annons['Doctrine\\ORM\\Mapping\\OneToMany'])) {
                     foreach ($this->{$method}() as $obj) {
                         if (is_object($obj)) {
                             $obj->setParent($this);
                             $obj->isValid($this);
                         }
                     }
                 } else {
                     if (isset($annons['Doctrine\\ORM\\Mapping\\Column'])) {
                         $this->checkType($attr, $annons['Doctrine\\ORM\\Mapping\\Column']->type, $annons['Doctrine\\ORM\\Mapping\\Column']->nullable);
                         $this->checkMaxSize($attr, $annons['Doctrine\\ORM\\Mapping\\Column']->length);
                         $this->checkNullable($attr, $annons['Doctrine\\ORM\\Mapping\\Column']->nullable);
                     }
                 }
             }
         }
     }
     if ($this->__parent != $this && $this->hasErrors()) {
         throw new ValidationException($this->getErrors());
     }
     if ($this->hasErrors()) {
         throw new ValidationException($this->getErrors());
     }
 }
 /**
  * Verifica atributos unique em registros ativos
  *
  * @param  ServiceDto $dto [description]
  * @return null          [description]
  */
 public function checkUnique(ServiceDto $dto, AbstractEntity $entity)
 {
     $reflx = new \ReflectionClass($this->getEntityName());
     $reader = new IndexedReader(new AnnotationReader());
     $props = $reflx->getProperties();
     foreach ($props as $prop) {
         $annons = $reader->getPropertyAnnotations($prop);
         if ($prop->getName() != 'id' && isset($annons['Doctrine\\ORM\\Mapping\\Column']->unique) && $annons['Doctrine\\ORM\\Mapping\\Column']->unique) {
             $pt = $annons['Doctrine\\ORM\\Mapping\\Column']->type;
             $getMethod = 'get' . ucfirst($prop->getName());
             $uniqueParam = $entity->{$getMethod}();
             //verificar e adicionar o erro
             $qb = $this->createQueryBuilder('u');
             $qb->select('u.id')->andWhere($qb->expr()->eq($this->ci('u.' . $prop->getName(), $pt), $this->ci(':param', $pt)))->setParameter('param', $uniqueParam);
             $id = $entity->getId();
             if (is_null($id)) {
                 $qb->andWhere($qb->expr()->isNotNull('u.id'));
             } else {
                 $qb->andWhere($qb->expr()->neq('u.id', ':id'))->setParameter('id', $id);
             }
             $query = $qb->getQuery();
             $boolAttr = $reflx->hasProperty('isActive') ? 'isActive' : ($reflx->hasProperty('flActive') ? 'flActive' : false);
             if ($boolAttr) {
                 $query->setDQL($query->getDQL() . ' and u.' . $boolAttr . ' = :boolFlag');
                 $query->setParameter('boolFlag', true);
             }
             if ($reflx->hasProperty('statusTuple')) {
                 $query->setDQL($query->getDQL() . ' and u.statusTuple <> 0 ');
             }
             if (count($query->getScalarResult())) {
                 $this->addError('verificação', 'Já existe o valor informado para ' . $prop->getName() . '.', 'Repository', get_class($entity), $prop->getName());
             }
         }
     }
 }