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'); }
/** * 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}"); }