cycle / docs

Cycle ORM Documentation
https://cycle-orm.dev/docs
110 stars 38 forks source link

Updated class path for repository #87

Closed patoui closed 3 years ago

patoui commented 3 years ago

Description

Using forward slash / is causing is_subclass_of to return false when calling https://github.com/cycle/orm/blob/master/src/Factory.php#L160

Steps to reproduce:

composer create-project spiral/app test-spiral
cd test-spiral
php app.php create:entity User
php app.php create:repository User

Edit the generated entity in app/src/Database/User.php add column and repository annotations, example:

<?php

declare(strict_types=1);

namespace App\Database;

use Cycle\Annotated\Annotation as Cycle;

/**
 * @Cycle\Entity(repository = "App/Repository/UserRepository")
 */
class User
{
    /** @Cycle\Column(type="primary") */
    public $id;
}

Run cycle

php app.php cycle

Update the HomeController index method:

public function index(): ResponseInterface
{
    return $this->response->json($this->orm->getRepository(User::class)->findAll());
}

Start app

./spiral serve -v -d

Visit root route output by above command (probably http://localhost:8080), you should see this error:

Cycle\ORM\Exception\TypecastException: App/Repository/UserRepository does not implement Cycle\ORM\RepositoryInterface

If you change the annotation on the User entity to:

@Cycle\Entity(repository = "App\Repository\UserRepository")

Re-run cycle:

php app.php cycle

Start the app and visit root route, it should work now

./spiral serve -v -d
wolfy-j commented 3 years ago

Thank you!