/** * {@inheritDoc} */ public function loadMetadataForClass($className, ServiceMetadata $serviceMetadata) { // get all class annotations $reflClass = new \ReflectionClass($className); $classAnnotations = $this->reader->getClassAnnotations($reflClass); $classAnnotations = $this->indexAnnotationsByType($classAnnotations); // load headline service information $serviceAnnotation = $this->getAnnotation($classAnnotations, self::ANNOTATION_SERVICE); if ($serviceAnnotation === false) { throw Exception::classIsNotMappedService($className); } // process events foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) { $methodAnnotations = $this->reader->getMethodAnnotations($reflMethod); $methodAnnotations = $this->indexAnnotationsByType($methodAnnotations); // process listeners $listenerAnnotations = $this->getAnnotation($methodAnnotations, self::ANNOTATION_LISTENER); if ($listenerAnnotations !== false) { if (!is_array($listenerAnnotations)) { $listenerAnnotations = array($listenerAnnotations); } foreach ($listenerAnnotations as $listenerAnnotation) { // ensure we don't double-up listener entries $existingListeners = $serviceMetadata->getListeners($listenerAnnotation->event); if (!in_array($reflMethod->getName(), $existingListeners)) { $serviceMetadata->addListener($listenerAnnotation->event, $reflMethod->getName()); } } } } }
/** * Returns ServiceMetadata for the specified class. * * @param string $className * @throws \BedRest\Service\Mapping\Exception * @return \BedRest\Service\Mapping\ServiceMetadata */ public function getMetadataFor($className) { if (!$this->isService($className)) { throw Exception::classIsNotMappedService($className); } if (!isset($this->loadedMetadata[$className])) { $this->loadMetadata($className); } if ($this->cache) { $cacheId = $this->cachePrefix . $className . $this->cacheSuffix; if (($cached = $this->cache->fetch($cacheId)) !== false) { $this->loadedMetadata[$className] = $cached; } else { $this->loadMetadata($className); $this->cache->save($cacheId, $this->loadedMetadata[$className], null); } } else { $this->loadMetadata($className); } return $this->loadedMetadata[$className]; }