コード例 #1
0
ファイル: RequestEventTest.php プロジェクト: bedrest/bedrest
 public function testData()
 {
     $testData = array('test' => 'value', 'another_test' => 'another_value');
     $this->event->setData($testData);
     $this->assertEquals($testData, $this->event->getData());
 }
コード例 #2
0
ファイル: Dispatcher.php プロジェクト: bedrest/bedrest
 /**
  * Processes a REST request, returning a Response object.
  *
  * @param  \BedRest\Rest\Request\Request   $request
  * @throws \BedRest\Rest\Exception
  * @return \BedRest\Rest\Response\Response
  */
 public function dispatch(Request $request)
 {
     // determine resource
     $resourceParts = explode('/', $request->getResource());
     $resourceName = $resourceParts[0];
     $subResourceName = false;
     if (count($resourceParts) > 1) {
         $subResourceName = $resourceParts[1];
     }
     try {
         $resourceMetadata = $this->resourceMetadataFactory->getMetadataByResourceName($resourceName);
     } catch (ResourceMappingException $e) {
         throw Exception::resourceNotFound($resourceName, 404, $e);
     }
     // determine service
     if ($subResourceName) {
         if (!$resourceMetadata->hasSubResource($subResourceName)) {
             throw Exception::resourceNotFound($request->getResource());
         }
         $subResourceMapping = $resourceMetadata->getSubResource($subResourceName);
         $service = $this->serviceLocator->get($subResourceMapping['service']);
     } else {
         $service = $this->serviceLocator->get($resourceMetadata->getService());
     }
     $this->registerListeners($service);
     $event = new RequestEvent();
     $event->setRequest($request);
     $this->eventManager->dispatch($request->getMethod(), $event);
     return $event->getData();
 }