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

Debug toolbar