sample event listener and scaffolding for a module
This commit is contained in:
@@ -2,10 +2,13 @@ APP_ENV=dev
|
||||
APP_KEY=base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI=
|
||||
APP_DEBUG=true
|
||||
APP_LOCALE=en
|
||||
APP_LOG_LEVEL=debug
|
||||
APP_URL=http://localhost
|
||||
APP_SETTINGS_STORE=json
|
||||
|
||||
APP_LOG=daily
|
||||
APP_LOG_LEVEL=debug
|
||||
APP_LOG_MAX_FILES=7
|
||||
|
||||
DB_CONNECTION=local
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
|
||||
23
app/Events/TestEvent.php
Normal file
23
app/Events/TestEvent.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class TestEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ class HomeController extends AppBaseController
|
||||
{
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
'App\Events\SomeEvent' => [
|
||||
/*'App\Events\TestEvent' => [
|
||||
'App\Listeners\EventListener',
|
||||
],
|
||||
],*/
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,8 @@
|
||||
"mockery/mockery": "0.9.*",
|
||||
"laravel/homestead": "v6.2.2",
|
||||
"filp/whoops": "~2.0",
|
||||
"orchestra/testbench": "v3.5.2"
|
||||
"orchestra/testbench": "v3.5.2",
|
||||
"bpocallaghan/generators": "5.0.1"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
|
||||
53
composer.lock
generated
53
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "33bef024a559e95406c1115a955a8c5e",
|
||||
"content-hash": "0cb626a4524ce3b7000623610d46d686",
|
||||
"packages": [
|
||||
{
|
||||
"name": "anlutro/l4-settings",
|
||||
@@ -6654,6 +6654,57 @@
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "bpocallaghan/generators",
|
||||
"version": "5.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bpocallaghan/generators.git",
|
||||
"reference": "69641f0b43e996e2155b43bb87af296dd3ef6349"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/bpocallaghan/generators/zipball/69641f0b43e996e2155b43bb87af296dd3ef6349",
|
||||
"reference": "69641f0b43e996e2155b43bb87af296dd3ef6349",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Bpocallaghan\\Generators\\GeneratorsServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Bpocallaghan\\Generators\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ben-Piet O'Callaghan",
|
||||
"email": "bpocallaghan@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Custom Laravel 5 File Generators with config and publishable stubs.",
|
||||
"keywords": [
|
||||
"commands",
|
||||
"config",
|
||||
"customization",
|
||||
"generators",
|
||||
"laravel",
|
||||
"stubs"
|
||||
],
|
||||
"time": "2017-11-16T12:28:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "filp/whoops",
|
||||
"version": "2.1.14",
|
||||
|
||||
@@ -15,8 +15,9 @@ return [
|
||||
'key' => env('APP_KEY'),
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
'log' => env('APP_LOG', 'single'),
|
||||
'log' => env('APP_LOG', 'daily'),
|
||||
'log_level' => env('APP_LOG_LEVEL', 'debug'),
|
||||
'log_max_files' => env('APP_LOG_MAX_FILES', 7),
|
||||
|
||||
'providers' => [
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ return [
|
||||
'enabled' => true,
|
||||
'path' => resource_path() . '/stubs/modules',
|
||||
'files' => [
|
||||
'start' => 'start.php',
|
||||
'routes' => 'Http/routes.php',
|
||||
'event-service-provider' => 'Providers/EventServiceProvider.php',
|
||||
'views/index' => 'Resources/views/index.blade.php',
|
||||
'views/index-admin' => 'Resources/views/admin/index.blade.php',
|
||||
'views/frontend' => 'Resources/views/layouts/frontend.blade.php',
|
||||
'views/admin' => 'Resources/views/layouts/admin.blade.php',
|
||||
'listener-test' => 'Listeners/TestEventListener.php',
|
||||
'controller-admin' => 'Http/Controllers/AdminController.php',
|
||||
'scaffold/config' => 'Config/config.php',
|
||||
'composer' => 'composer.json',
|
||||
@@ -22,6 +23,8 @@ return [
|
||||
'start' => ['LOWER_NAME', 'ROUTES_LOCATION'],
|
||||
'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
||||
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
||||
'event-service-provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
||||
'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
|
||||
'views/index' => ['LOWER_NAME'],
|
||||
'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'],
|
||||
'views/frontend' => ['STUDLY_NAME'],
|
||||
@@ -60,7 +63,7 @@ return [
|
||||
'test' => ['path' => 'tests', 'generate' => true],
|
||||
'repository' => ['path' => 'Repositories', 'generate' => false],
|
||||
'event' => ['path' => 'Events', 'generate' => false],
|
||||
'listener' => ['path' => 'Listeners', 'generate' => false],
|
||||
'listener' => ['path' => 'Listeners', 'generate' => true],
|
||||
'policies' => ['path' => 'Policies', 'generate' => false],
|
||||
'rules' => ['path' => 'Rules', 'generate' => false],
|
||||
'jobs' => ['path' => 'Jobs', 'generate' => false],
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Modules\\Sample\\Providers\\SampleServiceProvider"
|
||||
"Modules\\Sample\\Providers\\SampleServiceProvider",
|
||||
"Modules\\Sample\\Providers\\EventServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
"active": 1,
|
||||
"order": 0,
|
||||
"providers": [
|
||||
"Modules\\Sample\\Providers\\SampleServiceProvider"
|
||||
"Modules\\Sample\\Providers\\SampleServiceProvider",
|
||||
"Modules\\Sample\\Providers\\EventServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [
|
||||
"start.php"
|
||||
],
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Namespaces And Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When a module starting, this file will executed automatically. This helps
|
||||
| to register some namespaces like translator or view. Also this file
|
||||
| will load the routes file for each module. You may also modify
|
||||
| this file as you want.
|
||||
|
|
||||
*/
|
||||
|
||||
/*if (!app()->routesAreCached()) {
|
||||
require __DIR__ . '/Http/routes.php';
|
||||
}*/
|
||||
@@ -10,10 +10,11 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider"
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider",
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\EventServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
25
resources/stubs/modules/event-service-provider.stub
Normal file
25
resources/stubs/modules/event-service-provider.stub
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*/
|
||||
protected $listen = [
|
||||
'App\Events\TestEvent' => [
|
||||
'$MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\TestEventListener',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,10 @@
|
||||
"active": 1,
|
||||
"order": 0,
|
||||
"providers": [
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider"
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider",
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\EventServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [
|
||||
"start.php"
|
||||
],
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
||||
|
||||
16
resources/stubs/modules/listener-test.stub
Normal file
16
resources/stubs/modules/listener-test.stub
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners;
|
||||
|
||||
use App\Events\TestEvent;
|
||||
use Log;
|
||||
|
||||
class TestEventListener
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(TestEvent $event) {
|
||||
Log::info('Received event', [$event]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user