Today I was working on method which is responsible to read information of an uploaded file. I came across the same problem I had in my previous blog post ( The use of function filectime() / filemtime() is discouraged in Magento2 ).
1 |
154 | WARNING | The use of function is_readable() is discouraged |
This time it was able to get rid of the warning quickly, because \Magento\Framework\Filesystem\Driver\File was already injected in my constructor.
1 2 3 4 5 6 7 8 9 10 11 |
protected $driverFile; ... public function __construct( ... \Magento\Framework\Filesystem\Driver\File $driverFile, ... ) { $this->driverFile = $driverFile; ... parent::__construct($context); } |
I simply replaced is_readable with the below condition.
1 2 3 |
if ($this->driverFile->isReadable(...)) { } |
That’s it. Check my blog post about Working with files and folders in Magento2 for more information.