1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 
<?php
namespace Omeka\ServiceManager;

use Zend\EventManager\EventManagerAwareTrait;
use Zend\ServiceManager\AbstractPluginManager as ZendAbstractPluginManager;
use Zend\EventManager\Event;

abstract class AbstractPluginManager extends ZendAbstractPluginManager
{
    use EventManagerAwareTrait;

    /**
     * Sorted array of service names. Names specified here are sorted
     * accordingly in the getRegisteredNames output. Names not specified
     * are left in their natural order.
     *
     * @var array
     */
    protected $sortedNames = [];

    public function __construct($configOrContainerInterface = null, array $v3config = [])
    {
        parent::__construct($configOrContainerInterface, $v3config);
        $this->setEventManager($configOrContainerInterface->get('EventManager'));

        if (isset($v3config['sorted_names'])) {
            $this->sortedNames = $v3config['sorted_names'];
        }
    }
    /**
     * Get registered names.
     *
     * An alternative to parent::getCanonicalNames(). Returns only the names
     * that are registered in configuration as invokable classes and factories.
     * The list many be modified during the service.registered_names event.
     *
     * @return array
     */
    public function getRegisteredNames()
    {
        $aliases = $this->aliases;
        $registeredNames = array_keys($aliases);
        foreach ($this->factories as $key => $value) {
            if (!in_array($key, $aliases)) {
                $registeredNames[] = $key;
            }
        }
        $registeredNames = array_merge($this->sortedNames, array_diff($registeredNames, $this->sortedNames));
        $args = $this->getEventManager()->prepareArgs([
            'registered_names' => $registeredNames,
        ]);
        $this->getEventManager()->trigger('service.registered_names', $this, $args);
        return $args['registered_names'];
    }
}