Skip to content

Commit

Permalink
Change facade alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ElForastero committed Dec 8, 2018
1 parent 5cb7506 commit 4b8fcf5
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added configuration file transliterate.php
- Added ability to define custom transliteration maps
- Added ability to define transformers
- Added optional removing accents using ICU
- Added tests

## Removed
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ ElForastero\Transliterate\ServiceProvider::class,

Если вы хотите использовать алиас, добавьте его в массив `facades` в `app.php`.

Рекомендую в качестве алиаса использовать `Transliterate`, чтобы избежать конфликтов с Transliterator классом из расширения Intl.

```php
'Transliterator' => ElForastero\Transliterate\Facade::class,
'Transliterate' => ElForastero\Transliterate\Facade::class,
```

## Конфигурация
Expand All @@ -61,15 +63,17 @@ ElForastero\Transliterate\ServiceProvider::class,
Вы можете использовать фасад для транслитерации строк.

```php
use Transliterator;
use Transliterate;

(new Transliterator)->make('Двадцать тысяч льё под водой');
Transliterate::make('Двадцать тысяч льё под водой');
// "Dvadcat tisyach lyo pod vodoy"
```

Альтернативная карта транслитерации может быть передана вторым параметром.

```php
use ElForastero\Transliterate\Transliterator;

$transliterator = new Transliterator(Map::LANG_RU, Map::GOST_7_79_2000);
$transliterator->make('Двадцать тысяч льё под водой');
// "Dvadcat` ty'syach l`yo pod vodoj"
Expand All @@ -80,7 +84,7 @@ $transliterator->make('Двадцать тысяч льё под водой');
Метод `slugify` генерирует URL, убирая из строки все знаки препинания и заменяя пробелы на "-".

```php
(new Transliterator)->slugify('Съешь еще этих мягких французских булок, да выпей чаю!');
Transliterate::slugify('Съешь еще этих мягких французских булок, да выпей чаю!');
// sesh-eshhe-etih-myagkih-francuzskih-bulok-da-vipey-chayu
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"ElForastero\\Transliterate\\ServiceProvider"
],
"aliases": {
"Transliteration": "ElForastero\\Transliterate\\Facade"
"Transliterate": "ElForastero\\Transliterate\\Facade"
}
},
"hooks": {
Expand Down
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class Facade extends BaseFacade
*/
public static function getFacadeAccessor()
{
return 'Transliterator';
return 'Transliterate';
}
}
12 changes: 11 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
class ServiceProvider extends BaseServiceProvider
{
protected $defer = true;

/**
* Bootstrap the application services.
*/
Expand All @@ -32,8 +34,16 @@ public function register()

$this->mergeConfigFrom($configPath, 'transliterate');

$this->app->bind('Transliterator', function ($app) {
$this->app->bind('Transliterate', function () {
return new Transliterator();
});
}

/**
* @return array
*/
public function provides()
{
return ['Transliterate'];
}
}
12 changes: 6 additions & 6 deletions src/Transliterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ElForastero\Transliterate;

use \Transliterator as IntlTransliterator;
use Transliterator as IntlTransliterator;

/**
* Feel free to change it.
Expand Down Expand Up @@ -34,7 +34,7 @@ public function __construct(string $lang = null, string $map = null)
/**
* Change transliterating text language.
*
* @param string $lang One of the Map::LANG_* constants or custom language.
* @param string $lang one of the Map::LANG_* constants or custom language
*
* @return Transliterator
*/
Expand All @@ -46,9 +46,9 @@ public function from(string $lang): self
}

/**
* Change transliteration map
* Change transliteration map.
*
* @param string $map Name of the transliteration map.
* @param string $map name of the transliteration map
*
* @return Transliterator
*/
Expand Down Expand Up @@ -114,8 +114,8 @@ private function getMap(): array
$lang = $this->lang ?? config('transliterate.default_lang');
$customMaps = config('transliterate.custom_maps');

$vendorMapsPath = __DIR__ . DIRECTORY_SEPARATOR . 'maps' . DIRECTORY_SEPARATOR;
$path = $customMaps[$lang][$map] ?? $vendorMapsPath . $lang . DIRECTORY_SEPARATOR . $map . '.php';
$vendorMapsPath = __DIR__.DIRECTORY_SEPARATOR.'maps'.DIRECTORY_SEPARATOR;
$path = $customMaps[$lang][$map] ?? $vendorMapsPath.$lang.DIRECTORY_SEPARATOR.$map.'.php';

if (!file_exists($path)) {
throw new \InvalidArgumentException("The transliteration map '${path}' doesn't exist");
Expand Down
2 changes: 1 addition & 1 deletion src/config/transliterate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use ElForastero\Transliterate\Map;

/** @noinspection PhpVoidFunctionResultUsedInspection */
/* @noinspection PhpVoidFunctionResultUsedInspection */
return [
/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 4b8fcf5

Please sign in to comment.