1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
Yii::import('cii.commands.CiiConsoleCommand');
|
4
|
|
|
class CiiClassMapCommand extends CiiConsoleCommand
|
|
|
|
|
5
|
|
|
{
|
6
|
|
|
public function actionIndex()
|
7
|
|
|
{
|
8
|
|
|
$data = "<?php\n";
|
9
|
|
|
$data .= '$basePath = dirname(__FILE__) . \'/..\';' . "\n";
|
10
|
|
|
$data .= 'Yii::$classMap = ' . "array(\n";
|
11
|
|
|
|
12
|
|
|
$this->updateDataPath(Yii::getPathOfAlias('ext'), $data);
|
13
|
|
|
$this->updateDataPath( Yii::getPathOfAlias('application.models'), $data);
|
14
|
|
|
$this->updateDataPath(Yii::getPathOfAlias('application.controllers'), $data);
|
15
|
|
|
|
16
|
|
|
$data .= ");\n";
|
17
|
|
|
|
18
|
|
|
$handle = fopen(Yii::getPathOfAlias('application.config') . DIRECTORY_SEPARATOR . 'classmap.php', 'w+');
|
19
|
|
|
fwrite($handle, $data);
|
20
|
|
|
fclose($handle);
|
21
|
|
|
return;
|
22
|
|
|
}
|
23
|
|
|
|
24
|
|
|
private function updateDataPath($path, &$data)
|
25
|
|
|
{
|
26
|
|
|
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
|
27
|
|
|
foreach($objects as $name => $object)
|
28
|
|
|
{
|
29
|
|
|
if (strpos($name, '.php') !== false && strpos($name, 'gii') === false)
|
30
|
|
|
{
|
31
|
|
|
$id = str_replace('.php', '', substr( $name, strrpos( $name, '/' )+1 ));
|
32
|
|
|
if ($this->startsWithUpper($id))
|
33
|
|
|
$data .= " '" . $id . "' => " . '$basePath . \'' . str_replace('/var/www/ciims/protected', '', $name) . "',\n";
|
34
|
|
|
}
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
return $data;
|
38
|
|
|
}
|
39
|
|
|
|
40
|
|
|
/**
|
41
|
|
|
* @param string $str
|
42
|
|
|
*/
|
43
|
|
|
private function startsWithUpper($str)
|
44
|
|
|
{
|
45
|
|
|
$chr = mb_substr ($str, 0, 1, "UTF-8");
|
|
|
|
|
46
|
|
|
return mb_strtolower($chr, "UTF-8") != $chr;
|
|
|
|
|
47
|
|
|
}
|
48
|
|
|
}
|
49
|
|
|
|
50
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.