Service Locators

I am learning Yii2 concepts and writing an application based on it.

Until things went too far I’d like to understand the idea of Application components/Service locators.

I’m using few external libraries like Guzzle and PHPExcel. Also I’m planning to add more libraries which will be used in different places of application.

Should I register those libraries as application components as described in guides?

What is better:

$client = new \GuzzleHttp\Client;



Well, it depends on how do you plan using these. Yii::$app->guzzle provides a way to configure component application wide and make sure you have only one instance. I’m not sure it’s actually needed in your case. Also if you don’t plan replacing guzzle with something else there’s no sense in abstracting it.