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:  * Webservice api2 config model
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Api2
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Api2_Model_Config extends Varien_Simplexml_Config
 35: {
 36:     /**
 37:      * Node name of resource groups
 38:      */
 39:     const NODE_RESOURCE_GROUPS = 'resource_groups';
 40: 
 41:     /**
 42:      * Id for config cache
 43:      */
 44:     const CACHE_ID  = 'config_api2';
 45: 
 46:     /**
 47:      * Tag name for config cache
 48:      */
 49:     const CACHE_TAG = 'CONFIG_API2';
 50: 
 51:     /**
 52:      * Is resources added to group
 53:      *
 54:      * @var boolean
 55:      */
 56:     protected $_resourcesGrouped = false;
 57: 
 58:     /**
 59:      * Constructor
 60:      * Initializes XML for this configuration
 61:      * Local cache configuration
 62:      *
 63:      * @param string|Varien_Simplexml_Element|null $sourceData
 64:      */
 65:     public function __construct($sourceData = null)
 66:     {
 67:         parent::__construct($sourceData);
 68: 
 69:         $canUserCache = Mage::app()->useCache('config');
 70:         if ($canUserCache) {
 71:             $this->setCacheId(self::CACHE_ID)
 72:                 ->setCacheTags(array(self::CACHE_TAG))
 73:                 ->setCacheChecksum(null)
 74:                 ->setCache(Mage::app()->getCache());
 75: 
 76:             if ($this->loadCache()) {
 77:                 return;
 78:             }
 79:         }
 80: 
 81:         // Load data of config files api2.xml
 82:         $config = Mage::getConfig()->loadModulesConfiguration('api2.xml');
 83:         $this->setXml($config->getNode('api2'));
 84: 
 85:         if ($canUserCache) {
 86:             $this->saveCache();
 87:         }
 88:     }
 89: 
 90:     /**
 91:      * Fetch all routes of the given api type from config files api2.xml
 92:      *
 93:      * @param string $apiType
 94:      * @throws Mage_Api2_Exception
 95:      * @return array
 96:      */
 97:     public function getRoutes($apiType)
 98:     {
 99:         /** @var $helper Mage_Api2_Helper_Data */
100:         $helper = Mage::helper('api2');
101:         if (!$helper->isApiTypeSupported($apiType)) {
102:             throw new Mage_Api2_Exception(sprintf('API type "%s" is not supported', $apiType),
103:                 Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
104:         }
105: 
106:         $routes = array();
107:         foreach ($this->getResources() as $resourceKey => $resource) {
108:             if (!$resource->routes) {
109:                 continue;
110:             }
111: 
112:             /** @var $routes Varien_Simplexml_Element */
113:             foreach ($resource->routes->children() as $route) {
114:                 $arguments = array(
115:                     Mage_Api2_Model_Route_Abstract::PARAM_ROUTE    => (string)$route->route,
116:                     Mage_Api2_Model_Route_Abstract::PARAM_DEFAULTS => array(
117:                         'model'       => (string)$resource->model,
118:                         'type'        => (string)$resourceKey,
119:                         'action_type' => (string)$route->action_type
120:                     )
121:                 );
122: 
123:                 $routes[] = Mage::getModel('api2/route_' . $apiType, $arguments);
124:             }
125:         }
126:         return $routes;
127:     }
128: 
129:     /**
130:      * Retrieve all resources from config files api2.xml
131:      *
132:      * @return Varien_Simplexml_Element
133:      */
134:     public function getResources()
135:     {
136:         return $this->getNode('resources')->children();
137:     }
138: 
139:     /**
140:      * Retrieve all resources types
141:      *
142:      * @return array
143:      */
144:     public function getResourcesTypes()
145:     {
146:         $list = array();
147: 
148:         foreach ($this->getResources() as $resourceType => $resourceCfg) {
149:             $list[] = (string) $resourceType;
150:         }
151:         return $list;
152:     }
153: 
154:     /**
155:      * Retrieve all resource groups from config files api2.xml
156:      *
157:      * @return Varien_Simplexml_Element|boolean
158:      */
159:     public function getResourceGroups()
160:     {
161:         $groups = $this->getXpath('//' . self::NODE_RESOURCE_GROUPS);
162:         if (!$groups) {
163:             return false;
164:         }
165: 
166:         /** @var $groups Varien_Simplexml_Element */
167:         $groups = $groups[0];
168: 
169:         if (!$this->_resourcesGrouped) {
170:             /** @var $node Varien_Simplexml_Element */
171:             foreach ($this->getResources() as $node) {
172:                 $result = $node->xpath('group');
173:                 if (!$result) {
174:                     continue;
175:                 }
176:                 $groupName = (string) $result[0];
177:                 if ($groupName) {
178:                     $result = $groups->xpath('.//' . $groupName);
179:                     if (!$result) {
180:                         continue;
181:                     }
182: 
183:                     /** @var $group Varien_Simplexml_Element */
184:                     $group = $result[0];
185: 
186:                     if (!isset($group->children)) {
187:                         $children = new Varien_Simplexml_Element('<children />');
188:                     } else {
189:                         $children = $group->children;
190:                     }
191:                     $node->resource = 1;
192:                     $children->appendChild($node);
193:                     $group->appendChild($children);
194:                 }
195:             }
196:         }
197:         return $groups;
198:     }
199: 
200:     /**
201:      * Retrieve resource group from config files api2.xml
202:      *
203:      * @param string $name
204:      * @return Mage_Core_Model_Config_Element|boolean
205:      */
206:     public function getResourceGroup($name)
207:     {
208:         $group = $this->getResourceGroups()->xpath('.//' . $name);
209:         if (!$group) {
210:             return false;
211:         }
212:         return $group[0];
213:     }
214: 
215:     /**
216:      * Retrieve resource by type (node)
217:      *
218:      * @param string $node
219:      * @return Varien_Simplexml_Element|boolean
220:      */
221:     public function getResource($node)
222:     {
223:         return $this->getNode('resources/' . $node);
224:     }
225: 
226:     /**
227:      * Retrieve resource attributes
228:      *
229:      * @param string $node
230:      * @return array
231:      */
232:     public function getResourceAttributes($node)
233:     {
234:         $attributes = $this->getNode('resources/' . $node . '/attributes');
235:         return $attributes ? $attributes->asCanonicalArray() : array();
236:     }
237: 
238:     /**
239:      * Get excluded attributes of API resource
240:      *
241:      * @param string $resource
242:      * @param string $userType
243:      * @param string $operation
244:      * @return array
245:      */
246:     public function getResourceExcludedAttributes($resource, $userType, $operation)
247:     {
248:         $node = $this->getNode('resources/' . $resource . '/exclude_attributes/' . $userType . '/' . $operation);
249:         $exclAttributes = array();
250: 
251:         if ($node) {
252:             foreach ($node->children() as $attribute => $status) {
253:                 if ((string) $status) {
254:                     $exclAttributes[] = $attribute;
255:                 }
256:             }
257:         }
258:         return $exclAttributes;
259:     }
260: 
261:     /**
262:      * Get forced attributes of API resource
263:      *
264:      * @param string $resource
265:      * @param string $userType
266:      * @return array
267:      */
268:     public function getResourceForcedAttributes($resource, $userType)
269:     {
270:         $node = $this->getNode('resources/' . $resource . '/force_attributes/' . $userType);
271:         $forcedAttributes = array();
272: 
273:         if ($node) {
274:             foreach ($node->children() as $attribute => $status) {
275:                 if ((string) $status) {
276:                     $forcedAttributes[] = $attribute;
277:                 }
278:             }
279:         }
280:         return $forcedAttributes;
281:     }
282: 
283:     /**
284:      * Get included attributes
285:      *
286:      * @param string $resource API resource ID
287:      * @param string $userType API user type
288:      * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
289:      * @return array
290:      */
291:     public function getResourceIncludedAttributes($resource, $userType, $operationType)
292:     {
293:         $node = $this->getNode('resources/' . $resource . '/include_attributes/' . $userType . '/' . $operationType);
294:         $inclAttributes = array();
295: 
296:         if ($node) {
297:             foreach ($node->children() as $attribute => $status) {
298:                 if ((string) $status) {
299:                     $inclAttributes[] = $attribute;
300:                 }
301:             }
302:         }
303:         return $inclAttributes;
304:     }
305: 
306:     /**
307:      * Get entity only attributes
308:      *
309:      * @param string $resource API resource ID
310:      * @param string $userType API user type
311:      * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
312:      * @return array
313:      */
314:     public function getResourceEntityOnlyAttributes($resource, $userType, $operationType)
315:     {
316:         $node = $this->getNode('resources/' . $resource . '/entity_only_attributes/' . $userType . '/' .
317:             $operationType);
318:         $entityOnlyAttributes = array();
319: 
320:         if ($node) {
321:             foreach ($node->children() as $attribute => $status) {
322:                 if ((string) $status) {
323:                     $entityOnlyAttributes[] = $attribute;
324:                 }
325:             }
326:         }
327:         return $entityOnlyAttributes;
328:     }
329: 
330:     /**
331:      * Retrieve resource working model
332:      *
333:      * @param string $node
334:      * @return string
335:      */
336:     public function getResourceWorkingModel($node)
337:     {
338:         return (string)$this->getNode('resources/' . $node . '/working_model');
339:     }
340: 
341:     /**
342:      * Get resource allowed versions sorted in reverse order
343:      *
344:      * @param string $node
345:      * @return array
346:      * @throws Exception
347:      */
348:     public function getVersions($node)
349:     {
350:         $element = $this->getNode('resources/' . $node . '/versions');
351:         if (!$element) {
352:             throw new Exception(
353:                 sprintf('Resource "%s" does not have node <versions> in config.', htmlspecialchars($node))
354:             );
355:         }
356: 
357:         $versions = explode(',', (string)$element);
358:         if (count(array_filter($versions, 'is_numeric')) != count($versions)) {
359:             throw new Exception(sprintf('Invalid resource "%s" versions in config.', htmlspecialchars($node)));
360:         }
361: 
362:         rsort($versions, SORT_NUMERIC);
363: 
364:         return $versions;
365:     }
366: 
367:     /**
368:      * Retrieve resource model
369:      *
370:      * @param string $node
371:      * @return string
372:      */
373:     public function getResourceModel($node)
374:     {
375:         return (string)$this->getNode('resources/' . $node . '/model');
376:     }
377: 
378:     /**
379:      * Retrieve API user privileges for specified resource
380:      *
381:      * @param string $resource
382:      * @param string $userType
383:      * @return array
384:      */
385:     public function getResourceUserPrivileges($resource, $userType)
386:     {
387:         $attributes = $this->getNode('resources/' . $resource . '/privileges/' . $userType);
388:         return $attributes ? $attributes->asCanonicalArray() : array();
389:     }
390: 
391:     /**
392:      * Retrieve resource subresources
393:      *
394:      * @param string $node
395:      * @return array
396:      */
397:     public function getResourceSubresources($node)
398:     {
399:         $subresources = $this->getNode('resources/' . $node . '/subresources');
400:         return $subresources ? $subresources->asCanonicalArray() : array();
401:     }
402: 
403:     /**
404:      * Get validation config by validator type
405:      *
406:      * @param string $resourceType
407:      * @param string $validatorType
408:      * @return array
409:      */
410:     public function getValidationConfig($resourceType, $validatorType)
411:     {
412:         $config = $this->getNode('resources/' . $resourceType . '/validators/' . $validatorType);
413:         return $config ? $config->asCanonicalArray() : array();
414:     }
415: 
416:     /**
417:      * Get latest version of resource model. If second arg is specified - use it as a limiter
418:      *
419:      * @param string $resourceType Resource type
420:      * @param int $lowerOrEqualsTo OPTIONAL If specified - return version equal or lower to
421:      * @return int
422:      */
423:     public function getResourceLastVersion($resourceType, $lowerOrEqualsTo = null)
424:     {
425:         $availVersions = $this->getVersions($resourceType); // already ordered in reverse order
426:         $useVersion    = reset($availVersions);
427: 
428:         if (null !== $lowerOrEqualsTo) {
429:             foreach ($availVersions as $availVersion) {
430:                 if ($availVersion <= $lowerOrEqualsTo) {
431:                     $useVersion = $availVersion;
432:                     break;
433:                 }
434:             }
435:         }
436:         return (int)$useVersion;
437:     }
438: 
439:     /**
440:      * Get route with Mage_Api2_Model_Resource::ACTION_TYPE_ENTITY type
441:      *
442:      * @param string $node
443:      * @return string
444:      */
445:     public function getRouteWithEntityTypeAction($node)
446:     {
447:         return (string)$this->getNode('resources/' . $node . '/routes/route_entity/route');
448:     }
449: }
450: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0