Completed
Branch BUG/send-test-email-not-requir... (ff675f)
by
unknown
02:14 queued 29s
created
core/services/route_match/RouteMatchSpecificationCollection.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 class RouteMatchSpecificationCollection extends Collection
17 17
 {
18 18
 
19
-    const COLLECTION_NAME = 'route_match_specifications';
20
-
21
-
22
-    /**
23
-     * RouteMatchSpecificationCollection constructor
24
-     *
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    public function __construct()
28
-    {
29
-        parent::__construct(
30
-            'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
31
-            RouteMatchSpecificationCollection::COLLECTION_NAME
32
-        );
33
-    }
34
-
35
-
36
-    /**
37
-     * getIdentifier
38
-     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
-     * If no $identifier is supplied, then the  fully qualified class name is used
40
-     *
41
-     * @param        $object
42
-     * @param  mixed $identifier
43
-     * @return bool
44
-     */
45
-    public function getIdentifier($object, $identifier = null)
46
-    {
47
-        return ! empty($identifier)
48
-            ? $identifier
49
-            : get_class($object);
50
-    }
19
+	const COLLECTION_NAME = 'route_match_specifications';
20
+
21
+
22
+	/**
23
+	 * RouteMatchSpecificationCollection constructor
24
+	 *
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	public function __construct()
28
+	{
29
+		parent::__construct(
30
+			'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
31
+			RouteMatchSpecificationCollection::COLLECTION_NAME
32
+		);
33
+	}
34
+
35
+
36
+	/**
37
+	 * getIdentifier
38
+	 * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
+	 * If no $identifier is supplied, then the  fully qualified class name is used
40
+	 *
41
+	 * @param        $object
42
+	 * @param  mixed $identifier
43
+	 * @return bool
44
+	 */
45
+	public function getIdentifier($object, $identifier = null)
46
+	{
47
+		return ! empty($identifier)
48
+			? $identifier
49
+			: get_class($object);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
core/services/collections/Collection.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     protected function setCollectionInterface($collection_interface)
68 68
     {
69
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
69
+        if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) {
70 70
             throw new InvalidInterfaceException($collection_interface);
71 71
         }
72 72
         $this->collection_interface = $collection_interface;
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
     protected function setCollectionIdentifier()
112 112
     {
113 113
         // hash a few collection details
114
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
114
+        $identifier = md5(spl_object_hash($this).$this->collection_interface.time());
115 115
         // grab a few characters from the start, middle, and end of the hash
116 116
         $id = array();
117 117
         for ($x = 0; $x < 19; $x += 9) {
118 118
             $id[] = substr($identifier, $x, 3);
119 119
         }
120
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
120
+        $this->collection_identifier = $this->collection_name.'-'.strtoupper(implode('-', $id));
121 121
     }
122 122
 
123 123
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function add($object, $identifier = null)
137 137
     {
138
-        if (! $object instanceof $this->collection_interface) {
138
+        if ( ! $object instanceof $this->collection_interface) {
139 139
             throw new InvalidEntityException($object, $this->collection_interface);
140 140
         }
141 141
         if ($this->contains($object)) {
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      */
352 352
     public function indexOf($object)
353 353
     {
354
-        if (! $this->contains($object)) {
354
+        if ( ! $this->contains($object)) {
355 355
             return false;
356 356
         }
357 357
         foreach ($this as $index => $obj) {
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
             $remaining_objects = $this->slice($index, $this->count() - $index);
421 421
             foreach ($remaining_objects as $key => $remaining_object) {
422 422
                 // we need to grab the identifiers for each object and use them as keys
423
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
423
+                $remaining_objects[$remaining_object->getInfo()] = $remaining_object;
424 424
                 // and then remove the object from the current tracking array
425
-                unset($remaining_objects[ $key ]);
425
+                unset($remaining_objects[$key]);
426 426
                 // and then remove it from the Collection
427 427
                 $this->detach($remaining_object);
428 428
             }
@@ -446,17 +446,17 @@  discard block
 block discarded – undo
446 446
      */
447 447
     public function insertAt($objects, $index)
448 448
     {
449
-        if (! is_array($objects)) {
449
+        if ( ! is_array($objects)) {
450 450
             $objects = array($objects);
451 451
         }
452 452
         // check to ensure that objects don't already exist in the collection
453 453
         foreach ($objects as $key => $object) {
454 454
             if ($this->contains($object)) {
455
-                unset($objects[ $key ]);
455
+                unset($objects[$key]);
456 456
             }
457 457
         }
458 458
         // do we have any objects left?
459
-        if (! $objects) {
459
+        if ( ! $objects) {
460 460
             return;
461 461
         }
462 462
         // detach any objects at or past this index
Please login to merge, or discard this patch.
Indentation   +500 added lines, -500 removed lines patch added patch discarded remove patch
@@ -19,504 +19,504 @@
 block discarded – undo
19 19
 class Collection extends SplObjectStorage implements CollectionInterface
20 20
 {
21 21
 
22
-    /**
23
-     * a unique string for identifying this collection
24
-     *
25
-     * @type string $collection_identifier
26
-     */
27
-    protected $collection_identifier;
28
-
29
-
30
-    /**
31
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
32
-     * this should be set from within the child class constructor
33
-     *
34
-     * @type string $interface
35
-     */
36
-    protected $collection_interface;
37
-
38
-    /**
39
-     * a short dash separated string describing the contents of this collection
40
-     * used as the base for the $collection_identifier
41
-     * defaults to the class short name if not set
42
-     *
43
-     * @type string $collection_identifier
44
-     */
45
-    protected $collection_name;
46
-
47
-
48
-    /**
49
-     * Collection constructor
50
-     *
51
-     * @param string $collection_interface
52
-     * @param string $collection_name
53
-     * @throws InvalidInterfaceException
54
-     */
55
-    public function __construct($collection_interface, $collection_name = '')
56
-    {
57
-        $this->setCollectionInterface($collection_interface);
58
-        $this->setCollectionName($collection_name);
59
-        $this->setCollectionIdentifier();
60
-    }
61
-
62
-
63
-    /**
64
-     * setCollectionInterface
65
-     *
66
-     * @param  string $collection_interface
67
-     * @throws InvalidInterfaceException
68
-     */
69
-    protected function setCollectionInterface($collection_interface)
70
-    {
71
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
72
-            throw new InvalidInterfaceException($collection_interface);
73
-        }
74
-        $this->collection_interface = $collection_interface;
75
-    }
76
-
77
-
78
-    /**
79
-     * @return string
80
-     */
81
-    public function collectionName()
82
-    {
83
-        return $this->collection_name;
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $collection_name
89
-     */
90
-    protected function setCollectionName($collection_name)
91
-    {
92
-        $this->collection_name = ! empty($collection_name)
93
-            ? sanitize_key($collection_name)
94
-            : basename(str_replace('\\', '/', get_class($this)));
95
-    }
96
-
97
-
98
-    /**
99
-     * @return string
100
-     */
101
-    public function collectionIdentifier()
102
-    {
103
-        return $this->collection_identifier;
104
-    }
105
-
106
-
107
-    /**
108
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
109
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
110
-     *
111
-     * @return void
112
-     */
113
-    protected function setCollectionIdentifier()
114
-    {
115
-        // hash a few collection details
116
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
117
-        // grab a few characters from the start, middle, and end of the hash
118
-        $id = array();
119
-        for ($x = 0; $x < 19; $x += 9) {
120
-            $id[] = substr($identifier, $x, 3);
121
-        }
122
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
123
-    }
124
-
125
-
126
-    /**
127
-     * add
128
-     * attaches an object to the Collection
129
-     * and sets any supplied data associated with the current iterator entry
130
-     * by calling EE_Object_Collection::set_identifier()
131
-     *
132
-     * @param        $object
133
-     * @param  mixed $identifier
134
-     * @return bool
135
-     * @throws InvalidEntityException
136
-     * @throws DuplicateCollectionIdentifierException
137
-     */
138
-    public function add($object, $identifier = null)
139
-    {
140
-        if (! $object instanceof $this->collection_interface) {
141
-            throw new InvalidEntityException($object, $this->collection_interface);
142
-        }
143
-        if ($this->contains($object)) {
144
-            throw new DuplicateCollectionIdentifierException($identifier);
145
-        }
146
-        $this->attach($object);
147
-        $this->setIdentifier($object, $identifier);
148
-        return $this->contains($object);
149
-    }
150
-
151
-
152
-    /**
153
-     * getIdentifier
154
-     * if no $identifier is supplied, then the spl_object_hash() is used
155
-     *
156
-     * @param        $object
157
-     * @param  mixed $identifier
158
-     * @return bool
159
-     */
160
-    public function getIdentifier($object, $identifier = null)
161
-    {
162
-        return ! empty($identifier)
163
-            ? $identifier
164
-            : spl_object_hash($object);
165
-    }
166
-
167
-
168
-    /**
169
-     * setIdentifier
170
-     * Sets the data associated with an object in the Collection
171
-     * if no $identifier is supplied, then the spl_object_hash() is used
172
-     *
173
-     * @param        $object
174
-     * @param  mixed $identifier
175
-     * @return bool
176
-     */
177
-    public function setIdentifier($object, $identifier = null)
178
-    {
179
-        $identifier = $this->getIdentifier($object, $identifier);
180
-        $this->rewind();
181
-        while ($this->valid()) {
182
-            if ($object === $this->current()) {
183
-                $this->setInfo($identifier);
184
-                $this->rewind();
185
-                return true;
186
-            }
187
-            $this->next();
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-    /**
194
-     * get
195
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
196
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
197
-     *
198
-     * @param mixed $identifier
199
-     * @return mixed
200
-     */
201
-    public function get($identifier)
202
-    {
203
-        $this->rewind();
204
-        while ($this->valid()) {
205
-            if ($identifier === $this->getInfo()) {
206
-                $object = $this->current();
207
-                $this->rewind();
208
-                return $object;
209
-            }
210
-            $this->next();
211
-        }
212
-        return null;
213
-    }
214
-
215
-
216
-    /**
217
-     * has
218
-     * returns TRUE or FALSE
219
-     * depending on whether the object is within the Collection
220
-     * based on the supplied $identifier
221
-     *
222
-     * @param  mixed $identifier
223
-     * @return bool
224
-     */
225
-    public function has($identifier)
226
-    {
227
-        $this->rewind();
228
-        while ($this->valid()) {
229
-            if ($identifier === $this->getInfo()) {
230
-                $this->rewind();
231
-                return true;
232
-            }
233
-            $this->next();
234
-        }
235
-        return false;
236
-    }
237
-
238
-
239
-    /**
240
-     * hasObject
241
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
242
-     *
243
-     * @param $object
244
-     * @return bool
245
-     */
246
-    public function hasObject($object)
247
-    {
248
-        return $this->contains($object);
249
-    }
250
-
251
-
252
-    /**
253
-     * hasObjects
254
-     * returns true if there are objects within the Collection, and false if it is empty
255
-     *
256
-     * @return bool
257
-     */
258
-    public function hasObjects()
259
-    {
260
-        return $this->count() !== 0;
261
-    }
262
-
263
-
264
-    /**
265
-     * isEmpty
266
-     * returns true if there are no objects within the Collection, and false if there are
267
-     *
268
-     * @return bool
269
-     */
270
-    public function isEmpty()
271
-    {
272
-        return $this->count() === 0;
273
-    }
274
-
275
-
276
-    /**
277
-     * remove
278
-     * detaches an object from the Collection
279
-     *
280
-     * @param $object
281
-     * @return bool
282
-     */
283
-    public function remove($object)
284
-    {
285
-        $this->detach($object);
286
-        return true;
287
-    }
288
-
289
-
290
-    /**
291
-     * setCurrent
292
-     * advances pointer to the object whose identifier matches that which was provided
293
-     *
294
-     * @param mixed $identifier
295
-     * @return boolean
296
-     */
297
-    public function setCurrent($identifier)
298
-    {
299
-        $this->rewind();
300
-        while ($this->valid()) {
301
-            if ($identifier === $this->getInfo()) {
302
-                return true;
303
-            }
304
-            $this->next();
305
-        }
306
-        return false;
307
-    }
308
-
309
-
310
-    /**
311
-     * setCurrentUsingObject
312
-     * advances pointer to the provided object
313
-     *
314
-     * @param $object
315
-     * @return boolean
316
-     */
317
-    public function setCurrentUsingObject($object)
318
-    {
319
-        $this->rewind();
320
-        while ($this->valid()) {
321
-            if ($this->current() === $object) {
322
-                return true;
323
-            }
324
-            $this->next();
325
-        }
326
-        return false;
327
-    }
328
-
329
-
330
-    /**
331
-     * Returns the object occupying the index before the current object,
332
-     * unless this is already the first object, in which case it just returns the first object
333
-     *
334
-     * @return mixed
335
-     */
336
-    public function previous()
337
-    {
338
-        $index = $this->indexOf($this->current());
339
-        if ($index === 0) {
340
-            return $this->current();
341
-        }
342
-        $index--;
343
-        return $this->objectAtIndex($index);
344
-    }
345
-
346
-
347
-    /**
348
-     * Returns the index of a given object, or false if not found
349
-     *
350
-     * @see http://stackoverflow.com/a/8736013
351
-     * @param $object
352
-     * @return boolean|int|string
353
-     */
354
-    public function indexOf($object)
355
-    {
356
-        if (! $this->contains($object)) {
357
-            return false;
358
-        }
359
-        foreach ($this as $index => $obj) {
360
-            if ($obj === $object) {
361
-                return $index;
362
-            }
363
-        }
364
-        return false;
365
-    }
366
-
367
-
368
-    /**
369
-     * Returns the object at the given index
370
-     *
371
-     * @see http://stackoverflow.com/a/8736013
372
-     * @param int $index
373
-     * @return mixed
374
-     */
375
-    public function objectAtIndex($index)
376
-    {
377
-        $iterator = new LimitIterator($this, $index, 1);
378
-        $iterator->rewind();
379
-        return $iterator->current();
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns the sequence of objects as specified by the offset and length
385
-     *
386
-     * @see http://stackoverflow.com/a/8736013
387
-     * @param int $offset
388
-     * @param int $length
389
-     * @return array
390
-     */
391
-    public function slice($offset, $length)
392
-    {
393
-        $slice = array();
394
-        $iterator = new LimitIterator($this, $offset, $length);
395
-        foreach ($iterator as $object) {
396
-            $slice[] = $object;
397
-        }
398
-        return $slice;
399
-    }
400
-
401
-
402
-    /**
403
-     * Inserts an object at a certain point
404
-     *
405
-     * @see http://stackoverflow.com/a/8736013
406
-     * @param mixed $object A single object
407
-     * @param int   $index
408
-     * @param mixed $identifier
409
-     * @return bool
410
-     * @throws DuplicateCollectionIdentifierException
411
-     * @throws InvalidEntityException
412
-     */
413
-    public function insertObjectAt($object, $index, $identifier = null)
414
-    {
415
-        // check to ensure that objects don't already exist in the collection
416
-        if ($this->has($identifier)) {
417
-            throw new DuplicateCollectionIdentifierException($identifier);
418
-        }
419
-        // detach any objects at or past this index
420
-        $remaining_objects = array();
421
-        if ($index < $this->count()) {
422
-            $remaining_objects = $this->slice($index, $this->count() - $index);
423
-            foreach ($remaining_objects as $key => $remaining_object) {
424
-                // we need to grab the identifiers for each object and use them as keys
425
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
426
-                // and then remove the object from the current tracking array
427
-                unset($remaining_objects[ $key ]);
428
-                // and then remove it from the Collection
429
-                $this->detach($remaining_object);
430
-            }
431
-        }
432
-        // add the new object we're splicing in
433
-        $this->add($object, $identifier);
434
-        // attach the objects we previously detached
435
-        foreach ($remaining_objects as $key => $remaining_object) {
436
-            $this->add($remaining_object, $key);
437
-        }
438
-        return $this->contains($object);
439
-    }
440
-
441
-
442
-    /**
443
-     * Inserts an object (or an array of objects) at a certain point
444
-     *
445
-     * @see http://stackoverflow.com/a/8736013
446
-     * @param mixed $objects A single object or an array of objects
447
-     * @param int   $index
448
-     */
449
-    public function insertAt($objects, $index)
450
-    {
451
-        if (! is_array($objects)) {
452
-            $objects = array($objects);
453
-        }
454
-        // check to ensure that objects don't already exist in the collection
455
-        foreach ($objects as $key => $object) {
456
-            if ($this->contains($object)) {
457
-                unset($objects[ $key ]);
458
-            }
459
-        }
460
-        // do we have any objects left?
461
-        if (! $objects) {
462
-            return;
463
-        }
464
-        // detach any objects at or past this index
465
-        $remaining = array();
466
-        if ($index < $this->count()) {
467
-            $remaining = $this->slice($index, $this->count() - $index);
468
-            foreach ($remaining as $object) {
469
-                $this->detach($object);
470
-            }
471
-        }
472
-        // add the new objects we're splicing in
473
-        foreach ($objects as $object) {
474
-            $this->attach($object);
475
-        }
476
-        // attach the objects we previously detached
477
-        foreach ($remaining as $object) {
478
-            $this->attach($object);
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * Removes the object at the given index
485
-     *
486
-     * @see http://stackoverflow.com/a/8736013
487
-     * @param int $index
488
-     */
489
-    public function removeAt($index)
490
-    {
491
-        $this->detach($this->objectAtIndex($index));
492
-    }
493
-
494
-
495
-    /**
496
-     * detaches ALL objects from the Collection
497
-     */
498
-    public function detachAll()
499
-    {
500
-        $this->rewind();
501
-        while ($this->valid()) {
502
-            $object = $this->current();
503
-            $this->next();
504
-            $this->detach($object);
505
-        }
506
-    }
507
-
508
-
509
-    /**
510
-     * unsets and detaches ALL objects from the Collection
511
-     */
512
-    public function trashAndDetachAll()
513
-    {
514
-        $this->rewind();
515
-        while ($this->valid()) {
516
-            $object = $this->current();
517
-            $this->next();
518
-            $this->detach($object);
519
-            unset($object);
520
-        }
521
-    }
22
+	/**
23
+	 * a unique string for identifying this collection
24
+	 *
25
+	 * @type string $collection_identifier
26
+	 */
27
+	protected $collection_identifier;
28
+
29
+
30
+	/**
31
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
32
+	 * this should be set from within the child class constructor
33
+	 *
34
+	 * @type string $interface
35
+	 */
36
+	protected $collection_interface;
37
+
38
+	/**
39
+	 * a short dash separated string describing the contents of this collection
40
+	 * used as the base for the $collection_identifier
41
+	 * defaults to the class short name if not set
42
+	 *
43
+	 * @type string $collection_identifier
44
+	 */
45
+	protected $collection_name;
46
+
47
+
48
+	/**
49
+	 * Collection constructor
50
+	 *
51
+	 * @param string $collection_interface
52
+	 * @param string $collection_name
53
+	 * @throws InvalidInterfaceException
54
+	 */
55
+	public function __construct($collection_interface, $collection_name = '')
56
+	{
57
+		$this->setCollectionInterface($collection_interface);
58
+		$this->setCollectionName($collection_name);
59
+		$this->setCollectionIdentifier();
60
+	}
61
+
62
+
63
+	/**
64
+	 * setCollectionInterface
65
+	 *
66
+	 * @param  string $collection_interface
67
+	 * @throws InvalidInterfaceException
68
+	 */
69
+	protected function setCollectionInterface($collection_interface)
70
+	{
71
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
72
+			throw new InvalidInterfaceException($collection_interface);
73
+		}
74
+		$this->collection_interface = $collection_interface;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return string
80
+	 */
81
+	public function collectionName()
82
+	{
83
+		return $this->collection_name;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $collection_name
89
+	 */
90
+	protected function setCollectionName($collection_name)
91
+	{
92
+		$this->collection_name = ! empty($collection_name)
93
+			? sanitize_key($collection_name)
94
+			: basename(str_replace('\\', '/', get_class($this)));
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function collectionIdentifier()
102
+	{
103
+		return $this->collection_identifier;
104
+	}
105
+
106
+
107
+	/**
108
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
109
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
110
+	 *
111
+	 * @return void
112
+	 */
113
+	protected function setCollectionIdentifier()
114
+	{
115
+		// hash a few collection details
116
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
117
+		// grab a few characters from the start, middle, and end of the hash
118
+		$id = array();
119
+		for ($x = 0; $x < 19; $x += 9) {
120
+			$id[] = substr($identifier, $x, 3);
121
+		}
122
+		$this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
123
+	}
124
+
125
+
126
+	/**
127
+	 * add
128
+	 * attaches an object to the Collection
129
+	 * and sets any supplied data associated with the current iterator entry
130
+	 * by calling EE_Object_Collection::set_identifier()
131
+	 *
132
+	 * @param        $object
133
+	 * @param  mixed $identifier
134
+	 * @return bool
135
+	 * @throws InvalidEntityException
136
+	 * @throws DuplicateCollectionIdentifierException
137
+	 */
138
+	public function add($object, $identifier = null)
139
+	{
140
+		if (! $object instanceof $this->collection_interface) {
141
+			throw new InvalidEntityException($object, $this->collection_interface);
142
+		}
143
+		if ($this->contains($object)) {
144
+			throw new DuplicateCollectionIdentifierException($identifier);
145
+		}
146
+		$this->attach($object);
147
+		$this->setIdentifier($object, $identifier);
148
+		return $this->contains($object);
149
+	}
150
+
151
+
152
+	/**
153
+	 * getIdentifier
154
+	 * if no $identifier is supplied, then the spl_object_hash() is used
155
+	 *
156
+	 * @param        $object
157
+	 * @param  mixed $identifier
158
+	 * @return bool
159
+	 */
160
+	public function getIdentifier($object, $identifier = null)
161
+	{
162
+		return ! empty($identifier)
163
+			? $identifier
164
+			: spl_object_hash($object);
165
+	}
166
+
167
+
168
+	/**
169
+	 * setIdentifier
170
+	 * Sets the data associated with an object in the Collection
171
+	 * if no $identifier is supplied, then the spl_object_hash() is used
172
+	 *
173
+	 * @param        $object
174
+	 * @param  mixed $identifier
175
+	 * @return bool
176
+	 */
177
+	public function setIdentifier($object, $identifier = null)
178
+	{
179
+		$identifier = $this->getIdentifier($object, $identifier);
180
+		$this->rewind();
181
+		while ($this->valid()) {
182
+			if ($object === $this->current()) {
183
+				$this->setInfo($identifier);
184
+				$this->rewind();
185
+				return true;
186
+			}
187
+			$this->next();
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+	/**
194
+	 * get
195
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
196
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
197
+	 *
198
+	 * @param mixed $identifier
199
+	 * @return mixed
200
+	 */
201
+	public function get($identifier)
202
+	{
203
+		$this->rewind();
204
+		while ($this->valid()) {
205
+			if ($identifier === $this->getInfo()) {
206
+				$object = $this->current();
207
+				$this->rewind();
208
+				return $object;
209
+			}
210
+			$this->next();
211
+		}
212
+		return null;
213
+	}
214
+
215
+
216
+	/**
217
+	 * has
218
+	 * returns TRUE or FALSE
219
+	 * depending on whether the object is within the Collection
220
+	 * based on the supplied $identifier
221
+	 *
222
+	 * @param  mixed $identifier
223
+	 * @return bool
224
+	 */
225
+	public function has($identifier)
226
+	{
227
+		$this->rewind();
228
+		while ($this->valid()) {
229
+			if ($identifier === $this->getInfo()) {
230
+				$this->rewind();
231
+				return true;
232
+			}
233
+			$this->next();
234
+		}
235
+		return false;
236
+	}
237
+
238
+
239
+	/**
240
+	 * hasObject
241
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
242
+	 *
243
+	 * @param $object
244
+	 * @return bool
245
+	 */
246
+	public function hasObject($object)
247
+	{
248
+		return $this->contains($object);
249
+	}
250
+
251
+
252
+	/**
253
+	 * hasObjects
254
+	 * returns true if there are objects within the Collection, and false if it is empty
255
+	 *
256
+	 * @return bool
257
+	 */
258
+	public function hasObjects()
259
+	{
260
+		return $this->count() !== 0;
261
+	}
262
+
263
+
264
+	/**
265
+	 * isEmpty
266
+	 * returns true if there are no objects within the Collection, and false if there are
267
+	 *
268
+	 * @return bool
269
+	 */
270
+	public function isEmpty()
271
+	{
272
+		return $this->count() === 0;
273
+	}
274
+
275
+
276
+	/**
277
+	 * remove
278
+	 * detaches an object from the Collection
279
+	 *
280
+	 * @param $object
281
+	 * @return bool
282
+	 */
283
+	public function remove($object)
284
+	{
285
+		$this->detach($object);
286
+		return true;
287
+	}
288
+
289
+
290
+	/**
291
+	 * setCurrent
292
+	 * advances pointer to the object whose identifier matches that which was provided
293
+	 *
294
+	 * @param mixed $identifier
295
+	 * @return boolean
296
+	 */
297
+	public function setCurrent($identifier)
298
+	{
299
+		$this->rewind();
300
+		while ($this->valid()) {
301
+			if ($identifier === $this->getInfo()) {
302
+				return true;
303
+			}
304
+			$this->next();
305
+		}
306
+		return false;
307
+	}
308
+
309
+
310
+	/**
311
+	 * setCurrentUsingObject
312
+	 * advances pointer to the provided object
313
+	 *
314
+	 * @param $object
315
+	 * @return boolean
316
+	 */
317
+	public function setCurrentUsingObject($object)
318
+	{
319
+		$this->rewind();
320
+		while ($this->valid()) {
321
+			if ($this->current() === $object) {
322
+				return true;
323
+			}
324
+			$this->next();
325
+		}
326
+		return false;
327
+	}
328
+
329
+
330
+	/**
331
+	 * Returns the object occupying the index before the current object,
332
+	 * unless this is already the first object, in which case it just returns the first object
333
+	 *
334
+	 * @return mixed
335
+	 */
336
+	public function previous()
337
+	{
338
+		$index = $this->indexOf($this->current());
339
+		if ($index === 0) {
340
+			return $this->current();
341
+		}
342
+		$index--;
343
+		return $this->objectAtIndex($index);
344
+	}
345
+
346
+
347
+	/**
348
+	 * Returns the index of a given object, or false if not found
349
+	 *
350
+	 * @see http://stackoverflow.com/a/8736013
351
+	 * @param $object
352
+	 * @return boolean|int|string
353
+	 */
354
+	public function indexOf($object)
355
+	{
356
+		if (! $this->contains($object)) {
357
+			return false;
358
+		}
359
+		foreach ($this as $index => $obj) {
360
+			if ($obj === $object) {
361
+				return $index;
362
+			}
363
+		}
364
+		return false;
365
+	}
366
+
367
+
368
+	/**
369
+	 * Returns the object at the given index
370
+	 *
371
+	 * @see http://stackoverflow.com/a/8736013
372
+	 * @param int $index
373
+	 * @return mixed
374
+	 */
375
+	public function objectAtIndex($index)
376
+	{
377
+		$iterator = new LimitIterator($this, $index, 1);
378
+		$iterator->rewind();
379
+		return $iterator->current();
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns the sequence of objects as specified by the offset and length
385
+	 *
386
+	 * @see http://stackoverflow.com/a/8736013
387
+	 * @param int $offset
388
+	 * @param int $length
389
+	 * @return array
390
+	 */
391
+	public function slice($offset, $length)
392
+	{
393
+		$slice = array();
394
+		$iterator = new LimitIterator($this, $offset, $length);
395
+		foreach ($iterator as $object) {
396
+			$slice[] = $object;
397
+		}
398
+		return $slice;
399
+	}
400
+
401
+
402
+	/**
403
+	 * Inserts an object at a certain point
404
+	 *
405
+	 * @see http://stackoverflow.com/a/8736013
406
+	 * @param mixed $object A single object
407
+	 * @param int   $index
408
+	 * @param mixed $identifier
409
+	 * @return bool
410
+	 * @throws DuplicateCollectionIdentifierException
411
+	 * @throws InvalidEntityException
412
+	 */
413
+	public function insertObjectAt($object, $index, $identifier = null)
414
+	{
415
+		// check to ensure that objects don't already exist in the collection
416
+		if ($this->has($identifier)) {
417
+			throw new DuplicateCollectionIdentifierException($identifier);
418
+		}
419
+		// detach any objects at or past this index
420
+		$remaining_objects = array();
421
+		if ($index < $this->count()) {
422
+			$remaining_objects = $this->slice($index, $this->count() - $index);
423
+			foreach ($remaining_objects as $key => $remaining_object) {
424
+				// we need to grab the identifiers for each object and use them as keys
425
+				$remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
426
+				// and then remove the object from the current tracking array
427
+				unset($remaining_objects[ $key ]);
428
+				// and then remove it from the Collection
429
+				$this->detach($remaining_object);
430
+			}
431
+		}
432
+		// add the new object we're splicing in
433
+		$this->add($object, $identifier);
434
+		// attach the objects we previously detached
435
+		foreach ($remaining_objects as $key => $remaining_object) {
436
+			$this->add($remaining_object, $key);
437
+		}
438
+		return $this->contains($object);
439
+	}
440
+
441
+
442
+	/**
443
+	 * Inserts an object (or an array of objects) at a certain point
444
+	 *
445
+	 * @see http://stackoverflow.com/a/8736013
446
+	 * @param mixed $objects A single object or an array of objects
447
+	 * @param int   $index
448
+	 */
449
+	public function insertAt($objects, $index)
450
+	{
451
+		if (! is_array($objects)) {
452
+			$objects = array($objects);
453
+		}
454
+		// check to ensure that objects don't already exist in the collection
455
+		foreach ($objects as $key => $object) {
456
+			if ($this->contains($object)) {
457
+				unset($objects[ $key ]);
458
+			}
459
+		}
460
+		// do we have any objects left?
461
+		if (! $objects) {
462
+			return;
463
+		}
464
+		// detach any objects at or past this index
465
+		$remaining = array();
466
+		if ($index < $this->count()) {
467
+			$remaining = $this->slice($index, $this->count() - $index);
468
+			foreach ($remaining as $object) {
469
+				$this->detach($object);
470
+			}
471
+		}
472
+		// add the new objects we're splicing in
473
+		foreach ($objects as $object) {
474
+			$this->attach($object);
475
+		}
476
+		// attach the objects we previously detached
477
+		foreach ($remaining as $object) {
478
+			$this->attach($object);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * Removes the object at the given index
485
+	 *
486
+	 * @see http://stackoverflow.com/a/8736013
487
+	 * @param int $index
488
+	 */
489
+	public function removeAt($index)
490
+	{
491
+		$this->detach($this->objectAtIndex($index));
492
+	}
493
+
494
+
495
+	/**
496
+	 * detaches ALL objects from the Collection
497
+	 */
498
+	public function detachAll()
499
+	{
500
+		$this->rewind();
501
+		while ($this->valid()) {
502
+			$object = $this->current();
503
+			$this->next();
504
+			$this->detach($object);
505
+		}
506
+	}
507
+
508
+
509
+	/**
510
+	 * unsets and detaches ALL objects from the Collection
511
+	 */
512
+	public function trashAndDetachAll()
513
+	{
514
+		$this->rewind();
515
+		while ($this->valid()) {
516
+			$object = $this->current();
517
+			$this->next();
518
+			$this->detach($object);
519
+			unset($object);
520
+		}
521
+	}
522 522
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     ) {
88 88
         try {
89 89
             $this->collection_details = $collection_details;
90
-            if (! $collection instanceof CollectionInterface) {
90
+            if ( ! $collection instanceof CollectionInterface) {
91 91
                 $collection = new Collection($this->collection_details->getCollectionInterface());
92 92
             }
93 93
             $this->collection = $collection;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function loadAllFromFilepaths()
121 121
     {
122
-        if (! $this->file_locator instanceof FileLocator) {
122
+        if ( ! $this->file_locator instanceof FileLocator) {
123 123
             $this->file_locator = new FileLocator();
124 124
         }
125 125
         $this->file_locator->setFileMask($this->collection_details->getFileMask());
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
      */
153 153
     protected function loadClassFromFilepath($filepath)
154 154
     {
155
-        if (! is_string($filepath)) {
155
+        if ( ! is_string($filepath)) {
156 156
             throw new InvalidDataTypeException('$filepath', $filepath, 'string');
157 157
         }
158
-        if (! is_readable($filepath)) {
158
+        if ( ! is_readable($filepath)) {
159 159
             throw new InvalidFilePathException($filepath);
160 160
         }
161 161
         require_once $filepath;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         $file_name = basename($filepath);
164 164
         // now remove any file extensions
165 165
         $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
166
-        if (! class_exists($class_name)) {
166
+        if ( ! class_exists($class_name)) {
167 167
             throw new InvalidClassException($class_name);
168 168
         }
169 169
         $entity = $this->entity_factory instanceof FactoryInterface
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
             // objects added to the collection based on entity callback, so the entity itself decides
238 238
             case CollectionDetails::ID_CALLBACK_METHOD:
239 239
                 $identifier_callback = $this->collection_details->identifierCallback();
240
-                if (! method_exists($entity, $identifier_callback)) {
240
+                if ( ! method_exists($entity, $identifier_callback)) {
241 241
                     throw new InvalidEntityException(
242 242
                         $entity,
243 243
                         $this->collection_details->getCollectionInterface(),
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
      */
304 304
     protected function loadClassFromFQCN($FQCN)
305 305
     {
306
-        if (! is_string($FQCN)) {
306
+        if ( ! is_string($FQCN)) {
307 307
             throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
308 308
         }
309
-        if (! class_exists($FQCN)) {
309
+        if ( ! class_exists($FQCN)) {
310 310
             throw new InvalidClassException($FQCN);
311 311
         }
312 312
         do_action(
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -29,295 +29,295 @@
 block discarded – undo
29 29
 class CollectionLoader
30 30
 {
31 31
 
32
-    /**
33
-     * possible return value when adding entities to a collection.
34
-     * denotes that the entity was NOT ADDED to the collection
35
-     */
36
-    const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
32
+	/**
33
+	 * possible return value when adding entities to a collection.
34
+	 * denotes that the entity was NOT ADDED to the collection
35
+	 */
36
+	const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
37 37
 
38
-    /**
39
-     * possible return value when adding entities to a collection.
40
-     * denotes that the entity was SUCCESSFULLY ADDED to the collection
41
-     */
42
-    const ENTITY_ADDED = 'entity-added-to-collection';
38
+	/**
39
+	 * possible return value when adding entities to a collection.
40
+	 * denotes that the entity was SUCCESSFULLY ADDED to the collection
41
+	 */
42
+	const ENTITY_ADDED = 'entity-added-to-collection';
43 43
 
44
-    /**
45
-     * possible return value when adding entities to a collection.
46
-     * denotes that the entity was ALREADY ADDED to the collection,
47
-     * and therefore could not be added again.
48
-     */
49
-    const ENTITY_EXISTS = 'entity-already-in-collection';
44
+	/**
45
+	 * possible return value when adding entities to a collection.
46
+	 * denotes that the entity was ALREADY ADDED to the collection,
47
+	 * and therefore could not be added again.
48
+	 */
49
+	const ENTITY_EXISTS = 'entity-already-in-collection';
50 50
 
51 51
 
52
-    /**
53
-     * @var CollectionDetailsInterface $collection_details
54
-     */
55
-    protected $collection_details;
52
+	/**
53
+	 * @var CollectionDetailsInterface $collection_details
54
+	 */
55
+	protected $collection_details;
56 56
 
57
-    /**
58
-     * @var CollectionInterface $collection
59
-     */
60
-    protected $collection;
57
+	/**
58
+	 * @var CollectionInterface $collection
59
+	 */
60
+	protected $collection;
61 61
 
62
-    /**
63
-     * @var FactoryInterface $entity_factory
64
-     */
65
-    protected $entity_factory;
62
+	/**
63
+	 * @var FactoryInterface $entity_factory
64
+	 */
65
+	protected $entity_factory;
66 66
 
67
-    /**
68
-     * @var FileLocator $file_locator
69
-     */
70
-    protected $file_locator;
67
+	/**
68
+	 * @var FileLocator $file_locator
69
+	 */
70
+	protected $file_locator;
71 71
 
72 72
 
73
-    /**
74
-     * CollectionLoader constructor.
75
-     *
76
-     * @param CollectionDetailsInterface $collection_details
77
-     * @param CollectionInterface        $collection
78
-     * @param LocatorInterface           $file_locator
79
-     * @param FactoryInterface|null      $entity_factory
80
-     * @throws CollectionLoaderException
81
-     */
82
-    public function __construct(
83
-        CollectionDetailsInterface $collection_details,
84
-        CollectionInterface $collection = null,
85
-        LocatorInterface $file_locator = null,
86
-        FactoryInterface $entity_factory = null
87
-    ) {
88
-        try {
89
-            $this->collection_details = $collection_details;
90
-            if (! $collection instanceof CollectionInterface) {
91
-                $collection = new Collection($this->collection_details->getCollectionInterface());
92
-            }
93
-            $this->collection = $collection;
94
-            $this->file_locator = $file_locator;
95
-            $this->entity_factory = $entity_factory;
96
-            $this->loadAllFromFilepaths();
97
-            $this->loadFromFQCNs();
98
-        } catch (Exception $exception) {
99
-            throw new CollectionLoaderException($exception);
100
-        }
101
-    }
73
+	/**
74
+	 * CollectionLoader constructor.
75
+	 *
76
+	 * @param CollectionDetailsInterface $collection_details
77
+	 * @param CollectionInterface        $collection
78
+	 * @param LocatorInterface           $file_locator
79
+	 * @param FactoryInterface|null      $entity_factory
80
+	 * @throws CollectionLoaderException
81
+	 */
82
+	public function __construct(
83
+		CollectionDetailsInterface $collection_details,
84
+		CollectionInterface $collection = null,
85
+		LocatorInterface $file_locator = null,
86
+		FactoryInterface $entity_factory = null
87
+	) {
88
+		try {
89
+			$this->collection_details = $collection_details;
90
+			if (! $collection instanceof CollectionInterface) {
91
+				$collection = new Collection($this->collection_details->getCollectionInterface());
92
+			}
93
+			$this->collection = $collection;
94
+			$this->file_locator = $file_locator;
95
+			$this->entity_factory = $entity_factory;
96
+			$this->loadAllFromFilepaths();
97
+			$this->loadFromFQCNs();
98
+		} catch (Exception $exception) {
99
+			throw new CollectionLoaderException($exception);
100
+		}
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @return CollectionInterface
106
-     */
107
-    public function getCollection()
108
-    {
109
-        return $this->collection;
110
-    }
104
+	/**
105
+	 * @return CollectionInterface
106
+	 */
107
+	public function getCollection()
108
+	{
109
+		return $this->collection;
110
+	}
111 111
 
112 112
 
113
-    /**
114
-     * @throws InvalidClassException
115
-     * @throws InvalidFilePathException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     * @throws DuplicateCollectionIdentifierException
119
-     */
120
-    protected function loadAllFromFilepaths()
121
-    {
122
-        if (! $this->file_locator instanceof FileLocator) {
123
-            $this->file_locator = new FileLocator();
124
-        }
125
-        $this->file_locator->setFileMask($this->collection_details->getFileMask());
126
-        // find all of the files that match the file mask in the specified folder
127
-        $this->file_locator->locate($this->collection_details->getCollectionPaths());
128
-        // filter the results
129
-        $filepaths = (array) apply_filters(
130
-            'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
131
-            $this->file_locator->getFilePaths(),
132
-            $this->collection_details->collectionName(),
133
-            $this->collection_details
134
-        );
135
-        if (empty($filepaths)) {
136
-            return;
137
-        }
138
-        foreach ($filepaths as $filepath) {
139
-            $this->loadClassFromFilepath($filepath);
140
-        }
141
-    }
113
+	/**
114
+	 * @throws InvalidClassException
115
+	 * @throws InvalidFilePathException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 * @throws DuplicateCollectionIdentifierException
119
+	 */
120
+	protected function loadAllFromFilepaths()
121
+	{
122
+		if (! $this->file_locator instanceof FileLocator) {
123
+			$this->file_locator = new FileLocator();
124
+		}
125
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
126
+		// find all of the files that match the file mask in the specified folder
127
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
128
+		// filter the results
129
+		$filepaths = (array) apply_filters(
130
+			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
131
+			$this->file_locator->getFilePaths(),
132
+			$this->collection_details->collectionName(),
133
+			$this->collection_details
134
+		);
135
+		if (empty($filepaths)) {
136
+			return;
137
+		}
138
+		foreach ($filepaths as $filepath) {
139
+			$this->loadClassFromFilepath($filepath);
140
+		}
141
+	}
142 142
 
143 143
 
144
-    /**
145
-     * @param  string $filepath
146
-     * @return string
147
-     * @throws InvalidEntityException
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidFilePathException
150
-     * @throws InvalidClassException
151
-     * @throws DuplicateCollectionIdentifierException
152
-     */
153
-    protected function loadClassFromFilepath($filepath)
154
-    {
155
-        if (! is_string($filepath)) {
156
-            throw new InvalidDataTypeException('$filepath', $filepath, 'string');
157
-        }
158
-        if (! is_readable($filepath)) {
159
-            throw new InvalidFilePathException($filepath);
160
-        }
161
-        require_once $filepath;
162
-        // extract filename from path
163
-        $file_name = basename($filepath);
164
-        // now remove any file extensions
165
-        $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
166
-        if (! class_exists($class_name)) {
167
-            throw new InvalidClassException($class_name);
168
-        }
169
-        $entity = $this->entity_factory instanceof FactoryInterface
170
-            ? call_user_func(array($this->entity_factory, 'create'), $class_name)
171
-            : new $class_name();
172
-        return $this->addEntityToCollection($entity, $file_name);
173
-    }
144
+	/**
145
+	 * @param  string $filepath
146
+	 * @return string
147
+	 * @throws InvalidEntityException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidFilePathException
150
+	 * @throws InvalidClassException
151
+	 * @throws DuplicateCollectionIdentifierException
152
+	 */
153
+	protected function loadClassFromFilepath($filepath)
154
+	{
155
+		if (! is_string($filepath)) {
156
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
157
+		}
158
+		if (! is_readable($filepath)) {
159
+			throw new InvalidFilePathException($filepath);
160
+		}
161
+		require_once $filepath;
162
+		// extract filename from path
163
+		$file_name = basename($filepath);
164
+		// now remove any file extensions
165
+		$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
166
+		if (! class_exists($class_name)) {
167
+			throw new InvalidClassException($class_name);
168
+		}
169
+		$entity = $this->entity_factory instanceof FactoryInterface
170
+			? call_user_func(array($this->entity_factory, 'create'), $class_name)
171
+			: new $class_name();
172
+		return $this->addEntityToCollection($entity, $file_name);
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * @param        $entity
178
-     * @param  mixed $identifier
179
-     * @return string
180
-     * @throws InvalidEntityException
181
-     * @throws DuplicateCollectionIdentifierException
182
-     */
183
-    protected function addEntityToCollection($entity, $identifier)
184
-    {
185
-        do_action(
186
-            'FHEE__CollectionLoader__addEntityToCollection__entity',
187
-            $entity,
188
-            $this->collection_details->collectionName(),
189
-            $this->collection_details
190
-        );
191
-        $identifier = $this->setIdentifier($entity, $identifier);
192
-        if ($this->collection->has($identifier)) {
193
-            do_action(
194
-                'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
195
-                $this,
196
-                $this->collection_details->collectionName(),
197
-                $this->collection_details
198
-            );
199
-            return CollectionLoader::ENTITY_EXISTS;
200
-        }
201
-        if ($this->collection->add($entity, $identifier)) {
202
-            do_action(
203
-                'FHEE__CollectionLoader__addEntityToCollection__entity_added',
204
-                $this,
205
-                $this->collection_details->collectionName(),
206
-                $this->collection_details
207
-            );
208
-            return CollectionLoader::ENTITY_ADDED;
209
-        }
210
-        do_action(
211
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
212
-            $this,
213
-            $this->collection_details->collectionName(),
214
-            $this->collection_details
215
-        );
216
-        return CollectionLoader::ENTITY_NOT_ADDED;
217
-    }
176
+	/**
177
+	 * @param        $entity
178
+	 * @param  mixed $identifier
179
+	 * @return string
180
+	 * @throws InvalidEntityException
181
+	 * @throws DuplicateCollectionIdentifierException
182
+	 */
183
+	protected function addEntityToCollection($entity, $identifier)
184
+	{
185
+		do_action(
186
+			'FHEE__CollectionLoader__addEntityToCollection__entity',
187
+			$entity,
188
+			$this->collection_details->collectionName(),
189
+			$this->collection_details
190
+		);
191
+		$identifier = $this->setIdentifier($entity, $identifier);
192
+		if ($this->collection->has($identifier)) {
193
+			do_action(
194
+				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
195
+				$this,
196
+				$this->collection_details->collectionName(),
197
+				$this->collection_details
198
+			);
199
+			return CollectionLoader::ENTITY_EXISTS;
200
+		}
201
+		if ($this->collection->add($entity, $identifier)) {
202
+			do_action(
203
+				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
204
+				$this,
205
+				$this->collection_details->collectionName(),
206
+				$this->collection_details
207
+			);
208
+			return CollectionLoader::ENTITY_ADDED;
209
+		}
210
+		do_action(
211
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
212
+			$this,
213
+			$this->collection_details->collectionName(),
214
+			$this->collection_details
215
+		);
216
+		return CollectionLoader::ENTITY_NOT_ADDED;
217
+	}
218 218
 
219 219
 
220
-    /**
221
-     * @param        $entity
222
-     * @param  mixed $identifier
223
-     * @return string
224
-     * @throws InvalidEntityException
225
-     */
226
-    protected function setIdentifier($entity, $identifier)
227
-    {
228
-        switch ($this->collection_details->identifierType()) {
229
-            // every unique object gets added to the collection, but not duplicates of the exact same object
230
-            case CollectionDetails::ID_OBJECT_HASH:
231
-                $identifier = spl_object_hash($entity);
232
-                break;
233
-            // only one entity per class can be added to collection, like a singleton
234
-            case CollectionDetails::ID_CLASS_NAME:
235
-                $identifier = get_class($entity);
236
-                break;
237
-            // objects added to the collection based on entity callback, so the entity itself decides
238
-            case CollectionDetails::ID_CALLBACK_METHOD:
239
-                $identifier_callback = $this->collection_details->identifierCallback();
240
-                if (! method_exists($entity, $identifier_callback)) {
241
-                    throw new InvalidEntityException(
242
-                        $entity,
243
-                        $this->collection_details->getCollectionInterface(),
244
-                        sprintf(
245
-                            esc_html__(
246
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
220
+	/**
221
+	 * @param        $entity
222
+	 * @param  mixed $identifier
223
+	 * @return string
224
+	 * @throws InvalidEntityException
225
+	 */
226
+	protected function setIdentifier($entity, $identifier)
227
+	{
228
+		switch ($this->collection_details->identifierType()) {
229
+			// every unique object gets added to the collection, but not duplicates of the exact same object
230
+			case CollectionDetails::ID_OBJECT_HASH:
231
+				$identifier = spl_object_hash($entity);
232
+				break;
233
+			// only one entity per class can be added to collection, like a singleton
234
+			case CollectionDetails::ID_CLASS_NAME:
235
+				$identifier = get_class($entity);
236
+				break;
237
+			// objects added to the collection based on entity callback, so the entity itself decides
238
+			case CollectionDetails::ID_CALLBACK_METHOD:
239
+				$identifier_callback = $this->collection_details->identifierCallback();
240
+				if (! method_exists($entity, $identifier_callback)) {
241
+					throw new InvalidEntityException(
242
+						$entity,
243
+						$this->collection_details->getCollectionInterface(),
244
+						sprintf(
245
+							esc_html__(
246
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
247 247
                                 of "%2$s", but does not contain this method.',
248
-                                'event_espresso'
249
-                            ),
250
-                            $identifier_callback,
251
-                            get_class($entity)
252
-                        )
253
-                    );
254
-                }
255
-                $identifier = $entity->{$identifier_callback}();
256
-                break;
257
-        }
258
-        return apply_filters(
259
-            'FHEE__CollectionLoader__addEntityToCollection__identifier',
260
-            $identifier,
261
-            $this->collection_details->collectionName(),
262
-            $this->collection_details
263
-        );
264
-    }
248
+								'event_espresso'
249
+							),
250
+							$identifier_callback,
251
+							get_class($entity)
252
+						)
253
+					);
254
+				}
255
+				$identifier = $entity->{$identifier_callback}();
256
+				break;
257
+		}
258
+		return apply_filters(
259
+			'FHEE__CollectionLoader__addEntityToCollection__identifier',
260
+			$identifier,
261
+			$this->collection_details->collectionName(),
262
+			$this->collection_details
263
+		);
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * @throws ReflectionException
269
-     * @throws InvalidArgumentException
270
-     * @throws InvalidInterfaceException
271
-     * @throws EE_Error
272
-     * @throws InvalidClassException
273
-     * @throws InvalidDataTypeException
274
-     * @throws InvalidEntityException
275
-     * @throws DuplicateCollectionIdentifierException
276
-     */
277
-    protected function loadFromFQCNs()
278
-    {
279
-        $FQCNs = $this->collection_details->getCollectionFQCNs();
280
-        $FQCNs = (array) apply_filters(
281
-            'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
282
-            $FQCNs,
283
-            $this->collection_details->collectionName(),
284
-            $this->collection_details
285
-        );
286
-        foreach ($FQCNs as $FQCN) {
287
-            $this->loadClassFromFQCN($FQCN);
288
-        }
289
-    }
267
+	/**
268
+	 * @throws ReflectionException
269
+	 * @throws InvalidArgumentException
270
+	 * @throws InvalidInterfaceException
271
+	 * @throws EE_Error
272
+	 * @throws InvalidClassException
273
+	 * @throws InvalidDataTypeException
274
+	 * @throws InvalidEntityException
275
+	 * @throws DuplicateCollectionIdentifierException
276
+	 */
277
+	protected function loadFromFQCNs()
278
+	{
279
+		$FQCNs = $this->collection_details->getCollectionFQCNs();
280
+		$FQCNs = (array) apply_filters(
281
+			'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
282
+			$FQCNs,
283
+			$this->collection_details->collectionName(),
284
+			$this->collection_details
285
+		);
286
+		foreach ($FQCNs as $FQCN) {
287
+			$this->loadClassFromFQCN($FQCN);
288
+		}
289
+	}
290 290
 
291 291
 
292
-    /**
293
-     * @param  string $FQCN Fully Qualified Class Name
294
-     * @return string
295
-     * @throws InvalidArgumentException
296
-     * @throws InvalidInterfaceException
297
-     * @throws ReflectionException
298
-     * @throws EE_Error
299
-     * @throws InvalidEntityException
300
-     * @throws InvalidDataTypeException
301
-     * @throws InvalidClassException
302
-     * @throws DuplicateCollectionIdentifierException
303
-     */
304
-    protected function loadClassFromFQCN($FQCN)
305
-    {
306
-        if (! is_string($FQCN)) {
307
-            throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
308
-        }
309
-        if (! class_exists($FQCN)) {
310
-            throw new InvalidClassException($FQCN);
311
-        }
312
-        do_action(
313
-            'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading',
314
-            $FQCN,
315
-            $this->collection_details->collectionName(),
316
-            $this->collection_details
317
-        );
318
-        $entity = $this->entity_factory instanceof FactoryInterface
319
-            ? call_user_func(array($this->entity_factory, 'create'), $FQCN)
320
-            : EE_Registry::instance()->create($FQCN);
321
-        return $this->addEntityToCollection($entity, $FQCN);
322
-    }
292
+	/**
293
+	 * @param  string $FQCN Fully Qualified Class Name
294
+	 * @return string
295
+	 * @throws InvalidArgumentException
296
+	 * @throws InvalidInterfaceException
297
+	 * @throws ReflectionException
298
+	 * @throws EE_Error
299
+	 * @throws InvalidEntityException
300
+	 * @throws InvalidDataTypeException
301
+	 * @throws InvalidClassException
302
+	 * @throws DuplicateCollectionIdentifierException
303
+	 */
304
+	protected function loadClassFromFQCN($FQCN)
305
+	{
306
+		if (! is_string($FQCN)) {
307
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
308
+		}
309
+		if (! class_exists($FQCN)) {
310
+			throw new InvalidClassException($FQCN);
311
+		}
312
+		do_action(
313
+			'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading',
314
+			$FQCN,
315
+			$this->collection_details->collectionName(),
316
+			$this->collection_details
317
+		);
318
+		$entity = $this->entity_factory instanceof FactoryInterface
319
+			? call_user_func(array($this->entity_factory, 'create'), $FQCN)
320
+			: EE_Registry::instance()->create($FQCN);
321
+		return $this->addEntityToCollection($entity, $FQCN);
322
+	}
323 323
 }
Please login to merge, or discard this patch.
core/services/session/SessionStartHandler.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
         // If not, then attempt to deal with any errors,
101 101
         // otherwise, try to hobble along without the session
102
-        if (! $this->handleSessionSaveHandlerErrors()) {
102
+        if ( ! $this->handleSessionSaveHandlerErrors()) {
103 103
             return;
104 104
         }
105 105
         // there is no record of a fatal error while trying to start the session
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                     ),
250 250
                     '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
251 251
                     '</a>',
252
-                    '<a href="' . $retry_session_url . '">'
252
+                    '<a href="'.$retry_session_url.'">'
253 253
                 ),
254 254
                 __FILE__,
255 255
                 __FUNCTION__,
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -27,237 +27,237 @@
 block discarded – undo
27 27
  */
28 28
 class SessionStartHandler
29 29
 {
30
-    const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
-    const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session';
32
-    const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed';
33
-    const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success';
34
-    const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested';
30
+	const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
+	const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session';
32
+	const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed';
33
+	const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success';
34
+	const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested';
35 35
 
36
-    /**
37
-     * @var RequestInterface $request
38
-     */
39
-    protected $request;
36
+	/**
37
+	 * @var RequestInterface $request
38
+	 */
39
+	protected $request;
40 40
 
41
-    /**
42
-     * StartSession constructor.
43
-     *
44
-     * @param RequestInterface $request
45
-     */
46
-    public function __construct(RequestInterface $request)
47
-    {
48
-        $this->request = $request;
49
-    }
41
+	/**
42
+	 * StartSession constructor.
43
+	 *
44
+	 * @param RequestInterface $request
45
+	 */
46
+	public function __construct(RequestInterface $request)
47
+	{
48
+		$this->request = $request;
49
+	}
50 50
 
51
-    /**
52
-     * Check if a custom session save handler is in play
53
-     * and attempt to start the PHP session
54
-     *
55
-     * @since 4.9.68.p
56
-     */
57
-    public function startSession()
58
-    {
59
-        // check that session has started
60
-        if (session_id() === '') {
61
-            // starts a new session if one doesn't already exist, or re-initiates an existing one
62
-            if ($this->hasKnownCustomSessionSaveHandler()) {
63
-                $this->checkCustomSessionSaveHandler();
64
-            } else {
65
-                session_start();
66
-                session_write_close();
67
-            }
68
-        }
69
-    }
51
+	/**
52
+	 * Check if a custom session save handler is in play
53
+	 * and attempt to start the PHP session
54
+	 *
55
+	 * @since 4.9.68.p
56
+	 */
57
+	public function startSession()
58
+	{
59
+		// check that session has started
60
+		if (session_id() === '') {
61
+			// starts a new session if one doesn't already exist, or re-initiates an existing one
62
+			if ($this->hasKnownCustomSessionSaveHandler()) {
63
+				$this->checkCustomSessionSaveHandler();
64
+			} else {
65
+				session_start();
66
+				session_write_close();
67
+			}
68
+		}
69
+	}
70 70
 
71
-    /**
72
-     * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
73
-     *
74
-     * @since 4.9.68.p
75
-     * @return bool
76
-     */
77
-    private function hasKnownCustomSessionSaveHandler()
78
-    {
79
-        return in_array(
80
-            ini_get('session.save_handler'),
81
-            array(
82
-                'user',
83
-            ),
84
-            true
85
-        );
86
-    }
71
+	/**
72
+	 * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
73
+	 *
74
+	 * @since 4.9.68.p
75
+	 * @return bool
76
+	 */
77
+	private function hasKnownCustomSessionSaveHandler()
78
+	{
79
+		return in_array(
80
+			ini_get('session.save_handler'),
81
+			array(
82
+				'user',
83
+			),
84
+			true
85
+		);
86
+	}
87 87
 
88
-    /**
89
-     * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
90
-     *
91
-     * @since 4.9.68.p
92
-     */
93
-    private function checkCustomSessionSaveHandler()
94
-    {
95
-        // If we've already successfully tested the session save handler
96
-        // on a previous request then just start the session
97
-        if ($this->sessionSaveHandlerIsValid()) {
98
-            session_start();
99
-            session_write_close();
100
-            return;
101
-        }
102
-        // If not, then attempt to deal with any errors,
103
-        // otherwise, try to hobble along without the session
104
-        if (! $this->handleSessionSaveHandlerErrors()) {
105
-            return;
106
-        }
107
-        // there is no record of a fatal error while trying to start the session
108
-        // so let's see if there's a custom session save handler. Proceed with caution
109
-        $this->initializeSessionSaveHandlerStatus();
110
-        // hold your breath, the custom session save handler might cause a fatal here...
111
-        session_start();
112
-        session_write_close();
113
-        // phew! we made it! the custom session handler is a-ok
114
-        $this->setSessionSaveHandlerStatusToValid();
115
-    }
88
+	/**
89
+	 * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
90
+	 *
91
+	 * @since 4.9.68.p
92
+	 */
93
+	private function checkCustomSessionSaveHandler()
94
+	{
95
+		// If we've already successfully tested the session save handler
96
+		// on a previous request then just start the session
97
+		if ($this->sessionSaveHandlerIsValid()) {
98
+			session_start();
99
+			session_write_close();
100
+			return;
101
+		}
102
+		// If not, then attempt to deal with any errors,
103
+		// otherwise, try to hobble along without the session
104
+		if (! $this->handleSessionSaveHandlerErrors()) {
105
+			return;
106
+		}
107
+		// there is no record of a fatal error while trying to start the session
108
+		// so let's see if there's a custom session save handler. Proceed with caution
109
+		$this->initializeSessionSaveHandlerStatus();
110
+		// hold your breath, the custom session save handler might cause a fatal here...
111
+		session_start();
112
+		session_write_close();
113
+		// phew! we made it! the custom session handler is a-ok
114
+		$this->setSessionSaveHandlerStatusToValid();
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * retrieves the value for the 'ee_session_save_handler_status' WP option.
120
-     * default value = 'session_save_handler_untested'
121
-     *
122
-     * @since 4.9.68.p
123
-     * @return string
124
-     */
125
-    private function getSessionSaveHandlerStatus()
126
-    {
127
-        return get_option(
128
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
129
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
130
-        );
131
-    }
118
+	/**
119
+	 * retrieves the value for the 'ee_session_save_handler_status' WP option.
120
+	 * default value = 'session_save_handler_untested'
121
+	 *
122
+	 * @since 4.9.68.p
123
+	 * @return string
124
+	 */
125
+	private function getSessionSaveHandlerStatus()
126
+	{
127
+		return get_option(
128
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
129
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
130
+		);
131
+	}
132 132
 
133
-    /**
134
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
135
-     * which can then be upgraded is everything works correctly
136
-     *
137
-     * @since 4.9.68.p
138
-     * @return bool
139
-     */
140
-    private function initializeSessionSaveHandlerStatus()
141
-    {
142
-        return update_option(
143
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
144
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
145
-        );
146
-    }
133
+	/**
134
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
135
+	 * which can then be upgraded is everything works correctly
136
+	 *
137
+	 * @since 4.9.68.p
138
+	 * @return bool
139
+	 */
140
+	private function initializeSessionSaveHandlerStatus()
141
+	{
142
+		return update_option(
143
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
144
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
145
+		);
146
+	}
147 147
 
148
-    /**
149
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
150
-     *
151
-     * @since 4.9.68.p
152
-     * @return bool
153
-     */
154
-    private function setSessionSaveHandlerStatusToValid()
155
-    {
156
-        return update_option(
157
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
158
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
159
-        );
160
-    }
148
+	/**
149
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
150
+	 *
151
+	 * @since 4.9.68.p
152
+	 * @return bool
153
+	 */
154
+	private function setSessionSaveHandlerStatusToValid()
155
+	{
156
+		return update_option(
157
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
158
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
159
+		);
160
+	}
161 161
 
162
-    /**
163
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
164
-     *
165
-     * @since 4.9.68.p
166
-     * @return bool
167
-     */
168
-    private function resetSessionSaveHandlerStatus()
169
-    {
170
-        return update_option(
171
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
172
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
173
-        );
174
-    }
162
+	/**
163
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
164
+	 *
165
+	 * @since 4.9.68.p
166
+	 * @return bool
167
+	 */
168
+	private function resetSessionSaveHandlerStatus()
169
+	{
170
+		return update_option(
171
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
172
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
173
+		);
174
+	}
175 175
 
176
-    /**
177
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
178
-     * is equal to 'session_save_handler_success'
179
-     *
180
-     * @since 4.9.68.p
181
-     * @return bool
182
-     */
183
-    private function sessionSaveHandlerIsValid()
184
-    {
185
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
186
-    }
176
+	/**
177
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
178
+	 * is equal to 'session_save_handler_success'
179
+	 *
180
+	 * @since 4.9.68.p
181
+	 * @return bool
182
+	 */
183
+	private function sessionSaveHandlerIsValid()
184
+	{
185
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
186
+	}
187 187
 
188
-    /**
189
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
190
-     * is equal to 'session_save_handler_failed'
191
-     *
192
-     * @since 4.9.68.p
193
-     * @return bool
194
-     */
195
-    private function sessionSaveHandlerFailed()
196
-    {
197
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
198
-    }
188
+	/**
189
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
190
+	 * is equal to 'session_save_handler_failed'
191
+	 *
192
+	 * @since 4.9.68.p
193
+	 * @return bool
194
+	 */
195
+	private function sessionSaveHandlerFailed()
196
+	{
197
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
198
+	}
199 199
 
200
-    /**
201
-     * Returns `true` if no errors were detected with the session save handler,
202
-     * otherwise attempts to work notify the appropriate authorities
203
-     * with a suggestion for how to fix the issue, and returns `false`.
204
-     *
205
-     *
206
-     * @since 4.9.68.p
207
-     * @return bool
208
-     */
209
-    private function handleSessionSaveHandlerErrors()
210
-    {
211
-        // Check if we had a fatal error last time while trying to start the session
212
-        if ($this->sessionSaveHandlerFailed()) {
213
-            // apparently, last time we tried using the custom session save handler there was a fatal
214
-            if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
215
-                $this->resetSessionSaveHandlerStatus();
216
-                // remove "ee_retry_session", otherwise if the problem still isn't fixed,
217
-                // we'll just keep getting the fatal error over and over.
218
-                // Better to remove it and redirect, and try on the next request
219
-                EEH_URL::safeRedirectAndExit(
220
-                    remove_query_arg(
221
-                        array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION),
222
-                        EEH_URL::current_url()
223
-                    )
224
-                );
225
-            }
226
-            // so the session is broken, don't try it again,
227
-            // just show a message to users that can fix it
228
-            $this->displaySessionSaveHandlerErrorNotice();
229
-            return false;
230
-        }
231
-        return true;
232
-    }
200
+	/**
201
+	 * Returns `true` if no errors were detected with the session save handler,
202
+	 * otherwise attempts to work notify the appropriate authorities
203
+	 * with a suggestion for how to fix the issue, and returns `false`.
204
+	 *
205
+	 *
206
+	 * @since 4.9.68.p
207
+	 * @return bool
208
+	 */
209
+	private function handleSessionSaveHandlerErrors()
210
+	{
211
+		// Check if we had a fatal error last time while trying to start the session
212
+		if ($this->sessionSaveHandlerFailed()) {
213
+			// apparently, last time we tried using the custom session save handler there was a fatal
214
+			if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
215
+				$this->resetSessionSaveHandlerStatus();
216
+				// remove "ee_retry_session", otherwise if the problem still isn't fixed,
217
+				// we'll just keep getting the fatal error over and over.
218
+				// Better to remove it and redirect, and try on the next request
219
+				EEH_URL::safeRedirectAndExit(
220
+					remove_query_arg(
221
+						array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION),
222
+						EEH_URL::current_url()
223
+					)
224
+				);
225
+			}
226
+			// so the session is broken, don't try it again,
227
+			// just show a message to users that can fix it
228
+			$this->displaySessionSaveHandlerErrorNotice();
229
+			return false;
230
+		}
231
+		return true;
232
+	}
233 233
 
234
-    /**
235
-     * Generates an EE_Error notice regarding the current session woes
236
-     * but only if the current user is an admin with permission to 'install_plugins'.
237
-     *
238
-     * @since 4.9.68.p
239
-     */
240
-    private function displaySessionSaveHandlerErrorNotice()
241
-    {
242
-        if (current_user_can('install_plugins')) {
243
-            $retry_session_url = add_query_arg(
244
-                array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true),
245
-                EEH_URL::current_url()
246
-            );
247
-            EE_Error::add_error(
248
-                sprintf(
249
-                    esc_html__(
250
-                        'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
251
-                        'event_espresso'
252
-                    ),
253
-                    '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
254
-                    '</a>',
255
-                    '<a href="' . $retry_session_url . '">'
256
-                ),
257
-                __FILE__,
258
-                __FUNCTION__,
259
-                __LINE__
260
-            );
261
-        }
262
-    }
234
+	/**
235
+	 * Generates an EE_Error notice regarding the current session woes
236
+	 * but only if the current user is an admin with permission to 'install_plugins'.
237
+	 *
238
+	 * @since 4.9.68.p
239
+	 */
240
+	private function displaySessionSaveHandlerErrorNotice()
241
+	{
242
+		if (current_user_can('install_plugins')) {
243
+			$retry_session_url = add_query_arg(
244
+				array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true),
245
+				EEH_URL::current_url()
246
+			);
247
+			EE_Error::add_error(
248
+				sprintf(
249
+					esc_html__(
250
+						'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
251
+						'event_espresso'
252
+					),
253
+					'<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
254
+					'</a>',
255
+					'<a href="' . $retry_session_url . '">'
256
+				),
257
+				__FILE__,
258
+				__FUNCTION__,
259
+				__LINE__
260
+			);
261
+		}
262
+	}
263 263
 }
Please login to merge, or discard this patch.
core/services/dependencies/ClassAlias.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      */
35 35
     public function __construct($alias, $fqcn)
36 36
     {
37
-        if (! is_subclass_of($fqcn, $alias)) {
37
+        if ( ! is_subclass_of($fqcn, $alias)) {
38 38
             throw new InvalidAliasException($fqcn, $alias);
39 39
         }
40 40
         $this->alias = $alias;
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -17,46 +17,46 @@
 block discarded – undo
17 17
 class ClassAlias
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $alias   an interface or base class representing what object
22
-     *                      can be utilized by another object and/or function
23
-     */
24
-    private $alias;
25
-
26
-    /**
27
-     * @var string $fqcn the actual class that should be substituted for the alias above
28
-     */
29
-    private $fqcn;
30
-
31
-    /**
32
-     * ClassAlias constructor.
33
-     *
34
-     * @param string $alias Interface specified by implementing class
35
-     * @param string $fqcn  Concrete class that satisfies interface
36
-     * @throws InvalidAliasException
37
-     */
38
-    public function __construct($alias, $fqcn)
39
-    {
40
-        if (! is_subclass_of($fqcn, $alias)) {
41
-            throw new InvalidAliasException($fqcn, $alias);
42
-        }
43
-        $this->alias = $alias;
44
-        $this->fqcn = $fqcn;
45
-    }
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function alias()
51
-    {
52
-        return $this->alias;
53
-    }
54
-
55
-    /**
56
-     * @return string
57
-     */
58
-    public function fqcn()
59
-    {
60
-        return $this->fqcn;
61
-    }
20
+	/**
21
+	 * @var string $alias   an interface or base class representing what object
22
+	 *                      can be utilized by another object and/or function
23
+	 */
24
+	private $alias;
25
+
26
+	/**
27
+	 * @var string $fqcn the actual class that should be substituted for the alias above
28
+	 */
29
+	private $fqcn;
30
+
31
+	/**
32
+	 * ClassAlias constructor.
33
+	 *
34
+	 * @param string $alias Interface specified by implementing class
35
+	 * @param string $fqcn  Concrete class that satisfies interface
36
+	 * @throws InvalidAliasException
37
+	 */
38
+	public function __construct($alias, $fqcn)
39
+	{
40
+		if (! is_subclass_of($fqcn, $alias)) {
41
+			throw new InvalidAliasException($fqcn, $alias);
42
+		}
43
+		$this->alias = $alias;
44
+		$this->fqcn = $fqcn;
45
+	}
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function alias()
51
+	{
52
+		return $this->alias;
53
+	}
54
+
55
+	/**
56
+	 * @return string
57
+	 */
58
+	public function fqcn()
59
+	{
60
+		return $this->fqcn;
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/services/factory/FactoryWithDependencyResolver.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,41 +18,41 @@
 block discarded – undo
18 18
  */
19 19
 abstract class FactoryWithDependencyResolver implements FactoryInterface
20 20
 {
21
-    /**
22
-     * @var DependencyResolverInterface $dependency_resolver
23
-     */
24
-    private $dependency_resolver;
21
+	/**
22
+	 * @var DependencyResolverInterface $dependency_resolver
23
+	 */
24
+	private $dependency_resolver;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    private $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	private $loader;
30 30
 
31
-    /**
32
-     * FactoryWithDependencyResolver constructor.
33
-     *
34
-     * @param DependencyResolverInterface $dependency_resolver
35
-     * @param LoaderInterface             $loader
36
-     */
37
-    public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
-    {
39
-        $this->dependency_resolver = $dependency_resolver;
40
-        $this->loader = $loader;
41
-    }
31
+	/**
32
+	 * FactoryWithDependencyResolver constructor.
33
+	 *
34
+	 * @param DependencyResolverInterface $dependency_resolver
35
+	 * @param LoaderInterface             $loader
36
+	 */
37
+	public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
+	{
39
+		$this->dependency_resolver = $dependency_resolver;
40
+		$this->loader = $loader;
41
+	}
42 42
 
43
-    /**
44
-     * @return DependencyResolverInterface
45
-     */
46
-    public function dependencyResolver()
47
-    {
48
-        return $this->dependency_resolver;
49
-    }
43
+	/**
44
+	 * @return DependencyResolverInterface
45
+	 */
46
+	public function dependencyResolver()
47
+	{
48
+		return $this->dependency_resolver;
49
+	}
50 50
 
51
-    /**
52
-     * @return LoaderInterface
53
-     */
54
-    public function loader()
55
-    {
56
-        return $this->loader;
57
-    }
51
+	/**
52
+	 * @return LoaderInterface
53
+	 */
54
+	public function loader()
55
+	{
56
+		return $this->loader;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/domain/services/factories/FactoryInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@
 block discarded – undo
11 11
 interface FactoryInterface
12 12
 {
13 13
 
14
-    /**
15
-     * @param mixed $arguments Either a Fully Qualified Class Name
16
-     *                         or array of data required for construction
17
-     * @return mixed
18
-     */
19
-    public static function create($arguments);
14
+	/**
15
+	 * @param mixed $arguments Either a Fully Qualified Class Name
16
+	 *                         or array of data required for construction
17
+	 * @return mixed
18
+	 */
19
+	public static function create($arguments);
20 20
 }
Please login to merge, or discard this patch.
core/domain/entities/route_match/MatchAllRouteSpecifications.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     public function isMatchingRoute()
24 24
     {
25 25
         foreach ($this->specifications as $specification) {
26
-            if (! $specification->isMatchingRoute()) {
26
+            if ( ! $specification->isMatchingRoute()) {
27 27
                 return false;
28 28
             }
29 29
         }
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 class MatchAllRouteSpecifications extends MultiRouteSpecification
15 15
 {
16 16
 
17
-    /**
18
-     * returns true if current request matches specification
19
-     *
20
-     * @since 4.9.71.p
21
-     * @return boolean
22
-     */
23
-    public function isMatchingRoute()
24
-    {
25
-        foreach ($this->specifications as $specification) {
26
-            if (! $specification->isMatchingRoute()) {
27
-                return false;
28
-            }
29
-        }
30
-        return true;
31
-    }
17
+	/**
18
+	 * returns true if current request matches specification
19
+	 *
20
+	 * @since 4.9.71.p
21
+	 * @return boolean
22
+	 */
23
+	public function isMatchingRoute()
24
+	{
25
+		foreach ($this->specifications as $specification) {
26
+			if (! $specification->isMatchingRoute()) {
27
+				return false;
28
+			}
29
+		}
30
+		return true;
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/services/route_match/RouteMatchSpecificationManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
     {
116 116
         /** @var RouteMatchSpecificationInterface $specification */
117 117
         $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
118
+        if ( ! $specification instanceof $routeMatchSpecificationFqcn) {
119 119
             throw new InvalidClassException($routeMatchSpecificationFqcn);
120 120
         }
121 121
         return $specification->isMatchingRoute();
Please login to merge, or discard this patch.
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -25,122 +25,122 @@
 block discarded – undo
25 25
  */
26 26
 class RouteMatchSpecificationManager
27 27
 {
28
-    /**
29
-     * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications
30
-     */
31
-    private $specifications;
28
+	/**
29
+	 * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications
30
+	 */
31
+	private $specifications;
32 32
 
33
-    /**
34
-     * @var RouteMatchSpecificationFactory $specifications_factory
35
-     */
36
-    private $specifications_factory;
33
+	/**
34
+	 * @var RouteMatchSpecificationFactory $specifications_factory
35
+	 */
36
+	private $specifications_factory;
37 37
 
38 38
 
39
-    /**
40
-     * RouteMatchSpecificationManager constructor.
41
-     *
42
-     * @param RouteMatchSpecificationCollection $specifications
43
-     * @param RouteMatchSpecificationFactory    $specifications_factory
44
-     */
45
-    public function __construct(
46
-        RouteMatchSpecificationCollection $specifications,
47
-        RouteMatchSpecificationFactory $specifications_factory
48
-    ) {
49
-        $this->specifications = $specifications;
50
-        $this->specifications_factory = $specifications_factory;
51
-        add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
52
-    }
39
+	/**
40
+	 * RouteMatchSpecificationManager constructor.
41
+	 *
42
+	 * @param RouteMatchSpecificationCollection $specifications
43
+	 * @param RouteMatchSpecificationFactory    $specifications_factory
44
+	 */
45
+	public function __construct(
46
+		RouteMatchSpecificationCollection $specifications,
47
+		RouteMatchSpecificationFactory $specifications_factory
48
+	) {
49
+		$this->specifications = $specifications;
50
+		$this->specifications_factory = $specifications_factory;
51
+		add_action('AHEE__EE_System__loadRouteMatchSpecifications', array($this, 'initialize'));
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Perform any early setup required for block editors to functions
57
-     *
58
-     * @return void
59
-     * @throws CollectionLoaderException
60
-     * @throws CollectionDetailsException
61
-     */
62
-    public function initialize()
63
-    {
64
-        $this->populateSpecificationCollection();
65
-    }
55
+	/**
56
+	 * Perform any early setup required for block editors to functions
57
+	 *
58
+	 * @return void
59
+	 * @throws CollectionLoaderException
60
+	 * @throws CollectionDetailsException
61
+	 */
62
+	public function initialize()
63
+	{
64
+		$this->populateSpecificationCollection();
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * @return CollectionInterface|RouteMatchSpecificationInterface[]
70
-     * @throws CollectionLoaderException
71
-     * @throws CollectionDetailsException
72
-     * @since 4.9.71.p
73
-     */
74
-    private function populateSpecificationCollection()
75
-    {
76
-        $loader = new CollectionLoader(
77
-            new CollectionDetails(
78
-                // collection name
79
-                RouteMatchSpecificationCollection::COLLECTION_NAME,
80
-                // collection interface
81
-                'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
82
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
83
-                apply_filters(
84
-                    'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
85
-                    array(
86
-                        'EventEspresso\core\domain\entities\route_match\specifications\admin',
87
-                        'EventEspresso\core\domain\entities\route_match\specifications\frontend',
88
-                    )
89
-                ),
90
-                // filepaths to classes to add
91
-                array(),
92
-                // file mask to use if parsing folder for files to add
93
-                '',
94
-                // what to use as identifier for collection entities
95
-                // using CLASS NAME prevents duplicates (works like a singleton)
96
-                CollectionDetails::ID_CLASS_NAME
97
-            ),
98
-            $this->specifications,
99
-            null,
100
-            $this->specifications_factory
101
-        );
102
-        return $loader->getCollection();
103
-    }
68
+	/**
69
+	 * @return CollectionInterface|RouteMatchSpecificationInterface[]
70
+	 * @throws CollectionLoaderException
71
+	 * @throws CollectionDetailsException
72
+	 * @since 4.9.71.p
73
+	 */
74
+	private function populateSpecificationCollection()
75
+	{
76
+		$loader = new CollectionLoader(
77
+			new CollectionDetails(
78
+				// collection name
79
+				RouteMatchSpecificationCollection::COLLECTION_NAME,
80
+				// collection interface
81
+				'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
82
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
83
+				apply_filters(
84
+					'FHEE__EventEspresso_core_services_route_match_RouteMatchSpecificationManager__populateSpecificationCollection__collection_FQCNs',
85
+					array(
86
+						'EventEspresso\core\domain\entities\route_match\specifications\admin',
87
+						'EventEspresso\core\domain\entities\route_match\specifications\frontend',
88
+					)
89
+				),
90
+				// filepaths to classes to add
91
+				array(),
92
+				// file mask to use if parsing folder for files to add
93
+				'',
94
+				// what to use as identifier for collection entities
95
+				// using CLASS NAME prevents duplicates (works like a singleton)
96
+				CollectionDetails::ID_CLASS_NAME
97
+			),
98
+			$this->specifications,
99
+			null,
100
+			$this->specifications_factory
101
+		);
102
+		return $loader->getCollection();
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
-     *
109
-     * @param string $routeMatchSpecificationFqcn fully qualified class name
110
-     * @return bool
111
-     * @throws InvalidClassException
112
-     * @since 4.9.71.p
113
-     */
114
-    public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
-    {
116
-        /** @var RouteMatchSpecificationInterface $specification */
117
-        $specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
-        if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
-            throw new InvalidClassException($routeMatchSpecificationFqcn);
120
-        }
121
-        return $specification->isMatchingRoute();
122
-    }
106
+	/**
107
+	 * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches
108
+	 *
109
+	 * @param string $routeMatchSpecificationFqcn fully qualified class name
110
+	 * @return bool
111
+	 * @throws InvalidClassException
112
+	 * @since 4.9.71.p
113
+	 */
114
+	public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn)
115
+	{
116
+		/** @var RouteMatchSpecificationInterface $specification */
117
+		$specification = $this->specifications->get($routeMatchSpecificationFqcn);
118
+		if (! $specification instanceof $routeMatchSpecificationFqcn) {
119
+			throw new InvalidClassException($routeMatchSpecificationFqcn);
120
+		}
121
+		return $specification->isMatchingRoute();
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Handy method for development that returns
127
-     * a list of existing RouteMatchSpecification classes
128
-     * matching the current request that can be used to identify it.
129
-     * If no matches are returned (or nothing acceptable)
130
-     * then create a new one that better matches your requirements.
131
-     *
132
-     * @return array
133
-     * @since 4.9.71.p
134
-     */
135
-    public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
-    {
137
-        $matches = array();
138
-        foreach ($this->specifications as $specification) {
139
-            /** @var RouteMatchSpecificationInterface $specification */
140
-            if ($specification->isMatchingRoute()) {
141
-                $matches[] = get_class($specification);
142
-            }
143
-        }
144
-        return $matches;
145
-    }
125
+	/**
126
+	 * Handy method for development that returns
127
+	 * a list of existing RouteMatchSpecification classes
128
+	 * matching the current request that can be used to identify it.
129
+	 * If no matches are returned (or nothing acceptable)
130
+	 * then create a new one that better matches your requirements.
131
+	 *
132
+	 * @return array
133
+	 * @since 4.9.71.p
134
+	 */
135
+	public function findRouteMatchSpecificationsMatchingCurrentRequest()
136
+	{
137
+		$matches = array();
138
+		foreach ($this->specifications as $specification) {
139
+			/** @var RouteMatchSpecificationInterface $specification */
140
+			if ($specification->isMatchingRoute()) {
141
+				$matches[] = get_class($specification);
142
+			}
143
+		}
144
+		return $matches;
145
+	}
146 146
 }
Please login to merge, or discard this patch.