Changeset 22976
- Timestamp:
- 10/12/09 23:56:20 (4 years ago)
- Files:
-
- plugins/swOptimizeRoutesPlugin/trunk/lib/output/swApacheOutputHandler.class.php (modified) (4 diffs)
- plugins/swOptimizeRoutesPlugin/trunk/lib/output/swBaseOutputHandler.class.php (modified) (2 diffs)
- plugins/swOptimizeRoutesPlugin/trunk/lib/swOptimizePatternRouting.class.php (modified) (6 diffs)
- plugins/swOptimizeRoutesPlugin/trunk/lib/swOptimizeRoutingConfigHandler.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/swOptimizeRoutesPlugin/trunk/lib/output/swApacheOutputHandler.class.php
r22847 r22976 26 26 { 27 27 28 $output = ""; 28 $output = array( 29 'HEAD' => array(), 30 'PUT' => array(), 31 'DELETE' => array(), 32 'POST' => array(), 33 'GET' => array(), 34 'OTHER' => array(), 35 ); 36 29 37 foreach($this->routing->getRoutes() as $name => $route) 30 38 { … … 79 87 } 80 88 89 $methods = $this->getMethods($requirements['sf_method']); 90 81 91 $url = $this->fixUrl($route, $url, $sf_format); 82 92 $condition .= $this->renderCondition($name, $url, $sf_format); 83 93 84 $output .= $condition."\n"; 94 foreach($methods as $method) 95 { 96 97 $output[$method][] = $condition; 98 } 99 } 100 101 $final_output = ""; 102 103 if( count($output['OTHER']) > 0) 104 { 105 $final_output .= implode("\n", $output['OTHER']); 106 $final_output .= "\n\n"; 107 } 108 109 if( count($output['PUT']) > 0) 110 { 111 $final_output .= 'RewriteCond %{REQUEST_METHOD} "GET"'; 112 $final_output .= "\n"; 113 $final_output .= implode("\n", $output['GET']); 114 115 $final_output .= "\n\n"; 85 116 } 86 117 87 return $output; 118 if( count($output['HEAD']) > 0) 119 { 120 $final_output .= 'RewriteCond %{REQUEST_METHOD} "HEAD"'; 121 $final_output .= "\n"; 122 $final_output .= implode("\n", $output['HEAD']); 123 124 $final_output .= "\n\n"; 125 } 126 127 if( count($output['DELETE']) > 0) 128 { 129 $final_output .= 'RewriteCond %{REQUEST_METHOD} "DELETE"'; 130 $final_output .= "\n"; 131 $final_output .= implode("\n", $output['DELETE']); 132 133 $final_output .= "\n\n"; 134 } 135 136 if( count($output['GET']) > 0) 137 { 138 $final_output .= 'RewriteCond %{REQUEST_METHOD} "GET"'; 139 $final_output .= "\n"; 140 $final_output .= implode("\n", $output['GET']); 141 142 $final_output .= "\n\n"; 143 } 144 145 if( count($output['POST']) > 0) 146 { 147 $final_output .= 'RewriteCond %{REQUEST_METHOD} "POST"'; 148 $final_output .= "\n"; 149 $final_output .= implode("\n", $output['POST']); 150 151 $final_output .= "\n\n"; 152 } 153 154 return $final_output; 88 155 } 89 156 … … 91 158 { 92 159 93 return sprintf('RewriteRule ^%-60s %s?sf_route=%s [QSA,L]', 160 return sprintf('RewriteRule ^%s%-60s %s?sf_route=%s [QSA,L]', 161 $this->url_prefix, 94 162 $url, 95 163 $this->path_prefix, … … 99 167 } 100 168 169 101 170 // NOTE to handle .:sf_format option : (\.([^/\.])+$|$) 102 103 171 public function fixUrl($route, $url, $sf_format) 104 172 { plugins/swOptimizeRoutesPlugin/trunk/lib/output/swBaseOutputHandler.class.php
r22847 r22976 21 21 protected 22 22 $routing = null, 23 $url_prefix = '', 23 24 $path_prefix = '/index.php'; 24 25 … … 30 31 * 31 32 */ 32 public function __construct(sfRouting $routing )33 public function __construct(sfRouting $routing, $options = array()) 33 34 { 35 34 36 $this->routing = $routing; 37 $this->path_prefix = $options['path_prefix']; 38 $this->url_prefix = $options['url_prefix']; 39 } 40 41 public function getMethods($methods) 42 { 43 44 if($methods === null) 45 { 46 $methods = array('OTHER'); 47 } 48 49 if(!is_array($methods)) 50 { 51 $methods = array($methods); 52 } 53 54 // clean the sf_format, as the sf_format 55 // is just simulated 56 $final_methods = array(); 57 $simulated_formats = array('PUT', 'DELETE', 'HEAD'); 58 foreach($methods as $method) 59 { 60 $method = strtoupper($method); 61 62 $final_methods[] = $method; 63 if( in_array($method, $simulated_formats) && !in_array('POST', $methods)) 64 { 65 $final_methods[] = 'POST'; 66 } 67 } 68 69 70 return $final_methods; 35 71 } 36 72 plugins/swOptimizeRoutesPlugin/trunk/lib/swOptimizePatternRouting.class.php
r22872 r22976 41 41 } 42 42 43 throw new sfException('The route cannot be match by yourserver');43 throw new sfException('The route cannot be match by the server'); 44 44 45 45 return parent::findRoute($url); … … 78 78 79 79 $class = $route_information['route_class']; 80 $data = gzinflate($route_information['route_serialization']); 81 // $data = $route_information['route_serialization']; 82 83 84 $options = array(); 80 $data = $route_information['route_serialization']; 85 81 86 82 // set array in a config file 87 83 // or add options to call the event dispatcher 84 $options = array(); 88 85 if(in_array($class, array('sfDoctrineRoute', 'sfPropelRoute'))) 89 86 { … … 91 88 $options['type'] = 'object'; 92 89 } 93 90 94 91 $route = new $class('/foo', array(), array(), $options); 95 92 $route->unserialize($data); … … 97 94 $this->routes[$name] = $route; 98 95 99 if ( true ||$this->options['logging'])96 if ($this->options['logging']) 100 97 { 101 98 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Load route on demand "%s" (%s)', get_class($route), $name, $route->getPattern())))); … … 152 149 public function loadConfiguration() 153 150 { 154 // $time = microtime(true);155 156 151 if ($this->options['load_configuration'] 157 152 && $config = $this->getConfiguration()->getConfigCache()->checkConfig('config/routing.yml', true)) … … 161 156 $this->dispatcher->notify(new sfEvent($this, 'routing.load_configuration')); 162 157 } 163 164 // echo microtime(true) - $time;165 166 158 } 167 159 } plugins/swOptimizeRoutesPlugin/trunk/lib/swOptimizeRoutingConfigHandler.class.php
r22847 r22976 36 36 $export = array( 37 37 'route_class' => get_class($route_instance), 38 'route_serialization' => gzdeflate($route_instance->serialize()) 39 // 'route_serialization' => $route_instance->serialize() 38 'route_serialization' => $route_instance->serialize() 40 39 ); 41 40 42 41 $data[] = sprintf('\'%s\' => %s,', $name, var_export($export, 1)); 43 42 } 43 44 44 45 45 public function execute($configFiles)