first version

This commit is contained in:
Bastian Allgeier
2019-01-13 23:17:34 +01:00
commit 01277f79f2
595 changed files with 82913 additions and 0 deletions

81
kirby/src/Cms/FileVersion.php Executable file
View File

@@ -0,0 +1,81 @@
<?php
namespace Kirby\Cms;
class FileVersion extends Asset
{
protected $modifications;
protected $original;
public function __call(string $method, array $arguments = [])
{
// public property access
if (isset($this->$method) === true) {
return $this->$method;
}
// asset method proxy
if (method_exists($this->asset(), $method)) {
if ($this->exists() === false) {
$this->save();
}
return $this->asset()->$method(...$arguments);
}
// content fields
return $this->original()->content()->get($method, $arguments);
}
public function id(): string
{
return dirname($this->original()->id()) . '/' . $this->filename();
}
public function kirby(): App
{
return $this->original()->kirby();
}
public function modifications(): array
{
return $this->modifications ?? [];
}
public function original(): File
{
return $this->original;
}
public function save()
{
$this->kirby()->thumb($this->original()->root(), $this->root(), $this->modifications());
return $this;
}
protected function setModifications(array $modifications = null)
{
$this->modifications = $modifications;
}
protected function setOriginal(File $original)
{
$this->original = $original;
}
/**
* Convert the object to an array
*
* @return array
*/
public function toArray(): array
{
$array = array_merge(parent::toArray(), [
'modifications' => $this->modifications(),
]);
ksort($array);
return $array;
}
}