Completed
Branch FET-10657-loader (a10de3)
by
unknown
61:09 queued 50:10
created
core/services/loaders/CachingLoader.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -22,114 +22,114 @@
 block discarded – undo
22 22
 class CachingLoader extends LoaderDecorator
23 23
 {
24 24
 
25
-    /**
26
-     * @var CollectionInterface $cache
27
-     */
28
-    protected $cache;
29
-
30
-    /**
31
-     * @var string $identifier
32
-     */
33
-    protected $identifier;
34
-
35
-
36
-
37
-    /**
38
-     * CachingLoader constructor.
39
-     *
40
-     * @param LoaderInterface     $loader
41
-     * @param CollectionInterface $cache
42
-     * @param string              $identifier
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '')
46
-    {
47
-        parent::__construct($loader);
48
-        $this->cache = $cache;
49
-        $this->setIdentifier($identifier);
50
-        if ($this->identifier !== '') {
51
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
52
-            // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER');
53
-            // where "IDENTIFIER" = the string that was set during construction
54
-            add_action(
55
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
56
-                array($this, 'reset')
57
-            );
58
-        }
59
-        // to clear ALL caches, simply do the following:
60
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
61
-        add_action(
62
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
63
-            array($this, 'reset')
64
-        );
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return string
71
-     */
72
-    public function identifier()
73
-    {
74
-        return $this->identifier;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @param string $identifier
81
-     * @throws InvalidDataTypeException
82
-     */
83
-    private function setIdentifier($identifier)
84
-    {
85
-        if ( ! is_string($identifier)) {
86
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
87
-        }
88
-        $this->identifier = $identifier;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @param string $fqcn
95
-     * @param array  $arguments
96
-     * @return mixed
97
-     * @throws InvalidEntityException
98
-     * @throws ServiceNotFoundException
99
-     */
100
-    public function load($fqcn, $arguments = array())
101
-    {
102
-        $fqcn = ltrim($fqcn, '\\');
103
-        // caching can be turned off via the following code:
104
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
105
-        if(
106
-            apply_filters(
107
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
108
-                false,
109
-                $this
110
-            )
111
-        ){
112
-            return $this->loader->load($fqcn, $arguments);
113
-        }
114
-        $identifier = md5($fqcn . serialize($arguments));
115
-        if($this->cache->has($identifier)){
116
-            return $this->cache->get($identifier);
117
-        }
118
-        $object = $this->loader->load($fqcn, $arguments);
119
-        $this->cache->add($object, $identifier);
120
-        return $object;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * empties cache and calls reset() on loader if method exists
127
-     */
128
-    public function reset()
129
-    {
130
-        $this->cache->detachAll();
131
-        $this->loader->reset();
132
-    }
25
+	/**
26
+	 * @var CollectionInterface $cache
27
+	 */
28
+	protected $cache;
29
+
30
+	/**
31
+	 * @var string $identifier
32
+	 */
33
+	protected $identifier;
34
+
35
+
36
+
37
+	/**
38
+	 * CachingLoader constructor.
39
+	 *
40
+	 * @param LoaderInterface     $loader
41
+	 * @param CollectionInterface $cache
42
+	 * @param string              $identifier
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '')
46
+	{
47
+		parent::__construct($loader);
48
+		$this->cache = $cache;
49
+		$this->setIdentifier($identifier);
50
+		if ($this->identifier !== '') {
51
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
52
+			// do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER');
53
+			// where "IDENTIFIER" = the string that was set during construction
54
+			add_action(
55
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
56
+				array($this, 'reset')
57
+			);
58
+		}
59
+		// to clear ALL caches, simply do the following:
60
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
61
+		add_action(
62
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
63
+			array($this, 'reset')
64
+		);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return string
71
+	 */
72
+	public function identifier()
73
+	{
74
+		return $this->identifier;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @param string $identifier
81
+	 * @throws InvalidDataTypeException
82
+	 */
83
+	private function setIdentifier($identifier)
84
+	{
85
+		if ( ! is_string($identifier)) {
86
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
87
+		}
88
+		$this->identifier = $identifier;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @param string $fqcn
95
+	 * @param array  $arguments
96
+	 * @return mixed
97
+	 * @throws InvalidEntityException
98
+	 * @throws ServiceNotFoundException
99
+	 */
100
+	public function load($fqcn, $arguments = array())
101
+	{
102
+		$fqcn = ltrim($fqcn, '\\');
103
+		// caching can be turned off via the following code:
104
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
105
+		if(
106
+			apply_filters(
107
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
108
+				false,
109
+				$this
110
+			)
111
+		){
112
+			return $this->loader->load($fqcn, $arguments);
113
+		}
114
+		$identifier = md5($fqcn . serialize($arguments));
115
+		if($this->cache->has($identifier)){
116
+			return $this->cache->get($identifier);
117
+		}
118
+		$object = $this->loader->load($fqcn, $arguments);
119
+		$this->cache->add($object, $identifier);
120
+		return $object;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * empties cache and calls reset() on loader if method exists
127
+	 */
128
+	public function reset()
129
+	{
130
+		$this->cache->detachAll();
131
+		$this->loader->reset();
132
+	}
133 133
 
134 134
 
135 135
 }
Please login to merge, or discard this patch.