Changeset 204

Show
Ignore:
Timestamp:
02/02/07 16:59:03 (2 years ago)
Author:
mikey
Message:

allowed safe cloning of net.stubbles.xml.xsl.stubXSLProcessor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/stubXMLXIncludeStreamWrapper.php

    r199 r204  
    127127    protected function processFile() 
    128128    { 
    129         $xslProcessorClassName = get_class(self::$xslProcessor); 
    130         $xslProcessor          = new $xslProcessorClassName(); 
    131         foreach (self::$xslProcessor->getParameterNamespaces() as $nameSpace) { 
    132             $xslProcessor->setParameters($nameSpace, self::$xslProcessor->getParameters($nameSpace)); 
    133         } 
    134          
    135         foreach (self::$xslProcessor->getStylesheets() as $stylesheet) { 
    136             $xslProcessor->importXSLStylesheet($stylesheet); 
    137         } 
    138  
     129        $xslProcessor = clone self::$xslProcessor; 
    139130        $xslProcessor->setXMLDocument(DOMDocument::load($this->fileName)); 
    140131        $resultDoc = $xslProcessor->transformToDoc(); 
  • trunk/src/main/php/net/stubbles/xml/xsl/stubXSLProcessor.php

    r200 r204  
    231231     
    232232    /** 
     233     * does some corrections after cloning 
     234     */ 
     235    public function __clone() 
     236    { 
     237        $this->createXSLTProcessor(); 
     238        foreach ($this->parameters as $nameSpace => $params) { 
     239            $this->xsltProcessor->setParameter($nameSpace, $params); 
     240        } 
     241         
     242        foreach ($this->stylesheets as $stylesheet) { 
     243            $this->xsltProcessor->importStylesheet($stylesheet); 
     244        } 
     245         
     246        $this->document = null; 
     247    } 
     248     
     249    /** 
    233250     * transoforms the document into another DOMDocument 
    234251     *  
  • trunk/src/test/php/net/stubbles/xml/xsl/stubXSLProcessorTestCase.php

    r200 r204  
    1717    { 
    1818        parent::registerCallbacks(); 
     19    } 
     20     
     21    public function getXMLDocument() 
     22    { 
     23        return $this->document; 
    1924    } 
    2025     
     
    165170     
    166171    /** 
     172     * test that cloning works as expected 
     173     */ 
     174    public function testClone() 
     175    { 
     176        $anotherMockXSLTProcessor                = new MockXSLTProcessor(); 
     177        TeststubXSLProcessor::$mockXSLTProcessor = $anotherMockXSLTProcessor; 
     178        $this->xslProcessor->setParameter('foo', 'bar', 'baz'); 
     179        $stylesheet = new DOMDocument(); 
     180        $this->xslProcessor->importXSLStylesheet($stylesheet); 
     181        $this->mockXSLTProcessor->expectNever('setParameter'); 
     182        $anotherMockXSLTProcessor->expect('setParameter', array('foo', array('bar' => 'baz'))); 
     183        $this->mockXSLTProcessor->expectNever('importStylesheet'); 
     184        $anotherMockXSLTProcessor->expect('importStylesheet', array($stylesheet)); 
     185        $clonedXSLProcessor = clone $this->xslProcessor; 
     186        $this->assertReference($this->xslProcessor->getXMLDocument(), $this->document); 
     187        $this->assertNull($clonedXSLProcessor->getXMLDocument()); 
     188    } 
     189     
     190    /** 
    167191     * test transforming a document 
    168192     */