<commit_before><?php

namespace ZfcBase\Service;

use Zend\Loader\LocatorAware,
    Zend\EventManager\EventManagerAwareInterface,
    Zend\Di\LocatorInterface,
    Zend\EventManager\EventManagerInterface;

class ServiceAbstract implements LocatorAware, EventManagerAwareInterface {
    /**
     * @var EventManagerInterface
     */
    protected $events;
    
    /**
     * @var Zend\Loader\Locator;
     */
    protected $locator;
    
    public function setLocator(LocatorInterface $locator) {
        $this->locator = $locator;
    }
    
    public function getLocator() {
        return $this->locator;
    }
    
    /**
     * Set the event manager instance used by this context
     * 
     * @param  EventManagerInterface $events
     * @return mixed
     */
    public function setEventManager(EventManagerInterface $events)
    {
        $events->setIdentifiers(array(__CLASS__, get_class($this)));
        $this->events = $events;
        $this->attachDefaultListeners();
        return $this;
    }

    /**
     * Retrieve the event manager
     *
     * Lazy-loads an EventManager instance if none registered.
     * 
     * @return EventManagerInterface
     */
    public function events()
    {
        if (!$this->events instanceof EventManagerInterface) {
            $this->setEventManager(new EventManager());
        }
        return $this->events;
    }
    
    /**
     * Method merges return values of each listener's response into original $argv array and returns it.
     * 
     * @param string $event
     * @param array $argv
     * @param callback $callback
     * @return array 
     */
    protected function triggerParamsMergeEvent($event, $argv = array(), $callback = null)
    {
        $eventRet = $this->triggerEvent($event, $argv, $callback);
        foreach($eventRet as $event) {
            if(is_array($event) || $event instanceof Traversable) {
                $argv = array_merge_recursive($argv, $event);
            }
        }
        
        return $argv;
    }
    
    protected function triggerEvent($event, $argv = array(), $callback = null)
    {
        return $this->events()->trigger($event, $this, $argv, $callback);
    }
    
    protected function attachDefaultListeners()
    {
        
    }
    
}<commit_msg>refactor ServiceAbstract.php to reflect recent refactorings in ZF2<commit_after><?php

namespace ZfcBase\Service;

use Zend\ServiceManager\ServiceLocatorAwareInterface,
    Zend\ServiceManager\ServiceLocatorInterface,
    Zend\EventManager\EventManagerAwareInterface,
    Zend\EventManager\EventManagerInterface;

class ServiceAbstract implements ServiceLocatorAwareInterface, EventManagerAwareInterface {
    /**
     * @var EventManagerInterface
     */
    protected $events;
    
    /**
     * @var Zend\ServiceManager\ServiceManagerInterface;
     */
    protected $locator;
    
    public function setServiceLocator(ServiceLocatorInterface $locator) {
        $this->locator = $locator;
    }
    
    public function getServiceLocator() {
        return $this->locator;
    }
    
    /**
     * Set the event manager instance used by this context
     * 
     * @param  EventManagerInterface $events
     * @return mixed
     */
    public function setEventManager(EventManagerInterface $events)
    {
        $events->setIdentifiers(array(__CLASS__, get_class($this)));
        $this->events = $events;
        $this->attachDefaultListeners();
        return $this;
    }

    /**
     * Retrieve the event manager
     *
     * Lazy-loads an EventManager instance if none registered.
     * 
     * @return EventManagerInterface
     */
    public function events()
    {
        return $this->events;
    }
    
    /**
     * Method merges return values of each listener's response into original $argv array and returns it.
     * 
     * @param string $event
     * @param array $argv
     * @param callback $callback
     * @return array 
     */
    protected function triggerParamsMergeEvent($event, $argv = array(), $callback = null)
    {
        $eventRet = $this->triggerEvent($event, $argv, $callback);
        foreach($eventRet as $event) {
            if(is_array($event) || $event instanceof Traversable) {
                $argv = array_merge_recursive($argv, $event);
            }
        }
        
        return $argv;
    }
    
    protected function triggerEvent($event, $argv = array(), $callback = null)
    {
        return $this->events()->trigger($event, $this, $argv, $callback);
    }
    
    protected function attachDefaultListeners()
    {
        
    }
    
}

{'fraction_non_alphanumeric': 0.10534351145038168, 'fraction_numerical': 0.00021810250817884405, 'mean_word_length': 2.3720588235294118, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, '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': '3939762', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1255, 'n_words': 291}