Skip to content

Commit

Permalink
'2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Mar 7, 2019
1 parent 0211a5c commit c6e2575
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "lsys/format",
"type" : "library",
"license": "Apache-2.0",
"version" : "1.0.0",
"version" : "2.0.0",
"description" : "lsys module format",
"autoload":{
"psr-4": {
Expand All @@ -11,7 +11,7 @@
},
"require": {
"php": ">=5.4",
"lsys/core":"~1.0.0"
"lsys/core":"~2.0.0"
},
"require-dev" : {
"phpunit/phpunit" : "~7.1.5",
Expand Down
2 changes: 1 addition & 1 deletion dome/dome.php
Expand Up @@ -5,7 +5,7 @@
use LSYS\FormatData\DataHandler\TextData;
include_once __DIR__."/../vendor/autoload.php";

$format=\LSYS\FormatData\DI::get()->format_data();
$format=\LSYS\FormatData\DI::get()->formatData();

var_dump($format->format(DateTimeData::class,time()-1000,DateTimeData::FORMAT_LESS));

Expand Down
4 changes: 2 additions & 2 deletions src/classes/LSYS/FormatData/DI.php
@@ -1,15 +1,15 @@
<?php
namespace LSYS\FormatData;
/**
* @method \LSYS\FormatData format_data()
* @method \LSYS\FormatData formatData()
*/
class DI extends \LSYS\DI{
/**
* @return static
*/
public static function get(){
$di=parent::get();
!isset($di->format_data)&&$di->format_data(new \LSYS\DI\SingletonCallback(function (){
!isset($di->formatData)&&$di->formatData(new \LSYS\DI\SingletonCallback(function (){
return new \LSYS\FormatData();
}));
return $di;
Expand Down
16 changes: 8 additions & 8 deletions src/classes/LSYS/FormatData/DataHandler/DateTimeData.php
Expand Up @@ -43,9 +43,9 @@ public function format($format,$data,$args=null){
case self::FORMAT_MINUTE:
return date("Y-m-d H:i",$data);
case self::FORMAT_TIME:
return $this->_time_show($data);
return $this->_timeShow($data);
case self::FORMAT_LESS:
return $this->_less_show($data);
return $this->_lessShow($data);
default:
return date("Y-m-d H:i:s",$data);
}
Expand All @@ -61,7 +61,7 @@ public function format($format,$data,$args=null){
* @param int $time
* @return string
*/
public static function less_chinese($time){
public static function lessChinese($time){
$cTime = time();
$dTime = $cTime - $time;
$dDay = intval(date("z",$cTime)) - intval(date("z",$time));
Expand Down Expand Up @@ -92,7 +92,7 @@ public static function less_chinese($time){
* @param int $time
* @return string
*/
public static function less_english($time){
public static function lessEnglish($time){
$local_timestamp = time();
// Determine the difference in seconds
$offset = abs($local_timestamp - $timestamp);
Expand Down Expand Up @@ -187,18 +187,18 @@ public static function less_english($time){
return 'in '.$span;
}
}
protected function _less_show($time){
protected function _lessShow($time){
switch ($this->_language){
case null:
case 'zh_CN':
return self::less_chinese($time);
return self::lessChinese($time);
break;
case 'en_US':
return self::less_english($time);
return self::lessEnglish($time);
break;
}
}
protected function _time_show($second){
protected function _timeShow($second){
if ($second<=60)return $second."";
elseif($second>=60&&$second<3600){
return floor($second/60).":".($second%60)."";
Expand Down
4 changes: 2 additions & 2 deletions src/classes/LSYS/FormatData/DataHandler/MoneyData.php
Expand Up @@ -51,7 +51,7 @@ class MoneyData extends DataHandler{
public function format($format,$data,$args=null){
switch ($format){
case self::FORMAT_CHINESE:
return self::to_chinese($data);
return self::toChinese($data);
default:
$prefix=$args?$args:self::$prefix;
if (isset(self::$_prefix[$prefix]))$prefix=self::$_prefix[$prefix];
Expand All @@ -65,7 +65,7 @@ public function format($format,$data,$args=null){
* @param number $money
* @return string
*/
public static function to_chinese($money){
public static function toChinese($money){
$c1 = "零壹贰叁肆伍陆柒捌玖";
$c2 = "分角元拾佰仟万拾佰仟亿";
//精确到分后面就不要了,所以只留两个小数位
Expand Down
14 changes: 7 additions & 7 deletions src/classes/LSYS/FormatData/DataHandler/NumData.php
Expand Up @@ -35,10 +35,10 @@ public function format($format,$data,$args=null){
case self::FORMAT_BYTES:
return $this->_bytes($data);
case self::FORMAT_IP:
return $this->_int_to_ip($data);
return $this->_intToIp($data);
case self::FORMAT_NUM:
if ($args==null)$args=2;
return $this->_num_format($data, $args);
return $this->_numFormat($data, $args);
}
}
const ROUND_HALF_UP = 1;
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function round($value, $precision = 0, $mode = self::ROUND_HALF_UP
* @return string
* @since 3.0.2
*/
protected function _num_format($number, $places)
protected function _numFormat($number, $places)
{
$info = localeconv();
$decimal = $info['decimal_point'];
Expand All @@ -137,14 +137,14 @@ protected function _num_format($number, $places)
}
protected function _bytes($size)
{
return self::format_bytes($size);
return self::formatBytes($size);
}
/**
* 把字节数转为可视字符串
* @param int $size
* @return string
*/
public static function format_bytes($size){
public static function formatBytes($size){
$pi=array(
'B','KB','MB','GB','TB'
);
Expand Down Expand Up @@ -211,7 +211,7 @@ public static function format_bytes($size){
* @param string $size
* @return number
*/
public static function to_bytes($size)
public static function toBytes($size)
{
// Prepare the size
$size = trim( (string) $size);
Expand All @@ -233,7 +233,7 @@ public static function to_bytes($size)
* 整数转IP
* @param int $iIP
*/
protected function _int_to_ip($iIP){
protected function _intToIp($iIP){
return self::intip($iIP);
}
/**
Expand Down
16 changes: 8 additions & 8 deletions src/classes/LSYS/FormatData/DataHandler/TextData.php
Expand Up @@ -34,27 +34,27 @@ public function format($format,$data,$args=null){
switch ($format){
case self::FORMAT_TEXT_HIDDEN:
if ($args==null)$args=6;
return $this->_hide_text($data,$args);
return $this->_hideText($data,$args);
case self::FORMAT_MOBILE_HIDDEN:
if ($args==null)$args=4;
return $this->_hide_mobile($data,$args);
return $this->_hideMobile($data,$args);
case self::FORMAT_EMAIL_HIDDEN:
return $this->_hide_email($data);
return $this->_hideEmail($data);
}
}
protected function _hide_text($text,$show){
protected function _hideText($text,$show){
if ($show<=1) return '*';
$s=intval($show/3);
return substr($text, 0,$s+$show%2).str_pad("", $s,"*").($s?substr($text, -$s,strlen($text)):'');
}
protected function _hide_mobile($text,$show){
protected function _hideMobile($text,$show){
$start=ceil((11-$show)/2);
return substr_replace($text,str_pad("", $show,"*"),$start,$show);
}
protected function _hide_email($email){
return self::js_email($email);
protected function _hideEmail($email){
return self::jsEmail($email);
}
public static function js_email($email){
public static function jsEmail($email){
$text = str_replace('@', '[at]', $email);
$email = explode("@", $email);
$output = '<script type="text/javascript">';
Expand Down

0 comments on commit c6e2575

Please sign in to comment.