| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Str | 
| 6 | 6 |  { | 
| 7 | - public static function toUtf8($str) | |
| 8 | -    { | |
| 9 | - return utf8_encode($str); | |
| 10 | - } | |
| 7 | + public static function toUtf8($str) | |
| 8 | +	{ | |
| 9 | + return utf8_encode($str); | |
| 10 | + } | |
| 11 | 11 | } | 
| @@ -4,13 +4,13 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Hex | 
| 6 | 6 |  { | 
| 7 | - public static function toStr($hex) | |
| 8 | -    { | |
| 9 | - $str = ''; | |
| 10 | -        for ($i = 0; $i < strlen($hex); $i += 2) { | |
| 11 | - $str .= chr(hexdec(substr($hex, $i, 2))); | |
| 12 | - } | |
| 7 | + public static function toStr($hex) | |
| 8 | +	{ | |
| 9 | + $str = ''; | |
| 10 | +		for ($i = 0; $i < strlen($hex); $i += 2) { | |
| 11 | + $str .= chr(hexdec(substr($hex, $i, 2))); | |
| 12 | + } | |
| 13 | 13 | |
| 14 | - return $str; | |
| 15 | - } | |
| 14 | + return $str; | |
| 15 | + } | |
| 16 | 16 | } | 
| @@ -4,27 +4,27 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Bin | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * Converts Binary to Hexadecimal. | |
| 9 | - * | |
| 10 | - * @param string $bin | |
| 11 | - * | |
| 12 | - * @return string | |
| 13 | - */ | |
| 14 | - public static function toHex($bin) | |
| 15 | -    { | |
| 16 | - return bin2hex($bin); | |
| 17 | - } | |
| 7 | + /** | |
| 8 | + * Converts Binary to Hexadecimal. | |
| 9 | + * | |
| 10 | + * @param string $bin | |
| 11 | + * | |
| 12 | + * @return string | |
| 13 | + */ | |
| 14 | + public static function toHex($bin) | |
| 15 | +	{ | |
| 16 | + return bin2hex($bin); | |
| 17 | + } | |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * Converts Binary to ASCII. | |
| 21 | - * | |
| 22 | - * @param string $bin | |
| 23 | - * | |
| 24 | - * @return string | |
| 25 | - */ | |
| 26 | - public static function toStr($bin) | |
| 27 | -    { | |
| 28 | - return Hex::toStr(self::toHex($bin)); | |
| 29 | - } | |
| 19 | + /** | |
| 20 | + * Converts Binary to ASCII. | |
| 21 | + * | |
| 22 | + * @param string $bin | |
| 23 | + * | |
| 24 | + * @return string | |
| 25 | + */ | |
| 26 | + public static function toStr($bin) | |
| 27 | +	{ | |
| 28 | + return Hex::toStr(self::toHex($bin)); | |
| 29 | + } | |
| 30 | 30 | } | 
| @@ -4,17 +4,17 @@ | ||
| 4 | 4 | |
| 5 | 5 | class IntColumn extends ColumnRule implements ColumnInterface | 
| 6 | 6 |  { | 
| 7 | - const DEFAULT_LENGTH = 2; | |
| 7 | + const DEFAULT_LENGTH = 2; | |
| 8 | 8 | |
| 9 | - public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 10 | -    { | |
| 11 | - $this->setTitle($title); | |
| 12 | - $this->setType(self::TYPE_INT); | |
| 13 | - $this->setLength($length); | |
| 14 | - } | |
| 9 | + public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 10 | +	{ | |
| 11 | + $this->setTitle($title); | |
| 12 | + $this->setType(self::TYPE_INT); | |
| 13 | + $this->setLength($length); | |
| 14 | + } | |
| 15 | 15 | |
| 16 | - public static function cast($content) | |
| 17 | -    { | |
| 18 | - return intval($content); | |
| 19 | - } | |
| 16 | + public static function cast($content) | |
| 17 | +	{ | |
| 18 | + return intval($content); | |
| 19 | + } | |
| 20 | 20 | } | 
| @@ -6,24 +6,24 @@ | ||
| 6 | 6 | |
| 7 | 7 | class IdColumn extends ColumnRule implements ColumnInterface | 
| 8 | 8 |  { | 
| 9 | - const DEFAULT_LENGTH = 1; | |
| 9 | + const DEFAULT_LENGTH = 1; | |
| 10 | 10 | |
| 11 | - public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 12 | -    { | |
| 13 | - $this->setTitle($title); | |
| 14 | - $this->setType(self::TYPE_ID); | |
| 15 | - $this->setLength($length); | |
| 16 | - } | |
| 11 | + public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 12 | +	{ | |
| 13 | + $this->setTitle($title); | |
| 14 | + $this->setType(self::TYPE_ID); | |
| 15 | + $this->setLength($length); | |
| 16 | + } | |
| 17 | 17 | |
| 18 | - public static function cast($content) | |
| 19 | -    { | |
| 20 | - $content = str_split(Bin::toHex($content), 2); | |
| 18 | + public static function cast($content) | |
| 19 | +	{ | |
| 20 | + $content = str_split(Bin::toHex($content), 2); | |
| 21 | 21 | |
| 22 | - $id = 0; | |
| 23 | -        foreach ($content as $power => $value) { | |
| 24 | - $id += hexdec($value) * pow(256, $power); | |
| 25 | - } | |
| 22 | + $id = 0; | |
| 23 | +		foreach ($content as $power => $value) { | |
| 24 | + $id += hexdec($value) * pow(256, $power); | |
| 25 | + } | |
| 26 | 26 | |
| 27 | - return intval($id); | |
| 28 | - } | |
| 27 | + return intval($id); | |
| 28 | + } | |
| 29 | 29 | } | 
| @@ -4,5 +4,5 @@ | ||
| 4 | 4 | |
| 5 | 5 | interface ColumnInterface | 
| 6 | 6 |  { | 
| 7 | - public static function cast($content); | |
| 7 | + public static function cast($content); | |
| 8 | 8 | } | 
| @@ -7,39 +7,39 @@ | ||
| 7 | 7 | |
| 8 | 8 | class ColumnRule extends Rule implements RuleInterface | 
| 9 | 9 |  { | 
| 10 | - const TYPE_DATE = 0; | |
| 11 | - const TYPE_FLOAT = 1; | |
| 12 | - const TYPE_ID = 2; | |
| 13 | - const TYPE_INT = 3; | |
| 14 | - const TYPE_STRING = 4; | |
| 15 | - | |
| 16 | - protected $title; | |
| 17 | - protected $type; | |
| 18 | - | |
| 19 | - public function __construct($title, $type, $length) | |
| 20 | -    { | |
| 21 | - $this->setTitle($title); | |
| 22 | - $this->setType($type); | |
| 23 | - $this->setLength($length); | |
| 24 | - } | |
| 25 | - | |
| 26 | - public function setTitle($title) | |
| 27 | -    { | |
| 28 | - $this->title = $title; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function getTitle() | |
| 32 | -    { | |
| 33 | - return $this->title; | |
| 34 | - } | |
| 35 | - | |
| 36 | - public function setType($type) | |
| 37 | -    { | |
| 38 | - $this->type = $type; | |
| 39 | - } | |
| 40 | - | |
| 41 | - public function getType() | |
| 42 | -    { | |
| 43 | - return $this->type; | |
| 44 | - } | |
| 10 | + const TYPE_DATE = 0; | |
| 11 | + const TYPE_FLOAT = 1; | |
| 12 | + const TYPE_ID = 2; | |
| 13 | + const TYPE_INT = 3; | |
| 14 | + const TYPE_STRING = 4; | |
| 15 | + | |
| 16 | + protected $title; | |
| 17 | + protected $type; | |
| 18 | + | |
| 19 | + public function __construct($title, $type, $length) | |
| 20 | +	{ | |
| 21 | + $this->setTitle($title); | |
| 22 | + $this->setType($type); | |
| 23 | + $this->setLength($length); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public function setTitle($title) | |
| 27 | +	{ | |
| 28 | + $this->title = $title; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public function getTitle() | |
| 32 | +	{ | |
| 33 | + return $this->title; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function setType($type) | |
| 37 | +	{ | |
| 38 | + $this->type = $type; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public function getType() | |
| 42 | +	{ | |
| 43 | + return $this->type; | |
| 44 | + } | |
| 45 | 45 | } | 
| @@ -8,39 +8,39 @@ | ||
| 8 | 8 | |
| 9 | 9 | class DateColumn extends ColumnRule implements ColumnInterface | 
| 10 | 10 |  { | 
| 11 | - const DEFAULT_LENGTH = 8; | |
| 12 | - | |
| 13 | - public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 14 | -    { | |
| 15 | - $this->setTitle($title); | |
| 16 | - $this->setType(self::TYPE_DATE); | |
| 17 | - $this->setLength($length); | |
| 18 | - } | |
| 19 | - | |
| 20 | - public static function cast($content) | |
| 21 | -    { | |
| 22 | -        if (self::validate($content)) { | |
| 23 | - return; | |
| 24 | - } | |
| 25 | - | |
| 26 | - $content = Hex::toStr($content); | |
| 27 | - | |
| 28 | -        try { | |
| 29 | -            $content = DateTime::createFromFormat('Ymd', $content); | |
| 30 | - $content->setTime(0, 0, 0); | |
| 31 | -        } catch (Exception $e) { | |
| 32 | - $content = null; | |
| 33 | - } | |
| 34 | - | |
| 35 | - return $content; | |
| 36 | - } | |
| 37 | - | |
| 38 | - public static function validate($content) | |
| 39 | -    { | |
| 40 | -        if (intval($content) == 0 or strlen($content) < 8 or $content == '2020202020202020') { | |
| 41 | - return false; | |
| 42 | - } | |
| 43 | - | |
| 44 | - return true; | |
| 45 | - } | |
| 11 | + const DEFAULT_LENGTH = 8; | |
| 12 | + | |
| 13 | + public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 14 | +	{ | |
| 15 | + $this->setTitle($title); | |
| 16 | + $this->setType(self::TYPE_DATE); | |
| 17 | + $this->setLength($length); | |
| 18 | + } | |
| 19 | + | |
| 20 | + public static function cast($content) | |
| 21 | +	{ | |
| 22 | +		if (self::validate($content)) { | |
| 23 | + return; | |
| 24 | + } | |
| 25 | + | |
| 26 | + $content = Hex::toStr($content); | |
| 27 | + | |
| 28 | +		try { | |
| 29 | +			$content = DateTime::createFromFormat('Ymd', $content); | |
| 30 | + $content->setTime(0, 0, 0); | |
| 31 | +		} catch (Exception $e) { | |
| 32 | + $content = null; | |
| 33 | + } | |
| 34 | + | |
| 35 | + return $content; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public static function validate($content) | |
| 39 | +	{ | |
| 40 | +		if (intval($content) == 0 or strlen($content) < 8 or $content == '2020202020202020') { | |
| 41 | + return false; | |
| 42 | + } | |
| 43 | + | |
| 44 | + return true; | |
| 45 | + } | |
| 46 | 46 | } | 
| @@ -4,17 +4,17 @@ | ||
| 4 | 4 | |
| 5 | 5 | class FloatColumn extends ColumnRule implements ColumnInterface | 
| 6 | 6 |  { | 
| 7 | - const DEFAULT_LENGTH = 2; | |
| 7 | + const DEFAULT_LENGTH = 2; | |
| 8 | 8 | |
| 9 | - public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 10 | -    { | |
| 11 | - $this->setTitle($title); | |
| 12 | - $this->setType(self::TYPE_FLOAT); | |
| 13 | - $this->setLength($length); | |
| 14 | - } | |
| 9 | + public function __construct($title, $length = self::DEFAULT_LENGTH) | |
| 10 | +	{ | |
| 11 | + $this->setTitle($title); | |
| 12 | + $this->setType(self::TYPE_FLOAT); | |
| 13 | + $this->setLength($length); | |
| 14 | + } | |
| 15 | 15 | |
| 16 | - public static function cast($content) | |
| 17 | -    { | |
| 18 | - return floatval($content); | |
| 19 | - } | |
| 16 | + public static function cast($content) | |
| 17 | +	{ | |
| 18 | + return floatval($content); | |
| 19 | + } | |
| 20 | 20 | } |