/lib/vendor/symfony/lib/task/project/sfProjectFreezeTask.class.php

https://github.com/proyectoalba/alba · PHP · 112 lines · 68 code · 20 blank · 24 comment · 6 complexity · 84b0009b90fb6bc65d8ef0be08f3fef0 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Freezes symfony libraries.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfProjectFreezeTask.class.php 14421 2009-01-02 03:48:52Z Carl.Vondrick $
  16. */
  17. class sfProjectFreezeTask extends sfBaseTask
  18. {
  19. /**
  20. * @see sfTask
  21. */
  22. protected function configure()
  23. {
  24. $this->addArguments(array(
  25. new sfCommandArgument('symfony_data_dir', sfCommandArgument::REQUIRED, 'The symfony data directory'),
  26. ));
  27. $this->aliases = array('freeze');
  28. $this->namespace = 'project';
  29. $this->name = 'freeze';
  30. $this->briefDescription = 'Freezes symfony libraries';
  31. $this->detailedDescription = <<<EOF
  32. The [project:freeze|INFO] task copies all the symfony core files to
  33. the current project:
  34. [./symfony project:freeze /path/to/symfony/data/directory|INFO]
  35. The task takes a mandatory argument of the path to the symfony data
  36. directory.
  37. The task also changes [config/config.php|COMMENT] to switch to the
  38. embedded symfony files.
  39. EOF;
  40. }
  41. /**
  42. * @see sfTask
  43. */
  44. protected function execute($arguments = array(), $options = array())
  45. {
  46. // check that the symfony librairies are not already freeze for this project
  47. if (is_readable(sfConfig::get('sf_lib_dir').'/symfony'))
  48. {
  49. throw new sfCommandException('You can only freeze when lib/symfony is empty.');
  50. }
  51. if (is_readable(sfConfig::get('sf_data_dir').'/symfony'))
  52. {
  53. throw new sfCommandException('You can only freeze when data/symfony is empty.');
  54. }
  55. if (is_readable(sfConfig::get('sf_web_dir').'/sf'))
  56. {
  57. throw new sfCommandException('You can only freeze when web/sf is empty.');
  58. }
  59. if (is_link(sfConfig::get('sf_web_dir').'/sf'))
  60. {
  61. $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf');
  62. }
  63. $symfonyLibDir = sfConfig::get('sf_symfony_lib_dir');
  64. $symfonyDataDir = $arguments['symfony_data_dir'];
  65. if (!is_readable($symfonyDataDir))
  66. {
  67. throw new sfCommandException(sprintf('The symfony data dir does not seem to be located at "%s".', $symfonyDataDir));
  68. }
  69. $this->logSection('freeze', sprintf('freezing lib found in "%s"', $symfonyLibDir));
  70. $this->logSection('freeze', sprintf('freezing data found in "%s"', $symfonyDataDir));
  71. $this->getFilesystem()->mkdirs('lib'.DIRECTORY_SEPARATOR.'symfony');
  72. $this->getFilesystem()->mkdirs('data'.DIRECTORY_SEPARATOR.'symfony');
  73. $finder = sfFinder::type('any')->exec(array($this, 'excludeTests'));
  74. $this->getFilesystem()->mirror($symfonyLibDir, sfConfig::get('sf_lib_dir').'/symfony', $finder);
  75. $this->getFilesystem()->mirror($symfonyDataDir, sfConfig::get('sf_data_dir').'/symfony', $finder);
  76. $this->getFilesystem()->rename(sfConfig::get('sf_data_dir').'/symfony/web/sf', sfConfig::get('sf_web_dir').'/sf');
  77. $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter);
  78. $publishAssets->setCommandApplication($this->commandApplication);
  79. // change symfony path in ProjectConfiguration.class.php
  80. $config = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php';
  81. $content = file_get_contents($config);
  82. $content = str_replace('<?php', "<?php\n\n# FROZEN_SF_LIB_DIR: $symfonyLibDir", $content);
  83. $content = preg_replace('#(\'|")'.preg_quote($symfonyLibDir, '#').'#', "dirname(__FILE__).$1/../lib/symfony", $content);
  84. file_put_contents($config, $content);
  85. // re-publish assets
  86. $publishAssets->run(array(), array('--symfony-lib-dir='.sfConfig::get('sf_lib_dir').'/symfony'));
  87. }
  88. public function excludeTests($dir, $entry)
  89. {
  90. return false === strpos($dir.'/'.$entry, 'Plugin/test/');
  91. }
  92. }