Compare commits

..

6 Commits

Author SHA1 Message Date
ece0147b3a Fix MongoHydrator BSON handling 2026-04-12 01:57:12 +03:00
d133898383 Enable PHP DI attributes 2026-04-12 01:50:07 +03:00
9f8c2b1959 Fix missing nbf 2026-04-12 01:40:54 +03:00
404e2089eb Remove deprecated method 2026-04-12 01:24:19 +03:00
58c9b298db Register Logger 2026-04-06 20:38:57 +03:00
72415949e3 Register Config and Environment 2026-04-06 20:30:34 +03:00
4 changed files with 38 additions and 6 deletions

View File

@@ -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` (если есть) — файл возвращает

View File

@@ -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());

View File

@@ -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)) {

View File

@@ -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) {