Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
21 / 21
Loader
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
21 / 21
 add_action
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 get_actions
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 add_filter
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 get_filters
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 componentify
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 run
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
9 / 9
<?php
/**
 * Loader Class
 *
 * @category    PHP
 * @package     WpWodify
 * @subpackage  Loader
 * @since       File available since release 1.0.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
namespace WpWodify;
/**
 * Loader Class
 *
 * @category    PHP
 * @package     WpWodify
 * @subpackage  Loader
 * @since       Class available since release 1.0.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class Loader {
    /**
     * A list of actions to add.
     *
     * @var array
     */
    protected $actions = array();
    /**
     * A list of filters to add.
     *
     * @var array
     */
    protected $filters = array();
    /**
     * Adds an action to the list of actions.
     *
     * @param string $hook The name of the hook to implement
     * @param mixed $component The class instance which a callback will be called on.
     * @param string $callback Name of the method to call on the component.
     *
     * @return WpWodify\Overlord Returns $this, for object-chaining.
     */
    public function add_action( $hook, $component, $callback ) {
        $this->actions[] = $this->componentify( $hook, $component, $callback );
        return $this;
    }
    /**
     * Gets the actions,
     *
     * @return array The array of actions.
     */
    public function get_actions() {
        return $this->actions;
    }
    /**
     * Adds an filter to the list of filters.
     *
     * @param string $hook The name of the hook to implement
     * @param mixed $component The class instance which a callback will be called on.
     * @param string $callback Name of the method to call on the component.
     *
     * @return WpWodify\Overlord Returns $this, for object-chaining.
     */
    public function add_filter( $hook, $component, $callback ) {
        $this->filters[] = $this->componentify( $hook, $component, $callback );
        return $this;
    }
    /**
     * Gets the filters,
     *
     * @return array The array of filters.
     */
    public function get_filters() {
        return $this->filters;
    }
    /**
     * Takes string arguments, and turns them into an standardized array.
     *
     * @param string $hook the name of a wordpress hook
     * @param mixed $component A class instance.
     * @param string $callback The name of a method to call on the component.
     *
     * @return array The resulting array.
     */
    protected function componentify( $hook, $component, $callback ) {
        $result = array(
            'hook'          => $hook,
            'function'      => array( $component, $callback ),
            'priority'      => 10,
            'accepted_args' => 1,
        );
        return $result;
    }
    /**
     * Runs the loader.
     *
     * @return WpWodify\Loader Returns $this, for object-chaining.
     */
    public function run() {
        $filters = $this->get_filters();
        $actions = $this->get_actions();
        foreach ($filters as $filter) {
           \add_filter($filter['hook'], $filter['function']);
        }
        foreach ($actions as $action) {
            \add_filter($action['hook'], $action['function']);
        }
        return $this;
    }
}