8000 [DependencyInjection] Wrong factory method reported in exception message during container compilation · Issue #29678 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Wrong factory method reported in exception message during container compilation #29678

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

Closed
zanbaldwin opened this issue Dec 24, 2018 · 0 comments

Comments

@zanbaldwin
Copy link
Member

Symfony version(s) affected: at least 3.4.20, 4.1.9, 4.2.1

Description

When a service definition with a factory defines invalid arguments, the resulting exception message incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments.

In ResolveNamedArgumentsPass.php line 70:

  Invalid service "GuzzleHttp\ClientInterface": method "App\Factory\ApiHttpClientFactory::__construct()" has no argument named "$baseUri". Check your service definition.

How to reproduce

  • git clone git://github.com/symfony/skeleton.git && cd skeleton
  • Add files config/packages/app.yaml and src/Factory/ApiClientFactory.php (see below).
  • composer install

Additional context

config/packages/app.yaml

parameters:
    env(API_AUTH_SECRET): 'password'
    env(API_BASE_URI): 'localhost:8080'

services:

    App\Factory\ApiClientFactory:
        arguments:
            $baseUri: '%env(API_AUTH_SECRET)%'
            $authSecret: '%env(API_BASE_URI)%'

    GuzzleHttp\ClientInterface:
        class: 'GuzzleHttp\ClientInterface'
        factory: [ 'App\Factory\ApiClientFactory', 'create' ]
        arguments:
            $baseUri: '%env(API_AUTH_SECRET)%'
            $authSecret: '%env(API_BASE_URI)%'

src/Factory/ApiClientFactory.php

<?php declare(strict_types=1);

namespace App\Factory;

use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\ClientInterface as GuzzleInterface;

class ApiClientFactory
{
    /** @var string $baseUri */
    private $baseUri;
    /** @var string $authSecret */
    private $authSecret;

    public function __construct(string $baseUri, string $authSecret)
    {
        $this->baseUri = $baseUri;
        $this->authSecret = $authSecret;
    }

    public function create(): GuzzleInterface
    {
        return new Guzzle([
            'base_uri' => $this->baseUri,
            'headers' => ['Authorization' => sprintf('Bearer %s', $this->authSecret)]
        ]);
    }
}
@zanbaldwin zanbaldwin changed the title [DependencyInjection] Wrong $class::$method() reported in exception message during compilation [DependencyInjection] Wrong factory method reported in exception message during container compilation Dec 24, 2018
@fabpot fabpot closed this as completed Jan 5, 2019
fabpot added a commit that referenced this issue Jan 5, 2019
…czyca)

This PR was submitted for the 4.2 branch but it was merged into the 4.1 branch instead (closes #29697).

Discussion
----------

[DI] Fixed wrong factory method in exception

| Q             | A
| ------------- | ---
| Branch?       |  4.2 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29678   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | n/a <!-- required for new features -->

When a service definition with a factory defines invalid arguments, the [resulting exception message ](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php#L70)incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments.

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

922885c [DI] Fixed wrong factory method in exception
xabbuh pushed a commit that referenced this issue Jan 5, 2019
…czyca)

This PR was submitted for the 4.2 branch but it was merged into the 4.1 branch instead (closes #29697).

Discussion
----------

[DI] Fixed wrong factory method in exception

| Q             | A
| ------------- | ---
| Branch?       |  4.2 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29678   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | n/a <!-- required for new features -->

When a service definition with a factory defines invalid arguments, the [resulting exception message ](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php#L70)incorrectly specifies the factory constructor instead of the factory method as not having the specified named arguments.

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

922885c [DI] Fixed wrong factory method in exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0