Location: PHPKode > scripts > Redstart Templating > Redstart-Templating-master/Redstart/Templating/Escape/EscapeHandler.php
<?php

namespace Redstart\Templating\Escape;

/**
 * Escape Handler
 * 
 * @package Redstart    
 * @subpackage Redstart_Templating_Escape
 *
 * @author Hyyan Abo Fakher
 * @since Redstart 1.0
 * @version 1.0
 */
class EscapeHandler implements EscapeHandlerInterface {

    private $escapelist;

    /**
     * Constrcut new escape handler
     * @param \Redstart\Templating\Escape\EscapeListInterface $list defaut is 
     * <tt>EscapeList</tt> with <tt>htmlspecialchars()</tt> listener
     */
    public function __construct(EscapeListInterface $list = null) {
        $this->setEscapeList(
                $list === null ? new EscapeList() : $list
        );
    }

    /**
     * Set escape list
     * @param \Redstart\Templating\Escape\EscapeListInterface $list
     */
    public function setEscapeList(EscapeListInterface $list) {
        $this->escapelist = $list;
    }

    /**
     * Get escape list
     * @return \Redstart\Templating\Escape\EscapeListInterface 
     */
    public function getEscapeList() {
        return $this->escapelist;
    }

    /**
     * Applies escaping to a value.
     * 
     * @param string $value the value to apply escaping to it
     * @param array $listeners array of listeners to overide predefined escaping
     *                         listeners
     * 
     * @return string escaped value
     */
    public function escape($value, array $listeners = array()) {
        $result = (string) $value;
        if (empty($listeners)) {
            foreach ($this->getEscapeList() as $listener) {
                $result = call_user_func($listener, $result);
            }
        } else {
            foreach ($listeners as $listener) {
                $result = call_user_func($listener, $result);
            }
        }
        return $result;
    }

}

Return current item: Redstart Templating