From c3a07ae2acc8487f4744b85a6b00a0d731a987d5 Mon Sep 17 00:00:00 2001 From: overtrue Date: Tue, 12 Jan 2016 11:22:55 +0800 Subject: [PATCH] Lumen support. --- LICENSE | 0 README.md | 30 +++++++++++++++++++++++++++--- composer.json | 0 src/ServiceProvider.php | 12 +++++++++--- src/config.php | 8 ++++---- src/helpers.php | 0 6 files changed, 40 insertions(+), 10 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 composer.json mode change 100644 => 100755 src/ServiceProvider.php mode change 100644 => 100755 src/config.php mode change 100644 => 100755 src/helpers.php diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 11482c5..6a2b93e --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Laravel-pinyin -Chinese to Pinyin translator for Laravel 5 based on [overtrue/pinyin](https://github.com/overtrue/pinyin). +Chinese to Pinyin translator for Laravel5 / Lumen based on [overtrue/pinyin](https://github.com/overtrue/pinyin). [![Latest Stable Version](https://poser.pugx.org/overtrue/laravel-pinyin/v/stable.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![Total Downloads](https://poser.pugx.org/overtrue/laravel-pinyin/downloads.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![Latest Unstable Version](https://poser.pugx.org/overtrue/laravel-pinyin/v/unstable.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) [![License](https://poser.pugx.org/overtrue/laravel-pinyin/license.svg)](https://packagist.org/packages/overtrue/laravel-pinyin) @@ -22,13 +22,16 @@ then ```shell composer update ``` -After completion of the above, add the following line to the section `providers` of `config/app.php`: + +## For Laravel + +Add the following line to the section `providers` of `config/app.php`: ```php 'Overtrue\LaravelPinyin\ServiceProvider', ``` -## Configuration +### config file you can publish the config file to `config/pinyin.php`: @@ -36,6 +39,27 @@ you can publish the config file to `config/pinyin.php`: php artisan vendor:publish --provider="Overtrue\LaravelPinyin\ServiceProvider" --tag="config" ``` +## For Lumen + +Add the following line to `bootstrap/app.php` after `// $app->withEloquent();` + +```php +... +// $app->withEloquent(); + +$app->register(Overtrue\LaravelPinyin\ServiceProvider::class); +... +``` + +## configuration + +| .env | config/pinyin.php | default | description | +| `PINYIN_DELIMITER` | delimiter | `" "` | Symbol for stitching each pinyin. `'-' => dài-zhe-xī-wàng-qù-lǔ-xíng` | +| PINYIN_ACCENT | accent | `true` | Output with tone symbol. | +| PINYIN_ONLY_CHINESE | only_chinese | `true` | Leaving only the Chinese characters. | +| PINYIN_UPPERCASE | uppercase | `true` | Output uppercase(letter) | + + ## Usage you can get the instance of `Overtrue\Pinyin\Pinyin` from app container: diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php old mode 100644 new mode 100755 index 5026cb8..98fca5c --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -14,9 +14,11 @@ class ServiceProvider extends LaravelServiceProvider */ public function boot() { - $this->publishes([ - __DIR__ . '/config.php' => config_path('pinyin.php'), - ], 'config'); + if (function_exists('config_path')) { + $this->publishes([ + __DIR__ . '/config.php' => config_path('pinyin.php'), + ], 'config'); + } } /** @@ -26,6 +28,10 @@ public function boot() */ public function register() { + $this->mergeConfigFrom( + __DIR__.'/config.php', 'pinyin' + ); + Pinyin::settings(config('pinyin', [])); $this->app->singleton('pinyin', function($app) diff --git a/src/config.php b/src/config.php old mode 100644 new mode 100755 index c5ff87e..0d88004 --- a/src/config.php +++ b/src/config.php @@ -9,7 +9,7 @@ * '': dàizhexīwàngqùlǔxíng * '-' dài-zhe-xī-wàng-qù-lǔ-xíng */ - 'delimiter' => ' ', + 'delimiter' => env('PINYIN_DELIMITER', ' '), /** * Output with tone symbol. @@ -17,7 +17,7 @@ * true: dài * false: dai */ - 'accent' => true, + 'accent' => env('PINYIN_ACCENT', true), /** * Leaving only the Chinese characters. @@ -29,10 +29,10 @@ * true: dài zhe xī wàng qù lǔ xíng * false: dài zhe xī wàng %¥@ qù lǔ xíng */ - 'only_chinese' => false, + 'only_chinese' => env('PINYIN_ONLY_CHINESE', true), /** * Output uppercase. */ - 'uppercase' => false + 'uppercase' => env('PINYIN_UPPERCASE', false) ]; \ No newline at end of file diff --git a/src/helpers.php b/src/helpers.php old mode 100644 new mode 100755