Changeset 11783
- Timestamp:
- 09/25/08 18:21:27 (5 years ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (2 diffs)
- branches/1.2/lib/action/sfAction.class.php (modified) (2 diffs)
- branches/1.2/lib/config/sfApplicationConfiguration.class.php (modified) (5 diffs)
- branches/1.2/lib/config/sfLoader.class.php (modified) (3 diffs)
- branches/1.2/lib/config/sfProjectConfiguration.class.php (modified) (10 diffs)
- branches/1.2/lib/filter/sfCommonFilter.class.php (modified) (1 diff)
- branches/1.2/lib/helper/DateFormHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/DateHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/FormHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/HelperHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/ObjectAdminHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/ObjectHelper.php (modified) (1 diff)
- branches/1.2/lib/helper/sfRichTextEditorTinyMCE.class.php (modified) (1 diff)
- branches/1.2/lib/plugins/sfProtoculousPlugin/lib/helper/JavascriptHelper.php (modified) (1 diff)
- branches/1.2/lib/view/sfPHPView.class.php (modified) (1 diff)
- branches/1.2/lib/view/sfViewCacheManager.class.php (modified) (1 diff)
- branches/1.2/test/unit/filter/sfCommonFilterTest.php (modified) (1 diff)
- branches/1.2/test/unit/helper/FormHelperTest.php (modified) (1 diff)
- branches/1.2/test/unit/sfContextMock.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11701 r11783 1247 1247 public function setup() 1248 1248 { 1249 $this->setPlugins( 'sfDoctrinePlugin', 'sfCompat10Plugin');1249 $this->setPlugins(array('sfDoctrinePlugin', 'sfCompat10Plugin')); 1250 1250 } 1251 1251 … … 1278 1278 If you upgrade from 1.0 or 1.1, this line will make symfony behave like in 1279 1279 symfony 1.0 and 1.1. 1280 1281 The `sfLoader` class is deprecated as the `getHelperDirs()` and `loadHelpers()` 1282 methods are now part of the `sfApplicationConfiguration` class. The `sfLoader` 1283 methods now generate a deprecated log message and then call the new methods from 1284 the current active configuration. 1280 1285 1281 1286 Filters branches/1.2/lib/action/sfAction.class.php
r11254 r11783 274 274 public function getPartial($templateName, $vars = null) 275 275 { 276 sfLoader::loadHelpers('Partial');276 $this->getContext()->getConfiguration()->loadHelpers('Partial'); 277 277 278 278 $vars = !is_null($vars) ? $vars : $this->varHolder->getAll(); … … 317 317 public function getComponent($moduleName, $componentName, $vars = null) 318 318 { 319 sfLoader::loadHelpers('Partial');319 $this->getContext()->getConfiguration()->loadHelpers('Partial'); 320 320 321 321 $vars = !is_null($vars) ? $vars : $this->varHolder->getAll(); branches/1.2/lib/config/sfApplicationConfiguration.class.php
r11644 r11783 20 20 { 21 21 static protected 22 $coreLoaded = false; 22 $coreLoaded = false, 23 $loadedHelpers = array(); 23 24 24 25 protected … … 315 316 } 316 317 317 $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/templates'; // application 318 319 foreach ($this->getPluginPaths() as $path) 320 { 321 if (is_dir($dir = $path.'/modules/'.$moduleName.'/templates')) 322 { 323 $dirs[] = $dir; // plugins 324 } 325 } 326 327 $dirs[] = sfConfig::get('sf_symfony_lib_dir').'/controller/'.$moduleName.'/templates'; // core modules 328 $dirs[] = sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($moduleName.'/templates'); // generated templates in cache 318 $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/templates'; // application 319 $dirs = array_merge($dirs, $this->getPluginSubPaths('/modules/'.$moduleName.'/templates')); // plugins 320 $dirs[] = sfConfig::get('sf_symfony_lib_dir').'/controller/'.$moduleName.'/templates'; // core modules 321 $dirs[] = sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($moduleName.'/templates'); // generated templates in cache 329 322 330 323 return $dirs; 324 } 325 326 /** 327 * Gets the helper directories for a given module name. 328 * 329 * @param string $moduleName The module name 330 * 331 * @return array An array of directories 332 */ 333 public function getHelperDirs($moduleName = '') 334 { 335 $dirs = array(); 336 337 if ($moduleName) 338 { 339 $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/lib/helper'; // module 340 341 $dirs = array_merge($dirs, $this->getPluginSubPaths('/modules/'.$moduleName.'/lib/helper')); 342 } 343 344 return array_merge( 345 $dirs, 346 array( 347 sfConfig::get('sf_app_lib_dir').'/helper', // application 348 sfConfig::get('sf_lib_dir').'/helper', // project 349 ), 350 $this->getPluginSubPaths('/lib/helper'), // plugins 351 array(sfConfig::get('sf_symfony_lib_dir').'/helper') // symfony 352 ); 331 353 } 332 354 … … 411 433 412 434 // plugins 413 foreach ($this->getPluginPaths() as $path) 414 { 415 if (is_dir($dir = $path.'/i18n')) 416 { 417 $dirs[] = $dir; 418 } 419 } 420 421 return $dirs; 435 return array_merge($dirs, $this->getPluginPaths('/i18n')); 422 436 } 423 437 … … 445 459 } 446 460 447 // module in plugins 448 foreach ($this->getPluginPaths() as $path) 449 { 450 if (is_dir($dir = $path.'/modules/'.$moduleName.'/i18n')) 451 { 452 $dirs[] = $dir; 453 } 454 } 455 456 // plugins 457 foreach ($this->getPluginPaths() as $path) 458 { 459 if (is_dir($dir = $path.'/i18n')) 460 { 461 $dirs[] = $dir; 462 } 463 } 464 465 return $dirs; 461 return array_merge( 462 $dirs, 463 $this->getPluginSubPaths('/modules/'.$moduleName.'/i18n'), // module in plugins 464 $this->getPluginSubPaths('/i18n') // plugins 465 ); 466 466 } 467 467 … … 519 519 520 520 /** 521 * Loads helpers. 522 * 523 * @param array $helpers An array of helpers to load 524 * @param string $moduleName A module name (optional) 525 */ 526 public function loadHelpers($helpers, $moduleName = '') 527 { 528 $dirs = $this->getHelperDirs($moduleName); 529 foreach ((array) $helpers as $helperName) 530 { 531 if (isset(self::$loadedHelpers[$helperName])) 532 { 533 continue; 534 } 535 536 $fileName = $helperName.'Helper.php'; 537 foreach ($dirs as $dir) 538 { 539 $included = false; 540 if (is_readable($dir.'/'.$fileName)) 541 { 542 include_once($dir.'/'.$fileName); 543 $included = true; 544 break; 545 } 546 } 547 548 if (!$included) 549 { 550 // search in the include path 551 if ((@include_once('helper/'.$fileName)) != 1) 552 { 553 $dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path())); 554 555 // remove sf_root_dir from dirs 556 foreach ($dirs as &$dir) 557 { 558 $dir = str_replace('%SF_ROOT_DIR%', sfConfig::get('sf_root_dir'), $dir); 559 } 560 561 throw new InvalidArgumentException(sprintf('Unable to load "%sHelper.php" helper in: %s.', $helperName, implode(', ', $dirs))); 562 } 563 } 564 565 self::$loadedHelpers[$helperName] = true; 566 } 567 } 568 569 /** 521 570 * Loads config.php files from plugins 522 571 * branches/1.2/lib/config/sfLoader.class.php
r10147 r11783 11 11 /** 12 12 * sfLoader is a class which contains the logic to look for files/classes in symfony. 13 * 14 * This class is deprecated. The same methods now exist in sfApplicationConfiguration. 13 15 * 14 16 * @package symfony … … 28 30 static public function getHelperDirs($moduleName = '') 29 31 { 30 $ dirs = array();32 $configuration = sfProjectConfiguration::getActive(); 31 33 32 if ($moduleName) 33 { 34 $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/lib/helper'; // module 34 $configuration->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('The sfLoader::getHelperDirs() method is deprecated. Please use the same method from sfApplicationConfiguration.', 'priority' => sfLogger::ERR))); 35 35 36 if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$moduleName.'/lib/helper')) 37 { 38 $dirs = array_merge($dirs, $pluginDirs); // module plugins 39 } 40 } 41 42 $dirs[] = sfConfig::get('sf_app_lib_dir').'/helper'; // application 43 44 $dirs[] = sfConfig::get('sf_lib_dir').'/helper'; // project 45 46 if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/helper')) 47 { 48 $dirs = array_merge($dirs, $pluginDirs); // plugins 49 } 50 51 $dirs[] = sfConfig::get('sf_symfony_lib_dir').'/helper'; // symfony 52 53 if ($pluginDirs = glob(sfConfig::get('sf_symfony_lib_dir').'/plugins/*/lib/helper')) 54 { 55 $dirs = array_merge($dirs, $pluginDirs); // symfony bundled plugins 56 } 57 58 return $dirs; 36 return $configuration->getHelperDirs($moduleName); 59 37 } 60 38 … … 69 47 static public function loadHelpers($helpers, $moduleName = '') 70 48 { 71 static $loaded = array();49 $configuration = sfProjectConfiguration::getActive(); 72 50 73 $dirs = self::getHelperDirs($moduleName); 74 foreach ((array) $helpers as $helperName) 75 { 76 if (isset($loaded[$helperName])) 77 { 78 continue; 79 } 51 $configuration->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('The sfLoader::loadHelpers() method is deprecated. Please use the same method from sfApplicationConfiguration.', 'priority' => sfLogger::ERR))); 80 52 81 $fileName = $helperName.'Helper.php'; 82 foreach ($dirs as $dir) 83 { 84 $included = false; 85 if (is_readable($dir.'/'.$fileName)) 86 { 87 include_once($dir.'/'.$fileName); 88 $included = true; 89 break; 90 } 91 } 92 93 if (!$included) 94 { 95 // search in the include path 96 if ((@include_once('helper/'.$fileName)) != 1) 97 { 98 $dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path())); 99 100 // remove sf_root_dir from dirs 101 foreach ($dirs as &$dir) 102 { 103 $dir = str_replace('%SF_ROOT_DIR%', sfConfig::get('sf_root_dir'), $dir); 104 } 105 106 throw new sfViewException(sprintf('Unable to load "%sHelper.php" helper in: %s.', $helperName, implode(', ', $dirs))); 107 } 108 } 109 110 $loaded[$helperName] = true; 111 } 53 return $configuration->loadHelpers($helpers, $moduleName); 112 54 } 113 55 } branches/1.2/lib/config/sfProjectConfiguration.class.php
r11776 r11783 23 23 $symfonyLibDir = null, 24 24 $plugins = array('sfPropelPlugin'), 25 $pluginPaths = null;25 $pluginPaths = array(); 26 26 27 27 static protected … … 148 148 public function getModelDirs() 149 149 { 150 $dirs = array(); 151 152 foreach ($this->getPluginPaths() as $path) 153 { 154 if (is_dir($dir = $path.'/lib/model')) 155 { 156 $dirs[] = $dir; // plugins 157 } 158 } 159 160 $dirs[] = sfConfig::get('sf_lib_dir').'/model'; // project 161 162 return $dirs; 150 return array_merge( 151 $this->getPluginSubPaths('/lib/model'), // plugins 152 array(sfConfig::get('sf_lib_dir').'/model') // project 153 ); 163 154 } 164 155 … … 173 164 public function getGeneratorTemplateDirs($class, $theme) 174 165 { 175 $dirs = array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'); // project 176 177 foreach ($this->getPluginPaths() as $path) 178 { 179 if (is_dir($dir = $path.'/data/generator/'.$class.'/'.$theme.'/template')) 180 { 181 $dirs[] = $dir; // plugins 182 } 183 } 184 185 return $dirs; 166 return array_merge( 167 array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'), // project 168 $this->getPluginSubPaths('/data/generator/'.$class.'/'.$theme.'/template') //plugins 169 ); 186 170 } 187 171 … … 196 180 public function getGeneratorSkeletonDirs($class, $theme) 197 181 { 198 $dirs = array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'); // project 199 200 foreach ($this->getPluginPaths() as $path) 201 { 202 if (is_dir($dir = $path.'/data/generator/'.$class.'/'.$theme.'/skeleton')) 203 { 204 $dirs[] = $dir; // plugins 205 } 206 } 207 208 return $dirs; 182 return array_merge( 183 array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'), // project 184 $this->getPluginSubPaths('/data/generator/'.$class.'/'.$theme.'/skeleton') // plugins 185 ); 209 186 } 210 187 … … 299 276 * Gets the list of enabled plugins. 300 277 * 301 * @ paramarray An array of enabled plugins278 * @return array An array of enabled plugins 302 279 */ 303 280 public function getPlugins() … … 307 284 308 285 /** 286 * Gets the paths plugin sub-directories, minding overloaded plugins. 287 * 288 * @param string $subPath The subdirectory to look for 289 * 290 * @return array The plugin paths. 291 */ 292 public function getPluginSubPaths($subPath = '') 293 { 294 if (array_key_exists($subPath, $this->pluginPaths)) 295 { 296 return $this->pluginPaths[$subPath]; 297 } 298 299 $this->pluginPaths[$subPath] = array(); 300 $pluginPaths = $this->getPluginPaths(); 301 foreach ($pluginPaths as $pluginPath) 302 { 303 if (is_dir($pluginPath.$subPath)) 304 { 305 $this->pluginPaths[$subPath][] = $pluginPath.$subPath; 306 } 307 } 308 309 return $this->pluginPaths[$subPath]; 310 } 311 312 /** 309 313 * Gets the paths to plugins root directories, minding overloaded plugins. 310 314 * … … 313 317 public function getPluginPaths() 314 318 { 315 if ( !is_null($this->pluginPaths))316 { 317 return $this->pluginPaths ;319 if (array_key_exists('', $this->pluginPaths)) 320 { 321 return $this->pluginPaths['']; 318 322 } 319 323 … … 322 326 // order the plugins 323 327 $basePaths = array_map(create_function('$v', 'return basename($v);'), $pluginPaths); 324 $this->pluginPaths = array();328 $this->pluginPaths[''] = array(); 325 329 326 330 foreach ($this->getPlugins() as $plugin) … … 328 332 if (false !== $pos = array_search($plugin, $basePaths)) 329 333 { 330 $this->pluginPaths[ ] = $pluginPaths[$pos];334 $this->pluginPaths[''][] = $pluginPaths[$pos]; 331 335 } 332 336 else … … 336 340 } 337 341 338 return $this->pluginPaths ;342 return $this->pluginPaths['']; 339 343 } 340 344 branches/1.2/lib/filter/sfCommonFilter.class.php
r9087 r11783 36 36 if (false !== ($pos = strpos($content, '</head>'))) 37 37 { 38 sfLoader::loadHelpers(array('Tag', 'Asset'));38 $this->context->getConfiguration()->loadHelpers(array('Tag', 'Asset')); 39 39 $html = ''; 40 40 if (!sfConfig::get('symfony.asset.javascripts_included', false)) branches/1.2/lib/helper/DateFormHelper.php
r11700 r11783 1 1 <?php 2 2 3 use_helper('Form');3 require_once dirname(__FILE__).'/FormHelper.php'; 4 4 5 5 /* branches/1.2/lib/helper/DateHelper.php
r8764 r11783 154 154 if (sfConfig::get('sf_i18n')) 155 155 { 156 use_helper('I18N');156 require_once dirname(__FILE__).'/I18NHelper.php'; 157 157 158 158 return __($string, $parameters); branches/1.2/lib/helper/FormHelper.php
r11700 r11783 715 715 if (!_get_option($options, 'rich', false)) 716 716 { 717 use_helper('DateForm');717 require_once dirname(__FILE__).'/DateFormHelper.php'; 718 718 719 719 // set culture for month tag branches/1.2/lib/helper/HelperHelper.php
r7757 r11783 20 20 function use_helper() 21 21 { 22 sfLoader::loadHelpers(func_get_args(), sfContext::getInstance()->getModuleName()); 22 $context = sfContext::getInstance(); 23 24 $context->getConfiguration()->loadHelpers(func_get_args(), $context->getModuleName()); 23 25 } branches/1.2/lib/helper/ObjectAdminHelper.php
r11778 r11783 1 1 <?php 2 2 3 use_helper('Form', 'JavascriptBase', 'Helper', 'I18N'); 3 require_once dirname(__FILE__).'/FormHelper.php'; 4 require_once dirname(__FILE__).'/JavascriptBaseHelper.php'; 5 require_once dirname(__FILE__).'/I18NHelper.php'; 4 6 5 7 /* branches/1.2/lib/helper/ObjectHelper.php
r11018 r11783 1 1 <?php 2 2 3 use_helper('Form');3 require_once dirname(__FILE__).'/FormHelper.php'; 4 4 5 5 /* branches/1.2/lib/helper/sfRichTextEditorTinyMCE.class.php
r11775 r11783 56 56 sfContext::getInstance()->getResponse()->addJavascript($js_path); 57 57 58 use_helper('JavascriptBase');58 require_once dirname(__FILE__).'/JavascriptBaseHelper.php'; 59 59 60 60 $tinymce_options = ''; branches/1.2/lib/plugins/sfProtoculousPlugin/lib/helper/JavascriptHelper.php
r11510 r11783 1 1 <?php 2 2 3 use_helper('JavascriptBase');3 require_once dirname(__FILE__).'/JavascriptBaseHelper.php'; 4 4 5 5 /* branches/1.2/lib/view/sfPHPView.class.php
r9945 r11783 50 50 } 51 51 52 sfLoader::loadHelpers($helpers);52 $this->context->getConfiguration()->loadHelpers($helpers); 53 53 } 54 54 branches/1.2/lib/view/sfViewCacheManager.class.php
r11502 r11783 860 860 } 861 861 862 sfLoader::loadHelpers(array('Helper', 'Url', 'Asset', 'Tag'));862 $this->context->getConfiguration()->loadHelpers(array('Helper', 'Url', 'Asset', 'Tag')); 863 863 864 864 $bgColor = $event['new'] ? '#9ff' : '#ff9'; branches/1.2/test/unit/filter/sfCommonFilterTest.php
r11277 r11783 81 81 } 82 82 83 class ProjectConfiguration extends sfProjectConfiguration 84 { 85 } 86 87 class TestConfiguration extends sfApplicationConfiguration 88 { 89 public function getI18NGlobalDirs() 90 { 91 return array(dirname(__FILE__).'/fixtures'); 92 } 93 } 94 83 95 $context = sfContext::getInstance(array( 84 96 'request' => 'myRequest', 85 97 'response' => 'sfWebResponse', 86 98 )); 99 100 $context->configuration = new TestConfiguration('test', true, dirname(__FILE__).'/../../lib'); 87 101 88 102 $response = $context->response; branches/1.2/test/unit/helper/FormHelperTest.php
r11566 r11783 42 42 } 43 43 } 44 45 class ProjectConfiguration extends sfProjectConfiguration 46 { 47 } 48 49 $configuration = new ProjectConfiguration(dirname(__FILE__).'/../../lib', new sfEventDispatcher()); 44 50 45 51 $t = new lime_test(95, new lime_output_color()); branches/1.2/test/unit/sfContextMock.class.php
r8227 r11783 15 15 16 16 public 17 $request = null, 18 $response = null, 19 $controller = null, 20 $routing = null, 21 $user = null, 22 $storage = null; 17 $configuration = null, 18 $request = null, 19 $response = null, 20 $controller = null, 21 $routing = null, 22 $user = null, 23 $storage = null; 23 24 24 25 protected … … 68 69 { 69 70 return 'action'; 71 } 72 73 public function getConfiguration() 74 { 75 return $this->configuration; 70 76 } 71 77