Changeset 1609

Show
Ignore:
Timestamp:
01/30/07 10:03:24 (2 years ago)
Author:
david
Message:

added 'more'-assigns for the template that are resolved at rendering time, these are 'container', 'view' and 'inner' (for the previous, wrapped layer's output). can be changed via 'assigns' parameter for the renderer, of course. container response gets now cleared prior to view execution. refs #287 and #373

Location:
branches/0.11/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/filter/AgaviExecutionFilter.class.php

    r1600 r1609  
    326326      $actionAttributes = $container->getAttributes(); 
    327327    } 
     328     
     329    $response->clear(); 
    328330 
    329331    if($viewName !== AgaviView::NONE) { 
     
    383385              } 
    384386            } 
    385             $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output); 
     387            $moreAssigns = array( 
     388              'container' => $container, 
     389              'inner' => $nextOutput, 
     390              'view' => $viewInstance, 
     391            ); 
     392            $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output, $moreAssigns); 
    386393            $output = array(); 
    387394            $output[$layer->getName()] = $nextOutput; 
  • branches/0.11/src/renderer/AgaviPhpRenderer.class.php

    r1568 r1609  
    3939   *                                used during rendering. 
    4040   */ 
    41   protected $_layer = null; 
     41  private $layer = null; 
    4242   
    4343  /** 
     
    4545   *                   rendering. 
    4646   */ 
    47   protected $_attributes = null; 
     47  private $attributes = null; 
    4848   
    4949  /** 
     
    5151   *                   rendering. 
    5252   */ 
    53   protected $_slots = null; 
     53  private $slots = null; 
     54   
     55  /** 
     56   * @var        array Temporary storage for additional assigns, used during 
     57   *                   rendering. 
     58   */ 
     59  private $additionalAssigns = null; 
    5460   
    5561  /** 
     
    5965   * @param      array              The template variables. 
    6066   * @param      array              The slots. 
     67   * @param      array              Associative array of additional assigns. 
    6168   * 
    6269   * @return     string A rendered result. 
     
    6572   * @since      0.11.0 
    6673   */ 
    67   public function render(AgaviTemplateLayer $layer, array &$attributes, array &$slots = array()) 
     74  public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) 
    6875  { 
    6976    // DO NOT USE VARIABLES IN HERE, THEY MIGHT INTERFERE WITH TEMPLATE VARS 
    70     $this->_layer = $layer; 
    71     $this->_attributes =& $attributes; 
    72     $this->_slots =& $slots; 
    73     unset($layer, $attributes, $slots); 
     77    $this->layer = $layer; 
     78    $this->attributes =& $attributes; 
     79    $this->slots =& $slots; 
     80    foreach($moreAssigns as $moreAssignName => &$moreAssign) { 
     81      if(isset($this->moreAssignNames[$moreAssignName])) { 
     82        $moreAssignName = $this->moreAssignNames[$moreAssignName]; 
     83      } 
     84      $this->moreAssigns[$moreAssignName] =& $moreAssign; 
     85    } 
     86    unset($layer, $attributes, $slots, $moreAssigns); 
    7487     
    7588    if($this->extractVars) { 
    76       extract($this->_attributes, EXTR_REFS | EXTR_PREFIX_INVALID, '_'); 
     89      extract($this->attributes, EXTR_REFS | EXTR_PREFIX_INVALID, '_'); 
    7790    } else { 
    78       ${$this->varName} =& $this->_attributes; 
     91      ${$this->varName} =& $this->attributes; 
    7992    } 
    8093     
    81     ${$this->slotsVarName} =& $this->_slots;  
     94    ${$this->slotsVarName} =& $this->slots;  
    8295     
    8396    extract($this->assigns); 
    8497     
     98    extract($this->moreAssigns, EXTR_REFS); 
     99     
    85100    ob_start(); 
    86101     
    87     require($this->_layer->getResourceStreamIdentifier()); 
     102    require($this->layer->getResourceStreamIdentifier()); 
    88103     
    89104    $retval = ob_get_contents(); 
    90105    ob_end_clean(); 
    91106     
    92     unset($this->_layer, $this->_attributes, $this->_slots); 
     107    unset($this->layer, $this->attributes, $this->slots, $this->moreAssigns); 
    93108     
    94109    return $retval; 
  • branches/0.11/src/renderer/AgaviPhptalRenderer.class.php

    r1568 r1609  
    8383   * @param      array              The template variables. 
    8484   * @param      array              The slots. 
     85   * @param      array              Associative array of additional assigns. 
    8586   * 
    8687   * @return     string A rendered result. 
     
    9091   * @since      0.11.0 
    9192   */ 
    92   public function render(AgaviTemplateLayer $layer, array &$attributes, array &$slots = array()) 
     93  public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) 
    9394  { 
    9495    $engine = $this->getEngine(); 
     
    108109    } 
    109110     
     111    foreach($moreAssigns as $key => $value) { 
     112      if(isset($this->moreAssignNames[$key])) { 
     113        $key = $this->moreAssignNames[$key]; 
     114      } 
     115      $engine->set($key, $value); 
     116    } 
     117     
    110118    $engine->setTemplate($layer->getResourceStreamIdentifier()); 
    111119     
  • branches/0.11/src/renderer/AgaviRenderer.class.php

    r1568 r1609  
    6161   
    6262  /** 
     63   * @var        array An array of names for the "more" assigns. 
     64   */ 
     65  protected $moreAssignNames = array(); 
     66   
     67  /** 
    6368   * Initialize this Renderer. 
    6469   * 
     
    8590    } 
    8691    if(isset($parameters['assigns'])) { 
    87       foreach($parameters['assigns'] as $factory => $var) { 
    88         $getter = 'get' . str_replace('_', '', $factory); 
    89         $this->assigns[$var] = $this->context->$getter(); 
     92      foreach($parameters['assigns'] as $item => $var) { 
     93        $getter = 'get' . str_replace('_', '', $item); 
     94        if(method_exists($this->context, $getter)) { 
     95          $this->assigns[$var] = $this->context->$getter(); 
     96        } else { 
     97          $this->moreAssignNames[$item] = $var; 
     98        } 
    9099      } 
    91100    } 
     
    124133   * @param      array              The template variables. 
    125134   * @param      array              The slots. 
     135   * @param      array              Associative array of additional assigns. 
    126136   * 
    127137   * @return     string A rendered result. 
     
    130140   * @since      0.11.0 
    131141   */ 
    132   abstract public function render(AgaviTemplateLayer $layer, array &$attributes, array &$slots = array()); 
     142  abstract public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()); 
    133143} 
    134144 
  • branches/0.11/src/renderer/AgaviSmartyRenderer.class.php

    r1568 r1609  
    114114   * @param      array              The template variables. 
    115115   * @param      array              The slots. 
     116   * @param      array              Associative array of additional assigns. 
    116117   * 
    117118   * @return     string A rendered result. 
     
    120121   * @since      0.11.0 
    121122   */ 
    122   public function render(AgaviTemplateLayer $layer, array &$attributes, array &$slots = array()) 
     123  public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) 
    123124  { 
    124125    $engine = $this->getEngine(); 
     
    138139    } 
    139140     
     141    foreach($moreAssigns as $key => &$value) { 
     142      if(isset($this->moreAssignNames[$key])) { 
     143        $key = $this->moreAssignNames[$key]; 
     144      } 
     145      $engine->assign_by_ref($key, $value); 
     146    } 
     147     
    140148    return $this->getEngine()->fetch($layer->getResourceStreamIdentifier()); 
    141149  }