slickframework /
web-stack
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of php-scaffold |
||
| 5 | * |
||
| 6 | * For the full copyright and license information, please view the LICENSE |
||
| 7 | * file that was distributed with this source code. |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace config\services; |
||
| 11 | |||
| 12 | use Psr\Http\Message\ServerRequestInterface; |
||
| 13 | use Psr\Log\LoggerInterface; |
||
| 14 | use Slick\Di\ContainerInterface; |
||
| 15 | use Slick\Di\Definition\ObjectDefinition; |
||
| 16 | use Slick\Http\Session\SessionDriverInterface; |
||
| 17 | use Slick\WebStack\Domain\Security\Authentication\Token\Storage\TokenStorage; |
||
| 18 | use Slick\WebStack\Domain\Security\Authentication\Token\TokenStorageInterface as SessionTokenStorageInterface; |
||
| 19 | use Slick\WebStack\Domain\Security\AuthorizationCheckerInterface; |
||
| 20 | use Slick\WebStack\Domain\Security\Csrf\CsrfTokenManager; |
||
| 21 | use Slick\WebStack\Domain\Security\Csrf\CsrfTokenManagerInterface; |
||
| 22 | use Slick\WebStack\Domain\Security\Csrf\TokenGenerator\UriSafeTokenGenerator; |
||
| 23 | use Slick\WebStack\Domain\Security\Csrf\TokenStorage\SessionCsrfTokenStorage; |
||
| 24 | use Slick\WebStack\Domain\Security\Csrf\TokenStorageInterface; |
||
| 25 | use Slick\WebStack\Domain\Security\Http\RememberMe\RememberMeHandlerInterface; |
||
| 26 | use Slick\WebStack\Domain\Security\Http\RememberMe\SignatureRememberMeHandler; |
||
| 27 | use Slick\WebStack\Domain\Security\Http\SecurityProfileFactory; |
||
| 28 | use Slick\WebStack\Domain\Security\PasswordHasher\Hasher\Pbkdf2PasswordHasher; |
||
| 29 | use Slick\WebStack\Domain\Security\PasswordHasher\Hasher\PhpPasswordHasher; |
||
| 30 | use Slick\WebStack\Domain\Security\PasswordHasher\Hasher\PlaintextPasswordHasher; |
||
| 31 | use Slick\WebStack\Domain\Security\PasswordHasher\PasswordHasherInterface; |
||
| 32 | use Slick\WebStack\Domain\Security\Security; |
||
| 33 | use Slick\WebStack\Domain\Security\SecurityAuthenticatorInterface; |
||
| 34 | use Slick\WebStack\Domain\Security\Signature\SignatureHasher; |
||
|
0 ignored issues
–
show
|
|||
| 35 | use Slick\WebStack\Domain\Security\User\UserProviderInterface; |
||
| 36 | use function Slick\ModuleApi\importSettingsFile; |
||
| 37 | |||
| 38 | $services = []; |
||
| 39 | |||
| 40 | $services[SecurityProfileFactory::class] = function (ContainerInterface $container) { |
||
| 41 | return new SecurityProfileFactory($container); |
||
| 42 | }; |
||
| 43 | |||
| 44 | $securityVariable = '@security'; |
||
| 45 | $services[SecurityAuthenticatorInterface::class] = $securityVariable; |
||
| 46 | $services[AuthorizationCheckerInterface::class] = $securityVariable; |
||
| 47 | $services[Security::class] = $securityVariable; |
||
| 48 | $services['security'] = function (ContainerInterface $container) { |
||
| 49 | $securityConfigPath = APP_ROOT . '/config/security.php'; |
||
| 50 | if (!is_file($securityConfigPath)) { |
||
| 51 | file_put_contents($securityConfigPath, file_get_contents(__DIR__.'/default-security.settings.php')); |
||
| 52 | } |
||
| 53 | |||
| 54 | return new Security( |
||
| 55 | $container->get(SecurityProfileFactory::class), |
||
| 56 | $container->get('security.token.storage'), |
||
| 57 | importSettingsFile($securityConfigPath), |
||
| 58 | $container->get(SessionDriverInterface::class) |
||
| 59 | ); |
||
| 60 | }; |
||
| 61 | |||
| 62 | $services[TokenStorageInterface::class] = '@security.token.storage'; |
||
| 63 | $services['security.token.storage'] = ObjectDefinition::create(TokenStorage::class); |
||
| 64 | |||
| 65 | $services[RememberMeHandlerInterface::class] = function (ContainerInterface $container) { |
||
| 66 | return new SignatureRememberMeHandler( |
||
| 67 | $container->get(SignatureHasher::class), |
||
| 68 | $container->get(UserProviderInterface::class), |
||
| 69 | $container->get(ServerRequestInterface::class), |
||
| 70 | $container->get('remember.me.cookie.options'), |
||
| 71 | $container->get(LoggerInterface::class) |
||
| 72 | ); |
||
| 73 | }; |
||
| 74 | |||
| 75 | //------------------------------------------------------------------ |
||
| 76 | // Session storage |
||
| 77 | //------------------------------------------------------------------ |
||
| 78 | $services[SessionTokenStorageInterface::class] = '@security.token.storage'; |
||
| 79 | |||
| 80 | $envAppSecret = $_ENV["APP_SECRET"] ?? ''; |
||
| 81 | //------------------------------------------------------------------ |
||
| 82 | // Password hasher |
||
| 83 | //------------------------------------------------------------------ |
||
| 84 | $services[PasswordHasherInterface::class] = '@password.hasher'; |
||
| 85 | $services[PhpPasswordHasher::class] = '@password.hasher'; |
||
| 86 | $services['password.hasher'] = function () { |
||
| 87 | return new PhpPasswordHasher(); |
||
| 88 | }; |
||
| 89 | $services[Pbkdf2PasswordHasher::class] = fn() => new Pbkdf2PasswordHasher(salt: $envAppSecret); |
||
| 90 | $services[PlaintextPasswordHasher::class] = fn() => new PlaintextPasswordHasher(); |
||
| 91 | |||
| 92 | $services[CsrfTokenManagerInterface::class] = function (ContainerInterface $container) { |
||
| 93 | $session = $container->get(SessionDriverInterface::class); |
||
| 94 | return new CsrfTokenManager(new SessionCsrfTokenStorage($session), new UriSafeTokenGenerator()); |
||
| 95 | }; |
||
| 96 | |||
| 97 | return $services; |
||
| 98 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths