public function fromClass($class, $dir = '') { $classInfo = new RecessReflectionClass($class); $this->docComment = $classInfo->getDocComment(); $this->file = $classInfo->getFileName(); $package = Library::getPackage($class); if ($dir != '') { if (strpos($dir, '/' . str_replace('.', '/', $package)) !== 0) { throw new RecessException('The class: ' . $class . ' has been imported incorectly with ' . $package . '.' . $class . '. The real location is: ' . $dir, get_defined_vars()); } } if ($package != '') { $packageReflector = new RecessReflectorPackage(); $packageReflector->name = $package; if ($packageReflector->exists()) { $this->setPackage($packageReflector); } else { $packageReflector->insert(); $this->setPackage($packageReflector); } } $this->save(); $parent = $classInfo->getParentClass(); if ($parent != null) { $parentReflectorClass = new RecessReflectorClass(); $parentReflectorClass->name = $parent->name; $exists = $parentReflectorClass->find()->first(); if (!$exists) { $parentReflectorClass->fromClass($parent->name); $this->setParent($parentReflectorClass); } else { $this->setParent($exists); } } }
/** * Call all other methods on this class registered to be called after * the wrapped method has returned. * * @param $object * @param $returnValue * @return mixed Should be of the same type as the wrapped method returns. */ function after($object, $returnValue) { $reflectedClass = new RecessReflectionClass($object); foreach ($this->callAfter as $method) { $reflectedMethod = $reflectedClass->getMethod($method); $result = $reflectedMethod->invoke($object, $returnValue); if ($result !== null) { $returnValue = $result; } } return $returnValue; }
/** !Route GET, class/$class */ public function classInfo($class) { $this->checkTables(); $result = $this->indexClass($class, ''); if ($result === false) { return new NotFoundResponse($this->request); } $this->reflector = $result; $className = Library::getClassName($class); $reflection = new RecessReflectionClass($className); $this->reflection = $reflection; $this->className = $className; if ($reflection->isSubclassOf('Model')) { $this->relationships = Model::getRelationships($className); $this->columns = Model::getColumns($className); $this->table = Model::tableFor($className); $this->source = Model::sourceNameFor($className); } }
function testInvalidAnnotationValue() { $reflection = new RecessReflectionClass('InvalidAnnotationValue'); try { $annotations = $reflection->getAnnotations(); $this->fail('Should throw an InvalidAnnotationValueException.'); } catch (InvalidAnnotationValueException $e) { // Pass } }
/** * Builds a class' metadata structure (Class Descriptor through reflection * and expansion of annotations. Hooks are provided in a Strategy Pattern-like * fashion to allow subclasses to influence various points in the pipeline of * building a class descriptor (initialization, discovery of method, discovery of * property, finalization). * * @param $class Name of class whose descriptor is being built. * @return ClassDescriptor */ protected static function buildClassDescriptor($class) { $descriptor = call_user_func(array($class, 'initClassDescriptor'), $class); try { $reflection = new RecessReflectionClass($class); } catch (ReflectionException $e) { throw new RecessException('Class "' . $class . '" has not been declared.', get_defined_vars()); } foreach ($reflection->getAnnotations() as $annotation) { $annotation->expandAnnotation($class, $reflection, $descriptor); } foreach ($reflection->getMethods(false) as $method) { $annotations = $method->getAnnotations(); $descriptor = call_user_func(array($class, 'shapeDescriptorWithMethod'), $class, $method, $descriptor, $annotations); foreach ($annotations as $annotation) { $annotation->expandAnnotation($class, $method, $descriptor); } } foreach ($reflection->getProperties(false) as $property) { $annotations = $property->getAnnotations(); $descriptor = call_user_func(array($class, 'shapeDescriptorWithProperty'), $class, $property, $descriptor, $annotations); foreach ($annotations as $annotation) { $annotation->expandAnnotation($class, $property, $descriptor); } } $descriptor = call_user_func(array($class, 'finalClassDescriptor'), $class, $descriptor); return $descriptor; }