/**
  * @return ViewModel
  */
 public function showAction()
 {
     $apiName = $this->params()->fromRoute('api');
     $apiVersion = $this->params()->fromRoute('version', '1');
     $viewModel = new ViewModel(['api' => $apiName]);
     $viewModel->setTemplate('zf-apigility-documentation-blueprint/api');
     $viewModel->setTerminal(true);
     $api = $this->apiFactory->createApi($apiName, $apiVersion);
     $viewModel->setVariable('documentation', $api);
     $viewModel->setVariable('type', 'api');
     return $viewModel;
 }
コード例 #2
0
 public function sourceAction()
 {
     $request = $this->getRequest();
     switch ($request->getMethod()) {
         case $request::METHOD_GET:
             $module = urldecode($this->params()->fromQuery('module', false));
             if (!$module) {
                 return new ApiProblemModel(new ApiProblem(422, 'Module parameter not provided', 'https://tools.ietf.org/html/rfc4918', 'Unprocessable Entity'));
             }
             $result = $this->moduleModel->getModule($module);
             if (!$result) {
                 return new ApiProblemModel(new ApiProblem(422, 'The module specified doesn\'t exist', 'https://tools.ietf.org/html/rfc4918', 'Unprocessable Entity'));
             }
             $class = urldecode($this->params()->fromQuery('class', false));
             if (!$class) {
                 return new ApiProblemModel(new ApiProblem(422, 'Class parameter not provided', 'https://tools.ietf.org/html/rfc4918', 'Unprocessable Entity'));
             }
             if (!class_exists($class)) {
                 return new ApiProblemModel(new ApiProblem(422, 'The class specified doesn\'t exist', 'https://tools.ietf.org/html/rfc4918', 'Unprocessable Entity'));
             }
             $reflector = new ReflectionClass($class);
             $fileName = $reflector->getFileName();
             $metadata = ['module' => $module, 'class' => $class, 'file' => $fileName, 'source' => $this->highlightFileWithNum($fileName)];
             $model = new ViewModel($metadata);
             $model->setTerminal(true);
             return $model;
         default:
             return new ApiProblemModel(new ApiProblem(405, 'Only the method PUT is allowed for this URI'));
     }
 }
コード例 #3
0
 public function cacheEnabledAction()
 {
     $cacheEnabled = false;
     switch (true) {
         case php_sapi_name() === 'cli-server':
             // built-in PHP webserver never truly enables opcode caching
             break;
         case ini_get('opcache.enable'):
             // zf-configuration has opcache rules for invalidating the cache built-in
             break;
         case ini_get('apc.enabled') && extension_loaded('apc'):
             // APC
             $cacheEnabled = true;
             break;
         case ini_get('zend_optimizerplus.enable'):
             // Optimizer+
             $cacheEnabled = true;
             break;
         case ini_get('eaccelerator.enable'):
             // EAccelerator
             $cacheEnabled = true;
             break;
         case ini_get('xcache.cacher'):
             // XCache
             $cacheEnabled = true;
             break;
         case ini_get('wincache.ocenabled'):
             // WinCache
             $cacheEnabled = true;
             break;
     }
     $viewModel = new ViewModel(['cache_enabled' => $cacheEnabled]);
     $viewModel->setTerminal(true);
     return $viewModel;
 }
コード例 #4
0
 /**
  * Create a view model with the given adapters to indicate authentication types available.
  *
  * @param array $adapters
  * @return ViewModel
  */
 private function createViewModel($adapters)
 {
     $model = new ViewModel(array(
         'auth-types' => $adapters
     ));
     $model->setTerminal(true);
     return $model;
 }
コード例 #5
0
 protected function processResult(MvcEvent $event, $return)
 {
     if ($return instanceof ApiProblem) {
         return new ApiProblemResponse($return);
     }
     if (!$return instanceof HalEntity && !$return instanceof HalCollection) {
         return $return;
     }
     // Set the fallback content negotiation to use HalJson.
     $event->setParam('ZFContentNegotiationFallback', 'HalJson');
     // Use content negotiation for creating the view model
     $viewModel = new ContentNegotiationViewModel(array('payload' => $return));
     $viewModel->setTerminal(true);
     $event->setResult($viewModel);
     return $viewModel;
 }
コード例 #6
0
 /**
  * Create a view model detailing the authentication adapter mapped
  *
  * @param string $adapter
  * @return ViewModel
  */
 private function createAuthenticationMapResult($adapter)
 {
     $model = new ViewModel(['authentication' => $adapter]);
     $model->setTerminal(true);
     return $model;
 }
コード例 #7
0
 /**
  * Handle the dispatch event
  *
  * Does several "pre-flight" checks:
  * - Raises an exception if no resource is composed.
  * - Raises an exception if no route is composed.
  * - Returns a 405 response if the current HTTP request method is not in
  *   $options
  *
  * When the dispatch is complete, it will check to see if an array was
  * returned; if so, it will cast it to a view model using the
  * AcceptableViewModelSelector plugin, and the $acceptCriteria property.
  *
  * @param  MvcEvent $e
  * @return mixed
  * @throws DomainException
  */
 public function onDispatch(MvcEvent $e)
 {
     if (!$this->getResource()) {
         throw new DomainException(sprintf('%s requires that a %s\\ResourceInterface object is composed; none provided', __CLASS__, __NAMESPACE__));
     }
     if (!$this->route) {
         throw new DomainException(sprintf('%s requires that a route name for the resource is composed; none provided', __CLASS__));
     }
     // Check for an API-Problem in the event
     $return = $e->getParam('api-problem', false);
     // If no API-Problem, dispatch the parent event
     if (!$return) {
         $return = parent::onDispatch($e);
     }
     if (!$return instanceof ApiProblem && !$return instanceof HalEntity && !$return instanceof HalCollection) {
         return $return;
     }
     if ($return instanceof ApiProblem) {
         return new ApiProblemResponse($return);
     }
     // Set the fallback content negotiation to use HalJson.
     $e->setParam('ZFContentNegotiationFallback', 'HalJson');
     // Use content negotiation for creating the view model
     $viewModel = new ContentNegotiationViewModel(array('payload' => $return));
     $viewModel->setTerminal(true);
     $e->setResult($viewModel);
     return $viewModel;
 }