@@ -31,8 +31,9 @@ discard block |
||
| 31 | 31 | $this->width = $width; |
| 32 | 32 | $this->webp = $webp; |
| 33 | 33 | |
| 34 | - if ($this->model->type != FileType::IMAGE) |
|
| 35 | - throw new ErrorException('File is not an image.'); |
|
| 34 | + if ($this->model->type != FileType::IMAGE) { |
|
| 35 | + throw new ErrorException('File is not an image.'); |
|
| 36 | + } |
|
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | /** |
@@ -40,8 +41,9 @@ discard block |
||
| 40 | 41 | */ |
| 41 | 42 | public function getUrl() |
| 42 | 43 | { |
| 43 | - if ($this->model->isSvg()) |
|
| 44 | - return $this->model->getRootPath(); |
|
| 44 | + if ($this->model->isSvg()) { |
|
| 45 | + return $this->model->getRootPath(); |
|
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | $this->fileName = Yii::$app->getModule('files')->cacheFullPath . DIRECTORY_SEPARATOR . $this->model->makeNameWithSize($this->model->filename, |
| 47 | 49 | $this->width, 0); |
@@ -50,14 +52,17 @@ discard block |
||
| 50 | 52 | |
| 51 | 53 | $this->prepareFolder(); |
| 52 | 54 | |
| 53 | - if (!file_exists($this->fileName) || filesize($this->fileName) == 0) |
|
| 54 | - $this->createPreview(); |
|
| 55 | + if (!file_exists($this->fileName) || filesize($this->fileName) == 0) { |
|
| 56 | + $this->createPreview(); |
|
| 57 | + } |
|
| 55 | 58 | |
| 56 | - if ($this->webp && !file_exists($this->fileNameWebp)) |
|
| 57 | - $this->createPreviewWebp(); |
|
| 59 | + if ($this->webp && !file_exists($this->fileNameWebp)) { |
|
| 60 | + $this->createPreviewWebp(); |
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | - if ($this->webp) |
|
| 60 | - return $this->fileNameWebp; |
|
| 63 | + if ($this->webp) { |
|
| 64 | + return $this->fileNameWebp; |
|
| 65 | + } |
|
| 61 | 66 | |
| 62 | 67 | return $this->fileName; |
| 63 | 68 | } |
@@ -79,8 +84,9 @@ discard block |
||
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | $saveType = $img->image_type; |
| 82 | - if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC) |
|
| 83 | - $saveType = IMG_JPEG; |
|
| 87 | + if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC) { |
|
| 88 | + $saveType = IMG_JPEG; |
|
| 89 | + } |
|
| 84 | 90 | $img->save($this->fileName, $saveType); |
| 85 | 91 | } |
| 86 | 92 | |
@@ -99,20 +105,24 @@ discard block |
||
| 99 | 105 | */ |
| 100 | 106 | protected function prepareFolder() |
| 101 | 107 | { |
| 102 | - if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) |
|
| 103 | - mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
| 108 | + if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) { |
|
| 109 | + mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
| 110 | + } |
|
| 104 | 111 | $folders = []; |
| 105 | 112 | $lastFolder = '/'; |
| 106 | 113 | $explodes = explode('/', $this->fileName); |
| 107 | 114 | array_pop($explodes); |
| 108 | - if (empty($explodes)) |
|
| 109 | - return; |
|
| 115 | + if (empty($explodes)) { |
|
| 116 | + return; |
|
| 117 | + } |
|
| 110 | 118 | foreach ($explodes as $folder) { |
| 111 | - if (empty($folder)) |
|
| 112 | - continue; |
|
| 119 | + if (empty($folder)) { |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 113 | 122 | $lastFolder = $lastFolder . $folder . '/'; |
| 114 | - if (!file_exists($lastFolder)) |
|
| 115 | - mkdir($lastFolder); |
|
| 123 | + if (!file_exists($lastFolder)) { |
|
| 124 | + mkdir($lastFolder); |
|
| 125 | + } |
|
| 116 | 126 | $folders[] = $lastFolder; |
| 117 | 127 | } |
| 118 | 128 | } |