2
votes

I just tried the https://api-platform.com/docs/core/operations/#recommended-method example.

  1. I generated the Book.class as described
  2. Add CreateBookPublication class
  3. If I invoke the API I receive the following error:

(1/1) RuntimeException Cannot autowire service "App\Controller\CreateBookPublication": argument "$bookPublishingHandler" of method "__construct()" has type "App\Controller\BookPublishingHandler" but this class was not found.

Do you have any idea? I would like to generate an own hardcoded response without doctrine for test purposes.

1

1 Answers

7
votes

It looks like you don't have BookPublishingHandler class, you must implement it yourself, this docs example is not fully working demo.

Error says DI trying to find App\Controller\CreateBookPublication but it's not exists or it's not registered as service. I assume you are using default configuration and it is register services found in src/ directory automatically.

So create directory src/Handler, inside create class file BookPublishingHandler.php

<?php

namespace App\Handler;

use App\Entity\Book;

class BookPublishingHandler
{
    public function handle(Book $book): array
    {
        // your logic for publishing book or/and eg. return your custom data
    }
}

and add import to your CreateBookPublication controller

<?php

namespace App\Controller;

use App\Handler\BookPublishingHandler;

Or you can just for test return hardcoded array directly from controller.