From ebc687a8c13316193c1fee26e1cce32583a695fa Mon Sep 17 00:00:00 2001 From: Alexander Mohorev Date: Fri, 15 May 2020 12:59:57 +0300 Subject: [PATCH] Change file property visibility to protected (#63) --- .travis.yml | 4 +++- src/UploadBehavior.php | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 44bdcae..74e074d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 sudo: false @@ -25,7 +27,7 @@ before_script: fi script: - - phpunit --verbose $PHPUNIT_FLAGS + - ./vendor/bin/phpunit --verbose $PHPUNIT_FLAGS after_script: - | diff --git a/src/UploadBehavior.php b/src/UploadBehavior.php index 8d7791b..34d5978 100644 --- a/src/UploadBehavior.php +++ b/src/UploadBehavior.php @@ -87,7 +87,7 @@ class UploadBehavior extends Behavior /** * @var UploadedFile the uploaded file instance. */ - private $_file; + protected $file; /** @@ -132,17 +132,17 @@ public function beforeValidate() $model = $this->owner; if (in_array($model->scenario, $this->scenarios)) { if (($file = $model->getAttribute($this->attribute)) instanceof UploadedFile) { - $this->_file = $file; + $this->file = $file; } else { if ($this->instanceByName === true) { - $this->_file = UploadedFile::getInstanceByName($this->attribute); + $this->file = UploadedFile::getInstanceByName($this->attribute); } else { - $this->_file = UploadedFile::getInstance($model, $this->attribute); + $this->file = UploadedFile::getInstance($model, $this->attribute); } } - if ($this->_file instanceof UploadedFile) { - $this->_file->name = $this->getFileName($this->_file); - $model->setAttribute($this->attribute, $this->_file); + if ($this->file instanceof UploadedFile) { + $this->file->name = $this->getFileName($this->file); + $model->setAttribute($this->attribute, $this->file); } } } @@ -155,13 +155,13 @@ public function beforeSave() /** @var BaseActiveRecord $model */ $model = $this->owner; if (in_array($model->scenario, $this->scenarios)) { - if ($this->_file instanceof UploadedFile) { + if ($this->file instanceof UploadedFile) { if (!$model->getIsNewRecord() && $model->isAttributeChanged($this->attribute)) { if ($this->unlinkOnSave === true) { $this->delete($this->attribute, true); } } - $model->setAttribute($this->attribute, $this->_file->name); + $model->setAttribute($this->attribute, $this->file->name); } else { // Protect attribute unset($model->{$this->attribute}); @@ -181,10 +181,10 @@ public function beforeSave() */ public function afterSave() { - if ($this->_file instanceof UploadedFile) { + if ($this->file instanceof UploadedFile) { $path = $this->getUploadPath($this->attribute); if (is_string($path) && FileHelper::createDirectory(dirname($path))) { - $this->save($this->_file, $path); + $this->save($this->file, $path); $this->afterUpload(); } else { throw new InvalidArgumentException( @@ -242,7 +242,7 @@ public function getUploadUrl($attribute) */ protected function getUploadedFile() { - return $this->_file; + return $this->file; } /**