forked from yiisoft/yii
/
AutoloadCommand.php
85 lines (79 loc) · 2 KB
/
AutoloadCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* AutoloadCommand class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id$
*/
/**
* AutoloadCommand generates the class map for {@link YiiBase}.
* The class file YiiBase.php will be modified with updated class map.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.build
* @since 1.0
*/
class AutoloadCommand extends CConsoleCommand
{
public function getHelp()
{
return <<<EOD
USAGE
build autoload
DESCRIPTION
This command updates YiiBase.php with the latest class map.
The class map is used by Yii::autoload() to quickly include a class on demand.
Do not run this command unless you change or add core framework classes.
EOD;
}
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function run($args)
{
$options=array(
'fileTypes'=>array('php'),
'exclude'=>array(
'.svn',
'/messages',
'/views',
'/cli',
'/yii.php',
'/yiit.php',
'/yiilite.php',
'/web/js',
'/vendors',
'/i18n/data',
'/utils/mimeTypes.php',
'/test',
'/zii',
'/gii',
),
);
$files=CFileHelper::findFiles(YII_PATH,$options);
$map='';
foreach($files as $file)
{
if(($pos=strpos($file,YII_PATH))!==0)
die("Invalid file '$file' found.");
$path=str_replace('\\','/',substr($file,strlen(YII_PATH)));
$className=substr(basename($path),0,-4);
if($className[0]==='C')
$map.="\t\t'$className' => '$path',\n";
}
$yiiBase=file_get_contents(YII_PATH.'/YiiBase.php');
$newYiiBase=preg_replace('/private\s+static\s+\$_coreClasses\s*=\s*array\s*\([^\)]*\)\s*;/',"private static \$_coreClasses=array(\n{$map}\t);",$yiiBase);
if($yiiBase!==$newYiiBase)
{
file_put_contents(YII_PATH.'/YiiBase.php',$newYiiBase);
echo "YiiBase.php is updated successfully.\n";
}
else
echo "Nothing changed.\n";
}
}