Show
Ignore:
Timestamp:
03/18/08 14:59:53 (2 years ago)
Author:
mikey
Message:

enhancement #133, part 1: XML processor should use website cache - xml generators now have methods to determine cache ability and cache keys

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/main/php/net/stubbles/websites/xml/generator/stubPageXMLGenerator.php

    r1427 r1433  
    1010                      'net::stubbles::ipo::request::stubRequest', 
    1111                      'net::stubbles::ipo::request::stubRequestPrefixDecorator', 
     12                      'net::stubbles::ipo::response::stubResponse', 
    1213                      'net::stubbles::ipo::session::stubSession', 
    1314                      'net::stubbles::lang::exceptions::stubRuntimeException', 
    14                       'net::stubbles::util::stubRegistry', 
    1515                      'net::stubbles::websites::stubPage', 
    1616                      'net::stubbles::websites::xml::generator::stubXMLGenerator', 
     
    5050    protected $page; 
    5151    /** 
     52     * list of available page elements 
     53     * 
     54     * @var  array<string,stubPageElement> 
     55     */ 
     56    protected $pageElements = array(); 
     57    /** 
    5258     * injector instance to be used 
    5359     * 
     
    5561     */ 
    5662    protected $injector; 
     63    /** 
     64     * switch whether document part is cachable or not 
     65     * 
     66     * @var  bool 
     67     */ 
     68    protected $isCachable   = true; 
     69    /** 
     70     * list of cache variables for this page 
     71     * 
     72     * @var  array<string,scalar> 
     73     */ 
     74    protected $cacheVars    = array(); 
     75    /** 
     76     * list of used files for this page 
     77     * 
     78     * @var  array<string> 
     79     */ 
     80    protected $usedFiles    = array(); 
    5781 
    5882    /** 
     
    6286     * @param  stubSession   $session 
    6387     * @param  stubResponse  $response 
    64      * @param  stubPage      $page 
    6588     * @param  stubInjector  $injector 
    6689     * @Inject 
    6790     */ 
    68     public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPage $page, stubInjector $injector) 
     91    public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubInjector $injector) 
    6992    { 
    70         $this->request  = $request; 
     93        $this->request  = new stubRequestPrefixDecorator($request, ''); 
    7194        $this->session  = $session; 
    7295        $this->response = $response; 
    73         $this->page     = $page; 
    7496        $this->injector = $injector; 
     97    } 
     98 
     99    /** 
     100     * sets the page 
     101     * 
     102     * @param  stubPage  $page 
     103     * @Inject 
     104     */ 
     105    public function setPage(stubPage $page) 
     106    { 
     107        $this->page = $page; 
     108        if (count($this->page->getResources()) > 0) { 
     109            $this->isCachable = false; 
     110        } 
     111         
     112        foreach ($this->page->getElements() as $name => $element) { 
     113            $this->request->setPrefix($name); 
     114            $this->injector->handleInjections($element); 
     115            $element->init($this->request, $this->session, $this->response); 
     116            if ($element->isAvailable() === true) { 
     117                $this->pageElements[$name] = $element; 
     118                // we can spare this if the page is not cachable 
     119                if (true === $this->isCachable) { 
     120                    if ($element->isCachable() === false) { 
     121                        $this->isCachable = false; 
     122                    } elseif (true === $this->isCachable) { 
     123                        $this->cacheVars = array_merge($this->cacheVars, $element->getCacheVars()); 
     124                        $this->usedFiles = array_merge($this->usedFiles, $element->getUsedFiles()); 
     125                    } 
     126                } 
     127            } 
     128        } 
     129    } 
     130 
     131    /** 
     132     * checks whether document part is cachable or not 
     133     * 
     134     * Document part is cachable if page has no session resources and all page 
     135     * elements are cachable. 
     136     * 
     137     * @return  bool 
     138     */ 
     139    public function isCachable() 
     140    { 
     141        return $this->isCachable; 
     142    } 
     143 
     144    /** 
     145     * returns a list of variables that have an influence on caching 
     146     * 
     147     * @return  array<string,scalar> 
     148     */ 
     149    public function getCacheVars() 
     150    { 
     151        return $this->cacheVars; 
     152    } 
     153 
     154    /** 
     155     * returns a list of files used to create the content 
     156     * 
     157     * @return  array<string> 
     158     */ 
     159    public function getUsedFiles() 
     160    { 
     161        return $this->usedFiles; 
    75162    } 
    76163 
     
    83170    public function generate(stubXMLStreamWriter $xmlStreamWriter, stubXMLSerializer $xmlSerializer) 
    84171    { 
    85         $prefixRequest = new stubRequestPrefixDecorator($this->request, ''); 
    86         $formValues    = array(); 
    87         foreach ($this->page->getElements() as $name => $element) { 
    88             $prefixRequest->setPrefix($name); 
    89             $this->injector->handleInjections($element); 
    90             $element->init($prefixRequest, $this->session, $this->response); 
    91             if ($element->isAvailable() === true) { 
    92                 $data = $element->process(); 
    93                 if ($prefixRequest->isCancelled() === true) { 
    94                     return; 
    95                 } 
    96      
    97                 $xmlSerializer->serialize($data, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => $name)); 
    98                 if ($element instanceof stubXMLPageElement) { 
    99                     $formValues[$name] = $element->getFormValues(); 
    100                 } 
     172        $formValues = array(); 
     173        foreach ($this->pageElements as $name => $element) { 
     174            $this->request->setPrefix($name); 
     175            $element->init($this->request, $this->session, $this->response); 
     176            $data = $element->process(); 
     177            if ($this->request->isCancelled() === true) { 
     178                return; 
     179            } 
     180             
     181            $xmlSerializer->serialize($data, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => $name)); 
     182            if ($element instanceof stubXMLPageElement) { 
     183                $formValues[$name] = $element->getFormValues(); 
    101184            } 
    102185        }