1<?php
2/**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license   http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10namespace Zend\EventManager;
11
12/**
13 * Static version of EventManager
14 */
15class StaticEventManager extends SharedEventManager
16{
17    /**
18     * @var SharedEventManagerInterface
19     */
20    protected static $instance;
21
22    /**
23     * Singleton
24     */
25    protected function __construct()
26    {
27    }
28
29    /**
30     * Singleton
31     *
32     * @return void
33     */
34    private function __clone()
35    {
36    }
37
38    /**
39     * Retrieve instance
40     *
41     * @return StaticEventManager
42     */
43    public static function getInstance()
44    {
45        if (null === static::$instance) {
46            static::setInstance(new static());
47        }
48        return static::$instance;
49    }
50
51    /**
52     * Set the singleton to a specific SharedEventManagerInterface instance
53     *
54     * @param SharedEventManagerInterface $instance
55     * @return void
56     */
57    public static function setInstance(SharedEventManagerInterface $instance)
58    {
59        static::$instance = $instance;
60    }
61
62    /**
63     * Is a singleton instance defined?
64     *
65     * @return bool
66     */
67    public static function hasInstance()
68    {
69        return (static::$instance instanceof SharedEventManagerInterface);
70    }
71
72    /**
73     * Reset the singleton instance
74     *
75     * @return void
76     */
77    public static function resetInstance()
78    {
79        static::$instance = null;
80    }
81}
82