Completed
Branch FET/asset-manager (018c4e)
by
unknown
87:46 queued 74:14
created
core/services/loaders/CachingLoader.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $identifier = ''
54 54
     ) {
55 55
         parent::__construct($loader);
56
-        $this->cache       = $cache;
56
+        $this->cache = $cache;
57 57
         $this->object_identifier = $object_identifier;
58 58
         $this->setIdentifier($identifier);
59 59
         if ($this->identifier !== '') {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     private function setIdentifier($identifier)
91 91
     {
92
-        if (! is_string($identifier)) {
92
+        if ( ! is_string($identifier)) {
93 93
             throw new InvalidDataTypeException('$identifier', $identifier, 'string');
94 94
         }
95 95
         $this->identifier = $identifier;
Please login to merge, or discard this patch.
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -21,158 +21,158 @@
 block discarded – undo
21 21
 class CachingLoader extends CachingLoaderDecorator
22 22
 {
23 23
 
24
-    /**
25
-     * @var string $identifier
26
-     */
27
-    protected $identifier;
28
-
29
-    /**
30
-     * @var CollectionInterface $cache
31
-     */
32
-    protected $cache;
33
-
34
-    /**
35
-     * @var ObjectIdentifier
36
-     */
37
-    private $object_identifier;
38
-
39
-
40
-    /**
41
-     * CachingLoader constructor.
42
-     *
43
-     * @param LoaderDecoratorInterface $loader
44
-     * @param CollectionInterface      $cache
45
-     * @param ObjectIdentifier         $object_identifier
46
-     * @param string                   $identifier
47
-     * @throws InvalidDataTypeException
48
-     */
49
-    public function __construct(
50
-        LoaderDecoratorInterface $loader,
51
-        CollectionInterface $cache,
52
-        ObjectIdentifier $object_identifier,
53
-        $identifier = ''
54
-    ) {
55
-        parent::__construct($loader);
56
-        $this->cache       = $cache;
57
-        $this->object_identifier = $object_identifier;
58
-        $this->setIdentifier($identifier);
59
-        if ($this->identifier !== '') {
60
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
61
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
62
-            // where "IDENTIFIER" = the string that was set during construction
63
-            add_action(
64
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
65
-                array($this, 'reset')
66
-            );
67
-        }
68
-        // to clear ALL caches, simply do the following:
69
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
70
-        add_action(
71
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
72
-            array($this, 'reset')
73
-        );
74
-    }
75
-
76
-
77
-    /**
78
-     * @return string
79
-     */
80
-    public function identifier()
81
-    {
82
-        return $this->identifier;
83
-    }
84
-
85
-
86
-    /**
87
-     * @param string $identifier
88
-     * @throws InvalidDataTypeException
89
-     */
90
-    private function setIdentifier($identifier)
91
-    {
92
-        if (! is_string($identifier)) {
93
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
94
-        }
95
-        $this->identifier = $identifier;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param FullyQualifiedName|string $fqcn
101
-     * @param mixed                     $object
102
-     * @return bool
103
-     * @throws InvalidArgumentException
104
-     */
105
-    public function share($fqcn, $object)
106
-    {
107
-        if ($object instanceof $fqcn) {
108
-            return $this->cache->add($object, md5($fqcn));
109
-        }
110
-        throw new InvalidArgumentException(
111
-            sprintf(
112
-                esc_html__(
113
-                    'The supplied class name "%1$s" must match the class of the supplied object.',
114
-                    'event_espresso'
115
-                ),
116
-                $fqcn
117
-            )
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * @param FullyQualifiedName|string $fqcn
124
-     * @param array                     $arguments
125
-     * @param bool                      $shared
126
-     * @param array                     $interfaces
127
-     * @return mixed
128
-     */
129
-    public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
130
-    {
131
-        $fqcn = ltrim($fqcn, '\\');
132
-        // caching can be turned off via the following code:
133
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
134
-        if (
135
-            apply_filters(
136
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
137
-                false,
138
-                $this
139
-            )
140
-        ) {
141
-            // even though $shared might be true, caching could be bypassed for whatever reason,
142
-            // so we don't want the core loader to cache anything, therefore caching is turned off
143
-            return $this->loader->load($fqcn, $arguments, false);
144
-        }
145
-        $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
146
-        if ($this->cache->has($object_identifier)) {
147
-            return $this->cache->get($object_identifier);
148
-        }
149
-        $object = $this->loader->load($fqcn, $arguments, $shared);
150
-        if ($object instanceof $fqcn) {
151
-            $this->cache->add($object, $object_identifier);
152
-        }
153
-        return $object;
154
-    }
155
-
156
-
157
-    /**
158
-     * empties cache and calls reset() on loader if method exists
159
-     */
160
-    public function reset()
161
-    {
162
-        $this->clearCache();
163
-        $this->loader->reset();
164
-    }
165
-
166
-
167
-    /**
168
-     * unsets and detaches ALL objects from the cache
169
-     *
170
-     * @since $VID:$
171
-     */
172
-    public function clearCache()
173
-    {
174
-        $this->cache->trashAndDetachAll();
175
-    }
24
+	/**
25
+	 * @var string $identifier
26
+	 */
27
+	protected $identifier;
28
+
29
+	/**
30
+	 * @var CollectionInterface $cache
31
+	 */
32
+	protected $cache;
33
+
34
+	/**
35
+	 * @var ObjectIdentifier
36
+	 */
37
+	private $object_identifier;
38
+
39
+
40
+	/**
41
+	 * CachingLoader constructor.
42
+	 *
43
+	 * @param LoaderDecoratorInterface $loader
44
+	 * @param CollectionInterface      $cache
45
+	 * @param ObjectIdentifier         $object_identifier
46
+	 * @param string                   $identifier
47
+	 * @throws InvalidDataTypeException
48
+	 */
49
+	public function __construct(
50
+		LoaderDecoratorInterface $loader,
51
+		CollectionInterface $cache,
52
+		ObjectIdentifier $object_identifier,
53
+		$identifier = ''
54
+	) {
55
+		parent::__construct($loader);
56
+		$this->cache       = $cache;
57
+		$this->object_identifier = $object_identifier;
58
+		$this->setIdentifier($identifier);
59
+		if ($this->identifier !== '') {
60
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
61
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
62
+			// where "IDENTIFIER" = the string that was set during construction
63
+			add_action(
64
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
65
+				array($this, 'reset')
66
+			);
67
+		}
68
+		// to clear ALL caches, simply do the following:
69
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
70
+		add_action(
71
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
72
+			array($this, 'reset')
73
+		);
74
+	}
75
+
76
+
77
+	/**
78
+	 * @return string
79
+	 */
80
+	public function identifier()
81
+	{
82
+		return $this->identifier;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @param string $identifier
88
+	 * @throws InvalidDataTypeException
89
+	 */
90
+	private function setIdentifier($identifier)
91
+	{
92
+		if (! is_string($identifier)) {
93
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
94
+		}
95
+		$this->identifier = $identifier;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param FullyQualifiedName|string $fqcn
101
+	 * @param mixed                     $object
102
+	 * @return bool
103
+	 * @throws InvalidArgumentException
104
+	 */
105
+	public function share($fqcn, $object)
106
+	{
107
+		if ($object instanceof $fqcn) {
108
+			return $this->cache->add($object, md5($fqcn));
109
+		}
110
+		throw new InvalidArgumentException(
111
+			sprintf(
112
+				esc_html__(
113
+					'The supplied class name "%1$s" must match the class of the supplied object.',
114
+					'event_espresso'
115
+				),
116
+				$fqcn
117
+			)
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @param FullyQualifiedName|string $fqcn
124
+	 * @param array                     $arguments
125
+	 * @param bool                      $shared
126
+	 * @param array                     $interfaces
127
+	 * @return mixed
128
+	 */
129
+	public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
130
+	{
131
+		$fqcn = ltrim($fqcn, '\\');
132
+		// caching can be turned off via the following code:
133
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
134
+		if (
135
+			apply_filters(
136
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
137
+				false,
138
+				$this
139
+			)
140
+		) {
141
+			// even though $shared might be true, caching could be bypassed for whatever reason,
142
+			// so we don't want the core loader to cache anything, therefore caching is turned off
143
+			return $this->loader->load($fqcn, $arguments, false);
144
+		}
145
+		$object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
146
+		if ($this->cache->has($object_identifier)) {
147
+			return $this->cache->get($object_identifier);
148
+		}
149
+		$object = $this->loader->load($fqcn, $arguments, $shared);
150
+		if ($object instanceof $fqcn) {
151
+			$this->cache->add($object, $object_identifier);
152
+		}
153
+		return $object;
154
+	}
155
+
156
+
157
+	/**
158
+	 * empties cache and calls reset() on loader if method exists
159
+	 */
160
+	public function reset()
161
+	{
162
+		$this->clearCache();
163
+		$this->loader->reset();
164
+	}
165
+
166
+
167
+	/**
168
+	 * unsets and detaches ALL objects from the cache
169
+	 *
170
+	 * @since $VID:$
171
+	 */
172
+	public function clearCache()
173
+	{
174
+		$this->cache->trashAndDetachAll();
175
+	}
176 176
 }
177 177
 // End of file CachingLoader.php
178 178
 // Location: EventEspresso\core\services\loaders/CachingLoader.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderFactory.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -80,47 +80,47 @@
 block discarded – undo
80 80
 class LoaderFactory
81 81
 {
82 82
 
83
-    /**
84
-     * @var LoaderInterface $loader ;
85
-     */
86
-    private static $loader;
83
+	/**
84
+	 * @var LoaderInterface $loader ;
85
+	 */
86
+	private static $loader;
87 87
 
88 88
 
89
-    /**
90
-     * @param EE_Registry|CoffeeShop   $generator   provided during very first instantiation in
91
-     *                                              BootstrapDependencyInjectionContainer::buildLoader()
92
-     *                                              otherwise can be left null
93
-     * @param ClassInterfaceCache|null $class_cache also provided during first instantiation
94
-     * @param ObjectIdentifier|null    $object_identifier
95
-     * @return LoaderInterface
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     */
100
-    public static function getLoader(
101
-        $generator = null,
102
-        ClassInterfaceCache $class_cache = null,
103
-        ObjectIdentifier $object_identifier = null
104
-    ) {
105
-        if (
106
-            ! LoaderFactory::$loader instanceof LoaderInterface
107
-            && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)
108
-            && $class_cache instanceof ClassInterfaceCache
109
-            && $object_identifier instanceof ObjectIdentifier
110
-        ) {
111
-            $core_loader = new CoreLoader($generator);
112
-            LoaderFactory::$loader = new Loader(
113
-                $core_loader,
114
-                new CachingLoader(
115
-                    $core_loader,
116
-                    new LooseCollection(''),
117
-                    $object_identifier
118
-                ),
119
-                $class_cache
120
-            );
121
-        }
122
-        return LoaderFactory::$loader;
123
-    }
89
+	/**
90
+	 * @param EE_Registry|CoffeeShop   $generator   provided during very first instantiation in
91
+	 *                                              BootstrapDependencyInjectionContainer::buildLoader()
92
+	 *                                              otherwise can be left null
93
+	 * @param ClassInterfaceCache|null $class_cache also provided during first instantiation
94
+	 * @param ObjectIdentifier|null    $object_identifier
95
+	 * @return LoaderInterface
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 */
100
+	public static function getLoader(
101
+		$generator = null,
102
+		ClassInterfaceCache $class_cache = null,
103
+		ObjectIdentifier $object_identifier = null
104
+	) {
105
+		if (
106
+			! LoaderFactory::$loader instanceof LoaderInterface
107
+			&& ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)
108
+			&& $class_cache instanceof ClassInterfaceCache
109
+			&& $object_identifier instanceof ObjectIdentifier
110
+		) {
111
+			$core_loader = new CoreLoader($generator);
112
+			LoaderFactory::$loader = new Loader(
113
+				$core_loader,
114
+				new CachingLoader(
115
+					$core_loader,
116
+					new LooseCollection(''),
117
+					$object_identifier
118
+				),
119
+				$class_cache
120
+			);
121
+		}
122
+		return LoaderFactory::$loader;
123
+	}
124 124
 
125 125
 
126 126
 }
Please login to merge, or discard this patch.
core/services/loaders/ObjectIdentifier.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -20,113 +20,113 @@
 block discarded – undo
20 20
 class ObjectIdentifier
21 21
 {
22 22
 
23
-    /**
24
-     * used to separate the FQCN from the class's arguments identifier
25
-     */
26
-    const DELIMITER = '____';
27
-
28
-    /**
29
-     * @var ClassInterfaceCache $class_cache
30
-     */
31
-    private $class_cache;
32
-
33
-
34
-    /**
35
-     * ObjectIdentifier constructor.
36
-     *
37
-     * @param ClassInterfaceCache $class_cache
38
-     */
39
-    public function __construct(ClassInterfaceCache $class_cache)
40
-    {
41
-        $this->class_cache = $class_cache;
42
-    }
43
-
44
-
45
-    /**
46
-     * Returns true if the supplied $object_identifier contains
47
-     * the delimiter used to separate an fqcn from the arguments hash
48
-     *
49
-     * @param string $object_identifier
50
-     * @return bool
51
-     */
52
-    public function hasArguments($object_identifier)
53
-    {
54
-        // type casting to bool instead of using strpos() !== false
55
-        // because an object identifier should never begin with the delimiter
56
-        // therefore the delimiter should NOT be found at position 0
57
-        return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
58
-    }
59
-
60
-
61
-    /**
62
-     * Returns true if the supplied FQCN equals the supplied $object_identifier
63
-     * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
64
-     * AND that $object_identifier is for an object with arguments.
65
-     * This allows a request for an object using a FQCN to match
66
-     * a previously instantiated object with arguments
67
-     * without having to know those arguments.
68
-     *
69
-     * @param string $fqcn
70
-     * @param string $object_identifier
71
-     * @return bool
72
-     */
73
-    public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
74
-    {
75
-        return $fqcn === $object_identifier
76
-               || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
77
-    }
78
-
79
-
80
-    /**
81
-     * build a string representation of an object's FQCN and arguments
82
-     *
83
-     * @param string $fqcn
84
-     * @param array  $arguments
85
-     * @return string
86
-     */
87
-    public function getIdentifier($fqcn, array $arguments = array())
88
-    {
89
-        // only build identifier from arguments if class is not ReservedInstanceInterface
90
-        $identifier = ! $this->class_cache->hasInterface(
91
-            $fqcn,
92
-            'EventEspresso\core\interfaces\ReservedInstanceInterface'
93
-        )
94
-            ? $this->getIdentifierForArguments($arguments)
95
-            : '';
96
-        if (! empty($identifier)) {
97
-            $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
98
-        }
99
-        return $fqcn;
100
-    }
101
-
102
-
103
-    /**
104
-     * build a string representation of a object's arguments
105
-     * (mostly because Closures can't be serialized)
106
-     *
107
-     * @param array $arguments
108
-     * @return string
109
-     */
110
-    protected function getIdentifierForArguments(array $arguments)
111
-    {
112
-        if (empty($arguments)) {
113
-            return '';
114
-        }
115
-        $identifier = '';
116
-        foreach ($arguments as $argument) {
117
-            switch (true) {
118
-                case is_object($argument) :
119
-                case $argument instanceof Closure :
120
-                    $identifier .= spl_object_hash($argument);
121
-                    break;
122
-                case is_array($argument) :
123
-                    $identifier .= $this->getIdentifierForArguments($argument);
124
-                    break;
125
-                default :
126
-                    $identifier .= $argument;
127
-                    break;
128
-            }
129
-        }
130
-        return $identifier;
131
-    }
23
+	/**
24
+	 * used to separate the FQCN from the class's arguments identifier
25
+	 */
26
+	const DELIMITER = '____';
27
+
28
+	/**
29
+	 * @var ClassInterfaceCache $class_cache
30
+	 */
31
+	private $class_cache;
32
+
33
+
34
+	/**
35
+	 * ObjectIdentifier constructor.
36
+	 *
37
+	 * @param ClassInterfaceCache $class_cache
38
+	 */
39
+	public function __construct(ClassInterfaceCache $class_cache)
40
+	{
41
+		$this->class_cache = $class_cache;
42
+	}
43
+
44
+
45
+	/**
46
+	 * Returns true if the supplied $object_identifier contains
47
+	 * the delimiter used to separate an fqcn from the arguments hash
48
+	 *
49
+	 * @param string $object_identifier
50
+	 * @return bool
51
+	 */
52
+	public function hasArguments($object_identifier)
53
+	{
54
+		// type casting to bool instead of using strpos() !== false
55
+		// because an object identifier should never begin with the delimiter
56
+		// therefore the delimiter should NOT be found at position 0
57
+		return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
58
+	}
59
+
60
+
61
+	/**
62
+	 * Returns true if the supplied FQCN equals the supplied $object_identifier
63
+	 * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
64
+	 * AND that $object_identifier is for an object with arguments.
65
+	 * This allows a request for an object using a FQCN to match
66
+	 * a previously instantiated object with arguments
67
+	 * without having to know those arguments.
68
+	 *
69
+	 * @param string $fqcn
70
+	 * @param string $object_identifier
71
+	 * @return bool
72
+	 */
73
+	public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
74
+	{
75
+		return $fqcn === $object_identifier
76
+			   || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
77
+	}
78
+
79
+
80
+	/**
81
+	 * build a string representation of an object's FQCN and arguments
82
+	 *
83
+	 * @param string $fqcn
84
+	 * @param array  $arguments
85
+	 * @return string
86
+	 */
87
+	public function getIdentifier($fqcn, array $arguments = array())
88
+	{
89
+		// only build identifier from arguments if class is not ReservedInstanceInterface
90
+		$identifier = ! $this->class_cache->hasInterface(
91
+			$fqcn,
92
+			'EventEspresso\core\interfaces\ReservedInstanceInterface'
93
+		)
94
+			? $this->getIdentifierForArguments($arguments)
95
+			: '';
96
+		if (! empty($identifier)) {
97
+			$fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
98
+		}
99
+		return $fqcn;
100
+	}
101
+
102
+
103
+	/**
104
+	 * build a string representation of a object's arguments
105
+	 * (mostly because Closures can't be serialized)
106
+	 *
107
+	 * @param array $arguments
108
+	 * @return string
109
+	 */
110
+	protected function getIdentifierForArguments(array $arguments)
111
+	{
112
+		if (empty($arguments)) {
113
+			return '';
114
+		}
115
+		$identifier = '';
116
+		foreach ($arguments as $argument) {
117
+			switch (true) {
118
+				case is_object($argument) :
119
+				case $argument instanceof Closure :
120
+					$identifier .= spl_object_hash($argument);
121
+					break;
122
+				case is_array($argument) :
123
+					$identifier .= $this->getIdentifierForArguments($argument);
124
+					break;
125
+				default :
126
+					$identifier .= $argument;
127
+					break;
128
+			}
129
+		}
130
+		return $identifier;
131
+	}
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
74 74
     {
75 75
         return $fqcn === $object_identifier
76
-               || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
76
+               || strpos($object_identifier, $fqcn.ObjectIdentifier::DELIMITER) === 0;
77 77
     }
78 78
 
79 79
 
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
         )
94 94
             ? $this->getIdentifierForArguments($arguments)
95 95
             : '';
96
-        if (! empty($identifier)) {
97
-            $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
96
+        if ( ! empty($identifier)) {
97
+            $fqcn .= ObjectIdentifier::DELIMITER.md5($identifier);
98 98
         }
99 99
         return $fqcn;
100 100
     }
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 3 patches
Doc Comments   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -375,11 +375,11 @@  discard block
 block discarded – undo
375 375
 
376 376
 
377 377
     /**
378
-     * @param mixed      $var
378
+     * @param string      $var
379 379
      * @param string     $var_name
380 380
      * @param string     $file
381 381
      * @param int|string $line
382
-     * @param int|string $heading_tag
382
+     * @param integer $heading_tag
383 383
      * @param bool       $die
384 384
      * @param string     $margin
385 385
      */
@@ -411,6 +411,9 @@  discard block
 block discarded – undo
411 411
     }
412 412
 
413 413
 
414
+    /**
415
+     * @param integer $heading_tag
416
+     */
414 417
     protected static function headingTag($heading_tag)
415 418
     {
416 419
         $heading_tag = absint($heading_tag);
@@ -532,8 +535,8 @@  discard block
 block discarded – undo
532 535
      * @param mixed      $var
533 536
      * @param string     $var_name
534 537
      * @param string     $file
535
-     * @param int|string $line
536
-     * @param int|string $heading_tag
538
+     * @param integer $line
539
+     * @param integer $heading_tag
537 540
      * @param bool       $die
538 541
      */
539 542
     public static function printr(
@@ -596,7 +599,7 @@  discard block
 block discarded – undo
596 599
 
597 600
     /**
598 601
      * @deprecated 4.9.39.rc.034
599
-     * @param null $timer_name
602
+     * @param string $timer_name
600 603
      */
601 604
     public function start_timer($timer_name = null)
602 605
     {
Please login to merge, or discard this patch.
Indentation   +674 added lines, -674 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,664 +17,664 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed      $var
379
-     * @param string     $var_name
380
-     * @param string     $file
381
-     * @param int|string $line
382
-     * @param int|string $heading_tag
383
-     * @param bool       $die
384
-     * @param string     $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = '',
390
-        $line = '',
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
400
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
401
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402
-        $result .= $is_method
403
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
405
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
407
-        if ($die) {
408
-            die($result);
409
-        }
410
-        echo $result;
411
-    }
412
-
413
-
414
-    protected static function headingTag($heading_tag)
415
-    {
416
-        $heading_tag = absint($heading_tag);
417
-        return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
418
-    }
419
-
420
-
421
-    protected static function headingSpacer($heading_tag)
422
-    {
423
-        return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
424
-            ? "\n"
425
-            : '';
426
-    }
427
-
428
-
429
-    protected static function plainOutput()
430
-    {
431
-        return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX);
432
-    }
433
-
434
-
435
-    /**
436
-     * @param string $var_name
437
-     * @param string $heading_tag
438
-     * @param string $margin
439
-     * @param int    $line
440
-     * @return string
441
-     */
442
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
443
-    {
444
-        if (EEH_Debug_Tools::plainOutput()) {
445
-            $heading = '';
446
-            if($heading_tag === 'h1' || $heading_tag === 'h2') {
447
-                $heading .= "\n";
448
-            }
449
-            $heading .= "\n{$line}) {$var_name}";
450
-            return $heading;
451
-        }
452
-        $margin = "25px 0 0 {$margin}";
453
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * @param string $heading_tag
460
-     * @return string
461
-     */
462
-    protected static function headingX($heading_tag = 'h5')
463
-    {
464
-        if (EEH_Debug_Tools::plainOutput()) {
465
-            return '';
466
-        }
467
-        return '</' . $heading_tag . '>';
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     * @param string $content
474
-     * @return string
475
-     */
476
-    protected static function grey_span($content = '')
477
-    {
478
-        if (EEH_Debug_Tools::plainOutput()) {
479
-            return $content;
480
-        }
481
-        return '<span style="color:#999">' . $content . '</span>';
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * @param string $file
488
-     * @param int    $line
489
-     * @return string
490
-     */
491
-    protected static function file_and_line($file, $line, $heading_tag)
492
-    {
493
-        if ($file === '' || $line === '') {
494
-            return '';
495
-        }
496
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
497
-        if (EEH_Debug_Tools::plainOutput()) {
498
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
499
-                return " ({$file})";
500
-            }
501
-            return '';
502
-        }
503
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
504
-               . $file
505
-               . '<br />line no: '
506
-               . $line
507
-               . '</span>';
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param string $content
514
-     * @return string
515
-     */
516
-    protected static function orange_span($content = '')
517
-    {
518
-        if (EEH_Debug_Tools::plainOutput()) {
519
-            return $content;
520
-        }
521
-        return '<span style="color:#E76700">' . $content . '</span>';
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     * @param mixed $var
528
-     * @return string
529
-     */
530
-    protected static function pre_span($var)
531
-    {
532
-        ob_start();
533
-        var_dump($var);
534
-        $var = ob_get_clean();
535
-        if (EEH_Debug_Tools::plainOutput()) {
536
-            return $var;
537
-        }
538
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * @param mixed      $var
545
-     * @param string     $var_name
546
-     * @param string     $file
547
-     * @param int|string $line
548
-     * @param int|string $heading_tag
549
-     * @param bool       $die
550
-     */
551
-    public static function printr(
552
-        $var,
553
-        $var_name = '',
554
-        $file = '',
555
-        $line = '',
556
-        $heading_tag = 5,
557
-        $die = false
558
-    ) {
559
-        // return;
560
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
561
-        $margin = is_admin() ? ' 180px' : '0';
562
-        //$print_r = false;
563
-        if (is_string($var)) {
564
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
565
-            return;
566
-        }
567
-        if (is_object($var)) {
568
-            $var_name = ! $var_name ? 'object' : $var_name;
569
-            //$print_r = true;
570
-        } else if (is_array($var)) {
571
-            $var_name = ! $var_name ? 'array' : $var_name;
572
-            //$print_r = true;
573
-        } else if (is_numeric($var)) {
574
-            $var_name = ! $var_name ? 'numeric' : $var_name;
575
-        } else if ($var === null) {
576
-            $var_name = ! $var_name ? 'null' : $var_name;
577
-        }
578
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
579
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
580
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
581
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
582
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
583
-                EEH_Debug_Tools::pre_span($var)
584
-            );
585
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
586
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
587
-        if ($die) {
588
-            die($result);
589
-        }
590
-        echo $result;
591
-    }
592
-
593
-
594
-
595
-    /******************** deprecated ********************/
596
-
597
-
598
-
599
-    /**
600
-     * @deprecated 4.9.39.rc.034
601
-     */
602
-    public function reset_times()
603
-    {
604
-        Benchmark::resetTimes();
605
-    }
606
-
607
-
608
-
609
-    /**
610
-     * @deprecated 4.9.39.rc.034
611
-     * @param null $timer_name
612
-     */
613
-    public function start_timer($timer_name = null)
614
-    {
615
-        Benchmark::startTimer($timer_name);
616
-    }
617
-
618
-
619
-
620
-    /**
621
-     * @deprecated 4.9.39.rc.034
622
-     * @param string $timer_name
623
-     */
624
-    public function stop_timer($timer_name = '')
625
-    {
626
-        Benchmark::stopTimer($timer_name);
627
-    }
628
-
629
-
630
-
631
-    /**
632
-     * @deprecated 4.9.39.rc.034
633
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
634
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
635
-     * @return void
636
-     */
637
-    public function measure_memory($label, $output_now = false)
638
-    {
639
-        Benchmark::measureMemory($label, $output_now);
640
-    }
641
-
642
-
643
-
644
-    /**
645
-     * @deprecated 4.9.39.rc.034
646
-     * @param int $size
647
-     * @return string
648
-     */
649
-    public function convert($size)
650
-    {
651
-        return Benchmark::convert($size);
652
-    }
653
-
654
-
655
-
656
-    /**
657
-     * @deprecated 4.9.39.rc.034
658
-     * @param bool $output_now
659
-     * @return string
660
-     */
661
-    public function show_times($output_now = true)
662
-    {
663
-        return Benchmark::displayResults($output_now);
664
-    }
665
-
666
-
667
-
668
-    /**
669
-     * @deprecated 4.9.39.rc.034
670
-     * @param string $timer_name
671
-     * @param float  $total_time
672
-     * @return string
673
-     */
674
-    public function format_time($timer_name, $total_time)
675
-    {
676
-        return Benchmark::formatTime($timer_name, $total_time);
677
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed      $var
379
+	 * @param string     $var_name
380
+	 * @param string     $file
381
+	 * @param int|string $line
382
+	 * @param int|string $heading_tag
383
+	 * @param bool       $die
384
+	 * @param string     $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = '',
390
+		$line = '',
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
400
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
401
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402
+		$result .= $is_method
403
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
405
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
407
+		if ($die) {
408
+			die($result);
409
+		}
410
+		echo $result;
411
+	}
412
+
413
+
414
+	protected static function headingTag($heading_tag)
415
+	{
416
+		$heading_tag = absint($heading_tag);
417
+		return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
418
+	}
419
+
420
+
421
+	protected static function headingSpacer($heading_tag)
422
+	{
423
+		return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
424
+			? "\n"
425
+			: '';
426
+	}
427
+
428
+
429
+	protected static function plainOutput()
430
+	{
431
+		return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX);
432
+	}
433
+
434
+
435
+	/**
436
+	 * @param string $var_name
437
+	 * @param string $heading_tag
438
+	 * @param string $margin
439
+	 * @param int    $line
440
+	 * @return string
441
+	 */
442
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
443
+	{
444
+		if (EEH_Debug_Tools::plainOutput()) {
445
+			$heading = '';
446
+			if($heading_tag === 'h1' || $heading_tag === 'h2') {
447
+				$heading .= "\n";
448
+			}
449
+			$heading .= "\n{$line}) {$var_name}";
450
+			return $heading;
451
+		}
452
+		$margin = "25px 0 0 {$margin}";
453
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * @param string $heading_tag
460
+	 * @return string
461
+	 */
462
+	protected static function headingX($heading_tag = 'h5')
463
+	{
464
+		if (EEH_Debug_Tools::plainOutput()) {
465
+			return '';
466
+		}
467
+		return '</' . $heading_tag . '>';
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 * @param string $content
474
+	 * @return string
475
+	 */
476
+	protected static function grey_span($content = '')
477
+	{
478
+		if (EEH_Debug_Tools::plainOutput()) {
479
+			return $content;
480
+		}
481
+		return '<span style="color:#999">' . $content . '</span>';
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * @param string $file
488
+	 * @param int    $line
489
+	 * @return string
490
+	 */
491
+	protected static function file_and_line($file, $line, $heading_tag)
492
+	{
493
+		if ($file === '' || $line === '') {
494
+			return '';
495
+		}
496
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
497
+		if (EEH_Debug_Tools::plainOutput()) {
498
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
499
+				return " ({$file})";
500
+			}
501
+			return '';
502
+		}
503
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
504
+			   . $file
505
+			   . '<br />line no: '
506
+			   . $line
507
+			   . '</span>';
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param string $content
514
+	 * @return string
515
+	 */
516
+	protected static function orange_span($content = '')
517
+	{
518
+		if (EEH_Debug_Tools::plainOutput()) {
519
+			return $content;
520
+		}
521
+		return '<span style="color:#E76700">' . $content . '</span>';
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 * @param mixed $var
528
+	 * @return string
529
+	 */
530
+	protected static function pre_span($var)
531
+	{
532
+		ob_start();
533
+		var_dump($var);
534
+		$var = ob_get_clean();
535
+		if (EEH_Debug_Tools::plainOutput()) {
536
+			return $var;
537
+		}
538
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * @param mixed      $var
545
+	 * @param string     $var_name
546
+	 * @param string     $file
547
+	 * @param int|string $line
548
+	 * @param int|string $heading_tag
549
+	 * @param bool       $die
550
+	 */
551
+	public static function printr(
552
+		$var,
553
+		$var_name = '',
554
+		$file = '',
555
+		$line = '',
556
+		$heading_tag = 5,
557
+		$die = false
558
+	) {
559
+		// return;
560
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
561
+		$margin = is_admin() ? ' 180px' : '0';
562
+		//$print_r = false;
563
+		if (is_string($var)) {
564
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
565
+			return;
566
+		}
567
+		if (is_object($var)) {
568
+			$var_name = ! $var_name ? 'object' : $var_name;
569
+			//$print_r = true;
570
+		} else if (is_array($var)) {
571
+			$var_name = ! $var_name ? 'array' : $var_name;
572
+			//$print_r = true;
573
+		} else if (is_numeric($var)) {
574
+			$var_name = ! $var_name ? 'numeric' : $var_name;
575
+		} else if ($var === null) {
576
+			$var_name = ! $var_name ? 'null' : $var_name;
577
+		}
578
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
579
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
580
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
581
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
582
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
583
+				EEH_Debug_Tools::pre_span($var)
584
+			);
585
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
586
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
587
+		if ($die) {
588
+			die($result);
589
+		}
590
+		echo $result;
591
+	}
592
+
593
+
594
+
595
+	/******************** deprecated ********************/
596
+
597
+
598
+
599
+	/**
600
+	 * @deprecated 4.9.39.rc.034
601
+	 */
602
+	public function reset_times()
603
+	{
604
+		Benchmark::resetTimes();
605
+	}
606
+
607
+
608
+
609
+	/**
610
+	 * @deprecated 4.9.39.rc.034
611
+	 * @param null $timer_name
612
+	 */
613
+	public function start_timer($timer_name = null)
614
+	{
615
+		Benchmark::startTimer($timer_name);
616
+	}
617
+
618
+
619
+
620
+	/**
621
+	 * @deprecated 4.9.39.rc.034
622
+	 * @param string $timer_name
623
+	 */
624
+	public function stop_timer($timer_name = '')
625
+	{
626
+		Benchmark::stopTimer($timer_name);
627
+	}
628
+
629
+
630
+
631
+	/**
632
+	 * @deprecated 4.9.39.rc.034
633
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
634
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
635
+	 * @return void
636
+	 */
637
+	public function measure_memory($label, $output_now = false)
638
+	{
639
+		Benchmark::measureMemory($label, $output_now);
640
+	}
641
+
642
+
643
+
644
+	/**
645
+	 * @deprecated 4.9.39.rc.034
646
+	 * @param int $size
647
+	 * @return string
648
+	 */
649
+	public function convert($size)
650
+	{
651
+		return Benchmark::convert($size);
652
+	}
653
+
654
+
655
+
656
+	/**
657
+	 * @deprecated 4.9.39.rc.034
658
+	 * @param bool $output_now
659
+	 * @return string
660
+	 */
661
+	public function show_times($output_now = true)
662
+	{
663
+		return Benchmark::displayResults($output_now);
664
+	}
665
+
666
+
667
+
668
+	/**
669
+	 * @deprecated 4.9.39.rc.034
670
+	 * @param string $timer_name
671
+	 * @param float  $total_time
672
+	 * @return string
673
+	 */
674
+	public function format_time($timer_name, $total_time)
675
+	{
676
+		return Benchmark::formatTime($timer_name, $total_time);
677
+	}
678 678
 
679 679
 
680 680
 
@@ -687,31 +687,31 @@  discard block
 block discarded – undo
687 687
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
688 688
  */
689 689
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
690
-    function dump_wp_query()
691
-    {
692
-        global $wp_query;
693
-        d($wp_query);
694
-    }
690
+	function dump_wp_query()
691
+	{
692
+		global $wp_query;
693
+		d($wp_query);
694
+	}
695 695
 }
696 696
 /**
697 697
  * borrowed from Kint Debugger
698 698
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
699 699
  */
700 700
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
701
-    function dump_wp()
702
-    {
703
-        global $wp;
704
-        d($wp);
705
-    }
701
+	function dump_wp()
702
+	{
703
+		global $wp;
704
+		d($wp);
705
+	}
706 706
 }
707 707
 /**
708 708
  * borrowed from Kint Debugger
709 709
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
710 710
  */
711 711
 if (class_exists('Kint') && ! function_exists('dump_post')) {
712
-    function dump_post()
713
-    {
714
-        global $post;
715
-        d($post);
716
-    }
712
+	function dump_post()
713
+	{
714
+		global $post;
715
+		d($post);
716
+	}
717 717
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
401 401
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
402 402
         $result .= $is_method
403
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
404
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
403
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
404
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
405 405
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
406 406
         $result .= EEH_Debug_Tools::headingX($heading_tag);
407 407
         if ($die) {
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
     {
444 444
         if (EEH_Debug_Tools::plainOutput()) {
445 445
             $heading = '';
446
-            if($heading_tag === 'h1' || $heading_tag === 'h2') {
446
+            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
447 447
                 $heading .= "\n";
448 448
             }
449 449
             $heading .= "\n{$line}) {$var_name}";
450 450
             return $heading;
451 451
         }
452 452
         $margin = "25px 0 0 {$margin}";
453
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
453
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
454 454
     }
455 455
 
456 456
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
         if (EEH_Debug_Tools::plainOutput()) {
465 465
             return '';
466 466
         }
467
-        return '</' . $heading_tag . '>';
467
+        return '</'.$heading_tag.'>';
468 468
     }
469 469
 
470 470
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
         if (EEH_Debug_Tools::plainOutput()) {
479 479
             return $content;
480 480
         }
481
-        return '<span style="color:#999">' . $content . '</span>';
481
+        return '<span style="color:#999">'.$content.'</span>';
482 482
     }
483 483
 
484 484
 
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         if (EEH_Debug_Tools::plainOutput()) {
519 519
             return $content;
520 520
         }
521
-        return '<span style="color:#E76700">' . $content . '</span>';
521
+        return '<span style="color:#E76700">'.$content.'</span>';
522 522
     }
523 523
 
524 524
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
         if (EEH_Debug_Tools::plainOutput()) {
536 536
             return $var;
537 537
         }
538
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
538
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
539 539
     }
540 540
 
541 541
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
         $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
580 580
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
581 581
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
582
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
582
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
583 583
                 EEH_Debug_Tools::pre_span($var)
584 584
             );
585 585
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
Please login to merge, or discard this patch.
core/domain/DomainFactory.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -28,63 +28,63 @@
 block discarded – undo
28 28
 class DomainFactory
29 29
 {
30 30
 
31
-    /**
32
-     * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
33
-     * @param array $arguments                  [required] array of arguments to be passed to the Domain class
34
-     *                                          constructor. Must at least include the following two value objects:
35
-     *                                          array(
36
-     *                                              EventEspresso\core\domain\values\FilePath $plugin_file
37
-     *                                              EventEspresso\core\domain\values\Version $version
38
-     *                                          )
39
-     * @return mixed
40
-     * @throws DomainException
41
-     * @throws InvalidArgumentException
42
-     * @throws InvalidDataTypeException
43
-     * @throws InvalidInterfaceException
44
-     */
45
-    public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
46
-    {
47
-        if (! isset($arguments[0], $arguments[1])) {
48
-            throw new InvalidArgumentException(
49
-                esc_html__(
50
-                    'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
51
-                    'event_espresso'
52
-                )
53
-            );
54
-        }
55
-        $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
56
-        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
57
-            throw new DomainException(
58
-                sprintf(
59
-                    esc_html__(
60
-                        'The requested Domain class "%1$s" could not be loaded.',
61
-                        'event_espresso'
62
-                    ),
63
-                    $domain_fqcn
64
-                )
65
-            );
66
-        }
67
-        return $domain;
68
-    }
31
+	/**
32
+	 * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
33
+	 * @param array $arguments                  [required] array of arguments to be passed to the Domain class
34
+	 *                                          constructor. Must at least include the following two value objects:
35
+	 *                                          array(
36
+	 *                                              EventEspresso\core\domain\values\FilePath $plugin_file
37
+	 *                                              EventEspresso\core\domain\values\Version $version
38
+	 *                                          )
39
+	 * @return mixed
40
+	 * @throws DomainException
41
+	 * @throws InvalidArgumentException
42
+	 * @throws InvalidDataTypeException
43
+	 * @throws InvalidInterfaceException
44
+	 */
45
+	public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
46
+	{
47
+		if (! isset($arguments[0], $arguments[1])) {
48
+			throw new InvalidArgumentException(
49
+				esc_html__(
50
+					'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
51
+					'event_espresso'
52
+				)
53
+			);
54
+		}
55
+		$domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
56
+		if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
57
+			throw new DomainException(
58
+				sprintf(
59
+					esc_html__(
60
+						'The requested Domain class "%1$s" could not be loaded.',
61
+						'event_espresso'
62
+					),
63
+					$domain_fqcn
64
+				)
65
+			);
66
+		}
67
+		return $domain;
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * @return Domain
73
-     * @throws DomainException
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidFilePathException
77
-     * @throws InvalidInterfaceException
78
-     */
79
-    public static function getEventEspressoCoreDomain()
80
-    {
81
-        $domain = new Domain(
82
-            new FilePath(EVENT_ESPRESSO_MAIN_FILE),
83
-            Version::fromString(espresso_version())
84
-        );
85
-        LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
86
-        return $domain;
87
-    }
71
+	/**
72
+	 * @return Domain
73
+	 * @throws DomainException
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidFilePathException
77
+	 * @throws InvalidInterfaceException
78
+	 */
79
+	public static function getEventEspressoCoreDomain()
80
+	{
81
+		$domain = new Domain(
82
+			new FilePath(EVENT_ESPRESSO_MAIN_FILE),
83
+			Version::fromString(espresso_version())
84
+		);
85
+		LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
86
+		return $domain;
87
+	}
88 88
 }
89 89
 
90 90
 
Please login to merge, or discard this patch.
core/services/loaders/ClassInterfaceCache.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -20,160 +20,160 @@
 block discarded – undo
20 20
 class ClassInterfaceCache
21 21
 {
22 22
 
23
-    /**
24
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
-     *
26
-     * @var string[][] $interfaces
27
-     */
28
-    private $interfaces = array();
29
-
30
-    /**
31
-     * @type string[][] $aliases
32
-     */
33
-    protected $aliases = array();
34
-
35
-
36
-    /**
37
-     * @param string $fqn
38
-     * @return string
39
-     */
40
-    public function getFqn($fqn)
41
-    {
42
-        return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
43
-    }
44
-
45
-
46
-    /**
47
-     * @param string $fqn
48
-     * @return array
49
-     */
50
-    public function getInterfaces($fqn)
51
-    {
52
-        $fqn = $this->getFqn($fqn);
53
-        // have we already seen this FQCN ?
54
-        if (! array_key_exists($fqn, $this->interfaces)) {
55
-            $this->interfaces[ $fqn ] = array();
56
-            if (class_exists($fqn)) {
57
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
58
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
-                    ? $this->interfaces[ $fqn ]
60
-                    : array();
61
-            }
62
-        }
63
-        return $this->interfaces[ $fqn ];
64
-    }
65
-
66
-
67
-    /**
68
-     * @param string $fqn
69
-     * @param string $interface
70
-     * @return bool
71
-     */
72
-    public function hasInterface($fqn, $interface)
73
-    {
74
-        $fqn        = $this->getFqn($fqn);
75
-        $interfaces = $this->getInterfaces($fqn);
76
-        return in_array($interface, $interfaces, true);
77
-    }
78
-
79
-
80
-    /**
81
-     * adds an alias for a classname
82
-     *
83
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
84
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
85
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
86
-     */
87
-    public function addAlias($fqn, $alias, $for_class = '')
88
-    {
89
-        $fqn   = $this->getFqn($fqn);
90
-        $alias = $this->getFqn($alias);
91
-        // are we adding an alias for a specific class?
92
-        if ($for_class !== '') {
93
-            // make sure it's set up as an array
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
96
-            }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
98
-            return;
99
-        }
100
-        $this->aliases[ $alias ] = $fqn;
101
-    }
102
-
103
-
104
-    /**
105
-     * returns TRUE if the provided FQN is an alias
106
-     *
107
-     * @param string $fqn
108
-     * @param string $for_class
109
-     * @return bool
110
-     */
111
-    public function isAlias($fqn = '', $for_class = '')
112
-    {
113
-        $fqn = $this->getFqn($fqn);
114
-        if ($this->isAliasForClass($fqn, $for_class)) {
115
-            return true;
116
-        }
117
-        if ($for_class === '' && $this->isDirectAlias($fqn)) {
118
-            return true;
119
-        }
120
-        return false;
121
-    }
122
-
123
-
124
-    /**
125
-     * returns TRUE if the provided FQN is an alias
126
-     *
127
-     * @param string $fqn
128
-     * @return bool
129
-     */
130
-    protected function isDirectAlias($fqn = '')
131
-    {
132
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
133
-    }
134
-
135
-
136
-    /**
137
-     * returns TRUE if the provided FQN is an alias for the specified class
138
-     *
139
-     * @param string $fqn
140
-     * @param string $for_class
141
-     * @return bool
142
-     */
143
-    protected function isAliasForClass($fqn = '', $for_class = '')
144
-    {
145
-        return (
146
-            $for_class !== ''
147
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
148
-        );
149
-    }
150
-
151
-
152
-    /**
153
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
154
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
155
-     *  for example:
156
-     *      if the following two entries were added to the aliases array:
157
-     *          array(
158
-     *              'interface_alias'           => 'some\namespace\interface'
159
-     *              'some\namespace\interface'  => 'some\namespace\classname'
160
-     *          )
161
-     *      then one could use Loader::getNew( 'interface_alias' )
162
-     *      to load an instance of 'some\namespace\classname'
163
-     *
164
-     * @param string $alias
165
-     * @param string $for_class
166
-     * @return string
167
-     */
168
-    public function getFqnForAlias($alias = '', $for_class = '')
169
-    {
170
-        $alias = $this->getFqn($alias);
171
-        if ($this->isAliasForClass($alias, $for_class)) {
172
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
173
-        }
174
-        if ($this->isDirectAlias($alias)) {
175
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
176
-        }
177
-        return $alias;
178
-    }
23
+	/**
24
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
+	 *
26
+	 * @var string[][] $interfaces
27
+	 */
28
+	private $interfaces = array();
29
+
30
+	/**
31
+	 * @type string[][] $aliases
32
+	 */
33
+	protected $aliases = array();
34
+
35
+
36
+	/**
37
+	 * @param string $fqn
38
+	 * @return string
39
+	 */
40
+	public function getFqn($fqn)
41
+	{
42
+		return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
43
+	}
44
+
45
+
46
+	/**
47
+	 * @param string $fqn
48
+	 * @return array
49
+	 */
50
+	public function getInterfaces($fqn)
51
+	{
52
+		$fqn = $this->getFqn($fqn);
53
+		// have we already seen this FQCN ?
54
+		if (! array_key_exists($fqn, $this->interfaces)) {
55
+			$this->interfaces[ $fqn ] = array();
56
+			if (class_exists($fqn)) {
57
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
58
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
+					? $this->interfaces[ $fqn ]
60
+					: array();
61
+			}
62
+		}
63
+		return $this->interfaces[ $fqn ];
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param string $fqn
69
+	 * @param string $interface
70
+	 * @return bool
71
+	 */
72
+	public function hasInterface($fqn, $interface)
73
+	{
74
+		$fqn        = $this->getFqn($fqn);
75
+		$interfaces = $this->getInterfaces($fqn);
76
+		return in_array($interface, $interfaces, true);
77
+	}
78
+
79
+
80
+	/**
81
+	 * adds an alias for a classname
82
+	 *
83
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
84
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
85
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
86
+	 */
87
+	public function addAlias($fqn, $alias, $for_class = '')
88
+	{
89
+		$fqn   = $this->getFqn($fqn);
90
+		$alias = $this->getFqn($alias);
91
+		// are we adding an alias for a specific class?
92
+		if ($for_class !== '') {
93
+			// make sure it's set up as an array
94
+			if (! isset($this->aliases[ $for_class ])) {
95
+				$this->aliases[ $for_class ] = array();
96
+			}
97
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
98
+			return;
99
+		}
100
+		$this->aliases[ $alias ] = $fqn;
101
+	}
102
+
103
+
104
+	/**
105
+	 * returns TRUE if the provided FQN is an alias
106
+	 *
107
+	 * @param string $fqn
108
+	 * @param string $for_class
109
+	 * @return bool
110
+	 */
111
+	public function isAlias($fqn = '', $for_class = '')
112
+	{
113
+		$fqn = $this->getFqn($fqn);
114
+		if ($this->isAliasForClass($fqn, $for_class)) {
115
+			return true;
116
+		}
117
+		if ($for_class === '' && $this->isDirectAlias($fqn)) {
118
+			return true;
119
+		}
120
+		return false;
121
+	}
122
+
123
+
124
+	/**
125
+	 * returns TRUE if the provided FQN is an alias
126
+	 *
127
+	 * @param string $fqn
128
+	 * @return bool
129
+	 */
130
+	protected function isDirectAlias($fqn = '')
131
+	{
132
+		return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
133
+	}
134
+
135
+
136
+	/**
137
+	 * returns TRUE if the provided FQN is an alias for the specified class
138
+	 *
139
+	 * @param string $fqn
140
+	 * @param string $for_class
141
+	 * @return bool
142
+	 */
143
+	protected function isAliasForClass($fqn = '', $for_class = '')
144
+	{
145
+		return (
146
+			$for_class !== ''
147
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
148
+		);
149
+	}
150
+
151
+
152
+	/**
153
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
154
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
155
+	 *  for example:
156
+	 *      if the following two entries were added to the aliases array:
157
+	 *          array(
158
+	 *              'interface_alias'           => 'some\namespace\interface'
159
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
160
+	 *          )
161
+	 *      then one could use Loader::getNew( 'interface_alias' )
162
+	 *      to load an instance of 'some\namespace\classname'
163
+	 *
164
+	 * @param string $alias
165
+	 * @param string $for_class
166
+	 * @return string
167
+	 */
168
+	public function getFqnForAlias($alias = '', $for_class = '')
169
+	{
170
+		$alias = $this->getFqn($alias);
171
+		if ($this->isAliasForClass($alias, $for_class)) {
172
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
173
+		}
174
+		if ($this->isDirectAlias($alias)) {
175
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
176
+		}
177
+		return $alias;
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $fqn = $this->getFqn($fqn);
53 53
         // have we already seen this FQCN ?
54
-        if (! array_key_exists($fqn, $this->interfaces)) {
55
-            $this->interfaces[ $fqn ] = array();
54
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
55
+            $this->interfaces[$fqn] = array();
56 56
             if (class_exists($fqn)) {
57
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
58
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
-                    ? $this->interfaces[ $fqn ]
57
+                $this->interfaces[$fqn] = class_implements($fqn, false);
58
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
59
+                    ? $this->interfaces[$fqn]
60 60
                     : array();
61 61
             }
62 62
         }
63
-        return $this->interfaces[ $fqn ];
63
+        return $this->interfaces[$fqn];
64 64
     }
65 65
 
66 66
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
         // are we adding an alias for a specific class?
92 92
         if ($for_class !== '') {
93 93
             // make sure it's set up as an array
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
94
+            if ( ! isset($this->aliases[$for_class])) {
95
+                $this->aliases[$for_class] = array();
96 96
             }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
97
+            $this->aliases[$for_class][$alias] = $fqn;
98 98
             return;
99 99
         }
100
-        $this->aliases[ $alias ] = $fqn;
100
+        $this->aliases[$alias] = $fqn;
101 101
     }
102 102
 
103 103
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     protected function isDirectAlias($fqn = '')
131 131
     {
132
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
132
+        return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]);
133 133
     }
134 134
 
135 135
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     {
145 145
         return (
146 146
             $for_class !== ''
147
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
147
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
148 148
         );
149 149
     }
150 150
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
     {
170 170
         $alias = $this->getFqn($alias);
171 171
         if ($this->isAliasForClass($alias, $for_class)) {
172
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
172
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
173 173
         }
174 174
         if ($this->isDirectAlias($alias)) {
175
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
175
+            return $this->getFqnForAlias($this->aliases[(string) $alias], '');
176 176
         }
177 177
         return $alias;
178 178
     }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\request\RequestInterface;
9 9
 use EventEspresso\core\services\request\ResponseInterface;
10 10
 
11
-if (! defined('EVENT_ESPRESSO_VERSION')) {
11
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
12 12
     exit('No direct script access allowed');
13 13
 }
14 14
 
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
     ) {
214 214
         $class = trim($class, '\\');
215 215
         $registered = false;
216
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
217
-            self::$_instance->_dependency_map[ $class ] = array();
216
+        if (empty(self::$_instance->_dependency_map[$class])) {
217
+            self::$_instance->_dependency_map[$class] = array();
218 218
         }
219 219
         // we need to make sure that any aliases used when registering a dependency
220 220
         // get resolved to the correct class name
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             $alias = self::$_instance->getFqnForAlias($dependency);
223 223
             if (
224 224
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
225
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
226 226
             ) {
227 227
                 unset($dependencies[$dependency]);
228 228
                 $dependencies[$alias] = $load_source;
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
236 236
         // Union is way faster than array_merge() but should be used with caution...
237 237
         // especially with numerically indexed arrays
238
-        $dependencies += self::$_instance->_dependency_map[ $class ];
238
+        $dependencies += self::$_instance->_dependency_map[$class];
239 239
         // now we need to ensure that the resulting dependencies
240 240
         // array only has the entries that are required for the class
241 241
         // so first count how many dependencies were originally registered for the class
242
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
242
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
243 243
         // if that count is non-zero (meaning dependencies were already registered)
244
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
244
+        self::$_instance->_dependency_map[$class] = $dependency_count
245 245
             // then truncate the  final array to match that count
246 246
             ? array_slice($dependencies, 0, $dependency_count)
247 247
             // otherwise just take the incoming array because nothing previously existed
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public static function register_class_loader($class_name, $loader = 'load_core')
261 261
     {
262
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
262
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263 263
             throw new DomainException(
264 264
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265 265
             );
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             );
284 284
         }
285 285
         $class_name = self::$_instance->getFqnForAlias($class_name);
286
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
286
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
287 287
             self::$_instance->_class_loaders[$class_name] = $loader;
288 288
             return true;
289 289
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
     public function class_loader($class_name)
369 369
     {
370 370
         // all legacy models use load_model()
371
-        if(strpos($class_name, 'EEM_') === 0){
371
+        if (strpos($class_name, 'EEM_') === 0) {
372 372
             return 'load_model';
373 373
         }
374 374
         $class_name = $this->getFqnForAlias($class_name);
@@ -766,13 +766,13 @@  discard block
 block discarded – undo
766 766
             'EE_Front_Controller'      => 'load_core',
767 767
             'EE_Module_Request_Router' => 'load_core',
768 768
             'EE_Registry'              => 'load_core',
769
-            'EE_Request'               => function () use (&$legacy_request) {
769
+            'EE_Request'               => function() use (&$legacy_request) {
770 770
                 return $legacy_request;
771 771
             },
772
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
772
+            'EventEspresso\core\services\request\Request' => function() use (&$request) {
773 773
                 return $request;
774 774
             },
775
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
775
+            'EventEspresso\core\services\request\Response' => function() use (&$response) {
776 776
                 return $response;
777 777
             },
778 778
             'EE_Base'             => 'load_core',
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
796 796
             'EE_Message_Template_Group_Collection' => 'load_lib',
797 797
             'EE_Payment_Method_Manager'            => 'load_lib',
798
-            'EE_Messages_Generator'                => function () {
798
+            'EE_Messages_Generator'                => function() {
799 799
                 return EE_Registry::instance()->load_lib(
800 800
                     'Messages_Generator',
801 801
                     array(),
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
                     false
804 804
                 );
805 805
             },
806
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
806
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
807 807
                 return EE_Registry::instance()->load_lib(
808 808
                     'Messages_Template_Defaults',
809 809
                     $arguments,
@@ -812,34 +812,34 @@  discard block
 block discarded – undo
812 812
                 );
813 813
             },
814 814
             //load_helper
815
-            'EEH_Parse_Shortcodes'                 => function () {
815
+            'EEH_Parse_Shortcodes'                 => function() {
816 816
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
817 817
                     return new EEH_Parse_Shortcodes();
818 818
                 }
819 819
                 return null;
820 820
             },
821
-            'EE_Template_Config'                   => function () {
821
+            'EE_Template_Config'                   => function() {
822 822
                 return EE_Config::instance()->template_settings;
823 823
             },
824
-            'EE_Currency_Config'                   => function () {
824
+            'EE_Currency_Config'                   => function() {
825 825
                 return EE_Config::instance()->currency;
826 826
             },
827
-            'EE_Registration_Config'                   => function () {
827
+            'EE_Registration_Config'                   => function() {
828 828
                 return EE_Config::instance()->registration;
829 829
             },
830
-            'EE_Core_Config'                   => function () {
830
+            'EE_Core_Config'                   => function() {
831 831
                 return EE_Config::instance()->core;
832 832
             },
833
-            'EventEspresso\core\services\loaders\Loader' => function () {
833
+            'EventEspresso\core\services\loaders\Loader' => function() {
834 834
                 return LoaderFactory::getLoader();
835 835
             },
836 836
             'EE_Network_Config' => function() {
837 837
                 return EE_Network_Config::instance();
838 838
             },
839
-            'EE_Config' => function () {
839
+            'EE_Config' => function() {
840 840
                 return EE_Config::instance();
841 841
             },
842
-            'EventEspresso\core\domain\Domain' => function () {
842
+            'EventEspresso\core\domain\Domain' => function() {
843 843
                 return DomainFactory::getEventEspressoCoreDomain();
844 844
             },
845 845
         );
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
             'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
896 896
         );
897 897
         foreach ($aliases as $alias => $fqn) {
898
-            if(is_array($fqn)) {
898
+            if (is_array($fqn)) {
899 899
                 foreach ($fqn as $class => $for_class) {
900 900
                     $this->class_cache->addAlias($class, $alias, $for_class);
901 901
                 }
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
             }
904 904
             $this->class_cache->addAlias($fqn, $alias);
905 905
         }
906
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
906
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
907 907
             $this->class_cache->addAlias(
908 908
                 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
909 909
                 'EventEspresso\core\services\notices\NoticeConverterInterface'
Please login to merge, or discard this patch.
Indentation   +976 added lines, -976 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 use EventEspresso\core\services\request\ResponseInterface;
10 10
 
11 11
 if (! defined('EVENT_ESPRESSO_VERSION')) {
12
-    exit('No direct script access allowed');
12
+	exit('No direct script access allowed');
13 13
 }
14 14
 
15 15
 
@@ -26,981 +26,981 @@  discard block
 block discarded – undo
26 26
 class EE_Dependency_Map
27 27
 {
28 28
 
29
-    /**
30
-     * This means that the requested class dependency is not present in the dependency map
31
-     */
32
-    const not_registered = 0;
33
-
34
-    /**
35
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
36
-     */
37
-    const load_new_object = 1;
38
-
39
-    /**
40
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
41
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
42
-     */
43
-    const load_from_cache = 2;
44
-
45
-    /**
46
-     * When registering a dependency,
47
-     * this indicates to keep any existing dependencies that already exist,
48
-     * and simply discard any new dependencies declared in the incoming data
49
-     */
50
-    const KEEP_EXISTING_DEPENDENCIES = 0;
51
-
52
-    /**
53
-     * When registering a dependency,
54
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
55
-     */
56
-    const OVERWRITE_DEPENDENCIES = 1;
57
-
58
-
59
-
60
-    /**
61
-     * @type EE_Dependency_Map $_instance
62
-     */
63
-    protected static $_instance;
64
-
65
-    /**
66
-     * @var ClassInterfaceCache $class_cache
67
-     */
68
-    private $class_cache;
69
-
70
-    /**
71
-     * @type RequestInterface $request
72
-     */
73
-    protected $request;
74
-
75
-    /**
76
-     * @type LegacyRequestInterface $legacy_request
77
-     */
78
-    protected $legacy_request;
79
-
80
-    /**
81
-     * @type ResponseInterface $response
82
-     */
83
-    protected $response;
84
-
85
-    /**
86
-     * @type LoaderInterface $loader
87
-     */
88
-    protected $loader;
89
-
90
-    /**
91
-     * @type array $_dependency_map
92
-     */
93
-    protected $_dependency_map = array();
94
-
95
-    /**
96
-     * @type array $_class_loaders
97
-     */
98
-    protected $_class_loaders = array();
99
-
100
-
101
-    /**
102
-     * EE_Dependency_Map constructor.
103
-     *
104
-     * @param ClassInterfaceCache $class_cache
105
-     */
106
-    protected function __construct(ClassInterfaceCache $class_cache)
107
-    {
108
-        $this->class_cache = $class_cache;
109
-        do_action('EE_Dependency_Map____construct', $this);
110
-    }
111
-
112
-
113
-    /**
114
-     * @return void
115
-     */
116
-    public function initialize()
117
-    {
118
-        $this->_register_core_dependencies();
119
-        $this->_register_core_class_loaders();
120
-        $this->_register_core_aliases();
121
-    }
122
-
123
-
124
-    /**
125
-     * @singleton method used to instantiate class object
126
-     * @param ClassInterfaceCache|null $class_cache
127
-     * @return EE_Dependency_Map
128
-     */
129
-    public static function instance(ClassInterfaceCache $class_cache = null) {
130
-        // check if class object is instantiated, and instantiated properly
131
-        if (
132
-            ! self::$_instance instanceof EE_Dependency_Map
133
-            && $class_cache instanceof ClassInterfaceCache
134
-        ) {
135
-            self::$_instance = new EE_Dependency_Map($class_cache);
136
-        }
137
-        return self::$_instance;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param RequestInterface $request
143
-     */
144
-    public function setRequest(RequestInterface $request)
145
-    {
146
-        $this->request = $request;
147
-    }
148
-
149
-
150
-    /**
151
-     * @param LegacyRequestInterface $legacy_request
152
-     */
153
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
154
-    {
155
-        $this->legacy_request = $legacy_request;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param ResponseInterface $response
161
-     */
162
-    public function setResponse(ResponseInterface $response)
163
-    {
164
-        $this->response = $response;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @param LoaderInterface $loader
171
-     */
172
-    public function setLoader(LoaderInterface $loader)
173
-    {
174
-        $this->loader = $loader;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * @param string $class
181
-     * @param array  $dependencies
182
-     * @param int    $overwrite
183
-     * @return bool
184
-     */
185
-    public static function register_dependencies(
186
-        $class,
187
-        array $dependencies,
188
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
189
-    ) {
190
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * Assigns an array of class names and corresponding load sources (new or cached)
197
-     * to the class specified by the first parameter.
198
-     * IMPORTANT !!!
199
-     * The order of elements in the incoming $dependencies array MUST match
200
-     * the order of the constructor parameters for the class in question.
201
-     * This is especially important when overriding any existing dependencies that are registered.
202
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
203
-     *
204
-     * @param string $class
205
-     * @param array  $dependencies
206
-     * @param int    $overwrite
207
-     * @return bool
208
-     */
209
-    public function registerDependencies(
210
-        $class,
211
-        array $dependencies,
212
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
213
-    ) {
214
-        $class = trim($class, '\\');
215
-        $registered = false;
216
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
217
-            self::$_instance->_dependency_map[ $class ] = array();
218
-        }
219
-        // we need to make sure that any aliases used when registering a dependency
220
-        // get resolved to the correct class name
221
-        foreach ($dependencies as $dependency => $load_source) {
222
-            $alias = self::$_instance->getFqnForAlias($dependency);
223
-            if (
224
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
226
-            ) {
227
-                unset($dependencies[$dependency]);
228
-                $dependencies[$alias] = $load_source;
229
-                $registered = true;
230
-            }
231
-        }
232
-        // now add our two lists of dependencies together.
233
-        // using Union (+=) favours the arrays in precedence from left to right,
234
-        // so $dependencies is NOT overwritten because it is listed first
235
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
236
-        // Union is way faster than array_merge() but should be used with caution...
237
-        // especially with numerically indexed arrays
238
-        $dependencies += self::$_instance->_dependency_map[ $class ];
239
-        // now we need to ensure that the resulting dependencies
240
-        // array only has the entries that are required for the class
241
-        // so first count how many dependencies were originally registered for the class
242
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
243
-        // if that count is non-zero (meaning dependencies were already registered)
244
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
245
-            // then truncate the  final array to match that count
246
-            ? array_slice($dependencies, 0, $dependency_count)
247
-            // otherwise just take the incoming array because nothing previously existed
248
-            : $dependencies;
249
-        return $registered;
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @param string $class_name
256
-     * @param string $loader
257
-     * @return bool
258
-     * @throws DomainException
259
-     */
260
-    public static function register_class_loader($class_name, $loader = 'load_core')
261
-    {
262
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263
-            throw new DomainException(
264
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265
-            );
266
-        }
267
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
268
-        if (
269
-            ! is_callable($loader)
270
-            && (
271
-                strpos($loader, 'load_') !== 0
272
-                || ! method_exists('EE_Registry', $loader)
273
-            )
274
-        ) {
275
-            throw new DomainException(
276
-                sprintf(
277
-                    esc_html__(
278
-                        '"%1$s" is not a valid loader method on EE_Registry.',
279
-                        'event_espresso'
280
-                    ),
281
-                    $loader
282
-                )
283
-            );
284
-        }
285
-        $class_name = self::$_instance->getFqnForAlias($class_name);
286
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
287
-            self::$_instance->_class_loaders[$class_name] = $loader;
288
-            return true;
289
-        }
290
-        return false;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * @return array
297
-     */
298
-    public function dependency_map()
299
-    {
300
-        return $this->_dependency_map;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * returns TRUE if dependency map contains a listing for the provided class name
307
-     *
308
-     * @param string $class_name
309
-     * @return boolean
310
-     */
311
-    public function has($class_name = '')
312
-    {
313
-        // all legacy models have the same dependencies
314
-        if (strpos($class_name, 'EEM_') === 0) {
315
-            $class_name = 'LEGACY_MODELS';
316
-        }
317
-        return isset($this->_dependency_map[$class_name]) ? true : false;
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
324
-     *
325
-     * @param string $class_name
326
-     * @param string $dependency
327
-     * @return bool
328
-     */
329
-    public function has_dependency_for_class($class_name = '', $dependency = '')
330
-    {
331
-        // all legacy models have the same dependencies
332
-        if (strpos($class_name, 'EEM_') === 0) {
333
-            $class_name = 'LEGACY_MODELS';
334
-        }
335
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
336
-        return isset($this->_dependency_map[$class_name][$dependency])
337
-            ? true
338
-            : false;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
345
-     *
346
-     * @param string $class_name
347
-     * @param string $dependency
348
-     * @return int
349
-     */
350
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
351
-    {
352
-        // all legacy models have the same dependencies
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            $class_name = 'LEGACY_MODELS';
355
-        }
356
-        $dependency = $this->getFqnForAlias($dependency);
357
-        return $this->has_dependency_for_class($class_name, $dependency)
358
-            ? $this->_dependency_map[$class_name][$dependency]
359
-            : EE_Dependency_Map::not_registered;
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * @param string $class_name
366
-     * @return string | Closure
367
-     */
368
-    public function class_loader($class_name)
369
-    {
370
-        // all legacy models use load_model()
371
-        if(strpos($class_name, 'EEM_') === 0){
372
-            return 'load_model';
373
-        }
374
-        $class_name = $this->getFqnForAlias($class_name);
375
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * @return array
382
-     */
383
-    public function class_loaders()
384
-    {
385
-        return $this->_class_loaders;
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     * adds an alias for a classname
392
-     *
393
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
394
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
395
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
396
-     */
397
-    public function add_alias($fqcn, $alias, $for_class = '')
398
-    {
399
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Returns TRUE if the provided fully qualified name IS an alias
406
-     * WHY?
407
-     * Because if a class is type hinting for a concretion,
408
-     * then why would we need to find another class to supply it?
409
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
410
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
411
-     * Don't go looking for some substitute.
412
-     * Whereas if a class is type hinting for an interface...
413
-     * then we need to find an actual class to use.
414
-     * So the interface IS the alias for some other FQN,
415
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
416
-     * represents some other class.
417
-     *
418
-     * @param string $fqn
419
-     * @param string $for_class
420
-     * @return bool
421
-     */
422
-    public function isAlias($fqn = '', $for_class = '')
423
-    {
424
-        return $this->class_cache->isAlias($fqn, $for_class);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
431
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
432
-     *  for example:
433
-     *      if the following two entries were added to the _aliases array:
434
-     *          array(
435
-     *              'interface_alias'           => 'some\namespace\interface'
436
-     *              'some\namespace\interface'  => 'some\namespace\classname'
437
-     *          )
438
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
439
-     *      to load an instance of 'some\namespace\classname'
440
-     *
441
-     * @param string $alias
442
-     * @param string $for_class
443
-     * @return string
444
-     */
445
-    public function getFqnForAlias($alias = '', $for_class = '')
446
-    {
447
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
454
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
455
-     * This is done by using the following class constants:
456
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
457
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
458
-     */
459
-    protected function _register_core_dependencies()
460
-    {
461
-        $this->_dependency_map = array(
462
-            'EE_Request_Handler'                                                                                          => array(
463
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_System'                                                                                                   => array(
466
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
467
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
468
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
469
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
470
-            ),
471
-            'EE_Session'                                                                                                  => array(
472
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
473
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
474
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
475
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
476
-            ),
477
-            'EE_Cart'                                                                                                     => array(
478
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EE_Front_Controller'                                                                                         => array(
481
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
482
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
483
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
484
-            ),
485
-            'EE_Messenger_Collection_Loader'                                                                              => array(
486
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
487
-            ),
488
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
489
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
490
-            ),
491
-            'EE_Message_Resource_Manager'                                                                                 => array(
492
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
493
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
494
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EE_Message_Factory'                                                                                          => array(
497
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EE_messages'                                                                                                 => array(
500
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EE_Messages_Generator'                                                                                       => array(
503
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
504
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
505
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
506
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EE_Messages_Processor'                                                                                       => array(
509
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
510
-            ),
511
-            'EE_Messages_Queue'                                                                                           => array(
512
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
513
-            ),
514
-            'EE_Messages_Template_Defaults'                                                                               => array(
515
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
516
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
519
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
520
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
521
-            ),
522
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
523
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
526
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
527
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
528
-            ),
529
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
530
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
533
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
534
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
537
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
540
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
543
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
546
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
549
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
552
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
555
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
558
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
561
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
564
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
567
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
570
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
-            ),
572
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
573
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_Data_Migration_Class_Base'                                                                                => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
595
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
599
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
-            ),
602
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
603
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
607
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
611
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
612
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
615
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
616
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
617
-            ),
618
-            'EventEspresso\core\services\assets\I18nRegistry' => array(
619
-                array(),
620
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
621
-            ),
622
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
623
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
624
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
625
-            ),
626
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
627
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
630
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
-            ),
632
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
633
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
634
-            ),
635
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
636
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
639
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
640
-            ),
641
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
642
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
643
-            ),
644
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
645
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
646
-            ),
647
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
648
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
649
-            ),
650
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
651
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
652
-            ),
653
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
654
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
655
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
656
-            ),
657
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
658
-                null,
659
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
660
-            ),
661
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
662
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
663
-            ),
664
-            'LEGACY_MODELS'                                                   => array(
665
-                null,
666
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
667
-            ),
668
-            'EE_Module_Request_Router' => array(
669
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
670
-            ),
671
-            'EE_Registration_Processor' => array(
672
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
673
-            ),
674
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
675
-                null,
676
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
677
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
678
-            ),
679
-            'EventEspresso\core\services\licensing\LicenseService' => array(
680
-                'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
681
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
682
-            ),
683
-            'EE_Admin_Transactions_List_Table' => array(
684
-                null,
685
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
686
-			),
687
-            'EventEspresso\core\domain\services\pue\Stats' => array(
688
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
689
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
690
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
691
-            ),
692
-            'EventEspresso\core\domain\services\pue\Config' => array(
693
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
694
-                'EE_Config' => EE_Dependency_Map::load_from_cache
695
-            ),
696
-            'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
697
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
698
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
699
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
700
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
701
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
702
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
703
-                'EE_Config' => EE_Dependency_Map::load_from_cache
704
-            ),
705
-            'EventEspresso\core\domain\services\admin\ExitModal' => array(
706
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
707
-            ),
708
-            'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
709
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
710
-            ),
711
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
712
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
713
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
714
-            ),
715
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
716
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
717
-            ),
718
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
719
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
720
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
721
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
722
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
723
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
724
-            ),
725
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
726
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
727
-            ),
728
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
729
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
730
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
731
-            ),
732
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
733
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
734
-            ),
735
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
736
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
737
-            ),
738
-            'EE_CPT_Strategy'   => array(
739
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
740
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
741
-            ),
742
-            'EventEspresso\core\services\loaders\ObjectIdentifier' => array(
743
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
744
-            ),
745
-            'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
746
-                'EventEspresso\core\domain\Domain'            => EE_Dependency_Map::load_from_cache,
747
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
748
-            ),
749
-            'EventEspresso\core\services\assets\AssetManager'                         => array(
750
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
751
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
752
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache
753
-            ),
754
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'              => array(
755
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
756
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
757
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
758
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
759
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
760
-            ),
761
-        );
762
-    }
763
-
764
-
765
-    /**
766
-     * Registers how core classes are loaded.
767
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
768
-     *        'EE_Request_Handler' => 'load_core'
769
-     *        'EE_Messages_Queue'  => 'load_lib'
770
-     *        'EEH_Debug_Tools'    => 'load_helper'
771
-     * or, if greater control is required, by providing a custom closure. For example:
772
-     *        'Some_Class' => function () {
773
-     *            return new Some_Class();
774
-     *        },
775
-     * This is required for instantiating dependencies
776
-     * where an interface has been type hinted in a class constructor. For example:
777
-     *        'Required_Interface' => function () {
778
-     *            return new A_Class_That_Implements_Required_Interface();
779
-     *        },
780
-     *
781
-     */
782
-    protected function _register_core_class_loaders()
783
-    {
784
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
785
-        //be used in a closure.
786
-        $request = &$this->request;
787
-        $response = &$this->response;
788
-        $legacy_request = &$this->legacy_request;
789
-        // $loader = &$this->loader;
790
-        $this->_class_loaders = array(
791
-            //load_core
792
-            'EE_Capabilities'          => 'load_core',
793
-            'EE_Encryption'            => 'load_core',
794
-            'EE_Front_Controller'      => 'load_core',
795
-            'EE_Module_Request_Router' => 'load_core',
796
-            'EE_Registry'              => 'load_core',
797
-            'EE_Request'               => function () use (&$legacy_request) {
798
-                return $legacy_request;
799
-            },
800
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
801
-                return $request;
802
-            },
803
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
804
-                return $response;
805
-            },
806
-            'EE_Base'             => 'load_core',
807
-            'EE_Request_Handler'       => 'load_core',
808
-            'EE_Session'               => 'load_core',
809
-            'EE_Cron_Tasks'            => 'load_core',
810
-            'EE_System'                => 'load_core',
811
-            'EE_Maintenance_Mode'      => 'load_core',
812
-            'EE_Register_CPTs'         => 'load_core',
813
-            'EE_Admin'                 => 'load_core',
814
-            'EE_CPT_Strategy'          => 'load_core',
815
-            //load_lib
816
-            'EE_Message_Resource_Manager'          => 'load_lib',
817
-            'EE_Message_Type_Collection'           => 'load_lib',
818
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
819
-            'EE_Messenger_Collection'              => 'load_lib',
820
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
821
-            'EE_Messages_Processor'                => 'load_lib',
822
-            'EE_Message_Repository'                => 'load_lib',
823
-            'EE_Messages_Queue'                    => 'load_lib',
824
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
825
-            'EE_Message_Template_Group_Collection' => 'load_lib',
826
-            'EE_Payment_Method_Manager'            => 'load_lib',
827
-            'EE_Messages_Generator'                => function () {
828
-                return EE_Registry::instance()->load_lib(
829
-                    'Messages_Generator',
830
-                    array(),
831
-                    false,
832
-                    false
833
-                );
834
-            },
835
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
836
-                return EE_Registry::instance()->load_lib(
837
-                    'Messages_Template_Defaults',
838
-                    $arguments,
839
-                    false,
840
-                    false
841
-                );
842
-            },
843
-            //load_helper
844
-            'EEH_Parse_Shortcodes'                 => function () {
845
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
846
-                    return new EEH_Parse_Shortcodes();
847
-                }
848
-                return null;
849
-            },
850
-            'EE_Template_Config'                   => function () {
851
-                return EE_Config::instance()->template_settings;
852
-            },
853
-            'EE_Currency_Config'                   => function () {
854
-                return EE_Config::instance()->currency;
855
-            },
856
-            'EE_Registration_Config'                   => function () {
857
-                return EE_Config::instance()->registration;
858
-            },
859
-            'EE_Core_Config'                   => function () {
860
-                return EE_Config::instance()->core;
861
-            },
862
-            'EventEspresso\core\services\loaders\Loader' => function () {
863
-                return LoaderFactory::getLoader();
864
-            },
865
-            'EE_Network_Config' => function() {
866
-                return EE_Network_Config::instance();
867
-            },
868
-            'EE_Config' => function () {
869
-                return EE_Config::instance();
870
-            },
871
-            'EventEspresso\core\domain\Domain' => function () {
872
-                return DomainFactory::getEventEspressoCoreDomain();
873
-            },
874
-        );
875
-    }
876
-
877
-
878
-
879
-
880
-    /**
881
-     * can be used for supplying alternate names for classes,
882
-     * or for connecting interface names to instantiable classes
883
-     */
884
-    protected function _register_core_aliases()
885
-    {
886
-        $aliases = array(
887
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
888
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
889
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
890
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
891
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
892
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
893
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
894
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
895
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
896
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
897
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
898
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
899
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
900
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
901
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
902
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
903
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
904
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
905
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
906
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
907
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
908
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
909
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
910
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
911
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
912
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
913
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
914
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
915
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
916
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
917
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
918
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
919
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
920
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
921
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
922
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
923
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
924
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
925
-        );
926
-        foreach ($aliases as $alias => $fqn) {
927
-            if(is_array($fqn)) {
928
-                foreach ($fqn as $class => $for_class) {
929
-                    $this->class_cache->addAlias($class, $alias, $for_class);
930
-                }
931
-                continue;
932
-            }
933
-            $this->class_cache->addAlias($fqn, $alias);
934
-        }
935
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
936
-            $this->class_cache->addAlias(
937
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
938
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
939
-            );
940
-        }
941
-    }
942
-
943
-
944
-
945
-    /**
946
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
947
-     * request Primarily used by unit tests.
948
-     */
949
-    public function reset()
950
-    {
951
-        $this->_register_core_class_loaders();
952
-        $this->_register_core_dependencies();
953
-    }
954
-
955
-
956
-    /**
957
-     * PLZ NOTE: a better name for this method would be is_alias()
958
-     * because it returns TRUE if the provided fully qualified name IS an alias
959
-     * WHY?
960
-     * Because if a class is type hinting for a concretion,
961
-     * then why would we need to find another class to supply it?
962
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
963
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
964
-     * Don't go looking for some substitute.
965
-     * Whereas if a class is type hinting for an interface...
966
-     * then we need to find an actual class to use.
967
-     * So the interface IS the alias for some other FQN,
968
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
969
-     * represents some other class.
970
-     *
971
-     * @deprecated $VID:$
972
-     * @param string $fqn
973
-     * @param string $for_class
974
-     * @return bool
975
-     */
976
-    public function has_alias($fqn = '', $for_class = '')
977
-    {
978
-        return $this->isAlias($fqn, $for_class);
979
-    }
980
-
981
-
982
-    /**
983
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
984
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
985
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
986
-     *  for example:
987
-     *      if the following two entries were added to the _aliases array:
988
-     *          array(
989
-     *              'interface_alias'           => 'some\namespace\interface'
990
-     *              'some\namespace\interface'  => 'some\namespace\classname'
991
-     *          )
992
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
993
-     *      to load an instance of 'some\namespace\classname'
994
-     *
995
-     * @deprecated $VID:$
996
-     * @param string $alias
997
-     * @param string $for_class
998
-     * @return string
999
-     */
1000
-    public function get_alias($alias = '', $for_class = '')
1001
-    {
1002
-        return $this->getFqnForAlias($alias, $for_class);
1003
-    }
29
+	/**
30
+	 * This means that the requested class dependency is not present in the dependency map
31
+	 */
32
+	const not_registered = 0;
33
+
34
+	/**
35
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
36
+	 */
37
+	const load_new_object = 1;
38
+
39
+	/**
40
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
41
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
42
+	 */
43
+	const load_from_cache = 2;
44
+
45
+	/**
46
+	 * When registering a dependency,
47
+	 * this indicates to keep any existing dependencies that already exist,
48
+	 * and simply discard any new dependencies declared in the incoming data
49
+	 */
50
+	const KEEP_EXISTING_DEPENDENCIES = 0;
51
+
52
+	/**
53
+	 * When registering a dependency,
54
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
55
+	 */
56
+	const OVERWRITE_DEPENDENCIES = 1;
57
+
58
+
59
+
60
+	/**
61
+	 * @type EE_Dependency_Map $_instance
62
+	 */
63
+	protected static $_instance;
64
+
65
+	/**
66
+	 * @var ClassInterfaceCache $class_cache
67
+	 */
68
+	private $class_cache;
69
+
70
+	/**
71
+	 * @type RequestInterface $request
72
+	 */
73
+	protected $request;
74
+
75
+	/**
76
+	 * @type LegacyRequestInterface $legacy_request
77
+	 */
78
+	protected $legacy_request;
79
+
80
+	/**
81
+	 * @type ResponseInterface $response
82
+	 */
83
+	protected $response;
84
+
85
+	/**
86
+	 * @type LoaderInterface $loader
87
+	 */
88
+	protected $loader;
89
+
90
+	/**
91
+	 * @type array $_dependency_map
92
+	 */
93
+	protected $_dependency_map = array();
94
+
95
+	/**
96
+	 * @type array $_class_loaders
97
+	 */
98
+	protected $_class_loaders = array();
99
+
100
+
101
+	/**
102
+	 * EE_Dependency_Map constructor.
103
+	 *
104
+	 * @param ClassInterfaceCache $class_cache
105
+	 */
106
+	protected function __construct(ClassInterfaceCache $class_cache)
107
+	{
108
+		$this->class_cache = $class_cache;
109
+		do_action('EE_Dependency_Map____construct', $this);
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return void
115
+	 */
116
+	public function initialize()
117
+	{
118
+		$this->_register_core_dependencies();
119
+		$this->_register_core_class_loaders();
120
+		$this->_register_core_aliases();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @singleton method used to instantiate class object
126
+	 * @param ClassInterfaceCache|null $class_cache
127
+	 * @return EE_Dependency_Map
128
+	 */
129
+	public static function instance(ClassInterfaceCache $class_cache = null) {
130
+		// check if class object is instantiated, and instantiated properly
131
+		if (
132
+			! self::$_instance instanceof EE_Dependency_Map
133
+			&& $class_cache instanceof ClassInterfaceCache
134
+		) {
135
+			self::$_instance = new EE_Dependency_Map($class_cache);
136
+		}
137
+		return self::$_instance;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param RequestInterface $request
143
+	 */
144
+	public function setRequest(RequestInterface $request)
145
+	{
146
+		$this->request = $request;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param LegacyRequestInterface $legacy_request
152
+	 */
153
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
154
+	{
155
+		$this->legacy_request = $legacy_request;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param ResponseInterface $response
161
+	 */
162
+	public function setResponse(ResponseInterface $response)
163
+	{
164
+		$this->response = $response;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @param LoaderInterface $loader
171
+	 */
172
+	public function setLoader(LoaderInterface $loader)
173
+	{
174
+		$this->loader = $loader;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * @param string $class
181
+	 * @param array  $dependencies
182
+	 * @param int    $overwrite
183
+	 * @return bool
184
+	 */
185
+	public static function register_dependencies(
186
+		$class,
187
+		array $dependencies,
188
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
189
+	) {
190
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * Assigns an array of class names and corresponding load sources (new or cached)
197
+	 * to the class specified by the first parameter.
198
+	 * IMPORTANT !!!
199
+	 * The order of elements in the incoming $dependencies array MUST match
200
+	 * the order of the constructor parameters for the class in question.
201
+	 * This is especially important when overriding any existing dependencies that are registered.
202
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
203
+	 *
204
+	 * @param string $class
205
+	 * @param array  $dependencies
206
+	 * @param int    $overwrite
207
+	 * @return bool
208
+	 */
209
+	public function registerDependencies(
210
+		$class,
211
+		array $dependencies,
212
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
213
+	) {
214
+		$class = trim($class, '\\');
215
+		$registered = false;
216
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
217
+			self::$_instance->_dependency_map[ $class ] = array();
218
+		}
219
+		// we need to make sure that any aliases used when registering a dependency
220
+		// get resolved to the correct class name
221
+		foreach ($dependencies as $dependency => $load_source) {
222
+			$alias = self::$_instance->getFqnForAlias($dependency);
223
+			if (
224
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
226
+			) {
227
+				unset($dependencies[$dependency]);
228
+				$dependencies[$alias] = $load_source;
229
+				$registered = true;
230
+			}
231
+		}
232
+		// now add our two lists of dependencies together.
233
+		// using Union (+=) favours the arrays in precedence from left to right,
234
+		// so $dependencies is NOT overwritten because it is listed first
235
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
236
+		// Union is way faster than array_merge() but should be used with caution...
237
+		// especially with numerically indexed arrays
238
+		$dependencies += self::$_instance->_dependency_map[ $class ];
239
+		// now we need to ensure that the resulting dependencies
240
+		// array only has the entries that are required for the class
241
+		// so first count how many dependencies were originally registered for the class
242
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
243
+		// if that count is non-zero (meaning dependencies were already registered)
244
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
245
+			// then truncate the  final array to match that count
246
+			? array_slice($dependencies, 0, $dependency_count)
247
+			// otherwise just take the incoming array because nothing previously existed
248
+			: $dependencies;
249
+		return $registered;
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @param string $class_name
256
+	 * @param string $loader
257
+	 * @return bool
258
+	 * @throws DomainException
259
+	 */
260
+	public static function register_class_loader($class_name, $loader = 'load_core')
261
+	{
262
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263
+			throw new DomainException(
264
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265
+			);
266
+		}
267
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
268
+		if (
269
+			! is_callable($loader)
270
+			&& (
271
+				strpos($loader, 'load_') !== 0
272
+				|| ! method_exists('EE_Registry', $loader)
273
+			)
274
+		) {
275
+			throw new DomainException(
276
+				sprintf(
277
+					esc_html__(
278
+						'"%1$s" is not a valid loader method on EE_Registry.',
279
+						'event_espresso'
280
+					),
281
+					$loader
282
+				)
283
+			);
284
+		}
285
+		$class_name = self::$_instance->getFqnForAlias($class_name);
286
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
287
+			self::$_instance->_class_loaders[$class_name] = $loader;
288
+			return true;
289
+		}
290
+		return false;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * @return array
297
+	 */
298
+	public function dependency_map()
299
+	{
300
+		return $this->_dependency_map;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * returns TRUE if dependency map contains a listing for the provided class name
307
+	 *
308
+	 * @param string $class_name
309
+	 * @return boolean
310
+	 */
311
+	public function has($class_name = '')
312
+	{
313
+		// all legacy models have the same dependencies
314
+		if (strpos($class_name, 'EEM_') === 0) {
315
+			$class_name = 'LEGACY_MODELS';
316
+		}
317
+		return isset($this->_dependency_map[$class_name]) ? true : false;
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
324
+	 *
325
+	 * @param string $class_name
326
+	 * @param string $dependency
327
+	 * @return bool
328
+	 */
329
+	public function has_dependency_for_class($class_name = '', $dependency = '')
330
+	{
331
+		// all legacy models have the same dependencies
332
+		if (strpos($class_name, 'EEM_') === 0) {
333
+			$class_name = 'LEGACY_MODELS';
334
+		}
335
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
336
+		return isset($this->_dependency_map[$class_name][$dependency])
337
+			? true
338
+			: false;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
345
+	 *
346
+	 * @param string $class_name
347
+	 * @param string $dependency
348
+	 * @return int
349
+	 */
350
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
351
+	{
352
+		// all legacy models have the same dependencies
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			$class_name = 'LEGACY_MODELS';
355
+		}
356
+		$dependency = $this->getFqnForAlias($dependency);
357
+		return $this->has_dependency_for_class($class_name, $dependency)
358
+			? $this->_dependency_map[$class_name][$dependency]
359
+			: EE_Dependency_Map::not_registered;
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * @param string $class_name
366
+	 * @return string | Closure
367
+	 */
368
+	public function class_loader($class_name)
369
+	{
370
+		// all legacy models use load_model()
371
+		if(strpos($class_name, 'EEM_') === 0){
372
+			return 'load_model';
373
+		}
374
+		$class_name = $this->getFqnForAlias($class_name);
375
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * @return array
382
+	 */
383
+	public function class_loaders()
384
+	{
385
+		return $this->_class_loaders;
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 * adds an alias for a classname
392
+	 *
393
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
394
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
395
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
396
+	 */
397
+	public function add_alias($fqcn, $alias, $for_class = '')
398
+	{
399
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Returns TRUE if the provided fully qualified name IS an alias
406
+	 * WHY?
407
+	 * Because if a class is type hinting for a concretion,
408
+	 * then why would we need to find another class to supply it?
409
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
410
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
411
+	 * Don't go looking for some substitute.
412
+	 * Whereas if a class is type hinting for an interface...
413
+	 * then we need to find an actual class to use.
414
+	 * So the interface IS the alias for some other FQN,
415
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
416
+	 * represents some other class.
417
+	 *
418
+	 * @param string $fqn
419
+	 * @param string $for_class
420
+	 * @return bool
421
+	 */
422
+	public function isAlias($fqn = '', $for_class = '')
423
+	{
424
+		return $this->class_cache->isAlias($fqn, $for_class);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
431
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
432
+	 *  for example:
433
+	 *      if the following two entries were added to the _aliases array:
434
+	 *          array(
435
+	 *              'interface_alias'           => 'some\namespace\interface'
436
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
437
+	 *          )
438
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
439
+	 *      to load an instance of 'some\namespace\classname'
440
+	 *
441
+	 * @param string $alias
442
+	 * @param string $for_class
443
+	 * @return string
444
+	 */
445
+	public function getFqnForAlias($alias = '', $for_class = '')
446
+	{
447
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
454
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
455
+	 * This is done by using the following class constants:
456
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
457
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
458
+	 */
459
+	protected function _register_core_dependencies()
460
+	{
461
+		$this->_dependency_map = array(
462
+			'EE_Request_Handler'                                                                                          => array(
463
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_System'                                                                                                   => array(
466
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
467
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
468
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
469
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
470
+			),
471
+			'EE_Session'                                                                                                  => array(
472
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
473
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
474
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
475
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
476
+			),
477
+			'EE_Cart'                                                                                                     => array(
478
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EE_Front_Controller'                                                                                         => array(
481
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
482
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
483
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
484
+			),
485
+			'EE_Messenger_Collection_Loader'                                                                              => array(
486
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
487
+			),
488
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
489
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
490
+			),
491
+			'EE_Message_Resource_Manager'                                                                                 => array(
492
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
493
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
494
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EE_Message_Factory'                                                                                          => array(
497
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EE_messages'                                                                                                 => array(
500
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EE_Messages_Generator'                                                                                       => array(
503
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
504
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
505
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
506
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EE_Messages_Processor'                                                                                       => array(
509
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
510
+			),
511
+			'EE_Messages_Queue'                                                                                           => array(
512
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
513
+			),
514
+			'EE_Messages_Template_Defaults'                                                                               => array(
515
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
516
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
519
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
520
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
521
+			),
522
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
523
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
526
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
527
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
528
+			),
529
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
530
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
533
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
534
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
537
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
540
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
543
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
546
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
549
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
552
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
555
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
558
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
561
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
564
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
567
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
570
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
+			),
572
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
573
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_Data_Migration_Class_Base'                                                                                => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
595
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
599
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
+			),
602
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
603
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
607
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
611
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
612
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
615
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
616
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
617
+			),
618
+			'EventEspresso\core\services\assets\I18nRegistry' => array(
619
+				array(),
620
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
621
+			),
622
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
623
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
624
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
625
+			),
626
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
627
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
630
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
+			),
632
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
633
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
634
+			),
635
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
636
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
639
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
640
+			),
641
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
642
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
643
+			),
644
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
645
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
646
+			),
647
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
648
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
649
+			),
650
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
651
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
652
+			),
653
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
654
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
655
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
656
+			),
657
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
658
+				null,
659
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
660
+			),
661
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
662
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
663
+			),
664
+			'LEGACY_MODELS'                                                   => array(
665
+				null,
666
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
667
+			),
668
+			'EE_Module_Request_Router' => array(
669
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
670
+			),
671
+			'EE_Registration_Processor' => array(
672
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
673
+			),
674
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
675
+				null,
676
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
677
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
678
+			),
679
+			'EventEspresso\core\services\licensing\LicenseService' => array(
680
+				'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
681
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
682
+			),
683
+			'EE_Admin_Transactions_List_Table' => array(
684
+				null,
685
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
686
+			),
687
+			'EventEspresso\core\domain\services\pue\Stats' => array(
688
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
689
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
690
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
691
+			),
692
+			'EventEspresso\core\domain\services\pue\Config' => array(
693
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
694
+				'EE_Config' => EE_Dependency_Map::load_from_cache
695
+			),
696
+			'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
697
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
698
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
699
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
700
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
701
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
702
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
703
+				'EE_Config' => EE_Dependency_Map::load_from_cache
704
+			),
705
+			'EventEspresso\core\domain\services\admin\ExitModal' => array(
706
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
707
+			),
708
+			'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
709
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
710
+			),
711
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
712
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
713
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
714
+			),
715
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
716
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
717
+			),
718
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
719
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
720
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
721
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
722
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
723
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
724
+			),
725
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
726
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
727
+			),
728
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
729
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
730
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
731
+			),
732
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
733
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
734
+			),
735
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
736
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
737
+			),
738
+			'EE_CPT_Strategy'   => array(
739
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
740
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
741
+			),
742
+			'EventEspresso\core\services\loaders\ObjectIdentifier' => array(
743
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
744
+			),
745
+			'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
746
+				'EventEspresso\core\domain\Domain'            => EE_Dependency_Map::load_from_cache,
747
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
748
+			),
749
+			'EventEspresso\core\services\assets\AssetManager'                         => array(
750
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
751
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
752
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache
753
+			),
754
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'              => array(
755
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
756
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
757
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
758
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
759
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
760
+			),
761
+		);
762
+	}
763
+
764
+
765
+	/**
766
+	 * Registers how core classes are loaded.
767
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
768
+	 *        'EE_Request_Handler' => 'load_core'
769
+	 *        'EE_Messages_Queue'  => 'load_lib'
770
+	 *        'EEH_Debug_Tools'    => 'load_helper'
771
+	 * or, if greater control is required, by providing a custom closure. For example:
772
+	 *        'Some_Class' => function () {
773
+	 *            return new Some_Class();
774
+	 *        },
775
+	 * This is required for instantiating dependencies
776
+	 * where an interface has been type hinted in a class constructor. For example:
777
+	 *        'Required_Interface' => function () {
778
+	 *            return new A_Class_That_Implements_Required_Interface();
779
+	 *        },
780
+	 *
781
+	 */
782
+	protected function _register_core_class_loaders()
783
+	{
784
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
785
+		//be used in a closure.
786
+		$request = &$this->request;
787
+		$response = &$this->response;
788
+		$legacy_request = &$this->legacy_request;
789
+		// $loader = &$this->loader;
790
+		$this->_class_loaders = array(
791
+			//load_core
792
+			'EE_Capabilities'          => 'load_core',
793
+			'EE_Encryption'            => 'load_core',
794
+			'EE_Front_Controller'      => 'load_core',
795
+			'EE_Module_Request_Router' => 'load_core',
796
+			'EE_Registry'              => 'load_core',
797
+			'EE_Request'               => function () use (&$legacy_request) {
798
+				return $legacy_request;
799
+			},
800
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
801
+				return $request;
802
+			},
803
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
804
+				return $response;
805
+			},
806
+			'EE_Base'             => 'load_core',
807
+			'EE_Request_Handler'       => 'load_core',
808
+			'EE_Session'               => 'load_core',
809
+			'EE_Cron_Tasks'            => 'load_core',
810
+			'EE_System'                => 'load_core',
811
+			'EE_Maintenance_Mode'      => 'load_core',
812
+			'EE_Register_CPTs'         => 'load_core',
813
+			'EE_Admin'                 => 'load_core',
814
+			'EE_CPT_Strategy'          => 'load_core',
815
+			//load_lib
816
+			'EE_Message_Resource_Manager'          => 'load_lib',
817
+			'EE_Message_Type_Collection'           => 'load_lib',
818
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
819
+			'EE_Messenger_Collection'              => 'load_lib',
820
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
821
+			'EE_Messages_Processor'                => 'load_lib',
822
+			'EE_Message_Repository'                => 'load_lib',
823
+			'EE_Messages_Queue'                    => 'load_lib',
824
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
825
+			'EE_Message_Template_Group_Collection' => 'load_lib',
826
+			'EE_Payment_Method_Manager'            => 'load_lib',
827
+			'EE_Messages_Generator'                => function () {
828
+				return EE_Registry::instance()->load_lib(
829
+					'Messages_Generator',
830
+					array(),
831
+					false,
832
+					false
833
+				);
834
+			},
835
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
836
+				return EE_Registry::instance()->load_lib(
837
+					'Messages_Template_Defaults',
838
+					$arguments,
839
+					false,
840
+					false
841
+				);
842
+			},
843
+			//load_helper
844
+			'EEH_Parse_Shortcodes'                 => function () {
845
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
846
+					return new EEH_Parse_Shortcodes();
847
+				}
848
+				return null;
849
+			},
850
+			'EE_Template_Config'                   => function () {
851
+				return EE_Config::instance()->template_settings;
852
+			},
853
+			'EE_Currency_Config'                   => function () {
854
+				return EE_Config::instance()->currency;
855
+			},
856
+			'EE_Registration_Config'                   => function () {
857
+				return EE_Config::instance()->registration;
858
+			},
859
+			'EE_Core_Config'                   => function () {
860
+				return EE_Config::instance()->core;
861
+			},
862
+			'EventEspresso\core\services\loaders\Loader' => function () {
863
+				return LoaderFactory::getLoader();
864
+			},
865
+			'EE_Network_Config' => function() {
866
+				return EE_Network_Config::instance();
867
+			},
868
+			'EE_Config' => function () {
869
+				return EE_Config::instance();
870
+			},
871
+			'EventEspresso\core\domain\Domain' => function () {
872
+				return DomainFactory::getEventEspressoCoreDomain();
873
+			},
874
+		);
875
+	}
876
+
877
+
878
+
879
+
880
+	/**
881
+	 * can be used for supplying alternate names for classes,
882
+	 * or for connecting interface names to instantiable classes
883
+	 */
884
+	protected function _register_core_aliases()
885
+	{
886
+		$aliases = array(
887
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
888
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
889
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
890
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
891
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
892
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
893
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
894
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
895
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
896
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
897
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
898
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
899
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
900
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
901
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
902
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
903
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
904
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
905
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
906
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
907
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
908
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
909
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
910
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
911
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
912
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
913
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
914
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
915
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
916
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
917
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
918
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
919
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
920
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
921
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
922
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
923
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
924
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
925
+		);
926
+		foreach ($aliases as $alias => $fqn) {
927
+			if(is_array($fqn)) {
928
+				foreach ($fqn as $class => $for_class) {
929
+					$this->class_cache->addAlias($class, $alias, $for_class);
930
+				}
931
+				continue;
932
+			}
933
+			$this->class_cache->addAlias($fqn, $alias);
934
+		}
935
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
936
+			$this->class_cache->addAlias(
937
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
938
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
939
+			);
940
+		}
941
+	}
942
+
943
+
944
+
945
+	/**
946
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
947
+	 * request Primarily used by unit tests.
948
+	 */
949
+	public function reset()
950
+	{
951
+		$this->_register_core_class_loaders();
952
+		$this->_register_core_dependencies();
953
+	}
954
+
955
+
956
+	/**
957
+	 * PLZ NOTE: a better name for this method would be is_alias()
958
+	 * because it returns TRUE if the provided fully qualified name IS an alias
959
+	 * WHY?
960
+	 * Because if a class is type hinting for a concretion,
961
+	 * then why would we need to find another class to supply it?
962
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
963
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
964
+	 * Don't go looking for some substitute.
965
+	 * Whereas if a class is type hinting for an interface...
966
+	 * then we need to find an actual class to use.
967
+	 * So the interface IS the alias for some other FQN,
968
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
969
+	 * represents some other class.
970
+	 *
971
+	 * @deprecated $VID:$
972
+	 * @param string $fqn
973
+	 * @param string $for_class
974
+	 * @return bool
975
+	 */
976
+	public function has_alias($fqn = '', $for_class = '')
977
+	{
978
+		return $this->isAlias($fqn, $for_class);
979
+	}
980
+
981
+
982
+	/**
983
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
984
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
985
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
986
+	 *  for example:
987
+	 *      if the following two entries were added to the _aliases array:
988
+	 *          array(
989
+	 *              'interface_alias'           => 'some\namespace\interface'
990
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
991
+	 *          )
992
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
993
+	 *      to load an instance of 'some\namespace\classname'
994
+	 *
995
+	 * @deprecated $VID:$
996
+	 * @param string $alias
997
+	 * @param string $for_class
998
+	 * @return string
999
+	 */
1000
+	public function get_alias($alias = '', $for_class = '')
1001
+	{
1002
+		return $this->getFqnForAlias($alias, $for_class);
1003
+	}
1004 1004
 }
1005 1005
 // End of file EE_Dependency_Map.core.php
1006 1006
 // Location: /EE_Dependency_Map.core.php
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Indentation   +330 added lines, -330 removed lines patch added patch discarded remove patch
@@ -20,336 +20,336 @@
 block discarded – undo
20 20
 class Benchmark
21 21
 {
22 22
 
23
-    /**
24
-     * @var string $output
25
-     */
26
-    private static $output;
27
-
28
-    /**
29
-     * @var array $start_times array containing the start time for the timers
30
-     */
31
-    private static $start_times;
32
-
33
-    /**
34
-     * @var array $times array containing all the timer'd times, which can be outputted via show_times()
35
-     */
36
-    private static $times = array();
37
-
38
-    /**
39
-     * @var array $memory_usage
40
-     */
41
-    protected static $memory_usage = array();
42
-
43
-
44
-    /**
45
-     * @param string $output
46
-     * @param bool   $formatted
47
-     */
48
-    public static function addOutput($output, $formatted = true)
49
-    {
50
-        Benchmark::$output .= $formatted
51
-            ? "<br />{$output}"
52
-            : "\n{$output}";
53
-    }
54
-
55
-
56
-    /**
57
-     * @return void
58
-     */
59
-    public static function resetOutput()
60
-    {
61
-        Benchmark::$output = '';
62
-    }
63
-
64
-    /**
65
-     * whether to benchmark code or not
66
-     */
67
-    public static function doNotRun()
68
-    {
69
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * resetTimes
76
-     */
77
-    public static function resetTimes()
78
-    {
79
-        Benchmark::$times = array();
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
86
-     *
87
-     * @param null $timer_name
88
-     */
89
-    public static function startTimer($timer_name = null)
90
-    {
91
-        if (Benchmark::doNotRun()) {
92
-            return;
93
-        }
94
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
95
-        Benchmark::$start_times[$timer_name] = microtime(true);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
102
-     *
103
-     * @param string $timer_name
104
-     */
105
-    public static function stopTimer($timer_name = '')
106
-    {
107
-        if (Benchmark::doNotRun()) {
108
-            return;
109
-        }
110
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
111
-        if (isset(Benchmark::$start_times[$timer_name])) {
112
-            $start_time = Benchmark::$start_times[$timer_name];
113
-            unset(Benchmark::$start_times[$timer_name]);
114
-        } else {
115
-            $start_time = array_pop(Benchmark::$start_times);
116
-        }
117
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * Measure the memory usage by PHP so far.
124
-     *
125
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
126
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
127
-     * @param bool    $formatted
128
-     * @return void
129
-     */
130
-    public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
131
-    {
132
-        if (Benchmark::doNotRun()) {
133
-            return;
134
-        }
135
-        $memory_used = Benchmark::convert(memory_get_usage(true));
136
-        Benchmark::$memory_usage[$label] = $memory_used;
137
-        if ($output_now) {
138
-            echo $formatted
139
-                ? "<br>{$label} : {$memory_used}"
140
-                : "\n {$label} : {$memory_used}";
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * will display the benchmarking results at shutdown
148
-     *
149
-     * @param bool $formatted
150
-     * @return void
151
-     */
152
-    public static function displayResultsAtShutdown($formatted = true)
153
-    {
154
-        Benchmark::resetOutput();
155
-        add_action(
156
-            'shutdown',
157
-            function () use ($formatted) {
158
-                Benchmark::displayResults(true, $formatted);
159
-            },
160
-            999999
161
-        );
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * will display the benchmarking results at shutdown
168
-     *
169
-     * @param string $filepath
170
-     * @param bool   $formatted
171
-     * @param bool   $append
172
-     * @return void
173
-     */
174
-    public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
175
-    {
176
-        Benchmark::resetOutput();
177
-        add_action(
178
-            'shutdown',
179
-            function () use ($filepath, $formatted, $append) {
180
-                Benchmark::writeResultsToFile($filepath, $formatted, $append);
181
-            },
182
-            999999
183
-        );
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param bool $formatted
190
-     * @return string
191
-     */
192
-    private static function generateResults($formatted = true)
193
-    {
194
-        if (Benchmark::doNotRun()) {
195
-            return '';
196
-        }
197
-        if (! empty(Benchmark::$times)) {
198
-            $total = 0;
199
-            Benchmark::$output .= $formatted
200
-                ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
201
-                : '';
202
-            foreach (Benchmark::$times as $timer_name => $total_time) {
203
-                Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
204
-                Benchmark::$output .= $formatted ? '<br />'  : "\n";
205
-                $total += $total_time;
206
-            }
207
-            if($formatted) {
208
-                Benchmark::$output .= '<br />';
209
-                Benchmark::$output .= '<h4>TOTAL TIME</h4>';
210
-                Benchmark::$output .= Benchmark::formatTime('', $total, $formatted);
211
-                Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
212
-                Benchmark::$output .= '<br />';
213
-                Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>';
214
-                Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
215
-                Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
216
-                Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
217
-                Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />';
218
-                Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />';
219
-                Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
220
-            }
221
-        }
222
-        if (! empty(Benchmark::$memory_usage)) {
223
-            Benchmark::$output .= $formatted
224
-                ? '<h5>Memory</h5>'
225
-                : "\nMemory";
226
-            foreach (Benchmark::$memory_usage as $label => $memory_usage) {
227
-                Benchmark::$output .= $formatted
228
-                    ? "<br />{$memory_usage} : {$label}"
229
-                    : "\n{$memory_usage} : {$label}";
230
-            }
231
-        }
232
-        if (empty(Benchmark::$output)) {
233
-            return '';
234
-        }
235
-        Benchmark::$output = $formatted
236
-            ? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
237
-              . (is_admin()
238
-                ? ' margin:2em 2em 2em 180px;'
239
-                : ' margin:2em;')
240
-              . ' padding:2em;">'
241
-              . '<h4>BENCHMARKING</h4>'
242
-              . Benchmark::$output
243
-              . '</div>'
244
-            : Benchmark::$output;
245
-        return Benchmark::$output;
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * @param bool $echo
252
-     * @param bool $formatted
253
-     * @return string
254
-     */
255
-    public static function displayResults($echo = true, $formatted = true)
256
-    {
257
-        $results = Benchmark::generateResults($formatted);
258
-        if ($echo) {
259
-            echo $results;
260
-            $results = '';
261
-        }
262
-        return $results;
263
-    }
264
-
265
-
266
-    /**
267
-     * @param string $filepath
268
-     * @param bool   $formatted
269
-     * @param bool   $append
270
-     * @throws EE_Error
271
-     */
272
-    public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
273
-    {
274
-        $filepath = ! empty($filepath) && is_readable(dirname($filepath))
275
-            ? $filepath
276
-            : '';
277
-        if( empty($filepath)) {
278
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
279
-        }
280
-        EEH_File::ensure_file_exists_and_is_writable($filepath);
281
-        file_put_contents(
282
-            $filepath,
283
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
284
-            $append ? FILE_APPEND | LOCK_EX : LOCK_EX
285
-        );
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
292
-     *
293
-     * @param int $size
294
-     * @return string
295
-     */
296
-    public static function convert($size)
297
-    {
298
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
299
-        return round(
300
-            $size / pow(1024, $i = floor(log($size, 1024))),
301
-            2
302
-        ) . ' ' . $unit[absint($i)];
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * @param string $timer_name
309
-     * @param float  $total_time
310
-     * @param bool   $formatted
311
-     * @return string
312
-     */
313
-    public static function formatTime($timer_name, $total_time, $formatted = true)
314
-    {
315
-        $total_time *= 1000;
316
-        switch ($total_time) {
317
-            case $total_time > 12500 :
318
-                $color = 'red';
319
-                $bold = 'bold';
320
-                break;
321
-            case $total_time > 2500 :
322
-                $color = 'darkorange';
323
-                $bold = 'bold';
324
-                break;
325
-            case $total_time > 500 :
326
-                $color = 'gold';
327
-                $bold = 'bold';
328
-                break;
329
-            case $total_time > 100 :
330
-                $color = 'limegreen';
331
-                $bold = 'normal';
332
-                break;
333
-            case $total_time > 20 :
334
-                $color = 'deepskyblue';
335
-                $bold = 'normal';
336
-                break;
337
-            default :
338
-                $color = 'mediumpurple';
339
-                $bold = 'normal';
340
-                break;
341
-        }
342
-        return $formatted
343
-            ? '<span style="min-width: 10px; margin:0 1em; color:'
344
-               . $color
345
-               . '; font-weight:'
346
-               . $bold
347
-               . '; font-size:1.2em;">'
348
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
349
-               . '</span> '
350
-               . $timer_name
351
-            :  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
352
-    }
23
+	/**
24
+	 * @var string $output
25
+	 */
26
+	private static $output;
27
+
28
+	/**
29
+	 * @var array $start_times array containing the start time for the timers
30
+	 */
31
+	private static $start_times;
32
+
33
+	/**
34
+	 * @var array $times array containing all the timer'd times, which can be outputted via show_times()
35
+	 */
36
+	private static $times = array();
37
+
38
+	/**
39
+	 * @var array $memory_usage
40
+	 */
41
+	protected static $memory_usage = array();
42
+
43
+
44
+	/**
45
+	 * @param string $output
46
+	 * @param bool   $formatted
47
+	 */
48
+	public static function addOutput($output, $formatted = true)
49
+	{
50
+		Benchmark::$output .= $formatted
51
+			? "<br />{$output}"
52
+			: "\n{$output}";
53
+	}
54
+
55
+
56
+	/**
57
+	 * @return void
58
+	 */
59
+	public static function resetOutput()
60
+	{
61
+		Benchmark::$output = '';
62
+	}
63
+
64
+	/**
65
+	 * whether to benchmark code or not
66
+	 */
67
+	public static function doNotRun()
68
+	{
69
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * resetTimes
76
+	 */
77
+	public static function resetTimes()
78
+	{
79
+		Benchmark::$times = array();
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
86
+	 *
87
+	 * @param null $timer_name
88
+	 */
89
+	public static function startTimer($timer_name = null)
90
+	{
91
+		if (Benchmark::doNotRun()) {
92
+			return;
93
+		}
94
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
95
+		Benchmark::$start_times[$timer_name] = microtime(true);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
102
+	 *
103
+	 * @param string $timer_name
104
+	 */
105
+	public static function stopTimer($timer_name = '')
106
+	{
107
+		if (Benchmark::doNotRun()) {
108
+			return;
109
+		}
110
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
111
+		if (isset(Benchmark::$start_times[$timer_name])) {
112
+			$start_time = Benchmark::$start_times[$timer_name];
113
+			unset(Benchmark::$start_times[$timer_name]);
114
+		} else {
115
+			$start_time = array_pop(Benchmark::$start_times);
116
+		}
117
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * Measure the memory usage by PHP so far.
124
+	 *
125
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
126
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
127
+	 * @param bool    $formatted
128
+	 * @return void
129
+	 */
130
+	public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
131
+	{
132
+		if (Benchmark::doNotRun()) {
133
+			return;
134
+		}
135
+		$memory_used = Benchmark::convert(memory_get_usage(true));
136
+		Benchmark::$memory_usage[$label] = $memory_used;
137
+		if ($output_now) {
138
+			echo $formatted
139
+				? "<br>{$label} : {$memory_used}"
140
+				: "\n {$label} : {$memory_used}";
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * will display the benchmarking results at shutdown
148
+	 *
149
+	 * @param bool $formatted
150
+	 * @return void
151
+	 */
152
+	public static function displayResultsAtShutdown($formatted = true)
153
+	{
154
+		Benchmark::resetOutput();
155
+		add_action(
156
+			'shutdown',
157
+			function () use ($formatted) {
158
+				Benchmark::displayResults(true, $formatted);
159
+			},
160
+			999999
161
+		);
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * will display the benchmarking results at shutdown
168
+	 *
169
+	 * @param string $filepath
170
+	 * @param bool   $formatted
171
+	 * @param bool   $append
172
+	 * @return void
173
+	 */
174
+	public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
175
+	{
176
+		Benchmark::resetOutput();
177
+		add_action(
178
+			'shutdown',
179
+			function () use ($filepath, $formatted, $append) {
180
+				Benchmark::writeResultsToFile($filepath, $formatted, $append);
181
+			},
182
+			999999
183
+		);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param bool $formatted
190
+	 * @return string
191
+	 */
192
+	private static function generateResults($formatted = true)
193
+	{
194
+		if (Benchmark::doNotRun()) {
195
+			return '';
196
+		}
197
+		if (! empty(Benchmark::$times)) {
198
+			$total = 0;
199
+			Benchmark::$output .= $formatted
200
+				? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
201
+				: '';
202
+			foreach (Benchmark::$times as $timer_name => $total_time) {
203
+				Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
204
+				Benchmark::$output .= $formatted ? '<br />'  : "\n";
205
+				$total += $total_time;
206
+			}
207
+			if($formatted) {
208
+				Benchmark::$output .= '<br />';
209
+				Benchmark::$output .= '<h4>TOTAL TIME</h4>';
210
+				Benchmark::$output .= Benchmark::formatTime('', $total, $formatted);
211
+				Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
212
+				Benchmark::$output .= '<br />';
213
+				Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>';
214
+				Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
215
+				Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
216
+				Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
217
+				Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />';
218
+				Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />';
219
+				Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
220
+			}
221
+		}
222
+		if (! empty(Benchmark::$memory_usage)) {
223
+			Benchmark::$output .= $formatted
224
+				? '<h5>Memory</h5>'
225
+				: "\nMemory";
226
+			foreach (Benchmark::$memory_usage as $label => $memory_usage) {
227
+				Benchmark::$output .= $formatted
228
+					? "<br />{$memory_usage} : {$label}"
229
+					: "\n{$memory_usage} : {$label}";
230
+			}
231
+		}
232
+		if (empty(Benchmark::$output)) {
233
+			return '';
234
+		}
235
+		Benchmark::$output = $formatted
236
+			? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
237
+			  . (is_admin()
238
+				? ' margin:2em 2em 2em 180px;'
239
+				: ' margin:2em;')
240
+			  . ' padding:2em;">'
241
+			  . '<h4>BENCHMARKING</h4>'
242
+			  . Benchmark::$output
243
+			  . '</div>'
244
+			: Benchmark::$output;
245
+		return Benchmark::$output;
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * @param bool $echo
252
+	 * @param bool $formatted
253
+	 * @return string
254
+	 */
255
+	public static function displayResults($echo = true, $formatted = true)
256
+	{
257
+		$results = Benchmark::generateResults($formatted);
258
+		if ($echo) {
259
+			echo $results;
260
+			$results = '';
261
+		}
262
+		return $results;
263
+	}
264
+
265
+
266
+	/**
267
+	 * @param string $filepath
268
+	 * @param bool   $formatted
269
+	 * @param bool   $append
270
+	 * @throws EE_Error
271
+	 */
272
+	public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
273
+	{
274
+		$filepath = ! empty($filepath) && is_readable(dirname($filepath))
275
+			? $filepath
276
+			: '';
277
+		if( empty($filepath)) {
278
+			$filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
279
+		}
280
+		EEH_File::ensure_file_exists_and_is_writable($filepath);
281
+		file_put_contents(
282
+			$filepath,
283
+			"\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
284
+			$append ? FILE_APPEND | LOCK_EX : LOCK_EX
285
+		);
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
292
+	 *
293
+	 * @param int $size
294
+	 * @return string
295
+	 */
296
+	public static function convert($size)
297
+	{
298
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
299
+		return round(
300
+			$size / pow(1024, $i = floor(log($size, 1024))),
301
+			2
302
+		) . ' ' . $unit[absint($i)];
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * @param string $timer_name
309
+	 * @param float  $total_time
310
+	 * @param bool   $formatted
311
+	 * @return string
312
+	 */
313
+	public static function formatTime($timer_name, $total_time, $formatted = true)
314
+	{
315
+		$total_time *= 1000;
316
+		switch ($total_time) {
317
+			case $total_time > 12500 :
318
+				$color = 'red';
319
+				$bold = 'bold';
320
+				break;
321
+			case $total_time > 2500 :
322
+				$color = 'darkorange';
323
+				$bold = 'bold';
324
+				break;
325
+			case $total_time > 500 :
326
+				$color = 'gold';
327
+				$bold = 'bold';
328
+				break;
329
+			case $total_time > 100 :
330
+				$color = 'limegreen';
331
+				$bold = 'normal';
332
+				break;
333
+			case $total_time > 20 :
334
+				$color = 'deepskyblue';
335
+				$bold = 'normal';
336
+				break;
337
+			default :
338
+				$color = 'mediumpurple';
339
+				$bold = 'normal';
340
+				break;
341
+		}
342
+		return $formatted
343
+			? '<span style="min-width: 10px; margin:0 1em; color:'
344
+			   . $color
345
+			   . '; font-weight:'
346
+			   . $bold
347
+			   . '; font-size:1.2em;">'
348
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
349
+			   . '</span> '
350
+			   . $timer_name
351
+			:  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
352
+	}
353 353
 
354 354
 
355 355
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         Benchmark::resetOutput();
155 155
         add_action(
156 156
             'shutdown',
157
-            function () use ($formatted) {
157
+            function() use ($formatted) {
158 158
                 Benchmark::displayResults(true, $formatted);
159 159
             },
160 160
             999999
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         Benchmark::resetOutput();
177 177
         add_action(
178 178
             'shutdown',
179
-            function () use ($filepath, $formatted, $append) {
179
+            function() use ($filepath, $formatted, $append) {
180 180
                 Benchmark::writeResultsToFile($filepath, $formatted, $append);
181 181
             },
182 182
             999999
@@ -194,17 +194,17 @@  discard block
 block discarded – undo
194 194
         if (Benchmark::doNotRun()) {
195 195
             return '';
196 196
         }
197
-        if (! empty(Benchmark::$times)) {
197
+        if ( ! empty(Benchmark::$times)) {
198 198
             $total = 0;
199 199
             Benchmark::$output .= $formatted
200 200
                 ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
201 201
                 : '';
202 202
             foreach (Benchmark::$times as $timer_name => $total_time) {
203 203
                 Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
204
-                Benchmark::$output .= $formatted ? '<br />'  : "\n";
204
+                Benchmark::$output .= $formatted ? '<br />' : "\n";
205 205
                 $total += $total_time;
206 206
             }
207
-            if($formatted) {
207
+            if ($formatted) {
208 208
                 Benchmark::$output .= '<br />';
209 209
                 Benchmark::$output .= '<h4>TOTAL TIME</h4>';
210 210
                 Benchmark::$output .= Benchmark::formatTime('', $total, $formatted);
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                 Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
220 220
             }
221 221
         }
222
-        if (! empty(Benchmark::$memory_usage)) {
222
+        if ( ! empty(Benchmark::$memory_usage)) {
223 223
             Benchmark::$output .= $formatted
224 224
                 ? '<h5>Memory</h5>'
225 225
                 : "\nMemory";
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
         $filepath = ! empty($filepath) && is_readable(dirname($filepath))
275 275
             ? $filepath
276 276
             : '';
277
-        if( empty($filepath)) {
278
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
277
+        if (empty($filepath)) {
278
+            $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html';
279 279
         }
280 280
         EEH_File::ensure_file_exists_and_is_writable($filepath);
281 281
         file_put_contents(
282 282
             $filepath,
283
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
283
+            "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted),
284 284
             $append ? FILE_APPEND | LOCK_EX : LOCK_EX
285 285
         );
286 286
     }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         return round(
300 300
             $size / pow(1024, $i = floor(log($size, 1024))),
301 301
             2
302
-        ) . ' ' . $unit[absint($i)];
302
+        ).' '.$unit[absint($i)];
303 303
     }
304 304
 
305 305
 
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.031');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.031');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.