Skip to content

Commit 64d1ba7

Browse files
committed
Initial commit
0 parents  commit 64d1ba7

15 files changed

+779
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build
2+
vendor
3+
tests/Support/temp
4+
tests/temp
5+
composer.lock
6+
phpunit.xml
7+
.env

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

LICENSE.md

Whitespace-only changes.

README.md

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Module loader inside your Laravel app
2+
3+
The `zonneplan/laravel-module-loader` package provides an easy to use module loader
4+
which can be used to modulize your project.
5+
6+
## How to use
7+
8+
First install the package, see the installation section.
9+
10+
#### Creating a new module:
11+
12+
- Create a folder, for example: `Modules` in the app directory.
13+
- After that create another one, for example: `User`.
14+
- In the root of that folder insert a `UserServiceProvider` which extends our abstract `Module` class.
15+
- Implement the function `getModuleNamespace()` like:
16+
``` php
17+
namespace Modules\User;
18+
19+
use Zonneplan/ModuleLoader/Module;
20+
21+
class UserServiceProvider extends Module
22+
{
23+
public function getModuleNamespace(): string
24+
{
25+
return 'user';
26+
}
27+
}
28+
```
29+
- Register the `UserServiceProvider` in the `config/app.php` file.
30+
``` php
31+
'providers' => [
32+
Modules\User\UserServiceProvider::class
33+
]
34+
```
35+
36+
#### Structure within the module:
37+
The expected structure is seen below. Most of it is optional.
38+
39+
```$xslt
40+
app
41+
├── Modules
42+
├──MyModule
43+
├──Config
44+
├──Console
45+
├──Database
46+
├──Factories
47+
├──Migrations
48+
├──Exceptions
49+
├──Http
50+
├──Controllers
51+
├──Middleware
52+
├──Requests
53+
├──Resources
54+
├──Resources
55+
├──lang
56+
├──views
57+
├──Routes
58+
├──web.php
59+
├──api.php
60+
├──channels.php
61+
├──console.php
62+
├──MyModuleServiceProvider.php
63+
├──tests
64+
```
65+
66+
#### Access a view from the module:
67+
To access a view from a module it will look like `'my-module::path.to.view'`
68+
69+
For example:
70+
``` php
71+
// In a controller
72+
view('user::index');
73+
74+
// In a blade file
75+
@include('user::index');
76+
@include('user::partials.form');
77+
````
78+
79+
#### Registering Policies:
80+
To register policies overwrite the `$policies` variable in the ServiceProvider of your module
81+
82+
For example:
83+
``` php
84+
protected $policies = [
85+
MyModel::class => MyModelPolicy::class,
86+
];
87+
```
88+
89+
#### Registering Middleware:
90+
To register middleware overwrite the `$middleware` variable in the ServiceProvider of your module
91+
92+
For example:
93+
``` php
94+
protected $middleware = [
95+
'my-middleware' => MyMiddleware::class,
96+
];
97+
```
98+
99+
#### Registering Events & Listeners:
100+
To register events & listeners overwrite the `$listen` variable in the ServiceProvider of your module
101+
102+
For example:
103+
``` php
104+
protected $listen = [
105+
MyEvent::class => [
106+
MyListener::class
107+
],
108+
];
109+
```
110+
111+
#### Registering Event Subscribers:
112+
To register event subscribers overwrite the `$subscribe` variable in the ServiceProvider of your module
113+
114+
For example:
115+
``` php
116+
protected $subscribe = [
117+
MySubscriber::class
118+
];
119+
```
120+
121+
## Requirements
122+
123+
This package requires at least Laravel 5.8 or higher, PHP 7.2 or higher
124+
125+
## Installation
126+
127+
`composer require zonneplan/laravel-module-loader`
128+
129+
The package will automatically register itself.
130+
131+
Register the namespace: `"Modules\\": "app/Modules"` in `composer.json` like:
132+
```$xslt
133+
"autoload": {
134+
"psr-4": {
135+
"App\\": "app/",
136+
"Modules\\": "app/Modules"
137+
},
138+
...
139+
```
140+
141+
In the following files: `web.php`, `api.php`, `channels.php`, `console.php` insert respectively:
142+
``` php
143+
Route::modules('web');
144+
Route::modules('api');
145+
Route::modules('channels');
146+
Route::modules('console');
147+
```
148+
149+
Routes will then be searched in the `Routes` folder of every module, but don't necessarily have to exist:
150+
151+
```$xslt
152+
├──MyModule
153+
├──Routes
154+
├──web.php (optional)
155+
├──api.php (optional)
156+
├──channels.php (optional)
157+
├──console.php (optional)
158+
```
159+
160+
There is also the option to insert:
161+
``` php
162+
Route::modules();
163+
```
164+
Routes will then be searched in `routes.php` at the root of the module
165+
166+
## Authors
167+
168+
* **Aron Rotteveel**
169+
* **Dennis Stolmeijer**
170+
* **Wout Hoeve**
171+
* **Johnny Borg**
172+
* **Rick Gout**
173+
* **Thijs Nijholt**

composer.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "zonneplan/laravel-module-loader",
3+
"description": "Module loader for Laravel",
4+
"keywords": [
5+
"zonneplan",
6+
"laravel",
7+
"module",
8+
"modules",
9+
"loader"
10+
],
11+
"homepage": "https://zonneplan.nl",
12+
"license": "MIT",
13+
"authors": [],
14+
"require": {
15+
"php": "^7.2",
16+
"illuminate/console": "5.8.*|^6.0",
17+
"illuminate/database": "5.8.*|^6.0",
18+
"illuminate/support": "5.8.*|^6.0",
19+
"illuminate/routing": "5.8.*|^6.0"
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit" : "^8.0",
23+
"mockery/mockery": "^1.0",
24+
"orchestra/testbench": "^4.0"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"Zonneplan\\ModuleLoader\\": "src"
29+
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"Zonneplan\\ModuleLoader\\Test\\": "tests"
34+
}
35+
},
36+
"extra": {
37+
"laravel": {
38+
"providers": [
39+
"Zonneplan\\ModuleLoader\\ModulesServiceProvider"
40+
],
41+
"aliases": {
42+
"Module": "Zonneplan\\ModuleLoader\\Facade"
43+
}
44+
}
45+
},
46+
"minimum-stability": "dev",
47+
"prefer-stable": true
48+
}

src/Facades/ModuleFacade.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Zonneplan\ModuleLoader\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
use Zonneplan\ModuleLoader\Support\Contracts\ModuleRepositoryContract;
7+
8+
class ModuleFacade extends Facade
9+
{
10+
/**
11+
* @return string
12+
*/
13+
protected static function getFacadeAccessor(): string
14+
{
15+
return ModuleRepositoryContract::class;
16+
}
17+
}

0 commit comments

Comments
 (0)