/** * Construct. Set all depends. * * Required parameteres for options: * - resource * * @param array $options * @throws Exception If passed parameter 'resource' is wrong */ public function __construct($options) { if (!isset($options['resource']) || !$options['resource'] instanceof Mage_Api2_Model_Resource) { throw new Exception("Passed parameter 'resource' is wrong."); } $this->_resource = $options['resource']; $validationConfig = $this->_resource->getConfig()->getValidationConfig($this->_resource->getResourceType(), self::CONFIG_NODE_KEY); if (!is_array($validationConfig)) { $validationConfig = array(); } $this->_buildValidatorsChain($validationConfig); }
/** * Fetch array of allowed attributes for given resource type, operation and user type. * * @param string $operationType OPTIONAL One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant * @return array */ public function getAllowedAttributes($operationType = null) { if (null === $this->_allowedAttributes) { /** @var $helper Mage_Api2_Helper_Data */ $helper = Mage::helper('api2/data'); if (null === $operationType) { $operationType = $helper->getTypeOfOperation($this->_resource->getOperation()); } if ($helper->isAllAttributesAllowed($this->_resource->getUserType())) { $this->_allowedAttributes = array_keys($this->_resource->getAvailableAttributes($this->_resource->getUserType(), $operationType)); } else { $this->_allowedAttributes = $helper->getAllowedAttributes($this->_resource->getUserType(), $this->_resource->getResourceType(), $operationType); } // force attributes to be no filtered foreach ($this->_resource->getForcedAttributes() as $forcedAttr) { if (!in_array($forcedAttr, $this->_allowedAttributes)) { $this->_allowedAttributes[] = $forcedAttr; } } } return $this->_allowedAttributes; }