K
K
kaxa32012019-07-31 19:37:18
symfony
kaxa3201, 2019-07-31 19:37:18

How to correctly write Di in yaml?

I use a separate component "symfony/http-foundation" write test classes
I get this error

The routing file "/code/app/Http/Controllers/../../../config/services.yaml" contains unsupported keys for "services": "demo.service", "dependent.service". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition", "controller", "name_prefix", "trailing_slash_on_root", "locale", "format", "utf8".

services:
  demo.service:
    class:     \App\Services\DemoService
  dependent.service:
    class:     \App\Services\DependentService
    arguments: ["@demo.service"]

<?php
namespace App\Services;
class DemoService
{
    public function helloWorld()
    {
        return "Hello World!\n";
    }
}

<?php
namespace App\Services;
class DependentService
{
    private $demo_service;

    public function __construct( $demoService)
    {
        $this->demo_service = $demoService;
    }
    public function helloWorld()
    {
        return $this->demo_service->helloWorld();
    }
}

class ExampleController
{
    public function test(Request $request)
    {
        $containerBuilder = new ContainerBuilder();
        $loader = new YamlFileLoader(new FileLocator(__DIR__));
        $loader->load('../../../config/services.yaml');

        $service = $containerBuilder->get('dependent.service');
       echo $serviceOne->helloWorld();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Derepko, 2019-07-31
@kaxa3201

If the problem is in the config, why are you showing incomprehensible DependentService/Service?
What is ExampleController and why does it return a service instance?
How is the route configured?
services.yml to studio

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question