diff --git a/composer.json b/composer.json index a5b5914e4..5f63f311d 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "qtism/qtism", "description": "OAT QTI Software Module Library", "type": "library", - "version": "0.9.21", + "version": "0.9.22", "authors": [ { "name": "Open Assessment Technologies S.A.", diff --git a/qtism/common/datatypes/files/FileSystemFile.php b/qtism/common/datatypes/files/FileSystemFile.php index 22d26df4d..7106a68df 100644 --- a/qtism/common/datatypes/files/FileSystemFile.php +++ b/qtism/common/datatypes/files/FileSystemFile.php @@ -75,11 +75,15 @@ class FileSystemFile implements File { * @throws RuntimeException If the file cannot be retrieved correctly. */ public function __construct($path) { + $this->setPath($path); + } + + private function readInfo() { // Retrieve filename and mime type. - $fp = @fopen($path, 'r'); + $fp = @fopen($this->getPath(), 'r'); if ($fp === false) { - $msg = "Unable to retrieve QTI file at '${path}."; + $msg = "Unable to retrieve QTI file at '".$this->getPath()."."; throw new RuntimeException($msg); } @@ -95,7 +99,6 @@ public function __construct($path) { $this->setFilename($filename); $this->setMimeType($mimeType); - $this->setPath($path); } /** @@ -121,10 +124,16 @@ protected function setMimeType($mimeType) { } public function getMimeType() { + if (is_null($this->mimeType)) { + $this->readInfo(); + } return $this->mimeType; } public function getFilename() { + if (empty($this->filename)) { + $this->readInfo(); + } return $this->filename; } @@ -332,4 +341,4 @@ public function getIdentifier() { public function __toString() { return $this->getFilename(); } -} \ No newline at end of file +} diff --git a/test/qtism/common/datatypes/files/FileSystemFileTest.php b/test/qtism/common/datatypes/files/FileSystemFileTest.php index 9e284b899..8b51020ab 100644 --- a/test/qtism/common/datatypes/files/FileSystemFileTest.php +++ b/test/qtism/common/datatypes/files/FileSystemFileTest.php @@ -72,6 +72,7 @@ public function testGetStream($path, $expectedData) { public function testInstantiationWrongPath() { $this->setExpectedException('\\RuntimeException'); $pFile = new FileSystemFile('/qtism/test'); + $pFile->getFilename(); } public function retrieveProvider() { @@ -96,4 +97,4 @@ public function createFromExistingFileProvider() { array(self::samplesDir() . 'datatypes/file/raw/text.txt', 'text/plain', 'new-name.txt'), ); } -} \ No newline at end of file +}