<commit_before><?php
/**
 * Events Manager
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @version 1.2.6
 * @package Phalcon
*/
namespace Phalcon\Events;

use \Phalcon\Events\ManagerInterface,
	\Phalcon\Events\Exception,
	\Phalcon\Events\Event,
	\SplPriorityQueue,
	\Closure;

/**
 * Phalcon\Events\Manager
 *
 * Phalcon Events Manager, offers an easy way to intercept and manipulate, if needed,
 * the normal flow of operation. With the EventsManager the developer can create hooks or
 * plugins that will offer monitoring of data, manipulation, conditional execution and much more.
 *
 * @see https://github.com/phalcon/cphalcon/blob/1.2.6/ext/events/manager.c
 */
class Manager implements ManagerInterface
{
	/**
	 * Events
	 * 
	 * @var array|null
	 * @access protected
	*/
	protected $_events;

	/**
	 * Collect
	 * 
	 * @var boolean
	 * @access protected
	*/
	protected $_collect = false;

	/**
	 * Enable Priorities
	 * 
	 * @var boolean
	 * @access protected
	*/
	protected $_enablePriorities = false;

	/**
	 * Responses
	 * 
	 * @var array|null
	 * @access protected
	*/
	protected $_responses;

	/**
	 * Attach a listener to the events manager
	 *
	 * @param string $eventType
	 * @param object|callable $handler
	 * @param int|null $priority
	 * @throws Exception
	 */
	public function attach($eventType, $handler, $priority = null)
	{
		if(is_null($priority) === true) {
			$priority = 100;
		} elseif(is_int($priority) === false) {
			throw new Exception('Invalid parameter type.');
		}

		if(is_string($eventType) === false) {
			throw new Exception('Event type must be a string');
		}

		if(is_object($handler) === false &&
			is_callable($handler) === false) {
			throw new Exception('Event handler must be an Object');
		}

		if(is_array($this->_events) === false) {
			$this->_events = array();
		}

		if(isset($this->_events[$eventType]) === false) {
			if($this->_enablePriorities === true) {
				//Create a SplPriorityQueue to store the events with priorities
				$priorityQueue = new SplPriorityQueue();
				$priorityQueue->setExtractFlags(1);
				$this->_events[$eventType] = $priorityQueue;
			} else {
				$this->_events[$eventType] = array();
			}
		}

		//Get the current queue
		$priorityQueue = $this->_events[$eventType];

		//Insert the handler in the queue
		if(is_object($priorityQueue) === true) {
			//Pointer usage
			$priorityQueue->insert($handler, $priority);
		} else {
			$priorityQueue[] = $handler;

			//Append the events to the queue
			$this->_events[$eventType] = $priorityQueue;
		}
	}

	/**
	 * Set if priorities are enabled in the EventsManager
	 *
	 * @param boolean $enablePriorities
	 * @throws Exception
	 */
	public function enablePriorities($enablePriorities)
	{
		if(is_bool($enablePriorities) === false) {
			throw new Exception('Invalid parameter type.');
		}

		$this->_enablePriorities = $enablePriorities;
	}

	/**
	 * Returns if priorities are enabled
	 *
	 * @return boolean
	 */
	public function arePrioritiesEnabled()
	{
		return $this->_enablePriorities;
	}

	/**
	 * Tells the event manager if it needs to collect all the responses returned by every
	 * registered listener in a single fire
	 *
	 * @param boolean $collect
	 * @throws Exception
	 */
	public function collectResponses($collect)
	{
		if(is_bool($collect) === false) {
			throw new Exception('Invalid parameter type.');
		}
		$this->_collect = $collect;
	}

	/**
	 * Check if the events manager is collecting all all the responses returned by every
	 * registered listener in a single fire
	 * 
	 * @return boolean
	 */
	public function isCollecting()
	{
		return $this->_collect;
	}

	/**
	 * Returns all the responses returned by every handler executed by the last 'fire' executed
	 *
	 * @return array|null
	 */
	public function getResponses()
	{
		return $this->_responses;
	}

	/**
	 * Removes all events from the EventsManager
	 *
	 * @param string|null $type
	 * @throws Exception
	 */
	public function detachAll($type = null)
	{
		if(is_null($type) === true) {
			unset($this->_events);
		} elseif(is_string($type) === true) {
			unset($this->_events[$type]);
		} else {<commit_msg>[Unit Tests #38] Fixed attribute removal<commit_after><?php
/**
 * Events Manager
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @version 1.2.6
 * @package Phalcon
*/
namespace Phalcon\Events;

use \Phalcon\Events\ManagerInterface,
	\Phalcon\Events\Exception,
	\Phalcon\Events\Event,
	\SplPriorityQueue,
	\Closure;

/**
 * Phalcon\Events\Manager
 *
 * Phalcon Events Manager, offers an easy way to intercept and manipulate, if needed,
 * the normal flow of operation. With the EventsManager the developer can create hooks or
 * plugins that will offer monitoring of data, manipulation, conditional execution and much more.
 *
 * @see https://github.com/phalcon/cphalcon/blob/1.2.6/ext/events/manager.c
 */
class Manager implements ManagerInterface
{
	/**
	 * Events
	 * 
	 * @var array|null
	 * @access protected
	*/
	protected $_events;

	/**
	 * Collect
	 * 
	 * @var boolean
	 * @access protected
	*/
	protected $_collect = false;

	/**
	 * Enable Priorities
	 * 
	 * @var boolean
	 * @access protected
	*/
	protected $_enablePriorities = false;

	/**
	 * Responses
	 * 
	 * @var array|null
	 * @access protected
	*/
	protected $_responses;

	/**
	 * Attach a listener to the events manager
	 *
	 * @param string $eventType
	 * @param object|callable $handler
	 * @param int|null $priority
	 * @throws Exception
	 */
	public function attach($eventType, $handler, $priority = null)
	{
		if(is_null($priority) === true) {
			$priority = 100;
		} elseif(is_int($priority) === false) {
			throw new Exception('Invalid parameter type.');
		}

		if(is_string($eventType) === false) {
			throw new Exception('Event type must be a string');
		}

		if(is_object($handler) === false &&
			is_callable($handler) === false) {
			throw new Exception('Event handler must be an Object');
		}

		if(is_array($this->_events) === false) {
			$this->_events = array();
		}

		if(isset($this->_events[$eventType]) === false) {
			if($this->_enablePriorities === true) {
				//Create a SplPriorityQueue to store the events with priorities
				$priorityQueue = new SplPriorityQueue();
				$priorityQueue->setExtractFlags(1);
				$this->_events[$eventType] = $priorityQueue;
			} else {
				$this->_events[$eventType] = array();
			}
		}

		//Get the current queue
		$priorityQueue = $this->_events[$eventType];

		//Insert the handler in the queue
		if(is_object($priorityQueue) === true) {
			//Pointer usage
			$priorityQueue->insert($handler, $priority);
		} else {
			$priorityQueue[] = $handler;

			//Append the events to the queue
			$this->_events[$eventType] = $priorityQueue;
		}
	}

	/**
	 * Set if priorities are enabled in the EventsManager
	 *
	 * @param boolean $enablePriorities
	 * @throws Exception
	 */
	public function enablePriorities($enablePriorities)
	{
		if(is_bool($enablePriorities) === false) {
			throw new Exception('Invalid parameter type.');
		}

		$this->_enablePriorities = $enablePriorities;
	}

	/**
	 * Returns if priorities are enabled
	 *
	 * @return boolean
	 */
	public function arePrioritiesEnabled()
	{
		return $this->_enablePriorities;
	}

	/**
	 * Tells the event manager if it needs to collect all the responses returned by every
	 * registered listener in a single fire
	 *
	 * @param boolean $collect
	 * @throws Exception
	 */
	public function collectResponses($collect)
	{
		if(is_bool($collect) === false) {
			throw new Exception('Invalid parameter type.');
		}
		$this->_collect = $collect;
	}

	/**
	 * Check if the events manager is collecting all all the responses returned by every
	 * registered listener in a single fire
	 * 
	 * @return boolean
	 */
	public function isCollecting()
	{
		return $this->_collect;
	}

	/**
	 * Returns all the responses returned by every handler executed by the last 'fire' executed
	 *
	 * @return array|null
	 */
	public function getResponses()
	{
		return $this->_responses;
	}

	/**
	 * Removes all events from the EventsManager
	 *
	 * @param string|null $type
	 * @throws Exception
	 */
	public function detachAll($type = null)
	{
		if(is_null($type) === true) {
			$this->_events = null;
		} elseif(is_string($type) === true) {
			unset($this->_events[$type]);
		} else {
{'fraction_non_alphanumeric': 0.13637994975475534, 'fraction_numerical': 0.002631893767197033, 'mean_word_length': 3.5238095238095237, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 55, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '5875827', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2505, 'n_words': 724}