среда, 17 апреля 2019 г.

Another way to create Sylius Resource factory

Use this in services.yaml:

App\Factory\RideFactory:
        decorates: app.factory.ride
        arguments:
            - "@App\Factory\RideFactory.inner"


App\Factory\RideFactory:
<?php
declare(strict_types=1);

namespace App\Factory;

use App\Entity\Ride;
use Sylius\Component\Resource\Factory\FactoryInterface;

class RideFactory implements FactoryInterface
{
    /**
     * @var FactoryInterface
     */
    private $decorated;

    public function __construct(FactoryInterface $decoratedFactory)
    {
        $this->decorated = $decoratedFactory;
    }

    public function createNew()
    {
        return new Ride();
    }
}

Finally you shouldn't add anything into `sylius_resource` in config.yml.

Комментариев нет:

Отправить комментарий