| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfProjectFreezeTask extends sfBaseTask |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* @see sfTask |
|---|
| 23 |
*/ |
|---|
| 24 |
protected function configure() |
|---|
| 25 |
{ |
|---|
| 26 |
$this->addArguments(array( |
|---|
| 27 |
new sfCommandArgument('symfony_data_dir', sfCommandArgument::REQUIRED, 'The symfony data directory'), |
|---|
| 28 |
)); |
|---|
| 29 |
|
|---|
| 30 |
$this->aliases = array('freeze'); |
|---|
| 31 |
$this->namespace = 'project'; |
|---|
| 32 |
$this->name = 'freeze'; |
|---|
| 33 |
$this->briefDescription = 'Freezes symfony libraries'; |
|---|
| 34 |
|
|---|
| 35 |
$this->detailedDescription = <<<EOF |
|---|
| 36 |
The [project:freeze|INFO] task copies all the symfony core files to |
|---|
| 37 |
the current project: |
|---|
| 38 |
|
|---|
| 39 |
[./symfony project:freeze|INFO] |
|---|
| 40 |
|
|---|
| 41 |
The task also changes [config/config.php|COMMENT] to switch to the |
|---|
| 42 |
embedded symfony files. |
|---|
| 43 |
EOF; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* @see sfTask |
|---|
| 48 |
*/ |
|---|
| 49 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 50 |
{ |
|---|
| 51 |
|
|---|
| 52 |
if (is_readable(sfConfig::get('sf_lib_dir').'/symfony')) |
|---|
| 53 |
{ |
|---|
| 54 |
throw new sfCommandException('You can only freeze when lib/symfony is empty.'); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
if (is_readable(sfConfig::get('sf_data_dir').'/symfony')) |
|---|
| 58 |
{ |
|---|
| 59 |
throw new sfCommandException('You can only freeze when data/symfony is empty.'); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
if (is_readable(sfConfig::get('sf_web_dir').'/sf')) |
|---|
| 63 |
{ |
|---|
| 64 |
throw new sfCommandException('You can only freeze when web/sf is empty.'); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
if (is_link(sfConfig::get('sf_web_dir').'/sf')) |
|---|
| 68 |
{ |
|---|
| 69 |
$this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf'); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
$symfonyLibDir = sfConfig::get('sf_symfony_lib_dir'); |
|---|
| 73 |
$symfonyDataDir = $arguments['symfony_data_dir']; |
|---|
| 74 |
|
|---|
| 75 |
if (!is_readable($symfonyDataDir)) |
|---|
| 76 |
{ |
|---|
| 77 |
throw new sfCommandException(sprintf('The symfony data dir does not seem to be located at "%s".', $symfonyDataDir)); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
$this->logSection('freeze', sprintf('freezing lib found in "%s"', $symfonyLibDir)); |
|---|
| 81 |
$this->logSection('freeze', sprintf('freezing data found in "%s"', $symfonyDataDir)); |
|---|
| 82 |
|
|---|
| 83 |
$this->getFilesystem()->mkdirs('lib'.DIRECTORY_SEPARATOR.'symfony'); |
|---|
| 84 |
$this->getFilesystem()->mkdirs('data'.DIRECTORY_SEPARATOR.'symfony'); |
|---|
| 85 |
|
|---|
| 86 |
$finder = sfFinder::type('any')->exec(array($this, 'excludeTests')); |
|---|
| 87 |
$this->getFilesystem()->mirror($symfonyLibDir, sfConfig::get('sf_lib_dir').'/symfony', $finder); |
|---|
| 88 |
$this->getFilesystem()->mirror($symfonyDataDir, sfConfig::get('sf_data_dir').'/symfony', $finder); |
|---|
| 89 |
$this->getFilesystem()->rename(sfConfig::get('sf_data_dir').'/symfony/web/sf', sfConfig::get('sf_web_dir').'/sf'); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
$config = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php'; |
|---|
| 93 |
$content = file_get_contents($config); |
|---|
| 94 |
$content = str_replace('<?php', "<?php\n\n# FROZEN_SF_LIB_DIR: $symfonyLibDir", $content); |
|---|
| 95 |
$content = preg_replace('#(\'|")'.preg_quote($symfonyLibDir, '#').'#', "dirname(__FILE__).$1/../lib/symfony", $content); |
|---|
| 96 |
file_put_contents($config, $content); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
public function excludeTests($dir, $entry) |
|---|
| 100 |
{ |
|---|
| 101 |
return false === strpos($dir.'/'.$entry, 'Plugin/test/'); |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|