Changeset 10627
- Timestamp:
- 08/03/08 10:52:28 (4 months ago)
- Files:
-
- branches/1.2/lib/config/config/factories.yml (modified) (1 diff)
- branches/1.2/lib/config/config/settings.yml (modified) (1 diff)
- branches/1.2/lib/config/sfFactoryConfigHandler.class.php (modified) (1 diff)
- branches/1.2/lib/plugins/sfCompat10Plugin/config/config.php (modified) (2 diffs)
- branches/1.2/lib/plugins/sfCompat10Plugin/lib/request (added)
- branches/1.2/lib/plugins/sfCompat10Plugin/lib/request/sfRequestCompat10.class.php (added)
- branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/request/sfRequestTest.php (modified) (2 diffs)
- branches/1.2/lib/request/sfRequest.class.php (modified) (5 diffs)
- branches/1.2/lib/request/sfWebRequest.class.php (modified) (10 diffs)
- branches/1.2/lib/task/generator/skeleton/app/app/config/settings.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/config/config/factories.yml
r9285 r10627 6 6 class: sfWebRequest 7 7 param: 8 logging: %SF_LOGGING_ENABLED% 9 path_info_array: SERVER 10 path_info_key: PATH_INFO 8 11 formats: 9 12 txt: text/plain branches/1.2/lib/config/config/settings.yml
r10124 r10627 64 64 strip_comments: on # Remove comments in core framework classes as defined in the core_compile.yml 65 65 max_forwards: 5 66 path_info_array: SERVER67 path_info_key: PATH_INFO68 66 url_format: PATH 69 67 branches/1.2/lib/config/sfFactoryConfigHandler.class.php
r9159 r10627 91 91 92 92 case 'request': 93 $instances[] = sprintf(" \$class = sfConfig::get('sf_factory_request', '%s');\n \$this->factories['request'] = new \$class(\$this->dispatcher, array(), sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", $class, var_export($parameters, true));93 $instances[] = sprintf(" \$class = sfConfig::get('sf_factory_request', '%s');\n \$this->factories['request'] = new \$class(\$this->dispatcher, array(), array(), sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", $class, var_export($parameters, true)); 94 94 break; 95 95 branches/1.2/lib/plugins/sfCompat10Plugin/config/config.php
r8596 r10627 7 7 class sfCompatAutoload extends sfSimpleAutoload 8 8 { 9 10 9 } 11 10 … … 22 21 sfProjectConfiguration::getActive()->getConfigCache()->registerConfigHandler('modules/*/config/mailer.yml', 'sfDefineEnvironmentConfigHandler', array('prefix' => 'sf_mailer_', 'module' => 'yes')); 23 22 23 // register request compat methods 24 if ($this instanceof sfConfigCache) 25 { 26 // here if we are included from an admin generator module (for 1.0) 27 sfProjectConfiguration::getActive()->getEventDispatcher()->connect('request.method_not_found', array('sfRequestCompat10', 'call')); 28 } 29 else 30 { 31 $this->dispatcher->connect('request.method_not_found', array('sfRequestCompat10', 'call')); 32 } 33 24 34 // register the validation execution filter 25 35 sfConfig::set('sf_execution_filter', array('sfValidationExecutionFilter', array())); branches/1.2/lib/plugins/sfCompat10Plugin/test/unit/request/sfRequestTest.php
r5493 r10627 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 sfConfig::set('sf_compat_10', true);14 15 13 class myRequest extends sfRequest 16 14 { … … 24 22 25 23 $dispatcher = new sfEventDispatcher(); 24 $dispatcher->connect('request.method_not_found', array('sfRequestCompat10', 'call')); 25 26 26 $request = new myRequest($dispatcher); 27 27 branches/1.2/lib/request/sfRequest.class.php
r9098 r10627 60 60 61 61 protected 62 $errors = array(),63 62 $dispatcher = null, 64 63 $method = null, 64 $options = array(), 65 65 $parameterHolder = null, 66 $config = null,67 66 $attributeHolder = null; 68 67 … … 72 71 * @see initialize() 73 72 */ 74 public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array() )75 { 76 $this->initialize($dispatcher, $parameters, $attributes );73 public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) 74 { 75 $this->initialize($dispatcher, $parameters, $attributes, $options); 77 76 } 78 77 … … 88 87 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRequest 89 88 */ 90 public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array() )89 public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) 91 90 { 92 91 $this->dispatcher = $dispatcher; 92 93 $this->options = $options; 94 95 if (!isset($this->options['logging'])) 96 { 97 $this->options['logging'] = false; 98 } 93 99 94 100 // initialize parameter and attribute holders … … 126 132 127 133 /** 128 * Retrieves an error message.129 *130 * @param string $name An error name131 *132 * @return string An error message, if the error exists, otherwise null133 */134 public function getError($name)135 {136 if (!sfConfig::get('sf_compat_10'))137 {138 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');139 }140 141 return isset($this->errors[$name]) ? $this->errors[$name] : null;142 }143 144 /**145 * Retrieves an array of error names.146 *147 * @return array An indexed array of error names148 */149 public function getErrorNames()150 {151 if (!sfConfig::get('sf_compat_10'))152 {153 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');154 }155 156 return array_keys($this->errors);157 }158 159 /**160 * Retrieves an array of errors.161 *162 * @return array An associative array of errors163 */164 public function getErrors()165 {166 if (!sfConfig::get('sf_compat_10'))167 {168 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');169 }170 171 return $this->errors;172 }173 174 /**175 134 * Retrieves this request's method. 176 135 * … … 182 141 { 183 142 return $this->method; 184 }185 186 /**187 * Indicates whether or not an error exists.188 *189 * @param string $name An error name190 *191 * @return bool true, if the error exists, otherwise false192 */193 public function hasError($name)194 {195 if (!sfConfig::get('sf_compat_10'))196 {197 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');198 }199 200 return array_key_exists($name, $this->errors);201 }202 203 /**204 * Indicates whether or not any errors exist.205 *206 * @return bool true, if any error exist, otherwise false207 */208 public function hasErrors()209 {210 if (!sfConfig::get('sf_compat_10'))211 {212 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');213 }214 215 return count($this->errors) > 0;216 }217 218 /**219 * Removes an error.220 *221 * @param string $name An error name222 *223 * @return string An error message, if the error was removed, otherwise null224 */225 public function removeError($name)226 {227 if (!sfConfig::get('sf_compat_10'))228 {229 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');230 }231 232 $retval = null;233 234 if (isset($this->errors[$name]))235 {236 $retval = $this->errors[$name];237 238 unset($this->errors[$name]);239 }240 241 return $retval;242 }243 244 /**245 * Sets an error.246 *247 * @param string $name An error name248 * @param string $message An error message249 *250 */251 public function setError($name, $message)252 {253 if (!sfConfig::get('sf_compat_10'))254 {255 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');256 }257 258 if (sfConfig::get('sf_logging_enabled'))259 {260 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Error in form for parameter "%s" (with message "%s")', $name, $message))));261 }262 263 $this->errors[$name] = $message;264 }265 266 /**267 * Sets an array of errors268 *269 * If an existing error name matches any of the keys in the supplied270 * array, the associated message will be overridden.271 *272 * @param array $erros An associative array of errors and their associated messages273 *274 */275 public function setErrors($errors)276 {277 if (!sfConfig::get('sf_compat_10'))278 {279 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');280 }281 282 $this->errors = array_merge($this->errors, $errors);283 143 } 284 144 branches/1.2/lib/request/sfWebRequest.class.php
r10060 r10627 46 46 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRequest 47 47 */ 48 public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array() )49 { 50 parent::initialize($dispatcher, $parameters, $attributes );48 public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) 49 { 50 parent::initialize($dispatcher, $parameters, $attributes, $options); 51 51 52 52 if (isset($_SERVER['REQUEST_METHOD'])) … … 84 84 } 85 85 86 foreach ($this->getAttribute('formats', array()) as $format => $mimeTypes) 87 { 88 $this->setFormat($format, $mimeTypes); 86 if (isset($this->options['formats'])) 87 { 88 foreach ($this->options['formats'] as $format => $mimeTypes) 89 { 90 $this->setFormat($format, $mimeTypes); 91 } 92 } 93 94 if (!isset($this->options['path_info_key'])) 95 { 96 $this->options['path_info_key'] = 'PATH_INFO'; 97 } 98 99 if (!isset($this->options['path_info_array'])) 100 { 101 $this->options['path_info_array'] = 'SERVER'; 89 102 } 90 103 … … 94 107 95 108 /** 96 * Retrieves an array of file information.97 *98 * @param string $name A file name99 *100 * @return array An associative array of file information, if the file exists, otherwise null101 */102 public function getFile($name)103 {104 if (!sfConfig::get('sf_compat_10'))105 {106 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');107 }108 109 return $this->hasFile($name) ? $this->getFileValues($name) : null;110 }111 112 /**113 * Retrieves a file error.114 *115 * @param string $name A file name116 *117 * @return int One of the following error codes:118 *119 * - <b>UPLOAD_ERR_OK</b> (no error)120 * - <b>UPLOAD_ERR_INI_SIZE</b> (the uploaded file exceeds the121 * upload_max_filesize directive122 * in php.ini)123 * - <b>UPLOAD_ERR_FORM_SIZE</b> (the uploaded file exceeds the124 * MAX_FILE_SIZE directive that125 * was specified in the HTML form)126 * - <b>UPLOAD_ERR_PARTIAL</b> (the uploaded file was only127 * partially uploaded)128 * - <b>UPLOAD_ERR_NO_FILE</b> (no file was uploaded)129 */130 public function getFileError($name)131 {132 if (!sfConfig::get('sf_compat_10'))133 {134 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');135 }136 137 return $this->hasFile($name) ? $this->getFileValue($name, 'error') : UPLOAD_ERR_NO_FILE;138 }139 140 /**141 * Retrieves a file name.142 *143 * @param string $name A file nam.144 *145 * @return string A file name, if the file exists, otherwise null146 */147 public function getFileName($name)148 {149 if (!sfConfig::get('sf_compat_10'))150 {151 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');152 }153 154 return $this->hasFile($name) ? $this->getFileValue($name, 'name') : null;155 }156 157 /**158 * Retrieves an array of file names.159 *160 * @return array An indexed array of file names161 */162 public function getFileNames()163 {164 if (!sfConfig::get('sf_compat_10'))165 {166 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');167 }168 169 return array_keys($_FILES);170 }171 172 /**173 * Retrieves an array of files.174 *175 * @param string $key A key176 * @return array An associative array of files177 */178 public function getFiles($key = null)179 {180 return is_null($key) ? $_FILES : (isset($_FILES[$key]) ? $_FILES[$key] : array());181 }182 183 /**184 * Retrieves a file path.185 *186 * @param string $name A file name187 *188 * @return string A file path, if the file exists, otherwise null189 */190 public function getFilePath($name)191 {192 if (!sfConfig::get('sf_compat_10'))193 {194 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');195 }196 197 return $this->hasFile($name) ? $this->getFileValue($name, 'tmp_name') : null;198 }199 200 /**201 * Retrieve a file size.202 *203 * @param string $name A file name204 *205 * @return int A file size, if the file exists, otherwise null206 */207 public function getFileSize($name)208 {209 if (!sfConfig::get('sf_compat_10'))210 {211 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');212 }213 214 return $this->hasFile($name) ? $this->getFileValue($name, 'size') : null;215 }216 217 /**218 * Retrieves a file type.219 *220 * This may not be accurate. This is the mime-type sent by the browser221 * during the upload.222 *223 * @param string $name A file name224 *225 * @return string A file type, if the file exists, otherwise null226 */227 public function getFileType($name)228 {229 if (!sfConfig::get('sf_compat_10'))230 {231 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');232 }233 234 return $this->hasFile($name) ? $this->getFileValue($name, 'type') : null;235 }236 237 /**238 * Indicates whether or not a file exists.239 *240 * @param string $name A file name241 *242 * @return bool true, if the file exists, otherwise false243 */244 public function hasFile($name)245 {246 if (!sfConfig::get('sf_compat_10'))247 {248 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');249 }250 251 if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))252 {253 return isset($_FILES[$match[1]]['name'][$match[2]]);254 }255 else256 {257 return isset($_FILES[$name]);258 }259 }260 261 /**262 * Indicates whether or not a file error exists.263 *264 * @param string $name A file name265 *266 * @return bool true, if the file error exists, otherwise false267 */268 public function hasFileError($name)269 {270 if (!sfConfig::get('sf_compat_10'))271 {272 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');273 }274 275 return $this->hasFile($name) ? ($this->getFileValue($name, 'error') != UPLOAD_ERR_OK) : false;276 }277 278 /**279 * Indicates whether or not any file errors occured.280 *281 * @return bool true, if any file errors occured, otherwise false282 */283 public function hasFileErrors()284 {285 if (!sfConfig::get('sf_compat_10'))286 {287 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');288 }289 290 foreach ($this->getFileNames() as $name)291 {292 if ($this->hasFileError($name) === true)293 {294 return true;295 }296 }297 298 return false;299 }300 301 /**302 * Indicates whether or not any files exist.303 *304 * @return boolean true, if any files exist, otherwise false305 */306 public function hasFiles()307 {308 if (!sfConfig::get('sf_compat_10'))309 {310 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');311 }312 313 return (count($_FILES) > 0);314 }315 316 /**317 * Retrieves a file value.318 *319 * @param string $name A file name320 * @param string $key Value to search in the file321 *322 * @return string File value323 */324 public function getFileValue($name, $key)325 {326 if (!sfConfig::get('sf_compat_10'))327 {328 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');329 }330 331 if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))332 {333 return $_FILES[$match[1]][$key][$match[2]];334 }335 else336 {337 return $_FILES[$name][$key];338 }339 }340 341 /**342 * Retrieves all the values from a file.343 *344 * @param string $name A file name345 *346 * @return array Associative list of the file values347 */348 public function getFileValues($name)349 {350 if (!sfConfig::get('sf_compat_10'))351 {352 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');353 }354 355 if (preg_match('/^(.+?)\[(.+?)\]$/', $name, $match))356 {357 return array(358 'name' => $_FILES[$match[1]]['name'][$match[2]],359 'type' => $_FILES[$match[1]]['type'][$match[2]],360 'tmp_name' => $_FILES[$match[1]]['tmp_name'][$match[2]],361 'error' => $_FILES[$match[1]]['error'][$match[2]],362 'size' => $_FILES[$match[1]]['size'][$match[2]],363 );364 }365 else366 {367 return $_FILES[$name];368 }369 }370 371 /**372 * Retrieves an extension for a given file.373 *374 * @param string $name A file name375 *376 * @return string Extension for the file377 */378 public function getFileExtension($name)379 {380 if (!sfConfig::get('sf_compat_10'))381 {382 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');383 }384 385 static $mimeTypes = null;386 387 $fileType = $this->getFileType($name);388 389 if (!$fileType)390 {391 return '.bin';392 }393 394 if (is_null($mimeTypes))395 {396 $mimeTypes = unserialize(file_get_contents(sfConfig::get('sf_symfony_lib_dir').'/plugins/sfCompat10Plugin/data/mime_types.dat'));397 }398 399 return isset($mimeTypes[$fileType]) ? '.'.$mimeTypes[$fileType] : '.bin';400 }401 402 /**403 109 * Retrieves the uniform resource identifier for the current web request. 404 110 * … … 474 180 475 181 // simulate PATH_INFO if needed 476 $sf_path_info_key = sfConfig::get('sf_path_info_key', 'PATH_INFO');182 $sf_path_info_key = $this->options['path_info_key']; 477 183 if (!isset($pathArray[$sf_path_info_key]) || !$pathArray[$sf_path_info_key]) 478 184 { … … 491 197 { 492 198 $pathInfo = $pathArray[$sf_path_info_key]; 493 if ($ sf_relative_url_root = $this->getRelativeUrlRoot())494 { 495 $pathInfo = preg_replace('/^'.str_replace('/', '\\/', $ sf_relative_url_root).'\//', '', $pathInfo);199 if ($relativeUrlRoot = $this->getRelativeUrlRoot()) 200 { 201 $pathInfo = preg_replace('/^'.str_replace('/', '\\/', $relativeUrlRoot).'\//', '', $pathInfo); 496 202 } 497 203 } … … 524 230 { 525 231 return $this->requestParameters; 526 }527 528 /**529 * Moves an uploaded file.530 *531 * @param string $name A file name532 * @param string $file An absolute filesystem path to where you would like the533 * file moved. This includes the new filename as well, since534 * uploaded files are stored with random names535 * @param int $fileMode The octal mode to use for the new file536 * @param bool $create Indicates that we should make the directory before moving the file537 * @param int $dirMode The octal mode to use when creating the directory538 *539 * @return bool true, if the file was moved, otherwise false540 *541 * @throws <b>sfFileException</b> If a major error occurs while attempting to move the file542 */543 public function moveFile($name, $file, $fileMode = 0666, $create = true, $dirMode = 0777)544 {545 if (!sfConfig::get('sf_compat_10'))546 {547 throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');548 }549 550 if ($this->hasFile($name) && $this->getFileValue($name, 'error') == UPLOAD_ERR_OK && $this->getFileValue($name, 'size') > 0)551 {552 // get our directory path from the destination filename553 $directory = dirname($file);554 555 if (!is_readable($directory))556 {557 $fmode = 0777;558 559 if ($create && !@mkdir($directory, $dirMode, true))560 {561 // failed to create the directory562 throw new sfFileException(sprintf('Failed to create file upload directory "%s".', $directory));563 }564 565 // chmod the directory since it doesn't seem to work on566 // recursive paths567 @chmod($directory, $dirMode);568 }569 else if (!is_dir($directory))570 {571 // the directory path exists but it's not a directory572 throw new sfFileException(sprintf('File upload path "%s" exists, but is not a directory.', $directory));573 }574 else if (!is_writable($directory))575 {576 // the directory isn't writable577 throw new sfFileException(sprintf('File upload path "%s" is not writable.', $directory));578 }579 580 if (@move_uploaded_file($this->getFileValue($name, 'tmp_name'), $file))581 {582 // chmod our file583 @chmod($file, $fileMode);584 585 return true;586 }587 }588 589 return false;590 232 } 591 233 … … 849 491 public function getRelativeUrlRoot() 850 492 { 851 if ($this->relativeUrlRoot === null) 852 { 853 $this->relativeUrlRoot = sfConfig::get('sf_relative_url_root', preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName())); 493 if (is_null($this->relativeUrlRoot)) 494 { 495 if (!isset($this->options['relative_url_root'])) 496 { 497 $this->relativeUrlRoot = preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName()); 498 } 499 else 500 { 501 $this->relativeUrlRoot = $this->options['relative_url_root']; 502 } 854 503 } 855 504 … … 908 557 { 909 558 // parse PATH_INFO 910 switch ( sfConfig::get('sf_path_info_array', 'SERVER'))559 switch ($this->options['path_info_array']) 911 560 { 912 561 case 'SERVER': … … 1007 656 1008 657 /** 658 * Retrieves an array of files. 659 * 660 * @param string $key A key 661 * @return array An associative array of files 662 */ 663 static public function getFiles($key = null) 664 { 665 return is_null($key) ? $_FILES : (isset($_FILES[$key]) ? $_FILES[$key] : array()); 666 } 667 668 /** 1009 669 * Returns the value of a GET parameter. 1010 670 * … … 1138 798 } 1139 799 1140 if ( sfConfig::get('sf_logging_enabled'))800 if ($this->options['logging']) 1141 801 { 1142 802 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))))); branches/1.2/lib/task/generator/skeleton/app/app/config/settings.yml
r10124 r10627 87 87 # strip_comments: on # Remove comments in core framework classes as defined in the core_compile.yml 88 88 # max_forwards: 5 89 # path_info_array: SERVER90 # path_info_key: PATH_INFO91 89 # url_format: PATH 92 90 #