@@ -52,8 +52,6 @@ discard block |
||
| 52 | 52 | * 'uploadFileBehavior' => [ |
| 53 | 53 | * 'class' => UploadFileBehavior::className(), |
| 54 | 54 | * 'nameOfAttributeStorage' => 'img_src', |
| 55 | - |
|
| 56 | - |
|
| 57 | 55 | * 'targets' => [ |
| 58 | 56 | * |
| 59 | 57 | * [ |
@@ -173,8 +171,8 @@ discard block |
||
| 173 | 171 | private $time = false; |
| 174 | 172 | |
| 175 | 173 | /** |
| 176 | - * @inheritdoc |
|
| 177 | - */ |
|
| 174 | + * @inheritdoc |
|
| 175 | + */ |
|
| 178 | 176 | public function init() |
| 179 | 177 | { |
| 180 | 178 | parent::init(); |
@@ -206,9 +204,9 @@ discard block |
||
| 206 | 204 | |
| 207 | 205 | } |
| 208 | 206 | |
| 209 | - /** |
|
| 210 | - * {@inheritdoc} |
|
| 211 | - */ |
|
| 207 | + /** |
|
| 208 | + * {@inheritdoc} |
|
| 209 | + */ |
|
| 212 | 210 | public function events() |
| 213 | 211 | { |
| 214 | 212 | return [ |
@@ -381,7 +379,7 @@ discard block |
||
| 381 | 379 | $baseName = $file->baseName; |
| 382 | 380 | $ext = $file->extension; |
| 383 | 381 | |
| 384 | - return $this->newFileName ? |
|
| 382 | + return $this->newFileName ? |
|
| 385 | 383 | $this->newFileName . '.' . $file->extension : |
| 386 | 384 | $file->baseName . '_' . $this->time . '.' . $file->extension; |
| 387 | 385 | } |
@@ -312,10 +312,9 @@ discard block |
||
| 312 | 312 | if(is_string($path)){ |
| 313 | 313 | $path = rtrim($path, '/') . '/'; |
| 314 | 314 | $dirPath = \Yii::getAlias($path); |
| 315 | - } |
|
| 316 | - elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) { |
|
| 315 | + } elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) { |
|
| 317 | 316 | $dirPath = $path($this->owner->attributes); |
| 318 | - }else{ |
|
| 317 | + } else{ |
|
| 319 | 318 | throw new InvalidCallException('Param `path` mast be string instanceof Closure or callable method.'); |
| 320 | 319 | } |
| 321 | 320 | |
@@ -325,7 +324,7 @@ discard block |
||
| 325 | 324 | protected function getHendler($hendler, $tmp, $path){ |
| 326 | 325 | if ($hendler instanceof Closure || (is_array($hendler) && is_callable($hendler))) { |
| 327 | 326 | $hendler($tmp, $path); |
| 328 | - }elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){ |
|
| 327 | + } elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){ |
|
| 329 | 328 | if(!in_array($hendler['type'], self::supportedFileTypes())) |
| 330 | 329 | { |
| 331 | 330 | throw new InvalidConfigException('File type not supported: ' . $hendler['type']); |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | break; |
| 342 | 341 | } |
| 343 | 342 | |
| 344 | - }else{ |
|
| 343 | + } else{ |
|
| 345 | 344 | throw new InvalidCallException('Param `hendler` mast be instanceof Closure ,callable method or array with allowed configs.'); |
| 346 | 345 | } |
| 347 | 346 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | class UploadFileBehavior extends Behavior |
| 106 | 106 | { |
| 107 | 107 | const TYPE_IMAGE = 'image'; |
| 108 | - const TYPE_FILE = 'file';//not supported yet |
|
| 108 | + const TYPE_FILE = 'file'; //not supported yet |
|
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * Name of attribute for recording file from form to ActiveRecord. DEfault name of attribute is `file` |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | ]; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - protected static function supportedFileTypes(){ |
|
| 223 | + protected static function supportedFileTypes() { |
|
| 224 | 224 | return [ |
| 225 | 225 | self::TYPE_IMAGE |
| 226 | 226 | ]; |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | public function loadFile() |
| 235 | 235 | { |
| 236 | - if($this->isFile()){ |
|
| 237 | - $this->owner->file = $this->getFileInstance();//virtual attribute |
|
| 236 | + if ($this->isFile()) { |
|
| 237 | + $this->owner->file = $this->getFileInstance(); //virtual attribute |
|
| 238 | 238 | $this->owner->{$this->nameOfAttributeStorage} = $this->getNewFileName(); |
| 239 | 239 | } |
| 240 | 240 | } |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | public function afterDelete($event) |
| 269 | 269 | { |
| 270 | - if($this->deleteImageWithRecord){ |
|
| 271 | - foreach($this->targets as $target){ |
|
| 270 | + if ($this->deleteImageWithRecord) { |
|
| 271 | + foreach ($this->targets as $target) { |
|
| 272 | 272 | $dirPath = $this->getPath($target['path']); |
| 273 | 273 | FileHelper::removeDirectory($dirPath); |
| 274 | 274 | } |
@@ -287,16 +287,16 @@ discard block |
||
| 287 | 287 | { |
| 288 | 288 | if ($this->isFile() && $this->inScenario()) |
| 289 | 289 | { |
| 290 | - foreach($this->targets as $target){ |
|
| 290 | + foreach ($this->targets as $target) { |
|
| 291 | 291 | $dirPath = $this->getPath($target['path']); |
| 292 | 292 | |
| 293 | - if(!$insert){ |
|
| 293 | + if (!$insert) { |
|
| 294 | 294 | |
| 295 | 295 | FileHelper::removeDirectory($dirPath); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | FileHelper::createDirectory($dirPath); |
| 299 | - $newFilePath = $dirPath . $this->getNewFileName(); |
|
| 299 | + $newFilePath = $dirPath.$this->getNewFileName(); |
|
| 300 | 300 | |
| 301 | 301 | $this->getHendler($target['hendler'], $this->getFileInstance()->tempName, $newFilePath); |
| 302 | 302 | |
@@ -309,29 +309,29 @@ discard block |
||
| 309 | 309 | * @param string $path |
| 310 | 310 | * @return string $dirPath |
| 311 | 311 | */ |
| 312 | - protected function getPath($path){ |
|
| 313 | - if(is_string($path)){ |
|
| 314 | - $path = rtrim($path, '/') . '/'; |
|
| 312 | + protected function getPath($path) { |
|
| 313 | + if (is_string($path)) { |
|
| 314 | + $path = rtrim($path, '/').'/'; |
|
| 315 | 315 | $dirPath = \Yii::getAlias($path); |
| 316 | 316 | } |
| 317 | 317 | elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) { |
| 318 | 318 | $dirPath = $path($this->owner->attributes); |
| 319 | - }else{ |
|
| 319 | + } else { |
|
| 320 | 320 | throw new InvalidCallException('Param `path` mast be string instanceof Closure or callable method.'); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | return $dirPath; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - protected function getHendler($hendler, $tmp, $path){ |
|
| 326 | + protected function getHendler($hendler, $tmp, $path) { |
|
| 327 | 327 | if ($hendler instanceof Closure || (is_array($hendler) && is_callable($hendler))) { |
| 328 | 328 | $hendler($tmp, $path); |
| 329 | - }elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){ |
|
| 330 | - if(!in_array($hendler['type'], self::supportedFileTypes())) |
|
| 329 | + }elseif (is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)) { |
|
| 330 | + if (!in_array($hendler['type'], self::supportedFileTypes())) |
|
| 331 | 331 | { |
| 332 | - throw new InvalidConfigException('File type not supported: ' . $hendler['type']); |
|
| 332 | + throw new InvalidConfigException('File type not supported: '.$hendler['type']); |
|
| 333 | 333 | } |
| 334 | - switch($hendler['type']) { |
|
| 334 | + switch ($hendler['type']) { |
|
| 335 | 335 | case self::TYPE_IMAGE: |
| 336 | 336 | $sizeW = $hendler['config']['size']['width']; |
| 337 | 337 | $sizeH = $hendler['config']['size']['height']; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | break; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - }else{ |
|
| 345 | + } else { |
|
| 346 | 346 | throw new InvalidCallException('Param `hendler` mast be instanceof Closure ,callable method or array with allowed configs.'); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -383,8 +383,7 @@ discard block |
||
| 383 | 383 | $ext = $file->extension; |
| 384 | 384 | |
| 385 | 385 | return $this->newFileName ? |
| 386 | - $this->newFileName . '.' . $file->extension : |
|
| 387 | - $file->baseName . '_' . $this->time . '.' . $file->extension; |
|
| 386 | + $this->newFileName.'.'.$file->extension : $file->baseName.'_'.$this->time.'.'.$file->extension; |
|
| 388 | 387 | } |
| 389 | 388 | |
| 390 | 389 | /** |