This commit is contained in:
2023-10-02 23:10:49 +03:00
commit c6cb488379
255 changed files with 18731 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Lucent\Channel;
use Lucent\Primitive\Collection;
use Lucent\Schema\Schema;
final class Channel
{
public string $lucentUrl;
public string $filesUrl;
/**
* @param Collection<Schema> $schemas
*/
function __construct(
public string $name,
public string $url,
public Collection $schemas,
public array $imageFilters,
// public Collection $previewTargets,
)
{
$this->lucentUrl = $url . "/lucent";
$this->filesUrl = $url . "/storage";
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Lucent\Channel;
use Lucent\Primitive\Collection;
use Lucent\Schema\Schema;
use Lucent\Schema\SchemaService;
use PhpOption\Option;
final class ChannelService
{
public Channel $channel;
private function __construct(
public SchemaService $schemaService
)
{
}
public static function fromConfig(): ChannelService
{
$configJson = file_get_contents(storage_path("lucent.config.json"));
$configArray = json_decode($configJson, true);
$schemaService = new SchemaService();
$schemasCollection = (new Collection($configArray["schemas"]))->map([$schemaService, 'fromArray']);
$channel = new Channel(
name: $configArray["name"],
url: rtrim($configArray["url"], "/"),
schemas: $schemasCollection,
imageFilters: $configArray["imageFilters"] ?? [],
);
$channelService = new ChannelService($schemaService);
$channelService->channel = $channel;
return $channelService;
}
/**
* @param string $name
* @return Option<Schema>
*/
public function getSchema(string $name): Option
{
$schema = $this->channel->schemas->firstWhere("name", $name);
if (empty($schema)) {
return none();
}
return some($schema);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Lucent\Channel;
use Lucent\Validator\Validator;
class PreviewTarget
{
function __construct(
public readonly string $label,
public readonly string $url,
)
{
Validator::single("label", $label, "required|min:2|max:50");
Validator::single("url", $url, "required|url");
}
public static function fromArray(array $data): PreviewTarget
{
return new PreviewTarget(
label: $data["label"],
url: $data["url"],
);
}
}