mapado / rest-client-sdk-bundle

Symfony Bundle for https://github.com/mapado/rest-client-sdk
MIT License
5 stars 1 forks source link

Symfony 4 compatibility? Config location? #15

Closed wilmervanheerde closed 6 years ago

wilmervanheerde commented 6 years ago

Hi, is this bundle compatible with Symfony 4?

If it is, where to put the configuration? Symfony can't find the namespace for it

There is no extension able to load the configuration for "mapado_rest_client_sdk" (in /symfony4-project/product-service/config/mapado_rest_client_sdk.yml). Looked for namespace "mapado_rest_client_sdk", found "framework", "web_server", "twig", " security", "nelmio_cors", "doctrine_cache", "doctrine", "api_platform", "doctrine_migrations"

jdeniau commented 6 years ago

Just tried with a plain SF4 + flex configuration (I assume you are using flex + the new Symfony configuration) :

What I did made:

composer create-project symfony/skeleton my_project
cd my_project/
composer require mapado/rest-client-sdk-bundle
// config/bundle.php
<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Mapado\RestClientSdkBundle\MapadoRestClientSdkBundle::class => ['all' => true],
];
# config/packages/mapado_rest_client_sdk.yaml
mapado_rest_client_sdk:
    # debug: %kernel.debug%
    # cache_dir: '%kernel.cache_dir%/mapado/rest_client_sdk_bundle/'
    entity_managers:
        foo:
            server_url: 'http://foo.com:8080'
            mappings:
                dir: '%kernel.root_dir%/../src/Entity/'
# config/services.yaml

services:
    # ...
    Mapado\RestClientSdk\SdkClient: '@mapado.rest_client_sdk.foo'
<?php

namespace App\Controller;

use Mapado\RestClientSdk\SdkClient;
use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
    public function __construct(SdkClient $sdkClient)
    {
        $this->sdkClient = $sdkClient;
    }

    public function number()
    {
        $number = mt_rand(0, 100);

        var_dump(get_class($this->sdkClient)); // output : string(30) "Mapado\RestClientSdk\SdkClient"

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

I will update the README file to explain the "Symfony 4" way of thing, and maybe try to add a recipe if possible to auto-configure.

If you need help or find a bug somewhere, feel free to re-open the issue with more informations

wilmervanheerde commented 6 years ago

Thanks for the quick response, the solution you've provided works. Good that you updated the readme, should be clear now for other users :)

I'll close this issue now as it has been resolved. Feel free to re-open if needed.

jdeniau commented 6 years ago

For the record, the recipe PR is made, just waiting validation, so it should be even simpler for the next Symfony Flex users.

Thank you for your report though !

wilmervanheerde commented 6 years ago

Sorry to bug you again, how would I fetch multiple entity managers? With your current configuration it's only possible to assign a single entity manager

jdeniau commented 6 years ago

You can refer to the symfony documentation on how to autowire multiple instance of same type

The easy way is : don't auto-wire Another way can be : use the arguments binding by specifying different name for different managers

Ex:

SomeService:
        autowire: true

        # If you wanted to choose the non-default service, wire it manually
        arguments:
            $fooManager:  '@mapado.rest_client_sdk.foo'
            $barManager:  '@mapado.rest_client_sdk.bar'
wilmervanheerde commented 6 years ago

Thanks once again for your help, the issue has been resolved :)

Closing this issue again. Feel free to re-open.