@@ -21,17 +21,17 @@ |
||
21 | 21 | $contextsArray = array_reverse(explode('-', $context)); |
22 | 22 | $module = new AssistedModule; |
23 | 23 | foreach ($contextsArray as $contextItem) { |
24 | - $class = $appMeta->name . '\Module\\' . ucwords($contextItem) . 'Module'; |
|
25 | - if (! class_exists($class)) { |
|
26 | - $class = 'BEAR\Package\Context\\' . ucwords($contextItem) . 'Module'; |
|
24 | + $class = $appMeta->name.'\Module\\'.ucwords($contextItem).'Module'; |
|
25 | + if (!class_exists($class)) { |
|
26 | + $class = 'BEAR\Package\Context\\'.ucwords($contextItem).'Module'; |
|
27 | 27 | } |
28 | - if (! is_a($class, AbstractModule::class, true)) { |
|
28 | + if (!is_a($class, AbstractModule::class, true)) { |
|
29 | 29 | throw new InvalidContextException($contextItem); |
30 | 30 | } |
31 | 31 | /* @var $module AbstractModule */ |
32 | 32 | $module = is_subclass_of($class, AbstractAppModule::class) ? new $class($appMeta, $module) : new $class($module); |
33 | 33 | } |
34 | - if (! $module instanceof AbstractModule) { |
|
34 | + if (!$module instanceof AbstractModule) { |
|
35 | 35 | throw new InvalidModuleException; // @codeCoverageIgnore |
36 | 36 | } |
37 | 37 | $module->override(new AppMetaModule($appMeta)); |
@@ -22,10 +22,10 @@ |
||
22 | 22 | |
23 | 23 | public function __invoke(string $path) : void |
24 | 24 | { |
25 | - if ($this->isOptional && file_exists($path . '/.do_not_clear')) { |
|
25 | + if ($this->isOptional && file_exists($path.'/.do_not_clear')) { |
|
26 | 26 | return; |
27 | 27 | } |
28 | - foreach ((array) glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*') as $file) { |
|
28 | + foreach ((array) glob(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'*') as $file) { |
|
29 | 29 | is_dir((string) $file) ? $this->__invoke((string) $file) : unlink((string) $file); |
30 | 30 | @rmdir((string) $file); |
31 | 31 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | public function get() : Logger |
29 | 29 | { |
30 | 30 | $format = "[%datetime%] %level_name%: %message% %context%\n"; |
31 | - $stream = new StreamHandler($this->appMeta->logDir . '/app.log', Logger::DEBUG); |
|
31 | + $stream = new StreamHandler($this->appMeta->logDir.'/app.log', Logger::DEBUG); |
|
32 | 32 | $stream->setFormatter(new LineFormatter($format)); |
33 | 33 | |
34 | 34 | return new Logger($this->appMeta->name, [$stream]); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | private function getParams(string $method, array $server, array $post) : array |
88 | 88 | { |
89 | 89 | // post data exists |
90 | - if ($method === 'post' && ! empty($post)) { |
|
90 | + if ($method === 'post' && !empty($post)) { |
|
91 | 91 | return $post; |
92 | 92 | } |
93 | 93 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | return $put; |
112 | 112 | } |
113 | 113 | $isApplicationJson = strpos($contentType, self::APPLICATION_JSON) !== false; |
114 | - if (! $isApplicationJson) { |
|
114 | + if (!$isApplicationJson) { |
|
115 | 115 | return []; |
116 | 116 | } |
117 | 117 | $content = json_decode($this->getRawBody($server), true); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function __invoke(string $appName, string $context, string $appDir) : string |
42 | 42 | { |
43 | - $this->ns = (string) filemtime(realpath($appDir) . '/src'); |
|
43 | + $this->ns = (string) filemtime(realpath($appDir).'/src'); |
|
44 | 44 | $this->registerLoader($appDir); |
45 | 45 | $appMeta = new Meta($appName, $context, $appDir); |
46 | 46 | $autoload = $this->compileAutoload($appMeta, $context); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $module = (new Module)($appMeta, $context); |
49 | 49 | $this->compileSrc($module, $appMeta, $context); |
50 | 50 | $this->compileDiScripts($appMeta, $context); |
51 | - $logFile = realpath($appMeta->logDir) . '/compile.log'; |
|
51 | + $logFile = realpath($appMeta->logDir).'/compile.log'; |
|
52 | 52 | file_put_contents($logFile, (string) $module); |
53 | 53 | |
54 | 54 | return sprintf("Compile Log: %s\nautoload.php: %s\npreload.php: %s", $logFile, $autoload, $preload); |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | |
57 | 57 | public function registerLoader(string $appDir) : void |
58 | 58 | { |
59 | - $loaderFile = $appDir . '/vendor/autoload.php'; |
|
60 | - if (! file_exists($loaderFile)) { |
|
59 | + $loaderFile = $appDir.'/vendor/autoload.php'; |
|
60 | + if (!file_exists($loaderFile)) { |
|
61 | 61 | throw new \RuntimeException('no loader'); |
62 | 62 | } |
63 | 63 | $loaderFile = require $loaderFile; |
64 | 64 | spl_autoload_register( |
65 | - function ($class) use ($loaderFile) : void { |
|
65 | + function($class) use ($loaderFile) : void { |
|
66 | 66 | $loaderFile->loadClass($class); |
67 | 67 | if ($class !== NullPage::class) { |
68 | 68 | $this->classes[] = $class; |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | |
119 | 119 | private function dumpAutoload(string $appDir, array $paths) : string |
120 | 120 | { |
121 | - $autoloadFile = '<?php' . PHP_EOL; |
|
121 | + $autoloadFile = '<?php'.PHP_EOL; |
|
122 | 122 | foreach ($paths as $path) { |
123 | 123 | $autoloadFile .= sprintf( |
124 | 124 | "require %s';\n", |
125 | 125 | $this->getRelativePath($appDir, $path) |
126 | 126 | ); |
127 | 127 | } |
128 | - $autoloadFile .= "require __DIR__ . '/vendor/autoload.php';" . PHP_EOL; |
|
129 | - $loaderFile = realpath($appDir) . '/autoload.php'; |
|
128 | + $autoloadFile .= "require __DIR__ . '/vendor/autoload.php';".PHP_EOL; |
|
129 | + $loaderFile = realpath($appDir).'/autoload.php'; |
|
130 | 130 | file_put_contents($loaderFile, $autoloadFile); |
131 | 131 | |
132 | 132 | return $loaderFile; |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | { |
137 | 137 | $this->loadResources($appMeta->name, $context, $appMeta->appDir); |
138 | 138 | $paths = $this->getPaths($this->classes, $appMeta->appDir); |
139 | - $output = '<?php' . PHP_EOL; |
|
140 | - $output .= "require __DIR__ . '/vendor/autoload.php';" . PHP_EOL; |
|
139 | + $output = '<?php'.PHP_EOL; |
|
140 | + $output .= "require __DIR__ . '/vendor/autoload.php';".PHP_EOL; |
|
141 | 141 | foreach ($paths as $path) { |
142 | 142 | $output .= sprintf( |
143 | 143 | "require %s';\n", |
144 | 144 | $this->getRelativePath($appMeta->appDir, $path) |
145 | 145 | ); |
146 | 146 | } |
147 | - $preloadFile = realpath($appMeta->appDir) . '/preload.php'; |
|
147 | + $preloadFile = realpath($appMeta->appDir).'/preload.php'; |
|
148 | 148 | file_put_contents($preloadFile, $output); |
149 | 149 | |
150 | 150 | return $preloadFile; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | { |
155 | 155 | $dir = (string) realpath($rootDir); |
156 | 156 | if (strpos($file, $dir) !== false) { |
157 | - return (string) preg_replace('#^' . preg_quote($dir, '#') . '#', "__DIR__ . '", $file); |
|
157 | + return (string) preg_replace('#^'.preg_quote($dir, '#').'#', "__DIR__ . '", $file); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return $file; |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | private function saveNamedParam(NamedParameterInterface $namedParameter, object $instance, string $method) : void |
201 | 201 | { |
202 | 202 | // named parameter |
203 | - if (! \in_array($method, ['onGet', 'onPost', 'onPut', 'onPatch', 'onDelete', 'onHead'], true)) { |
|
203 | + if (!\in_array($method, ['onGet', 'onPost', 'onPut', 'onPatch', 'onDelete', 'onHead'], true)) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | $callable = [$instance, $method]; |
207 | - if (! is_callable($callable)) { |
|
207 | + if (!is_callable($callable)) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | try { |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | $paths = []; |
220 | 220 | foreach ($classes as $class) { |
221 | 221 | // could be phpdoc tag by annotation loader |
222 | - $isAutoloadFailed = ! class_exists($class, false) && ! interface_exists($class, false) && ! trait_exists($class, false); |
|
222 | + $isAutoloadFailed = !class_exists($class, false) && !interface_exists($class, false) && !trait_exists($class, false); |
|
223 | 223 | if ($isAutoloadFailed) { |
224 | 224 | continue; |
225 | 225 | } |
226 | 226 | $filePath = (string) (new ReflectionClass($class))->getFileName(); |
227 | - if (! file_exists($filePath) || strpos($filePath, 'phar') === 0) { |
|
227 | + if (!file_exists($filePath) || strpos($filePath, 'phar') === 0) { |
|
228 | 228 | continue; |
229 | 229 | } |
230 | 230 | $paths[] = $this->getRelativePath($appDir, $filePath); |
@@ -31,11 +31,11 @@ |
||
31 | 31 | |
32 | 32 | public function newApp(AbstractAppMeta $appMeta, string $contexts, Cache $cache = null, string $cacheNamespace = null) : AbstractApp |
33 | 33 | { |
34 | - $cacheNamespace = is_string($cacheNamespace) ? $cacheNamespace : (string) filemtime($appMeta->appDir . '/src'); |
|
34 | + $cacheNamespace = is_string($cacheNamespace) ? $cacheNamespace : (string) filemtime($appMeta->appDir.'/src'); |
|
35 | 35 | $injector = new AppInjector($appMeta->name, $contexts, $appMeta, $cacheNamespace); |
36 | 36 | $cache = $cache instanceof Cache ? $cache : $injector->getCachedInstance(Cache::class); // array cache in non-production |
37 | 37 | assert($cache instanceof Cache); |
38 | - $appId = $appMeta->name . $contexts . $cacheNamespace; |
|
38 | + $appId = $appMeta->name.$contexts.$cacheNamespace; |
|
39 | 39 | $app = $cache->fetch($appId); |
40 | 40 | if ($app instanceof AbstractApp) { |
41 | 41 | return $app; |
@@ -29,7 +29,7 @@ |
||
29 | 29 | protected function configure() : void |
30 | 30 | { |
31 | 31 | $this->bind(AbstractAppMeta::class)->toInstance($this->appMeta); |
32 | - $this->bind(AppInterface::class)->to($this->appMeta->name . '\Module\App')->in(Scope::SINGLETON); |
|
32 | + $this->bind(AppInterface::class)->to($this->appMeta->name.'\Module\App')->in(Scope::SINGLETON); |
|
33 | 33 | $this->bind()->annotatedWith(AppName::class)->toInstance($this->appMeta->name); |
34 | 34 | } |
35 | 35 | } |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | $this->context = $context; |
57 | 57 | $this->appMeta = $appMeta instanceof AbstractAppMeta ? $appMeta : new Meta($name, $context); |
58 | 58 | $this->cacheNamespace = (string) $cacheNamespace; |
59 | - $scriptDir = $this->appMeta->tmpDir . '/di'; |
|
60 | - ! is_dir($scriptDir) && ! @mkdir($scriptDir) && ! is_dir($scriptDir); |
|
59 | + $scriptDir = $this->appMeta->tmpDir.'/di'; |
|
60 | + !is_dir($scriptDir) && !@mkdir($scriptDir) && !is_dir($scriptDir); |
|
61 | 61 | $this->scriptDir = $scriptDir; |
62 | - $appDir = $this->appMeta->tmpDir . '/app'; |
|
63 | - ! is_dir($appDir) && ! @mkdir($appDir) && ! is_dir($appDir); |
|
64 | - touch($appDir . '/.do_not_clear'); |
|
62 | + $appDir = $this->appMeta->tmpDir.'/app'; |
|
63 | + !is_dir($appDir) && !@mkdir($appDir) && !is_dir($appDir); |
|
64 | + touch($appDir.'/.do_not_clear'); |
|
65 | 65 | $this->appDir = $appDir; |
66 | - $this->injector = new ScriptInjector($this->scriptDir, function () { |
|
66 | + $this->injector = new ScriptInjector($this->scriptDir, function() { |
|
67 | 67 | return $this->getModule(); |
68 | 68 | }); |
69 | 69 | if ($cacheNamespace === null) { |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | if ((new Unlink)->once($this->appMeta->tmpDir)) { |
101 | 101 | return; |
102 | 102 | } |
103 | - $diDir = $this->appMeta->tmpDir . '/di'; |
|
104 | - ! is_dir($diDir) && ! @mkdir($diDir) && ! is_dir($diDir); |
|
105 | - file_put_contents($this->scriptDir . ScriptInjector::MODULE, serialize($this->getModule())); |
|
103 | + $diDir = $this->appMeta->tmpDir.'/di'; |
|
104 | + !is_dir($diDir) && !@mkdir($diDir) && !is_dir($diDir); |
|
105 | + file_put_contents($this->scriptDir.ScriptInjector::MODULE, serialize($this->getModule())); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | public function getCachedInstance(string $interface, string $name = Name::ANY) |
112 | 112 | { |
113 | 113 | $cache = new FilesystemCache($this->appDir); |
114 | - $id = $interface . $name . $this->context . $this->cacheNamespace; |
|
114 | + $id = $interface.$name.$this->context.$this->cacheNamespace; |
|
115 | 115 | $instance = $cache->fetch($id); |
116 | 116 | if ($instance) { |
117 | 117 | return $instance; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | public static function getInstance(string $appName, string $context, string $appDir, string $cacheNamespace = '') : InjectorInterface |
32 | 32 | { |
33 | - $injectorId = $appName . $context . $cacheNamespace; |
|
33 | + $injectorId = $appName.$context.$cacheNamespace; |
|
34 | 34 | if (isset(self::$instances[$injectorId])) { |
35 | 35 | return unserialize(self::$instances[$injectorId], ['allowed_classes' => true]); // __wakeup the injector |
36 | 36 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | |
46 | 46 | private static function factory(Meta $meta, string $context, string $cacheNamespace, ChainCache $cache) : InjectorInterface |
47 | 47 | { |
48 | - $scriptDir = $meta->tmpDir . '/di'; |
|
49 | - ! is_dir($scriptDir) && ! @mkdir($scriptDir) && ! is_dir($scriptDir); |
|
48 | + $scriptDir = $meta->tmpDir.'/di'; |
|
49 | + !is_dir($scriptDir) && !@mkdir($scriptDir) && !is_dir($scriptDir); |
|
50 | 50 | $module = (new Module)($meta, $context, $cacheNamespace); |
51 | 51 | $rayInjector = new RayInjector($module, $scriptDir); |
52 | 52 | $isDev = $rayInjector->getInstance(Cache::class) instanceof ArrayCache; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | return $rayInjector; |
57 | 57 | } |
58 | - $scriptInjector = new ScriptInjector($scriptDir, function () use ($scriptDir, $module) { |
|
58 | + $scriptInjector = new ScriptInjector($scriptDir, function() use ($scriptDir, $module) { |
|
59 | 59 | return new ScriptinjectorModule($scriptDir, $module); |
60 | 60 | }); |
61 | 61 | $scriptInjector->getInstance(AppInterface::class); // cache App as a singleton |