В cycle orm Не ресолвится роль, Что и где я упустил?

Причём схема компилируется, об этом сужу по тому, что изменения анотации в сущности приводят к изменению в БД
подключаю Cycle orm так:

// Cycle DBAL
    DatabaseManager::class => function (ContainerInterface $container) {
        return new Database\DatabaseManager(
            new Database\Config\DatabaseConfig(require __DIR__ . '/connection.php')
        );
    },
    DatabaseProviderInterface::class => static function (ContainerInterface $container) {
        return $container->get(DatabaseManager::class);
    },
    // Cycle ORM
    ORMInterface::class => function (ContainerInterface $container) {
        $dbal = $container->get(Spiral\Database\DatabaseManager::class);
        $orm = new Cycle\ORM\ORM(new Cycle\ORM\Factory($dbal), $container->get(SchemaInterface::class));
        return $orm; 
    },
    // Schema
    SchemaInterface::class => static function (ContainerInterface $container) {
        return new \Cycle\ORM\Schema($container->get(Schema::class));
    },

    Schema::class => static function (ContainerInterface $container) {
        // Class locator
        $cl = (new Tokenizer\Tokenizer(new Tokenizer\Config\TokenizerConfig([
            'directories' => ['../src'],
        ])))->classLocator();
        $dbal = $container->get(Spiral\Database\DatabaseManager::class);
        $schema = (new Schema\Compiler())->compile(new Schema\Registry($dbal), [
            new Annotated\Embeddings($cl),            // register embeddable entities
            new Annotated\Entities($cl),              // register annotated entities
            new Schema\Generator\ResetTables(),       // re-declared table schemas (remove columns)
            new Annotated\MergeColumns(),             // copy column declarations from all related classes (@Table annotation)
            new Schema\Generator\GenerateRelations(), // generate entity relations
            new Schema\Generator\ValidateEntities(),  // make sure all entity schemas are correct
            new Schema\Generator\RenderTables(),      // declare table schemas
            new Schema\Generator\RenderRelations(),   // declare relation keys and indexes
            new Annotated\MergeIndexes(),             // copy index declarations from all related classes (@Table annotation)
            new Schema\Generator\SyncTables(),        // sync table changes to database
            new Schema\Generator\GenerateTypecast(),  // typecast non string columns
        ]);
        return $schema;
    },



user entity
<?php

namespace App\Domain\User;

use Cycle\Annotated\Annotation as Cycle;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Table;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Embeddable;
use DateTimeImmutable;

/**
 * @Entity(
 *    table="users",
 *    role="user",
 *    repository="App\Domain\User\UserRepository"
 *  )
 */
class User
{
    /** @Column(type = "primary") */
    protected $id;

    /** @Column(type = "string(64)", name = "username") */
    protected $username;

    /** @Column(type = "string(64)", name = "email") */
    protected $email;

    /** @Column(type = "string(64)") */
    protected $password;

    /** @Column(type = "string(128)", nullable = true) */
    protected $token;

    /** @Column(type = "tinyInteger")*/
    protected $status;
    
    protected DateTimeImmutable $created_at;
    protected DateTimeImmutable $updated_at;

    
}


user repository
<?php

namespace App\Domain\User;

use Cycle\ORM\ORMInterface;
use Cycle\ORM\Select;
use Cycle\ORM\Transaction;

class UserRepository extends Select\Repository
{
    private ORMInterface $orm;

    public function __construct(Select $select, ORMInterface $orm)
    {
        $this->orm = $orm;
        parent::__construct($select);
    }

}


user action
<?php

namespace App\Http\Action;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

use Spiral\Database;
use Spiral\Database\DatabaseManager;
use Cycle\ORM;

use Cycle\ORM\ORMInterface;

use App\Domain\User;
use App\Domain\User\UserRepository;


final class UserAction
{
    
   private UserRepository $repository;
   private ORMInterface $orm;


    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
    {

        $data = $this->repository->findByPk(1);
        $response->getBody()->write(
              json_encode((array)$data, JSON_THROW_ON_ERROR)
        );
        return $response->withHeader('Content-Type', 'application/json');
        return $response;
    }
}


Текст ошибки
Message: Entry "App\Http\Action\UserAction" cannot be resolved: Entry "App\Domain\User\UserRepository" cannot be resolved: Entry "Cycle\ORM\Select" cannot be resolved: Parameter $role of __construct() has no value defined or guessable Full definition: Object ( class = Cycle\ORM\Select lazy = false __construct( $orm = get(Cycle\ORM\ORMInterface) $role = #UNDEFINED# ) ) Full definition: Object ( class = App\Domain\User\UserRepository lazy = false __construct( $select = get(Cycle\ORM\Select) $orm = get(Cycle\ORM\ORMInterface) ) ) Full definition: Object ( class = App\Http\Action\UserAction lazy = false __construct( $repository = get(App\Domain\User\UserRepository) ) )
File: /var/www/api/vendor/php-di/php-di/src/Definition/Exception/InvalidDefinition.php
  • Вопрос задан
  • 157 просмотров
Пригласить эксперта
Ответы на вопрос 2
Russell-s-Teapot
@Russell-s-Teapot Автор вопроса
Да, роль в конструкторе select и не будет ресолвиться, php-di не может отресолвить обычный строковый параметр :(
Ответ написан
Комментировать
alestro
@alestro
Зарегистрируйте фабрику для UserRepository в di контейнер
UserRepository::class => static fn(ContainerInterface $container)  => $container->get(ORMInterface::class)->getRepository(User::class),
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы