Exemplo n.º 1
0
 /**
  * Finds and calls the requested resource
  * @param	string	$resource_name	Requested resource name
  * @return	string
  */
 public final function fetchResource($resource_name = null)
 {
     if ($resource_name == null) {
         $resource_name = $this->get('resource');
     }
     $resource_obj = ApiResource::getInstance($resource_name, $this);
     if ($resource_obj === false) {
         $this->checkInternally($resource_name);
     }
     $user = APIAuthentication::authenticateRequest();
     $this->set('user', $user);
     $session = JFactory::getSession();
     $session->set('user', $user);
     $access = $this->getResourceAccess($resource_name, $this->request_method);
     if ($access == 'protected' && $user === false) {
         ApiError::raiseError(403, APIAuthentication::getAuthError());
     }
     if (!$this->checkRequestLimit()) {
         ApiError::raiseError(403, JText::_('COM_API_RATE_LIMIT_EXCEEDED'));
     }
     $this->log();
     $this->lastUsed();
     if ($resource_obj !== false) {
         $resource_obj->invoke();
     } else {
         call_user_func(array($this, $resource_name));
     }
     $output = $this->encode();
     return $output;
 }