Imbo\EventListener\ImageVariations\Storage\Filesystem::storeImageVariation PHP Method

storeImageVariation() public method

public storeImageVariation ( $user, $imageIdentifier, $blob, $width )
    public function storeImageVariation($user, $imageIdentifier, $blob, $width)
    {
        if (!is_writable($this->params['dataDir'])) {
            throw new StorageException('Could not store image variation (directory not writable)', 500);
        }
        $variationsDir = $this->getImagePath($user, $imageIdentifier, $width, false);
        $oldUmask = umask(0);
        if (!is_dir($variationsDir)) {
            mkdir($variationsDir, 0775, true);
        }
        umask($oldUmask);
        $variationsPath = $this->getImagePath($user, $imageIdentifier, $width);
        return (bool) file_put_contents($variationsPath, $blob);
    }

Usage Example

Example #1
0
 /**
  * @covers Imbo\EventListener\ImageVariations\Storage\Filesystem::storeImageVariation
  * @expectedException Imbo\Exception\StorageException
  * @expectedExceptionMessage Could not store image variation (directory not writable)
  * @expectedExceptionCode 500
  */
 public function testThrowsExceptionWhenNotAbleToWriteToDirectory()
 {
     $dir = 'unwritableDirectory';
     // Create the virtual directory with no permissions
     vfsStream::setup($dir, 0);
     $adapter = new Filesystem(['dataDir' => vfsStream::url($dir)]);
     $adapter->storeImageVariation('pub', 'img', 'blob', 700);
 }