Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chipslays committed Jul 3, 2024
1 parent a5acb24 commit d641d27
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
20 changes: 13 additions & 7 deletions src/Alisa.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Alisa\Events\Event;
use Alisa\Events\Group;
use Alisa\Events\Scene;
use Alisa\Support\Asset;
use Alisa\Support\Collection;
use Alisa\Support\Storage;
use Alisa\Yandex\Entities\DatetimeEntity;
Expand All @@ -28,7 +29,7 @@ class Alisa
{
protected Context $context;

protected Collection $options;
protected Config $config;

protected Storage $storage;

Expand All @@ -44,12 +45,12 @@ class Alisa

protected Sound $sound;

public function __construct(array $options = [])
public function __construct(array $config = [])
{
$this->options = new Collection($options);
$this->context = new Context($this->options->get('payload'));
$this->config = new Config($config);
$this->context = new Context($this->config->get('payload'));
$this->dispatcher = new Dispatcher;
$this->storage = new Storage($this->options->get('storage'), $this->options->get('skill_id'));
$this->storage = new Storage($this->config->get('storage'), $this->config->get('skill_id'));

// https://yandex.ru/dev/dialogs/alice/doc/health-check.html
if ($this->context->isPing()) {
Expand All @@ -75,6 +76,11 @@ public function __construct(array $options = [])
default => new Entity($entity, $this->context),
});
}

$this->components($this->config->get('components', []));
$this->middleware($this->config->get('middlewares', []));

Asset::load($this->config->get('assets', []));
}

public function components(array $components): static
Expand All @@ -92,9 +98,9 @@ public function components(array $components): static
return $this;
}

public function options(): Collection
public function config(): Config
{
return $this->options;
return $this->config;
}

public function context(): Context
Expand Down
29 changes: 29 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Alisa;

use Alisa\Support\Collection;

class Config extends Collection
{
protected array $items = [
'skill_id' => null,

'oauth' => null,

'storage' => null,

'payload' => null,

'assets' => [],

'components' => [],

'middlewares' => [],
];

public function __construct(array $items = [])
{
$this->items = array_replace_recursive($this->items, $items);
}
}
9 changes: 2 additions & 7 deletions src/Support/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ class Asset
{
protected static array $assets = [];

public static function set(array $assets): void
public static function load(array $assets): void
{
self::$assets = $assets;
}

public static function append(array $assets): void
{
self::$assets = [...self::$assets, ...$assets];
}

public static function add(string $alias, string $value): void
public static function set(string $alias, string $value): void
{
self::$assets[$alias] = $value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Yandex/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class Image

public function __construct(protected Alisa $alisa)
{
if (!$this->token = $this->alisa->options()->get('oauth')) {
if (!$this->token = $this->alisa->config()->get('oauth')) {
throw new ImageException('Заполните в конфиге OAuth-токен (token)');
}

if (!$this->skillId = $this->alisa->options()->get('skill_id')) {
if (!$this->skillId = $this->alisa->config()->get('skill_id')) {
if (!$this->skillId = $this->alisa->context()->get('session.skill_id')) {
throw new ImageException('Заполните в конфиге идентификатор навыка (skill_id)');
}
}

$root = rtrim($this->alisa->options()->get('storage', sys_get_temp_dir() . '/alisa'), '\/');
$root = rtrim($this->alisa->config()->get('storage', sys_get_temp_dir() . '/alisa'), '\/');

$this->path = $root . '/' . $this->skillId . '/__images__';

Expand Down
6 changes: 3 additions & 3 deletions src/Yandex/Sound.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class Sound

public function __construct(protected Alisa $alisa)
{
if (!$this->token = $this->alisa->options()->get('oauth')) {
if (!$this->token = $this->alisa->config()->get('oauth')) {
throw new SoundException('Заполните в конфиге OAuth-токен (token)');
}

if (!$this->skillId = $this->alisa->options()->get('skill_id')) {
if (!$this->skillId = $this->alisa->config()->get('skill_id')) {
if (!$this->skillId = $this->alisa->context()->get('session.skill_id')) {
throw new SoundException('Заполните в конфиге идентификатор навыка (skill_id)');
}
}

$root = rtrim($this->alisa->options()->get('storage', sys_get_temp_dir() . '/alisa'), '\/');
$root = rtrim($this->alisa->config()->get('storage', sys_get_temp_dir() . '/alisa'), '\/');

$this->path = $root . '/' . $this->skillId . '/__sounds__';

Expand Down

0 comments on commit d641d27

Please sign in to comment.