sfProjectClearControllersTask.class.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * Clears all non production environment controllers.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfProjectClearControllersTask.class.php 10582 2008-08-01 14:45:42Z nicolas $
  16. */
  17. class sfProjectClearControllersTask extends sfBaseTask
  18. {
  19. /**
  20. * @see sfTask
  21. */
  22. protected function configure()
  23. {
  24. $this->aliases = array('clear-controllers');
  25. $this->namespace = 'project';
  26. $this->name = 'clear-controllers';
  27. $this->briefDescription = 'Clears all non production environment controllers';
  28. $this->detailedDescription = <<<EOF
  29. The [project:clear-controllers|INFO] task clears all non production environment
  30. controllers:
  31. [./symfony project:clear-controllers|INFO]
  32. You can use this task on a production server to remove all front
  33. controller scripts except the production ones.
  34. If you have two applications named [frontend|COMMENT] and [backend|COMMENT],
  35. you have four default controller scripts in [web/|COMMENT]:
  36. [index.php
  37. frontend_dev.php
  38. backend.php
  39. backend_dev.php|INFO]
  40. After executing the [project:clear-controllers|COMMENT] task, two front
  41. controller scripts are left in [web/|COMMENT]:
  42. [index.php
  43. backend.php|INFO]
  44. Those two controllers are safe because debug mode and the web debug
  45. toolbar are disabled.
  46. EOF;
  47. }
  48. /**
  49. * @see sfTask
  50. */
  51. protected function execute($arguments = array(), $options = array())
  52. {
  53. $finder = sfFinder::type('file')->maxdepth(1)->name('*.php');
  54. foreach ($finder->in(sfConfig::get('sf_web_dir')) as $controller)
  55. {
  56. $content = file_get_contents($controller);
  57. if (preg_match('/ProjectConfiguration::getApplicationConfiguration\(\'(.*?)\', \'(.*?)\'/', $content, $match))
  58. {
  59. // Remove file if it has found an application and the environment is not production
  60. if ($match[2] != 'prod')
  61. {
  62. $this->getFilesystem()->remove($controller);
  63. }
  64. }
  65. }
  66. }
  67. }