Completed
Branch models-cleanup/model-relations (db5ca7)
by
unknown
13:03 queued 08:35
created
core/exceptions/InvalidAliasException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
 class InvalidAliasException extends DomainException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidClassException constructor.
21
-     *
22
-     * @param string    $fqcn
23
-     * @param string    $alias
24
-     * @param string    $message
25
-     * @param int       $code
26
-     * @param Exception $previous
27
-     */
28
-    public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null)
29
-    {
30
-        if (empty($message)) {
31
-            $message = sprintf(
32
-                __(
33
-                    '"%1$s" can not be used as an alias because the "%2$s"  class does not extend or implement it.',
34
-                    'event_espresso'
35
-                ),
36
-                $alias,
37
-                $fqcn
38
-            );
39
-        }
40
-        parent::__construct($message, $code, $previous);
41
-    }
19
+	/**
20
+	 * InvalidClassException constructor.
21
+	 *
22
+	 * @param string    $fqcn
23
+	 * @param string    $alias
24
+	 * @param string    $message
25
+	 * @param int       $code
26
+	 * @param Exception $previous
27
+	 */
28
+	public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null)
29
+	{
30
+		if (empty($message)) {
31
+			$message = sprintf(
32
+				__(
33
+					'"%1$s" can not be used as an alias because the "%2$s"  class does not extend or implement it.',
34
+					'event_espresso'
35
+				),
36
+				$alias,
37
+				$fqcn
38
+			);
39
+		}
40
+		parent::__construct($message, $code, $previous);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
core/services/dependencies/ClassAlias.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      */
35 35
     public function __construct($alias, $fqcn)
36 36
     {
37
-        if (! is_subclass_of($fqcn, $alias)) {
37
+        if ( ! is_subclass_of($fqcn, $alias)) {
38 38
             throw new InvalidAliasException($fqcn, $alias);
39 39
         }
40 40
         $this->alias = $alias;
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -17,46 +17,46 @@
 block discarded – undo
17 17
 class ClassAlias
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $alias   an interface or base class representing what object
22
-     *                      can be utilized by another object and/or function
23
-     */
24
-    private $alias;
25
-
26
-    /**
27
-     * @var string $fqcn the actual class that should be substituted for the alias above
28
-     */
29
-    private $fqcn;
30
-
31
-    /**
32
-     * ClassAlias constructor.
33
-     *
34
-     * @param string $alias Interface specified by implementing class
35
-     * @param string $fqcn  Concrete class that satisfies interface
36
-     * @throws InvalidAliasException
37
-     */
38
-    public function __construct($alias, $fqcn)
39
-    {
40
-        if (! is_subclass_of($fqcn, $alias)) {
41
-            throw new InvalidAliasException($fqcn, $alias);
42
-        }
43
-        $this->alias = $alias;
44
-        $this->fqcn = $fqcn;
45
-    }
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function alias()
51
-    {
52
-        return $this->alias;
53
-    }
54
-
55
-    /**
56
-     * @return string
57
-     */
58
-    public function fqcn()
59
-    {
60
-        return $this->fqcn;
61
-    }
20
+	/**
21
+	 * @var string $alias   an interface or base class representing what object
22
+	 *                      can be utilized by another object and/or function
23
+	 */
24
+	private $alias;
25
+
26
+	/**
27
+	 * @var string $fqcn the actual class that should be substituted for the alias above
28
+	 */
29
+	private $fqcn;
30
+
31
+	/**
32
+	 * ClassAlias constructor.
33
+	 *
34
+	 * @param string $alias Interface specified by implementing class
35
+	 * @param string $fqcn  Concrete class that satisfies interface
36
+	 * @throws InvalidAliasException
37
+	 */
38
+	public function __construct($alias, $fqcn)
39
+	{
40
+		if (! is_subclass_of($fqcn, $alias)) {
41
+			throw new InvalidAliasException($fqcn, $alias);
42
+		}
43
+		$this->alias = $alias;
44
+		$this->fqcn = $fqcn;
45
+	}
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function alias()
51
+	{
52
+		return $this->alias;
53
+	}
54
+
55
+	/**
56
+	 * @return string
57
+	 */
58
+	public function fqcn()
59
+	{
60
+		return $this->fqcn;
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/services/factory/FactoryWithDependencyResolver.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,41 +18,41 @@
 block discarded – undo
18 18
  */
19 19
 abstract class FactoryWithDependencyResolver implements FactoryInterface
20 20
 {
21
-    /**
22
-     * @var DependencyResolverInterface $dependency_resolver
23
-     */
24
-    private $dependency_resolver;
21
+	/**
22
+	 * @var DependencyResolverInterface $dependency_resolver
23
+	 */
24
+	private $dependency_resolver;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    private $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	private $loader;
30 30
 
31
-    /**
32
-     * FactoryWithDependencyResolver constructor.
33
-     *
34
-     * @param DependencyResolverInterface $dependency_resolver
35
-     * @param LoaderInterface             $loader
36
-     */
37
-    public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
-    {
39
-        $this->dependency_resolver = $dependency_resolver;
40
-        $this->loader = $loader;
41
-    }
31
+	/**
32
+	 * FactoryWithDependencyResolver constructor.
33
+	 *
34
+	 * @param DependencyResolverInterface $dependency_resolver
35
+	 * @param LoaderInterface             $loader
36
+	 */
37
+	public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader)
38
+	{
39
+		$this->dependency_resolver = $dependency_resolver;
40
+		$this->loader = $loader;
41
+	}
42 42
 
43
-    /**
44
-     * @return DependencyResolverInterface
45
-     */
46
-    public function dependencyResolver()
47
-    {
48
-        return $this->dependency_resolver;
49
-    }
43
+	/**
44
+	 * @return DependencyResolverInterface
45
+	 */
46
+	public function dependencyResolver()
47
+	{
48
+		return $this->dependency_resolver;
49
+	}
50 50
 
51
-    /**
52
-     * @return LoaderInterface
53
-     */
54
-    public function loader()
55
-    {
56
-        return $this->loader;
57
-    }
51
+	/**
52
+	 * @return LoaderInterface
53
+	 */
54
+	public function loader()
55
+	{
56
+		return $this->loader;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/domain/services/factories/FactoryInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@
 block discarded – undo
11 11
 interface FactoryInterface
12 12
 {
13 13
 
14
-    /**
15
-     * @param mixed $arguments Either a Fully Qualified Class Name
16
-     *                         or array of data required for construction
17
-     * @return mixed
18
-     */
19
-    public static function create($arguments);
14
+	/**
15
+	 * @param mixed $arguments Either a Fully Qualified Class Name
16
+	 *                         or array of data required for construction
17
+	 * @return mixed
18
+	 */
19
+	public static function create($arguments);
20 20
 }
Please login to merge, or discard this patch.
core/services/editor/BlockRegistrationManager.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
             foreach ($this->blocks as $block) {
146 146
                 $block->initialize();
147 147
                 $this->trackAssetManagersForBlocks($block);
148
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
148
+                if ( ! $this->block_asset_manager_collection->has($block->assetManager())) {
149 149
                     $this->block_asset_manager_collection->add($block->assetManager());
150 150
                     $block->assetManager()->setAssetHandles();
151 151
                 }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         $supported_routes = $block->supportedRoutes();
168 168
         foreach ($supported_routes as $supported_route) {
169 169
             if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
170
-                $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
170
+                $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace();
171 171
             }
172 172
         }
173 173
     }
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function matchesRoute(BlockInterface $block)
185 185
     {
186
-        if (isset($this->block_asset_managers[ $block->blockType() ])) {
186
+        if (isset($this->block_asset_managers[$block->blockType()])) {
187 187
             return true;
188 188
         }
189
-        unset($this->block_asset_managers[ $block->blockType() ]);
189
+        unset($this->block_asset_managers[$block->blockType()]);
190 190
         return false;
191 191
     }
192 192
 
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
         try {
203 203
             // cycle thru block loader folders
204 204
             foreach ($this->blocks as $block) {
205
-                if (! $this->matchesRoute($block)) {
205
+                if ( ! $this->matchesRoute($block)) {
206 206
                     continue;
207 207
                 }
208 208
                 // perform any setup required for the block
209 209
                 $block_type = $block->registerBlock();
210
-                if (! $block_type instanceof WP_Block_Type) {
210
+                if ( ! $block_type instanceof WP_Block_Type) {
211 211
                     throw new InvalidEntityException($block_type, 'WP_Block_Type');
212 212
                 }
213 213
                 do_action(
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         $assets = array_flip($this->block_asset_managers);
227 227
         foreach ($this->block_asset_manager_collection as $asset_manager) {
228 228
             // if there are no longer any blocks that require these assets,
229
-            if (! isset($assets[ $asset_manager->assetNamespace() ])) {
229
+            if ( ! isset($assets[$asset_manager->assetNamespace()])) {
230 230
                 // then unset asset enqueueing and bail
231 231
                 remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
232 232
                 remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -32,223 +32,223 @@
 block discarded – undo
32 32
 class BlockRegistrationManager extends BlockManager
33 33
 {
34 34
 
35
-    /**
36
-     * @var BlockAssetManagerCollection $block_asset_manager_collection
37
-     */
38
-    protected $block_asset_manager_collection;
39
-
40
-    /**
41
-     * @var RouteMatchSpecificationManager $route_manager
42
-     */
43
-    protected $route_manager;
44
-
45
-    /**
46
-     * array for tracking asset managers required by blocks for the current route
47
-     *
48
-     * @var array $block_asset_managers
49
-     */
50
-    protected $block_asset_managers = array();
51
-
52
-
53
-    /**
54
-     * BlockRegistrationManager constructor.
55
-     *
56
-     * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
-     * @param BlockCollection                $blocks
58
-     * @param RouteMatchSpecificationManager $route_manager
59
-     * @param RequestInterface               $request
60
-     */
61
-    public function __construct(
62
-        BlockAssetManagerCollection $block_asset_manager_collection,
63
-        BlockCollection $blocks,
64
-        RouteMatchSpecificationManager $route_manager,
65
-        RequestInterface $request
66
-    ) {
67
-        $this->block_asset_manager_collection = $block_asset_manager_collection;
68
-        $this->route_manager = $route_manager;
69
-        parent::__construct($blocks, $request);
70
-    }
71
-
72
-
73
-    /**
74
-     *  Returns the name of a hook point to be used to call initialize()
75
-     *
76
-     * @return string
77
-     */
78
-    public function initHook()
79
-    {
80
-        return 'AHEE__EE_System__initialize';
81
-    }
82
-
83
-
84
-    /**
85
-     * Perform any early setup required for block editors to functions
86
-     *
87
-     * @return void
88
-     * @throws Exception
89
-     */
90
-    public function initialize()
91
-    {
92
-        $this->initializeBlocks();
93
-        add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
-        add_action('wp_loaded', array($this, 'unloadAssets'));
95
-        add_filter('block_categories', array($this, 'addEspressoBlockCategories'));
96
-    }
97
-
98
-
99
-    /**
100
-     * @param array $categories
101
-     * @since 4.9.71.p
102
-     * @return array
103
-     */
104
-    public function addEspressoBlockCategories(array $categories)
105
-    {
106
-        return array_merge(
107
-            $categories,
108
-            array(
109
-                array(
110
-                    'slug' => 'event-espresso',
111
-                    'title' => esc_html__('Event Espresso', 'event_espresso'),
112
-                ),
113
-            )
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @return CollectionInterface|BlockInterface[]
120
-     * @throws CollectionLoaderException
121
-     * @throws CollectionDetailsException
122
-     */
123
-    protected function populateBlockCollection()
124
-    {
125
-        $loader = new CollectionLoader(
126
-            new CollectionDetails(
127
-                // collection name
128
-                'editor_blocks',
129
-                // collection interface
130
-                'EventEspresso\core\domain\entities\editor\BlockInterface',
131
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
132
-                apply_filters(
133
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
134
-                    array('EventEspresso\core\domain\entities\editor\blocks')
135
-                ),
136
-                // file paths to classes to add
137
-                array(),
138
-                // file mask to use if parsing folder for files to add
139
-                '',
140
-                // what to use as identifier for collection entities
141
-                // using CLASS NAME prevents duplicates (works like a singleton)
142
-                CollectionDetails::ID_CLASS_NAME
143
-            ),
144
-            $this->blocks
145
-        );
146
-        return $loader->getCollection();
147
-    }
148
-
149
-
150
-    /**
151
-     * populates the BlockCollection and calls initialize() on all installed blocks
152
-     *
153
-     * @return void
154
-     * @throws Exception
155
-     */
156
-    public function initializeBlocks()
157
-    {
158
-        try {
159
-            $this->populateBlockCollection();
160
-            // cycle thru block loaders and initialize each loader
161
-            foreach ($this->blocks as $block) {
162
-                $block->initialize();
163
-                $this->trackAssetManagersForBlocks($block);
164
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
165
-                    $this->block_asset_manager_collection->add($block->assetManager());
166
-                    $block->assetManager()->setAssetHandles();
167
-                }
168
-            }
169
-        } catch (Exception $exception) {
170
-            new ExceptionStackTraceDisplay($exception);
171
-        }
172
-    }
173
-
174
-
175
-    /**
176
-     * track blocks with routes that match the current request
177
-     *
178
-     * @param BlockInterface $block
179
-     * @throws InvalidClassException
180
-     */
181
-    private function trackAssetManagersForBlocks(BlockInterface $block)
182
-    {
183
-        $supported_routes = $block->supportedRoutes();
184
-        foreach ($supported_routes as $supported_route) {
185
-            if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
186
-                $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
187
-            }
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * returns true if the block should be registered for the current request
194
-     * else removes block from block_routes array and returns false
195
-     *
196
-     * @param BlockInterface $block
197
-     * @return boolean
198
-     * @throws InvalidClassException
199
-     */
200
-    public function matchesRoute(BlockInterface $block)
201
-    {
202
-        if (isset($this->block_asset_managers[ $block->blockType() ])) {
203
-            return true;
204
-        }
205
-        unset($this->block_asset_managers[ $block->blockType() ]);
206
-        return false;
207
-    }
208
-
209
-
210
-    /**
211
-     * calls registerBlock() and load assets for all installed blocks
212
-     *
213
-     * @return void
214
-     * @throws Exception
215
-     */
216
-    public function registerBlocks()
217
-    {
218
-        try {
219
-            // cycle thru block loader folders
220
-            foreach ($this->blocks as $block) {
221
-                if (! $this->matchesRoute($block)) {
222
-                    continue;
223
-                }
224
-                // perform any setup required for the block
225
-                $block_type = $block->registerBlock();
226
-                if (! $block_type instanceof WP_Block_Type) {
227
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
228
-                }
229
-                do_action(
230
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
231
-                    $block,
232
-                    $block_type
233
-                );
234
-            }
235
-        } catch (Exception $exception) {
236
-            new ExceptionStackTraceDisplay($exception);
237
-        }
238
-    }
239
-
240
-    public function unloadAssets()
241
-    {
242
-        $assets = array_flip($this->block_asset_managers);
243
-        foreach ($this->block_asset_manager_collection as $asset_manager) {
244
-            // if there are no longer any blocks that require these assets,
245
-            if (! isset($assets[ $asset_manager->assetNamespace() ])) {
246
-                // then unset asset enqueueing and bail
247
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
248
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
249
-                remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
250
-                remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
251
-            }
252
-        }
253
-    }
35
+	/**
36
+	 * @var BlockAssetManagerCollection $block_asset_manager_collection
37
+	 */
38
+	protected $block_asset_manager_collection;
39
+
40
+	/**
41
+	 * @var RouteMatchSpecificationManager $route_manager
42
+	 */
43
+	protected $route_manager;
44
+
45
+	/**
46
+	 * array for tracking asset managers required by blocks for the current route
47
+	 *
48
+	 * @var array $block_asset_managers
49
+	 */
50
+	protected $block_asset_managers = array();
51
+
52
+
53
+	/**
54
+	 * BlockRegistrationManager constructor.
55
+	 *
56
+	 * @param BlockAssetManagerCollection    $block_asset_manager_collection
57
+	 * @param BlockCollection                $blocks
58
+	 * @param RouteMatchSpecificationManager $route_manager
59
+	 * @param RequestInterface               $request
60
+	 */
61
+	public function __construct(
62
+		BlockAssetManagerCollection $block_asset_manager_collection,
63
+		BlockCollection $blocks,
64
+		RouteMatchSpecificationManager $route_manager,
65
+		RequestInterface $request
66
+	) {
67
+		$this->block_asset_manager_collection = $block_asset_manager_collection;
68
+		$this->route_manager = $route_manager;
69
+		parent::__construct($blocks, $request);
70
+	}
71
+
72
+
73
+	/**
74
+	 *  Returns the name of a hook point to be used to call initialize()
75
+	 *
76
+	 * @return string
77
+	 */
78
+	public function initHook()
79
+	{
80
+		return 'AHEE__EE_System__initialize';
81
+	}
82
+
83
+
84
+	/**
85
+	 * Perform any early setup required for block editors to functions
86
+	 *
87
+	 * @return void
88
+	 * @throws Exception
89
+	 */
90
+	public function initialize()
91
+	{
92
+		$this->initializeBlocks();
93
+		add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks'));
94
+		add_action('wp_loaded', array($this, 'unloadAssets'));
95
+		add_filter('block_categories', array($this, 'addEspressoBlockCategories'));
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param array $categories
101
+	 * @since 4.9.71.p
102
+	 * @return array
103
+	 */
104
+	public function addEspressoBlockCategories(array $categories)
105
+	{
106
+		return array_merge(
107
+			$categories,
108
+			array(
109
+				array(
110
+					'slug' => 'event-espresso',
111
+					'title' => esc_html__('Event Espresso', 'event_espresso'),
112
+				),
113
+			)
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return CollectionInterface|BlockInterface[]
120
+	 * @throws CollectionLoaderException
121
+	 * @throws CollectionDetailsException
122
+	 */
123
+	protected function populateBlockCollection()
124
+	{
125
+		$loader = new CollectionLoader(
126
+			new CollectionDetails(
127
+				// collection name
128
+				'editor_blocks',
129
+				// collection interface
130
+				'EventEspresso\core\domain\entities\editor\BlockInterface',
131
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
132
+				apply_filters(
133
+					'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
134
+					array('EventEspresso\core\domain\entities\editor\blocks')
135
+				),
136
+				// file paths to classes to add
137
+				array(),
138
+				// file mask to use if parsing folder for files to add
139
+				'',
140
+				// what to use as identifier for collection entities
141
+				// using CLASS NAME prevents duplicates (works like a singleton)
142
+				CollectionDetails::ID_CLASS_NAME
143
+			),
144
+			$this->blocks
145
+		);
146
+		return $loader->getCollection();
147
+	}
148
+
149
+
150
+	/**
151
+	 * populates the BlockCollection and calls initialize() on all installed blocks
152
+	 *
153
+	 * @return void
154
+	 * @throws Exception
155
+	 */
156
+	public function initializeBlocks()
157
+	{
158
+		try {
159
+			$this->populateBlockCollection();
160
+			// cycle thru block loaders and initialize each loader
161
+			foreach ($this->blocks as $block) {
162
+				$block->initialize();
163
+				$this->trackAssetManagersForBlocks($block);
164
+				if (! $this->block_asset_manager_collection->has($block->assetManager())) {
165
+					$this->block_asset_manager_collection->add($block->assetManager());
166
+					$block->assetManager()->setAssetHandles();
167
+				}
168
+			}
169
+		} catch (Exception $exception) {
170
+			new ExceptionStackTraceDisplay($exception);
171
+		}
172
+	}
173
+
174
+
175
+	/**
176
+	 * track blocks with routes that match the current request
177
+	 *
178
+	 * @param BlockInterface $block
179
+	 * @throws InvalidClassException
180
+	 */
181
+	private function trackAssetManagersForBlocks(BlockInterface $block)
182
+	{
183
+		$supported_routes = $block->supportedRoutes();
184
+		foreach ($supported_routes as $supported_route) {
185
+			if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) {
186
+				$this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace();
187
+			}
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * returns true if the block should be registered for the current request
194
+	 * else removes block from block_routes array and returns false
195
+	 *
196
+	 * @param BlockInterface $block
197
+	 * @return boolean
198
+	 * @throws InvalidClassException
199
+	 */
200
+	public function matchesRoute(BlockInterface $block)
201
+	{
202
+		if (isset($this->block_asset_managers[ $block->blockType() ])) {
203
+			return true;
204
+		}
205
+		unset($this->block_asset_managers[ $block->blockType() ]);
206
+		return false;
207
+	}
208
+
209
+
210
+	/**
211
+	 * calls registerBlock() and load assets for all installed blocks
212
+	 *
213
+	 * @return void
214
+	 * @throws Exception
215
+	 */
216
+	public function registerBlocks()
217
+	{
218
+		try {
219
+			// cycle thru block loader folders
220
+			foreach ($this->blocks as $block) {
221
+				if (! $this->matchesRoute($block)) {
222
+					continue;
223
+				}
224
+				// perform any setup required for the block
225
+				$block_type = $block->registerBlock();
226
+				if (! $block_type instanceof WP_Block_Type) {
227
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
228
+				}
229
+				do_action(
230
+					'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
231
+					$block,
232
+					$block_type
233
+				);
234
+			}
235
+		} catch (Exception $exception) {
236
+			new ExceptionStackTraceDisplay($exception);
237
+		}
238
+	}
239
+
240
+	public function unloadAssets()
241
+	{
242
+		$assets = array_flip($this->block_asset_managers);
243
+		foreach ($this->block_asset_manager_collection as $asset_manager) {
244
+			// if there are no longer any blocks that require these assets,
245
+			if (! isset($assets[ $asset_manager->assetNamespace() ])) {
246
+				// then unset asset enqueueing and bail
247
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
248
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0);
249
+				remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
250
+				remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2);
251
+			}
252
+		}
253
+	}
254 254
 }
Please login to merge, or discard this patch.
core/domain/services/pue/Config.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,131 +16,131 @@
 block discarded – undo
16 16
  */
17 17
 class Config
18 18
 {
19
-    /**
20
-     * @var EE_Network_Config
21
-     */
22
-    private $network_config;
23
-
24
-
25
-    /**
26
-     * @var EE_Config
27
-     */
28
-    private $ee_config;
29
-
30
-
31
-    public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
32
-    {
33
-        $this->network_config = $network_config;
34
-        $this->ee_config = $ee_config;
35
-    }
36
-
37
-
38
-    /**
39
-     * Get the site license key for the site.
40
-     */
41
-    public function siteLicenseKey()
42
-    {
43
-        return $this->network_config->core->site_license_key;
44
-    }
45
-
46
-
47
-    public function i18nDomain()
48
-    {
49
-        return 'event_espresso';
50
-    }
51
-
52
-
53
-    public function checkPeriod()
54
-    {
55
-        return 24;
56
-    }
57
-
58
-
59
-    public function optionKey()
60
-    {
61
-        return 'ee_site_license_key';
62
-    }
63
-
64
-
65
-    public function optionsPageSlug()
66
-    {
67
-        return 'espresso_general_settings';
68
-    }
69
-
70
-
71
-    public function hostServerUrl()
72
-    {
73
-        return defined('PUE_UPDATES_ENDPOINT')
74
-            ? PUE_UPDATES_ENDPOINT
75
-            : 'https://eventespresso.com';
76
-    }
77
-
78
-
79
-    public function pluginSlug()
80
-    {
81
-        // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
82
-        //  So it's important that you use a key for the version type that is unique and not found in another key.
83
-        // For example:
84
-        // $plugin_slug['premium']['p'] = 'some-premium-slug';
85
-        // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
86
-        // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
87
-        // so doing something like:
88
-        // $plugin_slug['premium']['p'] = 'some-premium-slug';
89
-        // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
90
-        // ..WOULD work!
91
-        return array(
92
-            'free'       => array('decaf' => 'event-espresso-core-decaf'),
93
-            'premium'    => array('p' => 'event-espresso-core-reg'),
94
-            'prerelease' => array('beta' => 'event-espresso-core-pr'),
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * Return whether the site is opted in for UXIP or not.
101
-     *
102
-     * @return bool
103
-     */
104
-    public function isOptedInForUxip()
105
-    {
106
-        return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
107
-    }
108
-
109
-
110
-    /**
111
-     * Return whether the site has been notified about UXIP or not.
112
-     *
113
-     * @return bool
114
-     */
115
-    public function hasNotifiedForUxip()
116
-    {
117
-        return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
118
-    }
119
-
120
-
121
-    /**
122
-     * Set the site opted in for UXIP.
123
-     */
124
-    public function setHasOptedInForUxip()
125
-    {
126
-        $this->ee_config->core->ee_ueip_optin = true;
127
-        $this->ee_config->update_espresso_config(false, false);
128
-    }
129
-
130
-
131
-    /**
132
-     * Set the site opted out for UXIP
133
-     */
134
-    public function setHasOptedOutForUxip()
135
-    {
136
-        $this->ee_config->core->ee_ueip_optin = false;
137
-        $this->ee_config->update_espresso_config(false, false);
138
-    }
139
-
140
-
141
-    public function setHasNotifiedAboutUxip()
142
-    {
143
-        $this->ee_config->core->ee_ueip_has_notified = true;
144
-        $this->ee_config->update_espresso_config(false, false);
145
-    }
19
+	/**
20
+	 * @var EE_Network_Config
21
+	 */
22
+	private $network_config;
23
+
24
+
25
+	/**
26
+	 * @var EE_Config
27
+	 */
28
+	private $ee_config;
29
+
30
+
31
+	public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
32
+	{
33
+		$this->network_config = $network_config;
34
+		$this->ee_config = $ee_config;
35
+	}
36
+
37
+
38
+	/**
39
+	 * Get the site license key for the site.
40
+	 */
41
+	public function siteLicenseKey()
42
+	{
43
+		return $this->network_config->core->site_license_key;
44
+	}
45
+
46
+
47
+	public function i18nDomain()
48
+	{
49
+		return 'event_espresso';
50
+	}
51
+
52
+
53
+	public function checkPeriod()
54
+	{
55
+		return 24;
56
+	}
57
+
58
+
59
+	public function optionKey()
60
+	{
61
+		return 'ee_site_license_key';
62
+	}
63
+
64
+
65
+	public function optionsPageSlug()
66
+	{
67
+		return 'espresso_general_settings';
68
+	}
69
+
70
+
71
+	public function hostServerUrl()
72
+	{
73
+		return defined('PUE_UPDATES_ENDPOINT')
74
+			? PUE_UPDATES_ENDPOINT
75
+			: 'https://eventespresso.com';
76
+	}
77
+
78
+
79
+	public function pluginSlug()
80
+	{
81
+		// Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
82
+		//  So it's important that you use a key for the version type that is unique and not found in another key.
83
+		// For example:
84
+		// $plugin_slug['premium']['p'] = 'some-premium-slug';
85
+		// $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
86
+		// The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
87
+		// so doing something like:
88
+		// $plugin_slug['premium']['p'] = 'some-premium-slug';
89
+		// $plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
90
+		// ..WOULD work!
91
+		return array(
92
+			'free'       => array('decaf' => 'event-espresso-core-decaf'),
93
+			'premium'    => array('p' => 'event-espresso-core-reg'),
94
+			'prerelease' => array('beta' => 'event-espresso-core-pr'),
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Return whether the site is opted in for UXIP or not.
101
+	 *
102
+	 * @return bool
103
+	 */
104
+	public function isOptedInForUxip()
105
+	{
106
+		return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Return whether the site has been notified about UXIP or not.
112
+	 *
113
+	 * @return bool
114
+	 */
115
+	public function hasNotifiedForUxip()
116
+	{
117
+		return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Set the site opted in for UXIP.
123
+	 */
124
+	public function setHasOptedInForUxip()
125
+	{
126
+		$this->ee_config->core->ee_ueip_optin = true;
127
+		$this->ee_config->update_espresso_config(false, false);
128
+	}
129
+
130
+
131
+	/**
132
+	 * Set the site opted out for UXIP
133
+	 */
134
+	public function setHasOptedOutForUxip()
135
+	{
136
+		$this->ee_config->core->ee_ueip_optin = false;
137
+		$this->ee_config->update_espresso_config(false, false);
138
+	}
139
+
140
+
141
+	public function setHasNotifiedAboutUxip()
142
+	{
143
+		$this->ee_config->core->ee_ueip_has_notified = true;
144
+		$this->ee_config->update_espresso_config(false, false);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/domain/entities/custom_post_types/CustomTaxonomyDefinitions.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -15,145 +15,145 @@
 block discarded – undo
15 15
 class CustomTaxonomyDefinitions
16 16
 {
17 17
 
18
-    /**
19
-     * @var array $taxonomies
20
-     */
21
-    private $taxonomies;
18
+	/**
19
+	 * @var array $taxonomies
20
+	 */
21
+	private $taxonomies;
22 22
 
23 23
 
24
-    /**
25
-     * EspressoCustomPostTypeDefinitions constructor.
26
-     */
27
-    public function __construct()
28
-    {
29
-        $this->setTaxonomies();
30
-        add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2);
31
-    }
24
+	/**
25
+	 * EspressoCustomPostTypeDefinitions constructor.
26
+	 */
27
+	public function __construct()
28
+	{
29
+		$this->setTaxonomies();
30
+		add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2);
31
+	}
32 32
 
33 33
 
34
-    private function setTaxonomies()
35
-    {
36
-        $this->taxonomies = array(
37
-            'espresso_event_categories' => array(
38
-                'singular_name' => esc_html__('Event Category', 'event_espresso'),
39
-                'plural_name'   => esc_html__('Event Categories', 'event_espresso'),
40
-                'args'          => array(
41
-                    'public'            => true,
42
-                    'show_in_nav_menus' => true,
43
-                    'show_in_rest'      => true,
44
-                    'capabilities'      => array(
45
-                        'manage_terms' => 'ee_manage_event_categories',
46
-                        'edit_terms'   => 'ee_edit_event_category',
47
-                        'delete_terms' => 'ee_delete_event_category',
48
-                        'assign_terms' => 'ee_assign_event_category',
49
-                    ),
50
-                    'rewrite'           => array(
51
-                        'slug' => EEH_URL::slugify(
52
-                            __('event-category', 'event_espresso'),
53
-                            'event-category'
54
-                        )
55
-                    ),
56
-                ),
57
-            ),
58
-            'espresso_venue_categories' => array(
59
-                'singular_name' => esc_html__('Venue Category', 'event_espresso'),
60
-                'plural_name'   => esc_html__('Venue Categories', 'event_espresso'),
61
-                'args'          => array(
62
-                    'public'            => true,
63
-                    'show_in_nav_menus' => false, // by default this doesn't show for decaf
64
-                    'show_in_rest'      => true,
65
-                    'capabilities'      => array(
66
-                        'manage_terms' => 'ee_manage_venue_categories',
67
-                        'edit_terms'   => 'ee_edit_venue_category',
68
-                        'delete_terms' => 'ee_delete_venue_category',
69
-                        'assign_terms' => 'ee_assign_venue_category',
70
-                    ),
71
-                    'rewrite'           => array(
72
-                        'slug' => EEH_URL::slugify(
73
-                            __('venue-category', 'event_espresso'),
74
-                            'venue-category'
75
-                        )
76
-                    ),
77
-                ),
78
-            ),
79
-            'espresso_event_type'       => array(
80
-                'singular_name' => esc_html__('Event Type', 'event_espresso'),
81
-                'plural_name'   => esc_html__('Event Types', 'event_espresso'),
82
-                'args'          => array(
83
-                    'public'       => true,
84
-                    'show_ui'      => false,
85
-                    'show_in_rest' => true,
86
-                    'capabilities' => array(
87
-                        'manage_terms' => 'ee_read_event_type',
88
-                        'edit_terms'   => 'ee_edit_event_type',
89
-                        'delete_terms' => 'ee_delete_event_type',
90
-                        'assign_terms' => 'ee_assign_event_type',
91
-                    ),
92
-                    'rewrite'      => array(
93
-                        'slug' => EEH_URL::slugify(
94
-                            __('event-type', 'event_espresso'),
95
-                            'event-type'
96
-                        )
97
-                    ),
98
-                    'hierarchical' => true,
99
-                ),
100
-            ),
101
-        );
102
-    }
34
+	private function setTaxonomies()
35
+	{
36
+		$this->taxonomies = array(
37
+			'espresso_event_categories' => array(
38
+				'singular_name' => esc_html__('Event Category', 'event_espresso'),
39
+				'plural_name'   => esc_html__('Event Categories', 'event_espresso'),
40
+				'args'          => array(
41
+					'public'            => true,
42
+					'show_in_nav_menus' => true,
43
+					'show_in_rest'      => true,
44
+					'capabilities'      => array(
45
+						'manage_terms' => 'ee_manage_event_categories',
46
+						'edit_terms'   => 'ee_edit_event_category',
47
+						'delete_terms' => 'ee_delete_event_category',
48
+						'assign_terms' => 'ee_assign_event_category',
49
+					),
50
+					'rewrite'           => array(
51
+						'slug' => EEH_URL::slugify(
52
+							__('event-category', 'event_espresso'),
53
+							'event-category'
54
+						)
55
+					),
56
+				),
57
+			),
58
+			'espresso_venue_categories' => array(
59
+				'singular_name' => esc_html__('Venue Category', 'event_espresso'),
60
+				'plural_name'   => esc_html__('Venue Categories', 'event_espresso'),
61
+				'args'          => array(
62
+					'public'            => true,
63
+					'show_in_nav_menus' => false, // by default this doesn't show for decaf
64
+					'show_in_rest'      => true,
65
+					'capabilities'      => array(
66
+						'manage_terms' => 'ee_manage_venue_categories',
67
+						'edit_terms'   => 'ee_edit_venue_category',
68
+						'delete_terms' => 'ee_delete_venue_category',
69
+						'assign_terms' => 'ee_assign_venue_category',
70
+					),
71
+					'rewrite'           => array(
72
+						'slug' => EEH_URL::slugify(
73
+							__('venue-category', 'event_espresso'),
74
+							'venue-category'
75
+						)
76
+					),
77
+				),
78
+			),
79
+			'espresso_event_type'       => array(
80
+				'singular_name' => esc_html__('Event Type', 'event_espresso'),
81
+				'plural_name'   => esc_html__('Event Types', 'event_espresso'),
82
+				'args'          => array(
83
+					'public'       => true,
84
+					'show_ui'      => false,
85
+					'show_in_rest' => true,
86
+					'capabilities' => array(
87
+						'manage_terms' => 'ee_read_event_type',
88
+						'edit_terms'   => 'ee_edit_event_type',
89
+						'delete_terms' => 'ee_delete_event_type',
90
+						'assign_terms' => 'ee_assign_event_type',
91
+					),
92
+					'rewrite'      => array(
93
+						'slug' => EEH_URL::slugify(
94
+							__('event-type', 'event_espresso'),
95
+							'event-type'
96
+						)
97
+					),
98
+					'hierarchical' => true,
99
+				),
100
+			),
101
+		);
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * @return array
107
-     */
108
-    public function getCustomTaxonomyDefinitions()
109
-    {
110
-        return (array) apply_filters(
111
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
112
-            // legacy filter applied for now,
113
-            // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
114
-            apply_filters(
115
-                'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies',
116
-                $this->taxonomies
117
-            )
118
-        );
119
-    }
105
+	/**
106
+	 * @return array
107
+	 */
108
+	public function getCustomTaxonomyDefinitions()
109
+	{
110
+		return (array) apply_filters(
111
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
112
+			// legacy filter applied for now,
113
+			// later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
114
+			apply_filters(
115
+				'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies',
116
+				$this->taxonomies
117
+			)
118
+		);
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * @return array
124
-     */
125
-    public function getCustomTaxonomySlugs()
126
-    {
127
-        return array_keys($this->getCustomTaxonomyDefinitions());
128
-    }
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public function getCustomTaxonomySlugs()
126
+	{
127
+		return array_keys($this->getCustomTaxonomyDefinitions());
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * By default, WordPress strips all html from term taxonomy description content.
133
-     * The purpose of this method is to remove that restriction
134
-     * and ensure that we still run ee term taxonomy descriptions
135
-     * through some full html sanitization equivalent to the post content field.
136
-     * So first we remove default filter for term description
137
-     * but we have to do this earlier before wp sets their own filter
138
-     * because they just set a global filter on all term descriptions
139
-     * before the custom term description filter.
140
-     * Really sux.
141
-     *
142
-     * @param string $description The description content.
143
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
144
-     * @return string
145
-     */
146
-    public function filterCustomTermDescription($description, $taxonomy)
147
-    {
148
-        // get a list of EE taxonomies
149
-        $custom_taxonomies = $this->getCustomTaxonomySlugs();
150
-        // only do our own thing if the taxonomy listed is an ee taxonomy.
151
-        if (in_array($taxonomy, $custom_taxonomies, true)) {
152
-            // remove default wp filter
153
-            remove_filter('pre_term_description', 'wp_filter_kses');
154
-            // sanitize THIS content.
155
-            $description = wp_kses($description, wp_kses_allowed_html('post'));
156
-        }
157
-        return $description;
158
-    }
131
+	/**
132
+	 * By default, WordPress strips all html from term taxonomy description content.
133
+	 * The purpose of this method is to remove that restriction
134
+	 * and ensure that we still run ee term taxonomy descriptions
135
+	 * through some full html sanitization equivalent to the post content field.
136
+	 * So first we remove default filter for term description
137
+	 * but we have to do this earlier before wp sets their own filter
138
+	 * because they just set a global filter on all term descriptions
139
+	 * before the custom term description filter.
140
+	 * Really sux.
141
+	 *
142
+	 * @param string $description The description content.
143
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
144
+	 * @return string
145
+	 */
146
+	public function filterCustomTermDescription($description, $taxonomy)
147
+	{
148
+		// get a list of EE taxonomies
149
+		$custom_taxonomies = $this->getCustomTaxonomySlugs();
150
+		// only do our own thing if the taxonomy listed is an ee taxonomy.
151
+		if (in_array($taxonomy, $custom_taxonomies, true)) {
152
+			// remove default wp filter
153
+			remove_filter('pre_term_description', 'wp_filter_kses');
154
+			// sanitize THIS content.
155
+			$description = wp_kses($description, wp_kses_allowed_html('post'));
156
+		}
157
+		return $description;
158
+	}
159 159
 }
Please login to merge, or discard this patch.
core/services/request/middleware/DetectFileEditorRequest.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -17,23 +17,23 @@
 block discarded – undo
17 17
 class DetectFileEditorRequest extends Middleware
18 18
 {
19 19
 
20
-    /**
21
-     * converts a Request to a Response
22
-     *
23
-     * @param RequestInterface  $request
24
-     * @param ResponseInterface $response
25
-     * @return ResponseInterface
26
-     */
27
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
28
-    {
29
-        $this->request  = $request;
30
-        $this->response = $response;
31
-        // can't store user data during WP error scrapes if no user exists
32
-        // so don't load the session since it's not going to work anyways
33
-        if ($this->request->isWordPressScrape()) {
34
-            add_filter('FHEE_load_EE_Session', '__return_false', 999);
35
-        }
36
-        $this->response = $this->processRequestStack($this->request, $this->response);
37
-        return $this->response;
38
-    }
20
+	/**
21
+	 * converts a Request to a Response
22
+	 *
23
+	 * @param RequestInterface  $request
24
+	 * @param ResponseInterface $response
25
+	 * @return ResponseInterface
26
+	 */
27
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
28
+	{
29
+		$this->request  = $request;
30
+		$this->response = $response;
31
+		// can't store user data during WP error scrapes if no user exists
32
+		// so don't load the session since it's not going to work anyways
33
+		if ($this->request->isWordPressScrape()) {
34
+			add_filter('FHEE_load_EE_Session', '__return_false', 999);
35
+		}
36
+		$this->response = $this->processRequestStack($this->request, $this->response);
37
+		return $this->response;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
core/entities/models/JsonModelSchema.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,22 +76,22 @@  discard block
 block discarded – undo
76 76
     public function getModelSchemaForFields(array $model_fields, array $schema)
77 77
     {
78 78
         foreach ($model_fields as $field => $model_field) {
79
-            if (! $model_field instanceof EE_Model_Field_Base) {
79
+            if ( ! $model_field instanceof EE_Model_Field_Base) {
80 80
                 continue;
81 81
             }
82
-            $schema['properties'][ $field ] = $model_field->getSchema();
82
+            $schema['properties'][$field] = $model_field->getSchema();
83 83
 
84 84
             // if this is a primary key field add the primary key item
85 85
             if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
-                $schema['properties'][ $field ]['primary_key'] = true;
86
+                $schema['properties'][$field]['primary_key'] = true;
87 87
                 if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
-                    $schema['properties'][ $field ]['readonly'] = true;
88
+                    $schema['properties'][$field]['readonly'] = true;
89 89
                 }
90 90
             }
91 91
 
92 92
             // if this is a foreign key field add the foreign key item
93 93
             if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
-                $schema['properties'][ $field ]['foreign_key'] = array(
94
+                $schema['properties'][$field]['foreign_key'] = array(
95 95
                     'description' => esc_html__(
96 96
                         'This is a foreign key the points to the given models.',
97 97
                         'event_espresso'
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
     public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116 116
     {
117 117
         foreach ($relations_on_model as $model_name => $relation) {
118
-            if (! $relation instanceof EE_Model_Relation_Base) {
118
+            if ( ! $relation instanceof EE_Model_Relation_Base) {
119 119
                 continue;
120 120
             }
121 121
             $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122 122
                 ? strtolower($model_name)
123 123
                 : EEH_Inflector::pluralize_and_lower($model_name);
124
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
124
+            $schema['properties'][$model_name_for_schema] = $relation->getSchema();
125
+            $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
126 126
 
127 127
             // links schema
128
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
128
+            $links_key = 'https://api.eventespresso.com/'.strtolower($model_name);
129
+            $schema['properties']['_links']['properties'][$links_key] = array(
130 130
                 'description' => esc_html__(
131 131
                     'Array of objects describing the link(s) for this relation resource.',
132 132
                     'event_espresso'
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -25,256 +25,256 @@
 block discarded – undo
25 25
 class JsonModelSchema
26 26
 {
27 27
 
28
-    /**
29
-     * @var EEM_Base
30
-     */
31
-    protected $model;
28
+	/**
29
+	 * @var EEM_Base
30
+	 */
31
+	protected $model;
32 32
 
33
-    /**
34
-     * @var CalculatedModelFields
35
-     */
36
-    protected $fields_calculator;
33
+	/**
34
+	 * @var CalculatedModelFields
35
+	 */
36
+	protected $fields_calculator;
37 37
 
38 38
 
39
-    /**
40
-     * JsonModelSchema constructor.
41
-     *
42
-     * @param EEM_Base              $model
43
-     * @param CalculatedModelFields $fields_calculator
44
-     */
45
-    public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
46
-    {
47
-        $this->model = $model;
48
-        $this->fields_calculator = $fields_calculator;
49
-    }
39
+	/**
40
+	 * JsonModelSchema constructor.
41
+	 *
42
+	 * @param EEM_Base              $model
43
+	 * @param CalculatedModelFields $fields_calculator
44
+	 */
45
+	public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
46
+	{
47
+		$this->model = $model;
48
+		$this->fields_calculator = $fields_calculator;
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Return the schema for a given model from a given model.
54
-     *
55
-     * @return array
56
-     */
57
-    public function getModelSchema()
58
-    {
59
-        return $this->getModelSchemaForRelations(
60
-            $this->model->relation_settings(),
61
-            $this->getModelSchemaForFields(
62
-                $this->model->field_settings(),
63
-                $this->getInitialSchemaStructure()
64
-            )
65
-        );
66
-    }
52
+	/**
53
+	 * Return the schema for a given model from a given model.
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public function getModelSchema()
58
+	{
59
+		return $this->getModelSchemaForRelations(
60
+			$this->model->relation_settings(),
61
+			$this->getModelSchemaForFields(
62
+				$this->model->field_settings(),
63
+				$this->getInitialSchemaStructure()
64
+			)
65
+		);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Get the schema for a given set of model fields.
71
-     *
72
-     * @param EE_Model_Field_Base[] $model_fields
73
-     * @param array                  $schema
74
-     * @return array
75
-     */
76
-    public function getModelSchemaForFields(array $model_fields, array $schema)
77
-    {
78
-        foreach ($model_fields as $field => $model_field) {
79
-            if (! $model_field instanceof EE_Model_Field_Base) {
80
-                continue;
81
-            }
82
-            $schema['properties'][ $field ] = $model_field->getSchema();
69
+	/**
70
+	 * Get the schema for a given set of model fields.
71
+	 *
72
+	 * @param EE_Model_Field_Base[] $model_fields
73
+	 * @param array                  $schema
74
+	 * @return array
75
+	 */
76
+	public function getModelSchemaForFields(array $model_fields, array $schema)
77
+	{
78
+		foreach ($model_fields as $field => $model_field) {
79
+			if (! $model_field instanceof EE_Model_Field_Base) {
80
+				continue;
81
+			}
82
+			$schema['properties'][ $field ] = $model_field->getSchema();
83 83
 
84
-            // if this is a primary key field add the primary key item
85
-            if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
-                $schema['properties'][ $field ]['primary_key'] = true;
87
-                if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
-                    $schema['properties'][ $field ]['readonly'] = true;
89
-                }
90
-            }
84
+			// if this is a primary key field add the primary key item
85
+			if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
+				$schema['properties'][ $field ]['primary_key'] = true;
87
+				if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
+					$schema['properties'][ $field ]['readonly'] = true;
89
+				}
90
+			}
91 91
 
92
-            // if this is a foreign key field add the foreign key item
93
-            if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
-                $schema['properties'][ $field ]['foreign_key'] = array(
95
-                    'description' => esc_html__(
96
-                        'This is a foreign key the points to the given models.',
97
-                        'event_espresso'
98
-                    ),
99
-                    'type'        => 'array',
100
-                    'enum'        => $model_field->get_model_class_names_pointed_to(),
101
-                );
102
-            }
103
-        }
104
-        return $schema;
105
-    }
92
+			// if this is a foreign key field add the foreign key item
93
+			if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
+				$schema['properties'][ $field ]['foreign_key'] = array(
95
+					'description' => esc_html__(
96
+						'This is a foreign key the points to the given models.',
97
+						'event_espresso'
98
+					),
99
+					'type'        => 'array',
100
+					'enum'        => $model_field->get_model_class_names_pointed_to(),
101
+				);
102
+			}
103
+		}
104
+		return $schema;
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * Get the schema for a given set of model relations
110
-     *
111
-     * @param EE_Model_Relation_Base[] $relations_on_model
112
-     * @param array                    $schema
113
-     * @return array
114
-     */
115
-    public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116
-    {
117
-        foreach ($relations_on_model as $model_name => $relation) {
118
-            if (! $relation instanceof EE_Model_Relation_Base) {
119
-                continue;
120
-            }
121
-            $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122
-                ? strtolower($model_name)
123
-                : EEH_Inflector::pluralize_and_lower($model_name);
124
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
108
+	/**
109
+	 * Get the schema for a given set of model relations
110
+	 *
111
+	 * @param EE_Model_Relation_Base[] $relations_on_model
112
+	 * @param array                    $schema
113
+	 * @return array
114
+	 */
115
+	public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116
+	{
117
+		foreach ($relations_on_model as $model_name => $relation) {
118
+			if (! $relation instanceof EE_Model_Relation_Base) {
119
+				continue;
120
+			}
121
+			$model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122
+				? strtolower($model_name)
123
+				: EEH_Inflector::pluralize_and_lower($model_name);
124
+			$schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
+			$schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
126 126
 
127
-            // links schema
128
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
130
-                'description' => esc_html__(
131
-                    'Array of objects describing the link(s) for this relation resource.',
132
-                    'event_espresso'
133
-                ),
134
-                'type' => 'array',
135
-                'readonly' => true,
136
-                'items' => array(
137
-                    'type' => 'object',
138
-                    'properties' => array(
139
-                        'href' => array(
140
-                            'type' => 'string',
141
-                            'description' => sprintf(
142
-                                // translators: placeholder is the model name for the relation.
143
-                                esc_html__(
144
-                                    'The link to the resource for the %s relation(s) to this entity',
145
-                                    'event_espresso'
146
-                                ),
147
-                                $model_name
148
-                            ),
149
-                        ),
150
-                        'single' => array(
151
-                            'type' => 'boolean',
152
-                            'description' => sprintf(
153
-                                // translators: placeholder is the model name for the relation.
154
-                                esc_html__(
155
-                                    'Whether or not there is only a single %s relation to this entity',
156
-                                    'event_espresso'
157
-                                ),
158
-                                $model_name
159
-                            ),
160
-                        ),
161
-                    ),
162
-                    'additionalProperties' => false
163
-                ),
164
-            );
165
-        }
166
-        return $schema;
167
-    }
127
+			// links schema
128
+			$links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
+			$schema['properties']['_links']['properties'][ $links_key ] = array(
130
+				'description' => esc_html__(
131
+					'Array of objects describing the link(s) for this relation resource.',
132
+					'event_espresso'
133
+				),
134
+				'type' => 'array',
135
+				'readonly' => true,
136
+				'items' => array(
137
+					'type' => 'object',
138
+					'properties' => array(
139
+						'href' => array(
140
+							'type' => 'string',
141
+							'description' => sprintf(
142
+								// translators: placeholder is the model name for the relation.
143
+								esc_html__(
144
+									'The link to the resource for the %s relation(s) to this entity',
145
+									'event_espresso'
146
+								),
147
+								$model_name
148
+							),
149
+						),
150
+						'single' => array(
151
+							'type' => 'boolean',
152
+							'description' => sprintf(
153
+								// translators: placeholder is the model name for the relation.
154
+								esc_html__(
155
+									'Whether or not there is only a single %s relation to this entity',
156
+									'event_espresso'
157
+								),
158
+								$model_name
159
+							),
160
+						),
161
+					),
162
+					'additionalProperties' => false
163
+				),
164
+			);
165
+		}
166
+		return $schema;
167
+	}
168 168
 
169 169
 
170
-    /**
171
-     * Outputs the schema header for a model.
172
-     *
173
-     * @return array
174
-     */
175
-    public function getInitialSchemaStructure()
176
-    {
177
-        return array(
178
-            '$schema'    => 'http://json-schema.org/draft-04/schema#',
179
-            'title'      => $this->model->get_this_model_name(),
180
-            'type'       => 'object',
181
-            'properties' => array(
182
-                'link' => array(
183
-                    'description' => esc_html__(
184
-                        'Link to event on WordPress site hosting events.',
185
-                        'event_espresso'
186
-                    ),
187
-                    'type' => 'string',
188
-                    'readonly' => true,
189
-                ),
190
-                '_links' => array(
191
-                    'description' => esc_html__(
192
-                        'Various links for resources related to the entity.',
193
-                        'event_espresso'
194
-                    ),
195
-                    'type' => 'object',
196
-                    'readonly' => true,
197
-                    'properties' => array(
198
-                        'self' => array(
199
-                            'description' => esc_html__(
200
-                                'Link to this entities resource.',
201
-                                'event_espresso'
202
-                            ),
203
-                            'type' => 'array',
204
-                            'items' => array(
205
-                                'type' => 'object',
206
-                                'properties' => array(
207
-                                    'href' => array(
208
-                                        'type' => 'string',
209
-                                    ),
210
-                                ),
211
-                                'additionalProperties' => false
212
-                            ),
213
-                            'readonly' => true
214
-                        ),
215
-                        'collection' => array(
216
-                            'description' => esc_html__(
217
-                                'Link to this entities collection resource.',
218
-                                'event_espresso'
219
-                            ),
220
-                            'type' => 'array',
221
-                            'items' => array(
222
-                                'type' => 'object',
223
-                                'properties' => array(
224
-                                    'href' => array(
225
-                                        'type' => 'string'
226
-                                    ),
227
-                                ),
228
-                                'additionalProperties' => false
229
-                            ),
230
-                            'readonly' => true
231
-                        ),
232
-                    ),
233
-                    'additionalProperties' => false,
234
-                ),
235
-                '_calculated_fields' => array_merge(
236
-                    $this->fields_calculator->getJsonSchemaForModel($this->model),
237
-                    array(
238
-                        '_protected' => $this->getProtectedFieldsSchema()
239
-                    )
240
-                ),
241
-                '_protected' => $this->getProtectedFieldsSchema()
242
-            ),
243
-            'additionalProperties' => false,
244
-        );
245
-    }
170
+	/**
171
+	 * Outputs the schema header for a model.
172
+	 *
173
+	 * @return array
174
+	 */
175
+	public function getInitialSchemaStructure()
176
+	{
177
+		return array(
178
+			'$schema'    => 'http://json-schema.org/draft-04/schema#',
179
+			'title'      => $this->model->get_this_model_name(),
180
+			'type'       => 'object',
181
+			'properties' => array(
182
+				'link' => array(
183
+					'description' => esc_html__(
184
+						'Link to event on WordPress site hosting events.',
185
+						'event_espresso'
186
+					),
187
+					'type' => 'string',
188
+					'readonly' => true,
189
+				),
190
+				'_links' => array(
191
+					'description' => esc_html__(
192
+						'Various links for resources related to the entity.',
193
+						'event_espresso'
194
+					),
195
+					'type' => 'object',
196
+					'readonly' => true,
197
+					'properties' => array(
198
+						'self' => array(
199
+							'description' => esc_html__(
200
+								'Link to this entities resource.',
201
+								'event_espresso'
202
+							),
203
+							'type' => 'array',
204
+							'items' => array(
205
+								'type' => 'object',
206
+								'properties' => array(
207
+									'href' => array(
208
+										'type' => 'string',
209
+									),
210
+								),
211
+								'additionalProperties' => false
212
+							),
213
+							'readonly' => true
214
+						),
215
+						'collection' => array(
216
+							'description' => esc_html__(
217
+								'Link to this entities collection resource.',
218
+								'event_espresso'
219
+							),
220
+							'type' => 'array',
221
+							'items' => array(
222
+								'type' => 'object',
223
+								'properties' => array(
224
+									'href' => array(
225
+										'type' => 'string'
226
+									),
227
+								),
228
+								'additionalProperties' => false
229
+							),
230
+							'readonly' => true
231
+						),
232
+					),
233
+					'additionalProperties' => false,
234
+				),
235
+				'_calculated_fields' => array_merge(
236
+					$this->fields_calculator->getJsonSchemaForModel($this->model),
237
+					array(
238
+						'_protected' => $this->getProtectedFieldsSchema()
239
+					)
240
+				),
241
+				'_protected' => $this->getProtectedFieldsSchema()
242
+			),
243
+			'additionalProperties' => false,
244
+		);
245
+	}
246 246
 
247
-    /**
248
-     * Returns an array of JSON schema to describe the _protected property on responses
249
-     * @since 4.9.74.p
250
-     * @return array
251
-     */
252
-    protected function getProtectedFieldsSchema()
253
-    {
254
-        return array(
255
-            'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'),
256
-            'type' => 'array',
257
-            'items' => array(
258
-                'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'),
259
-                'type' => 'string',
260
-                'readonly' => true,
261
-            ),
262
-            'readonly' => true
263
-        );
264
-    }
247
+	/**
248
+	 * Returns an array of JSON schema to describe the _protected property on responses
249
+	 * @since 4.9.74.p
250
+	 * @return array
251
+	 */
252
+	protected function getProtectedFieldsSchema()
253
+	{
254
+		return array(
255
+			'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'),
256
+			'type' => 'array',
257
+			'items' => array(
258
+				'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'),
259
+				'type' => 'string',
260
+				'readonly' => true,
261
+			),
262
+			'readonly' => true
263
+		);
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Allows one to just use the object as a string to get the json.
269
-     * eg.
270
-     * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
271
-     * echo $json_schema; //outputs the schema as a json formatted string.
272
-     *
273
-     * @return string
274
-     */
275
-    public function __toString()
276
-    {
277
-        $schema = wp_json_encode($this->getModelSchema());
278
-        return is_string($schema) ? $schema : '';
279
-    }
267
+	/**
268
+	 * Allows one to just use the object as a string to get the json.
269
+	 * eg.
270
+	 * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
271
+	 * echo $json_schema; //outputs the schema as a json formatted string.
272
+	 *
273
+	 * @return string
274
+	 */
275
+	public function __toString()
276
+	{
277
+		$schema = wp_json_encode($this->getModelSchema());
278
+		return is_string($schema) ? $schema : '';
279
+	}
280 280
 }
Please login to merge, or discard this patch.