Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/libraries/plugin_api/EE_Register_Personal_Data_Exporter.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$exporters[ $identifier ] = $setup_args;
31
+        self::$exporters[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$exporters[ $identifier ]);
45
+        unset(self::$exporters[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $exporters = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $exporters = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$exporters[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
-            ['EE_Register_Personal_Data_Exporter', 'addExporters']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$exporters[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
+			['EE_Register_Personal_Data_Exporter', 'addExporters']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$exporters[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$exporters[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data exporters registered by add-ons
50
-     *
51
-     * @param string[] $exporters
52
-     * @return string[]
53
-     */
54
-    public static function addExporters(array $exporters)
55
-    {
56
-        foreach (self::$exporters as $exporters_per_addon) {
57
-            $exporters = array_merge(
58
-                $exporters,
59
-                $exporters_per_addon
60
-            );
61
-        }
62
-        return $exporters;
63
-    }
48
+	/**
49
+	 * Adds our personal data exporters registered by add-ons
50
+	 *
51
+	 * @param string[] $exporters
52
+	 * @return string[]
53
+	 */
54
+	public static function addExporters(array $exporters)
55
+	{
56
+		foreach (self::$exporters as $exporters_per_addon) {
57
+			$exporters = array_merge(
58
+				$exporters,
59
+				$exporters_per_addon
60
+			);
61
+		}
62
+		return $exporters;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Exporter.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Personal_Data_Eraser.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$erasers[ $identifier ] = $setup_args;
31
+        self::$erasers[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$erasers[ $identifier ]);
45
+        unset(self::$erasers[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $erasers = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $erasers = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$erasers[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
-            ['EE_Register_Personal_Data_Eraser', 'addErasers']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$erasers[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
+			['EE_Register_Personal_Data_Eraser', 'addErasers']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$erasers[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$erasers[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data erasers registered by add-ons
50
-     *
51
-     * @param string[] $erasers
52
-     * @return string[]
53
-     */
54
-    public static function addErasers(array $erasers)
55
-    {
56
-        foreach (self::$erasers as $erasers_per_addon) {
57
-            $erasers = array_merge(
58
-                $erasers,
59
-                $erasers_per_addon
60
-            );
61
-        }
62
-        return $erasers;
63
-    }
48
+	/**
49
+	 * Adds our personal data erasers registered by add-ons
50
+	 *
51
+	 * @param string[] $erasers
52
+	 * @return string[]
53
+	 */
54
+	public static function addErasers(array $erasers)
55
+	{
56
+		foreach (self::$erasers as $erasers_per_addon) {
57
+			$erasers = array_merge(
58
+				$erasers,
59
+				$erasers_per_addon
60
+			);
61
+		}
62
+		return $erasers;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Eraser.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Privacy_Policy.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$privacy_policies[ $identifier ] = $setup_args;
31
+        self::$privacy_policies[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$privacy_policies[ $identifier ]);
45
+        unset(self::$privacy_policies[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Privacy_Policy implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $privacy_policies = array();
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $privacy_policies = array();
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *              OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$privacy_policies[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
34
-            array('EE_Register_Privacy_Policy', 'addPrivacyPolicies')
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *              OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$privacy_policies[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
34
+			array('EE_Register_Privacy_Policy', 'addPrivacyPolicies')
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$privacy_policies[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$privacy_policies[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our privacy policy generators registered by add-ons
50
-     *
51
-     * @param string[] $privacy_policies
52
-     * @return string[]
53
-     */
54
-    public static function addPrivacyPolicies(array $privacy_policies)
55
-    {
56
-        foreach (self::$privacy_policies as $privacy_policies_per_addon) {
57
-            $privacy_policies = array_merge(
58
-                $privacy_policies,
59
-                $privacy_policies_per_addon
60
-            );
61
-        }
62
-        return $privacy_policies;
63
-    }
48
+	/**
49
+	 * Adds our privacy policy generators registered by add-ons
50
+	 *
51
+	 * @param string[] $privacy_policies
52
+	 * @return string[]
53
+	 */
54
+	public static function addPrivacyPolicies(array $privacy_policies)
55
+	{
56
+		foreach (self::$privacy_policies as $privacy_policies_per_addon) {
57
+			$privacy_policies = array_merge(
58
+				$privacy_policies,
59
+				$privacy_policies_per_addon
60
+			);
61
+		}
62
+		return $privacy_policies;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Privacy_Policy.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Privacy_Policy.lib.php
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStepManager.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
         $this->setDisplayStrategy($display_strategy_name);
76 76
         $this->setDefaultStep($default_step);
77 77
         $this->setFormStepUrlKey($form_step_url_key);
78
-        if (! $collection instanceof CollectionInterface) {
78
+        if ( ! $collection instanceof CollectionInterface) {
79 79
             $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
80 80
         }
81 81
         $this->collection = $collection;
82
-        if (! $request instanceof RequestInterface) {
82
+        if ( ! $request instanceof RequestInterface) {
83 83
             /** @var RequestInterface $request */
84 84
             $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
85 85
         }
@@ -94,23 +94,23 @@  discard block
 block discarded – undo
94 94
      */
95 95
     protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
96 96
     {
97
-        if (! is_string($display_strategy_name)) {
97
+        if ( ! is_string($display_strategy_name)) {
98 98
             throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
99 99
         }
100 100
         // build up FQCN from incoming display strategy folder name
101 101
         $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
102
-        $display_strategy_class .= $display_strategy_name . '\\';
102
+        $display_strategy_class .= $display_strategy_name.'\\';
103 103
         $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
104 104
         $display_strategy_class .= 'ProgressStepsDisplay';
105 105
         $display_strategy_class = apply_filters(
106 106
             'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
107 107
             $display_strategy_class
108 108
         );
109
-        if (! class_exists($display_strategy_class)) {
109
+        if ( ! class_exists($display_strategy_class)) {
110 110
             throw new InvalidClassException($display_strategy_class);
111 111
         }
112 112
         $display_strategy = new $display_strategy_class();
113
-        if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
113
+        if ( ! $display_strategy instanceof ProgressStepsDisplayInterface) {
114 114
             throw new InvalidClassException(
115 115
                 $display_strategy_class,
116 116
                 sprintf(
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function setDefaultStep($default_step)
132 132
     {
133
-        if (! is_string($default_step)) {
133
+        if ( ! is_string($default_step)) {
134 134
             throw new InvalidDataTypeException('$default_step', $default_step, 'string');
135 135
         }
136 136
         $this->default_step = $default_step;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
145 145
     {
146
-        if (! is_string($form_step_url_key)) {
146
+        if ( ! is_string($form_step_url_key)) {
147 147
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
148 148
         }
149 149
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         // grab the step previously known as current, in case we need to revert
164 164
         $current_current_step = $this->collection->current();
165 165
         // verify that requested step exists
166
-        if (! $this->collection->has($step)) {
166
+        if ( ! $this->collection->has($step)) {
167 167
             throw new InvalidIdentifierException($step, $this->default_step);
168 168
         }
169 169
         if ($this->collection->setCurrent($step)) {
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -26,225 +26,225 @@
 block discarded – undo
26 26
  */
27 27
 class ProgressStepManager
28 28
 {
29
-    /**
30
-     * @var ProgressStepInterface[]
31
-     */
32
-    private $collection;
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    private $default_step;
38
-
39
-    /**
40
-     * the key used for the URL param that denotes the current form step
41
-     * defaults to 'ee-form-step'
42
-     *
43
-     * @var string
44
-     */
45
-    private $form_step_url_key = '';
46
-
47
-    /**
48
-     * @var ProgressStepsDisplayInterface
49
-     */
50
-    private $display_strategy;
51
-
52
-    /**
53
-     * @var RequestInterface
54
-     */
55
-    private $request;
56
-
57
-
58
-    /**
59
-     * ProgressStepManager constructor
60
-     *
61
-     * @param string              $display_strategy_name
62
-     * @param string              $default_step
63
-     * @param string              $form_step_url_key
64
-     * @param CollectionInterface $collection
65
-     * @param RequestInterface    $request
66
-     */
67
-    public function __construct(
68
-        $display_strategy_name = 'number_bubbles',
69
-        $default_step = '',
70
-        $form_step_url_key = '',
71
-        CollectionInterface $collection = null,
72
-        RequestInterface $request = null
73
-    ) {
74
-        $this->setDisplayStrategy($display_strategy_name);
75
-        $this->setDefaultStep($default_step);
76
-        $this->setFormStepUrlKey($form_step_url_key);
77
-        if (! $collection instanceof CollectionInterface) {
78
-            $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
79
-        }
80
-        $this->collection = $collection;
81
-        if (! $request instanceof RequestInterface) {
82
-            /** @var RequestInterface $request */
83
-            $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
84
-        }
85
-        $this->request = $request;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string $display_strategy_name
91
-     * @throws InvalidDataTypeException
92
-     * @throws InvalidClassException
93
-     */
94
-    protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
95
-    {
96
-        if (! is_string($display_strategy_name)) {
97
-            throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
98
-        }
99
-        // build up FQCN from incoming display strategy folder name
100
-        $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
101
-        $display_strategy_class .= $display_strategy_name . '\\';
102
-        $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
103
-        $display_strategy_class .= 'ProgressStepsDisplay';
104
-        $display_strategy_class = apply_filters(
105
-            'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
106
-            $display_strategy_class
107
-        );
108
-        if (! class_exists($display_strategy_class)) {
109
-            throw new InvalidClassException($display_strategy_class);
110
-        }
111
-        $display_strategy = new $display_strategy_class();
112
-        if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
113
-            throw new InvalidClassException(
114
-                $display_strategy_class,
115
-                sprintf(
116
-                    esc_html__('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'),
117
-                    $display_strategy_class,
118
-                    '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface'
119
-                )
120
-            );
121
-        }
122
-        $this->display_strategy = $display_strategy;
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $default_step
128
-     * @throws InvalidDataTypeException
129
-     */
130
-    public function setDefaultStep($default_step)
131
-    {
132
-        if (! is_string($default_step)) {
133
-            throw new InvalidDataTypeException('$default_step', $default_step, 'string');
134
-        }
135
-        $this->default_step = $default_step;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param string $form_step_url_key
141
-     * @throws InvalidDataTypeException
142
-     */
143
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
144
-    {
145
-        if (! is_string($form_step_url_key)) {
146
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
147
-        }
148
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
149
-    }
150
-
151
-
152
-    /**
153
-     * @param string $step
154
-     * @throws InvalidIdentifierException
155
-     */
156
-    public function setCurrentStep($step = '')
157
-    {
158
-        // use incoming value if it's set, otherwise use request param if it's set, otherwise use default
159
-        $step = ! empty($step)
160
-            ? $step
161
-            : $this->request->getRequestParam($this->form_step_url_key, $this->default_step);
162
-        // grab the step previously known as current, in case we need to revert
163
-        $current_current_step = $this->collection->current();
164
-        // verify that requested step exists
165
-        if (! $this->collection->has($step)) {
166
-            throw new InvalidIdentifierException($step, $this->default_step);
167
-        }
168
-        if ($this->collection->setCurrent($step)) {
169
-            // if the old boss is the same as the new boss, then nothing changes
170
-            if ($this->collection->current() !== $current_current_step) {
171
-                $current_current_step->setIsCurrent(false);
172
-            }
173
-            $this->collection->current()->setIsCurrent();
174
-        } else {
175
-            $this->collection->setCurrent($current_current_step->id());
176
-            $current_current_step->setIsCurrent(true);
177
-        }
178
-    }
179
-
180
-
181
-    /**
182
-     * setPreviousStepsCompleted
183
-     */
184
-    public function setPreviousStepsCompleted()
185
-    {
186
-        $current_current_step = $this->collection->current();
187
-        $this->collection->rewind();
188
-        while ($this->collection->valid()) {
189
-            if ($this->collection->current() === $current_current_step) {
190
-                break;
191
-            }
192
-            $this->setCurrentStepCompleted();
193
-            $this->collection->next();
194
-        }
195
-        $this->collection->setCurrentUsingObject($current_current_step);
196
-        return false;
197
-    }
198
-
199
-
200
-    /**
201
-     * @return ProgressStepInterface
202
-     */
203
-    public function currentStep()
204
-    {
205
-        return $this->collection->current();
206
-    }
207
-
208
-
209
-    /**
210
-     * @return ProgressStepInterface
211
-     */
212
-    public function nextStep()
213
-    {
214
-        return $this->collection->next();
215
-    }
216
-
217
-
218
-    /**
219
-     * @return void
220
-     */
221
-    public function enqueueStylesAndScripts()
222
-    {
223
-        $this->display_strategy->enqueueStylesAndScripts();
224
-    }
225
-
226
-
227
-    /**
228
-     * echos out HTML
229
-     *
230
-     * @return string
231
-     */
232
-    public function displaySteps()
233
-    {
234
-        return EEH_Template::display_template(
235
-            $this->display_strategy->getTemplate(),
236
-            array('progress_steps' => $this->collection),
237
-            true
238
-        );
239
-    }
240
-
241
-
242
-    /**
243
-     * @param bool $completed
244
-     * @return ProgressStepInterface
245
-     */
246
-    public function setCurrentStepCompleted($completed = true)
247
-    {
248
-        return $this->collection->current()->setIsCompleted($completed);
249
-    }
29
+	/**
30
+	 * @var ProgressStepInterface[]
31
+	 */
32
+	private $collection;
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private $default_step;
38
+
39
+	/**
40
+	 * the key used for the URL param that denotes the current form step
41
+	 * defaults to 'ee-form-step'
42
+	 *
43
+	 * @var string
44
+	 */
45
+	private $form_step_url_key = '';
46
+
47
+	/**
48
+	 * @var ProgressStepsDisplayInterface
49
+	 */
50
+	private $display_strategy;
51
+
52
+	/**
53
+	 * @var RequestInterface
54
+	 */
55
+	private $request;
56
+
57
+
58
+	/**
59
+	 * ProgressStepManager constructor
60
+	 *
61
+	 * @param string              $display_strategy_name
62
+	 * @param string              $default_step
63
+	 * @param string              $form_step_url_key
64
+	 * @param CollectionInterface $collection
65
+	 * @param RequestInterface    $request
66
+	 */
67
+	public function __construct(
68
+		$display_strategy_name = 'number_bubbles',
69
+		$default_step = '',
70
+		$form_step_url_key = '',
71
+		CollectionInterface $collection = null,
72
+		RequestInterface $request = null
73
+	) {
74
+		$this->setDisplayStrategy($display_strategy_name);
75
+		$this->setDefaultStep($default_step);
76
+		$this->setFormStepUrlKey($form_step_url_key);
77
+		if (! $collection instanceof CollectionInterface) {
78
+			$collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
79
+		}
80
+		$this->collection = $collection;
81
+		if (! $request instanceof RequestInterface) {
82
+			/** @var RequestInterface $request */
83
+			$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
84
+		}
85
+		$this->request = $request;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string $display_strategy_name
91
+	 * @throws InvalidDataTypeException
92
+	 * @throws InvalidClassException
93
+	 */
94
+	protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
95
+	{
96
+		if (! is_string($display_strategy_name)) {
97
+			throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
98
+		}
99
+		// build up FQCN from incoming display strategy folder name
100
+		$display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
101
+		$display_strategy_class .= $display_strategy_name . '\\';
102
+		$display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
103
+		$display_strategy_class .= 'ProgressStepsDisplay';
104
+		$display_strategy_class = apply_filters(
105
+			'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
106
+			$display_strategy_class
107
+		);
108
+		if (! class_exists($display_strategy_class)) {
109
+			throw new InvalidClassException($display_strategy_class);
110
+		}
111
+		$display_strategy = new $display_strategy_class();
112
+		if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
113
+			throw new InvalidClassException(
114
+				$display_strategy_class,
115
+				sprintf(
116
+					esc_html__('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'),
117
+					$display_strategy_class,
118
+					'\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface'
119
+				)
120
+			);
121
+		}
122
+		$this->display_strategy = $display_strategy;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $default_step
128
+	 * @throws InvalidDataTypeException
129
+	 */
130
+	public function setDefaultStep($default_step)
131
+	{
132
+		if (! is_string($default_step)) {
133
+			throw new InvalidDataTypeException('$default_step', $default_step, 'string');
134
+		}
135
+		$this->default_step = $default_step;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param string $form_step_url_key
141
+	 * @throws InvalidDataTypeException
142
+	 */
143
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
144
+	{
145
+		if (! is_string($form_step_url_key)) {
146
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
147
+		}
148
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param string $step
154
+	 * @throws InvalidIdentifierException
155
+	 */
156
+	public function setCurrentStep($step = '')
157
+	{
158
+		// use incoming value if it's set, otherwise use request param if it's set, otherwise use default
159
+		$step = ! empty($step)
160
+			? $step
161
+			: $this->request->getRequestParam($this->form_step_url_key, $this->default_step);
162
+		// grab the step previously known as current, in case we need to revert
163
+		$current_current_step = $this->collection->current();
164
+		// verify that requested step exists
165
+		if (! $this->collection->has($step)) {
166
+			throw new InvalidIdentifierException($step, $this->default_step);
167
+		}
168
+		if ($this->collection->setCurrent($step)) {
169
+			// if the old boss is the same as the new boss, then nothing changes
170
+			if ($this->collection->current() !== $current_current_step) {
171
+				$current_current_step->setIsCurrent(false);
172
+			}
173
+			$this->collection->current()->setIsCurrent();
174
+		} else {
175
+			$this->collection->setCurrent($current_current_step->id());
176
+			$current_current_step->setIsCurrent(true);
177
+		}
178
+	}
179
+
180
+
181
+	/**
182
+	 * setPreviousStepsCompleted
183
+	 */
184
+	public function setPreviousStepsCompleted()
185
+	{
186
+		$current_current_step = $this->collection->current();
187
+		$this->collection->rewind();
188
+		while ($this->collection->valid()) {
189
+			if ($this->collection->current() === $current_current_step) {
190
+				break;
191
+			}
192
+			$this->setCurrentStepCompleted();
193
+			$this->collection->next();
194
+		}
195
+		$this->collection->setCurrentUsingObject($current_current_step);
196
+		return false;
197
+	}
198
+
199
+
200
+	/**
201
+	 * @return ProgressStepInterface
202
+	 */
203
+	public function currentStep()
204
+	{
205
+		return $this->collection->current();
206
+	}
207
+
208
+
209
+	/**
210
+	 * @return ProgressStepInterface
211
+	 */
212
+	public function nextStep()
213
+	{
214
+		return $this->collection->next();
215
+	}
216
+
217
+
218
+	/**
219
+	 * @return void
220
+	 */
221
+	public function enqueueStylesAndScripts()
222
+	{
223
+		$this->display_strategy->enqueueStylesAndScripts();
224
+	}
225
+
226
+
227
+	/**
228
+	 * echos out HTML
229
+	 *
230
+	 * @return string
231
+	 */
232
+	public function displaySteps()
233
+	{
234
+		return EEH_Template::display_template(
235
+			$this->display_strategy->getTemplate(),
236
+			array('progress_steps' => $this->collection),
237
+			true
238
+		);
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param bool $completed
244
+	 * @return ProgressStepInterface
245
+	 */
246
+	public function setCurrentStepCompleted($completed = true)
247
+	{
248
+		return $this->collection->current()->setIsCompleted($completed);
249
+	}
250 250
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     protected function setBaseUrl($base_url)
142 142
     {
143
-        if (! is_string($base_url)) {
143
+        if ( ! is_string($base_url)) {
144 144
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
145 145
         }
146 146
         if (empty($base_url)) {
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
173 173
     {
174
-        if (! is_string($form_step_url_key)) {
174
+        if ( ! is_string($form_step_url_key)) {
175 175
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
176 176
         }
177 177
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     protected function setDefaultFormStep($default_form_step)
195 195
     {
196
-        if (! is_string($default_form_step)) {
196
+        if ( ! is_string($default_form_step)) {
197 197
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
198 198
         }
199 199
         $this->default_form_step = $default_form_step;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
     protected function setCurrentStepFromRequest()
209 209
     {
210 210
         $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep());
211
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
211
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
212 212
             throw new InvalidIdentifierException(
213 213
                 $current_step_slug,
214 214
                 $this->defaultFormStep(),
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public function getCurrentStep()
229 229
     {
230
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
230
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
231 231
             throw new InvalidFormHandlerException($this->form_steps->current());
232 232
         }
233 233
         return $this->form_steps->current();
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      */
241 241
     public function formAction()
242 242
     {
243
-        if (! is_string($this->form_action) || empty($this->form_action)) {
243
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
244 244
             $this->form_action = $this->baseUrl();
245 245
         }
246 246
         return $this->form_action;
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      */
254 254
     public function setFormAction($form_action)
255 255
     {
256
-        if (! is_string($form_action)) {
256
+        if ( ! is_string($form_action)) {
257 257
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
258 258
         }
259 259
         $this->form_action = $form_action;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public function addFormActionArgs($form_action_args = array())
269 269
     {
270
-        if (! is_array($form_action_args)) {
270
+        if ( ! is_array($form_action_args)) {
271 271
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
272 272
         }
273 273
         $form_action_args = ! empty($form_action_args)
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
     protected function getProgressStepsCollection()
333 333
     {
334 334
         static $collection = null;
335
-        if (! $collection instanceof ProgressStepCollection) {
335
+        if ( ! $collection instanceof ProgressStepCollection) {
336 336
             $collection = new ProgressStepCollection();
337 337
         }
338 338
         return $collection;
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
         /** @var SequentialStepForm $form_step */
355 355
         foreach ($this->form_steps as $form_step) {
356 356
             // is this step active ?
357
-            if (! $form_step->initialize()) {
357
+            if ( ! $form_step->initialize()) {
358 358
                 continue;
359 359
             }
360 360
             $progress_steps_collection->add(
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
     {
424 424
         $form_step = $this->buildCurrentStepForm();
425 425
         // no displayable content ? then skip straight to processing
426
-        if (! $form_step->displayable()) {
426
+        if ( ! $form_step->displayable()) {
427 427
             $this->addFormActionArgs();
428 428
             $form_step->setFormAction($this->formAction());
429 429
             wp_safe_redirect($form_step->formAction());
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
     public function displayProgressSteps($return_as_string = true)
500 500
     {
501 501
         $form_step = $this->getCurrentStep();
502
-        if (! $form_step->displayable()) {
502
+        if ( ! $form_step->displayable()) {
503 503
             return '';
504 504
         }
505 505
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
Indentation   +579 added lines, -579 removed lines patch added patch discarded remove patch
@@ -30,583 +30,583 @@
 block discarded – undo
30 30
  */
31 31
 abstract class SequentialStepFormManager
32 32
 {
33
-    /**
34
-     * a simplified URL with no form related parameters
35
-     * that will be used to build the form's redirect URLs
36
-     *
37
-     * @var string $base_url
38
-     */
39
-    private $base_url = '';
40
-
41
-    /**
42
-     * the key used for the URL param that denotes the current form step
43
-     * defaults to 'ee-form-step'
44
-     *
45
-     * @var string $form_step_url_key
46
-     */
47
-    private $form_step_url_key = '';
48
-
49
-    /**
50
-     * @var string $default_form_step
51
-     */
52
-    private $default_form_step = '';
53
-
54
-    /**
55
-     * @var string $form_action
56
-     */
57
-    private $form_action;
58
-
59
-    /**
60
-     * value of one of the string constant above
61
-     *
62
-     * @var string $form_config
63
-     */
64
-    private $form_config;
65
-
66
-    /**
67
-     * @var string $progress_step_style
68
-     */
69
-    private $progress_step_style = '';
70
-
71
-    /**
72
-     * @var RequestInterface $request
73
-     */
74
-    private $request;
75
-
76
-    /**
77
-     * @var Collection $form_steps
78
-     */
79
-    protected $form_steps;
80
-
81
-    /**
82
-     * @var ProgressStepManager $progress_step_manager
83
-     */
84
-    protected $progress_step_manager;
85
-
86
-
87
-    /**
88
-     * @return Collection|null
89
-     */
90
-    abstract protected function getFormStepsCollection();
91
-
92
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
93
-    /**
94
-     * StepsManager constructor
95
-     *
96
-     * @param string                           $base_url
97
-     * @param string                           $default_form_step
98
-     * @param string                           $form_action
99
-     * @param string                           $form_config
100
-     * @param EE_Request|RequestInterface|null $request
101
-     * @param string                           $progress_step_style
102
-     * @throws InvalidDataTypeException
103
-     * @throws InvalidArgumentException
104
-     */
105
-    public function __construct(
106
-        $base_url,
107
-        $default_form_step,
108
-        $form_action = '',
109
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
110
-        $progress_step_style = 'number_bubbles',
111
-        $request = null
112
-    ) {
113
-        $this->setBaseUrl($base_url);
114
-        $this->setDefaultFormStep($default_form_step);
115
-        $this->setFormAction($form_action);
116
-        $this->setFormConfig($form_config);
117
-        $this->setProgressStepStyle($progress_step_style);
118
-        $this->request = $request instanceof RequestInterface
119
-            ? $request
120
-            : LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
121
-    }
122
-
123
-
124
-    /**
125
-     * @return string
126
-     * @throws InvalidFormHandlerException
127
-     */
128
-    public function baseUrl()
129
-    {
130
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
131
-            add_query_arg(
132
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
133
-                $this->base_url
134
-            );
135
-        }
136
-        return $this->base_url;
137
-    }
138
-
139
-
140
-    /**
141
-     * @param string $base_url
142
-     * @throws InvalidDataTypeException
143
-     * @throws InvalidArgumentException
144
-     */
145
-    protected function setBaseUrl($base_url)
146
-    {
147
-        if (! is_string($base_url)) {
148
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
149
-        }
150
-        if (empty($base_url)) {
151
-            throw new InvalidArgumentException(
152
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
153
-            );
154
-        }
155
-        $this->base_url = $base_url;
156
-    }
157
-
158
-
159
-    /**
160
-     * @return string
161
-     * @throws InvalidDataTypeException
162
-     */
163
-    public function formStepUrlKey()
164
-    {
165
-        if (empty($this->form_step_url_key)) {
166
-            $this->setFormStepUrlKey();
167
-        }
168
-        return $this->form_step_url_key;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $form_step_url_key
174
-     * @throws InvalidDataTypeException
175
-     */
176
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
177
-    {
178
-        if (! is_string($form_step_url_key)) {
179
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
180
-        }
181
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
182
-    }
183
-
184
-
185
-    /**
186
-     * @return string
187
-     */
188
-    public function defaultFormStep()
189
-    {
190
-        return $this->default_form_step;
191
-    }
192
-
193
-
194
-    /**
195
-     * @param $default_form_step
196
-     * @throws InvalidDataTypeException
197
-     */
198
-    protected function setDefaultFormStep($default_form_step)
199
-    {
200
-        if (! is_string($default_form_step)) {
201
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
202
-        }
203
-        $this->default_form_step = $default_form_step;
204
-    }
205
-
206
-
207
-    /**
208
-     * @return void
209
-     * @throws InvalidIdentifierException
210
-     * @throws InvalidDataTypeException
211
-     */
212
-    protected function setCurrentStepFromRequest()
213
-    {
214
-        $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep());
215
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
216
-            throw new InvalidIdentifierException(
217
-                $current_step_slug,
218
-                $this->defaultFormStep(),
219
-                sprintf(
220
-                    esc_html__('The "%1$s" form step could not be set.', 'event_espresso'),
221
-                    $current_step_slug
222
-                )
223
-            );
224
-        }
225
-    }
226
-
227
-
228
-    /**
229
-     * @return SequentialStepFormInterface|object
230
-     * @throws InvalidFormHandlerException
231
-     */
232
-    public function getCurrentStep()
233
-    {
234
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
235
-            throw new InvalidFormHandlerException($this->form_steps->current());
236
-        }
237
-        return $this->form_steps->current();
238
-    }
239
-
240
-
241
-    /**
242
-     * @return string
243
-     * @throws InvalidFormHandlerException
244
-     */
245
-    public function formAction()
246
-    {
247
-        if (! is_string($this->form_action) || empty($this->form_action)) {
248
-            $this->form_action = $this->baseUrl();
249
-        }
250
-        return $this->form_action;
251
-    }
252
-
253
-
254
-    /**
255
-     * @param string $form_action
256
-     * @throws InvalidDataTypeException
257
-     */
258
-    public function setFormAction($form_action)
259
-    {
260
-        if (! is_string($form_action)) {
261
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262
-        }
263
-        $this->form_action = $form_action;
264
-    }
265
-
266
-
267
-    /**
268
-     * @param array $form_action_args
269
-     * @throws InvalidDataTypeException
270
-     * @throws InvalidFormHandlerException
271
-     */
272
-    public function addFormActionArgs($form_action_args = array())
273
-    {
274
-        if (! is_array($form_action_args)) {
275
-            throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276
-        }
277
-        $form_action_args = ! empty($form_action_args)
278
-            ? $form_action_args
279
-            : array($this->formStepUrlKey() => $this->form_steps->current()->slug());
280
-        $this->getCurrentStep()->setFormAction(
281
-            add_query_arg($form_action_args, $this->formAction())
282
-        );
283
-        $this->form_action = $this->getCurrentStep()->formAction();
284
-    }
285
-
286
-
287
-    /**
288
-     * @return string
289
-     */
290
-    public function formConfig()
291
-    {
292
-        return $this->form_config;
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $form_config
298
-     */
299
-    public function setFormConfig($form_config)
300
-    {
301
-        $this->form_config = $form_config;
302
-    }
303
-
304
-
305
-    /**
306
-     * @return string
307
-     */
308
-    public function progressStepStyle()
309
-    {
310
-        return $this->progress_step_style;
311
-    }
312
-
313
-
314
-    /**
315
-     * @param string $progress_step_style
316
-     */
317
-    public function setProgressStepStyle($progress_step_style)
318
-    {
319
-        $this->progress_step_style = $progress_step_style;
320
-    }
321
-
322
-
323
-    /**
324
-     * @return RequestInterface
325
-     */
326
-    public function request()
327
-    {
328
-        return $this->request;
329
-    }
330
-
331
-
332
-    /**
333
-     * @return Collection|null
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    protected function getProgressStepsCollection()
337
-    {
338
-        static $collection = null;
339
-        if (! $collection instanceof ProgressStepCollection) {
340
-            $collection = new ProgressStepCollection();
341
-        }
342
-        return $collection;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param Collection $progress_steps_collection
348
-     * @return ProgressStepManager
349
-     * @throws InvalidInterfaceException
350
-     * @throws InvalidClassException
351
-     * @throws InvalidDataTypeException
352
-     * @throws InvalidEntityException
353
-     * @throws InvalidFormHandlerException
354
-     */
355
-    protected function generateProgressSteps(Collection $progress_steps_collection)
356
-    {
357
-        $current_step = $this->getCurrentStep();
358
-        /** @var SequentialStepForm $form_step */
359
-        foreach ($this->form_steps as $form_step) {
360
-            // is this step active ?
361
-            if (! $form_step->initialize()) {
362
-                continue;
363
-            }
364
-            $progress_steps_collection->add(
365
-                new ProgressStep(
366
-                    $form_step->order(),
367
-                    $form_step->slug(),
368
-                    $form_step->slug(),
369
-                    $form_step->formName()
370
-                ),
371
-                $form_step->slug()
372
-            );
373
-        }
374
-        // set collection pointer back to current step
375
-        $this->form_steps->setCurrentUsingObject($current_step);
376
-        return new ProgressStepManager(
377
-            $this->progressStepStyle(),
378
-            $this->defaultFormStep(),
379
-            $this->formStepUrlKey(),
380
-            $progress_steps_collection
381
-        );
382
-    }
383
-
384
-
385
-    /**
386
-     * @throws InvalidClassException
387
-     * @throws InvalidDataTypeException
388
-     * @throws InvalidEntityException
389
-     * @throws InvalidIdentifierException
390
-     * @throws InvalidInterfaceException
391
-     * @throws InvalidArgumentException
392
-     * @throws InvalidFormHandlerException
393
-     */
394
-    public function buildForm()
395
-    {
396
-        $this->buildCurrentStepFormForDisplay();
397
-    }
398
-
399
-
400
-    /**
401
-     * @param array $form_data
402
-     * @throws InvalidArgumentException
403
-     * @throws InvalidClassException
404
-     * @throws InvalidDataTypeException
405
-     * @throws InvalidEntityException
406
-     * @throws InvalidFormHandlerException
407
-     * @throws InvalidIdentifierException
408
-     * @throws InvalidInterfaceException
409
-     */
410
-    public function processForm($form_data = array())
411
-    {
412
-        $this->buildCurrentStepFormForProcessing();
413
-        $this->processCurrentStepForm($form_data);
414
-    }
415
-
416
-
417
-    /**
418
-     * @throws InvalidClassException
419
-     * @throws InvalidDataTypeException
420
-     * @throws InvalidEntityException
421
-     * @throws InvalidInterfaceException
422
-     * @throws InvalidIdentifierException
423
-     * @throws InvalidArgumentException
424
-     * @throws InvalidFormHandlerException
425
-     */
426
-    public function buildCurrentStepFormForDisplay()
427
-    {
428
-        $form_step = $this->buildCurrentStepForm();
429
-        // no displayable content ? then skip straight to processing
430
-        if (! $form_step->displayable()) {
431
-            $this->addFormActionArgs();
432
-            $form_step->setFormAction($this->formAction());
433
-            wp_safe_redirect($form_step->formAction());
434
-        }
435
-    }
436
-
437
-
438
-    /**
439
-     * @throws InvalidClassException
440
-     * @throws InvalidDataTypeException
441
-     * @throws InvalidEntityException
442
-     * @throws InvalidInterfaceException
443
-     * @throws InvalidIdentifierException
444
-     * @throws InvalidArgumentException
445
-     * @throws InvalidFormHandlerException
446
-     */
447
-    public function buildCurrentStepFormForProcessing()
448
-    {
449
-        $this->buildCurrentStepForm(false);
450
-    }
451
-
452
-
453
-    /**
454
-     * @param bool $for_display
455
-     * @return SequentialStepFormInterface
456
-     * @throws InvalidArgumentException
457
-     * @throws InvalidClassException
458
-     * @throws InvalidDataTypeException
459
-     * @throws InvalidEntityException
460
-     * @throws InvalidFormHandlerException
461
-     * @throws InvalidIdentifierException
462
-     * @throws InvalidInterfaceException
463
-     */
464
-    private function buildCurrentStepForm($for_display = true)
465
-    {
466
-        $this->form_steps = $this->getFormStepsCollection();
467
-        $this->setCurrentStepFromRequest();
468
-        $form_step = $this->getCurrentStep();
469
-        if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
470
-            $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
471
-        }
472
-        if ($for_display && $form_step->displayable()) {
473
-            $this->progress_step_manager = $this->generateProgressSteps(
474
-                $this->getProgressStepsCollection()
475
-            );
476
-            $this->progress_step_manager->setCurrentStep(
477
-                $form_step->slug()
478
-            );
479
-            // mark all previous progress steps as completed
480
-            $this->progress_step_manager->setPreviousStepsCompleted();
481
-            $this->progress_step_manager->enqueueStylesAndScripts();
482
-            $this->addFormActionArgs();
483
-            $form_step->setFormAction($this->formAction());
484
-        } else {
485
-            $form_step->setRedirectUrl($this->baseUrl());
486
-            $form_step->addRedirectArgs(
487
-                array($this->formStepUrlKey() => $this->form_steps->current()->slug())
488
-            );
489
-        }
490
-        $form_step->generate();
491
-        if ($for_display) {
492
-            $form_step->enqueueStylesAndScripts();
493
-        }
494
-        return $form_step;
495
-    }
496
-
497
-
498
-    /**
499
-     * @param bool $return_as_string
500
-     * @return string
501
-     * @throws InvalidFormHandlerException
502
-     */
503
-    public function displayProgressSteps($return_as_string = true)
504
-    {
505
-        $form_step = $this->getCurrentStep();
506
-        if (! $form_step->displayable()) {
507
-            return '';
508
-        }
509
-        $progress_steps = apply_filters(
510
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
511
-            ''
512
-        );
513
-        $progress_steps .= $this->progress_step_manager->displaySteps();
514
-        $progress_steps .= apply_filters(
515
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
516
-            ''
517
-        );
518
-        if ($return_as_string) {
519
-            return $progress_steps;
520
-        }
521
-        echo wp_kses($progress_steps, AllowedTags::getWithFormTags());
522
-        return '';
523
-    }
524
-
525
-
526
-    /**
527
-     * @param bool $return_as_string
528
-     * @return string
529
-     * @throws InvalidFormHandlerException
530
-     */
531
-    public function displayCurrentStepForm($return_as_string = true)
532
-    {
533
-        if ($return_as_string) {
534
-            return $this->getCurrentStep()->display();
535
-        }
536
-        echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags());
537
-        return '';
538
-    }
539
-
540
-
541
-    /**
542
-     * @param array $form_data
543
-     * @return void
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidFormHandlerException
547
-     */
548
-    public function processCurrentStepForm($form_data = array())
549
-    {
550
-        // grab instance of current step because after calling next() below,
551
-        // any calls to getCurrentStep() will return the "next" step because we advanced
552
-        $current_step = $this->getCurrentStep();
553
-        try {
554
-            // form processing should either throw exceptions or return true
555
-            $current_step->process($form_data);
556
-        } catch (Exception $e) {
557
-            // something went wrong, convert the Exception to an EE_Error
558
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
559
-            // prevent redirect to next step or other if exception was thrown
560
-            if (
561
-                $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
562
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
563
-            ) {
564
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
565
-            }
566
-        }
567
-        // save notices to a transient so that when we redirect back
568
-        // to the display portion for this step
569
-        // those notices can be displayed
570
-        EE_Error::get_notices(false, true);
571
-        $this->redirectForm($current_step);
572
-    }
573
-
574
-
575
-    /**
576
-     * handles where to go to next
577
-     *
578
-     * @param SequentialStepFormInterface $current_step
579
-     * @throws InvalidArgumentException
580
-     * @throws InvalidDataTypeException
581
-     * @throws InvalidFormHandlerException
582
-     */
583
-    public function redirectForm(SequentialStepFormInterface $current_step)
584
-    {
585
-        $redirect_step = $current_step;
586
-        switch ($current_step->redirectTo()) {
587
-            case SequentialStepForm::REDIRECT_TO_OTHER:
588
-                // going somewhere else, so just check out now
589
-                wp_safe_redirect($redirect_step->redirectUrl());
590
-                exit();
591
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
592
-                $redirect_step = $this->form_steps->previous();
593
-                break;
594
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
595
-                $this->form_steps->next();
596
-                if ($this->form_steps->valid()) {
597
-                    $redirect_step = $this->form_steps->current();
598
-                }
599
-                break;
600
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
601
-            default:
602
-                // $redirect_step is already set
603
-        }
604
-        $current_step->setRedirectUrl($this->baseUrl());
605
-        $current_step->addRedirectArgs(
606
-            // use the slug for whatever step we are redirecting too
607
-            array($this->formStepUrlKey() => $redirect_step->slug())
608
-        );
609
-        wp_safe_redirect($current_step->redirectUrl());
610
-        exit();
611
-    }
33
+	/**
34
+	 * a simplified URL with no form related parameters
35
+	 * that will be used to build the form's redirect URLs
36
+	 *
37
+	 * @var string $base_url
38
+	 */
39
+	private $base_url = '';
40
+
41
+	/**
42
+	 * the key used for the URL param that denotes the current form step
43
+	 * defaults to 'ee-form-step'
44
+	 *
45
+	 * @var string $form_step_url_key
46
+	 */
47
+	private $form_step_url_key = '';
48
+
49
+	/**
50
+	 * @var string $default_form_step
51
+	 */
52
+	private $default_form_step = '';
53
+
54
+	/**
55
+	 * @var string $form_action
56
+	 */
57
+	private $form_action;
58
+
59
+	/**
60
+	 * value of one of the string constant above
61
+	 *
62
+	 * @var string $form_config
63
+	 */
64
+	private $form_config;
65
+
66
+	/**
67
+	 * @var string $progress_step_style
68
+	 */
69
+	private $progress_step_style = '';
70
+
71
+	/**
72
+	 * @var RequestInterface $request
73
+	 */
74
+	private $request;
75
+
76
+	/**
77
+	 * @var Collection $form_steps
78
+	 */
79
+	protected $form_steps;
80
+
81
+	/**
82
+	 * @var ProgressStepManager $progress_step_manager
83
+	 */
84
+	protected $progress_step_manager;
85
+
86
+
87
+	/**
88
+	 * @return Collection|null
89
+	 */
90
+	abstract protected function getFormStepsCollection();
91
+
92
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
93
+	/**
94
+	 * StepsManager constructor
95
+	 *
96
+	 * @param string                           $base_url
97
+	 * @param string                           $default_form_step
98
+	 * @param string                           $form_action
99
+	 * @param string                           $form_config
100
+	 * @param EE_Request|RequestInterface|null $request
101
+	 * @param string                           $progress_step_style
102
+	 * @throws InvalidDataTypeException
103
+	 * @throws InvalidArgumentException
104
+	 */
105
+	public function __construct(
106
+		$base_url,
107
+		$default_form_step,
108
+		$form_action = '',
109
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
110
+		$progress_step_style = 'number_bubbles',
111
+		$request = null
112
+	) {
113
+		$this->setBaseUrl($base_url);
114
+		$this->setDefaultFormStep($default_form_step);
115
+		$this->setFormAction($form_action);
116
+		$this->setFormConfig($form_config);
117
+		$this->setProgressStepStyle($progress_step_style);
118
+		$this->request = $request instanceof RequestInterface
119
+			? $request
120
+			: LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return string
126
+	 * @throws InvalidFormHandlerException
127
+	 */
128
+	public function baseUrl()
129
+	{
130
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
131
+			add_query_arg(
132
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
133
+				$this->base_url
134
+			);
135
+		}
136
+		return $this->base_url;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @param string $base_url
142
+	 * @throws InvalidDataTypeException
143
+	 * @throws InvalidArgumentException
144
+	 */
145
+	protected function setBaseUrl($base_url)
146
+	{
147
+		if (! is_string($base_url)) {
148
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
149
+		}
150
+		if (empty($base_url)) {
151
+			throw new InvalidArgumentException(
152
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
153
+			);
154
+		}
155
+		$this->base_url = $base_url;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return string
161
+	 * @throws InvalidDataTypeException
162
+	 */
163
+	public function formStepUrlKey()
164
+	{
165
+		if (empty($this->form_step_url_key)) {
166
+			$this->setFormStepUrlKey();
167
+		}
168
+		return $this->form_step_url_key;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $form_step_url_key
174
+	 * @throws InvalidDataTypeException
175
+	 */
176
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
177
+	{
178
+		if (! is_string($form_step_url_key)) {
179
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
180
+		}
181
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return string
187
+	 */
188
+	public function defaultFormStep()
189
+	{
190
+		return $this->default_form_step;
191
+	}
192
+
193
+
194
+	/**
195
+	 * @param $default_form_step
196
+	 * @throws InvalidDataTypeException
197
+	 */
198
+	protected function setDefaultFormStep($default_form_step)
199
+	{
200
+		if (! is_string($default_form_step)) {
201
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
202
+		}
203
+		$this->default_form_step = $default_form_step;
204
+	}
205
+
206
+
207
+	/**
208
+	 * @return void
209
+	 * @throws InvalidIdentifierException
210
+	 * @throws InvalidDataTypeException
211
+	 */
212
+	protected function setCurrentStepFromRequest()
213
+	{
214
+		$current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep());
215
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
216
+			throw new InvalidIdentifierException(
217
+				$current_step_slug,
218
+				$this->defaultFormStep(),
219
+				sprintf(
220
+					esc_html__('The "%1$s" form step could not be set.', 'event_espresso'),
221
+					$current_step_slug
222
+				)
223
+			);
224
+		}
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return SequentialStepFormInterface|object
230
+	 * @throws InvalidFormHandlerException
231
+	 */
232
+	public function getCurrentStep()
233
+	{
234
+		if (! $this->form_steps->current() instanceof SequentialStepForm) {
235
+			throw new InvalidFormHandlerException($this->form_steps->current());
236
+		}
237
+		return $this->form_steps->current();
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return string
243
+	 * @throws InvalidFormHandlerException
244
+	 */
245
+	public function formAction()
246
+	{
247
+		if (! is_string($this->form_action) || empty($this->form_action)) {
248
+			$this->form_action = $this->baseUrl();
249
+		}
250
+		return $this->form_action;
251
+	}
252
+
253
+
254
+	/**
255
+	 * @param string $form_action
256
+	 * @throws InvalidDataTypeException
257
+	 */
258
+	public function setFormAction($form_action)
259
+	{
260
+		if (! is_string($form_action)) {
261
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262
+		}
263
+		$this->form_action = $form_action;
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param array $form_action_args
269
+	 * @throws InvalidDataTypeException
270
+	 * @throws InvalidFormHandlerException
271
+	 */
272
+	public function addFormActionArgs($form_action_args = array())
273
+	{
274
+		if (! is_array($form_action_args)) {
275
+			throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276
+		}
277
+		$form_action_args = ! empty($form_action_args)
278
+			? $form_action_args
279
+			: array($this->formStepUrlKey() => $this->form_steps->current()->slug());
280
+		$this->getCurrentStep()->setFormAction(
281
+			add_query_arg($form_action_args, $this->formAction())
282
+		);
283
+		$this->form_action = $this->getCurrentStep()->formAction();
284
+	}
285
+
286
+
287
+	/**
288
+	 * @return string
289
+	 */
290
+	public function formConfig()
291
+	{
292
+		return $this->form_config;
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $form_config
298
+	 */
299
+	public function setFormConfig($form_config)
300
+	{
301
+		$this->form_config = $form_config;
302
+	}
303
+
304
+
305
+	/**
306
+	 * @return string
307
+	 */
308
+	public function progressStepStyle()
309
+	{
310
+		return $this->progress_step_style;
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param string $progress_step_style
316
+	 */
317
+	public function setProgressStepStyle($progress_step_style)
318
+	{
319
+		$this->progress_step_style = $progress_step_style;
320
+	}
321
+
322
+
323
+	/**
324
+	 * @return RequestInterface
325
+	 */
326
+	public function request()
327
+	{
328
+		return $this->request;
329
+	}
330
+
331
+
332
+	/**
333
+	 * @return Collection|null
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	protected function getProgressStepsCollection()
337
+	{
338
+		static $collection = null;
339
+		if (! $collection instanceof ProgressStepCollection) {
340
+			$collection = new ProgressStepCollection();
341
+		}
342
+		return $collection;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param Collection $progress_steps_collection
348
+	 * @return ProgressStepManager
349
+	 * @throws InvalidInterfaceException
350
+	 * @throws InvalidClassException
351
+	 * @throws InvalidDataTypeException
352
+	 * @throws InvalidEntityException
353
+	 * @throws InvalidFormHandlerException
354
+	 */
355
+	protected function generateProgressSteps(Collection $progress_steps_collection)
356
+	{
357
+		$current_step = $this->getCurrentStep();
358
+		/** @var SequentialStepForm $form_step */
359
+		foreach ($this->form_steps as $form_step) {
360
+			// is this step active ?
361
+			if (! $form_step->initialize()) {
362
+				continue;
363
+			}
364
+			$progress_steps_collection->add(
365
+				new ProgressStep(
366
+					$form_step->order(),
367
+					$form_step->slug(),
368
+					$form_step->slug(),
369
+					$form_step->formName()
370
+				),
371
+				$form_step->slug()
372
+			);
373
+		}
374
+		// set collection pointer back to current step
375
+		$this->form_steps->setCurrentUsingObject($current_step);
376
+		return new ProgressStepManager(
377
+			$this->progressStepStyle(),
378
+			$this->defaultFormStep(),
379
+			$this->formStepUrlKey(),
380
+			$progress_steps_collection
381
+		);
382
+	}
383
+
384
+
385
+	/**
386
+	 * @throws InvalidClassException
387
+	 * @throws InvalidDataTypeException
388
+	 * @throws InvalidEntityException
389
+	 * @throws InvalidIdentifierException
390
+	 * @throws InvalidInterfaceException
391
+	 * @throws InvalidArgumentException
392
+	 * @throws InvalidFormHandlerException
393
+	 */
394
+	public function buildForm()
395
+	{
396
+		$this->buildCurrentStepFormForDisplay();
397
+	}
398
+
399
+
400
+	/**
401
+	 * @param array $form_data
402
+	 * @throws InvalidArgumentException
403
+	 * @throws InvalidClassException
404
+	 * @throws InvalidDataTypeException
405
+	 * @throws InvalidEntityException
406
+	 * @throws InvalidFormHandlerException
407
+	 * @throws InvalidIdentifierException
408
+	 * @throws InvalidInterfaceException
409
+	 */
410
+	public function processForm($form_data = array())
411
+	{
412
+		$this->buildCurrentStepFormForProcessing();
413
+		$this->processCurrentStepForm($form_data);
414
+	}
415
+
416
+
417
+	/**
418
+	 * @throws InvalidClassException
419
+	 * @throws InvalidDataTypeException
420
+	 * @throws InvalidEntityException
421
+	 * @throws InvalidInterfaceException
422
+	 * @throws InvalidIdentifierException
423
+	 * @throws InvalidArgumentException
424
+	 * @throws InvalidFormHandlerException
425
+	 */
426
+	public function buildCurrentStepFormForDisplay()
427
+	{
428
+		$form_step = $this->buildCurrentStepForm();
429
+		// no displayable content ? then skip straight to processing
430
+		if (! $form_step->displayable()) {
431
+			$this->addFormActionArgs();
432
+			$form_step->setFormAction($this->formAction());
433
+			wp_safe_redirect($form_step->formAction());
434
+		}
435
+	}
436
+
437
+
438
+	/**
439
+	 * @throws InvalidClassException
440
+	 * @throws InvalidDataTypeException
441
+	 * @throws InvalidEntityException
442
+	 * @throws InvalidInterfaceException
443
+	 * @throws InvalidIdentifierException
444
+	 * @throws InvalidArgumentException
445
+	 * @throws InvalidFormHandlerException
446
+	 */
447
+	public function buildCurrentStepFormForProcessing()
448
+	{
449
+		$this->buildCurrentStepForm(false);
450
+	}
451
+
452
+
453
+	/**
454
+	 * @param bool $for_display
455
+	 * @return SequentialStepFormInterface
456
+	 * @throws InvalidArgumentException
457
+	 * @throws InvalidClassException
458
+	 * @throws InvalidDataTypeException
459
+	 * @throws InvalidEntityException
460
+	 * @throws InvalidFormHandlerException
461
+	 * @throws InvalidIdentifierException
462
+	 * @throws InvalidInterfaceException
463
+	 */
464
+	private function buildCurrentStepForm($for_display = true)
465
+	{
466
+		$this->form_steps = $this->getFormStepsCollection();
467
+		$this->setCurrentStepFromRequest();
468
+		$form_step = $this->getCurrentStep();
469
+		if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
470
+			$form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
471
+		}
472
+		if ($for_display && $form_step->displayable()) {
473
+			$this->progress_step_manager = $this->generateProgressSteps(
474
+				$this->getProgressStepsCollection()
475
+			);
476
+			$this->progress_step_manager->setCurrentStep(
477
+				$form_step->slug()
478
+			);
479
+			// mark all previous progress steps as completed
480
+			$this->progress_step_manager->setPreviousStepsCompleted();
481
+			$this->progress_step_manager->enqueueStylesAndScripts();
482
+			$this->addFormActionArgs();
483
+			$form_step->setFormAction($this->formAction());
484
+		} else {
485
+			$form_step->setRedirectUrl($this->baseUrl());
486
+			$form_step->addRedirectArgs(
487
+				array($this->formStepUrlKey() => $this->form_steps->current()->slug())
488
+			);
489
+		}
490
+		$form_step->generate();
491
+		if ($for_display) {
492
+			$form_step->enqueueStylesAndScripts();
493
+		}
494
+		return $form_step;
495
+	}
496
+
497
+
498
+	/**
499
+	 * @param bool $return_as_string
500
+	 * @return string
501
+	 * @throws InvalidFormHandlerException
502
+	 */
503
+	public function displayProgressSteps($return_as_string = true)
504
+	{
505
+		$form_step = $this->getCurrentStep();
506
+		if (! $form_step->displayable()) {
507
+			return '';
508
+		}
509
+		$progress_steps = apply_filters(
510
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
511
+			''
512
+		);
513
+		$progress_steps .= $this->progress_step_manager->displaySteps();
514
+		$progress_steps .= apply_filters(
515
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
516
+			''
517
+		);
518
+		if ($return_as_string) {
519
+			return $progress_steps;
520
+		}
521
+		echo wp_kses($progress_steps, AllowedTags::getWithFormTags());
522
+		return '';
523
+	}
524
+
525
+
526
+	/**
527
+	 * @param bool $return_as_string
528
+	 * @return string
529
+	 * @throws InvalidFormHandlerException
530
+	 */
531
+	public function displayCurrentStepForm($return_as_string = true)
532
+	{
533
+		if ($return_as_string) {
534
+			return $this->getCurrentStep()->display();
535
+		}
536
+		echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags());
537
+		return '';
538
+	}
539
+
540
+
541
+	/**
542
+	 * @param array $form_data
543
+	 * @return void
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidFormHandlerException
547
+	 */
548
+	public function processCurrentStepForm($form_data = array())
549
+	{
550
+		// grab instance of current step because after calling next() below,
551
+		// any calls to getCurrentStep() will return the "next" step because we advanced
552
+		$current_step = $this->getCurrentStep();
553
+		try {
554
+			// form processing should either throw exceptions or return true
555
+			$current_step->process($form_data);
556
+		} catch (Exception $e) {
557
+			// something went wrong, convert the Exception to an EE_Error
558
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
559
+			// prevent redirect to next step or other if exception was thrown
560
+			if (
561
+				$current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
562
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
563
+			) {
564
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
565
+			}
566
+		}
567
+		// save notices to a transient so that when we redirect back
568
+		// to the display portion for this step
569
+		// those notices can be displayed
570
+		EE_Error::get_notices(false, true);
571
+		$this->redirectForm($current_step);
572
+	}
573
+
574
+
575
+	/**
576
+	 * handles where to go to next
577
+	 *
578
+	 * @param SequentialStepFormInterface $current_step
579
+	 * @throws InvalidArgumentException
580
+	 * @throws InvalidDataTypeException
581
+	 * @throws InvalidFormHandlerException
582
+	 */
583
+	public function redirectForm(SequentialStepFormInterface $current_step)
584
+	{
585
+		$redirect_step = $current_step;
586
+		switch ($current_step->redirectTo()) {
587
+			case SequentialStepForm::REDIRECT_TO_OTHER:
588
+				// going somewhere else, so just check out now
589
+				wp_safe_redirect($redirect_step->redirectUrl());
590
+				exit();
591
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
592
+				$redirect_step = $this->form_steps->previous();
593
+				break;
594
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
595
+				$this->form_steps->next();
596
+				if ($this->form_steps->valid()) {
597
+					$redirect_step = $this->form_steps->current();
598
+				}
599
+				break;
600
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
601
+			default:
602
+				// $redirect_step is already set
603
+		}
604
+		$current_step->setRedirectUrl($this->baseUrl());
605
+		$current_step->addRedirectArgs(
606
+			// use the slug for whatever step we are redirecting too
607
+			array($this->formStepUrlKey() => $redirect_step->slug())
608
+		);
609
+		wp_safe_redirect($current_step->redirectUrl());
610
+		exit();
611
+	}
612 612
 }
Please login to merge, or discard this patch.
core/services/request/Response.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function setNotice($key, $value)
56 56
     {
57
-        $this->notice[ $key ] = $value;
57
+        $this->notice[$key] = $value;
58 58
     }
59 59
 
60 60
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function getNotice($key)
66 66
     {
67
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
67
+        return isset($this->notice[$key]) ? $this->notice[$key] : null;
68 68
     }
69 69
 
70 70
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function getOutput($as_string = true, $separator = PHP_EOL)
100 100
     {
101
-        return $as_string ? implode($separator, $this->output) : $this->output ;
101
+        return $as_string ? implode($separator, $this->output) : $this->output;
102 102
     }
103 103
 
104 104
 
Please login to merge, or discard this patch.
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,125 +14,125 @@
 block discarded – undo
14 14
  */
15 15
 class Response implements ResponseInterface, ReservedInstanceInterface
16 16
 {
17
-    /**
18
-     * @var array $notice
19
-     */
20
-    protected $notice = [];
21
-
22
-    /**
23
-     * rendered output to be returned to WP
24
-     *
25
-     * @var array
26
-     */
27
-    protected $output = [];
28
-
29
-    /**
30
-     * @var bool
31
-     */
32
-    protected $request_terminated = false;
33
-
34
-    /**
35
-     * @var bool $deactivate_plugin
36
-     */
37
-    protected $deactivate_plugin = false;
38
-
39
-
40
-    /**
41
-     * EE_Response constructor.
42
-     */
43
-    public function __construct()
44
-    {
45
-        $this->terminateRequest(false);
46
-    }
47
-
48
-
49
-    /**
50
-     * @param $key
51
-     * @param $value
52
-     * @return    void
53
-     */
54
-    public function setNotice($key, $value)
55
-    {
56
-        $this->notice[ $key ] = $value;
57
-    }
58
-
59
-
60
-    /**
61
-     * @param $key
62
-     * @return    mixed
63
-     */
64
-    public function getNotice($key)
65
-    {
66
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
67
-    }
68
-
69
-
70
-    /**
71
-     * @return array
72
-     */
73
-    public function getNotices()
74
-    {
75
-        return $this->notice;
76
-    }
77
-
78
-
79
-    /**
80
-     * @param string $string
81
-     * @param bool   $append
82
-     */
83
-    public function addOutput($string, $append = true)
84
-    {
85
-        if ($append) {
86
-            $this->output[] = $string;
87
-            return;
88
-        }
89
-        array_unshift($this->output, $string);
90
-    }
91
-
92
-
93
-    /**
94
-     * @param bool   $as_string
95
-     * @param string $separator
96
-     * @return array|string
97
-     */
98
-    public function getOutput($as_string = true, $separator = PHP_EOL)
99
-    {
100
-        return $as_string ? implode($separator, $this->output) : $this->output ;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return boolean
106
-     */
107
-    public function requestTerminated()
108
-    {
109
-        return $this->request_terminated;
110
-    }
111
-
112
-
113
-    /**
114
-     * @param boolean $request_terminated
115
-     */
116
-    public function terminateRequest($request_terminated = true)
117
-    {
118
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
119
-    }
120
-
121
-
122
-    /**
123
-     * @return boolean
124
-     */
125
-    public function pluginDeactivated()
126
-    {
127
-        return $this->deactivate_plugin;
128
-    }
129
-
130
-
131
-    /**
132
-     * sets $deactivate_plugin to true
133
-     */
134
-    public function deactivatePlugin()
135
-    {
136
-        $this->deactivate_plugin = true;
137
-    }
17
+	/**
18
+	 * @var array $notice
19
+	 */
20
+	protected $notice = [];
21
+
22
+	/**
23
+	 * rendered output to be returned to WP
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $output = [];
28
+
29
+	/**
30
+	 * @var bool
31
+	 */
32
+	protected $request_terminated = false;
33
+
34
+	/**
35
+	 * @var bool $deactivate_plugin
36
+	 */
37
+	protected $deactivate_plugin = false;
38
+
39
+
40
+	/**
41
+	 * EE_Response constructor.
42
+	 */
43
+	public function __construct()
44
+	{
45
+		$this->terminateRequest(false);
46
+	}
47
+
48
+
49
+	/**
50
+	 * @param $key
51
+	 * @param $value
52
+	 * @return    void
53
+	 */
54
+	public function setNotice($key, $value)
55
+	{
56
+		$this->notice[ $key ] = $value;
57
+	}
58
+
59
+
60
+	/**
61
+	 * @param $key
62
+	 * @return    mixed
63
+	 */
64
+	public function getNotice($key)
65
+	{
66
+		return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
67
+	}
68
+
69
+
70
+	/**
71
+	 * @return array
72
+	 */
73
+	public function getNotices()
74
+	{
75
+		return $this->notice;
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param string $string
81
+	 * @param bool   $append
82
+	 */
83
+	public function addOutput($string, $append = true)
84
+	{
85
+		if ($append) {
86
+			$this->output[] = $string;
87
+			return;
88
+		}
89
+		array_unshift($this->output, $string);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @param bool   $as_string
95
+	 * @param string $separator
96
+	 * @return array|string
97
+	 */
98
+	public function getOutput($as_string = true, $separator = PHP_EOL)
99
+	{
100
+		return $as_string ? implode($separator, $this->output) : $this->output ;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return boolean
106
+	 */
107
+	public function requestTerminated()
108
+	{
109
+		return $this->request_terminated;
110
+	}
111
+
112
+
113
+	/**
114
+	 * @param boolean $request_terminated
115
+	 */
116
+	public function terminateRequest($request_terminated = true)
117
+	{
118
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return boolean
124
+	 */
125
+	public function pluginDeactivated()
126
+	{
127
+		return $this->deactivate_plugin;
128
+	}
129
+
130
+
131
+	/**
132
+	 * sets $deactivate_plugin to true
133
+	 */
134
+	public function deactivatePlugin()
135
+	{
136
+		$this->deactivate_plugin = true;
137
+	}
138 138
 }
Please login to merge, or discard this patch.
core/services/container/Mirror.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function getReflectionClass($class_name)
62 62
     {
63
-        if (! is_string($class_name)) {
63
+        if ( ! is_string($class_name)) {
64 64
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
65 65
         }
66
-        if (! isset($this->classes[ $class_name ])) {
67
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
66
+        if ( ! isset($this->classes[$class_name])) {
67
+            $this->classes[$class_name] = new ReflectionClass($class_name);
68 68
         }
69
-        return $this->classes[ $class_name ];
69
+        return $this->classes[$class_name];
70 70
     }
71 71
 
72 72
 
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function getConstructor($class_name)
80 80
     {
81
-        if (! is_string($class_name)) {
81
+        if ( ! is_string($class_name)) {
82 82
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
83 83
         }
84
-        if (! isset($this->constructors[ $class_name ])) {
84
+        if ( ! isset($this->constructors[$class_name])) {
85 85
             $reflection_class                  = $this->getReflectionClass($class_name);
86
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
86
+            $this->constructors[$class_name] = $reflection_class->getConstructor();
87 87
         }
88
-        return $this->constructors[ $class_name ];
88
+        return $this->constructors[$class_name];
89 89
     }
90 90
 
91 91
 
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getParameters($class_name)
111 111
     {
112
-        if (! isset($this->parameters[ $class_name ])) {
112
+        if ( ! isset($this->parameters[$class_name])) {
113 113
             $constructor                     = $this->getConstructor($class_name);
114
-            $this->parameters[ $class_name ] = $constructor->getParameters();
114
+            $this->parameters[$class_name] = $constructor->getParameters();
115 115
         }
116
-        return $this->parameters[ $class_name ];
116
+        return $this->parameters[$class_name];
117 117
     }
118 118
 
119 119
 
@@ -149,20 +149,20 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
151 151
     {
152
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
153
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
152
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) {
153
+            return $this->parameter_classes[$class_name][$index]['param_class_name'];
154 154
         }
155
-        if (! isset($this->parameter_classes[ $class_name ])) {
156
-            $this->parameter_classes[ $class_name ] = [];
155
+        if ( ! isset($this->parameter_classes[$class_name])) {
156
+            $this->parameter_classes[$class_name] = [];
157 157
         }
158
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
159
-            $this->parameter_classes[ $class_name ][ $index ] = [];
158
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
159
+            $this->parameter_classes[$class_name][$index] = [];
160 160
         }
161 161
         // ReflectionParameter::getClass() is deprecated in PHP 8+
162
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100
162
+        $this->parameter_classes[$class_name][$index]['param_class_name'] = PHP_VERSION_ID < 70100
163 163
             ? $this->getParameterClassNameLegacy($param)
164 164
             : $this->getParameterClassNamePhp8($param);
165
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
165
+        return $this->parameter_classes[$class_name][$index]['param_class_name'];
166 166
     }
167 167
 
168 168
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
      */
216 216
     public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
217 217
     {
218
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
219
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
218
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) {
219
+            return $this->parameter_classes[$class_name][$index]['param_class_default'];
220 220
         }
221
-        if (! isset($this->parameter_classes[ $class_name ])) {
222
-            $this->parameter_classes[ $class_name ] = [];
221
+        if ( ! isset($this->parameter_classes[$class_name])) {
222
+            $this->parameter_classes[$class_name] = [];
223 223
         }
224
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
225
-            $this->parameter_classes[ $class_name ][ $index ] = [];
224
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
225
+            $this->parameter_classes[$class_name][$index] = [];
226 226
         }
227
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
227
+        $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable()
228 228
             ? $param->getDefaultValue()
229 229
             : null;
230
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
230
+        return $this->parameter_classes[$class_name][$index]['param_class_default'];
231 231
     }
232 232
 
233 233
 
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
      */
240 240
     public function getProperties($class_name)
241 241
     {
242
-        if (! isset($this->properties[ $class_name ])) {
242
+        if ( ! isset($this->properties[$class_name])) {
243 243
             $reflection_class                = $this->getReflectionClass($class_name);
244
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
244
+            $this->properties[$class_name] = $reflection_class->getProperties();
245 245
         }
246
-        return $this->properties[ $class_name ];
246
+        return $this->properties[$class_name];
247 247
     }
248 248
 
249 249
 
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public function getMethods($class_name)
269 269
     {
270
-        if (! isset($this->methods[ $class_name ])) {
270
+        if ( ! isset($this->methods[$class_name])) {
271 271
             $reflection_class             = $this->getReflectionClass($class_name);
272
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
272
+            $this->methods[$class_name] = $reflection_class->getMethods();
273 273
         }
274
-        return $this->methods[ $class_name ];
274
+        return $this->methods[$class_name];
275 275
     }
276 276
 
277 277
 
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -20,268 +20,268 @@
 block discarded – undo
20 20
  */
21 21
 class Mirror
22 22
 {
23
-    /**
24
-     * @var ReflectionClass[] $classes
25
-     */
26
-    private $classes = [];
27
-
28
-    /**
29
-     * @var ReflectionMethod[] $constructors
30
-     */
31
-    private $constructors = [];
32
-
33
-    /**
34
-     * @var ReflectionParameter[][] $parameters
35
-     */
36
-    private $parameters = [];
37
-
38
-    /**
39
-     * @var ReflectionParameter[][] $parameters
40
-     */
41
-    private $parameter_classes = [];
42
-
43
-    /**
44
-     * @var ReflectionProperty[][] $properties
45
-     */
46
-    private $properties = [];
47
-
48
-    /**
49
-     * @var ReflectionMethod[][] $methods
50
-     */
51
-    private $methods = [];
52
-
53
-
54
-    /**
55
-     * @param string $class_name
56
-     * @return ReflectionClass
57
-     * @throws ReflectionException
58
-     * @throws InvalidDataTypeException
59
-     */
60
-    public function getReflectionClass($class_name)
61
-    {
62
-        if (! is_string($class_name)) {
63
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
64
-        }
65
-        if (! isset($this->classes[ $class_name ])) {
66
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
67
-        }
68
-        return $this->classes[ $class_name ];
69
-    }
70
-
71
-
72
-    /**
73
-     * @param string $class_name
74
-     * @return ReflectionMethod
75
-     * @throws InvalidDataTypeException
76
-     * @throws ReflectionException
77
-     */
78
-    public function getConstructor($class_name)
79
-    {
80
-        if (! is_string($class_name)) {
81
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
82
-        }
83
-        if (! isset($this->constructors[ $class_name ])) {
84
-            $reflection_class                  = $this->getReflectionClass($class_name);
85
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
86
-        }
87
-        return $this->constructors[ $class_name ];
88
-    }
89
-
90
-
91
-    /**
92
-     * @param ReflectionClass $reflection_class
93
-     * @return ReflectionMethod
94
-     * @throws InvalidDataTypeException
95
-     * @throws ReflectionException
96
-     */
97
-    public function getConstructorFromReflection(ReflectionClass $reflection_class)
98
-    {
99
-        return $this->getConstructor($reflection_class->getName());
100
-    }
101
-
102
-
103
-    /**
104
-     * @param string $class_name
105
-     * @return ReflectionParameter[]
106
-     * @throws InvalidDataTypeException
107
-     * @throws ReflectionException
108
-     */
109
-    public function getParameters($class_name)
110
-    {
111
-        if (! isset($this->parameters[ $class_name ])) {
112
-            $constructor                     = $this->getConstructor($class_name);
113
-            $this->parameters[ $class_name ] = $constructor->getParameters();
114
-        }
115
-        return $this->parameters[ $class_name ];
116
-    }
117
-
118
-
119
-    /**
120
-     * @param ReflectionClass $reflection_class
121
-     * @return ReflectionParameter[]
122
-     * @throws InvalidDataTypeException
123
-     * @throws ReflectionException
124
-     */
125
-    public function getParametersFromReflection(ReflectionClass $reflection_class)
126
-    {
127
-        return $this->getParameters($reflection_class->getName());
128
-    }
129
-
130
-
131
-    /**
132
-     * @param ReflectionMethod $constructor
133
-     * @return ReflectionParameter[]
134
-     * @throws InvalidDataTypeException
135
-     * @throws ReflectionException
136
-     */
137
-    public function getParametersFromReflectionConstructor(ReflectionMethod $constructor)
138
-    {
139
-        return $this->getParameters($constructor->getDeclaringClass());
140
-    }
141
-
142
-
143
-    /**
144
-     * @param ReflectionParameter $param
145
-     * @param string              $class_name
146
-     * @param string              $index
147
-     * @return string|null
148
-     */
149
-    public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
150
-    {
151
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
152
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
153
-        }
154
-        if (! isset($this->parameter_classes[ $class_name ])) {
155
-            $this->parameter_classes[ $class_name ] = [];
156
-        }
157
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
158
-            $this->parameter_classes[ $class_name ][ $index ] = [];
159
-        }
160
-        // ReflectionParameter::getClass() is deprecated in PHP 8+
161
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100
162
-            ? $this->getParameterClassNameLegacy($param)
163
-            : $this->getParameterClassNamePhp8($param);
164
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
165
-    }
166
-
167
-
168
-    /**
169
-     * @param ReflectionParameter $param
170
-     * @return string|null
171
-     * @since   4.10.13.p
172
-     */
173
-    private function getParameterClassNameLegacy(ReflectionParameter $param)
174
-    {
175
-        $reflection_class = $param->getClass();
176
-        return $reflection_class instanceof ReflectionClass
177
-            ? $reflection_class->getName()
178
-            : null;
179
-    }
180
-
181
-
182
-    /**
183
-     * ReflectionParameter::getClass() is deprecated in PHP 8+,
184
-     * so the class name for a parameter needs to be extracted from the ReflectionType,
185
-     * which can either be a ReflectionNamedType or ReflectionUnionType
186
-     *
187
-     * @param ReflectionParameter $param
188
-     * @return null
189
-     * @since   4.10.13.p
190
-     */
191
-    private function getParameterClassNamePhp8(ReflectionParameter $param)
192
-    {
193
-        $reflection_type = $param->getType();
194
-        if ($reflection_type instanceof \ReflectionNamedType) {
195
-            return $reflection_type->getName();
196
-        }
197
-        if ($reflection_type instanceof \ReflectionUnionType) {
198
-            $reflection_types = $reflection_type->getTypes();
199
-            if (is_array($reflection_types)) {
200
-                $first = reset($reflection_types);
201
-                return $first->getName();
202
-            }
203
-        }
204
-        return null;
205
-    }
206
-
207
-
208
-    /**
209
-     * @param ReflectionParameter $param
210
-     * @param string              $class_name
211
-     * @param string              $index
212
-     * @return string|null
213
-     * @throws ReflectionException
214
-     */
215
-    public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
216
-    {
217
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
218
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
219
-        }
220
-        if (! isset($this->parameter_classes[ $class_name ])) {
221
-            $this->parameter_classes[ $class_name ] = [];
222
-        }
223
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
224
-            $this->parameter_classes[ $class_name ][ $index ] = [];
225
-        }
226
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
227
-            ? $param->getDefaultValue()
228
-            : null;
229
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
230
-    }
231
-
232
-
233
-    /**
234
-     * @param string $class_name
235
-     * @return ReflectionProperty[]
236
-     * @throws InvalidDataTypeException
237
-     * @throws ReflectionException
238
-     */
239
-    public function getProperties($class_name)
240
-    {
241
-        if (! isset($this->properties[ $class_name ])) {
242
-            $reflection_class                = $this->getReflectionClass($class_name);
243
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
244
-        }
245
-        return $this->properties[ $class_name ];
246
-    }
247
-
248
-
249
-    /**
250
-     * @param ReflectionClass $reflection_class
251
-     * @return ReflectionProperty[]
252
-     * @throws InvalidDataTypeException
253
-     * @throws ReflectionException
254
-     */
255
-    public function getPropertiesFromReflection(ReflectionClass $reflection_class)
256
-    {
257
-        return $this->getProperties($reflection_class->getName());
258
-    }
259
-
260
-
261
-    /**
262
-     * @param string $class_name
263
-     * @return ReflectionMethod[]
264
-     * @throws InvalidDataTypeException
265
-     * @throws ReflectionException
266
-     */
267
-    public function getMethods($class_name)
268
-    {
269
-        if (! isset($this->methods[ $class_name ])) {
270
-            $reflection_class             = $this->getReflectionClass($class_name);
271
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
272
-        }
273
-        return $this->methods[ $class_name ];
274
-    }
275
-
276
-
277
-    /**
278
-     * @param ReflectionClass $reflection_class )
279
-     * @return ReflectionMethod[]
280
-     * @throws InvalidDataTypeException
281
-     * @throws ReflectionException
282
-     */
283
-    public function getMethodsFromReflection(ReflectionClass $reflection_class)
284
-    {
285
-        return $this->getMethods($reflection_class->getName());
286
-    }
23
+	/**
24
+	 * @var ReflectionClass[] $classes
25
+	 */
26
+	private $classes = [];
27
+
28
+	/**
29
+	 * @var ReflectionMethod[] $constructors
30
+	 */
31
+	private $constructors = [];
32
+
33
+	/**
34
+	 * @var ReflectionParameter[][] $parameters
35
+	 */
36
+	private $parameters = [];
37
+
38
+	/**
39
+	 * @var ReflectionParameter[][] $parameters
40
+	 */
41
+	private $parameter_classes = [];
42
+
43
+	/**
44
+	 * @var ReflectionProperty[][] $properties
45
+	 */
46
+	private $properties = [];
47
+
48
+	/**
49
+	 * @var ReflectionMethod[][] $methods
50
+	 */
51
+	private $methods = [];
52
+
53
+
54
+	/**
55
+	 * @param string $class_name
56
+	 * @return ReflectionClass
57
+	 * @throws ReflectionException
58
+	 * @throws InvalidDataTypeException
59
+	 */
60
+	public function getReflectionClass($class_name)
61
+	{
62
+		if (! is_string($class_name)) {
63
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
64
+		}
65
+		if (! isset($this->classes[ $class_name ])) {
66
+			$this->classes[ $class_name ] = new ReflectionClass($class_name);
67
+		}
68
+		return $this->classes[ $class_name ];
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param string $class_name
74
+	 * @return ReflectionMethod
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws ReflectionException
77
+	 */
78
+	public function getConstructor($class_name)
79
+	{
80
+		if (! is_string($class_name)) {
81
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
82
+		}
83
+		if (! isset($this->constructors[ $class_name ])) {
84
+			$reflection_class                  = $this->getReflectionClass($class_name);
85
+			$this->constructors[ $class_name ] = $reflection_class->getConstructor();
86
+		}
87
+		return $this->constructors[ $class_name ];
88
+	}
89
+
90
+
91
+	/**
92
+	 * @param ReflectionClass $reflection_class
93
+	 * @return ReflectionMethod
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws ReflectionException
96
+	 */
97
+	public function getConstructorFromReflection(ReflectionClass $reflection_class)
98
+	{
99
+		return $this->getConstructor($reflection_class->getName());
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param string $class_name
105
+	 * @return ReflectionParameter[]
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function getParameters($class_name)
110
+	{
111
+		if (! isset($this->parameters[ $class_name ])) {
112
+			$constructor                     = $this->getConstructor($class_name);
113
+			$this->parameters[ $class_name ] = $constructor->getParameters();
114
+		}
115
+		return $this->parameters[ $class_name ];
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param ReflectionClass $reflection_class
121
+	 * @return ReflectionParameter[]
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws ReflectionException
124
+	 */
125
+	public function getParametersFromReflection(ReflectionClass $reflection_class)
126
+	{
127
+		return $this->getParameters($reflection_class->getName());
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param ReflectionMethod $constructor
133
+	 * @return ReflectionParameter[]
134
+	 * @throws InvalidDataTypeException
135
+	 * @throws ReflectionException
136
+	 */
137
+	public function getParametersFromReflectionConstructor(ReflectionMethod $constructor)
138
+	{
139
+		return $this->getParameters($constructor->getDeclaringClass());
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param ReflectionParameter $param
145
+	 * @param string              $class_name
146
+	 * @param string              $index
147
+	 * @return string|null
148
+	 */
149
+	public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
150
+	{
151
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
152
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
153
+		}
154
+		if (! isset($this->parameter_classes[ $class_name ])) {
155
+			$this->parameter_classes[ $class_name ] = [];
156
+		}
157
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
158
+			$this->parameter_classes[ $class_name ][ $index ] = [];
159
+		}
160
+		// ReflectionParameter::getClass() is deprecated in PHP 8+
161
+		$this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100
162
+			? $this->getParameterClassNameLegacy($param)
163
+			: $this->getParameterClassNamePhp8($param);
164
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
165
+	}
166
+
167
+
168
+	/**
169
+	 * @param ReflectionParameter $param
170
+	 * @return string|null
171
+	 * @since   4.10.13.p
172
+	 */
173
+	private function getParameterClassNameLegacy(ReflectionParameter $param)
174
+	{
175
+		$reflection_class = $param->getClass();
176
+		return $reflection_class instanceof ReflectionClass
177
+			? $reflection_class->getName()
178
+			: null;
179
+	}
180
+
181
+
182
+	/**
183
+	 * ReflectionParameter::getClass() is deprecated in PHP 8+,
184
+	 * so the class name for a parameter needs to be extracted from the ReflectionType,
185
+	 * which can either be a ReflectionNamedType or ReflectionUnionType
186
+	 *
187
+	 * @param ReflectionParameter $param
188
+	 * @return null
189
+	 * @since   4.10.13.p
190
+	 */
191
+	private function getParameterClassNamePhp8(ReflectionParameter $param)
192
+	{
193
+		$reflection_type = $param->getType();
194
+		if ($reflection_type instanceof \ReflectionNamedType) {
195
+			return $reflection_type->getName();
196
+		}
197
+		if ($reflection_type instanceof \ReflectionUnionType) {
198
+			$reflection_types = $reflection_type->getTypes();
199
+			if (is_array($reflection_types)) {
200
+				$first = reset($reflection_types);
201
+				return $first->getName();
202
+			}
203
+		}
204
+		return null;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @param ReflectionParameter $param
210
+	 * @param string              $class_name
211
+	 * @param string              $index
212
+	 * @return string|null
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
216
+	{
217
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
218
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
219
+		}
220
+		if (! isset($this->parameter_classes[ $class_name ])) {
221
+			$this->parameter_classes[ $class_name ] = [];
222
+		}
223
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
224
+			$this->parameter_classes[ $class_name ][ $index ] = [];
225
+		}
226
+		$this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
227
+			? $param->getDefaultValue()
228
+			: null;
229
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param string $class_name
235
+	 * @return ReflectionProperty[]
236
+	 * @throws InvalidDataTypeException
237
+	 * @throws ReflectionException
238
+	 */
239
+	public function getProperties($class_name)
240
+	{
241
+		if (! isset($this->properties[ $class_name ])) {
242
+			$reflection_class                = $this->getReflectionClass($class_name);
243
+			$this->properties[ $class_name ] = $reflection_class->getProperties();
244
+		}
245
+		return $this->properties[ $class_name ];
246
+	}
247
+
248
+
249
+	/**
250
+	 * @param ReflectionClass $reflection_class
251
+	 * @return ReflectionProperty[]
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws ReflectionException
254
+	 */
255
+	public function getPropertiesFromReflection(ReflectionClass $reflection_class)
256
+	{
257
+		return $this->getProperties($reflection_class->getName());
258
+	}
259
+
260
+
261
+	/**
262
+	 * @param string $class_name
263
+	 * @return ReflectionMethod[]
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws ReflectionException
266
+	 */
267
+	public function getMethods($class_name)
268
+	{
269
+		if (! isset($this->methods[ $class_name ])) {
270
+			$reflection_class             = $this->getReflectionClass($class_name);
271
+			$this->methods[ $class_name ] = $reflection_class->getMethods();
272
+		}
273
+		return $this->methods[ $class_name ];
274
+	}
275
+
276
+
277
+	/**
278
+	 * @param ReflectionClass $reflection_class )
279
+	 * @return ReflectionMethod[]
280
+	 * @throws InvalidDataTypeException
281
+	 * @throws ReflectionException
282
+	 */
283
+	public function getMethodsFromReflection(ReflectionClass $reflection_class)
284
+	{
285
+		return $this->getMethods($reflection_class->getName());
286
+	}
287 287
 }
Please login to merge, or discard this patch.
core/services/loaders/ClassInterfaceCache.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
     {
50 50
         $fqn = $this->getFqn($fqn);
51 51
         // have we already seen this FQCN ?
52
-        if (! array_key_exists($fqn, $this->interfaces)) {
53
-            $this->interfaces[ $fqn ] = array();
52
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
53
+            $this->interfaces[$fqn] = array();
54 54
             if (class_exists($fqn)) {
55
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
56
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
57
-                    ? $this->interfaces[ $fqn ]
55
+                $this->interfaces[$fqn] = class_implements($fqn, false);
56
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
57
+                    ? $this->interfaces[$fqn]
58 58
                     : array();
59 59
             }
60 60
         }
61
-        return $this->interfaces[ $fqn ];
61
+        return $this->interfaces[$fqn];
62 62
     }
63 63
 
64 64
 
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
         // are we adding an alias for a specific class?
94 94
         if ($for_class !== '') {
95 95
             // make sure it's set up as an array
96
-            if (! isset($this->aliases[ $for_class ])) {
97
-                $this->aliases[ $for_class ] = array();
96
+            if ( ! isset($this->aliases[$for_class])) {
97
+                $this->aliases[$for_class] = array();
98 98
             }
99
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
99
+            $this->aliases[$for_class][$alias] = $fqn;
100 100
             return;
101 101
         }
102
-        $this->aliases[ $alias ] = $fqn;
102
+        $this->aliases[$alias] = $fqn;
103 103
     }
104 104
 
105 105
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function isDirectAlias($fqn = '')
133 133
     {
134
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
134
+        return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]);
135 135
     }
136 136
 
137 137
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     {
147 147
         return (
148 148
             $for_class !== ''
149
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
149
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
150 150
         );
151 151
     }
152 152
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
     {
172 172
         $alias = $this->getFqn($alias);
173 173
         if ($this->isAliasForClass($alias, $for_class)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
174
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
175 175
         }
176 176
         if ($this->isDirectAlias($alias)) {
177 177
             // note: changed '' to $for_class
178
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], $for_class);
178
+            return $this->getFqnForAlias($this->aliases[(string) $alias], $for_class);
179 179
         }
180 180
         return $alias;
181 181
     }
Please login to merge, or discard this patch.
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -16,180 +16,180 @@
 block discarded – undo
16 16
  */
17 17
 class ClassInterfaceCache
18 18
 {
19
-    /**
20
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
21
-     *
22
-     * @var string[][] $interfaces
23
-     */
24
-    private $interfaces = array();
25
-
26
-    /**
27
-     * @type string[][] $aliases
28
-     */
29
-    protected $aliases = array();
30
-
31
-
32
-    /**
33
-     * @param string $fqn
34
-     * @return string
35
-     */
36
-    public function getFqn($fqn)
37
-    {
38
-        $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
39
-        return ltrim((string) $fqn, '\\');
40
-    }
41
-
42
-
43
-    /**
44
-     * @param string $fqn
45
-     * @return array
46
-     */
47
-    public function getInterfaces($fqn)
48
-    {
49
-        $fqn = $this->getFqn($fqn);
50
-        // have we already seen this FQCN ?
51
-        if (! array_key_exists($fqn, $this->interfaces)) {
52
-            $this->interfaces[ $fqn ] = array();
53
-            if (class_exists($fqn)) {
54
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
55
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
56
-                    ? $this->interfaces[ $fqn ]
57
-                    : array();
58
-            }
59
-        }
60
-        return $this->interfaces[ $fqn ];
61
-    }
62
-
63
-
64
-    /**
65
-     * @param string $fqn
66
-     * @param string $interface
67
-     * @return bool
68
-     */
69
-    public function hasInterface($fqn, $interface)
70
-    {
71
-        $fqn        = $this->getFqn($fqn);
72
-        $interfaces = $this->getInterfaces($fqn);
73
-        return in_array($interface, $interfaces, true);
74
-    }
75
-
76
-
77
-    /**
78
-     * adds an alias for a classname
79
-     *
80
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
81
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
82
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
83
-     * @throws InvalidAliasException
84
-     */
85
-    public function addAlias($fqn, $alias, $for_class = '')
86
-    {
87
-        $fqn   = $this->getFqn($fqn);
88
-        $alias = $this->getFqn($alias);
89
-        if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
90
-            throw new InvalidAliasException($fqn, $alias);
91
-        }
92
-        // are we adding an alias for a specific class?
93
-        if ($for_class !== '') {
94
-            // make sure it's set up as an array
95
-            if (! isset($this->aliases[ $for_class ])) {
96
-                $this->aliases[ $for_class ] = array();
97
-            }
98
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
99
-            return;
100
-        }
101
-        $this->aliases[ $alias ] = $fqn;
102
-    }
103
-
104
-
105
-    /**
106
-     * returns TRUE if the provided FQN is an alias
107
-     *
108
-     * @param string $fqn
109
-     * @param string $for_class
110
-     * @return bool
111
-     */
112
-    public function isAlias($fqn = '', $for_class = '')
113
-    {
114
-        $fqn = $this->getFqn($fqn);
115
-        if ($this->isAliasForClass($fqn, $for_class)) {
116
-            return true;
117
-        }
118
-        if ($this->isDirectAlias($fqn)) {
119
-            return true;
120
-        }
121
-        return false;
122
-    }
123
-
124
-
125
-    /**
126
-     * returns TRUE if the provided FQN is an alias
127
-     *
128
-     * @param string $fqn
129
-     * @return bool
130
-     */
131
-    protected function isDirectAlias($fqn = '')
132
-    {
133
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
134
-    }
135
-
136
-
137
-    /**
138
-     * returns TRUE if the provided FQN is an alias for the specified class
139
-     *
140
-     * @param string $fqn
141
-     * @param string $for_class
142
-     * @return bool
143
-     */
144
-    protected function isAliasForClass($fqn = '', $for_class = '')
145
-    {
146
-        return (
147
-            $for_class !== ''
148
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
149
-        );
150
-    }
151
-
152
-
153
-    /**
154
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
155
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
156
-     *  for example:
157
-     *      if the following two entries were added to the aliases array:
158
-     *          array(
159
-     *              'interface_alias'           => 'some\namespace\interface'
160
-     *              'some\namespace\interface'  => 'some\namespace\classname'
161
-     *          )
162
-     *      then one could use Loader::getNew( 'interface_alias' )
163
-     *      to load an instance of 'some\namespace\classname'
164
-     *
165
-     * @param string $alias
166
-     * @param string $for_class
167
-     * @return string
168
-     */
169
-    public function getFqnForAlias($alias = '', $for_class = '')
170
-    {
171
-        $alias = $this->getFqn($alias);
172
-        if ($this->isAliasForClass($alias, $for_class)) {
173
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
174
-        }
175
-        if ($this->isDirectAlias($alias)) {
176
-            // note: changed '' to $for_class
177
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], $for_class);
178
-        }
179
-        return $alias;
180
-    }
181
-
182
-
183
-    // public function debug($for_class = '')
184
-    // {
185
-    //     if ($for_class !== '') {
186
-    //         if ( ! isset($this->aliases[ $for_class ])) {
187
-    //             \EEH_Debug_Tools::printr('NOT FOUND', "aliases[ $for_class ]", __FILE__, __LINE__);
188
-    //             return;
189
-    //         }
190
-    //         \EEH_Debug_Tools::printr($this->aliases[ $for_class ], "aliases[ $for_class ]", __FILE__, __LINE__);
191
-    //         return;
192
-    //     }
193
-    //     \EEH_Debug_Tools::printr($this->aliases, '$this->aliases', __FILE__, __LINE__);
194
-    // }
19
+	/**
20
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
21
+	 *
22
+	 * @var string[][] $interfaces
23
+	 */
24
+	private $interfaces = array();
25
+
26
+	/**
27
+	 * @type string[][] $aliases
28
+	 */
29
+	protected $aliases = array();
30
+
31
+
32
+	/**
33
+	 * @param string $fqn
34
+	 * @return string
35
+	 */
36
+	public function getFqn($fqn)
37
+	{
38
+		$fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
39
+		return ltrim((string) $fqn, '\\');
40
+	}
41
+
42
+
43
+	/**
44
+	 * @param string $fqn
45
+	 * @return array
46
+	 */
47
+	public function getInterfaces($fqn)
48
+	{
49
+		$fqn = $this->getFqn($fqn);
50
+		// have we already seen this FQCN ?
51
+		if (! array_key_exists($fqn, $this->interfaces)) {
52
+			$this->interfaces[ $fqn ] = array();
53
+			if (class_exists($fqn)) {
54
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
55
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
56
+					? $this->interfaces[ $fqn ]
57
+					: array();
58
+			}
59
+		}
60
+		return $this->interfaces[ $fqn ];
61
+	}
62
+
63
+
64
+	/**
65
+	 * @param string $fqn
66
+	 * @param string $interface
67
+	 * @return bool
68
+	 */
69
+	public function hasInterface($fqn, $interface)
70
+	{
71
+		$fqn        = $this->getFqn($fqn);
72
+		$interfaces = $this->getInterfaces($fqn);
73
+		return in_array($interface, $interfaces, true);
74
+	}
75
+
76
+
77
+	/**
78
+	 * adds an alias for a classname
79
+	 *
80
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
81
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
82
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
83
+	 * @throws InvalidAliasException
84
+	 */
85
+	public function addAlias($fqn, $alias, $for_class = '')
86
+	{
87
+		$fqn   = $this->getFqn($fqn);
88
+		$alias = $this->getFqn($alias);
89
+		if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
90
+			throw new InvalidAliasException($fqn, $alias);
91
+		}
92
+		// are we adding an alias for a specific class?
93
+		if ($for_class !== '') {
94
+			// make sure it's set up as an array
95
+			if (! isset($this->aliases[ $for_class ])) {
96
+				$this->aliases[ $for_class ] = array();
97
+			}
98
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
99
+			return;
100
+		}
101
+		$this->aliases[ $alias ] = $fqn;
102
+	}
103
+
104
+
105
+	/**
106
+	 * returns TRUE if the provided FQN is an alias
107
+	 *
108
+	 * @param string $fqn
109
+	 * @param string $for_class
110
+	 * @return bool
111
+	 */
112
+	public function isAlias($fqn = '', $for_class = '')
113
+	{
114
+		$fqn = $this->getFqn($fqn);
115
+		if ($this->isAliasForClass($fqn, $for_class)) {
116
+			return true;
117
+		}
118
+		if ($this->isDirectAlias($fqn)) {
119
+			return true;
120
+		}
121
+		return false;
122
+	}
123
+
124
+
125
+	/**
126
+	 * returns TRUE if the provided FQN is an alias
127
+	 *
128
+	 * @param string $fqn
129
+	 * @return bool
130
+	 */
131
+	protected function isDirectAlias($fqn = '')
132
+	{
133
+		return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
134
+	}
135
+
136
+
137
+	/**
138
+	 * returns TRUE if the provided FQN is an alias for the specified class
139
+	 *
140
+	 * @param string $fqn
141
+	 * @param string $for_class
142
+	 * @return bool
143
+	 */
144
+	protected function isAliasForClass($fqn = '', $for_class = '')
145
+	{
146
+		return (
147
+			$for_class !== ''
148
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
149
+		);
150
+	}
151
+
152
+
153
+	/**
154
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
155
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
156
+	 *  for example:
157
+	 *      if the following two entries were added to the aliases array:
158
+	 *          array(
159
+	 *              'interface_alias'           => 'some\namespace\interface'
160
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
161
+	 *          )
162
+	 *      then one could use Loader::getNew( 'interface_alias' )
163
+	 *      to load an instance of 'some\namespace\classname'
164
+	 *
165
+	 * @param string $alias
166
+	 * @param string $for_class
167
+	 * @return string
168
+	 */
169
+	public function getFqnForAlias($alias = '', $for_class = '')
170
+	{
171
+		$alias = $this->getFqn($alias);
172
+		if ($this->isAliasForClass($alias, $for_class)) {
173
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
174
+		}
175
+		if ($this->isDirectAlias($alias)) {
176
+			// note: changed '' to $for_class
177
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], $for_class);
178
+		}
179
+		return $alias;
180
+	}
181
+
182
+
183
+	// public function debug($for_class = '')
184
+	// {
185
+	//     if ($for_class !== '') {
186
+	//         if ( ! isset($this->aliases[ $for_class ])) {
187
+	//             \EEH_Debug_Tools::printr('NOT FOUND', "aliases[ $for_class ]", __FILE__, __LINE__);
188
+	//             return;
189
+	//         }
190
+	//         \EEH_Debug_Tools::printr($this->aliases[ $for_class ], "aliases[ $for_class ]", __FILE__, __LINE__);
191
+	//         return;
192
+	//     }
193
+	//     \EEH_Debug_Tools::printr($this->aliases, '$this->aliases', __FILE__, __LINE__);
194
+	// }
195 195
 }
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodesManager.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function getShortcodes()
83 83
     {
84
-        if (! $this->shortcodes instanceof CollectionInterface) {
84
+        if ( ! $this->shortcodes instanceof CollectionInterface) {
85 85
             $this->shortcodes = $this->loadShortcodesCollection();
86 86
         }
87 87
         return $this->shortcodes;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
139 139
                 $this->getShortcodes()
140 140
             );
141
-            if (! $this->shortcodes instanceof CollectionInterface) {
141
+            if ( ! $this->shortcodes instanceof CollectionInterface) {
142 142
                 throw new InvalidEntityException(
143 143
                     $this->shortcodes,
144 144
                     'CollectionInterface',
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
                     add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11);
173 173
                 }
174 174
                 // add_shortcode() if it has not already been added
175
-                if (! shortcode_exists($shortcode->getTag())) {
175
+                if ( ! shortcode_exists($shortcode->getTag())) {
176 176
                     add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']);
177 177
                 }
178 178
             }
Please login to merge, or discard this patch.
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -29,210 +29,210 @@
 block discarded – undo
29 29
  */
30 30
 class ShortcodesManager
31 31
 {
32
-    /**
33
-     * @type CurrentPage
34
-     */
35
-    protected $current_page;
36
-
37
-    /**
38
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
39
-     */
40
-    private $legacy_shortcodes_manager;
41
-
42
-    /**
43
-     * @var ShortcodeInterface[] $shortcodes
44
-     */
45
-    private $shortcodes;
46
-
47
-
48
-    /**
49
-     * ShortcodesManager constructor
50
-     *
51
-     * @param LegacyShortcodesManager $legacy_shortcodes_manager
52
-     * @param CurrentPage             $current_page
53
-     */
54
-    public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager, CurrentPage $current_page)
55
-    {
56
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
57
-        $this->current_page              = $current_page;
58
-        // assemble a list of installed and active shortcodes
59
-        add_action(
60
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
61
-            [$this, 'registerShortcodes'],
62
-            999
63
-        );
64
-        //  call add_shortcode() for all installed shortcodes
65
-        add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'addShortcodes']);
66
-        // check content for shortcodes the old way
67
-        add_action('parse_query', [$this->legacy_shortcodes_manager, 'initializeShortcodes'], 5);
68
-        // check content for shortcodes the NEW more efficient way
69
-        add_action('template_redirect', [$this, 'templateRedirect'], 999);
70
-    }
71
-
72
-
73
-    /**
74
-     * @return CollectionInterface|ShortcodeInterface[]
75
-     * @throws InvalidIdentifierException
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidFilePathException
78
-     * @throws InvalidEntityException
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidClassException
81
-     */
82
-    public function getShortcodes()
83
-    {
84
-        if (! $this->shortcodes instanceof CollectionInterface) {
85
-            $this->shortcodes = $this->loadShortcodesCollection();
86
-        }
87
-        return $this->shortcodes;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return CollectionInterface|ShortcodeInterface[]
93
-     * @throws InvalidIdentifierException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidFilePathException
96
-     * @throws InvalidEntityException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidClassException
99
-     */
100
-    protected function loadShortcodesCollection()
101
-    {
102
-        $loader = new CollectionLoader(
103
-            new CollectionDetails(
104
-            // collection name
105
-                'shortcodes',
106
-                // collection interface
107
-                'EventEspresso\core\services\shortcodes\ShortcodeInterface',
108
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
109
-                ['EventEspresso\core\domain\entities\shortcodes'],
110
-                // filepaths to classes to add
111
-                [],
112
-                // file mask to use if parsing folder for files to add
113
-                '',
114
-                // what to use as identifier for collection entities
115
-                // using CLASS NAME prevents duplicates (works like a singleton)
116
-                CollectionDetails::ID_CLASS_NAME
117
-            )
118
-        );
119
-        return $loader->getCollection();
120
-    }
121
-
122
-
123
-    /**
124
-     * @return void
125
-     * @throws DomainException
126
-     * @throws InvalidInterfaceException
127
-     * @throws InvalidIdentifierException
128
-     * @throws InvalidFilePathException
129
-     * @throws InvalidEntityException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidClassException
132
-     * @throws Exception
133
-     */
134
-    public function registerShortcodes()
135
-    {
136
-        try {
137
-            $this->shortcodes = apply_filters(
138
-                'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
139
-                $this->getShortcodes()
140
-            );
141
-            if (! $this->shortcodes instanceof CollectionInterface) {
142
-                throw new InvalidEntityException(
143
-                    $this->shortcodes,
144
-                    'CollectionInterface',
145
-                    sprintf(
146
-                        esc_html__(
147
-                            'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
148
-                            'event_espresso'
149
-                        ),
150
-                        is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
151
-                    )
152
-                );
153
-            }
154
-            $this->legacy_shortcodes_manager->registerShortcodes();
155
-        } catch (Exception $exception) {
156
-            new ExceptionStackTraceDisplay($exception);
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * @return void
163
-     * @throws Exception
164
-     */
165
-    public function addShortcodes()
166
-    {
167
-        try {
168
-            // cycle thru shortcode folders
169
-            foreach ($this->shortcodes as $shortcode) {
170
-                if ($shortcode instanceof EnqueueAssetsInterface) {
171
-                    add_action('wp_enqueue_scripts', [$shortcode, 'registerScriptsAndStylesheets'], 10);
172
-                    add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11);
173
-                }
174
-                // add_shortcode() if it has not already been added
175
-                if (! shortcode_exists($shortcode->getTag())) {
176
-                    add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']);
177
-                }
178
-            }
179
-            $this->legacy_shortcodes_manager->addShortcodes();
180
-        } catch (Exception $exception) {
181
-            new ExceptionStackTraceDisplay($exception);
182
-        }
183
-    }
184
-
185
-
186
-    /**
187
-     * callback for the "template_redirect" hook point
188
-     * checks posts for EE shortcodes, and initializes them,
189
-     * then toggles filter switch that loads core default assets
190
-     *
191
-     * @return void
192
-     */
193
-    public function templateRedirect()
194
-    {
195
-        global $wp_query;
196
-        if (empty($wp_query->posts)) {
197
-            return;
198
-        }
199
-        $load_assets = false;
200
-        // array of posts displayed in current request
201
-        $posts = is_array($wp_query->posts) ? $wp_query->posts : [$wp_query->posts];
202
-        foreach ($posts as $post) {
203
-            // now check post content and excerpt for EE shortcodes
204
-            $load_assets = $this->parseContentForShortcodes($post->post_content)
205
-                ? true
206
-                : $load_assets;
207
-        }
208
-        if ($load_assets) {
209
-            $this->current_page->setEspressoPage(true);
210
-            add_filter('FHEE_load_css', '__return_true');
211
-            add_filter('FHEE_load_js', '__return_true');
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * checks supplied content against list of shortcodes,
218
-     * then initializes any found shortcodes, and returns true.
219
-     * returns false if no shortcodes found.
220
-     *
221
-     * @param string $content
222
-     * @return bool
223
-     */
224
-    public function parseContentForShortcodes($content)
225
-    {
226
-        if (empty($this->shortcodes)) {
227
-            return false;
228
-        }
229
-        $has_shortcode = false;
230
-        foreach ($this->shortcodes as $shortcode) {
231
-            if (has_shortcode($content, $shortcode->getTag())) {
232
-                $shortcode->initializeShortcode();
233
-                $has_shortcode = true;
234
-            }
235
-        }
236
-        return $has_shortcode;
237
-    }
32
+	/**
33
+	 * @type CurrentPage
34
+	 */
35
+	protected $current_page;
36
+
37
+	/**
38
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
39
+	 */
40
+	private $legacy_shortcodes_manager;
41
+
42
+	/**
43
+	 * @var ShortcodeInterface[] $shortcodes
44
+	 */
45
+	private $shortcodes;
46
+
47
+
48
+	/**
49
+	 * ShortcodesManager constructor
50
+	 *
51
+	 * @param LegacyShortcodesManager $legacy_shortcodes_manager
52
+	 * @param CurrentPage             $current_page
53
+	 */
54
+	public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager, CurrentPage $current_page)
55
+	{
56
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
57
+		$this->current_page              = $current_page;
58
+		// assemble a list of installed and active shortcodes
59
+		add_action(
60
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
61
+			[$this, 'registerShortcodes'],
62
+			999
63
+		);
64
+		//  call add_shortcode() for all installed shortcodes
65
+		add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'addShortcodes']);
66
+		// check content for shortcodes the old way
67
+		add_action('parse_query', [$this->legacy_shortcodes_manager, 'initializeShortcodes'], 5);
68
+		// check content for shortcodes the NEW more efficient way
69
+		add_action('template_redirect', [$this, 'templateRedirect'], 999);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @return CollectionInterface|ShortcodeInterface[]
75
+	 * @throws InvalidIdentifierException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidFilePathException
78
+	 * @throws InvalidEntityException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidClassException
81
+	 */
82
+	public function getShortcodes()
83
+	{
84
+		if (! $this->shortcodes instanceof CollectionInterface) {
85
+			$this->shortcodes = $this->loadShortcodesCollection();
86
+		}
87
+		return $this->shortcodes;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return CollectionInterface|ShortcodeInterface[]
93
+	 * @throws InvalidIdentifierException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidFilePathException
96
+	 * @throws InvalidEntityException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidClassException
99
+	 */
100
+	protected function loadShortcodesCollection()
101
+	{
102
+		$loader = new CollectionLoader(
103
+			new CollectionDetails(
104
+			// collection name
105
+				'shortcodes',
106
+				// collection interface
107
+				'EventEspresso\core\services\shortcodes\ShortcodeInterface',
108
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
109
+				['EventEspresso\core\domain\entities\shortcodes'],
110
+				// filepaths to classes to add
111
+				[],
112
+				// file mask to use if parsing folder for files to add
113
+				'',
114
+				// what to use as identifier for collection entities
115
+				// using CLASS NAME prevents duplicates (works like a singleton)
116
+				CollectionDetails::ID_CLASS_NAME
117
+			)
118
+		);
119
+		return $loader->getCollection();
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return void
125
+	 * @throws DomainException
126
+	 * @throws InvalidInterfaceException
127
+	 * @throws InvalidIdentifierException
128
+	 * @throws InvalidFilePathException
129
+	 * @throws InvalidEntityException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidClassException
132
+	 * @throws Exception
133
+	 */
134
+	public function registerShortcodes()
135
+	{
136
+		try {
137
+			$this->shortcodes = apply_filters(
138
+				'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
139
+				$this->getShortcodes()
140
+			);
141
+			if (! $this->shortcodes instanceof CollectionInterface) {
142
+				throw new InvalidEntityException(
143
+					$this->shortcodes,
144
+					'CollectionInterface',
145
+					sprintf(
146
+						esc_html__(
147
+							'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
148
+							'event_espresso'
149
+						),
150
+						is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
151
+					)
152
+				);
153
+			}
154
+			$this->legacy_shortcodes_manager->registerShortcodes();
155
+		} catch (Exception $exception) {
156
+			new ExceptionStackTraceDisplay($exception);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * @return void
163
+	 * @throws Exception
164
+	 */
165
+	public function addShortcodes()
166
+	{
167
+		try {
168
+			// cycle thru shortcode folders
169
+			foreach ($this->shortcodes as $shortcode) {
170
+				if ($shortcode instanceof EnqueueAssetsInterface) {
171
+					add_action('wp_enqueue_scripts', [$shortcode, 'registerScriptsAndStylesheets'], 10);
172
+					add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11);
173
+				}
174
+				// add_shortcode() if it has not already been added
175
+				if (! shortcode_exists($shortcode->getTag())) {
176
+					add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']);
177
+				}
178
+			}
179
+			$this->legacy_shortcodes_manager->addShortcodes();
180
+		} catch (Exception $exception) {
181
+			new ExceptionStackTraceDisplay($exception);
182
+		}
183
+	}
184
+
185
+
186
+	/**
187
+	 * callback for the "template_redirect" hook point
188
+	 * checks posts for EE shortcodes, and initializes them,
189
+	 * then toggles filter switch that loads core default assets
190
+	 *
191
+	 * @return void
192
+	 */
193
+	public function templateRedirect()
194
+	{
195
+		global $wp_query;
196
+		if (empty($wp_query->posts)) {
197
+			return;
198
+		}
199
+		$load_assets = false;
200
+		// array of posts displayed in current request
201
+		$posts = is_array($wp_query->posts) ? $wp_query->posts : [$wp_query->posts];
202
+		foreach ($posts as $post) {
203
+			// now check post content and excerpt for EE shortcodes
204
+			$load_assets = $this->parseContentForShortcodes($post->post_content)
205
+				? true
206
+				: $load_assets;
207
+		}
208
+		if ($load_assets) {
209
+			$this->current_page->setEspressoPage(true);
210
+			add_filter('FHEE_load_css', '__return_true');
211
+			add_filter('FHEE_load_js', '__return_true');
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * checks supplied content against list of shortcodes,
218
+	 * then initializes any found shortcodes, and returns true.
219
+	 * returns false if no shortcodes found.
220
+	 *
221
+	 * @param string $content
222
+	 * @return bool
223
+	 */
224
+	public function parseContentForShortcodes($content)
225
+	{
226
+		if (empty($this->shortcodes)) {
227
+			return false;
228
+		}
229
+		$has_shortcode = false;
230
+		foreach ($this->shortcodes as $shortcode) {
231
+			if (has_shortcode($content, $shortcode->getTag())) {
232
+				$shortcode->initializeShortcode();
233
+				$has_shortcode = true;
234
+			}
235
+		}
236
+		return $has_shortcode;
237
+	}
238 238
 }
Please login to merge, or discard this patch.