Skip to content

Commit afa2851

Browse files
committed
Added name getter to morphy, also added check morphy names for uniqueness
1 parent 3c75e8c commit afa2851

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Factory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ public static function makeMorphy(array $config, ?array $commonOptions = null):
3838
$dictsPath = ($dictsPath === null || $dictsStorage !== 'storage') ?:
3939
Storage::path($dictsPath);
4040

41-
return new Morphy($config['language'], $options, $dictsPath);
41+
return new Morphy($config['name'], $config['language'], $options, $dictsPath);
4242
}
4343

4444
public static function fromArray(array $configs, ?array $commonOptions = null): array
4545
{
4646
$morphies = [];
4747
foreach ($configs as $config) {
48+
if (array_key_exists($config['name'], $morphies)) {
49+
throw new InvalidArgumentException(
50+
"Duplicate morphy name: {$config['name']}"
51+
);
52+
}
53+
4854
$morphies[$config['name']] = self::makeMorphy($config, $commonOptions);
4955
}
5056
return $morphies;

src/Morphy.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Morphy extends phpMorphy
2424
self::germanLang,
2525
];
2626

27+
protected $name;
2728
protected $language;
2829
protected $options;
2930
protected $dictsPath;
@@ -49,17 +50,23 @@ protected function checkedOptions(?array $options): array
4950
}
5051

5152
public function __construct(
53+
string $name,
5254
string $language = self::russianLang,
5355
?array $options = null,
5456
?string $dictsPath = null
5557
) {
58+
$this->name = $name;
5659
$this->language = $this->checkedLanguage($language);
5760
$this->options = $this->checkedOptions($options);
5861
$this->dictsPath = $dictsPath;
5962

6063
parent::__construct($this->dictsPath, $this->language, $this->options);
6164
}
6265

66+
public function name(): string {
67+
return $this->name;
68+
}
69+
6370
public function findWord($word, $type = self::NORMAL) {
6471
return parent::findWord(self::preprocessedWord($word, $this), $type);
6572
}

0 commit comments

Comments
 (0)