Skip to content

Commit 4170f65

Browse files
author
Roy Freij
committed
Initial commit
0 parents  commit 4170f65

23 files changed

+624
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.swp
2+
.DS_Store
3+
vendor/
4+
composer.lock
5+
storage/
6+
bootstrap/

.scrutinizer.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
build:
2+
nodes:
3+
analysis:
4+
project_setup:
5+
override: true
6+
tests:
7+
override: [php-scrutinizer-run]
8+
9+
filter:
10+
excluded_paths: [tests/*]
11+
12+
checks:
13+
php:
14+
remove_extra_empty_lines: true
15+
remove_php_closing_tag: true
16+
remove_trailing_whitespace: true
17+
fix_use_statements:
18+
remove_unused: true
19+
preserve_multiple: false
20+
preserve_blanklines: true
21+
order_alphabetically: true
22+
fix_php_opening_tag: true
23+
fix_linefeed: true
24+
fix_line_ending: true
25+
fix_identation_4spaces: true
26+
fix_doc_comments: true

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: php
2+
3+
php:
4+
- 7.0
5+
- 7.1
6+
- 7.2
7+
8+
before_script:
9+
- travis_retry composer self-update
10+
- travis_retry composer install --no-interaction --prefer-source --dev
11+
12+
script: vendor/bin/phpunit
13+
14+
after_success:
15+
- travis_retry php vendor/bin/php-coveralls

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Roy Freij
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 all
13+
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 THE
21+
SOFTWARE.

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# laravel-package-boilerplate
2+
3+
Boilerplate for Laravel packages. Use it as a starting point for your own Laravel packages.
4+
5+
Includes PHPUnit and PHPCodeSniffer configuration, as well as a known good Travis CI configuration and a couple of base test cases. Uses `orchestra/testbench` as the basis of the provided base test.
6+
7+
Also includes my [Artisan Standalone](https://github.com/matthewbdaly/artisan-standalone) package as a development dependency. As a result, you should be able to run Artisan commands as follows:
8+
9+
```bash
10+
vendor/bin/artisan make:model Example
11+
```
12+
13+
How do I use it?
14+
----------------
15+
###### Step 1
16+
```bash
17+
composer create-project matthewbdaly/laravel-package-boilerplate <YOUR_NEW_PACKAGE_DIRECTORY>
18+
```
19+
20+
This will generate a starting boilerplate for your app.
21+
22+
###### Step 2
23+
You'll want to update your `composer.json` with your required namespace and other details - you can do this by running
24+
```bash
25+
vendor/bin/artisan app:name InsertYourProjectNameHere
26+
```
27+
28+
Test cases
29+
----------
30+
31+
The package includes three test cases:
32+
33+
* `TestCase` - Effectively the normal Laravel test case. Use it the same way you would your normal Laravel test case
34+
* `SimpleTestCase` - Extends the default PHPUnit test case, so it doesn't set up a Laravel application, making it quicker and well-suited to properly isolated unit tests
35+
* `BrowserKitTestCase` - Sets up BrowserKit

composer.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "netcreaties/laravel-modulize",
3+
"description": "Creating easy to use modules without having to configure them.",
4+
"type": "library",
5+
"keywords": ["laravel"],
6+
"require": {},
7+
"require-dev": {
8+
"matthewbdaly/artisan-standalone": "0.0.*",
9+
"mockery/mockery": "~1.0",
10+
"orchestra/testbench": "^3.7",
11+
"orchestra/testbench-browser-kit": "^3.7",
12+
"php-coveralls/php-coveralls": "^2.1",
13+
"phpstan/phpstan": "^0.10.5",
14+
"phpunit/phpunit": "^7.0",
15+
"psy/psysh": "^0.9.8",
16+
"sebastian/phpcpd": "^4.0",
17+
"squizlabs/php_codesniffer": "^3.3"
18+
},
19+
"license": "MIT",
20+
"authors": [
21+
{
22+
"name": "Roy Freij",
23+
"email": "[email protected]"
24+
}
25+
],
26+
"autoload": {
27+
"psr-4": {
28+
"LaravelModulize\\": "src/"
29+
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"Tests\\": "tests/"
34+
}
35+
},
36+
"config": {
37+
"preferred-install": "dist",
38+
"sort-packages": true,
39+
"optimize-autoloader": true
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"LaravelModulize\\Providers\\ModulizeServiceProvider"
45+
]
46+
}
47+
}
48+
}

phpcs.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<description>Coding standard for Laravel package boilerplate.</description>
4+
<file>src</file>
5+
<arg value="np"/>
6+
<rule ref="PSR2"/>
7+
<rule ref="Squiz.Commenting.FunctionComment" />
8+
<rule ref="Squiz.Commenting.FunctionCommentThrowTag" />
9+
<rule ref="Squiz.Commenting.ClassComment" />
10+
</ruleset>

phpstan.neon

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 7
3+
paths: ['src/']
4+
autoload_files:
5+
- vendor/autoload.php

phpunit.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Tests">
13+
<directory suffix="Test.php">./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
<php>
22+
<env name="APP_ENV" value="testing"/>
23+
<env name="CACHE_DRIVER" value="array"/>
24+
<env name="SESSION_DRIVER" value="array"/>
25+
<env name="QUEUE_DRIVER" value="sync"/>
26+
<env name="DB_CONNECTION" value="sqlite"/>
27+
<env name="DB_DATABASE" value=":memory:"/>
28+
</php>
29+
</phpunit>

src/Contracts/LoadsFiles.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace LaravelModulize\Contracts;
4+
5+
use Illuminate\Support\Collection;
6+
7+
interface LoadsFiles
8+
{
9+
public function bootstrap(): void;
10+
11+
public function getFilesPath(string $module): string;
12+
13+
public function getFilesToLoad(string $module): Collection;
14+
15+
public function getNamespace(string $module): string;
16+
17+
public function loadFiles(string $module): void;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace LaravelModulize\Contracts;
4+
5+
use Illuminate\Support\Collection;
6+
7+
interface ModulizerRepositoryInterface
8+
{
9+
public function getBasePath(): string;
10+
11+
public function hasModules(): bool;
12+
13+
public function getModules(): Collection;
14+
15+
public function getModulePath(string $module): string;
16+
17+
public function getFiles(string $path): Collection;
18+
19+
public function getRootNamespace(): string;
20+
21+
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace LaravelModulize\Providers;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
use LaravelModulize\Services\Modulizer;
7+
use LaravelModulize\Services\ModulizerRepository;
8+
use LaravelModulize\Contracts\ModulizerRepositoryInterface;
9+
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
10+
11+
/**
12+
* Service provider
13+
*/
14+
class ModulizeServiceProvider extends BaseServiceProvider
15+
{
16+
/**
17+
* Bootstrap the application services.
18+
*
19+
* @return void
20+
*/
21+
public function boot()
22+
{
23+
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
24+
// $this->loadRoutesFrom(__DIR__.'/../../routes.php');
25+
// $this->loadViewsFrom(__DIR__.'/../views', 'packagename');
26+
}
27+
28+
/**
29+
* Register the application services.
30+
*
31+
* @return void
32+
*/
33+
public function register()
34+
{
35+
$this->app->singleton(ModulizerRepository::class, function ($app) {
36+
return new ModulizerRepository(new Filesystem());
37+
});
38+
39+
$this->app->bind(
40+
ModulizerRepositoryInterface::class,
41+
ModulizerRepository::class
42+
);
43+
44+
$this->app->singleton('modulizer', function ($app) {
45+
return new Modulizer($app);
46+
});
47+
48+
$this->mergeConfigFrom(
49+
$this->getDefaultConfigFilePath('modulizer'), 'modulizer'
50+
);
51+
}
52+
53+
54+
/**
55+
* Get default configuration file path
56+
*
57+
* @return string
58+
*/
59+
public function getDefaultConfigFilePath($configName)
60+
{
61+
return realpath(__DIR__ . "/../config/{$configName}.php");
62+
}
63+
}

src/Services/Modulizer.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace LaravelModulize\Services;
4+
5+
use Illuminate\Support\Collection;
6+
use LaravelModulize\Services\RoutesLoader;
7+
use Illuminate\Contracts\Foundation\Application;
8+
use LaravelModulize\Contracts\ModulizerRepositoryInterface;
9+
10+
class Modulizer
11+
{
12+
/**
13+
* @var \Illuminate\Contracts\Foundation\Application
14+
*/
15+
protected $app;
16+
17+
/**
18+
* Repository
19+
*
20+
* @var \LaravelModulize\Contracts\ModulizerRepositoryInterface
21+
*/
22+
public $repository;
23+
24+
protected $fileLoaders = [
25+
RoutesLoader::class
26+
];
27+
28+
/**
29+
* Modulizer constructor
30+
*
31+
* @param \Illuminate\Contracts\Foundation\Application $app
32+
*/
33+
public function __construct(ModulizerRepositoryInterface $repository, Application $app)
34+
{
35+
$this->app = $app;
36+
$this->repository = $repository;
37+
38+
$this->bootstrapLoaders();
39+
}
40+
41+
public function bootstrapLoaders()
42+
{
43+
dump($this->repository->hasModules());
44+
if ($this->repository->hasModules()) {
45+
$this->getFileLoaders()->each(function ($fileLoader) {
46+
$this->call($fileLoader)->bootstrap();
47+
});
48+
}
49+
}
50+
51+
private function call(string $class)
52+
{
53+
return $this->app->make($class);
54+
}
55+
56+
private function getFileLoaders(): Collection
57+
{
58+
return collect($this->fileLoaders);
59+
}
60+
}

0 commit comments

Comments
 (0)