private function initFieldsAndPks($class) { $field_objects = []; $pks = []; $generators = []; $comment = new \PhpComment\Comment($class); $tags = $comment->getAttributeTags(); foreach ($tags as $p => $t) { /* @var $t Tags */ if ($field_values = $t->get('field')) { $field_objects[$p] = $this->getFieldByTagVaule($field_values[0]); if ($t->get('primary')) { $pks[] = $p; } if ($generator_value = $t->get('generator')) { $generator_info = $this->parseTagValueAndParameters($generator_value[0]); $generator_class_name = '\\Hitar\\Id\\' . ucfirst($generator_info['value']) . 'Generator'; $generators[$p] = new $generator_class_name($generator_info['parameters']); } } } $this->fields = $field_objects; $this->primary_keys = $pks; $this->generators = $generators; }
function testComment() { $obj = new ClassWithComment(); $comment = new \PhpComment\Comment($obj); $prop_tags = $comment->getAttributeTags(); $this->assertArrayHasKey('prop1', $prop_tags); $this->assertEquals(["var" => ["string"]], $prop_tags['prop1']->get()); $func_tags = $comment->getMethodTags(); $this->assertArrayHasKey('func1', $func_tags); $this->assertEquals(['return' => ['boolean']], $func_tags['func1']->get()); $class_tag = $comment->getClassTag(); $this->assertEquals(['author' => ['kasonyang']], $class_tag->get()); }