From 3881b0456395b8886bbd26a018f8996b2679fd57 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Thu, 20 Feb 2025 14:40:25 +0100 Subject: [PATCH] fix!: remove entity generator, remove plugin generator --- composer.json | 6 +- src/Command/MakeDefinition.php | 61 ----- src/Command/MakePlugin.php | 144 ----------- ...BuildEntityDefinitionNamesCompilerPass.php | 24 -- .../Definition/CollectionGenerator.php | 49 ---- .../Definition/DefinitionGenerator.php | 161 ------------ .../Definition/EntityConsoleQuestion.php | 155 ------------ .../Generator/Definition/EntityGenerator.php | 158 ------------ .../Generator/Definition/EntityLoader.php | 239 ------------------ .../Definition/ExtensionGenerator.php | 106 -------- .../Definition/ParserBuilderTrait.php | 75 ------ .../Generator/Definition/QuestionHelper.php | 51 ---- .../Generator/Definition/TypeMapping.php | 142 ----------- src/Component/Generator/FixCodeStyle.php | 62 ----- .../QuestionHandler/GenericHandler.php | 164 ------------ .../QuestionHandler/ManyToManyHandler.php | 159 ------------ .../QuestionHandlerInterface.php | 14 - src/Component/Generator/Struct/Definition.php | 79 ------ src/Component/Generator/Struct/Field.php | 150 ----------- src/Component/Generator/Struct/Flag.php | 22 -- .../Generator/Struct/MappingDefinition.php | 21 -- .../Struct/TranslationDefinition.php | 11 - src/Component/Generator/UseHelper.php | 43 ---- src/FroshDevelopmentHelper.php | 1 - src/Resources/config/services.xml | 13 - 25 files changed, 2 insertions(+), 2108 deletions(-) delete mode 100644 src/Command/MakeDefinition.php delete mode 100644 src/Command/MakePlugin.php delete mode 100644 src/Component/DependencyInjection/BuildEntityDefinitionNamesCompilerPass.php delete mode 100644 src/Component/Generator/Definition/CollectionGenerator.php delete mode 100644 src/Component/Generator/Definition/DefinitionGenerator.php delete mode 100644 src/Component/Generator/Definition/EntityConsoleQuestion.php delete mode 100644 src/Component/Generator/Definition/EntityGenerator.php delete mode 100644 src/Component/Generator/Definition/EntityLoader.php delete mode 100644 src/Component/Generator/Definition/ExtensionGenerator.php delete mode 100644 src/Component/Generator/Definition/ParserBuilderTrait.php delete mode 100644 src/Component/Generator/Definition/QuestionHelper.php delete mode 100644 src/Component/Generator/Definition/TypeMapping.php delete mode 100644 src/Component/Generator/FixCodeStyle.php delete mode 100644 src/Component/Generator/QuestionHandler/GenericHandler.php delete mode 100644 src/Component/Generator/QuestionHandler/ManyToManyHandler.php delete mode 100644 src/Component/Generator/QuestionHandler/QuestionHandlerInterface.php delete mode 100644 src/Component/Generator/Struct/Definition.php delete mode 100644 src/Component/Generator/Struct/Field.php delete mode 100644 src/Component/Generator/Struct/Flag.php delete mode 100644 src/Component/Generator/Struct/MappingDefinition.php delete mode 100644 src/Component/Generator/Struct/TranslationDefinition.php delete mode 100644 src/Component/Generator/UseHelper.php diff --git a/composer.json b/composer.json index d71d4f5..cf52926 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "frosh/development-helper", - "version": "1.0.3", + "version": "2.0.0", "description": "Development Helper", "type": "shopware-platform-plugin", "license": "MIT", @@ -16,9 +16,7 @@ } }, "require": { - "shopware/core": "~6.5.0 || ~6.6.0", - "nikic/php-parser": "*", - "friendsofphp/php-cs-fixer": "*", + "shopware/core": "~6.6.0", "psy/psysh": "*" }, "extra": { diff --git a/src/Command/MakeDefinition.php b/src/Command/MakeDefinition.php deleted file mode 100644 index 09fc228..0000000 --- a/src/Command/MakeDefinition.php +++ /dev/null @@ -1,61 +0,0 @@ -addArgument('namespace', InputArgument::REQUIRED, 'Namespace (FroshTest\\Content\\Store)'); - } - - public function execute(InputInterface $input, OutputInterface $output): int - { - $io = new SymfonyStyle($input, $output); - $result = $this->entityLoader->load($input->getArgument('namespace'), $io); - - $this->entityConsoleQuestion->question($io, $result); - - $this->definitionGenerator->generate($result); - $this->entityGenerator->generate($result); - $this->collectionGenerator->generate($result); - $this->fixCodeStyle->fix($result); - - if ($result->translation) { - $this->definitionGenerator->generate($result->translation); - $this->entityGenerator->generate($result->translation); - $this->collectionGenerator->generate($result->translation); - $this->fixCodeStyle->fix($result->translation); - } - - $io->warning('Don\'t forget to add this Definition to your services.xml'); - - return 0; - } -} diff --git a/src/Command/MakePlugin.php b/src/Command/MakePlugin.php deleted file mode 100644 index 3d6b5b9..0000000 --- a/src/Command/MakePlugin.php +++ /dev/null @@ -1,144 +0,0 @@ -pluginFolderDir = $kernelRootDir . '/custom/plugins/'; - } - - public function configure(): void - { - $this - ->addArgument('name', InputArgument::REQUIRED, 'Plugin Name') - ->addOption('namespace', null, InputOption::VALUE_OPTIONAL, 'Start namespace of the plugin'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $fs = new Filesystem(); - - $pluginPath = $this->pluginFolderDir . '/' . $input->getArgument('name'); - if ($fs->exists($pluginPath)) { - throw new \RuntimeException(sprintf('Plugin with name "%s" already exists', $input->getArgument('name'))); - } - - $namespace = $input->getOption('namespace') ?? $input->getArgument('name'); - - $fs->mkdir([ - $pluginPath, - $pluginPath . '/src/', - $pluginPath . '/src/Resources', - $pluginPath . '/src/Resources/config', - ]); - - $io = new SymfonyStyle($input, $output); - - $this->makeComposerJson($fs, $pluginPath, $input->getArgument('name'), $namespace, $io); - $this->makeBootstrap($fs, $pluginPath, $input->getArgument('name'), $namespace); - $this->makeChangelogFiles($fs, $pluginPath); - $this->makeDefaultServicesXml($fs, $pluginPath); - - $io->warning('To pass the Extension Store guidelines you need to provide an plugin.png in src/Resources/config/plugin.png'); - - return 0; - } - - private function makeComposerJson(Filesystem $fs, string $pluginPath, string $pluginName, string $namespace, SymfonyStyle $io): void - { - $composerJson = [ - 'name' => $io->ask('Composer Package name (vendor/package-name)', 'acme/example'), - 'version' => '1.0.0', - 'description' => $io->ask('Package description', ''), - 'type' => 'shopware-platform-plugin', - 'license' => $io->ask('Package license', 'MIT'), - 'autoload' => [ - 'psr-4' => [ - $namespace . '\\' => 'src/' - ] - ], - 'extra' => [ - 'shopware-plugin-class' => $namespace . '\\' . $pluginName, - 'label' => [ - 'de-DE' => $io->ask('Plugin Label [DE]') ?? $pluginName, - 'en-GB' => $io->ask('Plugin Label [EN]') ?? $pluginName, - ], - 'description' => [ - 'de-DE' => $io->ask('Plugin Description [DE]') ?? $pluginName, - 'en-GB' => $io->ask('Plugin Description [EN]') ?? $pluginName, - ], - 'manufacturerLink' => [ - 'de-DE' => $manufacturerLink = $io->ask('Plugin Manufacturer Link') ?? 'https://example.com', - 'en-GB' => $manufacturerLink, - ], - 'supportLink' => [ - 'de-DE' => $supportLink = $io->ask('Plugin Support Link') ?? 'https://example.com/support', - 'en-GB' => $supportLink, - ] - ] - ]; - - $fs->dumpFile($pluginPath . '/composer.json', json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - - } - - private function makeBootstrap(Filesystem $fs, string $pluginPath, string $pluginName, string $namespace): void - { - $tpl = <<dumpFile($pluginPath . '/src/' . $pluginName . '.php', str_replace(['#namespace#', '#class#'], [$namespace, $pluginName], $tpl)); - } - - private function makeChangelogFiles(Filesystem $fs, string $pluginPath): void - { - $enChangelog = <<dumpFile($pluginPath . '/CHANGELOG.md', $enChangelog); - } - - private function makeDefaultServicesXml(Filesystem $fs, string $pluginPath): void - { - $xml = << - - - - - - - -XML; - - $fs->dumpFile($pluginPath . '/src/Resources/config/services.xml', $xml); - } -} diff --git a/src/Component/DependencyInjection/BuildEntityDefinitionNamesCompilerPass.php b/src/Component/DependencyInjection/BuildEntityDefinitionNamesCompilerPass.php deleted file mode 100644 index 169b30f..0000000 --- a/src/Component/DependencyInjection/BuildEntityDefinitionNamesCompilerPass.php +++ /dev/null @@ -1,24 +0,0 @@ -findTaggedServiceIds('shopware.entity.definition') as $id => $options) { - if ($container->hasAlias($id)) { - continue; - } - - $names[] = $container->getDefinition($id)->getClass(); - } - - $container->setParameter('frosh_development_helper.names', array_unique($names)); - } -} diff --git a/src/Component/Generator/Definition/CollectionGenerator.php b/src/Component/Generator/Definition/CollectionGenerator.php deleted file mode 100644 index aa0d266..0000000 --- a/src/Component/Generator/Definition/CollectionGenerator.php +++ /dev/null @@ -1,49 +0,0 @@ -folder) && !mkdir($concurrentDirectory = $loaderResult->folder, 0777, true) && !is_dir($concurrentDirectory)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); - } - - $builder = new BuilderFactory(); - - if (file_exists($loaderResult->getCollectionFilePath())) { - return; - } - - $phpDoc = '/** - * @extends EntityCollection<%className%> - */'; - - $node = $builder - ->namespace($loaderResult->namespace) - ->addStmt($builder->use(EntityCollection::class)) - ->addStmt( - $builder->class($loaderResult->getCollectionClassName()) - ->setDocComment(str_replace('%className%', $loaderResult->name . 'Entity', $phpDoc)) - ->extend('EntityCollection') - ->addStmt( - $builder->method('getExpectedClass') - ->makePublic() - ->setReturnType('string') - ->addStmt(new Return_($builder->classConstFetch($loaderResult->name . 'Entity', 'class'))) - ) - ) - ->getNode(); - - $printer = new Standard(); - - file_put_contents($loaderResult->getCollectionFilePath(), $printer->prettyPrintFile([$node])); - } -} diff --git a/src/Component/Generator/Definition/DefinitionGenerator.php b/src/Component/Generator/Definition/DefinitionGenerator.php deleted file mode 100644 index 72c8212..0000000 --- a/src/Component/Generator/Definition/DefinitionGenerator.php +++ /dev/null @@ -1,161 +0,0 @@ -folder) && !mkdir($concurrentDirectory = $definition->folder, 0777, true) && !is_dir($concurrentDirectory)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); - } - - $useHelper = new UseHelper(); - - if (file_exists($definition->getDefinitionFilePath())) { - $namespace = $this->buildNamespaceFromExistingFile($definition->getDefinitionFilePath(), $useHelper); - } else { - $namespace = $this->buildNewNamespace($definition, $useHelper); - } - - $nodeFinder = new NodeFinder(); - - /** @var ClassMethod $method */ - $method = $nodeFinder->findFirst([$namespace], static fn(Node $node) => $node instanceof ClassMethod && $node->name->name === 'defineFields'); - - $method->stmts = [new Return_(new New_( - new Name('FieldCollection'), - [ - new Arg($this->buildFieldCollection($definition->fields, $useHelper)) - ] - ))]; - - $namespace->stmts = array_merge($useHelper->getStms(), $namespace->stmts); - - $printer = new Standard(); - - file_put_contents($definition->getDefinitionFilePath(), $printer->prettyPrintFile([$namespace])); - } - - private function buildNewNamespace(Definition $definition, UseHelper $useHelper): Namespace_ - { - $builder = new BuilderFactory(); - $namespace = new Namespace_(new Name($definition->namespace)); - - $class = new Class_(new Identifier($definition->getDefinitionClassName())); - $namespace->stmts[] = $class; - - if ($definition instanceof TranslationDefinition) { - $class->extends = new Name('EntityTranslationDefinition'); - $useHelper->addUse(EntityTranslationDefinition::class); - } elseif ($definition instanceof MappingDefinition) { - $class->extends = new Name('MappingEntityDefinition'); - $useHelper->addUse(MappingEntityDefinition::class); - } else { - $class->extends = new Name('EntityDefinition'); - $useHelper->addUse(EntityDefinition::class); - } - - $entityName = new ClassMethod(new Identifier('getEntityName')); - $entityName->returnType = new Name('string'); - $entityName->flags = Class_::MODIFIER_PUBLIC; - $entityName->stmts[] = new Return_(new String_($definition->getDefinitionName())); - - $defineFields = new ClassMethod(new Identifier('defineFields')); - $defineFields->returnType = new Identifier('FieldCollection'); - $defineFields->flags = Class_::MODIFIER_PROTECTED; - $useHelper->addUse(FieldCollection::class); - - $class->stmts[] = $entityName; - $class->stmts[] = $defineFields; - - if ($definition instanceof MappingDefinition) { - return $namespace; - } - - $class->stmts[] = $builder->method('getEntityClass') - ->makePublic() - ->setReturnType(new Name('string')) - ->addStmt(new Return_($builder->classConstFetch($definition->getEntityClassName(), 'class'))) - ->getNode(); - - $class->stmts[] = $builder->method('getCollectionClass') - ->makePublic() - ->setReturnType(new Name('string')) - ->addStmt(new Return_($builder->classConstFetch($definition->getCollectionClassName(), 'class'))) - ->getNode(); - - if ($definition instanceof TranslationDefinition) { - $class->stmts[] = $builder->method('getParentDefinitionClass') - ->makePublic() - ->setReturnType(new Name('string')) - ->addStmt(new Return_($builder->classConstFetch('\\' . $definition->parent->getDefinitionClass(), 'class'))) - ->getNode(); - } - - return $namespace; - } - - private function buildNamespaceFromExistingFile(string $entityFile, UseHelper $useHelper): Namespace_ - { - $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); - $ast = $parser->parse(file_get_contents($entityFile)); - - $nodeFinder = new NodeFinder(); - - $useFlags = $nodeFinder->findInstanceOf($ast, UseUse::class); - /** @var UseUse $useFlag */ - foreach ($useFlags as $useFlag) { - $useHelper->addUsage((string) $useFlag->name); - } - - return $nodeFinder->findFirstInstanceOf($ast, Namespace_::class); - } - - /** - * @param Field[] $fieldCollection - */ - private function buildFieldCollection(array $fieldCollection, UseHelper $useHelper): Array_ - { - $array = new Array_(); - - foreach ($fieldCollection as $element) { - $useHelper->addUse($element->name); - - $array->items[] = $this->buildField($element, $useHelper); - } - - return $array; - } -} diff --git a/src/Component/Generator/Definition/EntityConsoleQuestion.php b/src/Component/Generator/Definition/EntityConsoleQuestion.php deleted file mode 100644 index cce954e..0000000 --- a/src/Component/Generator/Definition/EntityConsoleQuestion.php +++ /dev/null @@ -1,155 +0,0 @@ -fieldsTypes = TypeMapping::getCompletionTypes(); - } - - /** - * @param Field[] $fieldCollection - */ - public function question(SymfonyStyle $io, Definition $definition): void - { - if (!$this->hasField($definition->fields, IdField::class)) { - $definition->fields[] = new Field(IdField::class, ['id', 'id'], [new Flag(Required::class), new Flag(PrimaryKey::class)]); - } - - $currentFields = $this->getCurrentFields($definition->fields); - - while (true) { - $field = $this->askForNextField($io, $currentFields, $definition); - - if ($field === null) { - break; - } - - $currentFields[] = $field->getPropertyName(); - - if ($field->translateable) { - $definition->fields[] = new Field(TranslatedField::class, [$field->getPropertyName()]); - $definition->translation->fields[] = $field; - } else { - $definition->fields[] = $field; - } - } - - $definition->fields = $this->addMissingFkFields($definition->fields); - - if ($definition->translation && !$this->hasField($definition->fields, TranslationsAssociationField::class)) { - $definition->fields[] = new Field( - TranslationsAssociationField::class, - [ - $definition->translation->getDefinitionClass() . '::class', - $definition->getDefinitionName() . '_id' - ] - ); - } - } - - private function askForNextField(SymfonyStyle $io, array $currentFields, Definition $definition): ?Field - { - $fieldName = $io->ask('New property name (press to stop adding fields)', null, function ($name) use ($currentFields) { - // allow it to be empty - if (!$name) { - return $name; - } - if (\in_array($name, $currentFields, true)) { - throw new \InvalidArgumentException(sprintf('The "%s" property already exists.', $name)); - } - return $name; - }); - - if (!$fieldName) { - return null; - } - - - $type = null; - - while ($type === null) { - $question = new Question('Field type', 'StringField'); - $question->setAutocompleterValues($this->fieldsTypes); - $type = $io->askQuestion($question); - - if (!\in_array($type, $this->fieldsTypes, true)) { - $io->error(sprintf('Invalid type "%s".', $type)); - $io->writeln(''); - $type = null; - } - } - - foreach ($this->questionHelpers as $helper) { - if ($helper->supports($type)) { - return $helper->handle($definition, $io, $fieldName, $type); - } - } - } - - private function hasField(array $fieldCollection, string $field): bool - { - foreach ($fieldCollection as $element) { - if ($element->name === $field) { - return true; - } - } - - return false; - } - - private function getCurrentFields(array $fieldCollection): array - { - return array_map(static fn(Field $field) => $field->getPropertyName(), $fieldCollection); - } - - private function addMissingFkFields(array $fieldCollection): array - { - /** @var Field $field */ - foreach ($fieldCollection as $field) { - if ($field->name === ManyToOneAssociationField::class || $field->name === OneToOneAssociationField::class) { - $haveFkField = false; - $associationStorageName = $field->getStorageName(); - - /** @var Field $nField */ - foreach ($fieldCollection as $nField) { - if (!$nField->isStorageAware()) { - continue; - } - - if ($nField->name !== $field->name && $nField->getStorageName() === $associationStorageName) { - $haveFkField = true; - } - } - - if ($haveFkField) { - continue; - } - - $fieldCollection[] = new Field(FkField::class, [$associationStorageName, $associationStorageName, $field->getReferenceClass()], $field->flags); - } - } - - return $fieldCollection; - } -} diff --git a/src/Component/Generator/Definition/EntityGenerator.php b/src/Component/Generator/Definition/EntityGenerator.php deleted file mode 100644 index 6b9613e..0000000 --- a/src/Component/Generator/Definition/EntityGenerator.php +++ /dev/null @@ -1,158 +0,0 @@ -folder) && !mkdir($concurrentDirectory = $definition->folder, 0777, true) && !is_dir($concurrentDirectory)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); - } - - $builder = new BuilderFactory(); - $nodeFinder = new NodeFinder(); - $useHelper = new UseHelper(); - - if (file_exists($definition->getEntityFilePath())) { - $namespace = $this->buildNamespaceFromExistingFile($definition->getEntityFilePath(), $useHelper); - } else { - $namespace = $this->buildNewNamespace($definition, $useHelper); - } - - $namespace->stmts = array_merge($useHelper->getStms(), $namespace->stmts); - - /** @var Class_ $class */ - $class = $nodeFinder->findFirstInstanceOf([$namespace], Class_::class); - - $classProperties = $nodeFinder->findInstanceOf([$class], PropertyProperty::class); - $classMethods = $nodeFinder->findInstanceOf([$class], ClassMethod::class); - - /** @var Field $field */ - foreach ($definition->fields as $field) { - if ($field->name === IdField::class) { - continue; - } - - if ($this->hasProperty($classProperties, $field->getPropertyName())) { - continue; - } - - $type = TypeMapping::mapToPhpType($field, false, $definition); - if ($field->isNullable()) { - $type = '?' . $type; - } - - $node = $builder - ->property($field->getPropertyName()) - ->setType($type) - ->makePublic(); - - if ($field->isNullable()) { - $node = $node->setDefault(null); - } - - $class->stmts[] = $node - ->getNode(); - } - - $printer = new Standard(); - - file_put_contents($definition->getEntityFilePath(), $printer->prettyPrintFile([$namespace])); - } - - private function buildNewNamespace(Definition $loaderResult, UseHelper $useHelper): Namespace_ - { - $factory = new BuilderFactory(); - - $namespace = new Namespace_(new Name($loaderResult->namespace)); - - $class = $factory->class($loaderResult->name . 'Entity'); - - if ($loaderResult instanceof TranslationDefinition) { - $useHelper->addUse(TranslationEntity::class); - $class - ->extend('TranslationEntity') - ->addStmt($factory->useTrait('EntityIdTrait')); - } else { - $useHelper->addUse(Entity::class); - $class - ->extend('Entity') - ->addStmt($factory->useTrait('EntityIdTrait')); - } - - $namespace->stmts[] = $class->getNode(); - - $useHelper->addUse(EntityIdTrait::class); - - return $namespace; - } - - private function hasProperty(array $properties, string $name): bool - { - /** @var PropertyProperty $property */ - foreach ($properties as $property) { - if ((string) $property->name === $name) { - return true; - } - } - - return false; - } - - private function hasMethod(array $methods, string $name): bool - { - /** @var ClassMethod $method */ - foreach ($methods as $method) { - if ((string) $method->name === $name) { - return true; - } - } - - return false; - } - - private function buildNamespaceFromExistingFile(string $entityFile, UseHelper $useHelper): Namespace_ - { - $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); - $ast = $parser->parse(file_get_contents($entityFile)); - - $nodeFinder = new NodeFinder(); - - $useFlags = $nodeFinder->findInstanceOf($ast, UseUse::class); - /** @var UseUse $useFlag */ - foreach ($useFlags as $useFlag) { - $useHelper->addUsage((string) $useFlag->name); - } - - return $nodeFinder->findFirstInstanceOf($ast, Namespace_::class); - } -} diff --git a/src/Component/Generator/Definition/EntityLoader.php b/src/Component/Generator/Definition/EntityLoader.php deleted file mode 100644 index f158adf..0000000 --- a/src/Component/Generator/Definition/EntityLoader.php +++ /dev/null @@ -1,239 +0,0 @@ -name = $this->normalizeName($class); - $result->namespace = $this->normalizeNamespace($class); - $result->fields = []; - - if (class_exists($result->getDefinitionClass())) { - $refClass = new \ReflectionClass($result->getDefinitionClass()); - $folder = pathinfo($refClass->getFileName(), PATHINFO_DIRNAME); - - $result->folder = $folder . '/'; - $result->fields = $this->parseFile($refClass->getFileName()); - - $translationDefinition = $result->getDefinitionName() . '_translation'; - - // Find by dal registration - if ($this->instanceRegistry->has($translationDefinition)) { - $result->translation = TranslationDefinition::createFrom($this->load($this->instanceRegistry->getRepository($translationDefinition)->getDefinition()->getClass(), $io)); - $result->translation->parent = $result; - } else { - // Find by default name / folder - $translation = $this->createDefaultTranslation($result); - if (class_exists($translation->getDefinitionClass())) { - $result->translation = TranslationDefinition::createFrom($this->load($translation->getDefinitionClass(), $io)); - $result->translation->parent = $result; - } - } - - return $result; - } - - $result->folder = $this->getNewEntityFolder($class); - - (new Filesystem())->mkdir($result->folder); - - if ($io->confirm('This entity will need translations?')) { - $result->translation = $this->createDefaultTranslation($result); - } - - return $result; - } - - private function parseFile(string $entityFile): array - { - $fields = []; - $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); - $ast = $parser->parse(file_get_contents($entityFile)); - - $nodeFinder = new NodeFinder(); - - $this->useFlags = $nodeFinder->findInstanceOf($ast, Use_::class); - - $method = $nodeFinder->findFirst($ast, fn(Node $node) => $node instanceof ClassMethod && $node->name->name === 'defineFields'); - - if (! $method instanceof ClassMethod) { - throw new \RuntimeException('Class does not implement defineFields'); - } - - /** @var Node\Expr\New_ $fieldCollection */ - $fieldCollection = $nodeFinder->findFirst([$method], fn(Node $node) => $node instanceof New_ && (string) $node->class === 'FieldCollection'); - - /** @var Node\Expr\Array_ $array */ - $array = $fieldCollection->args[0]->value; - - /** @var Node\Expr\ArrayItem $item */ - foreach ($array->items as $item) { - $flags = []; - /** @var Node\Expr\New_ $exprNew */ - $exprNew = null; - if ($item->value instanceof MethodCall) { - // Ignore remove flags - if ((string) $item->value->name !== 'addFlags') { - continue; - } - - foreach ($item->value->args as $arg) { - $flags[] = new Flag($this->getFQCN((string) $arg->value->class), $this->parserArgumentsToPhp($arg->value->args)); - } - $exprNew = $item->value->var; - } else { - $exprNew = $item->value; - } - - $className = $this->getFQCN((string) $exprNew->class); - - $fields[] = new Field($className, $this->parserArgumentsToPhp($exprNew->args), $flags); - } - - return $fields; - } - - private function parserArgumentsToPhp($element): array - { - $args = []; - - /** @var Node\Arg $arg */ - foreach ($element as $arg) { - switch (true) { - case $arg->value instanceof String_: - $args[] = (string) $arg->value->value; - break; - case $arg->value instanceof LNumber: - $args[] = (int) $arg->value->value; - break; - case $arg->value instanceof ClassConstFetch: - $args[] = $this->getFQCN($arg->value->class) . '::' . $arg->value->name; - break; - case $arg->value instanceof ConstFetch: - $value = (string) $arg->value->name; - if ($value === 'null') { - $value = null; - } elseif ($value === 'false') { - $value = false; - } elseif ($value === 'true') { - $value = true; - } - - $args[] = $value; - break; - case $arg->value instanceof Array_: - $args[] = $this->parserArgumentsToPhp($arg->value->items);; - break; - default: - throw new \RuntimeException('Type not supported: ' . $arg->value::class); - } - } - - return $args; - } - - public function getFQCN(string $name): string - { - foreach ($this->useFlags as $useFlag) { - /** @var Node\Stmt\UseUse $item */ - foreach ($useFlag->uses as $item) { - if (str_contains((string) $item->name, '\\' . $name)) { - return $item->name; - } - } - } - - return $name; - } - - private function normalizeNamespace(string $class): string - { - $splitt = explode('\\', $class); - unset($splitt[count($splitt) - 1]); - - $class = implode('\\', $splitt); - - if ($class[0] === '\\') { - $class = substr($class, 1); - } - - return $class; - } - - private function normalizeName(string $class): string - { - $splitt = explode('\\', $class); - $name = $splitt[count($splitt) - 1]; - return str_replace('Definition', '', $name); - } - - private function getNewEntityFolder(string $namespace): string - { - $prefixes = $this->kernel->getPluginLoader()->getClassLoader()->getPrefixesPsr4(); - - $namespaceSplit = explode('\\', $namespace); - unset($namespaceSplit[count($namespaceSplit) -1 ]); - $namespaceCount = count($namespaceSplit); - $suffix = []; - - for ($i = 0; $i < $namespaceCount; $i++) { - $loopNamespace = implode('\\', $namespaceSplit) . '\\'; - - if (isset($prefixes[$loopNamespace])) { - return rtrim(rtrim((string) $prefixes[$loopNamespace][0],'/').'/' . implode('/', array_reverse($suffix)), '/') . '/'; - } - - $index = count($namespaceSplit) -1; - $suffix[] = $namespaceSplit[$index]; - - unset($namespaceSplit[$index]); - } - - throw new \RuntimeException(sprintf('Namespace "%s" doees not fit in all known namespaces', $namespace)); - } - - private function createDefaultTranslation(Definition $result): TranslationDefinition - { - $translation = new TranslationDefinition(); - $translation->name = $result->name . 'Translation'; - $translation->folder = $result->folder . 'Aggregate/' . $result->name . 'Translation/'; - $translation->namespace = $result->namespace . '\\Aggregate\\' . $result->name . 'Translation'; - $translation->fields = []; - $translation->parent = $result; - - return $translation; - } -} diff --git a/src/Component/Generator/Definition/ExtensionGenerator.php b/src/Component/Generator/Definition/ExtensionGenerator.php deleted file mode 100644 index d0fa8fe..0000000 --- a/src/Component/Generator/Definition/ExtensionGenerator.php +++ /dev/null @@ -1,106 +0,0 @@ -getDefinitionName()) . 'Extension'; - $namespace = $definition->namespace . '\\Extensions'; - $folder = $definition->folder . '/Extensions/'; - $filePath = $folder . $name . '.php'; - - (new Filesystem())->mkdir($folder); - - $useHelper = new UseHelper(); - - if (file_exists($filePath)) { - $namespace = $this->buildNamespaceFromExistingFile($filePath, $useHelper); - } else { - $namespace = $this->buildNewNamespace($name, $namespace, $reference->getDefinitionClass(), $useHelper); - } - - $nodeFinder = new NodeFinder(); - $builder = new BuilderFactory(); - - /** @var ClassMethod $method */ - $method = $nodeFinder->findFirst([$namespace], static fn(Node $node) => $node instanceof ClassMethod && $node->name->name === 'extendFields'); - - $useHelper->addUse($field->name); - $method->stmts[] = new Expression($builder->methodCall($builder->var('collection'), new Identifier('add'), [$this->buildField($field, $useHelper)])); - - $namespace->stmts = array_merge($useHelper->getStms(), $namespace->stmts); - - $printer = new Standard(); - - file_put_contents($filePath, $printer->prettyPrintFile([$namespace])); - } - - private function buildNewNamespace(string $name, string $namespace, string $referenceClass, UseHelper $useHelper): Namespace_ - { - $useHelper->addUse(EntityExtension::class); - $useHelper->addUse(FieldCollection::class); - $useHelper->addUse($referenceClass); - - $builder = new BuilderFactory(); - $namespace = new Namespace_(new Name($namespace)); - - $class = new Class_(new Identifier($name)); - $namespace->stmts[] = $class; - - $class->extends = new Name('EntityExtension'); - - $class->stmts[] = $builder->method('getDefinitionClass') - ->makePublic() - ->setReturnType(new Name('string')) - ->addStmt(new Return_($builder->classConstFetch($useHelper->getShortName($referenceClass), 'class'))) - ->getNode(); - - $class->stmts[] = $builder->method('extendFields') - ->makePublic() - ->setReturnType(new Name('void')) - ->addParam($builder->param('collection')->setType(new Name('FieldCollection'))) - ->getNode(); - - return $namespace; - } - - private function buildNamespaceFromExistingFile(string $entityFile, UseHelper $useHelper): Namespace_ - { - $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); - $ast = $parser->parse(file_get_contents($entityFile)); - - $nodeFinder = new NodeFinder(); - - $useFlags = $nodeFinder->findInstanceOf($ast, UseUse::class); - /** @var UseUse $useFlag */ - foreach ($useFlags as $useFlag) { - $useHelper->addUsage((string) $useFlag->name); - } - - return $nodeFinder->findFirstInstanceOf($ast, Namespace_::class); - } -} diff --git a/src/Component/Generator/Definition/ParserBuilderTrait.php b/src/Component/Generator/Definition/ParserBuilderTrait.php deleted file mode 100644 index 5b274af..0000000 --- a/src/Component/Generator/Definition/ParserBuilderTrait.php +++ /dev/null @@ -1,75 +0,0 @@ -getShortName($field->name)), $this->buildArgsForParser($field->args)); - - if (!empty($field->flags)) { - $args = []; - - foreach ($field->flags as $flag) { - $useHelper->addUse($flag->name); - $args[] = new Arg(new New_(new Name($useHelper->getShortName($flag->name)), $this->buildArgsForParser($flag->args))); - } - - $parserField = new MethodCall($parserField, 'addFlags', $args); - } - - return $parserField; - } - - private function buildArgsForParser(array $elementArgs): array - { - $args = []; - - foreach ($elementArgs as $arg) { - switch (gettype($arg)) { - case 'string': - if (str_contains($arg, '::class')) { - $args[] = new Arg(new ClassConstFetch(new Name('\\' . substr($arg, 0, -7)), new Identifier('class'))); - } elseif (str_contains($arg, '::')) { - [$firstPart, $secondPart] = explode('::', $arg, 2); - $args[] = new Arg(new ClassConstFetch(new Name('\\' . $firstPart), new Identifier($secondPart))); - } else { - $args[] = new Arg(new String_($arg)); - } - - break; - case 'integer': - $args[] = new Arg(new LNumber($arg)); - break; - case 'NULL': - $args[] = new Arg(new ConstFetch(new Name('null'))); - break; - case 'boolean': - $args[] = new Arg(new ConstFetch(new Name($arg ? 'true' : 'false'))); - break; - case 'array': - $args[] = new Arg(new Array_()); - break; - default: - throw new \RuntimeException('Invalid type ' . gettype($arg)); - } - } - - return $args; - } -} diff --git a/src/Component/Generator/Definition/QuestionHelper.php b/src/Component/Generator/Definition/QuestionHelper.php deleted file mode 100644 index 692db65..0000000 --- a/src/Component/Generator/Definition/QuestionHelper.php +++ /dev/null @@ -1,51 +0,0 @@ -confirm(sprintf( - 'Is the %s property allowed to be null (nullable)?', - $fieldName - )); - - if (!$isNullable) { - $flags[] = new Flag(Required::class); - } - - if (in_array($type, self::HTML_RELEVANT_FIELDS, true)) { - $allowHtml = $io->confirm(sprintf( - 'Can %s contain html?', - $fieldName - ), false); - - if ($allowHtml) { - $flags[] = new Flag(AllowHtml::class); - } - } - - return $flags; - } - - public static function handleTranslationQuestion(SymfonyStyle $io): bool - { - return $io->confirm('Field can be translated?', false); - } -} diff --git a/src/Component/Generator/Definition/TypeMapping.php b/src/Component/Generator/Definition/TypeMapping.php deleted file mode 100644 index b9e2f86..0000000 --- a/src/Component/Generator/Definition/TypeMapping.php +++ /dev/null @@ -1,142 +0,0 @@ - 'string', - BoolField::class => 'bool', - CalculatedPriceField::class => 'array', - CartPriceField::class => 'array', - ChildCountField::class => 'int', - ChildrenAssociationField::class => '', - CreatedAtField::class => '\DateTime', - CustomFields::class => 'array', - DateField::class => '\DateTime', - DateTimeField::class => '\DateTime', - EmailField::class => 'string', - FkField::class => 'string', - FloatField::class => 'float', - IntField::class => 'int', - JsonField::class => 'array', - ListField::class => 'array', - LockedField::class => 'bool', - LongTextField::class => 'string', - ObjectField::class => 'array', - PriceDefinitionField::class => PriceDefinitionInterface::class, - PriceField::class => PriceCollection::class, - RemoteAddressField::class => 'array', - StateMachineStateField::class => 'string', - StringField::class => 'string', - TranslatedField::class => null, - TreeBreadcrumbField::class => 'array', - TreeLevelField::class => 'int', - TreePathField::class => 'string', - UpdatedAtField::class => '\DateTime', - VersionField::class => 'string', - PasswordField::class => 'string', - NumberRangeField::class => 'string', - ManyToManyIdField::class => 'array', - TranslationsAssociationField::class => 'translationCollection', - - ManyToOneAssociationField::class => 'associationField', - OneToOneAssociationField::class => 'associationField', - OneToManyAssociationField::class => 'associationField', - ManyToManyAssociationField::class => 'associationField', - ]; - - public static function getCompletionTypes(): array - { - $types = []; - foreach (array_keys(self::TYPES) as $fieldsType) { - $types[] = str_replace('Shopware\Core\Framework\DataAbstractionLayer\Field\\', '', $fieldsType); - } - - return $types; - } - - public static function mapToPhpType(Field $field, bool $respectNull, Definition $definition): string - { - $type = self::TYPES[$field->name] ?? null; - - if ($type === 'associationField') { - $type = substr($field->getReferenceClass(), 0, -7); - - if (str_contains($type, '\\')) { - $type = '\\' . $type; - } - } - - if ($type === 'translationCollection') { - return '\\' . $definition->translation->getCollectionClass(); - } - - if ($respectNull && $field->isNullable()) { - $type .= '|null'; - } - - if ($field->name === TranslatedField::class) { - return self::getTranslatedType($field, $respectNull, $definition); - } - - return $type; - } - - private static function getTranslatedType(Field $field, bool $respectNull, Definition $definition): string - { - foreach ($definition->translation->fields as $translatedField) { - if ($translatedField->getPropertyName() === $field->getPropertyName()) { - return self::mapToPhpType($translatedField, $respectNull, $definition); - } - } - - throw new \RuntimeException(sprintf('Field %s does not exists in translation', $field->getPropertyName())); - } -} diff --git a/src/Component/Generator/FixCodeStyle.php b/src/Component/Generator/FixCodeStyle.php deleted file mode 100644 index 95d2ac6..0000000 --- a/src/Component/Generator/FixCodeStyle.php +++ /dev/null @@ -1,62 +0,0 @@ -setRules([ - '@PSR2' => true, - '@Symfony' => true, - 'declare_strict_types' => true, - 'fully_qualified_strict_types' => true, - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline' - ], - 'ordered_class_elements' => true, - ]); - $config->setRiskyAllowed(true); - - $resolver = new ConfigurationResolver( - $config, - [ - 'dry-run' => false, - 'stop-on-violation' => false, - ], - getcwd(), - new ToolInfo() - ); - - $finder = new Finder(); - $finder = $finder->in($loaderResult->folder) - ->name('*' . $loaderResult->name . '*') - ->depth(0) - ->files(); - - $runner = new Runner( - $finder, - $resolver->getFixers(), - $resolver->getDiffer(), - new EventDispatcher(), - new ErrorsManager(), - $resolver->getLinter(), - $resolver->isDryRun(), - $resolver->getCacheManager(), - $resolver->getDirectory(), - $resolver->shouldStopOnViolation() - ); - - $runner->fix(); - } -} diff --git a/src/Component/Generator/QuestionHandler/GenericHandler.php b/src/Component/Generator/QuestionHandler/GenericHandler.php deleted file mode 100644 index 06e4b28..0000000 --- a/src/Component/Generator/QuestionHandler/GenericHandler.php +++ /dev/null @@ -1,164 +0,0 @@ -getConstructor()->getParameters(); - - $args = []; - foreach ($parameters as $parameter) { - if ($parameter->name === 'propertyName') { - $args[] = $name; - continue; - } - - if ($parameter->name === 'referenceClass') { - $question = new Question('Reference Class'); - $question->setAutocompleterValues($this->entityDefinitions); - $question->setValidator(function ($value) { - if (!in_array($value, $this->entityDefinitions, true)) { - throw new \InvalidArgumentException(sprintf('%s is an invalid reference class', $value)); - } - - return $value; - }); - $value = $io->askQuestion($question); - - $args[] = $value . '::class'; - continue; - } - - $default = null; - if ($parameter->isDefaultValueAvailable()) { - $default = $parameter->getDefaultValue(); - } - - if ($parameter->name === 'storageName' && $default === null) { - $default = (new CamelCaseToSnakeCaseNameConverter())->normalize($name); - } - - if (is_bool($default)) { - $default = $default ? 'true' : 'false'; - } - - // array is currently not supported - if (is_array($default)) { - $args[] = $default; - continue; - } - - $question = new Question('Parameter ' . $parameter->name, $default); - $answer = $io->askQuestion($question); - if ($answer === 'true') { - $answer = true; - } else if($answer === 'false') { - $answer = false; - } else if(strlen((string) $answer) && $parameter->hasType()) { - $parameterType = (string) ($parameter->getType() ? $parameter->getType()->getName() : null); - - if ($parameterType === 'int' || $parameterType === '?int') { - $answer = (int) $answer; - } else if($parameterType === 'float' || $parameterType === '?float') { - $answer = (float) $answer; - } - } - - $args[] = $answer; - } - - $field = new Field( - $type, - $args, - QuestionHelper::handleFlags($io, $name, $type, $args), - $definition->translation !== null && QuestionHelper::handleTranslationQuestion($io) - ); - - if (in_array($field->getName(), [OneToOneAssociationField::class, OneToManyAssociationField::class, ManyToOneAssociationField::class])) { - if ($io->confirm('Create an own entity extensions?')) { - $this->buildEntityExtension($field, $definition); - } - } - - return $field; - } - - private function buildEntityExtension(Field $field, Definition $localDefinition): void - { - $refClass = str_replace('::class', '', $field->getReferenceClass()); - $targetDefinition = $this->entityLoader->load($refClass, new SymfonyStyle(new ArgvInput(), new NullOutput())); - - $extensionField = null; - - if ($field->getName() === OneToOneAssociationField::class) { - $extensionField = new Field( - OneToOneAssociationField::class, - [ - $this->normalize($localDefinition->getDefinitionName()), - $field->getArg(2), // Obtain reference field from local - $field->getArg(1), // Obtain local field - $localDefinition->getDefinitionClass(). '::class' - ] - ); - } else if($field->getName() === OneToManyAssociationField::class) { - $extensionField = new Field( - ManyToOneAssociationField::class, - [ - $this->normalize($localDefinition->getDefinitionName()), - $field->getArg(2), // Obtain reference field from local - $localDefinition->getDefinitionClass(). '::class', // Reference class - $field->getArg(3) ?? 'id', // Obtain local field - ] - ); - } else if($field->getName() === ManyToOneAssociationField::class) { - $extensionField = new Field( - OneToManyAssociationField::class, - [ - $this->normalize($localDefinition->getDefinitionName()), - $localDefinition->getDefinitionClass(). '::class', // Reference class - $field->getArg(1), // Obtain reference field from local - $field->getArg(3) ?? 'id', // Obtain local field - ] - ); - } - - $this->extensionGenerator->generate( - $localDefinition, - $targetDefinition, - $extensionField - ); - } - - private function normalize(string $name): string - { - return (new CamelCaseToSnakeCaseNameConverter())->normalize($name); - } -} diff --git a/src/Component/Generator/QuestionHandler/ManyToManyHandler.php b/src/Component/Generator/QuestionHandler/ManyToManyHandler.php deleted file mode 100644 index 5c2e5f7..0000000 --- a/src/Component/Generator/QuestionHandler/ManyToManyHandler.php +++ /dev/null @@ -1,159 +0,0 @@ -args[] = $name; - - $question = new Question('Reference Class'); - $question->setAutocompleterValues($this->entityDefinitions); - $question->setValidator(function ($value) { - if (!in_array($value, $this->entityDefinitions, true)) { - throw new \InvalidArgumentException(sprintf('%s is an invalid reference class', $value)); - } - - return $value; - }); - - $referenceClass = $io->askQuestion($question); - $field->args[] = $referenceClass . '::class'; - - $referenceDefinition = $this->loader->load($referenceClass, $io); - $mappingDefinition = $this->createMappingDefinition($definition, $referenceDefinition); - - $this->definitionGenerator->generate($mappingDefinition); - - $field->args[] = $mappingDefinition->getDefinitionClass(); - $field->args[] = $mappingDefinition->getStorageNameByReference($definition->getDefinitionClass()); - $field->args[] = $mappingDefinition->getStorageNameByReference($referenceDefinition->getDefinitionClass()); - - $this->updateReference($io, $referenceDefinition, $definition, $mappingDefinition); - - return $field; - } - - private function createMappingDefinition(Definition $definition, Definition $reference): MappingDefinition - { - $mapping = new MappingDefinition(); - $mapping->name = $definition->name . $reference->name; - $mapping->namespace = $definition->namespace . '\\Aggregate\\' . $mapping->name; - $mapping->folder = $definition->folder . 'Aggregate/' . $mapping->name . '/'; - - $mapping->fields[] = new Field( - FkField::class, - [ - $this->normalize($definition->name) . '_id', - lcfirst($definition->name) . 'Id', - $definition->getDefinitionClass() . '::class' - ], - [ - new Flag(PrimaryKey::class), - new Flag(Required::class) - ] - ); - - $mapping->fields[] = new Field(ManyToOneAssociationField::class, - [ - lcfirst($definition->name), - $this->normalize($definition->name) . '_id', - $definition->getDefinitionClass() . '::class', - 'id', - false - ] - ); - - $mapping->fields[] = new Field( - FkField::class, - [ - $this->normalize($reference->name) . '_id', - lcfirst($reference->name) . 'Id', - $reference->getDefinitionClass() . '::class' - ], - [ - new Flag(PrimaryKey::class), - new Flag(Required::class) - ] - ); - - $mapping->fields[] = new Field(ManyToOneAssociationField::class, - [ - lcfirst($reference->name), - $this->normalize($reference->name) . '_id', - $reference->getDefinitionClass() . '::class', - 'id', - false - ] - ); - - $mapping->fields[] = new Field(CreatedAtField::class); - - return $mapping; - } - - private function normalize(string $name): string - { - return (new CamelCaseToSnakeCaseNameConverter())->normalize($name); - } - - private function updateReference(SymfonyStyle $io, Definition $reference, Definition $definition, MappingDefinition $mapping): void - { - $createExtension = $io->confirm('Create an own entity extensions?'); - - $field = new Field( - ManyToManyAssociationField::class, - [ - lcfirst($definition->name) . 's', - $definition->getDefinitionClass() . '::class', - $mapping->getDefinitionClass() . '::class', - $mapping->getStorageNameByReference($reference->getDefinitionClass()), - $mapping->getStorageNameByReference($definition->getDefinitionClass()), - ] - ); - - if ($createExtension) { - $this->extensionGenerator->generate($definition, $reference, $field); - } else { - $reference->fields[] = $field; - $this->definitionGenerator->generate($reference); - $this->entityGenerator->generate($reference); - } - } -} diff --git a/src/Component/Generator/QuestionHandler/QuestionHandlerInterface.php b/src/Component/Generator/QuestionHandler/QuestionHandlerInterface.php deleted file mode 100644 index 592b7fb..0000000 --- a/src/Component/Generator/QuestionHandler/QuestionHandlerInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -normalize($this->name); - } - - public function getEntityClassName(): string - { - return $this->name . 'Entity'; - } - - public function getCollectionClassName(): string - { - return $this->name . 'Collection'; - } - - public function getCollectionClass(): string - { - return $this->namespace . '\\' . $this->getCollectionClassName(); - } - - public function getDefinitionClassName(): string - { - return $this->name . 'Definition'; - } - - public function getDefinitionClass(): string - { - return $this->namespace . '\\' . $this->getDefinitionClassName(); - } - - public function getEntityFilePath(): string - { - return $this->folder . $this->getEntityClassName() . '.php'; - } - - public function getCollectionFilePath(): string - { - return $this->folder . $this->getCollectionClassName() . '.php'; - } - - public function getDefinitionFilePath(): string - { - return $this->folder . $this->getDefinitionClassName() . '.php'; - } -} diff --git a/src/Component/Generator/Struct/Field.php b/src/Component/Generator/Struct/Field.php deleted file mode 100644 index 2dee432..0000000 --- a/src/Component/Generator/Struct/Field.php +++ /dev/null @@ -1,150 +0,0 @@ -name = $name; - $this->args = $args; - $this->flags = $flags; - $this->translateable = $translateable; - } - - public function isNullable(): bool - { - foreach ($this->flags as $flag) { - if ($flag->name === Required::class) { - return false; - } - } - - return true; - } - - public function getPropertyName(): string - { - if ($this->propertyName) { - return $this->propertyName; - } - - if ($this->name === CustomFields::class) { - return 'customFields'; - } - - if ($this->name === TranslationsAssociationField::class) { - return 'translations'; - } - - $ref = new \ReflectionClass($this->name); - foreach ($ref->getConstructor()->getParameters() as $i => $parameter) { - if ($parameter->name === 'propertyName') { - return $this->propertyName = $this->args[$i]; - } - } - - throw new \RuntimeException('Cannot find propertyName'); - } - - public function getStorageName(): ?string - { - if ($this->storageName) { - return $this->storageName; - } - - if (in_array($this->name, [OneToManyAssociationField::class, ManyToManyAssociationField::class])) { - return $this->getReferenceClass(); - } - - if ($this->name === CustomFields::class) { - return 'customFields'; - } - - $ref = new \ReflectionClass($this->name); - foreach ($ref->getConstructor()->getParameters() as $i => $parameter) { - if ($parameter->name === 'storageName') { - return $this->storageName = $this->args[$i]; - } - } - - throw new \RuntimeException('Cannot find storageName'); - } - - public function getReferenceClass(): string - { - if ($this->referenceClass) { - return $this->referenceClass; - } - - if ($this->name === CustomFields::class) { - return 'custom_fields'; - } - - $ref = new \ReflectionClass($this->name); - foreach ($ref->getConstructor()->getParameters() as $i => $parameter) { - if ($parameter->name === 'referenceClass' || $parameter->name === 'referenceDefinition' || $parameter->name === 'toManyDefinitionClass') { - return $this->referenceClass = $this->args[$i]; - } - } - - throw new \RuntimeException('Cannot find referenceClass'); - } - - public function isStorageAware(): bool - { - return is_a($this->name, StorageAware::class, true); - } - - public function getName(): string - { - return $this->name; - } - - public function getArg(int $index) - { - return $this->args[$index] ?? null; - } -} diff --git a/src/Component/Generator/Struct/Flag.php b/src/Component/Generator/Struct/Flag.php deleted file mode 100644 index 6972ea2..0000000 --- a/src/Component/Generator/Struct/Flag.php +++ /dev/null @@ -1,22 +0,0 @@ -name = $name; - $this->args = $args; - } -} diff --git a/src/Component/Generator/Struct/MappingDefinition.php b/src/Component/Generator/Struct/MappingDefinition.php deleted file mode 100644 index f8f4ce5..0000000 --- a/src/Component/Generator/Struct/MappingDefinition.php +++ /dev/null @@ -1,21 +0,0 @@ -fields as $field) { - if ($field->name === FkField::class && $field->args[2] === $class) { - return $field->getStorageName(); - } - } - - throw new \RuntimeException(sprintf('Cannot find FkField for class "%s"', $class)); - } -} diff --git a/src/Component/Generator/Struct/TranslationDefinition.php b/src/Component/Generator/Struct/TranslationDefinition.php deleted file mode 100644 index 617f149..0000000 --- a/src/Component/Generator/Struct/TranslationDefinition.php +++ /dev/null @@ -1,11 +0,0 @@ -alreadyAddedUses[] = $use; - } - - public function addUse(string $use): void - { - if (in_array($use, $this->alreadyAddedUses, true)) { - return; - } - - $this->alreadyAddedUses[] = $use; - $this->printUses[] = $use; - } - - /** - * @return Use_[] - */ - public function getStms(): array - { - return array_map(static fn(string $use) => new Use_([new UseUse(new Name($use))]), $this->printUses); - } - - public function getShortName(string $name): string - { - $array = explode('\\', $name); - - return end($array); - } -} diff --git a/src/FroshDevelopmentHelper.php b/src/FroshDevelopmentHelper.php index 30c6a07..71d60b9 100644 --- a/src/FroshDevelopmentHelper.php +++ b/src/FroshDevelopmentHelper.php @@ -21,7 +21,6 @@ public function build(ContainerBuilder $container): void { $container->addCompilerPass(new DisableTwigCacheCompilerPass()); $container->addCompilerPass(new CustomProfilerExtensions()); - $container->addCompilerPass(new BuildEntityDefinitionNamesCompilerPass()); $this->buildConfig($container); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 73b1abf..7f129bd 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -7,24 +7,11 @@ %kernel.project_dir% - %frosh_development_helper.names% %kernel.plugin_infos% %frosh_development_helper.twig.exclude_keywords% - - - - - - - - - - - -