Completed
Branch Gutenberg/block-manager (78b45d)
by
unknown
74:10 queued 60:16
created
core/services/loaders/ClassInterfaceCache.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -20,160 +20,160 @@
 block discarded – undo
20 20
 class ClassInterfaceCache
21 21
 {
22 22
 
23
-    /**
24
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
-     *
26
-     * @var string[][] $interfaces
27
-     */
28
-    private $interfaces = array();
29
-
30
-    /**
31
-     * @type string[][] $aliases
32
-     */
33
-    protected $aliases = array();
34
-
35
-
36
-    /**
37
-     * @param string $fqn
38
-     * @return string
39
-     */
40
-    public function getFqn($fqn)
41
-    {
42
-        return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
43
-    }
44
-
45
-
46
-    /**
47
-     * @param string $fqn
48
-     * @return array
49
-     */
50
-    public function getInterfaces($fqn)
51
-    {
52
-        $fqn = $this->getFqn($fqn);
53
-        // have we already seen this FQCN ?
54
-        if (! array_key_exists($fqn, $this->interfaces)) {
55
-            $this->interfaces[ $fqn ] = array();
56
-            if (class_exists($fqn)) {
57
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
58
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
-                    ? $this->interfaces[ $fqn ]
60
-                    : array();
61
-            }
62
-        }
63
-        return $this->interfaces[ $fqn ];
64
-    }
65
-
66
-
67
-    /**
68
-     * @param string $fqn
69
-     * @param string $interface
70
-     * @return bool
71
-     */
72
-    public function hasInterface($fqn, $interface)
73
-    {
74
-        $fqn        = $this->getFqn($fqn);
75
-        $interfaces = $this->getInterfaces($fqn);
76
-        return in_array($interface, $interfaces, true);
77
-    }
78
-
79
-
80
-    /**
81
-     * adds an alias for a classname
82
-     *
83
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
84
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
85
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
86
-     */
87
-    public function addAlias($fqn, $alias, $for_class = '')
88
-    {
89
-        $fqn   = $this->getFqn($fqn);
90
-        $alias = $this->getFqn($alias);
91
-        // are we adding an alias for a specific class?
92
-        if ($for_class !== '') {
93
-            // make sure it's set up as an array
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
96
-            }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
98
-            return;
99
-        }
100
-        $this->aliases[ $alias ] = $fqn;
101
-    }
102
-
103
-
104
-    /**
105
-     * returns TRUE if the provided FQN is an alias
106
-     *
107
-     * @param string $fqn
108
-     * @param string $for_class
109
-     * @return bool
110
-     */
111
-    public function isAlias($fqn = '', $for_class = '')
112
-    {
113
-        $fqn = $this->getFqn($fqn);
114
-        if ($this->isAliasForClass($fqn, $for_class)) {
115
-            return true;
116
-        }
117
-        if ($for_class === '' && $this->isDirectAlias($fqn)) {
118
-            return true;
119
-        }
120
-        return false;
121
-    }
122
-
123
-
124
-    /**
125
-     * returns TRUE if the provided FQN is an alias
126
-     *
127
-     * @param string $fqn
128
-     * @return bool
129
-     */
130
-    protected function isDirectAlias($fqn = '')
131
-    {
132
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
133
-    }
134
-
135
-
136
-    /**
137
-     * returns TRUE if the provided FQN is an alias for the specified class
138
-     *
139
-     * @param string $fqn
140
-     * @param string $for_class
141
-     * @return bool
142
-     */
143
-    protected function isAliasForClass($fqn = '', $for_class = '')
144
-    {
145
-        return (
146
-            $for_class !== ''
147
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
148
-        );
149
-    }
150
-
151
-
152
-    /**
153
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
154
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
155
-     *  for example:
156
-     *      if the following two entries were added to the aliases array:
157
-     *          array(
158
-     *              'interface_alias'           => 'some\namespace\interface'
159
-     *              'some\namespace\interface'  => 'some\namespace\classname'
160
-     *          )
161
-     *      then one could use Loader::getNew( 'interface_alias' )
162
-     *      to load an instance of 'some\namespace\classname'
163
-     *
164
-     * @param string $alias
165
-     * @param string $for_class
166
-     * @return string
167
-     */
168
-    public function getFqnForAlias($alias = '', $for_class = '')
169
-    {
170
-        $alias = $this->getFqn($alias);
171
-        if ($this->isAliasForClass($alias, $for_class)) {
172
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
173
-        }
174
-        if ($this->isDirectAlias($alias)) {
175
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
176
-        }
177
-        return $alias;
178
-    }
23
+	/**
24
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
+	 *
26
+	 * @var string[][] $interfaces
27
+	 */
28
+	private $interfaces = array();
29
+
30
+	/**
31
+	 * @type string[][] $aliases
32
+	 */
33
+	protected $aliases = array();
34
+
35
+
36
+	/**
37
+	 * @param string $fqn
38
+	 * @return string
39
+	 */
40
+	public function getFqn($fqn)
41
+	{
42
+		return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
43
+	}
44
+
45
+
46
+	/**
47
+	 * @param string $fqn
48
+	 * @return array
49
+	 */
50
+	public function getInterfaces($fqn)
51
+	{
52
+		$fqn = $this->getFqn($fqn);
53
+		// have we already seen this FQCN ?
54
+		if (! array_key_exists($fqn, $this->interfaces)) {
55
+			$this->interfaces[ $fqn ] = array();
56
+			if (class_exists($fqn)) {
57
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
58
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
+					? $this->interfaces[ $fqn ]
60
+					: array();
61
+			}
62
+		}
63
+		return $this->interfaces[ $fqn ];
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param string $fqn
69
+	 * @param string $interface
70
+	 * @return bool
71
+	 */
72
+	public function hasInterface($fqn, $interface)
73
+	{
74
+		$fqn        = $this->getFqn($fqn);
75
+		$interfaces = $this->getInterfaces($fqn);
76
+		return in_array($interface, $interfaces, true);
77
+	}
78
+
79
+
80
+	/**
81
+	 * adds an alias for a classname
82
+	 *
83
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
84
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
85
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
86
+	 */
87
+	public function addAlias($fqn, $alias, $for_class = '')
88
+	{
89
+		$fqn   = $this->getFqn($fqn);
90
+		$alias = $this->getFqn($alias);
91
+		// are we adding an alias for a specific class?
92
+		if ($for_class !== '') {
93
+			// make sure it's set up as an array
94
+			if (! isset($this->aliases[ $for_class ])) {
95
+				$this->aliases[ $for_class ] = array();
96
+			}
97
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
98
+			return;
99
+		}
100
+		$this->aliases[ $alias ] = $fqn;
101
+	}
102
+
103
+
104
+	/**
105
+	 * returns TRUE if the provided FQN is an alias
106
+	 *
107
+	 * @param string $fqn
108
+	 * @param string $for_class
109
+	 * @return bool
110
+	 */
111
+	public function isAlias($fqn = '', $for_class = '')
112
+	{
113
+		$fqn = $this->getFqn($fqn);
114
+		if ($this->isAliasForClass($fqn, $for_class)) {
115
+			return true;
116
+		}
117
+		if ($for_class === '' && $this->isDirectAlias($fqn)) {
118
+			return true;
119
+		}
120
+		return false;
121
+	}
122
+
123
+
124
+	/**
125
+	 * returns TRUE if the provided FQN is an alias
126
+	 *
127
+	 * @param string $fqn
128
+	 * @return bool
129
+	 */
130
+	protected function isDirectAlias($fqn = '')
131
+	{
132
+		return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
133
+	}
134
+
135
+
136
+	/**
137
+	 * returns TRUE if the provided FQN is an alias for the specified class
138
+	 *
139
+	 * @param string $fqn
140
+	 * @param string $for_class
141
+	 * @return bool
142
+	 */
143
+	protected function isAliasForClass($fqn = '', $for_class = '')
144
+	{
145
+		return (
146
+			$for_class !== ''
147
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
148
+		);
149
+	}
150
+
151
+
152
+	/**
153
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
154
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
155
+	 *  for example:
156
+	 *      if the following two entries were added to the aliases array:
157
+	 *          array(
158
+	 *              'interface_alias'           => 'some\namespace\interface'
159
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
160
+	 *          )
161
+	 *      then one could use Loader::getNew( 'interface_alias' )
162
+	 *      to load an instance of 'some\namespace\classname'
163
+	 *
164
+	 * @param string $alias
165
+	 * @param string $for_class
166
+	 * @return string
167
+	 */
168
+	public function getFqnForAlias($alias = '', $for_class = '')
169
+	{
170
+		$alias = $this->getFqn($alias);
171
+		if ($this->isAliasForClass($alias, $for_class)) {
172
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
173
+		}
174
+		if ($this->isDirectAlias($alias)) {
175
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
176
+		}
177
+		return $alias;
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $fqn = $this->getFqn($fqn);
53 53
         // have we already seen this FQCN ?
54
-        if (! array_key_exists($fqn, $this->interfaces)) {
55
-            $this->interfaces[ $fqn ] = array();
54
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
55
+            $this->interfaces[$fqn] = array();
56 56
             if (class_exists($fqn)) {
57
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
58
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
59
-                    ? $this->interfaces[ $fqn ]
57
+                $this->interfaces[$fqn] = class_implements($fqn, false);
58
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
59
+                    ? $this->interfaces[$fqn]
60 60
                     : array();
61 61
             }
62 62
         }
63
-        return $this->interfaces[ $fqn ];
63
+        return $this->interfaces[$fqn];
64 64
     }
65 65
 
66 66
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
         // are we adding an alias for a specific class?
92 92
         if ($for_class !== '') {
93 93
             // make sure it's set up as an array
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
94
+            if ( ! isset($this->aliases[$for_class])) {
95
+                $this->aliases[$for_class] = array();
96 96
             }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
97
+            $this->aliases[$for_class][$alias] = $fqn;
98 98
             return;
99 99
         }
100
-        $this->aliases[ $alias ] = $fqn;
100
+        $this->aliases[$alias] = $fqn;
101 101
     }
102 102
 
103 103
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     protected function isDirectAlias($fqn = '')
131 131
     {
132
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
132
+        return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]);
133 133
     }
134 134
 
135 135
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     {
145 145
         return (
146 146
             $for_class !== ''
147
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
147
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
148 148
         );
149 149
     }
150 150
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
     {
170 170
         $alias = $this->getFqn($alias);
171 171
         if ($this->isAliasForClass($alias, $for_class)) {
172
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
172
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
173 173
         }
174 174
         if ($this->isDirectAlias($alias)) {
175
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
175
+            return $this->getFqnForAlias($this->aliases[(string) $alias], '');
176 176
         }
177 177
         return $alias;
178 178
     }
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RegisterCustomPostTypes.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
     {
62 62
         $custom_post_types = $this->custom_post_types->getDefinitions();
63 63
         foreach ($custom_post_types as $custom_post_type => $CPT) {
64
-            $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType(
64
+            $this->wp_post_types[$custom_post_type] = $this->registerCustomPostType(
65 65
                 $custom_post_type,
66 66
                 $CPT['singular_name'],
67 67
                 $CPT['plural_name'],
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -18,240 +18,240 @@
 block discarded – undo
18 18
 class RegisterCustomPostTypes
19 19
 {
20 20
 
21
-    /**
22
-     * @var CustomPostTypeDefinitions $custom_post_types
23
-     */
24
-    public $custom_post_types;
21
+	/**
22
+	 * @var CustomPostTypeDefinitions $custom_post_types
23
+	 */
24
+	public $custom_post_types;
25 25
 
26
-    /**
27
-     * @var WP_Post_Type[] $wp_post_types
28
-     */
29
-    public $wp_post_types = array();
26
+	/**
27
+	 * @var WP_Post_Type[] $wp_post_types
28
+	 */
29
+	public $wp_post_types = array();
30 30
 
31 31
 
32
-    /**
33
-     * RegisterCustomPostTypes constructor.
34
-     *
35
-     * @param CustomPostTypeDefinitions $custom_post_types
36
-     */
37
-    public function __construct(CustomPostTypeDefinitions $custom_post_types)
38
-    {
39
-        $this->custom_post_types = $custom_post_types;
40
-    }
32
+	/**
33
+	 * RegisterCustomPostTypes constructor.
34
+	 *
35
+	 * @param CustomPostTypeDefinitions $custom_post_types
36
+	 */
37
+	public function __construct(CustomPostTypeDefinitions $custom_post_types)
38
+	{
39
+		$this->custom_post_types = $custom_post_types;
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * @return WP_Post_Type[]
45
-     */
46
-    public function getRegisteredCustomPostTypes()
47
-    {
48
-        return $this->wp_post_types;
49
-    }
43
+	/**
44
+	 * @return WP_Post_Type[]
45
+	 */
46
+	public function getRegisteredCustomPostTypes()
47
+	{
48
+		return $this->wp_post_types;
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * @return void
54
-     * @throws DomainException
55
-     */
56
-    public function registerCustomPostTypes()
57
-    {
58
-        $custom_post_types = $this->custom_post_types->getDefinitions();
59
-        foreach ($custom_post_types as $custom_post_type => $CPT) {
60
-            $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType(
61
-                $custom_post_type,
62
-                $CPT['singular_name'],
63
-                $CPT['plural_name'],
64
-                $CPT['singular_slug'],
65
-                $CPT['plural_slug'],
66
-                $CPT['args']
67
-            );
68
-        }
69
-    }
52
+	/**
53
+	 * @return void
54
+	 * @throws DomainException
55
+	 */
56
+	public function registerCustomPostTypes()
57
+	{
58
+		$custom_post_types = $this->custom_post_types->getDefinitions();
59
+		foreach ($custom_post_types as $custom_post_type => $CPT) {
60
+			$this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType(
61
+				$custom_post_type,
62
+				$CPT['singular_name'],
63
+				$CPT['plural_name'],
64
+				$CPT['singular_slug'],
65
+				$CPT['plural_slug'],
66
+				$CPT['args']
67
+			);
68
+		}
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * Registers a new custom post type. Sets default settings given only the following params.
74
-     * Returns the registered post type object, or an error object.
75
-     *
76
-     * @param string $post_type          the actual post type name
77
-     *                                   IMPORTANT:
78
-     *                                   this must match what the slug is for admin pages related to this CPT
79
-     *                                   Also any models must use this slug as well
80
-     * @param string $singular_name      a pre-internationalized string for the singular name of the objects
81
-     * @param string $plural_name        a pre-internationalized string for the plural name of the objects
82
-     * @param string $singular_slug
83
-     * @param string $plural_slug
84
-     * @param array  $override_arguments exactly like $args as described in
85
-     *                                   http://codex.wordpress.org/Function_Reference/register_post_type
86
-     * @return WP_Post_Type|WP_Error
87
-     * @throws DomainException
88
-     */
89
-    public function registerCustomPostType(
90
-        $post_type,
91
-        $singular_name,
92
-        $plural_name,
93
-        $singular_slug = '',
94
-        $plural_slug = '',
95
-        array $override_arguments = array()
96
-    ) {
97
-        $wp_post_type = register_post_type(
98
-            $post_type,
99
-            $this->prepareArguments(
100
-                $post_type,
101
-                $singular_name,
102
-                $plural_name,
103
-                $singular_slug,
104
-                $plural_slug,
105
-                $override_arguments
106
-            )
107
-        );
108
-        if ($wp_post_type instanceof WP_Error) {
109
-            throw new DomainException($wp_post_type->get_error_message());
110
-        }
111
-        return $wp_post_type;
112
-    }
72
+	/**
73
+	 * Registers a new custom post type. Sets default settings given only the following params.
74
+	 * Returns the registered post type object, or an error object.
75
+	 *
76
+	 * @param string $post_type          the actual post type name
77
+	 *                                   IMPORTANT:
78
+	 *                                   this must match what the slug is for admin pages related to this CPT
79
+	 *                                   Also any models must use this slug as well
80
+	 * @param string $singular_name      a pre-internationalized string for the singular name of the objects
81
+	 * @param string $plural_name        a pre-internationalized string for the plural name of the objects
82
+	 * @param string $singular_slug
83
+	 * @param string $plural_slug
84
+	 * @param array  $override_arguments exactly like $args as described in
85
+	 *                                   http://codex.wordpress.org/Function_Reference/register_post_type
86
+	 * @return WP_Post_Type|WP_Error
87
+	 * @throws DomainException
88
+	 */
89
+	public function registerCustomPostType(
90
+		$post_type,
91
+		$singular_name,
92
+		$plural_name,
93
+		$singular_slug = '',
94
+		$plural_slug = '',
95
+		array $override_arguments = array()
96
+	) {
97
+		$wp_post_type = register_post_type(
98
+			$post_type,
99
+			$this->prepareArguments(
100
+				$post_type,
101
+				$singular_name,
102
+				$plural_name,
103
+				$singular_slug,
104
+				$plural_slug,
105
+				$override_arguments
106
+			)
107
+		);
108
+		if ($wp_post_type instanceof WP_Error) {
109
+			throw new DomainException($wp_post_type->get_error_message());
110
+		}
111
+		return $wp_post_type;
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * @param string $post_type          the actual post type name
117
-     * @param string $singular_name      a pre-internationalized string for the singular name of the objects
118
-     * @param string $plural_name        a pre-internationalized string for the plural name of the objects
119
-     * @param string $singular_slug
120
-     * @param string $plural_slug
121
-     * @param array  $override_arguments The default values set in this function will be overridden
122
-     *                                   by whatever you set in $override_arguments
123
-     * @return array
124
-     */
125
-    protected function prepareArguments(
126
-        $post_type,
127
-        $singular_name,
128
-        $plural_name,
129
-        $singular_slug,
130
-        $plural_slug,
131
-        array $override_arguments = array()
132
-    ) {
133
-        // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
134
-        $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
135
-        $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
136
-        $labels = $this->getLabels(
137
-            $singular_name,
138
-            $plural_name,
139
-            $singular_slug,
140
-            $plural_slug
141
-        );
142
-        // note the page_templates arg in the supports index is something specific to EE.
143
-        // WordPress doesn't actually have that in their register_post_type api.
144
-        $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug);
145
-        if ($override_arguments) {
146
-            if (isset($override_arguments['labels'])) {
147
-                $labels = array_merge($arguments['labels'], $override_arguments['labels']);
148
-            }
149
-            $arguments = array_merge($arguments, $override_arguments);
150
-            $arguments['labels'] = $labels;
151
-        }
152
-        return $arguments;
153
-    }
115
+	/**
116
+	 * @param string $post_type          the actual post type name
117
+	 * @param string $singular_name      a pre-internationalized string for the singular name of the objects
118
+	 * @param string $plural_name        a pre-internationalized string for the plural name of the objects
119
+	 * @param string $singular_slug
120
+	 * @param string $plural_slug
121
+	 * @param array  $override_arguments The default values set in this function will be overridden
122
+	 *                                   by whatever you set in $override_arguments
123
+	 * @return array
124
+	 */
125
+	protected function prepareArguments(
126
+		$post_type,
127
+		$singular_name,
128
+		$plural_name,
129
+		$singular_slug,
130
+		$plural_slug,
131
+		array $override_arguments = array()
132
+	) {
133
+		// verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
134
+		$singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
135
+		$plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
136
+		$labels = $this->getLabels(
137
+			$singular_name,
138
+			$plural_name,
139
+			$singular_slug,
140
+			$plural_slug
141
+		);
142
+		// note the page_templates arg in the supports index is something specific to EE.
143
+		// WordPress doesn't actually have that in their register_post_type api.
144
+		$arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug);
145
+		if ($override_arguments) {
146
+			if (isset($override_arguments['labels'])) {
147
+				$labels = array_merge($arguments['labels'], $override_arguments['labels']);
148
+			}
149
+			$arguments = array_merge($arguments, $override_arguments);
150
+			$arguments['labels'] = $labels;
151
+		}
152
+		return $arguments;
153
+	}
154 154
 
155 155
 
156
-    /**
157
-     * @param string $singular_name
158
-     * @param string $plural_name
159
-     * @param string $singular_slug
160
-     * @param string $plural_slug
161
-     * @return array
162
-     */
163
-    private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug)
164
-    {
165
-        return array(
166
-            'name'               => $plural_name,
167
-            'singular_name'      => $singular_name,
168
-            'singular_slug'      => $singular_slug,
169
-            'plural_slug'        => $plural_slug,
170
-            'add_new'            => sprintf(
171
-                esc_html_x('Add %s', 'Add Event', 'event_espresso'),
172
-                $singular_name
173
-            ),
174
-            'add_new_item'       => sprintf(
175
-                esc_html_x('Add New %s', 'Add New Event', 'event_espresso'),
176
-                $singular_name
177
-            ),
178
-            'edit_item'          => sprintf(
179
-                esc_html_x('Edit %s', 'Edit Event', 'event_espresso'),
180
-                $singular_name
181
-            ),
182
-            'new_item'           => sprintf(
183
-                esc_html_x('New %s', 'New Event', 'event_espresso'),
184
-                $singular_name
185
-            ),
186
-            'all_items'          => sprintf(
187
-                esc_html_x('All %s', 'All Events', 'event_espresso'),
188
-                $plural_name
189
-            ),
190
-            'view_item'          => sprintf(
191
-                esc_html_x('View %s', 'View Event', 'event_espresso'),
192
-                $singular_name
193
-            ),
194
-            'search_items'       => sprintf(
195
-                esc_html_x('Search %s', 'Search Events', 'event_espresso'),
196
-                $plural_name
197
-            ),
198
-            'not_found'          => sprintf(
199
-                esc_html_x('No %s found', 'No Events found', 'event_espresso'),
200
-                $plural_name
201
-            ),
202
-            'not_found_in_trash' => sprintf(
203
-                esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'),
204
-                $plural_name
205
-            ),
206
-            'parent_item_colon'  => '',
207
-            'menu_name'          => $plural_name,
208
-        );
209
-    }
156
+	/**
157
+	 * @param string $singular_name
158
+	 * @param string $plural_name
159
+	 * @param string $singular_slug
160
+	 * @param string $plural_slug
161
+	 * @return array
162
+	 */
163
+	private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug)
164
+	{
165
+		return array(
166
+			'name'               => $plural_name,
167
+			'singular_name'      => $singular_name,
168
+			'singular_slug'      => $singular_slug,
169
+			'plural_slug'        => $plural_slug,
170
+			'add_new'            => sprintf(
171
+				esc_html_x('Add %s', 'Add Event', 'event_espresso'),
172
+				$singular_name
173
+			),
174
+			'add_new_item'       => sprintf(
175
+				esc_html_x('Add New %s', 'Add New Event', 'event_espresso'),
176
+				$singular_name
177
+			),
178
+			'edit_item'          => sprintf(
179
+				esc_html_x('Edit %s', 'Edit Event', 'event_espresso'),
180
+				$singular_name
181
+			),
182
+			'new_item'           => sprintf(
183
+				esc_html_x('New %s', 'New Event', 'event_espresso'),
184
+				$singular_name
185
+			),
186
+			'all_items'          => sprintf(
187
+				esc_html_x('All %s', 'All Events', 'event_espresso'),
188
+				$plural_name
189
+			),
190
+			'view_item'          => sprintf(
191
+				esc_html_x('View %s', 'View Event', 'event_espresso'),
192
+				$singular_name
193
+			),
194
+			'search_items'       => sprintf(
195
+				esc_html_x('Search %s', 'Search Events', 'event_espresso'),
196
+				$plural_name
197
+			),
198
+			'not_found'          => sprintf(
199
+				esc_html_x('No %s found', 'No Events found', 'event_espresso'),
200
+				$plural_name
201
+			),
202
+			'not_found_in_trash' => sprintf(
203
+				esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'),
204
+				$plural_name
205
+			),
206
+			'parent_item_colon'  => '',
207
+			'menu_name'          => $plural_name,
208
+		);
209
+	}
210 210
 
211 211
 
212
-    /**
213
-     * @param array  $labels
214
-     * @param string $post_type
215
-     * @param string $plural_slug
216
-     * @return array
217
-     */
218
-    private function getDefaultArguments(array $labels, $post_type, $plural_slug)
219
-    {
220
-        return array(
221
-            'labels'             => $labels,
222
-            'public'             => true,
223
-            'publicly_queryable' => true,
224
-            'show_ui'            => false,
225
-            'show_ee_ui'         => true,
226
-            'show_in_menu'       => false,
227
-            'show_in_nav_menus'  => false,
228
-            'query_var'          => true,
229
-            'rewrite'            => apply_filters(
230
-                'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite',
231
-                // legacy filter applied for now,
232
-                // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
233
-                apply_filters(
234
-                    'FHEE__EE_Register_CPTs__register_CPT__rewrite',
235
-                    array('slug' => $plural_slug),
236
-                    $post_type
237
-                ),
238
-                $post_type,
239
-                $plural_slug
240
-            ),
241
-            'capability_type'    => 'post',
242
-            'map_meta_cap'       => true,
243
-            'has_archive'        => true,
244
-            'hierarchical'       => false,
245
-            'menu_position'      => null,
246
-            'supports'           => array(
247
-                'title',
248
-                'editor',
249
-                'author',
250
-                'thumbnail',
251
-                'excerpt',
252
-                'custom-fields',
253
-                'comments',
254
-            ),
255
-        );
256
-    }
212
+	/**
213
+	 * @param array  $labels
214
+	 * @param string $post_type
215
+	 * @param string $plural_slug
216
+	 * @return array
217
+	 */
218
+	private function getDefaultArguments(array $labels, $post_type, $plural_slug)
219
+	{
220
+		return array(
221
+			'labels'             => $labels,
222
+			'public'             => true,
223
+			'publicly_queryable' => true,
224
+			'show_ui'            => false,
225
+			'show_ee_ui'         => true,
226
+			'show_in_menu'       => false,
227
+			'show_in_nav_menus'  => false,
228
+			'query_var'          => true,
229
+			'rewrite'            => apply_filters(
230
+				'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite',
231
+				// legacy filter applied for now,
232
+				// later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
233
+				apply_filters(
234
+					'FHEE__EE_Register_CPTs__register_CPT__rewrite',
235
+					array('slug' => $plural_slug),
236
+					$post_type
237
+				),
238
+				$post_type,
239
+				$plural_slug
240
+			),
241
+			'capability_type'    => 'post',
242
+			'map_meta_cap'       => true,
243
+			'has_archive'        => true,
244
+			'hierarchical'       => false,
245
+			'menu_position'      => null,
246
+			'supports'           => array(
247
+				'title',
248
+				'editor',
249
+				'author',
250
+				'thumbnail',
251
+				'excerpt',
252
+				'custom-fields',
253
+				'comments',
254
+			),
255
+		);
256
+	}
257 257
 }
Please login to merge, or discard this patch.
core/services/collections/Collection.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      *
157 157
      * @access public
158 158
      * @param mixed $identifier
159
-     * @return mixed
159
+     * @return boolean
160 160
      */
161 161
     public function get($identifier)
162 162
     {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * advances pointer to the provided object
279 279
      *
280 280
      * @access public
281
-     * @param $object
281
+     * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepForm $object
282 282
      * @return boolean
283 283
      */
284 284
     public function setCurrentUsingObject($object)
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @see http://stackoverflow.com/a/8736013
318 318
      * @param $object
319
-     * @return boolean|int|string
319
+     * @return integer
320 320
      */
321 321
     public function indexOf($object)
322 322
     {
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -68,14 +68,14 @@  discard block
 block discarded – undo
68 68
     protected function setCollectionIdentifier()
69 69
     {
70 70
         // hash a few collection details
71
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
71
+        $identifier = md5(spl_object_hash($this).$this->collection_interface.time());
72 72
         // grab a few characters from the start, middle, and end of the hash
73 73
         $id = array();
74 74
         for ($x = 0; $x < 19; $x += 9) {
75 75
             $id[] = substr($identifier, $x, 3);
76 76
         }
77 77
         $identifier = basename(str_replace('\\', '/', get_class($this)));
78
-        $identifier .= '-' . strtoupper(implode('-', $id));
78
+        $identifier .= '-'.strtoupper(implode('-', $id));
79 79
         $this->collection_identifier = $identifier;
80 80
     }
81 81
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     protected function setCollectionInterface($collection_interface)
91 91
     {
92
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
92
+        if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) {
93 93
             throw new InvalidInterfaceException($collection_interface);
94 94
         }
95 95
         $this->collection_interface = $collection_interface;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function add($object, $identifier = null)
113 113
     {
114
-        if (! $object instanceof $this->collection_interface) {
114
+        if ( ! $object instanceof $this->collection_interface) {
115 115
             throw new InvalidEntityException($object, $this->collection_interface);
116 116
         }
117 117
         if ($this->contains($object)) {
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function indexOf($object)
324 324
     {
325
-        if (! $this->contains($object)) {
325
+        if ( ! $this->contains($object)) {
326 326
             return false;
327 327
         }
328 328
         foreach ($this as $index => $obj) {
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
             $remaining_objects = $this->slice($index, $this->count() - $index);
392 392
             foreach ($remaining_objects as $key => $remaining_object) {
393 393
                 // we need to grab the identifiers for each object and use them as keys
394
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
394
+                $remaining_objects[$remaining_object->getInfo()] = $remaining_object;
395 395
                 // and then remove the object from the current tracking array
396
-                unset($remaining_objects[ $key ]);
396
+                unset($remaining_objects[$key]);
397 397
                 // and then remove it from the Collection
398 398
                 $this->detach($remaining_object);
399 399
             }
@@ -417,17 +417,17 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public function insertAt($objects, $index)
419 419
     {
420
-        if (! is_array($objects)) {
420
+        if ( ! is_array($objects)) {
421 421
             $objects = array($objects);
422 422
         }
423 423
         // check to ensure that objects don't already exist in the collection
424 424
         foreach ($objects as $key => $object) {
425 425
             if ($this->contains($object)) {
426
-                unset($objects[ $key ]);
426
+                unset($objects[$key]);
427 427
             }
428 428
         }
429 429
         // do we have any objects left?
430
-        if (! $objects) {
430
+        if ( ! $objects) {
431 431
             return;
432 432
         }
433 433
         // detach any objects at or past this index
Please login to merge, or discard this patch.
Indentation   +466 added lines, -466 removed lines patch added patch discarded remove patch
@@ -19,470 +19,470 @@
 block discarded – undo
19 19
 class Collection extends SplObjectStorage implements CollectionInterface
20 20
 {
21 21
 
22
-    /**
23
-     * a unique string for identifying this collection
24
-     *
25
-     * @type string $collection_identifier
26
-     */
27
-    protected $collection_identifier;
28
-
29
-
30
-    /**
31
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
32
-     * this should be set from within the child class constructor
33
-     *
34
-     * @type string $interface
35
-     */
36
-    protected $collection_interface;
37
-
38
-
39
-    /**
40
-     * Collection constructor
41
-     *
42
-     * @param string $collection_interface
43
-     * @throws InvalidInterfaceException
44
-     */
45
-    public function __construct($collection_interface)
46
-    {
47
-        $this->setCollectionInterface($collection_interface);
48
-        $this->setCollectionIdentifier();
49
-    }
50
-
51
-
52
-    /**
53
-     * @return string
54
-     */
55
-    public function collectionIdentifier()
56
-    {
57
-        return $this->collection_identifier;
58
-    }
59
-
60
-
61
-    /**
62
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
63
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
64
-     *
65
-     * @return void
66
-     */
67
-    protected function setCollectionIdentifier()
68
-    {
69
-        // hash a few collection details
70
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
71
-        // grab a few characters from the start, middle, and end of the hash
72
-        $id = array();
73
-        for ($x = 0; $x < 19; $x += 9) {
74
-            $id[] = substr($identifier, $x, 3);
75
-        }
76
-        $identifier = basename(str_replace('\\', '/', get_class($this)));
77
-        $identifier .= '-' . strtoupper(implode('-', $id));
78
-        $this->collection_identifier = $identifier;
79
-    }
80
-
81
-
82
-    /**
83
-     * setCollectionInterface
84
-     *
85
-     * @param  string $collection_interface
86
-     * @throws InvalidInterfaceException
87
-     */
88
-    protected function setCollectionInterface($collection_interface)
89
-    {
90
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
91
-            throw new InvalidInterfaceException($collection_interface);
92
-        }
93
-        $this->collection_interface = $collection_interface;
94
-    }
95
-
96
-
97
-    /**
98
-     * add
99
-     * attaches an object to the Collection
100
-     * and sets any supplied data associated with the current iterator entry
101
-     * by calling EE_Object_Collection::set_identifier()
102
-     *
103
-     * @param        $object
104
-     * @param  mixed $identifier
105
-     * @return bool
106
-     * @throws InvalidEntityException
107
-     * @throws DuplicateCollectionIdentifierException
108
-     */
109
-    public function add($object, $identifier = null)
110
-    {
111
-        if (! $object instanceof $this->collection_interface) {
112
-            throw new InvalidEntityException($object, $this->collection_interface);
113
-        }
114
-        if ($this->contains($object)) {
115
-            throw new DuplicateCollectionIdentifierException($identifier);
116
-        }
117
-        $this->attach($object);
118
-        $this->setIdentifier($object, $identifier);
119
-        return $this->contains($object);
120
-    }
121
-
122
-
123
-    /**
124
-     * setIdentifier
125
-     * Sets the data associated with an object in the Collection
126
-     * if no $identifier is supplied, then the spl_object_hash() is used
127
-     *
128
-     * @access public
129
-     * @param        $object
130
-     * @param  mixed $identifier
131
-     * @return bool
132
-     */
133
-    public function setIdentifier($object, $identifier = null)
134
-    {
135
-        $identifier = ! empty($identifier)
136
-            ? $identifier
137
-            : spl_object_hash($object);
138
-        $this->rewind();
139
-        while ($this->valid()) {
140
-            if ($object === $this->current()) {
141
-                $this->setInfo($identifier);
142
-                $this->rewind();
143
-                return true;
144
-            }
145
-            $this->next();
146
-        }
147
-        return false;
148
-    }
149
-
150
-
151
-    /**
152
-     * get
153
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
154
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
155
-     *
156
-     * @access public
157
-     * @param mixed $identifier
158
-     * @return mixed
159
-     */
160
-    public function get($identifier)
161
-    {
162
-        $this->rewind();
163
-        while ($this->valid()) {
164
-            if ($identifier === $this->getInfo()) {
165
-                $object = $this->current();
166
-                $this->rewind();
167
-                return $object;
168
-            }
169
-            $this->next();
170
-        }
171
-        return null;
172
-    }
173
-
174
-
175
-    /**
176
-     * has
177
-     * returns TRUE or FALSE
178
-     * depending on whether the object is within the Collection
179
-     * based on the supplied $identifier
180
-     *
181
-     * @access public
182
-     * @param  mixed $identifier
183
-     * @return bool
184
-     */
185
-    public function has($identifier)
186
-    {
187
-        $this->rewind();
188
-        while ($this->valid()) {
189
-            if ($identifier === $this->getInfo()) {
190
-                $this->rewind();
191
-                return true;
192
-            }
193
-            $this->next();
194
-        }
195
-        return false;
196
-    }
197
-
198
-
199
-    /**
200
-     * hasObject
201
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
202
-     *
203
-     * @access public
204
-     * @param $object
205
-     * @return bool
206
-     */
207
-    public function hasObject($object)
208
-    {
209
-        return $this->contains($object);
210
-    }
211
-
212
-
213
-    /**
214
-     * hasObjects
215
-     * returns true if there are objects within the Collection, and false if it is empty
216
-     *
217
-     * @access public
218
-     * @return bool
219
-     */
220
-    public function hasObjects()
221
-    {
222
-        return $this->count() !== 0;
223
-    }
224
-
225
-
226
-    /**
227
-     * isEmpty
228
-     * returns true if there are no objects within the Collection, and false if there are
229
-     *
230
-     * @access public
231
-     * @return bool
232
-     */
233
-    public function isEmpty()
234
-    {
235
-        return $this->count() === 0;
236
-    }
237
-
238
-
239
-    /**
240
-     * remove
241
-     * detaches an object from the Collection
242
-     *
243
-     * @access public
244
-     * @param $object
245
-     * @return bool
246
-     */
247
-    public function remove($object)
248
-    {
249
-        $this->detach($object);
250
-        return true;
251
-    }
252
-
253
-
254
-    /**
255
-     * setCurrent
256
-     * advances pointer to the object whose identifier matches that which was provided
257
-     *
258
-     * @access public
259
-     * @param mixed $identifier
260
-     * @return boolean
261
-     */
262
-    public function setCurrent($identifier)
263
-    {
264
-        $this->rewind();
265
-        while ($this->valid()) {
266
-            if ($identifier === $this->getInfo()) {
267
-                return true;
268
-            }
269
-            $this->next();
270
-        }
271
-        return false;
272
-    }
273
-
274
-
275
-    /**
276
-     * setCurrentUsingObject
277
-     * advances pointer to the provided object
278
-     *
279
-     * @access public
280
-     * @param $object
281
-     * @return boolean
282
-     */
283
-    public function setCurrentUsingObject($object)
284
-    {
285
-        $this->rewind();
286
-        while ($this->valid()) {
287
-            if ($this->current() === $object) {
288
-                return true;
289
-            }
290
-            $this->next();
291
-        }
292
-        return false;
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns the object occupying the index before the current object,
298
-     * unless this is already the first object, in which case it just returns the first object
299
-     *
300
-     * @return mixed
301
-     */
302
-    public function previous()
303
-    {
304
-        $index = $this->indexOf($this->current());
305
-        if ($index === 0) {
306
-            return $this->current();
307
-        }
308
-        $index--;
309
-        return $this->objectAtIndex($index);
310
-    }
311
-
312
-
313
-    /**
314
-     * Returns the index of a given object, or false if not found
315
-     *
316
-     * @see http://stackoverflow.com/a/8736013
317
-     * @param $object
318
-     * @return boolean|int|string
319
-     */
320
-    public function indexOf($object)
321
-    {
322
-        if (! $this->contains($object)) {
323
-            return false;
324
-        }
325
-        foreach ($this as $index => $obj) {
326
-            if ($obj === $object) {
327
-                return $index;
328
-            }
329
-        }
330
-        return false;
331
-    }
332
-
333
-
334
-    /**
335
-     * Returns the object at the given index
336
-     *
337
-     * @see http://stackoverflow.com/a/8736013
338
-     * @param int $index
339
-     * @return mixed
340
-     */
341
-    public function objectAtIndex($index)
342
-    {
343
-        $iterator = new LimitIterator($this, $index, 1);
344
-        $iterator->rewind();
345
-        return $iterator->current();
346
-    }
347
-
348
-
349
-    /**
350
-     * Returns the sequence of objects as specified by the offset and length
351
-     *
352
-     * @see http://stackoverflow.com/a/8736013
353
-     * @param int $offset
354
-     * @param int $length
355
-     * @return array
356
-     */
357
-    public function slice($offset, $length)
358
-    {
359
-        $slice = array();
360
-        $iterator = new LimitIterator($this, $offset, $length);
361
-        foreach ($iterator as $object) {
362
-            $slice[] = $object;
363
-        }
364
-        return $slice;
365
-    }
366
-
367
-
368
-    /**
369
-     * Inserts an object at a certain point
370
-     *
371
-     * @see http://stackoverflow.com/a/8736013
372
-     * @param mixed $object A single object
373
-     * @param int   $index
374
-     * @param mixed $identifier
375
-     * @return bool
376
-     * @throws DuplicateCollectionIdentifierException
377
-     * @throws InvalidEntityException
378
-     */
379
-    public function insertObjectAt($object, $index, $identifier = null)
380
-    {
381
-        // check to ensure that objects don't already exist in the collection
382
-        if ($this->has($identifier)) {
383
-            throw new DuplicateCollectionIdentifierException($identifier);
384
-        }
385
-        // detach any objects at or past this index
386
-        $remaining_objects = array();
387
-        if ($index < $this->count()) {
388
-            $remaining_objects = $this->slice($index, $this->count() - $index);
389
-            foreach ($remaining_objects as $key => $remaining_object) {
390
-                // we need to grab the identifiers for each object and use them as keys
391
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
392
-                // and then remove the object from the current tracking array
393
-                unset($remaining_objects[ $key ]);
394
-                // and then remove it from the Collection
395
-                $this->detach($remaining_object);
396
-            }
397
-        }
398
-        // add the new object we're splicing in
399
-        $this->add($object, $identifier);
400
-        // attach the objects we previously detached
401
-        foreach ($remaining_objects as $key => $remaining_object) {
402
-            $this->add($remaining_object, $key);
403
-        }
404
-        return $this->contains($object);
405
-    }
406
-
407
-
408
-    /**
409
-     * Inserts an object (or an array of objects) at a certain point
410
-     *
411
-     * @see http://stackoverflow.com/a/8736013
412
-     * @param mixed $objects A single object or an array of objects
413
-     * @param int   $index
414
-     */
415
-    public function insertAt($objects, $index)
416
-    {
417
-        if (! is_array($objects)) {
418
-            $objects = array($objects);
419
-        }
420
-        // check to ensure that objects don't already exist in the collection
421
-        foreach ($objects as $key => $object) {
422
-            if ($this->contains($object)) {
423
-                unset($objects[ $key ]);
424
-            }
425
-        }
426
-        // do we have any objects left?
427
-        if (! $objects) {
428
-            return;
429
-        }
430
-        // detach any objects at or past this index
431
-        $remaining = array();
432
-        if ($index < $this->count()) {
433
-            $remaining = $this->slice($index, $this->count() - $index);
434
-            foreach ($remaining as $object) {
435
-                $this->detach($object);
436
-            }
437
-        }
438
-        // add the new objects we're splicing in
439
-        foreach ($objects as $object) {
440
-            $this->attach($object);
441
-        }
442
-        // attach the objects we previously detached
443
-        foreach ($remaining as $object) {
444
-            $this->attach($object);
445
-        }
446
-    }
447
-
448
-
449
-    /**
450
-     * Removes the object at the given index
451
-     *
452
-     * @see http://stackoverflow.com/a/8736013
453
-     * @param int $index
454
-     */
455
-    public function removeAt($index)
456
-    {
457
-        $this->detach($this->objectAtIndex($index));
458
-    }
459
-
460
-
461
-    /**
462
-     * detaches ALL objects from the Collection
463
-     */
464
-    public function detachAll()
465
-    {
466
-        $this->rewind();
467
-        while ($this->valid()) {
468
-            $object = $this->current();
469
-            $this->next();
470
-            $this->detach($object);
471
-        }
472
-    }
473
-
474
-
475
-    /**
476
-     * unsets and detaches ALL objects from the Collection
477
-     */
478
-    public function trashAndDetachAll()
479
-    {
480
-        $this->rewind();
481
-        while ($this->valid()) {
482
-            $object = $this->current();
483
-            $this->next();
484
-            $this->detach($object);
485
-            unset($object);
486
-        }
487
-    }
22
+	/**
23
+	 * a unique string for identifying this collection
24
+	 *
25
+	 * @type string $collection_identifier
26
+	 */
27
+	protected $collection_identifier;
28
+
29
+
30
+	/**
31
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
32
+	 * this should be set from within the child class constructor
33
+	 *
34
+	 * @type string $interface
35
+	 */
36
+	protected $collection_interface;
37
+
38
+
39
+	/**
40
+	 * Collection constructor
41
+	 *
42
+	 * @param string $collection_interface
43
+	 * @throws InvalidInterfaceException
44
+	 */
45
+	public function __construct($collection_interface)
46
+	{
47
+		$this->setCollectionInterface($collection_interface);
48
+		$this->setCollectionIdentifier();
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return string
54
+	 */
55
+	public function collectionIdentifier()
56
+	{
57
+		return $this->collection_identifier;
58
+	}
59
+
60
+
61
+	/**
62
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
63
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
64
+	 *
65
+	 * @return void
66
+	 */
67
+	protected function setCollectionIdentifier()
68
+	{
69
+		// hash a few collection details
70
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
71
+		// grab a few characters from the start, middle, and end of the hash
72
+		$id = array();
73
+		for ($x = 0; $x < 19; $x += 9) {
74
+			$id[] = substr($identifier, $x, 3);
75
+		}
76
+		$identifier = basename(str_replace('\\', '/', get_class($this)));
77
+		$identifier .= '-' . strtoupper(implode('-', $id));
78
+		$this->collection_identifier = $identifier;
79
+	}
80
+
81
+
82
+	/**
83
+	 * setCollectionInterface
84
+	 *
85
+	 * @param  string $collection_interface
86
+	 * @throws InvalidInterfaceException
87
+	 */
88
+	protected function setCollectionInterface($collection_interface)
89
+	{
90
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
91
+			throw new InvalidInterfaceException($collection_interface);
92
+		}
93
+		$this->collection_interface = $collection_interface;
94
+	}
95
+
96
+
97
+	/**
98
+	 * add
99
+	 * attaches an object to the Collection
100
+	 * and sets any supplied data associated with the current iterator entry
101
+	 * by calling EE_Object_Collection::set_identifier()
102
+	 *
103
+	 * @param        $object
104
+	 * @param  mixed $identifier
105
+	 * @return bool
106
+	 * @throws InvalidEntityException
107
+	 * @throws DuplicateCollectionIdentifierException
108
+	 */
109
+	public function add($object, $identifier = null)
110
+	{
111
+		if (! $object instanceof $this->collection_interface) {
112
+			throw new InvalidEntityException($object, $this->collection_interface);
113
+		}
114
+		if ($this->contains($object)) {
115
+			throw new DuplicateCollectionIdentifierException($identifier);
116
+		}
117
+		$this->attach($object);
118
+		$this->setIdentifier($object, $identifier);
119
+		return $this->contains($object);
120
+	}
121
+
122
+
123
+	/**
124
+	 * setIdentifier
125
+	 * Sets the data associated with an object in the Collection
126
+	 * if no $identifier is supplied, then the spl_object_hash() is used
127
+	 *
128
+	 * @access public
129
+	 * @param        $object
130
+	 * @param  mixed $identifier
131
+	 * @return bool
132
+	 */
133
+	public function setIdentifier($object, $identifier = null)
134
+	{
135
+		$identifier = ! empty($identifier)
136
+			? $identifier
137
+			: spl_object_hash($object);
138
+		$this->rewind();
139
+		while ($this->valid()) {
140
+			if ($object === $this->current()) {
141
+				$this->setInfo($identifier);
142
+				$this->rewind();
143
+				return true;
144
+			}
145
+			$this->next();
146
+		}
147
+		return false;
148
+	}
149
+
150
+
151
+	/**
152
+	 * get
153
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
154
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
155
+	 *
156
+	 * @access public
157
+	 * @param mixed $identifier
158
+	 * @return mixed
159
+	 */
160
+	public function get($identifier)
161
+	{
162
+		$this->rewind();
163
+		while ($this->valid()) {
164
+			if ($identifier === $this->getInfo()) {
165
+				$object = $this->current();
166
+				$this->rewind();
167
+				return $object;
168
+			}
169
+			$this->next();
170
+		}
171
+		return null;
172
+	}
173
+
174
+
175
+	/**
176
+	 * has
177
+	 * returns TRUE or FALSE
178
+	 * depending on whether the object is within the Collection
179
+	 * based on the supplied $identifier
180
+	 *
181
+	 * @access public
182
+	 * @param  mixed $identifier
183
+	 * @return bool
184
+	 */
185
+	public function has($identifier)
186
+	{
187
+		$this->rewind();
188
+		while ($this->valid()) {
189
+			if ($identifier === $this->getInfo()) {
190
+				$this->rewind();
191
+				return true;
192
+			}
193
+			$this->next();
194
+		}
195
+		return false;
196
+	}
197
+
198
+
199
+	/**
200
+	 * hasObject
201
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
202
+	 *
203
+	 * @access public
204
+	 * @param $object
205
+	 * @return bool
206
+	 */
207
+	public function hasObject($object)
208
+	{
209
+		return $this->contains($object);
210
+	}
211
+
212
+
213
+	/**
214
+	 * hasObjects
215
+	 * returns true if there are objects within the Collection, and false if it is empty
216
+	 *
217
+	 * @access public
218
+	 * @return bool
219
+	 */
220
+	public function hasObjects()
221
+	{
222
+		return $this->count() !== 0;
223
+	}
224
+
225
+
226
+	/**
227
+	 * isEmpty
228
+	 * returns true if there are no objects within the Collection, and false if there are
229
+	 *
230
+	 * @access public
231
+	 * @return bool
232
+	 */
233
+	public function isEmpty()
234
+	{
235
+		return $this->count() === 0;
236
+	}
237
+
238
+
239
+	/**
240
+	 * remove
241
+	 * detaches an object from the Collection
242
+	 *
243
+	 * @access public
244
+	 * @param $object
245
+	 * @return bool
246
+	 */
247
+	public function remove($object)
248
+	{
249
+		$this->detach($object);
250
+		return true;
251
+	}
252
+
253
+
254
+	/**
255
+	 * setCurrent
256
+	 * advances pointer to the object whose identifier matches that which was provided
257
+	 *
258
+	 * @access public
259
+	 * @param mixed $identifier
260
+	 * @return boolean
261
+	 */
262
+	public function setCurrent($identifier)
263
+	{
264
+		$this->rewind();
265
+		while ($this->valid()) {
266
+			if ($identifier === $this->getInfo()) {
267
+				return true;
268
+			}
269
+			$this->next();
270
+		}
271
+		return false;
272
+	}
273
+
274
+
275
+	/**
276
+	 * setCurrentUsingObject
277
+	 * advances pointer to the provided object
278
+	 *
279
+	 * @access public
280
+	 * @param $object
281
+	 * @return boolean
282
+	 */
283
+	public function setCurrentUsingObject($object)
284
+	{
285
+		$this->rewind();
286
+		while ($this->valid()) {
287
+			if ($this->current() === $object) {
288
+				return true;
289
+			}
290
+			$this->next();
291
+		}
292
+		return false;
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns the object occupying the index before the current object,
298
+	 * unless this is already the first object, in which case it just returns the first object
299
+	 *
300
+	 * @return mixed
301
+	 */
302
+	public function previous()
303
+	{
304
+		$index = $this->indexOf($this->current());
305
+		if ($index === 0) {
306
+			return $this->current();
307
+		}
308
+		$index--;
309
+		return $this->objectAtIndex($index);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Returns the index of a given object, or false if not found
315
+	 *
316
+	 * @see http://stackoverflow.com/a/8736013
317
+	 * @param $object
318
+	 * @return boolean|int|string
319
+	 */
320
+	public function indexOf($object)
321
+	{
322
+		if (! $this->contains($object)) {
323
+			return false;
324
+		}
325
+		foreach ($this as $index => $obj) {
326
+			if ($obj === $object) {
327
+				return $index;
328
+			}
329
+		}
330
+		return false;
331
+	}
332
+
333
+
334
+	/**
335
+	 * Returns the object at the given index
336
+	 *
337
+	 * @see http://stackoverflow.com/a/8736013
338
+	 * @param int $index
339
+	 * @return mixed
340
+	 */
341
+	public function objectAtIndex($index)
342
+	{
343
+		$iterator = new LimitIterator($this, $index, 1);
344
+		$iterator->rewind();
345
+		return $iterator->current();
346
+	}
347
+
348
+
349
+	/**
350
+	 * Returns the sequence of objects as specified by the offset and length
351
+	 *
352
+	 * @see http://stackoverflow.com/a/8736013
353
+	 * @param int $offset
354
+	 * @param int $length
355
+	 * @return array
356
+	 */
357
+	public function slice($offset, $length)
358
+	{
359
+		$slice = array();
360
+		$iterator = new LimitIterator($this, $offset, $length);
361
+		foreach ($iterator as $object) {
362
+			$slice[] = $object;
363
+		}
364
+		return $slice;
365
+	}
366
+
367
+
368
+	/**
369
+	 * Inserts an object at a certain point
370
+	 *
371
+	 * @see http://stackoverflow.com/a/8736013
372
+	 * @param mixed $object A single object
373
+	 * @param int   $index
374
+	 * @param mixed $identifier
375
+	 * @return bool
376
+	 * @throws DuplicateCollectionIdentifierException
377
+	 * @throws InvalidEntityException
378
+	 */
379
+	public function insertObjectAt($object, $index, $identifier = null)
380
+	{
381
+		// check to ensure that objects don't already exist in the collection
382
+		if ($this->has($identifier)) {
383
+			throw new DuplicateCollectionIdentifierException($identifier);
384
+		}
385
+		// detach any objects at or past this index
386
+		$remaining_objects = array();
387
+		if ($index < $this->count()) {
388
+			$remaining_objects = $this->slice($index, $this->count() - $index);
389
+			foreach ($remaining_objects as $key => $remaining_object) {
390
+				// we need to grab the identifiers for each object and use them as keys
391
+				$remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
392
+				// and then remove the object from the current tracking array
393
+				unset($remaining_objects[ $key ]);
394
+				// and then remove it from the Collection
395
+				$this->detach($remaining_object);
396
+			}
397
+		}
398
+		// add the new object we're splicing in
399
+		$this->add($object, $identifier);
400
+		// attach the objects we previously detached
401
+		foreach ($remaining_objects as $key => $remaining_object) {
402
+			$this->add($remaining_object, $key);
403
+		}
404
+		return $this->contains($object);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Inserts an object (or an array of objects) at a certain point
410
+	 *
411
+	 * @see http://stackoverflow.com/a/8736013
412
+	 * @param mixed $objects A single object or an array of objects
413
+	 * @param int   $index
414
+	 */
415
+	public function insertAt($objects, $index)
416
+	{
417
+		if (! is_array($objects)) {
418
+			$objects = array($objects);
419
+		}
420
+		// check to ensure that objects don't already exist in the collection
421
+		foreach ($objects as $key => $object) {
422
+			if ($this->contains($object)) {
423
+				unset($objects[ $key ]);
424
+			}
425
+		}
426
+		// do we have any objects left?
427
+		if (! $objects) {
428
+			return;
429
+		}
430
+		// detach any objects at or past this index
431
+		$remaining = array();
432
+		if ($index < $this->count()) {
433
+			$remaining = $this->slice($index, $this->count() - $index);
434
+			foreach ($remaining as $object) {
435
+				$this->detach($object);
436
+			}
437
+		}
438
+		// add the new objects we're splicing in
439
+		foreach ($objects as $object) {
440
+			$this->attach($object);
441
+		}
442
+		// attach the objects we previously detached
443
+		foreach ($remaining as $object) {
444
+			$this->attach($object);
445
+		}
446
+	}
447
+
448
+
449
+	/**
450
+	 * Removes the object at the given index
451
+	 *
452
+	 * @see http://stackoverflow.com/a/8736013
453
+	 * @param int $index
454
+	 */
455
+	public function removeAt($index)
456
+	{
457
+		$this->detach($this->objectAtIndex($index));
458
+	}
459
+
460
+
461
+	/**
462
+	 * detaches ALL objects from the Collection
463
+	 */
464
+	public function detachAll()
465
+	{
466
+		$this->rewind();
467
+		while ($this->valid()) {
468
+			$object = $this->current();
469
+			$this->next();
470
+			$this->detach($object);
471
+		}
472
+	}
473
+
474
+
475
+	/**
476
+	 * unsets and detaches ALL objects from the Collection
477
+	 */
478
+	public function trashAndDetachAll()
479
+	{
480
+		$this->rewind();
481
+		while ($this->valid()) {
482
+			$object = $this->current();
483
+			$this->next();
484
+			$this->detach($object);
485
+			unset($object);
486
+		}
487
+	}
488 488
 }
Please login to merge, or discard this patch.
core/services/collections/InvalidCollectionIdentifierException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@
 block discarded – undo
16 16
 class InvalidCollectionIdentifierException extends OutOfBoundsException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidCollectionIdentifierException constructor.
21
-     *
22
-     * @param                $identifier
23
-     * @param string         $message
24
-     * @param int            $code
25
-     * @param Exception|null $previous
26
-     */
27
-    public function __construct($identifier, $message = '', $code = 0, Exception $previous = null)
28
-    {
29
-        if (empty($message)) {
30
-            $message = sprintf(
31
-                __(
32
-                    'The supplied identifier "%1$s" does not exist within this collection. 
19
+	/**
20
+	 * InvalidCollectionIdentifierException constructor.
21
+	 *
22
+	 * @param                $identifier
23
+	 * @param string         $message
24
+	 * @param int            $code
25
+	 * @param Exception|null $previous
26
+	 */
27
+	public function __construct($identifier, $message = '', $code = 0, Exception $previous = null)
28
+	{
29
+		if (empty($message)) {
30
+			$message = sprintf(
31
+				__(
32
+					'The supplied identifier "%1$s" does not exist within this collection. 
33 33
                     You may need to delay adding this asset until the required dependency has been added.',
34
-                    'event_espresso'
35
-                ),
36
-                $identifier
37
-            );
38
-        }
39
-        parent::__construct($message, $code, $previous);
40
-    }
34
+					'event_espresso'
35
+				),
36
+				$identifier
37
+			);
38
+		}
39
+		parent::__construct($message, $code, $previous);
40
+	}
41 41
 }
Please login to merge, or discard this patch.
core/services/collections/DuplicateCollectionIdentifierException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 block discarded – undo
16 16
 class DuplicateCollectionIdentifierException extends OutOfRangeException
17 17
 {
18 18
 
19
-    /**
20
-     * DuplicateCollectionIdentifierException constructor.
21
-     *
22
-     * @param                $identifier
23
-     * @param string         $message
24
-     * @param int            $code
25
-     * @param Exception|null $previous
26
-     */
27
-    public function __construct($identifier, $message = '', $code = 0, Exception $previous = null)
28
-    {
29
-        if (empty($message)) {
30
-            $message = sprintf(
31
-                __(
32
-                    'The supplied identifier "%1$s" already exists within this collection.',
33
-                    'event_espresso'
34
-                ),
35
-                $identifier
36
-            );
37
-        }
38
-        parent::__construct($message, $code, $previous);
39
-    }
19
+	/**
20
+	 * DuplicateCollectionIdentifierException constructor.
21
+	 *
22
+	 * @param                $identifier
23
+	 * @param string         $message
24
+	 * @param int            $code
25
+	 * @param Exception|null $previous
26
+	 */
27
+	public function __construct($identifier, $message = '', $code = 0, Exception $previous = null)
28
+	{
29
+		if (empty($message)) {
30
+			$message = sprintf(
31
+				__(
32
+					'The supplied identifier "%1$s" already exists within this collection.',
33
+					'event_espresso'
34
+				),
35
+				$identifier
36
+			);
37
+		}
38
+		parent::__construct($message, $code, $previous);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -21,86 +21,86 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since $VID:$
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since $VID:$
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since $VID:$
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since $VID:$
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since $VID:$
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since $VID:$
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * @param $type
67
-     * @return array
68
-     * @since $VID:$
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
65
+	/**
66
+	 * @param $type
67
+	 * @return array
68
+	 * @since $VID:$
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since $VID:$
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since $VID:$
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
core/services/assets/AssetManagerInterface.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,71 +20,71 @@
 block discarded – undo
20 20
 interface AssetManagerInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @return ManifestFile
25
-     * @throws DuplicateCollectionIdentifierException
26
-     * @throws InvalidDataTypeException
27
-     * @throws InvalidEntityException
28
-     * @since $VID:$
29
-     */
30
-    public function addManifestFile();
23
+	/**
24
+	 * @return ManifestFile
25
+	 * @throws DuplicateCollectionIdentifierException
26
+	 * @throws InvalidDataTypeException
27
+	 * @throws InvalidEntityException
28
+	 * @since $VID:$
29
+	 */
30
+	public function addManifestFile();
31 31
 
32 32
 
33
-    /**
34
-     * @return ManifestFile[]
35
-     * @since $VID:$
36
-     */
37
-    public function getManifestFile();
33
+	/**
34
+	 * @return ManifestFile[]
35
+	 * @since $VID:$
36
+	 */
37
+	public function getManifestFile();
38 38
 
39 39
 
40
-    /**
41
-     * @param string $handle
42
-     * @param string $source
43
-     * @param array  $dependencies
44
-     * @param bool   $load_in_footer
45
-     * @return JavascriptAsset
46
-     * @throws DuplicateCollectionIdentifierException
47
-     * @throws InvalidDataTypeException
48
-     * @throws InvalidEntityException
49
-     * @since $VID:$
50
-     */
51
-    public function addJavascript(
52
-        $handle,
53
-        $source,
54
-        array $dependencies = array(),
55
-        $load_in_footer = true
56
-    );
40
+	/**
41
+	 * @param string $handle
42
+	 * @param string $source
43
+	 * @param array  $dependencies
44
+	 * @param bool   $load_in_footer
45
+	 * @return JavascriptAsset
46
+	 * @throws DuplicateCollectionIdentifierException
47
+	 * @throws InvalidDataTypeException
48
+	 * @throws InvalidEntityException
49
+	 * @since $VID:$
50
+	 */
51
+	public function addJavascript(
52
+		$handle,
53
+		$source,
54
+		array $dependencies = array(),
55
+		$load_in_footer = true
56
+	);
57 57
 
58 58
 
59
-    /**
60
-     * @return JavascriptAsset[]
61
-     * @since $VID:$
62
-     */
63
-    public function getJavascriptAssets();
59
+	/**
60
+	 * @return JavascriptAsset[]
61
+	 * @since $VID:$
62
+	 */
63
+	public function getJavascriptAssets();
64 64
 
65 65
 
66
-    /**
67
-     * @param string $handle
68
-     * @param string $source
69
-     * @param array  $dependencies
70
-     * @param string $media
71
-     * @return StylesheetAsset
72
-     * @throws DuplicateCollectionIdentifierException
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidEntityException
75
-     * @since $VID:$
76
-     */
77
-    public function addStylesheet(
78
-        $handle,
79
-        $source,
80
-        array $dependencies = array(),
81
-        $media = 'all'
82
-    );
66
+	/**
67
+	 * @param string $handle
68
+	 * @param string $source
69
+	 * @param array  $dependencies
70
+	 * @param string $media
71
+	 * @return StylesheetAsset
72
+	 * @throws DuplicateCollectionIdentifierException
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidEntityException
75
+	 * @since $VID:$
76
+	 */
77
+	public function addStylesheet(
78
+		$handle,
79
+		$source,
80
+		array $dependencies = array(),
81
+		$media = 'all'
82
+	);
83 83
 
84 84
 
85
-    /**
86
-     * @return StylesheetAsset[]
87
-     * @since $VID:$
88
-     */
89
-    public function getStylesheetAssets();
85
+	/**
86
+	 * @return StylesheetAsset[]
87
+	 * @since $VID:$
88
+	 */
89
+	public function getStylesheetAssets();
90 90
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidIdentifierException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@
 block discarded – undo
16 16
 class InvalidIdentifierException extends InvalidArgumentException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidIdentifierException constructor.
21
-     *
22
-     * @param string     $actual   the identifier that was supplied
23
-     * @param string     $expected example of an acceptable identifier
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 identifier "%1$s" is invalid. A value like "%2$s" was expected.',
34
-                    'event_espresso'
35
-                ),
36
-                $actual,
37
-                $expected
38
-            );
39
-        }
40
-        parent::__construct($message, $code, $previous);
41
-    }
19
+	/**
20
+	 * InvalidIdentifierException constructor.
21
+	 *
22
+	 * @param string     $actual   the identifier that was supplied
23
+	 * @param string     $expected example of an acceptable identifier
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 identifier "%1$s" is invalid. A value like "%2$s" was expected.',
34
+					'event_espresso'
35
+				),
36
+				$actual,
37
+				$expected
38
+			);
39
+		}
40
+		parent::__construct($message, $code, $previous);
41
+	}
42 42
 }
43 43
 // Location: core/exceptions/InvalidIdentifierException.php
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             //js.api
176 176
             $this->addJavascript(
177 177
                 CoreAssetManager::JS_HANDLE_EE_JS_API,
178
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
178
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
179 179
                 array(
180 180
                     CoreAssetManager::JS_HANDLE_UNDERSCORE,
181 181
                     CoreAssetManager::JS_HANDLE_EE_JS_CORE
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 
188 188
         $this->addJavascript(
189 189
             CoreAssetManager::JS_HANDLE_EE_CORE,
190
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
190
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
191 191
             array(CoreAssetManager::JS_HANDLE_JQUERY)
192 192
         )
193 193
         ->setLocalizationCallback(
194
-            function () {
194
+            function() {
195 195
                 wp_localize_script(
196 196
                     CoreAssetManager::JS_HANDLE_EE_CORE,
197 197
                     CoreAssetManager::JS_HANDLE_EE_I18N,
@@ -213,16 +213,16 @@  discard block
 block discarded – undo
213 213
         if ($this->template_config->enable_default_style && ! is_admin()) {
214 214
             $this->addStylesheet(
215 215
                 CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
216
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
216
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
217 217
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
218
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
218
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
219 219
                 array('dashicons')
220 220
             );
221 221
             //Load custom style sheet if available
222 222
             if ($this->template_config->custom_style_sheet !== null) {
223 223
                 $this->addStylesheet(
224 224
                     CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
225
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
225
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
226 226
                     array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
227 227
                 );
228 228
             }
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
     {
243 243
         $this->addJavascript(
244 244
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
245
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
245
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
246 246
             array(CoreAssetManager::JS_HANDLE_JQUERY)
247 247
         )
248 248
         ->setVersion('1.15.0');
249 249
 
250 250
         $this->addJavascript(
251 251
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
252
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
252
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
253 253
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
254 254
         )
255 255
         ->setVersion('1.15.0');
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         // @link http://josscrowcroft.github.io/accounting.js/
271 271
         $this->addJavascript(
272 272
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
273
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
273
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
274 274
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
275 275
         )
276 276
         ->setVersion('0.3.2');
@@ -278,11 +278,11 @@  discard block
 block discarded – undo
278 278
         $currency_config = $this->currency_config;
279 279
         $this->addJavascript(
280 280
             CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
281
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
281
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
282 282
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
283 283
         )
284 284
         ->setLocalizationCallback(
285
-            function () use ($currency_config) {
285
+            function() use ($currency_config) {
286 286
                  wp_localize_script(
287 287
                      CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
288 288
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -27,330 +27,330 @@
 block discarded – undo
27 27
 class CoreAssetManager extends AssetManager
28 28
 {
29 29
 
30
-    // WordPress core / Third party JS asset handles
31
-    const JS_HANDLE_JQUERY                = 'jquery';
32
-
33
-    const JS_HANDLE_JQUERY_VALIDATE       = 'jquery-validate';
34
-
35
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
36
-
37
-    const JS_HANDLE_UNDERSCORE            = 'underscore';
38
-
39
-    const JS_HANDLE_ACCOUNTING_CORE       = 'ee-accounting-core';
40
-
41
-    // EE JS assets handles
42
-    const JS_HANDLE_EE_MANIFEST        = 'ee-manifest';
43
-
44
-    const JS_HANDLE_EE_JS_CORE         = 'eejs-core';
45
-
46
-    const JS_HANDLE_EE_VENDOR_REACT    = 'ee-vendor-react';
47
-
48
-    const JS_HANDLE_EE_JS_API          = 'eejs-api';
49
-
50
-    const JS_HANDLE_EE_CORE            = 'espresso_core';
51
-
52
-    const JS_HANDLE_EE_I18N            = 'eei18n';
53
-
54
-    const JS_HANDLE_EE_ACCOUNTING      = 'ee-accounting';
55
-
56
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
57
-
58
-    // EE CSS assets handles
59
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
60
-
61
-    const CSS_HANDLE_EE_CUSTOM  = 'espresso_custom_css';
62
-
63
-    /**
64
-     * @var EE_Currency_Config $currency_config
65
-     */
66
-    protected $currency_config;
67
-
68
-    /**
69
-     * @var EE_Template_Config $template_config
70
-     */
71
-    protected $template_config;
72
-
73
-
74
-    /**
75
-     * CoreAssetRegister constructor.
76
-     *
77
-     * @param AssetCollection    $assets
78
-     * @param EE_Currency_Config $currency_config
79
-     * @param EE_Template_Config $template_config
80
-     * @param DomainInterface    $domain
81
-     * @param Registry           $registry
82
-     */
83
-    public function __construct(
84
-        AssetCollection $assets,
85
-        EE_Currency_Config $currency_config,
86
-        EE_Template_Config $template_config,
87
-        DomainInterface $domain,
88
-        Registry $registry
89
-    ) {
90
-        $this->currency_config = $currency_config;
91
-        $this->template_config = $template_config;
92
-        parent::__construct($domain, $assets, $registry);
93
-    }
94
-
95
-
96
-    /**
97
-     * @since $VID:$
98
-     * @throws DuplicateCollectionIdentifierException
99
-     * @throws InvalidArgumentException
100
-     * @throws InvalidDataTypeException
101
-     * @throws InvalidEntityException
102
-     */
103
-    public function addAssets()
104
-    {
105
-        $this->addJavascriptFiles();
106
-        $this->addStylesheetFiles();
107
-    }
108
-
109
-
110
-    /**
111
-     * @since $VID:$
112
-     * @throws DuplicateCollectionIdentifierException
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidEntityException
116
-     */
117
-    public function addJavascriptFiles()
118
-    {
119
-        $this->loadCoreJs();
120
-        $this->loadJqueryValidate();
121
-        $this->loadAccountingJs();
122
-        add_action(
123
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
124
-            array($this, 'loadQtipJs')
125
-        );
126
-        $this->registerAdminAssets();
127
-    }
128
-
129
-
130
-    /**
131
-     * @since $VID:$
132
-     * @throws DuplicateCollectionIdentifierException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidEntityException
135
-     */
136
-    public function addStylesheetFiles()
137
-    {
138
-        $this->loadCoreCss();
139
-    }
140
-
141
-
142
-    /**
143
-     * core default javascript
144
-     *
145
-     * @since $VID:$
146
-     * @throws DuplicateCollectionIdentifierException
147
-     * @throws InvalidArgumentException
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidEntityException
150
-     */
151
-    private function loadCoreJs()
152
-    {
153
-        $this->addJavascript(
154
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
155
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
156
-        );
157
-
158
-        $this->addJavascript(
159
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
160
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
161
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
162
-        )
163
-        ->setRequiresTranslation()
164
-        ->setHasLocalizedData();
165
-
166
-        $this->addJavascript(
167
-            CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
168
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'),
169
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
170
-        );
171
-
172
-        global $wp_version;
173
-        if (version_compare($wp_version, '4.4.0', '>')) {
174
-            //js.api
175
-            $this->addJavascript(
176
-                CoreAssetManager::JS_HANDLE_EE_JS_API,
177
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
178
-                array(
179
-                    CoreAssetManager::JS_HANDLE_UNDERSCORE,
180
-                    CoreAssetManager::JS_HANDLE_EE_JS_CORE
181
-                )
182
-            );
183
-            $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
184
-            $this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/')));
185
-        }
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_CORE,
189
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
190
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
191
-        )
192
-        ->setLocalizationCallback(
193
-            function () {
194
-                wp_localize_script(
195
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
196
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
197
-                    EE_Registry::$i18n_js_strings
198
-                );
199
-            }
200
-        );
201
-    }
202
-
203
-
204
-    /**
205
-     * @since $VID:$
206
-     * @throws DuplicateCollectionIdentifierException
207
-     * @throws InvalidDataTypeException
208
-     * @throws InvalidEntityException
209
-     */
210
-    private function loadCoreCss()
211
-    {
212
-        if ($this->template_config->enable_default_style && ! is_admin()) {
213
-            $this->addStylesheet(
214
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
215
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
216
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
217
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
218
-                array('dashicons')
219
-            );
220
-            //Load custom style sheet if available
221
-            if ($this->template_config->custom_style_sheet !== null) {
222
-                $this->addStylesheet(
223
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
224
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
225
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
226
-                );
227
-            }
228
-        }
229
-    }
230
-
231
-
232
-    /**
233
-     * jQuery Validate for form validation
234
-     *
235
-     * @since $VID:$
236
-     * @throws DuplicateCollectionIdentifierException
237
-     * @throws InvalidDataTypeException
238
-     * @throws InvalidEntityException
239
-     */
240
-    private function loadJqueryValidate()
241
-    {
242
-        $this->addJavascript(
243
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
244
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
245
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
246
-        )
247
-        ->setVersion('1.15.0');
248
-
249
-        $this->addJavascript(
250
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
251
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
252
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
253
-        )
254
-        ->setVersion('1.15.0');
255
-    }
256
-
257
-
258
-    /**
259
-     * accounting.js for performing client-side calculations
260
-     *
261
-     * @since $VID:$
262
-     * @throws DuplicateCollectionIdentifierException
263
-     * @throws InvalidDataTypeException
264
-     * @throws InvalidEntityException
265
-     */
266
-    private function loadAccountingJs()
267
-    {
268
-        //accounting.js library
269
-        // @link http://josscrowcroft.github.io/accounting.js/
270
-        $this->addJavascript(
271
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
272
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
273
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
274
-        )
275
-        ->setVersion('0.3.2');
276
-
277
-        $currency_config = $this->currency_config;
278
-        $this->addJavascript(
279
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
280
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
281
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
282
-        )
283
-        ->setLocalizationCallback(
284
-            function () use ($currency_config) {
285
-                 wp_localize_script(
286
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
287
-                     'EE_ACCOUNTING_CFG',
288
-                     array(
289
-                         'currency' => array(
290
-                             'symbol'    => $currency_config->sign,
291
-                             'format'    => array(
292
-                                 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
293
-                                 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
294
-                                 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
295
-                             ),
296
-                             'decimal'   => $currency_config->dec_mrk,
297
-                             'thousand'  => $currency_config->thsnds,
298
-                             'precision' => $currency_config->dec_plc,
299
-                         ),
300
-                         'number'   => array(
301
-                             'precision' => $currency_config->dec_plc,
302
-                             'thousand'  => $currency_config->thsnds,
303
-                             'decimal'   => $currency_config->dec_mrk,
304
-                         ),
305
-                     )
306
-                 );
307
-            }
308
-        )
309
-        ->setVersion();
310
-    }
311
-
312
-
313
-    /**
314
-     * registers assets for cleaning your ears
315
-     *
316
-     * @param JavascriptAsset $script
317
-     */
318
-    public function loadQtipJs(JavascriptAsset $script)
319
-    {
320
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
321
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
322
-        if (
323
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
324
-            && apply_filters('FHEE_load_qtip', false)
325
-        ) {
326
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
327
-        }
328
-    }
329
-
330
-
331
-    /**
332
-     * assets that are used in the WordPress admin
333
-     *
334
-     * @since $VID:$
335
-     * @throws DuplicateCollectionIdentifierException
336
-     * @throws InvalidDataTypeException
337
-     * @throws InvalidEntityException
338
-     */
339
-    private function registerAdminAssets()
340
-    {
341
-        $this->addJavascript(
342
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
343
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
344
-            array(
345
-                CoreAssetManager::JS_HANDLE_JQUERY,
346
-                CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
347
-            )
348
-        )
349
-        ->setRequiresTranslation();
350
-
351
-        $this->addStylesheet(
352
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
353
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
354
-        );
355
-    }
30
+	// WordPress core / Third party JS asset handles
31
+	const JS_HANDLE_JQUERY                = 'jquery';
32
+
33
+	const JS_HANDLE_JQUERY_VALIDATE       = 'jquery-validate';
34
+
35
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
36
+
37
+	const JS_HANDLE_UNDERSCORE            = 'underscore';
38
+
39
+	const JS_HANDLE_ACCOUNTING_CORE       = 'ee-accounting-core';
40
+
41
+	// EE JS assets handles
42
+	const JS_HANDLE_EE_MANIFEST        = 'ee-manifest';
43
+
44
+	const JS_HANDLE_EE_JS_CORE         = 'eejs-core';
45
+
46
+	const JS_HANDLE_EE_VENDOR_REACT    = 'ee-vendor-react';
47
+
48
+	const JS_HANDLE_EE_JS_API          = 'eejs-api';
49
+
50
+	const JS_HANDLE_EE_CORE            = 'espresso_core';
51
+
52
+	const JS_HANDLE_EE_I18N            = 'eei18n';
53
+
54
+	const JS_HANDLE_EE_ACCOUNTING      = 'ee-accounting';
55
+
56
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
57
+
58
+	// EE CSS assets handles
59
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
60
+
61
+	const CSS_HANDLE_EE_CUSTOM  = 'espresso_custom_css';
62
+
63
+	/**
64
+	 * @var EE_Currency_Config $currency_config
65
+	 */
66
+	protected $currency_config;
67
+
68
+	/**
69
+	 * @var EE_Template_Config $template_config
70
+	 */
71
+	protected $template_config;
72
+
73
+
74
+	/**
75
+	 * CoreAssetRegister constructor.
76
+	 *
77
+	 * @param AssetCollection    $assets
78
+	 * @param EE_Currency_Config $currency_config
79
+	 * @param EE_Template_Config $template_config
80
+	 * @param DomainInterface    $domain
81
+	 * @param Registry           $registry
82
+	 */
83
+	public function __construct(
84
+		AssetCollection $assets,
85
+		EE_Currency_Config $currency_config,
86
+		EE_Template_Config $template_config,
87
+		DomainInterface $domain,
88
+		Registry $registry
89
+	) {
90
+		$this->currency_config = $currency_config;
91
+		$this->template_config = $template_config;
92
+		parent::__construct($domain, $assets, $registry);
93
+	}
94
+
95
+
96
+	/**
97
+	 * @since $VID:$
98
+	 * @throws DuplicateCollectionIdentifierException
99
+	 * @throws InvalidArgumentException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws InvalidEntityException
102
+	 */
103
+	public function addAssets()
104
+	{
105
+		$this->addJavascriptFiles();
106
+		$this->addStylesheetFiles();
107
+	}
108
+
109
+
110
+	/**
111
+	 * @since $VID:$
112
+	 * @throws DuplicateCollectionIdentifierException
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidEntityException
116
+	 */
117
+	public function addJavascriptFiles()
118
+	{
119
+		$this->loadCoreJs();
120
+		$this->loadJqueryValidate();
121
+		$this->loadAccountingJs();
122
+		add_action(
123
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
124
+			array($this, 'loadQtipJs')
125
+		);
126
+		$this->registerAdminAssets();
127
+	}
128
+
129
+
130
+	/**
131
+	 * @since $VID:$
132
+	 * @throws DuplicateCollectionIdentifierException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidEntityException
135
+	 */
136
+	public function addStylesheetFiles()
137
+	{
138
+		$this->loadCoreCss();
139
+	}
140
+
141
+
142
+	/**
143
+	 * core default javascript
144
+	 *
145
+	 * @since $VID:$
146
+	 * @throws DuplicateCollectionIdentifierException
147
+	 * @throws InvalidArgumentException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidEntityException
150
+	 */
151
+	private function loadCoreJs()
152
+	{
153
+		$this->addJavascript(
154
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
155
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
156
+		);
157
+
158
+		$this->addJavascript(
159
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
160
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
161
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
162
+		)
163
+		->setRequiresTranslation()
164
+		->setHasLocalizedData();
165
+
166
+		$this->addJavascript(
167
+			CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
168
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'),
169
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
170
+		);
171
+
172
+		global $wp_version;
173
+		if (version_compare($wp_version, '4.4.0', '>')) {
174
+			//js.api
175
+			$this->addJavascript(
176
+				CoreAssetManager::JS_HANDLE_EE_JS_API,
177
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
178
+				array(
179
+					CoreAssetManager::JS_HANDLE_UNDERSCORE,
180
+					CoreAssetManager::JS_HANDLE_EE_JS_CORE
181
+				)
182
+			);
183
+			$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
184
+			$this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/')));
185
+		}
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_CORE,
189
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
190
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
191
+		)
192
+		->setLocalizationCallback(
193
+			function () {
194
+				wp_localize_script(
195
+					CoreAssetManager::JS_HANDLE_EE_CORE,
196
+					CoreAssetManager::JS_HANDLE_EE_I18N,
197
+					EE_Registry::$i18n_js_strings
198
+				);
199
+			}
200
+		);
201
+	}
202
+
203
+
204
+	/**
205
+	 * @since $VID:$
206
+	 * @throws DuplicateCollectionIdentifierException
207
+	 * @throws InvalidDataTypeException
208
+	 * @throws InvalidEntityException
209
+	 */
210
+	private function loadCoreCss()
211
+	{
212
+		if ($this->template_config->enable_default_style && ! is_admin()) {
213
+			$this->addStylesheet(
214
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
215
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
216
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
217
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
218
+				array('dashicons')
219
+			);
220
+			//Load custom style sheet if available
221
+			if ($this->template_config->custom_style_sheet !== null) {
222
+				$this->addStylesheet(
223
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
224
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
225
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
226
+				);
227
+			}
228
+		}
229
+	}
230
+
231
+
232
+	/**
233
+	 * jQuery Validate for form validation
234
+	 *
235
+	 * @since $VID:$
236
+	 * @throws DuplicateCollectionIdentifierException
237
+	 * @throws InvalidDataTypeException
238
+	 * @throws InvalidEntityException
239
+	 */
240
+	private function loadJqueryValidate()
241
+	{
242
+		$this->addJavascript(
243
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
244
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
245
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
246
+		)
247
+		->setVersion('1.15.0');
248
+
249
+		$this->addJavascript(
250
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
251
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
252
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
253
+		)
254
+		->setVersion('1.15.0');
255
+	}
256
+
257
+
258
+	/**
259
+	 * accounting.js for performing client-side calculations
260
+	 *
261
+	 * @since $VID:$
262
+	 * @throws DuplicateCollectionIdentifierException
263
+	 * @throws InvalidDataTypeException
264
+	 * @throws InvalidEntityException
265
+	 */
266
+	private function loadAccountingJs()
267
+	{
268
+		//accounting.js library
269
+		// @link http://josscrowcroft.github.io/accounting.js/
270
+		$this->addJavascript(
271
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
272
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
273
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
274
+		)
275
+		->setVersion('0.3.2');
276
+
277
+		$currency_config = $this->currency_config;
278
+		$this->addJavascript(
279
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
280
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
281
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
282
+		)
283
+		->setLocalizationCallback(
284
+			function () use ($currency_config) {
285
+				 wp_localize_script(
286
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
287
+					 'EE_ACCOUNTING_CFG',
288
+					 array(
289
+						 'currency' => array(
290
+							 'symbol'    => $currency_config->sign,
291
+							 'format'    => array(
292
+								 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
293
+								 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
294
+								 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
295
+							 ),
296
+							 'decimal'   => $currency_config->dec_mrk,
297
+							 'thousand'  => $currency_config->thsnds,
298
+							 'precision' => $currency_config->dec_plc,
299
+						 ),
300
+						 'number'   => array(
301
+							 'precision' => $currency_config->dec_plc,
302
+							 'thousand'  => $currency_config->thsnds,
303
+							 'decimal'   => $currency_config->dec_mrk,
304
+						 ),
305
+					 )
306
+				 );
307
+			}
308
+		)
309
+		->setVersion();
310
+	}
311
+
312
+
313
+	/**
314
+	 * registers assets for cleaning your ears
315
+	 *
316
+	 * @param JavascriptAsset $script
317
+	 */
318
+	public function loadQtipJs(JavascriptAsset $script)
319
+	{
320
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
321
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
322
+		if (
323
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
324
+			&& apply_filters('FHEE_load_qtip', false)
325
+		) {
326
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
327
+		}
328
+	}
329
+
330
+
331
+	/**
332
+	 * assets that are used in the WordPress admin
333
+	 *
334
+	 * @since $VID:$
335
+	 * @throws DuplicateCollectionIdentifierException
336
+	 * @throws InvalidDataTypeException
337
+	 * @throws InvalidEntityException
338
+	 */
339
+	private function registerAdminAssets()
340
+	{
341
+		$this->addJavascript(
342
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
343
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
344
+			array(
345
+				CoreAssetManager::JS_HANDLE_JQUERY,
346
+				CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
347
+			)
348
+		)
349
+		->setRequiresTranslation();
350
+
351
+		$this->addStylesheet(
352
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
353
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
354
+		);
355
+	}
356 356
 }
Please login to merge, or discard this patch.