Skip to main content

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 Repository here
Read more about Command here