Laravelのconfigはデフォルトでフラットにずらっとファイルが並んでいます。いくつかパッケージを入れても多くは水平に広がっていくのみです。そのため同じようにファイルを置くのみにしてしまいがちですが、ディレクトリを置いても読み込めます。
例えば以下の様にあると
config
| app.php
| auth.php
| broadcasting.php
| cache.php
| database.php
| filesystems.php
| hashing.php
| ide-helper.php
| logging.php
| mail.php
| queue.php
| services.php
| session.php
| view.php
|
\----const
common.php
location.php
// location.php
return [
'pref' => [
'TOKYO' => 13,
]
];
constディレクトリ中のlocation.php中の東京都の番号を呼ぶには
config('const.location.pref.TOKYO')
と書けます。これをうまいこと使うと参照しにくい巨大ファイルを減らせます。
artisanはもっと単純です。artisanのローディングはCommandsディレクトリ以下のファイルを軒並み読んで、読んだファイルがCommandクラスの条件を満たしているかチェックしているのみです。
// Commands/Kernel.phpのロード呼び出し部
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
// フレームワーク内ロード処理メイン
$command = $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($command->getPathname(), realpath(app_path()).DIRECTORY_SEPARATOR)
);
if (is_subclass_of($command, Command::class) &&
! (new ReflectionClass($command))->isAbstract()) {
Artisan::starting(function ($artisan) use ($command) {
$artisan->resolve($command);
});
}
このためCommandsディレクトリ以下ならばどこに置いてあってもCommandクラス内で記述したsignatureないしnameの名前でartisanからコマンドを実行できます。例えば自分なら開発者用のコマンド(ファイル自動生成, 権限無視のexecのラッピングなど)をForDevelopと分けたりと整理しています。