Ejemplo n.º 1
0
 /**
  * Load item object
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed    Object on success, false on failure.
  *
  * @since   1.2
  */
 public function getItem($pk = null)
 {
     if (!($item = parent::getItem($pk))) {
         return $item;
     }
     if (!empty($item->id) && is_null($this->xmlFile)) {
         try {
             $this->xmlFile = RApiHalHelper::loadWebserviceConfiguration($item->name, $item->version, 'xml', $item->path, $item->client);
         } catch (Exception $e) {
             JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_REDCORE_WEBSERVICE_ERROR_LOADING_XML', $e->getMessage()), 'error');
         }
     }
     // Add default webservice parameters since this is new webservice
     if (empty($this->xmlFile)) {
         $this->xmlFile = $this->defaultXmlFile;
     }
     return $item;
 }
Ejemplo n.º 2
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @throws Exception
  * @since   1.2
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     JPluginHelper::importPlugin('redcore');
     $this->setWebserviceName();
     $this->client = $this->options->get('webserviceClient', 'site');
     $this->webserviceVersion = $this->options->get('webserviceVersion', '');
     $this->hal = new RApiHalDocumentResource('');
     if (!empty($this->webserviceName)) {
         if (empty($this->webserviceVersion)) {
             $this->webserviceVersion = RApiHalHelper::getNewestWebserviceVersion($this->client, $this->webserviceName);
         }
         $this->webservice = RApiHalHelper::getInstalledWebservice($this->client, $this->webserviceName, $this->webserviceVersion);
         if (empty($this->webservice)) {
             throw new Exception(JText::sprintf('LIB_REDCORE_API_HAL_WEBSERVICE_NOT_INSTALLED', $this->webserviceName, $this->webserviceVersion));
         }
         if (empty($this->webservice['state'])) {
             throw new Exception(JText::sprintf('LIB_REDCORE_API_HAL_WEBSERVICE_UNPUBLISHED', $this->webserviceName, $this->webserviceVersion));
         }
         $this->webservicePath = $this->webservice['path'];
         $this->configuration = RApiHalHelper::loadWebserviceConfiguration($this->webserviceName, $this->webserviceVersion, 'xml', $this->webservicePath, $this->client);
         // Set option and view name
         $this->setOptionViewName($this->webserviceName, $this->configuration);
         // Set base data
         $this->setBaseDataValues();
     }
     // Init Environment
     $this->triggerFunction('setApiOperation');
     // Set initial status code
     $this->setStatusCode($this->statusCode);
     // Check for defined constants
     if (!defined('JSON_UNESCAPED_SLASHES')) {
         define('JSON_UNESCAPED_SLASHES', 64);
     }
     // OAuth2 check
     if (RBootstrap::getConfig('webservices_authorization_check', 0) == 0) {
         $this->authorizationCheck = 'oauth2';
     } elseif (RBootstrap::getConfig('webservices_authorization_check', 0) == 1) {
         $this->authorizationCheck = 'joomla';
     }
 }