Compare commits
6 Commits
5e68f7dd64
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ece0147b3a | |||
| d133898383 | |||
| 9f8c2b1959 | |||
| 404e2089eb | |||
| 58c9b298db | |||
| 72415949e3 |
@@ -41,6 +41,10 @@ ContainerFactory::build(Environment $env, Config $config, string $basePath): Con
|
||||
|
||||
- Autowiring включён всегда
|
||||
- В prod: `$builder->enableCompilation($basePath . '/var/cache/prod/')`
|
||||
- Автоматически регистрирует `Config::class`, `Environment::class` и `LoggerInterface::class`
|
||||
в контейнере — любой класс может получить их через DI без ручного биндинга в `services.php`
|
||||
- `LoggerInterface` по умолчанию резолвится в `CompositeLogger([StdoutLogger])`;
|
||||
если задан `log.file` — добавляется `FileLogger`
|
||||
- Загружает `$basePath/config/routes.php` (если есть) — файл возвращает `RouteDefinition[]`,
|
||||
фреймворк автоматически создаёт `Router` и регистрирует его в контейнере
|
||||
- Загружает `$basePath/config/services.php` (если есть) — файл возвращает
|
||||
|
||||
@@ -28,8 +28,8 @@ final class JwtService
|
||||
$signer = new Sha256();
|
||||
$key = InMemory::plainText($secret);
|
||||
|
||||
$this->jwtConfig = Configuration::forSymmetricSigner($signer, $key);
|
||||
$this->jwtConfig->setValidationConstraints(
|
||||
$jwtConfig = Configuration::forSymmetricSigner($signer, $key);
|
||||
$this->jwtConfig = $jwtConfig->withValidationConstraints(
|
||||
new SignedWith($signer, $key),
|
||||
new StrictValidAt(new class implements ClockInterface {
|
||||
public function now(): DateTimeImmutable
|
||||
@@ -45,6 +45,7 @@ final class JwtService
|
||||
$now = new DateTimeImmutable();
|
||||
$token = $this->jwtConfig->builder()
|
||||
->issuedAt($now)
|
||||
->canOnlyBeUsedAfter($now)
|
||||
->expiresAt($now->modify("+{$this->accessTtl} seconds"))
|
||||
->relatedTo($userId)
|
||||
->getToken($this->jwtConfig->signer(), $this->jwtConfig->signingKey());
|
||||
|
||||
@@ -5,6 +5,10 @@ namespace Pronchev\Pinecore;
|
||||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
use Pronchev\Pinecore\Http\Router;
|
||||
use Pronchev\Pinecore\Log\CompositeLogger;
|
||||
use Pronchev\Pinecore\Log\FileLogger;
|
||||
use Pronchev\Pinecore\Log\StdoutLogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ContainerFactory
|
||||
{
|
||||
@@ -20,7 +24,19 @@ class ContainerFactory
|
||||
$builder->enableCompilation($cacheDir);
|
||||
}
|
||||
|
||||
$builder->useAutowiring(true);
|
||||
$builder->useAttributes(true);
|
||||
|
||||
$builder->addDefinitions([
|
||||
Config::class => $config,
|
||||
Environment::class => $env,
|
||||
LoggerInterface::class => function ($c) use ($config) {
|
||||
$loggers = [$c->get(StdoutLogger::class)];
|
||||
if ($config->get('log.file')) {
|
||||
$loggers[] = $c->get(FileLogger::class);
|
||||
}
|
||||
return new CompositeLogger($loggers);
|
||||
},
|
||||
]);
|
||||
|
||||
$routesFile = $basePath . '/config/routes.php';
|
||||
if (file_exists($routesFile)) {
|
||||
|
||||
@@ -20,9 +20,7 @@ final class MongoHydrator
|
||||
$propName = $field->property->getName();
|
||||
$value = $doc[$key] ?? null;
|
||||
|
||||
if ($value instanceof \MongoDB\Model\BSONArray) {
|
||||
$value = $value->getArrayCopy();
|
||||
}
|
||||
$value = $this->normalizeBson($value);
|
||||
|
||||
if ($field->isEmbedded && $value !== null) {
|
||||
$value = $this->hydrate($field->embeddedClass, $this->toArray($value));
|
||||
@@ -72,6 +70,19 @@ final class MongoHydrator
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function normalizeBson(mixed $value): mixed
|
||||
{
|
||||
if ($value instanceof \MongoDB\Model\BSONArray) {
|
||||
return array_map($this->normalizeBson(...), $value->getArrayCopy());
|
||||
}
|
||||
|
||||
if ($value instanceof BSONDocument) {
|
||||
return array_map($this->normalizeBson(...), iterator_to_array($value));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function toArray(array|BSONDocument $doc): array
|
||||
{
|
||||
if ($doc instanceof BSONDocument) {
|
||||
|
||||
Reference in New Issue
Block a user