/classes/webservice/WebserviceRequest.php
PHP | 1089 lines | 723 code | 79 blank | 287 comment | 159 complexity | e149f0c555ca717d852536ed267df3e7 MD5 | raw file
- <?php
- /*
- * 2007-2015 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author Prestashop SA <contact@prestashop.com>
- * @copyright 2007-2010 Prestashop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- class WebserviceRequestCore
- {
- const HTTP_GET = 1;
- const HTTP_POST = 2;
- const HTTP_PUT = 4;
- protected $_available_languages = null;
- /**
- * Errors triggered at execution
- * @var array
- */
- public $errors = array();
- /**
- * Set if return should display content or not
- * @var bool
- */
- protected $_outputEnabled = true;
- /**
- * Set if the management is specific or if it is classic (entity management)
- * @var WebserviceSpecificManagementImages|WebserviceSpecificManagementSearch|false
- */
- protected $objectSpecificManagement = false;
- /**
- * Base PrestaShop webservice URL
- * @var string
- */
- public $wsUrl;
- /**
- * PrestaShop Webservice Documentation URL
- * @var string
- */
- protected $_docUrl = 'http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service';
- /**
- * Set if the authentication key was checked
- * @var bool
- */
- protected $_authenticated = false;
- /**
- * HTTP Method to support
- * @var string
- */
- public $method;
- /**
- * The segment of the URL
- * @var array
- */
- public $urlSegment = array();
- /**
- * The segment list of the URL after the "api" segment
- * @var array
- */
- public $urlFragments = array();
- /**
- * The time in microseconds of the start of the execution of the web service request
- * @var int
- */
- protected $_startTime = 0;
- /**
- * The list of each resources manageable via web service
- * @var array
- */
- public $resourceList;
- /**
- * The configuration parameters of the current resource
- * @var array
- */
- public $resourceConfiguration;
- /**
- * The permissions for the current key
- * @var array
- */
- public $keyPermissions;
- /**
- * The XML string to display if web service call succeed
- * @var string
- */
- protected $specificOutput = '';
- /**
- * The list of objects to display
- * @var array
- */
- public $objects;
- /**
- * The current object to support, it extends the PrestaShop ObjectModel
- * @var ObjectModel
- */
- protected $_object;
- /**
- * The schema to display.
- * If null, no schema have to be displayed and normal management has to be performed
- * @var string
- */
- public $schemaToDisplay;
- /**
- * The fields to display. These fields will be displayed when retrieving objects
- * @var string
- */
- public $fieldsToDisplay = 'minimum';
- /**
- * If we are in PUT or POST case, we use this attribute to store the xml string value during process
- * @var string
- */
- protected $_inputXml;
- /**
- * Object instance for singleton
- * @var WebserviceRequest
- */
- protected static $_instance;
- /**
- * Key used for authentication
- * @var string
- */
- protected $_key;
- /**
- * This is used to have a deeper tree diagram.
- * @var int
- */
- public $depth = 0;
- /**
- * Name of the output format
- * @var string
- */
- protected $outputFormat = 'xml';
- /**
- * The object to build the output.
- * @var WebserviceOutputBuilder
- */
- protected $objOutput;
- /**
- * Save the class name for override used in getInstance()
- * @var string
- */
- public static $ws_current_classname;
- public static $shopIDs;
- public function getOutputEnabled()
- {
- return $this->_outputEnabled;
- }
- public function setOutputEnabled($bool)
- {
- if (Validate::isBool($bool)) {
- $this->_outputEnabled = $bool;
- }
- return $this;
- }
- /**
- * Get WebserviceRequest object instance (Singleton)
- *
- * @return object WebserviceRequest instance
- */
- public static function getInstance()
- {
- if (!isset(self::$_instance)) {
- self::$_instance = new WebserviceRequest::$ws_current_classname();
- }
- return self::$_instance;
- }
- /*
- protected function getOutputObject($type)
- {
- switch ($type)
- {
- case 'XML' :
- default :
- $obj_render = new WebserviceOutputXML();
- break;
- }
- return $obj_render;
- }
- */
- protected function getOutputObject($type)
- {
- // set header param in header or as get param
- $headers = self::getallheaders();
- if (isset($headers['Io-Format'])) {
- $type = $headers['Io-Format'];
- } elseif (isset($headers['Output-Format'])) {
- $type = $headers['Output-Format'];
- } elseif (isset($_GET['output_format'])) {
- $type = $_GET['output_format'];
- } elseif (isset($_GET['io_format'])) {
- $type = $_GET['io_format'];
- }
- $this->outputFormat = $type;
- switch ($type) {
- case 'JSON' :
- require_once dirname(__FILE__).'/WebserviceOutputJSON.php';
- $obj_render = new WebserviceOutputJSON();
- break;
- case 'XML' :
-