From e386eec0c68437a5d0457848961139ce770ff08d Mon Sep 17 00:00:00 2001 From: Gravitano Date: Thu, 4 Jun 2015 16:20:40 +0700 Subject: [PATCH 01/36] use develop version --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9e886d1..0745134 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=5.4.0", - "laravel/framework": "5.0.*", - "pingpong/generators": "~2.0", - "pingpong/support": "~2.0", + "laravel/framework": "5.1.*@dev", + "pingpong/generators": "2.1.*@dev", + "pingpong/support": "2.1.*@dev", "laravelcollective/html": "~5.0" }, "require-dev": { From ed8291dfd6863fcd135e3c31cbb76195c741abe1 Mon Sep 17 00:00:00 2001 From: Gravitano Date: Thu, 4 Jun 2015 21:02:33 +0700 Subject: [PATCH 02/36] remove branch aliases --- composer.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.json b/composer.json index 0745134..82832d0 100644 --- a/composer.json +++ b/composer.json @@ -36,11 +36,5 @@ "Tests\\": "tests" } }, - "extra": { - "branch-alias": { - "dev-master": "1.2-dev", - "dev-develop": "1.3-dev" - } - }, "minimum-stability": "stable" } From 377676ee772d0658666fd06cce12709e3e615388 Mon Sep 17 00:00:00 2001 From: Gravitano Date: Sun, 14 Jun 2015 21:30:44 +0700 Subject: [PATCH 03/36] upgrade to laravel 5.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 746348e..e3843b7 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.4.0", - "laravel/framework": "5.1.*@dev", + "laravel/framework": "5.1.*", "pingpong/generators": "2.1.*@dev", "pingpong/support": "2.1.*@dev", "laravelcollective/html": "~5.0" From 9eceef2cec39f94236dfcaca8aa84f0297e1830b Mon Sep 17 00:00:00 2001 From: Gravitano Date: Thu, 18 Jun 2015 23:06:31 +0700 Subject: [PATCH 04/36] change custom exception class with global exception class. ref: #177 --- Commands/MigrationCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Commands/MigrationCommand.php b/Commands/MigrationCommand.php index a2904e7..2115b73 100644 --- a/Commands/MigrationCommand.php +++ b/Commands/MigrationCommand.php @@ -3,7 +3,6 @@ namespace Pingpong\Modules\Commands; use Illuminate\Support\Str; -use Pingpong\Generators\Exceptions\InvalidMigrationNameException; use Pingpong\Generators\Migrations\NameParser; use Pingpong\Generators\Migrations\SchemaParser; use Pingpong\Support\Stub; @@ -102,7 +101,7 @@ protected function getTemplateContents() ]); } - throw new InvalidMigrationNameException(); + throw new \InvalidArgumentException('Invalid migration name'); } /** From b46f7a58e822a97f3d6a59da83c3ba314f1b1381 Mon Sep 17 00:00:00 2001 From: Gravitano Date: Sat, 27 Jun 2015 23:39:03 +0700 Subject: [PATCH 05/36] remove FileMissingException class --- Exceptions/FileMissingException.php | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Exceptions/FileMissingException.php diff --git a/Exceptions/FileMissingException.php b/Exceptions/FileMissingException.php deleted file mode 100644 index a1df395..0000000 --- a/Exceptions/FileMissingException.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Sun, 28 Jun 2015 00:17:44 +0700 Subject: [PATCH 06/36] require stable version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e3843b7..972f7fb 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "require": { "php": ">=5.4.0", "laravel/framework": "5.1.*", - "pingpong/generators": "2.1.*@dev", - "pingpong/support": "2.1.*@dev", + "pingpong/generators": "2.1.*", + "pingpong/support": "2.1.*", "laravelcollective/html": "~5.0" }, "require-dev": { From 00c8d86611d5442d49aa2e06ecd5084a1c2d9b6b Mon Sep 17 00:00:00 2001 From: Gravitano Date: Tue, 30 Jun 2015 15:35:01 +0700 Subject: [PATCH 07/36] update module's view path --- Commands/stubs/scaffold/provider.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 83f845a..4e001f8 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -55,7 +55,7 @@ class $CLASS$ extends ServiceProvider { */ public function registerViews() { - $viewPath = base_path('views/modules/$LOWER_NAME$'); + $viewPath = base_path('resources/views/modules/$LOWER_NAME$'); $sourcePath = __DIR__.'/../Resources/views'; From 0649359bb1de09900e467f4db071241846f86ea2 Mon Sep 17 00:00:00 2001 From: Marco Tisi Date: Thu, 23 Jul 2015 16:55:40 +0200 Subject: [PATCH 08/36] Bugfix: When installing a package via git, the process Installer checked out master branch on the project root instead of the modules root. --- Process/Installer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Process/Installer.php b/Process/Installer.php index bd44145..e1b6706 100644 --- a/Process/Installer.php +++ b/Process/Installer.php @@ -248,10 +248,11 @@ public function getPackageName() public function installViaGit() { return new Process(sprintf( - 'cd %s && git clone %s %s && git checkout %s', + 'cd %s && git clone %s %s && cd %s && git checkout %s', base_path(), $this->getRepoUrl(), $this->getDestinationPath(), + $this->getDestinationPath(), $this->getBranch() )); } From f6dc01f2261655dceff4dd6ea7768cede5f7838d Mon Sep 17 00:00:00 2001 From: Syahril Zulkefli Date: Mon, 17 Aug 2015 18:39:22 +0800 Subject: [PATCH 09/36] Added publishing group tag for config file Added publishing file group tag for config file so we can use php artisan vendor:publish --tag=config --- ModulesServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ModulesServiceProvider.php b/ModulesServiceProvider.php index 0763b82..592f8e0 100644 --- a/ModulesServiceProvider.php +++ b/ModulesServiceProvider.php @@ -64,7 +64,9 @@ protected function registerNamespaces() { $configPath = __DIR__.'/src/config/config.php'; $this->mergeConfigFrom($configPath, 'modules'); - $this->publishes([$configPath => config_path('modules.php')]); + $this->publishes([ + $configPath => config_path('modules.php') + ], 'config'); } /** From 4b74850d6fc5eeab644d54ff273d32a87c0356ac Mon Sep 17 00:00:00 2001 From: Marcus Reinhardt Date: Thu, 20 Aug 2015 16:44:21 +0200 Subject: [PATCH 10/36] fixed missing stub replacements --- Commands/ControllerCommand.php | 16 ++++++++++------ Commands/GenerateFilterCommand.php | 9 +++++++-- Commands/GenerateProviderCommand.php | 10 +++++++--- Commands/GenerateRouteProviderCommand.php | 12 +++++++++--- Commands/MakeRequestCommand.php | 12 +++++++----- Commands/ModelCommand.php | 14 ++++++++------ Commands/SeedMakeCommand.php | 1 + 7 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Commands/ControllerCommand.php b/Commands/ControllerCommand.php index 1b958f8..6e2b0c5 100644 --- a/Commands/ControllerCommand.php +++ b/Commands/ControllerCommand.php @@ -53,12 +53,16 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/controller.stub', [ - 'MODULENAME' => $module->getStudlyName(), - 'CONTROLLERNAME' => $this->getControllerName(), - 'CLASS' => $this->getClass(), - 'NAMESPACE' => $module->getLowername(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'MODULENAME' => $module->getStudlyName(), + 'CONTROLLERNAME' => $this->getControllerName(), + 'NAMESPACE' => $module->getLowername(), + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/GenerateFilterCommand.php b/Commands/GenerateFilterCommand.php index 0239e51..bc2c990 100644 --- a/Commands/GenerateFilterCommand.php +++ b/Commands/GenerateFilterCommand.php @@ -53,8 +53,13 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/filter.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getFileName(), + 'STUDLY_NAME' => $this->getFileName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/GenerateProviderCommand.php b/Commands/GenerateProviderCommand.php index f1fb2d8..976df64 100644 --- a/Commands/GenerateProviderCommand.php +++ b/Commands/GenerateProviderCommand.php @@ -68,9 +68,13 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/'.$stub.'.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), - 'LOWER_NAME' => $module->getLowerName(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getFileName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/GenerateRouteProviderCommand.php b/Commands/GenerateRouteProviderCommand.php index 43c47b6..04bc1ba 100644 --- a/Commands/GenerateRouteProviderCommand.php +++ b/Commands/GenerateRouteProviderCommand.php @@ -43,10 +43,16 @@ protected function getArguments() */ protected function getTemplateContents() { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + return (new Stub('/route-provider.stub', [ - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getFileName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getFileName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/MakeRequestCommand.php b/Commands/MakeRequestCommand.php index 4da7609..82bec02 100644 --- a/Commands/MakeRequestCommand.php +++ b/Commands/MakeRequestCommand.php @@ -53,11 +53,13 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/request.stub', [ - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getFileName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getFileName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/ModelCommand.php b/Commands/ModelCommand.php index 81ed01d..0a9cf14 100644 --- a/Commands/ModelCommand.php +++ b/Commands/ModelCommand.php @@ -66,12 +66,14 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/model.stub', [ - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getModelName(), - 'FILLABLE' => $this->getFillable(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'NAME' => $this->getModelName(), + 'FILLABLE' => $this->getFillable(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/SeedMakeCommand.php b/Commands/SeedMakeCommand.php index 83414ae..88bc825 100644 --- a/Commands/SeedMakeCommand.php +++ b/Commands/SeedMakeCommand.php @@ -65,6 +65,7 @@ protected function getTemplateContents() 'NAME' => $this->getSeederName(), 'MODULE' => $this->getModuleName(), 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + ]))->render(); } From 8218796db8de0e680ba02720071fc8120775b455 Mon Sep 17 00:00:00 2001 From: Serhii Kyrychenko Date: Wed, 9 Sep 2015 18:38:41 +0200 Subject: [PATCH 11/36] Updated stub to use all the paths of view finder When some extension already extended \Illuminate\View\FileViewFinder with additional view paths, we need to consider all of them. Example: https://github.com/igaster/laravel-theme Here paths will be like resources//views, resources/views - we need to check modules template files in all of them (according to themes fallback). So, in our case it will become resources//views/module/ and resources/views/module/ (last one is the same as `$viewPath` variable. Why not publishes themes templates? IMO, modules should not be supplied with strange themes, unless it is module bringing specific theme, but in this case this module provider could do publish by itself. Thanks --- Commands/stubs/scaffold/provider.stub | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 83f845a..8c192fd 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -63,7 +63,9 @@ class $CLASS$ extends ServiceProvider { $sourcePath => $viewPath ]); - $this->loadViewsFrom([$viewPath, $sourcePath], '$LOWER_NAME$'); + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/$LOWER_NAME$'; + }, app('view.finder')->getPaths()), [$sourcePath]), '$LOWER_NAME$'); } /** From fbb16d29c7d09b5c0abcc89c6844f457bc05890b Mon Sep 17 00:00:00 2001 From: Serhii Kyrychenko Date: Thu, 10 Sep 2015 15:22:18 +0200 Subject: [PATCH 12/36] Fixed view paths to be get from config --- Commands/stubs/scaffold/provider.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 8c192fd..5460638 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -65,7 +65,7 @@ class $CLASS$ extends ServiceProvider { $this->loadViewsFrom(array_merge(array_map(function ($path) { return $path . '/modules/$LOWER_NAME$'; - }, app('view.finder')->getPaths()), [$sourcePath]), '$LOWER_NAME$'); + }, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$'); } /** From a90f915e48d3742fda7e89914a9934874809b528 Mon Sep 17 00:00:00 2001 From: vagrant Date: Fri, 23 Oct 2015 10:15:59 +0000 Subject: [PATCH 13/36] fix command module:migrate-rollback to run modules in reverse order --- Commands/MigrateRollbackCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/MigrateRollbackCommand.php b/Commands/MigrateRollbackCommand.php index 07a7208..f26bf7e 100644 --- a/Commands/MigrateRollbackCommand.php +++ b/Commands/MigrateRollbackCommand.php @@ -41,7 +41,7 @@ public function fire() return; } - foreach ($this->laravel['modules']->all() as $module) { + foreach (array_reverse($this->laravel['modules']->all()) as $module) { $this->line('Running for module: '.$module->getName().''); $this->rollback($module); From e990804bb903ba4c04196e3eafe50b599ffbbe6a Mon Sep 17 00:00:00 2001 From: Kallef Alexandre de Souza Date: Tue, 27 Oct 2015 13:10:01 -0200 Subject: [PATCH 14/36] Order boot provider, supports the lang module Ordering boot provider, now config module supports the languages module. --- Commands/stubs/scaffold/provider.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 83f845a..e040038 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -18,8 +18,8 @@ class $CLASS$ extends ServiceProvider { */ public function boot() { - $this->registerConfig(); $this->registerTranslations(); + $this->registerConfig(); $this->registerViews(); } From 0c5ca60d89fe9dc0154cfcca954a3d22a5e9ab43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20K=C3=A9sede?= Date: Wed, 4 Nov 2015 01:34:30 -0300 Subject: [PATCH 15/36] Added --all option to module:seed --- Commands/SeedCommand.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index a2f1168..0c9e787 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -35,20 +35,31 @@ public function fire() { $this->module = $this->laravel['modules']; - $module = Str::studly($this->argument('module')) ?: $this->getModuleName(); + if ($this->argument('module')) { + $modules = $this->argument('module'); + } + elseif ($this->option('all')) { + $modules = $this->module->all(); + } + else { + try { + $modules = $this->getModuleName(); + } catch (\Exception $e) { + return $this->info("Use module:use to select which module you want to migrate."); + } + } - if ($module) { - if ($this->module->has($module)) { - $this->dbseed($module); + foreach ((array) $modules as $module) { + $name = $module instanceof Module ? Str::studly($module->getName()) : Str::studly($module); - return $this->info("Module [$module] seeded."); + if (! $this->module->has($name)) { + $this->error("Module [$module] does not exists."); + continue; } - return $this->error("Module [$module] does not exists."); - } - - foreach ($this->module->all() as $name) { $this->dbseed($name); + + $this->info("Module [$module] seeded."); } return $this->info('All modules seeded.'); @@ -111,7 +122,8 @@ protected function getOptions() { return array( array('class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', null), + array('all', null, InputOption::VALUE_NONE, 'Whether or not we should seed all modules.'), array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'), ); } -} +} \ No newline at end of file From 0cd498649a79246d93b0b1c4ec5654a3508b2608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20K=C3=A9sede?= Date: Wed, 4 Nov 2015 01:51:07 -0300 Subject: [PATCH 16/36] Fix the module without seed class issue --- Commands/SeedCommand.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index 0c9e787..66722b7 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -57,9 +57,11 @@ public function fire() continue; } - $this->dbseed($name); + if (class_exists($this->getSeederName($name))) { + $this->dbseed($name); - $this->info("Module [$module] seeded."); + $this->info("Module [$module] seeded."); + } } return $this->info('All modules seeded.'); @@ -98,7 +100,7 @@ public function getSeederName($name) $namespace = $this->laravel['modules']->config('namespace'); - return $namespace.'\\'.$name.'\Database\Seeders\\'.$name.'DatabaseSeeder'; + return $namespace.'\\'.$name.'\Database\Seeders\\'.$name.'TableSeeder'; } /** From 58df48a19ec637565907176f66a6eda1bff8d2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20K=C3=A9sede?= Date: Wed, 4 Nov 2015 02:15:04 -0300 Subject: [PATCH 17/36] Remove -all option and remove user module option --- Commands/SeedCommand.php | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index 66722b7..2c6edd6 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -35,32 +35,30 @@ public function fire() { $this->module = $this->laravel['modules']; - if ($this->argument('module')) { - $modules = $this->argument('module'); - } - elseif ($this->option('all')) { - $modules = $this->module->all(); - } - else { - try { - $modules = $this->getModuleName(); - } catch (\Exception $e) { - return $this->info("Use module:use to select which module you want to migrate."); + $name = $this->argument('module'); + + if ($name) { + if (!$this->module->has($name)) { + return $this->error("Module [$name] does not exists."); } - } - foreach ((array) $modules as $module) { - $name = $module instanceof Module ? Str::studly($module->getName()) : Str::studly($module); + $class = $this->getSeederName($name); + if (class_exists($class)) { + $this->dbseed($name); - if (! $this->module->has($name)) { - $this->error("Module [$module] does not exists."); - continue; + return $this->info("Module [$name] seeded."); + } else { + return $this->error("Class [$class] does not exists."); } + } + + foreach ($this->module->getOrdered() as $module) { + $name = $module->getName(); if (class_exists($this->getSeederName($name))) { $this->dbseed($name); - $this->info("Module [$module] seeded."); + $this->info("Module [$name] seeded."); } } From cc2b4bdcd528f992d0ed27369f0c4b6523bf988a Mon Sep 17 00:00:00 2001 From: Gravitano Date: Fri, 6 Nov 2015 13:53:58 +0700 Subject: [PATCH 18/36] CS fixes --- Commands/GenerateProviderCommand.php | 2 +- Commands/SeedCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Commands/GenerateProviderCommand.php b/Commands/GenerateProviderCommand.php index 976df64..592a7e6 100644 --- a/Commands/GenerateProviderCommand.php +++ b/Commands/GenerateProviderCommand.php @@ -74,7 +74,7 @@ protected function getTemplateContents() 'MODULE' => $this->getModuleName(), 'NAME' => $this->getFileName(), 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index 2c6edd6..255919d 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -126,4 +126,4 @@ protected function getOptions() array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'), ); } -} \ No newline at end of file +} From 159768961bea5f9034309ef510cc64cd60596b83 Mon Sep 17 00:00:00 2001 From: Felipe Fontana Date: Mon, 16 Nov 2015 17:54:15 -0300 Subject: [PATCH 19/36] Fix namespace path of Controller he create wrong path to controller namespace --- Commands/ControllerCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/ControllerCommand.php b/Commands/ControllerCommand.php index 6e2b0c5..4ad68f4 100644 --- a/Commands/ControllerCommand.php +++ b/Commands/ControllerCommand.php @@ -55,7 +55,7 @@ protected function getTemplateContents() return (new Stub('/controller.stub', [ 'MODULENAME' => $module->getStudlyName(), 'CONTROLLERNAME' => $this->getControllerName(), - 'NAMESPACE' => $module->getLowername(), + 'NAMESPACE' => $module->getStudlyName(), 'CLASS_NAMESPACE' => $this->getClassNamespace($module), 'CLASS' => $this->getClass(), 'LOWER_NAME' => $module->getLowerName(), From 396d5e99e0c7ddefd6333b1232b3a0dd43da6d97 Mon Sep 17 00:00:00 2001 From: Mahmut Bayri Date: Mon, 23 Nov 2015 08:12:41 +0200 Subject: [PATCH 20/36] Fix caching problem. --- Repository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Repository.php b/Repository.php index c3f69de..0302287 100644 --- a/Repository.php +++ b/Repository.php @@ -160,7 +160,9 @@ protected function formatCached($cached) foreach ($cached as $name => $module) { $path = $this->config('paths.modules').'/'.$name; - $modules[] = new Module($this->app, $name, $path); + $lowerName = strtolower($name); + + $modules[$name] = new Module($this->app, $lowerName, $path); } return $modules; From 22d1bc629630c0fa75343e72e2f957dfa5f32dae Mon Sep 17 00:00:00 2001 From: Mahmut Bayri Date: Mon, 30 Nov 2015 14:42:14 +0200 Subject: [PATCH 21/36] Fix getting dependencies from composer.json file with module:update command. Otherwise module:update looks at module.json for its own dependencies. --- Module.php | 21 +++++++++++++++++++-- Process/Updater.php | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Module.php b/Module.php index 476ec9b..cb9d88a 100644 --- a/Module.php +++ b/Module.php @@ -169,9 +169,13 @@ protected function registerTranslation() * * @return Json */ - public function json() + public function json($file = null) { - return new Json($this->getPath().'/module.json', $this->app['files']); + if (is_null($file)) { + $file = 'module.json'; + } + + return new Json($this->getPath() . '/' . $file, $this->app['files']); } /** @@ -187,6 +191,19 @@ public function get($key, $default = null) return $this->json()->get($key, $default); } + /** + * Get a specific data from composer.json file by given the key. + * + * @param $key + * @param null $default + * + * @return mixed + */ + public function getComposerAttr($key, $default = null) + { + return $this->json('composer.json')->get($key, $default); + } + /** * Register the module. */ diff --git a/Process/Updater.php b/Process/Updater.php index 5ba314d..1e8f290 100644 --- a/Process/Updater.php +++ b/Process/Updater.php @@ -13,7 +13,7 @@ public function update($module) { $module = $this->module->findOrFail($module); - $packages = $module->get('require', []); + $packages = $module->getComposerAttr('require', []); chdir(base_path()); From 073f43f027a3ea762e6522a3cad37d1bdf3e8c7a Mon Sep 17 00:00:00 2001 From: Gravitano Date: Wed, 23 Dec 2015 13:22:51 +0700 Subject: [PATCH 22/36] reverse array --- Commands/MigrateResetCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/MigrateResetCommand.php b/Commands/MigrateResetCommand.php index 88da875..4fe07e7 100644 --- a/Commands/MigrateResetCommand.php +++ b/Commands/MigrateResetCommand.php @@ -41,7 +41,7 @@ public function fire() return; } - foreach ($this->laravel['modules']->all() as $module) { + foreach (array_reverse($this->laravel['modules']->all()) as $module) { $this->line('Running for module: '.$module->getName().''); $this->reset($module); From 8895b24fef1c9c33681c89e3e4ee7035a17d651b Mon Sep 17 00:00:00 2001 From: Gravitano Date: Wed, 23 Dec 2015 14:02:49 +0700 Subject: [PATCH 23/36] upgrade requirements for support laravel 5.2 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 972f7fb..a0c5c12 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=5.4.0", - "laravel/framework": "5.1.*", - "pingpong/generators": "2.1.*", - "pingpong/support": "2.1.*", + "laravel/framework": "5.2.*", + "pingpong/generators": "2.2.*@dev", + "pingpong/support": "2.2.*@dev", "laravelcollective/html": "~5.0" }, "require-dev": { From fbed30d478a41e1599eb740d6d17ce09924bef1e Mon Sep 17 00:00:00 2001 From: Marcin Ceran Date: Wed, 23 Dec 2015 10:58:07 +0100 Subject: [PATCH 24/36] Fixing deprecated method bindShared Switched to singleton --- ModulesServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModulesServiceProvider.php b/ModulesServiceProvider.php index 592f8e0..1df90ce 100644 --- a/ModulesServiceProvider.php +++ b/ModulesServiceProvider.php @@ -90,7 +90,7 @@ protected function registerHtml() */ protected function registerServices() { - $this->app->bindShared('modules', function ($app) { + $this->app->singleton('modules', function ($app) { $path = $app['config']->get('modules.paths.modules'); return new Repository($app, $path); From 575d9f6f049676f93a8899ac901f12a960225439 Mon Sep 17 00:00:00 2001 From: Gravitano Date: Wed, 6 Jan 2016 16:07:41 +0700 Subject: [PATCH 25/36] use stable version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a0c5c12..a8db845 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "require": { "php": ">=5.4.0", "laravel/framework": "5.2.*", - "pingpong/generators": "2.2.*@dev", - "pingpong/support": "2.2.*@dev", + "pingpong/generators": "2.2.*", + "pingpong/support": "2.2.*", "laravelcollective/html": "~5.0" }, "require-dev": { From dd814a1d5f0d88dac71f6e847b1eaaa32e559476 Mon Sep 17 00:00:00 2001 From: Sonus Sundar Date: Fri, 8 Jan 2016 11:38:53 +0530 Subject: [PATCH 26/36] Fix for php artisan module:seed command This should call $name.'DatabaseSeeder' instead ob $name.'TableSeeder' --- Commands/SeedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index 255919d..c1f003a 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -98,7 +98,7 @@ public function getSeederName($name) $namespace = $this->laravel['modules']->config('namespace'); - return $namespace.'\\'.$name.'\Database\Seeders\\'.$name.'TableSeeder'; + return $namespace.'\\'.$name.'\Database\Seeders\\'.$name.'DatabaseSeeder'; } /** From 05186d8151fae13622277cb6303bf3ea0f8a357d Mon Sep 17 00:00:00 2001 From: Gravitano Date: Mon, 11 Jan 2016 14:06:02 +0700 Subject: [PATCH 27/36] update base controller class --- Routing/Controller.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Routing/Controller.php b/Routing/Controller.php index 9283498..c0742c8 100644 --- a/Routing/Controller.php +++ b/Routing/Controller.php @@ -2,11 +2,12 @@ namespace Pingpong\Modules\Routing; -use Illuminate\Foundation\Bus\DispatchesCommands; +use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; -abstract class Controller extends BaseController +class Controller extends BaseController { - use DispatchesCommands, ValidatesRequests; + use AuthorizesRequests, DispatchesJobs, ValidatesRequests; } From 666848947065f281ab4ae2697fe9c61016e9c10b Mon Sep 17 00:00:00 2001 From: Gravitano Date: Mon, 11 Jan 2016 14:09:40 +0700 Subject: [PATCH 28/36] fix view name --- Commands/stubs/controller.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/controller.stub b/Commands/stubs/controller.stub index 2d2352f..82dc564 100644 --- a/Commands/stubs/controller.stub +++ b/Commands/stubs/controller.stub @@ -6,7 +6,7 @@ class $CLASS$ extends Controller { public function index() { - return view('$NAMESPACE$::index'); + return view('$LOWER_NAME$::index'); } } \ No newline at end of file From c3836e23529b15312467da835099454e975005a0 Mon Sep 17 00:00:00 2001 From: Gravitano Date: Mon, 11 Jan 2016 14:10:27 +0700 Subject: [PATCH 29/36] add web middleware --- Commands/stubs/routes.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/routes.stub b/Commands/stubs/routes.stub index 7231ccf..e89b280 100644 --- a/Commands/stubs/routes.stub +++ b/Commands/stubs/routes.stub @@ -1,6 +1,6 @@ '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function() +Route::group(['middleware' => 'web', 'prefix' => '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function() { Route::get('/', '$STUDLY_NAME$Controller@index'); }); \ No newline at end of file From 6c2f0187bcf773cb083a794c06894ebba40760fe Mon Sep 17 00:00:00 2001 From: Gravitano Date: Mon, 11 Jan 2016 14:30:37 +0700 Subject: [PATCH 30/36] fix module name --- Commands/SeedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/SeedCommand.php b/Commands/SeedCommand.php index c1f003a..82ab158 100644 --- a/Commands/SeedCommand.php +++ b/Commands/SeedCommand.php @@ -38,7 +38,7 @@ public function fire() $name = $this->argument('module'); if ($name) { - if (!$this->module->has($name)) { + if (!$this->module->has(Str::studly($name))) { return $this->error("Module [$name] does not exists."); } From c9901ba65d7556053743b768939fc42aa9a7c84a Mon Sep 17 00:00:00 2001 From: Gravitano Date: Mon, 11 Jan 2016 14:46:38 +0700 Subject: [PATCH 31/36] allow to install module from github via https --- Process/Installer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Process/Installer.php b/Process/Installer.php index e1b6706..b007831 100644 --- a/Process/Installer.php +++ b/Process/Installer.php @@ -152,6 +152,7 @@ public function getProcess() { switch ($this->type) { case 'github': + case 'github-https': case 'bitbucket': if ($this->tree) { $process = $this->installViaSubtree(); @@ -194,6 +195,10 @@ public function getRepoUrl() return "git@github.com:{$this->name}.git"; break; + case 'github-https': + return "https://github.com/{$this->name}.git"; + break; + case 'bitbucket': return "git@bitbucket.org:{$this->name}.git"; break; From cefe62e256a759beb545f732f378dddc7e6a554c Mon Sep 17 00:00:00 2001 From: Phan Thanh Cong Date: Fri, 29 Jan 2016 10:34:30 +0700 Subject: [PATCH 32/36] fix wrong paths in service provider --- Commands/GenerateProviderCommand.php | 3 +++ Commands/stubs/scaffold/provider.stub | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Commands/GenerateProviderCommand.php b/Commands/GenerateProviderCommand.php index 592a7e6..a14b6b8 100644 --- a/Commands/GenerateProviderCommand.php +++ b/Commands/GenerateProviderCommand.php @@ -75,6 +75,9 @@ protected function getTemplateContents() 'NAME' => $this->getFileName(), 'STUDLY_NAME' => $module->getStudlyName(), 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'PATH_VIEWS' => $this->laravel['config']->get('modules.paths.generator.views'), + 'PATH_LANG' => $this->laravel['config']->get('modules.paths.generator.lang'), + 'PATH_CONFIG' => $this->laravel['config']->get('modules.paths.generator.config') ]))->render(); } diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 0018354..fa1ca20 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -13,7 +13,7 @@ class $CLASS$ extends ServiceProvider { /** * Boot the application events. - * + * * @return void */ public function boot() @@ -29,35 +29,35 @@ class $CLASS$ extends ServiceProvider { * @return void */ public function register() - { + { // } /** * Register config. - * + * * @return void */ protected function registerConfig() { $this->publishes([ - __DIR__.'/../Config/config.php' => config_path('$LOWER_NAME$.php'), + __DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'), ]); $this->mergeConfigFrom( - __DIR__.'/../Config/config.php', '$LOWER_NAME$' + __DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$' ); } /** * Register views. - * + * * @return void */ public function registerViews() { $viewPath = base_path('resources/views/modules/$LOWER_NAME$'); - $sourcePath = __DIR__.'/../Resources/views'; + $sourcePath = __DIR__.'/../$PATH_VIEWS$'; $this->publishes([ $sourcePath => $viewPath @@ -70,7 +70,7 @@ class $CLASS$ extends ServiceProvider { /** * Register translations. - * + * * @return void */ public function registerTranslations() @@ -80,7 +80,7 @@ class $CLASS$ extends ServiceProvider { if (is_dir($langPath)) { $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); } else { - $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', '$LOWER_NAME$'); + $this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$'); } } From f9e515a327b8e3c5cca871b239ffc6234ef5dbba Mon Sep 17 00:00:00 2001 From: Taras Ivasyshyn Date: Mon, 16 May 2016 14:03:09 +0200 Subject: [PATCH 33/36] Update index.stub --- Commands/stubs/views/index.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/stubs/views/index.stub b/Commands/stubs/views/index.stub index ade7584..589a996 100644 --- a/Commands/stubs/views/index.stub +++ b/Commands/stubs/views/index.stub @@ -8,4 +8,4 @@ This view is loaded from module: {!! config('$LOWER_NAME$.name') !!}

-@stop \ No newline at end of file +@endsection From 0622ad7cfab2d63fd56abfc3b22b9ee14798e556 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Wed, 22 Jun 2016 21:21:02 +0200 Subject: [PATCH 34/36] Allow caching of the json file --- Json.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Json.php b/Json.php index 717abc8..999b6c6 100644 --- a/Json.php +++ b/Json.php @@ -118,7 +118,13 @@ public function getContents() */ public function getAttributes() { - return json_decode($this->getContents(), 1); + if (config('modules.cache.enabled') === false) { + return json_decode($this->getContents(), 1); + } + + return app('cache')->remember($this->getPath(), config('modules.cache.lifetime'), function () { + return json_decode($this->getContents(), 1); + }); } /** From a7d164635166e9817eef3011ddd9b2da29f69e47 Mon Sep 17 00:00:00 2001 From: gravitano Date: Tue, 30 Aug 2016 11:31:32 +0700 Subject: [PATCH 35/36] upgrade to laravel 5.3 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a8db845..b76beaa 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ ], "require": { "php": ">=5.4.0", - "laravel/framework": "5.2.*", + "laravel/framework": "5.3.*", "pingpong/generators": "2.2.*", - "pingpong/support": "2.2.*", + "pingpong/support": "dev-master", "laravelcollective/html": "~5.0" }, "require-dev": { From ad25066492490af119ec17a211f3be165b676ef2 Mon Sep 17 00:00:00 2001 From: gravitano Date: Thu, 8 Sep 2016 14:24:38 +0700 Subject: [PATCH 36/36] update readme --- README.md | 612 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 610 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb00da5..70e34ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,612 @@ Laravel 5 Modules -============== +=============== -Official documentation is located [here](http://sky.pingpong-labs.com/docs/2.0/modules) \ No newline at end of file +- [Upgrade Guide](#upgrade-guide) +- [Installation](#installation) +- [Configuration](#configuration) +- [Naming Convension](#naming-convension) +- [Folder Structure](#folder-structure) +- [Creating Module](#creating-a-module) +- [Artisan Commands](#artisan-commands) +- [Facades](#facades) +- [Entity](#entity) +- [Auto Scan Vendor Directory](#auto-scan-vendor-directory) +- [Publishing Modules](#publishing-modules) + +`pingpong/modules` is a laravel package which created to manage your large laravel app using modules. Module is like a laravel package, it have some views, controllers or models. This package is supported and tested in both Laravel 4 and Laravel 5. + + +## Upgrade Guide + +#### To 2.0.18 + +If you have been updated to version `2.0.18`, please read [this release note](https://github.com/pingpong-labs/modules/releases/tag/2.0.18). + +#### To 2.0.10 + +Previously, we add two service provider from this package. In version `2.0.5`, we just need register one service provider. Now, we can remove `Pingpong\Modules\Providers\BootstrapServiceProvider` from `providers` array, because now it service provider is registered automatically by `Pingpong\Modules\ModulesServiceProvider`. + +#### From Laravel 4 to Laravel 5 + +If upgrade your Laravel app from Laravel 4 to Laravel 5, there is a few things to do if you are using this package. You will receive some kind errors about config not loaded. To fix this issue, please follow this instruction. + +- If you publish the package's configuration file, you need to move the config file from `app/config/packages/pingpong/modules/config.php` to `app/config/modules.php`. +- If you are not publish the package's configuration file and you want to publish the config file, just run `php artisan vendor:publish` command and you are done. + +#### From 1.1.* to 1.2.0 + +New configuration file. This breaking change affected if you publish the configuration file from this package. To fix this issue, create new config file called `config.php` in your `app/config/packages/pingpong/modules/` directory. Next move the array contents from `paths.php` file to `paths` array in new configuration file. +Your config file will looks like [this](https://github.com/pingpong-labs/modules/blob/1.2.0/src/config/config.php). + + +## Installation + +To install through composer, simply put the following in your composer.json file: + +```json +{ + "require": { + "pingpong/modules": "~2.1" + } +} +``` + +And then run `composer install` to fetch the package. + +#### Quick Installation + +You could also simplify the above code by using the following command: + +``` +composer require "pingpong/modules:~2.1" +``` + +#### Add Service Provider + +Next add the following service provider in `config/app.php`. + +```php +'providers' => array( + 'Pingpong\Modules\ModulesServiceProvider', +), +``` + +Next, add the following aliases to `aliases` array in the same file. + +``` +'aliases' => array( + 'Module' => 'Pingpong\Modules\Facades\Module', +), + +``` + +Next publish the package's configuration file by run : + +``` +php artisan vendor:publish +``` + +#### Autoloading + +By default controllers, entities or repositories not loaded automatically. You can autoload all that stuff using `psr-4`. For example : + +```json +{ + "autoload": { + "psr-4": { + "App\\": "app/", + "Modules\\": "modules/" + } + } +} +``` + + +## Configuration + +- `modules` - Used for save the generated modules. +- `assets` - Used for save the modules's assets from each modules. +- `migration` - Used for save the modules's migrations if you publish the modules's migrations. +- `generator` - Used for generate modules folders. +- `scan` - Used for allow to scan other folders. +- `enabled` - If `true`, the package will scan other paths. By default the value is `false` +- `paths` - The list of path which can scanned automatically by the package. +- `composer` + - `vendor` - Composer vendor name. + - `author.name` - Composer author name. + - `author.email` - Composer author email. +- `cache` + - `enabled` - If `true`, the scanned modules (all modules) will cached automatically. By default the value is `false` + - `key` - The name of cache. + - `lifetime` - Lifetime of cache. + + +## Creating A Module + +To create a new module you can simply run : + +``` +php artisan module:make +``` + +- `` - Required. The name of module will be created. + +**Create a new module** + +``` +php artisan module:make Blog +``` + +**Create multiple modules** + +``` +php artisan module:make Blog User Auth +``` + +By default if you create a new module, that will add some resources like controller, seed class or provider automatically. If you don't want these, you can add `--plain` flag, to generate a plain module. + +```shell +php artisan module:make Blog --plain +#OR +php artisan module:make Blog -p +``` + + +**Naming Convension** + +Because we are autoloading the modules using `psr-4`, we strongly recommend using `StudlyCase` convension. + + +**Folder Structure** + +``` +laravel-app/ +app/ +bootstrap/ +vendor/ +modules/ + ├── Blog/ + ├── Assets/ + ├── Config/ + ├── Console/ + ├── Database/ + ├── Migrations/ + ├── Seeders/ + ├── Entities/ + ├── Http/ + ├── Controllers/ + ├── Middleware/ + ├── Requests/ + ├── routes.php + ├── Providers/ + ├── BlogServiceProvider.php + ├── Resources/ + ├── lang/ + ├── views/ + ├── Repositories/ + ├── Tests/ + ├── composer.json + ├── module.json + ├── start.php +``` + + +## Artisan Commands + +Create new module. + +``` +php artisan module:make blog +``` + +Use the specified module. Please see [#26](https://github.com/pingpong-labs/modules/pull/26). + +```php +php artisan module:use blog +``` + +Show all modules in command line. + +``` +php artisan module:list +``` + +Create new command for the specified module. + +``` +php artisan module:make-command CustomCommand blog + +php artisan module:make-command CustomCommand --command=custom:command blog + +php artisan module:make-command CustomCommand --namespace=Modules\Blog\Commands blog +``` + +Create new migration for the specified module. + +``` +php artisan module:make-migration create_users_table blog + +php artisan module:make-migration create_users_table --fields="username:string, password:string" blog + +php artisan module:make-migration add_email_to_users_table --fields="email:string:unique" blog + +php artisan module:make-migration remove_email_from_users_table --fields="email:string:unique" blog + +php artisan module:make-migration drop_users_table blog +``` + +Rollback, Reset and Refresh The Modules Migrations. +``` +php artisan module:migrate-rollback + +php artisan module:migrate-reset + +php artisan module:migrate-refresh +``` + +Rollback, Reset and Refresh The Migrations for the specified module. +``` +php artisan module:migrate-rollback blog + +php artisan module:migrate-reset blog + +php artisan module:migrate-refresh blog +``` + +Create new seed for the specified module. + +``` +php artisan module:make-seed users blog +``` + +Migrate from the specified module. + +``` +php artisan module:migrate blog +``` + +Migrate from all modules. + +``` +php artisan module:migrate +``` + +Seed from the specified module. + +``` +php artisan module:seed blog +``` + +Seed from all modules. + +``` +php artisan module:seed +``` + +Create new controller for the specified module. + +``` +php artisan module:make-controller SiteController blog +``` + +Publish assets from the specified module to public directory. + +``` +php artisan module:publish blog +``` + +Publish assets from all modules to public directory. + +``` +php artisan module:publish +``` + +Create new model for the specified module. + +``` +php artisan module:make-model User blog + +php artisan module:make-model User blog --fillable="username,email,password" +``` + +Create new service provider for the specified module. + +``` +php artisan module:make-provider MyServiceProvider blog +``` + +Publish migration for the specified module or for all modules. +This helpful when you want to rollback the migrations. You can also run `php artisan migrate` instead of `php artisan module:migrate` command for migrate the migrations. + +For the specified module. +``` +php artisan module:publish-migration blog +``` + +For all modules. +``` +php artisan module:publish-migration +``` + +Enable the specified module. + +``` +php artisan module:enable blog +``` + +Disable the specified module. + +``` +php artisan module:disable blog +``` + +Generate new middleware class. +``` +php artisan module:make-middleware Auth +``` + +Update dependencies for the specified module. +``` +php artisan module:update ModuleName +``` + +Update dependencies for all modules. +``` +php artisan module:update +``` + +Show the list of modules. +``` +php artisan module:list +``` + + +## Facades + +Get all modules. +```php +Module::all(); +``` + +Get all cached modules. +```php +Module::getCached() +``` + +Get ordered modules. The modules will be ordered by the `priority` key in `module.json` file. +```php +Module::getOrdered(); +``` + +Get scanned modules. +```php +Module::scan(); +``` + +Find a specific module. +```php +Module::find('name'); +// OR +Module::get('name'); +``` + +Find a module, if there is one, return the `Module` instance, otherwise throw `Pingpong\Modules\Exeptions\ModuleNotFoundException`. +```php +Module::findOrFail('module-name'); +``` + +Get scanned paths. +```php +Module::getScanPaths(); +``` + +Get all modules as a collection instance. +```php +Module::toCollection(); +``` + +Get modules by the status. 1 for active and 0 for inactive. +```php +Module::getByStatus(1); +``` + +Check the specified module. If it exists, will return `true`, otherwise `false`. +```php +Module::has('blog'); +``` + +Get all enabled modules. +```php +Module::enabled(); +``` + +Get all disabled modules. +```php +Module::disabled(); +``` + +Get count of all modules. +```php +Module::count(); +``` + +Get module path. +```php +Module::getPath(); +``` + +Register the modules. +```php +Module::register(); +``` + +Boot all available modules. +```php +Module::boot(); +``` + +Get all enabled modules as collection instance. +```php +Module::collections(); +``` + +Get module path from the specified module. +```php +Module::getModulePath('name'); +``` + +Get assets path from the specified module. +```php +Module::getAssetPath('name'); +``` + +Get config value from this package. +```php +Module::config('composer.vendor'); +``` + +Get used storage path. +```php +Module::getUsedStoragePath(); +``` + +Get used module for cli session. +```php +Module::getUsedNow(); +// OR +Module::getUsed(); +``` + +Set used module for cli session. +```php +Module::setUsed('name'); +``` + +Get modules's assets path. +```php +Module::getAssetsPath(); +``` + +Get asset url from specific module. +```php +Module::asset('blog:img/logo.img'); +``` + +Install the specified module by given module name. +```php +Module::install('pingpong-modules/hello'); +``` + +Update dependencies for the specified module. +```php +Module::update('hello'); +``` + + +## Module Entity + +Get an entity from a specific module. + +```php +$module = Module::find('blog'); +``` + +Get module name. +``` +$module->getName(); +``` + +Get module name in lowercase. +``` +$module->getLowerName(); +``` + +Get module name in studlycase. +``` +$module->getStudlyName(); +``` + +Get module path. +``` +$module->getPath(); +``` + +Get extra path. +``` +$module->getExtraPath('Assets'); +``` + +Disable the specified module. +``` +$module->enable(); +``` + +Enable the specified module. +``` +$module->disable(); +``` + +Delete the specified module. +``` +$module->delete(); +``` + + +## Custom Namespaces +When you create a new module it also registers new custom namespace for `Lang`, `View` and `Config`. For example, if you create a new module named blog, it will also register new namespace/hint blog for that module. Then, you can use that namespace for calling `Lang`, `View` or `Config`. Following are some examples of its usage: + +Calling Lang: +```php +Lang::get('blog::group.name'); +``` + +Calling View: +```php +View::make('blog::index') + +View::make('blog::partials.sidebar') +``` + +Calling Config: +```php +Config::get('blog.name') +``` + +## Publishing Modules + +Have you created a laravel modules? Yes, I've. Then, I want to publish my modules. Where do I publish it? That's the question. What's the answer ? The answer is [Packagist](http://packagist.org). In pingpong/modules version >= 1.2.0, when you generate a module, you will see there is a new file generated called `composer.json`. + + +### Auto Scan Vendor Directory + +By default the `vendor` directory is not scanned automatically, you need to update the configuration file to allow that. Set `scan.enabled` value to `true`. For example : + +```php +// file config/modules.php + +return [ + //... + 'scan' => [ + 'enabled' => true + ] + //... +] +``` + +You can verify the module has been installed using `module:list` command: + +``` +php artisan module:list +``` + + +## Publishing Modules + +After creating a module and you are sure your module module will be used by other developers. You can push your module to [github](https://github.com) or [bitbucket](https://bitbucket.org) and after that you can submit your module to the packagist website. + +You can follow this step to publish your module. + +1. Create A Module. +2. Push the module to github. +3. Submit your module to the packagist website. +Submit to packagist is very easy, just give your github repository, click submit and you done.