/** * Creates a new reflection class instance from the passed PHP reflection class. * * @param \ReflectionClass $reflectionClass The PHP reflection class to load the data from * @param array $annotationsToIgnore An array with annotations names we want to ignore when loaded * @param array $annotationAliases An array with annotation aliases used when create annotation instances * * @return \AppserverIo\Lang\Reflection\ReflectionClass The instance */ public static function fromPhpReflectionClass(\ReflectionClass $reflectionClass, array $annotationsToIgnore = array(), array $annotationAliases = array()) { // initialize the array with the annotations we want to ignore $annotationsToIgnore = array_merge($annotationsToIgnore, array('author', 'package', 'license', 'copyright', 'param', 'return', 'throws', 'see', 'link')); // initialize the array with the aliases for the enterprise bean annotations $annotationAliases = array_merge(array(PersistenceUnit::ANNOTATION => PersistenceUnit::__getClass(), MessageDriven::ANNOTATION => MessageDriven::__getClass(), PostConstruct::ANNOTATION => PostConstruct::__getClass(), PreDestroy::ANNOTATION => PreDestroy::__getClass(), PostDetach::ANNOTATION => PostDetach::__getClass(), PreAttach::ANNOTATION => PreAttach::__getClass(), Schedule::ANNOTATION => Schedule::__getClass(), Singleton::ANNOTATION => Singleton::__getClass(), Startup::ANNOTATION => Startup::__getClass(), Stateful::ANNOTATION => Stateful::__getClass(), Stateless::ANNOTATION => Stateless::__getClass(), Timeout::ANNOTATION => Timeout::__getClass(), EnterpriseBean::ANNOTATION => EnterpriseBean::__getClass(), Resource::ANNOTATION => Resource::__getClass())); // create a new timed object instance return new TimedObject($reflectionClass->getName(), $annotationsToIgnore, $annotationAliases); }
/** * Tests that initialization from a reflection class works as expected. * * @return void */ public function testFromReflectionClass() { // initialize the annotation aliases $aliases = array(Stateful::ANNOTATION => Stateful::__getClass(), PreAttach::ANNOTATION => PreAttach::__getClass(), PostDetach::ANNOTATION => PostDetach::__getClass(), PostActivate::ANNOTATION => PostActivate::__getClass(), PrePassivate::ANNOTATION => PrePassivate::__getClass()); // create the reflection class $reflectionClass = new ReflectionClass(__CLASS__, array(), $aliases); // check that the descriptor has been initialized $this->assertSame($this->descriptor, $this->descriptor->fromReflectionClass($reflectionClass)); $this->assertSame('StatefulSessionBeanDescriptorTest', $this->descriptor->getName()); $this->assertSame('AppserverIo\\Description\\StatefulSessionBeanDescriptorTest', $this->descriptor->getClassName()); $this->assertCount(0, $this->descriptor->getEpbReferences()); $this->assertCount(0, $this->descriptor->getResReferences()); $this->assertCount(0, $this->descriptor->getReferences()); $this->assertCount(1, $this->descriptor->getPreAttachCallbacks()); $this->assertCount(1, $this->descriptor->getPostDetachCallbacks()); $this->assertCount(1, $this->descriptor->getPostActivateCallbacks()); $this->assertCount(1, $this->descriptor->getPrePassivateCallbacks()); }
/** * Returns a reflection class instance for the passed class name. * * @param string $className The class name to return the reflection instance for * * @return \AppserverIo\Lang\Reflection\ReflectionClass The reflection instance */ public function newReflectionClass($className) { // initialize the array with the annotations we want to ignore $annotationsToIgnore = array('author', 'package', 'license', 'copyright', 'param', 'return', 'throws', 'see', 'link'); // initialize the array with the aliases for the enterprise bean annotations $annotationAliases = array(Route::ANNOTATION => Route::__getClass(), Resource::ANNOTATION => Resource::__getClass(), Timeout::ANNOTATION => Timeout::__getClass(), Stateless::ANNOTATION => Stateless::__getClass(), Stateful::ANNOTATION => Stateful::__getClass(), Startup::ANNOTATION => Startup::__getClass(), Singleton::ANNOTATION => Singleton::__getClass(), Schedule::ANNOTATION => Schedule::__getClass(), PreAttach::ANNOTATION => PreAttach::__getClass(), PostDetach::ANNOTATION => PostDetach::__getClass(), PreDestroy::ANNOTATION => PreDestroy::__getClass(), PostConstruct::ANNOTATION => PostConstruct::__getClass(), MessageDriven::ANNOTATION => MessageDriven::__getClass(), EnterpriseBean::ANNOTATION => EnterpriseBean::__getClass(), PersistenceUnit::ANNOTATION => PersistenceUnit::__getClass()); // return the reflection class instance return new ReflectionClass($className, $annotationsToIgnore, $annotationAliases); }