|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------------+ |
|
4
|
|
|
// | This file is part of the Agavi package. | |
|
5
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
|
6
|
|
|
// | | |
|
7
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
|
8
|
|
|
// | file that was distributed with this source code. You can also view the | |
|
9
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
|
10
|
|
|
// | vi: set noexpandtab: | |
|
11
|
|
|
// | Local Variables: | |
|
12
|
|
|
// | indent-tabs-mode: t | |
|
13
|
|
|
// | End: | |
|
14
|
|
|
// +---------------------------------------------------------------------------+ |
|
15
|
|
|
|
|
16
|
|
|
require_once(__DIR__ . '/AgaviTask.php'); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Displays all controllers in an Agavi module. |
|
20
|
|
|
* |
|
21
|
|
|
* @package agavi |
|
22
|
|
|
* @subpackage build |
|
23
|
|
|
* |
|
24
|
|
|
* @author Noah Fontes <[email protected]> |
|
25
|
|
|
* @copyright Authors |
|
26
|
|
|
* @copyright The Agavi Project |
|
27
|
|
|
* |
|
28
|
|
|
* @since 1.0.0 |
|
29
|
|
|
* |
|
30
|
|
|
* @version $Id$ |
|
31
|
|
|
*/ |
|
32
|
|
|
class AgaviDisplayControllersTask extends AgaviTask |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
protected $path = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Sets the path to the project directory from which this task will read. |
|
38
|
|
|
* |
|
39
|
|
|
* @param PhingFile Path to the project directory. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function setPath(PhingFile $path) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->path = $path; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Executes this task. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function main() |
|
50
|
|
|
{ |
|
51
|
|
|
if($this->path === null) { |
|
52
|
|
|
throw new \Agavi\Build\Exception\BuildException('The path attribute must be specified'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$check = new \Agavi\Build\Check\ModuleFilesystemCheck(); |
|
56
|
|
|
$check->setConfigDirectory($this->project->getProperty('module.config.directory')); |
|
57
|
|
|
|
|
58
|
|
|
$check->setPath($this->path->getAbsolutePath()); |
|
59
|
|
|
if(!$check->check()) { |
|
60
|
|
|
throw new \Agavi\Build\Exception\BuildException('The path attribute must be a valid module base directory'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/* We don't know whether the module is configured or not here, so load the |
|
64
|
|
|
* values we want properly. */ |
|
65
|
|
|
$this->tryLoadAgavi(); |
|
66
|
|
|
$this->tryBootstrapAgavi(); |
|
67
|
|
|
|
|
68
|
|
|
require_once(\Agavi\Config\ConfigCache::checkConfig( |
|
69
|
|
|
sprintf('%s/%s/module.xml', |
|
70
|
|
|
$this->path->getAbsolutePath(), |
|
71
|
|
|
(string)$this->project->getProperty('module.config.directory') |
|
72
|
|
|
) |
|
73
|
|
|
)); |
|
74
|
|
|
|
|
75
|
|
|
$controllerPath = \Agavi\Util\Toolkit::expandVariables( |
|
76
|
|
|
\Agavi\Util\Toolkit::expandDirectives(\Agavi\Config\Config::get( |
|
77
|
|
|
sprintf('modules.%s.agavi.controller.path', strtolower($this->path->getName())), |
|
78
|
|
|
'%core.module_dir%/${moduleName}/controllers/${controllerName}Controller.class.php' |
|
79
|
|
|
)), |
|
80
|
|
|
array( |
|
81
|
|
|
'moduleName' => $this->path->getName() |
|
82
|
|
|
) |
|
83
|
|
|
); |
|
84
|
|
|
$pattern = '#^' . \Agavi\Util\Toolkit::expandVariables( |
|
85
|
|
|
/* Blaaaaaaaaauuuuuughhhhhhh... */ |
|
86
|
|
|
str_replace('\\$\\{controllerName\\}', '${controllerName}', preg_quote($controllerPath, '#')), |
|
87
|
|
|
array('controllerName' => '(?P<controller_name>.*?)') |
|
88
|
|
|
) . '$#'; |
|
89
|
|
|
|
|
90
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath())); |
|
91
|
|
View Code Duplication |
for(; $iterator->valid(); $iterator->next()) { |
|
|
|
|
|
|
92
|
|
|
$rdi = $iterator->getInnerIterator(); |
|
93
|
|
|
if($rdi->isDot() || !$rdi->isFile()) { |
|
94
|
|
|
continue; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$file = $rdi->getPathname(); |
|
98
|
|
|
if(preg_match($pattern, $file, $matches)) { |
|
99
|
|
|
$this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['controller_name'])); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
?> |
|
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.