Imbo\Storage\Filesystem::getLastModified PHP Method

getLastModified() public method

public getLastModified ( $user, $imageIdentifier )
    public function getLastModified($user, $imageIdentifier)
    {
        if (!$this->imageExists($user, $imageIdentifier)) {
            throw new StorageException('File not found', 404);
        }
        $path = $this->getImagePath($user, $imageIdentifier);
        // Get the unix timestamp
        $timestamp = filemtime($path);
        // Create a new datetime instance
        return new DateTime('@' . $timestamp, new DateTimeZone('UTC'));
    }

Usage Example

Example #1
0
 /**
  * @covers Imbo\Storage\Filesystem::getLastModified
  */
 public function testGetLastModified()
 {
     vfsStream::setup('basedir');
     $driver = new Filesystem(['dataDir' => vfsStream::url('basedir')]);
     $root = vfsStreamWrapper::getRoot();
     $last = $root;
     $parts = [$this->user[0], $this->user[1], $this->user[2], $this->user, $this->imageIdentifier[0], $this->imageIdentifier[1], $this->imageIdentifier[2]];
     foreach ($parts as $part) {
         $d = vfsStream::newDirectory($part);
         $last->addChild($d);
         $last = $d;
     }
     $now = time();
     $content = 'some binary content';
     $file = vfsStream::newFile($this->imageIdentifier);
     $file->setContent($content);
     $file->lastModified($now);
     $last->addChild($file);
     $this->assertInstanceOf('DateTime', $driver->getLastModified($this->user, $this->imageIdentifier));
 }