Development

Changeset 20049

You must first sign up to be able to contribute.

Changeset 20049

Show
Ignore:
Timestamp:
07/09/09 12:03:04 (4 years ago)
Author:
nicolas
Message:

[1.1, 1.2, 1.3] fixed tasks autoloading order, added tests for proof

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/command/sfSymfonyCommandApplication.class.php

    r19980 r20049  
    1919class sfSymfonyCommandApplication extends sfCommandApplication 
    2020{ 
     21  protected $taskDirs = array(); 
     22   
    2123  /** 
    2224   * Configures the current symfony command application. 
     
    8991  { 
    9092    // Symfony core tasks 
    91     $dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
     93    $this->taskDirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
    9294 
    9395    // Plugin tasks 
     
    9698      if (is_dir($taskPath = $path.'/lib/task')) 
    9799      { 
    98         $dirs[] = $taskPath; 
     100        $this->taskDirs[] = $taskPath; 
    99101      } 
    100102    } 
    101103 
    102104    // project tasks 
    103     $dirs[] = sfConfig::get('sf_lib_dir').'/task'; 
     105    $this->taskDirs[] = sfConfig::get('sf_lib_dir').'/task'; 
    104106 
    105107    // require tasks 
    106     $finder = sfFinder::type('file')->sort_by_name()->name('*Task.class.php'); 
    107     foreach ($finder->in($dirs) as $task) 
     108    $finder = sfFinder::type('file')->name('*Task.class.php'); 
     109 
     110    // register local autoloader for tasks 
     111    spl_autoload_register(array($this, 'autoloadTask')); 
     112 
     113    foreach ($finder->in($this->taskDirs) as $task) 
    108114    { 
    109       // force autoloading the class 
    110       if (!class_exists(basename($task, '.class.php'))) 
     115      // forces autoloading of each task class 
     116      class_exists(basename($task, '.class.php'), true); 
     117    } 
     118 
     119    // unregister local autoloader 
     120    spl_autoload_unregister(array($this, 'autoloadTask')); 
     121  } 
     122 
     123  /** 
     124   * Autoloads a task class 
     125   * 
     126   * @param  string  $class  The task class name 
     127   * 
     128   * @return Boolean 
     129   */ 
     130  public function autoloadTask($class) 
     131  { 
     132    foreach ($this->taskDirs as $dir) 
     133    { 
     134      if (file_exists($file = $dir.'/'.$class.'.class.php')) 
    111135      { 
    112         require_once $task; 
     136        require_once $file; 
     137 
     138        return true; 
    113139      } 
    114140    } 
     141 
     142    return false; 
    115143  } 
    116144 
  • branches/1.1/test/other/tasksTest.php

    r18746 r20049  
    6565} 
    6666 
    67 $t = new lime_test(34, new lime_output_color()); 
     67$t = new lime_test(37, new lime_output_color()); 
    6868 
    6969if (!extension_loaded('SQLite')) 
     
    142142$content = $c->execute_command('cache:clear'); 
    143143 
     144// Test task autoloading 
     145mkdir($c->tmp_dir.DS.'lib'.DS.'task'); 
     146copy(dirname(__FILE__).'/fixtures/task/aTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'aTask.class.php'); 
     147copy(dirname(__FILE__).'/fixtures/task/zTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'zTask.class.php'); 
     148mkdir($pluginDir = $c->tmp_dir.DS.'plugins'.DS.'myFooPlugin'.DS.'lib'.DS.'task', 0777, true); 
     149copy(dirname(__FILE__).'/fixtures/task/myPluginTask.class.php', $pluginDir.DS.'myPluginTask.class.php'); 
     150 
     151$c->execute_command('a:run'); 
     152$c->execute_command('z:run'); 
     153$c->execute_command('p:run'); 
     154 
    144155$c->shutdown(); 
  • branches/1.2/lib/command/sfSymfonyCommandApplication.class.php

    r19980 r20049  
    1919class sfSymfonyCommandApplication extends sfCommandApplication 
    2020{ 
     21  protected $taskDirs = array(); 
     22   
    2123  /** 
    2224   * Configures the current symfony command application. 
     
    8991  { 
    9092    // Symfony core tasks 
    91     $dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
     93    $this->taskDirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
    9294 
    9395    // Plugin tasks 
     
    9698      if (is_dir($taskPath = $path.'/lib/task')) 
    9799      { 
    98         $dirs[] = $taskPath; 
     100        $this->taskDirs[] = $taskPath; 
    99101      } 
    100102    } 
    101103 
    102104    // project tasks 
    103     $dirs[] = sfConfig::get('sf_lib_dir').'/task'; 
     105    $this->taskDirs[] = sfConfig::get('sf_lib_dir').'/task'; 
    104106 
    105107    // require tasks 
    106     $finder = sfFinder::type('file')->sort_by_name()->name('*Task.class.php'); 
    107     foreach ($finder->in($dirs) as $task) 
     108    $finder = sfFinder::type('file')->name('*Task.class.php'); 
     109 
     110    // register local autoloader for tasks 
     111    spl_autoload_register(array($this, 'autoloadTask')); 
     112 
     113    foreach ($finder->in($this->taskDirs) as $task) 
    108114    { 
    109       // force autoloading the class 
    110       if (!class_exists(basename($task, '.class.php'))) 
     115      // forces autoloading of each task class 
     116      class_exists(basename($task, '.class.php'), true); 
     117    } 
     118 
     119    // unregister local autoloader 
     120    spl_autoload_unregister(array($this, 'autoloadTask')); 
     121  } 
     122 
     123  /** 
     124   * Autoloads a task class 
     125   * 
     126   * @param  string  $class  The task class name 
     127   * 
     128   * @return Boolean 
     129   */ 
     130  public function autoloadTask($class) 
     131  { 
     132    foreach ($this->taskDirs as $dir) 
     133    { 
     134      if (file_exists($file = $dir.'/'.$class.'.class.php')) 
    111135      { 
    112         require_once $task; 
     136        require_once $file; 
     137 
     138        return true; 
    113139      } 
    114140    } 
     141 
     142    return false; 
    115143  } 
    116144 
  • branches/1.2/test/other/tasksTest.php

    r18746 r20049  
    6666} 
    6767 
    68 $t = new lime_test(37, new lime_output_color()); 
     68$t = new lime_test(40, new lime_output_color()); 
    6969 
    7070if (!extension_loaded('SQLite')) 
     
    148148$content = $c->execute_command('cache:clear'); 
    149149 
     150// Test task autoloading 
     151mkdir($c->tmp_dir.DS.'lib'.DS.'task'); 
     152copy(dirname(__FILE__).'/fixtures/task/aTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'aTask.class.php'); 
     153copy(dirname(__FILE__).'/fixtures/task/zTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'zTask.class.php'); 
     154mkdir($pluginDir = $c->tmp_dir.DS.'plugins'.DS.'myFooPlugin'.DS.'lib'.DS.'task', 0777, true); 
     155copy(dirname(__FILE__).'/fixtures/task/myPluginTask.class.php', $pluginDir.DS.'myPluginTask.class.php'); 
     156 
     157$c->execute_command('a:run'); 
     158$c->execute_command('z:run'); 
     159$c->execute_command('p:run'); 
     160 
    150161$c->shutdown(); 
  • branches/1.3/lib/command/sfSymfonyCommandApplication.class.php

    r19980 r20049  
    1919class sfSymfonyCommandApplication extends sfCommandApplication 
    2020{ 
     21  protected $taskDirs = array(); 
     22   
    2123  /** 
    2224   * Configures the current symfony command application. 
     
    8991  { 
    9092    // Symfony core tasks 
    91     $dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
     93    $this->taskDirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); 
    9294 
    9395    // Plugin tasks 
     
    9698      if (is_dir($taskPath = $path.'/lib/task')) 
    9799      { 
    98         $dirs[] = $taskPath; 
     100        $this->taskDirs[] = $taskPath; 
    99101      } 
    100102    } 
    101103 
    102104    // project tasks 
    103     $dirs[] = sfConfig::get('sf_lib_dir').'/task'; 
     105    $this->taskDirs[] = sfConfig::get('sf_lib_dir').'/task'; 
    104106 
    105107    // require tasks 
    106     $finder = sfFinder::type('file')->sort_by_name()->name('*Task.class.php'); 
    107     foreach ($finder->in($dirs) as $task) 
     108    $finder = sfFinder::type('file')->name('*Task.class.php'); 
     109 
     110    // register local autoloader for tasks 
     111    spl_autoload_register(array($this, 'autoloadTask')); 
     112 
     113    foreach ($finder->in($this->taskDirs) as $task) 
    108114    { 
    109       // force autoloading the class 
    110       if (!class_exists(basename($task, '.class.php'))) 
     115      // forces autoloading of each task class 
     116      class_exists(basename($task, '.class.php'), true); 
     117    } 
     118 
     119    // unregister local autoloader 
     120    spl_autoload_unregister(array($this, 'autoloadTask')); 
     121  } 
     122 
     123  /** 
     124   * Autoloads a task class 
     125   * 
     126   * @param  string  $class  The task class name 
     127   * 
     128   * @return Boolean 
     129   */ 
     130  public function autoloadTask($class) 
     131  { 
     132    foreach ($this->taskDirs as $dir) 
     133    { 
     134      if (file_exists($file = $dir.'/'.$class.'.class.php')) 
    111135      { 
    112         require_once $task; 
     136        require_once $file; 
     137 
     138        return true; 
    113139      } 
    114140    } 
     141 
     142    return false; 
    115143  } 
    116144 
  • branches/1.3/test/other/tasksTest.php

    r19531 r20049  
    6666} 
    6767 
    68 $t = new lime_test(35); 
     68$t = new lime_test(38); 
    6969 
    7070if (!extension_loaded('SQLite')) 
     
    144144$content = $c->execute_command('cache:clear'); 
    145145 
     146// Test task autoloading 
     147mkdir($c->tmp_dir.DS.'lib'.DS.'task'); 
     148copy(dirname(__FILE__).'/fixtures/task/aTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'aTask.class.php'); 
     149copy(dirname(__FILE__).'/fixtures/task/zTask.class.php', $c->tmp_dir.DS.'lib'.DS.'task'.DS.'zTask.class.php'); 
     150mkdir($pluginDir = $c->tmp_dir.DS.'plugins'.DS.'myFooPlugin'.DS.'lib'.DS.'task', 0777, true); 
     151copy(dirname(__FILE__).'/fixtures/task/myPluginTask.class.php', $pluginDir.DS.'myPluginTask.class.php'); 
     152file_put_contents( 
     153  $projectConfigurationFile = $c->tmp_dir.DS.'config'.DS.'ProjectConfiguration.class.php',  
     154  str_replace( 
     155    '$this->enablePlugins(\'sfPropelPlugin\')',  
     156    '$this->enablePlugins(array(\'myFooPlugin\', \'sfPropelPlugin\'))',  
     157    file_get_contents($projectConfigurationFile) 
     158  ) 
     159); 
     160 
     161$c->execute_command('a:run'); 
     162$c->execute_command('z:run'); 
     163$c->execute_command('p:run'); 
     164 
    146165$c->shutdown();