Skip to content

Remove autowiring #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2023
Merged

Conversation

norkunas
Copy link
Collaborator

Pull Request

Related issue

Fixes #279

What does this PR do?

  • Removes services autowiring as they should be defined explicitly.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

@norkunas norkunas requested a review from brunoocasali August 16, 2023 06:21
@@ -31,7 +31,6 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
} else {
$loader->load(__DIR__.'/config/config_php7.yaml');
}
$loader->load(__DIR__.'/../config/services.xml');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong, because the MeilisearchBundle loads the services, so this was just overrode always what the bundle defined, that means what we set in MeilisearchExtension was lost and many tests were failing because the configuration was not properly injected to the SearchService.

{
$this->normalizer = $normalizer;
$this->engine = $engine;
$this->configuration = new Collection($configuration);
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
$this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony defines a property accessor already, so we can inject it through DI.

@norkunas norkunas force-pushed the remove-autowiring branch 2 times, most recently from 7b29a3d to f8da79c Compare August 16, 2023 06:24
@norkunas
Copy link
Collaborator Author

@brunoocasali not sure tests/Integration/EventListener/DoctrineEventSubscriberTest.php was supposed to test, as now it always fail.

I think that it needs to use a different config without any subscribed events, to test each event separately?

@norkunas norkunas force-pushed the remove-autowiring branch 3 times, most recently from d9f4dc5 to dd4483e Compare August 16, 2023 06:52
Comment on lines +30 to +35
<argument /><!-- url -->
<argument /><!-- api key -->
<argument type="service" id="psr18.http_client" on-invalid="ignore" /><!-- http client -->
<argument>null</argument><!-- request factory -->
<argument /><!-- client agents -->
<argument>null</argument><!-- stream factory -->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to rework this as something was not right on Symfony 5.4: Symfony\Component\DependencyInjection\Exception\RuntimeException: Invalid constructor argument for service "meilisearch.client": integer expected but found string "url". Check your service definition.

@@ -17,10 +17,10 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode
->children()
->scalarNode('url')->end()
->scalarNode('url')->cannotBeEmpty()->end()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is like a BC break.. but Meilisearch\Client expects a string for the base url and if it was not set then MeilisearchExtension was setting argument to null which does not make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Not adding the URL means the library will not work. Unless somewhere else we have the localhost being passed automatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, we could set http://localhost:7700 as default value then, at least it would not break app in compilation time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be written somewhere then :)

<argument key="$clientAgents" type="collection">
<argument>%meili_symfony_version%</argument>
</argument>
<argument /><!-- url -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, now we don't need to add the key=""?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the src/DependencyInjection/MeilisearchExtension.php, I saw that you are changing to use a positional instead of a named argument. How is this better?

Copy link
Collaborator Author

@norkunas norkunas Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After PR, I left the comment about it :) #285 (comment)

@norkunas norkunas force-pushed the remove-autowiring branch 5 times, most recently from 2a704fb to ab4c3f4 Compare August 18, 2023 07:34
Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved! LGTM!

@norkunas
Copy link
Collaborator Author

bors merge

@norkunas norkunas closed this Aug 21, 2023
@meili-bors meili-bors bot merged commit ecd40c1 into meilisearch:main Aug 21, 2023
@norkunas norkunas deleted the remove-autowiring branch August 22, 2023 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autowiring should not be used
2 participants