-1

I have the following service :

<?php

namespace App\Services;

use ADOConnection;

class ADOdbConnection
{
    /**
     * AdodbConnection constructor.
     * @param $host
     * @param $user
     * @param $pwd
     * @param $db
     */
    public function __construct($host, $user, $pwd, $db_name)
    {
        $db = ADONewConnection('odbc');
        $db->connect($host, $user, $pwd, $db_name);
    }

    /**
     * Testing current connection
     * @return mixed
     */
    public function testConnection()
    {
        return $this->db->IsConnected();
    }

}

Very simple, and the pending configuration into config/services.yaml :

// config/services.yaml
services:
   //... -- 15 lines -- //
   App\Services\ADOdbConnection:
        arguments:
            $host: '111.11.11.11'
            $user: 'ROOT'
            $pwd: '%env(resolve:DATABASE_W2_PASSWORD)%'
            $db_name: 'CUSTOMER'

(See full config/services.yaml)

In my controller i got this :

public function index(ADOdbConnection $ADOdbConnection)
    {
        dump($ADOdbConnection->testConnection());
}

And the result is this error :

Cannot resolve argument $ADOdbConnection of "App\Controller\ArticleController::index()": Cannot autowire service "App\Services\ADOdbConnection": argument "$host" of method "__construct()" has no type-hint, you should configure its value explicitly.

I have read this doc :

And this one :

I do the same thing as explain in the symfonycast formation, but i can't get it why it is not working...

I have also read this :

But i'm not interested in this feature at the moment.

EDIT :

I just figure that i need to define the arguments configuration into my config/services_dev.yaml but to me this is a weird since kernel read the file in order

  • config/services.yaml
  • then config/services_XXX.yaml

So i should not need to define those parameter a second time.

vincent PHILIPPE
  • 975
  • 11
  • 26
  • I just figure that i need to define the arguments configuration into my ``config/services_dev.yaml`` but to me this is a weird since kernel read the file in order -> config/services.yaml -> then config/services_XXX.yaml – vincent PHILIPPE Jul 28 '20 at 08:18
  • Consider creating a new project and just wire this one service. The notion that it works with services_dev.yaml possibly indicates that some other code is trying to configure it. Maybe even a third party compiler pass? Does seem strange. Symfony version? Is this a legacy project? – Cerad Jul 28 '20 at 10:55
  • Yes it is a standard project i use symfony 5. I've created this project 3 week ago. I'll try later to create a new project. – vincent PHILIPPE Jul 28 '20 at 13:12

1 Answers1

0

Arguments in ADOdbConnection constructor and service.yaml should match. Your 4th parameter is $db_name, but it's $db: 'CUSTOMER' in YAML.

P.S. I don't think you need service_dev.yml for this issue.

Leprechaun
  • 759
  • 5
  • 14
  • I've edit my services.yaml file to match constructor parameter name, and i have remove services_dev.yaml configuration for this services. Now i still have the same error :( – vincent PHILIPPE Jul 28 '20 at 08:48
  • Could you provide full config/services.yaml file? You can use https://gist.github.com/ for this – Leprechaun Jul 28 '20 at 08:53
  • https://gist.github.com/Vin57/040245c96a74ded4b75064d7f268cb38 Can you see it ? – vincent PHILIPPE Jul 28 '20 at 08:55
  • Really weird, it's working in my local env. So configuration and class are totally fine. Maybe it's cache issue? Try `php bin/console cache:clear --env=prod`. And I don't really understand why file `service_dev.yml` is working for you. – Leprechaun Jul 28 '20 at 09:27
  • This still not working even after clearing the cache, sad me – vincent PHILIPPE Jul 28 '20 at 09:30