Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created August 17, 2013 20:45
Show Gist options
  • Save ryaan-anthony/6258608 to your computer and use it in GitHub Desktop.
Save ryaan-anthony/6258608 to your computer and use it in GitHub Desktop.
Facade
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Block, that can get data from layout or from registry.
* Can compare its data values by specified keys
*
* @category Mage
* @package Mage_Core
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Core_Block_Template_Facade extends Mage_Core_Block_Template
{
/**
* Just set data, like Varien_Object
*
* This method is to be used in layout.
* In layout it can be understood better, than setSomeKeyBlahBlah()
*
* @param string $key
* @param string $value
*/
public function setDataByKey($key, $value)
{
$this->_data[$key] = $value;
}
/**
* Also set data, but take the value from registry by registry key
*
* @param string $key
* @param string $registryKey
*/
public function setDataByKeyFromRegistry($key, $registryKey)
{
$registryItem = Mage::registry($registryKey);
if (empty($registryItem)) {
return;
}
$value = $registryItem->getData($key);
$this->setDataByKey($key, $value);
}
/**
* Check if data values by specified keys are equal
* $conditionKeys can be array or arbitrary set of params (func_get_args())
*
* @param array $conditionKeys
* @return bool
*/
public function ifEquals($conditionKeys)
{
if (!is_array($conditionKeys)) {
$conditionKeys = func_get_args();
}
// evaluate conditions (equality)
if (!empty($conditionKeys)) {
foreach ($conditionKeys as $key) {
if (!isset($this->_data[$key])) {
return false;
}
}
$lastValue = $this->_data[$key];
foreach ($conditionKeys as $key) {
if ($this->_data[$key] !== $lastValue) {
return false;
}
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment