Completed
Branch sideload-all-language-files (d12b05)
by
unknown
52:19 queued 43:17
created
core/services/loaders/CachingLoader.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $identifier = ''
54 54
     ) {
55 55
         parent::__construct($loader);
56
-        $this->cache       = $cache;
56
+        $this->cache = $cache;
57 57
         $this->object_identifier = $object_identifier;
58 58
         $this->setIdentifier($identifier);
59 59
         if ($this->identifier !== '') {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     private function setIdentifier($identifier)
91 91
     {
92
-        if (! is_string($identifier)) {
92
+        if ( ! is_string($identifier)) {
93 93
             throw new InvalidDataTypeException('$identifier', $identifier, 'string');
94 94
         }
95 95
         $this->identifier = $identifier;
Please login to merge, or discard this patch.
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -17,158 +17,158 @@
 block discarded – undo
17 17
 class CachingLoader extends CachingLoaderDecorator
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $identifier
22
-     */
23
-    protected $identifier;
24
-
25
-    /**
26
-     * @var CollectionInterface $cache
27
-     */
28
-    protected $cache;
29
-
30
-    /**
31
-     * @var ObjectIdentifier
32
-     */
33
-    private $object_identifier;
34
-
35
-
36
-    /**
37
-     * CachingLoader constructor.
38
-     *
39
-     * @param LoaderDecoratorInterface $loader
40
-     * @param CollectionInterface      $cache
41
-     * @param ObjectIdentifier         $object_identifier
42
-     * @param string                   $identifier
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct(
46
-        LoaderDecoratorInterface $loader,
47
-        CollectionInterface $cache,
48
-        ObjectIdentifier $object_identifier,
49
-        $identifier = ''
50
-    ) {
51
-        parent::__construct($loader);
52
-        $this->cache       = $cache;
53
-        $this->object_identifier = $object_identifier;
54
-        $this->setIdentifier($identifier);
55
-        if ($this->identifier !== '') {
56
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
57
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
58
-            // where "IDENTIFIER" = the string that was set during construction
59
-            add_action(
60
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
61
-                array($this, 'reset')
62
-            );
63
-        }
64
-        // to clear ALL caches, simply do the following:
65
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
66
-        add_action(
67
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
68
-            array($this, 'reset')
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * @return string
75
-     */
76
-    public function identifier()
77
-    {
78
-        return $this->identifier;
79
-    }
80
-
81
-
82
-    /**
83
-     * @param string $identifier
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    private function setIdentifier($identifier)
87
-    {
88
-        if (! is_string($identifier)) {
89
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
-        }
91
-        $this->identifier = $identifier;
92
-    }
93
-
94
-
95
-    /**
96
-     * @param FullyQualifiedName|string $fqcn
97
-     * @param mixed                     $object
98
-     * @param array                     $arguments
99
-     * @return bool
100
-     * @throws InvalidArgumentException
101
-     */
102
-    public function share($fqcn, $object, array $arguments = array())
103
-    {
104
-        if ($object instanceof $fqcn) {
105
-            return $this->cache->add(
106
-                $object,
107
-                $this->object_identifier->getIdentifier($fqcn, $arguments)
108
-            );
109
-        }
110
-        throw new InvalidArgumentException(
111
-            sprintf(
112
-                esc_html__(
113
-                    'The supplied class name "%1$s" must match the class of the supplied object.',
114
-                    'event_espresso'
115
-                ),
116
-                $fqcn
117
-            )
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * @param FullyQualifiedName|string $fqcn
124
-     * @param array                     $arguments
125
-     * @param bool                      $shared
126
-     * @param array                     $interfaces
127
-     * @return mixed
128
-     */
129
-    public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
130
-    {
131
-        $fqcn = ltrim($fqcn, '\\');
132
-        // caching can be turned off via the following code:
133
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
134
-        if (apply_filters(
135
-            'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
136
-            false,
137
-            $this
138
-        )) {
139
-            // even though $shared might be true, caching could be bypassed for whatever reason,
140
-            // so we don't want the core loader to cache anything, therefore caching is turned off
141
-            return $this->loader->load($fqcn, $arguments, false);
142
-        }
143
-        $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
144
-        if ($this->cache->has($object_identifier)) {
145
-            return $this->cache->get($object_identifier);
146
-        }
147
-        $object = $this->loader->load($fqcn, $arguments, $shared);
148
-        if ($object instanceof $fqcn) {
149
-            $this->cache->add($object, $object_identifier);
150
-        }
151
-        return $object;
152
-    }
153
-
154
-
155
-    /**
156
-     * empties cache and calls reset() on loader if method exists
157
-     */
158
-    public function reset()
159
-    {
160
-        $this->clearCache();
161
-        $this->loader->reset();
162
-    }
163
-
164
-
165
-    /**
166
-     * unsets and detaches ALL objects from the cache
167
-     *
168
-     * @since 4.9.62.p
169
-     */
170
-    public function clearCache()
171
-    {
172
-        $this->cache->trashAndDetachAll();
173
-    }
20
+	/**
21
+	 * @var string $identifier
22
+	 */
23
+	protected $identifier;
24
+
25
+	/**
26
+	 * @var CollectionInterface $cache
27
+	 */
28
+	protected $cache;
29
+
30
+	/**
31
+	 * @var ObjectIdentifier
32
+	 */
33
+	private $object_identifier;
34
+
35
+
36
+	/**
37
+	 * CachingLoader constructor.
38
+	 *
39
+	 * @param LoaderDecoratorInterface $loader
40
+	 * @param CollectionInterface      $cache
41
+	 * @param ObjectIdentifier         $object_identifier
42
+	 * @param string                   $identifier
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct(
46
+		LoaderDecoratorInterface $loader,
47
+		CollectionInterface $cache,
48
+		ObjectIdentifier $object_identifier,
49
+		$identifier = ''
50
+	) {
51
+		parent::__construct($loader);
52
+		$this->cache       = $cache;
53
+		$this->object_identifier = $object_identifier;
54
+		$this->setIdentifier($identifier);
55
+		if ($this->identifier !== '') {
56
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
57
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
58
+			// where "IDENTIFIER" = the string that was set during construction
59
+			add_action(
60
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
61
+				array($this, 'reset')
62
+			);
63
+		}
64
+		// to clear ALL caches, simply do the following:
65
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
66
+		add_action(
67
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
68
+			array($this, 'reset')
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @return string
75
+	 */
76
+	public function identifier()
77
+	{
78
+		return $this->identifier;
79
+	}
80
+
81
+
82
+	/**
83
+	 * @param string $identifier
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	private function setIdentifier($identifier)
87
+	{
88
+		if (! is_string($identifier)) {
89
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
+		}
91
+		$this->identifier = $identifier;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param FullyQualifiedName|string $fqcn
97
+	 * @param mixed                     $object
98
+	 * @param array                     $arguments
99
+	 * @return bool
100
+	 * @throws InvalidArgumentException
101
+	 */
102
+	public function share($fqcn, $object, array $arguments = array())
103
+	{
104
+		if ($object instanceof $fqcn) {
105
+			return $this->cache->add(
106
+				$object,
107
+				$this->object_identifier->getIdentifier($fqcn, $arguments)
108
+			);
109
+		}
110
+		throw new InvalidArgumentException(
111
+			sprintf(
112
+				esc_html__(
113
+					'The supplied class name "%1$s" must match the class of the supplied object.',
114
+					'event_espresso'
115
+				),
116
+				$fqcn
117
+			)
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @param FullyQualifiedName|string $fqcn
124
+	 * @param array                     $arguments
125
+	 * @param bool                      $shared
126
+	 * @param array                     $interfaces
127
+	 * @return mixed
128
+	 */
129
+	public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
130
+	{
131
+		$fqcn = ltrim($fqcn, '\\');
132
+		// caching can be turned off via the following code:
133
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
134
+		if (apply_filters(
135
+			'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
136
+			false,
137
+			$this
138
+		)) {
139
+			// even though $shared might be true, caching could be bypassed for whatever reason,
140
+			// so we don't want the core loader to cache anything, therefore caching is turned off
141
+			return $this->loader->load($fqcn, $arguments, false);
142
+		}
143
+		$object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments);
144
+		if ($this->cache->has($object_identifier)) {
145
+			return $this->cache->get($object_identifier);
146
+		}
147
+		$object = $this->loader->load($fqcn, $arguments, $shared);
148
+		if ($object instanceof $fqcn) {
149
+			$this->cache->add($object, $object_identifier);
150
+		}
151
+		return $object;
152
+	}
153
+
154
+
155
+	/**
156
+	 * empties cache and calls reset() on loader if method exists
157
+	 */
158
+	public function reset()
159
+	{
160
+		$this->clearCache();
161
+		$this->loader->reset();
162
+	}
163
+
164
+
165
+	/**
166
+	 * unsets and detaches ALL objects from the cache
167
+	 *
168
+	 * @since 4.9.62.p
169
+	 */
170
+	public function clearCache()
171
+	{
172
+		$this->cache->trashAndDetachAll();
173
+	}
174 174
 }
Please login to merge, or discard this patch.
core/services/loaders/ObjectIdentifier.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
74 74
     {
75 75
         return $fqcn === $object_identifier
76
-               || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
76
+               || strpos($object_identifier, $fqcn.ObjectIdentifier::DELIMITER) === 0;
77 77
     }
78 78
 
79 79
 
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
         )
94 94
             ? $this->getIdentifierForArguments($arguments)
95 95
             : '';
96
-        if (! empty($identifier)) {
97
-            $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
96
+        if ( ! empty($identifier)) {
97
+            $fqcn .= ObjectIdentifier::DELIMITER.md5($identifier);
98 98
         }
99 99
         return $fqcn;
100 100
     }
Please login to merge, or discard this patch.
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -16,113 +16,113 @@
 block discarded – undo
16 16
 class ObjectIdentifier
17 17
 {
18 18
 
19
-    /**
20
-     * used to separate the FQCN from the class's arguments identifier
21
-     */
22
-    const DELIMITER = '____';
19
+	/**
20
+	 * used to separate the FQCN from the class's arguments identifier
21
+	 */
22
+	const DELIMITER = '____';
23 23
 
24
-    /**
25
-     * @var ClassInterfaceCache $class_cache
26
-     */
27
-    private $class_cache;
24
+	/**
25
+	 * @var ClassInterfaceCache $class_cache
26
+	 */
27
+	private $class_cache;
28 28
 
29 29
 
30
-    /**
31
-     * ObjectIdentifier constructor.
32
-     *
33
-     * @param ClassInterfaceCache $class_cache
34
-     */
35
-    public function __construct(ClassInterfaceCache $class_cache)
36
-    {
37
-        $this->class_cache = $class_cache;
38
-    }
30
+	/**
31
+	 * ObjectIdentifier constructor.
32
+	 *
33
+	 * @param ClassInterfaceCache $class_cache
34
+	 */
35
+	public function __construct(ClassInterfaceCache $class_cache)
36
+	{
37
+		$this->class_cache = $class_cache;
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * Returns true if the supplied $object_identifier contains
43
-     * the delimiter used to separate an fqcn from the arguments hash
44
-     *
45
-     * @param string $object_identifier
46
-     * @return bool
47
-     */
48
-    public function hasArguments($object_identifier)
49
-    {
50
-        // type casting to bool instead of using strpos() !== false
51
-        // because an object identifier should never begin with the delimiter
52
-        // therefore the delimiter should NOT be found at position 0
53
-        return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
54
-    }
41
+	/**
42
+	 * Returns true if the supplied $object_identifier contains
43
+	 * the delimiter used to separate an fqcn from the arguments hash
44
+	 *
45
+	 * @param string $object_identifier
46
+	 * @return bool
47
+	 */
48
+	public function hasArguments($object_identifier)
49
+	{
50
+		// type casting to bool instead of using strpos() !== false
51
+		// because an object identifier should never begin with the delimiter
52
+		// therefore the delimiter should NOT be found at position 0
53
+		return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Returns true if the supplied FQCN equals the supplied $object_identifier
59
-     * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
60
-     * AND that $object_identifier is for an object with arguments.
61
-     * This allows a request for an object using a FQCN to match
62
-     * a previously instantiated object with arguments
63
-     * without having to know those arguments.
64
-     *
65
-     * @param string $fqcn
66
-     * @param string $object_identifier
67
-     * @return bool
68
-     */
69
-    public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
70
-    {
71
-        return $fqcn === $object_identifier
72
-               || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
73
-    }
57
+	/**
58
+	 * Returns true if the supplied FQCN equals the supplied $object_identifier
59
+	 * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
60
+	 * AND that $object_identifier is for an object with arguments.
61
+	 * This allows a request for an object using a FQCN to match
62
+	 * a previously instantiated object with arguments
63
+	 * without having to know those arguments.
64
+	 *
65
+	 * @param string $fqcn
66
+	 * @param string $object_identifier
67
+	 * @return bool
68
+	 */
69
+	public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
70
+	{
71
+		return $fqcn === $object_identifier
72
+			   || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * build a string representation of an object's FQCN and arguments
78
-     *
79
-     * @param string $fqcn
80
-     * @param array  $arguments
81
-     * @return string
82
-     */
83
-    public function getIdentifier($fqcn, array $arguments = array())
84
-    {
85
-        // only build identifier from arguments if class is not ReservedInstanceInterface
86
-        $identifier = ! $this->class_cache->hasInterface(
87
-            $fqcn,
88
-            'EventEspresso\core\interfaces\ReservedInstanceInterface'
89
-        )
90
-            ? $this->getIdentifierForArguments($arguments)
91
-            : '';
92
-        if (! empty($identifier)) {
93
-            $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
94
-        }
95
-        return $fqcn;
96
-    }
76
+	/**
77
+	 * build a string representation of an object's FQCN and arguments
78
+	 *
79
+	 * @param string $fqcn
80
+	 * @param array  $arguments
81
+	 * @return string
82
+	 */
83
+	public function getIdentifier($fqcn, array $arguments = array())
84
+	{
85
+		// only build identifier from arguments if class is not ReservedInstanceInterface
86
+		$identifier = ! $this->class_cache->hasInterface(
87
+			$fqcn,
88
+			'EventEspresso\core\interfaces\ReservedInstanceInterface'
89
+		)
90
+			? $this->getIdentifierForArguments($arguments)
91
+			: '';
92
+		if (! empty($identifier)) {
93
+			$fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
94
+		}
95
+		return $fqcn;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * build a string representation of a object's arguments
101
-     * (mostly because Closures can't be serialized)
102
-     *
103
-     * @param array $arguments
104
-     * @return string
105
-     */
106
-    protected function getIdentifierForArguments(array $arguments)
107
-    {
108
-        if (empty($arguments)) {
109
-            return '';
110
-        }
111
-        $identifier = '';
112
-        foreach ($arguments as $argument) {
113
-            switch (true) {
114
-                case is_object($argument):
115
-                case $argument instanceof Closure:
116
-                    $identifier .= spl_object_hash($argument);
117
-                    break;
118
-                case is_array($argument):
119
-                    $identifier .= $this->getIdentifierForArguments($argument);
120
-                    break;
121
-                default:
122
-                    $identifier .= $argument;
123
-                    break;
124
-            }
125
-        }
126
-        return $identifier;
127
-    }
99
+	/**
100
+	 * build a string representation of a object's arguments
101
+	 * (mostly because Closures can't be serialized)
102
+	 *
103
+	 * @param array $arguments
104
+	 * @return string
105
+	 */
106
+	protected function getIdentifierForArguments(array $arguments)
107
+	{
108
+		if (empty($arguments)) {
109
+			return '';
110
+		}
111
+		$identifier = '';
112
+		foreach ($arguments as $argument) {
113
+			switch (true) {
114
+				case is_object($argument):
115
+				case $argument instanceof Closure:
116
+					$identifier .= spl_object_hash($argument);
117
+					break;
118
+				case is_array($argument):
119
+					$identifier .= $this->getIdentifierForArguments($argument);
120
+					break;
121
+				default:
122
+					$identifier .= $argument;
123
+					break;
124
+			}
125
+		}
126
+		return $identifier;
127
+	}
128 128
 }
Please login to merge, or discard this patch.
core/domain/DomainInterface.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
 interface DomainInterface extends InterminableInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @return string
21
-     * @throws DomainException
22
-     */
23
-    public function pluginFile();
19
+	/**
20
+	 * @return string
21
+	 * @throws DomainException
22
+	 */
23
+	public function pluginFile();
24 24
 
25 25
 
26
-    /**
27
-     * @return string
28
-     * @throws DomainException
29
-     */
30
-    public function pluginBasename();
26
+	/**
27
+	 * @return string
28
+	 * @throws DomainException
29
+	 */
30
+	public function pluginBasename();
31 31
 
32 32
 
33
-    /**
34
-     * @return string
35
-     */
36
-    public function pluginPath();
33
+	/**
34
+	 * @return string
35
+	 */
36
+	public function pluginPath();
37 37
 
38 38
 
39
-    /**
40
-     * @return string
41
-     * @throws DomainException
42
-     */
43
-    public function pluginUrl();
39
+	/**
40
+	 * @return string
41
+	 * @throws DomainException
42
+	 */
43
+	public function pluginUrl();
44 44
 
45 45
 
46
-    /**
47
-     * @return string
48
-     * @throws DomainException
49
-     */
50
-    public function version();
46
+	/**
47
+	 * @return string
48
+	 * @throws DomainException
49
+	 */
50
+	public function version();
51 51
 
52 52
 
53
-    /**
54
-     * @return string
55
-     */
56
-    public function distributionAssetsPath();
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function distributionAssetsPath();
57 57
 
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function distributionAssetsUrl();
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function distributionAssetsUrl();
63 63
 
64 64
 
65
-    /**
66
-     * @return string
67
-     */
68
-    public function assetNamespace();
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function assetNamespace();
69 69
 
70 70
 }
Please login to merge, or discard this patch.
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.
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -21,471 +21,471 @@
 block discarded – undo
21 21
 class Collection extends SplObjectStorage implements CollectionInterface
22 22
 {
23 23
 
24
-    /**
25
-     * a unique string for identifying this collection
26
-     *
27
-     * @type string $collection_identifier
28
-     */
29
-    protected $collection_identifier;
30
-
31
-    /**
32
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
33
-     * this should be set from within the child class constructor
34
-     *
35
-     * @type string $interface
36
-     */
37
-    protected $collection_interface;
38
-
39
-
40
-    /**
41
-     * Collection constructor
42
-     *
43
-     * @param string $collection_interface
44
-     * @throws InvalidInterfaceException
45
-     */
46
-    public function __construct($collection_interface)
47
-    {
48
-        $this->setCollectionInterface($collection_interface);
49
-        $this->setCollectionIdentifier();
50
-    }
51
-
52
-
53
-    /**
54
-     * @return string
55
-     */
56
-    public function collectionIdentifier()
57
-    {
58
-        return $this->collection_identifier;
59
-    }
60
-
61
-
62
-    /**
63
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
64
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
65
-     *
66
-     * @return void
67
-     */
68
-    protected function setCollectionIdentifier()
69
-    {
70
-        // hash a few collection details
71
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
72
-        // grab a few characters from the start, middle, and end of the hash
73
-        $id = array();
74
-        for ($x = 0; $x < 19; $x += 9) {
75
-            $id[] = substr($identifier, $x, 3);
76
-        }
77
-        $identifier = basename(str_replace('\\', '/', get_class($this)));
78
-        $identifier .= '-' . strtoupper(implode('-', $id));
79
-        $this->collection_identifier = $identifier;
80
-    }
81
-
82
-
83
-    /**
84
-     * setCollectionInterface
85
-     *
86
-     * @access protected
87
-     * @param  string $collection_interface
88
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
89
-     */
90
-    protected function setCollectionInterface($collection_interface)
91
-    {
92
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
93
-            throw new InvalidInterfaceException($collection_interface);
94
-        }
95
-        $this->collection_interface = $collection_interface;
96
-    }
97
-
98
-
99
-    /**
100
-     * add
101
-     * attaches an object to the Collection
102
-     * and sets any supplied data associated with the current iterator entry
103
-     * by calling EE_Object_Collection::set_identifier()
104
-     *
105
-     * @access public
106
-     * @param        $object
107
-     * @param  mixed $identifier
108
-     * @return bool
109
-     * @throws InvalidEntityException
110
-     * @throws DuplicateCollectionIdentifierException
111
-     */
112
-    public function add($object, $identifier = null)
113
-    {
114
-        if (! $object instanceof $this->collection_interface) {
115
-            throw new InvalidEntityException($object, $this->collection_interface);
116
-        }
117
-        if ($this->contains($object)) {
118
-            throw new DuplicateCollectionIdentifierException($identifier);
119
-        }
120
-        $this->attach($object);
121
-        $this->setIdentifier($object, $identifier);
122
-        return $this->contains($object);
123
-    }
124
-
125
-
126
-    /**
127
-     * setIdentifier
128
-     * Sets the data associated with an object in the Collection
129
-     * if no $identifier is supplied, then the spl_object_hash() is used
130
-     *
131
-     * @access public
132
-     * @param        $object
133
-     * @param  mixed $identifier
134
-     * @return bool
135
-     */
136
-    public function setIdentifier($object, $identifier = null)
137
-    {
138
-        $identifier = ! empty($identifier)
139
-            ? $identifier
140
-            : spl_object_hash($object);
141
-        $this->rewind();
142
-        while ($this->valid()) {
143
-            if ($object === $this->current()) {
144
-                $this->setInfo($identifier);
145
-                $this->rewind();
146
-                return true;
147
-            }
148
-            $this->next();
149
-        }
150
-        return false;
151
-    }
152
-
153
-
154
-    /**
155
-     * get
156
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
157
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
158
-     *
159
-     * @access public
160
-     * @param mixed $identifier
161
-     * @return mixed
162
-     */
163
-    public function get($identifier)
164
-    {
165
-        $this->rewind();
166
-        while ($this->valid()) {
167
-            if ($identifier === $this->getInfo()) {
168
-                $object = $this->current();
169
-                $this->rewind();
170
-                return $object;
171
-            }
172
-            $this->next();
173
-        }
174
-        return null;
175
-    }
176
-
177
-
178
-    /**
179
-     * has
180
-     * returns TRUE or FALSE
181
-     * depending on whether the object is within the Collection
182
-     * based on the supplied $identifier
183
-     *
184
-     * @access public
185
-     * @param  mixed $identifier
186
-     * @return bool
187
-     */
188
-    public function has($identifier)
189
-    {
190
-        $this->rewind();
191
-        while ($this->valid()) {
192
-            if ($identifier === $this->getInfo()) {
193
-                $this->rewind();
194
-                return true;
195
-            }
196
-            $this->next();
197
-        }
198
-        return false;
199
-    }
200
-
201
-
202
-    /**
203
-     * hasObject
204
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
205
-     *
206
-     * @access public
207
-     * @param $object
208
-     * @return bool
209
-     */
210
-    public function hasObject($object)
211
-    {
212
-        return $this->contains($object);
213
-    }
214
-
215
-
216
-    /**
217
-     * hasObjects
218
-     * returns true if there are objects within the Collection, and false if it is empty
219
-     *
220
-     * @access public
221
-     * @return bool
222
-     */
223
-    public function hasObjects()
224
-    {
225
-        return $this->count() !== 0;
226
-    }
227
-
228
-
229
-    /**
230
-     * isEmpty
231
-     * returns true if there are no objects within the Collection, and false if there are
232
-     *
233
-     * @access public
234
-     * @return bool
235
-     */
236
-    public function isEmpty()
237
-    {
238
-        return $this->count() === 0;
239
-    }
240
-
241
-
242
-    /**
243
-     * remove
244
-     * detaches an object from the Collection
245
-     *
246
-     * @access public
247
-     * @param $object
248
-     * @return bool
249
-     */
250
-    public function remove($object)
251
-    {
252
-        $this->detach($object);
253
-        return true;
254
-    }
255
-
256
-
257
-    /**
258
-     * setCurrent
259
-     * advances pointer to the object whose identifier matches that which was provided
260
-     *
261
-     * @access public
262
-     * @param mixed $identifier
263
-     * @return boolean
264
-     */
265
-    public function setCurrent($identifier)
266
-    {
267
-        $this->rewind();
268
-        while ($this->valid()) {
269
-            if ($identifier === $this->getInfo()) {
270
-                return true;
271
-            }
272
-            $this->next();
273
-        }
274
-        return false;
275
-    }
276
-
277
-
278
-    /**
279
-     * setCurrentUsingObject
280
-     * advances pointer to the provided object
281
-     *
282
-     * @access public
283
-     * @param $object
284
-     * @return boolean
285
-     */
286
-    public function setCurrentUsingObject($object)
287
-    {
288
-        $this->rewind();
289
-        while ($this->valid()) {
290
-            if ($this->current() === $object) {
291
-                return true;
292
-            }
293
-            $this->next();
294
-        }
295
-        return false;
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns the object occupying the index before the current object,
301
-     * unless this is already the first object, in which case it just returns the first object
302
-     *
303
-     * @return mixed
304
-     */
305
-    public function previous()
306
-    {
307
-        $index = $this->indexOf($this->current());
308
-        if ($index === 0) {
309
-            return $this->current();
310
-        }
311
-        $index--;
312
-        return $this->objectAtIndex($index);
313
-    }
314
-
315
-
316
-    /**
317
-     * Returns the index of a given object, or false if not found
318
-     *
319
-     * @see http://stackoverflow.com/a/8736013
320
-     * @param $object
321
-     * @return boolean|int|string
322
-     */
323
-    public function indexOf($object)
324
-    {
325
-        if (! $this->contains($object)) {
326
-            return false;
327
-        }
328
-        foreach ($this as $index => $obj) {
329
-            if ($obj === $object) {
330
-                return $index;
331
-            }
332
-        }
333
-        return false;
334
-    }
335
-
336
-
337
-    /**
338
-     * Returns the object at the given index
339
-     *
340
-     * @see http://stackoverflow.com/a/8736013
341
-     * @param int $index
342
-     * @return mixed
343
-     */
344
-    public function objectAtIndex($index)
345
-    {
346
-        $iterator = new LimitIterator($this, $index, 1);
347
-        $iterator->rewind();
348
-        return $iterator->current();
349
-    }
350
-
351
-
352
-    /**
353
-     * Returns the sequence of objects as specified by the offset and length
354
-     *
355
-     * @see http://stackoverflow.com/a/8736013
356
-     * @param int $offset
357
-     * @param int $length
358
-     * @return array
359
-     */
360
-    public function slice($offset, $length)
361
-    {
362
-        $slice = array();
363
-        $iterator = new LimitIterator($this, $offset, $length);
364
-        foreach ($iterator as $object) {
365
-            $slice[] = $object;
366
-        }
367
-        return $slice;
368
-    }
369
-
370
-
371
-    /**
372
-     * Inserts an object at a certain point
373
-     *
374
-     * @see http://stackoverflow.com/a/8736013
375
-     * @param mixed $object A single object
376
-     * @param int   $index
377
-     * @param mixed $identifier
378
-     * @return bool
379
-     * @throws DuplicateCollectionIdentifierException
380
-     * @throws InvalidEntityException
381
-     */
382
-    public function insertObjectAt($object, $index, $identifier = null)
383
-    {
384
-        // check to ensure that objects don't already exist in the collection
385
-        if ($this->has($identifier)) {
386
-            throw new DuplicateCollectionIdentifierException($identifier);
387
-        }
388
-        // detach any objects at or past this index
389
-        $remaining_objects = array();
390
-        if ($index < $this->count()) {
391
-            $remaining_objects = $this->slice($index, $this->count() - $index);
392
-            foreach ($remaining_objects as $key => $remaining_object) {
393
-                // we need to grab the identifiers for each object and use them as keys
394
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
395
-                // and then remove the object from the current tracking array
396
-                unset($remaining_objects[ $key ]);
397
-                // and then remove it from the Collection
398
-                $this->detach($remaining_object);
399
-            }
400
-        }
401
-        // add the new object we're splicing in
402
-        $this->add($object, $identifier);
403
-        // attach the objects we previously detached
404
-        foreach ($remaining_objects as $key => $remaining_object) {
405
-            $this->add($remaining_object, $key);
406
-        }
407
-        return $this->contains($object);
408
-    }
409
-
410
-
411
-    /**
412
-     * Inserts an object (or an array of objects) at a certain point
413
-     *
414
-     * @see http://stackoverflow.com/a/8736013
415
-     * @param mixed $objects A single object or an array of objects
416
-     * @param int   $index
417
-     */
418
-    public function insertAt($objects, $index)
419
-    {
420
-        if (! is_array($objects)) {
421
-            $objects = array($objects);
422
-        }
423
-        // check to ensure that objects don't already exist in the collection
424
-        foreach ($objects as $key => $object) {
425
-            if ($this->contains($object)) {
426
-                unset($objects[ $key ]);
427
-            }
428
-        }
429
-        // do we have any objects left?
430
-        if (! $objects) {
431
-            return;
432
-        }
433
-        // detach any objects at or past this index
434
-        $remaining = array();
435
-        if ($index < $this->count()) {
436
-            $remaining = $this->slice($index, $this->count() - $index);
437
-            foreach ($remaining as $object) {
438
-                $this->detach($object);
439
-            }
440
-        }
441
-        // add the new objects we're splicing in
442
-        foreach ($objects as $object) {
443
-            $this->attach($object);
444
-        }
445
-        // attach the objects we previously detached
446
-        foreach ($remaining as $object) {
447
-            $this->attach($object);
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     * Removes the object at the given index
454
-     *
455
-     * @see http://stackoverflow.com/a/8736013
456
-     * @param int $index
457
-     */
458
-    public function removeAt($index)
459
-    {
460
-        $this->detach($this->objectAtIndex($index));
461
-    }
462
-
463
-
464
-    /**
465
-     * detaches ALL objects from the Collection
466
-     */
467
-    public function detachAll()
468
-    {
469
-        $this->rewind();
470
-        while ($this->valid()) {
471
-            $object = $this->current();
472
-            $this->next();
473
-            $this->detach($object);
474
-        }
475
-    }
476
-
477
-
478
-    /**
479
-     * unsets and detaches ALL objects from the Collection
480
-     */
481
-    public function trashAndDetachAll()
482
-    {
483
-        $this->rewind();
484
-        while ($this->valid()) {
485
-            $object = $this->current();
486
-            $this->next();
487
-            $this->detach($object);
488
-            unset($object);
489
-        }
490
-    }
24
+	/**
25
+	 * a unique string for identifying this collection
26
+	 *
27
+	 * @type string $collection_identifier
28
+	 */
29
+	protected $collection_identifier;
30
+
31
+	/**
32
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
33
+	 * this should be set from within the child class constructor
34
+	 *
35
+	 * @type string $interface
36
+	 */
37
+	protected $collection_interface;
38
+
39
+
40
+	/**
41
+	 * Collection constructor
42
+	 *
43
+	 * @param string $collection_interface
44
+	 * @throws InvalidInterfaceException
45
+	 */
46
+	public function __construct($collection_interface)
47
+	{
48
+		$this->setCollectionInterface($collection_interface);
49
+		$this->setCollectionIdentifier();
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function collectionIdentifier()
57
+	{
58
+		return $this->collection_identifier;
59
+	}
60
+
61
+
62
+	/**
63
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
64
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
65
+	 *
66
+	 * @return void
67
+	 */
68
+	protected function setCollectionIdentifier()
69
+	{
70
+		// hash a few collection details
71
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
72
+		// grab a few characters from the start, middle, and end of the hash
73
+		$id = array();
74
+		for ($x = 0; $x < 19; $x += 9) {
75
+			$id[] = substr($identifier, $x, 3);
76
+		}
77
+		$identifier = basename(str_replace('\\', '/', get_class($this)));
78
+		$identifier .= '-' . strtoupper(implode('-', $id));
79
+		$this->collection_identifier = $identifier;
80
+	}
81
+
82
+
83
+	/**
84
+	 * setCollectionInterface
85
+	 *
86
+	 * @access protected
87
+	 * @param  string $collection_interface
88
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
89
+	 */
90
+	protected function setCollectionInterface($collection_interface)
91
+	{
92
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
93
+			throw new InvalidInterfaceException($collection_interface);
94
+		}
95
+		$this->collection_interface = $collection_interface;
96
+	}
97
+
98
+
99
+	/**
100
+	 * add
101
+	 * attaches an object to the Collection
102
+	 * and sets any supplied data associated with the current iterator entry
103
+	 * by calling EE_Object_Collection::set_identifier()
104
+	 *
105
+	 * @access public
106
+	 * @param        $object
107
+	 * @param  mixed $identifier
108
+	 * @return bool
109
+	 * @throws InvalidEntityException
110
+	 * @throws DuplicateCollectionIdentifierException
111
+	 */
112
+	public function add($object, $identifier = null)
113
+	{
114
+		if (! $object instanceof $this->collection_interface) {
115
+			throw new InvalidEntityException($object, $this->collection_interface);
116
+		}
117
+		if ($this->contains($object)) {
118
+			throw new DuplicateCollectionIdentifierException($identifier);
119
+		}
120
+		$this->attach($object);
121
+		$this->setIdentifier($object, $identifier);
122
+		return $this->contains($object);
123
+	}
124
+
125
+
126
+	/**
127
+	 * setIdentifier
128
+	 * Sets the data associated with an object in the Collection
129
+	 * if no $identifier is supplied, then the spl_object_hash() is used
130
+	 *
131
+	 * @access public
132
+	 * @param        $object
133
+	 * @param  mixed $identifier
134
+	 * @return bool
135
+	 */
136
+	public function setIdentifier($object, $identifier = null)
137
+	{
138
+		$identifier = ! empty($identifier)
139
+			? $identifier
140
+			: spl_object_hash($object);
141
+		$this->rewind();
142
+		while ($this->valid()) {
143
+			if ($object === $this->current()) {
144
+				$this->setInfo($identifier);
145
+				$this->rewind();
146
+				return true;
147
+			}
148
+			$this->next();
149
+		}
150
+		return false;
151
+	}
152
+
153
+
154
+	/**
155
+	 * get
156
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
157
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
158
+	 *
159
+	 * @access public
160
+	 * @param mixed $identifier
161
+	 * @return mixed
162
+	 */
163
+	public function get($identifier)
164
+	{
165
+		$this->rewind();
166
+		while ($this->valid()) {
167
+			if ($identifier === $this->getInfo()) {
168
+				$object = $this->current();
169
+				$this->rewind();
170
+				return $object;
171
+			}
172
+			$this->next();
173
+		}
174
+		return null;
175
+	}
176
+
177
+
178
+	/**
179
+	 * has
180
+	 * returns TRUE or FALSE
181
+	 * depending on whether the object is within the Collection
182
+	 * based on the supplied $identifier
183
+	 *
184
+	 * @access public
185
+	 * @param  mixed $identifier
186
+	 * @return bool
187
+	 */
188
+	public function has($identifier)
189
+	{
190
+		$this->rewind();
191
+		while ($this->valid()) {
192
+			if ($identifier === $this->getInfo()) {
193
+				$this->rewind();
194
+				return true;
195
+			}
196
+			$this->next();
197
+		}
198
+		return false;
199
+	}
200
+
201
+
202
+	/**
203
+	 * hasObject
204
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
205
+	 *
206
+	 * @access public
207
+	 * @param $object
208
+	 * @return bool
209
+	 */
210
+	public function hasObject($object)
211
+	{
212
+		return $this->contains($object);
213
+	}
214
+
215
+
216
+	/**
217
+	 * hasObjects
218
+	 * returns true if there are objects within the Collection, and false if it is empty
219
+	 *
220
+	 * @access public
221
+	 * @return bool
222
+	 */
223
+	public function hasObjects()
224
+	{
225
+		return $this->count() !== 0;
226
+	}
227
+
228
+
229
+	/**
230
+	 * isEmpty
231
+	 * returns true if there are no objects within the Collection, and false if there are
232
+	 *
233
+	 * @access public
234
+	 * @return bool
235
+	 */
236
+	public function isEmpty()
237
+	{
238
+		return $this->count() === 0;
239
+	}
240
+
241
+
242
+	/**
243
+	 * remove
244
+	 * detaches an object from the Collection
245
+	 *
246
+	 * @access public
247
+	 * @param $object
248
+	 * @return bool
249
+	 */
250
+	public function remove($object)
251
+	{
252
+		$this->detach($object);
253
+		return true;
254
+	}
255
+
256
+
257
+	/**
258
+	 * setCurrent
259
+	 * advances pointer to the object whose identifier matches that which was provided
260
+	 *
261
+	 * @access public
262
+	 * @param mixed $identifier
263
+	 * @return boolean
264
+	 */
265
+	public function setCurrent($identifier)
266
+	{
267
+		$this->rewind();
268
+		while ($this->valid()) {
269
+			if ($identifier === $this->getInfo()) {
270
+				return true;
271
+			}
272
+			$this->next();
273
+		}
274
+		return false;
275
+	}
276
+
277
+
278
+	/**
279
+	 * setCurrentUsingObject
280
+	 * advances pointer to the provided object
281
+	 *
282
+	 * @access public
283
+	 * @param $object
284
+	 * @return boolean
285
+	 */
286
+	public function setCurrentUsingObject($object)
287
+	{
288
+		$this->rewind();
289
+		while ($this->valid()) {
290
+			if ($this->current() === $object) {
291
+				return true;
292
+			}
293
+			$this->next();
294
+		}
295
+		return false;
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns the object occupying the index before the current object,
301
+	 * unless this is already the first object, in which case it just returns the first object
302
+	 *
303
+	 * @return mixed
304
+	 */
305
+	public function previous()
306
+	{
307
+		$index = $this->indexOf($this->current());
308
+		if ($index === 0) {
309
+			return $this->current();
310
+		}
311
+		$index--;
312
+		return $this->objectAtIndex($index);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Returns the index of a given object, or false if not found
318
+	 *
319
+	 * @see http://stackoverflow.com/a/8736013
320
+	 * @param $object
321
+	 * @return boolean|int|string
322
+	 */
323
+	public function indexOf($object)
324
+	{
325
+		if (! $this->contains($object)) {
326
+			return false;
327
+		}
328
+		foreach ($this as $index => $obj) {
329
+			if ($obj === $object) {
330
+				return $index;
331
+			}
332
+		}
333
+		return false;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Returns the object at the given index
339
+	 *
340
+	 * @see http://stackoverflow.com/a/8736013
341
+	 * @param int $index
342
+	 * @return mixed
343
+	 */
344
+	public function objectAtIndex($index)
345
+	{
346
+		$iterator = new LimitIterator($this, $index, 1);
347
+		$iterator->rewind();
348
+		return $iterator->current();
349
+	}
350
+
351
+
352
+	/**
353
+	 * Returns the sequence of objects as specified by the offset and length
354
+	 *
355
+	 * @see http://stackoverflow.com/a/8736013
356
+	 * @param int $offset
357
+	 * @param int $length
358
+	 * @return array
359
+	 */
360
+	public function slice($offset, $length)
361
+	{
362
+		$slice = array();
363
+		$iterator = new LimitIterator($this, $offset, $length);
364
+		foreach ($iterator as $object) {
365
+			$slice[] = $object;
366
+		}
367
+		return $slice;
368
+	}
369
+
370
+
371
+	/**
372
+	 * Inserts an object at a certain point
373
+	 *
374
+	 * @see http://stackoverflow.com/a/8736013
375
+	 * @param mixed $object A single object
376
+	 * @param int   $index
377
+	 * @param mixed $identifier
378
+	 * @return bool
379
+	 * @throws DuplicateCollectionIdentifierException
380
+	 * @throws InvalidEntityException
381
+	 */
382
+	public function insertObjectAt($object, $index, $identifier = null)
383
+	{
384
+		// check to ensure that objects don't already exist in the collection
385
+		if ($this->has($identifier)) {
386
+			throw new DuplicateCollectionIdentifierException($identifier);
387
+		}
388
+		// detach any objects at or past this index
389
+		$remaining_objects = array();
390
+		if ($index < $this->count()) {
391
+			$remaining_objects = $this->slice($index, $this->count() - $index);
392
+			foreach ($remaining_objects as $key => $remaining_object) {
393
+				// we need to grab the identifiers for each object and use them as keys
394
+				$remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
395
+				// and then remove the object from the current tracking array
396
+				unset($remaining_objects[ $key ]);
397
+				// and then remove it from the Collection
398
+				$this->detach($remaining_object);
399
+			}
400
+		}
401
+		// add the new object we're splicing in
402
+		$this->add($object, $identifier);
403
+		// attach the objects we previously detached
404
+		foreach ($remaining_objects as $key => $remaining_object) {
405
+			$this->add($remaining_object, $key);
406
+		}
407
+		return $this->contains($object);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Inserts an object (or an array of objects) at a certain point
413
+	 *
414
+	 * @see http://stackoverflow.com/a/8736013
415
+	 * @param mixed $objects A single object or an array of objects
416
+	 * @param int   $index
417
+	 */
418
+	public function insertAt($objects, $index)
419
+	{
420
+		if (! is_array($objects)) {
421
+			$objects = array($objects);
422
+		}
423
+		// check to ensure that objects don't already exist in the collection
424
+		foreach ($objects as $key => $object) {
425
+			if ($this->contains($object)) {
426
+				unset($objects[ $key ]);
427
+			}
428
+		}
429
+		// do we have any objects left?
430
+		if (! $objects) {
431
+			return;
432
+		}
433
+		// detach any objects at or past this index
434
+		$remaining = array();
435
+		if ($index < $this->count()) {
436
+			$remaining = $this->slice($index, $this->count() - $index);
437
+			foreach ($remaining as $object) {
438
+				$this->detach($object);
439
+			}
440
+		}
441
+		// add the new objects we're splicing in
442
+		foreach ($objects as $object) {
443
+			$this->attach($object);
444
+		}
445
+		// attach the objects we previously detached
446
+		foreach ($remaining as $object) {
447
+			$this->attach($object);
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 * Removes the object at the given index
454
+	 *
455
+	 * @see http://stackoverflow.com/a/8736013
456
+	 * @param int $index
457
+	 */
458
+	public function removeAt($index)
459
+	{
460
+		$this->detach($this->objectAtIndex($index));
461
+	}
462
+
463
+
464
+	/**
465
+	 * detaches ALL objects from the Collection
466
+	 */
467
+	public function detachAll()
468
+	{
469
+		$this->rewind();
470
+		while ($this->valid()) {
471
+			$object = $this->current();
472
+			$this->next();
473
+			$this->detach($object);
474
+		}
475
+	}
476
+
477
+
478
+	/**
479
+	 * unsets and detaches ALL objects from the Collection
480
+	 */
481
+	public function trashAndDetachAll()
482
+	{
483
+		$this->rewind();
484
+		while ($this->valid()) {
485
+			$object = $this->current();
486
+			$this->next();
487
+			$this->detach($object);
488
+			unset($object);
489
+		}
490
+	}
491 491
 }
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.
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/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.