/** * Returns the life time defined in the expires header * * @return int */ public function getExpiresHeaderLifeTime() { if ($this->expiresHeaderLifeTime === NULL) { $readCacheLifeTime = $this->objectManager->getConfigurationProvider()->getSetting('expiresHeaderLifeTime'); $this->expiresHeaderLifeTime = $readCacheLifeTime !== NULL ? intval($readCacheLifeTime) : $this->getCacheLifeTime(); } return $this->expiresHeaderLifeTime; }
/** * List all Models * * @return array Returns all Models */ public function listAll() { /* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM */ /* LIST */ /* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM */ $dataProvider = $this->getDataProvider(); $allModels = $dataProvider->getAllModelsForPath($this->getPath()); if (!is_array($allModels) && $allModels instanceof Traversable) { $allModels = iterator_to_array($allModels); } $result = array_map(array($dataProvider, 'getModelData'), $allModels); if ($this->objectManager->getConfigurationProvider()->getSetting('addRootObjectForCollection')) { return array($this->getRequest()->getRootObjectKey() => $result); } return $result; }
/** * Returns the request * * @return \Cundd\Rest\Request */ public function getRequest() { if (!$this->request) { $format = ''; $uri = $this->getUri($format); /* * Transform Document URLs * @Todo: Make this better */ if (substr($uri, 0, 9) === 'Document/') { $uri = 'Document-' . substr($uri, 9); } $this->request = new Request(NULL, $uri); $this->request->injectConfigurationProvider($this->objectManager->getConfigurationProvider()); if ($format) { $this->request->format($format); } } return $this->request; }
/** * @test */ public function getConfigurationProviderTest() { $object = $this->fixture->getConfigurationProvider(); $this->assertInstanceOf('Cundd\\Rest\\Configuration\\TypoScriptConfigurationProvider', $object); }
/** * Dispatch the request * * @param \Cundd\Rest\Request $request Overwrite the request * @param Response $responsePointer Reference to be filled with the response * @return boolean Returns if the request has been successfully dispatched */ public function dispatch(Request $request = NULL, Response &$responsePointer = NULL) { if ($request) { $this->requestFactory->registerCurrentRequest($request); $this->objectManager->reassignRequest(); } else { $request = $this->requestFactory->getRequest(); } $requestPath = $request->path(); if (!$requestPath) { return $this->greet(); } // Checks if the request needs authentication switch ($this->objectManager->getAccessController()->getAccess()) { case AccessControllerInterface::ACCESS_ALLOW: break; case AccessControllerInterface::ACCESS_UNAUTHORIZED: echo $this->responseFactory->createErrorResponse('Unauthorized', 401); return FALSE; case AccessControllerInterface::ACCESS_DENY: default: echo $this->responseFactory->createErrorResponse('Forbidden', 403); return FALSE; } /** @var Cache $cache */ $cache = $this->objectManager->getCache(); $response = $cache->getCachedValueForRequest($request); $success = TRUE; // If no cached response exists if (!$response) { // If a path is given let the handler build up the routes if ($requestPath) { $this->logRequest(sprintf('path: "%s" method: "%s"', $requestPath, $request->method())); $this->objectManager->getHandler()->configureApiPaths(); } // Let Bullet PHP do the hard work $response = $this->app->run($request); // Handle exceptions if ($response->content() instanceof \Exception) { $success = FALSE; $exception = $response->content(); $this->logException($exception); $response = $this->exceptionToResponse($exception); } else { // Cache the response $cache->setCachedValueForRequest($request, $response); } } // Additional custom headers $additionalResponseHeaders = $this->objectManager->getConfigurationProvider()->getSetting('responseHeaders', array()); if (is_array($additionalResponseHeaders) && count($additionalResponseHeaders)) { foreach ($additionalResponseHeaders as $responseHeaderType => $value) { if (is_string($value)) { $response->header($responseHeaderType, $value); } elseif (is_array($value) && array_key_exists('userFunc', $value)) { $response->header(rtrim($responseHeaderType, '.'), GeneralUtility::callUserFunction($value['userFunc'], $value, $this)); } } } $responsePointer = $response; $responseString = (string) $response; $this->logResponse('response: ' . $response->status(), array('response' => '' . $responseString)); echo $responseString; return $success; }