Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Ability to work without EasyThumbnail component
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed Nov 2, 2018
1 parent 7bc63fc commit d2e4b2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions EasyThumbnailImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use yii\base\InvalidConfigException;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\httpclient\Client as HttpClient;
use yii\imagine\Image;

/**
Expand Down Expand Up @@ -245,7 +246,7 @@ protected static function errorHandler($error, $filename)
*/
protected static function fileFromUrlDate($url)
{
$response = self::$httpClient
$response = self::getHttpClient()
->head($url)
->send();
if (!$response->isOk) {
Expand All @@ -264,7 +265,7 @@ protected static function fileFromUrlDate($url)
*/
protected static function fileFromUrlContent($url)
{
$response = self::$httpClient
$response = self::getHttpClient()
->createRequest()
->setMethod('GET')
->setUrl($url)
Expand All @@ -275,4 +276,16 @@ protected static function fileFromUrlContent($url)

return $response->content;
}

/**
* @return HttpClient
*/
protected static function getHttpClient()
{
if (self::$httpClient === null || !(self::$httpClient instanceof HttpClient)) {
self::$httpClient = new HttpClient();
}

return self::$httpClient;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ or add

to the require section of your application's `composer.json` file.

* Add a new component in `components` section of your application's configuration file (optional), for example:
* Add a new component in `components` section of your application's configuration file, for example:

```php
'components' => [
Expand Down

0 comments on commit d2e4b2e

Please sign in to comment.