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_Api_Controller_Action
  • Mage_Api_Helper_Data
  • Mage_Api_IndexController
  • Mage_Api_Model_Acl
  • Mage_Api_Model_Acl_Assert_Ip
  • Mage_Api_Model_Acl_Assert_Time
  • Mage_Api_Model_Acl_Resource
  • Mage_Api_Model_Acl_Role
  • Mage_Api_Model_Acl_Role_Generic
  • Mage_Api_Model_Acl_Role_Group
  • Mage_Api_Model_Acl_Role_Registry
  • Mage_Api_Model_Acl_Role_User
  • Mage_Api_Model_Config
  • Mage_Api_Model_Mysql4_Acl
  • Mage_Api_Model_Mysql4_Acl_Role
  • Mage_Api_Model_Mysql4_Acl_Role_Collection
  • Mage_Api_Model_Mysql4_Permissions_Collection
  • Mage_Api_Model_Mysql4_Role
  • Mage_Api_Model_Mysql4_Role_Collection
  • Mage_Api_Model_Mysql4_Roles
  • Mage_Api_Model_Mysql4_Roles_Collection
  • Mage_Api_Model_Mysql4_Roles_User_Collection
  • Mage_Api_Model_Mysql4_Rules
  • Mage_Api_Model_Mysql4_Rules_Collection
  • Mage_Api_Model_Mysql4_User
  • Mage_Api_Model_Mysql4_User_Collection
  • Mage_Api_Model_Resource_Abstract
  • Mage_Api_Model_Resource_Acl
  • Mage_Api_Model_Resource_Acl_Role
  • Mage_Api_Model_Resource_Acl_Role_Collection
  • Mage_Api_Model_Resource_Permissions_Collection
  • Mage_Api_Model_Resource_Role
  • Mage_Api_Model_Resource_Role_Collection
  • Mage_Api_Model_Resource_Roles
  • Mage_Api_Model_Resource_Roles_Collection
  • Mage_Api_Model_Resource_Roles_User_Collection
  • Mage_Api_Model_Resource_Rules
  • Mage_Api_Model_Resource_Rules_Collection
  • Mage_Api_Model_Resource_User
  • Mage_Api_Model_Resource_User_Collection
  • Mage_Api_Model_Role
  • Mage_Api_Model_Roles
  • Mage_Api_Model_Rules
  • Mage_Api_Model_Server
  • Mage_Api_Model_Server_Adapter_Soap
  • Mage_Api_Model_Server_Adapter_Xmlrpc
  • Mage_Api_Model_Server_Handler
  • Mage_Api_Model_Server_Handler_Abstract
  • Mage_Api_Model_Server_V2_Adapter_Soap
  • Mage_Api_Model_Server_V2_Handler
  • Mage_Api_Model_Server_WSI_Adapter_Soap
  • Mage_Api_Model_Server_WSI_Handler
  • Mage_Api_Model_Session
  • Mage_Api_Model_User
  • Mage_Api_Model_Wsdl_Config
  • Mage_Api_Model_Wsdl_Config_Base
  • Mage_Api_SoapController
  • Mage_Api_V2_SoapController
  • Mage_Api_XmlrpcController

Interfaces

  • Mage_Api_Model_Server_Adapter_Interface

Exceptions

  • Mage_Api_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_Api
 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:  * Web service api main helper
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Api
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Api_Helper_Data extends Mage_Core_Helper_Abstract
 35: {
 36:     const XML_PATH_API_WSI = 'api/config/compliance_wsi';
 37: 
 38:     /**
 39:      * Method to find adapter code depending on WS-I compatibility setting
 40:      *
 41:      * @return string
 42:      */
 43:     public function getV2AdapterCode()
 44:     {
 45:         return $this->isComplianceWSI() ? 'soap_wsi' : 'soap_v2';
 46:     }
 47: 
 48:     /**
 49:      * @return boolean
 50:      */
 51:     public function isComplianceWSI()
 52:     {
 53:         return Mage::getStoreConfig(self::XML_PATH_API_WSI);
 54:     }
 55: 
 56:     /**
 57:      * Go thru a WSI args array and turns it to correct state.
 58:      *
 59:      * @param Object $obj - Link to Object
 60:      * @return Object
 61:      */
 62:     public function wsiArrayUnpacker(&$obj)
 63:     {
 64:         if (is_object($obj)) {
 65: 
 66:             $modifiedKeys = $this->clearWsiFootprints($obj);
 67: 
 68:             foreach ($obj as $key => $value) {
 69:                 if (is_object($value)) {
 70:                     $this->wsiArrayUnpacker($value);
 71:                 }
 72:                 if (is_array($value)) {
 73:                     foreach ($value as &$val) {
 74:                         if (is_object($val)) {
 75:                             $this->wsiArrayUnpacker($val);
 76:                         }
 77:                     }
 78:                 }
 79:             }
 80: 
 81:             foreach ($modifiedKeys as $arrKey) {
 82:                 $this->associativeArrayUnpack($obj->$arrKey);
 83:             }
 84:         }
 85:     }
 86: 
 87:     /**
 88:      * Go thru an object parameters and unpak associative object to array.
 89:      *
 90:      * @param Object $obj - Link to Object
 91:      * @return Object
 92:      */
 93:     public function v2AssociativeArrayUnpacker(&$obj)
 94:     {
 95:         if (is_object($obj)
 96:             && property_exists($obj, 'key')
 97:             && property_exists($obj, 'value')
 98:         ) {
 99:             if (count(array_keys(get_object_vars($obj))) == 2) {
100:                 $obj = array($obj->key => $obj->value);
101:                 return true;
102:             }
103:         } elseif (is_array($obj)) {
104:             $arr = array();
105:             $needReplacement = true;
106:             foreach ($obj as $key => &$value) {
107:                 $isAssoc = $this->v2AssociativeArrayUnpacker($value);
108:                 if ($isAssoc) {
109:                     foreach ($value as $aKey => $aVal) {
110:                         $arr[$aKey] = $aVal;
111:                     }
112:                 } else {
113:                     $needReplacement = false;
114:                 }
115:             }
116:             if ($needReplacement) {
117:                 $obj = $arr;
118:             }
119:         } elseif (is_object($obj)) {
120:             $objectKeys = array_keys(get_object_vars($obj));
121: 
122:             foreach ($objectKeys as $key) {
123:                 $this->v2AssociativeArrayUnpacker($obj->$key);
124:             }
125:         }
126:         return false;
127:     }
128: 
129:     /**
130:      * Go thru mixed and turns it to a correct look.
131:      *
132:      * @param Mixed $mixed A link to variable that may contain associative array.
133:      */
134:     public function associativeArrayUnpack(&$mixed)
135:     {
136:         if (is_array($mixed)) {
137:             $tmpArr = array();
138:             foreach ($mixed as $key => $value) {
139:                 if (is_object($value)) {
140:                     $value = get_object_vars($value);
141:                     if (count($value) == 2 && isset($value['key']) && isset($value['value'])) {
142:                         $tmpArr[$value['key']] = $value['value'];
143:                     }
144:                 }
145:             }
146:             if (count($tmpArr)) {
147:                 $mixed = $tmpArr;
148:             }
149:         }
150: 
151:         if (is_object($mixed)) {
152:             $numOfVals = count(get_object_vars($mixed));
153:             if ($numOfVals == 2 && isset($mixed->key) && isset($mixed->value)) {
154:                 $mixed = get_object_vars($mixed);
155:                 /*
156:                  * Processing an associative arrays.
157:                  * $mixed->key = '2'; $mixed->value = '3'; turns to array(2 => '3');
158:                  */
159:                 $mixed = array($mixed['key'] => $mixed['value']);
160:             }
161:         }
162:     }
163: 
164:     /**
165:      * Corrects data representation.
166:      *
167:      * @param Object $obj - Link to Object
168:      * @return Object
169:      */
170:     public function clearWsiFootprints(&$obj)
171:     {
172:         $modifiedKeys = array();
173: 
174:         $objectKeys = array_keys(get_object_vars($obj));
175: 
176:         foreach ($objectKeys as $key) {
177:             if (is_object($obj->$key) && isset($obj->$key->complexObjectArray)) {
178:                 if (is_array($obj->$key->complexObjectArray)) {
179:                     $obj->$key = $obj->$key->complexObjectArray;
180:                 } else { // for one element array
181:                     $obj->$key = array($obj->$key->complexObjectArray);
182:                 }
183:                 $modifiedKeys[] = $key;
184:             }
185:         }
186:         return $modifiedKeys;
187:     }
188: 
189:     /**
190:      * For the WSI, generates an response object.
191:      *
192:      * @param mixed $mixed - Link to Object
193:      * @return mixed
194:      */
195:     public function wsiArrayPacker($mixed)
196:     {
197:         if (is_array($mixed)) {
198:             $arrKeys = array_keys($mixed);
199:             $isDigit = false;
200:             $isString = false;
201:             foreach ($arrKeys as $key) {
202:                 if (is_int($key)) {
203:                     $isDigit = true;
204:                     break;
205:                 }
206:             }
207:             if ($isDigit) {
208:                 $mixed = $this->packArrayToObjec($mixed);
209:             } else {
210:                 $mixed = (object) $mixed;
211:             }
212:         }
213:         if (is_object($mixed) && isset($mixed->complexObjectArray)) {
214:             foreach ($mixed->complexObjectArray as $k => $v) {
215:                 $mixed->complexObjectArray[$k] = $this->wsiArrayPacker($v);
216:             }
217:         }
218:         return $mixed;
219:     }
220: 
221:     /**
222:      * For response to the WSI, generates an object from array.
223:      *
224:      * @param Array $arr - Link to Object
225:      * @return Object
226:      */
227:     public function packArrayToObjec(Array $arr)
228:     {
229:         $obj = new stdClass();
230:         $obj->complexObjectArray = $arr;
231:         return $obj;
232:     }
233: 
234:     /**
235:      * Convert objects and arrays to array recursively
236:      *
237:      * @param  array|object $data
238:      * @return void
239:      */
240:     public function toArray(&$data)
241:     {
242:         if (is_object($data)) {
243:             $data = get_object_vars($data);
244:         }
245:         if (is_array($data)) {
246:             foreach ($data as &$value) {
247:                 if (is_array($value) or is_object($value)) {
248:                     $this->toArray($value);
249:                 }
250:             }
251:         }
252:     }
253: 
254:     /**
255:      * Parse filters and format them to be applicable for collection filtration
256:      *
257:      * @param null|object|array $filters
258:      * @param array $fieldsMap Map of field names in format: array('field_name_in_filter' => 'field_name_in_db')
259:      * @return array
260:      */
261:     public function parseFilters($filters, $fieldsMap = null)
262:     {
263:         // if filters are used in SOAP they must be represented in array format to be used for collection filtration
264:         if (is_object($filters)) {
265:             $parsedFilters = array();
266:             // parse simple filter
267:             if (isset($filters->filter) && is_array($filters->filter)) {
268:                 foreach ($filters->filter as $field => $value) {
269:                     if (is_object($value) && isset($value->key) && isset($value->value)) {
270:                         $parsedFilters[$value->key] = $value->value;
271:                     } else {
272:                         $parsedFilters[$field] = $value;
273:                     }
274:                 }
275:             }
276:             // parse complex filter
277:             if (isset($filters->complex_filter) && is_array($filters->complex_filter)) {
278:                 if ($this->isComplianceWSI()) {
279:                     // WS-I compliance mode
280:                     foreach ($filters->complex_filter as $fieldName => $condition) {
281:                         if (is_object($condition) && isset($condition->key) && isset($condition->value)) {
282:                             $conditionName = $condition->key;
283:                             $conditionValue = $condition->value;
284:                             $this->formatFilterConditionValue($conditionName, $conditionValue);
285:                             $parsedFilters[$fieldName] = array($conditionName => $conditionValue);
286:                         }
287:                     }
288:                 } else {
289:                     // non WS-I compliance mode
290:                     foreach ($filters->complex_filter as $value) {
291:                         if (is_object($value) && isset($value->key) && isset($value->value)) {
292:                             $fieldName = $value->key;
293:                             $condition = $value->value;
294:                             if (is_object($condition) && isset($condition->key) && isset($condition->value)) {
295:                                 $this->formatFilterConditionValue($condition->key, $condition->value);
296:                                 $parsedFilters[$fieldName] = array($condition->key => $condition->value);
297:                             }
298:                         }
299:                     }
300:                 }
301:             }
302:             $filters = $parsedFilters;
303:         }
304:         // make sure that method result is always array
305:         if (!is_array($filters)) {
306:             $filters = array();
307:         }
308:         // apply fields mapping
309:         if (isset($fieldsMap) && is_array($fieldsMap)) {
310:             foreach ($filters as $field => $value) {
311:                 if (isset($fieldsMap[$field])) {
312:                     unset($filters[$field]);
313:                     $field = $fieldsMap[$field];
314:                     $filters[$field] = $value;
315:                 }
316:             }
317:         }
318:         return $filters;
319:     }
320: 
321:     /**
322:      * Convert condition value from the string into the array
323:      * for the condition operators that require value to be an array.
324:      * Condition value is changed by reference
325:      *
326:      * @param string $conditionOperator
327:      * @param string $conditionValue
328:      */
329:     public function formatFilterConditionValue($conditionOperator, &$conditionValue)
330:     {
331:         if (is_string($conditionOperator) && in_array($conditionOperator, array('in', 'nin', 'finset'))
332:             && is_string($conditionValue)
333:         ) {
334:             $delimiter = ',';
335:             $conditionValue = explode($delimiter, $conditionValue);
336:         }
337:     }
338: }
339: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0