Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
106 / 106 |
|
100.00% |
13 / 13 |
CRAP | |
100.00% |
1 / 1 |
| Defaults | |
100.00% |
106 / 106 |
|
100.00% |
13 / 13 |
13 | |
100.00% |
1 / 1 |
| values | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| app | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| auth | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| paths | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| panel | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| error | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| icons | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| database | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| session | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| media | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| upload | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 | |||
| uid | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| password | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Config; |
| 6 | |
| 7 | use Cosray\Uid as UidGenerator; |
| 8 | use Cosray\Util\Password; |
| 9 | |
| 10 | use function Cosray\env; |
| 11 | |
| 12 | final class Defaults |
| 13 | { |
| 14 | /** @return array<string, mixed> */ |
| 15 | public static function values(string $root, Env $env): array |
| 16 | { |
| 17 | return array_merge( |
| 18 | self::app($env), |
| 19 | self::auth($env), |
| 20 | self::paths($root), |
| 21 | self::panel(), |
| 22 | self::error(), |
| 23 | self::icons(), |
| 24 | self::database(), |
| 25 | self::session($env), |
| 26 | self::media(), |
| 27 | self::upload(), |
| 28 | self::uid(), |
| 29 | self::password(), |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** @return array<string, mixed> */ |
| 34 | private static function app(Env $env): array |
| 35 | { |
| 36 | return [ |
| 37 | 'app.name' => env('APP_NAME', 'cosray'), |
| 38 | 'app.debug' => $env->bool('APP_DEBUG', false), |
| 39 | 'app.env' => env('APP_ENV', ''), |
| 40 | 'app.secret' => env('APP_SECRET', null), |
| 41 | 'app.timezone' => env('APP_TIMEZONE', 'UTC'), |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | /** @return array<string, mixed> */ |
| 46 | private static function auth(Env $env): array |
| 47 | { |
| 48 | return [ |
| 49 | 'auth.remember_lifetime' => $env->int('AUTH_REMEMBER_LIFETIME', 60 * 60 * 24 * 30), |
| 50 | ]; |
| 51 | } |
| 52 | |
| 53 | /** @return array<string, mixed> */ |
| 54 | private static function paths(string $root): array |
| 55 | { |
| 56 | return [ |
| 57 | 'path.root' => $root, |
| 58 | 'path.public' => $root . '/public', |
| 59 | 'path.prefix' => '', |
| 60 | 'path.assets' => '/assets', |
| 61 | 'path.cache' => '/cache', |
| 62 | 'path.views' => '/views', |
| 63 | 'path.panel' => '/cp', |
| 64 | 'path.api' => null, |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | /** @return array<string, mixed> */ |
| 69 | private static function panel(): array |
| 70 | { |
| 71 | return [ |
| 72 | 'panel.theme' => [], |
| 73 | 'panel.logo' => '/images/logo.png', |
| 74 | ]; |
| 75 | } |
| 76 | |
| 77 | /** @return array<string, mixed> */ |
| 78 | private static function error(): array |
| 79 | { |
| 80 | return [ |
| 81 | 'error.enabled' => true, |
| 82 | 'error.renderer' => null, |
| 83 | 'error.trusted' => [], |
| 84 | 'error.views' => null, |
| 85 | 'error.whoops' => true, |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | /** @return array<string, mixed> */ |
| 90 | private static function icons(): array |
| 91 | { |
| 92 | return [ |
| 93 | 'icons.local.paths' => [], |
| 94 | 'icons.iconify.base_url' => 'https://api.iconify.design', |
| 95 | 'icons.iconify.timeout' => 5, |
| 96 | 'icons.iconify.user_agent' => 'cosray/cms', |
| 97 | ]; |
| 98 | } |
| 99 | |
| 100 | /** @return array<string, mixed> */ |
| 101 | private static function database(): array |
| 102 | { |
| 103 | return [ |
| 104 | 'db.dsn' => env('DATABASE_URL', null), |
| 105 | 'db.sql' => [], |
| 106 | 'db.migrations' => [], |
| 107 | 'db.placeholders' => [ |
| 108 | 'all' => [ |
| 109 | 'cms.prefix' => 'cms_', |
| 110 | ], |
| 111 | 'pgsql' => [ |
| 112 | 'cms.prefix' => 'cms.', |
| 113 | ], |
| 114 | ], |
| 115 | 'db.print' => false, |
| 116 | 'db.options' => [], |
| 117 | ]; |
| 118 | } |
| 119 | |
| 120 | /** @return array<string, mixed> */ |
| 121 | private static function session(Env $env): array |
| 122 | { |
| 123 | return [ |
| 124 | 'session.enabled' => $env->bool('SITE_SESSION_ENABLED', false), |
| 125 | 'session.options' => [ |
| 126 | 'cookie_httponly' => true, |
| 127 | 'cookie_samesite' => 'Lax', |
| 128 | 'cookie_secure' => $env->bool('SESSION_COOKIE_SECURE', true), |
| 129 | 'cookie_lifetime' => $env->int('SESSION_COOKIE_LIFETIME', 0), |
| 130 | 'gc_maxlifetime' => $env->int('SESSION_IDLE_TIMEOUT', 60 * 60 * 8), |
| 131 | 'cache_expire' => 3600, |
| 132 | ], |
| 133 | 'session.handler' => null, |
| 134 | ]; |
| 135 | } |
| 136 | |
| 137 | /** @return array<string, mixed> */ |
| 138 | private static function media(): array |
| 139 | { |
| 140 | return [ |
| 141 | 'media.fileserver' => null, |
| 142 | ]; |
| 143 | } |
| 144 | |
| 145 | /** @return array<string, mixed> */ |
| 146 | private static function upload(): array |
| 147 | { |
| 148 | return [ |
| 149 | 'upload.mimetypes.file' => [ |
| 150 | 'application/pdf' => ['pdf'], |
| 151 | ], |
| 152 | 'upload.mimetypes.image' => [ |
| 153 | 'image/gif' => ['gif'], |
| 154 | 'image/jpeg' => ['jpeg', 'jpg', 'jfif'], |
| 155 | 'image/png' => ['png'], |
| 156 | 'image/webp' => ['webp'], |
| 157 | 'image/svg+xml' => ['svg'], |
| 158 | ], |
| 159 | 'upload.mimetypes.video' => [ |
| 160 | 'video/mp4' => ['mp4'], |
| 161 | 'video/ogg' => ['ogg'], |
| 162 | ], |
| 163 | 'upload.maxsize' => 10 * 1024 * 1024, |
| 164 | ]; |
| 165 | } |
| 166 | |
| 167 | /** @return array<string, mixed> */ |
| 168 | private static function uid(): array |
| 169 | { |
| 170 | return [ |
| 171 | 'uid.alphabet' => UidGenerator::ALPHABET_LOWERCASE_WORD_SAFE, |
| 172 | 'uid.length' => 13, |
| 173 | ]; |
| 174 | } |
| 175 | |
| 176 | /** @return array<string, mixed> */ |
| 177 | private static function password(): array |
| 178 | { |
| 179 | return [ |
| 180 | 'password.entropy' => Password::DEFAULT_PASSWORD_ENTROPY, |
| 181 | 'password.algorithm' => null, |
| 182 | ]; |
| 183 | } |
| 184 | } |