mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
named backup changes
This commit is contained in:
@@ -21,7 +21,7 @@ class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
|
||||
imagesavealpha($clone, true);
|
||||
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
|
||||
|
||||
$image->setBackup($backupName, $clone);
|
||||
$image->setBackup($clone, $backupName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -19,9 +19,9 @@ class Image extends File
|
||||
protected $core;
|
||||
|
||||
/**
|
||||
* Image resource backup of current image processor
|
||||
* Array of Image resource backups of current image processor
|
||||
*
|
||||
* @var mixed
|
||||
* @var array
|
||||
*/
|
||||
protected $backups = array();
|
||||
|
||||
@@ -162,9 +162,15 @@ class Image extends File
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackup($name = 'default')
|
||||
public function getBackup($name = null)
|
||||
{
|
||||
$name = (is_null($name) ? 'default' : $name);
|
||||
$name = is_null($name) ? 'default' : $name;
|
||||
|
||||
if ( ! $this->backupExists($name)) {
|
||||
throw new \Intervention\Image\Exception\RuntimeException(
|
||||
"Backup with name ({$name}) not available. Call backup() before reset()."
|
||||
);
|
||||
}
|
||||
|
||||
return $this->backups[$name];
|
||||
}
|
||||
@@ -172,27 +178,30 @@ class Image extends File
|
||||
/**
|
||||
* Sets current image backup
|
||||
*
|
||||
* @param mixed $resource
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function setBackup($name, $value = null)
|
||||
public function setBackup($resource, $name = null)
|
||||
{
|
||||
// If there is just 1 argument specified then it's the value
|
||||
if (func_num_args() == 1) {
|
||||
$value = func_get_arg(0);
|
||||
$name = 'default';
|
||||
}
|
||||
elseif (is_null($name))
|
||||
{
|
||||
$name = 'default';
|
||||
}
|
||||
$name = is_null($name) ? 'default' : $name;
|
||||
|
||||
$this->backups[$name] = $value;
|
||||
$this->backups[$name] = $resource;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if named backup exists
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
private function backupExists($name)
|
||||
{
|
||||
return array_key_exists($name, $this->backups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current image is already encoded
|
||||
*
|
||||
|
@@ -15,7 +15,7 @@ class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
|
||||
$backupName = $this->argument(0)->value();
|
||||
|
||||
// clone current image resource
|
||||
$image->setBackup($backupName, clone $image->getCore());
|
||||
$image->setBackup(clone $image->getCore(), $backupName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user