Service
In Pandawa, service is used to handle the implemetation of each operation as a service. This is usually used with Command or Query.
Generating a new serviceโ
As for the current time, you need to manually make a new service.
tip
Read more about CLI.
Template ๐
Replace the things encapsulated with <> including itself as well.
<?php
declare(strict_types=1);
namespace <Namespace>\<Folder>\Service;
use Pandawa\Component\Ddd\AbstractModel;
final class <Name>
{
public function __construct() {}
//->
}
Example ๐งช
<?php
declare(strict_types=1);
namespace Pandawa\Product\Service;
use Pandawa\Product\Command\CreateProduct;
use Pandawa\Product\Model\Product;
use Pandawa\Product\Repository\ProductRepository;
final class ProductCreator {
public function __construct(private ProductRepository $repository) {}
public function create(CreateProduct $create): Product {
$product = new Product($create->origin()->all());
return $this->repository->save($product);
}
}
Read more about Command here