/** * Create resources from service. * * If service has a route identifier, creates both entity and collection * resources; otherwise, creates an RPC resource. * * @return void */ private function createResources() { // If there is routeIdentifierName, it is REST service and we need to // handle both collection and entities if ($this->service->getRouteIdentifierName()) { $this->resources[] = new Resource($this->service, $this->service->getOperations(), $this->getCollectionUri(), Resource::RESOURCE_TYPE_COLLECTION); $this->resources[] = new Resource($this->service, $this->service->getEntityOperations(), $this->getEntityUri(), Resource::RESOURCE_TYPE_ENTITY); return; } $this->resources[] = new Resource($this->service, $this->service->getOperations(), $this->getEntityUri(), Resource::RESOURCE_TYPE_RPC); }
/** * Return the URI path for a given service and operation * * @param Service $service * @param Operation $operation * @return string */ public function __invoke(Service $service, Operation $operation) { $route = $service->getRoute(); $routeIdentifier = $service->getRouteIdentifierName(); $entityOps = $service->getEntityOperations(); if (empty($routeIdentifier) || empty($entityOps)) { return $route; } return preg_replace('#\\[/?:' . preg_quote($routeIdentifier) . '\\]#', '', $route); }