public function testIgnoredAnnotationsAreNotUsed() { Addendum::ignore('FirstAnnotation', 'SecondAnnotation'); $reflection = new ReflectionAnnotatedClass('Example'); $this->assertFalse($reflection->hasAnnotation('FirstAnnotation')); $this->assertFalse($reflection->hasAnnotation('SecondAnnotation')); }
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()); } }
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; }
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; }
public function testSuccesfullyNestedAnnotationThrowsNoError() { $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass'); $reflection->getMethod('method2')->getAnnotation('MethodRestrictedAnnotation'); }
public function testAnnotationWithoutNamespaceShouldBeRecognized() { $reflection = new ReflectionAnnotatedClass('ClassAnnotatedWithNamespacedAnnotation'); $this->assertTrue($reflection->hasAnnotation('AnnotationWithNamespace')); }
public function testClassAndAnnotationInNamespaces() { $reflection = new ReflectionAnnotatedClass('Example\\Example'); $this->assertTrue($reflection->hasAnnotation('Example\\Annotation\\ExampleAnnotation')); }