From bb3976c9d64679eb1d0794abb6b3f852b34d1c21 Mon Sep 17 00:00:00 2001 From: Enzo Moretti Date: Sun, 2 Jun 2013 22:50:40 +0200 Subject: [PATCH 1/8] Use develop branch of foolz/package Use develop branch of foolz/package --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3b36b76..b3e52bf 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ }, "require": { "php": ">=5.4.0", - "foolz/package": "dev-master" + "foolz/package": "dev-develop" }, "autoload": { "psr-0": { "Foolz\\Plugin": "classes/" } } -} \ No newline at end of file +} From 89da934e9b9ac8026a96ab8ee1841a18fe8caeb6 Mon Sep 17 00:00:00 2001 From: Enzo Moretti Date: Sun, 2 Jun 2013 23:52:14 +0300 Subject: [PATCH 2/8] Reverting change, wrong branch! --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b3e52bf..9ac0a42 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "require": { "php": ">=5.4.0", - "foolz/package": "dev-develop" + "foolz/package": "dev-master" }, "autoload": { "psr-0": { From 4421fc6721b38191fe3461717be998795e0f4d1a Mon Sep 17 00:00:00 2001 From: woxxy Date: Tue, 29 Apr 2014 23:30:12 +0200 Subject: [PATCH 3/8] require package master --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b3e52bf..9ac0a42 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "require": { "php": ">=5.4.0", - "foolz/package": "dev-develop" + "foolz/package": "dev-master" }, "autoload": { "psr-0": { From b1a1e5c60998d5ff063cfb8c9d30a799ee108f26 Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Tue, 13 Jan 2015 19:04:17 -0600 Subject: [PATCH 4/8] update hook method calls --- classes/Foolz/Plugin/PlugSuit.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/Foolz/Plugin/PlugSuit.php b/classes/Foolz/Plugin/PlugSuit.php index 467682b..6f0fa50 100644 --- a/classes/Foolz/Plugin/PlugSuit.php +++ b/classes/Foolz/Plugin/PlugSuit.php @@ -26,7 +26,7 @@ public function __call($name, $parameters) throw new \BadMethodCallException('Method "'.$name.'" does not exist in "'.$class.'".'); } - $before = Hook::forge($class.'::'.$name.'.call.before.method') + $before = Hook::forge($class.'::'.$name.'#call.beforeMethod') ->setObject($this) ->setParams($parameters) ->execute(); @@ -67,7 +67,7 @@ public function __call($name, $parameters) } // in the after, the last parameter passed will be the result - $after = \Foolz\Plugin\Hook::forge($class.'::'.$name.'.call.after.method') + $after = \Foolz\Plugin\Hook::forge($class.'::'.$name.'#call.afterMethod') ->setParams($parameters) ->execute(); @@ -94,7 +94,7 @@ public static function __callStatic($name, $parameters) throw new \BadMethodCallException('Static method "'.$name.'" does not exist in "'.$class.'".'); } - $before = \Foolz\Plugin\Hook::forge($class.'.'.$name.'.call.before') + $before = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.before') ->setParams($parameters) ->execute(); @@ -135,7 +135,7 @@ public static function __callStatic($name, $parameters) } // in the after, the last parameter passed will be the result - $after = \Foolz\Plugin\Hook::forge($class.'.'.$name.'.call.after') + $after = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.after') ->setParams($parameters) ->execute(); From 87c7872778aaeeb4c6dc605e7b464810e69174d2 Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Thu, 22 Jan 2015 03:34:30 -0600 Subject: [PATCH 5/8] fixed code style and updated to use PSR-4 autoload logic --- bootstrap.php | 15 - classes/Foolz/Plugin/AssetManager.php | 16 - classes/Foolz/Plugin/Event.php | 149 -------- classes/Foolz/Plugin/Hook.php | 160 -------- classes/Foolz/Plugin/Loader.php | 53 --- classes/Foolz/Plugin/PlugSuit.php | 149 -------- classes/Foolz/Plugin/Plugin.php | 116 ------ classes/Foolz/Plugin/Result.php | 183 --------- classes/Foolz/Plugin/Util.php | 63 ---- composer.json | 6 +- src/AssetManager.php | 16 + src/Event.php | 146 +++++++ src/Hook.php | 157 ++++++++ src/Loader.php | 53 +++ src/PlugSuit.php | 137 +++++++ src/Plugin.php | 119 ++++++ src/Result.php | 180 +++++++++ src/Util.php | 56 +++ {classes/Foolz/Plugin => src}/Void.php | 22 +- tests/bootstrap.php | 4 +- tests/classes/EventTest.php | 46 +-- tests/classes/HookTest.php | 264 ++++++------- tests/classes/LoaderTest.php | 16 +- tests/classes/PluginTest.php | 357 +++++++++--------- tests/classes/ResultTest.php | 120 +++--- tests/classes/VoidTest.php | 10 +- tests/mock/foolz/broken_json/composer.json | 46 +-- tests/mock/foolz/fake/bootstrap.php | 31 +- .../foolz/fake/classes/Foolz/Fake/Fake.php | 10 +- tests/mock/foolz/fake/composer.json | 49 ++- tests/phpunit.xml | 10 +- 31 files changed, 1356 insertions(+), 1403 deletions(-) delete mode 100644 bootstrap.php delete mode 100644 classes/Foolz/Plugin/AssetManager.php delete mode 100644 classes/Foolz/Plugin/Event.php delete mode 100644 classes/Foolz/Plugin/Hook.php delete mode 100644 classes/Foolz/Plugin/Loader.php delete mode 100644 classes/Foolz/Plugin/PlugSuit.php delete mode 100644 classes/Foolz/Plugin/Plugin.php delete mode 100644 classes/Foolz/Plugin/Result.php delete mode 100644 classes/Foolz/Plugin/Util.php create mode 100644 src/AssetManager.php create mode 100644 src/Event.php create mode 100644 src/Hook.php create mode 100644 src/Loader.php create mode 100644 src/PlugSuit.php create mode 100644 src/Plugin.php create mode 100644 src/Result.php create mode 100644 src/Util.php rename {classes/Foolz/Plugin => src}/Void.php (57%) diff --git a/bootstrap.php b/bootstrap.php deleted file mode 100644 index dd22626..0000000 --- a/bootstrap.php +++ /dev/null @@ -1,15 +0,0 @@ - __DIR__.'/classes/Foolz/Plugin/Void.php', - 'Foolz\\Plugin\\Util' => __DIR__.'/classes/Foolz/Plugin/Util.php', - 'Foolz\\Plugin\\Loader' => __DIR__.'/classes/Foolz/Plugin/Loader.php', - 'Foolz\\Plugin\\Plugin' => __DIR__.'/classes/Foolz/Plugin/Plugin.php', - 'Foolz\\Plugin\\Hook' => __DIR__.'/classes/Foolz/Plugin/Hook.php', - 'Foolz\\Plugin\\Event' => __DIR__.'/classes/Foolz/Plugin/Event.php', - 'Foolz\\Plugin\\Result' => __DIR__.'/classes/Foolz/Plugin/Result.php', -)); \ No newline at end of file diff --git a/classes/Foolz/Plugin/AssetManager.php b/classes/Foolz/Plugin/AssetManager.php deleted file mode 100644 index 557db98..0000000 --- a/classes/Foolz/Plugin/AssetManager.php +++ /dev/null @@ -1,16 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Event -{ - /** - * Array of all the registered events - * - * @var array the key is the Hook key, value is the Event object - */ - protected static $events = array(); - - /** - * The Hook key - * - * @var null|string|array - */ - protected $key = null; - - /** - * Priority to order the execution of plugins on the same hook. Lower runs earlier, negative allowed. - * - * @var int - */ - protected $priority = 5; - - /** - * The string to call a static class method or a Closure - * - * @var null|string|Closure - */ - protected $callable = null; - - /** - * Takes the Hook key and stores the object in the static::$events array - * - * @param string|array $key the key or the array of keys - */ - public function __construct($key) - { - $this->key = $key; - - if (is_array($key)) - { - foreach ($key as $k) - { - static::$events[$k][] = $this; - } - } - else - { - static::$events[$key][] = $this; - } - } - - /** - * Shorthand for the construct for PHP 5.3 to allow chaining - * - * @param string $key - * @return \Foolz\Plugin\Event - */ - public static function forge($key) - { - return new static($key); - } - - /** - * Removes all the events with the key - * - * @param string $key - */ - public static function clear($key) - { - unset(static::$events[$key]); - } - - /** - * Returns all the events ordered by ascending priority number - * - * @param string $key - * @return array empty if no hooks present, ordered by ascending priority number - */ - public static function getByKey($key) - { - if ( ! isset(static::$events[$key])) - { - return array(); - } - - $events = static::$events[$key]; - - // sort by ascending priority - usort($events, function($a, $b) { return $a->getPriority() - $b->getPriority(); }); - - return $events; - } - - /** - * Returns the priority - * - * @return int - */ - public function getPriority() - { - return $this->priority; - } - - /** - * Sets the priority - * - * @param int $priority - * @return \Foolz\Plugin\Event - */ - public function setPriority($priority) - { - $this->priority = $priority; - return $this; - } - - /** - * Gets the method or the Closure to run - * - * @return string|Callable - */ - public function getCall() - { - return $this->callable; - } - - /** - * Sets the method or Closure to run - * - * @param string|Closure $callable - * @return \Foolz\Plugin\Event - */ - public function setCall($callable) - { - $this->callable = $callable; - return $this; - } -} \ No newline at end of file diff --git a/classes/Foolz/Plugin/Hook.php b/classes/Foolz/Plugin/Hook.php deleted file mode 100644 index cff2678..0000000 --- a/classes/Foolz/Plugin/Hook.php +++ /dev/null @@ -1,160 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Hook -{ - /** - * The hook key - * - * @var null|string - */ - protected $key = null; - - /** - * The object the hook has been placed in, if any - * - * @var null|object - */ - protected $object = null; - - /** - * The parameters to pass to the - * - * @var array - */ - protected $params = array(); - - /** - * The disabled keys - * - * @var array - */ - protected static $disabled = array(); - - /** - * Takes a hook key - * - * @param string $key - */ - public function __construct($key) - { - $this->key = $key; - } - - /** - * Shorthand for PHP5.3 to concatenate on constructor - * - * @param string $key - * @return \Foolz\Plugin\Hook - */ - public static function forge($key) - { - return new static($key); - } - - /** - * Enables the Hook key if it was disabled - * - * @param string $key - */ - public static function enable($key) - { - static::$disabled = array_diff(static::$disabled, array($key)); - } - - /** - * Disable the Hook key - * - * @param string $key - */ - public static function disable($key) - { - static::$disabled[] = $key; - } - - /** - * Sets the object the hook has been placed in - * - * @param object $object - * @return \Foolz\Plugin\Hook - */ - public function setObject($object) - { - $this->object = $object; - return $this; - } - - /** - * Sets a parameter that will be passed to the events - * - * @param string $key - * @param mixed $value - * @return \Foolz\Plugin\Hook - */ - public function setParam($key, $value) - { - $this->params[$key] = $value; - return $this; - } - - /** - * Set bulks of parameters - * - * @param array $arr - * @return \Foolz\Plugin\Hook - */ - public function setParams(array $arr) - { - foreach ($arr as $key => $item) - { - $this->params[$key] = $item; - } - - return $this; - } - - /** - * Executes the hook and cascades through all the events - * - * @return \Foolz\Plugin\Result - */ - public function execute() - { - $result = new Result($this->params, $this->object); - - if (in_array($this->key, static::$disabled)) - { - return $result; - } - - $events = Event::getByKey($this->key); - - foreach ($events as $event) - { - $call = $event->getCall(); - - // if we set an object, the call is a closure and the PHP version is at least 5.4... - if ($this->object !== null && $call instanceof \Closure && version_compare(PHP_VERSION, '5.4.0') >= 0 && !defined('HHVM_VERSION')) - { - // ...bind the Closure's $this to the object - $call = $call->bindTo($this->object, $this->object); - } - - // users may not set the call, and that would be troubles - if ($call !== null) - { - call_user_func($call, $result); - } - } - - return $result; - } -} diff --git a/classes/Foolz/Plugin/Loader.php b/classes/Foolz/Plugin/Loader.php deleted file mode 100644 index 410e67a..0000000 --- a/classes/Foolz/Plugin/Loader.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Loader extends \Foolz\Package\Loader -{ - /** - * The type of package in use. Can be in example 'theme' or 'plugin' - * Override this to change type of package - * - * @var string - */ - protected $type_name = 'plugin'; - - /** - * The class into which the resulting objects are created. - * Override this, in example Foolz\Plugin\Plugin or Foolz\Theme\Theme - * - * @var string - */ - protected $type_class = 'Foolz\Plugin\Plugin'; - - /** - * Gets all the plugins or the plugins from the directory - * - * @return \Foolz\Plugin\Plugin[] All the plugins or the plugins in the directory - * @throws \OutOfBoundsException If there isn't such a $dir_name set - */ - public function getAll() - { - return parent::getAll(); - } - - /** - * Gets a single plugin object - * - * @param string $slug The slug of the plugin - * - * @return \Foolz\Plugin\Plugin - * @throws \OutOfBoundsException if the plugin doesn't exist - */ - public function get($slug) - { - return parent::get($slug); - } -} \ No newline at end of file diff --git a/classes/Foolz/Plugin/PlugSuit.php b/classes/Foolz/Plugin/PlugSuit.php deleted file mode 100644 index 6f0fa50..0000000 --- a/classes/Foolz/Plugin/PlugSuit.php +++ /dev/null @@ -1,149 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -trait PlugSuit -{ - /** - * The methods with 'p_' prefix will respond to plugins before and after - * - * @param string $name The name of the method without the prefix - * @param array $parameters The parameters passed by the user - */ - public function __call($name, $parameters) - { - $class = get_class($this); - - if ( ! method_exists($this, 'p_'.$name)) - { - throw new \BadMethodCallException('Method "'.$name.'" does not exist in "'.$class.'".'); - } - - $before = Hook::forge($class.'::'.$name.'#call.beforeMethod') - ->setObject($this) - ->setParams($parameters) - ->execute(); - - $parameters = $before->getParams(); - - // if it's not void it means we've replaced the return - if ( ! $before->get() instanceof Void) - { - $return = $before->get(); - } - else - { - switch (count($parameters)) - { - case 0: - $return = $this->{'p_'.$name}(); - break; - case 1: - $return = $this->{'p_'.$name}($parameters[0]); - break; - case 2: - $return = $this->{'p_'.$name}($parameters[0], $parameters[1]); - break; - case 3: - $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2]); - break; - case 4: - $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2], $parameters[3]); - break; - case 5: - $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); - break; - default: - $return = call_user_func_array(array(&$this, 'p_'.$name), $parameters); - break; - } - } - - // in the after, the last parameter passed will be the result - $after = \Foolz\Plugin\Hook::forge($class.'::'.$name.'#call.afterMethod') - ->setParams($parameters) - ->execute(); - - if ( ! $after->get() instanceof \Foolz\Plugin\Void) - { - return $after->get(); - } - - return $return; - } - - /** - * The static methods with 'p_' prefix will respond to plugins before and after - * - * @param string $name The name of the method without the prefix - * @param array $parameters The parameters passed by the user - */ - public static function __callStatic($name, $parameters) - { - $class = get_called_class(); - - if ( ! method_exists($class, 'p_'.$name)) - { - throw new \BadMethodCallException('Static method "'.$name.'" does not exist in "'.$class.'".'); - } - - $before = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.before') - ->setParams($parameters) - ->execute(); - - $parameters = $before->getParams(); - - // if it's not void it means we've replaced the return - if ( ! $before->get() instanceof \Foolz\Plugin\Void) - { - $return = $before->get(); - } - else - { - $pname = 'p_'.$name; - switch (count($parameters)) - { - case 0: - $return = static::$pname(); - break; - case 1: - $return = static::$pname($parameters[0]); - break; - case 2: - $return = static::$pname($parameters[0], $parameters[1]); - break; - case 3: - $return = static::$pname($parameters[0], $parameters[1], $parameters[2]); - break; - case 4: - $return = static::$pname($parameters[0], $parameters[1], $parameters[2], $parameters[3]); - break; - case 5: - $return = static::$pname($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); - break; - default: - $return = call_user_func_array(get_called_class().'::'.$pname, $parameters); - break; - } - } - - // in the after, the last parameter passed will be the result - $after = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.after') - ->setParams($parameters) - ->execute(); - - if ( ! $after->get() instanceof Void) - { - return $after->get(); - } - - return $return; - } -} \ No newline at end of file diff --git a/classes/Foolz/Plugin/Plugin.php b/classes/Foolz/Plugin/Plugin.php deleted file mode 100644 index b34586c..0000000 --- a/classes/Foolz/Plugin/Plugin.php +++ /dev/null @@ -1,116 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Plugin extends \Foolz\Package\Package -{ - /** - * Returns an AssetManager object to deal with the assets - * - * @return \Foolz\Plugin\AssetManager A new instance of the AssetManager - */ - public function getAssetManager() - { - if ($this->asset_manager !== null) - { - return $this->asset_manager; - } - return $this->asset_manager = new AssetManager($this); - } - - /** - * Runs the execution block - * - * @return \Foolz\Plugin\Plugin - */ - public function execute() - { - // clear the hook since we might have an old one - \Foolz\Plugin\Event::clear(get_class().'::execute.'.$this->getConfig('name')); - - $this->bootstrap(); - \Foolz\Plugin\Hook::forge(get_class().'::execute.'.$this->getConfig('name')) - ->setObject($this) - ->execute(); - - return $this; - } - - /** - * Triggers the install methods for the plugin - * - * @return \Foolz\Plugin\Plugin - */ - public function install() - { - // clear the hook since we might have an old one - \Foolz\Plugin\Event::clear(get_class().'::install.'.$this->getJsonConfig('name')); - - // execute the bootstrap to get the events instantiated - $this->bootstrap(); - \Foolz\Plugin\Hook::forge(get_class().'::install.'.$this->getJsonConfig('name')) - ->setObject($this) - ->execute(); - - return $this; - } - - /** - * Triggers the remove methods for the plugin. Doesn't remove the files. - * - * @return \Foolz\Plugin\Plugin - */ - public function uninstall() - { - // clear the hook since we might have an old one - \Foolz\Plugin\Event::clear(get_class().'::uninstall.'.$this->getJsonConfig('name')); - - // execute the bootstrap to get the events instantiated - $this->bootstrap(); - \Foolz\Plugin\Hook::forge(get_class().'::uninstall.'.$this->getJsonConfig('name')) - ->setObject($this) - ->execute(); - - return $this; - } - - /** - * Triggers the upgrade methods for the plugin. At this point the files MUST have changed. - * It will give two parameters to the Event: old_revision and new_revision, which are previous and new value - * for extra.revision in the composer.json. These can be used to determine which actions to undertake. - * - * @return \Foolz\Plugin\Plugin - */ - public function upgrade() - { - // clear the json data so we use the latest - $this->clearJsonConfig(); - - // clear the hook since we for sure have an old one - \Foolz\Plugin\Event::clear(get_class().'::upgrade.'.$this->getJsonConfig('name')); - - // execute the bootstrap to get the events re-instantiated - $this->bootstrap(); - - // run the event - \Foolz\Plugin\Hook::forge(get_class().'::upgrade.'.$this->getJsonConfig('name')) - ->setObject($this) - // the PHP config holds the old revision - ->setParam('old_revision', $this->getConfig('extra.revision', 0)) - // the JSON config holds the new revision - ->setParam('new_revision', $this->getJsonConfig('extra.revision', 0)) - ->execute(); - - // update the PHP config file so it has the new revision - $this->refreshConfig(); - - return $this; - } -} \ No newline at end of file diff --git a/classes/Foolz/Plugin/Result.php b/classes/Foolz/Plugin/Result.php deleted file mode 100644 index a650a5f..0000000 --- a/classes/Foolz/Plugin/Result.php +++ /dev/null @@ -1,183 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Result -{ - /** - * The parameters (which can be modified with setParam()) - * - * @var array Array with as keys the parameter key - */ - protected $params = []; - - /** - * The original parameters (can't be modified) - * - * @var array Array with as key the parameter key - */ - protected $params_original = []; - - /** - * The object in which the Hook runs - * - * @var object - */ - protected $object = null; - - /** - * The result - * - * @var mixed - */ - protected $result = null; - - /** - * Sets the parameters and in case it's available the object - * - * @param array $params - * @param null|object $object - */ - public function __construct(array $params = array(), $object = null) - { - $this->params = $this->params_original = $params; - $this->object = $object; - $this->result = new Void(); - } - - /** - * Resets the object to the initial state - * - * @return \Foolz\Plugin\Result The current object - */ - public function reset() - { - $this->params = []; - $this->params_original = []; - $this->object = null; - $this->result = null; - return $this; - } - - /** - * Returns the result - * - * @return mixed - */ - public function get($fallback = null) - { - if ($this->result instanceof Void && func_num_args() === 1) - { - return $fallback; - } - - return $this->result; - } - - /** - * Sets the result - * - * @param mixed $val - * @return \Foolz\Plugin\Result - */ - public function set($val) - { - $this->result = $val; - return $this; - } - - /** - * Returns the object from - * - * @return mixed the object - * @throws \OutOfBoundsException if there's no object - */ - public function getObject() - { - if ($this->object === null) - { - throw new \OutOfBoundsException('No object has been set.'); - } - - return $this->object; - } - - /** - * Returns the array of parameters - * - * @param bool $orig whether we want the original array of parameters - * @return array - */ - public function getParams($orig = false) - { - if ($orig === true) - { - return $this->params_original; - } - - return $this->params; - } - - /** - * Returns the parameter with the key - * - * @param string $key - * @param bool $orig whether we want the original value of the parameter - * @return mixed - * @throws \OutOfBoundsException if the key is not set - */ - public function getParam($key, $orig = false) - { - if ($orig === true) - { - if ( ! isset($this->params_original[$key])) - { - throw new \OutOfBoundsException('Undefined original parameter.'); - } - - return $this->params_original[$key]; - } - - if ( ! isset($this->params[$key])) - { - throw new \OutOfBoundsException('Undefined parameter.'); - } - - return $this->params[$key]; - } - - /** - * Updates a parameter - * - * @param string $key - * @param mixed $value - * @return \Foolz\Plugin\Result - */ - public function setParam($key, $value) - { - $this->params[$key] = $value; - return $this; - } - - /** - * Updates several parameters - * - * @param array $array Array with as keys the parameter key and as value the parameter value - * @return \Foolz\Plugin\Result - */ - public function setParams($array) - { - foreach ($array as $key => $item) - { - $this->params[$key] = $item; - } - return $this; - } -} \ No newline at end of file diff --git a/classes/Foolz/Plugin/Util.php b/classes/Foolz/Plugin/Util.php deleted file mode 100644 index 1ba2ec8..0000000 --- a/classes/Foolz/Plugin/Util.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @package Foolz\Plugin - * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 - */ -class Util -{ - - /** - * Returns the value of a deep associative array by using a dotted notation for the keys - * - * @param array $config The config file to fetch the value from - * @param string $section The dotted keys: akey.anotherkey.key - * @param mixed $fallback The fallback value - * @return mixed - * @throws \DomainException if the fallback is \Foolz\Plugin\Void - */ - public static function dottedConfig($config, $section, $fallback) - { - // get the section with the dot separated string - $sections = explode('.', $section); - $current = $config; - foreach ($sections as $key) - { - if (isset($current[$key])) - { - $current = $current[$key]; - } - else - { - if ($fallback instanceof Void) - { - throw new \DomainException; - } - - return $fallback; - } - } - - return $current; - } - - /** - * Saves an array to a PHP file with a return statement - * - * @param string $path The target path - * @param array $array The array to save - */ - public static function saveArrayToFile($path, $array) - { - $content = "=5.4.0", - "foolz/package": "dev-master" + "foolz/package": "dev-master" }, "autoload": { - "psr-0": { - "Foolz\\Plugin": "classes/" + "psr-4": { + "Foolz\\Plugin\\": "src/" } } } diff --git a/src/AssetManager.php b/src/AssetManager.php new file mode 100644 index 0000000..1bf9aa5 --- /dev/null +++ b/src/AssetManager.php @@ -0,0 +1,16 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Event +{ + /** + * Array of all the registered events + * + * @var array the key is the Hook key, value is the Event object + */ + protected static $events = array(); + + /** + * The Hook key + * + * @var null|string|array + */ + protected $key = null; + + /** + * Priority to order the execution of plugins on the same hook. Lower runs earlier, negative allowed. + * + * @var int + */ + protected $priority = 5; + + /** + * The string to call a static class method or a Closure + * + * @var null|string|Closure + */ + protected $callable = null; + + /** + * Takes the Hook key and stores the object in the static::$events array + * + * @param string|array $key the key or the array of keys + */ + public function __construct($key) + { + $this->key = $key; + + if (is_array($key)) { + foreach ($key as $k) { + static::$events[$k][] = $this; + } + } else { + static::$events[$key][] = $this; + } + } + + /** + * Shorthand for the construct for PHP 5.3 to allow chaining + * + * @param string $key + * @return \Foolz\Plugin\Event + */ + public static function forge($key) + { + return new static($key); + } + + /** + * Removes all the events with the key + * + * @param string $key + */ + public static function clear($key) + { + unset(static::$events[$key]); + } + + /** + * Returns all the events ordered by ascending priority number + * + * @param string $key + * @return array empty if no hooks present, ordered by ascending priority number + */ + public static function getByKey($key) + { + if (!isset(static::$events[$key])) { + return array(); + } + + $events = static::$events[$key]; + + // sort by ascending priority + usort($events, function($a, $b) { return $a->getPriority() - $b->getPriority(); }); + + return $events; + } + + /** + * Returns the priority + * + * @return int + */ + public function getPriority() + { + return $this->priority; + } + + /** + * Sets the priority + * + * @param int $priority + * @return \Foolz\Plugin\Event + */ + public function setPriority($priority) + { + $this->priority = $priority; + + return $this; + } + + /** + * Gets the method or the Closure to run + * + * @return string|Callable + */ + public function getCall() + { + return $this->callable; + } + + /** + * Sets the method or Closure to run + * + * @param string|Closure $callable + * @return \Foolz\Plugin\Event + */ + public function setCall($callable) + { + $this->callable = $callable; + + return $this; + } +} diff --git a/src/Hook.php b/src/Hook.php new file mode 100644 index 0000000..8d24d1f --- /dev/null +++ b/src/Hook.php @@ -0,0 +1,157 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Hook +{ + /** + * The hook key + * + * @var null|string + */ + protected $key = null; + + /** + * The object the hook has been placed in, if any + * + * @var null|object + */ + protected $object = null; + + /** + * The parameters to pass to the + * + * @var array + */ + protected $params = array(); + + /** + * The disabled keys + * + * @var array + */ + protected static $disabled = array(); + + /** + * Takes a hook key + * + * @param string $key + */ + public function __construct($key) + { + $this->key = $key; + } + + /** + * Shorthand for PHP5.3 to concatenate on constructor + * + * @param string $key + * @return \Foolz\Plugin\Hook + */ + public static function forge($key) + { + return new static($key); + } + + /** + * Enables the Hook key if it was disabled + * + * @param string $key + */ + public static function enable($key) + { + static::$disabled = array_diff(static::$disabled, array($key)); + } + + /** + * Disable the Hook key + * + * @param string $key + */ + public static function disable($key) + { + static::$disabled[] = $key; + } + + /** + * Sets the object the hook has been placed in + * + * @param object $object + * @return \Foolz\Plugin\Hook + */ + public function setObject($object) + { + $this->object = $object; + + return $this; + } + + /** + * Sets a parameter that will be passed to the events + * + * @param string $key + * @param mixed $value + * @return \Foolz\Plugin\Hook + */ + public function setParam($key, $value) + { + $this->params[$key] = $value; + + return $this; + } + + /** + * Set bulks of parameters + * + * @param array $arr + * @return \Foolz\Plugin\Hook + */ + public function setParams(array $arr) + { + foreach ($arr as $key => $item) { + $this->params[$key] = $item; + } + + return $this; + } + + /** + * Executes the hook and cascades through all the events + * + * @return \Foolz\Plugin\Result + */ + public function execute() + { + $result = new Result($this->params, $this->object); + + if (in_array($this->key, static::$disabled)) { + return $result; + } + + $events = Event::getByKey($this->key); + + foreach ($events as $event) { + $call = $event->getCall(); + + // if we set an object, the call is a closure and the PHP version is at least 5.4... + if ($this->object !== null && $call instanceof \Closure && version_compare(PHP_VERSION, '5.4.0') >= 0 && !defined('HHVM_VERSION')) { + // ...bind the Closure's $this to the object + $call = $call->bindTo($this->object, $this->object); + } + + // users may not set the call, and that would be troubles + if ($call !== null) { + call_user_func($call, $result); + } + } + + return $result; + } +} diff --git a/src/Loader.php b/src/Loader.php new file mode 100644 index 0000000..d765d4e --- /dev/null +++ b/src/Loader.php @@ -0,0 +1,53 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Loader extends \Foolz\Package\Loader +{ + /** + * The type of package in use. Can be in example 'theme' or 'plugin' + * Override this to change type of package + * + * @var string + */ + protected $type_name = 'plugin'; + + /** + * The class into which the resulting objects are created. + * Override this, in example Foolz\Plugin\Plugin or Foolz\Theme\Theme + * + * @var string + */ + protected $type_class = 'Foolz\Plugin\Plugin'; + + /** + * Gets all the plugins or the plugins from the directory + * + * @return \Foolz\Plugin\Plugin[] All the plugins or the plugins in the directory + * @throws \OutOfBoundsException If there isn't such a $dir_name set + */ + public function getAll() + { + return parent::getAll(); + } + + /** + * Gets a single plugin object + * + * @param string $slug The slug of the plugin + * + * @return \Foolz\Plugin\Plugin + * @throws \OutOfBoundsException if the plugin doesn't exist + */ + public function get($slug) + { + return parent::get($slug); + } +} diff --git a/src/PlugSuit.php b/src/PlugSuit.php new file mode 100644 index 0000000..bea5ec6 --- /dev/null +++ b/src/PlugSuit.php @@ -0,0 +1,137 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +trait PlugSuit +{ + /** + * The methods with 'p_' prefix will respond to plugins before and after + * + * @param string $name The name of the method without the prefix + * @param array $parameters The parameters passed by the user + */ + public function __call($name, $parameters) + { + $class = get_class($this); + + if (!method_exists($this, 'p_'.$name)) { + throw new \BadMethodCallException('Method "'.$name.'" does not exist in "'.$class.'".'); + } + + $before = Hook::forge($class.'::'.$name.'#call.beforeMethod') + ->setObject($this) + ->setParams($parameters) + ->execute(); + + $parameters = $before->getParams(); + + // if it's not void it means we've replaced the return + if (!$before->get() instanceof Void) { + $return = $before->get(); + } else { + switch (count($parameters)) { + case 0: + $return = $this->{'p_'.$name}(); + break; + case 1: + $return = $this->{'p_'.$name}($parameters[0]); + break; + case 2: + $return = $this->{'p_'.$name}($parameters[0], $parameters[1]); + break; + case 3: + $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2]); + break; + case 4: + $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2], $parameters[3]); + break; + case 5: + $return = $this->{'p_'.$name}($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); + break; + default: + $return = call_user_func_array(array(&$this, 'p_'.$name), $parameters); + break; + } + } + + // in the after, the last parameter passed will be the result + $after = \Foolz\Plugin\Hook::forge($class.'::'.$name.'#call.afterMethod') + ->setParams($parameters) + ->execute(); + + if (!$after->get() instanceof \Foolz\Plugin\Void) { + return $after->get(); + } + + return $return; + } + + /** + * The static methods with 'p_' prefix will respond to plugins before and after + * + * @param string $name The name of the method without the prefix + * @param array $parameters The parameters passed by the user + */ + public static function __callStatic($name, $parameters) + { + $class = get_called_class(); + + if (!method_exists($class, 'p_'.$name)) { + throw new \BadMethodCallException('Static method "'.$name.'" does not exist in "'.$class.'".'); + } + + $before = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.before') + ->setParams($parameters) + ->execute(); + + $parameters = $before->getParams(); + + // if it's not void it means we've replaced the return + if (!$before->get() instanceof \Foolz\Plugin\Void) { + $return = $before->get(); + } else { + $pname = 'p_'.$name; + switch (count($parameters)) { + case 0: + $return = static::$pname(); + break; + case 1: + $return = static::$pname($parameters[0]); + break; + case 2: + $return = static::$pname($parameters[0], $parameters[1]); + break; + case 3: + $return = static::$pname($parameters[0], $parameters[1], $parameters[2]); + break; + case 4: + $return = static::$pname($parameters[0], $parameters[1], $parameters[2], $parameters[3]); + break; + case 5: + $return = static::$pname($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); + break; + default: + $return = call_user_func_array(get_called_class().'::'.$pname, $parameters); + break; + } + } + + // in the after, the last parameter passed will be the result + $after = \Foolz\Plugin\Hook::forge($class.'.'.$name.'#call.after') + ->setParams($parameters) + ->execute(); + + if (!$after->get() instanceof Void) { + return $after->get(); + } + + return $return; + } +} diff --git a/src/Plugin.php b/src/Plugin.php new file mode 100644 index 0000000..1957b3d --- /dev/null +++ b/src/Plugin.php @@ -0,0 +1,119 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Plugin extends \Foolz\Package\Package +{ + /** + * Returns an AssetManager object to deal with the assets + * + * @return \Foolz\Plugin\AssetManager A new instance of the AssetManager + */ + public function getAssetManager() + { + if ($this->asset_manager !== null) { + return $this->asset_manager; + } + + return $this->asset_manager = new AssetManager($this); + } + + /** + * Runs the execution block + * + * @return \Foolz\Plugin\Plugin + */ + public function execute() + { + // clear the hook since we might have an old one + \Foolz\Plugin\Event::clear(get_class().'::execute.'.$this->getConfig('name')); + + $this->bootstrap(); + + \Foolz\Plugin\Hook::forge(get_class().'::execute.'.$this->getConfig('name')) + ->setObject($this) + ->execute(); + + return $this; + } + + /** + * Triggers the install methods for the plugin + * + * @return \Foolz\Plugin\Plugin + */ + public function install() + { + // clear the hook since we might have an old one + \Foolz\Plugin\Event::clear(get_class().'::install.'.$this->getJsonConfig('name')); + + // execute the bootstrap to get the events instantiated + $this->bootstrap(); + + \Foolz\Plugin\Hook::forge(get_class().'::install.'.$this->getJsonConfig('name')) + ->setObject($this) + ->execute(); + + return $this; + } + + /** + * Triggers the remove methods for the plugin. Doesn't remove the files. + * + * @return \Foolz\Plugin\Plugin + */ + public function uninstall() + { + // clear the hook since we might have an old one + \Foolz\Plugin\Event::clear(get_class().'::uninstall.'.$this->getJsonConfig('name')); + + // execute the bootstrap to get the events instantiated + $this->bootstrap(); + + \Foolz\Plugin\Hook::forge(get_class().'::uninstall.'.$this->getJsonConfig('name')) + ->setObject($this) + ->execute(); + + return $this; + } + + /** + * Triggers the upgrade methods for the plugin. At this point the files MUST have changed. + * It will give two parameters to the Event: old_revision and new_revision, which are previous and new value + * for extra.revision in the composer.json. These can be used to determine which actions to undertake. + * + * @return \Foolz\Plugin\Plugin + */ + public function upgrade() + { + // clear the json data so we use the latest + $this->clearJsonConfig(); + + // clear the hook since we for sure have an old one + \Foolz\Plugin\Event::clear(get_class().'::upgrade.'.$this->getJsonConfig('name')); + + // execute the bootstrap to get the events re-instantiated + $this->bootstrap(); + + // run the event + \Foolz\Plugin\Hook::forge(get_class().'::upgrade.'.$this->getJsonConfig('name')) + ->setObject($this) + // the PHP config holds the old revision + ->setParam('old_revision', $this->getConfig('extra.revision', 0)) + // the JSON config holds the new revision + ->setParam('new_revision', $this->getJsonConfig('extra.revision', 0)) + ->execute(); + + // update the PHP config file so it has the new revision + $this->refreshConfig(); + + return $this; + } +} diff --git a/src/Result.php b/src/Result.php new file mode 100644 index 0000000..706b0b6 --- /dev/null +++ b/src/Result.php @@ -0,0 +1,180 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Result +{ + /** + * The parameters (which can be modified with setParam()) + * + * @var array Array with as keys the parameter key + */ + protected $params = []; + + /** + * The original parameters (can't be modified) + * + * @var array Array with as key the parameter key + */ + protected $params_original = []; + + /** + * The object in which the Hook runs + * + * @var object + */ + protected $object = null; + + /** + * The result + * + * @var mixed + */ + protected $result = null; + + /** + * Sets the parameters and in case it's available the object + * + * @param array $params + * @param null|object $object + */ + public function __construct(array $params = array(), $object = null) + { + $this->params = $this->params_original = $params; + $this->object = $object; + $this->result = new Void(); + } + + /** + * Resets the object to the initial state + * + * @return \Foolz\Plugin\Result The current object + */ + public function reset() + { + $this->params = []; + $this->params_original = []; + $this->object = null; + $this->result = null; + + return $this; + } + + /** + * Returns the result + * + * @return mixed + */ + public function get($fallback = null) + { + if ($this->result instanceof Void && func_num_args() === 1) { + return $fallback; + } + + return $this->result; + } + + /** + * Sets the result + * + * @param mixed $val + * @return \Foolz\Plugin\Result + */ + public function set($val) + { + $this->result = $val; + + return $this; + } + + /** + * Returns the object from + * + * @return mixed the object + * @throws \OutOfBoundsException if there's no object + */ + public function getObject() + { + if ($this->object === null) { + throw new \OutOfBoundsException('No object has been set.'); + } + + return $this->object; + } + + /** + * Returns the array of parameters + * + * @param bool $orig whether we want the original array of parameters + * @return array + */ + public function getParams($orig = false) + { + if ($orig === true) { + return $this->params_original; + } + + return $this->params; + } + + /** + * Returns the parameter with the key + * + * @param string $key + * @param bool $orig whether we want the original value of the parameter + * @return mixed + * @throws \OutOfBoundsException if the key is not set + */ + public function getParam($key, $orig = false) + { + if ($orig === true) { + if (!isset($this->params_original[$key])) { + throw new \OutOfBoundsException('Undefined original parameter.'); + } + + return $this->params_original[$key]; + } + + if (!isset($this->params[$key])) { + throw new \OutOfBoundsException('Undefined parameter.'); + } + + return $this->params[$key]; + } + + /** + * Updates a parameter + * + * @param string $key + * @param mixed $value + * @return \Foolz\Plugin\Result + */ + public function setParam($key, $value) + { + $this->params[$key] = $value; + + return $this; + } + + /** + * Updates several parameters + * + * @param array $array Array with as keys the parameter key and as value the parameter value + * @return \Foolz\Plugin\Result + */ + public function setParams($array) + { + foreach ($array as $key => $item) { + $this->params[$key] = $item; + } + + return $this; + } +} diff --git a/src/Util.php b/src/Util.php new file mode 100644 index 0000000..e3d98c2 --- /dev/null +++ b/src/Util.php @@ -0,0 +1,56 @@ + + * @package Foolz\Plugin + * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0 + */ +class Util +{ + /** + * Returns the value of a deep associative array by using a dotted notation for the keys + * + * @param array $config The config file to fetch the value from + * @param string $section The dotted keys: akey.anotherkey.key + * @param mixed $fallback The fallback value + * @return mixed + * @throws \DomainException if the fallback is \Foolz\Plugin\Void + */ + public static function dottedConfig($config, $section, $fallback) + { + // get the section with the dot separated string + $sections = explode('.', $section); + $current = $config; + + foreach ($sections as $key) { + if (isset($current[$key])) { + $current = $current[$key]; + } else { + if ($fallback instanceof Void) { + throw new \DomainException; + } + + return $fallback; + } + } + + return $current; + } + + /** + * Saves an array to a PHP file with a return statement + * + * @param string $path The target path + * @param array $array The array to save + */ + public static function saveArrayToFile($path, $array) + { + $content = "assertEmpty(Event::getByKey('testing')); + public function testEvent() + { + $this->assertEmpty(Event::getByKey('testing')); - $new = new Event('testing'); - $retrieved = Event::getByKey('testing'); - $this->assertSame($new, $retrieved[0]); - } + $new = new Event('testing'); + $retrieved = Event::getByKey('testing'); + $this->assertSame($new, $retrieved[0]); + } - public function testSetGetPriority() - { - $new = Event::forge('testing'); - $this->assertSame(5, $new->getPriority()); - $new->setPriority(8); - $this->assertSame(8, $new->getPriority()); - } + public function testSetGetPriority() + { + $new = Event::forge('testing'); + $this->assertSame(5, $new->getPriority()); + $new->setPriority(8); + $this->assertSame(8, $new->getPriority()); + } - public function testSetGetCall() - { - $new = new Event('testing'); - $this->assertNull($new->getCall()); + public function testSetGetCall() + { + $new = new Event('testing'); + $this->assertNull($new->getCall()); - $new->setCall(function(){ return 123; }); - $call = $new->getCall(); - $this->assertSame(123, $call()); - } -} \ No newline at end of file + $new->setCall(function(){ return 123; }); + $call = $new->getCall(); + $this->assertSame(123, $call()); + } +} diff --git a/tests/classes/HookTest.php b/tests/classes/HookTest.php index 313d2a8..26484d8 100644 --- a/tests/classes/HookTest.php +++ b/tests/classes/HookTest.php @@ -5,135 +5,135 @@ class HookTest extends PHPUnit_Framework_TestCase { - public function testHook() - { - $ev = new Event('testing'); - $ev->setCall(function($result) { - $obj = $result->getObject(); - $obj->assertSame(1, 1); - $result->set('success '.$result->getParam('test')); - }); - - $new = new Hook('testing'); - $result = $new->setObject($this) - ->setParam('test', 'tester') - ->execute(); - - $this->assertSame('success tester', $result->get()); - - // poor forge - $result = Hook::forge('testing') - ->setObject($this) - ->setParams(array('test' => 'tester')) - ->execute(); - - $this->assertSame('success tester', $result->get()); - - $ev = new Event('hardcore'); - $ev->setCall(function($result){ - $num = $result->getParam('num'); - $num++; - $result->setParam('num', $num); - $result->set($num); - }); - - $ev = new Event('hardcore'); - $ev->setCall(function($result){ - $num = $result->getParam('num'); - $num++; - $result->setParam('num', $num); - $result->set($num); - }); - - $result = Hook::forge('hardcore') - ->setParam('num', 0) - ->execute(); - - $this->assertSame(2, $result->getParam('num')); - $this->assertSame(2, $result->get()); - } - - public function testConstructArray() - { - $ev = new Event(array('easycore1', 'easycore2')); - $ev->setCall(function($result){ - $num = $result->getParam('num'); - $num++; - $result->setParam('num', $num); - $result->set($num); - }); - - $result1 = Hook::forge('easycore1') - ->setParam('num', 0) - ->execute() - ->get(0); - - $result2 = Hook::forge('easycore2') - ->setParam('num', 0) - ->execute() - ->get(0); - - $this->assertSame(1, $result1); - $this->assertSame(1, $result2); - } - - public function testObjectInheritance() - { - $class = new \stdClass(); - $class->value = 'success'; - - Event::forge('objecttests') - ->setCall(function($result) { - // over PHP 5.4 we can use $this - if(version_compare(phpversion(), '5.4.0') >= 0) - { - $result->set($this->value); - } - else - { - $obj = $result->getObject(); - $result->set($obj->value); - } - }); - - $result = Hook::forge('objecttests') - ->setObject($class) - ->execute() - ->get('failure'); - - $this->assertSame('success', $result); - } - - public function testDisable() - { - \Foolz\Plugin\Hook::disable('disable.me'); - - \Foolz\Plugin\Event::forge('disable.me') - ->setCall(function($result) { - $result->setParam('result', 'unexpected'); - }); - - $result = \Foolz\Plugin\Hook::forge('disable.me') - ->setParam('result', 'expected') - ->execute(); - - $this->assertSame('expected', $result->getParam('result')); - } - - public function testEnable() - { - \Foolz\Plugin\Hook::disable('disable.me2'); - \Foolz\Plugin\Hook::enable('disable.me2'); - - \Foolz\Plugin\Event::forge('disable.me2') - ->setCall(function($result) { - $result->setParam('result', 'expected'); - }); - - $result = \Foolz\Plugin\Hook::forge('disable.me2') - ->setParam('result', 'unexpected') - ->execute(); - - $this->assertSame('expected', $result->getParam('result')); - } -} \ No newline at end of file + public function testHook() + { + $ev = new Event('testing'); + $ev->setCall(function($result) { + $obj = $result->getObject(); + $obj->assertSame(1, 1); + $result->set('success '.$result->getParam('test')); + }); + + $new = new Hook('testing'); + $result = $new->setObject($this) + ->setParam('test', 'tester') + ->execute(); + + $this->assertSame('success tester', $result->get()); + + // poor forge + $result = Hook::forge('testing') + ->setObject($this) + ->setParams(array('test' => 'tester')) + ->execute(); + + $this->assertSame('success tester', $result->get()); + + $ev = new Event('hardcore'); + $ev->setCall(function($result){ + $num = $result->getParam('num'); + $num++; + $result->setParam('num', $num); + $result->set($num); + }); + + $ev = new Event('hardcore'); + $ev->setCall(function($result){ + $num = $result->getParam('num'); + $num++; + $result->setParam('num', $num); + $result->set($num); + }); + + $result = Hook::forge('hardcore') + ->setParam('num', 0) + ->execute(); + + $this->assertSame(2, $result->getParam('num')); + $this->assertSame(2, $result->get()); + } + + public function testConstructArray() + { + $ev = new Event(array('easycore1', 'easycore2')); + $ev->setCall(function($result){ + $num = $result->getParam('num'); + $num++; + $result->setParam('num', $num); + $result->set($num); + }); + + $result1 = Hook::forge('easycore1') + ->setParam('num', 0) + ->execute() + ->get(0); + + $result2 = Hook::forge('easycore2') + ->setParam('num', 0) + ->execute() + ->get(0); + + $this->assertSame(1, $result1); + $this->assertSame(1, $result2); + } + + public function testObjectInheritance() + { + $class = new \stdClass(); + $class->value = 'success'; + + Event::forge('objecttests') + ->setCall(function($result) { + // over PHP 5.4 we can use $this + if(version_compare(phpversion(), '5.4.0') >= 0) + { + $result->set($this->value); + } + else + { + $obj = $result->getObject(); + $result->set($obj->value); + } + }); + + $result = Hook::forge('objecttests') + ->setObject($class) + ->execute() + ->get('failure'); + + $this->assertSame('success', $result); + } + + public function testDisable() + { + \Foolz\Plugin\Hook::disable('disable.me'); + + \Foolz\Plugin\Event::forge('disable.me') + ->setCall(function($result) { + $result->setParam('result', 'unexpected'); + }); + + $result = \Foolz\Plugin\Hook::forge('disable.me') + ->setParam('result', 'expected') + ->execute(); + + $this->assertSame('expected', $result->getParam('result')); + } + + public function testEnable() + { + \Foolz\Plugin\Hook::disable('disable.me2'); + \Foolz\Plugin\Hook::enable('disable.me2'); + + \Foolz\Plugin\Event::forge('disable.me2') + ->setCall(function($result) { + $result->setParam('result', 'expected'); + }); + + $result = \Foolz\Plugin\Hook::forge('disable.me2') + ->setParam('result', 'unexpected') + ->execute(); + + $this->assertSame('expected', $result->getParam('result')); + } +} diff --git a/tests/classes/LoaderTest.php b/tests/classes/LoaderTest.php index 640b05a..14271e7 100644 --- a/tests/classes/LoaderTest.php +++ b/tests/classes/LoaderTest.php @@ -4,11 +4,11 @@ class LoaderTest extends PHPUnit_Framework_TestCase { - public function testGetPlugin() - { - $new = Loader::forge('default'); - $new->addDir('test', __DIR__.'/../../tests/mock/'); - $plugin = $new->get('test', 'foolz/fake'); - $this->assertInstanceOf('Foolz\Plugin\Plugin', $plugin); - } -} \ No newline at end of file + public function testGetPlugin() + { + $new = Loader::forge('default'); + $new->addDir('test', __DIR__.'/../../tests/mock/'); + $plugin = $new->get('test', 'foolz/fake'); + $this->assertInstanceOf('Foolz\Plugin\Plugin', $plugin); + } +} diff --git a/tests/classes/PluginTest.php b/tests/classes/PluginTest.php index b243844..ec17215 100644 --- a/tests/classes/PluginTest.php +++ b/tests/classes/PluginTest.php @@ -5,182 +5,181 @@ class PluginTest extends PHPUnit_Framework_TestCase { - public function unlinkConfig() - { - if (file_exists(__DIR__.'/../../tests/mock/foolz/fake/composer.php')) - { - unlink(__DIR__.'/../../tests/mock/foolz/fake/composer.php'); - } - } - - public function testConstruct() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertInstanceOf('Foolz\Plugin\Plugin', $plugin); - } - - /** - * @expectedException \DomainException - */ - public function testConstructThrows() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/blabla'); - } - - public function testGetSetLoader() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $loader = new Loader(); - $plugin->setLoader($loader); - $this->assertSame($loader, $plugin->getLoader()); - } - - public function testGetDir() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake'); - $this->assertFalse(__DIR__.'/../../tests/mock/foolz/fake' === $plugin->getDir()); - - // it always adds a trailing slash - $this->assertSame(__DIR__.'/../../tests/mock/foolz/fake/', $plugin->getDir()); - } - - public function testGetJsonConfig() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertArrayHasKey('name', $plugin->getJsonConfig()); - } - - public function testGetJsonConfigKey() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertSame('Fake', $plugin->getJsonConfig('extra.name')); - } - - public function testGetJsonConfigKeyFallback() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertSame('Fake', $plugin->getJsonConfig('extra.doesntexist', 'Fake')); - } - - /** - * @expectedException \DomainException - */ - public function testGetJsonConfigKeyThrows() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertSame('Fake', $plugin->getJsonConfig('extra.doesntexist')); - } - - /** - * @expectedException \DomainException - */ - public function testGetJsonConfigBrokenJsonThrows() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/broken_json/'); - $plugin->getJsonConfig(); - } - - public function testJsonToConfig() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->jsonToConfig(); - $this->assertSame($plugin->getJsonConfig(), $plugin->getConfig()); - $this->unlinkConfig(); - } - - public function testGetConfig() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertArrayHasKey('name', $plugin->getConfig()); - $this->unlinkConfig(); - } - - public function testGetConfigKey() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertSame('Fake', $plugin->getConfig('extra.name')); - $this->unlinkConfig(); - } - - public function testGetConfigKeyFallback() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $this->assertSame('Fake', $plugin->getConfig('extra.doesntexist', 'Fake')); - $this->unlinkConfig(); - } - - /** - * @expectedException \DomainException - */ - public function testGetConfigKeyFallbackThrows() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->getConfig('extra.doesntexist'); - $this->unlinkConfig(); - } - - public function testRefreshConfig() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->getConfig(); - - $plugin->refreshConfig(); - $this->assertFalse(file_exists(__DIR__.'/../../tests/mock/foolz/fake/composer.php')); - $this->unlinkConfig(); - } - - public function testBootstrap() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->bootstrap(); - // we set a trap in the bootstrap file - $result = \Foolz\Plugin\Hook::forge('the.bootstrap.was.loaded')->execute()->get('no load'); - $this->assertSame('success', $result); - $this->unlinkConfig(); - } - - public function testExecute() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->execute(); - $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.execute.foolz/fake') - ->execute()->get('no load'); - $this->assertSame('success', $result); - $this->unlinkConfig(); - } - - public function testInstall() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->install(); - $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.install.foolz/fake') - ->execute()->get('no load'); - $this->assertSame('success', $result); - $this->unlinkConfig(); - } - - public function testUninstall() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->uninstall(); - $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.uninstall.foolz/fake') - ->execute()->get('no load'); - $this->assertSame('success', $result); - $this->unlinkConfig(); - } - - public function testUpgrade() - { - $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); - $plugin->upgrade(); - $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.upgrade.foolz/fake') - ->setObject($this) - ->setParam('old_revision', $plugin->getConfig('extra.revision', 0)) - ->setParam('new_revision', $plugin->getJsonConfig('extra.revision', 0)) - ->execute(); - $this->assertSame('success', $result->get('no load')); - $this->assertSame(0, $result->getParam('old_revision')); - $this->assertSame(0, $result->getParam('new_revision')); - $this->unlinkConfig(); - } -} \ No newline at end of file + public function unlinkConfig() + { + if (file_exists(__DIR__.'/../../tests/mock/foolz/fake/composer.php')) { + unlink(__DIR__.'/../../tests/mock/foolz/fake/composer.php'); + } + } + + public function testConstruct() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertInstanceOf('Foolz\Plugin\Plugin', $plugin); + } + + /** + * @expectedException \DomainException + */ + public function testConstructThrows() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/blabla'); + } + + public function testGetSetLoader() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $loader = new Loader(); + $plugin->setLoader($loader); + $this->assertSame($loader, $plugin->getLoader()); + } + + public function testGetDir() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake'); + $this->assertFalse(__DIR__.'/../../tests/mock/foolz/fake' === $plugin->getDir()); + + // it always adds a trailing slash + $this->assertSame(__DIR__.'/../../tests/mock/foolz/fake/', $plugin->getDir()); + } + + public function testGetJsonConfig() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertArrayHasKey('name', $plugin->getJsonConfig()); + } + + public function testGetJsonConfigKey() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertSame('Fake', $plugin->getJsonConfig('extra.name')); + } + + public function testGetJsonConfigKeyFallback() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertSame('Fake', $plugin->getJsonConfig('extra.doesntexist', 'Fake')); + } + + /** + * @expectedException \DomainException + */ + public function testGetJsonConfigKeyThrows() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertSame('Fake', $plugin->getJsonConfig('extra.doesntexist')); + } + + /** + * @expectedException \DomainException + */ + public function testGetJsonConfigBrokenJsonThrows() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/broken_json/'); + $plugin->getJsonConfig(); + } + + public function testJsonToConfig() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->jsonToConfig(); + $this->assertSame($plugin->getJsonConfig(), $plugin->getConfig()); + $this->unlinkConfig(); + } + + public function testGetConfig() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertArrayHasKey('name', $plugin->getConfig()); + $this->unlinkConfig(); + } + + public function testGetConfigKey() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertSame('Fake', $plugin->getConfig('extra.name')); + $this->unlinkConfig(); + } + + public function testGetConfigKeyFallback() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $this->assertSame('Fake', $plugin->getConfig('extra.doesntexist', 'Fake')); + $this->unlinkConfig(); + } + + /** + * @expectedException \DomainException + */ + public function testGetConfigKeyFallbackThrows() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->getConfig('extra.doesntexist'); + $this->unlinkConfig(); + } + + public function testRefreshConfig() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->getConfig(); + + $plugin->refreshConfig(); + $this->assertFalse(file_exists(__DIR__.'/../../tests/mock/foolz/fake/composer.php')); + $this->unlinkConfig(); + } + + public function testBootstrap() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->bootstrap(); + // we set a trap in the bootstrap file + $result = \Foolz\Plugin\Hook::forge('the.bootstrap.was.loaded')->execute()->get('no load'); + $this->assertSame('success', $result); + $this->unlinkConfig(); + } + + public function testExecute() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->execute(); + $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.execute.foolz/fake') + ->execute()->get('no load'); + $this->assertSame('success', $result); + $this->unlinkConfig(); + } + + public function testInstall() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->install(); + $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.install.foolz/fake') + ->execute()->get('no load'); + $this->assertSame('success', $result); + $this->unlinkConfig(); + } + + public function testUninstall() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->uninstall(); + $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.uninstall.foolz/fake') + ->execute()->get('no load'); + $this->assertSame('success', $result); + $this->unlinkConfig(); + } + + public function testUpgrade() + { + $plugin = new Plugin(__DIR__.'/../../tests/mock/foolz/fake/'); + $plugin->upgrade(); + $result = \Foolz\Plugin\Hook::forge('foolz\plugin\plugin.upgrade.foolz/fake') + ->setObject($this) + ->setParam('old_revision', $plugin->getConfig('extra.revision', 0)) + ->setParam('new_revision', $plugin->getJsonConfig('extra.revision', 0)) + ->execute(); + $this->assertSame('success', $result->get('no load')); + $this->assertSame(0, $result->getParam('old_revision')); + $this->assertSame(0, $result->getParam('new_revision')); + $this->unlinkConfig(); + } +} diff --git a/tests/classes/ResultTest.php b/tests/classes/ResultTest.php index e3c3ddd..423c28d 100644 --- a/tests/classes/ResultTest.php +++ b/tests/classes/ResultTest.php @@ -4,76 +4,76 @@ class ResultTest extends PHPUnit_Framework_TestCase { - public function testResult() - { - $std = new stdClass(); - $new = new Result(array('param1' => 'test'), $std); + public function testResult() + { + $std = new stdClass(); + $new = new Result(array('param1' => 'test'), $std); - $this->assertSame($std, $new->getObject()); - } + $this->assertSame($std, $new->getObject()); + } - public function testSetGet() - { - $new = new Result(); - $new->set('bla'); - $this->assertSame('bla', $new->get()); - } + public function testSetGet() + { + $new = new Result(); + $new->set('bla'); + $this->assertSame('bla', $new->get()); + } - /** - * @expectedException \OutOfBoundsException - */ - public function testSetGetThrowsOutOfBounds() - { - $new = new Result(); - $new->getObject(); - } + /** + * @expectedException \OutOfBoundsException + */ + public function testSetGetThrowsOutOfBounds() + { + $new = new Result(); + $new->getObject(); + } - public function testSetGetFallback() - { - $new = new Result(); - $this->assertSame('blabla', $new->get('blabla')); - } + public function testSetGetFallback() + { + $new = new Result(); + $this->assertSame('blabla', $new->get('blabla')); + } - public function testSetGetParam() - { - $arr = array('param1' => 'test', 'param2' => 'testtest'); - $new = new Result($arr); + public function testSetGetParam() + { + $arr = array('param1' => 'test', 'param2' => 'testtest'); + $new = new Result($arr); - $this->assertSame($arr, $new->getParams()); + $this->assertSame($arr, $new->getParams()); - $this->assertSame('test', $new->getParam('param1')); + $this->assertSame('test', $new->getParam('param1')); - $new->setParam('param1', 'test1'); + $new->setParam('param1', 'test1'); - $this->assertSame($arr, $new->getParams(true)); - $this->assertSame('test', $new->getParam('param1', true)); - $this->assertSame('test1', $new->getParam('param1')); - } + $this->assertSame($arr, $new->getParams(true)); + $this->assertSame('test', $new->getParam('param1', true)); + $this->assertSame('test1', $new->getParam('param1')); + } - public function testSetGetParams() - { - $arr = array('param1' => 'test', 'param2' => 'testtest'); - $new = new Result(); - $new->setParams($arr); + public function testSetGetParams() + { + $arr = array('param1' => 'test', 'param2' => 'testtest'); + $new = new Result(); + $new->setParams($arr); - $this->assertSame($arr, $new->getParams()); - } + $this->assertSame($arr, $new->getParams()); + } - /** - * @expectedException \OutOfBoundsException - */ - public function testGetParamThrowsOutOfBounds() - { - $new = new Result(); - $new->getParam('herp'); - } + /** + * @expectedException \OutOfBoundsException + */ + public function testGetParamThrowsOutOfBounds() + { + $new = new Result(); + $new->getParam('herp'); + } - /** - * @expectedException \OutOfBoundsException - */ - public function testGetParamOrigThrowsOutOfBounds() - { - $new = new Result(); - $new->getParam('herp', true); - } -} \ No newline at end of file + /** + * @expectedException \OutOfBoundsException + */ + public function testGetParamOrigThrowsOutOfBounds() + { + $new = new Result(); + $new->getParam('herp', true); + } +} diff --git a/tests/classes/VoidTest.php b/tests/classes/VoidTest.php index aa3200e..f1a8874 100644 --- a/tests/classes/VoidTest.php +++ b/tests/classes/VoidTest.php @@ -2,8 +2,8 @@ class VoidTest extends PHPUnit_Framework_TestCase { - public function testForge() - { - $this->assertInstanceOf('Foolz\Plugin\Void', \Foolz\Plugin\Void::forge()); - } -} \ No newline at end of file + public function testForge() + { + $this->assertInstanceOf('Foolz\Plugin\Void', \Foolz\Plugin\Void::forge()); + } +} diff --git a/tests/mock/foolz/broken_json/composer.json b/tests/mock/foolz/broken_json/composer.json index e4fdd56..8ac32d1 100644 --- a/tests/mock/foolz/broken_json/composer.json +++ b/tests/mock/foolz/broken_json/composer.json @@ -1,27 +1,27 @@ ureghuregh{ - "name": "foolz/broken_json", - "type": "foolz-plugin", - "description": "A fake plugin", - "keywords": ["fake", "mock"], - "homepage": "http://www.foolz.us", - "license": "Apache-2.0", - "authors": [{"name": "foolz", "email": "support@foolz.us"}], - "support": { - "email": "support@foolz.us", - "irc": "irc://irc.irchighway.net/fooldriver" - }, + "name": "foolz/broken_json", + "type": "foolz-plugin", + "description": "A fake plugin", + "keywords": ["fake", "mock"], + "homepage": "http://www.foolz.us", + "license": "Apache-2.0", + "authors": [{"name": "foolz", "email": "support@foolz.us"}], + "support": { + "email": "support@foolz.us", + "irc": "irc://irc.irchighway.net/fooldriver" + }, - "require" : { - "foolz/plugin": "dev" - }, + "require" : { + "foolz/plugin": "dev" + }, - "autoload": { - "psr-0": { - "Foolz\\Fake" : "classes/" - } - }, + "autoload": { + "psr-0": { + "Foolz\\Fake" : "classes/" + } + }, - "extra": { - "name": "Fake" - } -} \ No newline at end of file + "extra": { + "name": "Fake" + } +} diff --git a/tests/mock/foolz/fake/bootstrap.php b/tests/mock/foolz/fake/bootstrap.php index bfccd81..00a0132 100644 --- a/tests/mock/foolz/fake/bootstrap.php +++ b/tests/mock/foolz/fake/bootstrap.php @@ -1,26 +1,27 @@ setCall(function($result) { - $result->set('success'); - }); + ->setCall(function($result) { + $result->set('success'); + }); \Foolz\Plugin\Event::forge('foolz\plugin\plugin.execute.foolz/fake') - ->setCall(function($result) { - $result->set('success'); - }); + ->setCall(function($result) { + $result->set('success'); + }); \Foolz\Plugin\Event::forge('foolz\plugin\plugin.install.foolz/fake') - ->setCall(function($result) { - $result->set('success'); - }); + ->setCall(function($result) { + $result->set('success'); + }); \Foolz\Plugin\Event::forge('foolz\plugin\plugin.uninstall.foolz/fake') - ->setCall(function($result) { - $result->set('success'); - }); + ->setCall(function($result) { + $result->set('success'); + }); \Foolz\Plugin\Event::forge('foolz\plugin\plugin.upgrade.foolz/fake') - ->setCall(function($result) { - $result->set('success'); - }); \ No newline at end of file + ->setCall(function($result) { + $result->set('success'); + }); + \ No newline at end of file diff --git a/tests/mock/foolz/fake/classes/Foolz/Fake/Fake.php b/tests/mock/foolz/fake/classes/Foolz/Fake/Fake.php index 3c5f349..f86ddac 100644 --- a/tests/mock/foolz/fake/classes/Foolz/Fake/Fake.php +++ b/tests/mock/foolz/fake/classes/Foolz/Fake/Fake.php @@ -4,8 +4,8 @@ class Fake { - public static function fake() - { - return 'I am fake.'; - } -} \ No newline at end of file + public static function fake() + { + return 'I am a fraud.'; + } +} diff --git a/tests/mock/foolz/fake/composer.json b/tests/mock/foolz/fake/composer.json index ae02b07..561e001 100644 --- a/tests/mock/foolz/fake/composer.json +++ b/tests/mock/foolz/fake/composer.json @@ -1,27 +1,24 @@ { - "name": "foolz/fake", - "type": "foolz-plugin", - "description": "A fake plugin", - "keywords": ["fake", "mock"], - "homepage": "http://www.foolz.us", - "license": "Apache-2.0", - "authors": [{"name": "foolz", "email": "support@foolz.us"}], - "support": { - "email": "support@foolz.us", - "irc": "irc://irc.irchighway.net/fooldriver" - }, - - "require" : { - "foolz/plugin": "dev" - }, - - "autoload": { - "psr-0": { - "Foolz\\Fake" : "classes/" - } - }, - - "extra": { - "name": "Fake" - } -} \ No newline at end of file + "name": "foolz/fake", + "type": "foolz-plugin", + "description": "A fake plugin", + "keywords": ["fake", "mock"], + "homepage": "http://www.foolz.us", + "license": "Apache-2.0", + "authors": [{"name": "foolz", "email": "support@foolz.us"}], + "support": { + "email": "support@foolz.us", + "irc": "irc://irc.irchighway.net/fooldriver" + }, + "require" : { + "foolz/plugin": "dev" + }, + "autoload": { + "psr-0": { + "Foolz\\Fake" : "classes/" + } + }, + "extra": { + "name": "Fake" + } +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 0fca72b..97b774b 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,9 +1,9 @@ - - - classes - - + + + classes + + From ed1113f41a8137ff2e741bada137fb811d49f594 Mon Sep 17 00:00:00 2001 From: Kallef Alexandre de Souza Date: Sun, 28 Feb 2016 22:19:00 -0300 Subject: [PATCH 6/8] Some fix links and syntax (: Some fix links and syntax (: --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ce3c159..65f9c59 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ Some examples follow. You can go in-depth with these explanations with the following pages: -* [Hooks, Events and Results](Plugin/blob/master/hooks_events_results.md) -* [Plugin packages](Plugin/blob/master/plugin_packages.md) +* [Hooks, Events and Results](hooks_events_results.md) +* [Plugin packages](plugin_packages.md) ## Hooks and Events @@ -111,7 +111,7 @@ $loader = Loader::forge()->setDir('main', '/path/to/plugins/'); $enabled_plugins = array('foolz/fake', 'foolz/kynet'); -foreach ($loader->getPlugins('main') as $plugin) +foreach ($loader->getPlugins('main') as $plugin)) { if (in_array($plugin->getConfig('name'), $enabled_plugins) { @@ -120,4 +120,4 @@ foreach ($loader->getPlugins('main') as $plugin) } ``` -Get more info about [plugins](Plugin/blob/master/plugin_packages.md). +Get more info about [plugins](plugin_packages.md). From 2057ac44a107bd3791fe7fdb418f6bc9ffe5b057 Mon Sep 17 00:00:00 2001 From: Kallef Alexandre de Souza Date: Sun, 28 Feb 2016 22:27:24 -0300 Subject: [PATCH 7/8] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65f9c59..c065f1b 100644 --- a/README.md +++ b/README.md @@ -111,9 +111,9 @@ $loader = Loader::forge()->setDir('main', '/path/to/plugins/'); $enabled_plugins = array('foolz/fake', 'foolz/kynet'); -foreach ($loader->getPlugins('main') as $plugin)) +foreach ($loader->getPlugins('main') as $plugin) { - if (in_array($plugin->getConfig('name'), $enabled_plugins) + if (in_array($plugin->getConfig('name'), $enabled_plugins)) { $plugin->execute(); } From c545ca3ff5d0b807006192877cad17ff1857e078 Mon Sep 17 00:00:00 2001 From: Parallel Date: Sat, 5 Mar 2016 15:29:04 +0800 Subject: [PATCH 8/8] rturn=>return --- hooks_events_results.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks_events_results.md b/hooks_events_results.md index 9eee9dc..e0faa64 100644 --- a/hooks_events_results.md +++ b/hooks_events_results.md @@ -205,7 +205,7 @@ _Chainable_ Gets the parameter. * int|string _$key_ - The key that was given to the parameter -* bool _$orig_ - If true eturns the first assigned value of the parameter +* bool _$orig_ - If true returns the first assigned value of the parameter #### ->setParam($key, $value) @@ -228,4 +228,4 @@ Sets several parameters. * array _$array_ - An array of $key => $value -_Chainable_ \ No newline at end of file +_Chainable_