Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Api2_Adminhtml_Api2_AttributeController
  • Mage_Api2_Adminhtml_Api2_RoleController
  • Mage_Api2_Block_Adminhtml_Attribute
  • Mage_Api2_Block_Adminhtml_Attribute_Buttons
  • Mage_Api2_Block_Adminhtml_Attribute_Edit
  • Mage_Api2_Block_Adminhtml_Attribute_Edit_Form
  • Mage_Api2_Block_Adminhtml_Attribute_Grid
  • Mage_Api2_Block_Adminhtml_Attribute_Tab_Resource
  • Mage_Api2_Block_Adminhtml_Attribute_Tabs
  • Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
  • Mage_Api2_Block_Adminhtml_Roles
  • Mage_Api2_Block_Adminhtml_Roles_Buttons
  • Mage_Api2_Block_Adminhtml_Roles_Grid
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Info
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Resources
  • Mage_Api2_Block_Adminhtml_Roles_Tab_Users
  • Mage_Api2_Block_Adminhtml_Roles_Tabs
  • Mage_Api2_Helper_Data
  • Mage_Api2_Model_Acl
  • Mage_Api2_Model_Acl_Filter
  • Mage_Api2_Model_Acl_Filter_Attribute
  • Mage_Api2_Model_Acl_Filter_Attribute_Operation
  • Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
  • Mage_Api2_Model_Acl_Global
  • Mage_Api2_Model_Acl_Global_Role
  • Mage_Api2_Model_Acl_Global_Rule
  • Mage_Api2_Model_Acl_Global_Rule_Permission
  • Mage_Api2_Model_Acl_Global_Rule_Privilege
  • Mage_Api2_Model_Acl_Global_Rule_ResourcePermission
  • Mage_Api2_Model_Acl_Global_Rule_Tree
  • Mage_Api2_Model_Auth
  • Mage_Api2_Model_Auth_Adapter
  • Mage_Api2_Model_Auth_Adapter_Abstract
  • Mage_Api2_Model_Auth_Adapter_Oauth
  • Mage_Api2_Model_Auth_User
  • Mage_Api2_Model_Auth_User_Abstract
  • Mage_Api2_Model_Auth_User_Admin
  • Mage_Api2_Model_Auth_User_Customer
  • Mage_Api2_Model_Auth_User_Guest
  • Mage_Api2_Model_Config
  • Mage_Api2_Model_Dispatcher
  • Mage_Api2_Model_Multicall
  • Mage_Api2_Model_Observer
  • Mage_Api2_Model_Renderer
  • Mage_Api2_Model_Renderer_Json
  • Mage_Api2_Model_Renderer_Query
  • Mage_Api2_Model_Renderer_Xml
  • Mage_Api2_Model_Renderer_Xml_Writer
  • Mage_Api2_Model_Request
  • Mage_Api2_Model_Request_Internal
  • Mage_Api2_Model_Request_Interpreter
  • Mage_Api2_Model_Request_Interpreter_Json
  • Mage_Api2_Model_Request_Interpreter_Query
  • Mage_Api2_Model_Request_Interpreter_Xml
  • Mage_Api2_Model_Resource
  • Mage_Api2_Model_Resource_Acl_Filter_Attribute
  • Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection
  • Mage_Api2_Model_Resource_Acl_Global_Role
  • Mage_Api2_Model_Resource_Acl_Global_Role_Collection
  • Mage_Api2_Model_Resource_Acl_Global_Rule
  • Mage_Api2_Model_Resource_Acl_Global_Rule_Collection
  • Mage_Api2_Model_Resource_Setup
  • Mage_Api2_Model_Resource_Validator
  • Mage_Api2_Model_Resource_Validator_Eav
  • Mage_Api2_Model_Resource_Validator_Fields
  • Mage_Api2_Model_Response
  • Mage_Api2_Model_Route_Abstract
  • Mage_Api2_Model_Route_ApiType
  • Mage_Api2_Model_Route_Rest
  • Mage_Api2_Model_Router
  • Mage_Api2_Model_Server

Interfaces

  • Mage_Api2_Model_Acl_PermissionInterface
  • Mage_Api2_Model_Renderer_Interface
  • Mage_Api2_Model_Request_Interpreter_Interface
  • Mage_Api2_Model_Route_Interface

Exceptions

  • Mage_Api2_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Api2
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * API Request model
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Api2
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Api2_Model_Request extends Zend_Controller_Request_Http
 35: {
 36:     /**
 37:      * Character set which must be used in request
 38:      */
 39:     const REQUEST_CHARSET = 'utf-8';
 40: 
 41:     /**#@+
 42:      * Name of query ($_GET) parameters to use in navigation and so on
 43:      */
 44:     const QUERY_PARAM_REQ_ATTRS   = 'attrs';
 45:     const QUERY_PARAM_PAGE_NUM    = 'page';
 46:     const QUERY_PARAM_PAGE_SIZE   = 'limit';
 47:     const QUERY_PARAM_ORDER_FIELD = 'order';
 48:     const QUERY_PARAM_ORDER_DIR   = 'dir';
 49:     const QUERY_PARAM_FILTER      = 'filter';
 50:     /**#@- */
 51: 
 52:     /**
 53:      * Interpreter adapter
 54:      *
 55:      * @var Mage_Api2_Model_Request_Interpreter_Interface
 56:      */
 57:     protected $_interpreter;
 58: 
 59:     /**
 60:      * Body params
 61:      *
 62:      * @var array
 63:      */
 64:     protected $_bodyParams;
 65: 
 66:     /**
 67:      * Constructor
 68:      *
 69:      * If a $uri is passed, the object will attempt to populate itself using
 70:      * that information.
 71:      * Override parent class to allow object instance get via Mage::getSingleton()
 72:      *
 73:      * @param string|Zend_Uri $uri
 74:      */
 75:     public function __construct($uri = null)
 76:     {
 77:         parent::__construct($uri ? $uri : null);
 78:     }
 79: 
 80:     /**
 81:      * Get request interpreter
 82:      *
 83:      * @return Mage_Api2_Model_Request_Interpreter_Interface
 84:      */
 85:     protected function _getInterpreter()
 86:     {
 87:         if (null === $this->_interpreter) {
 88:             $this->_interpreter = Mage_Api2_Model_Request_Interpreter::factory($this->getContentType());
 89:         }
 90:         return $this->_interpreter;
 91:     }
 92: 
 93:     /**
 94:      * Retrieve accept types understandable by requester in a form of array sorted by quality descending
 95:      *
 96:      * @return array
 97:      */
 98:     public function getAcceptTypes()
 99:     {
100:         $qualityToTypes = array();
101:         $orderedTypes   = array();
102: 
103:         foreach (preg_split('/,\s*/', $this->getHeader('Accept')) as $definition) {
104:             $typeWithQ = explode(';', $definition);
105:             $mimeType  = trim(array_shift($typeWithQ));
106: 
107:             // check MIME type validity
108:             if (!preg_match('~^([0-9a-z*+\-]+)(?:/([0-9a-z*+\-\.]+))?$~i', $mimeType)) {
109:                 continue;
110:             }
111:             $quality = '1.0'; // default value for quality
112: 
113:             if ($typeWithQ) {
114:                 $qAndValue = explode('=', $typeWithQ[0]);
115: 
116:                 if (2 == count($qAndValue)) {
117:                     $quality = $qAndValue[1];
118:                 }
119:             }
120:             $qualityToTypes[$quality][$mimeType] = true;
121:         }
122:         krsort($qualityToTypes);
123: 
124:         foreach ($qualityToTypes as $typeList) {
125:             $orderedTypes += $typeList;
126:         }
127:         return array_keys($orderedTypes);
128:     }
129: 
130:     /**
131:      * Get api type from Request
132:      *
133:      * @return string
134:      */
135:     public function getApiType()
136:     {
137:         // getParam() is not used to avoid parameter fetch from $_GET or $_POST
138:         return isset($this->_params['api_type']) ? $this->_params['api_type'] : null;
139:     }
140: 
141:     /**
142:      * Fetch data from HTTP Request body
143:      *
144:      * @return array
145:      */
146:     public function getBodyParams()
147:     {
148:         if (null == $this->_bodyParams) {
149:             $this->_bodyParams = $this->_getInterpreter()->interpret((string)$this->getRawBody());
150:         }
151:         return $this->_bodyParams;
152:     }
153: 
154:     /**
155:      * Get Content-Type of request
156:      *
157:      * @return string
158:      * @throws Mage_Api2_Exception
159:      */
160:     public function getContentType()
161:     {
162:         $headerValue = $this->getHeader('Content-Type');
163: 
164:         if (!$headerValue) {
165:             throw new Mage_Api2_Exception('Content-Type header is empty', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
166:         }
167:         if (!preg_match('~^([a-z\d/\-+.]+)(?:; *charset=(.+))?$~Ui', $headerValue, $matches)) {
168:             throw new Mage_Api2_Exception('Invalid Content-Type header', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
169:         }
170:         // request encoding check if it is specified in header
171:         if (isset($matches[2]) && self::REQUEST_CHARSET != strtolower($matches[2])) {
172:             throw new Mage_Api2_Exception(
173:                 'UTF-8 is the only supported charset', Mage_Api2_Model_Server::HTTP_BAD_REQUEST
174:             );
175:         }
176:         return $matches[1];
177:     }
178: 
179:     /**
180:      * Get filter settings passed by API user
181:      *
182:      * @return mixed
183:      */
184:     public function getFilter()
185:     {
186:         return $this->getQuery(self::QUERY_PARAM_FILTER);
187:     }
188: 
189:     /**
190:      * Get resource model class name
191:      *
192:      * @return string|null
193:      */
194:     public function getModel()
195:     {
196:         // getParam() is not used to avoid parameter fetch from $_GET or $_POST
197:         return isset($this->_params['model']) ? $this->_params['model'] : null;
198:     }
199: 
200:     /**
201:      * Retrieve one of CRUD operation dependent on HTTP method
202:      *
203:      * @return string
204:      * @throws Mage_Api2_Exception
205:      */
206:     public function getOperation()
207:     {
208:         if (!$this->isGet() && !$this->isPost() && !$this->isPut() && !$this->isDelete()) {
209:             throw new Mage_Api2_Exception('Invalid request method', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
210:         }
211:         // Map HTTP methods to classic CRUD verbs
212:         $operationByMethod = array(
213:             'GET'    => Mage_Api2_Model_Resource::OPERATION_RETRIEVE,
214:             'POST'   => Mage_Api2_Model_Resource::OPERATION_CREATE,
215:             'PUT'    => Mage_Api2_Model_Resource::OPERATION_UPDATE,
216:             'DELETE' => Mage_Api2_Model_Resource::OPERATION_DELETE
217:         );
218: 
219:         return $operationByMethod[$this->getMethod()];
220:     }
221: 
222:     /**
223:      * Get sort order direction requested by API user
224:      *
225:      * @return mixed
226:      */
227:     public function getOrderDirection()
228:     {
229:         return $this->getQuery(self::QUERY_PARAM_ORDER_DIR);
230:     }
231: 
232:     /**
233:      * Get sort order field requested by API user
234:      *
235:      * @return mixed
236:      */
237:     public function getOrderField()
238:     {
239:         return $this->getQuery(self::QUERY_PARAM_ORDER_FIELD);
240:     }
241: 
242:     /**
243:      * Retrieve page number requested by API user
244:      *
245:      * @return mixed
246:      */
247:     public function getPageNumber()
248:     {
249:         return $this->getQuery(self::QUERY_PARAM_PAGE_NUM);
250:     }
251: 
252:     /**
253:      * Retrieve page size requested by API user
254:      *
255:      * @return mixed
256:      */
257:     public function getPageSize()
258:     {
259:         return $this->getQuery(self::QUERY_PARAM_PAGE_SIZE);
260:     }
261: 
262:     /**
263:      * Get an array of attribute codes requested by API user
264:      *
265:      * @return array
266:      */
267:     public function getRequestedAttributes()
268:     {
269:         $include = $this->getQuery(self::QUERY_PARAM_REQ_ATTRS, array());
270: 
271:         //transform comma-separated list
272:         if (!is_array($include)) {
273:             $include = explode(',', $include);
274:         }
275:         return array_map('trim', $include);
276:     }
277: 
278:     /**
279:      * Retrieve resource type
280:      *
281:      * @return string
282:      */
283:     public function getResourceType()
284:     {
285:         // getParam() is not used to avoid parameter fetch from $_GET or $_POST
286:         return isset($this->_params['type']) ? $this->_params['type'] : null;
287:     }
288: 
289:     /**
290:      * Get Version header from headers
291:      *
292:      * @return string
293:      */
294:     public function getVersion()
295:     {
296:         return $this->getHeader('Version');
297:     }
298: 
299:     /**
300:      * Retrieve action type
301:      *
302:      * @return string|null
303:      */
304:     public function getActionType()
305:     {
306:         // getParam() is not used to avoid parameter fetch from $_GET or $_POST
307:         return isset($this->_params['action_type']) ? $this->_params['action_type'] : null;
308:     }
309: 
310:     /**
311:      * It checks if the array in the request body is an associative one.
312:      * It is required for definition of the dynamic aaction type (multi or single)
313:      *
314:      * @return bool
315:      */
316:     public function isAssocArrayInRequestBody()
317:     {
318:         $params = $this->getBodyParams();
319:         if (count($params)) {
320:             $keys = array_keys($params);
321:             return !is_numeric($keys[0]);
322:         }
323:         return false;
324:     }
325: }
326: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0