-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2cc2f
commit f9ea9f0
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright Andreas Heigl <andreas@heigl.org> | ||
* | ||
* Licensed under the MIT-license. For details see the included file LICENSE.md | ||
*/ | ||
|
||
namespace Org\Heigl\HyphenatorTest; | ||
|
||
use Org\Heigl\Hyphenator\Hyphenator; | ||
use Org\Heigl\Hyphenator\Options; | ||
|
||
final class HyphenatorService | ||
{ | ||
private static $instance = null; | ||
|
||
public function __construct(Hyphenator $hyphenator, array $customPattern) | ||
{ | ||
$o = new Options(); | ||
$o->setHyphen('-') | ||
->setDefaultLocale('de_DE') | ||
->setRightMin(2) | ||
->setLeftMin(2) | ||
->setWordMin(4) | ||
->setFilters('NonStandard') | ||
->setTokenizers('Whitespace, Punctuation'); | ||
|
||
$hyphenator->setOptions($o); | ||
|
||
$dictionary = $hyphenator->getDictionaries()->current(); | ||
foreach ($customPattern as $string => $pattern) { | ||
$dictionary->addPattern($string, $pattern); | ||
} | ||
|
||
$this->hyphenator = $hyphenator; | ||
} | ||
|
||
public static function singleton(): self | ||
{ | ||
if (self::$instance === null) { | ||
self::$instance = new self(new Hyphenator(), [ | ||
'spender' => '08000000', | ||
]); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
public function hyphenate(string $word): array | ||
{ | ||
return $this->hyphenator->hyphenate($word); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters