0 follower

Final Class Yiisoft\Yii\Gii\Controller\DefaultController

InheritanceYiisoft\Yii\Gii\Controller\DefaultController

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\DataResponse\DataResponseFactoryInterface $responseFactory, Yiisoft\Yii\Gii\ParametersProvider $parametersProvider )
$responseFactory \Yiisoft\DataResponse\DataResponseFactoryInterface
$parametersProvider Yiisoft\Yii\Gii\ParametersProvider

                public function __construct(
    private readonly DataResponseFactoryInterface $responseFactory,
    private readonly ParametersProvider $parametersProvider,
) {
}

            
diff() public method

public \Psr\Http\Message\ResponseInterface diff ( Yiisoft\Yii\Gii\Request\GeneratorRequest $request, Yiisoft\Yii\Gii\Generator\CommandHydrator $commandHydrator, string $file )
$request Yiisoft\Yii\Gii\Request\GeneratorRequest
$commandHydrator Yiisoft\Yii\Gii\Generator\CommandHydrator
$file string

                public function diff(
    GeneratorRequest $request,
    CommandHydrator $commandHydrator,
    #[Query('file')] string $file
): ResponseInterface {
    $generator = $request->getGenerator();
    $command = $commandHydrator->hydrate($generator::getCommandClass(), $request->getBody());
    try {
        $files = $generator->generate($command);
    } catch (InvalidGeneratorCommandException $e) {
        return $this->createErrorResponse($e);
    }
    foreach ($files as $generatedFile) {
        if ($generatedFile->getId() === $file) {
            return $this->responseFactory->createResponse(['diff' => $generatedFile->diff()]);
        }
    }
    return $this->responseFactory->createResponse(
        ['message' => "Code file not found: $file"],
        Status::UNPROCESSABLE_ENTITY
    );
}

            
generate() public method

public \Psr\Http\Message\ResponseInterface generate ( Yiisoft\Yii\Gii\Request\GeneratorRequest $request, Yiisoft\Yii\Gii\Component\CodeFile\CodeFileWriter $codeFileWriter, Yiisoft\Yii\Gii\Generator\CommandHydrator $commandHydrator )
$request Yiisoft\Yii\Gii\Request\GeneratorRequest
$codeFileWriter Yiisoft\Yii\Gii\Component\CodeFile\CodeFileWriter
$commandHydrator Yiisoft\Yii\Gii\Generator\CommandHydrator

                public function generate(
    GeneratorRequest $request,
    CodeFileWriter $codeFileWriter,
    CommandHydrator $commandHydrator
): ResponseInterface {
    $generator = $request->getGenerator();
    $command = $commandHydrator->hydrate($generator::getCommandClass(), $request->getBody());
    $answers = $request->getAnswers();
    try {
        $files = $generator->generate($command);
    } catch (InvalidGeneratorCommandException $e) {
        return $this->createErrorResponse($e);
    }
    /**
     * @psalm-suppress MixedArgumentTypeCoercion $answers
     */
    $result = $codeFileWriter->write($files, $answers);
    return $this->responseFactory->createResponse(array_values($result->getResults()));
}

            
get() public method

public \Psr\Http\Message\ResponseInterface get ( Yiisoft\Yii\Gii\Request\GeneratorRequest $request )
$request Yiisoft\Yii\Gii\Request\GeneratorRequest

                public function get(GeneratorRequest $request): ResponseInterface
{
    $generator = $request->getGenerator();
    return $this->responseFactory->createResponse(
        $this->serializeGenerator($generator::class)
    );
}

            
list() public method

public \Psr\Http\Message\ResponseInterface list ( Yiisoft\Yii\Gii\GiiInterface $gii )
$gii Yiisoft\Yii\Gii\GiiInterface

                public function list(GiiInterface $gii): ResponseInterface
{
    $generators = $gii->getGenerators();
    return $this->responseFactory->createResponse([
        'generators' => array_map(
            $this->serializeGenerator(...),
            array_values(
                array_map(
                    fn (GeneratorInterface|GeneratorProxy $generator) => $generator instanceof GeneratorProxy
                        ? $generator->getClass()
                        : $generator::class,
                    $generators
                )
            ),
        ),
    ]);
}

            
preview() public method

public \Psr\Http\Message\ResponseInterface preview ( Yiisoft\Yii\Gii\Request\GeneratorRequest $request, Yiisoft\Yii\Gii\Generator\CommandHydrator $commandHydrator, string|null $file null )
$request Yiisoft\Yii\Gii\Request\GeneratorRequest
$commandHydrator Yiisoft\Yii\Gii\Generator\CommandHydrator
$file string|null

                public function preview(
    GeneratorRequest $request,
    CommandHydrator $commandHydrator,
    #[Query('file')] ?string $file = null
): ResponseInterface {
    $generator = $request->getGenerator();
    $command = $commandHydrator->hydrate($generator::getCommandClass(), $request->getBody());
    try {
        $files = $generator->generate($command);
    } catch (InvalidGeneratorCommandException $e) {
        return $this->createErrorResponse($e);
    }
    if ($file === null) {
        return $this->responseFactory->createResponse([
            'files' => array_map($this->serializeCodeFile(...), array_values($files)),
            'operations' => CodeFileWriteOperationEnum::getLabels(),
        ]);
    }
    foreach ($files as $generatedFile) {
        if ($generatedFile->getId() === $file) {
            $content = $generatedFile->preview();
            return $this->responseFactory->createResponse(
                ['content' => is_string($content) ? $content : 'Preview is not available for this file type.']
            );
        }
    }
    return $this->responseFactory->createResponse(
        ['message' => "Code file not found: $file"],
        Status::UNPROCESSABLE_ENTITY
    );
}