Completed
Pull Request — master (#331)
by Darren
14:45
created
core/domain/services/admin/ExitModal.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -19,94 +19,94 @@
 block discarded – undo
19 19
 class ExitModal
20 20
 {
21 21
 
22
-    /**
23
-     * @var Registry
24
-     */
25
-    private $assets_registry;
22
+	/**
23
+	 * @var Registry
24
+	 */
25
+	private $assets_registry;
26 26
 
27
-    /**
28
-     * ExitModal constructor.
29
-     *
30
-     * @param Registry $assets_registry
31
-     */
32
-    public function __construct(Registry $assets_registry)
33
-    {
34
-        $this->assets_registry = $assets_registry;
35
-        add_action('in_admin_footer', array($this, 'modalContainer'));
36
-        add_action('admin_enqueue_scripts', array($this, 'enqueues'));
37
-    }
27
+	/**
28
+	 * ExitModal constructor.
29
+	 *
30
+	 * @param Registry $assets_registry
31
+	 */
32
+	public function __construct(Registry $assets_registry)
33
+	{
34
+		$this->assets_registry = $assets_registry;
35
+		add_action('in_admin_footer', array($this, 'modalContainer'));
36
+		add_action('admin_enqueue_scripts', array($this, 'enqueues'));
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Callback on in_admin_footer that is used to output the exit modal container.
42
-     */
43
-    public function modalContainer()
44
-    {
45
-        echo '<div id="ee-exit-survey-modal"></div>';
46
-    }
40
+	/**
41
+	 * Callback on in_admin_footer that is used to output the exit modal container.
42
+	 */
43
+	public function modalContainer()
44
+	{
45
+		echo '<div id="ee-exit-survey-modal"></div>';
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
51
-     *
52
-     * @throws InvalidArgumentException
53
-     */
54
-    public function enqueues()
55
-    {
56
-        $current_user = new WP_User(get_current_user_id());
57
-        $this->assets_registry->addData(
58
-            'exitModali18n',
59
-            array(
60
-                'introText' => htmlspecialchars(
61
-                    __(
62
-                        'Do you have a moment to share why you are deactivating Event Espresso?',
63
-                        'event_espresso'
64
-                    ),
65
-                    ENT_NOQUOTES
66
-                ),
67
-                'doSurveyButtonText' => htmlspecialchars(
68
-                    __(
69
-                        'Sure I\'ll help',
70
-                        'event_espresso'
71
-                    ),
72
-                    ENT_NOQUOTES
73
-                ),
74
-                'skipButtonText' => htmlspecialchars(
75
-                    __(
76
-                        'Skip',
77
-                        'event_espresso'
78
-                    ),
79
-                    ENT_NOQUOTES
80
-                )
81
-            )
82
-        );
83
-        $this->assets_registry->addData(
84
-            'exitModalInfo',
85
-            array(
86
-                'firstname' => htmlspecialchars($current_user->user_firstname),
87
-                'emailaddress' => htmlspecialchars($current_user->user_email),
88
-                'website' => htmlspecialchars(site_url()),
89
-                'isModalActive' => $this->isModalActive()
90
-            )
91
-        );
49
+	/**
50
+	 * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
51
+	 *
52
+	 * @throws InvalidArgumentException
53
+	 */
54
+	public function enqueues()
55
+	{
56
+		$current_user = new WP_User(get_current_user_id());
57
+		$this->assets_registry->addData(
58
+			'exitModali18n',
59
+			array(
60
+				'introText' => htmlspecialchars(
61
+					__(
62
+						'Do you have a moment to share why you are deactivating Event Espresso?',
63
+						'event_espresso'
64
+					),
65
+					ENT_NOQUOTES
66
+				),
67
+				'doSurveyButtonText' => htmlspecialchars(
68
+					__(
69
+						'Sure I\'ll help',
70
+						'event_espresso'
71
+					),
72
+					ENT_NOQUOTES
73
+				),
74
+				'skipButtonText' => htmlspecialchars(
75
+					__(
76
+						'Skip',
77
+						'event_espresso'
78
+					),
79
+					ENT_NOQUOTES
80
+				)
81
+			)
82
+		);
83
+		$this->assets_registry->addData(
84
+			'exitModalInfo',
85
+			array(
86
+				'firstname' => htmlspecialchars($current_user->user_firstname),
87
+				'emailaddress' => htmlspecialchars($current_user->user_email),
88
+				'website' => htmlspecialchars(site_url()),
89
+				'isModalActive' => $this->isModalActive()
90
+			)
91
+		);
92 92
 
93
-        wp_enqueue_script('ee-wp-plugins-page');
94
-        wp_enqueue_style('ee-wp-plugins-page');
95
-    }
93
+		wp_enqueue_script('ee-wp-plugins-page');
94
+		wp_enqueue_style('ee-wp-plugins-page');
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * Exposes a filter switch for turning off the enqueueing of the modal script.
100
-     * @return bool
101
-     */
102
-    private function isModalActive()
103
-    {
104
-        return filter_var(
105
-            apply_filters(
106
-                'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
107
-                true
108
-            ),
109
-            FILTER_VALIDATE_BOOLEAN
110
-        );
111
-    }
98
+	/**
99
+	 * Exposes a filter switch for turning off the enqueueing of the modal script.
100
+	 * @return bool
101
+	 */
102
+	private function isModalActive()
103
+	{
104
+		return filter_var(
105
+			apply_filters(
106
+				'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
107
+				true
108
+			),
109
+			FILTER_VALIDATE_BOOLEAN
110
+		);
111
+	}
112 112
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/BlockCollection.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -20,55 +20,55 @@
 block discarded – undo
20 20
 class BlockCollection extends Collection
21 21
 {
22 22
 
23
-    /**
24
-     * Collection constructor
25
-     *
26
-     * @throws InvalidInterfaceException
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface');
31
-    }
23
+	/**
24
+	 * Collection constructor
25
+	 *
26
+	 * @throws InvalidInterfaceException
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface');
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * unRegisterBlock
36
-     * finds block in the Collection based on the identifier that was set using addObject()
37
-     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
-     *
40
-     * @param mixed $identifier
41
-     * @return boolean
42
-     */
43
-    public function unRegisterBlock($identifier)
44
-    {
45
-        $this->rewind();
46
-        while ($this->valid()) {
47
-            if ($identifier === $this->getInfo()) {
48
-                $object = $this->current();
49
-                $this->rewind();
50
-                return $object->unRegisterBlock();
51
-            }
52
-            $this->next();
53
-        }
54
-        return false;
55
-    }
34
+	/**
35
+	 * unRegisterBlock
36
+	 * finds block in the Collection based on the identifier that was set using addObject()
37
+	 * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
+	 *
40
+	 * @param mixed $identifier
41
+	 * @return boolean
42
+	 */
43
+	public function unRegisterBlock($identifier)
44
+	{
45
+		$this->rewind();
46
+		while ($this->valid()) {
47
+			if ($identifier === $this->getInfo()) {
48
+				$object = $this->current();
49
+				$this->rewind();
50
+				return $object->unRegisterBlock();
51
+			}
52
+			$this->next();
53
+		}
54
+		return false;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * unRegisterAllBlocks
60
-     * calls unRegisterBlock() on all blocks in Collection.
61
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
-     *
63
-     * @return void
64
-     */
65
-    public function unRegisterAllBlocks()
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $this->current()->unRegisterBlock();
70
-            $this->next();
71
-        }
72
-        $this->rewind();
73
-    }
58
+	/**
59
+	 * unRegisterAllBlocks
60
+	 * calls unRegisterBlock() on all blocks in Collection.
61
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public function unRegisterAllBlocks()
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$this->current()->unRegisterBlock();
70
+			$this->next();
71
+		}
72
+		$this->rewind();
73
+	}
74 74
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@
 block discarded – undo
163 163
 
164 164
     /**
165 165
      * @param        $entity
166
-     * @param  mixed $identifier
166
+     * @param  string $identifier
167 167
      * @return string
168 168
      * @throws InvalidEntityException
169 169
      */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         LocatorInterface $file_locator = null
85 85
     ) {
86 86
         $this->collection_details = $collection_details;
87
-        if (! $collection instanceof CollectionInterface) {
87
+        if ( ! $collection instanceof CollectionInterface) {
88 88
             $collection = new Collection($this->collection_details->getCollectionInterface());
89 89
         }
90 90
         $this->collection = $collection;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     protected function loadAllFromFilepaths()
113 113
     {
114
-        if (! $this->file_locator instanceof FileLocator) {
114
+        if ( ! $this->file_locator instanceof FileLocator) {
115 115
             $this->file_locator = new FileLocator();
116 116
         }
117 117
         $this->file_locator->setFileMask($this->collection_details->getFileMask());
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
      */
144 144
     protected function loadClassFromFilepath($filepath)
145 145
     {
146
-        if (! is_string($filepath)) {
146
+        if ( ! is_string($filepath)) {
147 147
             throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148 148
         }
149
-        if (! is_readable($filepath)) {
149
+        if ( ! is_readable($filepath)) {
150 150
             throw new InvalidFilePathException($filepath);
151 151
         }
152 152
         require_once $filepath;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         $file_name = basename($filepath);
155 155
         // now remove any file extensions
156 156
         $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
-        if (! class_exists($class_name)) {
157
+        if ( ! class_exists($class_name)) {
158 158
             throw new InvalidClassException($class_name);
159 159
         }
160 160
         return $this->addEntityToCollection(new $class_name(), $file_name);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             // objects added to the collection based on entity callback, so the entity itself decides
225 225
             case CollectionDetails::ID_CALLBACK_METHOD:
226 226
                 $identifier_callback = $this->collection_details->identifierCallback();
227
-                if (! method_exists($entity, $identifier_callback)) {
227
+                if ( ! method_exists($entity, $identifier_callback)) {
228 228
                     throw new InvalidEntityException(
229 229
                         $entity,
230 230
                         $this->collection_details->getCollectionInterface(),
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
      */
289 289
     protected function loadClassFromFQCN($FQCN)
290 290
     {
291
-        if (! is_string($FQCN)) {
291
+        if ( ! is_string($FQCN)) {
292 292
             throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293 293
         }
294
-        if (! class_exists($FQCN)) {
294
+        if ( ! class_exists($FQCN)) {
295 295
             throw new InvalidClassException($FQCN);
296 296
         }
297 297
         return $this->addEntityToCollection(
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -27,276 +27,276 @@
 block discarded – undo
27 27
 class CollectionLoader
28 28
 {
29 29
 
30
-    /**
31
-     * possible return value when adding entities to a collection.
32
-     * denotes that the entity was NOT ADDED to the collection
33
-     */
34
-    const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
30
+	/**
31
+	 * possible return value when adding entities to a collection.
32
+	 * denotes that the entity was NOT ADDED to the collection
33
+	 */
34
+	const ENTITY_NOT_ADDED = 'entity-not-added-to-collection';
35 35
 
36
-    /**
37
-     * possible return value when adding entities to a collection.
38
-     * denotes that the entity was SUCCESSFULLY ADDED to the collection
39
-     */
40
-    const ENTITY_ADDED = 'entity-added-to-collection';
36
+	/**
37
+	 * possible return value when adding entities to a collection.
38
+	 * denotes that the entity was SUCCESSFULLY ADDED to the collection
39
+	 */
40
+	const ENTITY_ADDED = 'entity-added-to-collection';
41 41
 
42
-    /**
43
-     * possible return value when adding entities to a collection.
44
-     * denotes that the entity was ALREADY ADDED to the collection,
45
-     * and therefore could not be added again.
46
-     */
47
-    const ENTITY_EXISTS = 'entity-already-in-collection';
42
+	/**
43
+	 * possible return value when adding entities to a collection.
44
+	 * denotes that the entity was ALREADY ADDED to the collection,
45
+	 * and therefore could not be added again.
46
+	 */
47
+	const ENTITY_EXISTS = 'entity-already-in-collection';
48 48
 
49 49
 
50
-    /**
51
-     * @var CollectionDetailsInterface $collection_details
52
-     */
53
-    protected $collection_details;
50
+	/**
51
+	 * @var CollectionDetailsInterface $collection_details
52
+	 */
53
+	protected $collection_details;
54 54
 
55
-    /**
56
-     * @var CollectionInterface $collection
57
-     */
58
-    protected $collection;
55
+	/**
56
+	 * @var CollectionInterface $collection
57
+	 */
58
+	protected $collection;
59 59
 
60
-    /**
61
-     * @var FileLocator $file_locator
62
-     */
63
-    protected $file_locator;
60
+	/**
61
+	 * @var FileLocator $file_locator
62
+	 */
63
+	protected $file_locator;
64 64
 
65 65
 
66
-    /**
67
-     * CollectionLoader constructor.
68
-     *
69
-     * @param CollectionDetailsInterface $collection_details
70
-     * @param CollectionInterface        $collection
71
-     * @param LocatorInterface           $file_locator
72
-     * @throws ReflectionException
73
-     * @throws InvalidArgumentException
74
-     * @throws EE_Error
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidClassException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidFilePathException
79
-     * @throws InvalidEntityException
80
-     */
81
-    public function __construct(
82
-        CollectionDetailsInterface $collection_details,
83
-        CollectionInterface $collection = null,
84
-        LocatorInterface $file_locator = null
85
-    ) {
86
-        $this->collection_details = $collection_details;
87
-        if (! $collection instanceof CollectionInterface) {
88
-            $collection = new Collection($this->collection_details->getCollectionInterface());
89
-        }
90
-        $this->collection = $collection;
91
-        $this->file_locator = $file_locator;
92
-        $this->loadAllFromFilepaths();
93
-        $this->loadFromFQCNs();
94
-    }
66
+	/**
67
+	 * CollectionLoader constructor.
68
+	 *
69
+	 * @param CollectionDetailsInterface $collection_details
70
+	 * @param CollectionInterface        $collection
71
+	 * @param LocatorInterface           $file_locator
72
+	 * @throws ReflectionException
73
+	 * @throws InvalidArgumentException
74
+	 * @throws EE_Error
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidClassException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidFilePathException
79
+	 * @throws InvalidEntityException
80
+	 */
81
+	public function __construct(
82
+		CollectionDetailsInterface $collection_details,
83
+		CollectionInterface $collection = null,
84
+		LocatorInterface $file_locator = null
85
+	) {
86
+		$this->collection_details = $collection_details;
87
+		if (! $collection instanceof CollectionInterface) {
88
+			$collection = new Collection($this->collection_details->getCollectionInterface());
89
+		}
90
+		$this->collection = $collection;
91
+		$this->file_locator = $file_locator;
92
+		$this->loadAllFromFilepaths();
93
+		$this->loadFromFQCNs();
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * @return CollectionInterface
99
-     */
100
-    public function getCollection()
101
-    {
102
-        return $this->collection;
103
-    }
97
+	/**
98
+	 * @return CollectionInterface
99
+	 */
100
+	public function getCollection()
101
+	{
102
+		return $this->collection;
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * @throws InvalidClassException
108
-     * @throws InvalidFilePathException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidEntityException
111
-     */
112
-    protected function loadAllFromFilepaths()
113
-    {
114
-        if (! $this->file_locator instanceof FileLocator) {
115
-            $this->file_locator = new FileLocator();
116
-        }
117
-        $this->file_locator->setFileMask($this->collection_details->getFileMask());
118
-        // find all of the files that match the file mask in the specified folder
119
-        $this->file_locator->locate($this->collection_details->getCollectionPaths());
120
-        // filter the results
121
-        $filepaths = (array) apply_filters(
122
-            'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
123
-            $this->file_locator->getFilePaths(),
124
-            $this->collection_details->collectionName(),
125
-            $this->collection_details
126
-        );
127
-        if (empty($filepaths)) {
128
-            return;
129
-        }
130
-        foreach ($filepaths as $filepath) {
131
-            $this->loadClassFromFilepath($filepath);
132
-        }
133
-    }
106
+	/**
107
+	 * @throws InvalidClassException
108
+	 * @throws InvalidFilePathException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidEntityException
111
+	 */
112
+	protected function loadAllFromFilepaths()
113
+	{
114
+		if (! $this->file_locator instanceof FileLocator) {
115
+			$this->file_locator = new FileLocator();
116
+		}
117
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
118
+		// find all of the files that match the file mask in the specified folder
119
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
120
+		// filter the results
121
+		$filepaths = (array) apply_filters(
122
+			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
123
+			$this->file_locator->getFilePaths(),
124
+			$this->collection_details->collectionName(),
125
+			$this->collection_details
126
+		);
127
+		if (empty($filepaths)) {
128
+			return;
129
+		}
130
+		foreach ($filepaths as $filepath) {
131
+			$this->loadClassFromFilepath($filepath);
132
+		}
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * @param  string $filepath
138
-     * @return string
139
-     * @throws InvalidEntityException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidFilePathException
142
-     * @throws InvalidClassException
143
-     */
144
-    protected function loadClassFromFilepath($filepath)
145
-    {
146
-        if (! is_string($filepath)) {
147
-            throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148
-        }
149
-        if (! is_readable($filepath)) {
150
-            throw new InvalidFilePathException($filepath);
151
-        }
152
-        require_once $filepath;
153
-        // extract filename from path
154
-        $file_name = basename($filepath);
155
-        // now remove any file extensions
156
-        $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
-        if (! class_exists($class_name)) {
158
-            throw new InvalidClassException($class_name);
159
-        }
160
-        return $this->addEntityToCollection(new $class_name(), $file_name);
161
-    }
136
+	/**
137
+	 * @param  string $filepath
138
+	 * @return string
139
+	 * @throws InvalidEntityException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidFilePathException
142
+	 * @throws InvalidClassException
143
+	 */
144
+	protected function loadClassFromFilepath($filepath)
145
+	{
146
+		if (! is_string($filepath)) {
147
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
148
+		}
149
+		if (! is_readable($filepath)) {
150
+			throw new InvalidFilePathException($filepath);
151
+		}
152
+		require_once $filepath;
153
+		// extract filename from path
154
+		$file_name = basename($filepath);
155
+		// now remove any file extensions
156
+		$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
157
+		if (! class_exists($class_name)) {
158
+			throw new InvalidClassException($class_name);
159
+		}
160
+		return $this->addEntityToCollection(new $class_name(), $file_name);
161
+	}
162 162
 
163 163
 
164
-    /**
165
-     * @param        $entity
166
-     * @param  mixed $identifier
167
-     * @return string
168
-     * @throws InvalidEntityException
169
-     */
170
-    protected function addEntityToCollection($entity, $identifier)
171
-    {
172
-        do_action(
173
-            'FHEE__CollectionLoader__addEntityToCollection__entity',
174
-            $entity,
175
-            $this->collection_details->collectionName(),
176
-            $this->collection_details
177
-        );
178
-        $identifier = $this->setIdentifier($entity, $identifier);
179
-        if ($this->collection->has($identifier)) {
180
-            do_action(
181
-                'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
182
-                $this,
183
-                $this->collection_details->collectionName(),
184
-                $this->collection_details
185
-            );
186
-            return CollectionLoader::ENTITY_EXISTS;
187
-        }
188
-        if ($this->collection->add($entity, $identifier)) {
189
-            do_action(
190
-                'FHEE__CollectionLoader__addEntityToCollection__entity_added',
191
-                $this,
192
-                $this->collection_details->collectionName(),
193
-                $this->collection_details
194
-            );
195
-            return CollectionLoader::ENTITY_ADDED;
196
-        }
197
-        do_action(
198
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
199
-            $this,
200
-            $this->collection_details->collectionName(),
201
-            $this->collection_details
202
-        );
203
-        return CollectionLoader::ENTITY_NOT_ADDED;
204
-    }
164
+	/**
165
+	 * @param        $entity
166
+	 * @param  mixed $identifier
167
+	 * @return string
168
+	 * @throws InvalidEntityException
169
+	 */
170
+	protected function addEntityToCollection($entity, $identifier)
171
+	{
172
+		do_action(
173
+			'FHEE__CollectionLoader__addEntityToCollection__entity',
174
+			$entity,
175
+			$this->collection_details->collectionName(),
176
+			$this->collection_details
177
+		);
178
+		$identifier = $this->setIdentifier($entity, $identifier);
179
+		if ($this->collection->has($identifier)) {
180
+			do_action(
181
+				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
182
+				$this,
183
+				$this->collection_details->collectionName(),
184
+				$this->collection_details
185
+			);
186
+			return CollectionLoader::ENTITY_EXISTS;
187
+		}
188
+		if ($this->collection->add($entity, $identifier)) {
189
+			do_action(
190
+				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
191
+				$this,
192
+				$this->collection_details->collectionName(),
193
+				$this->collection_details
194
+			);
195
+			return CollectionLoader::ENTITY_ADDED;
196
+		}
197
+		do_action(
198
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
199
+			$this,
200
+			$this->collection_details->collectionName(),
201
+			$this->collection_details
202
+		);
203
+		return CollectionLoader::ENTITY_NOT_ADDED;
204
+	}
205 205
 
206 206
 
207
-    /**
208
-     * @param        $entity
209
-     * @param  mixed $identifier
210
-     * @return string
211
-     * @throws InvalidEntityException
212
-     */
213
-    protected function setIdentifier($entity, $identifier)
214
-    {
215
-        switch ($this->collection_details->identifierType()) {
216
-            // every unique object gets added to the collection, but not duplicates of the exact same object
217
-            case CollectionDetails::ID_OBJECT_HASH:
218
-                $identifier = spl_object_hash($entity);
219
-                break;
220
-            // only one entity per class can be added to collection, like a singleton
221
-            case CollectionDetails::ID_CLASS_NAME:
222
-                $identifier = get_class($entity);
223
-                break;
224
-            // objects added to the collection based on entity callback, so the entity itself decides
225
-            case CollectionDetails::ID_CALLBACK_METHOD:
226
-                $identifier_callback = $this->collection_details->identifierCallback();
227
-                if (! method_exists($entity, $identifier_callback)) {
228
-                    throw new InvalidEntityException(
229
-                        $entity,
230
-                        $this->collection_details->getCollectionInterface(),
231
-                        sprintf(
232
-                            __(
233
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
207
+	/**
208
+	 * @param        $entity
209
+	 * @param  mixed $identifier
210
+	 * @return string
211
+	 * @throws InvalidEntityException
212
+	 */
213
+	protected function setIdentifier($entity, $identifier)
214
+	{
215
+		switch ($this->collection_details->identifierType()) {
216
+			// every unique object gets added to the collection, but not duplicates of the exact same object
217
+			case CollectionDetails::ID_OBJECT_HASH:
218
+				$identifier = spl_object_hash($entity);
219
+				break;
220
+			// only one entity per class can be added to collection, like a singleton
221
+			case CollectionDetails::ID_CLASS_NAME:
222
+				$identifier = get_class($entity);
223
+				break;
224
+			// objects added to the collection based on entity callback, so the entity itself decides
225
+			case CollectionDetails::ID_CALLBACK_METHOD:
226
+				$identifier_callback = $this->collection_details->identifierCallback();
227
+				if (! method_exists($entity, $identifier_callback)) {
228
+					throw new InvalidEntityException(
229
+						$entity,
230
+						$this->collection_details->getCollectionInterface(),
231
+						sprintf(
232
+							__(
233
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
234 234
                                 of "%2$s", but does not contain this method.',
235
-                                'event_espresso'
236
-                            ),
237
-                            $identifier_callback,
238
-                            get_class($entity)
239
-                        )
240
-                    );
241
-                }
242
-                $identifier = $entity->{$identifier_callback}();
243
-                break;
244
-        }
245
-        return apply_filters(
246
-            'FHEE__CollectionLoader__addEntityToCollection__identifier',
247
-            $identifier,
248
-            $this->collection_details->collectionName(),
249
-            $this->collection_details
250
-        );
251
-    }
235
+								'event_espresso'
236
+							),
237
+							$identifier_callback,
238
+							get_class($entity)
239
+						)
240
+					);
241
+				}
242
+				$identifier = $entity->{$identifier_callback}();
243
+				break;
244
+		}
245
+		return apply_filters(
246
+			'FHEE__CollectionLoader__addEntityToCollection__identifier',
247
+			$identifier,
248
+			$this->collection_details->collectionName(),
249
+			$this->collection_details
250
+		);
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * @throws ReflectionException
256
-     * @throws InvalidArgumentException
257
-     * @throws InvalidInterfaceException
258
-     * @throws EE_Error
259
-     * @throws InvalidClassException
260
-     * @throws InvalidDataTypeException
261
-     * @throws InvalidEntityException
262
-     */
263
-    protected function loadFromFQCNs()
264
-    {
265
-        $FQCNs = $this->collection_details->getCollectionFQCNs();
266
-        $FQCNs = (array) apply_filters(
267
-            'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
268
-            $FQCNs,
269
-            $this->collection_details->collectionName(),
270
-            $this->collection_details
271
-        );
272
-        foreach ($FQCNs as $FQCN) {
273
-            $this->loadClassFromFQCN($FQCN);
274
-        }
275
-    }
254
+	/**
255
+	 * @throws ReflectionException
256
+	 * @throws InvalidArgumentException
257
+	 * @throws InvalidInterfaceException
258
+	 * @throws EE_Error
259
+	 * @throws InvalidClassException
260
+	 * @throws InvalidDataTypeException
261
+	 * @throws InvalidEntityException
262
+	 */
263
+	protected function loadFromFQCNs()
264
+	{
265
+		$FQCNs = $this->collection_details->getCollectionFQCNs();
266
+		$FQCNs = (array) apply_filters(
267
+			'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs',
268
+			$FQCNs,
269
+			$this->collection_details->collectionName(),
270
+			$this->collection_details
271
+		);
272
+		foreach ($FQCNs as $FQCN) {
273
+			$this->loadClassFromFQCN($FQCN);
274
+		}
275
+	}
276 276
 
277 277
 
278
-    /**
279
-     * @param  string $FQCN Fully Qualified Class Name
280
-     * @return string
281
-     * @throws InvalidArgumentException
282
-     * @throws InvalidInterfaceException
283
-     * @throws ReflectionException
284
-     * @throws EE_Error
285
-     * @throws InvalidEntityException
286
-     * @throws InvalidDataTypeException
287
-     * @throws InvalidClassException
288
-     */
289
-    protected function loadClassFromFQCN($FQCN)
290
-    {
291
-        if (! is_string($FQCN)) {
292
-            throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293
-        }
294
-        if (! class_exists($FQCN)) {
295
-            throw new InvalidClassException($FQCN);
296
-        }
297
-        return $this->addEntityToCollection(
298
-            EE_Registry::instance()->create($FQCN),
299
-            $FQCN
300
-        );
301
-    }
278
+	/**
279
+	 * @param  string $FQCN Fully Qualified Class Name
280
+	 * @return string
281
+	 * @throws InvalidArgumentException
282
+	 * @throws InvalidInterfaceException
283
+	 * @throws ReflectionException
284
+	 * @throws EE_Error
285
+	 * @throws InvalidEntityException
286
+	 * @throws InvalidDataTypeException
287
+	 * @throws InvalidClassException
288
+	 */
289
+	protected function loadClassFromFQCN($FQCN)
290
+	{
291
+		if (! is_string($FQCN)) {
292
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
293
+		}
294
+		if (! class_exists($FQCN)) {
295
+			throw new InvalidClassException($FQCN);
296
+		}
297
+		return $this->addEntityToCollection(
298
+			EE_Registry::instance()->create($FQCN),
299
+			$FQCN
300
+		);
301
+	}
302 302
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidEntityException.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -16,30 +16,30 @@
 block discarded – undo
16 16
 class InvalidEntityException extends InvalidArgumentException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidEntityException constructor.
21
-     *
22
-     * @param mixed     $actual   the actual object (or thing) we got
23
-     * @param string    $expected classname of the entity we wanted
24
-     * @param string    $message
25
-     * @param int       $code
26
-     * @param Exception $previous
27
-     */
28
-    public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
-    {
30
-        if (empty($message)) {
31
-            $message = sprintf(
32
-                __(
33
-                    'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s',
34
-                    'event_espresso'
35
-                ),
36
-                is_object($actual)
37
-                    ? get_class($actual)
38
-                    : gettype($actual),
39
-                $expected,
40
-                var_export($actual, true)
41
-            );
42
-        }
43
-        parent::__construct($message, $code, $previous);
44
-    }
19
+	/**
20
+	 * InvalidEntityException constructor.
21
+	 *
22
+	 * @param mixed     $actual   the actual object (or thing) we got
23
+	 * @param string    $expected classname of the entity we wanted
24
+	 * @param string    $message
25
+	 * @param int       $code
26
+	 * @param Exception $previous
27
+	 */
28
+	public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null)
29
+	{
30
+		if (empty($message)) {
31
+			$message = sprintf(
32
+				__(
33
+					'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s',
34
+					'event_espresso'
35
+				),
36
+				is_object($actual)
37
+					? get_class($actual)
38
+					: gettype($actual),
39
+				$expected,
40
+				var_export($actual, true)
41
+			);
42
+		}
43
+		parent::__construct($message, $code, $previous);
44
+	}
45 45
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionInterface.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -16,159 +16,159 @@
 block discarded – undo
16 16
 interface CollectionInterface extends Countable, Iterator, Serializable, ArrayAccess
17 17
 {
18 18
 
19
-    /**
20
-     * add
21
-     * attaches an object to the Collection
22
-     * and sets any supplied data associated with the current iterator entry
23
-     * by calling EE_Object_Collection::set_identifier()
24
-     *
25
-     * @access public
26
-     * @param        $object
27
-     * @param  mixed $identifier
28
-     * @return bool
29
-     */
30
-    public function add($object, $identifier = null);
31
-
32
-    /**
33
-     * setIdentifier
34
-     * Sets the data associated with an object in the Collection
35
-     * if no $identifier is supplied, then the spl_object_hash() is used
36
-     *
37
-     * @access public
38
-     * @param        $object
39
-     * @param  mixed $identifier
40
-     * @return bool
41
-     */
42
-    public function setIdentifier($object, $identifier = null);
43
-
44
-    /**
45
-     * get
46
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
47
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
48
-     *
49
-     * @access public
50
-     * @param mixed $identifier
51
-     * @return mixed
52
-     */
53
-    public function get($identifier);
54
-
55
-    /**
56
-     * has
57
-     * returns TRUE or FALSE
58
-     * depending on whether the object is within the Collection
59
-     * based on the supplied $identifier
60
-     *
61
-     * @access public
62
-     * @param  mixed $identifier
63
-     * @return bool
64
-     */
65
-    public function has($identifier);
66
-
67
-    /**
68
-     * hasObject
69
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
70
-     *
71
-     * @access public
72
-     * @param $object
73
-     * @return bool
74
-     */
75
-    public function hasObject($object);
76
-
77
-    /**
78
-     * remove
79
-     * detaches an object from the Collection
80
-     *
81
-     * @access public
82
-     * @param $object
83
-     * @return bool
84
-     */
85
-    public function remove($object);
86
-
87
-    /**
88
-     * setCurrent
89
-     * advances pointer to the object whose identifier matches that which was provided
90
-     *
91
-     * @access public
92
-     * @param mixed $identifier
93
-     * @return boolean
94
-     */
95
-    public function setCurrent($identifier);
96
-
97
-    /**
98
-     * setCurrentUsingObject
99
-     * advances pointer to the provided object
100
-     *
101
-     * @access public
102
-     * @param $object
103
-     * @return boolean
104
-     */
105
-    public function setCurrentUsingObject($object);
106
-
107
-    /**
108
-     * Returns the object occupying the index before the current object,
109
-     * unless this is already the first object, in which case it just returns the first object
110
-     *
111
-     * @return mixed
112
-     */
113
-    public function previous();
114
-
115
-        /**
116
-     * Returns the index of a given object, or false if not found
117
-     *
118
-     * @see http://stackoverflow.com/a/8736013
119
-     * @param $object
120
-     * @return boolean|int|string
121
-     */
122
-    public function indexOf($object);
123
-
124
-
125
-    /**
126
-     * Returns the object at the given index
127
-     *
128
-     * @see http://stackoverflow.com/a/8736013
129
-     * @param $index
130
-     * @return mixed
131
-     */
132
-    public function objectAtIndex($index);
133
-
134
-    /**
135
-     * Returns the sequence of objects as specified by the offset and length
136
-     *
137
-     * @see http://stackoverflow.com/a/8736013
138
-     * @param int $offset
139
-     * @param int $length
140
-     * @return array
141
-     */
142
-    public function slice($offset, $length);
143
-
144
-    /**
145
-     * Inserts an object (or an array of objects) at a certain point
146
-     *
147
-     * @see http://stackoverflow.com/a/8736013
148
-     * @param mixed   $objects A single object or an array of objects
149
-     * @param integer $index
150
-     */
151
-    public function insertAt($objects, $index);
152
-
153
-    /**
154
-     * Removes the object at the given index
155
-     *
156
-     * @see http://stackoverflow.com/a/8736013
157
-     * @param integer $index
158
-     */
159
-    public function removeAt($index);
160
-
161
-
162
-
163
-    /**
164
-     * detaches ALL objects from the Collection
165
-     */
166
-    public function detachAll();
167
-
168
-
169
-
170
-    /**
171
-     * unsets and detaches ALL objects from the Collection
172
-     */
173
-    public function trashAndDetachAll();
19
+	/**
20
+	 * add
21
+	 * attaches an object to the Collection
22
+	 * and sets any supplied data associated with the current iterator entry
23
+	 * by calling EE_Object_Collection::set_identifier()
24
+	 *
25
+	 * @access public
26
+	 * @param        $object
27
+	 * @param  mixed $identifier
28
+	 * @return bool
29
+	 */
30
+	public function add($object, $identifier = null);
31
+
32
+	/**
33
+	 * setIdentifier
34
+	 * Sets the data associated with an object in the Collection
35
+	 * if no $identifier is supplied, then the spl_object_hash() is used
36
+	 *
37
+	 * @access public
38
+	 * @param        $object
39
+	 * @param  mixed $identifier
40
+	 * @return bool
41
+	 */
42
+	public function setIdentifier($object, $identifier = null);
43
+
44
+	/**
45
+	 * get
46
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
47
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
48
+	 *
49
+	 * @access public
50
+	 * @param mixed $identifier
51
+	 * @return mixed
52
+	 */
53
+	public function get($identifier);
54
+
55
+	/**
56
+	 * has
57
+	 * returns TRUE or FALSE
58
+	 * depending on whether the object is within the Collection
59
+	 * based on the supplied $identifier
60
+	 *
61
+	 * @access public
62
+	 * @param  mixed $identifier
63
+	 * @return bool
64
+	 */
65
+	public function has($identifier);
66
+
67
+	/**
68
+	 * hasObject
69
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
70
+	 *
71
+	 * @access public
72
+	 * @param $object
73
+	 * @return bool
74
+	 */
75
+	public function hasObject($object);
76
+
77
+	/**
78
+	 * remove
79
+	 * detaches an object from the Collection
80
+	 *
81
+	 * @access public
82
+	 * @param $object
83
+	 * @return bool
84
+	 */
85
+	public function remove($object);
86
+
87
+	/**
88
+	 * setCurrent
89
+	 * advances pointer to the object whose identifier matches that which was provided
90
+	 *
91
+	 * @access public
92
+	 * @param mixed $identifier
93
+	 * @return boolean
94
+	 */
95
+	public function setCurrent($identifier);
96
+
97
+	/**
98
+	 * setCurrentUsingObject
99
+	 * advances pointer to the provided object
100
+	 *
101
+	 * @access public
102
+	 * @param $object
103
+	 * @return boolean
104
+	 */
105
+	public function setCurrentUsingObject($object);
106
+
107
+	/**
108
+	 * Returns the object occupying the index before the current object,
109
+	 * unless this is already the first object, in which case it just returns the first object
110
+	 *
111
+	 * @return mixed
112
+	 */
113
+	public function previous();
114
+
115
+		/**
116
+		 * Returns the index of a given object, or false if not found
117
+		 *
118
+		 * @see http://stackoverflow.com/a/8736013
119
+		 * @param $object
120
+		 * @return boolean|int|string
121
+		 */
122
+	public function indexOf($object);
123
+
124
+
125
+	/**
126
+	 * Returns the object at the given index
127
+	 *
128
+	 * @see http://stackoverflow.com/a/8736013
129
+	 * @param $index
130
+	 * @return mixed
131
+	 */
132
+	public function objectAtIndex($index);
133
+
134
+	/**
135
+	 * Returns the sequence of objects as specified by the offset and length
136
+	 *
137
+	 * @see http://stackoverflow.com/a/8736013
138
+	 * @param int $offset
139
+	 * @param int $length
140
+	 * @return array
141
+	 */
142
+	public function slice($offset, $length);
143
+
144
+	/**
145
+	 * Inserts an object (or an array of objects) at a certain point
146
+	 *
147
+	 * @see http://stackoverflow.com/a/8736013
148
+	 * @param mixed   $objects A single object or an array of objects
149
+	 * @param integer $index
150
+	 */
151
+	public function insertAt($objects, $index);
152
+
153
+	/**
154
+	 * Removes the object at the given index
155
+	 *
156
+	 * @see http://stackoverflow.com/a/8736013
157
+	 * @param integer $index
158
+	 */
159
+	public function removeAt($index);
160
+
161
+
162
+
163
+	/**
164
+	 * detaches ALL objects from the Collection
165
+	 */
166
+	public function detachAll();
167
+
168
+
169
+
170
+	/**
171
+	 * unsets and detaches ALL objects from the Collection
172
+	 */
173
+	public function trashAndDetachAll();
174 174
 }
Please login to merge, or discard this patch.
core/services/bootstrap/BootstrapCore.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -46,225 +46,225 @@
 block discarded – undo
46 46
 class BootstrapCore
47 47
 {
48 48
 
49
-    /**
50
-     * @type LoaderInterface $loader
51
-     */
52
-    private $loader;
49
+	/**
50
+	 * @type LoaderInterface $loader
51
+	 */
52
+	private $loader;
53 53
 
54
-    /**
55
-     * @var RequestInterface $request
56
-     */
57
-    protected $request;
54
+	/**
55
+	 * @var RequestInterface $request
56
+	 */
57
+	protected $request;
58 58
 
59
-    /**
60
-     * @var ResponseInterface $response
61
-     */
62
-    protected $response;
59
+	/**
60
+	 * @var ResponseInterface $response
61
+	 */
62
+	protected $response;
63 63
 
64
-    /**
65
-     * @var RequestStackBuilder $request_stack_builder
66
-     */
67
-    protected $request_stack_builder;
64
+	/**
65
+	 * @var RequestStackBuilder $request_stack_builder
66
+	 */
67
+	protected $request_stack_builder;
68 68
 
69
-    /**
70
-     * @var RequestStack $request_stack
71
-     */
72
-    protected $request_stack;
69
+	/**
70
+	 * @var RequestStack $request_stack
71
+	 */
72
+	protected $request_stack;
73 73
 
74 74
 
75
-    /**
76
-     * BootstrapCore constructor.
77
-     */
78
-    public function __construct()
79
-    {
80
-        do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct');
81
-        // construct request stack and run middleware apps as soon as all WP plugins are loaded
82
-        add_action('plugins_loaded', array($this, 'initialize'), 0);
83
-    }
75
+	/**
76
+	 * BootstrapCore constructor.
77
+	 */
78
+	public function __construct()
79
+	{
80
+		do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct');
81
+		// construct request stack and run middleware apps as soon as all WP plugins are loaded
82
+		add_action('plugins_loaded', array($this, 'initialize'), 0);
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * @throws DomainException
88
-     * @throws EE_Error
89
-     * @throws Exception
90
-     * @throws InvalidArgumentException
91
-     * @throws InvalidClassException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidFilePathException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidRequestStackMiddlewareException
96
-     * @throws OutOfBoundsException
97
-     * @throws ReflectionException
98
-     */
99
-    public function initialize()
100
-    {
101
-        $this->bootstrapDependencyInjectionContainer();
102
-        $this->bootstrapDomain();
103
-        $bootstrap_request = $this->bootstrapRequestResponseObjects();
104
-        add_action(
105
-            'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
106
-            array($bootstrap_request, 'setupLegacyRequest')
107
-        );
108
-        $this->runRequestStack();
109
-    }
86
+	/**
87
+	 * @throws DomainException
88
+	 * @throws EE_Error
89
+	 * @throws Exception
90
+	 * @throws InvalidArgumentException
91
+	 * @throws InvalidClassException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidFilePathException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidRequestStackMiddlewareException
96
+	 * @throws OutOfBoundsException
97
+	 * @throws ReflectionException
98
+	 */
99
+	public function initialize()
100
+	{
101
+		$this->bootstrapDependencyInjectionContainer();
102
+		$this->bootstrapDomain();
103
+		$bootstrap_request = $this->bootstrapRequestResponseObjects();
104
+		add_action(
105
+			'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
106
+			array($bootstrap_request, 'setupLegacyRequest')
107
+		);
108
+		$this->runRequestStack();
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * @throws ReflectionException
114
-     * @throws EE_Error
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidInterfaceException
118
-     * @throws OutOfBoundsException
119
-     */
120
-    private function bootstrapDependencyInjectionContainer()
121
-    {
122
-        $bootstrap_di = new BootstrapDependencyInjectionContainer();
123
-        $bootstrap_di->buildLegacyDependencyInjectionContainer();
124
-        $bootstrap_di->buildLoader();
125
-        $registry = $bootstrap_di->getRegistry();
126
-        $dependency_map = $bootstrap_di->getDependencyMap();
127
-        $dependency_map->initialize();
128
-        $registry->initialize();
129
-        $this->loader = $bootstrap_di->getLoader();
130
-    }
112
+	/**
113
+	 * @throws ReflectionException
114
+	 * @throws EE_Error
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidInterfaceException
118
+	 * @throws OutOfBoundsException
119
+	 */
120
+	private function bootstrapDependencyInjectionContainer()
121
+	{
122
+		$bootstrap_di = new BootstrapDependencyInjectionContainer();
123
+		$bootstrap_di->buildLegacyDependencyInjectionContainer();
124
+		$bootstrap_di->buildLoader();
125
+		$registry = $bootstrap_di->getRegistry();
126
+		$dependency_map = $bootstrap_di->getDependencyMap();
127
+		$dependency_map->initialize();
128
+		$registry->initialize();
129
+		$this->loader = $bootstrap_di->getLoader();
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * configures the Domain object for core
135
-     *
136
-     * @return void
137
-     * @throws DomainException
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidClassException
141
-     * @throws InvalidFilePathException
142
-     * @throws InvalidInterfaceException
143
-     */
144
-    private function bootstrapDomain()
145
-    {
146
-        DomainFactory::getEventEspressoCoreDomain();
147
-    }
133
+	/**
134
+	 * configures the Domain object for core
135
+	 *
136
+	 * @return void
137
+	 * @throws DomainException
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidClassException
141
+	 * @throws InvalidFilePathException
142
+	 * @throws InvalidInterfaceException
143
+	 */
144
+	private function bootstrapDomain()
145
+	{
146
+		DomainFactory::getEventEspressoCoreDomain();
147
+	}
148 148
 
149 149
 
150
-    /**
151
-     * sets up the request and response objects
152
-     *
153
-     * @return BootstrapRequestResponseObjects
154
-     * @throws InvalidArgumentException
155
-     */
156
-    private function bootstrapRequestResponseObjects()
157
-    {
158
-        /** @var BootstrapRequestResponseObjects $bootstrap_request */
159
-        $bootstrap_request = $this->loader->getShared(
160
-            'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
161
-            array($this->loader)
162
-        );
163
-        $bootstrap_request->buildRequestResponse();
164
-        $bootstrap_request->shareRequestResponse();
165
-        $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request');
166
-        $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
167
-        return $bootstrap_request;
168
-    }
150
+	/**
151
+	 * sets up the request and response objects
152
+	 *
153
+	 * @return BootstrapRequestResponseObjects
154
+	 * @throws InvalidArgumentException
155
+	 */
156
+	private function bootstrapRequestResponseObjects()
157
+	{
158
+		/** @var BootstrapRequestResponseObjects $bootstrap_request */
159
+		$bootstrap_request = $this->loader->getShared(
160
+			'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
161
+			array($this->loader)
162
+		);
163
+		$bootstrap_request->buildRequestResponse();
164
+		$bootstrap_request->shareRequestResponse();
165
+		$this->request = $this->loader->getShared('EventEspresso\core\services\request\Request');
166
+		$this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
167
+		return $bootstrap_request;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * run_request_stack
173
-     * construct request stack and run middleware apps
174
-     *
175
-     * @throws EE_Error
176
-     * @throws Exception
177
-     */
178
-    public function runRequestStack()
179
-    {
180
-        $this->loadAutoloader();
181
-        $this->setAutoloadersForRequiredFiles();
182
-        $this->request_stack_builder = $this->buildRequestStack();
183
-        $this->request_stack = $this->request_stack_builder->resolve(
184
-            new RequestStackCoreApp()
185
-        );
186
-        $this->request_stack->handleRequest($this->request, $this->response);
187
-        $this->request_stack->handleResponse();
188
-    }
171
+	/**
172
+	 * run_request_stack
173
+	 * construct request stack and run middleware apps
174
+	 *
175
+	 * @throws EE_Error
176
+	 * @throws Exception
177
+	 */
178
+	public function runRequestStack()
179
+	{
180
+		$this->loadAutoloader();
181
+		$this->setAutoloadersForRequiredFiles();
182
+		$this->request_stack_builder = $this->buildRequestStack();
183
+		$this->request_stack = $this->request_stack_builder->resolve(
184
+			new RequestStackCoreApp()
185
+		);
186
+		$this->request_stack->handleRequest($this->request, $this->response);
187
+		$this->request_stack->handleResponse();
188
+	}
189 189
 
190 190
 
191
-    /**
192
-     * load_autoloader
193
-     *
194
-     * @throws EE_Error
195
-     */
196
-    protected function loadAutoloader()
197
-    {
198
-        // load interfaces
199
-        espresso_load_required(
200
-            'EEH_Autoloader',
201
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
202
-        );
203
-        EEH_Autoloader::instance();
204
-    }
191
+	/**
192
+	 * load_autoloader
193
+	 *
194
+	 * @throws EE_Error
195
+	 */
196
+	protected function loadAutoloader()
197
+	{
198
+		// load interfaces
199
+		espresso_load_required(
200
+			'EEH_Autoloader',
201
+			EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
202
+		);
203
+		EEH_Autoloader::instance();
204
+	}
205 205
 
206 206
 
207
-    /**
208
-     * load_required_files
209
-     *
210
-     * @throws EE_Error
211
-     */
212
-    protected function setAutoloadersForRequiredFiles()
213
-    {
214
-        // load interfaces
215
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
216
-        // load helpers
217
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
218
-        // register legacy request stack classes just in case
219
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
220
-        // register legacy middleware classes just in case
221
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
222
-    }
207
+	/**
208
+	 * load_required_files
209
+	 *
210
+	 * @throws EE_Error
211
+	 */
212
+	protected function setAutoloadersForRequiredFiles()
213
+	{
214
+		// load interfaces
215
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
216
+		// load helpers
217
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
218
+		// register legacy request stack classes just in case
219
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
220
+		// register legacy middleware classes just in case
221
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
222
+	}
223 223
 
224 224
 
225
-    /**
226
-     * build_request_stack
227
-     *
228
-     * @return RequestStackBuilder
229
-     */
230
-    public function buildRequestStack()
231
-    {
232
-        $request_stack_builder = new RequestStackBuilder($this->loader);
233
-        /**
234
-         * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
235
-         * so items at the beginning of the final middleware stack will run last.
236
-         * First parameter is the middleware classname, second is an array of arguments
237
-         */
238
-        $stack_apps = apply_filters(
239
-            'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
240
-            array(
241
-                // first in last out
242
-                'EventEspresso\core\services\request\middleware\BotDetector'                 => array(),
243
-                'EventEspresso\core\services\request\middleware\DetectFileEditorRequest'     => array(),
244
-                'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
245
-                'EventEspresso\core\services\request\middleware\RecommendedVersions'         => array(),
246
-                // last in first out
247
-                'EventEspresso\core\services\request\middleware\DetectLogin'                 => array(),
248
-            )
249
-        );
250
-        // legacy filter for backwards compatibility
251
-        $stack_apps = apply_filters(
252
-            'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
253
-            $stack_apps
254
-        );
255
-        // load middleware onto stack : FILO (First In Last Out)
256
-        // items at the beginning of the $stack_apps array will run last
257
-        foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
258
-            $request_stack_builder->push(array($stack_app, $stack_app_args));
259
-        }
260
-        // finally, we'll add this on its own because we need it to always be part of the stack
261
-        // and we also need it to always run first because the rest of the system relies on it
262
-        $request_stack_builder->push(
263
-            array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
264
-        );
265
-        return apply_filters(
266
-            'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
267
-            $request_stack_builder
268
-        );
269
-    }
225
+	/**
226
+	 * build_request_stack
227
+	 *
228
+	 * @return RequestStackBuilder
229
+	 */
230
+	public function buildRequestStack()
231
+	{
232
+		$request_stack_builder = new RequestStackBuilder($this->loader);
233
+		/**
234
+		 * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
235
+		 * so items at the beginning of the final middleware stack will run last.
236
+		 * First parameter is the middleware classname, second is an array of arguments
237
+		 */
238
+		$stack_apps = apply_filters(
239
+			'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
240
+			array(
241
+				// first in last out
242
+				'EventEspresso\core\services\request\middleware\BotDetector'                 => array(),
243
+				'EventEspresso\core\services\request\middleware\DetectFileEditorRequest'     => array(),
244
+				'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
245
+				'EventEspresso\core\services\request\middleware\RecommendedVersions'         => array(),
246
+				// last in first out
247
+				'EventEspresso\core\services\request\middleware\DetectLogin'                 => array(),
248
+			)
249
+		);
250
+		// legacy filter for backwards compatibility
251
+		$stack_apps = apply_filters(
252
+			'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
253
+			$stack_apps
254
+		);
255
+		// load middleware onto stack : FILO (First In Last Out)
256
+		// items at the beginning of the $stack_apps array will run last
257
+		foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
258
+			$request_stack_builder->push(array($stack_app, $stack_app_args));
259
+		}
260
+		// finally, we'll add this on its own because we need it to always be part of the stack
261
+		// and we also need it to always run first because the rest of the system relies on it
262
+		$request_stack_builder->push(
263
+			array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
264
+		);
265
+		return apply_filters(
266
+			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
267
+			$request_stack_builder
268
+		);
269
+	}
270 270
 }
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Indentation   +1240 added lines, -1240 removed lines patch added patch discarded remove patch
@@ -22,1244 +22,1244 @@
 block discarded – undo
22 22
 class EED_Core_Rest_Api extends \EED_Module
23 23
 {
24 24
 
25
-    const ee_api_namespace = Domain::API_NAMESPACE;
26
-
27
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
28
-
29
-    const saved_routes_option_names = 'ee_core_routes';
30
-
31
-    /**
32
-     * string used in _links response bodies to make them globally unique.
33
-     *
34
-     * @see http://v2.wp-api.org/extending/linking/
35
-     */
36
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
37
-
38
-    /**
39
-     * @var CalculatedModelFields
40
-     */
41
-    protected static $_field_calculator;
42
-
43
-
44
-    /**
45
-     * @return EED_Core_Rest_Api|EED_Module
46
-     */
47
-    public static function instance()
48
-    {
49
-        self::$_field_calculator = new CalculatedModelFields();
50
-        return parent::get_instance(__CLASS__);
51
-    }
52
-
53
-
54
-    /**
55
-     *    set_hooks - for hooking into EE Core, other modules, etc
56
-     *
57
-     * @access    public
58
-     * @return    void
59
-     */
60
-    public static function set_hooks()
61
-    {
62
-        self::set_hooks_both();
63
-    }
64
-
65
-
66
-    /**
67
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
68
-     *
69
-     * @access    public
70
-     * @return    void
71
-     */
72
-    public static function set_hooks_admin()
73
-    {
74
-        self::set_hooks_both();
75
-    }
76
-
77
-
78
-    public static function set_hooks_both()
79
-    {
80
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
-        add_filter(
84
-            'rest_index',
85
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
86
-        );
87
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
-    }
89
-
90
-
91
-    /**
92
-     * sets up hooks which only need to be included as part of REST API requests;
93
-     * other requests like to the frontend or admin etc don't need them
94
-     *
95
-     * @throws \EE_Error
96
-     */
97
-    public static function set_hooks_rest_api()
98
-    {
99
-        // set hooks which account for changes made to the API
100
-        EED_Core_Rest_Api::_set_hooks_for_changes();
101
-    }
102
-
103
-
104
-    /**
105
-     * public wrapper of _set_hooks_for_changes.
106
-     * Loads all the hooks which make requests to old versions of the API
107
-     * appear the same as they always did
108
-     *
109
-     * @throws EE_Error
110
-     */
111
-    public static function set_hooks_for_changes()
112
-    {
113
-        self::_set_hooks_for_changes();
114
-    }
115
-
116
-
117
-    /**
118
-     * Loads all the hooks which make requests to old versions of the API
119
-     * appear the same as they always did
120
-     *
121
-     * @throws EE_Error
122
-     */
123
-    protected static function _set_hooks_for_changes()
124
-    {
125
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
126
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
127
-            // ignore the base parent class
128
-            // and legacy named classes
129
-            if ($classname_in_namespace === 'ChangesInBase'
130
-                || strpos($classname_in_namespace, 'Changes_In_') === 0
131
-            ) {
132
-                continue;
133
-            }
134
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
135
-            if (class_exists($full_classname)) {
136
-                $instance_of_class = new $full_classname;
137
-                if ($instance_of_class instanceof ChangesInBase) {
138
-                    $instance_of_class->setHooks();
139
-                }
140
-            }
141
-        }
142
-    }
143
-
144
-
145
-    /**
146
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
147
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
148
-     *
149
-     * @throws \EE_Error
150
-     */
151
-    public static function register_routes()
152
-    {
153
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
154
-            foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
155
-                /**
156
-                 * @var array     $data_for_multiple_endpoints numerically indexed array
157
-                 *                                         but can also contain route options like {
158
-                 * @type array    $schema                      {
159
-                 * @type callable $schema_callback
160
-                 * @type array    $callback_args               arguments that will be passed to the callback, after the
161
-                 * WP_REST_Request of course
162
-                 * }
163
-                 * }
164
-                 */
165
-                // when registering routes, register all the endpoints' data at the same time
166
-                $multiple_endpoint_args = array();
167
-                foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
168
-                    /**
169
-                     * @var array     $data_for_single_endpoint {
170
-                     * @type callable $callback
171
-                     * @type string methods
172
-                     * @type array args
173
-                     * @type array _links
174
-                     * @type array    $callback_args            arguments that will be passed to the callback, after the
175
-                     * WP_REST_Request of course
176
-                     * }
177
-                     */
178
-                    // skip route options
179
-                    if (! is_numeric($endpoint_key)) {
180
-                        continue;
181
-                    }
182
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
183
-                        throw new EE_Error(
184
-                            esc_html__(
185
-                            // @codingStandardsIgnoreStart
186
-                                'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
187
-                                // @codingStandardsIgnoreEnd
188
-                                'event_espresso'
189
-                            )
190
-                        );
191
-                    }
192
-                    $callback = $data_for_single_endpoint['callback'];
193
-                    $single_endpoint_args = array(
194
-                        'methods' => $data_for_single_endpoint['methods'],
195
-                        'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
196
-                            : array(),
197
-                    );
198
-                    if (isset($data_for_single_endpoint['_links'])) {
199
-                        $single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
200
-                    }
201
-                    if (isset($data_for_single_endpoint['callback_args'])) {
202
-                        $callback_args = $data_for_single_endpoint['callback_args'];
203
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
204
-                            $callback,
205
-                            $callback_args
206
-                        ) {
207
-                            array_unshift($callback_args, $request);
208
-                            return call_user_func_array(
209
-                                $callback,
210
-                                $callback_args
211
-                            );
212
-                        };
213
-                    } else {
214
-                        $single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
215
-                    }
216
-                    $multiple_endpoint_args[] = $single_endpoint_args;
217
-                }
218
-                if (isset($data_for_multiple_endpoints['schema'])) {
219
-                    $schema_route_data = $data_for_multiple_endpoints['schema'];
220
-                    $schema_callback = $schema_route_data['schema_callback'];
221
-                    $callback_args = $schema_route_data['callback_args'];
222
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
223
-                        return call_user_func_array(
224
-                            $schema_callback,
225
-                            $callback_args
226
-                        );
227
-                    };
228
-                }
229
-                register_rest_route(
230
-                    $namespace,
231
-                    $relative_route,
232
-                    $multiple_endpoint_args
233
-                );
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * Checks if there was a version change or something that merits invalidating the cached
241
-     * route data. If so, invalidates the cached route data so that it gets refreshed
242
-     * next time the WP API is used
243
-     */
244
-    public static function invalidate_cached_route_data_on_version_change()
245
-    {
246
-        if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
247
-            EED_Core_Rest_Api::invalidate_cached_route_data();
248
-        }
249
-        foreach (EE_Registry::instance()->addons as $addon) {
250
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
251
-                EED_Core_Rest_Api::invalidate_cached_route_data();
252
-            }
253
-        }
254
-    }
255
-
256
-
257
-    /**
258
-     * Removes the cached route data so it will get refreshed next time the WP API is used
259
-     */
260
-    public static function invalidate_cached_route_data()
261
-    {
262
-        // delete the saved EE REST API routes
263
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
264
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
265
-        }
266
-    }
267
-
268
-
269
-    /**
270
-     * Gets the EE route data
271
-     *
272
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
273
-     * @throws \EE_Error
274
-     * @type string|array $callback
275
-     * @type string       $methods
276
-     * @type boolean      $hidden_endpoint
277
-     * }
278
-     */
279
-    public static function get_ee_route_data()
280
-    {
281
-        $ee_routes = array();
282
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
283
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
284
-                $version,
285
-                $hidden_endpoints
286
-            );
287
-        }
288
-        return $ee_routes;
289
-    }
290
-
291
-
292
-    /**
293
-     * Gets the EE route data from the wp options if it exists already,
294
-     * otherwise re-generates it and saves it to the option
295
-     *
296
-     * @param string  $version
297
-     * @param boolean $hidden_endpoints
298
-     * @return array
299
-     * @throws \EE_Error
300
-     */
301
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
302
-    {
303
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
304
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
305
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
306
-        }
307
-        return $ee_routes;
308
-    }
309
-
310
-
311
-    /**
312
-     * Saves the EE REST API route data to a wp option and returns it
313
-     *
314
-     * @param string  $version
315
-     * @param boolean $hidden_endpoints
316
-     * @return mixed|null
317
-     * @throws \EE_Error
318
-     */
319
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
320
-    {
321
-        $instance = self::instance();
322
-        $routes = apply_filters(
323
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
324
-            array_replace_recursive(
325
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
326
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
327
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
328
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
329
-            )
330
-        );
331
-        $option_name = self::saved_routes_option_names . $version;
332
-        if (get_option($option_name)) {
333
-            update_option($option_name, $routes, true);
334
-        } else {
335
-            add_option($option_name, $routes, null, 'no');
336
-        }
337
-        return $routes;
338
-    }
339
-
340
-
341
-    /**
342
-     * Calculates all the EE routes and saves it to a WordPress option so we don't
343
-     * need to calculate it on every request
344
-     *
345
-     * @deprecated since version 4.9.1
346
-     * @return void
347
-     */
348
-    public static function save_ee_routes()
349
-    {
350
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
351
-            $instance = self::instance();
352
-            $routes = apply_filters(
353
-                'EED_Core_Rest_Api__save_ee_routes__routes',
354
-                array_replace_recursive(
355
-                    $instance->_register_config_routes(),
356
-                    $instance->_register_meta_routes(),
357
-                    $instance->_register_model_routes(),
358
-                    $instance->_register_rpc_routes()
359
-                )
360
-            );
361
-            update_option(self::saved_routes_option_names, $routes, true);
362
-        }
363
-    }
364
-
365
-
366
-    /**
367
-     * Gets all the route information relating to EE models
368
-     *
369
-     * @return array @see get_ee_route_data
370
-     * @deprecated since version 4.9.1
371
-     */
372
-    protected function _register_model_routes()
373
-    {
374
-        $model_routes = array();
375
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
376
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
377
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
378
-        }
379
-        return $model_routes;
380
-    }
381
-
382
-
383
-    /**
384
-     * Decides whether or not to add write endpoints for this model.
385
-     *
386
-     * Currently, this defaults to exclude all global tables and models
387
-     * which would allow inserting WP core data (we don't want to duplicate
388
-     * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
389
-     *
390
-     * @param EEM_Base $model
391
-     * @return bool
392
-     */
393
-    public static function should_have_write_endpoints(EEM_Base $model)
394
-    {
395
-        if ($model->is_wp_core_model()) {
396
-            return false;
397
-        }
398
-        foreach ($model->get_tables() as $table) {
399
-            if ($table->is_global()) {
400
-                return false;
401
-            }
402
-        }
403
-        return true;
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
409
-     * in this versioned namespace of EE4
410
-     *
411
-     * @param $version
412
-     * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
413
-     */
414
-    public static function model_names_with_plural_routes($version)
415
-    {
416
-        $model_version_info = new ModelVersionInfo($version);
417
-        $models_to_register = $model_version_info->modelsForRequestedVersion();
418
-        // let's not bother having endpoints for extra metas
419
-        unset(
420
-            $models_to_register['Extra_Meta'],
421
-            $models_to_register['Extra_Join'],
422
-            $models_to_register['Post_Meta']
423
-        );
424
-        return apply_filters(
425
-            'FHEE__EED_Core_REST_API___register_model_routes',
426
-            $models_to_register
427
-        );
428
-    }
429
-
430
-
431
-    /**
432
-     * Gets the route data for EE models in the specified version
433
-     *
434
-     * @param string  $version
435
-     * @param boolean $hidden_endpoint
436
-     * @return array
437
-     * @throws EE_Error
438
-     */
439
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
440
-    {
441
-        $model_routes = array();
442
-        $model_version_info = new ModelVersionInfo($version);
443
-        foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
444
-            $model = \EE_Registry::instance()->load_model($model_name);
445
-            // if this isn't a valid model then let's skip iterate to the next item in the loop.
446
-            if (! $model instanceof EEM_Base) {
447
-                continue;
448
-            }
449
-            // yes we could just register one route for ALL models, but then they wouldn't show up in the index
450
-            $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
451
-            $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
452
-            $model_routes[ $plural_model_route ] = array(
453
-                array(
454
-                    'callback'        => array(
455
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
456
-                        'handleRequestGetAll',
457
-                    ),
458
-                    'callback_args'   => array($version, $model_name),
459
-                    'methods'         => WP_REST_Server::READABLE,
460
-                    'hidden_endpoint' => $hidden_endpoint,
461
-                    'args'            => $this->_get_read_query_params($model, $version),
462
-                    '_links'          => array(
463
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
464
-                    ),
465
-                ),
466
-                'schema' => array(
467
-                    'schema_callback' => array(
468
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
469
-                        'handleSchemaRequest',
470
-                    ),
471
-                    'callback_args'   => array($version, $model_name),
472
-                ),
473
-            );
474
-            $model_routes[ $singular_model_route ] = array(
475
-                array(
476
-                    'callback'        => array(
477
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
478
-                        'handleRequestGetOne',
479
-                    ),
480
-                    'callback_args'   => array($version, $model_name),
481
-                    'methods'         => WP_REST_Server::READABLE,
482
-                    'hidden_endpoint' => $hidden_endpoint,
483
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
484
-                ),
485
-            );
486
-            if (apply_filters(
487
-                'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
488
-                EED_Core_Rest_Api::should_have_write_endpoints($model),
489
-                $model
490
-            )) {
491
-                $model_routes[ $plural_model_route ][] = array(
492
-                    'callback'        => array(
493
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Write',
494
-                        'handleRequestInsert',
495
-                    ),
496
-                    'callback_args'   => array($version, $model_name),
497
-                    'methods'         => WP_REST_Server::CREATABLE,
498
-                    'hidden_endpoint' => $hidden_endpoint,
499
-                    'args'            => $this->_get_write_params($model_name, $model_version_info, true),
500
-                );
501
-                $model_routes[ $singular_model_route ] = array_merge(
502
-                    $model_routes[ $singular_model_route ],
503
-                    array(
504
-                        array(
505
-                            'callback'        => array(
506
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
507
-                                'handleRequestUpdate',
508
-                            ),
509
-                            'callback_args'   => array($version, $model_name),
510
-                            'methods'         => WP_REST_Server::EDITABLE,
511
-                            'hidden_endpoint' => $hidden_endpoint,
512
-                            'args'            => $this->_get_write_params($model_name, $model_version_info),
513
-                        ),
514
-                        array(
515
-                            'callback'        => array(
516
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
517
-                                'handleRequestDelete',
518
-                            ),
519
-                            'callback_args'   => array($version, $model_name),
520
-                            'methods'         => WP_REST_Server::DELETABLE,
521
-                            'hidden_endpoint' => $hidden_endpoint,
522
-                            'args'            => $this->_get_delete_query_params($model, $version),
523
-                        ),
524
-                    )
525
-                );
526
-            }
527
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
528
-                $related_route = EED_Core_Rest_Api::get_relation_route_via(
529
-                    $model,
530
-                    '(?P<id>[^\/]+)',
531
-                    $relation_obj
532
-                );
533
-                $endpoints = array(
534
-                    array(
535
-                        'callback'        => array(
536
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
537
-                            'handleRequestGetRelated',
538
-                        ),
539
-                        'callback_args'   => array($version, $model_name, $relation_name),
540
-                        'methods'         => WP_REST_Server::READABLE,
541
-                        'hidden_endpoint' => $hidden_endpoint,
542
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
543
-                    ),
544
-                );
545
-                $model_routes[ $related_route ] = $endpoints;
546
-            }
547
-        }
548
-        return $model_routes;
549
-    }
550
-
551
-
552
-    /**
553
-     * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
554
-     * excluding the preceding slash.
555
-     * Eg you pass get_plural_route_to('Event') = 'events'
556
-     *
557
-     * @param EEM_Base $model
558
-     * @return string
559
-     */
560
-    public static function get_collection_route(EEM_Base $model)
561
-    {
562
-        return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
563
-    }
564
-
565
-
566
-    /**
567
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
568
-     * excluding the preceding slash.
569
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
570
-     *
571
-     * @param EEM_Base $model eg Event or Venue
572
-     * @param string   $id
573
-     * @return string
574
-     */
575
-    public static function get_entity_route($model, $id)
576
-    {
577
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
578
-    }
579
-
580
-
581
-    /**
582
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
583
-     * excluding the preceding slash.
584
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
585
-     *
586
-     * @param EEM_Base               $model eg Event or Venue
587
-     * @param string                 $id
588
-     * @param EE_Model_Relation_Base $relation_obj
589
-     * @return string
590
-     */
591
-    public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
592
-    {
593
-        $related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
594
-            $relation_obj->get_other_model()->get_this_model_name(),
595
-            $relation_obj
596
-        );
597
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
598
-    }
599
-
600
-
601
-    /**
602
-     * Adds onto the $relative_route the EE4 REST API versioned namespace.
603
-     * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
604
-     *
605
-     * @param string $relative_route
606
-     * @param string $version
607
-     * @return string
608
-     */
609
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36')
610
-    {
611
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
612
-    }
613
-
614
-
615
-    /**
616
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
617
-     * routes that don't conform to the traditional REST CRUD-style).
618
-     *
619
-     * @deprecated since 4.9.1
620
-     */
621
-    protected function _register_rpc_routes()
622
-    {
623
-        $routes = array();
624
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
625
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
626
-                $version,
627
-                $hidden_endpoint
628
-            );
629
-        }
630
-        return $routes;
631
-    }
632
-
633
-
634
-    /**
635
-     * @param string  $version
636
-     * @param boolean $hidden_endpoint
637
-     * @return array
638
-     */
639
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
640
-    {
641
-        $this_versions_routes = array();
642
-        // checkin endpoint
643
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
644
-            array(
645
-                'callback'        => array(
646
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
647
-                    'handleRequestToggleCheckin',
648
-                ),
649
-                'methods'         => WP_REST_Server::CREATABLE,
650
-                'hidden_endpoint' => $hidden_endpoint,
651
-                'args'            => array(
652
-                    'force' => array(
653
-                        'required'    => false,
654
-                        'default'     => false,
655
-                        'description' => __(
656
-                        // @codingStandardsIgnoreStart
657
-                            'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
658
-                            // @codingStandardsIgnoreEnd
659
-                            'event_espresso'
660
-                        ),
661
-                    ),
662
-                ),
663
-                'callback_args'   => array($version),
664
-            ),
665
-        );
666
-        return apply_filters(
667
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
668
-            $this_versions_routes,
669
-            $version,
670
-            $hidden_endpoint
671
-        );
672
-    }
673
-
674
-
675
-    /**
676
-     * Gets the query params that can be used when request one or many
677
-     *
678
-     * @param EEM_Base $model
679
-     * @param string   $version
680
-     * @return array
681
-     */
682
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
683
-    {
684
-        return apply_filters(
685
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
686
-            array(
687
-                'include'   => array(
688
-                    'required' => false,
689
-                    'default'  => '*',
690
-                    'type'     => 'string',
691
-                ),
692
-                'calculate' => array(
693
-                    'required'          => false,
694
-                    'default'           => '',
695
-                    'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
696
-                    'type'              => 'string',
697
-                    // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
698
-                    // freaks out. We'll just validate this argument while handling the request
699
-                    'validate_callback' => null,
700
-                    'sanitize_callback' => null,
701
-                ),
702
-            ),
703
-            $model,
704
-            $version
705
-        );
706
-    }
707
-
708
-
709
-    /**
710
-     * Gets the parameters acceptable for delete requests
711
-     *
712
-     * @param \EEM_Base $model
713
-     * @param string    $version
714
-     * @return array
715
-     */
716
-    protected function _get_delete_query_params(\EEM_Base $model, $version)
717
-    {
718
-        $params_for_delete = array(
719
-            'allow_blocking' => array(
720
-                'required' => false,
721
-                'default'  => true,
722
-                'type'     => 'boolean',
723
-            ),
724
-        );
725
-        $params_for_delete['force'] = array(
726
-            'required' => false,
727
-            'default'  => false,
728
-            'type'     => 'boolean',
729
-        );
730
-        return apply_filters(
731
-            'FHEE__EED_Core_Rest_Api___get_delete_query_params',
732
-            $params_for_delete,
733
-            $model,
734
-            $version
735
-        );
736
-    }
737
-
738
-
739
-    /**
740
-     * Gets info about reading query params that are acceptable
741
-     *
742
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
743
-     * @param  string   $version
744
-     * @return array    describing the args acceptable when querying this model
745
-     * @throws EE_Error
746
-     */
747
-    protected function _get_read_query_params(\EEM_Base $model, $version)
748
-    {
749
-        $default_orderby = array();
750
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
751
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
752
-        }
753
-        return array_merge(
754
-            $this->_get_response_selection_query_params($model, $version),
755
-            array(
756
-                'where'    => array(
757
-                    'required'          => false,
758
-                    'default'           => array(),
759
-                    'type'              => 'object',
760
-                    // because we accept an almost infinite list of possible where conditions, WP
761
-                    // core validation and sanitization freaks out. We'll just validate this argument
762
-                    // while handling the request
763
-                    'validate_callback' => null,
764
-                    'sanitize_callback' => null,
765
-                ),
766
-                'limit'    => array(
767
-                    'required'          => false,
768
-                    'default'           => EED_Core_Rest_Api::get_default_query_limit(),
769
-                    'type'              => array(
770
-                        'array',
771
-                        'string',
772
-                        'integer',
773
-                    ),
774
-                    // because we accept a variety of types, WP core validation and sanitization
775
-                    // freaks out. We'll just validate this argument while handling the request
776
-                    'validate_callback' => null,
777
-                    'sanitize_callback' => null,
778
-                ),
779
-                'order_by' => array(
780
-                    'required'          => false,
781
-                    'default'           => $default_orderby,
782
-                    'type'              => array(
783
-                        'object',
784
-                        'string',
785
-                    ),// because we accept a variety of types, WP core validation and sanitization
786
-                    // freaks out. We'll just validate this argument while handling the request
787
-                    'validate_callback' => null,
788
-                    'sanitize_callback' => null,
789
-                ),
790
-                'group_by' => array(
791
-                    'required'          => false,
792
-                    'default'           => null,
793
-                    'type'              => array(
794
-                        'object',
795
-                        'string',
796
-                    ),
797
-                    // because we accept  an almost infinite list of possible groupings,
798
-                    // WP core validation and sanitization
799
-                    // freaks out. We'll just validate this argument while handling the request
800
-                    'validate_callback' => null,
801
-                    'sanitize_callback' => null,
802
-                ),
803
-                'having'   => array(
804
-                    'required'          => false,
805
-                    'default'           => null,
806
-                    'type'              => 'object',
807
-                    // because we accept an almost infinite list of possible where conditions, WP
808
-                    // core validation and sanitization freaks out. We'll just validate this argument
809
-                    // while handling the request
810
-                    'validate_callback' => null,
811
-                    'sanitize_callback' => null,
812
-                ),
813
-                'caps'     => array(
814
-                    'required' => false,
815
-                    'default'  => EEM_Base::caps_read,
816
-                    'type'     => 'string',
817
-                    'enum'     => array(
818
-                        EEM_Base::caps_read,
819
-                        EEM_Base::caps_read_admin,
820
-                        EEM_Base::caps_edit,
821
-                        EEM_Base::caps_delete,
822
-                    ),
823
-                ),
824
-            )
825
-        );
826
-    }
827
-
828
-
829
-    /**
830
-     * Gets parameter information for a model regarding writing data
831
-     *
832
-     * @param string           $model_name
833
-     * @param ModelVersionInfo $model_version_info
834
-     * @param boolean          $create                                       whether this is for request to create (in
835
-     *                                                                       which case we need all required params) or
836
-     *                                                                       just to update (in which case we don't
837
-     *                                                                       need those on every request)
838
-     * @return array
839
-     */
840
-    protected function _get_write_params(
841
-        $model_name,
842
-        ModelVersionInfo $model_version_info,
843
-        $create = false
844
-    ) {
845
-        $model = EE_Registry::instance()->load_model($model_name);
846
-        $fields = $model_version_info->fieldsOnModelInThisVersion($model);
847
-        $args_info = array();
848
-        foreach ($fields as $field_name => $field_obj) {
849
-            if ($field_obj->is_auto_increment()) {
850
-                // totally ignore auto increment IDs
851
-                continue;
852
-            }
853
-            $arg_info = $field_obj->getSchema();
854
-            $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
855
-            $arg_info['required'] = $required;
856
-            // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
857
-            unset($arg_info['readonly']);
858
-            $schema_properties = $field_obj->getSchemaProperties();
859
-            if (isset($schema_properties['raw'])
860
-                && $field_obj->getSchemaType() === 'object'
861
-            ) {
862
-                // if there's a "raw" form of this argument, use those properties instead
863
-                $arg_info = array_replace(
864
-                    $arg_info,
865
-                    $schema_properties['raw']
866
-                );
867
-            }
868
-            $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
869
-                $field_obj,
870
-                $field_obj->get_default_value(),
871
-                $model_version_info->requestedVersion()
872
-            );
873
-            // we do our own validation and sanitization within the controller
874
-            if (function_exists('rest_validate_value_from_schema')) {
875
-                $sanitize_callback = array(
876
-                    'EED_Core_Rest_Api',
877
-                    'default_sanitize_callback',
878
-                );
879
-            } else {
880
-                $sanitize_callback = null;
881
-            }
882
-            $arg_info['sanitize_callback'] = $sanitize_callback;
883
-            $args_info[ $field_name ] = $arg_info;
884
-            if ($field_obj instanceof EE_Datetime_Field) {
885
-                $gmt_arg_info = $arg_info;
886
-                $gmt_arg_info['description'] = sprintf(
887
-                    esc_html__(
888
-                        '%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
889
-                        'event_espresso'
890
-                    ),
891
-                    $field_obj->get_nicename(),
892
-                    $field_name
893
-                );
894
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
895
-            }
896
-        }
897
-        return $args_info;
898
-    }
899
-
900
-
901
-    /**
902
-     * Replacement for WP API's 'rest_parse_request_arg'.
903
-     * If the value is blank but not required, don't bother validating it.
904
-     * Also, it uses our email validation instead of WP API's default.
905
-     *
906
-     * @param                 $value
907
-     * @param WP_REST_Request $request
908
-     * @param                 $param
909
-     * @return bool|true|WP_Error
910
-     * @throws InvalidArgumentException
911
-     * @throws InvalidInterfaceException
912
-     * @throws InvalidDataTypeException
913
-     */
914
-    public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
915
-    {
916
-        $attributes = $request->get_attributes();
917
-        if (! isset($attributes['args'][ $param ])
918
-            || ! is_array($attributes['args'][ $param ])) {
919
-            $validation_result = true;
920
-        } else {
921
-            $args = $attributes['args'][ $param ];
922
-            if ((
923
-                    $value === ''
924
-                    || $value === null
925
-                )
926
-                && (! isset($args['required'])
927
-                    || $args['required'] === false
928
-                )
929
-            ) {
930
-                // not required and not provided? that's cool
931
-                $validation_result = true;
932
-            } elseif (isset($args['format'])
933
-                      && $args['format'] === 'email'
934
-            ) {
935
-                $validation_result = true;
936
-                if (! self::_validate_email($value)) {
937
-                    $validation_result = new WP_Error(
938
-                        'rest_invalid_param',
939
-                        esc_html__(
940
-                            'The email address is not valid or does not exist.',
941
-                            'event_espresso'
942
-                        )
943
-                    );
944
-                }
945
-            } else {
946
-                $validation_result = rest_validate_value_from_schema($value, $args, $param);
947
-            }
948
-        }
949
-        if (is_wp_error($validation_result)) {
950
-            return $validation_result;
951
-        }
952
-        return rest_sanitize_request_arg($value, $request, $param);
953
-    }
954
-
955
-
956
-    /**
957
-     * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
958
-     *
959
-     * @param $email
960
-     * @return bool
961
-     * @throws InvalidArgumentException
962
-     * @throws InvalidInterfaceException
963
-     * @throws InvalidDataTypeException
964
-     */
965
-    protected static function _validate_email($email)
966
-    {
967
-        try {
968
-            EmailAddressFactory::create($email);
969
-            return true;
970
-        } catch (EmailValidationException $e) {
971
-            return false;
972
-        }
973
-    }
974
-
975
-
976
-    /**
977
-     * Gets routes for the config
978
-     *
979
-     * @return array @see _register_model_routes
980
-     * @deprecated since version 4.9.1
981
-     */
982
-    protected function _register_config_routes()
983
-    {
984
-        $config_routes = array();
985
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
986
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
987
-                $version,
988
-                $hidden_endpoint
989
-            );
990
-        }
991
-        return $config_routes;
992
-    }
993
-
994
-
995
-    /**
996
-     * Gets routes for the config for the specified version
997
-     *
998
-     * @param string  $version
999
-     * @param boolean $hidden_endpoint
1000
-     * @return array
1001
-     */
1002
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1003
-    {
1004
-        return array(
1005
-            'config'    => array(
1006
-                array(
1007
-                    'callback'        => array(
1008
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1009
-                        'handleRequest',
1010
-                    ),
1011
-                    'methods'         => WP_REST_Server::READABLE,
1012
-                    'hidden_endpoint' => $hidden_endpoint,
1013
-                    'callback_args'   => array($version),
1014
-                ),
1015
-            ),
1016
-            'site_info' => array(
1017
-                array(
1018
-                    'callback'        => array(
1019
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1020
-                        'handleRequestSiteInfo',
1021
-                    ),
1022
-                    'methods'         => WP_REST_Server::READABLE,
1023
-                    'hidden_endpoint' => $hidden_endpoint,
1024
-                    'callback_args'   => array($version),
1025
-                ),
1026
-            ),
1027
-        );
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * Gets the meta info routes
1033
-     *
1034
-     * @return array @see _register_model_routes
1035
-     * @deprecated since version 4.9.1
1036
-     */
1037
-    protected function _register_meta_routes()
1038
-    {
1039
-        $meta_routes = array();
1040
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1041
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1042
-                $version,
1043
-                $hidden_endpoint
1044
-            );
1045
-        }
1046
-        return $meta_routes;
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * @param string  $version
1052
-     * @param boolean $hidden_endpoint
1053
-     * @return array
1054
-     */
1055
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1056
-    {
1057
-        return array(
1058
-            'resources' => array(
1059
-                array(
1060
-                    'callback'        => array(
1061
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1062
-                        'handleRequestModelsMeta',
1063
-                    ),
1064
-                    'methods'         => WP_REST_Server::READABLE,
1065
-                    'hidden_endpoint' => $hidden_endpoint,
1066
-                    'callback_args'   => array($version),
1067
-                ),
1068
-            ),
1069
-        );
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * Tries to hide old 4.6 endpoints from the
1075
-     *
1076
-     * @param array $route_data
1077
-     * @return array
1078
-     * @throws \EE_Error
1079
-     */
1080
-    public static function hide_old_endpoints($route_data)
1081
-    {
1082
-        // allow API clients to override which endpoints get hidden, in case
1083
-        // they want to discover particular endpoints
1084
-        // also, we don't have access to the request so we have to just grab it from the superglobal
1085
-        $force_show_ee_namespace = ltrim(
1086
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1087
-            '/'
1088
-        );
1089
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1090
-            foreach ($relative_urls as $resource_name => $endpoints) {
1091
-                foreach ($endpoints as $key => $endpoint) {
1092
-                    // skip schema and other route options
1093
-                    if (! is_numeric($key)) {
1094
-                        continue;
1095
-                    }
1096
-                    // by default, hide "hidden_endpoint"s, unless the request indicates
1097
-                    // to $force_show_ee_namespace, in which case only show that one
1098
-                    // namespace's endpoints (and hide all others)
1099
-                    if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1100
-                        || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1101
-                    ) {
1102
-                        $full_route = '/' . ltrim($namespace, '/');
1103
-                        $full_route .= '/' . ltrim($resource_name, '/');
1104
-                        unset($route_data[ $full_route ]);
1105
-                    }
1106
-                }
1107
-            }
1108
-        }
1109
-        return $route_data;
1110
-    }
1111
-
1112
-
1113
-    /**
1114
-     * Returns an array describing which versions of core support serving requests for.
1115
-     * Keys are core versions' major and minor version, and values are the
1116
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1117
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
1118
-     * the answers table entirely, in which case it would be very difficult for
1119
-     * it to serve 4.6-style responses.
1120
-     * Versions of core that are missing from this array are unknowns.
1121
-     * previous ver
1122
-     *
1123
-     * @return array
1124
-     */
1125
-    public static function version_compatibilities()
1126
-    {
1127
-        return apply_filters(
1128
-            'FHEE__EED_Core_REST_API__version_compatibilities',
1129
-            array(
1130
-                '4.8.29' => '4.8.29',
1131
-                '4.8.33' => '4.8.29',
1132
-                '4.8.34' => '4.8.29',
1133
-                '4.8.36' => '4.8.29',
1134
-            )
1135
-        );
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * Gets the latest API version served. Eg if there
1141
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
1142
-     * we are on core version 4.8.34, it will return the string "4.8.32"
1143
-     *
1144
-     * @return string
1145
-     */
1146
-    public static function latest_rest_api_version()
1147
-    {
1148
-        $versions_served = \EED_Core_Rest_Api::versions_served();
1149
-        $versions_served_keys = array_keys($versions_served);
1150
-        return end($versions_served_keys);
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1156
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1157
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1158
-     * We also indicate whether or not this version should be put in the index or not
1159
-     *
1160
-     * @return array keys are API version numbers (just major and minor numbers), and values
1161
-     * are whether or not they should be hidden
1162
-     */
1163
-    public static function versions_served()
1164
-    {
1165
-        $versions_served = array();
1166
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1167
-        $lowest_compatible_version = end($possibly_served_versions);
1168
-        reset($possibly_served_versions);
1169
-        $versions_served_historically = array_keys($possibly_served_versions);
1170
-        $latest_version = end($versions_served_historically);
1171
-        reset($versions_served_historically);
1172
-        // for each version of core we have ever served:
1173
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
1174
-            // if it's not above the current core version, and it's compatible with the current version of core
1175
-            if ($key_versioned_endpoint === $latest_version) {
1176
-                // don't hide the latest version in the index
1177
-                $versions_served[ $key_versioned_endpoint ] = false;
1178
-            } elseif ($key_versioned_endpoint >= $lowest_compatible_version
1179
-                && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1180
-            ) {
1181
-                // include, but hide, previous versions which are still supported
1182
-                $versions_served[ $key_versioned_endpoint ] = true;
1183
-            } elseif (apply_filters(
1184
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1185
-                false,
1186
-                $possibly_served_versions
1187
-            )) {
1188
-                // if a version is no longer supported, don't include it in index or list of versions served
1189
-                $versions_served[ $key_versioned_endpoint ] = true;
1190
-            }
1191
-        }
1192
-        return $versions_served;
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * Gets the major and minor version of EE core's version string
1198
-     *
1199
-     * @return string
1200
-     */
1201
-    public static function core_version()
1202
-    {
1203
-        return apply_filters(
1204
-            'FHEE__EED_Core_REST_API__core_version',
1205
-            implode(
1206
-                '.',
1207
-                array_slice(
1208
-                    explode(
1209
-                        '.',
1210
-                        espresso_version()
1211
-                    ),
1212
-                    0,
1213
-                    3
1214
-                )
1215
-            )
1216
-        );
1217
-    }
1218
-
1219
-
1220
-    /**
1221
-     * Gets the default limit that should be used when querying for resources
1222
-     *
1223
-     * @return int
1224
-     */
1225
-    public static function get_default_query_limit()
1226
-    {
1227
-        // we actually don't use a const because we want folks to always use
1228
-        // this method, not the const directly
1229
-        return apply_filters(
1230
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1231
-            50
1232
-        );
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     *
1238
-     * @param string $version api version string (i.e. '4.8.36')
1239
-     * @return array
1240
-     */
1241
-    public static function getCollectionRoutesIndexedByModelName($version = '')
1242
-    {
1243
-        $version = empty($version) ? self::latest_rest_api_version() : $version;
1244
-        $model_names = self::model_names_with_plural_routes($version);
1245
-        $collection_routes = array();
1246
-        foreach ($model_names as $model_name => $model_class_name) {
1247
-            $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1248
-                                                            . EEH_Inflector::pluralize_and_lower($model_name);
1249
-        }
1250
-        return $collection_routes;
1251
-    }
1252
-
1253
-
1254
-
1255
-    /**
1256
-     *    run - initial module setup
1257
-     *
1258
-     * @access    public
1259
-     * @param  WP $WP
1260
-     * @return    void
1261
-     */
1262
-    public function run($WP)
1263
-    {
1264
-    }
25
+	const ee_api_namespace = Domain::API_NAMESPACE;
26
+
27
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
28
+
29
+	const saved_routes_option_names = 'ee_core_routes';
30
+
31
+	/**
32
+	 * string used in _links response bodies to make them globally unique.
33
+	 *
34
+	 * @see http://v2.wp-api.org/extending/linking/
35
+	 */
36
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
37
+
38
+	/**
39
+	 * @var CalculatedModelFields
40
+	 */
41
+	protected static $_field_calculator;
42
+
43
+
44
+	/**
45
+	 * @return EED_Core_Rest_Api|EED_Module
46
+	 */
47
+	public static function instance()
48
+	{
49
+		self::$_field_calculator = new CalculatedModelFields();
50
+		return parent::get_instance(__CLASS__);
51
+	}
52
+
53
+
54
+	/**
55
+	 *    set_hooks - for hooking into EE Core, other modules, etc
56
+	 *
57
+	 * @access    public
58
+	 * @return    void
59
+	 */
60
+	public static function set_hooks()
61
+	{
62
+		self::set_hooks_both();
63
+	}
64
+
65
+
66
+	/**
67
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
68
+	 *
69
+	 * @access    public
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks_admin()
73
+	{
74
+		self::set_hooks_both();
75
+	}
76
+
77
+
78
+	public static function set_hooks_both()
79
+	{
80
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
+		add_filter(
84
+			'rest_index',
85
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
86
+		);
87
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
+	}
89
+
90
+
91
+	/**
92
+	 * sets up hooks which only need to be included as part of REST API requests;
93
+	 * other requests like to the frontend or admin etc don't need them
94
+	 *
95
+	 * @throws \EE_Error
96
+	 */
97
+	public static function set_hooks_rest_api()
98
+	{
99
+		// set hooks which account for changes made to the API
100
+		EED_Core_Rest_Api::_set_hooks_for_changes();
101
+	}
102
+
103
+
104
+	/**
105
+	 * public wrapper of _set_hooks_for_changes.
106
+	 * Loads all the hooks which make requests to old versions of the API
107
+	 * appear the same as they always did
108
+	 *
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function set_hooks_for_changes()
112
+	{
113
+		self::_set_hooks_for_changes();
114
+	}
115
+
116
+
117
+	/**
118
+	 * Loads all the hooks which make requests to old versions of the API
119
+	 * appear the same as they always did
120
+	 *
121
+	 * @throws EE_Error
122
+	 */
123
+	protected static function _set_hooks_for_changes()
124
+	{
125
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
126
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
127
+			// ignore the base parent class
128
+			// and legacy named classes
129
+			if ($classname_in_namespace === 'ChangesInBase'
130
+				|| strpos($classname_in_namespace, 'Changes_In_') === 0
131
+			) {
132
+				continue;
133
+			}
134
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
135
+			if (class_exists($full_classname)) {
136
+				$instance_of_class = new $full_classname;
137
+				if ($instance_of_class instanceof ChangesInBase) {
138
+					$instance_of_class->setHooks();
139
+				}
140
+			}
141
+		}
142
+	}
143
+
144
+
145
+	/**
146
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
147
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
148
+	 *
149
+	 * @throws \EE_Error
150
+	 */
151
+	public static function register_routes()
152
+	{
153
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
154
+			foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
155
+				/**
156
+				 * @var array     $data_for_multiple_endpoints numerically indexed array
157
+				 *                                         but can also contain route options like {
158
+				 * @type array    $schema                      {
159
+				 * @type callable $schema_callback
160
+				 * @type array    $callback_args               arguments that will be passed to the callback, after the
161
+				 * WP_REST_Request of course
162
+				 * }
163
+				 * }
164
+				 */
165
+				// when registering routes, register all the endpoints' data at the same time
166
+				$multiple_endpoint_args = array();
167
+				foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
168
+					/**
169
+					 * @var array     $data_for_single_endpoint {
170
+					 * @type callable $callback
171
+					 * @type string methods
172
+					 * @type array args
173
+					 * @type array _links
174
+					 * @type array    $callback_args            arguments that will be passed to the callback, after the
175
+					 * WP_REST_Request of course
176
+					 * }
177
+					 */
178
+					// skip route options
179
+					if (! is_numeric($endpoint_key)) {
180
+						continue;
181
+					}
182
+					if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
183
+						throw new EE_Error(
184
+							esc_html__(
185
+							// @codingStandardsIgnoreStart
186
+								'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
187
+								// @codingStandardsIgnoreEnd
188
+								'event_espresso'
189
+							)
190
+						);
191
+					}
192
+					$callback = $data_for_single_endpoint['callback'];
193
+					$single_endpoint_args = array(
194
+						'methods' => $data_for_single_endpoint['methods'],
195
+						'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
196
+							: array(),
197
+					);
198
+					if (isset($data_for_single_endpoint['_links'])) {
199
+						$single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
200
+					}
201
+					if (isset($data_for_single_endpoint['callback_args'])) {
202
+						$callback_args = $data_for_single_endpoint['callback_args'];
203
+						$single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
204
+							$callback,
205
+							$callback_args
206
+						) {
207
+							array_unshift($callback_args, $request);
208
+							return call_user_func_array(
209
+								$callback,
210
+								$callback_args
211
+							);
212
+						};
213
+					} else {
214
+						$single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
215
+					}
216
+					$multiple_endpoint_args[] = $single_endpoint_args;
217
+				}
218
+				if (isset($data_for_multiple_endpoints['schema'])) {
219
+					$schema_route_data = $data_for_multiple_endpoints['schema'];
220
+					$schema_callback = $schema_route_data['schema_callback'];
221
+					$callback_args = $schema_route_data['callback_args'];
222
+					$multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
223
+						return call_user_func_array(
224
+							$schema_callback,
225
+							$callback_args
226
+						);
227
+					};
228
+				}
229
+				register_rest_route(
230
+					$namespace,
231
+					$relative_route,
232
+					$multiple_endpoint_args
233
+				);
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * Checks if there was a version change or something that merits invalidating the cached
241
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
242
+	 * next time the WP API is used
243
+	 */
244
+	public static function invalidate_cached_route_data_on_version_change()
245
+	{
246
+		if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
247
+			EED_Core_Rest_Api::invalidate_cached_route_data();
248
+		}
249
+		foreach (EE_Registry::instance()->addons as $addon) {
250
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
251
+				EED_Core_Rest_Api::invalidate_cached_route_data();
252
+			}
253
+		}
254
+	}
255
+
256
+
257
+	/**
258
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
259
+	 */
260
+	public static function invalidate_cached_route_data()
261
+	{
262
+		// delete the saved EE REST API routes
263
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
264
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
265
+		}
266
+	}
267
+
268
+
269
+	/**
270
+	 * Gets the EE route data
271
+	 *
272
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
273
+	 * @throws \EE_Error
274
+	 * @type string|array $callback
275
+	 * @type string       $methods
276
+	 * @type boolean      $hidden_endpoint
277
+	 * }
278
+	 */
279
+	public static function get_ee_route_data()
280
+	{
281
+		$ee_routes = array();
282
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
283
+			$ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
284
+				$version,
285
+				$hidden_endpoints
286
+			);
287
+		}
288
+		return $ee_routes;
289
+	}
290
+
291
+
292
+	/**
293
+	 * Gets the EE route data from the wp options if it exists already,
294
+	 * otherwise re-generates it and saves it to the option
295
+	 *
296
+	 * @param string  $version
297
+	 * @param boolean $hidden_endpoints
298
+	 * @return array
299
+	 * @throws \EE_Error
300
+	 */
301
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
302
+	{
303
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
304
+		if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
305
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
306
+		}
307
+		return $ee_routes;
308
+	}
309
+
310
+
311
+	/**
312
+	 * Saves the EE REST API route data to a wp option and returns it
313
+	 *
314
+	 * @param string  $version
315
+	 * @param boolean $hidden_endpoints
316
+	 * @return mixed|null
317
+	 * @throws \EE_Error
318
+	 */
319
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
320
+	{
321
+		$instance = self::instance();
322
+		$routes = apply_filters(
323
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
324
+			array_replace_recursive(
325
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
326
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
327
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
328
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
329
+			)
330
+		);
331
+		$option_name = self::saved_routes_option_names . $version;
332
+		if (get_option($option_name)) {
333
+			update_option($option_name, $routes, true);
334
+		} else {
335
+			add_option($option_name, $routes, null, 'no');
336
+		}
337
+		return $routes;
338
+	}
339
+
340
+
341
+	/**
342
+	 * Calculates all the EE routes and saves it to a WordPress option so we don't
343
+	 * need to calculate it on every request
344
+	 *
345
+	 * @deprecated since version 4.9.1
346
+	 * @return void
347
+	 */
348
+	public static function save_ee_routes()
349
+	{
350
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
351
+			$instance = self::instance();
352
+			$routes = apply_filters(
353
+				'EED_Core_Rest_Api__save_ee_routes__routes',
354
+				array_replace_recursive(
355
+					$instance->_register_config_routes(),
356
+					$instance->_register_meta_routes(),
357
+					$instance->_register_model_routes(),
358
+					$instance->_register_rpc_routes()
359
+				)
360
+			);
361
+			update_option(self::saved_routes_option_names, $routes, true);
362
+		}
363
+	}
364
+
365
+
366
+	/**
367
+	 * Gets all the route information relating to EE models
368
+	 *
369
+	 * @return array @see get_ee_route_data
370
+	 * @deprecated since version 4.9.1
371
+	 */
372
+	protected function _register_model_routes()
373
+	{
374
+		$model_routes = array();
375
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
376
+			$model_routes[ EED_Core_Rest_Api::ee_api_namespace
377
+						   . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
378
+		}
379
+		return $model_routes;
380
+	}
381
+
382
+
383
+	/**
384
+	 * Decides whether or not to add write endpoints for this model.
385
+	 *
386
+	 * Currently, this defaults to exclude all global tables and models
387
+	 * which would allow inserting WP core data (we don't want to duplicate
388
+	 * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
389
+	 *
390
+	 * @param EEM_Base $model
391
+	 * @return bool
392
+	 */
393
+	public static function should_have_write_endpoints(EEM_Base $model)
394
+	{
395
+		if ($model->is_wp_core_model()) {
396
+			return false;
397
+		}
398
+		foreach ($model->get_tables() as $table) {
399
+			if ($table->is_global()) {
400
+				return false;
401
+			}
402
+		}
403
+		return true;
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
409
+	 * in this versioned namespace of EE4
410
+	 *
411
+	 * @param $version
412
+	 * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
413
+	 */
414
+	public static function model_names_with_plural_routes($version)
415
+	{
416
+		$model_version_info = new ModelVersionInfo($version);
417
+		$models_to_register = $model_version_info->modelsForRequestedVersion();
418
+		// let's not bother having endpoints for extra metas
419
+		unset(
420
+			$models_to_register['Extra_Meta'],
421
+			$models_to_register['Extra_Join'],
422
+			$models_to_register['Post_Meta']
423
+		);
424
+		return apply_filters(
425
+			'FHEE__EED_Core_REST_API___register_model_routes',
426
+			$models_to_register
427
+		);
428
+	}
429
+
430
+
431
+	/**
432
+	 * Gets the route data for EE models in the specified version
433
+	 *
434
+	 * @param string  $version
435
+	 * @param boolean $hidden_endpoint
436
+	 * @return array
437
+	 * @throws EE_Error
438
+	 */
439
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
440
+	{
441
+		$model_routes = array();
442
+		$model_version_info = new ModelVersionInfo($version);
443
+		foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
444
+			$model = \EE_Registry::instance()->load_model($model_name);
445
+			// if this isn't a valid model then let's skip iterate to the next item in the loop.
446
+			if (! $model instanceof EEM_Base) {
447
+				continue;
448
+			}
449
+			// yes we could just register one route for ALL models, but then they wouldn't show up in the index
450
+			$plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
451
+			$singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
452
+			$model_routes[ $plural_model_route ] = array(
453
+				array(
454
+					'callback'        => array(
455
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
456
+						'handleRequestGetAll',
457
+					),
458
+					'callback_args'   => array($version, $model_name),
459
+					'methods'         => WP_REST_Server::READABLE,
460
+					'hidden_endpoint' => $hidden_endpoint,
461
+					'args'            => $this->_get_read_query_params($model, $version),
462
+					'_links'          => array(
463
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
464
+					),
465
+				),
466
+				'schema' => array(
467
+					'schema_callback' => array(
468
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
469
+						'handleSchemaRequest',
470
+					),
471
+					'callback_args'   => array($version, $model_name),
472
+				),
473
+			);
474
+			$model_routes[ $singular_model_route ] = array(
475
+				array(
476
+					'callback'        => array(
477
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
478
+						'handleRequestGetOne',
479
+					),
480
+					'callback_args'   => array($version, $model_name),
481
+					'methods'         => WP_REST_Server::READABLE,
482
+					'hidden_endpoint' => $hidden_endpoint,
483
+					'args'            => $this->_get_response_selection_query_params($model, $version),
484
+				),
485
+			);
486
+			if (apply_filters(
487
+				'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
488
+				EED_Core_Rest_Api::should_have_write_endpoints($model),
489
+				$model
490
+			)) {
491
+				$model_routes[ $plural_model_route ][] = array(
492
+					'callback'        => array(
493
+						'EventEspresso\core\libraries\rest_api\controllers\model\Write',
494
+						'handleRequestInsert',
495
+					),
496
+					'callback_args'   => array($version, $model_name),
497
+					'methods'         => WP_REST_Server::CREATABLE,
498
+					'hidden_endpoint' => $hidden_endpoint,
499
+					'args'            => $this->_get_write_params($model_name, $model_version_info, true),
500
+				);
501
+				$model_routes[ $singular_model_route ] = array_merge(
502
+					$model_routes[ $singular_model_route ],
503
+					array(
504
+						array(
505
+							'callback'        => array(
506
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
507
+								'handleRequestUpdate',
508
+							),
509
+							'callback_args'   => array($version, $model_name),
510
+							'methods'         => WP_REST_Server::EDITABLE,
511
+							'hidden_endpoint' => $hidden_endpoint,
512
+							'args'            => $this->_get_write_params($model_name, $model_version_info),
513
+						),
514
+						array(
515
+							'callback'        => array(
516
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
517
+								'handleRequestDelete',
518
+							),
519
+							'callback_args'   => array($version, $model_name),
520
+							'methods'         => WP_REST_Server::DELETABLE,
521
+							'hidden_endpoint' => $hidden_endpoint,
522
+							'args'            => $this->_get_delete_query_params($model, $version),
523
+						),
524
+					)
525
+				);
526
+			}
527
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
528
+				$related_route = EED_Core_Rest_Api::get_relation_route_via(
529
+					$model,
530
+					'(?P<id>[^\/]+)',
531
+					$relation_obj
532
+				);
533
+				$endpoints = array(
534
+					array(
535
+						'callback'        => array(
536
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
537
+							'handleRequestGetRelated',
538
+						),
539
+						'callback_args'   => array($version, $model_name, $relation_name),
540
+						'methods'         => WP_REST_Server::READABLE,
541
+						'hidden_endpoint' => $hidden_endpoint,
542
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
543
+					),
544
+				);
545
+				$model_routes[ $related_route ] = $endpoints;
546
+			}
547
+		}
548
+		return $model_routes;
549
+	}
550
+
551
+
552
+	/**
553
+	 * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
554
+	 * excluding the preceding slash.
555
+	 * Eg you pass get_plural_route_to('Event') = 'events'
556
+	 *
557
+	 * @param EEM_Base $model
558
+	 * @return string
559
+	 */
560
+	public static function get_collection_route(EEM_Base $model)
561
+	{
562
+		return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
563
+	}
564
+
565
+
566
+	/**
567
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
568
+	 * excluding the preceding slash.
569
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
570
+	 *
571
+	 * @param EEM_Base $model eg Event or Venue
572
+	 * @param string   $id
573
+	 * @return string
574
+	 */
575
+	public static function get_entity_route($model, $id)
576
+	{
577
+		return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
578
+	}
579
+
580
+
581
+	/**
582
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
583
+	 * excluding the preceding slash.
584
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
585
+	 *
586
+	 * @param EEM_Base               $model eg Event or Venue
587
+	 * @param string                 $id
588
+	 * @param EE_Model_Relation_Base $relation_obj
589
+	 * @return string
590
+	 */
591
+	public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
592
+	{
593
+		$related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
594
+			$relation_obj->get_other_model()->get_this_model_name(),
595
+			$relation_obj
596
+		);
597
+		return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
598
+	}
599
+
600
+
601
+	/**
602
+	 * Adds onto the $relative_route the EE4 REST API versioned namespace.
603
+	 * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
604
+	 *
605
+	 * @param string $relative_route
606
+	 * @param string $version
607
+	 * @return string
608
+	 */
609
+	public static function get_versioned_route_to($relative_route, $version = '4.8.36')
610
+	{
611
+		return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
612
+	}
613
+
614
+
615
+	/**
616
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
617
+	 * routes that don't conform to the traditional REST CRUD-style).
618
+	 *
619
+	 * @deprecated since 4.9.1
620
+	 */
621
+	protected function _register_rpc_routes()
622
+	{
623
+		$routes = array();
624
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
625
+			$routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
626
+				$version,
627
+				$hidden_endpoint
628
+			);
629
+		}
630
+		return $routes;
631
+	}
632
+
633
+
634
+	/**
635
+	 * @param string  $version
636
+	 * @param boolean $hidden_endpoint
637
+	 * @return array
638
+	 */
639
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
640
+	{
641
+		$this_versions_routes = array();
642
+		// checkin endpoint
643
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
644
+			array(
645
+				'callback'        => array(
646
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
647
+					'handleRequestToggleCheckin',
648
+				),
649
+				'methods'         => WP_REST_Server::CREATABLE,
650
+				'hidden_endpoint' => $hidden_endpoint,
651
+				'args'            => array(
652
+					'force' => array(
653
+						'required'    => false,
654
+						'default'     => false,
655
+						'description' => __(
656
+						// @codingStandardsIgnoreStart
657
+							'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
658
+							// @codingStandardsIgnoreEnd
659
+							'event_espresso'
660
+						),
661
+					),
662
+				),
663
+				'callback_args'   => array($version),
664
+			),
665
+		);
666
+		return apply_filters(
667
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
668
+			$this_versions_routes,
669
+			$version,
670
+			$hidden_endpoint
671
+		);
672
+	}
673
+
674
+
675
+	/**
676
+	 * Gets the query params that can be used when request one or many
677
+	 *
678
+	 * @param EEM_Base $model
679
+	 * @param string   $version
680
+	 * @return array
681
+	 */
682
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
683
+	{
684
+		return apply_filters(
685
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
686
+			array(
687
+				'include'   => array(
688
+					'required' => false,
689
+					'default'  => '*',
690
+					'type'     => 'string',
691
+				),
692
+				'calculate' => array(
693
+					'required'          => false,
694
+					'default'           => '',
695
+					'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
696
+					'type'              => 'string',
697
+					// because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
698
+					// freaks out. We'll just validate this argument while handling the request
699
+					'validate_callback' => null,
700
+					'sanitize_callback' => null,
701
+				),
702
+			),
703
+			$model,
704
+			$version
705
+		);
706
+	}
707
+
708
+
709
+	/**
710
+	 * Gets the parameters acceptable for delete requests
711
+	 *
712
+	 * @param \EEM_Base $model
713
+	 * @param string    $version
714
+	 * @return array
715
+	 */
716
+	protected function _get_delete_query_params(\EEM_Base $model, $version)
717
+	{
718
+		$params_for_delete = array(
719
+			'allow_blocking' => array(
720
+				'required' => false,
721
+				'default'  => true,
722
+				'type'     => 'boolean',
723
+			),
724
+		);
725
+		$params_for_delete['force'] = array(
726
+			'required' => false,
727
+			'default'  => false,
728
+			'type'     => 'boolean',
729
+		);
730
+		return apply_filters(
731
+			'FHEE__EED_Core_Rest_Api___get_delete_query_params',
732
+			$params_for_delete,
733
+			$model,
734
+			$version
735
+		);
736
+	}
737
+
738
+
739
+	/**
740
+	 * Gets info about reading query params that are acceptable
741
+	 *
742
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
743
+	 * @param  string   $version
744
+	 * @return array    describing the args acceptable when querying this model
745
+	 * @throws EE_Error
746
+	 */
747
+	protected function _get_read_query_params(\EEM_Base $model, $version)
748
+	{
749
+		$default_orderby = array();
750
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
751
+			$default_orderby[ $key_field->get_name() ] = 'ASC';
752
+		}
753
+		return array_merge(
754
+			$this->_get_response_selection_query_params($model, $version),
755
+			array(
756
+				'where'    => array(
757
+					'required'          => false,
758
+					'default'           => array(),
759
+					'type'              => 'object',
760
+					// because we accept an almost infinite list of possible where conditions, WP
761
+					// core validation and sanitization freaks out. We'll just validate this argument
762
+					// while handling the request
763
+					'validate_callback' => null,
764
+					'sanitize_callback' => null,
765
+				),
766
+				'limit'    => array(
767
+					'required'          => false,
768
+					'default'           => EED_Core_Rest_Api::get_default_query_limit(),
769
+					'type'              => array(
770
+						'array',
771
+						'string',
772
+						'integer',
773
+					),
774
+					// because we accept a variety of types, WP core validation and sanitization
775
+					// freaks out. We'll just validate this argument while handling the request
776
+					'validate_callback' => null,
777
+					'sanitize_callback' => null,
778
+				),
779
+				'order_by' => array(
780
+					'required'          => false,
781
+					'default'           => $default_orderby,
782
+					'type'              => array(
783
+						'object',
784
+						'string',
785
+					),// because we accept a variety of types, WP core validation and sanitization
786
+					// freaks out. We'll just validate this argument while handling the request
787
+					'validate_callback' => null,
788
+					'sanitize_callback' => null,
789
+				),
790
+				'group_by' => array(
791
+					'required'          => false,
792
+					'default'           => null,
793
+					'type'              => array(
794
+						'object',
795
+						'string',
796
+					),
797
+					// because we accept  an almost infinite list of possible groupings,
798
+					// WP core validation and sanitization
799
+					// freaks out. We'll just validate this argument while handling the request
800
+					'validate_callback' => null,
801
+					'sanitize_callback' => null,
802
+				),
803
+				'having'   => array(
804
+					'required'          => false,
805
+					'default'           => null,
806
+					'type'              => 'object',
807
+					// because we accept an almost infinite list of possible where conditions, WP
808
+					// core validation and sanitization freaks out. We'll just validate this argument
809
+					// while handling the request
810
+					'validate_callback' => null,
811
+					'sanitize_callback' => null,
812
+				),
813
+				'caps'     => array(
814
+					'required' => false,
815
+					'default'  => EEM_Base::caps_read,
816
+					'type'     => 'string',
817
+					'enum'     => array(
818
+						EEM_Base::caps_read,
819
+						EEM_Base::caps_read_admin,
820
+						EEM_Base::caps_edit,
821
+						EEM_Base::caps_delete,
822
+					),
823
+				),
824
+			)
825
+		);
826
+	}
827
+
828
+
829
+	/**
830
+	 * Gets parameter information for a model regarding writing data
831
+	 *
832
+	 * @param string           $model_name
833
+	 * @param ModelVersionInfo $model_version_info
834
+	 * @param boolean          $create                                       whether this is for request to create (in
835
+	 *                                                                       which case we need all required params) or
836
+	 *                                                                       just to update (in which case we don't
837
+	 *                                                                       need those on every request)
838
+	 * @return array
839
+	 */
840
+	protected function _get_write_params(
841
+		$model_name,
842
+		ModelVersionInfo $model_version_info,
843
+		$create = false
844
+	) {
845
+		$model = EE_Registry::instance()->load_model($model_name);
846
+		$fields = $model_version_info->fieldsOnModelInThisVersion($model);
847
+		$args_info = array();
848
+		foreach ($fields as $field_name => $field_obj) {
849
+			if ($field_obj->is_auto_increment()) {
850
+				// totally ignore auto increment IDs
851
+				continue;
852
+			}
853
+			$arg_info = $field_obj->getSchema();
854
+			$required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
855
+			$arg_info['required'] = $required;
856
+			// remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
857
+			unset($arg_info['readonly']);
858
+			$schema_properties = $field_obj->getSchemaProperties();
859
+			if (isset($schema_properties['raw'])
860
+				&& $field_obj->getSchemaType() === 'object'
861
+			) {
862
+				// if there's a "raw" form of this argument, use those properties instead
863
+				$arg_info = array_replace(
864
+					$arg_info,
865
+					$schema_properties['raw']
866
+				);
867
+			}
868
+			$arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
869
+				$field_obj,
870
+				$field_obj->get_default_value(),
871
+				$model_version_info->requestedVersion()
872
+			);
873
+			// we do our own validation and sanitization within the controller
874
+			if (function_exists('rest_validate_value_from_schema')) {
875
+				$sanitize_callback = array(
876
+					'EED_Core_Rest_Api',
877
+					'default_sanitize_callback',
878
+				);
879
+			} else {
880
+				$sanitize_callback = null;
881
+			}
882
+			$arg_info['sanitize_callback'] = $sanitize_callback;
883
+			$args_info[ $field_name ] = $arg_info;
884
+			if ($field_obj instanceof EE_Datetime_Field) {
885
+				$gmt_arg_info = $arg_info;
886
+				$gmt_arg_info['description'] = sprintf(
887
+					esc_html__(
888
+						'%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
889
+						'event_espresso'
890
+					),
891
+					$field_obj->get_nicename(),
892
+					$field_name
893
+				);
894
+				$args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
895
+			}
896
+		}
897
+		return $args_info;
898
+	}
899
+
900
+
901
+	/**
902
+	 * Replacement for WP API's 'rest_parse_request_arg'.
903
+	 * If the value is blank but not required, don't bother validating it.
904
+	 * Also, it uses our email validation instead of WP API's default.
905
+	 *
906
+	 * @param                 $value
907
+	 * @param WP_REST_Request $request
908
+	 * @param                 $param
909
+	 * @return bool|true|WP_Error
910
+	 * @throws InvalidArgumentException
911
+	 * @throws InvalidInterfaceException
912
+	 * @throws InvalidDataTypeException
913
+	 */
914
+	public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
915
+	{
916
+		$attributes = $request->get_attributes();
917
+		if (! isset($attributes['args'][ $param ])
918
+			|| ! is_array($attributes['args'][ $param ])) {
919
+			$validation_result = true;
920
+		} else {
921
+			$args = $attributes['args'][ $param ];
922
+			if ((
923
+					$value === ''
924
+					|| $value === null
925
+				)
926
+				&& (! isset($args['required'])
927
+					|| $args['required'] === false
928
+				)
929
+			) {
930
+				// not required and not provided? that's cool
931
+				$validation_result = true;
932
+			} elseif (isset($args['format'])
933
+					  && $args['format'] === 'email'
934
+			) {
935
+				$validation_result = true;
936
+				if (! self::_validate_email($value)) {
937
+					$validation_result = new WP_Error(
938
+						'rest_invalid_param',
939
+						esc_html__(
940
+							'The email address is not valid or does not exist.',
941
+							'event_espresso'
942
+						)
943
+					);
944
+				}
945
+			} else {
946
+				$validation_result = rest_validate_value_from_schema($value, $args, $param);
947
+			}
948
+		}
949
+		if (is_wp_error($validation_result)) {
950
+			return $validation_result;
951
+		}
952
+		return rest_sanitize_request_arg($value, $request, $param);
953
+	}
954
+
955
+
956
+	/**
957
+	 * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
958
+	 *
959
+	 * @param $email
960
+	 * @return bool
961
+	 * @throws InvalidArgumentException
962
+	 * @throws InvalidInterfaceException
963
+	 * @throws InvalidDataTypeException
964
+	 */
965
+	protected static function _validate_email($email)
966
+	{
967
+		try {
968
+			EmailAddressFactory::create($email);
969
+			return true;
970
+		} catch (EmailValidationException $e) {
971
+			return false;
972
+		}
973
+	}
974
+
975
+
976
+	/**
977
+	 * Gets routes for the config
978
+	 *
979
+	 * @return array @see _register_model_routes
980
+	 * @deprecated since version 4.9.1
981
+	 */
982
+	protected function _register_config_routes()
983
+	{
984
+		$config_routes = array();
985
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
986
+			$config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
987
+				$version,
988
+				$hidden_endpoint
989
+			);
990
+		}
991
+		return $config_routes;
992
+	}
993
+
994
+
995
+	/**
996
+	 * Gets routes for the config for the specified version
997
+	 *
998
+	 * @param string  $version
999
+	 * @param boolean $hidden_endpoint
1000
+	 * @return array
1001
+	 */
1002
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1003
+	{
1004
+		return array(
1005
+			'config'    => array(
1006
+				array(
1007
+					'callback'        => array(
1008
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1009
+						'handleRequest',
1010
+					),
1011
+					'methods'         => WP_REST_Server::READABLE,
1012
+					'hidden_endpoint' => $hidden_endpoint,
1013
+					'callback_args'   => array($version),
1014
+				),
1015
+			),
1016
+			'site_info' => array(
1017
+				array(
1018
+					'callback'        => array(
1019
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1020
+						'handleRequestSiteInfo',
1021
+					),
1022
+					'methods'         => WP_REST_Server::READABLE,
1023
+					'hidden_endpoint' => $hidden_endpoint,
1024
+					'callback_args'   => array($version),
1025
+				),
1026
+			),
1027
+		);
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * Gets the meta info routes
1033
+	 *
1034
+	 * @return array @see _register_model_routes
1035
+	 * @deprecated since version 4.9.1
1036
+	 */
1037
+	protected function _register_meta_routes()
1038
+	{
1039
+		$meta_routes = array();
1040
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1041
+			$meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1042
+				$version,
1043
+				$hidden_endpoint
1044
+			);
1045
+		}
1046
+		return $meta_routes;
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * @param string  $version
1052
+	 * @param boolean $hidden_endpoint
1053
+	 * @return array
1054
+	 */
1055
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1056
+	{
1057
+		return array(
1058
+			'resources' => array(
1059
+				array(
1060
+					'callback'        => array(
1061
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1062
+						'handleRequestModelsMeta',
1063
+					),
1064
+					'methods'         => WP_REST_Server::READABLE,
1065
+					'hidden_endpoint' => $hidden_endpoint,
1066
+					'callback_args'   => array($version),
1067
+				),
1068
+			),
1069
+		);
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * Tries to hide old 4.6 endpoints from the
1075
+	 *
1076
+	 * @param array $route_data
1077
+	 * @return array
1078
+	 * @throws \EE_Error
1079
+	 */
1080
+	public static function hide_old_endpoints($route_data)
1081
+	{
1082
+		// allow API clients to override which endpoints get hidden, in case
1083
+		// they want to discover particular endpoints
1084
+		// also, we don't have access to the request so we have to just grab it from the superglobal
1085
+		$force_show_ee_namespace = ltrim(
1086
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1087
+			'/'
1088
+		);
1089
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1090
+			foreach ($relative_urls as $resource_name => $endpoints) {
1091
+				foreach ($endpoints as $key => $endpoint) {
1092
+					// skip schema and other route options
1093
+					if (! is_numeric($key)) {
1094
+						continue;
1095
+					}
1096
+					// by default, hide "hidden_endpoint"s, unless the request indicates
1097
+					// to $force_show_ee_namespace, in which case only show that one
1098
+					// namespace's endpoints (and hide all others)
1099
+					if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1100
+						|| ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1101
+					) {
1102
+						$full_route = '/' . ltrim($namespace, '/');
1103
+						$full_route .= '/' . ltrim($resource_name, '/');
1104
+						unset($route_data[ $full_route ]);
1105
+					}
1106
+				}
1107
+			}
1108
+		}
1109
+		return $route_data;
1110
+	}
1111
+
1112
+
1113
+	/**
1114
+	 * Returns an array describing which versions of core support serving requests for.
1115
+	 * Keys are core versions' major and minor version, and values are the
1116
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1117
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
1118
+	 * the answers table entirely, in which case it would be very difficult for
1119
+	 * it to serve 4.6-style responses.
1120
+	 * Versions of core that are missing from this array are unknowns.
1121
+	 * previous ver
1122
+	 *
1123
+	 * @return array
1124
+	 */
1125
+	public static function version_compatibilities()
1126
+	{
1127
+		return apply_filters(
1128
+			'FHEE__EED_Core_REST_API__version_compatibilities',
1129
+			array(
1130
+				'4.8.29' => '4.8.29',
1131
+				'4.8.33' => '4.8.29',
1132
+				'4.8.34' => '4.8.29',
1133
+				'4.8.36' => '4.8.29',
1134
+			)
1135
+		);
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * Gets the latest API version served. Eg if there
1141
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
1142
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
1143
+	 *
1144
+	 * @return string
1145
+	 */
1146
+	public static function latest_rest_api_version()
1147
+	{
1148
+		$versions_served = \EED_Core_Rest_Api::versions_served();
1149
+		$versions_served_keys = array_keys($versions_served);
1150
+		return end($versions_served_keys);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1156
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1157
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1158
+	 * We also indicate whether or not this version should be put in the index or not
1159
+	 *
1160
+	 * @return array keys are API version numbers (just major and minor numbers), and values
1161
+	 * are whether or not they should be hidden
1162
+	 */
1163
+	public static function versions_served()
1164
+	{
1165
+		$versions_served = array();
1166
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1167
+		$lowest_compatible_version = end($possibly_served_versions);
1168
+		reset($possibly_served_versions);
1169
+		$versions_served_historically = array_keys($possibly_served_versions);
1170
+		$latest_version = end($versions_served_historically);
1171
+		reset($versions_served_historically);
1172
+		// for each version of core we have ever served:
1173
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
1174
+			// if it's not above the current core version, and it's compatible with the current version of core
1175
+			if ($key_versioned_endpoint === $latest_version) {
1176
+				// don't hide the latest version in the index
1177
+				$versions_served[ $key_versioned_endpoint ] = false;
1178
+			} elseif ($key_versioned_endpoint >= $lowest_compatible_version
1179
+				&& $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1180
+			) {
1181
+				// include, but hide, previous versions which are still supported
1182
+				$versions_served[ $key_versioned_endpoint ] = true;
1183
+			} elseif (apply_filters(
1184
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1185
+				false,
1186
+				$possibly_served_versions
1187
+			)) {
1188
+				// if a version is no longer supported, don't include it in index or list of versions served
1189
+				$versions_served[ $key_versioned_endpoint ] = true;
1190
+			}
1191
+		}
1192
+		return $versions_served;
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * Gets the major and minor version of EE core's version string
1198
+	 *
1199
+	 * @return string
1200
+	 */
1201
+	public static function core_version()
1202
+	{
1203
+		return apply_filters(
1204
+			'FHEE__EED_Core_REST_API__core_version',
1205
+			implode(
1206
+				'.',
1207
+				array_slice(
1208
+					explode(
1209
+						'.',
1210
+						espresso_version()
1211
+					),
1212
+					0,
1213
+					3
1214
+				)
1215
+			)
1216
+		);
1217
+	}
1218
+
1219
+
1220
+	/**
1221
+	 * Gets the default limit that should be used when querying for resources
1222
+	 *
1223
+	 * @return int
1224
+	 */
1225
+	public static function get_default_query_limit()
1226
+	{
1227
+		// we actually don't use a const because we want folks to always use
1228
+		// this method, not the const directly
1229
+		return apply_filters(
1230
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1231
+			50
1232
+		);
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 *
1238
+	 * @param string $version api version string (i.e. '4.8.36')
1239
+	 * @return array
1240
+	 */
1241
+	public static function getCollectionRoutesIndexedByModelName($version = '')
1242
+	{
1243
+		$version = empty($version) ? self::latest_rest_api_version() : $version;
1244
+		$model_names = self::model_names_with_plural_routes($version);
1245
+		$collection_routes = array();
1246
+		foreach ($model_names as $model_name => $model_class_name) {
1247
+			$collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1248
+															. EEH_Inflector::pluralize_and_lower($model_name);
1249
+		}
1250
+		return $collection_routes;
1251
+	}
1252
+
1253
+
1254
+
1255
+	/**
1256
+	 *    run - initial module setup
1257
+	 *
1258
+	 * @access    public
1259
+	 * @param  WP $WP
1260
+	 * @return    void
1261
+	 */
1262
+	public function run($WP)
1263
+	{
1264
+	}
1265 1265
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     protected static function _set_hooks_for_changes()
124 124
     {
125
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
125
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false);
126 126
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
127 127
             // ignore the base parent class
128 128
             // and legacy named classes
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             ) {
132 132
                 continue;
133 133
             }
134
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
134
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
135 135
             if (class_exists($full_classname)) {
136 136
                 $instance_of_class = new $full_classname;
137 137
                 if ($instance_of_class instanceof ChangesInBase) {
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
                      * }
177 177
                      */
178 178
                     // skip route options
179
-                    if (! is_numeric($endpoint_key)) {
179
+                    if ( ! is_numeric($endpoint_key)) {
180 180
                         continue;
181 181
                     }
182
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
182
+                    if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
183 183
                         throw new EE_Error(
184 184
                             esc_html__(
185 185
                             // @codingStandardsIgnoreStart
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                     }
201 201
                     if (isset($data_for_single_endpoint['callback_args'])) {
202 202
                         $callback_args = $data_for_single_endpoint['callback_args'];
203
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
203
+                        $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use (
204 204
                             $callback,
205 205
                             $callback_args
206 206
                         ) {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     $schema_route_data = $data_for_multiple_endpoints['schema'];
220 220
                     $schema_callback = $schema_route_data['schema_callback'];
221 221
                     $callback_args = $schema_route_data['callback_args'];
222
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
222
+                    $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) {
223 223
                         return call_user_func_array(
224 224
                             $schema_callback,
225 225
                             $callback_args
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     {
262 262
         // delete the saved EE REST API routes
263 263
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
264
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
264
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
265 265
         }
266 266
     }
267 267
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     {
281 281
         $ee_routes = array();
282 282
         foreach (self::versions_served() as $version => $hidden_endpoints) {
283
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
283
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version(
284 284
                 $version,
285 285
                 $hidden_endpoints
286 286
             );
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
      */
301 301
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
302 302
     {
303
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
304
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
303
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
304
+        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
305 305
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
306 306
         }
307 307
         return $ee_routes;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
329 329
             )
330 330
         );
331
-        $option_name = self::saved_routes_option_names . $version;
331
+        $option_name = self::saved_routes_option_names.$version;
332 332
         if (get_option($option_name)) {
333 333
             update_option($option_name, $routes, true);
334 334
         } else {
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
     {
374 374
         $model_routes = array();
375 375
         foreach (self::versions_served() as $version => $hidden_endpoint) {
376
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
377
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
376
+            $model_routes[EED_Core_Rest_Api::ee_api_namespace
377
+                           . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
378 378
         }
379 379
         return $model_routes;
380 380
     }
@@ -443,13 +443,13 @@  discard block
 block discarded – undo
443 443
         foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
444 444
             $model = \EE_Registry::instance()->load_model($model_name);
445 445
             // if this isn't a valid model then let's skip iterate to the next item in the loop.
446
-            if (! $model instanceof EEM_Base) {
446
+            if ( ! $model instanceof EEM_Base) {
447 447
                 continue;
448 448
             }
449 449
             // yes we could just register one route for ALL models, but then they wouldn't show up in the index
450 450
             $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
451 451
             $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
452
-            $model_routes[ $plural_model_route ] = array(
452
+            $model_routes[$plural_model_route] = array(
453 453
                 array(
454 454
                     'callback'        => array(
455 455
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
                     'hidden_endpoint' => $hidden_endpoint,
461 461
                     'args'            => $this->_get_read_query_params($model, $version),
462 462
                     '_links'          => array(
463
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
463
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
464 464
                     ),
465 465
                 ),
466 466
                 'schema' => array(
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
                     'callback_args'   => array($version, $model_name),
472 472
                 ),
473 473
             );
474
-            $model_routes[ $singular_model_route ] = array(
474
+            $model_routes[$singular_model_route] = array(
475 475
                 array(
476 476
                     'callback'        => array(
477 477
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
                 EED_Core_Rest_Api::should_have_write_endpoints($model),
489 489
                 $model
490 490
             )) {
491
-                $model_routes[ $plural_model_route ][] = array(
491
+                $model_routes[$plural_model_route][] = array(
492 492
                     'callback'        => array(
493 493
                         'EventEspresso\core\libraries\rest_api\controllers\model\Write',
494 494
                         'handleRequestInsert',
@@ -498,8 +498,8 @@  discard block
 block discarded – undo
498 498
                     'hidden_endpoint' => $hidden_endpoint,
499 499
                     'args'            => $this->_get_write_params($model_name, $model_version_info, true),
500 500
                 );
501
-                $model_routes[ $singular_model_route ] = array_merge(
502
-                    $model_routes[ $singular_model_route ],
501
+                $model_routes[$singular_model_route] = array_merge(
502
+                    $model_routes[$singular_model_route],
503 503
                     array(
504 504
                         array(
505 505
                             'callback'        => array(
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
                         'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
543 543
                     ),
544 544
                 );
545
-                $model_routes[ $related_route ] = $endpoints;
545
+                $model_routes[$related_route] = $endpoints;
546 546
             }
547 547
         }
548 548
         return $model_routes;
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      */
575 575
     public static function get_entity_route($model, $id)
576 576
     {
577
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
577
+        return EED_Core_Rest_Api::get_collection_route($model).'/'.$id;
578 578
     }
579 579
 
580 580
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
             $relation_obj->get_other_model()->get_this_model_name(),
595 595
             $relation_obj
596 596
         );
597
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
597
+        return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part;
598 598
     }
599 599
 
600 600
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
      */
609 609
     public static function get_versioned_route_to($relative_route, $version = '4.8.36')
610 610
     {
611
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
611
+        return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route;
612 612
     }
613 613
 
614 614
 
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
     {
623 623
         $routes = array();
624 624
         foreach (self::versions_served() as $version => $hidden_endpoint) {
625
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
625
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version(
626 626
                 $version,
627 627
                 $hidden_endpoint
628 628
             );
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
     {
749 749
         $default_orderby = array();
750 750
         foreach ($model->get_combined_primary_key_fields() as $key_field) {
751
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
751
+            $default_orderby[$key_field->get_name()] = 'ASC';
752 752
         }
753 753
         return array_merge(
754 754
             $this->_get_response_selection_query_params($model, $version),
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
                     'type'              => array(
783 783
                         'object',
784 784
                         'string',
785
-                    ),// because we accept a variety of types, WP core validation and sanitization
785
+                    ), // because we accept a variety of types, WP core validation and sanitization
786 786
                     // freaks out. We'll just validate this argument while handling the request
787 787
                     'validate_callback' => null,
788 788
                     'sanitize_callback' => null,
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
                 $sanitize_callback = null;
881 881
             }
882 882
             $arg_info['sanitize_callback'] = $sanitize_callback;
883
-            $args_info[ $field_name ] = $arg_info;
883
+            $args_info[$field_name] = $arg_info;
884 884
             if ($field_obj instanceof EE_Datetime_Field) {
885 885
                 $gmt_arg_info = $arg_info;
886 886
                 $gmt_arg_info['description'] = sprintf(
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
                     $field_obj->get_nicename(),
892 892
                     $field_name
893 893
                 );
894
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
894
+                $args_info[$field_name.'_gmt'] = $gmt_arg_info;
895 895
             }
896 896
         }
897 897
         return $args_info;
@@ -914,16 +914,16 @@  discard block
 block discarded – undo
914 914
     public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
915 915
     {
916 916
         $attributes = $request->get_attributes();
917
-        if (! isset($attributes['args'][ $param ])
918
-            || ! is_array($attributes['args'][ $param ])) {
917
+        if ( ! isset($attributes['args'][$param])
918
+            || ! is_array($attributes['args'][$param])) {
919 919
             $validation_result = true;
920 920
         } else {
921
-            $args = $attributes['args'][ $param ];
921
+            $args = $attributes['args'][$param];
922 922
             if ((
923 923
                     $value === ''
924 924
                     || $value === null
925 925
                 )
926
-                && (! isset($args['required'])
926
+                && ( ! isset($args['required'])
927 927
                     || $args['required'] === false
928 928
                 )
929 929
             ) {
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
                       && $args['format'] === 'email'
934 934
             ) {
935 935
                 $validation_result = true;
936
-                if (! self::_validate_email($value)) {
936
+                if ( ! self::_validate_email($value)) {
937 937
                     $validation_result = new WP_Error(
938 938
                         'rest_invalid_param',
939 939
                         esc_html__(
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
     {
984 984
         $config_routes = array();
985 985
         foreach (self::versions_served() as $version => $hidden_endpoint) {
986
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
986
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version(
987 987
                 $version,
988 988
                 $hidden_endpoint
989 989
             );
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
     {
1039 1039
         $meta_routes = array();
1040 1040
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1041
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1041
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version(
1042 1042
                 $version,
1043 1043
                 $hidden_endpoint
1044 1044
             );
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
             foreach ($relative_urls as $resource_name => $endpoints) {
1091 1091
                 foreach ($endpoints as $key => $endpoint) {
1092 1092
                     // skip schema and other route options
1093
-                    if (! is_numeric($key)) {
1093
+                    if ( ! is_numeric($key)) {
1094 1094
                         continue;
1095 1095
                     }
1096 1096
                     // by default, hide "hidden_endpoint"s, unless the request indicates
@@ -1099,9 +1099,9 @@  discard block
 block discarded – undo
1099 1099
                     if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1100 1100
                         || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1101 1101
                     ) {
1102
-                        $full_route = '/' . ltrim($namespace, '/');
1103
-                        $full_route .= '/' . ltrim($resource_name, '/');
1104
-                        unset($route_data[ $full_route ]);
1102
+                        $full_route = '/'.ltrim($namespace, '/');
1103
+                        $full_route .= '/'.ltrim($resource_name, '/');
1104
+                        unset($route_data[$full_route]);
1105 1105
                     }
1106 1106
                 }
1107 1107
             }
@@ -1174,19 +1174,19 @@  discard block
 block discarded – undo
1174 1174
             // if it's not above the current core version, and it's compatible with the current version of core
1175 1175
             if ($key_versioned_endpoint === $latest_version) {
1176 1176
                 // don't hide the latest version in the index
1177
-                $versions_served[ $key_versioned_endpoint ] = false;
1177
+                $versions_served[$key_versioned_endpoint] = false;
1178 1178
             } elseif ($key_versioned_endpoint >= $lowest_compatible_version
1179 1179
                 && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1180 1180
             ) {
1181 1181
                 // include, but hide, previous versions which are still supported
1182
-                $versions_served[ $key_versioned_endpoint ] = true;
1182
+                $versions_served[$key_versioned_endpoint] = true;
1183 1183
             } elseif (apply_filters(
1184 1184
                 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1185 1185
                 false,
1186 1186
                 $possibly_served_versions
1187 1187
             )) {
1188 1188
                 // if a version is no longer supported, don't include it in index or list of versions served
1189
-                $versions_served[ $key_versioned_endpoint ] = true;
1189
+                $versions_served[$key_versioned_endpoint] = true;
1190 1190
             }
1191 1191
         }
1192 1192
         return $versions_served;
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
         $model_names = self::model_names_with_plural_routes($version);
1245 1245
         $collection_routes = array();
1246 1246
         foreach ($model_names as $model_name => $model_class_name) {
1247
-            $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1247
+            $collection_routes[strtolower($model_name)] = '/'.self::ee_api_namespace.$version.'/'
1248 1248
                                                             . EEH_Inflector::pluralize_and_lower($model_name);
1249 1249
         }
1250 1250
         return $collection_routes;
Please login to merge, or discard this patch.
core/domain/DomainBase.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use EventEspresso\core\domain\values\FilePath;
6 6
 use EventEspresso\core\domain\values\Version;
7
-use EventEspresso\core\services\assets\Registry;
8 7
 
9 8
 /**
10 9
  * DomainBase Class
Please login to merge, or discard this patch.
core/services/assets/BlockAssetManager.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 
115 115
     /**
116
-     * @param       $handle
116
+     * @param       string $handle
117 117
      * @param array $dependencies
118 118
      * @since $VID:$
119 119
      * @return JavascriptAsset
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
 
138 138
     /**
139
-     * @param        $handle
139
+     * @param        string $handle
140 140
      * @param array  $dependencies
141 141
      * @since $VID:$
142 142
      * @return StylesheetAsset
Please login to merge, or discard this patch.
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -21,296 +21,296 @@
 block discarded – undo
21 21
 abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface
22 22
 {
23 23
 
24
-    /**
25
-     * @var string $editor_script_handle
26
-     */
27
-    private $editor_script_handle;
28
-
29
-    /**
30
-     * @var string $editor_style_handle
31
-     */
32
-    private $editor_style_handle;
33
-
34
-    /**
35
-     * @var string $script_handle
36
-     */
37
-    private $script_handle;
38
-
39
-    /**
40
-     * @var string $style_handle
41
-     */
42
-    private $style_handle;
43
-
44
-
45
-    /**
46
-     * @return string
47
-     */
48
-    public function getEditorScriptHandle()
49
-    {
50
-        return $this->editor_script_handle;
51
-    }
52
-
53
-
54
-    /**
55
-     * @param string $editor_script_handle
56
-     */
57
-    public function setEditorScriptHandle($editor_script_handle)
58
-    {
59
-        $this->editor_script_handle = $editor_script_handle;
60
-    }
61
-
62
-
63
-    /**
64
-     * @return string
65
-     */
66
-    public function getEditorStyleHandle()
67
-    {
68
-        return $this->editor_style_handle;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param string $editor_style_handle
74
-     */
75
-    public function setEditorStyleHandle($editor_style_handle)
76
-    {
77
-        $this->editor_style_handle = $editor_style_handle;
78
-    }
79
-
80
-
81
-    /**
82
-     * @return string
83
-     */
84
-    public function getScriptHandle()
85
-    {
86
-        return $this->script_handle;
87
-    }
88
-
89
-
90
-    /**
91
-     * @param string $script_handle
92
-     */
93
-    public function setScriptHandle($script_handle)
94
-    {
95
-        $this->script_handle = $script_handle;
96
-    }
97
-
98
-
99
-    /**
100
-     * @return string
101
-     */
102
-    public function getStyleHandle()
103
-    {
104
-        return $this->style_handle;
105
-    }
106
-
107
-
108
-    /**
109
-     * @param string $style_handle
110
-     */
111
-    public function setStyleHandle($style_handle)
112
-    {
113
-        $this->style_handle = $style_handle;
114
-    }
115
-
116
-    /**
117
-     * @since $VID:$
118
-     * @throws InvalidDataTypeException
119
-     * @throws InvalidEntityException
120
-     * @throws DuplicateCollectionIdentifierException
121
-     */
122
-    public function addAssets()
123
-    {
124
-        $this->addEditorScript($this->getEditorScriptHandle());
125
-        $this->addEditorStyle($this->getEditorStyleHandle());
126
-        $this->setScriptHandle($this->getScriptHandle());
127
-        $this->setStyleHandle($this->getStyleHandle());
128
-    }
129
-
130
-
131
-    /**
132
-     * @param       $handle
133
-     * @param array $dependencies
134
-     * @since $VID:$
135
-     * @return JavascriptAsset
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidEntityException
138
-     * @throws DuplicateCollectionIdentifierException
139
-     */
140
-    public function addEditorScript($handle, array $dependencies = array())
141
-    {
142
-        if($this->assets->has($handle)){
143
-            return $this->assets->get($handle);
144
-        }
145
-        return parent::addJavascript(
146
-            $handle,
147
-            $this->registry->getJsUrl(
148
-                $this->domain->assetNamespace(),
149
-                $handle
150
-            ),
151
-            $this->addDefaultBlockScriptDependencies($dependencies)
152
-        );
153
-    }
154
-
155
-
156
-    /**
157
-     * @param        $handle
158
-     * @param array  $dependencies
159
-     * @since $VID:$
160
-     * @return StylesheetAsset
161
-     * @throws InvalidDataTypeException
162
-     * @throws InvalidEntityException
163
-     * @throws DuplicateCollectionIdentifierException
164
-     */
165
-    public function addEditorStyle($handle, array $dependencies = array())
166
-    {
167
-        if ($this->assets->has($handle)) {
168
-            return $this->assets->get($handle);
169
-        }
170
-        return parent::addStylesheet(
171
-            $handle,
172
-            $this->registry->getCssUrl(
173
-                $this->domain->assetNamespace(),
174
-                $handle
175
-            ),
176
-            $dependencies
177
-        );
178
-    }
179
-
180
-
181
-    /**
182
-     * @param       $handle
183
-     * @param array $dependencies
184
-     * @since $VID:$
185
-     * @return JavascriptAsset
186
-     * @throws InvalidDataTypeException
187
-     * @throws InvalidEntityException
188
-     * @throws DuplicateCollectionIdentifierException
189
-     */
190
-    public function addScript($handle, array $dependencies = array())
191
-    {
192
-        if ($this->assets->has($handle)) {
193
-            return $this->assets->get($handle);
194
-        }
195
-        return parent::addJavascript(
196
-            $handle,
197
-            $this->registry->getJsUrl(
198
-                $this->domain->assetNamespace(),
199
-                $handle
200
-            ),
201
-            $this->addDefaultBlockScriptDependencies($dependencies)
202
-        );
203
-    }
204
-
205
-
206
-    /**
207
-     * @param        $handle
208
-     * @param array  $dependencies
209
-     * @since $VID:$
210
-     * @return StylesheetAsset
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidEntityException
213
-     * @throws DuplicateCollectionIdentifierException
214
-     */
215
-    public function addStyle($handle, array $dependencies = array())
216
-    {
217
-        if ($this->assets->has($handle)) {
218
-            return $this->assets->get($handle);
219
-        }
220
-        return parent::addStylesheet(
221
-            $handle,
222
-            $this->registry->getCssUrl(
223
-                $this->domain->assetNamespace(),
224
-                $handle
225
-            ),
226
-            $dependencies
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * @param array $dependencies
233
-     * @return array
234
-     */
235
-    protected function addDefaultBlockScriptDependencies(array $dependencies)
236
-    {
237
-        $dependencies += array(
238
-                CoreAssetManager::JS_HANDLE_EE_JS_CORE,
239
-                'wp-blocks',    // Provides useful functions and components for extending the editor
240
-                'wp-i18n',      // Provides localization functions
241
-                'wp-element',   // Provides React.Component
242
-                'wp-components' // Provides many prebuilt components and controls
243
-            );
244
-        return $dependencies;
245
-    }
246
-
247
-
248
-    /**
249
-     * @param string $handle
250
-     * @since $VID:$
251
-     * @return mixed|null
252
-     */
253
-    public function getAsset($handle)
254
-    {
255
-        if ($this->assets->has($handle)) {
256
-            return $this->assets->get($handle);
257
-        }
258
-        return null;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return JavascriptAsset|null
264
-     */
265
-    public function getEditorScript()
266
-    {
267
-        return $this->getAsset($this->editor_script_handle);
268
-    }
269
-
270
-
271
-    /**
272
-     * @return StylesheetAsset|null
273
-     */
274
-    public function getEditorStyle()
275
-    {
276
-        return $this->getAsset($this->editor_style_handle);
277
-    }
278
-
279
-
280
-    /**
281
-     * @return JavascriptAsset|null
282
-     */
283
-    public function getScript()
284
-    {
285
-        return $this->getAsset($this->script_handle);
286
-    }
287
-
288
-
289
-    /**
290
-     * @return StylesheetAsset|null
291
-     */
292
-    public function getStyle()
293
-    {
294
-        return $this->getAsset($this->style_handle);
295
-    }
296
-
297
-
298
-    /**
299
-     * @return  void
300
-     */
301
-    public function enqueueAssets()
302
-    {
303
-        $assets = array(
304
-            $this->getEditorScript(),
305
-            $this->getEditorStyle(),
306
-            $this->getScript(),
307
-            $this->getStyle(),
308
-        );
309
-        foreach ($assets as $asset) {
310
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
311
-                $asset->enqueueAsset();
312
-            }
313
-        }
314
-    }
24
+	/**
25
+	 * @var string $editor_script_handle
26
+	 */
27
+	private $editor_script_handle;
28
+
29
+	/**
30
+	 * @var string $editor_style_handle
31
+	 */
32
+	private $editor_style_handle;
33
+
34
+	/**
35
+	 * @var string $script_handle
36
+	 */
37
+	private $script_handle;
38
+
39
+	/**
40
+	 * @var string $style_handle
41
+	 */
42
+	private $style_handle;
43
+
44
+
45
+	/**
46
+	 * @return string
47
+	 */
48
+	public function getEditorScriptHandle()
49
+	{
50
+		return $this->editor_script_handle;
51
+	}
52
+
53
+
54
+	/**
55
+	 * @param string $editor_script_handle
56
+	 */
57
+	public function setEditorScriptHandle($editor_script_handle)
58
+	{
59
+		$this->editor_script_handle = $editor_script_handle;
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return string
65
+	 */
66
+	public function getEditorStyleHandle()
67
+	{
68
+		return $this->editor_style_handle;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param string $editor_style_handle
74
+	 */
75
+	public function setEditorStyleHandle($editor_style_handle)
76
+	{
77
+		$this->editor_style_handle = $editor_style_handle;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @return string
83
+	 */
84
+	public function getScriptHandle()
85
+	{
86
+		return $this->script_handle;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @param string $script_handle
92
+	 */
93
+	public function setScriptHandle($script_handle)
94
+	{
95
+		$this->script_handle = $script_handle;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return string
101
+	 */
102
+	public function getStyleHandle()
103
+	{
104
+		return $this->style_handle;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param string $style_handle
110
+	 */
111
+	public function setStyleHandle($style_handle)
112
+	{
113
+		$this->style_handle = $style_handle;
114
+	}
115
+
116
+	/**
117
+	 * @since $VID:$
118
+	 * @throws InvalidDataTypeException
119
+	 * @throws InvalidEntityException
120
+	 * @throws DuplicateCollectionIdentifierException
121
+	 */
122
+	public function addAssets()
123
+	{
124
+		$this->addEditorScript($this->getEditorScriptHandle());
125
+		$this->addEditorStyle($this->getEditorStyleHandle());
126
+		$this->setScriptHandle($this->getScriptHandle());
127
+		$this->setStyleHandle($this->getStyleHandle());
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param       $handle
133
+	 * @param array $dependencies
134
+	 * @since $VID:$
135
+	 * @return JavascriptAsset
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidEntityException
138
+	 * @throws DuplicateCollectionIdentifierException
139
+	 */
140
+	public function addEditorScript($handle, array $dependencies = array())
141
+	{
142
+		if($this->assets->has($handle)){
143
+			return $this->assets->get($handle);
144
+		}
145
+		return parent::addJavascript(
146
+			$handle,
147
+			$this->registry->getJsUrl(
148
+				$this->domain->assetNamespace(),
149
+				$handle
150
+			),
151
+			$this->addDefaultBlockScriptDependencies($dependencies)
152
+		);
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param        $handle
158
+	 * @param array  $dependencies
159
+	 * @since $VID:$
160
+	 * @return StylesheetAsset
161
+	 * @throws InvalidDataTypeException
162
+	 * @throws InvalidEntityException
163
+	 * @throws DuplicateCollectionIdentifierException
164
+	 */
165
+	public function addEditorStyle($handle, array $dependencies = array())
166
+	{
167
+		if ($this->assets->has($handle)) {
168
+			return $this->assets->get($handle);
169
+		}
170
+		return parent::addStylesheet(
171
+			$handle,
172
+			$this->registry->getCssUrl(
173
+				$this->domain->assetNamespace(),
174
+				$handle
175
+			),
176
+			$dependencies
177
+		);
178
+	}
179
+
180
+
181
+	/**
182
+	 * @param       $handle
183
+	 * @param array $dependencies
184
+	 * @since $VID:$
185
+	 * @return JavascriptAsset
186
+	 * @throws InvalidDataTypeException
187
+	 * @throws InvalidEntityException
188
+	 * @throws DuplicateCollectionIdentifierException
189
+	 */
190
+	public function addScript($handle, array $dependencies = array())
191
+	{
192
+		if ($this->assets->has($handle)) {
193
+			return $this->assets->get($handle);
194
+		}
195
+		return parent::addJavascript(
196
+			$handle,
197
+			$this->registry->getJsUrl(
198
+				$this->domain->assetNamespace(),
199
+				$handle
200
+			),
201
+			$this->addDefaultBlockScriptDependencies($dependencies)
202
+		);
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param        $handle
208
+	 * @param array  $dependencies
209
+	 * @since $VID:$
210
+	 * @return StylesheetAsset
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidEntityException
213
+	 * @throws DuplicateCollectionIdentifierException
214
+	 */
215
+	public function addStyle($handle, array $dependencies = array())
216
+	{
217
+		if ($this->assets->has($handle)) {
218
+			return $this->assets->get($handle);
219
+		}
220
+		return parent::addStylesheet(
221
+			$handle,
222
+			$this->registry->getCssUrl(
223
+				$this->domain->assetNamespace(),
224
+				$handle
225
+			),
226
+			$dependencies
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param array $dependencies
233
+	 * @return array
234
+	 */
235
+	protected function addDefaultBlockScriptDependencies(array $dependencies)
236
+	{
237
+		$dependencies += array(
238
+				CoreAssetManager::JS_HANDLE_EE_JS_CORE,
239
+				'wp-blocks',    // Provides useful functions and components for extending the editor
240
+				'wp-i18n',      // Provides localization functions
241
+				'wp-element',   // Provides React.Component
242
+				'wp-components' // Provides many prebuilt components and controls
243
+			);
244
+		return $dependencies;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param string $handle
250
+	 * @since $VID:$
251
+	 * @return mixed|null
252
+	 */
253
+	public function getAsset($handle)
254
+	{
255
+		if ($this->assets->has($handle)) {
256
+			return $this->assets->get($handle);
257
+		}
258
+		return null;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return JavascriptAsset|null
264
+	 */
265
+	public function getEditorScript()
266
+	{
267
+		return $this->getAsset($this->editor_script_handle);
268
+	}
269
+
270
+
271
+	/**
272
+	 * @return StylesheetAsset|null
273
+	 */
274
+	public function getEditorStyle()
275
+	{
276
+		return $this->getAsset($this->editor_style_handle);
277
+	}
278
+
279
+
280
+	/**
281
+	 * @return JavascriptAsset|null
282
+	 */
283
+	public function getScript()
284
+	{
285
+		return $this->getAsset($this->script_handle);
286
+	}
287
+
288
+
289
+	/**
290
+	 * @return StylesheetAsset|null
291
+	 */
292
+	public function getStyle()
293
+	{
294
+		return $this->getAsset($this->style_handle);
295
+	}
296
+
297
+
298
+	/**
299
+	 * @return  void
300
+	 */
301
+	public function enqueueAssets()
302
+	{
303
+		$assets = array(
304
+			$this->getEditorScript(),
305
+			$this->getEditorStyle(),
306
+			$this->getScript(),
307
+			$this->getStyle(),
308
+		);
309
+		foreach ($assets as $asset) {
310
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
311
+				$asset->enqueueAsset();
312
+			}
313
+		}
314
+	}
315 315
 
316 316
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function addEditorScript($handle, array $dependencies = array())
141 141
     {
142
-        if($this->assets->has($handle)){
142
+        if ($this->assets->has($handle)) {
143 143
             return $this->assets->get($handle);
144 144
         }
145 145
         return parent::addJavascript(
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
     {
237 237
         $dependencies += array(
238 238
                 CoreAssetManager::JS_HANDLE_EE_JS_CORE,
239
-                'wp-blocks',    // Provides useful functions and components for extending the editor
240
-                'wp-i18n',      // Provides localization functions
241
-                'wp-element',   // Provides React.Component
239
+                'wp-blocks', // Provides useful functions and components for extending the editor
240
+                'wp-i18n', // Provides localization functions
241
+                'wp-element', // Provides React.Component
242 242
                 'wp-components' // Provides many prebuilt components and controls
243 243
             );
244 244
         return $dependencies;
Please login to merge, or discard this patch.