for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
/*
* This file is part of FlexPHP.
*
* (c) Freddie Gar <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FlexPHP\Generator\Domain\UseCases;
use FlexPHP\Generator\Domain\Builders\Factory\FactoryBuilder;
use FlexPHP\Generator\Domain\Builders\Inflector;
use FlexPHP\Generator\Domain\Messages\Requests\CreateFactoryFileRequest;
use FlexPHP\Generator\Domain\Messages\Responses\CreateFactoryFileResponse;
use FlexPHP\Generator\Domain\Writers\PhpWriter;
final class CreateFactoryFileUseCase
{
public function execute(CreateFactoryFileRequest $request): CreateFactoryFileResponse
$inflector = new Inflector();
$entity = $inflector->entity($request->schema->name());
$factory = new FactoryBuilder($request->schema);
$filename = $entity . 'Factory';
$path = \sprintf('%1$s/../../tmp/skeleton/domain/%2$s', __DIR__, $entity);
$writer = new PhpWriter($factory->build(), $filename, $path);
return new CreateFactoryFileResponse($writer->save());
}