<commit_before><?php
/**
* @version		$Id$
* @category		Koowa
* @package      Koowa_Filter
* @copyright    Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
* @license      GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link 		http://www.nooku.org
*/

/**
 * Abstract filter.
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Filter
 */
abstract class KFilterAbstract implements KFilterInterface
{
	/**
	 * The filter chain
	 *
	 * @var	object
	 */
	protected $_chain = null;
	
	/**
	 * If the data to be santized or validated if an object or array,
	 * walk over each individual property or element. Default TRUE.
	 *
	 * @var	boolean
	 */
	protected $_walk = true;
	
	/**
	 * Constructor
	 *
	 * @param 	object	An optional KConfig object with configuration options
	 */
	public function __construct(KConfig $config) 
	{
		 $this->_chain = new KFilterChain();
		 $this->addFilter($this);
		 
		$this->_initialize($config);
	}
	
 	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options.
     * @return 	void
     */
    protected function _initialize(KConfig $config)
    {
    	//do nothing
    }
	
	/**
	 * Command handler
	 * 
	 * @param string  The command name
	 * @param object  The command context
	 *
	 * @return object
	 */
	final public function execute($name, KCommandContext $context) 
	{	
		$function = '_'.$name;
		return $this->$function($context->data);
	}

	/**
	 * Validate a variable or data collection
	 *
	 * @param	mixed	Data to be validated<commit_msg>re #135 : KFilterInterface now implements KObjectIdentifiable and KObjectInstantiatable. Filters are now singletons by default.<commit_after><?php
/**
* @version		$Id$
* @category		Koowa
* @package      Koowa_Filter
* @copyright    Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
* @license      GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link 		http://www.nooku.org
*/

/**
 * Abstract filter.
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Filter
 */
abstract class KFilterAbstract implements KFilterInterface
{
	/**
	 * The filter chain
	 *
	 * @var	object
	 */
	protected $_chain = null;
	
	/**
	 * If the data to be santized or validated if an object or array,
	 * walk over each individual property or element. Default TRUE.
	 *
	 * @var	boolean
	 */
	protected $_walk = true;
	
	/**
     * The object identifier
     *
     * @var KIdentifierInterface
     */
    protected $_identifier;
	
	/**
	 * Constructor
	 *
	 * @param 	object	An optional KConfig object with configuration options
	 */
	public function __construct(KConfig $config) 
	{
		 $this->_chain = new KFilterChain();
		 $this->addFilter($this);
		 
		$this->_initialize($config);
	}
	
 	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options.
     * @return 	void
     */
    protected function _initialize(KConfig $config)
    {
    	//do nothing
    }
    
	/**
     * Get the object identifier
     * 
     * @return  KIdentifier 
     * @see     KObjectIdentifiable
     */
    public function getIdentifier()
    {
        return $this->_identifier;
    }
    
	/**
     * Force creation of a singleton
     *
     * @return KDatabaseTableDefault
     */
    public static function getInstance($config = array())
    {
        static $instance;
        
        if ($instance === NULL) 
        {
            //Create the singleton
            $classname = $config->identifier->classname;
            $instance = new $classname($config);
        }
        
        return $instance;
    }
	
	/**
	 * Command handler
	 * 
	 * @param string  The command name
	 * @param object  The command context
	 *
	 * @return object
	 */
	final public function execute($name, KCommandContext $context) 
	{	
		$function = '_'.$name;
		return $this->$function($context->data);
	}

	/**
	 * Validate a variable or data collection
	 *
	 * @param	mixed	Data to be validated
{'fraction_non_alphanumeric': 0.11480075901328274, 'fraction_numerical': 0.004981024667931689, 'mean_word_length': 2.511240632805995, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613117', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1232, 'n_words': 379}