Closed wilmervanheerde closed 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
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.
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 !
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
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'
Thanks once again for your help, the issue has been resolved :)
Closing this issue again. Feel free to re-open.
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"