Changeset 1184 for branches

Show
Ignore:
Timestamp:
10/07/08 09:55:17 (2 months ago)
Author:
arnoschn
Message:

refactoring AkRequest? to move mimetype stuff to AkRequestMimeType? so the AkCacheHandler? can use it

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/arnoschn/cache/lib/AkActionController/AkCacheHandler.php

    r1182 r1184  
    1919 
    2020require_once(AK_LIB_DIR.DS.'AkCache.php'); 
    21  
     21require_once(AK_LIB_DIR.DS.'AkRequestMimeType.php'); 
    2222/** 
    2323 * 
     
    636636        $headerString = var_export($finalHeaders,true); 
    637637        //$functionStr = file_get_contents(dirname(__FILE__).DS.'cache_page_functions.txt'); 
     638        $content = preg_replace('/(<\?|<\?php|\?>)/','<?php echo "\1";?>', $content); 
    638639        $content = <<<EOF 
    639640<?php 
     
    677678        } 
    678679        Ak::parseOptions($options, $default_options,array(),true); 
    679      
     680         
    680681        foreach ($options as $sweeper => $params) { 
    681682            if (is_int($sweeper)) { 
     
    683684                $params = array(); 
    684685            } 
     686            if (isset($params['only']) && is_string($params['only'])) { 
     687                $params['only'] = array($params['only']); 
     688            } 
     689            if (isset($params['except']) && is_string($params['except'])) { 
     690                $params['except'] = array($params['except']); 
     691            } 
    685692            $this->_initSweeper($sweeper, $params); 
    686693        } 
     
    689696    function _initSweeper($sweeper, $options = array()) 
    690697    { 
    691         if (!empty($only) && !in_array($this->_controller->getActionName(), $options['only'])) return; 
    692         if (!empty($except) && !in_array($this->_controller->getActionName(), $options['except'])) return; 
     698        if (isset($options['only']) && !in_array($this->_controller->getActionName(), $options['only'])) return; 
     699        if (isset($options['except']) && !in_array($this->_controller->getActionName(), $options['except'])) return; 
    693700 
    694701        $sweeper_class = AkInflector::classify($sweeper); 
     
    814821                $cacheId.= '.'.$this->_controller->Request->getFormat(); 
    815822            } else { 
    816                 $cacheId.= $this->_page_cache_extension; 
     823                 
     824                list($format, $requestPath) = AkRequestMimeType::getFormat($path); 
     825                $cacheId.= '.'.$format; 
    817826            } 
    818827        } 
     
    911920        static $_cached; 
    912921 
    913                $key = $this->fragmentCachekey($key, $options); 
     922        $key = $this->fragmentCachekey($key, $options); 
    914923        if (empty($_cached)) { 
    915924            $_cached = array(); 
     
    960969    { 
    961970        if (!$this->cacheConfigured()) return false; 
    962  
     971         
     972        $orgkey = $key; 
     973         
    963974        $key = $this->fragmentCachekey($key, $options); 
    964  
     975         
    965976        return $this->_cache_store->get($key, isset($options['host'])? 
    966977        $options['host']:$this->_buildCacheGroup()); 
  • branches/arnoschn/cache/lib/AkRequest.php

    r1159 r1184  
    3131$_SERVER['REQUEST_URI'] = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME'].(( isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''))); 
    3232 
    33  
     33require_once(AK_LIB_DIR.DS.'AkRequestMimeType.php'); 
    3434/** 
    3535* Class that handles incoming request. 
     
    738738    function getFormat() 
    739739    { 
     740 
     741         
    740742        if (isset($this->_format)) { 
    741743            return $this->_format; 
    742744        } else if (isset($this->_request['format'])) { 
    743745            $this->_format = $this->_request['format']; 
    744         } elseif (preg_match('/^([^\.]+)\.(.+)$/', @$this->_request['ak'], $matches)) { 
    745             $this->_format = isset($matches[2])?strtolower($matches[2]):null; 
    746             $orgformat = $this->_format; 
    747             if ($this->_format == 'htm') { 
    748                 $this->_format = 'html'; 
    749             } 
    750             $this->_request['format'] = $this->_format; 
    751             $this->_request['ak'] = preg_replace('/^(.*)\.'.$orgformat.'$/','\1',$this->_request['ak']); 
    752         } else if ($this->isGet() || $this->isDelete()) { 
    753             $this->_format = $this->_bestMimeType(); 
    754         } else if ($this->isPost() || $this->isPut()) { 
    755             $this->_format = $this->_lookupMimeType($this->getContentType()); 
    756         } 
    757          
    758         if (empty($this->_format)) { 
    759             $this->_format = $this->mime_types['default']; 
     746        } else { 
     747            list($format, $requestPath) = AkRequestMimeType::getFormat(@$this->_request['ak']); 
     748             
     749            $this->_format = $format; 
     750            $this->_request['format'] = $format; 
     751            if ($requestPath!=null) { 
     752                $this->_request['ak'] = $requestPath; 
     753            } 
    760754        } 
    761755        return $this->_format; 
    762756    } 
    763757     
    764     function _sortAcceptHeader($a,$b)  
    765     {  
    766          //preserve the original order if q is equal  
    767         return $a['q'] == $b['q'] ? ($a['i'] > $b['i']) : ($a['q'] < $b['q']);  
    768     }  
    769     function _parseMimeType($mime_type)  
    770     {  
    771         @list($type,$parameter_string) = explode(';',$mime_type);  
    772         $mime_type_struct = array();  
    773         if ($parameter_string){  
    774             parse_str($parameter_string,$mime_type_struct);  
    775         }  
    776         $mime_type_struct['type'] = trim($type);  
    777         return $mime_type_struct;  
    778     } 
    779     function _getMimeType($acceptables) 
    780     {  
    781         // we group by 'quality'  
    782         $grouped_acceptables = array();  
    783         foreach ($acceptables as $acceptable){  
    784             $grouped_acceptables[$acceptable['q']][] = $acceptable['type'];  
    785         }  
    786           
    787           
    788         foreach ($grouped_acceptables as $q=>$array_with_acceptables_of_same_quality){  
    789             foreach ($this->mime_types as $mime_type=>$our_mime_type){  
    790                 foreach ($array_with_acceptables_of_same_quality as $acceptable){  
    791                     if ($mime_type == $acceptable){  
    792                         return $our_mime_type;  
    793                     }  
    794                 }  
    795             }  
    796         }  
    797         return $this->mime_types['default'];  
    798     }  
    799     function getContentType()  
    800     {  
    801         if (empty($this->env['CONTENT_TYPE'])) return false;  
    802         $mime_type_struct = $this->_parseMimeType($this->env['CONTENT_TYPE']);  
    803         return $mime_type_struct['type'];  
    804     }  
    805     function _lookupMimeType($mime_type)  
    806     {  
    807         if (!isset($this->mime_types[$mime_type])) { 
    808             //trigger_error(Ak::t('Unsupported mime %mime',array('%mime'=>$mime_type)), E_USER_WARNING); 
    809             return null; 
    810         } 
    811         return $this->mime_types[$mime_type];  
    812     } 
    813     function _bestMimeType()  
    814     {  
    815         return $this->_getMimeType($this->getAccepts());  
    816     }  
     758 
    817759    // {{{ recognize() 
    818760 
  • branches/arnoschn/cache/test/unit/lib/AkActionController/_respond_to_format.php

    r1067 r1184  
    1717         
    1818    } 
     19    function test_xml_format_with_accept_header() 
     20    { 
     21        $_SERVER['HTTP_ACCEPT'] = 'application/xml'; 
     22        $this->get('http://www.example.com/people/listing'); 
     23        $this->assertHeader('Content-Type','application/xml'); 
     24         
     25    } 
    1926    function test_xml_format() 
    2027    { 
  • branches/arnoschn/cache/test/unit/lib/AkActionController/_sweeper.php

    r897 r1184  
    9393        $this->post('http://www.example.com/cache_sweeper/delete/'.$this->userId,array('first_name'=>'Max Schmidt')); 
    9494        $this->assertResponse(200); 
     95        $this->get('http://www.example.com/page_caching/'); 
    9596        $this->_assertCacheExists('/'.Ak::lang().'/cache_sweeper/show/'.$this->userId,array('host'=>'www.example.com')); 
    9697         
     
    116117         */ 
    117118        $this->post('http://www.example.com/cache_sweeper2/delete/'.$this->userId); 
     119        $this->get('http://www.example.com/page_caching/'); 
    118120        $this->_assertCacheExists('/'.Ak::lang().'/cache_sweeper2/show/'.$this->userId,array('host'=>'www.example.com')); 
    119121        /**