PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / vendor / typisttech / imposter / src / Config.php

Config.php in Code Snippets 3.10.0, at vendor/typisttech/imposter/src/Config.php

82 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace TypistTech\Imposter;
6
7 class Config implements ConfigInterface
8 {
9 /**
10 * @var string
11 */
12 protected $packageDir;
13
14 /**
15 * @var array
16 */
17 private $config;
18
19 public function __construct(string $packageDir, array $config)
20 {
21 $this->packageDir = StringUtil::addTrailingSlash($packageDir);
22 $this->config = $config;
23 }
24
25 /**
26 * @return string[]
27 */
28 public function getAutoloads(): array
29 {
30 return array_map(function (string $autoload): string {
31 return $this->packageDir . $autoload;
32 }, array_unique($this->getAutoloadPaths()));
33 }
34
35 /**
36 * @return string[]
37 */
38 private function getAutoloadPaths(): array
39 {
40 $autoloads = $this->get('autoload');
41 unset($autoloads['exclude-from-classmap']);
42
43 return ArrayUtil::flattenMap(function ($autoloadConfig): array {
44 return $this->normalizeAutoload($autoloadConfig);
45 }, $autoloads);
46 }
47
48 protected function get(string $key): array
49 {
50 return $this->config[$key] ?? [];
51 }
52
53 /**
54 * @param $autoloadConfigs
55 *
56 * @return string[]
57 */
58 private function normalizeAutoload($autoloadConfigs): array
59 {
60 if (! is_array($autoloadConfigs)) {
61 return [$autoloadConfigs];
62 }
63
64 return ArrayUtil::flattenMap(function ($autoloadConfig): array {
65 return $this->normalizeAutoload($autoloadConfig);
66 }, $autoloadConfigs);
67 }
68
69 public function getPackageDir(): string
70 {
71 return $this->packageDir;
72 }
73
74 /**
75 * @return string[]
76 */
77 public function getRequires(): array
78 {
79 return array_keys($this->get('require'));
80 }
81 }
82