예제 #1
0
 /**
  * Register the API server.
  *
  * @throws \Exception
  * @return  boolean
  */
 public function register()
 {
     $uri = \JURI::getInstance();
     if (!$this->isApi()) {
         return false;
     }
     $app = \JFactory::getApplication();
     $input = $app->input;
     // Restore Joomla handler and using our Json handler.
     JsonResponse::registerErrorHandler();
     // Authentication
     if (!$this->isUserOperation($uri) && $this->option['authorise']) {
         if (!Authentication::authenticate($input->get('session_key'))) {
             throw new \Exception(\JText::_('JERROR_ALERTNOAUTHOR'), 403);
         }
     }
     // Set Format to JSON
     $input->set('format', 'json');
     // Store JDocumentJson to Factory
     \JFactory::$document = \JDocument::getInstance('json');
     $router = $app::getRouter();
     // Attach a hook to Router
     $router->attachParseRule(array($this, 'parseRule'));
     return true;
 }
예제 #2
0
 /**
  * Method to render the view.
  *
  * We just return JSON string for Joomla to respond it.
  *
  * @return  string  The rendered view.
  *
  * @throws  \RuntimeException
  */
 public function doRender()
 {
     return (string) JsonResponse::response($this->data->toArray());
 }