Completed
Push — master ( a1df86...c22e8e )
by Aimeos
02:33
created
admin/jsonadm/src/Admin/JsonAdm/Factory.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @param integer $id Context ID the objects have been created with (string of \Aimeos\MShop\Context\Item\Iface)
34 34
 	 * @param string $path Path describing the client to clear, e.g. "product/lists/type"
35 35
 	 */
36
-	static public function clear( $id = null, $path = null )
36
+	static public function clear($id = null, $path = null)
37 37
 	{
38
-		if( $id !== null )
38
+		if ($id !== null)
39 39
 		{
40
-			if( $path !== null ) {
40
+			if ($path !== null) {
41 41
 				self::$clients[$id][$path] = null;
42 42
 			} else {
43 43
 				self::$clients[$id] = [];
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	 * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance
66 66
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If the given path is invalid
67 67
 	 */
68
-	static public function createClient( \Aimeos\MShop\Context\Item\Iface $context,
69
-		array $templatePaths, $path, $name = null )
68
+	static public function createClient(\Aimeos\MShop\Context\Item\Iface $context,
69
+		array $templatePaths, $path, $name = null)
70 70
 	{
71
-		$path = strtolower( trim( $path, "/ \n\t\r\0\x0B" ) );
71
+		$path = strtolower(trim($path, "/ \n\t\r\0\x0B"));
72 72
 		$id = (string) $context;
73 73
 
74
-		if( self::$cache === false || !isset( self::$clients[$id][$path] ) ) {
75
-			self::$clients[$id][$path] = self::createClientNew( $context, $templatePaths, $path, $name );
74
+		if (self::$cache === false || !isset(self::$clients[$id][$path])) {
75
+			self::$clients[$id][$path] = self::createClientNew($context, $templatePaths, $path, $name);
76 76
 		}
77 77
 
78 78
 		return self::$clients[$id][$path];
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @param boolean $value True to enable caching, false to disable it.
86 86
 	 * @return boolean Previous cache setting
87 87
 	 */
88
-	static public function setCache( $value )
88
+	static public function setCache($value)
89 89
 	{
90 90
 		$old = self::$cache;
91 91
 		self::$cache = (boolean) $value;
@@ -104,26 +104,26 @@  discard block
 block discarded – undo
104 104
 	 * @return \Aimeos\Admin\JsonAdm\Iface JSON admin instance
105 105
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If the given path is invalid
106 106
 	 */
107
-	protected static function createClientNew( \Aimeos\MShop\Context\Item\Iface $context,
108
-		array $templatePaths, $path, $name )
107
+	protected static function createClientNew(\Aimeos\MShop\Context\Item\Iface $context,
108
+		array $templatePaths, $path, $name)
109 109
 	{
110
-		if( !empty( $path ) )
110
+		if (!empty($path))
111 111
 		{
112
-			$parts = explode( '/', $path );
112
+			$parts = explode('/', $path);
113 113
 
114
-			foreach( $parts as $key => $part )
114
+			foreach ($parts as $key => $part)
115 115
 			{
116
-				if( ctype_alnum( $part ) === false )
116
+				if (ctype_alnum($part) === false)
117 117
 				{
118
-					$msg = sprintf( 'Invalid client "%1$s" in "%2$s"', $part, $path );
119
-					throw new \Aimeos\Admin\JsonAdm\Exception( $msg, 400 );
118
+					$msg = sprintf('Invalid client "%1$s" in "%2$s"', $part, $path);
119
+					throw new \Aimeos\Admin\JsonAdm\Exception($msg, 400);
120 120
 				}
121 121
 
122
-				$parts[$key] = ucwords( $part );
122
+				$parts[$key] = ucwords($part);
123 123
 			}
124 124
 
125
-			$name = ( $name ?: $context->getConfig()->get( 'admin/jsonadm/' . $path . '/name', 'Standard' ) );
126
-			$classname = '\\Aimeos\\Admin\\JsonAdm\\' . join( '\\', $parts ) . '\\' . $name;
125
+			$name = ($name ?: $context->getConfig()->get('admin/jsonadm/' . $path . '/name', 'Standard'));
126
+			$classname = '\\Aimeos\\Admin\\JsonAdm\\' . join('\\', $parts) . '\\' . $name;
127 127
 		}
128 128
 		else
129 129
 		{
@@ -161,25 +161,25 @@  discard block
 block discarded – undo
161 161
 			 * @category Developer
162 162
 			 */
163 163
 
164
-			$name = ( $name ?: $context->getConfig()->get( 'admin/jsonadm/name', 'Standard' ) );
164
+			$name = ($name ?: $context->getConfig()->get('admin/jsonadm/name', 'Standard'));
165 165
 			$classname = '\\Aimeos\\Admin\\JsonAdm\\' . $name;
166 166
 		}
167 167
 
168 168
 
169
-		if( ctype_alnum( $name ) === false )
169
+		if (ctype_alnum($name) === false)
170 170
 		{
171
-			$classname = is_string( $name ) ? $classname : '<not a string>';
172
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid class name "%1$s"', $classname ) );
171
+			$classname = is_string($name) ? $classname : '<not a string>';
172
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid class name "%1$s"', $classname));
173 173
 		}
174 174
 
175
-		if( class_exists( $classname ) === false ) {
175
+		if (class_exists($classname) === false) {
176 176
 			$classname = '\\Aimeos\\Admin\\JsonAdm\\' . $name;
177 177
 		}
178 178
 
179 179
 		$view = $context->getView();
180 180
 		$iface = '\\Aimeos\\Admin\\JsonAdm\\Iface';
181 181
 
182
-		$client = self::createClientBase( $classname, $iface, $context, $view, $templatePaths, $path );
182
+		$client = self::createClientBase($classname, $iface, $context, $view, $templatePaths, $path);
183 183
 
184 184
 		/** admin/jsonadm/decorators/excludes
185 185
 		 * Excludes decorators added by the "common" option from the JSON API clients
@@ -259,6 +259,6 @@  discard block
 block discarded – undo
259 259
 		 * @see admin/jsonadm/decorators/global
260 260
 		 */
261 261
 
262
-		return self::addClientDecorators( $client, $context, $view, $templatePaths, $path );
262
+		return self::addClientDecorators($client, $context, $view, $templatePaths, $path);
263 263
 	}
264 264
 }
Please login to merge, or discard this patch.
admin/jsonadm/tests/Admin/JsonAdm/FactoryTest.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 		$context = \TestHelperJadm::getContext();
17 17
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
18 18
 
19
-		$client = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
20
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client );
21
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Order\\Standard', $client );
19
+		$client = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
20
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client);
21
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Order\\Standard', $client);
22 22
 	}
23 23
 
24 24
 
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 		$context = \TestHelperJadm::getContext();
28 28
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
29 29
 
30
-		$client = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order/base' );
31
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client );
32
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Order\\Base\\Standard', $client );
30
+		$client = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order/base');
31
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client);
32
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Order\\Base\\Standard', $client);
33 33
 	}
34 34
 
35 35
 
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 		$context = \TestHelperJadm::getContext();
39 39
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
40 40
 
41
-		$client = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'stock/type' );
42
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client );
43
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Standard', $client );
41
+		$client = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'stock/type');
42
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client);
43
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Standard', $client);
44 44
 	}
45 45
 
46 46
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 		$context = \TestHelperJadm::getContext();
50 50
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
51 51
 
52
-		$client = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, '' );
53
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client );
54
-		$this->assertInstanceOf( '\\Aimeos\\Admin\\JsonAdm\\Standard', $client );
52
+		$client = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, '');
53
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Common\\Iface', $client);
54
+		$this->assertInstanceOf('\\Aimeos\\Admin\\JsonAdm\\Standard', $client);
55 55
 	}
56 56
 
57 57
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 		$context = \TestHelperJadm::getContext();
61 61
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
62 62
 
63
-		$this->setExpectedException( '\\Aimeos\\Admin\\JsonAdm\\Exception' );
64
-		\Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, '%^' );
63
+		$this->setExpectedException('\\Aimeos\\Admin\\JsonAdm\\Exception');
64
+		\Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, '%^');
65 65
 	}
66 66
 
67 67
 
@@ -70,68 +70,68 @@  discard block
 block discarded – undo
70 70
 		$context = \TestHelperJadm::getContext();
71 71
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
72 72
 
73
-		$this->setExpectedException( '\\Aimeos\\Admin\\JsonAdm\\Exception' );
74
-		\Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, '', '%^' );
73
+		$this->setExpectedException('\\Aimeos\\Admin\\JsonAdm\\Exception');
74
+		\Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, '', '%^');
75 75
 	}
76 76
 
77 77
 
78 78
 	public function testClear()
79 79
 	{
80
-		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache( true );
80
+		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache(true);
81 81
 
82 82
 		$context = \TestHelperJadm::getContext();
83 83
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
84 84
 
85
-		$client1 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
85
+		$client1 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
86 86
 		\Aimeos\Admin\JsonAdm\Factory::clear();
87
-		$client2 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
87
+		$client2 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
88 88
 
89
-		\Aimeos\Admin\JsonAdm\Factory::setCache( $cache );
89
+		\Aimeos\Admin\JsonAdm\Factory::setCache($cache);
90 90
 
91
-		$this->assertNotSame( $client1, $client2 );
91
+		$this->assertNotSame($client1, $client2);
92 92
 	}
93 93
 
94 94
 
95 95
 	public function testClearSite()
96 96
 	{
97
-		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache( true );
97
+		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache(true);
98 98
 
99 99
 		$context = \TestHelperJadm::getContext();
100 100
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
101 101
 
102
-		$cntlA1 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
103
-		$cntlB1 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order/base' );
104
-		\Aimeos\Admin\JsonAdm\Factory::clear( (string) $context );
102
+		$cntlA1 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
103
+		$cntlB1 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order/base');
104
+		\Aimeos\Admin\JsonAdm\Factory::clear((string) $context);
105 105
 
106
-		$cntlA2 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
107
-		$cntlB2 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order/base' );
106
+		$cntlA2 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
107
+		$cntlB2 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order/base');
108 108
 
109
-		\Aimeos\Admin\JsonAdm\Factory::setCache( $cache );
109
+		\Aimeos\Admin\JsonAdm\Factory::setCache($cache);
110 110
 
111
-		$this->assertNotSame( $cntlA1, $cntlA2 );
112
-		$this->assertNotSame( $cntlB1, $cntlB2 );
111
+		$this->assertNotSame($cntlA1, $cntlA2);
112
+		$this->assertNotSame($cntlB1, $cntlB2);
113 113
 	}
114 114
 
115 115
 
116 116
 	public function testClearSpecific()
117 117
 	{
118
-		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache( true );
118
+		$cache = \Aimeos\Admin\JsonAdm\Factory::setCache(true);
119 119
 
120 120
 		$context = \TestHelperJadm::getContext();
121 121
 		$templatePaths = \TestHelperJadm::getJsonadmPaths();
122 122
 
123
-		$cntlA1 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
124
-		$cntlB1 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order/base' );
123
+		$cntlA1 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
124
+		$cntlB1 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order/base');
125 125
 
126
-		\Aimeos\Admin\JsonAdm\Factory::clear( (string) $context, 'order' );
126
+		\Aimeos\Admin\JsonAdm\Factory::clear((string) $context, 'order');
127 127
 
128
-		$cntlA2 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order' );
129
-		$cntlB2 = \Aimeos\Admin\JsonAdm\Factory::createClient( $context, $templatePaths, 'order/base' );
128
+		$cntlA2 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order');
129
+		$cntlB2 = \Aimeos\Admin\JsonAdm\Factory::createClient($context, $templatePaths, 'order/base');
130 130
 
131
-		\Aimeos\Admin\JsonAdm\Factory::setCache( $cache );
131
+		\Aimeos\Admin\JsonAdm\Factory::setCache($cache);
132 132
 
133
-		$this->assertNotSame( $cntlA1, $cntlA2 );
134
-		$this->assertSame( $cntlB1, $cntlB2 );
133
+		$this->assertNotSame($cntlA1, $cntlA2);
134
+		$this->assertSame($cntlB1, $cntlB2);
135 135
 	}
136 136
 
137 137
 }
138 138
\ No newline at end of file
Please login to merge, or discard this patch.