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 HomeControllerindex 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:
Description
Using forward slash
/
is causingis_subclass_of
to returnfalse
when calling https://github.com/cycle/orm/blob/master/src/Factory.php#L160Steps to reproduce:
Edit the generated entity in
app/src/Database/User.php
add column and repository annotations, example:Run
cycle
Update the
HomeController
index
method:Start app
Visit root route output by above command (probably http://localhost:8080), you should see this error:
If you change the annotation on the
User
entity to:Re-run
cycle
:Start the app and visit root route, it should work now