PHP code example of akito-tsukahara / laravel-di-scope
1. Go to this page and download the library: Download akito-tsukahara/laravel-di-scope library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
akito-tsukahara / laravel-di-scope example snippets
'scan' => [
// スキャン対象ディレクトリ(base_path()からの相対パス)
'paths' => [
'app/',
// 'packages/my-package/src/',
],
// 除外ディレクトリ
'exclude_paths' => [
// 'app/Providers/',
],
// 除外パターン(名前空間ベース、ワイルドカード対応)
'exclude_patterns' => [
'App\\Providers\\*',
],
],
'ignore' => [
'Illuminate\\*',
'Psr\\*',
'Symfony\\*',
],
'rules' => [
// Domain層はInfrastructure層に依存してはいけない
'App\\Domain\\*' => [
'deny' => ['App\\Infrastructure\\*'],
'allow' => ['App\\Domain\\*', 'App\\Application\\*'],
],
// ControllerはServiceに直接依存してはいけない例
'App\\Http\\Controllers\\*' => [
'deny' => ['App\\Services\\*'],
'allow' => ['App\\Http\\Requests\\*'],
],
],
'rules' => [
// Entities(Domain層)は何にも依存しない
'App\\Domain\\Entities\\*' => [
'deny' => ['App\\*'],
'allow' => ['App\\Domain\\Entities\\*'],
],
// UseCases(Application層)はDomain層のみ依存可
'App\\Domain\\UseCases\\*' => [
'deny' => ['App\\Infrastructure\\*', 'App\\Http\\*'],
'allow' => ['App\\Domain\\*'],
],
// Controllers(Interface層)はUseCasesに依存
'App\\Http\\Controllers\\*' => [
'deny' => ['App\\Infrastructure\\*', 'App\\Domain\\Entities\\*'],
'allow' => ['App\\Domain\\UseCases\\*', 'App\\Http\\*'],
],
],
'rules' => [
'App\\Domain\\*' => [
'deny' => ['App\\Infrastructure\\*'],
],
'App\\Application\\*' => [
'deny' => ['App\\Infrastructure\\*'],
],
],
bash
php artisan vendor:publish --tag=di-scope-config
bash
php artisan di:list
# singletonのみ表示
php artisan di:list --type=singleton
# 検索
php artisan di:list --search=Repository
bash
# app/配下をスキャンしてグラフ出力(デフォルト)
php artisan di:graph
# ファイルに保存
php artisan di:graph --output=graph.mmd
# 特定の名前空間にフォーカス
php artisan di:graph --focus="App\\Http\\Controllers"
# 依存の深さを制限
php artisan di:graph --depth=2
# 特定クラスのみ解析
php artisan di:graph --class="App\\Http\\Controllers\\Tweet\\CreateController"
# サービスコンテナのバインディングのみ解析(従来の動作)
php artisan di:graph --bindings