当前位置: 首页>>代码示例>>PHP>>正文


PHP RandomLib\Factory类代码示例

本文整理汇总了PHP中RandomLib\Factory的典型用法代码示例。如果您正苦于以下问题:PHP Factory类的具体用法?PHP Factory怎么用?PHP Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveTokenAction

 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function saveTokenAction(Request $request)
 {
     $apiToken = new ApiToken();
     $apiToken->setUser($this->getUser());
     $formBuilder = $this->createFormBuilder($apiToken, array('action' => $this->generateUrl('api_key_create'), 'data_class' => 'CSBill\\UserBundle\\Entity\\ApiToken'));
     $formBuilder->add('name');
     $form = $formBuilder->getForm();
     $form->handleRequest($request);
     $response = array();
     if ($form->isValid()) {
         $factory = new Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $token = $generator->generateString(64, Generator::CHAR_ALNUM);
         $apiToken->setToken($token);
         $this->save($apiToken);
         $response['status'] = 0;
         $response['token'] = array('token' => $apiToken->getToken(), 'name' => $apiToken->getName(), 'id' => $apiToken->getId());
         return $this->json($response);
     } else {
         $response['status'] = 1;
     }
     $content = $this->renderView('CSBillUserBundle:Api:create.html.twig', array('form' => $form->createView()));
     $response['content'] = $content;
     return $this->json($response);
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:30,代码来源:ApiController.php

示例2: register

 public function register(Application $app)
 {
     $app['randomgenerator'] = $app->share(function () {
         $factory = new RandomLib\Factory();
         return $factory->getGenerator(new Strength(Strength::MEDIUM));
     });
 }
开发者ID:atiarda,项目名称:bolt,代码行数:7,代码来源:RandomGeneratorServiceProvider.php

示例3: generateKey

 /**
  * Create a medium strength key
  *
  * Generates a medium strength random number of size $bytes and hash with the
  * algorithm specified in $hash.
  *
  * @param string  $hash  hash function to use
  * @param integer $bytes the number of random bytes to generate
  *
  * @return string hashed token
  */
 public static function generateKey($hash = 'sha512', $bytes = 128)
 {
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $token = hash($hash, $generator->generate($bytes));
     return $token;
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:18,代码来源:Random.php

示例4: createCode

 /**
  * @return string
  */
 public function createCode()
 {
     $factory = new RandomLibFactory();
     $generator = $factory->getLowStrengthGenerator();
     $randomString = $generator->generateString($this->confirmationCodeLength, $this->confirmationCodeCharacters);
     return $randomString;
 }
开发者ID:basilicom,项目名称:pimcore-plugin-participation,代码行数:10,代码来源:Confirmation.php

示例5: migrateSettingsFile

 public static function migrateSettingsFile(Event $event = null)
 {
     if ($event !== null) {
         $event->getIO()->write("Migrating old setting file...");
     }
     if ($event) {
         $root_dir = realpath('');
     } else {
         $root_dir = realpath('../../');
     }
     if (file_exists($root_dir . '/app/config/parameters.yml')) {
         return false;
     }
     if (file_exists($root_dir . '/' . self::SETTINGS_FILE)) {
         $tmp_settings = file_get_contents($root_dir . '/' . self::SETTINGS_FILE);
         if (strpos($tmp_settings, '_DB_SERVER_') !== false) {
             $tmp_settings = preg_replace('/(\'|")\\_/', '$1_LEGACY_', $tmp_settings);
             file_put_contents($root_dir . '/' . self::SETTINGS_FILE, $tmp_settings);
             include $root_dir . '/' . self::SETTINGS_FILE;
             $factory = new RandomLib\Factory();
             $generator = $factory->getLowStrengthGenerator();
             $secret = $generator->generateString(56);
             $default_parameters = Yaml::parse($root_dir . '/app/config/parameters.yml.dist');
             $parameters = array('parameters' => array('database_host' => _LEGACY_DB_SERVER_, 'database_port' => '~', 'database_user' => _LEGACY_DB_USER_, 'database_password' => _LEGACY_DB_PASSWD_, 'database_name' => _LEGACY_DB_NAME_, 'database_prefix' => _LEGACY_DB_PREFIX_, 'database_engine' => _LEGACY_MYSQL_ENGINE_, 'cookie_key' => _LEGACY_COOKIE_KEY_, 'cookie_iv' => _LEGACY_COOKIE_IV_, 'ps_caching' => _LEGACY_PS_CACHING_SYSTEM_, 'ps_cache_enable' => _LEGACY_PS_CACHE_ENABLED_, 'ps_creation_date' => _LEGACY_PS_CREATION_DATE_, 'secret' => $secret, 'mailer_transport' => 'smtp', 'mailer_host' => '127.0.0.1', 'mailer_user' => '~', 'mailer_password' => '~') + $default_parameters['parameters']);
             if (file_put_contents($root_dir . '/app/config/parameters.yml', Yaml::dump($parameters))) {
                 $settings_content = "<?php\n";
                 $settings_content .= "//@deprecated 1.7";
                 file_put_contents($root_dir . '/' . self::SETTINGS_FILE, $settings_content);
             }
         }
     }
     if ($event !== null) {
         $event->getIO()->write("Finished...");
     }
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:35,代码来源:Migrate.php

示例6: __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));
 }
开发者ID:phpgt,项目名称:csrf,代码行数:21,代码来源:TokenStore.php

示例7: generateString

 /**
  * Generate a medium-strength random string of the given length.
  *
  * @param int $length length of the generated string
  * @param string $characters characters to use to generate the string
  * @return string
  */
 public function generateString($length, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
 {
     if (is_null($this->_factory)) {
         $this->_factory = new \RandomLib\Factory();
         $this->_generator = $this->_factory->getMediumStrengthGenerator();
     }
     return $this->_generator->generateString($length, $characters);
 }
开发者ID:josephsnyder,项目名称:Midas,代码行数:15,代码来源:RandomComponent.php

示例8: let

 function let(Factory $factory, Generator $low, Generator $medium)
 {
     $factory->getMediumStrengthGenerator()->willReturn($medium);
     $factory->getLowStrengthGenerator()->willReturn($low);
     $this->beConstructedWith($factory);
     $defaults = ['length' => 32, 'chars' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'strength' => 'medium'];
     $this->setOptions($defaults);
 }
开发者ID:zittix,项目名称:StringGeneratorBundle,代码行数:8,代码来源:SecureStringGeneratorSpec.php

示例9: __construct

 public function __construct(Generator $generator = null)
 {
     $this->generator = $generator;
     if ($this->generator == null) {
         $factory = new Factory();
         $this->generator = $factory->getMediumStrengthGenerator();
     }
 }
开发者ID:00f100,项目名称:uuid,代码行数:8,代码来源:RandomLibAdapter.php

示例10: testGetSetKeyGenerator

 public function testGetSetKeyGenerator()
 {
     $this->assertInstanceOf('QueryAuth\\KeyGenerator', $this->requestSigner->getKeyGenerator());
     $randomFactory = new RandomFactory();
     $keyGenerator = new KeyGenerator($randomFactory->getMediumStrengthGenerator());
     $this->requestSigner->setKeyGenerator($keyGenerator);
     $this->assertSame($keyGenerator, $this->requestSigner->getKeyGenerator());
 }
开发者ID:jeremykendall,项目名称:query-auth,代码行数:8,代码来源:RequestSignerTest.php

示例11: 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);
 }
开发者ID:anolilab,项目名称:wordpress-salt-generator,代码行数:16,代码来源:Generator.php

示例12: generateLink

 public static function generateLink($event)
 {
     $model = $event->getModel();
     if (!$model->link) {
         $factory = new Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $model->link = $generator->generateString(32, Generator::CHAR_ALNUM);
     }
 }
开发者ID:idealistsoft,项目名称:framework-auth,代码行数:9,代码来源:UserLink.php

示例13: getAlternativeGenerator

 public function getAlternativeGenerator()
 {
     if (isset($this->generator)) {
         return $this->generator;
     }
     $factory = new RandomLib\Factory();
     $this->generator = $factory->getMediumStrengthGenerator();
     return $this->generator;
 }
开发者ID:Aasit,项目名称:DISCOUNT--SRV-I,代码行数:9,代码来源:RandomUtils.php

示例14: getAlternativeGenerator

 public function getAlternativeGenerator()
 {
     if (isset($this->generator)) {
         return $this->generator;
     }
     $factory = new RandomLib\Factory();
     $factory->registerSource('HashTiming', '\\SecurityMultiTool\\Random\\Source\\HashTiming');
     $this->generator = $factory->getMediumStrengthGenerator();
     return $this->generator;
 }
开发者ID:emma5021,项目名称:toba,代码行数:10,代码来源:Generator.php

示例15: testGetMediumStrengthGenerator

 /**
  * @covers RandomLib\Factory::getMediumStrengthGenerator
  * @covers RandomLib\Factory::getGenerator
  * @covers RandomLib\Factory::findMixer
  * @covers RandomLib\Factory::findSources
  */
 public function testGetMediumStrengthGenerator()
 {
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $this->assertTrue($generator instanceof Generator);
     $mixer = call_user_func(array(get_class($generator->getMixer()), 'getStrength'));
     $this->assertTrue($mixer->compare(new Strength(Strength::MEDIUM)) <= 0);
     foreach ($generator->getSources() as $source) {
         $strength = call_user_func(array(get_class($source), 'getStrength'));
         $this->assertTrue($strength->compare(new Strength(Strength::MEDIUM)) >= 0);
     }
 }
开发者ID:dukt,项目名称:craft-oauth,代码行数:18,代码来源:FactoryTest.php


注:本文中的RandomLib\Factory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。