Current file: htdocs/app/code/core/Mage/Core/Model/Layout.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 25 CRAP
0.00%0.00%
0.00% 0 / 251
 
Mage_Core_Model_Layout
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 25
0.00%0.00%
0.00% 0 / 251
 __construct($data=array()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 5
 getUpdate()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 setArea($area)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getArea()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 setDirectOutput($flag)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getDirectOutput()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 generateXml()
0.00%0.00%
0.00% 0 / 1 132
0.00%0.00%
0.00% 0 / 28
 generateBlocks($parent=null)
0.00%0.00%
0.00% 0 / 1 56
0.00%0.00%
0.00% 0 / 21
 _generateBlock($node, $parent)
0.00%0.00%
0.00% 0 / 1 182
0.00%0.00%
0.00% 0 / 43
 _generateAction($node, $parent)
0.00%0.00%
0.00% 0 / 1 210
0.00%0.00%
0.00% 0 / 47
 _translateLayoutNode($node, &$args)
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 10
 setBlock($name, $block)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 unsetBlock($name)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 createBlock($type, $name='', array $attributes = array()
0.00%0.00%
0.00% 0 / 1 56
0.00%0.00%
0.00% 0 / 19
 addBlock($block, $blockName)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 _getBlockInstance($block, array $attributes=array()
0.00%0.00%
0.00% 0 / 1 56
0.00%0.00%
0.00% 0 / 14
 getAllBlocks()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getBlock($name)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 3
 addOutputBlock($blockName, $method='toHtml')
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 removeOutputBlock($blockName)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getOutput()
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 7
 getMessagesBlock()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 getBlockSingleton($type)
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 14
 helper($name)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 findTranslationModuleName(Varien_Simplexml_Element $node)
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 14


       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_Core                                                                                               
      23                 :  * @copyright   Copyright (c) 2010 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                 : /**                                                                                                                     
      29                 :  * Layout model                                                                                                         
      30                 :  *                                                                                                                      
      31                 :  * @category   Mage                                                                                                     
      32                 :  * @package    Mage_Core                                                                                                
      33                 :  */                                                                                                                     
      34                 : class Mage_Core_Model_Layout extends Varien_Simplexml_Config                                                            
      35                 : {                                                                                                                       
      36                 :                                                                                                                         
      37                 :     /**                                                                                                                 
      38                 :      * Layout Update module                                                                                             
      39                 :      *                                                                                                                  
      40                 :      * @var Mage_Core_Model_Layout_Update                                                                               
      41                 :      */                                                                                                                 
      42                 :     protected $_update;                                                                                                 
      43                 :                                                                                                                         
      44                 :     /**                                                                                                                 
      45                 :      * Blocks registry                                                                                                  
      46                 :      *                                                                                                                  
      47                 :      * @var array                                                                                                       
      48                 :      */                                                                                                                 
      49                 :     protected $_blocks = array();                                                                                       
      50                 :                                                                                                                         
      51                 :     /**                                                                                                                 
      52                 :      * Cache of block callbacks to output during rendering                                                              
      53                 :      *                                                                                                                  
      54                 :      * @var array                                                                                                       
      55                 :      */                                                                                                                 
      56                 :     protected $_output = array();                                                                                       
      57                 :                                                                                                                         
      58                 :     /**                                                                                                                 
      59                 :      * Layout area (f.e. admin, frontend)                                                                               
      60                 :      *                                                                                                                  
      61                 :      * @var string                                                                                                      
      62                 :      */                                                                                                                 
      63                 :     protected $_area;                                                                                                   
      64                 :                                                                                                                         
      65                 :     /**                                                                                                                 
      66                 :      * Helper blocks cache for this layout                                                                              
      67                 :      *                                                                                                                  
      68                 :      * @var array                                                                                                       
      69                 :      */                                                                                                                 
      70                 :     protected $_helpers = array();                                                                                      
      71                 :                                                                                                                         
      72                 :     /**                                                                                                                 
      73                 :      * Flag to have blocks' output go directly to browser as oppose to return result                                    
      74                 :      *                                                                                                                  
      75                 :      * @var boolean                                                                                                     
      76                 :      */                                                                                                                 
      77                 :     protected $_directOutput = false;                                                                                   
      78                 :                                                                                                                         
      79                 :     /**                                                                                                                 
      80                 :      * Class constructor                                                                                                
      81                 :      *                                                                                                                  
      82                 :      * @param array $data                                                                                               
      83                 :      */                                                                                                                 
      84                 :     public function __construct($data=array())                                                                          
      85                 :     {                                                                                                                   
      86               0 :         $this->_elementClass = Mage::getConfig()->getModelClassName('core/layout_element');                             
      87               0 :         $this->setXml(simplexml_load_string('<layout/>', $this->_elementClass));                                        
      88               0 :         $this->_update = Mage::getModel('core/layout_update');                                                          
      89               0 :         parent::__construct($data);                                                                                     
      90               0 :     }                                                                                                                   
      91                 :                                                                                                                         
      92                 :     /**                                                                                                                 
      93                 :      * Layout update instance                                                                                           
      94                 :      *                                                                                                                  
      95                 :      * @return Mage_Core_Model_Layout_Update                                                                            
      96                 :      */                                                                                                                 
      97                 :     public function getUpdate()                                                                                         
      98                 :     {                                                                                                                   
      99               0 :         return $this->_update;                                                                                          
     100                 :     }                                                                                                                   
     101                 :                                                                                                                         
     102                 :     /**                                                                                                                 
     103                 :      * Set layout area                                                                                                  
     104                 :      *                                                                                                                  
     105                 :      * @param   string $area                                                                                            
     106                 :      * @return  Mage_Core_Model_Layout                                                                                  
     107                 :      */                                                                                                                 
     108                 :     public function setArea($area)                                                                                      
     109                 :     {                                                                                                                   
     110               0 :         $this->_area = $area;                                                                                           
     111               0 :         return $this;                                                                                                   
     112                 :     }                                                                                                                   
     113                 :                                                                                                                         
     114                 :     /**                                                                                                                 
     115                 :      * Retrieve layout area                                                                                             
     116                 :      *                                                                                                                  
     117                 :      * @return string                                                                                                   
     118                 :      */                                                                                                                 
     119                 :     public function getArea()                                                                                           
     120                 :     {                                                                                                                   
     121               0 :         return $this->_area;                                                                                            
     122                 :     }                                                                                                                   
     123                 :                                                                                                                         
     124                 :     /**                                                                                                                 
     125                 :      * Declaring layout direct output flag                                                                              
     126                 :      *                                                                                                                  
     127                 :      * @param   bool $flag                                                                                              
     128                 :      * @return  Mage_Core_Model_Layout                                                                                  
     129                 :      */                                                                                                                 
     130                 :     public function setDirectOutput($flag)                                                                              
     131                 :     {                                                                                                                   
     132               0 :         $this->_directOutput = $flag;                                                                                   
     133               0 :         return $this;                                                                                                   
     134                 :     }                                                                                                                   
     135                 :                                                                                                                         
     136                 :     /**                                                                                                                 
     137                 :      * Retrieve derect output flag                                                                                      
     138                 :      *                                                                                                                  
     139                 :      * @return bool                                                                                                     
     140                 :      */                                                                                                                 
     141                 :     public function getDirectOutput()                                                                                   
     142                 :     {                                                                                                                   
     143               0 :         return $this->_directOutput;                                                                                    
     144                 :     }                                                                                                                   
     145                 :                                                                                                                         
     146                 :     /**                                                                                                                 
     147                 :      * Loyout xml generation                                                                                            
     148                 :      *                                                                                                                  
     149                 :      * @return Mage_Core_Model_Layout                                                                                   
     150                 :      */                                                                                                                 
     151                 :     public function generateXml()                                                                                       
     152                 :     {                                                                                                                   
     153               0 :         $xml = $this->getUpdate()->asSimplexml();                                                                       
     154               0 :         $removeInstructions = $xml->xpath("//remove");                                                                  
     155               0 :         if (is_array($removeInstructions)) {                                                                            
     156               0 :             foreach ($removeInstructions as $infoNode) {                                                                
     157               0 :                 $attributes = $infoNode->attributes();                                                                  
     158               0 :                 $blockName = (string)$attributes->name;                                                                 
     159               0 :                 if ($blockName) {                                                                                       
     160               0 :                     $ignoreNodes = $xml->xpath("//block[@name='".$blockName."']");                                      
     161               0 :                     if (!is_array($ignoreNodes)) {                                                                      
     162               0 :                         continue;                                                                                       
     163                 :                     }                                                                                                   
     164               0 :                     $ignoreReferences = $xml->xpath("//reference[@name='".$blockName."']");                             
     165               0 :                     if (is_array($ignoreReferences)) {                                                                  
     166               0 :                         $ignoreNodes = array_merge($ignoreNodes, $ignoreReferences);                                    
     167               0 :                     }                                                                                                   
     168                 :                                                                                                                         
     169               0 :                     foreach ($ignoreNodes as $block) {                                                                  
     170               0 :                         if ($block->getAttribute('ignore') !== null) {                                                  
     171               0 :                             continue;                                                                                   
     172                 :                         }                                                                                               
     173               0 :                         if (($acl = (string)$attributes->acl) && Mage::getSingleton('admin/session')->isAllowed($acl)) {
     174               0 :                             continue;                                                                                   
     175                 :                         }                                                                                               
     176               0 :                         if (!isset($block->attributes()->ignore)) {                                                     
     177               0 :                             $block->addAttribute('ignore', true);                                                       
     178               0 :                         }                                                                                               
     179               0 :                     }                                                                                                   
     180               0 :                 }                                                                                                       
     181               0 :             }                                                                                                           
     182               0 :         }                                                                                                               
     183               0 :         $this->setXml($xml);                                                                                            
     184               0 :         return $this;                                                                                                   
     185                 :     }                                                                                                                   
     186                 :                                                                                                                         
     187                 :     /**                                                                                                                 
     188                 :      * Create layout blocks hierarchy from layout xml configuration                                                     
     189                 :      *                                                                                                                  
     190                 :      * @param Mage_Core_Layout_Element|null $parent                                                                     
     191                 :      */                                                                                                                 
     192                 :     public function generateBlocks($parent=null)                                                                        
     193                 :     {                                                                                                                   
     194               0 :         if (empty($parent)) {                                                                                           
     195               0 :             $parent = $this->getNode();                                                                                 
     196               0 :         }                                                                                                               
     197               0 :         foreach ($parent as $node) {                                                                                    
     198               0 :             $attributes = $node->attributes();                                                                          
     199               0 :             if ((bool)$attributes->ignore) {                                                                            
     200               0 :                 continue;                                                                                               
     201                 :             }                                                                                                           
     202               0 :             switch ($node->getName()) {                                                                                 
     203               0 :                 case 'block':                                                                                           
     204               0 :                     $this->_generateBlock($node, $parent);                                                              
     205               0 :                     $this->generateBlocks($node);                                                                       
     206               0 :                     break;                                                                                              
     207                 :                                                                                                                         
     208               0 :                 case 'reference':                                                                                       
     209               0 :                     $this->generateBlocks($node);                                                                       
     210               0 :                     break;                                                                                              
     211                 :                                                                                                                         
     212               0 :                 case 'action':                                                                                          
     213               0 :                     $this->_generateAction($node, $parent);                                                             
     214               0 :                     break;                                                                                              
     215               0 :             }                                                                                                           
     216               0 :         }                                                                                                               
     217               0 :     }                                                                                                                   
     218                 :                                                                                                                         
     219                 :     /**                                                                                                                 
     220                 :      * Add block object to layout based on xml node data                                                                
     221                 :      *                                                                                                                  
     222                 :      * @param Varien_Simplexml_Element $node                                                                            
     223                 :      * @param Varien_Simplexml_Element $parent                                                                          
     224                 :      * @return Mage_Core_Model_Layout                                                                                   
     225                 :      */                                                                                                                 
     226                 :     protected function _generateBlock($node, $parent)                                                                   
     227                 :     {                                                                                                                   
     228               0 :         if (!empty($node['class'])) {                                                                                   
     229               0 :             $className = (string)$node['class'];                                                                        
     230               0 :         } else {                                                                                                        
     231               0 :             $className = (string)$node['type'];                                                                         
     232                 :         }                                                                                                               
     233                 :                                                                                                                         
     234               0 :         $blockName = (string)$node['name'];                                                                             
     235               0 :         $_profilerKey = 'BLOCK: '.$blockName;                                                                           
     236               0 :         Varien_Profiler::start($_profilerKey);                                                                          
     237                 :                                                                                                                         
     238               0 :         $block = $this->addBlock($className, $blockName);                                                               
     239               0 :         if (!$block) {                                                                                                  
     240               0 :             return $this;                                                                                               
     241                 :         }                                                                                                               
     242                 :                                                                                                                         
     243               0 :         if (!empty($node['parent'])) {                                                                                  
     244               0 :             $parentBlock = $this->getBlock((string)$node['parent']);                                                    
     245               0 :         } else {                                                                                                        
     246               0 :             $parentName = $parent->getBlockName();                                                                      
     247               0 :             if (!empty($parentName)) {                                                                                  
     248               0 :                 $parentBlock = $this->getBlock($parentName);                                                            
     249               0 :             }                                                                                                           
     250                 :         }                                                                                                               
     251               0 :         if (!empty($parentBlock)) {                                                                                     
     252               0 :             $alias = isset($node['as']) ? (string)$node['as'] : '';                                                     
     253               0 :             if (isset($node['before'])) {                                                                               
     254               0 :                 $sibling = (string)$node['before'];                                                                     
     255               0 :                 if ('-'===$sibling) {                                                                                   
     256               0 :                     $sibling = '';                                                                                      
     257               0 :                 }                                                                                                       
     258               0 :                 $parentBlock->insert($block, $sibling, false, $alias);                                                  
     259               0 :             } elseif (isset($node['after'])) {                                                                          
     260               0 :                 $sibling = (string)$node['after'];                                                                      
     261               0 :                 if ('-'===$sibling) {                                                                                   
     262               0 :                     $sibling = '';                                                                                      
     263               0 :                 }                                                                                                       
     264               0 :                 $parentBlock->insert($block, $sibling, true, $alias);                                                   
     265               0 :             } else {                                                                                                    
     266               0 :                 $parentBlock->append($block, $alias);                                                                   
     267                 :             }                                                                                                           
     268               0 :         }                                                                                                               
     269               0 :         if (!empty($node['template'])) {                                                                                
     270               0 :             $block->setTemplate((string)$node['template']);                                                             
     271               0 :         }                                                                                                               
     272                 :                                                                                                                         
     273               0 :         if (!empty($node['output'])) {                                                                                  
     274               0 :             $method = (string)$node['output'];                                                                          
     275               0 :             $this->addOutputBlock($blockName, $method);                                                                 
     276               0 :         }                                                                                                               
     277               0 :         Varien_Profiler::stop($_profilerKey);                                                                           
     278                 :                                                                                                                         
     279               0 :         return $this;                                                                                                   
     280                 :     }                                                                                                                   
     281                 :                                                                                                                         
     282                 :     /**                                                                                                                 
     283                 :      * Enter description here...                                                                                        
     284                 :      *                                                                                                                  
     285                 :      * @param Varien_Simplexml_Element $node                                                                            
     286                 :      * @param Varien_Simplexml_Element $parent                                                                          
     287                 :      * @return Mage_Core_Model_Layout                                                                                   
     288                 :      */                                                                                                                 
     289                 :     protected function _generateAction($node, $parent)                                                                  
     290                 :     {                                                                                                                   
     291               0 :         if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {                                    
     292               0 :             if (!Mage::getStoreConfigFlag($configPath)) {                                                               
     293               0 :                 return $this;                                                                                           
     294                 :             }                                                                                                           
     295               0 :         }                                                                                                               
     296                 :                                                                                                                         
     297               0 :         $method = (string)$node['method'];                                                                              
     298               0 :         if (!empty($node['block'])) {                                                                                   
     299               0 :             $parentName = (string)$node['block'];                                                                       
     300               0 :         } else {                                                                                                        
     301               0 :             $parentName = $parent->getBlockName();                                                                      
     302                 :         }                                                                                                               
     303                 :                                                                                                                         
     304               0 :         $_profilerKey = 'BLOCK ACTION: '.$parentName.' -> '.$method;                                                    
     305               0 :         Varien_Profiler::start($_profilerKey);                                                                          
     306                 :                                                                                                                         
     307               0 :         if (!empty($parentName)) {                                                                                      
     308               0 :             $block = $this->getBlock($parentName);                                                                      
     309               0 :         }                                                                                                               
     310               0 :         if (!empty($block)) {                                                                                           
     311                 :                                                                                                                         
     312               0 :             $args = (array)$node->children();                                                                           
     313               0 :             unset($args['@attributes']);                                                                                
     314                 :                                                                                                                         
     315               0 :             foreach ($args as $key => $arg) {                                                                           
     316               0 :                 if (($arg instanceof Mage_Core_Model_Layout_Element)) {                                                 
     317               0 :                     if (isset($arg['helper'])) {                                                                        
     318               0 :                         $helperName = explode('/', (string)$arg['helper']);                                             
     319               0 :                         $helperMethod = array_pop($helperName);                                                         
     320               0 :                         $helperName = implode('/', $helperName);                                                        
     321               0 :                         $arg = $arg->asArray();                                                                         
     322               0 :                         unset($arg['@']);                                                                               
     323               0 :                         $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg);      
     324               0 :                     } else {                                                                                            
     325                 :                         /**                                                                                             
     326                 :                          * if there is no helper we hope that this is assoc array                                       
     327                 :                          */                                                                                             
     328               0 :                         $arr = array();                                                                                 
     329               0 :                         foreach($arg as $subkey => $value) {                                                            
     330               0 :                             $arr[(string)$subkey] = $value->asArray();                                                  
     331               0 :                         }                                                                                               
     332               0 :                         if (!empty($arr)) {                                                                             
     333               0 :                             $args[$key] = $arr;                                                                         
     334               0 :                         }                                                                                               
     335                 :                     }                                                                                                   
     336               0 :                 }                                                                                                       
     337               0 :             }                                                                                                           
     338                 :                                                                                                                         
     339               0 :             if (isset($node['json'])) {                                                                                 
     340               0 :                 $json = explode(' ', (string)$node['json']);                                                            
     341               0 :                 foreach ($json as $arg) {                                                                               
     342               0 :                     $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]);                                        
     343               0 :                 }                                                                                                       
     344               0 :             }                                                                                                           
     345                 :                                                                                                                         
     346               0 :             $this->_translateLayoutNode($node, $args);                                                                  
     347               0 :             call_user_func_array(array($block, $method), $args);                                                        
     348               0 :         }                                                                                                               
     349                 :                                                                                                                         
     350               0 :         Varien_Profiler::stop($_profilerKey);                                                                           
     351                 :                                                                                                                         
     352               0 :         return $this;                                                                                                   
     353                 :     }                                                                                                                   
     354                 :                                                                                                                         
     355                 :     /**                                                                                                                 
     356                 :      * Translate layout node                                                                                            
     357                 :      *                                                                                                                  
     358                 :      * @param Varien_Simplexml_Element $node                                                                            
     359                 :      * @param array $args                                                                                               
     360                 :      **/                                                                                                                
     361                 :     protected function _translateLayoutNode($node, &$args)                                                              
     362                 :     {                                                                                                                   
     363               0 :         if (isset($node['translate'])) {                                                                                
     364               0 :             $items = explode(' ', (string)$node['translate']);                                                          
     365               0 :             foreach ($items as $arg) {                                                                                  
     366               0 :                 if (isset($node['module'])) {                                                                           
     367               0 :                     $args[$arg] = Mage::helper((string)$node['module'])->__($args[$arg]);                               
     368               0 :                 }                                                                                                       
     369                 :                 else {                                                                                                  
     370               0 :                     $args[$arg] = Mage::helper('core')->__($args[$arg]);                                                
     371                 :                 }                                                                                                       
     372               0 :             }                                                                                                           
     373               0 :         }                                                                                                               
     374               0 :     }                                                                                                                   
     375                 :                                                                                                                         
     376                 :     /**                                                                                                                 
     377                 :      * Save block in blocks registry                                                                                    
     378                 :      *                                                                                                                  
     379                 :      * @param string $name                                                                                              
     380                 :      * @param Mage_Core_Model_Layout $block                                                                             
     381                 :      */                                                                                                                 
     382                 :     public function setBlock($name, $block)                                                                             
     383                 :     {                                                                                                                   
     384               0 :         $this->_blocks[$name] = $block;                                                                                 
     385               0 :         return $this;                                                                                                   
     386                 :     }                                                                                                                   
     387                 :                                                                                                                         
     388                 :     /**                                                                                                                 
     389                 :      * Remove block from registry                                                                                       
     390                 :      *                                                                                                                  
     391                 :      * @param string $name                                                                                              
     392                 :      */                                                                                                                 
     393                 :     public function unsetBlock($name)                                                                                   
     394                 :     {                                                                                                                   
     395               0 :         $this->_blocks[$name] = null;                                                                                   
     396               0 :         unset($this->_blocks[$name]);                                                                                   
     397               0 :         return $this;                                                                                                   
     398                 :     }                                                                                                                   
     399                 :                                                                                                                         
     400                 :     /**                                                                                                                 
     401                 :      * Block Factory                                                                                                    
     402                 :      *                                                                                                                  
     403                 :      * @param     string $type                                                                                          
     404                 :      * @param     string $blockName                                                                                     
     405                 :      * @param     array $attributes                                                                                     
     406                 :      * @return    Mage_Core_Block_Abstract                                                                              
     407                 :      */                                                                                                                 
     408                 :     public function createBlock($type, $name='', array $attributes = array())                                           
     409                 :     {                                                                                                                   
     410                 :         try {                                                                                                           
     411               0 :             $block = $this->_getBlockInstance($type, $attributes);                                                      
     412               0 :         } catch (Exception $e) {                                                                                        
     413               0 :             Mage::logException($e);                                                                                     
     414               0 :             return false;                                                                                               
     415                 :         }                                                                                                               
     416                 :                                                                                                                         
     417               0 :         if (empty($name) || '.'===$name{0}) {                                                                           
     418               0 :             $block->setIsAnonymous(true);                                                                               
     419               0 :             if (!empty($name)) {                                                                                        
     420               0 :                 $block->setAnonSuffix(substr($name, 1));                                                                
     421               0 :             }                                                                                                           
     422               0 :             $name = 'ANONYMOUS_'.sizeof($this->_blocks);                                                                
     423               0 :         } elseif (isset($this->_blocks[$name]) && Mage::getIsDeveloperMode()) {                                         
     424                 :             //Mage::throwException(Mage::helper('core')->__('Block with name "%s" already exists', $name));             
     425               0 :         }                                                                                                               
     426                 :                                                                                                                         
     427               0 :         $block->setType($type);                                                                                         
     428               0 :         $block->setNameInLayout($name);                                                                                 
     429               0 :         $block->addData($attributes);                                                                                   
     430               0 :         $block->setLayout($this);                                                                                       
     431                 :                                                                                                                         
     432               0 :         $this->_blocks[$name] = $block;                                                                                 
     433               0 :         Mage::dispatchEvent('core_layout_block_create_after', array('block'=>$block));                                  
     434               0 :         return $this->_blocks[$name];                                                                                   
     435                 :     }                                                                                                                   
     436                 :                                                                                                                         
     437                 :     /**                                                                                                                 
     438                 :      * Add a block to registry, create new object if needed                                                             
     439                 :      *                                                                                                                  
     440                 :      * @param string|Mage_Core_Block_Abstract $blockClass                                                               
     441                 :      * @param string $blockName                                                                                         
     442                 :      * @return Mage_Core_Block_Abstract                                                                                 
     443                 :      */                                                                                                                 
     444                 :     public function addBlock($block, $blockName)                                                                        
     445                 :     {                                                                                                                   
     446               0 :         return $this->createBlock($block, $blockName);                                                                  
     447                 :     }                                                                                                                   
     448                 :                                                                                                                         
     449                 :     /**                                                                                                                 
     450                 :      * Create block object instance based on block type                                                                 
     451                 :      *                                                                                                                  
     452                 :      * @param string $block                                                                                             
     453                 :      * @param array $attributes                                                                                         
     454                 :      * @return Mage_Core_Block_Abstract                                                                                 
     455                 :      */                                                                                                                 
     456                 :     protected function _getBlockInstance($block, array $attributes=array())                                             
     457                 :     {                                                                                                                   
     458               0 :         if (is_string($block)) {                                                                                        
     459               0 :             if (strpos($block, '/')!==false) {                                                                          
     460               0 :                 if (!$block = Mage::getConfig()->getBlockClassName($block)) {                                           
     461               0 :                     Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));                   
     462               0 :                 }                                                                                                       
     463               0 :             }                                                                                                           
     464               0 :             if (class_exists($block, false) || mageFindClassFile($block)) {                                             
     465               0 :                 $block = new $block($attributes);                                                                       
     466               0 :             }                                                                                                           
     467               0 :         }                                                                                                               
     468               0 :         if (!$block instanceof Mage_Core_Block_Abstract) {                                                              
     469               0 :             Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));                           
     470               0 :         }                                                                                                               
     471               0 :         return $block;                                                                                                  
     472                 :     }                                                                                                                   
     473                 :                                                                                                                         
     474                 :                                                                                                                         
     475                 :     /**                                                                                                                 
     476                 :      * Retrieve all blocks from registry as array                                                                       
     477                 :      *                                                                                                                  
     478                 :      * @return array                                                                                                    
     479                 :      */                                                                                                                 
     480                 :     public function getAllBlocks()                                                                                      
     481                 :     {                                                                                                                   
     482               0 :         return $this->_blocks;                                                                                          
     483                 :     }                                                                                                                   
     484                 :                                                                                                                         
     485                 :     /**                                                                                                                 
     486                 :      * Get block object by name                                                                                         
     487                 :      *                                                                                                                  
     488                 :      * @param string $name                                                                                              
     489                 :      * @return Mage_Core_Block_Abstract                                                                                 
     490                 :      */                                                                                                                 
     491                 :     public function getBlock($name)                                                                                     
     492                 :     {                                                                                                                   
     493               0 :         if (isset($this->_blocks[$name])) {                                                                             
     494               0 :             return $this->_blocks[$name];                                                                               
     495                 :         } else {                                                                                                        
     496               0 :             return false;                                                                                               
     497                 :         }                                                                                                               
     498                 :     }                                                                                                                   
     499                 :                                                                                                                         
     500                 :     /**                                                                                                                 
     501                 :      * Add a block to output                                                                                            
     502                 :      *                                                                                                                  
     503                 :      * @param string $blockName                                                                                         
     504                 :      * @param string $method                                                                                            
     505                 :      */                                                                                                                 
     506                 :     public function addOutputBlock($blockName, $method='toHtml')                                                        
     507                 :     {                                                                                                                   
     508                 :         //$this->_output[] = array($blockName, $method);                                                                
     509               0 :         $this->_output[$blockName] = array($blockName, $method);                                                        
     510               0 :         return $this;                                                                                                   
     511                 :     }                                                                                                                   
     512                 :                                                                                                                         
     513                 :     public function removeOutputBlock($blockName)                                                                       
     514                 :     {                                                                                                                   
     515               0 :         unset($this->_output[$blockName]);                                                                              
     516               0 :         return $this;                                                                                                   
     517                 :     }                                                                                                                   
     518                 :                                                                                                                         
     519                 :     /**                                                                                                                 
     520                 :      * Get all blocks marked for output                                                                                 
     521                 :      *                                                                                                                  
     522                 :      * @return string                                                                                                   
     523                 :      */                                                                                                                 
     524                 :     public function getOutput()                                                                                         
     525                 :     {                                                                                                                   
     526               0 :         $out = '';                                                                                                      
     527               0 :         if (!empty($this->_output)) {                                                                                   
     528               0 :             foreach ($this->_output as $callback) {                                                                     
     529               0 :                 $out .= $this->getBlock($callback[0])->$callback[1]();                                                  
     530               0 :             }                                                                                                           
     531               0 :         }                                                                                                               
     532                 :                                                                                                                         
     533               0 :         return $out;                                                                                                    
     534                 :     }                                                                                                                   
     535                 :                                                                                                                         
     536                 :     /**                                                                                                                 
     537                 :      * Retrieve messages block                                                                                          
     538                 :      *                                                                                                                  
     539                 :      * @return Mage_Core_Block_Messages                                                                                 
     540                 :      */                                                                                                                 
     541                 :     public function getMessagesBlock()                                                                                  
     542                 :     {                                                                                                                   
     543               0 :         $block = $this->getBlock('messages');                                                                           
     544               0 :         if ($block) {                                                                                                   
     545               0 :             return $block;                                                                                              
     546                 :         }                                                                                                               
     547               0 :         return $this->createBlock('core/messages', 'messages');                                                         
     548                 :     }                                                                                                                   
     549                 :                                                                                                                         
     550                 :     /**                                                                                                                 
     551                 :      * Enter description here...                                                                                        
     552                 :      *                                                                                                                  
     553                 :      * @param string $type                                                                                              
     554                 :      * @return Mage_Core_Helper_Abstract                                                                                
     555                 :      */                                                                                                                 
     556                 :     public function getBlockSingleton($type)                                                                            
     557                 :     {                                                                                                                   
     558               0 :         if (!isset($this->_helpers[$type])) {                                                                           
     559               0 :             $className = Mage::getConfig()->getBlockClassName($type);                                                   
     560               0 :             if (!$className) {                                                                                          
     561               0 :                 Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $type));                        
     562               0 :             }                                                                                                           
     563                 :                                                                                                                         
     564               0 :             $helper = new $className();                                                                                 
     565               0 :             if ($helper) {                                                                                              
     566               0 :                 if ($helper instanceof Mage_Core_Block_Abstract) {                                                      
     567               0 :                     $helper->setLayout($this);                                                                          
     568               0 :                 }                                                                                                       
     569               0 :                 $this->_helpers[$type] = $helper;                                                                       
     570               0 :             }                                                                                                           
     571               0 :         }                                                                                                               
     572               0 :         return $this->_helpers[$type];                                                                                  
     573                 :     }                                                                                                                   
     574                 :                                                                                                                         
     575                 :     /**                                                                                                                 
     576                 :      * Retrieve helper object                                                                                           
     577                 :      *                                                                                                                  
     578                 :      * @param   string $name                                                                                            
     579                 :      * @return  Mage_Core_Helper_Abstract                                                                               
     580                 :      */                                                                                                                 
     581                 :     public function helper($name)                                                                                       
     582                 :     {                                                                                                                   
     583               0 :         $helper = Mage::helper($name);                                                                                  
     584               0 :         if (!$helper) {                                                                                                 
     585               0 :             return false;                                                                                               
     586                 :         }                                                                                                               
     587               0 :         return $helper->setLayout($this);                                                                               
     588                 :     }                                                                                                                   
     589                 :                                                                                                                         
     590                 :     /**                                                                                                                 
     591                 :      * Lookup module name for translation from current specified layout node                                            
     592                 :      *                                                                                                                  
     593                 :      * Priorities:                                                                                                      
     594                 :      * 1) "module" attribute in the element                                                                             
     595                 :      * 2) "module" attribute in any ancestor element                                                                    
     596                 :      * 3) layout handle name - first 1 or 2 parts (namespace is determined automatically)                               
     597                 :      *                                                                                                                  
     598                 :      * @param Varien_Simplexml_Element $node                                                                            
     599                 :      * @return string                                                                                                   
     600                 :      */                                                                                                                 
     601                 :     public static function findTranslationModuleName(Varien_Simplexml_Element $node)                                    
     602                 :     {                                                                                                                   
     603               0 :         $result = $node->getAttribute('module');                                                                        
     604               0 :         if ($result) {                                                                                                  
     605               0 :             return (string)$result;                                                                                     
     606                 :         }                                                                                                               
     607               0 :         foreach (array_reverse($node->xpath('ancestor::*[@module]')) as $element) {                                     
     608               0 :             $result = $element->getAttribute('module');                                                                 
     609               0 :             if ($result) {                                                                                              
     610               0 :                 return (string)$result;                                                                                 
     611                 :             }                                                                                                           
     612               0 :         }                                                                                                               
     613               0 :         foreach ($node->xpath('ancestor-or-self::*[last()-1]') as $handle) {                                            
     614               0 :             $name = Mage::getConfig()->determineOmittedNamespace($handle->getName());                                   
     615               0 :             if ($name) {                                                                                                
     616               0 :                 return $name;                                                                                           
     617                 :             }                                                                                                           
     618               0 :         }                                                                                                               
     619               0 :         return 'core';                                                                                                  
     620                 :     }                                                                                                                   
     621                 : }                                                                                                                       

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.4 and PHPUnit 3.5.13 at Tue Jul 5 9:07:16 UTC 2011.