Added meters to miles conversion method
Rearranged methods as well, they needed to be in alphabetical order. In the case that I need more distance related conversions, I'll move that method to it's own class.
This commit is contained in:
parent
3290ee0135
commit
344e685035
2 changed files with 104 additions and 54 deletions
|
@ -18,36 +18,12 @@
|
||||||
/**
|
/**
|
||||||
* Convert Class
|
* Convert Class
|
||||||
*
|
*
|
||||||
* Collection of statically called methods to help aid in converting formats.
|
* Collection of statically called methods to help aid in converting formats as
|
||||||
|
* well as distances.
|
||||||
*/
|
*/
|
||||||
class Convert
|
class Convert
|
||||||
{
|
{
|
||||||
/**
|
// {{{ Array to XML
|
||||||
* To JSON
|
|
||||||
*
|
|
||||||
* Encodes passed variable as JSON.
|
|
||||||
*
|
|
||||||
* Requires PHP 5 >= 5.2.0 or PECL json >= 1.2.0
|
|
||||||
*
|
|
||||||
* @link http://json.org/
|
|
||||||
* @link http://us.php.net/json_encode
|
|
||||||
* @link http://pecl.php.net/package/json
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @param mixed $variable variable to convert
|
|
||||||
* @return JSON encoded string
|
|
||||||
*/
|
|
||||||
public static function toJSON($variable)
|
|
||||||
{
|
|
||||||
if (JSON_AVAILABLE)
|
|
||||||
{
|
|
||||||
return json_encode($variable);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return '{ "status": "error", "message": "json_encode() not found" }';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array to XML
|
* Array to XML
|
||||||
|
@ -140,6 +116,55 @@ class Convert
|
||||||
|
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ Meters to Miles
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meters to Miles
|
||||||
|
*
|
||||||
|
* Converts meters to miles.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param mixed $meters meters to convert to miles
|
||||||
|
* @return mixed number of miles
|
||||||
|
*/
|
||||||
|
public static function metersToMiles($meters)
|
||||||
|
{
|
||||||
|
return $meters * 0.00062137119;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ To JSON
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To JSON
|
||||||
|
*
|
||||||
|
* Encodes passed variable as JSON.
|
||||||
|
*
|
||||||
|
* Requires PHP 5 >= 5.2.0 or PECL json >= 1.2.0
|
||||||
|
*
|
||||||
|
* @link http://json.org/
|
||||||
|
* @link http://us.php.net/json_encode
|
||||||
|
* @link http://pecl.php.net/package/json
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param mixed $variable variable to convert
|
||||||
|
* @return JSON encoded string
|
||||||
|
*/
|
||||||
|
public static function toJSON($variable)
|
||||||
|
{
|
||||||
|
if (JSON_AVAILABLE)
|
||||||
|
{
|
||||||
|
return json_encode($variable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return '{ "status": "error", "message": "json_encode() not found" }';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
79
jar.php
79
jar.php
|
@ -1529,36 +1529,12 @@ class Controller extends Object
|
||||||
/**
|
/**
|
||||||
* Convert Class
|
* Convert Class
|
||||||
*
|
*
|
||||||
* Collection of statically called methods to help aid in converting formats.
|
* Collection of statically called methods to help aid in converting formats as
|
||||||
|
* well as distances.
|
||||||
*/
|
*/
|
||||||
class Convert
|
class Convert
|
||||||
{
|
{
|
||||||
/**
|
// {{{ Array to XML
|
||||||
* To JSON
|
|
||||||
*
|
|
||||||
* Encodes passed variable as JSON.
|
|
||||||
*
|
|
||||||
* Requires PHP 5 >= 5.2.0 or PECL json >= 1.2.0
|
|
||||||
*
|
|
||||||
* @link http://json.org/
|
|
||||||
* @link http://us.php.net/json_encode
|
|
||||||
* @link http://pecl.php.net/package/json
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @param mixed $variable variable to convert
|
|
||||||
* @return JSON encoded string
|
|
||||||
*/
|
|
||||||
public static function toJSON($variable)
|
|
||||||
{
|
|
||||||
if (JSON_AVAILABLE)
|
|
||||||
{
|
|
||||||
return json_encode($variable);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return '{ "status": "error", "message": "json_encode() not found" }';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array to XML
|
* Array to XML
|
||||||
|
@ -1651,6 +1627,55 @@ class Convert
|
||||||
|
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ Meters to Miles
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meters to Miles
|
||||||
|
*
|
||||||
|
* Converts meters to miles.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param mixed $meters meters to convert to miles
|
||||||
|
* @return mixed number of miles
|
||||||
|
*/
|
||||||
|
public static function metersToMiles($meters)
|
||||||
|
{
|
||||||
|
return $meters * 0.00062137119;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ To JSON
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To JSON
|
||||||
|
*
|
||||||
|
* Encodes passed variable as JSON.
|
||||||
|
*
|
||||||
|
* Requires PHP 5 >= 5.2.0 or PECL json >= 1.2.0
|
||||||
|
*
|
||||||
|
* @link http://json.org/
|
||||||
|
* @link http://us.php.net/json_encode
|
||||||
|
* @link http://pecl.php.net/package/json
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param mixed $variable variable to convert
|
||||||
|
* @return JSON encoded string
|
||||||
|
*/
|
||||||
|
public static function toJSON($variable)
|
||||||
|
{
|
||||||
|
if (JSON_AVAILABLE)
|
||||||
|
{
|
||||||
|
return json_encode($variable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return '{ "status": "error", "message": "json_encode() not found" }';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue