-
-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into make-entity-improved
* master: (47 commits) Updating CHANGELOG some improvements fix form variables added validation on arguments fix phpcs fix variables to follow official recommendations some make:form improvements + experiments final fix for skeleton templates making test name less specific so we can run only it Update index.rst phpcs fix some skeleton improvements Fixed CS of generated entity fix cs and improvements according to review request fix make:form completed improvement of make:form command added tests for crud testig fix tests on appveyor php cs fix update all to lastest bundle code ...
- Loading branch information
Showing
28 changed files
with
1,113 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony MakerBundle package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\MakerBundle\Doctrine; | ||
|
||
/** | ||
* @author Sadicov Vladimir <sadikoff@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class DoctrineEntityDetails | ||
{ | ||
private $repositoryClass; | ||
|
||
private $identifier; | ||
private $displayFields; | ||
private $formFields; | ||
|
||
public function __construct($repositoryClass, $identifier, $displayFields, $formFields) | ||
{ | ||
$this->repositoryClass = $repositoryClass; | ||
$this->identifier = $identifier; | ||
$this->displayFields = $displayFields; | ||
$this->formFields = $formFields; | ||
} | ||
|
||
public function getRepositoryClass() | ||
{ | ||
return $this->repositoryClass; | ||
} | ||
|
||
public function getIdentifier() | ||
{ | ||
return $this->identifier; | ||
} | ||
|
||
public function getDisplayFields() | ||
{ | ||
return $this->displayFields; | ||
} | ||
|
||
public function getFormFields() | ||
{ | ||
return $this->formFields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony MakerBundle package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\MakerBundle\Doctrine; | ||
|
||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; | ||
|
||
/** | ||
* @author Sadicov Vladimir <sadikoff@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class DoctrineEntityHelper | ||
{ | ||
private $metadataFactory; | ||
|
||
public function __construct(ManagerRegistry $registry = null) | ||
{ | ||
$this->metadataFactory = null !== $registry ? new DoctrineMetadataFactory($registry) : null; | ||
} | ||
|
||
private function isDoctrineInstalled(): bool | ||
{ | ||
return null !== $this->metadataFactory; | ||
} | ||
|
||
public function getEntitiesForAutocomplete(): array | ||
{ | ||
$entities = []; | ||
|
||
if ($this->isDoctrineInstalled()) { | ||
$allMetadata = $this->metadataFactory->getAllMetadata(); | ||
/** @var ClassMetadataInfo $metadata */ | ||
foreach ($allMetadata as $metadata) { | ||
$entityClassDetails = new ClassNameDetails($metadata->name, 'App\\Entity'); | ||
$entities[] = $entityClassDetails->getRelativeName(); | ||
} | ||
} | ||
|
||
return $entities; | ||
} | ||
|
||
/** | ||
* @param string $entityClassName | ||
* | ||
* @return null|DoctrineEntityDetails | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function createDoctrineDetails(string $entityClassName) | ||
{ | ||
$metadata = $this->getEntityMetadata($entityClassName); | ||
|
||
if (null !== $metadata) { | ||
return new DoctrineEntityDetails( | ||
$metadata->customRepositoryClassName, | ||
$metadata->identifier[0], | ||
$metadata->fieldMappings, | ||
$this->getFormFieldsFromEntity($metadata) | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getFormFieldsFromEntity(ClassMetadataInfo $metadata): array | ||
{ | ||
$fields = (array) $metadata->fieldNames; | ||
// Remove the primary key field if it's not managed manually | ||
if (!$metadata->isIdentifierNatural()) { | ||
$fields = array_diff($fields, $metadata->identifier); | ||
} | ||
foreach ($metadata->associationMappings as $fieldName => $relation) { | ||
if (ClassMetadataInfo::ONE_TO_MANY !== $relation['type']) { | ||
$fields[] = $fieldName; | ||
} | ||
} | ||
|
||
return $fields; | ||
} | ||
|
||
public function getEntityMetadata($entityClassName) | ||
{ | ||
if (null === $this->metadataFactory) { | ||
throw new \Exception('Somehow the doctrine service is missing. Is DoctrineBundle installed?'); | ||
} | ||
|
||
return $this->metadataFactory->getMetadataForClass($entityClassName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony MakerBundle package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\MakerBundle; | ||
|
||
/** | ||
* @author Sadicov Vladimir <sadikoff@gmail.com> | ||
*/ | ||
final class GeneratorTwigHelper | ||
{ | ||
private $fileManager; | ||
|
||
public function __construct(FileManager $fileManager) | ||
{ | ||
$this->fileManager = $fileManager; | ||
} | ||
|
||
public function getEntityFieldPrintCode($entity, $field): string | ||
{ | ||
$printCode = $entity.'.'.$field['fieldName']; | ||
|
||
switch ($field['type']) { | ||
case 'datetime': | ||
$printCode .= ' ? '.$printCode.'|date(\'Y-m-d H:i:s\') : \'\''; | ||
break; | ||
case 'date': | ||
$printCode .= ' ? '.$printCode.'|date(\'Y-m-d\') : \'\''; | ||
break; | ||
case 'time': | ||
$printCode .= ' ? '.$printCode.'|date(\'H:i:s\') : \'\''; | ||
break; | ||
case 'array': | ||
$printCode .= ' ? '.$printCode.'|join(\', \') : \'\''; | ||
break; | ||
case 'boolean': | ||
$printCode .= ' ? \'Yes\' : \'No\''; | ||
break; | ||
} | ||
|
||
return $printCode; | ||
} | ||
|
||
public function getHeadPrintCode($title): string | ||
{ | ||
if ($this->fileManager->fileExists('templates/base.html.twig')) { | ||
return <<<TWIG | ||
{% extends 'base.html.twig' %} | ||
{% block title %}$title{% endblock %} | ||
TWIG; | ||
} | ||
|
||
return <<<HTML | ||
<!DOCTYPE html> | ||
<title>$title</title> | ||
HTML; | ||
} | ||
} |
Oops, something went wrong.