Location: PHPKode > scripts > Redstart Templating > Redstart-Templating-master/Redstart/Templating/Plugin/PluginList.php
<?php

namespace Redstart\Templating\Plugin;

/**
 * Plugin List
 *
 * @package Redstart    
 * @subpackage Redstart_Templating_Plugin
 *
 * @author Hyyan Abo Fakher
 * @since Redstart 1.0
 */
class PluginList implements PluginListInterface {

    /**
     * Plugin list
     * @var array 
     */
    protected $plugins = array();

    /**
     * Constrcut New Plugin List
     */
    public function __construct() {
        
    }

    /**
     * Add plugin to the plugin list
     * @param \Redstart\Templating\PluginInterface $plugin
     * @throws \LogicException if plugin's name is in use
     * @return \Redstart\Templating\Plugin\PluginList
     */
    public function addPlugin(PluginInterface $plugin) {
        $name = $plugin->getName();
        if ($this->has($name)) {
            throw new \LogicException(
            sprintf("Plugin Name (%s) Is In Use", $name)
            );
        }
        $this->plugins[$name] = $plugin;
        return $this;
    }

    /**
     * Set array of plugins
     * 
     * @see PluginList::addPlugin()
     * 
     * @param array $plugins
     * @return \Redstart\Templating\Plugin\PluginList
     */
    public function setPlugin(array $plugins) {
        foreach ($plugins as $plugin) {
            $this->addPlugin($plugin);
        }
        return $this;
    }

    /**
     * Add plugin list
     * @param \Redstart\Templating\Plugin\PluginListInterface $list
     */
    public function addPluginList(PluginListInterface $list) {
        $this->setPlugin(iterator_to_array($list->getIterator()));
    }

    /**
     * Get plugin from the plugin list
     * 
     * @param strng $name plugin name 
     * @return \Redstart\Templating\PluginInterface|false
     */
    public function get($name) {
        if ($this->has($name)) {
            return $this->plugins[$name];
        }
        return false;
    }

    /**
     * Check if the plugin name is in the plugin list
     * 
     * @param string $name plugin name
     * @return boolean
     */
    public function has($name) {
        return isset($this->plugins[$name]);
    }

    /**
     * Remove plugn by name from the plugin set
     * 
     * @param string $name plugin name
     * @return boolean true if removed false otherwise
     */
    public function remove($name) {
        if ($this->has($name)) {
            unset($this->plugins[$name]);
            return true;
        }
        return false;
    }

    /**
     * Clear the plugin list
     * @return \Redstart\Templating\Plugin\PluginList
     */
    public function clear() {
        $this->plugins = array();
        return $this;
    }

    /**
     * Get Plugins number in the plugin list
     */
    public function count() {
        return count($this->plugins);
    }

    /**
     * Serialize the plugin list
     * @return string
     */
    public function serialize() {
        return serialize($this->plugins);
    }

    /**
     * Unserialize the plugin list
     * @param string $serialized
     */
    public function unserialize($serialized) {
        $this->plugins = unserialize($serialized);
    }

    /**
     * Get Iterator
     * @return \ArrayIterator
     */
    public function getIterator() {
        return new \ArrayIterator($this->plugins);
    }

}

Return current item: Redstart Templating