Completed
Branch models-cleanup/model-relations (db5ca7)
by
unknown
13:03 queued 08:35
created
core/domain/services/admin/privacy/erasure/EraseAttendeeData.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -16,74 +16,74 @@
 block discarded – undo
16 16
 class EraseAttendeeData implements PersonalDataEraserInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var EEM_Attendee
21
-     */
22
-    protected $attendee_model;
19
+	/**
20
+	 * @var EEM_Attendee
21
+	 */
22
+	protected $attendee_model;
23 23
 
24 24
 
25
-    /**
26
-     * EraseAttendeeData constructor.
27
-     *
28
-     * @param EEM_Attendee $attendee_model
29
-     */
30
-    public function __construct(EEM_Attendee $attendee_model)
31
-    {
32
-        $this->attendee_model = $attendee_model;
33
-    }
25
+	/**
26
+	 * EraseAttendeeData constructor.
27
+	 *
28
+	 * @param EEM_Attendee $attendee_model
29
+	 */
30
+	public function __construct(EEM_Attendee $attendee_model)
31
+	{
32
+		$this->attendee_model = $attendee_model;
33
+	}
34 34
 
35 35
 
36
-    /**
37
-     * Gets a translated string name for the data eraser
38
-     *
39
-     * @return string
40
-     */
41
-    public function name()
42
-    {
43
-        return esc_html__('Event Espresso Attendee Data', 'event_espresso');
44
-    }
36
+	/**
37
+	 * Gets a translated string name for the data eraser
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function name()
42
+	{
43
+		return esc_html__('Event Espresso Attendee Data', 'event_espresso');
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * Erases a "page" of personal user data
49
-     *
50
-     * @return array {
51
-     * @type boolean $items_removed  whether items were removed successfully or not
52
-     * @type boolean $items_retained whether any items were skipped or not
53
-     * @type array   $messages       values are messages to show
54
-     * @type boolean $done           whether this eraser is done or has more pages
55
-     *               }
56
-     * @throws \EE_Error
57
-     */
58
-    public function erase($email_address, $page = 1)
59
-    {
60
-        $rows_updated = $this->attendee_model->update(
61
-            array(
62
-                'ATT_fname'    => esc_html__('Anonymous', 'event_espresso'),
63
-                'ATT_lname'    => '',
64
-                'ATT_email'    => '',
65
-                'ATT_address'  => '',
66
-                'ATT_address2' => '',
67
-                'ATT_city'     => '',
68
-                'STA_ID'       => 0,
69
-                'CNT_ISO'      => '',
70
-                'ATT_zip'      => '',
71
-                'ATT_phone'    => '',
72
-            ),
73
-            array(
74
-                array(
75
-                    'ATT_email' => $email_address,
76
-                ),
77
-            )
78
-        );
47
+	/**
48
+	 * Erases a "page" of personal user data
49
+	 *
50
+	 * @return array {
51
+	 * @type boolean $items_removed  whether items were removed successfully or not
52
+	 * @type boolean $items_retained whether any items were skipped or not
53
+	 * @type array   $messages       values are messages to show
54
+	 * @type boolean $done           whether this eraser is done or has more pages
55
+	 *               }
56
+	 * @throws \EE_Error
57
+	 */
58
+	public function erase($email_address, $page = 1)
59
+	{
60
+		$rows_updated = $this->attendee_model->update(
61
+			array(
62
+				'ATT_fname'    => esc_html__('Anonymous', 'event_espresso'),
63
+				'ATT_lname'    => '',
64
+				'ATT_email'    => '',
65
+				'ATT_address'  => '',
66
+				'ATT_address2' => '',
67
+				'ATT_city'     => '',
68
+				'STA_ID'       => 0,
69
+				'CNT_ISO'      => '',
70
+				'ATT_zip'      => '',
71
+				'ATT_phone'    => '',
72
+			),
73
+			array(
74
+				array(
75
+					'ATT_email' => $email_address,
76
+				),
77
+			)
78
+		);
79 79
 
80
-        return array(
81
-            'items_removed'  => (bool) $rows_updated,
82
-            'items_retained' => false, // always false in this example
83
-            'messages'       => array(),
84
-            'done'           => true,
85
-        );
86
-    }
80
+		return array(
81
+			'items_removed'  => (bool) $rows_updated,
82
+			'items_retained' => false, // always false in this example
83
+			'messages'       => array(),
84
+			'done'           => true,
85
+		);
86
+	}
87 87
 }
88 88
 // End of file EraseAttendeeData.php
89 89
 // Location: EventEspresso\core\domain\services\privacy\erasure/EraseAttendeeData.php
Please login to merge, or discard this patch.
templates/reg_admin_details_main_meta_box_reg_questions.template.php 3 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,12 +23,15 @@
 block discarded – undo
23 23
             <input id="reg-admin-attendee-questions-submit" class="button-primary" value="Update Registration Questions"
24 24
                    type="submit"/>
25 25
             <?php endif; ?>
26
-        <?php else : ?>
26
+        <?php else {
27
+	: ?>
27 28
             <p class="ee-attention">
28 29
                 <?php _e(
29 30
                     'There were no custom questions asked for this registration.',
30 31
                     'event_espresso'
31
-                ); ?></p>
32
+                );
33
+}
34
+?></p>
32 35
         <?php endif; ?>
33 36
 
34 37
     </form>
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <div id="admin-primary-mbox-questions-dv" class="admin-primary-mbox-dv">
2 2
     <p>
3 3
         <?php _e(
4
-            'This displays the custom questions and answers for this registrant.  Please note that any answers to system questions have been saved with the contact record.  You can edit those answers via the "View/Edit this Contact" link in the Contact Details metabox in the sidebar.',
5
-            'event_espresso'
6
-        ); ?></p>
4
+			'This displays the custom questions and answers for this registrant.  Please note that any answers to system questions have been saved with the contact record.  You can edit those answers via the "View/Edit this Contact" link in the Contact Details metabox in the sidebar.',
5
+			'event_espresso'
6
+		); ?></p>
7 7
 
8 8
     <form name="reg-admin-attendee-questions-frm" id="reg-admin-attendee-questions-frm"
9 9
           action="<?php echo REG_ADMIN_URL; ?>" method="post">
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
16 16
         <?php echo $att_questions; ?>
17 17
         <?php if (! empty($att_questions)) : ?>
18 18
             <?php if (
19
-            EE_Registry::instance()->CAP->current_user_can(
20
-                'ee_edit_registration',
21
-                'edit-reg-questions-mbox',
22
-                $REG_ID
23
-            )
19
+			EE_Registry::instance()->CAP->current_user_can(
20
+				'ee_edit_registration',
21
+				'edit-reg-questions-mbox',
22
+				$REG_ID
23
+			)
24 24
 ) : ?>
25 25
             <input id="reg-admin-attendee-questions-submit" class="button-primary" value="Update Registration Questions"
26 26
                    type="submit"/>
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
         <?php else : ?>
29 29
             <p class="ee-attention">
30 30
                 <?php _e(
31
-                    'There were no custom questions asked for this registration.',
32
-                    'event_espresso'
33
-                ); ?></p>
31
+					'There were no custom questions asked for this registration.',
32
+					'event_espresso'
33
+				); ?></p>
34 34
         <?php endif; ?>
35 35
 
36 36
     </form>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 
8 8
     <form name="reg-admin-attendee-questions-frm" id="reg-admin-attendee-questions-frm"
9 9
           action="<?php echo REG_ADMIN_URL; ?>" method="post">
10
-        <?php wp_nonce_field($reg_questions_form_action . '_nonce', $reg_questions_form_action . '_nonce'); ?>
10
+        <?php wp_nonce_field($reg_questions_form_action.'_nonce', $reg_questions_form_action.'_nonce'); ?>
11 11
         <input type="hidden" name="page" value="<?php echo REG_PG_SLUG; ?>"/>
12 12
         <input type="hidden" name="action" value="<?php echo $reg_questions_form_action; ?>"/>
13 13
         <input type="hidden" name="_REG_ID" value="<?php echo $REG_ID; ?>"/>
14 14
         <input type="hidden" name="espresso_ajax" id="espresso-ajax" value="0"/>
15 15
         <input type="hidden" name="noheader" id="reg-admin-noheader-inp" value="true"/>
16 16
         <?php echo $att_questions; ?>
17
-        <?php if (! empty($att_questions)) : ?>
17
+        <?php if ( ! empty($att_questions)) : ?>
18 18
             <?php if (
19 19
             EE_Registry::instance()->CAP->current_user_can(
20 20
                 'ee_edit_registration',
Please login to merge, or discard this patch.
core/domain/entities/editor/BlockInterface.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -22,70 +22,70 @@
 block discarded – undo
22 22
 interface BlockInterface
23 23
 {
24 24
 
25
-    const NAME_SPACE = 'eventespresso';
26
-
27
-    /**
28
-     * Perform any early setup required by the block
29
-     * including setting the block type and supported post types
30
-     *
31
-     * @return void
32
-     */
33
-    public function initialize();
34
-
35
-
36
-    /**
37
-     * @return string
38
-     */
39
-    public function blockType();
40
-
41
-
42
-    /**
43
-     * AssetRegister that this editor block uses for asset registration
44
-     *
45
-     * @return BlockAssetManagerInterface
46
-     */
47
-    public function assetManager();
48
-
49
-
50
-    /**
51
-     * Registers the Editor Block with WP core;
52
-     * Returns the registered block type on success, or false on failure.
53
-     *
54
-     * @return WP_Block_Type|false
55
-     */
56
-    public function registerBlock();
57
-
58
-
59
-    /**
60
-     * Un-registers the Editor Block with WP core;
61
-     * Returns the registered block type on success, or false on failure.
62
-     *
63
-     * @return WP_Block_Type|false
64
-     */
65
-    public function unRegisterBlock();
66
-
67
-
68
-    /**
69
-     * returns an array of fully qualified class names
70
-     * for RouteMatchSpecificationInterface objects
71
-     * that specify routes that the block should be loaded for.
72
-     *
73
-     * @return array
74
-     */
75
-    public function supportedRoutes();
76
-
77
-
78
-    /**
79
-     * @return array
80
-     */
81
-    public function getEditorContainer();
82
-
83
-
84
-    /**
85
-     * returns the rendered HTML for the block
86
-     *
87
-     * @param array $attributes
88
-     * @return string
89
-     */
90
-    public function renderBlock(array $attributes = array());
25
+	const NAME_SPACE = 'eventespresso';
26
+
27
+	/**
28
+	 * Perform any early setup required by the block
29
+	 * including setting the block type and supported post types
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function initialize();
34
+
35
+
36
+	/**
37
+	 * @return string
38
+	 */
39
+	public function blockType();
40
+
41
+
42
+	/**
43
+	 * AssetRegister that this editor block uses for asset registration
44
+	 *
45
+	 * @return BlockAssetManagerInterface
46
+	 */
47
+	public function assetManager();
48
+
49
+
50
+	/**
51
+	 * Registers the Editor Block with WP core;
52
+	 * Returns the registered block type on success, or false on failure.
53
+	 *
54
+	 * @return WP_Block_Type|false
55
+	 */
56
+	public function registerBlock();
57
+
58
+
59
+	/**
60
+	 * Un-registers the Editor Block with WP core;
61
+	 * Returns the registered block type on success, or false on failure.
62
+	 *
63
+	 * @return WP_Block_Type|false
64
+	 */
65
+	public function unRegisterBlock();
66
+
67
+
68
+	/**
69
+	 * returns an array of fully qualified class names
70
+	 * for RouteMatchSpecificationInterface objects
71
+	 * that specify routes that the block should be loaded for.
72
+	 *
73
+	 * @return array
74
+	 */
75
+	public function supportedRoutes();
76
+
77
+
78
+	/**
79
+	 * @return array
80
+	 */
81
+	public function getEditorContainer();
82
+
83
+
84
+	/**
85
+	 * returns the rendered HTML for the block
86
+	 *
87
+	 * @param array $attributes
88
+	 * @return string
89
+	 */
90
+	public function renderBlock(array $attributes = array());
91 91
 }
Please login to merge, or discard this patch.
core/services/editor/BlockManager.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
 abstract class BlockManager
19 19
 {
20 20
 
21
-    /**
22
-     * @var CollectionInterface|BlockInterface[] $blocks
23
-     */
24
-    protected $blocks;
25
-
26
-    /**
27
-     * @var RequestInterface $request
28
-     */
29
-    protected $request;
30
-
31
-
32
-
33
-    /**
34
-     * BlockManager constructor.
35
-     *
36
-     * @param BlockCollection   $blocks
37
-     * @param RequestInterface  $request
38
-     */
39
-    public function __construct(
40
-        BlockCollection $blocks,
41
-        RequestInterface $request
42
-    ) {
43
-        $this->blocks            = $blocks;
44
-        $this->request           = $request;
45
-        add_action($this->initHook(), array($this, 'initialize'));
46
-    }
47
-
48
-
49
-    /**
50
-     *  Returns the name of a hookpoint to be used to call initialize()
51
-     *
52
-     * @return string
53
-     */
54
-    abstract public function initHook();
55
-
56
-
57
-    /**
58
-     * Perform any early setup required for block editors to functions
59
-     *
60
-     * @return void
61
-     */
62
-    abstract public function initialize();
21
+	/**
22
+	 * @var CollectionInterface|BlockInterface[] $blocks
23
+	 */
24
+	protected $blocks;
25
+
26
+	/**
27
+	 * @var RequestInterface $request
28
+	 */
29
+	protected $request;
30
+
31
+
32
+
33
+	/**
34
+	 * BlockManager constructor.
35
+	 *
36
+	 * @param BlockCollection   $blocks
37
+	 * @param RequestInterface  $request
38
+	 */
39
+	public function __construct(
40
+		BlockCollection $blocks,
41
+		RequestInterface $request
42
+	) {
43
+		$this->blocks            = $blocks;
44
+		$this->request           = $request;
45
+		add_action($this->initHook(), array($this, 'initialize'));
46
+	}
47
+
48
+
49
+	/**
50
+	 *  Returns the name of a hookpoint to be used to call initialize()
51
+	 *
52
+	 * @return string
53
+	 */
54
+	abstract public function initHook();
55
+
56
+
57
+	/**
58
+	 * Perform any early setup required for block editors to functions
59
+	 *
60
+	 * @return void
61
+	 */
62
+	abstract public function initialize();
63 63
 }
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
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
-                            __(
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
+							__(
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.
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.
core/services/collections/CollectionLoaderException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 block discarded – undo
16 16
 class CollectionLoaderException extends RuntimeException
17 17
 {
18 18
 
19
-    /**
20
-     * DuplicateCollectionIdentifierException constructor.
21
-     *
22
-     * @param Exception $previous
23
-     * @param string    $message
24
-     * @param int       $code
25
-     */
26
-    public function __construct(Exception $previous, $message = '', $code = 0)
27
-    {
28
-        if (empty($message)) {
29
-            $message = sprintf(
30
-                __(
31
-                    'The following error occurred during the creation and/or loading of this collection: %1$s %2$s',
32
-                    'event_espresso'
33
-                ),
34
-                '<br />',
35
-                $previous->getMessage()
36
-            );
37
-        }
38
-        parent::__construct($message, $code, $previous);
39
-    }
19
+	/**
20
+	 * DuplicateCollectionIdentifierException constructor.
21
+	 *
22
+	 * @param Exception $previous
23
+	 * @param string    $message
24
+	 * @param int       $code
25
+	 */
26
+	public function __construct(Exception $previous, $message = '', $code = 0)
27
+	{
28
+		if (empty($message)) {
29
+			$message = sprintf(
30
+				__(
31
+					'The following error occurred during the creation and/or loading of this collection: %1$s %2$s',
32
+					'event_espresso'
33
+				),
34
+				'<br />',
35
+				$previous->getMessage()
36
+			);
37
+		}
38
+		parent::__construct($message, $code, $previous);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionDetailsException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 block discarded – undo
16 16
 class CollectionDetailsException extends RuntimeException
17 17
 {
18 18
 
19
-    /**
20
-     * DuplicateCollectionIdentifierException constructor.
21
-     *
22
-     * @param Exception $previous
23
-     * @param string    $message
24
-     * @param int       $code
25
-     */
26
-    public function __construct(Exception $previous, $message = '', $code = 0)
27
-    {
28
-        if (empty($message)) {
29
-            $message = sprintf(
30
-                __(
31
-                    'The following error occurred during the collection details generation: %1$s %2$s',
32
-                    'event_espresso'
33
-                ),
34
-                '<br />',
35
-                $previous->getMessage()
36
-            );
37
-        }
38
-        parent::__construct($message, $code, $previous);
39
-    }
19
+	/**
20
+	 * DuplicateCollectionIdentifierException constructor.
21
+	 *
22
+	 * @param Exception $previous
23
+	 * @param string    $message
24
+	 * @param int       $code
25
+	 */
26
+	public function __construct(Exception $previous, $message = '', $code = 0)
27
+	{
28
+		if (empty($message)) {
29
+			$message = sprintf(
30
+				__(
31
+					'The following error occurred during the collection details generation: %1$s %2$s',
32
+					'event_espresso'
33
+				),
34
+				'<br />',
35
+				$previous->getMessage()
36
+			);
37
+		}
38
+		parent::__construct($message, $code, $previous);
39
+	}
40 40
 }
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.