Ejemplo n.º 1
0
 public function testIgnoredAnnotationsAreNotUsed()
 {
     Addendum::ignore('FirstAnnotation', 'SecondAnnotation');
     $reflection = new ReflectionAnnotatedClass('Example');
     $this->assertFalse($reflection->hasAnnotation('FirstAnnotation'));
     $this->assertFalse($reflection->hasAnnotation('SecondAnnotation'));
 }
Ejemplo n.º 2
0
 private function setTableName()
 {
     $classe = new ReflectionAnnotatedClass($this->type);
     if ($classe->hasAnnotation('Table') && $classe->getAnnotation('Table') != '') {
         $this->tableName = strtolower($classe->getAnnotation('Table')->value);
     } else {
         $this->tableName = strtolower($classe->getShortName());
     }
 }
Ejemplo n.º 3
0
 public function accept($chain, $controller, $method, $args, $request, $controller_ret = null)
 {
     if (isset($this->method)) {
         return true;
     }
     $re = new ReflectionAnnotatedClass(get_class($controller));
     $this->method = $re->getMethod($method);
     if ($this->method->hasAnnotation('Clips\\Rules')) {
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 private function checkTargetConstraints($target)
 {
     $reflection = new ReflectionAnnotatedClass($this);
     if ($reflection->hasAnnotation('Target')) {
         $value = $reflection->getAnnotation('Target')->value;
         $values = is_array($value) ? $value : array($value);
         foreach ($values as $value) {
             if ($value == 'class' && $target instanceof ReflectionClass) {
                 return;
             }
             if ($value == 'method' && $target instanceof ReflectionMethod) {
                 return;
             }
             if ($value == 'property' && $target instanceof ReflectionProperty) {
                 return;
             }
         }
         trigger_error("Annotation '" . get_class($this) . "' not allowed on " . $this->createName($target), E_USER_ERROR);
     }
 }
 /**
  * {@inheritDoc}
  */
 public final function scriptCreation($entity, $generateDropStatement = false)
 {
     $classe = new ReflectionAnnotatedClass($entity);
     if (!$classe->hasAnnotation('Table') && $classe->getAnnotation('Table') != '') {
         $this->tableName = strtolower($classe->getAnnotation('Table')->value);
     } else {
         $this->tableName = strtolower($classe->getShortName());
     }
     $tabela = $this->tableName;
     $propriedades = $classe->getProperties();
     //TODO Refactor me
     foreach ($propriedades as $propriedade) {
         if ($propriedade->hasAnnotation('Column')) {
             $getter = $propriedade->name;
             $key = $propriedade->getAnnotation('Column')->name;
             $params = (array) $propriedade->getAnnotation('Column');
             foreach ($params as $chave => $valor) {
                 $fields[$key][$chave] = $valor;
             }
         }
         if ($propriedade->hasAnnotation('Join')) {
             $params = (array) $propriedade->getAnnotation('Join');
             foreach ($params as $chave => $valor) {
                 $fields[$key][$chave] = $valor;
             }
         }
     }
     $script = '';
     if ($generateDropStatement == true) {
         $script .= "DROP TABLE IF EXISTS " . SCHEMA . $tabela . "; \n";
     }
     $script .= "CREATE TABLE " . SCHEMA . $tabela . " ( \n";
     $uid;
     // TODO extract to method
     foreach ($fields as $key => $value) {
         $fk;
         if (isset($value['joinTable'])) {
             $fk = "\tCONSTRAINT " . $tabela . "_" . $value['joinTable'] . "_fk FOREIGN KEY({$key})\n";
             $fk .= "\t\tREFERENCES " . SCHEMA . $value['joinTable'] . "({$value['joinColumn']}) MATCH SIMPLE\n";
             $fk .= "\t\tON UPDATE NO ACTION ON DELETE NO ACTION,\n";
             $script .= "\t" . $key . " integer, \n";
         } else {
             if ($key == 'uid') {
                 $script .= "\t" . $key . " serial NOT NULL, \n";
                 $uid = $key;
             } else {
                 // TODO Refactor to automatically detect the property's type
                 $script .= "\t" . $key . " " . ($value['type'] == 'integer' ? 'integer' : ($value['type'] == 'timestamp' ? 'timestamp' : 'character varying')) . ", \n";
             }
         }
     }
     $script .= @$fk;
     $script .= "\tCONSTRAINT " . $tabela . "_pk PRIMARY KEY (" . $uid . ") \n";
     $script .= " );";
     return $script;
 }
Ejemplo n.º 6
0
 public function testSuccesfullyNestedAnnotationThrowsNoError()
 {
     $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
     $reflection->getMethod('method2')->getAnnotation('MethodRestrictedAnnotation');
 }
Ejemplo n.º 7
0
 public function testAnnotationWithoutNamespaceShouldBeRecognized()
 {
     $reflection = new ReflectionAnnotatedClass('ClassAnnotatedWithNamespacedAnnotation');
     $this->assertTrue($reflection->hasAnnotation('AnnotationWithNamespace'));
 }
Ejemplo n.º 8
0
 public function testClassAndAnnotationInNamespaces()
 {
     $reflection = new ReflectionAnnotatedClass('Example\\Example');
     $this->assertTrue($reflection->hasAnnotation('Example\\Annotation\\ExampleAnnotation'));
 }