The problem I had today was located in a helper ( [Namespace]\[Module]\Helper\FileSystem ) which I have created for some basic filesystem operations. The below message was the result of Magento’s EQP which I use before I commit any code.
1 2 |
68 | WARNING | The use of function filectime() is discouraged 69 | WARNING | The use of function filemtime() is discouraged |
The warning message basically means, I should find another way to get the creation and modification time of a file because of Magento’s coding standards. I have done that a couple of times already and would like to share my solution this time. First you have to pass \Magento\Framework\Filesystem\Driver\File in your existing constructor or create a new one.
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); } |
Once you have re-compiled your code, you have access to the file stats as follows.
1 2 |
$file = '/absolute/path/to/your/file.extension'; $fileData = $this->driverFile->stat($file); |
Beside ctime and mtime the array $fileData should have other file information like size, atime, uid and gid.