Skip to content

Commit

Permalink
Added autoload command.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Jul 11, 2013
1 parent e11ce60 commit 3c09ead
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 237 deletions.
9 changes: 5 additions & 4 deletions build/build
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));

require(__DIR__ . '/../framework/yii/Yii.php');

$id = 'yii-build';
$basePath = __DIR__;

$application = new yii\console\Application(array('id' => $id, 'basePath' => $basePath));
$application = new yii\console\Application(array(
'id' => 'yii-build',
'basePath' => __DIR__,
'controllerNamespace' => 'yii\build\controllers',
));
$application->run();
89 changes: 89 additions & 0 deletions build/controllers/AutoloadController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\build\controllers;

use yii\console\Controller;
use yii\helpers\FileHelper;

/**
* @author Qiang Xue <[email protected]>
* @since 2.0
*/
class AutoloadController extends Controller
{
public $defaultAction = 'create';

/**
* Creates a class map for the core Yii classes.
* @param string $root the root path of Yii framework. Defaults to YII_PATH.
* @param string $mapFile the file to contain the class map. Defaults to YII_PATH . '/classes.php'.
*/
public function actionCreate($root = null, $mapFile = null)
{
if ($root === null) {
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = array(
'filter' => function($path) {
if (is_file($path)) {
$file = basename($path);
if ($file[0] < 'A' || $file[0] > 'Z') {
return false;
}
}
return null;
},
'only' => array('.php'),
'except' => array(
'Yii.php',
'YiiBase.php',
'/debug/',
'/console/',
'/test/',
),
);
$files = FileHelper::findFiles($root, $options);
$map = array();
foreach ($files as $file) {
if (($pos = strpos($file, $root)) !== 0) {
die("Something wrong: $file");
}
$path = str_replace('\\', '/', substr($file, strlen($root)));
$map[] = "\t'yii" . substr(str_replace('/', '\\', $path), 0, -4) . "' => YII_PATH . '$path',";
}
$map = implode("\n", $map);
$output = <<<EOD
<?php
/**
* Yii core class map.
*
* This file is automatically generated by the "build autoload" command under the "build" folder.
* Do not modify it directly.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
return array(
$map
);
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {
echo "Nothing changed.";
} else {
file_put_contents($mapFile, $output);
echo "Class map saved in $mapFile";
}
}
}
2 changes: 1 addition & 1 deletion build/controllers/LocaleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/

namespace app\controllers;
namespace yii\build\controllers;

use yii\console\Exception;
use yii\console\Controller;
Expand Down
Loading

0 comments on commit 3c09ead

Please sign in to comment.