Completed
Branch BUG-caching-loader-identifier (aef4b9)
by
unknown
34:44 queued 20:52
created
core/services/loaders/CachingLoader.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -17,158 +17,158 @@
 block discarded – undo
17 17
 class CachingLoader extends CachingLoaderDecorator
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $identifier
22
-     */
23
-    protected $identifier;
24
-
25
-    /**
26
-     * @var CollectionInterface $cache
27
-     */
28
-    protected $cache;
29
-
30
-    /**
31
-     * @var ObjectIdentifier
32
-     */
33
-    private $object_identifier;
34
-
35
-
36
-    /**
37
-     * CachingLoader constructor.
38
-     *
39
-     * @param LoaderDecoratorInterface $loader
40
-     * @param CollectionInterface      $cache
41
-     * @param ObjectIdentifier         $object_identifier
42
-     * @param string                   $identifier
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct(
46
-        LoaderDecoratorInterface $loader,
47
-        CollectionInterface $cache,
48
-        ObjectIdentifier $object_identifier,
49
-        $identifier = ''
50
-    ) {
51
-        parent::__construct($loader);
52
-        $this->cache       = $cache;
53
-        $this->object_identifier = $object_identifier;
54
-        $this->setIdentifier($identifier);
55
-        if ($this->identifier !== '') {
56
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
57
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
58
-            // where "IDENTIFIER" = the string that was set during construction
59
-            add_action(
60
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
61
-                array($this, 'reset')
62
-            );
63
-        }
64
-        // to clear ALL caches, simply do the following:
65
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
66
-        add_action(
67
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
68
-            array($this, 'reset')
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * @return string
75
-     */
76
-    public function identifier()
77
-    {
78
-        return $this->identifier;
79
-    }
80
-
81
-
82
-    /**
83
-     * @param string $identifier
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    private function setIdentifier($identifier)
87
-    {
88
-        if (! is_string($identifier)) {
89
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
-        }
91
-        $this->identifier = $identifier;
92
-    }
93
-
94
-
95
-    /**
96
-     * @param FullyQualifiedName|string $fqcn
97
-     * @param mixed                     $object
98
-     * @param array                     $arguments
99
-     * @return bool
100
-     * @throws InvalidArgumentException
101
-     */
102
-    public function share($fqcn, $object, array $arguments = array())
103
-    {
104
-        if ($object instanceof $fqcn) {
105
-            return $this->cache->add(
106
-                $object,
107
-                $this->object_identifier->getIdentifier($fqcn, $arguments)
108
-            );
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 (apply_filters(
135
-            'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
136
-            false,
137
-            $this
138
-        )) {
139
-            // even though $shared might be true, caching could be bypassed for whatever reason,
140
-            // so we don't want the core loader to cache anything, therefore caching is turned off
141
-            return $this->loader->load($fqcn, $arguments, false);
142
-        }
143
-        $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
144
-        if ($this->cache->has($object_identifier)) {
145
-            return $this->cache->get($object_identifier);
146
-        }
147
-        $object = $this->loader->load($fqcn, $arguments, $shared);
148
-        if ($object instanceof $fqcn) {
149
-            $this->cache->add($object, $object_identifier);
150
-        }
151
-        return $object;
152
-    }
153
-
154
-
155
-    /**
156
-     * empties cache and calls reset() on loader if method exists
157
-     */
158
-    public function reset()
159
-    {
160
-        $this->clearCache();
161
-        $this->loader->reset();
162
-    }
163
-
164
-
165
-    /**
166
-     * unsets and detaches ALL objects from the cache
167
-     *
168
-     * @since 4.9.62.p
169
-     */
170
-    public function clearCache()
171
-    {
172
-        $this->cache->trashAndDetachAll();
173
-    }
20
+	/**
21
+	 * @var string $identifier
22
+	 */
23
+	protected $identifier;
24
+
25
+	/**
26
+	 * @var CollectionInterface $cache
27
+	 */
28
+	protected $cache;
29
+
30
+	/**
31
+	 * @var ObjectIdentifier
32
+	 */
33
+	private $object_identifier;
34
+
35
+
36
+	/**
37
+	 * CachingLoader constructor.
38
+	 *
39
+	 * @param LoaderDecoratorInterface $loader
40
+	 * @param CollectionInterface      $cache
41
+	 * @param ObjectIdentifier         $object_identifier
42
+	 * @param string                   $identifier
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct(
46
+		LoaderDecoratorInterface $loader,
47
+		CollectionInterface $cache,
48
+		ObjectIdentifier $object_identifier,
49
+		$identifier = ''
50
+	) {
51
+		parent::__construct($loader);
52
+		$this->cache       = $cache;
53
+		$this->object_identifier = $object_identifier;
54
+		$this->setIdentifier($identifier);
55
+		if ($this->identifier !== '') {
56
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
57
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
58
+			// where "IDENTIFIER" = the string that was set during construction
59
+			add_action(
60
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
61
+				array($this, 'reset')
62
+			);
63
+		}
64
+		// to clear ALL caches, simply do the following:
65
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
66
+		add_action(
67
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
68
+			array($this, 'reset')
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @return string
75
+	 */
76
+	public function identifier()
77
+	{
78
+		return $this->identifier;
79
+	}
80
+
81
+
82
+	/**
83
+	 * @param string $identifier
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	private function setIdentifier($identifier)
87
+	{
88
+		if (! is_string($identifier)) {
89
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
+		}
91
+		$this->identifier = $identifier;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param FullyQualifiedName|string $fqcn
97
+	 * @param mixed                     $object
98
+	 * @param array                     $arguments
99
+	 * @return bool
100
+	 * @throws InvalidArgumentException
101
+	 */
102
+	public function share($fqcn, $object, array $arguments = array())
103
+	{
104
+		if ($object instanceof $fqcn) {
105
+			return $this->cache->add(
106
+				$object,
107
+				$this->object_identifier->getIdentifier($fqcn, $arguments)
108
+			);
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 (apply_filters(
135
+			'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
136
+			false,
137
+			$this
138
+		)) {
139
+			// even though $shared might be true, caching could be bypassed for whatever reason,
140
+			// so we don't want the core loader to cache anything, therefore caching is turned off
141
+			return $this->loader->load($fqcn, $arguments, false);
142
+		}
143
+		$object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
144
+		if ($this->cache->has($object_identifier)) {
145
+			return $this->cache->get($object_identifier);
146
+		}
147
+		$object = $this->loader->load($fqcn, $arguments, $shared);
148
+		if ($object instanceof $fqcn) {
149
+			$this->cache->add($object, $object_identifier);
150
+		}
151
+		return $object;
152
+	}
153
+
154
+
155
+	/**
156
+	 * empties cache and calls reset() on loader if method exists
157
+	 */
158
+	public function reset()
159
+	{
160
+		$this->clearCache();
161
+		$this->loader->reset();
162
+	}
163
+
164
+
165
+	/**
166
+	 * unsets and detaches ALL objects from the cache
167
+	 *
168
+	 * @since 4.9.62.p
169
+	 */
170
+	public function clearCache()
171
+	{
172
+		$this->cache->trashAndDetachAll();
173
+	}
174 174
 }
Please login to merge, or discard this patch.
core/bootstrap_espresso.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@  discard block
 block discarded – undo
6 6
  */
7 7
 function espresso_load_error_handling()
8 8
 {
9
-    static $error_handling_loaded = false;
10
-    if ($error_handling_loaded) {
11
-        return;
12
-    }
13
-    // load debugging tools
14
-    if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
-        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
16
-        \EEH_Debug_Tools::instance();
17
-    }
18
-    // load error handling
19
-    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
-        require_once EE_CORE . 'EE_Error.core.php';
21
-    } else {
22
-        wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23
-    }
24
-    $error_handling_loaded = true;
9
+	static $error_handling_loaded = false;
10
+	if ($error_handling_loaded) {
11
+		return;
12
+	}
13
+	// load debugging tools
14
+	if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
+		require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
16
+		\EEH_Debug_Tools::instance();
17
+	}
18
+	// load error handling
19
+	if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
+		require_once EE_CORE . 'EE_Error.core.php';
21
+	} else {
22
+		wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23
+	}
24
+	$error_handling_loaded = true;
25 25
 }
26 26
 
27 27
 
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function espresso_load_required($classname, $full_path_to_file)
37 37
 {
38
-    if (is_readable($full_path_to_file)) {
39
-        require_once $full_path_to_file;
40
-    } else {
41
-        throw new \EE_Error(
42
-            sprintf(
43
-                esc_html__(
44
-                    'The %s class file could not be located or is not readable due to file permissions.',
45
-                    'event_espresso'
46
-                ),
47
-                $classname
48
-            )
49
-        );
50
-    }
38
+	if (is_readable($full_path_to_file)) {
39
+		require_once $full_path_to_file;
40
+	} else {
41
+		throw new \EE_Error(
42
+			sprintf(
43
+				esc_html__(
44
+					'The %s class file could not be located or is not readable due to file permissions.',
45
+					'event_espresso'
46
+				),
47
+				$classname
48
+			)
49
+		);
50
+	}
51 51
 }
52 52
 
53 53
 
@@ -66,43 +66,43 @@  discard block
 block discarded – undo
66 66
  */
67 67
 function bootstrap_espresso()
68 68
 {
69
-    require_once __DIR__ . '/espresso_definitions.php';
70
-    try {
71
-        espresso_load_error_handling();
72
-        espresso_load_required(
73
-            'EEH_Base',
74
-            EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
75
-        );
76
-        espresso_load_required(
77
-            'EEH_File',
78
-            EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
79
-        );
80
-        espresso_load_required(
81
-            'EEH_File',
82
-            EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
83
-        );
84
-        espresso_load_required(
85
-            'EEH_Array',
86
-            EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
87
-        );
88
-        espresso_load_required(
89
-            'EE_Base',
90
-            EE_CORE . 'EE_Base.core.php'
91
-        );
92
-        // instantiate and configure PSR4 autoloader
93
-        espresso_load_required(
94
-            'Psr4Autoloader',
95
-            EE_CORE . 'Psr4Autoloader.php'
96
-        );
97
-        espresso_load_required(
98
-            'EE_Psr4AutoloaderInit',
99
-            EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
100
-        );
101
-        $AutoloaderInit = new EE_Psr4AutoloaderInit();
102
-        $AutoloaderInit->initializeAutoloader();
103
-        new EventEspresso\core\services\bootstrap\BootstrapCore();
104
-    } catch (Exception $e) {
105
-        require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
106
-        new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
107
-    }
69
+	require_once __DIR__ . '/espresso_definitions.php';
70
+	try {
71
+		espresso_load_error_handling();
72
+		espresso_load_required(
73
+			'EEH_Base',
74
+			EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
75
+		);
76
+		espresso_load_required(
77
+			'EEH_File',
78
+			EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
79
+		);
80
+		espresso_load_required(
81
+			'EEH_File',
82
+			EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
83
+		);
84
+		espresso_load_required(
85
+			'EEH_Array',
86
+			EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
87
+		);
88
+		espresso_load_required(
89
+			'EE_Base',
90
+			EE_CORE . 'EE_Base.core.php'
91
+		);
92
+		// instantiate and configure PSR4 autoloader
93
+		espresso_load_required(
94
+			'Psr4Autoloader',
95
+			EE_CORE . 'Psr4Autoloader.php'
96
+		);
97
+		espresso_load_required(
98
+			'EE_Psr4AutoloaderInit',
99
+			EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
100
+		);
101
+		$AutoloaderInit = new EE_Psr4AutoloaderInit();
102
+		$AutoloaderInit->initializeAutoloader();
103
+		new EventEspresso\core\services\bootstrap\BootstrapCore();
104
+	} catch (Exception $e) {
105
+		require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
106
+		new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
         return;
12 12
     }
13 13
     // load debugging tools
14
-    if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
-        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
14
+    if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
15
+        require_once EE_HELPERS.'EEH_Debug_Tools.helper.php';
16 16
         \EEH_Debug_Tools::instance();
17 17
     }
18 18
     // load error handling
19
-    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
-        require_once EE_CORE . 'EE_Error.core.php';
19
+    if (is_readable(EE_CORE.'EE_Error.core.php')) {
20
+        require_once EE_CORE.'EE_Error.core.php';
21 21
     } else {
22 22
         wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23 23
     }
@@ -66,43 +66,43 @@  discard block
 block discarded – undo
66 66
  */
67 67
 function bootstrap_espresso()
68 68
 {
69
-    require_once __DIR__ . '/espresso_definitions.php';
69
+    require_once __DIR__.'/espresso_definitions.php';
70 70
     try {
71 71
         espresso_load_error_handling();
72 72
         espresso_load_required(
73 73
             'EEH_Base',
74
-            EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
74
+            EE_CORE.'helpers'.DS.'EEH_Base.helper.php'
75 75
         );
76 76
         espresso_load_required(
77 77
             'EEH_File',
78
-            EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
78
+            EE_CORE.'interfaces'.DS.'EEHI_File.interface.php'
79 79
         );
80 80
         espresso_load_required(
81 81
             'EEH_File',
82
-            EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
82
+            EE_CORE.'helpers'.DS.'EEH_File.helper.php'
83 83
         );
84 84
         espresso_load_required(
85 85
             'EEH_Array',
86
-            EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
86
+            EE_CORE.'helpers'.DS.'EEH_Array.helper.php'
87 87
         );
88 88
         espresso_load_required(
89 89
             'EE_Base',
90
-            EE_CORE . 'EE_Base.core.php'
90
+            EE_CORE.'EE_Base.core.php'
91 91
         );
92 92
         // instantiate and configure PSR4 autoloader
93 93
         espresso_load_required(
94 94
             'Psr4Autoloader',
95
-            EE_CORE . 'Psr4Autoloader.php'
95
+            EE_CORE.'Psr4Autoloader.php'
96 96
         );
97 97
         espresso_load_required(
98 98
             'EE_Psr4AutoloaderInit',
99
-            EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
99
+            EE_CORE.'EE_Psr4AutoloaderInit.core.php'
100 100
         );
101 101
         $AutoloaderInit = new EE_Psr4AutoloaderInit();
102 102
         $AutoloaderInit->initializeAutoloader();
103 103
         new EventEspresso\core\services\bootstrap\BootstrapCore();
104 104
     } catch (Exception $e) {
105
-        require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
105
+        require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php';
106 106
         new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
107 107
     }
108 108
 }
Please login to merge, or discard this patch.