mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Implement DefinitionBook as MutableConfigurable
This is a slightly more correct implementation, but perhaps not worth the headache.
This commit is contained in:
parent
0ef406e6d2
commit
c835535176
@ -43,9 +43,7 @@ final class Reference implements StateUpdatingBlock
|
||||
'title' => isset($matches[3]) ? $matches[3] : null,
|
||||
];
|
||||
|
||||
$State = $State->setting(
|
||||
$State->get(DefinitionBook::class)->setting($id, $Data)
|
||||
);
|
||||
$State->get(DefinitionBook::class)->mutatingSet($id, $Data);
|
||||
|
||||
return new self($State);
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace Erusev\Parsedown\Configurables;
|
||||
|
||||
use Erusev\Parsedown\Configurable;
|
||||
use Erusev\Parsedown\MutableConfigurable;
|
||||
|
||||
/**
|
||||
* @psalm-type _Data=array{url: string, title: string|null}
|
||||
*/
|
||||
final class DefinitionBook implements Configurable
|
||||
final class DefinitionBook implements MutableConfigurable
|
||||
{
|
||||
/** @var array<string, _Data> */
|
||||
private $book;
|
||||
@ -29,14 +29,10 @@ final class DefinitionBook implements Configurable
|
||||
/**
|
||||
* @param string $id
|
||||
* @param _Data $data
|
||||
* @return self
|
||||
*/
|
||||
public function setting($id, array $data)
|
||||
public function mutatingSet($id, array $data): void
|
||||
{
|
||||
$book = $this->book;
|
||||
$book[$id] = $data;
|
||||
|
||||
return new self($book);
|
||||
$this->book[$id] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,4 +47,9 @@ final class DefinitionBook implements Configurable
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isolatedCopy(): self
|
||||
{
|
||||
return new self($this->book);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user