Skip to content

Commit

Permalink
update utils
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Nov 5, 2018
1 parent 4aee26e commit e1b5377
Showing 1 changed file with 73 additions and 8 deletions.
81 changes: 73 additions & 8 deletions src/Support/Utils.php
@@ -1,6 +1,8 @@
<?php
namespace IEXBase\TronAPI\Support;

use InvalidArgumentException;

class Utils
{
/**
Expand All @@ -14,22 +16,85 @@ public static function isValidUrl($url) :bool {
}

/**
* Check if the string is a 16th notation
* Check whether the passed parameter is an array
*
* @param $str
* @param $array
* @return bool
*/
public static function isHex($str) : bool {
return is_string($str) && !is_nan(intval($str,16));
public static function isArray($array) : bool {
return is_array($array);
}

/**
* Check whether the passed parameter is an array
* isZeroPrefixed
*
* @param $array
* @param string
* @return bool
*/
public static function isArray($array) : bool {
return is_array($array);
public static function isZeroPrefixed($value)
{
if (!is_string($value)) {
throw new InvalidArgumentException('The value to isZeroPrefixed function must be string.');
}
return (strpos($value, '0x') === 0);
}

/**
* stripZero
*
* @param string $value
* @return string
*/
public static function stripZero($value)
{
if (self::isZeroPrefixed($value)) {
$count = 1;
return str_replace('0x', '', $value, $count);
}
return $value;
}

/**
* isNegative
*
* @param string
* @return bool
*/
public static function isNegative($value)
{
if (!is_string($value)) {
throw new InvalidArgumentException('The value to isNegative function must be string.');
}
return (strpos($value, '-') === 0);
}

/**
* isHex
*
* @param string $value
* @return bool
*/
public static function isHex($value)
{
return (is_string($value) && preg_match('/^(0x)?[a-f0-9]*$/', $value) === 1);
}

/**
* hexToBin
*
* @param string
* @return string
*/
public static function hexToBin($value)
{
if (!is_string($value)) {
throw new InvalidArgumentException('The value to hexToBin function must be string.');
}
if (self::isZeroPrefixed($value)) {
$count = 1;
$value = str_replace('0x', '', $value, $count);
}
return pack('H*', $value);
}

}

0 comments on commit e1b5377

Please sign in to comment.