Move RandomGeneratorInterface and RandomGeneratorFactory to Generator NS

This commit is contained in:
Ben Ramsey
2015-07-16 09:54:04 -05:00
parent e006f669ad
commit b3ef99a2e9
10 changed files with 9 additions and 13 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Generator;
class RandomGeneratorFactory
{
/**
* For testing, openssl_random_pseudo_bytes() override; if true, treat as
* if openssl_random_pseudo_bytes() is not available
*
* @var bool
*/
public static $forceNoOpensslRandomPseudoBytes = false;
/**
* Returns true if the system has openssl_random_pseudo_bytes()
*
* @return bool
*/
protected static function hasOpensslRandomPseudoBytes()
{
return (function_exists('openssl_random_pseudo_bytes') && !self::$forceNoOpensslRandomPseudoBytes);
}
public static function getGenerator()
{
if (self::hasOpensslRandomPseudoBytes()) {
return new OpenSslGenerator();
}
return new MtRandGenerator();
}
}