本文整理汇总了PHP中RandomLib\Factory::getGenerator方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::getGenerator方法的具体用法?PHP Factory::getGenerator怎么用?PHP Factory::getGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomLib\Factory
的用法示例。
在下文中一共展示了Factory::getGenerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app['randomgenerator'] = $app->share(function () {
$factory = new RandomLib\Factory();
return $factory->getGenerator(new Strength(Strength::MEDIUM));
});
}
示例2: testGetGeneratorFallback
public function testGetGeneratorFallback()
{
$factory = new Factory();
$generator = $factory->getGenerator(new Strength(Strength::VERYLOW));
$mixer = call_user_func(array(get_class($generator->getMixer()), 'getStrength'));
$this->assertTrue($mixer->compare(new Strength(Strength::VERYLOW)) <= 0);
}
示例3: __construct
/**
* TokenStore constructor.
*
* @see TokenStore::$MAX_TOKENS the class property storing the maximum
* tokens limit.
*
* @param int|null $maxTokens An optional limit to the number of valid
* tokens the TokenStore will retain.
* If not specified, an unlimited number of
* tokens will be retained (which is probably
* fine unless you have a very, very busy site
* with long-running sessions).
*/
public function __construct(int $maxTokens = null)
{
if ($maxTokens !== null) {
self::$MAX_TOKENS = $maxTokens;
}
$factory = new Factory();
$this->tokenGenerator = $factory->getGenerator(new Strength(self::$strength));
}
示例4: generateSalt
/**
* Generates salt.
*
* @param integer $length
*
* @return string
*/
public function generateSalt($length = 64)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chars .= '!@#$%^&*()';
$chars .= '-_ []{}<>~`+=,.;:/?|';
$factory = new Factory();
$generator = $factory->getGenerator(new Strength(Strength::MEDIUM));
return $generator->generateString($length, $chars);
}
示例5: initProviders
public function initProviders()
{
// Make sure we keep our current locale.
$currentlocale = $this['locale'];
// Setup Swiftmailer, with the selected Mail Transport options: smtp or `mail()`.
$this->register(new Silex\Provider\SwiftmailerServiceProvider());
if ($this['config']->get('general/mailoptions')) {
// Use the preferred options. Assume it's SMTP, unless set differently.
$this['swiftmailer.options'] = $this['config']->get('general/mailoptions');
}
if (is_bool($this['config']->get('general/mailoptions/spool'))) {
// enable or disable the mail spooler.
$this['swiftmailer.use_spool'] = $this['config']->get('general/mailoptions/spool');
}
if ($this['config']->get('general/mailoptions/transport') == 'mail') {
// Use the 'mail' transport. Discouraged, but some people want it. ¯\_(ツ)_/¯
$this['swiftmailer.transport'] = \Swift_MailTransport::newInstance();
}
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$this->register(new Silex\Provider\HttpFragmentServiceProvider())->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\FormServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\RoutingServiceProvider())->register(new Silex\Provider\ServiceControllerServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider())->register(new Provider\OmnisearchServiceProvider())->register(new Provider\TemplateChooserServiceProvider())->register(new Provider\CronServiceProvider())->register(new Provider\FilePermissionsServiceProvider())->register(new Provider\MenuServiceProvider())->register(new Controllers\Upload())->register(new Controllers\Extend())->register(new Provider\FilesystemProvider())->register(new Thumbs\ThumbnailProvider())->register(new Provider\NutServiceProvider())->register(new Provider\GuzzleServiceProvider())->register(new Provider\PrefillServiceProvider())->register(new SlugifyServiceProvider())->register(new Provider\MarkdownServiceProvider());
$this['paths'] = $this['resources']->getPaths();
// For some obscure reason, and under suspicious circumstances $app['locale'] might become 'null'.
// Re-set it here, just to be sure. See https://github.com/bolt/bolt/issues/1405
$this['locale'] = $currentlocale;
// Initialize stopwatch even if debug is not enabled.
$this['stopwatch'] = $this->share(function () {
return new Stopwatch\Stopwatch();
});
}
示例6: initProviders
public function initProviders()
{
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$this->register(new Silex\Provider\HttpFragmentServiceProvider())->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\RoutingServiceProvider())->register(new Silex\Provider\ServiceControllerServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\QueryServiceProvider())->register(new Provider\AccessControlServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider())->register(new Provider\OmnisearchServiceProvider())->register(new Provider\TemplateChooserServiceProvider())->register(new Provider\CronServiceProvider())->register(new Provider\FilePermissionsServiceProvider())->register(new Provider\MenuServiceProvider())->register(new Provider\UploadServiceProvider())->register(new Provider\FilesystemProvider())->register(new Thumbs\ThumbnailProvider())->register(new Provider\NutServiceProvider())->register(new Provider\GuzzleServiceProvider())->register(new Provider\PrefillServiceProvider())->register(new SlugifyServiceProvider())->register(new Provider\MarkdownServiceProvider())->register(new Provider\ControllerServiceProvider())->register(new Provider\EventListenerServiceProvider())->register(new Provider\AssetServiceProvider())->register(new Provider\FormServiceProvider())->register(new Provider\MailerServiceProvider());
$this['paths'] = $this['resources']->getPaths();
// Initialize stopwatch even if debug is not enabled.
$this['stopwatch'] = $this->share(function () {
return new Stopwatch\Stopwatch();
});
}
示例7: setStrength
/**
* @param $strength
* @return null
*/
public static function setStrength($strength)
{
$factory = new Factory();
static::$generator = $factory->getGenerator(new Strength($strength));
return static::generator();
}
示例8: initProviders
public function initProviders()
{
// Make sure we keep our current locale..
$currentlocale = $this['locale'];
// Setup Swiftmailer, with optional SMTP settings. If no settings are provided in config.yml, mail() is used.
$this->register(new Silex\Provider\SwiftmailerServiceProvider());
if ($this['config']->get('general/mailoptions')) {
$this['swiftmailer.options'] = $this['config']->get('general/mailoptions');
}
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$this->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\FormServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\IntegrityCheckerProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider())->register(new Provider\OmnisearchServiceProvider())->register(new Provider\CronServiceProvider())->register(new Provider\SafeTwigServiceProvider())->register(new Provider\FilePermissionsServiceProvider())->register(new Controllers\Upload())->register(new Controllers\Extend())->register(new Provider\FilesystemProvider())->register(new Thumbs\ThumbnailProvider());
$this['paths'] = $this['resources']->getPaths();
$this['twig']->addGlobal('paths', $this['paths']);
// For some obscure reason, and under suspicious circumstances $app['locale'] might become 'null'.
// Re-set it here, just to be sure. See https://github.com/bolt/bolt/issues/1405
$this['locale'] = $currentlocale;
// Add the Bolt Twig functions, filters and tags.
$this['twig']->addExtension(new TwigExtension($this));
$this['safe_twig']->addExtension(new TwigExtension($this, true));
$this['twig']->addTokenParser(new SetcontentTokenParser());
// Initialize stopwatch even if debug is not enabled.
$this['stopwatch'] = $this->share(function () {
return new Stopwatch\Stopwatch();
});
// @todo: make a provider for the Integrity checker and Random generator..
}
示例9: reset
public function reset()
{
$this->testDescription = $this->testName = $this->testTitle = null;
$this->testResult = self::TEST_RESULT_PASSED;
$this->characteristics = [];
$this->events = [];
$factory = new Factory();
$generator = $factory->getGenerator(new Strength(Strength::MEDIUM));
$this->testId = $generator->generateString(64);
}
示例10: initProviders
public function initProviders()
{
// Make sure we keep our current locale.
$currentlocale = $this['locale'];
// Setup Swiftmailer, with the selected Mail Transport options: smtp or `mail()`.
$this->register(new Silex\Provider\SwiftmailerServiceProvider());
$this->setSwiftmailerOptions();
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
// Set up forms and use a secure CSRF secret
$this->register(new Silex\Provider\FormServiceProvider());
$this['form.secret'] = $this->share(function () {
if (!$this['session']->isStarted()) {
return;
} elseif ($secret = $this['session']->get('form.secret')) {
return $secret;
} else {
$secret = $this['randomgenerator']->generate(32);
$this['session']->set('form.secret', $secret);
return $secret;
}
});
$this->register(new Silex\Provider\HttpFragmentServiceProvider())->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\RoutingServiceProvider())->register(new Silex\Provider\ServiceControllerServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\AuthenticationServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider())->register(new Provider\OmnisearchServiceProvider())->register(new Provider\TemplateChooserServiceProvider())->register(new Provider\CronServiceProvider())->register(new Provider\FilePermissionsServiceProvider())->register(new Provider\MenuServiceProvider())->register(new Provider\UploadServiceProvider())->register(new Provider\FilesystemProvider())->register(new Thumbs\ThumbnailProvider())->register(new Provider\NutServiceProvider())->register(new Provider\GuzzleServiceProvider())->register(new Provider\PrefillServiceProvider())->register(new SlugifyServiceProvider())->register(new Provider\MarkdownServiceProvider())->register(new Provider\ControllerServiceProvider())->register(new Provider\EventListenerServiceProvider())->register(new Provider\AssetServiceProvider());
$this['paths'] = $this['resources']->getPaths();
// For some obscure reason, and under suspicious circumstances $app['locale'] might become 'null'.
// Re-set it here, just to be sure. See https://github.com/bolt/bolt/issues/1405
$this['locale'] = $currentlocale;
// Initialize stopwatch even if debug is not enabled.
$this['stopwatch'] = $this->share(function () {
return new Stopwatch\Stopwatch();
});
}
示例11: getRandomGenerator
/**
* @param int|Strength $strength
*
* @return Generator
* @static * @author Panagiotis Vagenas <pan.vagenas@gmail.com>
* @since 0.0.2
*/
protected static function getRandomGenerator($strength)
{
$factory = new Factory();
if (is_integer($strength)) {
$strength = new Strength($strength);
}
return $factory->getGenerator(new Strength($strength));
}
示例12: initProviders
public function initProviders()
{
// Setup Swiftmailer, with optional SMTP settings. If no settings are provided in config.yml, mail() is used.
$this->register(new Silex\Provider\SwiftmailerServiceProvider());
if ($this['config']->get('general/mailoptions')) {
$this['swiftmailer.options'] = $this['config']->get('general/mailoptions');
}
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$this->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\FormServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\IntegrityCheckerProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider())->register(new Provider\CronServiceProvider())->register(new Provider\SafeTwigServiceProvider())->register(new Provider\FilePermissionsServiceProvider())->register(new Controllers\Upload())->register(new Thumbs\ThumbnailProvider());
$this['paths'] = $this['resources']->getPaths();
$this['twig']->addGlobal('paths', $this['resources']->getPaths());
// Add the Bolt Twig functions, filters and tags.
$this['twig']->addExtension(new TwigExtension($this));
$this['safe_twig']->addExtension(new TwigExtension($this, true));
$this['twig']->addTokenParser(new SetcontentTokenParser());
// Initialize stopwatch even if debug is not enabled.
$this['stopwatch'] = $this->share(function () {
return new Stopwatch\Stopwatch();
});
// @todo: make a provider for the Integrity checker and Random generator..
}
示例13: initProviders
public function initProviders()
{
// Setup Swiftmailer, with optional SMTP settings. If no settings are provided in config.yml, mail() is used.
$this->register(new Silex\Provider\SwiftmailerServiceProvider());
if ($this['config']->get('general/mailoptions')) {
$this['swiftmailer.options'] = $this['config']->get('general/mailoptions');
}
// Set up our secure random generator.
$factory = new RandomLib\Factory();
$this['randomgenerator'] = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$this->register(new Silex\Provider\UrlGeneratorServiceProvider())->register(new Silex\Provider\FormServiceProvider())->register(new Silex\Provider\ValidatorServiceProvider())->register(new Provider\PermissionsServiceProvider())->register(new Provider\StorageServiceProvider())->register(new Provider\UsersServiceProvider())->register(new Provider\CacheServiceProvider())->register(new Provider\ExtensionServiceProvider())->register(new Provider\StackServiceProvider());
$this['paths'] = getPaths($this['config']);
$this['twig']->addGlobal('paths', $this['paths']);
// Add the Bolt Twig functions, filters and tags.
$this['twig']->addExtension(new TwigExtension($this));
$this['twig']->addTokenParser(new SetcontentTokenParser());
// Initialize enabled extensions.
$this['extensions']->initialize();
// @todo: make a provider for the Integrity checker and Random generator..
// Set up the integrity checker for the Database, to periodically check if the Database
// is up to date, and if needed: repair it.
$this['integritychecker'] = new Database\IntegrityChecker($this);
}
示例14: Capsule
// Import the necessary classes
use Aura\Session\SessionFactory;
use Illuminate\Database\Capsule\Manager as Capsule;
use Philo\Blade\Blade;
use RandomLib\Factory as PasswordFactory;
//database
$capsule = new Capsule();
$capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'ovalinfo', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
//manage session
$session_factory = new SessionFactory();
$session = $session_factory->newInstance($_COOKIE);
$session->setCookieParams(array('lifetime' => '1800'));
//30 seconds
$segment = $session->getSegment('oval/signup');
//manage password generation
$factory = new PasswordFactory();
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$pasword_characters = 'abcdefghijklmnopqrstuvwxyz';
//hashing IDs
$hashids = new Hashids\Hashids('REyUxDUiTEjlSqUBCRMXidLbuCLITJMoaehUoHmKrrZfeiXvaicKHBuUJjngTYzq', 10, 'abcdefghij1234567890');
//front-end view
$views = __DIR__ . '../../views';
$cache = __DIR__ . '../../cache';
$blade = new Blade($views, $cache);
//load env file
$dotenv = new Dotenv\Dotenv(__DIR__ . '../../');
$dotenv->load();
$err = array();
$msg = array();
示例15: random
/**
* 生成随机字符串
*
* @param int $length
* @param string $pool
* @return string
*/
public static function random($length = 20, $pool = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890')
{
// 如果pool只有一位
if (self::length($pool) == 1) {
return str_repeat($pool, $length);
}
$factory = new RandomFactory();
$generator = $factory->getGenerator(new RandomStrength(RandomStrength::MEDIUM));
return $generator->generateString($length, $pool);
}