JohanM Posted March 31, 2020 Share Posted March 31, 2020 Hi guys! I have a specific requirement and need some help Say i have an external api library with Client class looking like this: class Client { some constants.. private props.., __construct public function create($url) { some code } public function authenticate($token) { some code } ...dozen other methods } Current way of instantiating in every single other class where i need the client: use Client; MyFetchController { private $client; public function __construct() { $this->client = Client::create(getenv('URL'))->authenticate(getenv('TOKEN')) } $this->client->use other methods in Client class } Is there a way to wrap that class so i have external parameters loaded through .env file automaticaly available on new wrapper class intialization with something like this: MyFetchController { private $client; public function __construct(WrappedClient $client) { $this->client = $client } public function getData() { $data = $this->client->parse(...) } } Basically what i need is a class ready for DI in all other classes without inserting required auth and other parameters in constructor every single time Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2020 Share Posted March 31, 2020 Don't double-post Link to comment Share on other sites More sharing options...
Recommended Posts