- Timestamp:
- 10/07/08 09:55:17 (2 months ago)
- Files:
-
- branches/arnoschn/cache/lib/AkActionController/AkCacheHandler.php (modified) (8 diffs)
- branches/arnoschn/cache/lib/AkRequest.php (modified) (2 diffs)
- branches/arnoschn/cache/lib/AkRequestMimeType.php (added)
- branches/arnoschn/cache/test/unit/lib/AkActionController/_respond_to_format.php (modified) (1 diff)
- branches/arnoschn/cache/test/unit/lib/AkActionController/_sweeper.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/arnoschn/cache/lib/AkActionController/AkCacheHandler.php
r1182 r1184 19 19 20 20 require_once(AK_LIB_DIR.DS.'AkCache.php'); 21 21 require_once(AK_LIB_DIR.DS.'AkRequestMimeType.php'); 22 22 /** 23 23 * … … 636 636 $headerString = var_export($finalHeaders,true); 637 637 //$functionStr = file_get_contents(dirname(__FILE__).DS.'cache_page_functions.txt'); 638 $content = preg_replace('/(<\?|<\?php|\?>)/','<?php echo "\1";?>', $content); 638 639 $content = <<<EOF 639 640 <?php … … 677 678 } 678 679 Ak::parseOptions($options, $default_options,array(),true); 679 680 680 681 foreach ($options as $sweeper => $params) { 681 682 if (is_int($sweeper)) { … … 683 684 $params = array(); 684 685 } 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 } 685 692 $this->_initSweeper($sweeper, $params); 686 693 } … … 689 696 function _initSweeper($sweeper, $options = array()) 690 697 { 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; 693 700 694 701 $sweeper_class = AkInflector::classify($sweeper); … … 814 821 $cacheId.= '.'.$this->_controller->Request->getFormat(); 815 822 } else { 816 $cacheId.= $this->_page_cache_extension; 823 824 list($format, $requestPath) = AkRequestMimeType::getFormat($path); 825 $cacheId.= '.'.$format; 817 826 } 818 827 } … … 911 920 static $_cached; 912 921 913 $key = $this->fragmentCachekey($key, $options);922 $key = $this->fragmentCachekey($key, $options); 914 923 if (empty($_cached)) { 915 924 $_cached = array(); … … 960 969 { 961 970 if (!$this->cacheConfigured()) return false; 962 971 972 $orgkey = $key; 973 963 974 $key = $this->fragmentCachekey($key, $options); 964 975 965 976 return $this->_cache_store->get($key, isset($options['host'])? 966 977 $options['host']:$this->_buildCacheGroup()); branches/arnoschn/cache/lib/AkRequest.php
r1159 r1184 31 31 $_SERVER['REQUEST_URI'] = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME'].(( isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''))); 32 32 33 33 require_once(AK_LIB_DIR.DS.'AkRequestMimeType.php'); 34 34 /** 35 35 * Class that handles incoming request. … … 738 738 function getFormat() 739 739 { 740 741 740 742 if (isset($this->_format)) { 741 743 return $this->_format; 742 744 } else if (isset($this->_request['format'])) { 743 745 $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 } 760 754 } 761 755 return $this->_format; 762 756 } 763 757 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 817 759 // {{{ recognize() 818 760 branches/arnoschn/cache/test/unit/lib/AkActionController/_respond_to_format.php
r1067 r1184 17 17 18 18 } 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 } 19 26 function test_xml_format() 20 27 { branches/arnoschn/cache/test/unit/lib/AkActionController/_sweeper.php
r897 r1184 93 93 $this->post('http://www.example.com/cache_sweeper/delete/'.$this->userId,array('first_name'=>'Max Schmidt')); 94 94 $this->assertResponse(200); 95 $this->get('http://www.example.com/page_caching/'); 95 96 $this->_assertCacheExists('/'.Ak::lang().'/cache_sweeper/show/'.$this->userId,array('host'=>'www.example.com')); 96 97 … … 116 117 */ 117 118 $this->post('http://www.example.com/cache_sweeper2/delete/'.$this->userId); 119 $this->get('http://www.example.com/page_caching/'); 118 120 $this->_assertCacheExists('/'.Ak::lang().'/cache_sweeper2/show/'.$this->userId,array('host'=>'www.example.com')); 119 121 /**
