Completed
Branch dev (a3ade4)
by
unknown
10:45
created
core/domain/services/admin/privacy/erasure/EraseAnswers.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -16,88 +16,88 @@
 block discarded – undo
16 16
  */
17 17
 class EraseAnswers implements PersonalDataEraserInterface
18 18
 {
19
-    /**
20
-     * @var EEM_Answer
21
-     */
22
-    protected $answer_model;
19
+	/**
20
+	 * @var EEM_Answer
21
+	 */
22
+	protected $answer_model;
23 23
 
24
-    /**
25
-     * @var EEM_Question
26
-     */
27
-    protected $question_model;
24
+	/**
25
+	 * @var EEM_Question
26
+	 */
27
+	protected $question_model;
28 28
 
29
-    /**
30
-     * EraseAnswers constructor.
31
-     *
32
-     * @param EEM_Answer   $answer_model
33
-     * @param EEM_Question $question_model
34
-     */
35
-    public function __construct(EEM_Answer $answer_model, EEM_Question $question_model)
36
-    {
37
-        $this->answer_model = $answer_model;
38
-        $this->question_model = $question_model;
39
-    }
29
+	/**
30
+	 * EraseAnswers constructor.
31
+	 *
32
+	 * @param EEM_Answer   $answer_model
33
+	 * @param EEM_Question $question_model
34
+	 */
35
+	public function __construct(EEM_Answer $answer_model, EEM_Question $question_model)
36
+	{
37
+		$this->answer_model = $answer_model;
38
+		$this->question_model = $question_model;
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Gets a translated string name for the data eraser
44
-     *
45
-     * @return string
46
-     */
47
-    public function name()
48
-    {
49
-        return esc_html__('Event Espresso Registration Answers', 'event_espresso');
50
-    }
42
+	/**
43
+	 * Gets a translated string name for the data eraser
44
+	 *
45
+	 * @return string
46
+	 */
47
+	public function name()
48
+	{
49
+		return esc_html__('Event Espresso Registration Answers', 'event_espresso');
50
+	}
51 51
 
52
-    /**
53
-     * Erases a "page" of personal user data
54
-     *
55
-     * @return array {
56
-     * @type boolean $items_removed  whether items were removed successfully or not
57
-     * @type boolean $items_retained whether any items were skipped or not
58
-     * @type array   $messages       values are messages to show
59
-     * @type boolean $done           whether this eraser is done or has more pages
60
-     *               }
61
-     */
62
-    public function erase($email_address, $page = 1)
63
-    {
64
-        $multi_answer_enum_question_types = $this->question_model->question_types_in_category('multi-answer-enum');
65
-        $normal_questions_updated = $this->answer_model->update(
66
-            array(
67
-                'ANS_value' => '',
68
-            ),
69
-            array(
70
-                array(
71
-                    'Registration.Attendee.ATT_email' => $email_address,
72
-                    'Question.QST_type'               => array(
73
-                        'NOT_IN',
74
-                        $multi_answer_enum_question_types,
75
-                    ),
76
-                ),
77
-            )
78
-        );
79
-        $multi_value_questions_updated = $this->answer_model->update(
80
-            array(
81
-                'ANS_value' => array(),
82
-            ),
83
-            array(
84
-                array(
85
-                    'Registration.Attendee.ATT_email' => $email_address,
86
-                    'Question.QST_type'               => array(
87
-                        'IN',
88
-                        $multi_answer_enum_question_types,
89
-                    ),
90
-                ),
91
-            )
92
-        );
52
+	/**
53
+	 * Erases a "page" of personal user data
54
+	 *
55
+	 * @return array {
56
+	 * @type boolean $items_removed  whether items were removed successfully or not
57
+	 * @type boolean $items_retained whether any items were skipped or not
58
+	 * @type array   $messages       values are messages to show
59
+	 * @type boolean $done           whether this eraser is done or has more pages
60
+	 *               }
61
+	 */
62
+	public function erase($email_address, $page = 1)
63
+	{
64
+		$multi_answer_enum_question_types = $this->question_model->question_types_in_category('multi-answer-enum');
65
+		$normal_questions_updated = $this->answer_model->update(
66
+			array(
67
+				'ANS_value' => '',
68
+			),
69
+			array(
70
+				array(
71
+					'Registration.Attendee.ATT_email' => $email_address,
72
+					'Question.QST_type'               => array(
73
+						'NOT_IN',
74
+						$multi_answer_enum_question_types,
75
+					),
76
+				),
77
+			)
78
+		);
79
+		$multi_value_questions_updated = $this->answer_model->update(
80
+			array(
81
+				'ANS_value' => array(),
82
+			),
83
+			array(
84
+				array(
85
+					'Registration.Attendee.ATT_email' => $email_address,
86
+					'Question.QST_type'               => array(
87
+						'IN',
88
+						$multi_answer_enum_question_types,
89
+					),
90
+				),
91
+			)
92
+		);
93 93
 
94
-        return array(
95
-            'items_removed'  => (bool) $normal_questions_updated || (bool) $multi_value_questions_updated,
96
-            'items_retained' => false, // always false in this example
97
-            'messages'       => array(), // no messages in this example
98
-            'done'           => true,
99
-        );
100
-    }
94
+		return array(
95
+			'items_removed'  => (bool) $normal_questions_updated || (bool) $multi_value_questions_updated,
96
+			'items_retained' => false, // always false in this example
97
+			'messages'       => array(), // no messages in this example
98
+			'done'           => true,
99
+		);
100
+	}
101 101
 }
102 102
 // End of file EraseAnswers.php
103 103
 // Location: EventEspresso\core\domain\services\privacy\erasure/EraseAnswers.php
Please login to merge, or discard this patch.
core/services/privacy/export/PersonalDataExporterInterface.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -14,35 +14,35 @@
 block discarded – undo
14 14
  */
15 15
 interface PersonalDataExporterInterface
16 16
 {
17
-    /**
18
-     * Gets the Translated name of this exporter
19
-     *
20
-     * @return string
21
-     */
22
-    public function name();
17
+	/**
18
+	 * Gets the Translated name of this exporter
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function name();
23 23
 
24
-    /**
25
-     * Returns data for export.
26
-     *
27
-     * @param string    $email_address ,
28
-     * @param int       $page          starts at 1, not 0
29
-     * @return array {
30
-     * @type array      $data          {
31
-     * @type array {
32
-     * @type string     $group_id      (not translated, same for all exports)
33
-     * @type string     $group_label   (translated string)
34
-     * @type string|int $item_id
35
-     * @type array      $data          {
36
-     * @type array {
37
-     * @type string     $name          what's shown in the left-column of the export row
38
-     * @type string     $value         what's showin the right-column of the export row
39
-     *                                 }
40
-     *                                 }
41
-     *                                 }
42
-     *                                 }
43
-     *                                 }
44
-     */
45
-    public function export($email_address, $page = 1);
24
+	/**
25
+	 * Returns data for export.
26
+	 *
27
+	 * @param string    $email_address ,
28
+	 * @param int       $page          starts at 1, not 0
29
+	 * @return array {
30
+	 * @type array      $data          {
31
+	 * @type array {
32
+	 * @type string     $group_id      (not translated, same for all exports)
33
+	 * @type string     $group_label   (translated string)
34
+	 * @type string|int $item_id
35
+	 * @type array      $data          {
36
+	 * @type array {
37
+	 * @type string     $name          what's shown in the left-column of the export row
38
+	 * @type string     $value         what's showin the right-column of the export row
39
+	 *                                 }
40
+	 *                                 }
41
+	 *                                 }
42
+	 *                                 }
43
+	 *                                 }
44
+	 */
45
+	public function export($email_address, $page = 1);
46 46
 }
47 47
 // End of file PersonalDataExporterInterface.php
48 48
 // Location: EventEspresso\core\domain\services\admin/PersonalDataExporterInterface.php
Please login to merge, or discard this patch.
core/services/privacy/export/PersonalDataExporterManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
         // load all the privacy policy stuff
44 44
         // add post policy text
45 45
         foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
46
-            $exporters[ get_class($exporter) ] = array(
46
+            $exporters[get_class($exporter)] = array(
47 47
                 'exporter_friendly_name' => $exporter->name(),
48 48
                 'callback'               => array($exporter, 'export'),
49 49
             );
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -22,68 +22,68 @@
 block discarded – undo
22 22
  */
23 23
 class PersonalDataExporterManager
24 24
 {
25
-    public function __construct()
26
-    {
27
-        add_filter(
28
-            'wp_privacy_personal_data_exporters',
29
-            array($this, 'hookInExporters')
30
-        );
31
-    }
25
+	public function __construct()
26
+	{
27
+		add_filter(
28
+			'wp_privacy_personal_data_exporters',
29
+			array($this, 'hookInExporters')
30
+		);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * Adds EE's exporters to the list of WP exporters
36
-     *
37
-     * @param array $exporters
38
-     * @return array
39
-     */
40
-    public function hookInExporters($exporters)
41
-    {
42
-        // load all the privacy policy stuff
43
-        // add post policy text
44
-        foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
45
-            $exporters[ get_class($exporter) ] = array(
46
-                'exporter_friendly_name' => $exporter->name(),
47
-                'callback'               => array($exporter, 'export'),
48
-            );
49
-        }
50
-        return $exporters;
51
-    }
34
+	/**
35
+	 * Adds EE's exporters to the list of WP exporters
36
+	 *
37
+	 * @param array $exporters
38
+	 * @return array
39
+	 */
40
+	public function hookInExporters($exporters)
41
+	{
42
+		// load all the privacy policy stuff
43
+		// add post policy text
44
+		foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
45
+			$exporters[ get_class($exporter) ] = array(
46
+				'exporter_friendly_name' => $exporter->name(),
47
+				'callback'               => array($exporter, 'export'),
48
+			);
49
+		}
50
+		return $exporters;
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @return CollectionInterface|PersonalDataExporterInterface[]
56
-     * @throws InvalidIdentifierException
57
-     * @throws InvalidInterfaceException
58
-     * @throws InvalidFilePathException
59
-     * @throws InvalidEntityException
60
-     * @throws InvalidDataTypeException
61
-     * @throws InvalidClassException
62
-     */
63
-    protected function loadPrivateDataExporterCollection()
64
-    {
65
-        $loader = new CollectionLoader(
66
-            new CollectionDetails(
67
-                // collection name
68
-                'personal_data_exporters',
69
-                // collection interface
70
-                'EventEspresso\core\services\privacy\export\PersonalDataExporterInterface',
71
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
72
-                apply_filters(
73
-                    'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
74
-                    array('EventEspresso\core\domain\services\admin\privacy\export')
75
-                ),
76
-                // filepaths to classes to add
77
-                array(),
78
-                // file mask to use if parsing folder for files to add
79
-                '',
80
-                // what to use as identifier for collection entities
81
-                // using CLASS NAME prevents duplicates (works like a singleton)
82
-                CollectionDetails::ID_CLASS_NAME
83
-            )
84
-        );
85
-        return $loader->getCollection();
86
-    }
54
+	/**
55
+	 * @return CollectionInterface|PersonalDataExporterInterface[]
56
+	 * @throws InvalidIdentifierException
57
+	 * @throws InvalidInterfaceException
58
+	 * @throws InvalidFilePathException
59
+	 * @throws InvalidEntityException
60
+	 * @throws InvalidDataTypeException
61
+	 * @throws InvalidClassException
62
+	 */
63
+	protected function loadPrivateDataExporterCollection()
64
+	{
65
+		$loader = new CollectionLoader(
66
+			new CollectionDetails(
67
+				// collection name
68
+				'personal_data_exporters',
69
+				// collection interface
70
+				'EventEspresso\core\services\privacy\export\PersonalDataExporterInterface',
71
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
72
+				apply_filters(
73
+					'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
74
+					array('EventEspresso\core\domain\services\admin\privacy\export')
75
+				),
76
+				// filepaths to classes to add
77
+				array(),
78
+				// file mask to use if parsing folder for files to add
79
+				'',
80
+				// what to use as identifier for collection entities
81
+				// using CLASS NAME prevents duplicates (works like a singleton)
82
+				CollectionDetails::ID_CLASS_NAME
83
+			)
84
+		);
85
+		return $loader->getCollection();
86
+	}
87 87
 }
88 88
 
89 89
 // End of file PersonalDataExporterManager.php
Please login to merge, or discard this patch.
core/services/privacy/erasure/PersonalDataEraserManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
         // load all the privacy policy stuff
41 41
         // add post policy text
42 42
         foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
43
-            $erasers[ get_class($eraser) ] = array(
43
+            $erasers[get_class($eraser)] = array(
44 44
                 'eraser_friendly_name' => $eraser->name(),
45 45
                 'callback'             => array($eraser, 'erase'),
46 46
             );
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -22,65 +22,65 @@
 block discarded – undo
22 22
  */
23 23
 class PersonalDataEraserManager
24 24
 {
25
-    public function __construct()
26
-    {
27
-        add_filter(
28
-            'wp_privacy_personal_data_erasers',
29
-            array($this, 'hookInErasers')
30
-        );
31
-    }
25
+	public function __construct()
26
+	{
27
+		add_filter(
28
+			'wp_privacy_personal_data_erasers',
29
+			array($this, 'hookInErasers')
30
+		);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * For all the registered `PrivateDataEraserInterface`s, add them as erasers
36
-     */
37
-    public function hookInErasers($erasers)
38
-    {
39
-        // load all the privacy policy stuff
40
-        // add post policy text
41
-        foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
42
-            $erasers[ get_class($eraser) ] = array(
43
-                'eraser_friendly_name' => $eraser->name(),
44
-                'callback'             => array($eraser, 'erase'),
45
-            );
46
-        }
47
-        return $erasers;
48
-    }
34
+	/**
35
+	 * For all the registered `PrivateDataEraserInterface`s, add them as erasers
36
+	 */
37
+	public function hookInErasers($erasers)
38
+	{
39
+		// load all the privacy policy stuff
40
+		// add post policy text
41
+		foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
42
+			$erasers[ get_class($eraser) ] = array(
43
+				'eraser_friendly_name' => $eraser->name(),
44
+				'callback'             => array($eraser, 'erase'),
45
+			);
46
+		}
47
+		return $erasers;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return CollectionInterface|PersonalDataEraserInterface[]
53
-     * @throws InvalidIdentifierException
54
-     * @throws InvalidInterfaceException
55
-     * @throws InvalidFilePathException
56
-     * @throws InvalidEntityException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidClassException
59
-     */
60
-    protected function loadPrivateDataEraserCollection()
61
-    {
62
-        $loader = new CollectionLoader(
63
-            new CollectionDetails(
64
-                // collection name
65
-                'privacy_erasers',
66
-                // collection interface
67
-                'EventEspresso\core\services\privacy\erasure\PersonalDataEraserInterface',
68
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
69
-                apply_filters(
70
-                    'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
71
-                    array('EventEspresso\core\domain\services\admin\privacy\erasure')
72
-                ),
73
-                // filepaths to classes to add
74
-                array(),
75
-                // file mask to use if parsing folder for files to add
76
-                '',
77
-                // what to use as identifier for collection entities
78
-                // using CLASS NAME prevents duplicates (works like a singleton)
79
-                CollectionDetails::ID_CLASS_NAME
80
-            )
81
-        );
82
-        return $loader->getCollection();
83
-    }
51
+	/**
52
+	 * @return CollectionInterface|PersonalDataEraserInterface[]
53
+	 * @throws InvalidIdentifierException
54
+	 * @throws InvalidInterfaceException
55
+	 * @throws InvalidFilePathException
56
+	 * @throws InvalidEntityException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidClassException
59
+	 */
60
+	protected function loadPrivateDataEraserCollection()
61
+	{
62
+		$loader = new CollectionLoader(
63
+			new CollectionDetails(
64
+				// collection name
65
+				'privacy_erasers',
66
+				// collection interface
67
+				'EventEspresso\core\services\privacy\erasure\PersonalDataEraserInterface',
68
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
69
+				apply_filters(
70
+					'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
71
+					array('EventEspresso\core\domain\services\admin\privacy\erasure')
72
+				),
73
+				// filepaths to classes to add
74
+				array(),
75
+				// file mask to use if parsing folder for files to add
76
+				'',
77
+				// what to use as identifier for collection entities
78
+				// using CLASS NAME prevents duplicates (works like a singleton)
79
+				CollectionDetails::ID_CLASS_NAME
80
+			)
81
+		);
82
+		return $loader->getCollection();
83
+	}
84 84
 }
85 85
 // End of file PersonalDataEraserManager.php
86 86
 // Location: EventEspresso\core\domain\services\admin/PersonalDataEraserManager.php
Please login to merge, or discard this patch.
core/services/request/middleware/RecommendedVersions.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
         $this->request = $request;
33 33
         $this->response = $response;
34 34
         // check required WP version
35
-        if (! $this->minimumWordPressVersionRequired()) {
35
+        if ( ! $this->minimumWordPressVersionRequired()) {
36 36
             $this->request->unSetRequestParam('activate', true);
37 37
             add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
38 38
             $this->response->terminateRequest();
39 39
             $this->response->deactivatePlugin();
40 40
         }
41 41
         // check recommended PHP version
42
-        if (! $this->minimumPhpVersionRecommended()) {
42
+        if ( ! $this->minimumPhpVersionRecommended()) {
43 43
             $this->displayMinimumRecommendedPhpVersionNotice();
44 44
         }
45 45
         // upcoming required version
46
-        if (! $this->upcomingRequiredPhpVersion()) {
46
+        if ( ! $this->upcomingRequiredPhpVersion()) {
47 47
             $this->displayUpcomingRequiredVersion();
48 48
         }
49 49
         $this->response = $this->processRequestStack($this->request, $this->response);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         if ($this->request->isAdmin()) {
144 144
             new PersistentAdminNotice(
145
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
+                'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended',
146 146
                 sprintf(
147 147
                     esc_html__(
148 148
                         'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
             && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181 181
             && current_user_can('update_plugins')
182 182
         ) {
183
-            add_action('admin_notices', function () {
183
+            add_action('admin_notices', function() {
184 184
                 echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185 185
                      . sprintf(
186 186
                          esc_html__(
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -18,183 +18,183 @@
 block discarded – undo
18 18
  */
19 19
 class RecommendedVersions extends Middleware
20 20
 {
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     * @throws InvalidDataTypeException
28
-     */
29
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
-    {
31
-        $this->request = $request;
32
-        $this->response = $response;
33
-        // check required WP version
34
-        if (! $this->minimumWordPressVersionRequired()) {
35
-            $this->request->unSetRequestParam('activate', true);
36
-            add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
37
-            $this->response->terminateRequest();
38
-            $this->response->deactivatePlugin();
39
-        }
40
-        // check recommended PHP version
41
-        if (! $this->minimumPhpVersionRecommended()) {
42
-            $this->displayMinimumRecommendedPhpVersionNotice();
43
-        }
44
-        // upcoming required version
45
-        if (! $this->upcomingRequiredPhpVersion()) {
46
-            $this->displayUpcomingRequiredVersion();
47
-        }
48
-        $this->response = $this->processRequestStack($this->request, $this->response);
49
-        return $this->response;
50
-    }
51
-
52
-
53
-    /**
54
-     * Helper method to assess installed wp version against given values.
55
-     * By default this compares the required minimum version of WP for EE against the installed version of WP
56
-     * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
57
-     * against) so consider that when sending in your values.
58
-     *
59
-     * @param string $version_to_check
60
-     * @param string $operator
61
-     * @return bool
62
-     */
63
-    public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
64
-    {
65
-        global $wp_version;
66
-        return version_compare(
67
-            // first account for wp_version being pre-release
68
-            // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
69
-            strpos($wp_version, '-') > 0
70
-                ? substr($wp_version, 0, strpos($wp_version, '-'))
71
-                : $wp_version,
72
-            $version_to_check,
73
-            $operator
74
-        );
75
-    }
76
-
77
-
78
-    /**
79
-     * @return boolean
80
-     */
81
-    private function minimumWordPressVersionRequired()
82
-    {
83
-        return RecommendedVersions::compareWordPressVersion();
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $min_version
89
-     * @return boolean
90
-     */
91
-    private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
92
-    {
93
-        return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
94
-    }
95
-
96
-
97
-    /**
98
-     * @return boolean
99
-     */
100
-    private function minimumPhpVersionRecommended()
101
-    {
102
-        return $this->checkPhpVersion();
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function minimumWpVersionError()
110
-    {
111
-        global $wp_version;
112
-        ?>
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 * @throws InvalidDataTypeException
28
+	 */
29
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
+	{
31
+		$this->request = $request;
32
+		$this->response = $response;
33
+		// check required WP version
34
+		if (! $this->minimumWordPressVersionRequired()) {
35
+			$this->request->unSetRequestParam('activate', true);
36
+			add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
37
+			$this->response->terminateRequest();
38
+			$this->response->deactivatePlugin();
39
+		}
40
+		// check recommended PHP version
41
+		if (! $this->minimumPhpVersionRecommended()) {
42
+			$this->displayMinimumRecommendedPhpVersionNotice();
43
+		}
44
+		// upcoming required version
45
+		if (! $this->upcomingRequiredPhpVersion()) {
46
+			$this->displayUpcomingRequiredVersion();
47
+		}
48
+		$this->response = $this->processRequestStack($this->request, $this->response);
49
+		return $this->response;
50
+	}
51
+
52
+
53
+	/**
54
+	 * Helper method to assess installed wp version against given values.
55
+	 * By default this compares the required minimum version of WP for EE against the installed version of WP
56
+	 * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
57
+	 * against) so consider that when sending in your values.
58
+	 *
59
+	 * @param string $version_to_check
60
+	 * @param string $operator
61
+	 * @return bool
62
+	 */
63
+	public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
64
+	{
65
+		global $wp_version;
66
+		return version_compare(
67
+			// first account for wp_version being pre-release
68
+			// (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
69
+			strpos($wp_version, '-') > 0
70
+				? substr($wp_version, 0, strpos($wp_version, '-'))
71
+				: $wp_version,
72
+			$version_to_check,
73
+			$operator
74
+		);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return boolean
80
+	 */
81
+	private function minimumWordPressVersionRequired()
82
+	{
83
+		return RecommendedVersions::compareWordPressVersion();
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $min_version
89
+	 * @return boolean
90
+	 */
91
+	private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
92
+	{
93
+		return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return boolean
99
+	 */
100
+	private function minimumPhpVersionRecommended()
101
+	{
102
+		return $this->checkPhpVersion();
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function minimumWpVersionError()
110
+	{
111
+		global $wp_version;
112
+		?>
113 113
         <div class="error">
114 114
             <p>
115 115
                 <?php
116
-                printf(
117
-                    esc_html__(
118
-                        'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
119
-                        'event_espresso'
120
-                    ),
121
-                    EE_MIN_WP_VER_REQUIRED,
122
-                    $wp_version,
123
-                    '<br/>',
124
-                    '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
125
-                );
126
-                ?>
116
+				printf(
117
+					esc_html__(
118
+						'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
119
+						'event_espresso'
120
+					),
121
+					EE_MIN_WP_VER_REQUIRED,
122
+					$wp_version,
123
+					'<br/>',
124
+					'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
125
+				);
126
+				?>
127 127
             </p>
128 128
         </div>
129 129
         <?php
130
-    }
131
-
132
-
133
-    /**
134
-     *    _display_minimum_recommended_php_version_notice
135
-     *
136
-     * @access private
137
-     * @return void
138
-     * @throws InvalidDataTypeException
139
-     */
140
-    private function displayMinimumRecommendedPhpVersionNotice()
141
-    {
142
-        if ($this->request->isAdmin()) {
143
-            new PersistentAdminNotice(
144
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
-                sprintf(
146
-                    esc_html__(
147
-                        'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
148
-                        'event_espresso'
149
-                    ),
150
-                    EE_MIN_PHP_VER_RECOMMENDED,
151
-                    PHP_VERSION,
152
-                    '<br/>',
153
-                    '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
154
-                )
155
-            );
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns whether the provided php version number is less than the current version of php installed on the server.
162
-     *
163
-     * @param string $version_required
164
-     * @return bool
165
-     */
166
-    private function upcomingRequiredPhpVersion($version_required = '5.5')
167
-    {
168
-        return true;
169
-        // return $this->checkPhpVersion($version_required);
170
-    }
171
-
172
-
173
-    /**
174
-     *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
175
-     */
176
-    private function displayUpcomingRequiredVersion()
177
-    {
178
-        if (
179
-            $this->request->isAdmin()
180
-            && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
-            && current_user_can('update_plugins')
182
-        ) {
183
-            add_action('admin_notices', function () {
184
-                echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
-                     . sprintf(
186
-                         esc_html__(
187
-                             'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
-                             'event_espresso'
189
-                         ),
190
-                         '<strong>',
191
-                         '</strong>',
192
-                         PHP_VERSION,
193
-                         '<a href="https://wordpress.org/support/upgrade-php/">',
194
-                         '</a>'
195
-                     )
196
-                     . '</p></div>';
197
-            });
198
-        }
199
-    }
130
+	}
131
+
132
+
133
+	/**
134
+	 *    _display_minimum_recommended_php_version_notice
135
+	 *
136
+	 * @access private
137
+	 * @return void
138
+	 * @throws InvalidDataTypeException
139
+	 */
140
+	private function displayMinimumRecommendedPhpVersionNotice()
141
+	{
142
+		if ($this->request->isAdmin()) {
143
+			new PersistentAdminNotice(
144
+				'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
+				sprintf(
146
+					esc_html__(
147
+						'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
148
+						'event_espresso'
149
+					),
150
+					EE_MIN_PHP_VER_RECOMMENDED,
151
+					PHP_VERSION,
152
+					'<br/>',
153
+					'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
154
+				)
155
+			);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns whether the provided php version number is less than the current version of php installed on the server.
162
+	 *
163
+	 * @param string $version_required
164
+	 * @return bool
165
+	 */
166
+	private function upcomingRequiredPhpVersion($version_required = '5.5')
167
+	{
168
+		return true;
169
+		// return $this->checkPhpVersion($version_required);
170
+	}
171
+
172
+
173
+	/**
174
+	 *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
175
+	 */
176
+	private function displayUpcomingRequiredVersion()
177
+	{
178
+		if (
179
+			$this->request->isAdmin()
180
+			&& apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
+			&& current_user_can('update_plugins')
182
+		) {
183
+			add_action('admin_notices', function () {
184
+				echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
+					 . sprintf(
186
+						 esc_html__(
187
+							 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
+							 'event_espresso'
189
+						 ),
190
+						 '<strong>',
191
+						 '</strong>',
192
+						 PHP_VERSION,
193
+						 '<a href="https://wordpress.org/support/upgrade-php/">',
194
+						 '</a>'
195
+					 )
196
+					 . '</p></div>';
197
+			});
198
+		}
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -21,192 +21,192 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * returns TRUE or FALSE
110
-     * depending on whether the object is within the Collection
111
-     * based on the supplied $identifier and type
112
-     *
113
-     * @param  mixed $identifier
114
-     * @param string $type
115
-     * @return bool
116
-     * @since 4.9.63.p
117
-     */
118
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
-    {
120
-        $this->rewind();
121
-        while ($this->valid()) {
122
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
-                $this->rewind();
124
-                return true;
125
-            }
126
-            $this->next();
127
-        }
128
-        return false;
129
-    }
130
-
131
-
132
-    /**
133
-     * returns TRUE or FALSE
134
-     * depending on whether the Javascript Asset is within the Collection
135
-     * based on the supplied $identifier
136
-     *
137
-     * @param  mixed $identifier
138
-     * @return bool
139
-     * @since 4.9.63.p
140
-     */
141
-    public function hasJavascriptAsset($identifier)
142
-    {
143
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
-    }
145
-
146
-
147
-    /**
148
-     * returns TRUE or FALSE
149
-     * depending on whether the Stylesheet Asset is within the Collection
150
-     * based on the supplied $identifier
151
-     *
152
-     * @param  mixed $identifier
153
-     * @return bool
154
-     * @since 4.9.63.p
155
-     */
156
-    public function hasStylesheetAsset($identifier)
157
-    {
158
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
-    }
160
-
161
-    /**
162
-     * returns the object from the Collection
163
-     * based on the supplied $identifier and type
164
-     *
165
-     * @param  mixed $identifier
166
-     * @param string $type
167
-     * @return JavascriptAsset|StylesheetAsset
168
-     * @since 4.9.63.p
169
-     */
170
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
-    {
172
-        $this->rewind();
173
-        while ($this->valid()) {
174
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
-                /** @var JavascriptAsset|StylesheetAsset $object */
176
-                $object = $this->current();
177
-                $this->rewind();
178
-                return $object;
179
-            }
180
-            $this->next();
181
-        }
182
-        return null;
183
-    }
184
-
185
-
186
-    /**
187
-     * returns the Stylesheet Asset from the Collection
188
-     * based on the supplied $identifier
189
-     *
190
-     * @param  mixed $identifier
191
-     * @return StylesheetAsset
192
-     * @since 4.9.63.p
193
-     */
194
-    public function getStylesheetAsset($identifier)
195
-    {
196
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
-    }
198
-
199
-
200
-    /**
201
-     * returns the Javascript Asset from the Collection
202
-     * based on the supplied $identifier
203
-     *
204
-     * @param  mixed $identifier
205
-     * @return JavascriptAsset
206
-     * @since 4.9.63.p
207
-     */
208
-    public function getJavascriptAsset($identifier)
209
-    {
210
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * returns TRUE or FALSE
110
+	 * depending on whether the object is within the Collection
111
+	 * based on the supplied $identifier and type
112
+	 *
113
+	 * @param  mixed $identifier
114
+	 * @param string $type
115
+	 * @return bool
116
+	 * @since 4.9.63.p
117
+	 */
118
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
119
+	{
120
+		$this->rewind();
121
+		while ($this->valid()) {
122
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
123
+				$this->rewind();
124
+				return true;
125
+			}
126
+			$this->next();
127
+		}
128
+		return false;
129
+	}
130
+
131
+
132
+	/**
133
+	 * returns TRUE or FALSE
134
+	 * depending on whether the Javascript Asset is within the Collection
135
+	 * based on the supplied $identifier
136
+	 *
137
+	 * @param  mixed $identifier
138
+	 * @return bool
139
+	 * @since 4.9.63.p
140
+	 */
141
+	public function hasJavascriptAsset($identifier)
142
+	{
143
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
144
+	}
145
+
146
+
147
+	/**
148
+	 * returns TRUE or FALSE
149
+	 * depending on whether the Stylesheet Asset is within the Collection
150
+	 * based on the supplied $identifier
151
+	 *
152
+	 * @param  mixed $identifier
153
+	 * @return bool
154
+	 * @since 4.9.63.p
155
+	 */
156
+	public function hasStylesheetAsset($identifier)
157
+	{
158
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
159
+	}
160
+
161
+	/**
162
+	 * returns the object from the Collection
163
+	 * based on the supplied $identifier and type
164
+	 *
165
+	 * @param  mixed $identifier
166
+	 * @param string $type
167
+	 * @return JavascriptAsset|StylesheetAsset
168
+	 * @since 4.9.63.p
169
+	 */
170
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
171
+	{
172
+		$this->rewind();
173
+		while ($this->valid()) {
174
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
175
+				/** @var JavascriptAsset|StylesheetAsset $object */
176
+				$object = $this->current();
177
+				$this->rewind();
178
+				return $object;
179
+			}
180
+			$this->next();
181
+		}
182
+		return null;
183
+	}
184
+
185
+
186
+	/**
187
+	 * returns the Stylesheet Asset from the Collection
188
+	 * based on the supplied $identifier
189
+	 *
190
+	 * @param  mixed $identifier
191
+	 * @return StylesheetAsset
192
+	 * @since 4.9.63.p
193
+	 */
194
+	public function getStylesheetAsset($identifier)
195
+	{
196
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
197
+	}
198
+
199
+
200
+	/**
201
+	 * returns the Javascript Asset from the Collection
202
+	 * based on the supplied $identifier
203
+	 *
204
+	 * @param  mixed $identifier
205
+	 * @return JavascriptAsset
206
+	 * @since 4.9.63.p
207
+	 */
208
+	public function getJavascriptAsset($identifier)
209
+	{
210
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
211
+	}
212 212
 }
Please login to merge, or discard this patch.
strategies/display/EE_Radio_Button_Display_Strategy.strategy.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
             $html .= $this->_attributes_string(
33 33
                 array(
34 34
                     'for' => $html_id,
35
-                    'id' => $html_id . '-lbl',
35
+                    'id' => $html_id.'-lbl',
36 36
                     'class' => apply_filters(
37 37
                         'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
-                        'ee-radio-label-after' . $label_size_class,
38
+                        'ee-radio-label-after'.$label_size_class,
39 39
                         $this,
40 40
                         $input,
41 41
                         $value
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
             $html .= '>&nbsp;';
64 64
             $html .= $display_text;
65
-            $html .= EEH_HTML::nl(-1, 'radio') . '</label>';
65
+            $html .= EEH_HTML::nl(-1, 'radio').'</label>';
66 66
         }
67 67
         $html .= EEH_HTML::div('', '', 'clear-float');
68 68
         $html .= EEH_HTML::divx();
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -11,61 +11,61 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Radio_Button_Display_Strategy extends EE_Compound_Input_Display_Strategy
13 13
 {
14
-    /**
15
-     *
16
-     * @throws EE_Error
17
-     * @return string of html to display the field
18
-     */
19
-    public function display()
20
-    {
21
-        $input = $this->get_input();
22
-        $input->set_label_sizes();
23
-        $label_size_class = $input->get_label_size_class();
24
-        $html = '';
25
-        foreach ($input->options() as $value => $display_text) {
26
-            $value = $input->get_normalization_strategy()->unnormalize($value);
14
+	/**
15
+	 *
16
+	 * @throws EE_Error
17
+	 * @return string of html to display the field
18
+	 */
19
+	public function display()
20
+	{
21
+		$input = $this->get_input();
22
+		$input->set_label_sizes();
23
+		$label_size_class = $input->get_label_size_class();
24
+		$html = '';
25
+		foreach ($input->options() as $value => $display_text) {
26
+			$value = $input->get_normalization_strategy()->unnormalize($value);
27 27
 
28
-            $html_id = $this->get_sub_input_id($value);
29
-            $html .= EEH_HTML::nl(0, 'radio');
28
+			$html_id = $this->get_sub_input_id($value);
29
+			$html .= EEH_HTML::nl(0, 'radio');
30 30
 
31
-            $html .= $this->_opening_tag('label');
32
-            $html .= $this->_attributes_string(
33
-                array(
34
-                    'for' => $html_id,
35
-                    'id' => $html_id . '-lbl',
36
-                    'class' => apply_filters(
37
-                        'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
-                        'ee-radio-label-after' . $label_size_class,
39
-                        $this,
40
-                        $input,
41
-                        $value
42
-                    )
43
-                )
44
-            );
45
-            $html .= '>';
46
-            $html .= EEH_HTML::nl(1, 'radio');
47
-            $html .= $this->_opening_tag('input');
48
-            $attributes = array(
49
-                'id' => $html_id,
50
-                'name' => $input->html_name(),
51
-                'class' => $input->html_class(),
52
-                'style' => $input->html_style(),
53
-                'type' => 'radio',
54
-                'value' => $value,
55
-                0 => $input->other_html_attributes(),
56
-                'data-question_label' => $input->html_label_id()
57
-            );
58
-            if ($input->raw_value() === $value) {
59
-                $attributes['checked'] = 'checked';
60
-            }
61
-            $html .= $this->_attributes_string($attributes);
31
+			$html .= $this->_opening_tag('label');
32
+			$html .= $this->_attributes_string(
33
+				array(
34
+					'for' => $html_id,
35
+					'id' => $html_id . '-lbl',
36
+					'class' => apply_filters(
37
+						'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class',
38
+						'ee-radio-label-after' . $label_size_class,
39
+						$this,
40
+						$input,
41
+						$value
42
+					)
43
+				)
44
+			);
45
+			$html .= '>';
46
+			$html .= EEH_HTML::nl(1, 'radio');
47
+			$html .= $this->_opening_tag('input');
48
+			$attributes = array(
49
+				'id' => $html_id,
50
+				'name' => $input->html_name(),
51
+				'class' => $input->html_class(),
52
+				'style' => $input->html_style(),
53
+				'type' => 'radio',
54
+				'value' => $value,
55
+				0 => $input->other_html_attributes(),
56
+				'data-question_label' => $input->html_label_id()
57
+			);
58
+			if ($input->raw_value() === $value) {
59
+				$attributes['checked'] = 'checked';
60
+			}
61
+			$html .= $this->_attributes_string($attributes);
62 62
 
63
-            $html .= '>&nbsp;';
64
-            $html .= $display_text;
65
-            $html .= EEH_HTML::nl(-1, 'radio') . '</label>';
66
-        }
67
-        $html .= EEH_HTML::div('', '', 'clear-float');
68
-        $html .= EEH_HTML::divx();
69
-        return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input);
70
-    }
63
+			$html .= '>&nbsp;';
64
+			$html .= $display_text;
65
+			$html .= EEH_HTML::nl(-1, 'radio') . '</label>';
66
+		}
67
+		$html .= EEH_HTML::div('', '', 'clear-float');
68
+		$html .= EEH_HTML::divx();
69
+		return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
core/services/collections/Collection.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     protected function setCollectionInterface($collection_interface)
68 68
     {
69
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
69
+        if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) {
70 70
             throw new InvalidInterfaceException($collection_interface);
71 71
         }
72 72
         $this->collection_interface = $collection_interface;
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
     protected function setCollectionIdentifier()
112 112
     {
113 113
         // hash a few collection details
114
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
114
+        $identifier = md5(spl_object_hash($this).$this->collection_interface.time());
115 115
         // grab a few characters from the start, middle, and end of the hash
116 116
         $id = array();
117 117
         for ($x = 0; $x < 19; $x += 9) {
118 118
             $id[] = substr($identifier, $x, 3);
119 119
         }
120
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
120
+        $this->collection_identifier = $this->collection_name.'-'.strtoupper(implode('-', $id));
121 121
     }
122 122
 
123 123
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function add($object, $identifier = null)
137 137
     {
138
-        if (! $object instanceof $this->collection_interface) {
138
+        if ( ! $object instanceof $this->collection_interface) {
139 139
             throw new InvalidEntityException($object, $this->collection_interface);
140 140
         }
141 141
         if ($this->contains($object)) {
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      */
352 352
     public function indexOf($object)
353 353
     {
354
-        if (! $this->contains($object)) {
354
+        if ( ! $this->contains($object)) {
355 355
             return false;
356 356
         }
357 357
         foreach ($this as $index => $obj) {
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
             $remaining_objects = $this->slice($index, $this->count() - $index);
421 421
             foreach ($remaining_objects as $key => $remaining_object) {
422 422
                 // we need to grab the identifiers for each object and use them as keys
423
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
423
+                $remaining_objects[$remaining_object->getInfo()] = $remaining_object;
424 424
                 // and then remove the object from the current tracking array
425
-                unset($remaining_objects[ $key ]);
425
+                unset($remaining_objects[$key]);
426 426
                 // and then remove it from the Collection
427 427
                 $this->detach($remaining_object);
428 428
             }
@@ -446,17 +446,17 @@  discard block
 block discarded – undo
446 446
      */
447 447
     public function insertAt($objects, $index)
448 448
     {
449
-        if (! is_array($objects)) {
449
+        if ( ! is_array($objects)) {
450 450
             $objects = array($objects);
451 451
         }
452 452
         // check to ensure that objects don't already exist in the collection
453 453
         foreach ($objects as $key => $object) {
454 454
             if ($this->contains($object)) {
455
-                unset($objects[ $key ]);
455
+                unset($objects[$key]);
456 456
             }
457 457
         }
458 458
         // do we have any objects left?
459
-        if (! $objects) {
459
+        if ( ! $objects) {
460 460
             return;
461 461
         }
462 462
         // detach any objects at or past this index
Please login to merge, or discard this patch.
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -18,514 +18,514 @@
 block discarded – undo
18 18
  */
19 19
 class Collection extends SplObjectStorage implements CollectionInterface
20 20
 {
21
-    /**
22
-     * a unique string for identifying this collection
23
-     *
24
-     * @type string $collection_identifier
25
-     */
26
-    protected $collection_identifier;
27
-
28
-
29
-    /**
30
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
31
-     * this should be set from within the child class constructor
32
-     *
33
-     * @type string $interface
34
-     */
35
-    protected $collection_interface;
36
-
37
-    /**
38
-     * a short dash separated string describing the contents of this collection
39
-     * used as the base for the $collection_identifier
40
-     * defaults to the class short name if not set
41
-     *
42
-     * @type string $collection_identifier
43
-     */
44
-    protected $collection_name;
45
-
46
-
47
-    /**
48
-     * Collection constructor
49
-     *
50
-     * @param string $collection_interface
51
-     * @param string $collection_name
52
-     * @throws InvalidInterfaceException
53
-     */
54
-    public function __construct($collection_interface, $collection_name = '')
55
-    {
56
-        $this->setCollectionInterface($collection_interface);
57
-        $this->setCollectionName($collection_name);
58
-        $this->setCollectionIdentifier();
59
-    }
60
-
61
-
62
-    /**
63
-     * @return string
64
-     * @since 4.10.33.p
65
-     */
66
-    public function collectionInterface(): string
67
-    {
68
-        return $this->collection_interface;
69
-    }
70
-
71
-
72
-    /**
73
-     * setCollectionInterface
74
-     *
75
-     * @param  string $collection_interface
76
-     * @throws InvalidInterfaceException
77
-     */
78
-    protected function setCollectionInterface($collection_interface)
79
-    {
80
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
81
-            throw new InvalidInterfaceException($collection_interface);
82
-        }
83
-        $this->collection_interface = $collection_interface;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return string
89
-     */
90
-    public function collectionName()
91
-    {
92
-        return $this->collection_name;
93
-    }
94
-
95
-
96
-    /**
97
-     * @param string $collection_name
98
-     */
99
-    protected function setCollectionName($collection_name)
100
-    {
101
-        $this->collection_name = ! empty($collection_name)
102
-            ? sanitize_key($collection_name)
103
-            : basename(str_replace('\\', '/', get_class($this)));
104
-    }
105
-
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function collectionIdentifier()
111
-    {
112
-        return $this->collection_identifier;
113
-    }
114
-
115
-
116
-    /**
117
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
118
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
119
-     *
120
-     * @return void
121
-     */
122
-    protected function setCollectionIdentifier()
123
-    {
124
-        // hash a few collection details
125
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
126
-        // grab a few characters from the start, middle, and end of the hash
127
-        $id = array();
128
-        for ($x = 0; $x < 19; $x += 9) {
129
-            $id[] = substr($identifier, $x, 3);
130
-        }
131
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
132
-    }
133
-
134
-
135
-    /**
136
-     * add
137
-     * attaches an object to the Collection
138
-     * and sets any supplied data associated with the current iterator entry
139
-     * by calling EE_Object_Collection::set_identifier()
140
-     *
141
-     * @param        $object
142
-     * @param  mixed $identifier
143
-     * @return bool
144
-     * @throws InvalidEntityException
145
-     * @throws DuplicateCollectionIdentifierException
146
-     */
147
-    public function add($object, $identifier = null)
148
-    {
149
-        if (! $object instanceof $this->collection_interface) {
150
-            throw new InvalidEntityException($object, $this->collection_interface);
151
-        }
152
-        if ($this->contains($object)) {
153
-            throw new DuplicateCollectionIdentifierException($identifier);
154
-        }
155
-        $this->attach($object);
156
-        $this->setIdentifier($object, $identifier);
157
-        return $this->contains($object);
158
-    }
159
-
160
-
161
-    /**
162
-     * getIdentifier
163
-     * if no $identifier is supplied, then the spl_object_hash() is used
164
-     *
165
-     * @param        $object
166
-     * @param  mixed $identifier
167
-     * @return bool
168
-     */
169
-    public function getIdentifier($object, $identifier = null)
170
-    {
171
-        return ! empty($identifier)
172
-            ? $identifier
173
-            : spl_object_hash($object);
174
-    }
175
-
176
-
177
-    /**
178
-     * setIdentifier
179
-     * Sets the data associated with an object in the Collection
180
-     * if no $identifier is supplied, then the spl_object_hash() is used
181
-     *
182
-     * @param        $object
183
-     * @param  mixed $identifier
184
-     * @return bool
185
-     */
186
-    public function setIdentifier($object, $identifier = null)
187
-    {
188
-        $identifier = $this->getIdentifier($object, $identifier);
189
-        $this->rewind();
190
-        while ($this->valid()) {
191
-            if ($object === $this->current()) {
192
-                $this->setInfo($identifier);
193
-                $this->rewind();
194
-                return true;
195
-            }
196
-            $this->next();
197
-        }
198
-        return false;
199
-    }
200
-
201
-
202
-    /**
203
-     * get
204
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
205
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
206
-     *
207
-     * @param mixed $identifier
208
-     * @return mixed
209
-     */
210
-    public function get($identifier)
211
-    {
212
-        $this->rewind();
213
-        while ($this->valid()) {
214
-            if ($identifier === $this->getInfo()) {
215
-                $object = $this->current();
216
-                $this->rewind();
217
-                return $object;
218
-            }
219
-            $this->next();
220
-        }
221
-        return null;
222
-    }
223
-
224
-
225
-    /**
226
-     * has
227
-     * returns TRUE or FALSE
228
-     * depending on whether the object is within the Collection
229
-     * based on the supplied $identifier
230
-     *
231
-     * @param  mixed $identifier
232
-     * @return bool
233
-     */
234
-    public function has($identifier)
235
-    {
236
-        $this->rewind();
237
-        while ($this->valid()) {
238
-            if ($identifier === $this->getInfo()) {
239
-                $this->rewind();
240
-                return true;
241
-            }
242
-            $this->next();
243
-        }
244
-        return false;
245
-    }
246
-
247
-
248
-    /**
249
-     * hasObject
250
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
251
-     *
252
-     * @param $object
253
-     * @return bool
254
-     */
255
-    public function hasObject($object)
256
-    {
257
-        return $this->contains($object);
258
-    }
259
-
260
-
261
-    /**
262
-     * hasObjects
263
-     * returns true if there are objects within the Collection, and false if it is empty
264
-     *
265
-     * @return bool
266
-     */
267
-    public function hasObjects()
268
-    {
269
-        return $this->count() !== 0;
270
-    }
271
-
272
-
273
-    /**
274
-     * isEmpty
275
-     * returns true if there are no objects within the Collection, and false if there are
276
-     *
277
-     * @return bool
278
-     */
279
-    public function isEmpty()
280
-    {
281
-        return $this->count() === 0;
282
-    }
283
-
284
-
285
-    /**
286
-     * remove
287
-     * detaches an object from the Collection
288
-     *
289
-     * @param $object
290
-     * @return bool
291
-     */
292
-    public function remove($object)
293
-    {
294
-        $this->detach($object);
295
-        return true;
296
-    }
297
-
298
-
299
-    /**
300
-     * setCurrent
301
-     * advances pointer to the object whose identifier matches that which was provided
302
-     *
303
-     * @param mixed $identifier
304
-     * @return boolean
305
-     */
306
-    public function setCurrent($identifier)
307
-    {
308
-        $this->rewind();
309
-        while ($this->valid()) {
310
-            if ($identifier === $this->getInfo()) {
311
-                return true;
312
-            }
313
-            $this->next();
314
-        }
315
-        return false;
316
-    }
317
-
318
-
319
-    /**
320
-     * setCurrentUsingObject
321
-     * advances pointer to the provided object
322
-     *
323
-     * @param $object
324
-     * @return boolean
325
-     */
326
-    public function setCurrentUsingObject($object)
327
-    {
328
-        $this->rewind();
329
-        while ($this->valid()) {
330
-            if ($this->current() === $object) {
331
-                return true;
332
-            }
333
-            $this->next();
334
-        }
335
-        return false;
336
-    }
337
-
338
-
339
-    /**
340
-     * Returns the object occupying the index before the current object,
341
-     * unless this is already the first object, in which case it just returns the first object
342
-     *
343
-     * @return mixed
344
-     */
345
-    public function previous()
346
-    {
347
-        $index = $this->indexOf($this->current());
348
-        if ($index === 0) {
349
-            return $this->current();
350
-        }
351
-        $index--;
352
-        return $this->objectAtIndex($index);
353
-    }
354
-
355
-
356
-    /**
357
-     * Returns the index of a given object, or false if not found
358
-     *
359
-     * @see http://stackoverflow.com/a/8736013
360
-     * @param $object
361
-     * @return boolean|int|string
362
-     */
363
-    public function indexOf($object)
364
-    {
365
-        if (! $this->contains($object)) {
366
-            return false;
367
-        }
368
-        foreach ($this as $index => $obj) {
369
-            if ($obj === $object) {
370
-                return $index;
371
-            }
372
-        }
373
-        return false;
374
-    }
375
-
376
-
377
-    /**
378
-     * Returns the object at the given index
379
-     *
380
-     * @see http://stackoverflow.com/a/8736013
381
-     * @param int $index
382
-     * @return mixed
383
-     */
384
-    public function objectAtIndex($index)
385
-    {
386
-        $iterator = new LimitIterator($this, $index, 1);
387
-        $iterator->rewind();
388
-        return $iterator->current();
389
-    }
390
-
391
-
392
-    /**
393
-     * Returns the sequence of objects as specified by the offset and length
394
-     *
395
-     * @see http://stackoverflow.com/a/8736013
396
-     * @param int $offset
397
-     * @param int $length
398
-     * @return array
399
-     */
400
-    public function slice($offset, $length)
401
-    {
402
-        $slice = array();
403
-        $iterator = new LimitIterator($this, $offset, $length);
404
-        foreach ($iterator as $object) {
405
-            $slice[] = $object;
406
-        }
407
-        return $slice;
408
-    }
409
-
410
-
411
-    /**
412
-     * Inserts an object at a certain point
413
-     *
414
-     * @see http://stackoverflow.com/a/8736013
415
-     * @param mixed $object A single object
416
-     * @param int   $index
417
-     * @param mixed $identifier
418
-     * @return bool
419
-     * @throws DuplicateCollectionIdentifierException
420
-     * @throws InvalidEntityException
421
-     */
422
-    public function insertObjectAt($object, $index, $identifier = null)
423
-    {
424
-        // check to ensure that objects don't already exist in the collection
425
-        if ($this->has($identifier)) {
426
-            throw new DuplicateCollectionIdentifierException($identifier);
427
-        }
428
-        // detach any objects at or past this index
429
-        $remaining_objects = array();
430
-        if ($index < $this->count()) {
431
-            $remaining_objects = $this->slice($index, $this->count() - $index);
432
-            foreach ($remaining_objects as $key => $remaining_object) {
433
-                // we need to grab the identifiers for each object and use them as keys
434
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
435
-                // and then remove the object from the current tracking array
436
-                unset($remaining_objects[ $key ]);
437
-                // and then remove it from the Collection
438
-                $this->detach($remaining_object);
439
-            }
440
-        }
441
-        // add the new object we're splicing in
442
-        $this->add($object, $identifier);
443
-        // attach the objects we previously detached
444
-        foreach ($remaining_objects as $key => $remaining_object) {
445
-            $this->add($remaining_object, $key);
446
-        }
447
-        return $this->contains($object);
448
-    }
449
-
450
-
451
-    /**
452
-     * Inserts an object (or an array of objects) at a certain point
453
-     *
454
-     * @see http://stackoverflow.com/a/8736013
455
-     * @param mixed $objects A single object or an array of objects
456
-     * @param int   $index
457
-     */
458
-    public function insertAt($objects, $index)
459
-    {
460
-        if (! is_array($objects)) {
461
-            $objects = array($objects);
462
-        }
463
-        // check to ensure that objects don't already exist in the collection
464
-        foreach ($objects as $key => $object) {
465
-            if ($this->contains($object)) {
466
-                unset($objects[ $key ]);
467
-            }
468
-        }
469
-        // do we have any objects left?
470
-        if (! $objects) {
471
-            return;
472
-        }
473
-        // detach any objects at or past this index
474
-        $remaining = array();
475
-        if ($index < $this->count()) {
476
-            $remaining = $this->slice($index, $this->count() - $index);
477
-            foreach ($remaining as $object) {
478
-                $this->detach($object);
479
-            }
480
-        }
481
-        // add the new objects we're splicing in
482
-        foreach ($objects as $object) {
483
-            $this->attach($object);
484
-        }
485
-        // attach the objects we previously detached
486
-        foreach ($remaining as $object) {
487
-            $this->attach($object);
488
-        }
489
-    }
490
-
491
-
492
-    /**
493
-     * Removes the object at the given index
494
-     *
495
-     * @see http://stackoverflow.com/a/8736013
496
-     * @param int $index
497
-     */
498
-    public function removeAt($index)
499
-    {
500
-        $this->detach($this->objectAtIndex($index));
501
-    }
502
-
503
-
504
-    /**
505
-     * detaches ALL objects from the Collection
506
-     */
507
-    public function detachAll()
508
-    {
509
-        $this->rewind();
510
-        while ($this->valid()) {
511
-            $object = $this->current();
512
-            $this->next();
513
-            $this->detach($object);
514
-        }
515
-    }
516
-
517
-
518
-    /**
519
-     * unsets and detaches ALL objects from the Collection
520
-     */
521
-    public function trashAndDetachAll()
522
-    {
523
-        $this->rewind();
524
-        while ($this->valid()) {
525
-            $object = $this->current();
526
-            $this->next();
527
-            $this->detach($object);
528
-            unset($object);
529
-        }
530
-    }
21
+	/**
22
+	 * a unique string for identifying this collection
23
+	 *
24
+	 * @type string $collection_identifier
25
+	 */
26
+	protected $collection_identifier;
27
+
28
+
29
+	/**
30
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
31
+	 * this should be set from within the child class constructor
32
+	 *
33
+	 * @type string $interface
34
+	 */
35
+	protected $collection_interface;
36
+
37
+	/**
38
+	 * a short dash separated string describing the contents of this collection
39
+	 * used as the base for the $collection_identifier
40
+	 * defaults to the class short name if not set
41
+	 *
42
+	 * @type string $collection_identifier
43
+	 */
44
+	protected $collection_name;
45
+
46
+
47
+	/**
48
+	 * Collection constructor
49
+	 *
50
+	 * @param string $collection_interface
51
+	 * @param string $collection_name
52
+	 * @throws InvalidInterfaceException
53
+	 */
54
+	public function __construct($collection_interface, $collection_name = '')
55
+	{
56
+		$this->setCollectionInterface($collection_interface);
57
+		$this->setCollectionName($collection_name);
58
+		$this->setCollectionIdentifier();
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return string
64
+	 * @since 4.10.33.p
65
+	 */
66
+	public function collectionInterface(): string
67
+	{
68
+		return $this->collection_interface;
69
+	}
70
+
71
+
72
+	/**
73
+	 * setCollectionInterface
74
+	 *
75
+	 * @param  string $collection_interface
76
+	 * @throws InvalidInterfaceException
77
+	 */
78
+	protected function setCollectionInterface($collection_interface)
79
+	{
80
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
81
+			throw new InvalidInterfaceException($collection_interface);
82
+		}
83
+		$this->collection_interface = $collection_interface;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function collectionName()
91
+	{
92
+		return $this->collection_name;
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param string $collection_name
98
+	 */
99
+	protected function setCollectionName($collection_name)
100
+	{
101
+		$this->collection_name = ! empty($collection_name)
102
+			? sanitize_key($collection_name)
103
+			: basename(str_replace('\\', '/', get_class($this)));
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function collectionIdentifier()
111
+	{
112
+		return $this->collection_identifier;
113
+	}
114
+
115
+
116
+	/**
117
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
118
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function setCollectionIdentifier()
123
+	{
124
+		// hash a few collection details
125
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
126
+		// grab a few characters from the start, middle, and end of the hash
127
+		$id = array();
128
+		for ($x = 0; $x < 19; $x += 9) {
129
+			$id[] = substr($identifier, $x, 3);
130
+		}
131
+		$this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
132
+	}
133
+
134
+
135
+	/**
136
+	 * add
137
+	 * attaches an object to the Collection
138
+	 * and sets any supplied data associated with the current iterator entry
139
+	 * by calling EE_Object_Collection::set_identifier()
140
+	 *
141
+	 * @param        $object
142
+	 * @param  mixed $identifier
143
+	 * @return bool
144
+	 * @throws InvalidEntityException
145
+	 * @throws DuplicateCollectionIdentifierException
146
+	 */
147
+	public function add($object, $identifier = null)
148
+	{
149
+		if (! $object instanceof $this->collection_interface) {
150
+			throw new InvalidEntityException($object, $this->collection_interface);
151
+		}
152
+		if ($this->contains($object)) {
153
+			throw new DuplicateCollectionIdentifierException($identifier);
154
+		}
155
+		$this->attach($object);
156
+		$this->setIdentifier($object, $identifier);
157
+		return $this->contains($object);
158
+	}
159
+
160
+
161
+	/**
162
+	 * getIdentifier
163
+	 * if no $identifier is supplied, then the spl_object_hash() is used
164
+	 *
165
+	 * @param        $object
166
+	 * @param  mixed $identifier
167
+	 * @return bool
168
+	 */
169
+	public function getIdentifier($object, $identifier = null)
170
+	{
171
+		return ! empty($identifier)
172
+			? $identifier
173
+			: spl_object_hash($object);
174
+	}
175
+
176
+
177
+	/**
178
+	 * setIdentifier
179
+	 * Sets the data associated with an object in the Collection
180
+	 * if no $identifier is supplied, then the spl_object_hash() is used
181
+	 *
182
+	 * @param        $object
183
+	 * @param  mixed $identifier
184
+	 * @return bool
185
+	 */
186
+	public function setIdentifier($object, $identifier = null)
187
+	{
188
+		$identifier = $this->getIdentifier($object, $identifier);
189
+		$this->rewind();
190
+		while ($this->valid()) {
191
+			if ($object === $this->current()) {
192
+				$this->setInfo($identifier);
193
+				$this->rewind();
194
+				return true;
195
+			}
196
+			$this->next();
197
+		}
198
+		return false;
199
+	}
200
+
201
+
202
+	/**
203
+	 * get
204
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
205
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
206
+	 *
207
+	 * @param mixed $identifier
208
+	 * @return mixed
209
+	 */
210
+	public function get($identifier)
211
+	{
212
+		$this->rewind();
213
+		while ($this->valid()) {
214
+			if ($identifier === $this->getInfo()) {
215
+				$object = $this->current();
216
+				$this->rewind();
217
+				return $object;
218
+			}
219
+			$this->next();
220
+		}
221
+		return null;
222
+	}
223
+
224
+
225
+	/**
226
+	 * has
227
+	 * returns TRUE or FALSE
228
+	 * depending on whether the object is within the Collection
229
+	 * based on the supplied $identifier
230
+	 *
231
+	 * @param  mixed $identifier
232
+	 * @return bool
233
+	 */
234
+	public function has($identifier)
235
+	{
236
+		$this->rewind();
237
+		while ($this->valid()) {
238
+			if ($identifier === $this->getInfo()) {
239
+				$this->rewind();
240
+				return true;
241
+			}
242
+			$this->next();
243
+		}
244
+		return false;
245
+	}
246
+
247
+
248
+	/**
249
+	 * hasObject
250
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
251
+	 *
252
+	 * @param $object
253
+	 * @return bool
254
+	 */
255
+	public function hasObject($object)
256
+	{
257
+		return $this->contains($object);
258
+	}
259
+
260
+
261
+	/**
262
+	 * hasObjects
263
+	 * returns true if there are objects within the Collection, and false if it is empty
264
+	 *
265
+	 * @return bool
266
+	 */
267
+	public function hasObjects()
268
+	{
269
+		return $this->count() !== 0;
270
+	}
271
+
272
+
273
+	/**
274
+	 * isEmpty
275
+	 * returns true if there are no objects within the Collection, and false if there are
276
+	 *
277
+	 * @return bool
278
+	 */
279
+	public function isEmpty()
280
+	{
281
+		return $this->count() === 0;
282
+	}
283
+
284
+
285
+	/**
286
+	 * remove
287
+	 * detaches an object from the Collection
288
+	 *
289
+	 * @param $object
290
+	 * @return bool
291
+	 */
292
+	public function remove($object)
293
+	{
294
+		$this->detach($object);
295
+		return true;
296
+	}
297
+
298
+
299
+	/**
300
+	 * setCurrent
301
+	 * advances pointer to the object whose identifier matches that which was provided
302
+	 *
303
+	 * @param mixed $identifier
304
+	 * @return boolean
305
+	 */
306
+	public function setCurrent($identifier)
307
+	{
308
+		$this->rewind();
309
+		while ($this->valid()) {
310
+			if ($identifier === $this->getInfo()) {
311
+				return true;
312
+			}
313
+			$this->next();
314
+		}
315
+		return false;
316
+	}
317
+
318
+
319
+	/**
320
+	 * setCurrentUsingObject
321
+	 * advances pointer to the provided object
322
+	 *
323
+	 * @param $object
324
+	 * @return boolean
325
+	 */
326
+	public function setCurrentUsingObject($object)
327
+	{
328
+		$this->rewind();
329
+		while ($this->valid()) {
330
+			if ($this->current() === $object) {
331
+				return true;
332
+			}
333
+			$this->next();
334
+		}
335
+		return false;
336
+	}
337
+
338
+
339
+	/**
340
+	 * Returns the object occupying the index before the current object,
341
+	 * unless this is already the first object, in which case it just returns the first object
342
+	 *
343
+	 * @return mixed
344
+	 */
345
+	public function previous()
346
+	{
347
+		$index = $this->indexOf($this->current());
348
+		if ($index === 0) {
349
+			return $this->current();
350
+		}
351
+		$index--;
352
+		return $this->objectAtIndex($index);
353
+	}
354
+
355
+
356
+	/**
357
+	 * Returns the index of a given object, or false if not found
358
+	 *
359
+	 * @see http://stackoverflow.com/a/8736013
360
+	 * @param $object
361
+	 * @return boolean|int|string
362
+	 */
363
+	public function indexOf($object)
364
+	{
365
+		if (! $this->contains($object)) {
366
+			return false;
367
+		}
368
+		foreach ($this as $index => $obj) {
369
+			if ($obj === $object) {
370
+				return $index;
371
+			}
372
+		}
373
+		return false;
374
+	}
375
+
376
+
377
+	/**
378
+	 * Returns the object at the given index
379
+	 *
380
+	 * @see http://stackoverflow.com/a/8736013
381
+	 * @param int $index
382
+	 * @return mixed
383
+	 */
384
+	public function objectAtIndex($index)
385
+	{
386
+		$iterator = new LimitIterator($this, $index, 1);
387
+		$iterator->rewind();
388
+		return $iterator->current();
389
+	}
390
+
391
+
392
+	/**
393
+	 * Returns the sequence of objects as specified by the offset and length
394
+	 *
395
+	 * @see http://stackoverflow.com/a/8736013
396
+	 * @param int $offset
397
+	 * @param int $length
398
+	 * @return array
399
+	 */
400
+	public function slice($offset, $length)
401
+	{
402
+		$slice = array();
403
+		$iterator = new LimitIterator($this, $offset, $length);
404
+		foreach ($iterator as $object) {
405
+			$slice[] = $object;
406
+		}
407
+		return $slice;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Inserts an object at a certain point
413
+	 *
414
+	 * @see http://stackoverflow.com/a/8736013
415
+	 * @param mixed $object A single object
416
+	 * @param int   $index
417
+	 * @param mixed $identifier
418
+	 * @return bool
419
+	 * @throws DuplicateCollectionIdentifierException
420
+	 * @throws InvalidEntityException
421
+	 */
422
+	public function insertObjectAt($object, $index, $identifier = null)
423
+	{
424
+		// check to ensure that objects don't already exist in the collection
425
+		if ($this->has($identifier)) {
426
+			throw new DuplicateCollectionIdentifierException($identifier);
427
+		}
428
+		// detach any objects at or past this index
429
+		$remaining_objects = array();
430
+		if ($index < $this->count()) {
431
+			$remaining_objects = $this->slice($index, $this->count() - $index);
432
+			foreach ($remaining_objects as $key => $remaining_object) {
433
+				// we need to grab the identifiers for each object and use them as keys
434
+				$remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
435
+				// and then remove the object from the current tracking array
436
+				unset($remaining_objects[ $key ]);
437
+				// and then remove it from the Collection
438
+				$this->detach($remaining_object);
439
+			}
440
+		}
441
+		// add the new object we're splicing in
442
+		$this->add($object, $identifier);
443
+		// attach the objects we previously detached
444
+		foreach ($remaining_objects as $key => $remaining_object) {
445
+			$this->add($remaining_object, $key);
446
+		}
447
+		return $this->contains($object);
448
+	}
449
+
450
+
451
+	/**
452
+	 * Inserts an object (or an array of objects) at a certain point
453
+	 *
454
+	 * @see http://stackoverflow.com/a/8736013
455
+	 * @param mixed $objects A single object or an array of objects
456
+	 * @param int   $index
457
+	 */
458
+	public function insertAt($objects, $index)
459
+	{
460
+		if (! is_array($objects)) {
461
+			$objects = array($objects);
462
+		}
463
+		// check to ensure that objects don't already exist in the collection
464
+		foreach ($objects as $key => $object) {
465
+			if ($this->contains($object)) {
466
+				unset($objects[ $key ]);
467
+			}
468
+		}
469
+		// do we have any objects left?
470
+		if (! $objects) {
471
+			return;
472
+		}
473
+		// detach any objects at or past this index
474
+		$remaining = array();
475
+		if ($index < $this->count()) {
476
+			$remaining = $this->slice($index, $this->count() - $index);
477
+			foreach ($remaining as $object) {
478
+				$this->detach($object);
479
+			}
480
+		}
481
+		// add the new objects we're splicing in
482
+		foreach ($objects as $object) {
483
+			$this->attach($object);
484
+		}
485
+		// attach the objects we previously detached
486
+		foreach ($remaining as $object) {
487
+			$this->attach($object);
488
+		}
489
+	}
490
+
491
+
492
+	/**
493
+	 * Removes the object at the given index
494
+	 *
495
+	 * @see http://stackoverflow.com/a/8736013
496
+	 * @param int $index
497
+	 */
498
+	public function removeAt($index)
499
+	{
500
+		$this->detach($this->objectAtIndex($index));
501
+	}
502
+
503
+
504
+	/**
505
+	 * detaches ALL objects from the Collection
506
+	 */
507
+	public function detachAll()
508
+	{
509
+		$this->rewind();
510
+		while ($this->valid()) {
511
+			$object = $this->current();
512
+			$this->next();
513
+			$this->detach($object);
514
+		}
515
+	}
516
+
517
+
518
+	/**
519
+	 * unsets and detaches ALL objects from the Collection
520
+	 */
521
+	public function trashAndDetachAll()
522
+	{
523
+		$this->rewind();
524
+		while ($this->valid()) {
525
+			$object = $this->current();
526
+			$this->next();
527
+			$this->detach($object);
528
+			unset($object);
529
+		}
530
+	}
531 531
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     ) {
88 88
         try {
89 89
             $this->collection_details = $collection_details;
90
-            if (! $collection instanceof CollectionInterface) {
90
+            if ( ! $collection instanceof CollectionInterface) {
91 91
                 $collection = new Collection($this->collection_details->getCollectionInterface());
92 92
             }
93 93
             $this->collection = $collection;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function loadAllFromFilepaths()
121 121
     {
122
-        if (! $this->file_locator instanceof FileLocator) {
122
+        if ( ! $this->file_locator instanceof FileLocator) {
123 123
             $this->file_locator = new FileLocator();
124 124
         }
125 125
         $this->file_locator->setFileMask($this->collection_details->getFileMask());
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
      */
153 153
     protected function loadClassFromFilepath($filepath)
154 154
     {
155
-        if (! is_string($filepath)) {
155
+        if ( ! is_string($filepath)) {
156 156
             throw new InvalidDataTypeException('$filepath', $filepath, 'string');
157 157
         }
158
-        if (! is_readable($filepath)) {
158
+        if ( ! is_readable($filepath)) {
159 159
             throw new InvalidFilePathException($filepath);
160 160
         }
161 161
         require_once $filepath;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         $file_name = basename($filepath);
164 164
         // now remove any file extensions
165 165
         $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
166
-        if (! class_exists($class_name)) {
166
+        if ( ! class_exists($class_name)) {
167 167
             throw new InvalidClassException($class_name);
168 168
         }
169 169
         $entity = $this->entity_factory instanceof FactoryInterface
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
             // objects added to the collection based on entity callback, so the entity itself decides
238 238
             case CollectionDetails::ID_CALLBACK_METHOD:
239 239
                 $identifier_callback = $this->collection_details->identifierCallback();
240
-                if (! method_exists($entity, $identifier_callback)) {
240
+                if ( ! method_exists($entity, $identifier_callback)) {
241 241
                     throw new InvalidEntityException(
242 242
                         $entity,
243 243
                         $this->collection_details->getCollectionInterface(),
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
      */
304 304
     protected function loadClassFromFQCN($FQCN)
305 305
     {
306
-        if (! is_string($FQCN)) {
306
+        if ( ! is_string($FQCN)) {
307 307
             throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
308 308
         }
309
-        if (! class_exists($FQCN)) {
309
+        if ( ! class_exists($FQCN)) {
310 310
             throw new InvalidClassException($FQCN);
311 311
         }
312 312
         do_action(
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -28,295 +28,295 @@
 block discarded – undo
28 28
  */
29 29
 class CollectionLoader
30 30
 {
31
-    /**
32
-     * possible return value when adding entities to a collection.
33
-     * denotes that the entity was NOT ADDED to the collection
34
-     */
35
-    const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
31
+	/**
32
+	 * possible return value when adding entities to a collection.
33
+	 * denotes that the entity was NOT ADDED to the collection
34
+	 */
35
+	const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
36 36
 
37
-    /**
38
-     * possible return value when adding entities to a collection.
39
-     * denotes that the entity was SUCCESSFULLY ADDED to the collection
40
-     */
41
-    const ENTITY_ADDED = 'entity-added-to-collection';
37
+	/**
38
+	 * possible return value when adding entities to a collection.
39
+	 * denotes that the entity was SUCCESSFULLY ADDED to the collection
40
+	 */
41
+	const ENTITY_ADDED = 'entity-added-to-collection';
42 42
 
43
-    /**
44
-     * possible return value when adding entities to a collection.
45
-     * denotes that the entity was ALREADY ADDED to the collection,
46
-     * and therefore could not be added again.
47
-     */
48
-    const ENTITY_EXISTS = 'entity-already-in-collection';
43
+	/**
44
+	 * possible return value when adding entities to a collection.
45
+	 * denotes that the entity was ALREADY ADDED to the collection,
46
+	 * and therefore could not be added again.
47
+	 */
48
+	const ENTITY_EXISTS = 'entity-already-in-collection';
49 49
 
50 50
 
51
-    /**
52
-     * @var CollectionDetailsInterface $collection_details
53
-     */
54
-    protected $collection_details;
51
+	/**
52
+	 * @var CollectionDetailsInterface $collection_details
53
+	 */
54
+	protected $collection_details;
55 55
 
56
-    /**
57
-     * @var CollectionInterface $collection
58
-     */
59
-    protected $collection;
56
+	/**
57
+	 * @var CollectionInterface $collection
58
+	 */
59
+	protected $collection;
60 60
 
61
-    /**
62
-     * @var FactoryInterface $entity_factory
63
-     */
64
-    protected $entity_factory;
61
+	/**
62
+	 * @var FactoryInterface $entity_factory
63
+	 */
64
+	protected $entity_factory;
65 65
 
66
-    /**
67
-     * @var FileLocator $file_locator
68
-     */
69
-    protected $file_locator;
66
+	/**
67
+	 * @var FileLocator $file_locator
68
+	 */
69
+	protected $file_locator;
70 70
 
71 71
 
72
-    /**
73
-     * CollectionLoader constructor.
74
-     *
75
-     * @param CollectionDetailsInterface $collection_details
76
-     * @param CollectionInterface        $collection
77
-     * @param LocatorInterface           $file_locator
78
-     * @param FactoryInterface|null      $entity_factory
79
-     * @throws CollectionLoaderException
80
-     */
81
-    public function __construct(
82
-        CollectionDetailsInterface $collection_details,
83
-        CollectionInterface $collection = null,
84
-        LocatorInterface $file_locator = null,
85
-        FactoryInterface $entity_factory = null
86
-    ) {
87
-        try {
88
-            $this->collection_details = $collection_details;
89
-            if (! $collection instanceof CollectionInterface) {
90
-                $collection = new Collection($this->collection_details->getCollectionInterface());
91
-            }
92
-            $this->collection = $collection;
93
-            $this->file_locator = $file_locator;
94
-            $this->entity_factory = $entity_factory;
95
-            $this->loadAllFromFilepaths();
96
-            $this->loadFromFQCNs();
97
-        } catch (Exception $exception) {
98
-            throw new CollectionLoaderException($exception);
99
-        }
100
-    }
72
+	/**
73
+	 * CollectionLoader constructor.
74
+	 *
75
+	 * @param CollectionDetailsInterface $collection_details
76
+	 * @param CollectionInterface        $collection
77
+	 * @param LocatorInterface           $file_locator
78
+	 * @param FactoryInterface|null      $entity_factory
79
+	 * @throws CollectionLoaderException
80
+	 */
81
+	public function __construct(
82
+		CollectionDetailsInterface $collection_details,
83
+		CollectionInterface $collection = null,
84
+		LocatorInterface $file_locator = null,
85
+		FactoryInterface $entity_factory = null
86
+	) {
87
+		try {
88
+			$this->collection_details = $collection_details;
89
+			if (! $collection instanceof CollectionInterface) {
90
+				$collection = new Collection($this->collection_details->getCollectionInterface());
91
+			}
92
+			$this->collection = $collection;
93
+			$this->file_locator = $file_locator;
94
+			$this->entity_factory = $entity_factory;
95
+			$this->loadAllFromFilepaths();
96
+			$this->loadFromFQCNs();
97
+		} catch (Exception $exception) {
98
+			throw new CollectionLoaderException($exception);
99
+		}
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * @return CollectionInterface
105
-     */
106
-    public function getCollection()
107
-    {
108
-        return $this->collection;
109
-    }
103
+	/**
104
+	 * @return CollectionInterface
105
+	 */
106
+	public function getCollection()
107
+	{
108
+		return $this->collection;
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * @throws InvalidClassException
114
-     * @throws InvalidFilePathException
115
-     * @throws InvalidDataTypeException
116
-     * @throws InvalidEntityException
117
-     * @throws DuplicateCollectionIdentifierException
118
-     */
119
-    protected function loadAllFromFilepaths()
120
-    {
121
-        if (! $this->file_locator instanceof FileLocator) {
122
-            $this->file_locator = new FileLocator();
123
-        }
124
-        $this->file_locator->setFileMask($this->collection_details->getFileMask());
125
-        // find all of the files that match the file mask in the specified folder
126
-        $this->file_locator->locate($this->collection_details->getCollectionPaths());
127
-        // filter the results
128
-        $filepaths = (array) apply_filters(
129
-            'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
130
-            $this->file_locator->getFilePaths(),
131
-            $this->collection_details->collectionName(),
132
-            $this->collection_details
133
-        );
134
-        if (empty($filepaths)) {
135
-            return;
136
-        }
137
-        foreach ($filepaths as $filepath) {
138
-            $this->loadClassFromFilepath($filepath);
139
-        }
140
-    }
112
+	/**
113
+	 * @throws InvalidClassException
114
+	 * @throws InvalidFilePathException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws InvalidEntityException
117
+	 * @throws DuplicateCollectionIdentifierException
118
+	 */
119
+	protected function loadAllFromFilepaths()
120
+	{
121
+		if (! $this->file_locator instanceof FileLocator) {
122
+			$this->file_locator = new FileLocator();
123
+		}
124
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
125
+		// find all of the files that match the file mask in the specified folder
126
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
127
+		// filter the results
128
+		$filepaths = (array) apply_filters(
129
+			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
130
+			$this->file_locator->getFilePaths(),
131
+			$this->collection_details->collectionName(),
132
+			$this->collection_details
133
+		);
134
+		if (empty($filepaths)) {
135
+			return;
136
+		}
137
+		foreach ($filepaths as $filepath) {
138
+			$this->loadClassFromFilepath($filepath);
139
+		}
140
+	}
141 141
 
142 142
 
143
-    /**
144
-     * @param  string $filepath
145
-     * @return string
146
-     * @throws InvalidEntityException
147
-     * @throws InvalidDataTypeException
148
-     * @throws InvalidFilePathException
149
-     * @throws InvalidClassException
150
-     * @throws DuplicateCollectionIdentifierException
151
-     */
152
-    protected function loadClassFromFilepath($filepath)
153
-    {
154
-        if (! is_string($filepath)) {
155
-            throw new InvalidDataTypeException('$filepath', $filepath, 'string');
156
-        }
157
-        if (! is_readable($filepath)) {
158
-            throw new InvalidFilePathException($filepath);
159
-        }
160
-        require_once $filepath;
161
-        // extract filename from path
162
-        $file_name = basename($filepath);
163
-        // now remove any file extensions
164
-        $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
165
-        if (! class_exists($class_name)) {
166
-            throw new InvalidClassException($class_name);
167
-        }
168
-        $entity = $this->entity_factory instanceof FactoryInterface
169
-            ? call_user_func(array($this->entity_factory, 'create'), $class_name)
170
-            : new $class_name();
171
-        return $this->addEntityToCollection($entity, $file_name);
172
-    }
143
+	/**
144
+	 * @param  string $filepath
145
+	 * @return string
146
+	 * @throws InvalidEntityException
147
+	 * @throws InvalidDataTypeException
148
+	 * @throws InvalidFilePathException
149
+	 * @throws InvalidClassException
150
+	 * @throws DuplicateCollectionIdentifierException
151
+	 */
152
+	protected function loadClassFromFilepath($filepath)
153
+	{
154
+		if (! is_string($filepath)) {
155
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
156
+		}
157
+		if (! is_readable($filepath)) {
158
+			throw new InvalidFilePathException($filepath);
159
+		}
160
+		require_once $filepath;
161
+		// extract filename from path
162
+		$file_name = basename($filepath);
163
+		// now remove any file extensions
164
+		$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
165
+		if (! class_exists($class_name)) {
166
+			throw new InvalidClassException($class_name);
167
+		}
168
+		$entity = $this->entity_factory instanceof FactoryInterface
169
+			? call_user_func(array($this->entity_factory, 'create'), $class_name)
170
+			: new $class_name();
171
+		return $this->addEntityToCollection($entity, $file_name);
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * @param        $entity
177
-     * @param  mixed $identifier
178
-     * @return string
179
-     * @throws InvalidEntityException
180
-     * @throws DuplicateCollectionIdentifierException
181
-     */
182
-    protected function addEntityToCollection($entity, $identifier)
183
-    {
184
-        do_action(
185
-            'FHEE__CollectionLoader__addEntityToCollection__entity',
186
-            $entity,
187
-            $this->collection_details->collectionName(),
188
-            $this->collection_details
189
-        );
190
-        $identifier = $this->setIdentifier($entity, $identifier);
191
-        if ($this->collection->has($identifier)) {
192
-            do_action(
193
-                'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
194
-                $this,
195
-                $this->collection_details->collectionName(),
196
-                $this->collection_details
197
-            );
198
-            return CollectionLoader::ENTITY_EXISTS;
199
-        }
200
-        if ($this->collection->add($entity, $identifier)) {
201
-            do_action(
202
-                'FHEE__CollectionLoader__addEntityToCollection__entity_added',
203
-                $this,
204
-                $this->collection_details->collectionName(),
205
-                $this->collection_details
206
-            );
207
-            return CollectionLoader::ENTITY_ADDED;
208
-        }
209
-        do_action(
210
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
211
-            $this,
212
-            $this->collection_details->collectionName(),
213
-            $this->collection_details
214
-        );
215
-        return CollectionLoader::ENTITY_NOT_ADDED;
216
-    }
175
+	/**
176
+	 * @param        $entity
177
+	 * @param  mixed $identifier
178
+	 * @return string
179
+	 * @throws InvalidEntityException
180
+	 * @throws DuplicateCollectionIdentifierException
181
+	 */
182
+	protected function addEntityToCollection($entity, $identifier)
183
+	{
184
+		do_action(
185
+			'FHEE__CollectionLoader__addEntityToCollection__entity',
186
+			$entity,
187
+			$this->collection_details->collectionName(),
188
+			$this->collection_details
189
+		);
190
+		$identifier = $this->setIdentifier($entity, $identifier);
191
+		if ($this->collection->has($identifier)) {
192
+			do_action(
193
+				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
194
+				$this,
195
+				$this->collection_details->collectionName(),
196
+				$this->collection_details
197
+			);
198
+			return CollectionLoader::ENTITY_EXISTS;
199
+		}
200
+		if ($this->collection->add($entity, $identifier)) {
201
+			do_action(
202
+				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
203
+				$this,
204
+				$this->collection_details->collectionName(),
205
+				$this->collection_details
206
+			);
207
+			return CollectionLoader::ENTITY_ADDED;
208
+		}
209
+		do_action(
210
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
211
+			$this,
212
+			$this->collection_details->collectionName(),
213
+			$this->collection_details
214
+		);
215
+		return CollectionLoader::ENTITY_NOT_ADDED;
216
+	}
217 217
 
218 218
 
219
-    /**
220
-     * @param        $entity
221
-     * @param  mixed $identifier
222
-     * @return string
223
-     * @throws InvalidEntityException
224
-     */
225
-    protected function setIdentifier($entity, $identifier)
226
-    {
227
-        switch ($this->collection_details->identifierType()) {
228
-            // every unique object gets added to the collection, but not duplicates of the exact same object
229
-            case CollectionDetails::ID_OBJECT_HASH:
230
-                $identifier = spl_object_hash($entity);
231
-                break;
232
-            // only one entity per class can be added to collection, like a singleton
233
-            case CollectionDetails::ID_CLASS_NAME:
234
-                $identifier = get_class($entity);
235
-                break;
236
-            // objects added to the collection based on entity callback, so the entity itself decides
237
-            case CollectionDetails::ID_CALLBACK_METHOD:
238
-                $identifier_callback = $this->collection_details->identifierCallback();
239
-                if (! method_exists($entity, $identifier_callback)) {
240
-                    throw new InvalidEntityException(
241
-                        $entity,
242
-                        $this->collection_details->getCollectionInterface(),
243
-                        sprintf(
244
-                            esc_html__(
245
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
219
+	/**
220
+	 * @param        $entity
221
+	 * @param  mixed $identifier
222
+	 * @return string
223
+	 * @throws InvalidEntityException
224
+	 */
225
+	protected function setIdentifier($entity, $identifier)
226
+	{
227
+		switch ($this->collection_details->identifierType()) {
228
+			// every unique object gets added to the collection, but not duplicates of the exact same object
229
+			case CollectionDetails::ID_OBJECT_HASH:
230
+				$identifier = spl_object_hash($entity);
231
+				break;
232
+			// only one entity per class can be added to collection, like a singleton
233
+			case CollectionDetails::ID_CLASS_NAME:
234
+				$identifier = get_class($entity);
235
+				break;
236
+			// objects added to the collection based on entity callback, so the entity itself decides
237
+			case CollectionDetails::ID_CALLBACK_METHOD:
238
+				$identifier_callback = $this->collection_details->identifierCallback();
239
+				if (! method_exists($entity, $identifier_callback)) {
240
+					throw new InvalidEntityException(
241
+						$entity,
242
+						$this->collection_details->getCollectionInterface(),
243
+						sprintf(
244
+							esc_html__(
245
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
246 246
                                 of "%2$s", but does not contain this method.',
247
-                                'event_espresso'
248
-                            ),
249
-                            $identifier_callback,
250
-                            get_class($entity)
251
-                        )
252
-                    );
253
-                }
254
-                $identifier = $entity->{$identifier_callback}();
255
-                break;
256
-        }
257
-        return apply_filters(
258
-            'FHEE__CollectionLoader__addEntityToCollection__identifier',
259
-            $identifier,
260
-            $this->collection_details->collectionName(),
261
-            $this->collection_details
262
-        );
263
-    }
247
+								'event_espresso'
248
+							),
249
+							$identifier_callback,
250
+							get_class($entity)
251
+						)
252
+					);
253
+				}
254
+				$identifier = $entity->{$identifier_callback}();
255
+				break;
256
+		}
257
+		return apply_filters(
258
+			'FHEE__CollectionLoader__addEntityToCollection__identifier',
259
+			$identifier,
260
+			$this->collection_details->collectionName(),
261
+			$this->collection_details
262
+		);
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * @throws ReflectionException
268
-     * @throws InvalidArgumentException
269
-     * @throws InvalidInterfaceException
270
-     * @throws EE_Error
271
-     * @throws InvalidClassException
272
-     * @throws InvalidDataTypeException
273
-     * @throws InvalidEntityException
274
-     * @throws DuplicateCollectionIdentifierException
275
-     */
276
-    protected function loadFromFQCNs()
277
-    {
278
-        $FQCNs = $this->collection_details->getCollectionFQCNs();
279
-        $FQCNs = (array) apply_filters(
280
-            'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
281
-            $FQCNs,
282
-            $this->collection_details->collectionName(),
283
-            $this->collection_details
284
-        );
285
-        foreach ($FQCNs as $FQCN) {
286
-            $this->loadClassFromFQCN($FQCN);
287
-        }
288
-    }
266
+	/**
267
+	 * @throws ReflectionException
268
+	 * @throws InvalidArgumentException
269
+	 * @throws InvalidInterfaceException
270
+	 * @throws EE_Error
271
+	 * @throws InvalidClassException
272
+	 * @throws InvalidDataTypeException
273
+	 * @throws InvalidEntityException
274
+	 * @throws DuplicateCollectionIdentifierException
275
+	 */
276
+	protected function loadFromFQCNs()
277
+	{
278
+		$FQCNs = $this->collection_details->getCollectionFQCNs();
279
+		$FQCNs = (array) apply_filters(
280
+			'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
281
+			$FQCNs,
282
+			$this->collection_details->collectionName(),
283
+			$this->collection_details
284
+		);
285
+		foreach ($FQCNs as $FQCN) {
286
+			$this->loadClassFromFQCN($FQCN);
287
+		}
288
+	}
289 289
 
290 290
 
291
-    /**
292
-     * @param  string $FQCN Fully Qualified Class Name
293
-     * @return string
294
-     * @throws InvalidArgumentException
295
-     * @throws InvalidInterfaceException
296
-     * @throws ReflectionException
297
-     * @throws EE_Error
298
-     * @throws InvalidEntityException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidClassException
301
-     * @throws DuplicateCollectionIdentifierException
302
-     */
303
-    protected function loadClassFromFQCN($FQCN)
304
-    {
305
-        if (! is_string($FQCN)) {
306
-            throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
307
-        }
308
-        if (! class_exists($FQCN)) {
309
-            throw new InvalidClassException($FQCN);
310
-        }
311
-        do_action(
312
-            'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading',
313
-            $FQCN,
314
-            $this->collection_details->collectionName(),
315
-            $this->collection_details
316
-        );
317
-        $entity = $this->entity_factory instanceof FactoryInterface
318
-            ? call_user_func(array($this->entity_factory, 'create'), $FQCN)
319
-            : EE_Registry::instance()->create($FQCN);
320
-        return $this->addEntityToCollection($entity, $FQCN);
321
-    }
291
+	/**
292
+	 * @param  string $FQCN Fully Qualified Class Name
293
+	 * @return string
294
+	 * @throws InvalidArgumentException
295
+	 * @throws InvalidInterfaceException
296
+	 * @throws ReflectionException
297
+	 * @throws EE_Error
298
+	 * @throws InvalidEntityException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidClassException
301
+	 * @throws DuplicateCollectionIdentifierException
302
+	 */
303
+	protected function loadClassFromFQCN($FQCN)
304
+	{
305
+		if (! is_string($FQCN)) {
306
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
307
+		}
308
+		if (! class_exists($FQCN)) {
309
+			throw new InvalidClassException($FQCN);
310
+		}
311
+		do_action(
312
+			'FHEE__CollectionLoader__loadClassFromFQCN__beforeLoading',
313
+			$FQCN,
314
+			$this->collection_details->collectionName(),
315
+			$this->collection_details
316
+		);
317
+		$entity = $this->entity_factory instanceof FactoryInterface
318
+			? call_user_func(array($this->entity_factory, 'create'), $FQCN)
319
+			: EE_Registry::instance()->create($FQCN);
320
+		return $this->addEntityToCollection($entity, $FQCN);
321
+	}
322 322
 }
Please login to merge, or discard this patch.