Download the PHP package dnafactory/laravel-modular without Composer
On this page you can find all versions of the php package dnafactory/laravel-modular. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dnafactory/laravel-modular
More information about dnafactory/laravel-modular
Files in dnafactory/laravel-modular
Package laravel-modular
Short Description Transform laravel in a modular system
License MIT
Homepage https://github.com/danielrussob/laravel-modular.git
Informations about the package laravel-modular
Transform laravel in a modular system
Usage
Install
composer require dnafactory/laravel-modular
Create a folder Modules under app
-----> app/Modules
That's it!
Create a Module
Create a folder under Modules
ex.: app/Modules/Module1
that's it!
Module structure
app
├── Modules
├────── Module1
├──────────── Api
├───────────────── Data
├───────────────────── OneInterface.php
├───────────────────── TwoInterface.php
├───────────────── OneRepositoryInterface.php
├───────────────── TwoManagementInterface.php
├──────────── Channel
├───────────────── OneChannel.php
├───────────────── TwoChannel.php
├──────────── Command
├───────────────── OneCommand.php
├───────────────── TwoCommand.php
├──────────── configs
├───────────────── one.php
├───────────────── two.php
├───────────────── three.php
├───────────────── foldername
├───────────────────── four.php
├──────────── Controller
├───────────────── OneController.php
├───────────────── TwoController.php
├──────────── Management
├───────────────── OneManagement.php
├───────────────── TwoManagement.php
├──────────── etc
├───────────────── commands.php
├───────────────── di.php
├───────────────── providers.php
├──────────── Event
├───────────────── OneEvent.php
├───────────────── TwoEvent.php
├───────────────── ThreeEvent.php
├──────────── factories
├───────────────── One.php
├───────────────── Two.php
├───────────────── Three.php
├──────────── Factory
├───────────────── OneFactory.php
├───────────────── TwoFactory.php
├───────────────── ThreeFactory.php
├──────────── Management
├───────────────── OneManagement.php
├───────────────── TwoManagement.php
├───────────────── ThreeManagement.php
├──────────── Middleware
├───────────────── OneMiddleware.php
├───────────────── TwoMiddleware.php
├───────────────── ThreeMiddleware.php
├──────────── migrations
├───────────────── 2000_00_00_000010_create_first_table.php
├───────────────── 2000_00_00_000020_create_second_table.php
├──────────── Model
├───────────────── One.php
├───────────────── Two.php
├───────────────── Three.php
├──────────── Provider
├───────────────── OneServiceProvider.php
├───────────────── TwoServiceProvider.php
├───────────────── ThreeServiceProvider.php
├──────────── Queue
├───────────────── OnePublisher.php
├───────────────── OneConsumer.php
├──────────── Repository
├───────────────── OneRepository.php
├───────────────── TwoRepository.php
├──────────── routes
├───────────────── api.php
├───────────────── web.php
├──────────── Seed
├───────────────── OneSeeder.php
├───────────────── TwoSeeder.php
├──────────── views
├───────────────── first.blade.php
├───────────────── second.blade.php
├──────────── helpers.php
├──────────── routes.php
├────── Module2
├──────────── ...
├──────────── ...
├────── Module3
├──────────── ...
├──────────── ...
Api folder
All files in this folder are Service Contract's file of: Facade, Proxy, Mediator, Strategy or generic Service
All files are interface
Don't forget to register this class in etc/di.php
Be careful: Api has first letter in uppercase and singular
Api/Data folder
All files in this folder are Service Contract's file of: Model or generic Data Class
All files are interface
Don't forget to register this class in etc/di.php
Be careful: Data has first letter in uppercase and singular
Channel folder
All files in this folder are Event Channel
Be careful: Channel has first letter in uppercase and singular
Command folder
All files in this folder are Console Command
Be careful: Command has first letter in uppercase and singular
configs folder
All files in this folder will be consider configs
You can refer to it as config('MODULENAME.FILENAME') or config('MODULENAME.FOLDER.FILENAME')
ex.:
Be careful: configs are lowercase and plural
Controller folder
All files in this folder are Controller
All files must terminate with Controller word
Be careful: Controller has first letter in uppercase and singular
etc folder
There's some defined configuration in this folder
di.php
di.php are an array of di in module
providers.php
providers.php are an array of all service provider in module
commands.php
commands.php are an array of all commands in module
Event folder
All files in this folder are Event or Broadcast Event
Be careful: Event has first letter in uppercase and singular
factories folder
All files in this folder will be consider laravel's factory
then you could use factory(One::class) as if One.php was declared in factories folder of laravel
Be careful: factories are lowercase and plural
Factory folder
All files in this folder are custom Factory
All files must terminate with Factory word
Be careful: Factory has first letter in uppercase and singular
See Factory Pattern in https://refactoring.guru/design-patterns/factory-method
Management folder
All files in this folder are Management
Place here all: Facade, Proxy, Mediator, Strategy or generic Service
All files must terminate with Management word. You must not specify pattern in filename.
Be careful: Management has first letter in uppercase and singular
See Facade pattern: https://refactoring.guru/design-patterns/facade See Proxy pattern: https://refactoring.guru/design-patterns/proxy See Mediator pattern: https://refactoring.guru/design-patterns/mediator See Strategy pattern: https://refactoring.guru/design-patterns/strategy
Middleware folder
All files in this folder are Middleware file
Be careful: Middleware has first letter in uppercase and singular
migrations folder
All files in this folder will be consider migrations and will be executed in alphanumeric order (by all migrations in all modules)
Be careful: migrations are lowercase and plural
Model folder
All files in this folder are Model
Be careful: Model has first letter in uppercase and singular
Provider folder
All files in this folder are custom Provider
Don't forget to register all providers in etc/providers.php
All files must terminate with ServiceProvider word
Be careful: Provider has first letter in uppercase and singular
Queue folder
All files in this folder are publisher / consumer queue
All files must terminate with Publisher or Consumer word
Be careful: Queue has first letter in uppercase and singular
Repository folder
All files in this folder are Repository
All files must terminate with Repository word
Be careful: Repository has first letter in uppercase and singular
routes folder
web.php file or api.php
All routes in this file will be shared in all application as web or as api
ex. web.php:
Now you can access to yoursite.com/hello-world and see in page "Hello World"
Be careful: routes.php are lowercase and plural
Seed folder
All files in this folder are Seeder
All files must terminate with Seed word
Remember to extend \Illuminate\Database\Seeder
Be careful: Seeder has first letter in uppercase and singular
views folder
All files in this folder will be consider views.
You can refer to it as Module1::filename
ex.:
module1::first refer to first.blade.php
module1::first.foo refer to first/foo.blade.php
Be careful: views are lowercase and plural
helpers.php file
All functions in this file will be shared in all application
ex.:
Now you can use sum($a, $b) in all Class of your application
Be careful: helpers.php are lowercase and plural
How to register a Cron
Create a file in Provider folder called RegisterCronServiceProvider that extends \DNAFactory\Core\Provider\RegisterCronServiceProvider
Implement protected method registerCron(Schedule $schedule) like this
Now register this ServiceProvider in etc/providers.php
How to create a modular packages
In composer.json specify dependency for dnafactory/laravel-modular
Create a ServiceProvider that extends \DNAFactory\Core\Provider\ModuleRegisterServiceProvider
Implements getModuleName, specifing a Module name
Implements getBasePath, specifing a root path of module
If files are stored in root:
If files are stored in src:
Add This service provider in AutoDiscover
You can see an example in \DNAFactory\Core\Provider\ExampleModuleRegisterServiceProvider of this module