Skip to content

Commit

Permalink
upd config info
Browse files Browse the repository at this point in the history
  • Loading branch information
yuandeng committed May 21, 2020
1 parent 9a2ab9f commit dad8b7a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 123 deletions.
18 changes: 0 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,6 @@ echo $pinyin->sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo
```

There are more convenient functions:

| function | method |
| ------------- | --------------------------------------------------- |
| `pinyin(string $str, int $option, $loader)` | `Pinyin::setLoader($loader)->convert($str, $option)` |
| `pinyin_abbr(string $str, string $delimiter, int $option, $loader)` | `Pinyin::setLoader($loader)->abbr($str, $delimiter, $option)` |
| `pinyin_permalink(string $str, $delimiter, int $option, $loader)` | `Pinyin::setLoader($loader)->permalink($str, $delimiter, $option)` |
| `pinyin_sentence($string, $delimiter, $option, $loader)` | `Pinyin::setLoader($loader)->sentence($string, $delimiter, $option)` |

```php
var_dump(pinyin('带着希望去旅行,比到达终点更美好'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]

var_dump(pinyin_abbr('带着希望去旅行'));
// dzxwqlx
...
```

Using facade:

```php
Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
"require": {
"php": "^7.4",
"laravel/framework": "^7.0",
"mucts/pinyin": ">=1.1.1"
"mucts/pinyin": ">=1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"MuCTS\\Laravel\\Pinyin\\": "src/"
},
"files": [
"src/helpers.php"
]
}
},
"license": "MIT",
"authors": [
Expand Down
32 changes: 27 additions & 5 deletions config/pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,32 @@
*/

return [
/*
| ------------------------------------------------------------------
| Set the default conversion scheme
| ------------------------------------------------------------------
| The system has realized the following options:
| Memory type, suitable for server memory space is more abundant,
| advantages: fast conversion.
| Small memory (default), suitable for the memory is more tight environment,
| advantages: small footprint, conversion is not as fast as memory.
| Type I/O, suitable for virtual machine, memory limited environment.
| Pros: very small memory consumption. Cons: slow conversion,
| not as fast as memory conversion.
|
| Available Settings:file,generator,memory
|
*/
'default' => env('PINYIN_DICT_LOADER', 'file'),
'loaders' => [
'file' => MuCTS\Pinyin\Loaders\File::class,
'generator' => MuCTS\Pinyin\Loaders\GeneratorFile::class,
'memory' => MuCTS\Pinyin\Loaders\MemoryFile::class
]
/*
| ------------------------------------------------------------------
| Set up the custom implementation
| ------------------------------------------------------------------
| You can set up your own implemented transformation scheme,
| which can be configured here if you need to override or
| add a transformation scheme alias.
| Available Settings: 'file' => MuCTS\Pinyin\Loaders\File::class
|
*/
'alias' => []
];
4 changes: 3 additions & 1 deletion src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace MuCTS\Laravel\Pinyin;

use Exception;
use Illuminate\Support\Arr;
use MuCTS\Pinyin\Interfaces\DictLoader;
use MuCTS\Pinyin\Pinyin as Accessor;
Expand All @@ -35,11 +36,12 @@ public function __construct(?array $config = null)
*
* @param DictLoader|string|null $loader
* @return $this
* @throws Exception
*/
public function setLoader($loader = null)
{
$loader = $loader ?? Arr::get($this->config, 'default');
$loader = is_string($loader) ? Arr::get($this->config, 'loaders.' . $loader, $loader) : $loader;
$loader = is_string($loader) ? Arr::get($this->config, 'alias.' . $loader, $loader) : $loader;
parent::setLoader($loader);
return $this;
}
Expand Down
94 changes: 0 additions & 94 deletions src/helpers.php

This file was deleted.

0 comments on commit dad8b7a

Please sign in to comment.