Skip to content

Commit

Permalink
Merge pull request #5 from esemve/analysis-8K4GO3
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
esemve authored Feb 25, 2018
2 parents b1736e3 + 84a7f5c commit c127dda
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 88 deletions.
3 changes: 1 addition & 2 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public function call($parameters = null)
{
if ($this->run) {
$this->run = false;

return call_user_func_array($this->function, ($parameters ? $parameters : $this->parameters));
}

return null;
}

public function reset()
Expand Down
100 changes: 48 additions & 52 deletions src/Console/HookListeners.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
<?php

namespace Esemve\Hook\Console;

use Illuminate\Console\Command;
use Cache;
use Hook;

class HookListeners extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'hook:list';

/**
* The console command description.
*
* @var string
*/
protected $description = 'List all hook listeners';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

$list = Hook::getListeners();
$array = [];

foreach ($list as $hook => $lister) {
foreach ($lister as $key => $element) {

$array[] = [
$key,
$hook,
$element['caller']['class']
];
}
}

$headers = ['Sort', 'Hook name', 'Listener class'];

$this->table($headers, $array);

}
}
<?php

namespace Esemve\Hook\Console;

use Hook;
use Illuminate\Console\Command;

class HookListeners extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'hook:list';

/**
* The console command description.
*
* @var string
*/
protected $description = 'List all hook listeners';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$list = Hook::getListeners();
$array = [];

foreach ($list as $hook => $lister) {
foreach ($lister as $key => $element) {
$array[] = [
$key,
$hook,
$element['caller']['class'],
];
}
}

$headers = ['Sort', 'Hook name', 'Listener class'];

$this->table($headers, $array);
}
}
2 changes: 1 addition & 1 deletion src/Facades/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ protected static function getFacadeAccessor()
{
return 'Hook';
}
}
}
63 changes: 40 additions & 23 deletions src/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class Hook
protected $testing = false;

/**
* Return the hook answer
* @param string $hook Hook name
* @param array $params
* Return the hook answer.
*
* @param string $hook Hook name
* @param array $params
* @param callable $callback
* @param string $htmlContent content wrapped by hook
* @param string $htmlContent content wrapped by hook
*
* @return null|void
*/
public function get($hook, $params = [], callable $callback = null, $htmlContent = '')
Expand All @@ -33,11 +35,13 @@ public function get($hook, $params = [], callable $callback = null, $htmlContent
}

unset($callbackObject);

return $output;
}

/**
* Stop all another hook running
* Stop all another hook running.
*
* @param string $hook Hook name
*/
public function stop($hook)
Expand All @@ -46,7 +50,8 @@ public function stop($hook)
}

/**
* Subscribe to hook
* Subscribe to hook.
*
* @param string $hook Hook name
* @param $priority
* @param $function
Expand All @@ -65,30 +70,34 @@ public function listen($hook, $function, $priority = null)

$this->watch[$hook][$priority] = [
'function' => $function,
'caller' => [
'caller' => [
//'file' => $caller['file'],
//'line' => $caller['line'],
'class' => $caller['class']
]
'class' => $caller['class'],
],
];

ksort($this->watch[$hook]);
}

/**
* Return all registered hooks
* Return all registered hooks.
*
* @return array
*/
public function getHooks()
{
$hookNames = (array_keys($this->watch));
ksort($hookNames);

return $hookNames;
}

/**
* Return all listeners for hook
* Return all listeners for hook.
*
* @param string $hook
*
* @return array
*/
public function getEvents($hook)
Expand All @@ -103,9 +112,10 @@ public function getEvents($hook)
}

/**
* For testing
* @param string $name Hook name
* @param mixed $return Answer
* For testing.
*
* @param string $name Hook name
* @param mixed $return Answer
*/
public function mock($name, $return)
{
Expand All @@ -114,8 +124,10 @@ public function mock($name, $return)
}

/**
* Return the mock value
* Return the mock value.
*
* @param string $hook Hook name
*
* @return null|mixed
*/
protected function returnMockIfDebugModeAndMockExists($hook)
Expand All @@ -124,16 +136,18 @@ protected function returnMockIfDebugModeAndMockExists($hook)
if (array_key_exists($hook, $this->mock)) {
$output = $this->mock[$hook]['return'];
unset($this->mock[$hook]);

return $output;
}
}
return null;
}

/**
* Return a new callback object
* Return a new callback object.
*
* @param callable $callback function
* @param array $params parameters
* @param array $params parameters
*
* @return \Esemve\Hook\Callback
*/
protected function createCallbackObject($callback, $params)
Expand All @@ -142,11 +156,13 @@ protected function createCallbackObject($callback, $params)
}

/**
* Run hook events
* @param string $hook Hook name
* @param array $params Parameters
* Run hook events.
*
* @param string $hook Hook name
* @param array $params Parameters
* @param \Esemve\Hook\Callback $callback Callback object
* @param string $output html wrapped by hook
* @param string $output html wrapped by hook
*
* @return mixed
*/
protected function run($hook, $params, Callback $callback, $output = null)
Expand All @@ -172,7 +188,8 @@ protected function run($hook, $params, Callback $callback, $output = null)
}

/**
* Return the listeners
* Return the listeners.
*
* @return array
*/
public function getListeners()
Expand Down
18 changes: 8 additions & 10 deletions src/HookServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Esemve\Hook;

use Illuminate\Support\ServiceProvider;
use Blade;
use Illuminate\Support\ServiceProvider;

class HookServiceProvider extends ServiceProvider
{
Expand All @@ -19,22 +19,21 @@ public function register()
]);

$this->app->singleton('Hook', function () {
return new Hook;
return new Hook();
});
}

protected function bootDirectives()
{
Blade::directive('hook', function ($parameter) {

$parameter = trim($parameter, '()');
$parameters = explode(',', $parameter);

$name = trim($parameters[0], "'");

// $parameters[1] => bool => is this wrapper component?
if (!isset($parameters[1])) {
return ' <' . '?php
return ' <'.'?php
$__definedVars = (get_defined_vars()["__data"]);
if (empty($__definedVars))
Expand All @@ -44,17 +43,16 @@ protected function bootDirectives()
$output = \Hook::get("template.'.$name.'",["data"=>$__definedVars],function($data) { return null; });
if ($output)
echo $output;
?' . '>';
}else{
return ' <' . '?php
?'.'>';
} else {
return ' <'.'?php
$__hook_name="'.$name.'";
ob_start();
?' . '>';
?'.'>';
}
});

Blade::directive('endhook',function($parameter){

Blade::directive('endhook', function ($parameter) {
return ' <'.'?php
$__definedVars = (get_defined_vars()["__data"]);
if (empty($__definedVars))
Expand Down

0 comments on commit c127dda

Please sign in to comment.