├── LICENSE ├── composer.json ├── readme-ja.md ├── readme.md └── sources ├── Addons └── Commands │ ├── AddonListCommand.php │ ├── AddonMakeCommand.php │ ├── AddonNameCommand.php │ ├── AddonRemoveCommand.php │ └── AddonStatusCommand.php ├── Commands ├── AppContainerCommand.php ├── HashCheckCommand.php ├── HashMakeCommand.php ├── RouteListCommand.php └── TailCommand.php ├── ConsoleKernel.php ├── Database ├── Commands │ ├── DatabaseAgainCommand.php │ ├── DatabaseCleanCommand.php │ ├── DatabaseRefreshCommand.php │ ├── DatabaseRollbackCommand.php │ ├── DatabaseSeedCommand.php │ ├── DatabaseStatusCommand.php │ ├── DatabaseUpgradeCommand.php │ ├── MigrationMakeCommand.php │ └── SeederMakeCommand.php └── stubs │ ├── migration-create.stub │ ├── migration-update.stub │ ├── migration.stub │ └── seeder.stub ├── Generators ├── Commands │ ├── CommandMakeCommand.php │ ├── ControllerMakeCommand.php │ ├── DummyCommand.php │ ├── EventMakeCommand.php │ ├── JobMakeCommand.php │ ├── ListenerMakeCommand.php │ ├── MailMakeCommand.php │ ├── MiddlewareMakeCommand.php │ ├── ModelMakeCommand.php │ ├── NotificationMakeCommand.php │ ├── PolicyMakeCommand.php │ ├── ProviderMakeCommand.php │ ├── RequestMakeCommand.php │ ├── ResourceMakeCommand.php │ ├── RuleMakeCommand.php │ └── TestMakeCommand.php ├── GeneratorCommandTrait.php └── stubs │ ├── command.stub │ ├── controller-model.stub │ ├── controller-plain.stub │ ├── controller-resource.stub │ ├── event.stub │ ├── job-queued.stub │ ├── job-sync.stub │ ├── listener-queued.stub │ ├── listener-sync.stub │ ├── mail-markdown.stub │ ├── mail-view.stub │ ├── middleware.stub │ ├── model.stub │ ├── notification-html.stub │ ├── notification-markdown.stub │ ├── policy-model.stub │ ├── policy-plain.stub │ ├── provider.stub │ ├── request.stub │ ├── resource-collection.stub │ ├── resource.stub │ ├── rule.stub │ ├── test-feature.stub │ └── test-unit.stub ├── Hooks └── ApplicationHook.php ├── HttpKernel.php ├── Providers ├── ArtisanServiceProvider.php └── ExtensionServiceProvider.php ├── ServiceProvider.php ├── Specs ├── Factory.php ├── FormModel.php ├── InputModel.php ├── InputSpec.php └── Translator.php ├── Templates └── BladeExtension.php └── helpers.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Fumio Furukawa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-plus/extension", 3 | "type": "framework-extension", 4 | "description": "Laravel Extension Pack", 5 | "license": "MIT", 6 | "keywords": ["Laravel", "Laravel 5", "addon", "migration", "architecture", "facade"], 7 | "homepage": "https://laravel.tokyo", 8 | "authors": [ 9 | { 10 | "name": "Fumio Furukawa", 11 | "email": "fumio@jumilla.me" 12 | } 13 | ], 14 | "require": { 15 | "php": "^7.0", 16 | "laravel/framework": "^5.5", 17 | "jumilla/laravel-versionia": "^2.0", 18 | "jumilla/laravel-addomnipot": "^2.0", 19 | "jumilla/laravel-source-generator": "^1.3" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "^6.0", 23 | "mockery/mockery": "~0.9" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "LaravelPlus\\Extension\\": "sources/" 28 | }, 29 | "files": [ 30 | "sources/helpers.php" 31 | ] 32 | }, 33 | "extra": { 34 | "laravel": { 35 | "providers": [ 36 | "LaravelPlus\\Extension\\ServiceProvider" 37 | ], 38 | "aliases": { 39 | } 40 | } 41 | }, 42 | "minimum-stability": "stable", 43 | "prefer-stable": true 44 | } 45 | -------------------------------------------------------------------------------- /readme-ja.md: -------------------------------------------------------------------------------- 1 | 2 | # Laravel Extension Pack 3 | 4 | [![Build Status](https://travis-ci.org/jumilla/laravel-extension.svg)](https://travis-ci.org/jumilla/laravel-extension) 5 | [![Quality Score](https://img.shields.io/scrutinizer/g/jumilla/laravel-extension.svg?style=flat)](https://scrutinizer-ci.com/g/jumilla/laravel-extension) 6 | [![Code Coverage](https://scrutinizer-ci.com/g/jumilla/laravel-extension/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/jumilla/laravel-extension/) 7 | [![Latest Stable Version](https://poser.pugx.org/laravel-plus/extension/v/stable.svg)](https://packagist.org/packages/laravel-plus/extension) 8 | [![Total Downloads](https://poser.pugx.org/laravel-plus/extension/d/total.svg)](https://packagist.org/packages/laravel-plus/extension) 9 | [![Software License](https://poser.pugx.org/laravel-plus/extension/license.svg)](https://packagist.org/packages/laravel-plus/extension) 10 | 11 | ## 機能 12 | 13 | * バージョンベースマイグレーション機能の追加 14 | * セマンティックバージョンベースのデータベースマイグレーションライブラリ [Laravel Versionia](http://github.com/jumilla/laravel-versionia) を採用しました。 15 | * マイグレーション/シードクラスは、Laravel 5のディレクトリ構造に組み込まれました。**app\Database\Migrations** と **app\Database\Seeds** ディレクトリを使ってください。 16 | * マイグレーションにグループを指定できるようになりました。 17 | * シードに名前が付けられるようになりました。 18 | * バージョンとの指定は、`App/Providers/DatabaseServiceProvider` クラスで行います。 19 | * Laravelのマイグレーション/シードクラスをそのまま利用できます。 20 | 21 | * アドオン機能の追加 22 | * アプリケーション内のパッケージ機能です。Laravel 5のディレクトリ構造を複製するイメージで使うことができます。 23 | * デフォルトで、**addons** ディレクトリの下に配置されます。 24 | * アドオンに独自の名前空間(PSR-4)を一つ持たせることができます。 25 | * Laravel 5のパッケージとして扱えます。lang, viewの識別子の名前空間表記`{addon-name}::`が使えます。configも使えます。 26 | * アドオンの追加はディレクトリをコピーするだけ。**config/app.php** などの設定ファイルにコードを追加する必要はありません。 27 | * 7種類のひな形と2種類のサンプルを用意しています。`php artisan make:addon` で生成できます。 28 | 29 | * ファイル生成コマンド 30 | * コンソールコマンドやジョブ、プロバイダーなどLaravel 5のクラスをコマンドラインから生成できる機能です。 31 | * ジェネレーターコマンドに、カスタマイズしたスタブファイルを使用させることもできます。 32 | * Laravel 5の`make:xxx`コマンドに準拠しています。コマンド名やオプションは同じです。 33 | * `--addon`オプションで、アドオン内にファイルを生成することもできます。 34 | 35 | * 名前空間内でのファサード問題の解決 36 | * appディレクトリ下の名前空間付きクラスの中でファサードが使えます。(バックスラッシュ指定やuse宣言不要) 37 | * アドオンの名前空間付きクラスの中からも、同じ記述方法でファサードが扱えます。 38 | 39 | ## インストール方法 40 | 41 | ### [A] 組み込み済みのLaravelプロジェクトをダウンロードする 42 | 43 | ```sh 44 | composer create-project laravel-plus/laravel5 45 | ``` 46 | 47 | ### [B] 既存のプロジェクトにインストールする 48 | 49 | #### 1. Composerで`laravel-plus/extension`パッケージを追加します。 50 | 51 | ```sh 52 | composer require laravel-plus/extension 53 | ``` 54 | 55 | #### 2. サービスプロバイダーを追加・削除します。 56 | 57 | **config/app.php** ファイルの`providers`セクションに、`LaravelPlus\Extension\ServiceProvider`クラスを追加します。 58 | そして、`Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class` の行をコメントアウトします。 59 | 60 | ```php 61 | 'providers' => [ 62 | Illuminate\View\ViewServiceProvider:class, 63 | ... 64 | ↓次の行を追加する 65 | LaravelPlus\Extension\ServiceProvider::class, 66 | ], 67 | ``` 68 | 69 | ```php 70 | 'providers' => [ 71 | ↓次の行をコメントアウトする 72 | // Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 73 | ], 74 | ``` 75 | 76 | ## 動作確認 77 | 78 | サンプルとして、アドオン`wiki`を作成します。 79 | 80 | ```sh 81 | php artisan make:addon wiki sample:ui 82 | ``` 83 | 84 | ルーティング設定を確認してください。 85 | 86 | ```sh 87 | php artisan route:list 88 | ``` 89 | 90 | ローカルサーバーを立ち上げ、ブラウザで`http://localhost:8000/addons/wiki`にアクセスします。 91 | パッケージ名が表示されれば成功です。 92 | 93 | ```sh 94 | php artisan serve 95 | ``` 96 | 97 | ## コマンド 98 | 99 | ### database:status 100 | 101 | マイグレーション、シードの定義とインストール状態を表示します。 102 | 103 | ```sh 104 | php artisan database:status 105 | ``` 106 | 107 | ### database:upgrade 108 | 109 | すべてのグループのマイグレーションの`up()`を実行し、最新バージョンにします。 110 | 111 | ```sh 112 | php artisan database:upgrade 113 | ``` 114 | 115 | マイグレーション後にシードを実行させることもできます。 116 | 117 | ```sh 118 | php artisan database:upgrade --seed <シード> 119 | ``` 120 | 121 | ### database:clean 122 | 123 | すべてのグループのマイグレーションの`down()`を実行し、クリーン状態に戻します。 124 | 125 | ```sh 126 | php artisan database:clean 127 | ``` 128 | 129 | ### database:refresh 130 | 131 | すべてのグループのマイグレーションをやり直します。 132 | 133 | `database:clean`と`database:upgrade`を実行した結果と同じです。 134 | 135 | ```sh 136 | php artisan database:refresh 137 | ``` 138 | 139 | マイグレーション後にシードを実行させることもできます。 140 | 141 | ```sh 142 | php artisan database:refresh --seed <シード> 143 | ``` 144 | 145 | ### database:rollback 146 | 147 | 指定グループのバージョンをひとつ戻します。 148 | 149 | ```sh 150 | php artisan database:rollback <グループ> 151 | ``` 152 | 153 | `--all`オプションを付けると、指定グループのすべてのバージョンを削除します。 154 | 155 | ```sh 156 | php artisan database:rollback <グループ> --all 157 | ``` 158 | 159 | ### database:again 160 | 161 | 指定グループの最新バージョンを再作成します。 162 | 163 | `database:rollback <グループ>`と`database:upgrade`を実行したときと同じ効果があります。 164 | 165 | ```sh 166 | php artisan database:again <グループ> 167 | ``` 168 | 169 | マイグレーション後にシードを実行させることもできます。 170 | 171 | ```sh 172 | php artisan database:again <グループ> --seed <シード> 173 | ``` 174 | 175 | ### database:seed 176 | 177 | 指定のシードを実行します。 178 | 179 | ```sh 180 | php artisan database:seed <シード> 181 | ``` 182 | 183 | `<シード>`を省略した場合、デフォルトのシードを実行します。 184 | 185 | ```sh 186 | php artisan database:seed 187 | ``` 188 | 189 | ### addon:status 190 | 191 | アドオンの状態を確認できます。 192 | 193 | ```sh 194 | php artisan addon:status 195 | ``` 196 | 197 | `addons`ディレクトリや`config/addon.php`ファイルが存在しない場合は作成します。 198 | 199 | ### addon:name 200 | 201 | アドオン内のファイルを走査し、PHP名前空間を変更します。 202 | 203 | ```sh 204 | php artisan addon:name blog Sugoi/Blog 205 | ``` 206 | 207 | 走査したファイルを確認したい場合は、`-v`オプションを指定してください。 208 | 209 | ```sh 210 | php artisan addon:name blog Sugoi/Blog -v 211 | ``` 212 | 213 | ### addon:remove 214 | 215 | アドオンを削除します。 216 | 217 | ```sh 218 | php artisan addon:remove blog; 219 | ``` 220 | 221 | `addons/blog` ディレクトリを削除するだけです。 222 | 223 | ### make:addon 224 | 225 | アドオンを作成します。 226 | 次のコマンドは、アドオン `blog` を `ui`タイプのひな形を用いて PHP名前空間 `Blog` として生成します。 227 | 228 | ```sh 229 | php artisan make:addon blog ui 230 | ``` 231 | 232 | ひな形は9種類から選べます。 233 | 234 | - **minimum** - 最小構成 235 | - **simple** - **views** ディレクトリと **route.php** があるシンプルな構成 236 | - **library** - PHPクラスとデータベースを提供する構成 237 | - **api** - APIのための構成 238 | - **ui** - UIを含むフルセット 239 | - **debug** - デバッグ機能を収めるアドオン。'debug-bar'のサービスプロバイダ登録も含む。 240 | - **generator** - カスタマイズ用スタブファイル。 241 | - **laravel5** - Laravel 5のディレクトリ構成。 242 | - **sample:ui** - UIアドオンのサンプル 243 | - **sample:auth** - Laravel 5に含まれる認証サンプル。 244 | 245 | コマンド引数でひな形を指定しない場合、対話形式で選択できます。 246 | 247 | ```sh 248 | php artisan make:addon blog 249 | ``` 250 | 251 | PHP名前空間は `--namespace` オプションで指定することもできます。 252 | 名前空間の区切りには、`\\` か `/` を使ってください。 253 | 254 | ```sh 255 | php artisan make:addon blog --namespace App\\Blog 256 | php artisan make:addon blog --namespace App/Blog 257 | ``` 258 | 259 | ### make:console 260 | 261 | artisanコマンドクラスを生成します。 262 | 263 | 名前に`foo`を指定すると、`app/Console/Commands/Foo.php` ファイルを生成します。 264 | 265 | ```sh 266 | $ php artisan make:console foo 267 | ``` 268 | 269 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Commands/Foo.php` ファイルを生成します。 270 | 271 | ```sh 272 | $ php artisan make:console foo --addon=blog 273 | ``` 274 | 275 | ### make:controller 276 | 277 | コントローラークラスを生成します。 278 | 279 | 名前に`FooController`を指定すると、`app/Http/Controllers/FooController.php` ファイルを生成します。 280 | 281 | ```sh 282 | $ php artisan make:controller FooController 283 | ``` 284 | 285 | `--resource` オプションを指定すると、リソースコントローラーを生成します。 286 | 287 | ```sh 288 | $ php artisan make:controller FooController --resource 289 | ``` 290 | 291 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Controllers/FooController.php` ファイルを生成します。 292 | 293 | ```sh 294 | $ php artisan make:controller FooController --addon=blog 295 | ``` 296 | 297 | ### make:event 298 | 299 | イベントクラスを生成します。 300 | 301 | 名前に`FooEvent`を指定すると、`app/Events/FooEvent.php` ファイルを生成します。 302 | 303 | ```sh 304 | $ php artisan make:event FooEvent 305 | ``` 306 | 307 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Events/FooEvent.php` ファイルを生成します。 308 | 309 | ```sh 310 | $ php artisan make:event FooEvent --addon=blog 311 | ``` 312 | 313 | ### make:job 314 | 315 | ジョブクラスを生成します。 316 | 317 | 名前に`FooJob`を指定すると、`app/Jobs/FooJob.php` ファイルを生成します。 318 | 319 | ```sh 320 | $ php artisan make:job FooJob 321 | ``` 322 | 323 | `--queued` オプションを指定すると、`ShouldQueue` インターフェースを実装したジョブクラスを生成します。 324 | 325 | ```sh 326 | $ php artisan make:job FooJob --queued 327 | ``` 328 | 329 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Jobs/FooJob.php` ファイルを生成します。 330 | 331 | ```sh 332 | $ php artisan make:job FooJob --addon=blog 333 | ``` 334 | 335 | もし Laravel 5.0 の `App/Commands` ディレクトリを使っているなら、`app/Commands/FooCommand.php` も生成できます。 336 | 337 | ```sh 338 | $ php artisan make:job /Commands/FooCommand 339 | ``` 340 | 341 | ### make:listener 342 | 343 | リスナークラスを生成します。 344 | 345 | 名前に`FooListener`を指定すると、`app/Listeners/FooListener.php` ファイルを生成します。 346 | `--event` オプションは必須です。 347 | 348 | ```sh 349 | $ php artisan make:listener FooListener --event=bar 350 | ``` 351 | 352 | `--queued` オプションを指定すると、`ShouldQueue` インターフェースを実装したリスナークラスを生成します。 353 | 354 | ```sh 355 | $ php artisan make:listener FooListener --event=bar --queued 356 | ``` 357 | 358 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Listeners/FooListener.php` ファイルを生成します。 359 | 360 | ```sh 361 | $ php artisan make:listener FooListener --event=bar --addon=blog 362 | ``` 363 | 364 | ### make:middleware 365 | 366 | ミドルウェアクラスを生成します。 367 | 368 | 名前に`foo`を指定すると、`app/Http/Middleware/Foo.php` ファイルを生成します。 369 | 370 | ```sh 371 | $ php artisan make:middleware foo 372 | ``` 373 | 374 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Middleware/Foo.php` ファイルを生成します。 375 | 376 | ```sh 377 | $ php artisan make:middleware foo --addon=blog 378 | ``` 379 | 380 | ### make:migration 381 | 382 | マイグレーションクラスを生成します。 383 | 384 | 名前に`foo`を指定すると、`app/Database/Migrations/App_1_0.php` ファイルを生成します。 385 | 386 | ```sh 387 | $ php artisan make:migration App_1_0 388 | ``` 389 | 390 | `--create` オプションに `materials` を指定すると、**materials** テーブルを作成するマイグレーションクラスを生成します。 391 | 392 | ```sh 393 | $ php artisan make:migration App_1_1 --create=materials 394 | ``` 395 | 396 | `--update` オプションに `materials` を指定すると、**materials** テーブルを更新するマイグレーションクラスを生成します。 397 | 398 | ```sh 399 | $ php artisan make:migration App_1_2 --update=materials 400 | ``` 401 | 402 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Migrations/Blog_1_0.php` ファイルを生成します。 403 | 404 | ```sh 405 | $ php artisan make:migration Blog_1_0 --addon=blog 406 | ``` 407 | 408 | ### make:model 409 | 410 | Eloquentモデルクラスを生成します。 411 | 412 | 名前に`foo`を指定すると、**foos** テーブルに対応した `app/Foo.php` ファイルを生成します。 413 | 414 | ```sh 415 | $ php artisan make:model foo 416 | ``` 417 | 418 | 名前に`services/models/foo`を指定すると、**foos** テーブルに対応した `app/Services/Models/Foo.php` ファイルを生成します。 419 | PHP名前空間は `App\Services\Models` になります。 420 | 421 | ```sh 422 | $ php artisan make:model services/models/foo 423 | ``` 424 | 425 | `--migration` オプションに `App_1_1` を指定すると、マイグレーションファイルも一緒に生成します。 426 | `php artisan make:migration App_1_1 --create=foos` コマンドを実行した結果と同じです。 427 | 428 | ```sh 429 | $ php artisan make:model foo --migration=App_1_1 430 | ``` 431 | 432 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Foo.php` ファイルを生成します。 433 | 434 | ```sh 435 | $ php artisan make:model foo --addon=blog 436 | ``` 437 | 438 | ### make:policy 439 | 440 | ポリシークラスを生成します。 441 | 442 | 名前に`foo`を指定すると、`app/Policies/Foo.php` ファイルを生成します。 443 | 444 | ```sh 445 | $ php artisan make:policy foo 446 | ``` 447 | 448 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Policies/Foo.php` ファイルを生成します。 449 | 450 | ```sh 451 | $ php artisan make:policy foo --addon=blog 452 | ``` 453 | 454 | ### make:provider 455 | 456 | サービスプロバイダークラスを生成します。 457 | 458 | 名前に`FooServiceProvider`を指定すると、`app/Providers/FooServiceProvider.php` ファイルを生成します。 459 | 460 | ```sh 461 | $ php artisan make:provider FooServiceProvider 462 | ``` 463 | 464 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Providers/FooServiceProvider.php` ファイルを生成します。 465 | 466 | ```sh 467 | $ php artisan make:provider FooServiceProvider --addon=blog 468 | ``` 469 | 470 | ### make:request 471 | 472 | フォームリクエストクラスを生成します。 473 | 474 | 名前に`FooRequest`を指定すると、`app/Http/Requests/FooRequest.php` ファイルを生成します。 475 | 476 | ```sh 477 | $ php artisan make:request FooRequest 478 | ``` 479 | 480 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Requests/FooRequest.php` ファイルを生成します。 481 | 482 | ```sh 483 | $ php artisan make:request FooRequest --addon=blog 484 | ``` 485 | 486 | ### make:seeder 487 | 488 | シードクラスを生成します。 489 | 490 | 名前に`staging`を指定すると、`app/Database/Seeds/Staging.php` ファイルを生成します。 491 | 492 | ```sh 493 | $ php artisan make:request staging 494 | ``` 495 | 496 | `--addon` オプションに `blog` を指定すると、`addons/blog/classes/Seeds/Staging.php` ファイルを生成します。 497 | 498 | ```sh 499 | $ php artisan make:request staging --addon=blog 500 | ``` 501 | 502 | ### make:test 503 | 504 | PHPUnitテストスイートを生成します。 505 | 506 | 名前に`FooTests`を指定すると、`tests/FooTests.php` ファイルを生成します。 507 | 508 | ```sh 509 | $ php artisan make:test FooTests 510 | ``` 511 | 512 | `--addon` オプションに `blog` を指定すると、`addons/blog/tests/FooTests.php` ファイルを生成します。 513 | 514 | ```sh 515 | $ php artisan make:test FooTests --addon=blog 516 | ``` 517 | 518 | ## ヘルパ関数 519 | 520 | ### addon($name = null) 521 | 522 | 名前を指定してアドオンを取得します。 523 | 524 | ```php 525 | $addon = addon('blog'); 526 | ``` 527 | 528 | 名前を省略すると、呼び出し元のクラスが含まれるアドオンを返します。 529 | `addon(addon_name())` と等価です。 530 | 531 | ```php 532 | 533 | namespace Blog\Http\Controllers; 534 | 535 | class BlogController 536 | { 537 | public function index() 538 | { 539 | $addon = addon(); // == addon(addon_name()) 540 | Assert::same('blog', $addon->name()); 541 | } 542 | } 543 | ``` 544 | 545 | `addon()` 関数で取得したオブジェクトを使って、アドオンの属性やリソースにアクセスすることができます。 546 | 547 | ```php 548 | $addon = addon(); 549 | $addon->path(); // {$root}/addons/blog 550 | $addon->relativePath(); // addons/blog 551 | $addon->phpNamespace(); // Blog 552 | $addon->config('page.row_limit', 20); 553 | $addon->trans('emails.title'); 554 | $addon->transChoice('emails.title', 2); 555 | $addon->view('layouts.default'); 556 | $addon->spec('forms.user_register'); 557 | ``` 558 | 559 | ### addon_name($class) 560 | 561 | クラス名からアドオン名を取得します。 562 | クラス名は名前空間を含む完全修飾名でなければなりません。 563 | 名前を指定してアドオンを取得します。 564 | 565 | ```php 566 | $name = addon_name(get_class($this)); 567 | $name = addon_name(\Blog\Providers\AddonServiceProvider::class); // 'blog' 568 | ``` 569 | 570 | 引数を省略すると、呼び出し元のクラスが所属するアドオンの名前を返します。 571 | 572 | ```php 573 | 47 | ``` 48 | 49 | ### [B] It's installed in a project of existence. 50 | 51 | #### 1. Add the package `laravel-plus/extension` use Composer. 52 | 53 | Use composer. 54 | 55 | ```sh 56 | composer require laravel-plus/extension 57 | ``` 58 | 59 | #### 2. Add/Remove the service provider. 60 | 61 | Edit file `config/app.php`. 62 | - Add `LaravelPlus\Extension\ServiceProvider::class` in `providers` section. 63 | - Remove line includes `Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class` in `providers` section. 64 | 65 | ```php 66 | 'providers' => [ 67 | Illuminate\View\ViewServiceProvider:class, 68 | ... 69 | // Add the folloing line. 70 | LaravelPlus\Extension\ServiceProvider::class, 71 | ], 72 | ``` 73 | 74 | ```php 75 | 'providers' => [ 76 | // Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 77 | ], 78 | ``` 79 | 80 | ## Check for running 81 | 82 | Add-on `wiki` is made as a example. 83 | 84 | ```sh 85 | php artisan make:addon wiki sample:ui 86 | ``` 87 | 88 | Please confirm the routing setting. 89 | 90 | ```sh 91 | php artisan route:list 92 | ``` 93 | 94 | A local server is started and accesses `http://localhost:8000/addons/wiki` by a browser. 95 | When a package name is indicated, it's success. 96 | 97 | ```sh 98 | php artisan serve 99 | ``` 100 | 101 | ## Commands 102 | 103 | ### `database:status` 104 | 105 | Migration, seed's definition and installation state are indicated. 106 | 107 | ```sh 108 | php artisan database:status 109 | ``` 110 | 111 | ### `database:upgrade` 112 | 113 | `up()` method in migration of all groups, it's carried out and it's made a newest version. 114 | 115 | ```sh 116 | php artisan database:upgrade 117 | ``` 118 | 119 | It's possible to make them seed after my gray-tion. 120 | 121 | ```sh 122 | php artisan database:upgrade --seed 123 | ``` 124 | 125 | ### `database:clean` 126 | 127 | `down()` method in migration of all groups, , it's carried out and it's returned in the clean state. 128 | 129 | ```sh 130 | php artisan database:clean 131 | ``` 132 | 133 | ### `database:refresh` 134 | 135 | Re-run migration of all groups. 136 | 137 | After `database:clean` and `database:upgrade` were carried out, same. 138 | 139 | ```sh 140 | php artisan database:refresh 141 | ``` 142 | 143 | It's possible to make them seed after migration. 144 | 145 | ```sh 146 | php artisan database:refresh --seed 147 | ``` 148 | 149 | ### `database:rollback` 150 | 151 | The version of the specified group is returned one. 152 | 153 | ```sh 154 | php artisan database:rollback 155 | ``` 156 | 157 | When `--all` option is put, everything's version of the designation group is eliminated. 158 | 159 | ```sh 160 | php artisan database:rollback --all 161 | ``` 162 | 163 | ### `database:again` 164 | 165 | A newest version of a specified group is made. 166 | 167 | I have the same effect as the time when `database:rollback ` and `database:upgrade` were carried out. 168 | 169 | ```sh 170 | php artisan database:again 171 | ``` 172 | 173 | It's possible to make them seed after migration. 174 | 175 | ```sh 176 | php artisan database:again --seed 177 | ``` 178 | 179 | ### `database:seed` 180 | 181 | Run specified seed. 182 | 183 | ```sh 184 | php artisan database:seed 185 | ``` 186 | 187 | When omitting ``, run default seed. 188 | 189 | ```sh 190 | php artisan database:seed 191 | ``` 192 | 193 | ### `addon:status` 194 | 195 | Can check the status of addons. 196 | 197 | ```sh 198 | php artisan addon:status 199 | ``` 200 | 201 | When `addons` directory and `config/addon.php` file don't exist, it's made. 202 | 203 | ### `addon:name` 204 | 205 | A file in the add-on is scanned and the PHP namespace is changed. 206 | 207 | ```sh 208 | php artisan addon:name blog Wonderful/Blog 209 | ``` 210 | 211 | When you'd like to confirm the scanned file, please designate `-v` option. 212 | 213 | ```sh 214 | php artisan addon:name blog Sugoi/Blog -v 215 | ``` 216 | 217 | ### `addon:remove` 218 | 219 | An add-on is eliminated. 220 | 221 | ```sh 222 | php artisan addon:remove blog; 223 | ``` 224 | 225 | `addons/blog` A directory is just eliminated. 226 | 227 | ### `make:addon` 228 | 229 | An add-on is made. 230 | I add on the next command `blog` is generated as PHP name spatial `Blog` using a form of `ui`-type. 231 | 232 | ```sh 233 | php artisan make:addon blog ui 234 | ``` 235 | 236 | A skeleton can be chosen from 9 kinds. 237 | 238 | - **minimum** - Minimum structure. 239 | - **simple** - The simple structure with the directory **views** and the file **route.php**. 240 | - **library** - The composition to which a PHP range and a database are offered. 241 | - **api** - The structure for API. 242 | - **ui** - Full-set including UI. 243 | - **debug** - The add-on in which program testing facility is put. Service provider registration of 'debug-bar' is also included. 244 | - **generator** - Customized for stub files. 245 | - **laravel5** - The directory structure of Laravel 5. 246 | - **sample:ui** - Example of a UI add-on. 247 | - **sample:auth** - The authentication sample included in Laravel 5. 248 | 249 | When not designating a form by a command argument, it can be chosen by an interactive mode. 250 | 251 | ```sh 252 | php artisan make:addon blog 253 | ``` 254 | 255 | PHP namespace can designate `--namespace` by an option. 256 | Please use `\\` or `/` for a namespace separate. 257 | 258 | ```sh 259 | php artisan make:addon blog --namespace App\\Blog 260 | php artisan make:addon blog --namespace App/Blog 261 | ``` 262 | 263 | ### make:console 264 | 265 | Generate a class of artisan command. 266 | 267 | If you specify `foo` to name, to generate a file `app/Console/Commands/Foo.php`. 268 | 269 | ```sh 270 | $ php artisan make:console foo 271 | ``` 272 | 273 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Commands/Foo.php`. 274 | 275 | ```sh 276 | $ php artisan make:console foo --addon=blog 277 | ``` 278 | 279 | ### make:controller 280 | 281 | Generate a class of controller. 282 | 283 | If you specify `FooController` to name, to generate a file `app/Http/Controllers/FooController.php`. 284 | 285 | ```sh 286 | $ php artisan make:controller FooController 287 | ``` 288 | 289 | If you specify option `--resource`, to generate a resource controller. 290 | 291 | ```sh 292 | $ php artisan make:controller FooController --resource 293 | ``` 294 | 295 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Controllers/FooController.php`. 296 | 297 | ```sh 298 | $ php artisan make:controller FooController --addon=blog 299 | ``` 300 | 301 | ### make:event 302 | 303 | Generate a class of event. 304 | 305 | If you specify `FooEvent` to name, to generate a file `app/Events/FooEvent.php`. 306 | 307 | ```sh 308 | $ php artisan make:event FooEvent 309 | ``` 310 | 311 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Events/FooEvent.php`. 312 | 313 | ```sh 314 | $ php artisan make:event FooEvent --addon=blog 315 | ``` 316 | 317 | ### make:job 318 | 319 | Generate a class of job. 320 | 321 | If you specify a `FooJob` to name, to generate a file `app/Jobs/FooEvent.php`. 322 | 323 | ```sh 324 | $ php artisan make:job FooJob 325 | ``` 326 | 327 | If you specify option `--queued`, to generate a job class implemented `ShouldQueue` interface. 328 | 329 | ```sh 330 | $ php artisan make:job FooJob --queued 331 | ``` 332 | 333 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Jobs/FooJob.php`. 334 | 335 | ```sh 336 | $ php artisan make:job FooJob --addon=blog 337 | ``` 338 | 339 | If using a `App/Commands` directory of Laravel 5.0, `app/Commands/FooCommand.php` can also be generated. 340 | 341 | ```sh 342 | $ php artisan make:job /Commands/FooCommand 343 | ``` 344 | 345 | ### make:listener 346 | 347 | Generate a class of listener. 348 | 349 | If you specify `FooListener` to name, to generate a file `app/Listeners/FooListener.php`. 350 | Require `--event` option. 351 | 352 | ```sh 353 | $ php artisan make:listener FooListener --event=bar 354 | ``` 355 | 356 | If you specify option `--queued`, to generate a job class implemented `ShouldQueue` interface. 357 | 358 | ```sh 359 | $ php artisan make:listener FooListener --event=bar --queued 360 | ``` 361 | 362 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Listeners/FooListener.php`. 363 | 364 | ```sh 365 | $ php artisan make:listener FooListener --event=bar --addon=blog 366 | ``` 367 | 368 | ### make:middleware 369 | 370 | Generate a class of middleware. 371 | 372 | If you specify `foo` to name, to generate a file `app/Http/Middleware/Foo.php`. 373 | 374 | ```sh 375 | $ php artisan make:middleware foo 376 | ``` 377 | 378 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Middleware/Foo.php`. 379 | 380 | ```sh 381 | $ php artisan make:middleware foo --addon=blog 382 | ``` 383 | 384 | ### make:migration 385 | 386 | Generate a class of migration. 387 | 388 | If you specify `foo` to name, to generate a file `app/Database/Migrations/App_1_0.php`. 389 | 390 | ```sh 391 | $ php artisan make:migration App_1_0 392 | ``` 393 | 394 | If you specify `materials` to option `--create`, to generate a migration class for create **materials** table. 395 | 396 | ```sh 397 | $ php artisan make:migration App_1_1 --create=materials 398 | ``` 399 | 400 | If you specify `materials` to option `--update`, to generate a migration class for update **materials** table. 401 | 402 | ```sh 403 | $ php artisan make:migration App_1_2 --update=materials 404 | ``` 405 | 406 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Migrations/Blog_1_0.php`. 407 | 408 | ```sh 409 | $ php artisan make:migration Blog_1_0 --addon=blog 410 | ``` 411 | 412 | ### make:model 413 | 414 | Generate a class of Eloquent model. 415 | 416 | If you specify `foo` to name, to generate a file `app/Foo.php` related to **foos** table. 417 | 418 | ```sh 419 | $ php artisan make:model foo 420 | ``` 421 | 422 | If you specify `services/models/foo` to name, to generate a file `app/Services/Models/Foo.php` related to **foos** table. 423 | PHP namespace will be `App\Services\Models`. 424 | 425 | ```sh 426 | $ php artisan make:model services/models/foo 427 | ``` 428 | 429 | If you specify `App_1_1` to option `--migration`, also generates together migration file. 430 | This is the same as a result of executing the command `php artisan make:migration App_1_1 --create=foos`. 431 | 432 | ```sh 433 | $ php artisan make:model foo --migration=App_1_1 434 | ``` 435 | 436 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Foo.php`. 437 | 438 | ```sh 439 | $ php artisan make:model foo --addon=blog 440 | ``` 441 | 442 | ### make:policy 443 | 444 | Generate a class of policy. 445 | 446 | If you specify `foo` to name, to generate a file `app/Policies/Foo.php`. 447 | 448 | ```sh 449 | $ php artisan make:policy foo 450 | ``` 451 | 452 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Policies/Foo.php`. 453 | 454 | ```sh 455 | $ php artisan make:policy foo --addon=blog 456 | ``` 457 | 458 | ### make:provider 459 | 460 | Generate a class of service provider. 461 | 462 | If you specify `FooServiceProvider` to name, to generate a file `app/Providers/FooServiceProvider.php`. 463 | 464 | ```sh 465 | $ php artisan make:provider FooServiceProvider 466 | ``` 467 | 468 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Providers/FooServiceProvider.php`. 469 | 470 | ```sh 471 | $ php artisan make:provider FooServiceProvider --addon=blog 472 | ``` 473 | 474 | ### make:request 475 | 476 | Generate a class of form request. 477 | 478 | If you specify `FooRequest` to name, to generate a file `app/Http/Requests/FooRequest.php`. 479 | 480 | ```sh 481 | $ php artisan make:request FooRequest 482 | ``` 483 | 484 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Requests/FooRequest.php`. 485 | 486 | ```sh 487 | $ php artisan make:request FooRequest --addon=blog 488 | ``` 489 | 490 | ### make:seeder 491 | 492 | Generate a class of seeder. 493 | 494 | If you specify `staging` to name, to generate a file `app/Database/Seeds/Staging.php`. 495 | 496 | ```sh 497 | $ php artisan make:request staging 498 | ``` 499 | 500 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/classes/Seeds/Staging.php`. 501 | 502 | ```sh 503 | $ php artisan make:request staging --addon=blog 504 | ``` 505 | 506 | ### make:test 507 | 508 | Generate a class of PHPUnit test suite. 509 | 510 | If you specify `FooTests` to name, to generate a file `tests/FooTests.php`. 511 | 512 | ```sh 513 | $ php artisan make:test FooTests 514 | ``` 515 | 516 | If you specify `blog` to option `--addon`, to generate a file `addons/blog/tests/FooTests.php`. 517 | 518 | ```sh 519 | $ php artisan make:test FooTests --addon=blog 520 | ``` 521 | 522 | ## Helper functions 523 | 524 | ### addon($name = null) 525 | 526 | Get the add-on by name. 527 | 528 | ```php 529 | $addon = addon('blog'); 530 | ``` 531 | 532 | If omit the name, it returns the add-on that contains the calling class. 533 | This is equivalent to a `addon(addon_name())`. 534 | 535 | ```php 536 | 537 | namespace Blog\Http\Controllers; 538 | 539 | class BlogController 540 | { 541 | public function index() 542 | { 543 | $addon = addon(); // == addon(addon_name()) 544 | Assert::same('blog', $addon->name()); 545 | } 546 | } 547 | ``` 548 | 549 | object retrieved by the `addon()` function, you can access the add-on attributes and resources. 550 | 551 | ```php 552 | $addon = addon(); 553 | $addon->path(); // {$root}/addons/blog 554 | $addon->relativePath(); // addons/blog 555 | $addon->phpNamespace(); // Blog 556 | $addon->config('page.row_limit', 20); 557 | $addon->trans('emails.title'); 558 | $addon->transChoice('emails.title', 2); 559 | $addon->view('layouts.default'); 560 | $addon->spec('forms.user_register'); 561 | ``` 562 | 563 | ### addon_name($class) 564 | 565 | Get the add-on name from the class name . 566 | The class name must be a fully qualified name that contains the name space. 567 | Get the add-on by name. 568 | 569 | ```php 570 | $name = addon_name(get_class($this)); 571 | $name = addon_name(\Blog\Providers\AddonServiceProvider::class); // 'blog' 572 | ``` 573 | 574 | If you omit the argument, returns the name of the add-on contains the caller of the class. 575 | 576 | ```php 577 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Addons/Commands/AddonMakeCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Addons/Commands/AddonNameCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Addons/Commands/AddonRemoveCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Addons/Commands/AddonStatusCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Commands/AppContainerCommand.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class AppContainerCommand extends Command 13 | { 14 | /** 15 | * The console command signature. 16 | * 17 | * @var string 18 | */ 19 | protected $signature = 'app:container'; 20 | 21 | /** 22 | * The console command description. 23 | * 24 | * @var string 25 | */ 26 | protected $description = '[+] Lists object in application container'; 27 | 28 | /** 29 | * Execute the console command. 30 | * 31 | * @return mixed 32 | */ 33 | public function handle() 34 | { 35 | $app = new ApplicationHook($this->laravel); 36 | 37 | $instances = $app->getInstances(); 38 | $objects = $app->getBindings(); 39 | $aliases = []; 40 | 41 | foreach ($app->getAliases() as $alias => $abstract) { 42 | $aliases[$abstract][] = $alias; 43 | } 44 | 45 | ksort($objects); 46 | 47 | foreach ($objects as $name => $instance) { 48 | $this->info($name.': '); 49 | 50 | if (is_array($instance)) { 51 | if ($instance['shared']) { 52 | $this->output(array_get($instances, $name)); 53 | } 54 | else { 55 | $this->output($instance['concrete']); 56 | } 57 | } 58 | else { 59 | $this->output($instance); 60 | } 61 | 62 | if (isset($aliases[$name])) { 63 | foreach ($aliases[$name] as $value) { 64 | $this->line("\t[alias] \"$value\"\n"); 65 | } 66 | } 67 | } 68 | } 69 | 70 | private function output($instance) 71 | { 72 | $line = "\t"; 73 | if (is_object($instance)) { 74 | $line .= 'object "'.get_class($instance).'"'; 75 | } elseif (is_string($instance)) { 76 | $line .= 'string "'.$instance.'"'; 77 | } elseif (is_bool($instance)) { 78 | $line .= 'bool '.$instance.''; 79 | } elseif (is_null($instance)) { 80 | $line .= 'null'; 81 | } else { 82 | $line .= '(unknown) '.$instance; 83 | } 84 | $line .= "\n"; 85 | 86 | $this->line($line); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /sources/Commands/HashCheckCommand.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class HashCheckCommand extends Command 11 | { 12 | /** 13 | * The console command signature. 14 | * 15 | * @var string 16 | */ 17 | protected $signature = 'hash:check 18 | {string1 : Plain or Hashed string one.} 19 | {string2 : Plain or Hashed string two.} 20 | {--cost=10 : Cost of generate.} 21 | '; 22 | 23 | /** 24 | * The console command description. 25 | * 26 | * @var string 27 | */ 28 | protected $description = '[+] Check hashed value'; 29 | 30 | /** 31 | * Execute the console command. 32 | * 33 | * @return mixed 34 | */ 35 | public function handle() 36 | { 37 | $cost = $this->option('cost'); 38 | 39 | $string1 = $this->argument('string1'); 40 | $string2 = $this->argument('string2'); 41 | 42 | if ($this->isHashed($string1)) { 43 | $rawString = $string2; 44 | $hashedString = $string1; 45 | } elseif ($this->isHashed($string2)) { 46 | $rawString = $string1; 47 | $hashedString = $string2; 48 | } else { 49 | $this->error(sprintf('Error: both "%s" and "%s" are not hashed string.', $string1, $string2)); 50 | 51 | return; 52 | } 53 | 54 | $result = app('hash')->check($string1, $string2); 55 | 56 | $this->info($result ? 'Check OK!' : 'Check NG.'); 57 | } 58 | 59 | protected function isHashed($string) 60 | { 61 | return strlen($string) == 60 && starts_with($string, '$2y$'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sources/Commands/HashMakeCommand.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class HashMakeCommand extends Command 11 | { 12 | /** 13 | * The console command signature. 14 | * 15 | * @var string 16 | */ 17 | protected $signature = 'hash:make 18 | {string : Plain string.} 19 | {--cost=10 : Cost of generate.} 20 | '; 21 | 22 | /** 23 | * The console command description. 24 | * 25 | * @var string 26 | */ 27 | protected $description = '[+] Make hashed value'; 28 | 29 | /** 30 | * Execute the console command. 31 | * 32 | * @return mixed 33 | */ 34 | public function handle() 35 | { 36 | $cost = $this->option('cost'); 37 | 38 | $hashed = app('hash')->make($this->argument('string'), [ 39 | 'rounds' => $cost, 40 | ]); 41 | 42 | $this->info(sprintf('Generated hash: "%s"', $hashed)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sources/Commands/RouteListCommand.php: -------------------------------------------------------------------------------- 1 | laravel['config']['app.log'] === 'syslog') { 36 | $this->error('syslog not support.'); 37 | 38 | return; 39 | } 40 | 41 | $connection = $this->argument('connection'); 42 | 43 | // on Local 44 | if (is_null($connection)) { 45 | $path = $this->option('path') ?: $this->getLocalPath(); 46 | 47 | if ($path) { 48 | $this->tailLocalLogs($path); 49 | } else { 50 | $this->error('Could not determine path to log file.'); 51 | } 52 | } 53 | // on Remote 54 | else { 55 | $path = $this->option('path') ?: $this->getRemotePath($connection); 56 | 57 | if ($path) { 58 | $this->tailRemoteLogs($path, $connection); 59 | } else { 60 | $this->error('Could not determine path to log file.'); 61 | } 62 | } 63 | } 64 | 65 | /** 66 | * Get the path to the Laravel log file. 67 | * 68 | * @return string 69 | */ 70 | protected function getLocalPath() 71 | { 72 | switch ($this->laravel['config']['app.log']) { 73 | case 'single': 74 | return storage_path('logs/laravel.log'); 75 | 76 | case 'daily': 77 | $date = Carbon::today()->format('Y-m-d'); 78 | 79 | return storage_path("logs/laravel-{$date}.log"); 80 | 81 | case 'syslog': 82 | throw new \RuntimeException('syslog not support'); 83 | } 84 | } 85 | 86 | /** 87 | * Tail a local log file for the application. 88 | * 89 | * @param string $path 90 | * 91 | * @return string 92 | */ 93 | protected function tailLocalLogs($path) 94 | { 95 | $output = $this->output; 96 | 97 | $lines = $this->option('lines'); 98 | 99 | (new Process('tail -f -n '.$lines.' '.escapeshellarg($path)))->setTimeout(null)->run(function ($type, $line) use ($output) { 100 | $output->write($line); 101 | }); 102 | } 103 | 104 | /** 105 | * Get the path to the Laravel log file. 106 | * 107 | * @param string $connection 108 | * 109 | * @return string 110 | */ 111 | protected function getRemotePath($connection) 112 | { 113 | return $this->getRoot($connection).str_replace(base_path(), '', $this->getRemotePathFromStorage()); 114 | } 115 | 116 | /** 117 | * Get the path to the Laravel log file. 118 | * 119 | * @return string 120 | */ 121 | protected function getRemotePathFromStorage() 122 | { 123 | switch ($this->laravel['config']['app.log']) { 124 | case 'single': 125 | return storage_path('logs/laravel.log'); 126 | 127 | case 'daily': 128 | $date = Carbon::today()->format('Y-m-d'); 129 | 130 | return storage_path("logs/laravel-{$date}.log"); 131 | 132 | case 'syslog': 133 | throw new \RuntimeException('syslog not support'); 134 | } 135 | } 136 | 137 | /** 138 | * Get the path to the Laravel install root. 139 | * 140 | * @param string $connection 141 | * 142 | * @return string 143 | */ 144 | protected function getRoot($connection) 145 | { 146 | return $this->laravel['config']['remote.connections.'.$connection.'.root']; 147 | } 148 | 149 | /** 150 | * Tail a remote log file at the given path and connection. 151 | * 152 | * @param string $path 153 | * @param string $connection 154 | */ 155 | protected function tailRemoteLogs($path, $connection) 156 | { 157 | $out = $this->output; 158 | 159 | $lines = $this->option('lines'); 160 | 161 | $this->getRemote($connection)->run('tail -f -n '.$lines.' '.escapeshellarg($path), function ($line) use ($out) { 162 | $out->write($line); 163 | }); 164 | } 165 | 166 | /** 167 | * Get a connection to the remote server. 168 | * 169 | * @param string $connection 170 | * 171 | * @return \Illuminate\Remote\Connection 172 | */ 173 | protected function getRemote($connection) 174 | { 175 | return $this->laravel['remote']->connection($connection); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /sources/ConsoleKernel.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseCleanCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseRefreshCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseRollbackCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseSeedCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseStatusCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/DatabaseUpgradeCommand.php: -------------------------------------------------------------------------------- 1 | description = '[+] '.$this->description; 15 | 16 | parent::__construct(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/Database/Commands/MigrationMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 40 | } 41 | 42 | /** 43 | * Get the default namespace for the class. 44 | * 45 | * @return string 46 | */ 47 | protected function getDefaultNamespace() 48 | { 49 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Migrations' : 'Database\\Migrations'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sources/Database/Commands/SeederMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 38 | } 39 | 40 | /** 41 | * Get the default namespace for the class. 42 | * 43 | * @return string 44 | */ 45 | protected function getDefaultNamespace() 46 | { 47 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Seeds' : 'Database\\Seeds'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sources/Database/stubs/migration-create.stub: -------------------------------------------------------------------------------- 1 | increments('id'); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('{$table}'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sources/Database/stubs/migration-update.stub: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Commands' : 'Console\\Commands'); 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return 'command.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param \Jumilla\Generators\FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'class' => $class, 85 | 'command' => $this->option('command'), 86 | ]); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /sources/Generators/Commands/ControllerMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 49 | } 50 | 51 | /** 52 | * Get the default namespace for the class. 53 | * 54 | * @return string 55 | */ 56 | protected function getDefaultNamespace() 57 | { 58 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Controllers' : 'Http\\Controllers'); 59 | } 60 | 61 | /** 62 | * Get the stub file for the generator. 63 | * 64 | * @return string 65 | */ 66 | protected function getStub() 67 | { 68 | if ($this->option('model')) { 69 | return 'controller-model.stub'; 70 | } 71 | return $this->option('resource') ? 'controller-resource.stub' : 'controller-plain.stub'; 72 | } 73 | 74 | /** 75 | * Generate file. 76 | * 77 | * @param \Jumilla\Generators\FileGenerator $generator 78 | * @param string $path 79 | * @param string $fqcn 80 | * 81 | * @return bool 82 | */ 83 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 84 | { 85 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 86 | list($model_namespace, $model_class) = $this->splitFullQualifyClassName($this->parseModel($this->option('model', ''))); 87 | 88 | return $generator->file($path)->template($this->getStub(), [ 89 | 'namespace' => $namespace, 90 | 'root_namespace' => $this->getAppNamespace(), // use App\Http\Controllers\Controller 91 | 'class' => $class, 92 | 'model_namespace' => $model_namespace ? $model_namespace.'\\' : '', 93 | 'model_class' => $model_class, 94 | ]); 95 | } 96 | 97 | /** 98 | * Get the fully-qualified model class name. 99 | * 100 | * @param string $model 101 | * @return string 102 | */ 103 | protected function parseModel($model) 104 | { 105 | if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { 106 | throw new InvalidArgumentException('Model name contains invalid characters.'); 107 | } 108 | 109 | $model = trim(str_replace('/', '\\', $model), '\\'); 110 | 111 | return $model; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /sources/Generators/Commands/DummyCommand.php: -------------------------------------------------------------------------------- 1 | info('This is the dummy command. no effect.'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sources/Generators/Commands/EventMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 46 | } 47 | 48 | /** 49 | * Get the default namespace for the class. 50 | * 51 | * @return string 52 | */ 53 | protected function getDefaultNamespace() 54 | { 55 | return $this->getRootNamespace().'\\Events'; 56 | } 57 | 58 | /** 59 | * Get the stub file for the generator. 60 | * 61 | * @return string 62 | */ 63 | protected function getStub() 64 | { 65 | return 'event.stub'; 66 | } 67 | 68 | /** 69 | * Generate file. 70 | * 71 | * @param \Jumilla\Generators\FileGenerator $generator 72 | * @param string $path 73 | * @param string $fqcn 74 | * 75 | * @return bool 76 | */ 77 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 78 | { 79 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 80 | 81 | return $generator->file($path)->template($this->getStub(), [ 82 | 'namespace' => $namespace, 83 | 'root_namespace' => $this->getAppNamespace(), // use App\Events\Event 84 | 'class' => $class, 85 | ]); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sources/Generators/Commands/JobMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\Jobs'; 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return $this->option('sync') ? 'job-sync.stub' : 'job-queued.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param \Jumilla\Generators\FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'root_namespace' => $this->getAppNamespace(), // use App\Jobs\Job 85 | 'class' => $class, 86 | ]); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /sources/Generators/Commands/ListenerMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 49 | } 50 | 51 | /** 52 | * Process command line arguments 53 | * 54 | * @return bool 55 | */ 56 | protected function processArguments() 57 | { 58 | if ($this->option('event') == null) { 59 | throw new RuntimeException('Missing required option: --event'); 60 | } 61 | 62 | return true; 63 | } 64 | 65 | /** 66 | * Get the default namespace for the class. 67 | * 68 | * @return string 69 | */ 70 | protected function getDefaultNamespace() 71 | { 72 | return $this->getRootNamespace().'\\Listeners'; 73 | } 74 | 75 | /** 76 | * Get the stub file for the generator. 77 | * 78 | * @return string 79 | */ 80 | protected function getStub() 81 | { 82 | return $this->option('queued') ? 'listener-queued.stub' : 'listener-sync.stub'; 83 | } 84 | 85 | /** 86 | * Generate file. 87 | * 88 | * @param \Jumilla\Generators\FileGenerator $generator 89 | * @param string $path 90 | * @param string $fqcn 91 | * 92 | * @return bool 93 | */ 94 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 95 | { 96 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 97 | 98 | return $generator->file($path)->template($this->getStub(), [ 99 | 'namespace' => $namespace, 100 | 'root_namespace' => $this->getAppNamespace(), // use App\Events\{$event} 101 | 'class' => $class, 102 | 'event' => $this->option('event'), 103 | ]); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /sources/Generators/Commands/MailMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\Mail'; 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return $this->option('markdown') ? 'mail-markdown.stub' : 'mail-view.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param \Jumilla\Generators\FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'class' => $class, 85 | ]); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sources/Generators/Commands/MiddlewareMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 46 | } 47 | 48 | /** 49 | * Get the default namespace for the class. 50 | * 51 | * @return string 52 | */ 53 | protected function getDefaultNamespace() 54 | { 55 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Middleware' : 'Http\\Middleware'); 56 | } 57 | 58 | /** 59 | * Get the stub file for the generator. 60 | * 61 | * @return string 62 | */ 63 | protected function getStub() 64 | { 65 | return 'middleware.stub'; 66 | } 67 | 68 | /** 69 | * Generate file. 70 | * 71 | * @param \Jumilla\Generators\FileGenerator $generator 72 | * @param string $path 73 | * @param string $fqcn 74 | * 75 | * @return bool 76 | */ 77 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 78 | { 79 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 80 | 81 | return $generator->file($path)->template($this->getStub(), [ 82 | 'namespace' => $namespace, 83 | 'class' => $class, 84 | ]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sources/Generators/Commands/ModelMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 48 | } 49 | 50 | /** 51 | * Execute the console command. 52 | */ 53 | public function handle() 54 | { 55 | $this->addon = $this->getAddon(); 56 | 57 | if (parent::handle() !== false) { 58 | if ($this->option('migration')) { 59 | $table = $this->toTable($this->argument('name')); 60 | 61 | $this->call('make:migration', [ 62 | 'name' => $this->option('migration'), 63 | '--addon' => $this->option('addon'), 64 | '--create' => $table, 65 | ]); 66 | } 67 | } 68 | } 69 | 70 | /** 71 | * Get the default namespace for the class. 72 | * 73 | * @return string 74 | */ 75 | protected function getDefaultNamespace() 76 | { 77 | return $this->getRootNamespace(); 78 | } 79 | 80 | /** 81 | * Get the stub file for the generator. 82 | * 83 | * @return string 84 | */ 85 | protected function getStub() 86 | { 87 | return 'model.stub'; 88 | } 89 | 90 | /** 91 | * Generate file. 92 | * 93 | * @param \Jumilla\Generators\FileGenerator $generator 94 | * @param string $path 95 | * @param string $fqcn 96 | * 97 | * @return bool 98 | */ 99 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 100 | { 101 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 102 | 103 | return $generator->file($path)->template($this->getStub(), [ 104 | 'namespace' => $namespace, 105 | 'class' => $class, 106 | 'table' => $this->toTable($class), 107 | ]); 108 | } 109 | 110 | /** 111 | * Convert name to table. 112 | * 113 | * @param string $name 114 | * 115 | * @return string 116 | */ 117 | protected function toTable($name) 118 | { 119 | return Str::plural(Str::snake(class_basename($name))); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /sources/Generators/Commands/NotificationMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\Notifications'; 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return $this->option('markdown') ? 'notification-markdown.stub' : 'notification-html.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param \Jumilla\Generators\FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'class' => $class, 85 | ]); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sources/Generators/Commands/PolicyMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\Policies'; 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return $this->option('model') ? 'policy-model.stub' : 'policy-plain.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'class' => $class, 85 | 'root_namespace' => $this->getAppNamespace(), // use App\Jobs\Job 86 | 'model' => $this->option('model'), 87 | ]); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sources/Generators/Commands/ProviderMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 46 | } 47 | 48 | /** 49 | * Get the default namespace for the class. 50 | * 51 | * @return string 52 | */ 53 | protected function getDefaultNamespace() 54 | { 55 | return $this->getRootNamespace().'\\Providers'; 56 | } 57 | 58 | /** 59 | * Get the stub file for the generator. 60 | * 61 | * @return string 62 | */ 63 | protected function getStub() 64 | { 65 | return 'provider.stub'; 66 | } 67 | 68 | /** 69 | * Generate file. 70 | * 71 | * @param \Jumilla\Generators\FileGenerator $generator 72 | * @param string $path 73 | * @param string $fqcn 74 | * 75 | * @return bool 76 | */ 77 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 78 | { 79 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 80 | 81 | return $generator->file($path)->template($this->getStub(), [ 82 | 'namespace' => $namespace, 83 | 'class' => $class, 84 | ]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sources/Generators/Commands/RequestMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 46 | } 47 | 48 | /** 49 | * Get the default namespace for the class. 50 | * 51 | * @return string 52 | */ 53 | protected function getDefaultNamespace() 54 | { 55 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Requests' : 'Http\\Requests'); 56 | } 57 | 58 | /** 59 | * Get the stub file for the generator. 60 | * 61 | * @return string 62 | */ 63 | protected function getStub() 64 | { 65 | return 'request.stub'; 66 | } 67 | 68 | /** 69 | * Generate file. 70 | * 71 | * @param \Jumilla\Generators\FileGenerator $generator 72 | * @param string $path 73 | * @param string $fqcn 74 | * 75 | * @return bool 76 | */ 77 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 78 | { 79 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 80 | 81 | return $generator->file($path)->template($this->getStub(), [ 82 | 'namespace' => $namespace, 83 | 'class' => $class, 84 | ]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sources/Generators/Commands/ResourceMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the default namespace for the class. 51 | * 52 | * @return string 53 | */ 54 | protected function getDefaultNamespace() 55 | { 56 | return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Resources' : 'Http\\Resources'); 57 | } 58 | 59 | /** 60 | * Get the stub file for the generator. 61 | * 62 | * @return string 63 | */ 64 | protected function getStub() 65 | { 66 | return $this->option('collection') ? 'resource-collection.stub' : 'resource.stub'; 67 | } 68 | 69 | /** 70 | * Generate file. 71 | * 72 | * @param \Jumilla\Generators\FileGenerator $generator 73 | * @param string $path 74 | * @param string $fqcn 75 | * 76 | * @return bool 77 | */ 78 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 79 | { 80 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 81 | 82 | return $generator->file($path)->template($this->getStub(), [ 83 | 'namespace' => $namespace, 84 | 'class' => $class, 85 | ]); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sources/Generators/Commands/RuleMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 46 | } 47 | 48 | /** 49 | * Get the default namespace for the class. 50 | * 51 | * @return string 52 | */ 53 | protected function getDefaultNamespace() 54 | { 55 | return $this->getRootNamespace().'\\Rules'; 56 | } 57 | 58 | /** 59 | * Get the stub file for the generator. 60 | * 61 | * @return string 62 | */ 63 | protected function getStub() 64 | { 65 | return 'rule.stub'; 66 | } 67 | 68 | /** 69 | * Generate file. 70 | * 71 | * @param \Jumilla\Generators\FileGenerator $generator 72 | * @param string $path 73 | * @param string $fqcn 74 | * 75 | * @return bool 76 | */ 77 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 78 | { 79 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 80 | 81 | return $generator->file($path)->template($this->getStub(), [ 82 | 'namespace' => $namespace, 83 | 'class' => $class, 84 | ]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sources/Generators/Commands/TestMakeCommand.php: -------------------------------------------------------------------------------- 1 | setStubDirectory(__DIR__.'/../stubs'); 47 | } 48 | 49 | /** 50 | * Get the directory path for root namespace. 51 | * 52 | * @return string 53 | */ 54 | protected function getRootDirectory() 55 | { 56 | return $this->addon ? $this->addon->path('tests') : $this->laravel->basePath().'/tests'; 57 | } 58 | 59 | /** 60 | * Get the default namespace for the class. 61 | * 62 | * @return $string 63 | */ 64 | protected function getRootNamespace() 65 | { 66 | return $this->addon ? 'Tests\\'.studly_case($this->addon->name()) : 'Tests'; 67 | } 68 | 69 | /** 70 | * Get the root namespace for the class. 71 | * 72 | * @return string 73 | */ 74 | protected function getDefaultNamespace() 75 | { 76 | return $this->getRootNamespace() . ($this->option('unit') ? '\\Unit' : '\\Feature'); 77 | } 78 | 79 | /** 80 | * Get the stub file for the generator. 81 | * 82 | * @return string 83 | */ 84 | protected function getStub() 85 | { 86 | return $this->option('unit') ? 'test-unit.stub' : 'test-feature.stub'; 87 | } 88 | 89 | /** 90 | * Generate file. 91 | * 92 | * @param \Jumilla\Generators\FileGenerator $generator 93 | * @param string $path 94 | * @param string $fqcn 95 | * 96 | * @return bool 97 | */ 98 | protected function generateFile(FileGenerator $generator, $path, $fqcn) 99 | { 100 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); 101 | 102 | return $generator->file($path)->template($this->getStub(), [ 103 | 'namespace' => $namespace, 104 | 'root_namespace' => $this->getRootNamespace(), 105 | 'class' => $class, 106 | ]); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /sources/Generators/GeneratorCommandTrait.php: -------------------------------------------------------------------------------- 1 | processArguments()) { 26 | return false; 27 | } 28 | 29 | $this->addon = $this->getAddon(); 30 | 31 | return parent::handle(); 32 | } 33 | 34 | /** 35 | * Process command line arguments 36 | * 37 | * @return bool 38 | */ 39 | protected function processArguments() 40 | { 41 | return true; 42 | } 43 | 44 | /** 45 | * Option --addon specified. 46 | * 47 | * @return bool 48 | */ 49 | protected function onAddon() 50 | { 51 | return $this->option('addon') !== null; 52 | } 53 | 54 | /** 55 | * Get addon. 56 | * 57 | * @return string 58 | */ 59 | protected function getAddon() 60 | { 61 | if ($addon = $this->option('addon')) { 62 | $env = app(AddonEnvironment::class); 63 | 64 | if (!$env->exists($addon)) { 65 | throw new UnexpectedValueException("Addon '$addon' is not found."); 66 | } 67 | 68 | return $env->addon($addon); 69 | } else { 70 | return; 71 | } 72 | } 73 | 74 | /** 75 | * Get the application namespace. 76 | * 77 | * @return $string 78 | */ 79 | protected function getAppNamespace() 80 | { 81 | return trim($this->laravel->getNamespace(), '\\'); 82 | } 83 | 84 | /** 85 | * Get the addon namespace. 86 | * 87 | * @return $string 88 | */ 89 | protected function getAddonNamespace() 90 | { 91 | return $this->addon->phpNamespace(); 92 | } 93 | 94 | /** 95 | * Get the default namespace for the class. 96 | * 97 | * @return $string 98 | */ 99 | protected function getRootNamespace() 100 | { 101 | return $this->addon ? $this->getAddonNamespace() : $this->getAppNamespace(); 102 | } 103 | 104 | /** 105 | * Get the directory path for root namespace. 106 | * 107 | * @return string 108 | */ 109 | protected function getRootDirectory() 110 | { 111 | if ($this->addon) { 112 | $directories = $this->addon->config('addon.directories'); 113 | 114 | if (! $directories) { 115 | $directories = ['classes']; 116 | } 117 | 118 | return $this->addon->path($directories[0]); 119 | } 120 | else { 121 | return parent::getRootDirectory(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /sources/Generators/stubs/command.stub: -------------------------------------------------------------------------------- 1 | markdown('view.name'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sources/Generators/stubs/mail-view.stub: -------------------------------------------------------------------------------- 1 | view('view.name'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sources/Generators/stubs/middleware.stub: -------------------------------------------------------------------------------- 1 | line('The introduction to the notification.') 45 | ->action('Notification Action', url('/')) 46 | ->line('Thank you for using our application!'); 47 | } 48 | 49 | /** 50 | * Get the array representation of the notification. 51 | * 52 | * @param mixed $notifiable 53 | * @return array 54 | */ 55 | public function toArray($notifiable) 56 | { 57 | return [ 58 | // 59 | ]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sources/Generators/stubs/notification-markdown.stub: -------------------------------------------------------------------------------- 1 | markdown('view.name'); 44 | } 45 | 46 | /** 47 | * Get the array representation of the notification. 48 | * 49 | * @param mixed $notifiable 50 | * @return array 51 | */ 52 | public function toArray($notifiable) 53 | { 54 | return [ 55 | // 56 | ]; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sources/Generators/stubs/policy-model.stub: -------------------------------------------------------------------------------- 1 | assertTrue(true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sources/Generators/stubs/test-unit.stub: -------------------------------------------------------------------------------- 1 | assertTrue(true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sources/Hooks/ApplicationHook.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class ApplicationHook extends LaravelApplication implements ApplicationInterface 12 | { 13 | /** 14 | * @var \Illuminate\Contracts\Foundation\Application 15 | */ 16 | private $app; 17 | 18 | public function __construct(ApplicationInterface $app) 19 | { 20 | $this->app = $app; 21 | } 22 | 23 | /** 24 | * An array of the types that have been resolved. 25 | * 26 | * @return array 27 | */ 28 | public function getResolved() 29 | { 30 | return $this->app->resolved; 31 | } 32 | 33 | /** 34 | * The container's bindings. 35 | * 36 | * @return array 37 | */ 38 | public function getBindings() 39 | { 40 | return $this->app->bindings; 41 | } 42 | 43 | /** 44 | * The container's shared instances. 45 | * 46 | * @return array 47 | */ 48 | public function getInstances() 49 | { 50 | return $this->app->instances; 51 | } 52 | 53 | /** 54 | * The registered type aliases. 55 | * 56 | * @return array 57 | */ 58 | public function getAliases() 59 | { 60 | return $this->app->aliases; 61 | } 62 | 63 | /** 64 | * All of the registered tags. 65 | * 66 | * @return array 67 | */ 68 | public function getTags() 69 | { 70 | return $this->app->tags; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sources/HttpKernel.php: -------------------------------------------------------------------------------- 1 | 'command.cache.clear', 30 | 'CacheForget' => 'command.cache.forget', 31 | 'ClearCompiled' => 'command.clear-compiled', 32 | 'ClearResets' => 'command.auth.resets.clear', 33 | 'ConfigCache' => 'command.config.cache', 34 | 'ConfigClear' => 'command.config.clear', 35 | 'Down' => 'command.down', 36 | 'Environment' => 'command.environment', 37 | 'KeyGenerate' => 'command.key.generate', 38 | // 'Migrate' => 'command.migrate', 39 | // 'MigrateFresh' => 'command.migrate.fresh', 40 | // 'MigrateInstall' => 'command.migrate.install', 41 | // 'MigrateRefresh' => 'command.migrate.refresh', 42 | // 'MigrateReset' => 'command.migrate.reset', 43 | // 'MigrateRollback' => 'command.migrate.rollback', 44 | // 'MigrateStatus' => 'command.migrate.status', 45 | 'Optimize' => 'command.optimize', 46 | 'PackageDiscover' => 'command.package.discover', 47 | 'QueueFailed' => 'command.queue.failed', 48 | 'QueueFlush' => 'command.queue.flush', 49 | 'QueueForget' => 'command.queue.forget', 50 | 'QueueListen' => 'command.queue.listen', 51 | 'QueueRestart' => 'command.queue.restart', 52 | 'QueueRetry' => 'command.queue.retry', 53 | 'QueueWork' => 'command.queue.work', 54 | 'RouteCache' => 'command.route.cache', 55 | 'RouteClear' => 'command.route.clear', 56 | 'RouteList' => 'command.route.list', 57 | // 'Seed' => 'command.seed', 58 | 'ScheduleFinish' => ScheduleFinishCommand::class, 59 | 'ScheduleRun' => ScheduleRunCommand::class, 60 | 'StorageLink' => 'command.storage.link', 61 | 'Up' => 'command.up', 62 | 'ViewClear' => 'command.view.clear', 63 | 64 | 'Route' => 'command+.route', 65 | 'Tail' => 'command+.tail', 66 | 'AddonList' => 'command+.addon.list', 67 | 'AddonStatus' => 'command+.addon.status', 68 | 'DatabaseStatus' => 'command+.database.status', 69 | 'DatabaseUpgrade' => 'command+.database.upgrade', 70 | 'DatabaseClean' => 'command+.database.clean', 71 | 'DatabaseRefresh' => 'command+.database.refresh', 72 | 'DatabaseRollback' => 'command+.database.rollback', 73 | 'DatabaseAgain' => 'command+.database.again', 74 | 'DatabaseSeed' => 'command+.database.seed', 75 | 'HashMake' => 'command+.hash.make', 76 | 'HashCheck' => 'command+.hash.check', 77 | ]; 78 | 79 | /** 80 | * The commands to be registered. 81 | * 82 | * @var array 83 | */ 84 | protected $devCommands = [ 85 | 'AppName' => 'command.app.name', 86 | // 'AuthMake' => 'command.auth.make', 87 | // 'CacheTable' => 'command.cache.table', 88 | // 'ConsoleMake' => 'command.console.make', 89 | // 'ControllerMake' => 'command.controller.make', 90 | 'EventGenerate' => 'command.event.generate', 91 | // 'EventMake' => 'command.event.make', 92 | // 'FactoryMake' => 'command.factory.make', 93 | // 'JobMake' => 'command.job.make', 94 | // 'ListenerMake' => 'command.listener.make', 95 | // 'MailMake' => 'command.mail.make', 96 | // 'MiddlewareMake' => 'command.middleware.make', 97 | // 'MigrateMake' => 'command.migrate.make', 98 | // 'ModelMake' => 'command.model.make', 99 | // 'NotificationMake' => 'command.notification.make', 100 | // 'NotificationTable' => 'command.notification.table', 101 | // 'PolicyMake' => 'command.policy.make', 102 | // 'ProviderMake' => 'command.provider.make', 103 | // 'QueueFailedTable' => 'command.queue.failed-table', 104 | // 'QueueTable' => 'command.queue.table', 105 | // 'RequestMake' => 'command.request.make', 106 | // 'ResourceMake' => 'command.resource.make', 107 | // 'RuletMake' => 'command.rule.make', 108 | // 'SeederMake' => 'command.seeder.make', 109 | // 'SessionTable' => 'command.session.table', 110 | // 'TestMake' => 'command.test.make', 111 | 'Preset' => 'command.preset', 112 | 'Serve' => 'command.serve', 113 | 'VendorPublish' => 'command.vendor.publish', 114 | 115 | 'AppContainer' => 'command+.app.container', 116 | 'AddonName' => 'command+.addon.name', 117 | 'AddonRemove' => 'command+.addon.remove', 118 | 119 | 'MakeAddon' => 'command+.addon.make', 120 | 'MakeCommand' => 'command+.command.make', 121 | 'MakeController' => 'command+.controller.make', 122 | 'MakeEvent' => 'command+.event.make', 123 | 'MakeJob' => 'command+.job.make', 124 | 'MakeListener' => 'command+.listener.make', 125 | 'MakeMail' => 'command+.mail.make', 126 | 'MakeMiddleware' => 'command+.middleware.make', 127 | 'MakeMigration' => 'command+.migration.make', 128 | 'MakeModel' => 'command+.model.make', 129 | 'MakeNotification' => 'command+.notification.make', 130 | 'MakePolicy' => 'command+.policy.make', 131 | 'MakeProvider' => 'command+.provider.make', 132 | 'MakeRequest' => 'command+.request.make', 133 | 'MakeResource' => 'command+.resource.make', 134 | 'MakeRule' => 'command+.rule.make', 135 | 'MakeSeeder' => 'command+.seeder.make', 136 | 'MakeTest' => 'command+.test.make', 137 | ]; 138 | 139 | /** 140 | * Register the service provider. 141 | * 142 | * @return void 143 | */ 144 | public function register() 145 | { 146 | $this->registerCommands($this->availableCommands()); 147 | } 148 | 149 | /** 150 | * Get the services provided by the provider. 151 | * 152 | * @return array 153 | */ 154 | public function provides() 155 | { 156 | return array_values($this->availableCommands()); 157 | } 158 | 159 | /** 160 | * @return array 161 | */ 162 | protected function availableCommands() 163 | { 164 | $commands = $this->commands; 165 | 166 | if ($this->app->environment() != 'production') { 167 | $commands = array_merge($commands, $this->devCommands); 168 | } 169 | 170 | return $commands; 171 | } 172 | 173 | /** 174 | * Register the given commands. 175 | * 176 | * @param array $commands 177 | * @return void 178 | */ 179 | protected function registerCommands(array $commands) 180 | { 181 | foreach ($commands as $name => $command) { 182 | $this->{"register{$name}Command"}($command); 183 | } 184 | 185 | $this->commands(array_values($commands)); 186 | } 187 | 188 | /** 189 | * Register the command. 190 | * 191 | * @param string $command 192 | * @return void 193 | */ 194 | protected function registerRouteCommand($command) 195 | { 196 | $this->app->singleton($command, function ($app) { 197 | return new Commands\RouteListCommand($app); 198 | }); 199 | } 200 | 201 | /** 202 | * Register the command. 203 | * 204 | * @param string $command 205 | * @return void 206 | */ 207 | protected function registerTailCommand($command) 208 | { 209 | $this->app->singleton($command, function ($app) { 210 | return new Commands\TailCommand($app); 211 | }); 212 | } 213 | 214 | /** 215 | * Register the command. 216 | * 217 | * @param string $command 218 | * @return void 219 | */ 220 | protected function registerAppContainerCommand($command) 221 | { 222 | $this->app->singleton($command, function ($app) { 223 | return new Commands\AppContainerCommand($app); 224 | }); 225 | } 226 | 227 | /** 228 | * Register the command. 229 | * 230 | * @param string $command 231 | * @return void 232 | */ 233 | protected function registerAddonListCommand($command) 234 | { 235 | $this->app->singleton($command, function ($app) { 236 | return new Addons\Commands\AddonListCommand($app); 237 | }); 238 | } 239 | 240 | /** 241 | * Register the command. 242 | * 243 | * @param string $command 244 | * @return void 245 | */ 246 | protected function registerAddonStatusCommand($command) 247 | { 248 | $this->app->singleton($command, function ($app) { 249 | return new Addons\Commands\AddonStatusCommand($app); 250 | }); 251 | } 252 | 253 | /** 254 | * Register the command. 255 | * 256 | * @param string $command 257 | * @return void 258 | */ 259 | protected function registerAddonNameCommand($command) 260 | { 261 | $this->app->singleton($command, function ($app) { 262 | return new Addons\Commands\AddonNameCommand($app); 263 | }); 264 | } 265 | 266 | /** 267 | * Register the command. 268 | * 269 | * @param string $command 270 | * @return void 271 | */ 272 | protected function registerAddonRemoveCommand($command) 273 | { 274 | $this->app->singleton($command, function ($app) { 275 | return new Addons\Commands\AddonRemoveCommand($app); 276 | }); 277 | } 278 | 279 | /** 280 | * Register the command. 281 | * 282 | * @param string $command 283 | * @return void 284 | */ 285 | protected function registerDatabaseStatusCommand($command) 286 | { 287 | $this->app->singleton($command, function ($app) { 288 | return new Database\Commands\DatabaseStatusCommand($app); 289 | }); 290 | } 291 | 292 | /** 293 | * Register the command. 294 | * 295 | * @param string $command 296 | * @return void 297 | */ 298 | protected function registerDatabaseUpgradeCommand($command) 299 | { 300 | $this->app->singleton($command, function ($app) { 301 | return new Database\Commands\DatabaseUpgradeCommand($app); 302 | }); 303 | } 304 | 305 | /** 306 | * Register the command. 307 | * 308 | * @param string $command 309 | * @return void 310 | */ 311 | protected function registerDatabaseCleanCommand($command) 312 | { 313 | $this->app->singleton($command, function ($app) { 314 | return new Database\Commands\DatabaseCleanCommand($app); 315 | }); 316 | } 317 | 318 | /** 319 | * Register the command. 320 | * 321 | * @param string $command 322 | * @return void 323 | */ 324 | protected function registerDatabaseRefreshCommand($command) 325 | { 326 | $this->app->singleton($command, function ($app) { 327 | return new Database\Commands\DatabaseRefreshCommand($app); 328 | }); 329 | } 330 | 331 | /** 332 | * Register the command. 333 | * 334 | * @param string $command 335 | * @return void 336 | */ 337 | protected function registerDatabaseRollbackCommand($command) 338 | { 339 | $this->app->singleton($command, function ($app) { 340 | return new Database\Commands\DatabaseRollbackCommand($app); 341 | }); 342 | } 343 | 344 | /** 345 | * Register the command. 346 | * 347 | * @param string $command 348 | * @return void 349 | */ 350 | protected function registerDatabaseAgainCommand($command) 351 | { 352 | $this->app->singleton($command, function ($app) { 353 | return new Database\Commands\DatabaseAgainCommand($app); 354 | }); 355 | } 356 | 357 | /** 358 | * Register the command. 359 | * 360 | * @param string $command 361 | * @return void 362 | */ 363 | protected function registerDatabaseSeedCommand($command) 364 | { 365 | $this->app->singleton($command, function ($app) { 366 | return new Database\Commands\DatabaseSeedCommand($app); 367 | }); 368 | } 369 | 370 | /** 371 | * Register the command. 372 | * 373 | * @param string $command 374 | * @return void 375 | */ 376 | protected function registerHashMakeCommand($command) 377 | { 378 | $this->app->singleton($command, function ($app) { 379 | return new Commands\HashMakeCommand($app); 380 | }); 381 | } 382 | 383 | /** 384 | * Register the command. 385 | * 386 | * @param string $command 387 | * @return void 388 | */ 389 | protected function registerHashCheckCommand($command) 390 | { 391 | $this->app->singleton($command, function ($app) { 392 | return new Commands\HashCheckCommand($app); 393 | }); 394 | } 395 | 396 | /** 397 | * Register the command. 398 | * 399 | * @param string $command 400 | * @return void 401 | */ 402 | protected function registerMakeAddonCommand($command) 403 | { 404 | $this->app->singleton($command, function ($app) { 405 | return new Addons\Commands\AddonMakeCommand($app); 406 | }); 407 | } 408 | 409 | /** 410 | * Register the command. 411 | * 412 | * @param string $command 413 | * @return void 414 | */ 415 | protected function registerMakeCommandCommand($command) 416 | { 417 | $this->app->singleton($command, function ($app) { 418 | return new Generators\Commands\CommandMakeCommand($app); 419 | }); 420 | } 421 | 422 | /** 423 | * Register the command. 424 | * 425 | * @param string $command 426 | * @return void 427 | */ 428 | protected function registerMakeControllerCommand($command) 429 | { 430 | $this->app->singleton($command, function ($app) { 431 | return new Generators\Commands\ControllerMakeCommand($app); 432 | }); 433 | } 434 | 435 | /** 436 | * Register the command. 437 | * 438 | * @param string $command 439 | * @return void 440 | */ 441 | protected function registerMakeEventCommand($command) 442 | { 443 | $this->app->singleton($command, function ($app) { 444 | return new Generators\Commands\EventMakeCommand($app); 445 | }); 446 | } 447 | 448 | /** 449 | * Register the command. 450 | * 451 | * @param string $command 452 | * @return void 453 | */ 454 | protected function registerMakeJobCommand($command) 455 | { 456 | $this->app->singleton($command, function ($app) { 457 | return new Generators\Commands\JobMakeCommand($app); 458 | }); 459 | } 460 | 461 | /** 462 | * Register the command. 463 | * 464 | * @param string $command 465 | * @return void 466 | */ 467 | protected function registerMakeListenerCommand($command) 468 | { 469 | $this->app->singleton($command, function ($app) { 470 | return new Generators\Commands\ListenerMakeCommand($app); 471 | }); 472 | } 473 | 474 | /** 475 | * Register the command. 476 | * 477 | * @param string $command 478 | * @return void 479 | */ 480 | protected function registerMakeMailCommand($command) 481 | { 482 | $this->app->singleton($command, function ($app) { 483 | return new Generators\Commands\MailMakeCommand($app); 484 | }); 485 | } 486 | 487 | 488 | /** 489 | * Register the command. 490 | * 491 | * @param string $command 492 | * @return void 493 | */ 494 | protected function registerMakeMiddlewareCommand($command) 495 | { 496 | $this->app->singleton($command, function ($app) { 497 | return new Generators\Commands\MiddlewareMakeCommand($app); 498 | }); 499 | } 500 | 501 | /** 502 | * Register the command. 503 | * 504 | * @param string $command 505 | * @return void 506 | */ 507 | protected function registerMakeMigrationCommand($command) 508 | { 509 | $this->app->singleton($command, function ($app) { 510 | return new Database\Commands\MigrationMakeCommand($app); 511 | }); 512 | } 513 | 514 | /** 515 | * Register the command. 516 | * 517 | * @param string $command 518 | * @return void 519 | */ 520 | protected function registerMakeModelCommand($command) 521 | { 522 | $this->app->singleton($command, function ($app) { 523 | return new Generators\Commands\ModelMakeCommand($app); 524 | }); 525 | } 526 | 527 | /** 528 | * Register the command. 529 | * 530 | * @param string $command 531 | * @return void 532 | */ 533 | protected function registerMakeNotificationCommand($command) 534 | { 535 | $this->app->singleton($command, function ($app) { 536 | return new Generators\Commands\NotificationMakeCommand($app); 537 | }); 538 | } 539 | 540 | /** 541 | * Register the command. 542 | * 543 | * @param string $command 544 | * @return void 545 | */ 546 | protected function registerMakePolicyCommand($command) 547 | { 548 | $this->app->singleton($command, function ($app) { 549 | return new Generators\Commands\PolicyMakeCommand($app); 550 | }); 551 | } 552 | 553 | /** 554 | * Register the command. 555 | * 556 | * @param string $command 557 | * @return void 558 | */ 559 | protected function registerMakeProviderCommand($command) 560 | { 561 | $this->app->singleton($command, function ($app) { 562 | return new Generators\Commands\ProviderMakeCommand($app); 563 | }); 564 | } 565 | 566 | /** 567 | * Register the command. 568 | * 569 | * @param string $command 570 | * @return void 571 | */ 572 | protected function registerMakeRequestCommand($command) 573 | { 574 | $this->app->singleton($command, function ($app) { 575 | return new Generators\Commands\RequestMakeCommand($app); 576 | }); 577 | } 578 | 579 | /** 580 | * Register the command. 581 | * 582 | * @param string $command 583 | * @return void 584 | */ 585 | protected function registerMakeResourceCommand($command) 586 | { 587 | $this->app->singleton($command, function ($app) { 588 | return new Generators\Commands\ResourceMakeCommand($app); 589 | }); 590 | } 591 | 592 | /** 593 | * Register the command. 594 | * 595 | * @param string $command 596 | * @return void 597 | */ 598 | protected function registerMakeRuleCommand($command) 599 | { 600 | $this->app->singleton($command, function ($app) { 601 | return new Generators\Commands\RuleMakeCommand($app); 602 | }); 603 | } 604 | 605 | /** 606 | * Register the command. 607 | * 608 | * @param string $command 609 | * @return void 610 | */ 611 | protected function registerMakeSeederCommand($command) 612 | { 613 | $this->app->singleton($command, function ($app) { 614 | return new Database\Commands\SeederMakeCommand($app); 615 | }); 616 | } 617 | 618 | /** 619 | * Register the command. 620 | * 621 | * @param string $command 622 | * @return void 623 | */ 624 | protected function registerMakeTestCommand($command) 625 | { 626 | $this->app->singleton($command, function ($app) { 627 | return new Generators\Commands\TestMakeCommand($app); 628 | }); 629 | } 630 | } 631 | -------------------------------------------------------------------------------- /sources/Providers/ExtensionServiceProvider.php: -------------------------------------------------------------------------------- 1 | app; 39 | 40 | // register spec path for app 41 | $app['path.specs'] = $app->basePath().'/resources/specs'; 42 | 43 | // register spec repository 44 | $app->singleton('specs', function ($app) { 45 | $loader = new Repository\FileLoader($app['files'], $app['path.specs']); 46 | 47 | return new Repository\NamespacedRepository($loader); 48 | }); 49 | 50 | // register addon environment 51 | $app->instance('addon', $this->addonEnvironment = new AddonEnvironment($app)); 52 | $app->alias('addon', AddonEnvironment::class); 53 | 54 | // register addon generator 55 | $app->singleton('addon.generator', function ($app) { 56 | return new AddonGenerator(); 57 | }); 58 | $app->alias('addon.generator', AddonGenerator::class); 59 | 60 | // register database migrator 61 | $app->singleton('database.migrator', function ($app) { 62 | return new Migrator($app['db'], $app['config']); 63 | }); 64 | $app->alias('database.migrator', Migrator::class); 65 | 66 | $app['events']->fire(new AddonWorldCreated($this->addonEnvironment)); 67 | 68 | $this->registerClassResolvers(); 69 | 70 | (new AddonRegistrar)->register($app, $this->addonEnvironment->addons()); 71 | 72 | $app['events']->fire(new AddonRegistered($this->addonEnvironment)); 73 | } 74 | 75 | /** 76 | */ 77 | protected function registerClassResolvers() 78 | { 79 | $addons = $this->addonEnvironment->addons(); 80 | 81 | AddonClassLoader::register($this->addonEnvironment, $addons); 82 | 83 | AliasResolver::register($this->app['path'], $addons, $this->app['config']->get('app.aliases', [])); 84 | } 85 | 86 | /** 87 | * Bootstrap the application events. 88 | */ 89 | public function boot() 90 | { 91 | $app = $this->app; 92 | 93 | // 94 | $this->registerBladeExtensions(); 95 | 96 | // boot all addons 97 | (new AddonRegistrar)->boot($app, $this->addonEnvironment->addons()); 98 | 99 | $app['events']->fire(new AddonBooted($this->addonEnvironment)); 100 | } 101 | 102 | /** 103 | * register blade extensions. 104 | */ 105 | protected function registerBladeExtensions() 106 | { 107 | Blade::extend(BladeExtension::comment()); 108 | 109 | Blade::extend(BladeExtension::script()); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /sources/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | get($key, $default); 30 | } 31 | 32 | /** 33 | * @param string $namespace 34 | * 35 | * @return \LaravelPlus\Extension\Specs\Translator 36 | */ 37 | public function translator($namespace) 38 | { 39 | return new Translator(app('translator'), $namespace); 40 | } 41 | 42 | /** 43 | * @param string | \LaravelPlus\Extension\Specs\InputSpec $pathOrSpec 44 | * @param array $in 45 | * 46 | * @return \LaravelPlus\Extension\Specs\InputModel 47 | */ 48 | public function inputModel($pathOrSpec, array $in = null) 49 | { 50 | if (is_string($pathOrSpec)) { 51 | $spec = $this->make($pathOrSpec); 52 | } 53 | else { 54 | $spec = $pathOrSpec; 55 | } 56 | 57 | return new InputModel($spec, $in); 58 | } 59 | 60 | /** 61 | * @param string $id 62 | * @param string $path 63 | * 64 | * @return \LaravelPlus\Extension\Specs\FormModel 65 | */ 66 | public function formModel($id, $path) 67 | { 68 | return new FormModel($id, $this->make($path)); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /sources/Specs/FormModel.php: -------------------------------------------------------------------------------- 1 | id = $id; 39 | $this->spec = $spec; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function id() 46 | { 47 | return $this->id; 48 | } 49 | 50 | /** 51 | * @param $fieldName 52 | * 53 | * @return string 54 | */ 55 | public function fieldId($fieldName) 56 | { 57 | return $this->id.'-'.$fieldName; 58 | } 59 | 60 | /** 61 | * @param string $method 62 | * 63 | * @return array $arguments 64 | * @return mixed 65 | */ 66 | public function __call($method, $arguments) 67 | { 68 | return call_user_func_array([$this->spec, $method], $arguments); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sources/Specs/InputModel.php: -------------------------------------------------------------------------------- 1 | spec = $spec; 50 | $this->in = $in ?: $this->gatherInput(); 51 | 52 | $rules = $this->spec->rules(); 53 | if (!is_array($rules)) { 54 | throw new InvalidArgumentException("rule specs for '$path' must array."); 55 | } 56 | 57 | $ruleMessages = $this->spec->ruleMessages(); 58 | if (!is_array($ruleMessages)) { 59 | throw new InvalidArgumentException("rule translation for '$path' must array."); 60 | } 61 | 62 | $labels = $this->spec->labels(); 63 | if (!is_array($labels)) { 64 | throw new InvalidArgumentException("rule labels for '$path' must array."); 65 | } 66 | 67 | $this->validator = app('validator')->make($this->in, $rules, $ruleMessages, $labels); 68 | } 69 | 70 | /** 71 | * @return array 72 | */ 73 | protected function gatherInput() 74 | { 75 | return app('request')->only($this->spec->attributes()); 76 | } 77 | 78 | /** 79 | * @return bool 80 | */ 81 | public function passes() 82 | { 83 | return $this->validator->passes(); 84 | } 85 | 86 | /** 87 | * @return bool 88 | */ 89 | public function fails() 90 | { 91 | return $this->validator->fails(); 92 | } 93 | 94 | /** 95 | * @return \Illuminate\Support\MessageBag 96 | */ 97 | public function errors() 98 | { 99 | return $this->validator->errors(); 100 | } 101 | 102 | /** 103 | * @return \Illuminate\Validation\Validator 104 | */ 105 | public function validator() 106 | { 107 | return $this->validator; 108 | } 109 | 110 | /** 111 | * Dynamically retrieve attributes on the model. 112 | * 113 | * @param string $key 114 | * 115 | * @return mixed 116 | */ 117 | public function __get($key) 118 | { 119 | return $this->in[$key]; 120 | } 121 | 122 | /** 123 | * Dynamically set attributes on the model. 124 | * 125 | * @param string $key 126 | * @param mixed $value 127 | */ 128 | public function __set($key, $value) 129 | { 130 | $this->in[$key] = $value; 131 | } 132 | 133 | /** 134 | * @return array 135 | */ 136 | public function input() 137 | { 138 | return $this->in; 139 | } 140 | 141 | /** 142 | * Get the instance as an array. 143 | * 144 | * @return array 145 | */ 146 | public function toArray() 147 | { 148 | return $this->input(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /sources/Specs/InputSpec.php: -------------------------------------------------------------------------------- 1 | get($path); 39 | 40 | if (is_null($rules)) { 41 | throw new InvalidArgumentException("spec '$path' is not found"); 42 | } 43 | if (!is_array($rules)) { 44 | throw new InvalidArgumentException('$rules must array in path '.$path); 45 | } 46 | if (!$translator->has($path)) { 47 | throw new InvalidArgumentException("translate '$path' is not found"); 48 | } 49 | 50 | if (strpos($path, '::') !== false) { 51 | list($namespace, $path) = explode('::', $path, 2); 52 | } else { 53 | $namespace = ''; 54 | } 55 | 56 | $this->path = $path; 57 | $this->namespace = $namespace; 58 | $this->rules = $rules; 59 | $this->translator = new Translator($translator, $namespace); 60 | 61 | $this->resolveSpecReferences(); 62 | } 63 | 64 | /** 65 | * @return array 66 | */ 67 | public function attributes() 68 | { 69 | return array_keys($this->rules); 70 | } 71 | 72 | /** 73 | * @return array 74 | */ 75 | public function rules() 76 | { 77 | return $this->rules; 78 | } 79 | 80 | /** 81 | * @return array 82 | */ 83 | public function ruleMessages() 84 | { 85 | $path = $this->path.'.rules'; 86 | 87 | return $this->translator->get($path, []); 88 | } 89 | 90 | /** 91 | * @return array 92 | */ 93 | public function labels() 94 | { 95 | $path = $this->path.'.attributes'; 96 | 97 | return $this->translator->get($path, []); 98 | } 99 | 100 | /** 101 | * @return array 102 | */ 103 | public function values() 104 | { 105 | $path = $this->path.'.values'; 106 | 107 | return $this->translator->get($path, []); 108 | } 109 | 110 | /** 111 | * @param string $name 112 | * 113 | * @return bool 114 | */ 115 | public function required($name) 116 | { 117 | return $this->hasRule($this->rules[$name], 'required'); 118 | } 119 | 120 | /** 121 | * @param string $name 122 | * 123 | * @return string 124 | */ 125 | public function label($name) 126 | { 127 | $path = $this->path.'.attributes.'.$name; 128 | 129 | return $this->translator->get($path); 130 | } 131 | 132 | /** 133 | * @param string $name 134 | * 135 | * @return string 136 | */ 137 | public function helptext($name) 138 | { 139 | $path = $this->path.'.helptexts.'.$name; 140 | 141 | return $this->translator->get($path, ''); 142 | } 143 | 144 | /** 145 | * @param mixed $ruleOrRules 146 | * @param string $name 147 | * 148 | * @return bool 149 | */ 150 | protected function hasRule($ruleOrRules, $name) 151 | { 152 | if (is_string($ruleOrRules)) { 153 | return $this->hasRuleInArray(explode('|', $ruleOrRules), 'required'); 154 | } elseif (is_array($ruleOrRules)) { 155 | return $this->hasRuleInArray($ruleOrRules, 'required'); 156 | } else { 157 | return false; 158 | } 159 | } 160 | 161 | /** 162 | * @param array $rules 163 | * @param string $name 164 | * 165 | * @return bool 166 | */ 167 | private function hasRuleInArray(array $rules, $name) 168 | { 169 | foreach ($rules as $rule) { 170 | if ($rule == $name) { 171 | return true; 172 | } 173 | } 174 | 175 | return false; 176 | } 177 | 178 | /** 179 | */ 180 | private function resolveSpecReferences() 181 | { 182 | foreach ($this->rules as &$value) { 183 | if (strpos($value, '@') !== false) { 184 | list(, $key) = explode('@', $value, 2); 185 | 186 | $rule = app('specs')->get($this->fullkey('vocabulary.'.$key), null); 187 | 188 | if (empty($rule)) { 189 | throw new InvalidArgumentException('specs/vocabulary '.$key.' not found.'); 190 | } 191 | 192 | $value = $rule; 193 | } 194 | } 195 | } 196 | 197 | /** 198 | * @param string $key 199 | * 200 | * @return string 201 | */ 202 | private function fullkey($key) 203 | { 204 | return $this->namespace ? $this->namespace.'::'.$key : $key; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /sources/Specs/Translator.php: -------------------------------------------------------------------------------- 1 | translator = $translator; 26 | $this->namespace = $namespace; 27 | } 28 | 29 | /** 30 | * Determine if a translation exists. 31 | * 32 | * @param string $key 33 | * @param string $locale 34 | * @return bool 35 | */ 36 | public function has($key, $locale = null) 37 | { 38 | return $this->translator->has($this->fullkey($key)); 39 | } 40 | 41 | /** 42 | * @param string $key 43 | * @param mixed $default 44 | * 45 | * @return mixed 46 | */ 47 | public function get($key, $default = false) 48 | { 49 | $value = $this->translate($this->fullkey($key), $default); 50 | 51 | if (is_string($value)) { 52 | $value = $this->resolve($value); 53 | } elseif (is_array($value)) { 54 | foreach ($value as &$subValue) { 55 | $subValue = $this->resolve($subValue); 56 | } 57 | } 58 | 59 | return $value; 60 | } 61 | 62 | /** 63 | * @param string $string 64 | * @param string $default 65 | * 66 | * @return string 67 | */ 68 | public function resolve($string, $default = false) 69 | { 70 | if (strpos($string, '@') !== false) { 71 | list(, $key) = explode('@', $string, 2); 72 | 73 | $string = $this->translate($this->fullkey('vocabulary.'.$key), $default); 74 | } 75 | 76 | return $string; 77 | } 78 | 79 | /** 80 | * @param string $key 81 | * 82 | * @return string 83 | */ 84 | private function fullkey($key) 85 | { 86 | return $this->namespace ? $this->namespace.'::'.$key : $key; 87 | } 88 | 89 | /** 90 | * @param string $key 91 | * @param mixed $default 92 | * 93 | * @return mixed 94 | */ 95 | protected function translate($key, $default = false) 96 | { 97 | $string = $this->translator->get($key); 98 | 99 | if ($default !== false) { 100 | if ($string == $key) { 101 | return $default; 102 | } 103 | } 104 | 105 | return $string; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /sources/Templates/BladeExtension.php: -------------------------------------------------------------------------------- 1 | ', $value); 18 | }; 19 | } 20 | 21 | /** 22 | * Compile Blade script into valid PHP. 23 | * 24 | * @return \Closure 25 | */ 26 | public static function script() 27 | { 28 | return function ($value) { 29 | $pattern = sprintf('/%s((.|\s)*?)%s/', '{@', '@}'); 30 | 31 | return preg_replace($pattern, '', $value); 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sources/helpers.php: -------------------------------------------------------------------------------- 1 | make($path); 22 | } 23 | } 24 | --------------------------------------------------------------------------------