Created
May 22, 2013 18:01
-
-
Save xcommerce-gists/5629553 to your computer and use it in GitHub Desktop.
Magento data format factory: Mage_Webhook_Model_Formatter_Factory_Interface interface for extensibility alpha-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mage_Webhook_Model_Formatter_Factory_Json implements Mage_Webhook_Model_Formatter_Factory_Interface | |
{ | |
const XML_PATH_DEFAULT_OPTIONS = 'global/webhook/formats/json/options/'; | |
protected $_config; | |
public function __construct(Mage_Core_Model_Config $config) | |
{ | |
$this->_config = $config; | |
} | |
/** | |
* @param $format string indicating the format used | |
* @return Mage_Webhook_Model_Formatter_Interface | |
*/ | |
public function getFormatter($format) | |
{ | |
$modelName = (string) $this->_config->getNode( | |
self::XML_PATH_DEFAULT_OPTIONS . 'format/' . $format . '/formatter' | |
); | |
if (!$modelName) { | |
$modelName = (string) $this->_config->getNode(self::XML_PATH_DEFAULT_OPTIONS . 'default_formatter'); | |
} | |
if (!$modelName) { | |
throw new LogicException( | |
"There is no specific formatter for the format given $format and no default formatter." | |
); | |
} | |
$formatter = $this->getModel($modelName); | |
if (!$formatter instanceof Mage_Webhook_Model_Formatter_Interface) { | |
throw new LogicException("Wrong Formatter type for the model found given the format $format."); | |
} | |
return $formatter; | |
} | |
protected function getModel($modelName) | |
{ | |
// TODO: probably here we should pass only format configuration options | |
return Mage::getModel($modelName, $this->_config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment