public static function getAnnotationMember($class, $member, $annotation) { $rap = new \ReflectionAnnotatedProperty($class, $member); if ($rap != null) { $annot = $rap->getAnnotation($annotation); } return $annot; }
public function findPks($className) { $reflection = new ReflectionAnnotatedClass($className); // by class name $properties = $reflection->getProperties(); $atributes_column = array(); if (count($properties) > 0) { foreach ($properties as $key => $property) { $reflectionAnotatedProperty = new ReflectionAnnotatedProperty($className, $property->getName()); $Key = $reflectionAnotatedProperty->getAnnotation('Column')->Key; if (strlen($Key) > 0 && $Key == "PRI") { $atributes_column[] = (string) $reflectionAnotatedProperty->getAnnotation('Column')->Field; } } } if (count($atributes_column) > 0) { return $atributes_column; } throw new Exception('La clase ' . $className . " no tiene definidas llaves"); }
public function testReflectionAnnotatedProperty() { $reflection = new ReflectionAnnotatedProperty('Example', 'exampleProperty'); $this->assertTrue($reflection->hasAnnotation('SecondAnnotation')); $this->assertFalse($reflection->hasAnnotation('FirstAnnotation')); $this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation'); $this->assertFalse($reflection->getAnnotation('NonExistentAnnotation')); $annotations = $reflection->getAnnotations(); $this->assertEqual(count($annotations), 1); $this->assertIsA($annotations[0], 'SecondAnnotation'); $this->assertIsA($reflection->getDeclaringClass(), 'ReflectionAnnotatedClass'); }
private static function isTransient(\ReflectionAnnotatedProperty $property) { $annotations = $property->getAllAnnotations(); foreach ($annotations as $annotation) { return is_subclass_of($annotation, "Transient") || get_class($annotation) == "Transient"; } }
protected function doProperty(BeanDefinition $bean, \ReflectionAnnotatedProperty $property) { $listAnnotation = $property->getAllAnnotations(); foreach ($listAnnotation as $annotation) { if ($annotation instanceof annotations\PropertyAnnotation) { $annotation->doVariableProperty($bean, $property->name); } } }
/** * Saves the current node object. Creates a new Drupal node in the database if * one does not already exist. * * @access public * @return void */ public function save() { ## ## Create or retrieve raw node object to edit $editNode = $this->nid && $this->raw_node ? $this->raw_node : new stdClass(); if (!isset($editNode->type) || $editNode->type != $this->machine_name) { $editNode->type = $this->machine_name; } ## ## Set all annotated properties foreach (array_keys(get_object_vars($this)) as $property) { $reflectedProperty = new ReflectionAnnotatedProperty(get_class($this), $property); if ($reflectedProperty->hasAnnotation('NodeProperties')) { $nodeProperties = $reflectedProperty->getAnnotation('NodeProperties'); self::set($editNode->{$nodeProperties->name}, $nodeProperties->property_type, $nodeProperties->cardinality, $this->{$property}); } } ## ## Set node defaults $editNode->title = $this->title; $editNode->language = isset($editNode->language) && strlen($editNode->language) ? $editNode->language : 'und'; ## ## Set node body $editNode->body['und'][0]['value'] = $this->body; $editNode->body['und'][0]['summary'] = text_summary($this->body, NULL, 100); $editNode->body['und'][0]['format'] = 'full_html'; ## ## Save to DB node_object_prepare($editNode); node_save($editNode); ## ## Set nid and raw node, in the event that this is a newly created node $this->nid = $editNode->nid; $this->raw_node = node_load($this->nid); $this->uri = '/' . drupal_get_path_alias("node/{$this->nid}"); }