mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Update transformation lib structure
This commit is contained in:
@@ -4,22 +4,29 @@ namespace Appwrite\Transformation;
|
||||
|
||||
abstract class Adapter
|
||||
{
|
||||
protected mixed $input;
|
||||
protected mixed $output;
|
||||
|
||||
public function __construct(protected mixed $input)
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setInput(mixed $input): self
|
||||
{
|
||||
$this->input = $input;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOutput(): mixed
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $traits
|
||||
*/
|
||||
abstract public function isValid(array $traits): bool;
|
||||
|
||||
abstract public function transform(): bool;
|
||||
|
||||
public function getOutput(): mixed
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
abstract public function transform(): void;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Transformation\Adapter;
|
||||
|
||||
use Appwrite\Transformation\Adapter;
|
||||
|
||||
class Mock extends Adapter
|
||||
{
|
||||
/**
|
||||
* @param array<mixed> $traits Mock traits
|
||||
*/
|
||||
public function isValid(array $traits): bool
|
||||
{
|
||||
if ($traits['mock'] === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function transform(): void
|
||||
{
|
||||
$this->output = $this->input;
|
||||
$this->output = "Mock: " . $this->output;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class Preview extends Adapter
|
||||
return false;
|
||||
}
|
||||
|
||||
public function transform(): bool
|
||||
public function transform(): void
|
||||
{
|
||||
$this->output = $this->input;
|
||||
|
||||
@@ -197,7 +197,5 @@ class Preview extends Adapter
|
||||
EOT;
|
||||
|
||||
$this->output .= $banner;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,25 +4,71 @@ namespace Appwrite\Transformation;
|
||||
|
||||
class Transformation
|
||||
{
|
||||
public function __construct(protected Adapter $adapter)
|
||||
/**
|
||||
* @var array<Adapter> $adapters
|
||||
*/
|
||||
protected array $adapters;
|
||||
|
||||
/**
|
||||
* @var array<mixed> $traits
|
||||
*/
|
||||
protected array $traits;
|
||||
|
||||
protected mixed $input;
|
||||
protected mixed $output;
|
||||
|
||||
public function __construct(array $adapters = [])
|
||||
{
|
||||
$this->adapters = $adapters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $traits
|
||||
*/
|
||||
public function isValid(array $traits): bool
|
||||
public function setTraits(array $traits): self
|
||||
{
|
||||
return $this->adapter->isValid($traits);
|
||||
$this->traits = $traits;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setInput(mixed $input): self
|
||||
{
|
||||
$this->input = $input;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAdapter(Adapter $adapter): self
|
||||
{
|
||||
$this->adapters[] = $adapter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $traits
|
||||
*/
|
||||
public function transform(): bool
|
||||
{
|
||||
return $this->adapter->transform();
|
||||
foreach ($this->adapters as $adapter) {
|
||||
if (!$adapter->isValid($this->traits)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$output = $this->input;
|
||||
|
||||
foreach ($this->adapters as $adapter) {
|
||||
$adapter->setInput($output);
|
||||
$adapter->transform();
|
||||
$output = $adapter->getOutput();
|
||||
}
|
||||
|
||||
$this->output = $output;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getOutput(): mixed
|
||||
{
|
||||
return $this->adapter->getOutput();
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user