1. Go to this page and download the library: Download krak/api-platform-extra library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
krak / api-platform-extra example snippets
namespace App\Entity;
class Book
{
private $id;
private $name;
private $author;
private $createdAt;
public function __construct(string $name, Author $author) {
$this->name = $name;
$this->author = $author;
$this->createdAt = new \DateTime();
}
public function getId(): ?int {
return $this->id;
}
public function getName(): string {
return $this->name;
}
public function getAuthor(): Author {
return $this->author;
}
public function getCreatedAt(): \DateTimeInterface {
return $this->createdAt;
}
}
// under App\Entity
class Book
{
private $id;
private $name;
private $author;
public function __construct(string $name, Author $author) {
// assign
}
}
// under App\DTO
class CreateBookRequest
{
public $name;
public $authorName;
public function __construct(string $name, string $authorName) {
$this->name = $name;
$this->authorName = $authorName;
}
}
// under App\Service
class CreateBook
{
public function __invoke(CreateBookRequest $req): Book {
// use the req data to actually create then pesist/flush the Book instance
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.