I am trying to use guzzle 6.x on a CakePHP 2.x application.
What I need to do is to initialize Guzzle Client to some of my controllers but on the controllers that it will be loaded I need it to be loaded with the same configuration.
Basically what I don't know is which is the best approach to implement it. I was thinking about the following:
- Shall I create a function in
AppController
that will create and return a Guzzle object and then save it to a protected property insideAppController
? Maybe a function likesetUpGuzzle()
and call this function on the Controllers I need to load Guzzle Client. - Shall I create a component and then load Guzzle Client to a public property of this component. Then I could use it like this
$this->HttpClient->client->post()
- Shall I create a component and write one function for each of Guzzle public function? So I will have something like this
$this->HttpClient->post()
. - Thing is I don't like any of the above and I was hopping maybe there could be another way to do this. For example create a components which loads the Guzzle Client in a controller or loads the Guzzle Client inside the component collection.