Final Class Yiisoft\Yii\Gii\Controller\DefaultController
| Inheritance | Yiisoft\ |
|---|
Public Methods
Method Details
| public mixed __construct ( \ | ||
| $responseFactory | \ |
|
| $parametersProvider | Yiisoft\ |
|
public function __construct(
private readonly DataResponseFactoryInterface $responseFactory,
private readonly ParametersProvider $parametersProvider,
) {}
| public \ | ||
| $request | Yiisoft\ |
|
| $commandHydrator | Yiisoft\ |
|
| $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,
);
}
| public \ | ||
| $request | Yiisoft\ |
|
| $codeFileWriter | Yiisoft\ |
|
| $commandHydrator | Yiisoft\ |
|
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()));
}
| public \ | ||
| $request | Yiisoft\ |
|
public function get(GeneratorRequest $request): ResponseInterface
{
$generator = $request->getGenerator();
return $this->responseFactory->createResponse(
$this->serializeGenerator($generator::class),
);
}
| public \ | ||
| $gii | Yiisoft\ |
|
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,
),
),
),
]);
}
| public \ | ||
| $request | Yiisoft\ |
|
| $commandHydrator | Yiisoft\ |
|
| $file | ?string | |
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,
);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.