Пример #1
0
 /**
  * Determine context, format and uuid of the raw request
  *
  * @param Request $request A Request instance
  * @param int     $type    The type of the request (for Symfony compatibility, not implemented)
  *
  * @return Response A Response instance
  */
 public function handleRaw(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
 {
     // workaround for https://github.com/symfony/symfony/issues/13617
     $pathInfo = $request->server->has('PATH_INFO') ? $request->server->get('PATH_INFO') : '';
     if (0 === strlen($pathInfo)) {
         $pathInfo = $request->getPathInfo();
     }
     $format = pathinfo($pathInfo, PATHINFO_EXTENSION);
     if (!array_key_exists($format, self::$viewMapping)) {
         if (empty($pathInfo)) {
             throw new \Exception('Missing or invalid PATH_INFO');
         } elseif (empty($this->format)) {
             throw new \Exception('Missing format');
         } else {
             throw new \Exception('Unknown format: \'' . $this->format . '\'');
         }
     }
     // initialize debugging
     if (($debugLevel = $request->query->get('debug')) || ($debugLevel = Util\Configuration::read('debug'))) {
         if ($debugLevel > 0 && !Util\Debug::isActivated()) {
             new Util\Debug($debugLevel, $this->em);
         }
     } else {
         // make sure static debug instance is removed
         Util\Debug::deactivate();
     }
     $class = self::$viewMapping[$format];
     $this->view = new $class($request, $format);
     $path = explode('/', substr($pathInfo, 1, strrpos($pathInfo, '.') - 1));
     list($context, $uuid) = array_merge($path, array(null));
     // verify route
     if (!array_key_exists($context, self::$controllerMapping)) {
         throw new \Exception(empty($context) ? 'Missing context' : 'Unknown context: \'' . $context . '\'');
     }
     return $this->handler($request, $context, $uuid);
 }
Пример #2
0
 /**
  * Processes the request
  *
  * Example: http://sub.domain.local/middleware.php/channel/550e8400-e29b-11d4-a716-446655440000/data.json?operation=edit&title=New Title
  */
 function handler(Request $request, $context, $uuid)
 {
     // initialize debugging
     if (($debugLevel = $request->parameters->get('debug')) || ($debugLevel = Util\Configuration::read('debug'))) {
         if ($debugLevel > 0) {
             $this->debug = new Util\Debug($debugLevel, $this->em);
         }
     } else {
         // make sure static debug instance is removed
         Util\Debug::deactivate();
     }
     // get controller operation
     if (null === ($operation = $request->parameters->get('operation'))) {
         $operation = self::$operationMapping[strtolower($request->getMethod())];
     }
     $class = self::$controllerMapping[$context];
     $controller = new $class($request, $this->em);
     $result = $controller->run($operation, $uuid);
     $this->view->add($result);
     return $this->view->send();
 }