* @since 2.0 */ class ClassmapController 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 YII2_PATH. * @param string $mapFile the file to contain the class map. Defaults to YII2_PATH . '/classes.php'. */ public function actionCreate($root = null, $mapFile = null) { if ($root === null) { $root = YII2_PATH; } $root = FileHelper::normalizePath($root); if ($mapFile === null) { $mapFile = YII2_PATH . '/classes.php'; } $options = [ 'filter' => function ($path) { if (is_file($path)) { $file = basename($path); if ($file[0] < 'A' || $file[0] > 'Z') { return false; } } return null; }, 'only' => ['*.php'], 'except' => [ '/Yii.php', '/BaseYii.php', '/console/', '/requirements/', ], ]; $files = FileHelper::findFiles($root, $options); $map = []; foreach ($files as $file) { if (strpos($file, $root) !== 0) { throw new Exception("Something wrong: $file\n"); } $path = str_replace('\\', '/', substr($file, \strlen($root))); $map[$path] = " 'yii" . substr(str_replace('/', '\\', $path), 0, -4) . "' => YII2_PATH . '$path',"; } ksort($map); $map = implode("\n", $map); $output = <<