Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Added hooks #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"rap2hpoutre/laravel-log-viewer": "^1.3",
"mews/purifier": "^3.1",
"guzzlehttp/guzzle": "~6.0",
"laravel/socialite": "^4.3"
"laravel/socialite": "^4.3",
"esemve/hook": "^0.0.6"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 19 additions & 0 deletions src/Helpers/functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
<?php

use Esemve\Hook\Facades\Hook;

if(!function_exists('character'))
{
function character() {
return \Auth::user()->character;
}
}

if(!function_exists('run_hook'))
{
function run_hook(string $name, array $params, callable $callback)
{
return Hook::get($name, $params, $callback);
}
}

if(!function_exists('hook_listen'))
{
function hook_listen(string $name, callable $callback, $priority = 10)
{
Hook::listen($name, $callback, $priority);
}
}
14 changes: 14 additions & 0 deletions src/Hooks/AbstractHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: kyle
* Date: 2020-05-02
* Time: 08:39
*/

namespace PbbgIo\Titan\Hooks;

abstract class AbstractHook
{
abstract public function listen(string $name);
}
26 changes: 26 additions & 0 deletions src/Hooks/AddHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: kyle
* Date: 2020-05-02
* Time: 07:47
*/

namespace PbbgIo\Titan\Hooks;

class AddHook
{

private $hook, $name;

public function __construct(AbstractHook $hook, string $name)
{
$this->hook = $hook;
$this->name = $name;
}

public function run()
{
$this->hook->listen($this->name);
}
}
46 changes: 46 additions & 0 deletions src/Providers/TitanServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: kyle
* Date: 2020-05-02
* Time: 06:17
*/

namespace PbbgIo\Titan\Providers;

use Esemve\Hook\Facades\Hook;
use Esemve\Hook\HookServiceProvider;
use Illuminate\Support\ServiceProvider;
use PbbgIo\Titan\Hooks\AddHook;

class TitanServiceProvider extends ServiceProvider
{

protected $hooks = [];

private function registerHooks()
{
foreach ($this->hooks as $name => $listeners)
{
foreach (array_unique($listeners) as $listener) {
$hook = new AddHook(new $listener, $name);
$hook->run();
}
}
}

public function boot()
{

}

public function register()
{
$this->registerHooks();

$this->app->register(HookServiceProvider::class);

$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Hook', Hook::class);
}
}
12 changes: 9 additions & 3 deletions src/TitanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace PbbgIo\Titan;

use Esemve\Hook\Facades\Hook;
use Esemve\Hook\HookServiceProvider;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use PbbgIo\Titan\Providers\TitanServiceProvider as ServiceProvider;
use PbbgIo\Titan\Commands\MakeExtension;
use PbbgIo\Titan\Commands\RefreshExtensionsCache;
use PbbgIo\Titan\Commands\InstallTitan;
Expand All @@ -25,6 +27,7 @@ class TitanServiceProvider extends ServiceProvider
*/
public function boot()
{
parent::boot();

$this->loadRoutesFrom(__DIR__ . '/routes.php');

Expand Down Expand Up @@ -59,6 +62,9 @@ public function boot()
Stat::observe(StatObserver::class);

$this->app->register(ExtensionServiceProvider::class);

$this->app->register(BanUserServiceProvider::class);

}

/**
Expand All @@ -68,6 +74,8 @@ public function boot()
*/
public function register()
{
parent::register();

$this->app->singleton('menu', function () {
$menu = Menu::with('items')->whereEnabled(true)->get();
return $menu;
Expand All @@ -81,7 +89,5 @@ public function register()
__DIR__ . '/../config/titan.php', 'titan'
);

$this->app->register(BanUserServiceProvider::class);

}
}