Skip to content

Commit 3faa4e6

Browse files
authored
Merge pull request #5 from laravel-taiwan/1.x
Upgrade to PHP 5.5+ and Laravel 5+
2 parents fd7487f + c5af2bd commit 3faa4e6

11 files changed

+19186
-19174
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
.phpunit.result.cache

README.md

+21-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,36 @@ Laravel 繁簡轉換
33

44
# 安裝方式
55

6-
1. 在 composer.json中加入 "seta0909/laravel-zhconverter": "*"
7-
2. composer update
8-
3. 在 config/app.php 中加入 'Seta0909\LaravelZhconverter\LaravelZhconverterServiceProvider'
6+
1. 新增套件
7+
8+
```bash
9+
composer require seta0909/laravel-zhconverter
10+
```
11+
12+
2.`config/app.php` 中加入 Provider
13+
14+
```
15+
Seta0909\LaravelZhconverter\LaravelZhconverterServiceProvider
16+
```
917

1018
# 使用方式
1119

12-
###簡轉繁
20+
簡轉繁:
21+
22+
```
1323
ZhConvert::translate('无疑,这个村子弥漫着一种懒散而颓废的感觉>,这种感觉让我觉得非常的难受,比曾经我见过的那个无限轮回的死村还难受,毕竟无限轮回还有破除的消,这村子里的这种气氛无疑就是一种绝望','TW');
24+
```
25+
26+
繁轉簡:
1427

15-
###繁轉簡
28+
```
1629
ZhConvert::translate('我是一個不大會拒絕人的人,看著這個中年人>,或者是老年人吧,我覺得幾根兒煙也無可厚非,于是我把剩下的半包全部給了他,他接過煙,嘿嘿一笑,也不說聲謝謝,轉身就要走','CN');
30+
```
1731

1832
# 注意事項
1933

20-
1. 目前只支援UTF-8
34+
目前只支援 UTF-8
2135

2236
# 資料來源
2337

24-
繁簡字來源:http://www.mediawiki.org/wiki/MediaWiki
38+
繁簡字來源: http://www.mediawiki.org/wiki/MediaWiki

composer.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.4.0",
14-
"illuminate/support": "4.2.*"
13+
"php": "^5.5 | ^7.0 | ^8.0",
14+
"illuminate/support": "^5 | ^6 | ^7 | ^8 | ^9"
15+
},
16+
"require-dev": {
17+
"squizlabs/php_codesniffer": "^3.7",
18+
"phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9"
1519
},
1620
"autoload": {
1721
"psr-0": {
1822
"Seta0909\\LaravelZhconverter\\": "src/"
1923
}
2024
},
21-
"minimum-stability": "stable"
25+
"minimum-stability": "stable",
26+
"config": {
27+
"optimize-autoloader": true,
28+
"preferred-install": "dist",
29+
"sort-packages": true,
30+
"allow-plugins": {
31+
"composer/package-versions-deprecated": false
32+
}
33+
}
2234
}

phpcs.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<!-- display progress and sniff -->
4+
<arg value="p"/>
5+
<arg value="s"/>
6+
7+
<!-- use colors in output -->
8+
<arg name="colors"/>
9+
10+
<!-- check the php syntax -->
11+
<rule ref="Generic.PHP.Syntax"/>
12+
13+
<!-- inherit rules from: -->
14+
<rule ref="PSR12"/>
15+
16+
<!-- Paths and file to check -->
17+
<file>src</file>
18+
</ruleset>

phpunit.xml

-18
This file was deleted.

phpunit.xml.dist

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
verbose="true"
7+
>
8+
<testsuites>
9+
<testsuite name="Unit">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
<?php namespace Seta0909\LaravelZhconverter\Facades;
1+
<?php
2+
3+
namespace Seta0909\LaravelZhconverter\Facades;
24

35
use Illuminate\Support\Facades\Facade;
46

57
class LaravelZhconverter extends Facade
68
{
7-
89
/**
910
* Get the registered name of the component.
1011
*
1112
* @return string
1213
*/
13-
protected static function getFacadeAccessor() { return 'ZhConvert'; }
14-
15-
}
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'ZhConvert';
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
<?php
2-
namespace Seta0909\LaravelZhconverter;
32

4-
/**
5-
* Created by PhpStorm.
6-
* User: Seta
7-
* Date: 2015/1/19
8-
* Time: 上午 09:45
9-
*/
3+
namespace Seta0909\LaravelZhconverter;
104

11-
class LaravelZhconverter
5+
class LaravelZhconverter
6+
{
7+
public static function translate($words, $type)
128
{
13-
private static $instance;
14-
protected static $cnCode = [];
15-
protected static $twCode = [];
9+
$translated = '';
1610

17-
private static function getInstance()
18-
{
19-
if (!isset(self::$instance)) {
20-
require('ZhConversion.php');
21-
$class = __CLASS__;
22-
self::$instance = new $class();
23-
self::$cnCode = $zh2Hant;
24-
self::$twCode = $zh2Hans;
11+
for ($i = 0; $i < mb_strlen($words); $i++) {
12+
$word = mb_substr($words, $i, 1, "utf-8");
13+
if ($type == 'CN') {
14+
$translated .= isset(ZhConversion::$zh2Hans[$word])
15+
? ZhConversion::$zh2Hans[$word]
16+
: $word;
17+
} else {
18+
$translated .= isset(ZhConversion::$zh2Hant[$word])
19+
? ZhConversion::$zh2Hant[$word]
20+
: $word;
2521
}
2622
}
2723

28-
public static function translate($words, $type)
29-
{
30-
self::getInstance();
31-
$translated = '';
32-
for ($i = 0; $i < mb_strlen($words); $i++) {
33-
$word = mb_substr($words, $i, 1, "utf-8");
34-
if ($type == 'CN') {
35-
$translated .= (isset(self::$twCode[$word])) ? self::$twCode[$word] : $word;
36-
} else {
37-
$translated .= (isset(self::$cnCode[$word])) ? self::$cnCode[$word] : $word;
38-
}
39-
}
40-
return $translated;
41-
}
42-
}
24+
return $translated;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
1-
<?php namespace Seta0909\LaravelZhconverter;
1+
<?php
2+
3+
namespace Seta0909\LaravelZhconverter;
24

35
use Illuminate\Support\ServiceProvider;
46

57
class LaravelZhconverterServiceProvider extends ServiceProvider
68
{
7-
8-
/**
9-
* Indicates if loading of the provider is deferred.
10-
*
11-
* @var bool
12-
*/
13-
protected $defer = false;
14-
15-
/**
16-
* Bootstrap the application events.
17-
*
18-
* @return void
19-
*/
20-
public function boot()
21-
{
22-
$this->package('seta0909/laravel-zhconverter');
23-
}
24-
25-
/**
26-
* Register the service provider.
27-
*
28-
* @return void
29-
*/
309
public function register()
3110
{
32-
$this->app['ZhConvert'] = $this->app->share(function ($app) {
33-
return new LaravelZhconverter;
34-
});
35-
$this->app->booting(function () {
36-
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
37-
$loader->alias('ZhConvert', 'Seta0909\LaravelZhconverter\Facades\LaravelZhconverter');
11+
$this->app->singleton(LaravelZhconverter::class, function () {
12+
return new LaravelZhconverter();
3813
});
3914
}
40-
41-
/**
42-
* Get the services provided by the provider.
43-
*
44-
* @return array
45-
*/
46-
public function provides()
47-
{
48-
return array('ZhConvert');
49-
}
50-
5115
}

0 commit comments

Comments
 (0)