Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * Clears all non production environment controllers.
13
 *
14
 * @package    symfony
15
 * @subpackage task
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfProjectClearControllersTask.class.php 23922 2009-11-14 14:58:38Z fabien $
18
 */
19
class sfProjectClearControllersTask extends sfBaseTask
20
{
21
  /**
22
   * @see sfTask
23
   */
24
  protected function configure()
25
  {
26
    $this->namespace = 'project';
27
    $this->name = 'clear-controllers';
28
    $this->briefDescription = 'Clears all non production environment controllers';
29
 
30
    $this->detailedDescription = <<<EOF
31
The [project:clear-controllers|INFO] task clears all non production environment
32
controllers:
33
 
34
  [./symfony project:clear-controllers|INFO]
35
 
36
You can use this task on a production server to remove all front
37
controller scripts except the production ones.
38
 
39
If you have two applications named [frontend|COMMENT] and [backend|COMMENT],
40
you have four default controller scripts in [web/|COMMENT]:
41
 
42
  [index.php
43
  frontend_dev.php
44
  backend.php
45
  backend_dev.php|INFO]
46
 
47
After executing the [project:clear-controllers|COMMENT] task, two front
48
controller scripts are left in [web/|COMMENT]:
49
 
50
  [index.php
51
  backend.php|INFO]
52
 
53
Those two controllers are safe because debug mode and the web debug
54
toolbar are disabled.
55
EOF;
56
  }
57
 
58
  /**
59
   * @see sfTask
60
   */
61
  protected function execute($arguments = array(), $options = array())
62
  {
63
    $finder = sfFinder::type('file')->maxdepth(1)->name('*.php');
64
    foreach ($finder->in(sfConfig::get('sf_web_dir')) as $controller)
65
    {
66
      $content = file_get_contents($controller);
67
 
68
      if (preg_match('/ProjectConfiguration::getApplicationConfiguration\(\'(.*?)\', \'(.*?)\'/', $content, $match))
69
      {
70
        // Remove file if it has found an application and the environment is not production
71
        if ($match[2] != 'prod')
72
        {
73
          $this->getFilesystem()->remove($controller);
74
        }
75
      }
76
    }
77
  }
78
}