41 lines
1 KiB
PHP
41 lines
1 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Component\File;
|
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
use Trinity\Component\Exception\FileMethodNotFoundException;
|
|
|
|
class FileUploadCallback
|
|
{
|
|
protected $object;
|
|
protected $name;
|
|
|
|
public function __construct(FileUploadInterface $object, $name)
|
|
{
|
|
$this->object = $object;
|
|
$this->name = $name;
|
|
}
|
|
|
|
public function removeFile()
|
|
{
|
|
$getter = sprintf('get%s', ucfirst($this->name));
|
|
$setter = sprintf('set%s', ucfirst($this->name));
|
|
|
|
$file = call_user_func(array($this->object, $getter));
|
|
|
|
if (null !== $file && is_object($file) && $file instanceof File) {
|
|
return unlink($file->getRealpath());
|
|
}
|
|
|
|
return call_user_func(array($this->object, $setter), '');
|
|
}
|
|
|
|
public function rollBackField()
|
|
{
|
|
$rollback = sprintf('rollback_%s', $this->name);
|
|
$setter = sprintf('set%s', ucfirst($this->name));
|
|
|
|
return call_user_func(array($this->object, $setter), $this->object->$rollback);
|
|
}
|
|
}
|