Skip to content

Commit

Permalink
bug #474 Resource alias, always return 2 array items (Prometee, lchru…
Browse files Browse the repository at this point in the history
…sciel)

This PR was merged into the 1.9 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #473 
| License         | MIT

This PR fix #473 

Commits
-------

4e3d317 Always return 2 array items
bbb7304 Fix psalm errors
6cfc3cf [Test] Covering bugged case with spec to ensure that resource name may contain dots
  • Loading branch information
GSadee authored Aug 12, 2022
2 parents c19cf42 + 6cfc3cf commit 08f94b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, Configurati

if ($parentMetadata->isMappedSuperclass) {
foreach ($parentMetadata->getAssociationMappings() as $key => $value) {
Assert::integer($value['type']);

if ($this->isRelation($value['type']) && !isset($metadata->associationMappings[$key])) {
$metadata->associationMappings[$key] = $value;
}
Expand All @@ -96,8 +94,6 @@ private function unsetAssociationMappings(ClassMetadataInfo $metadata): void
}

foreach ($metadata->getAssociationMappings() as $key => $value) {
Assert::integer($value['type']);

if ($this->isRelation($value['type'])) {
unset($metadata->associationMappings[$key]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/EventListener/ORMTranslatableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void

public function postLoad(LifecycleEventArgs $args): void
{
$entity = $args->getEntity();
$entity = $args->getObject();

if (!$entity instanceof TranslatableInterface) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ private static function parseAlias(string $alias): array
throw new \InvalidArgumentException(sprintf('Invalid alias "%s" supplied, it should conform to the following format "<applicationName>.<name>".', $alias));
}

return explode('.', $alias);
return explode('.', $alias, 2);
}
}
23 changes: 23 additions & 0 deletions src/Component/spec/Metadata/MetadataSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ function it_has_alias(): void
$this->getAlias()->shouldReturn('app.product');
}

function it_allows_to_have_alias_with_dot_in_name(): void
{
$this->beConstructedThrough('fromAliasAndConfiguration', [
'app.product.with.dots',
[
'driver' => 'doctrine/orm',
'templates' => 'AppBundle:Resource',
'classes' => [
'model' => 'AppBundle\Model\Resource',
'form' => [
'default' => 'AppBundle\Form\Type\ResourceType',
'choice' => 'AppBundle\Form\Type\ResourceChoiceType',
'autocomplete' => 'AppBundle\Type\ResourceAutocompleteType',
],
],
],
]);

$this->getAlias()->shouldReturn('app.product.with.dots');
$this->getApplicationName()->shouldReturn('app');
$this->getName()->shouldReturn('product.with.dots');
}

function it_has_application_name(): void
{
$this->getApplicationName()->shouldReturn('app');
Expand Down

0 comments on commit 08f94b4

Please sign in to comment.