Example #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->dispatcher = new Dispatcher();
     $this->testResourceMeta = new ResourceMetadata('testResource');
     $this->testResourceMeta->setName('testResource');
     $this->testResourceMeta->setService('testService');
     $this->testResourceMeta->setSubResources(array('sub' => array('fieldName' => 'sub', 'service' => 'testSubService')));
     $this->testService = $this->getMock('BedRest\\TestFixtures\\Services\\Company\\Generic', array('getListener'), array(), 'testService');
     $this->testServiceMeta = new ServiceMetadata('testService');
     $this->testSubService = $this->getMock('BedRest\\TestFixtures\\Services\\Company\\Generic', array('getListener'), array(), 'testSubService');
     $this->testSubServiceMeta = new ServiceMetadata('testSubService');
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ResourceMetadata $resourceMetadata)
 {
     // get all class annotations
     $reflClass = new \ReflectionClass($className);
     $classAnnotations = $this->reader->getClassAnnotations($reflClass);
     $classAnnotations = $this->indexAnnotationsByType($classAnnotations);
     $resourceAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Resource');
     if ($resourceAnnotation !== false) {
         if (!empty($resourceAnnotation->name)) {
             $resourceMetadata->setName($resourceAnnotation->name);
         } else {
             $resourceName = Inflector::tableize(substr($className, strrpos($className, '\\') + 1));
             $resourceMetadata->setName($resourceName);
         }
     }
     $handlerAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Handler');
     if ($handlerAnnotation !== false) {
         if (!empty($handlerAnnotation->service)) {
             $resourceMetadata->setService($handlerAnnotation->service);
         }
     }
     // properties
     $subResources = array();
     foreach ($reflClass->getProperties() as $reflProp) {
         $propAnnotations = $this->reader->getPropertyAnnotations($reflProp);
         $propAnnotations = $this->indexAnnotationsByType($propAnnotations);
         $subResourceAnnotation = $this->getAnnotation($propAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\SubResource');
         if ($subResourceAnnotation !== false) {
             $subResources[$subResourceAnnotation->name] = array('fieldName' => $reflProp->name, 'service' => $subResourceAnnotation->service);
         }
     }
     $resourceMetadata->setSubResources($subResources);
 }
Example #3
0
 public function testServiceClass()
 {
     $meta = new ResourceMetadata('Resource\\Test');
     $meta->setService('Services\\Test');
     $this->assertEquals('Services\\Test', $meta->getService());
 }