├── LICENSE ├── README.md ├── composer.json ├── resources └── views │ ├── GeneratorCommands │ ├── controller.blade.php │ └── model.blade.php │ ├── ServiceProvider.blade.php │ ├── WelcomeController.blade.php │ ├── config.blade.php │ ├── routes.blade.php │ └── welcome.blade.php └── src ├── Commands ├── MakeController.php ├── MakeModel.php └── MakePackage.php ├── FileSystem ├── Filesystem.php └── Path.php ├── Generator └── Generator.php ├── LpackagerServiceProvider.php └── Parser └── NamespaceParser.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Houssain Amrani 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## lpackager 2 | 3 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/de72e940-3c06-4664-b84c-425838cd68ea/big.png)](https://insight.sensiolabs.com/projects/de72e940-3c06-4664-b84c-425838cd68ea) 4 | 5 | [![Build Status](https://travis-ci.org/amranidev/lpackager.svg?branch=master)](https://travis-ci.org/amranidev/lpackager) 6 | [![StyleCI](https://styleci.io/repos/57151159/shield?style=flat)](https://styleci.io/repos/57151159) 7 | [![Latest Stable Version](https://poser.pugx.org/amranidev/lpackager/v/stable)](https://packagist.org/packages/amranidev/lpackager) [![Latest Unstable Version](https://poser.pugx.org/amranidev/lpackager/v/unstable)](https://packagist.org/packages/amranidev/lpackager) [![License](https://poser.pugx.org/amranidev/lpackager/license)](https://packagist.org/packages/amranidev/lpackager) 8 | 9 | Lpackager is a CLI tool that allows you to generate packages/modules into your laravel app without forgetting business logic. [Split laravel app into packages/modules](http://amranidev.github.io/blog/site/split-your-laravel-app/). 10 | 11 | ### I. Package Installation 12 | 13 | 1. Run composer require to install Lpackager : 14 | 15 | ``` 16 | composer require Amranidev/Lpackager 17 | 18 | ``` 19 | 20 | Or add in composer.json: 21 | 22 | ```json 23 | require : { 24 | "Amranidev/Lpackager": "v1.0.*" 25 | } 26 | ``` 27 | 28 | Then update composer : 29 | 30 | ``` 31 | $ composer update 32 | ``` 33 | 34 | 3. Add the service providers to config/app.php : 35 | 36 | ```php 37 | 38 | Amranidev\Lpackager\LpackagerServiceProvider::class, 39 | 40 | ``` 41 | 42 | ### II. Quick Start 43 | 44 | Create new package by `php artisan lpackager:package <"NameSpace">` 45 | 46 | In this example, we will create a new (package/module) into our application with a name (Customer). 47 | 48 | 1. Create your first package: 49 | 50 | `php artisan lpackager:package Customer Kernel "Kernel\Customer"` 51 | 52 | ![Imgur](http://i.imgur.com/iRR8pF6.png) 53 | 54 | 2. Register namespace: 55 | 56 | Add to composer.json 57 | 58 | ```json 59 | "psr-4": { 60 | "App\\": "app/", 61 | "Kernel\\Customer\\": "Kernel/Customer/src" 62 | } 63 | ``` 64 | 3. Register the service provider: 65 | 66 | Add the service provider to config/app.php 67 | 68 | ```php 69 | Kernel\Customer\CustomerServiceProvider::class, 70 | ``` 71 | 4. Finally: 72 | 73 | Run `composer dump-autoload` 74 | 75 | Check if evreything is okey : 76 | 77 | `http://{your-project-url}/client` 78 | 79 | ### III. Commands 80 | 81 | * Create new Package : `php artisan lpackager:package <"NameSpace">` 82 | 83 | * Create new Controller : `php artisan lpackager:controller <"NameSpace">` 84 | 85 | * Create new Model : `php artisan lpackager:model <"NameSpace">` 86 | 87 | #### Contact : amranidev@gmail.com 88 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amranidev/lpackager", 3 | "description": "Packages Generator for Laravel", 4 | "homepage": "http://github.com/amranidev/scaffold-interface", 5 | "keywords": ["laravel", "framework", "package generator", "package"], 6 | "license": "MIT", 7 | "authors": [{ 8 | "name": "Amrani Houssain", 9 | "email": "amranidev@gmail.com" 10 | }], 11 | "require": { 12 | "php": ">=5.5.9" 13 | }, 14 | "require-dev": { 15 | "phpunit/phpunit": "~4.0|~5.0", 16 | "orchestra/testbench": "~3.0" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Amranidev\\Lpackager\\": "src/" 21 | } 22 | }, 23 | "autoload-dev": { 24 | "psr-4": { 25 | "Amranidev\\Lpackager\\Tests\\": "tests/" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /resources/views/GeneratorCommands/controller.blade.php: -------------------------------------------------------------------------------- 1 | namespace {{$nameSpace}} 2 | 3 | use {{$package}}AppController as Controller; 4 | 5 | class {{$className}} extends Controller 6 | { 7 | /** 8 | * Display a listing of the resource. 9 | * 10 | * @return \Illuminate\Http\Response 11 | */ 12 | public function index() 13 | { 14 | // 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /resources/views/GeneratorCommands/model.blade.php: -------------------------------------------------------------------------------- 1 | namespace {{$nameSpace}} 2 | 3 | use Illuminate\Database\Eloquent\Model; 4 | 5 | class {{$className}} extends Model 6 | { 7 | // 8 | } 9 | -------------------------------------------------------------------------------- /resources/views/ServiceProvider.blade.php: -------------------------------------------------------------------------------- 1 | namespace {{$namespace}}; 2 | 3 | use Illuminate\Support\ServiceProvider; 4 | use Illuminate\Foundation\AliasLoader; 5 | 6 | class {{$package}}ServiceProvider extends ServiceProvider 7 | { 8 | 9 | /** 10 | * Indicates if loading of the provider is deferred. 11 | * 12 | * @var bool 13 | */ 14 | protected $defer = false; 15 | 16 | /** 17 | * Bootstrap the application events. 18 | * 19 | * @return void 20 | */ 21 | public function boot() 22 | { 23 | // Get namespace 24 | $nameSpace = $this->app->getNamespace(); 25 | 26 | AliasLoader::getInstance()->alias('{{$package}}AppController', $nameSpace . 'Http\Controllers\Controller'); 27 | 28 | // Routes 29 | $this->app->router->group(['namespace' => $nameSpace . 'Http\Controllers'], function () { 30 | require __DIR__ . '/../routes/web.php'; 31 | }); 32 | 33 | // Load Views 34 | $this->loadViewsFrom(__DIR__ . '/../resources/views', '{{$package}}'); 35 | } 36 | 37 | public function register() 38 | { 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /resources/views/WelcomeController.blade.php: -------------------------------------------------------------------------------- 1 | 2 | namespace {{$controllerNameSpace}}; 3 | 4 | use {{$package}}AppController as Controller; 5 | 6 | 7 | class WelcomeController extends Controller 8 | { 9 | /** 10 | * Display a listing of the resource. 11 | * 12 | * @return \Illuminate\Http\Response 13 | */ 14 | public function index() 15 | { 16 | $package = "{{$package}}"; 17 | 18 | return view('{{$package}}::welcome' , compact('package')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /resources/views/config.blade.php: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | |------------------------------------------------------------------------- 4 | | "{{$package}}" config for scaffolding. 5 | |------------------------------------------------------------------------- 6 | | 7 | | You can replace this conf file with config/amranidev/config.php 8 | | to let scaffold-interface interact with "{{$package}}". 9 | | 10 | */ 11 | return [ 12 | 13 | 'env' => [ 14 | 'local', 15 | ], 16 | 17 | 'package' => '{{$package}}', 18 | 19 | 'model' => base_path() . '/{{$path}}/{{$package}}/src', 20 | 21 | 'views' => base_path() . '/{{$path}}/{{$package}}/resources/views', 22 | 23 | 'controller' => base_path() . '/{{$path}}/{{$package}}/src/Http/Controllers', 24 | 25 | 'migration' => base_path() . '/{{$path}}/{{$package}}/database/migrations', 26 | 27 | 'database' => '/{{$path}}/{{$package}}/database/migrations', 28 | 29 | 'routes' => base_path() . '/{{$path}}/{{$package}}/routes/web.php', 30 | 31 | 'controllerNameSpace' => '{{$namespace}}\\Http\\Controllers', 32 | 33 | 'modelNameSpace' => '{{$namespace}}', 34 | 35 | 'loadViews' => '{{$package}}', 36 | 37 | ]; 38 | -------------------------------------------------------------------------------- /resources/views/routes.blade.php: -------------------------------------------------------------------------------- 1 | /* 2 | |----------------------------------------------------- 3 | | {{$package}} Routes 4 | |----------------------------------------------------- 5 | | 6 | | Here is where {{$package}} package routes. 7 | | 8 | */ 9 | 10 | Route::get('{{lcfirst($package)}}','\{{$controllerNameSpace}}\WelcomeController@index'); 11 | -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @{{$package}} 5 | 6 | 7 | 8 | 33 | 34 | 35 |
36 |
37 |
@{{$package}}
38 |
39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /src/Commands/MakeController.php: -------------------------------------------------------------------------------- 1 | argument('namespace').'\\Http\\Controllers'; 48 | 49 | $package = $this->argument('package'); 50 | 51 | $className = $this->argument('class'); 52 | 53 | $packagePath = base_path().'/'.$this->argument('path').'/src/Http/Controllers/'.$className.'.php'; 54 | 55 | $fileSystem->make($packagePath, "render()); 57 | 58 | $this->comment($packagePath.' created successfully'); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Commands/MakeModel.php: -------------------------------------------------------------------------------- 1 | argument('namespace'); 47 | 48 | $className = $this->argument('class'); 49 | 50 | $packagePath = base_path().'/'.$this->argument('path').'/src/'.$className.'.php'; 51 | 52 | $fileSystem->make($packagePath, "render()); 54 | 55 | $this->comment($packagePath.' created successfully'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Commands/MakePackage.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class MakePackage extends Command 15 | { 16 | /** 17 | * The name and signature of the console command. 18 | * 19 | * @var string 20 | */ 21 | protected $signature = 'lpackager:package 22 | {package : Package name} 23 | {path : Package path} 24 | {namespace : Package namespace}'; 25 | 26 | /** 27 | * The console command description. 28 | * 29 | * @var string 30 | */ 31 | protected $description = 'Create a new package'; 32 | 33 | /** 34 | * Create a new command instance. 35 | * 36 | * @return void 37 | */ 38 | public function __construct() 39 | { 40 | parent::__construct(); 41 | } 42 | 43 | /** 44 | * Execute the console command. 45 | * 46 | * @return mixed 47 | */ 48 | public function handle() 49 | { 50 | $path = new Path($this->argument('path'), $this->argument('package')); 51 | 52 | $generator = new Generator($path, $this->argument('namespace')); 53 | 54 | //generate root directory 55 | 56 | $this->comment($generator->root()); 57 | 58 | //generate resources directory 59 | 60 | $this->comment($generator->resources()); 61 | 62 | //generate database directory 63 | 64 | $this->comment($generator->database()); 65 | 66 | //generate config directory 67 | 68 | $this->comment($generator->config()); 69 | 70 | //generate src directory 71 | 72 | $this->comment($generator->src()); 73 | 74 | //generate WelcomeController 75 | $this->comment($generator->generateWelcomeController()); 76 | //generate ServiceProvider 77 | $this->comment($generator->generateServiceProvider()); 78 | //generate WelcomeView 79 | $this->comment($generator->generateView()); 80 | //generate config file 81 | $this->comment($generator->generateConfig()); 82 | //generate routes file 83 | $this->comment($generator->generateRoute()); 84 | 85 | $this->comment($this->argument('package').' created successfully'); 86 | 87 | $this->comment('Go a head and:'); 88 | 89 | $this->comment('Add '.$this->argument('package').' package namespace to composer.json'); 90 | 91 | $this->comment('Add '.$this->argument('package').'ServiceProvider.php to config/app.php'); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/FileSystem/Filesystem.php: -------------------------------------------------------------------------------- 1 | exists($file)) { 20 | throw new \Exception('FileAlreadyExists'); 21 | } 22 | 23 | return file_put_contents($file, $content); 24 | } 25 | 26 | /** 27 | * Determine if the file already exists. 28 | * 29 | * @param string $file 30 | * 31 | * @return bool 32 | */ 33 | public function exists($file) 34 | { 35 | return file_exists($file); 36 | } 37 | 38 | /** 39 | * Make directory. 40 | * 41 | * @param string $path 42 | * 43 | * @return void 44 | */ 45 | public function makeDir($path) 46 | { 47 | if (is_dir($path)) { 48 | throw new \Exception('FileAlreadyExists'); 49 | } 50 | mkdir($path, 0777, true); 51 | } 52 | 53 | /** 54 | * File append. 55 | * 56 | * @param string $path 57 | * @param string $content 58 | * 59 | * @return int 60 | */ 61 | public function append($path, $content) 62 | { 63 | return file_put_contents($path, $content, FILE_APPEND | LOCK_EX); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/FileSystem/Path.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Path 11 | { 12 | /** 13 | * Package name. 14 | * 15 | * @var string package 16 | */ 17 | private $package; 18 | 19 | /** 20 | * Package path. 21 | * 22 | * @var string path 23 | */ 24 | private $path; 25 | 26 | /** 27 | * Create a new Path instance. 28 | * 29 | * @param string $package; 30 | * @param string $path 31 | */ 32 | public function __construct($path, $package) 33 | { 34 | $this->package = ucfirst($package); 35 | 36 | $this->path = $path; 37 | } 38 | 39 | /** 40 | * Get root path. 41 | * 42 | * @return string 43 | */ 44 | public function root() 45 | { 46 | return base_path().'/'.$this->path.'/'.$this->package; 47 | } 48 | 49 | /** 50 | * Get resources path. 51 | * 52 | * @return string 53 | */ 54 | public function resources() 55 | { 56 | return $this->root().'/resources/views'; 57 | } 58 | 59 | /** 60 | * Get database/migration path. 61 | * 62 | * @return string 63 | */ 64 | public function database() 65 | { 66 | return $this->root().'/database/migrations'; 67 | } 68 | 69 | /** 70 | * Get config path. 71 | * 72 | * @return string 73 | */ 74 | public function config() 75 | { 76 | return $this->root().'/config'; 77 | } 78 | 79 | /** 80 | * Get src path. 81 | * 82 | * @return string 83 | */ 84 | public function src() 85 | { 86 | return $this->root().'/src/Http/Controllers'; 87 | } 88 | 89 | /** 90 | * Get reoutes path. 91 | * 92 | * @return string 93 | */ 94 | public function routes() 95 | { 96 | return $this->root().'/routes'; 97 | } 98 | 99 | /** 100 | * Get Controller path. 101 | * 102 | * @return string 103 | */ 104 | public function controller() 105 | { 106 | return $this->root().'/src/Http/Controllers/WelcomeController.php'; 107 | } 108 | 109 | /** 110 | * Get ServiceProvider path. 111 | * 112 | * @return string 113 | */ 114 | public function serviceProvider() 115 | { 116 | return $this->root().'/src/'.$this->package.'ServiceProvider.php'; 117 | } 118 | 119 | /** 120 | * Get view path. 121 | * 122 | * @return string 123 | */ 124 | public function view() 125 | { 126 | return $this->root().'/resources/views/welcome.blade.php'; 127 | } 128 | 129 | /** 130 | * Get config file. 131 | * 132 | * @return string 133 | */ 134 | public function configFile() 135 | { 136 | return $this->config().'/config.php'; 137 | } 138 | 139 | /** 140 | * Get package name. 141 | * 142 | * @return string 143 | */ 144 | public function getPackage() 145 | { 146 | return $this->package; 147 | } 148 | 149 | /** 150 | * Get path. 151 | * 152 | * @return string 153 | */ 154 | public function getPath() 155 | { 156 | return $this->path; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/Generator/Generator.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class Generator extends Filesystem 15 | { 16 | /** 17 | * Path instance. 18 | * 19 | * @var \Amranidev\Lpackager\FileSystem\Path 20 | */ 21 | private $path; 22 | 23 | /** 24 | * NamespaceParser instance. 25 | * 26 | * @var \Amranidev\Lpackager\Parser\NamespaceParser 27 | */ 28 | private $namespaceParser; 29 | 30 | /** 31 | * Create new Generator instance. 32 | * 33 | * @param \Amranidev\Lpackager\FileSystem\Path 34 | * @param string $namespace 35 | * 36 | * @return void 37 | */ 38 | public function __construct(Path $path, $namespace) 39 | { 40 | $this->path = $path; 41 | 42 | $this->namespaceParser = new NamespaceParser($namespace); 43 | } 44 | 45 | /** 46 | * Create root directory. 47 | * 48 | * @return string 49 | */ 50 | public function root() 51 | { 52 | $this->makeDir($this->path->root()); 53 | 54 | return $this->path->root().' created successfully'; 55 | } 56 | 57 | /** 58 | * Create resources directory. 59 | * 60 | * @return string 61 | */ 62 | public function resources() 63 | { 64 | $this->makeDir($this->path->resources()); 65 | 66 | return $this->path->resources().' created successfully'; 67 | } 68 | 69 | /** 70 | * Create database directory. 71 | * 72 | * @return string 73 | */ 74 | public function database() 75 | { 76 | $this->makeDir($this->path->database()); 77 | 78 | return $this->path->database().' created successfully'; 79 | } 80 | 81 | /** 82 | * Create config directory. 83 | * 84 | * @return string 85 | */ 86 | public function config() 87 | { 88 | $this->makeDir($this->path->config()); 89 | 90 | return $this->path->config().' created successfully'; 91 | } 92 | 93 | /** 94 | * Create src directory. 95 | * 96 | * @return string 97 | */ 98 | public function src() 99 | { 100 | $this->makeDir($this->path->src()); 101 | 102 | return $this->path->src().' created successfully'; 103 | } 104 | 105 | /** 106 | * Generate welcomeController. 107 | * 108 | * @return string 109 | */ 110 | public function generateWelcomeController() 111 | { 112 | $this->make($this->path->controller(), " $this->namespaceParser->controllerNameSpace(), 'package' => $this->path->getPackage()])->render()); 113 | 114 | return $this->path->controller().' created successfully'; 115 | } 116 | 117 | /** 118 | * Generate ServiceProvider. 119 | * 120 | * @return string 121 | */ 122 | public function generateServiceProvider() 123 | { 124 | $this->make($this->path->serviceProvider(), " $this->path->getPAckage(), 'namespace' => $this->namespaceParser->getNamespace()])->render()); 125 | 126 | return $this->path->serviceProvider().' created successfully'; 127 | } 128 | 129 | /** 130 | * Generate WelcomeView. 131 | * 132 | * @return string 133 | */ 134 | public function generateView() 135 | { 136 | $this->make($this->path->view(), view('lpackager::welcome', ['package' => $this->path->getPAckage(), 'namespace' => $this->namespaceParser->getNamespace()])->render()); 137 | 138 | return $this->path->view().' created successfully'; 139 | } 140 | 141 | /** 142 | * Generate config file. 143 | * 144 | * @return string 145 | */ 146 | public function generateConfig() 147 | { 148 | $this->make($this->path->configFile(), " $this->path->getPAckage(), 'namespace' => $this->namespaceParser->getNamespace(), 'path' => $this->path->getPath()])->render()); 149 | 150 | return $this->path->configFile().' created successfully'; 151 | } 152 | 153 | /** 154 | * Generate routes file. 155 | * 156 | * @return string 157 | */ 158 | public function generateRoute() 159 | { 160 | $this->makeDir($this->path->routes()); 161 | 162 | $this->make($this->path->routes().'/web.php', " $this->namespaceParser->controllerNameSpace(), 'package' => $this->path->getPackage()])->render()); 163 | 164 | return $this->path->routes().'/web.php created successfully'; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/LpackagerServiceProvider.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class LpackagerServiceProvider extends ServiceProvider 13 | { 14 | /** 15 | * Indicates if loading of the provider is deferred. 16 | * 17 | * @var bool 18 | */ 19 | protected $defer = false; 20 | 21 | /** 22 | * Bootstrap the application events. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | // Load Views 29 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'lpackager'); 30 | 31 | $this->commands(['Amranidev\Lpackager\Commands\MakePackage', 'Amranidev\Lpackager\Commands\MakeController', 'Amranidev\Lpackager\Commands\MakeModel']); 32 | } 33 | 34 | /** 35 | * Register the service provider.. 36 | * 37 | * @return void 38 | */ 39 | public function register() 40 | { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Parser/NamespaceParser.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class NamespaceParser 11 | { 12 | /** 13 | * namespace. 14 | * 15 | * @var namespace 16 | */ 17 | private $namespace; 18 | 19 | /** 20 | * Create new NamespaceParser. 21 | * 22 | * @param string $namespace 23 | */ 24 | public function __construct($namespace) 25 | { 26 | $this->namespace = $namespace; 27 | } 28 | 29 | /** 30 | * Get Controller Namespace. 31 | * 32 | * @return string 33 | */ 34 | public function controllerNameSpace() 35 | { 36 | $controllerNameSpace = $this->namespace.'/Http/Controllers'; 37 | 38 | return str_replace('/', '\\', $controllerNameSpace); 39 | } 40 | 41 | /** 42 | * Get Namespace. 43 | * 44 | * @return string 45 | */ 46 | public function getNamespace() 47 | { 48 | return str_replace('/', '\\', $this->namespace); 49 | } 50 | } 51 | --------------------------------------------------------------------------------