-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from laravel-taiwan/1.x
Upgrade to PHP 5.5+ and Laravel 5+
- Loading branch information
Showing
11 changed files
with
19,186 additions
and
19,174 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,3 @@ | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache |
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
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
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,18 @@ | ||
<?xml version="1.0"?> | ||
<ruleset> | ||
<!-- display progress and sniff --> | ||
<arg value="p"/> | ||
<arg value="s"/> | ||
|
||
<!-- use colors in output --> | ||
<arg name="colors"/> | ||
|
||
<!-- check the php syntax --> | ||
<rule ref="Generic.PHP.Syntax"/> | ||
|
||
<!-- inherit rules from: --> | ||
<rule ref="PSR12"/> | ||
|
||
<!-- Paths and file to check --> | ||
<file>src</file> | ||
</ruleset> |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
13 changes: 8 additions & 5 deletions
13
src/Seta0909/LaravelZhconverter/Facades/LaravelZhconverter.php
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<?php namespace Seta0909\LaravelZhconverter\Facades; | ||
<?php | ||
|
||
namespace Seta0909\LaravelZhconverter\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class LaravelZhconverter extends Facade | ||
{ | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { return 'ZhConvert'; } | ||
|
||
} | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'ZhConvert'; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,42 +1,26 @@ | ||
<?php | ||
namespace Seta0909\LaravelZhconverter; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: Seta | ||
* Date: 2015/1/19 | ||
* Time: 上午 09:45 | ||
*/ | ||
namespace Seta0909\LaravelZhconverter; | ||
|
||
class LaravelZhconverter | ||
class LaravelZhconverter | ||
{ | ||
public static function translate($words, $type) | ||
{ | ||
private static $instance; | ||
protected static $cnCode = []; | ||
protected static $twCode = []; | ||
$translated = ''; | ||
|
||
private static function getInstance() | ||
{ | ||
if (!isset(self::$instance)) { | ||
require('ZhConversion.php'); | ||
$class = __CLASS__; | ||
self::$instance = new $class(); | ||
self::$cnCode = $zh2Hant; | ||
self::$twCode = $zh2Hans; | ||
for ($i = 0; $i < mb_strlen($words); $i++) { | ||
$word = mb_substr($words, $i, 1, "utf-8"); | ||
if ($type == 'CN') { | ||
$translated .= isset(ZhConversion::$zh2Hans[$word]) | ||
? ZhConversion::$zh2Hans[$word] | ||
: $word; | ||
} else { | ||
$translated .= isset(ZhConversion::$zh2Hant[$word]) | ||
? ZhConversion::$zh2Hant[$word] | ||
: $word; | ||
} | ||
} | ||
|
||
public static function translate($words, $type) | ||
{ | ||
self::getInstance(); | ||
$translated = ''; | ||
for ($i = 0; $i < mb_strlen($words); $i++) { | ||
$word = mb_substr($words, $i, 1, "utf-8"); | ||
if ($type == 'CN') { | ||
$translated .= (isset(self::$twCode[$word])) ? self::$twCode[$word] : $word; | ||
} else { | ||
$translated .= (isset(self::$cnCode[$word])) ? self::$cnCode[$word] : $word; | ||
} | ||
} | ||
return $translated; | ||
} | ||
} | ||
return $translated; | ||
} | ||
} |
46 changes: 5 additions & 41 deletions
46
src/Seta0909/LaravelZhconverter/LaravelZhconverterServiceProvider.php
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 |
---|---|---|
@@ -1,51 +1,15 @@ | ||
<?php namespace Seta0909\LaravelZhconverter; | ||
<?php | ||
|
||
namespace Seta0909\LaravelZhconverter; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class LaravelZhconverterServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('seta0909/laravel-zhconverter'); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app['ZhConvert'] = $this->app->share(function ($app) { | ||
return new LaravelZhconverter; | ||
}); | ||
$this->app->booting(function () { | ||
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); | ||
$loader->alias('ZhConvert', 'Seta0909\LaravelZhconverter\Facades\LaravelZhconverter'); | ||
$this->app->singleton(LaravelZhconverter::class, function () { | ||
return new LaravelZhconverter(); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array('ZhConvert'); | ||
} | ||
|
||
} |
Oops, something went wrong.