Changeset 1495

Show
Ignore:
Timestamp:
01/14/07 06:55:44 (2 years ago)
Author:
david
Message:

first take on response merging stuff, refs #373

Location:
branches/david-execution_flow/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/david-execution_flow/src/controller/AgaviController.class.php

    r1494 r1495  
    116116   * Create and initialize new execution container instance. 
    117117   * 
    118    * @param      string The name of the module. 
    119    * @param      string The name of the action. 
    120    * @param      array  Optional additional parameters. 
    121    * @param      string The name of the initial output type to set. 
     118   * @param      string          The name of the module. 
     119   * @param      string          The name of the action. 
     120   * @param      array           Optional additional parameters. 
     121   * @param      AgaviOutputType Optional name of an initial output type to set. 
    122122   * 
    123123   * @return     AgaviExecutionContainer A new execution container instance, 
     
    129129  public function createExecutionContainer($moduleName = null, $actionName = null, array $parameters = array(), AgaviOutputType $outputType = null) 
    130130  { 
    131     // create a new filter chain 
     131    // create a new execution container 
    132132    $ecfi = $this->context->getFactoryInfo('execution_container'); 
    133133    $container = new $ecfi['class'](); 
  • branches/david-execution_flow/src/controller/AgaviExecutionContainer.class.php

    r1494 r1495  
    101101   
    102102  /** 
     103   * Creates a new container instance with the same output type as this one. 
     104   * 
     105   * @param      string          The name of the module. 
     106   * @param      string          The name of the action. 
     107   * @param      array           Optional additional parameters. 
     108   * @param      AgaviOutputType Optional name of an initial output type to set. 
     109   * 
     110   * @return     AgaviExecutionContainer A new execution container instance, 
     111   *                                     fully initialized. 
     112   * 
     113   * @author     David Zuelke <dz@bitxtender.com> 
     114   * @since      0.11.0 
     115   */ 
     116  public function createExecutionContainer($moduleName = null, $actionName = null, array $parameters = array(), AgaviOutputType $outputType = null) 
     117  { 
     118    if($outputType === null) { 
     119      $outputType = $this->getOutputType(); 
     120    } 
     121    return $this->context->getController()->createExecutionContainer($moduleName, $actionName, $parameters, $outputType); 
     122  } 
     123   
     124  /** 
    103125   * Start execution. 
    104126   * 
  • branches/david-execution_flow/src/filter/AgaviExecutionFilter.class.php

    r1494 r1495  
    366366        $request->toggleLock($key); 
    367367         
    368         if(is_array($next) && count($next) >= 2) { 
    369           $container->setNext($controller->createExecutionContainer($next[0], $next[1], isset($next[2]) ? $next[2] : array(), isset($next[3]) ? ($next[3] instanceof AgaviOutputType ? $next[3] : $controller->getOutputType($next[3])) : $container->getOutputType())); 
     368        if($next instanceof AgaviExecutionContainer) { 
     369          $container->setNext($next); 
    370370        } else { 
    371371          $attributes =& $viewInstance->getAttributes(); 
     
    376376            foreach($layer->getSlots() as $slotName => $slotContainer) { 
    377377              $slotResponse = $slotContainer->execute(); 
    378               if($response) { 
     378              // FIXME: this if is always true 
     379              if($slotResponse) { 
    379380                // set the presentation data as a template attribute 
    380381                $output[$name] = $slotResponse->getContent(); 
    381                 // $response->merge($response->exportInfo()); 
     382                // let our response grab the stuff it needs from the slot's response 
     383                $response->merge($slotResponse); 
    382384              } else { 
    383385                $output[$name] = null; 
  • branches/david-execution_flow/src/response/AgaviResponse.class.php

    r1494 r1495  
    145145   
    146146  /** 
     147   * Import response metadata from another response. 
     148   * 
     149   * @param      AgaviResponse The other response to import information from. 
     150   * 
     151   * @author     David Zuelke <dz@bitxtender.com> 
     152   * @since      0.11.0 
     153   */ 
     154  abstract public function merge(AgaviResponse $otherResponse); 
     155   
     156  /** 
    147157   * Clear all data for this Response. 
    148158   * 
  • branches/david-execution_flow/src/response/AgaviWebResponse.class.php

    r1494 r1495  
    173173   
    174174  /** 
     175   * Import response metadata (headers, cookies) from another response. 
     176   * 
     177   * @param      AgaviResponse The other response to import information from. 
     178   * 
     179   * @author     David Zuelke <dz@bitxtender.com> 
     180   * @since      0.11.0 
     181   */ 
     182  public function merge(AgaviResponse $otherResponse) 
     183  { 
     184    if($otherResponse instanceof AgaviWebResponse) { 
     185      foreach($otherResponse->getHttpHeaders() as $name => $value) { 
     186        if(!$this->hasHttpHeader($name)) { 
     187          $this->setHttpHeader($name, $value); 
     188        } 
     189      } 
     190      foreach($otherResponse->getCookies() as $name => $cookie) { 
     191        if(!$this->hasCookie($name)) { 
     192          $this->setCookie($name, $cookie['value'], $cookie['lifetime'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']); 
     193        } 
     194      } 
     195    } 
     196  } 
     197   
     198   
     199  /** 
    175200   * Sets a HTTP status code for the response. 
    176201   * 
     
    304329   * 
    305330   * @param      string A cookie name. 
    306    * @param      mixed Data to store into a cookie. If null or empty cookie 
    307    *                   will be tried to be removed. 
     331   * @param      mixed  Data to store into a cookie. If null or empty cookie 
     332   *                    will be tried to be removed. 
    308333   * @param      int    The lifetime of the cookie in seconds. When you pass 0  
    309    *                    the cookie will be valid until the  browser gets closed. 
     334   *                    the cookie will be valid until the browser is closed. 
    310335   * @param      string The path on the server the cookie will be available on. 
    311336   * @param      string The domain the cookie is available on. 
     
    313338   *                    over a secure HTTPS connection. 
    314339   * @param      bool   Whether the cookie will be made accessible only through 
    315    *                    the HTTP protocol. 
     340   *                    the HTTP protocol, and not to client-side scripts. 
    316341   * 
    317342   * @author     Veikko Makinen <mail@veikkomakinen.com> 
     
    319344   * @since      0.11.0 
    320345   */ 
    321   public function setCookie($name, $value, $lifetime = null, $path = null, $domain = null, $secure = null, $httpOnly = false) 
    322   { 
    323     $lifetime = isset($lifetime) ? $lifetime : $this->cookieConfig['lifetime']; 
    324     $path     = isset($path)     ? $path     : $this->cookieConfig['path']; 
    325     $domain   = isset($domain)   ? $domain   : $this->cookieConfig['domain']; 
    326     $secure   = (bool) (isset($secure)   ? $secure   : $this->cookieConfig['secure']); 
    327     $httpOnly = (bool) (isset($httpOnly) ? $httpOnly : $this->cookieConfig['httpOnly']); 
     346  public function setCookie($name, $value, $lifetime = null, $path = null, $domain = null, $secure = null, $httpOnly = null) 
     347  { 
     348    $lifetime =         $lifetime === null ? $lifetime : $this->cookieConfig['lifetime']; 
     349    $path     =         $path === null     ? $path     : $this->cookieConfig['path']; 
     350    $domain   =         $domain === null   ? $domain   : $this->cookieConfig['domain']; 
     351    $secure   = (bool) ($secure === null   ? $secure   : $this->cookieConfig['secure']); 
     352    $httpOnly = (bool) ($httpOnly === null ? $httpOnly : $this->cookieConfig['httpOnly']); 
    328353 
    329354    $this->cookies[$name] = array( 
     
    336361    ); 
    337362  } 
    338  
     363   
     364  /** 
     365   * Get a cookie set for later sending. 
     366   * 
     367   * @param      string The name of the cookie. 
     368   * 
     369   * @return     array An associative array containing the cookie data or null 
     370   *                   if no cookie with that name has been set. 
     371   * 
     372   * @author     David Zuelke <dz@bitxtender.com> 
     373   * @since      0.11.0 
     374   */ 
     375  public function getCookie($name) 
     376  { 
     377    if(isset($this->cookies[$name])) { 
     378      return $this->cookies[$name]; 
     379    } 
     380  } 
     381   
     382  /** 
     383   * Check if a cookie has been set for later sending. 
     384   * 
     385   * @param      string The name of the cookie. 
     386   * 
     387   * @return     bool True if a cookie with that name has been set, else false. 
     388   * 
     389   * @author     David Zuelke <dz@bitxtender.com> 
     390   * @since      0.11.0 
     391   */ 
     392  public function hasCookie($name) 
     393  { 
     394    return isset($this->cookies[$name]); 
     395  } 
     396   
     397  /** 
     398   * Remove a cookie previously set for later sending. 
     399   * 
     400   * This method cannot be used to unset a cookie. It's purpose is to remove a 
     401   * cookie from the list of cookies to be sent along with the response. If you 
     402   * wish to remove an existing cookie, use the setCookie method and supply null 
     403   * as the value. 
     404   * 
     405   * @param      string The name of the cookie. 
     406   * 
     407   * @author     David Zuelke <dz@bitxtender.com> 
     408   * @since      0.11.0 
     409   */ 
     410  public function removeCookie($name) 
     411  { 
     412    if(isset($this->cookies[$name])) { 
     413      unset($this->cookies[$name]); 
     414    } 
     415  } 
     416   
     417  /** 
     418   * Get a list of cookies set for later sending. 
     419   * 
     420   * @return     array An associative array of cookie names (key) and cookie 
     421   *                   information (value, associative array). 
     422   * 
     423   * @author     David Zuelke <dz@bitxtender.com> 
     424   * @since      0.11.0 
     425   */ 
     426  public function getCookies() 
     427  { 
     428    return $this->cookies; 
     429  } 
     430   
    339431  /** 
    340432   * Remove the HTTP header set for the response