Skip to content

Commit 57f8dff

Browse files
authored
Merge pull request #10 from mhh1422/master
Updating tests
2 parents f09459d + d147c57 commit 57f8dff

40 files changed

+1183
-898
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ Allows modules structure of your project. Each module can have its views, config
2929
1. Modify the `config/modules.php` config file as needed.
3030
3131
## How It Works
32-
Your modules should go in a root modules folder. By default this is `app/Modules` which maps to the namespace
32+
Your modules should go in a root modules folder. By default this is `app/Modules` which maps to the namespace
3333
`\App\Modules`.
3434
35-
Each of your modules will have its own folder inside the modules root folder, the folder will be named after the module
35+
Each of your modules will have its own folder inside the modules root folder, the folder will be named after the module
3636
name, and will map to the namespace `\App\Modules\{ModuleName}`.
3737
38-
Each module will contain a base module definition class, which (by default) will be named `Module.php` and maps to
38+
Each module will contain a base module definition class, which (by default) will be named `Module.php` and maps to
3939
the namespace `\App\Modules\{ModuleName}\Module`. This class will act as the key generator for the module URLs, routes,
4040
and other framework-related values.
4141
4242
Each module will contain its data models, controllers, views, routes, and other project files as usual. The `composer`
4343
PSR-4 loader should take care of loading your module files and classes properly.
4444
45-
Your module controllers (by default go into the `Http/Controllers` folder) should inherite the
45+
Your module controllers (by default go into the `Http/Controllers` folder) should inherite the
4646
`ItvisionSy\Laravel\Modules\Controller` class to make views rendering and other tasks easier.
4747
4848
## Creating Modules
@@ -52,30 +52,31 @@ php artisan modules:make {id} {name} [--url={url}]
5252
```
5353
Values of `id`, `name`, and `url` are strings, and the URL part is optional and will be used to generate make the
5454
URLs of the module more human friendly.
55-
55+
5656
This command will create the basic folder structure inside the modules folder, along with the base module and a sample
5757
routes (inside `Http/routes.php`), controller (inside `Http/Controllers/`), and view (inside `Views`).
5858
5959
As you have the basic structure, you can start creating your files and classes as normal. Nothing special to worry about.
6060
6161
## What is Store Handler
62-
It is a feature allows a per-module configuration to be saved in the database, in addition to a flag to identify if a
62+
It is a feature allows a per-module configuration to be saved in the database, in addition to a flag to identify if a
6363
module is enabled or disabled.
6464
6565
You need a class that implements the `ItvisionSy\Laravel\Modules\Interfaces\KeyValueStoreInterface` interface, which
6666
defines two methods: `set($key, $value)` and `get($key, $default=null)`.
6767
68-
There is a ready made implementation in the `\ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler` class,
69-
which utilizes a DB connection (default one by default) to store the config in a simple key/value table.
68+
There are two ready-made implementations in the `\ItvisionSy\Laravel\Modules\StoreHandlers\` namespace, one is calle
69+
`MysqlSimpleDbStoreHandler` and the other `SqliteSimpleDbStoreHandler`, which utilizes a DB connection (default one
70+
by default) to store the config in a simple key/value table.
7071
7172
The feature comes disabled by default by setting the class `\ItvisionSy\Laravel\Modules\StoreHandlers\DummyStoreHandler`
72-
as the store handler. To enable it, just change the `store_handler` config setting in the `config/modules.php` config
73-
file to use the `SimpleDbStoreHandler` class mentioned above.
73+
as the store handler. To enable it, just change the `store_handler` config setting in the `config/modules.php` config
74+
file to use one of the two classes mentioned above.
7475
```php
7576
//config/modules.php config file
76-
return [
77-
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler::class,
78-
];
77+
78+
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\SqliteSimpleDbStoreHandler::class,
79+
7980
```
8081

8182
Also, you need to create the database table for the store. We provided a simple artisan command to do that. After you
@@ -84,7 +85,7 @@ have configured everything correctly, simply execute the following command:
8485
which will take care about creating the database table by executing the following SQL command:
8586
```sql
8687
CREATE TABLE IF NOT EXISTS `modules_storage` (
87-
`key` VARCHAR(200) UNIQUE NOT NULL PRIMARY KEY,
88+
`key` VARCHAR(200) UNIQUE NOT NULL PRIMARY KEY,
8889
`value` VARCHAR(200) NULL
8990
);
9091
```

composer.json

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
{
2-
"name": "itvisionsy/laravel-modules",
3-
"description": "Laravel 5.1 library to allow modules structure. Each module can have its routes, controllers, views, config, ...",
4-
"type": "library",
5-
"keywords": [
6-
"modules",
7-
"laravel"
8-
],
9-
"require": {
10-
"php": ">=5.5.9",
11-
"laravel/framework": "5.1.*"
12-
},
13-
"license": "MIT",
14-
"authors": [
15-
{
16-
"name": "Muhannad Shelleh",
17-
"email": "muhannad.shelleh@gmail.com"
18-
}
19-
],
20-
"autoload": {
21-
"psr-4": {
22-
"ItvisionSy\\Laravel\\Modules\\": "src"
23-
}
24-
},
25-
"autoload-dev": {
26-
"classmap": [
27-
"tests/LaravelModulesTestCase.php"
2+
"name": "itvisionsy/laravel-modules",
3+
"description": "Laravel 5.1 library to allow modules structure. Each module can have its routes, controllers, views, config, ...",
4+
"type": "library",
5+
"keywords": [
6+
"modules",
7+
"laravel"
8+
],
9+
"require": {
10+
"php": ">=5.5.9",
11+
"laravel/framework": "5.1.*",
12+
"nette/reflection": "^2.4"
13+
},
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Muhannad Shelleh",
18+
"email": "muhannad.shelleh@gmail.com"
19+
}
2820
],
29-
"psr-4": {
30-
"ItvisionSy\\Laravel\\Modules\\Tests\\": "tests/",
31-
"App\\": "app/"
21+
"autoload": {
22+
"psr-4": {
23+
"ItvisionSy\\Laravel\\Modules\\": "src"
24+
}
25+
},
26+
"autoload-dev": {
27+
"classmap": [
28+
"tests/LaravelModulesTestCase.php"
29+
],
30+
"psr-4": {
31+
"ItvisionSy\\Laravel\\Modules\\Tests\\": "tests/",
32+
"App\\": "app/"
33+
}
34+
},
35+
"require-dev": {
36+
"laravel/laravel": "^5.1",
37+
"phpunit/phpunit": "^5.7"
3238
}
33-
},
34-
"require-dev": {
35-
"laravel/laravel": "^5.1",
36-
"phpunit/phpunit": "^5.7"
37-
}
3839
}

src/Commands/InitiateDatabaseTable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Contracts\Bus\SelfHandling;
7-
use ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler;
7+
use ItvisionSy\Laravel\Modules\StoreHandlers\SqliteSimpleDbStoreHandler;
88

99
class InitiateDatabaseTable extends Command implements SelfHandling
1010
{
@@ -28,7 +28,7 @@ public function __construct()
2828
public function handle()
2929
{
3030
try {
31-
$result = SimpleDbStoreHandler::createTable();
31+
$result = SqliteSimpleDbStoreHandler::createTable();
3232
if ($result) {
3333
$this->info("Table modules_storage created successfully!");
3434
} else {

src/Commands/MakeModule.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Illuminate\Contracts\Bus\SelfHandling;
66
use Illuminate\Filesystem\Filesystem;
77

8-
class MakeModule extends \Illuminate\Console\Command implements SelfHandling
9-
{
8+
class MakeModule extends \Illuminate\Console\Command implements SelfHandling {
109

1110
protected $signature = 'make:module
1211
{id : the ID of the module. Should be unique across modules}
@@ -24,8 +23,7 @@ class MakeModule extends \Illuminate\Console\Command implements SelfHandling
2423
* Create a new command instance.
2524
* @param Filesystem $fileSystem
2625
*/
27-
public function __construct(Filesystem $fileSystem)
28-
{
26+
public function __construct(Filesystem $fileSystem) {
2927
parent::__construct();
3028
$this->fileSystem = $fileSystem;
3129
}
@@ -35,8 +33,7 @@ public function __construct(Filesystem $fileSystem)
3533
*
3634
* @return void
3735
*/
38-
public function handle()
39-
{
36+
public function handle() {
4037
//input
4138
$id = $this->argument('id');
4239
$name = $this->argument('name');
@@ -67,25 +64,22 @@ public function handle()
6764
$this->copyStub("index.blade.php.stub", "{$path}Views{$ds}index.blade.php", $stubData + []);
6865

6966
$this->info("Module {$id} has been created in {$path}");
70-
7167
}
7268

73-
protected function makeDirectory($path, $mode = 0777)
74-
{
69+
protected function makeDirectory($path, $mode = 0777) {
7570
if (!$this->fileSystem->isDirectory($path)) {
7671
$this->fileSystem->makeDirectory($path, $mode, true, true);
7772
}
7873
}
7974

80-
protected function copyStub($stubName, $filePath, array $values)
81-
{
75+
protected function copyStub($stubName, $filePath, array $values) {
8276
$path = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'MakeModule' . DIRECTORY_SEPARATOR . $stubName;
8377
$content = preg_replace_callback("/\{\{([a-zA-Z_\-]+)\}\}/", function ($matches) use ($values) {
8478
return $values[$matches[1]];
8579
}, file_get_contents($path));
86-
if ($this->fileSystem->exists($filePath)) {
87-
$this->fileSystem->delete($filePath);
80+
if (!$this->fileSystem->exists($filePath)) {
81+
$this->fileSystem->put($filePath, $content);
8882
}
89-
$this->fileSystem->put($filePath, $content);
9083
}
84+
9185
}

0 commit comments

Comments
 (0)