From 2bf2c58c938e6c30af893508197c5ac7d59cd5ed Mon Sep 17 00:00:00 2001 From: Artem Schander Date: Sun, 17 Nov 2019 17:07:16 +0100 Subject: [PATCH] Support for Laravel >= 5.7 --- README.md | 12 ++++++------ composer.json | 8 ++++---- src/Console/ModuleMakeCommand.php | 27 ++++++++++++++------------- src/Console/stubs/helper.stub | 4 ++-- src/Console/stubs/translation.stub | 2 +- src/ModuleServiceProvider.php | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 185b1e2..25b75aa 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Downloads](https://img.shields.io/packagist/dt/artem-schander/l5-modular.svg)](https://packagist.org/packages/artem-schander/l5-modular) [![License](https://poser.pugx.org/artem-schander/l5-modular/license)](https://opensource.org/licenses/MIT) -This package gives you the ability to use Laravel 5 with module system. +This package gives you the ability to use Laravel with module system. You can simply drop or generate modules with their own controllers, models, views, translations and a routes file into the `app/Modules` folder and go on working with them. Thanks to zyhn for the ["Modular Structure in Laravel 5" tutorial](http://ziyahanalbeniz.blogspot.com.tr/2015/03/modular-structure-in-laravel-5.html). Well explained and helped a lot. @@ -59,7 +59,7 @@ laravel-project/ │ ├── api.php │ └── web.php └── helper.php - + ``` @@ -94,21 +94,21 @@ In some cases there is a need to load different additional classes into a module F.a. If you want to add the `app/Modules/FooBar/Services/FancyService.php` to your module, you can absolutely do so. The file could then look like this: ```php -=5.4.0", - "laravel/framework": ">=5.1" + "php": ">=7.1", + "laravel/framework": ">=5.7" }, "autoload": { "psr-4": { diff --git a/src/Console/ModuleMakeCommand.php b/src/Console/ModuleMakeCommand.php index d54a76e..25b5123 100644 --- a/src/Console/ModuleMakeCommand.php +++ b/src/Console/ModuleMakeCommand.php @@ -2,6 +2,7 @@ namespace ArtemSchander\L5Modular\Console; +use Illuminate\Support\Str; use Illuminate\Console\GeneratorCommand; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; @@ -56,7 +57,7 @@ public function handle() $this->version = (int) str_replace('.', '', $app->version()); // check if module exists - if ($this->files->exists(app_path().'/Modules/'.studly_case($this->getNameInput()))) { + if ($this->files->exists(app_path().'/Modules/'.Str::studly($this->getNameInput()))) { return $this->error($this->type.' already exists!'); } @@ -82,11 +83,11 @@ public function handle() // Create WEB Routes file $this->generate('web'); - + // Create API Routes file $this->generate('api'); } - + // Create Helper file $this->generate('helper'); @@ -94,9 +95,9 @@ public function handle() if (! $this->option('no-migration')) { - // without hacky studly_case function + // without hacky Str::studly function // foo-bar results in foo-bar and not in foo_bar - $table = str_plural(snake_case(studly_case($this->getNameInput()))); + $table = Str::plural(Str::snake(Str::studly($this->getNameInput()))); $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]); } @@ -113,21 +114,21 @@ protected function generate($type) { switch ($type) { case 'controller': - $filename = studly_case($this->getNameInput()).ucfirst($type); + $filename = Str::studly($this->getNameInput()).ucfirst($type); break; case 'model': - $filename = studly_case($this->getNameInput()); + $filename = Str::studly($this->getNameInput()); break; case 'view': $filename = 'index.blade'; break; - + case 'translation': $filename = 'example'; break; - + case 'routes': $filename = 'routes'; break; @@ -141,7 +142,7 @@ protected function generate($type) $filename = 'api'; $folder = 'routes\\'; break; - + case 'helper': $filename = 'helper'; break; @@ -152,7 +153,7 @@ protected function generate($type) } $qualifyClass = method_exists($this, 'qualifyClass') ? 'qualifyClass' : 'parseName'; - $name = $this->$qualifyClass('Modules\\'.studly_case(ucfirst($this->getNameInput())).'\\'.$folder.$filename); + $name = $this->$qualifyClass('Modules\\'.Str::studly(ucfirst($this->getNameInput())).'\\'.$folder.$filename); if ($this->files->exists($path = $this->getPath($name))) { return $this->error($this->type.' already exists!'); @@ -173,7 +174,7 @@ protected function generate($type) protected function getNamespace($name) { $name = str_replace('\\routes\\', '\\', $name); - return trim(implode('\\', array_map('ucfirst', array_slice(explode('\\', studly_case($name)), 0, -1))), '\\'); + return trim(implode('\\', array_map('ucfirst', array_slice(explode('\\', Str::studly($name)), 0, -1))), '\\'); } /** @@ -198,7 +199,7 @@ protected function buildClass($name) protected function replaceName(&$stub, $name) { $stub = str_replace('DummyTitle', $name, $stub); - $stub = str_replace('DummyUCtitle', ucfirst(studly_case($name)), $stub); + $stub = str_replace('DummyUCtitle', ucfirst(Str::studly($name)), $stub); return $this; } diff --git a/src/Console/stubs/helper.stub b/src/Console/stubs/helper.stub index a9b90e3..e4c8e26 100644 --- a/src/Console/stubs/helper.stub +++ b/src/Console/stubs/helper.stub @@ -1,5 +1,5 @@ 'Welcome, this is DummyUCtitle module.' diff --git a/src/ModuleServiceProvider.php b/src/ModuleServiceProvider.php index 47683cc..f4ca738 100644 --- a/src/ModuleServiceProvider.php +++ b/src/ModuleServiceProvider.php @@ -68,7 +68,7 @@ public function register() protected function registerMakeCommand() { $this->commands('modules.make'); - + $bind_method = method_exists($this->app, 'bindShared') ? 'bindShared' : 'singleton'; $this->app->{$bind_method}('modules.make', function ($app) {