<commit_before><?php
/**
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace VXML\Rule;

use VXML\Event;
use VXML\Response;
use VXML\Context;
use VXML\Rule;

abstract class RuleAbstract implements Rule
{
    /**
     * Relative target of the rule, to be applied to the context
     * 
     * @var array
     */
    private $_target = array();
    
    /**
     * Last target of the rule, after it has been applied to the context
     * WARNING: This can change for rules that are applied multiple times
     * e.g. by Iterator
     * 
     * @var array
     */
    private $_resolvedTargets = array();
    
    /**
     * Rules options
     * 
     * @var array
     */
    private $_options = array();
    
    /**
     * Rules and callbacks listening to this rules events
     * 
     * @var array
     */
    private $_eventListeners = array();
    
// MAGIC
    /**
     * @param mixed $target
     * @param array $options OPTIONAL
     */
    public function __construct($target, $options = array())
    {
        $this->setRelativeTarget($target);
        $this->addOption('message', false);
        $this->initialize();
        
        $this->setOptions($options);
    }
    
// PUBLIC
    /**
     * To be implemented by a composite rule
     * 
     * @param Rule $rule
     * @return Rule
     */
    public function add($rule)
    {
        throw new \Exception('not supported');
    }
    
    /**
     * Add a rule or callback to an event
     * 
     * @param string $event
     * @param string|Rule $rule
     * @return $rule
     */
    public function addListener($event, $rule)
    {
        return $this->_eventListeners[$event][] = $rule;
    }
    
    /**
     * Evaluate rule and invoke events and setup context
     * 
     * @param Context $context
     * @param Response $response
     * @return boolean
     */
    public function execute(Context $context, Response $response)
    {<commit_msg>Add onValid listener shortcut<commit_after><?php
/**
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace VXML\Rule;

use VXML\Event;
use VXML\Response;
use VXML\Context;
use VXML\Rule;

abstract class RuleAbstract implements Rule
{
    /**
     * Relative target of the rule, to be applied to the context
     * 
     * @var array
     */
    private $_target = array();
    
    /**
     * Last target of the rule, after it has been applied to the context
     * WARNING: This can change for rules that are applied multiple times
     * e.g. by Iterator
     * 
     * @var array
     */
    private $_resolvedTargets = array();
    
    /**
     * Rules options
     * 
     * @var array
     */
    private $_options = array();
    
    /**
     * Rules and callbacks listening to this rules events
     * 
     * @var array
     */
    private $_eventListeners = array();
    
// MAGIC
    /**
     * @param mixed $target
     * @param array $options OPTIONAL
     */
    public function __construct($target, $options = array())
    {
        $this->setRelativeTarget($target);
        $this->addOption('message', false);
        $this->initialize();
        
        $this->setOptions($options);
    }
    
// PUBLIC
    /**
     * To be implemented by a composite rule
     * 
     * @param Rule $rule
     * @return Rule
     */
    public function add($rule)
    {
        throw new \Exception('not supported');
    }
    
    /**
     * Add a rule or callback to an event
     * 
     * @param string $event
     * @param string|Rule $rule
     * @return Rule
     */
    public function addListener($event, $rule)
    {
        return $this->_eventListeners[$event][] = $rule;
    }

    /**
     *
     * @param <type> $rule
     * @return Rule
     */
    public function onValid($rule)
    {
        return $this->addListener('valid', $rule);
    }
    
    /**
     * Evaluate rule and invoke events and setup context
     * 
     * @param Context $context
     * @param Response $response
     * @return boolean
     */
    public function execute(Context $context, Response $response)
    {
{'fraction_non_alphanumeric': 0.10531457600625244, 'fraction_numerical': 0.0031262211801484957, 'mean_word_length': 2.171623296158612, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2628600', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1405, 'n_words': 510}