protected $_tmp;
protected $_dirs = array();
+ /** @var IVirtualDirectoryErrorListener|null */
+ protected $_errorListener = null;
+
public function __construct($path)
{
$this->_path = Files::mkdir($path);
$this->_tmp = array();
}
- public function copy($from, $to, $prepend = false,$check=true)
+ /**
+ * @return IVirtualDirectoryErrorListener|null
+ */
+ public function getErrorListener(): ?IVirtualDirectoryErrorListener
+ {
+ return $this->_errorListener;
+ }
+
+ /**
+ * @param IVirtualDirectoryErrorListener|null $errorListener
+ */
+ public function setErrorListener(?IVirtualDirectoryErrorListener $errorListener): void
+ {
+ $this->_errorListener = $errorListener;
+ }
+
+ protected function throwError($message)
+ {
+ if (null === $this->_errorListener) {
+ throw new \Exception($message);
+ }
+ $this->_errorListener->handleVirtualDirectoryError($message);
+ }
+
+
+ public function copy($from, $to, $prepend = false, $check = true)
{
if ($check && !file_exists($from)) {
- throw new \Exception(sprintf('File "%s" doesn\'t exist (to %s)', $from, $to));
+ $this->throwError(sprintf('File "%s" doesn\'t exist (to %s)', $from, $to));
}
$realto = $this->path($to);
if (!$realto) {
public function copyDirectory($from, $to)
{
if (!file_exists($from)) {
- throw new \Exception(sprintf('Directory %s doen\'t exist', $from));
+ $this->throwError(sprintf('Directory %s doen\'t exist', $from));
}
$this->_directories[$this->path($to)] = $from;
return $this;
}
if (!file_exists($from)) {
- throw new \Exception(sprintf('Failed to copy %s to %s. Source doesn\'t exist', $from, $to));
+ $this->throwError(sprintf('Failed to copy %s to %s. Source doesn\'t exist', $from, $to));
}
if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) !== filemtime($to)) {
$from_esc = escapeshellarg($from);
`cp -p $from_esc $to_esc`;
if (!file_exists($to)) {
- throw new \Exception(sprintf('Failed to copy %s to %s', $from, $to));
+ $this->throwError(sprintf('Failed to copy %s to %s', $from, $to));
}
}
}