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 apia2 route abstract
29: *
30: * @category Mage
31: * @package Mage_Api2
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Api2_Model_Route_Abstract extends Zend_Controller_Router_Route
35: {
36: /**#@+
37: * Names for Zend_Controller_Router_Route::__construct params
38: */
39: const PARAM_ROUTE = 'route';
40: const PARAM_DEFAULTS = 'defaults';
41: const PARAM_REQS = 'reqs';
42: const PARAM_TRANSLATOR = 'translator';
43: const PARAM_LOCALE = 'locale';
44: /**#@- */
45:
46: /*
47: * Default values of parent::__construct() params
48: *
49: * @var array
50: */
51: protected $_paramsDefaultValues = array(
52: self::PARAM_ROUTE => null,
53: self::PARAM_DEFAULTS => array(),
54: self::PARAM_REQS => array(),
55: self::PARAM_TRANSLATOR => null,
56: self::PARAM_LOCALE => null
57: );
58:
59: /**
60: * Process construct param and call parent::__construct() with params
61: *
62: * @param array $arguments
63: */
64: public function __construct(array $arguments)
65: {
66: parent::__construct(
67: $this->_getArgumentValue(self::PARAM_ROUTE, $arguments),
68: $this->_getArgumentValue(self::PARAM_DEFAULTS, $arguments),
69: $this->_getArgumentValue(self::PARAM_REQS, $arguments),
70: $this->_getArgumentValue(self::PARAM_TRANSLATOR, $arguments),
71: $this->_getArgumentValue(self::PARAM_LOCALE, $arguments)
72: );
73: }
74:
75: /**
76: * Retrieve argument value
77: *
78: * @param string $name argument name
79: * @param array $arguments
80: * @return mixed
81: */
82: protected function _getArgumentValue($name, array $arguments)
83: {
84: return isset($arguments[$name]) ? $arguments[$name] : $this->_paramsDefaultValues[$name];
85: }
86:
87: /**
88: * Matches a Request with parts defined by a map. Assigns and
89: * returns an array of variables on a successful match.
90: *
91: * @param Mage_Api2_Model_Request $request
92: * @param boolean $partial Partial path matching
93: * @return array|bool An array of assigned values or a boolean false on a mismatch
94: */
95: public function match($request, $partial = false)
96: {
97: return parent::match(ltrim($request->getPathInfo(), $this->_urlDelimiter), $partial);
98: }
99: }
100: