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