Skip to content

Commit

Permalink
Support for Laravel >= 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Schander committed Nov 17, 2019
1 parent 5cf09c4 commit 2bf2c58
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -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.
Expand Down Expand Up @@ -59,7 +59,7 @@ laravel-project/
│ ├── api.php
│ └── web.php
└── helper.php
```

<a name="usage"></a>
Expand Down Expand Up @@ -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
<?php
<?php
namespace App\Modules\FooBar\Services;

class FancyService
class FancyService
{
public static function doFancyStuff() {
return 'some output';
}
}
}

```

#### Update to 1.3.0

Since version 1.3.0 you have to follow the `upper camel case` name convention for the module folder. If you had a `Modules/foo` folder you have to rename it to `Modules/Foo`.
Since version 1.3.0 you have to follow the `upper camel case` name convention for the module folder. If you had a `Modules/foo` folder you have to rename it to `Modules/Foo`.

Also there are changes in the `app/config/modules.php` file. Now you have to return an array with the key `enable` instead of `list`.

Expand Down
8 changes: 4 additions & 4 deletions composer.json
@@ -1,19 +1,19 @@
{
"name": "artem-schander/l5-modular",
"description": "Modular pattern generator for Laravel 5",
"description": "Modular pattern generator for Laravel",
"keywords": ["laravel", "modular", "modules", "module", "structure", "pattern", "Artem", "Schander", "l5modular", "artisan", "generator"],
"homepage": "https://github.com/Artem-Schander/L5Modular",
"license": "MIT",
"version": "1.4.1",
"version": "1.4.2",
"authors": [
{
"name": "Artem Schander",
"email": "a.schander@vanameland.de"
}
],
"require": {
"php": ">=5.4.0",
"laravel/framework": ">=5.1"
"php": ">=7.1",
"laravel/framework": ">=5.7"
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 14 additions & 13 deletions src/Console/ModuleMakeCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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!');
}

Expand All @@ -82,21 +83,21 @@ public function handle()

// Create WEB Routes file
$this->generate('web');

// Create API Routes file
$this->generate('api');
}

// Create Helper file
$this->generate('helper');



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]);
}

Expand All @@ -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;
Expand All @@ -141,7 +142,7 @@ protected function generate($type)
$filename = 'api';
$folder = 'routes\\';
break;

case 'helper':
$filename = 'helper';
break;
Expand All @@ -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!');
Expand All @@ -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))), '\\');
}

/**
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/stubs/helper.stub
@@ -1,5 +1,5 @@
<?php

/**
* DummyUCtitle Helper
*/
* DummyUCtitle Helper
*/
2 changes: 1 addition & 1 deletion src/Console/stubs/translation.stub
@@ -1,4 +1,4 @@
<?php
<?php

return [
'welcome' => 'Welcome, this is DummyUCtitle module.'
Expand Down
2 changes: 1 addition & 1 deletion src/ModuleServiceProvider.php
Expand Up @@ -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) {
Expand Down

0 comments on commit 2bf2c58

Please sign in to comment.