Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Doctrine/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@ public function createDoctrineDetails(string $entityClassName)

return null;
}

public function isClassAMappedEntity(string $className): bool
{
if (!$this->isDoctrineInstalled()) {
return false;
}

return (bool) $this->getMetadata($className);
}
}
42 changes: 33 additions & 9 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\MakerBundle;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;

Expand Down Expand Up @@ -84,6 +85,22 @@ public function dumpFile(string $targetPath, string $contents)
];
}

public function getFileContentsForPendingOperation(string $targetPath): string
{
if (!isset($this->pendingOperations[$targetPath])) {
throw new RuntimeCommandException(sprintf('File "%s" is not in the Generator\'s pending operations', $targetPath));
}

$templatePath = $this->pendingOperations[$targetPath]['template'];
$parameters = $this->pendingOperations[$targetPath]['variables'];

$templateParameters = array_merge($parameters, [
'relative_path' => $this->fileManager->relativizePath($targetPath),
]);

return $this->fileManager->parseTemplate($templatePath, $templateParameters);
}

/**
* Creates a helper object to get data about a class name.
*
Expand Down Expand Up @@ -178,15 +195,10 @@ public function writeChanges()
continue;
}

$templatePath = $templateData['template'];
$parameters = $templateData['variables'];

$templateParameters = array_merge($parameters, [
'relative_path' => $this->fileManager->relativizePath($targetPath),
]);

$fileContents = $this->fileManager->parseTemplate($templatePath, $templateParameters);
$this->fileManager->dumpFile($targetPath, $fileContents);
$this->fileManager->dumpFile(
$targetPath,
$this->getFileContentsForPendingOperation($targetPath, $templateData)
);
}

$this->pendingOperations = [];
Expand All @@ -196,4 +208,16 @@ public function getRootNamespace(): string
{
return $this->namespacePrefix;
}

public function generateController(string $controllerClassName, string $controllerTemplatePath, array $parameters = []): string
{
return $this->generateClass(
$controllerClassName,
$controllerTemplatePath,
$parameters +
[
'parent_class_name' => \method_exists(AbstractController::class, 'getParameter') ? 'AbstractController' : 'Controller',
]
);
}
}
15 changes: 15 additions & 0 deletions src/Maker/AbstractMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\MakerBundle\Maker;

use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -33,4 +34,18 @@ protected function writeSuccessMessage(ConsoleStyle $io)
$io->writeln(' <bg=green;fg=white> </>');
$io->newLine();
}

protected function addDependencies(array $dependencies, string $message = null): string
{
$dependencyBuilder = new DependencyBuilder();

foreach ($dependencies as $class => $name) {
$dependencyBuilder->addClassDependency($class, $name);
}

return $dependencyBuilder->getMissingPackagesMessage(
$this->getCommandName(),
$message
);
}
}
Loading