From: Michael M Slusarz Date: Tue, 3 Aug 2010 04:16:47 +0000 (-0600) Subject: Add Horde_Support_Randomid:: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a7806d8838addf9e85ea16a09f5ea4b131ed1275;p=horde.git Add Horde_Support_Randomid:: --- diff --git a/framework/Support/lib/Horde/Support/Randomid.php b/framework/Support/lib/Horde/Support/Randomid.php new file mode 100644 index 000000000..703c70f5c --- /dev/null +++ b/framework/Support/lib/Horde/Support/Randomid.php @@ -0,0 +1,66 @@ + + * + * + * + * @author Michael Slusarz + * @category Horde + * @copyright 2010 The Horde Project (http://www.horde.org/) + * @license http://opensource.org/licenses/bsd-license.php BSD + * @package Support + */ +class Horde_Support_Randomid +{ + /** + * Generated ID. + * + * @var string + */ + private $_rid; + + /** + * New random ID. + * + * @param integer $length The length of the ID. + */ + public function __construct($length = 16) + { + $this->generate($length); + } + + /** + * Generate a random ID. + * + * @param integer $length The length of the ID. + */ + public function generate($length = 16) + { + $this->_rid = substr(base_convert(dechex(strtr(microtime(), array('0.' => '', ' ' => ''))) . strtr(uniqid(mt_rand(), true), array('.' => '')), 16, 36), 0, $length); + } + + /** + * Cooerce to string. + * + * @return string The random ID. + */ + public function __toString() + { + return $this->_rid; + } + +} diff --git a/framework/Support/package.xml b/framework/Support/package.xml index 85fa66e88..2e655ffb7 100644 --- a/framework/Support/package.xml +++ b/framework/Support/package.xml @@ -21,8 +21,8 @@ beta BSD - -* Add Portuguese numerizer. + * Add Horde_Support_Randomid::. + * Add Portuguese numerizer. @@ -43,6 +43,7 @@ + @@ -66,6 +67,7 @@ + @@ -98,6 +100,7 @@ + @@ -112,6 +115,7 @@ + @@ -147,20 +151,5 @@ * Initial Horde_Support_Numerizer objects - - - 0.2.0 - 0.1.0 - - - beta - beta - - 2010-07-10 - BSD - -* Add Portuguese numerizer. - - diff --git a/framework/Support/test/Horde/Support/RandomidTest.php b/framework/Support/test/Horde/Support/RandomidTest.php new file mode 100644 index 000000000..26be46ae2 --- /dev/null +++ b/framework/Support/test/Horde/Support/RandomidTest.php @@ -0,0 +1,26 @@ +assertEquals(16, strlen($rid)); + } + +}