本文整理匯總了PHP中dmString::random方法的典型用法代碼示例。如果您正苦於以下問題:PHP dmString::random方法的具體用法?PHP dmString::random怎麽用?PHP dmString::random使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dmString
的用法示例。
在下文中一共展示了dmString::random方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: preSave
public function preSave($event)
{
parent::preSave($event);
if (!$this->hash) {
$this->hash = dmString::random(8);
}
}
示例2: randomizeDirName
public static function randomizeDirName($dir, $maxLen = 255)
{
$random = dmString::random(4);
$strip_len = $maxLen - strlen($random);
$strip_name = dmString::truncate(self::sanitizeDirName($file), $strip_len, "");
$final_name = $strip_name . "-" . $random;
return $final_name;
}
示例3: configureFromData
protected function configureFromData($data)
{
if (!$this->getOption('file_name')) {
$this->setOption('file_name', dmString::slugify(dmConfig::get('site_name')) . '-' . dmString::random(8));
}
if (!$this->getOption('file_size')) {
$this->setOption('file_size', strlen($data));
}
}
示例4: clearApcSystemCache
protected function clearApcSystemCache($siteUrl)
{
$this->log('Clear apc system cache');
$fileName = dmString::random(12) . '.php';
$file = sfConfig::get('sf_web_dir') . '/cache/' . $fileName;
file_put_contents($file, '<?php apc_clear_cache();');
$this->getContext()->get('web_browser')->get(trim($siteUrl, '/') . '/cache/' . $fileName);
unlink($file);
}
示例5: testNewPage
public function testNewPage(lime_test $t)
{
$t->diag('Adding a page');
$randomKey = dmString::random(4);
$newPage = $this->createPage('main', 'test' . $randomKey, 'Test Page ' . $randomKey);
$root = $this->pageTable->getTree()->fetchRoot();
$newPage->getNode()->insertAsLastChildOf($root);
$t->ok($newPage->exists(), 'newPage exists');
$t->is($newPage->getNode()->getParent(), $root, 'newPage is child of root');
$t->is($newPage->getNodeParentId(), $root->id, 'newPage->getNodeParentId() returns root.id');
$t->is($newPage->name, 'Test Page ' . $randomKey, 'newPage->name is ' . 'Test Page ' . $randomKey);
}
示例6: executeForgotPasswordWidget
/**
* Handle dmUser/forgotPassword form validation and sends an email with a new password
*/
public function executeForgotPasswordWidget(dmWebRequest $request)
{
// step 1
if (!($forgotPasswordCode = $request->getParameter('_code'))) {
$form = new DmForgotPasswordStep1Form();
if ($request->isMethod('post') && $request->hasParameter($form->getName())) {
$data = $request->getParameter($form->getName());
if ($form->isCaptchaEnabled()) {
$data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'))));
}
$form->bind($data, $request->getFiles($form->getName()));
if ($form->isValid()) {
$user = $form->getUserByEmail($form->getValue('email'));
$user->forgot_password_code = dmString::random(12);
$user->save();
$this->getService('mail')->setTemplate('dm_user_forgot_password')->addValues(array('username' => $user->username, 'email' => $user->email, 'step2_url' => $this->getHelper()->link($this->getPage())->param('_code', $user->forgot_password_code)->getAbsoluteHref()))->send();
$this->getUser()->setFlash('dm_forgot_password_email_sent', $user->email);
$this->redirectBack();
}
}
$this->forms['DmForgotPasswordStep1'] = $form;
} else {
$this->forward404Unless($user = dmDb::table('DmUser')->retrieveByForgotPasswordCode($forgotPasswordCode));
$form = new DmForgotPasswordStep2Form($user);
if ($request->isMethod('post') && $request->hasParameter($form->getName())) {
if ($form->bindAndValid($request)) {
$user->password = $form->getValue('password');
$user->forgot_password_code = null;
$user->save();
$this->getUser()->setFlash('dm_forgot_password_changed', true);
$this->redirectBack();
}
}
$this->forms['DmForgotPasswordStep2'] = $form;
}
}
示例7: dirname
<?php
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->bootFast();
$t = new lime_test();
$nbAreas = dmDb::table('DmArea')->count();
$t->comment($nbAreas . ' areas');
$pageView = dmDb::table('DmPageView')->create(array('module' => dmString::random(), 'action' => dmString::random()))->saveGet();
$area = $pageView->Area;
$t->ok($pageView->exists(), 'Created a pageView');
$t->ok($area->exists(), 'Created an area');
$t->is(dmDb::table('DmArea')->count(), $nbAreas + 1, $nbAreas . '+1 in db');
$pageView->delete();
$t->ok(!$pageView->exists(), 'Deleted the pageView');
$t->ok(!$area->exists(), 'Deleted the area by cascade');
$t->is(dmDb::table('DmArea')->count(), $nbAreas, $nbAreas . ' in db');
$layout = dmDb::table('DmLayout')->create(array('name' => dmString::random()))->saveGet();
$area = $layout->getArea('top');
$t->ok($layout->exists(), 'Created a layout');
$t->ok($area->exists(), 'Created a top area');
$t->is(dmDb::table('DmArea')->count(), $nbAreas + 1, $nbAreas . '+1 in db');
$layout->delete();
$t->ok(!$layout->exists(), 'Deleted the layout');
$t->ok(!$area->exists(), 'Deleted the area by cascade');
$t->is(dmDb::table('DmArea')->count(), $nbAreas, $nbAreas . ' in db');
示例8: dirname
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$t = new lime_test(24);
$t->diag('default culture tests');
$user = $helper->get('user');
$userCulture = $user->getCulture();
$t->is(myDoctrineRecord::getDefaultCulture(), $user->getCulture(), 'default culture is ' . $user->getCulture());
$user->setCulture('en');
$t->is(myDoctrineRecord::getDefaultCulture(), $user->getCulture(), 'default culture is ' . $user->getCulture());
$user->setCulture('es');
$t->is(myDoctrineRecord::getDefaultCulture(), $user->getCulture(), 'default culture is ' . $user->getCulture());
$user->setCulture($userCulture);
$t->is(myDoctrineRecord::getDefaultCulture(), $user->getCulture(), 'default culture is ' . $user->getCulture());
$t->diag('Basic record tests');
$layout = dmDb::create('DmLayout', array('name' => dmString::random(), 'css_class' => 'the_class'))->saveGet();
$t->ok($layout instanceof DmLayout, 'call saveGet() returns the record');
$t->is(dmDb::create('DmLayout')->orNull(), null, 'call orNull() on new record returns null');
$t->is($layout->orNull(), $layout, 'call orNull() on existing record returns the record');
$t->diag('Property access tests');
$t->is($layout->get('css_class'), 'the_class', '->get("css_class")');
$t->is($layout->getCssClass(), 'the_class', '->getCssClass()');
$t->is($layout->css_class, 'the_class', '->css_class');
$t->is($layout->cssClass, 'the_class', '->cssClass');
$t->is($layout['cssClass'], 'the_class', '["css_class"]');
$t->ok($layout->set('css_class', 'other_class'), '->set("css_class")');
$t->ok($layout->setCssClass('other_class'), '->setCssClass()');
$t->ok($layout->css_class = 'other_class', '->css_class');
$t->ok($layout->cssClass = 'other_class', '->cssClass');
$layout->delete();
dmDb::table('DmPage')->checkBasicPages();
示例9: dirname
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
$t = new lime_test(26);
$wtm = $helper->get('widget_type_manager');
$widgetType = $wtm->getWidgetType('dmWidgetContent', 'link');
$formClass = $widgetType->getOption('form_class');
$t->comment('Create a test page');
$testPage = dmDb::create('DmPage', array('module' => dmString::random(), 'action' => dmString::random(), 'name' => dmString::random(), 'slug' => dmString::random()));
$testPage->Node->insertAsFirstChildOf(dmDb::table('DmPage')->getTree()->fetchRoot());
$t->comment('Create a test widget');
$widget = dmDb::create('DmWidget', array('module' => $widgetType->getModule(), 'action' => $widgetType->getAction(), 'value' => '[]', 'dm_zone_id' => $testPage->PageView->Area->Zones[0]));
$t->comment('Create a ' . $formClass . ' instance');
dmDb::table('DmMediaFolder')->checkRoot();
$t->comment('Create a test image media');
$mediaFileName = 'test_' . dmString::random() . '.jpg';
copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data/image/defaultMedia.jpg'), dmOs::join(sfConfig::get('sf_upload_dir'), $mediaFileName));
$media = dmDb::create('DmMedia', array('file' => $mediaFileName, 'dm_media_folder_id' => dmDb::table('DmMediaFolder')->checkRoot()->id))->saveGet();
$t->ok($media->exists(), 'A test media has been created');
$form = new $formClass($widget);
$form->removeCsrfProtection();
$html = $form->render();
$t->like($html, '_^<form\\s(.|\\n)*</form>$_', 'Successfully obtained and rendered a ' . $formClass . ' instance');
$t->is($form->getStylesheets(), array(), 'This widget form requires no additional stylesheet');
$t->is($form->getJavascripts(), array(), 'This widget form requires no additional javascript');
$t->comment('Submit an empty form');
$form->bind(array(), array());
$t->is($form->isValid(), false, 'The form is not valid');
$t->comment('Use a bad href');
$form->bind(array('href' => 'bad href'), array());
$t->is($form->isValid(), false, 'The form is not valid');
示例10: realpath
<?php
require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$t = new lime_test();
$user = dmDb::query('DmUser u')->where('u.username = ?', 'admin')->fetchOne();
$t->comment('Signin ' . $user);
$helper->get('user')->signin($user);
$domain = dmDb::table('DmTestDomain')->create(array('title' => dmString::random()))->saveGet();
$t->is((string) $domain->getCurrentTranslation()->CreatedBy, 'admin');
$t->is((string) $domain->CreatedBy, 'admin');
示例11: dirname
<?php
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$t = new lime_test(15);
$fs = $helper->get('filesystem');
$t->comment($command = 'cd ./');
$t->is($fs->exec($command), true, 'Valid exec returns true');
$t->ok(is_array($fs->getLastExec()), '$fs->getLastExec() returns an array');
$t->is($fs->getLastExec('command'), $command, 'last command is ' . $command);
$t->comment($badCommand = 'cd diem-test-' . dmString::random(8));
$t->is($fs->exec($badCommand), false, 'Invalid exec returns false');
$t->ok(is_array($fs->getLastExec()), '$fs->getLastExec() returns an array');
$t->is($fs->getLastExec('command'), $badCommand, 'last command is ' . $badCommand);
$t->comment($command = 'echo diem-test');
$t->is($fs->exec($command), true, 'Valid exec returns true');
$t->ok(is_array($fs->getLastExec()), '$fs->getLastExec() returns an array');
$t->is($fs->getLastExec('command'), $command, 'last command is ' . $command);
$t->is($helper->fixLinebreaks($fs->getLastExec('output')), 'diem-test' . "\n", 'Output is "' . $fs->getLastExec('output') . '"');
$t->comment('Unix command : ' . ($command = 'whoami'));
$t->is($fs->exec($command), $success = '/' === DIRECTORY_SEPARATOR, 'Execution : ' . $success);
$t->comment('Test ->getFilesInDir()');
$fs->mirror(dirname(__FILE__), sfConfig::get('sf_cache_dir'), sfFinder::type('file'));
mkdir(sfConfig::get('sf_cache_dir') . '/test_dir');
$fullFind = $fs->find('file')->maxdepth(0)->in(sfConfig::get('sf_cache_dir'));
$fastFind = $fs->findFilesInDir(sfConfig::get('sf_cache_dir'));
$t->ok(count($fullFind) > 50, 'sfFinder finds ' . count($fullFind) . ' files');
$t->ok(in_array($file = sfConfig::get('sf_cache_dir') . '/' . basename(__FILE__), $fullFind), 'sfFinder found ' . $file);
$t->is(count($fastFind), count($fullFind), '->findFilesInDir finds ' . count($fullFind) . ' files');
$t->is_deeply($fastFind, $fullFind, '->findFilesInDir() works like sfFinder');
示例12:
/*
* With some old version of sqlite, like on continuous integration server
* This test will not work as expected
*/
if (strpos(getcwd(), 'hudson')) {
return;
}
$t->ok($page = $domain->getDmPage(), 'Domain has a page');
$t->is(dmDb::table('DmPage')->count(), $nbPage + 1, 'One new page');
$t->is($page->isActive, false, 'The page is not active');
$t->is($page->Record, $domain, 'The page record is the domain');
$domain = dmDb::table('DmTestDomain')->create(array('title' => dmString::random(), 'is_active' => true))->saveGet();
$t->ok($domain->exists(), 'Record has been saved');
$t->ok($domain->isActive, 'Record is active');
$t->is(dmDb::table('DmPage')->count(), $nbPage + 1, 'No new page');
$t->ok($page = $domain->getDmPage(), 'Domain has a page');
$t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'One new page');
$t->is($page->isActive, true, 'The page is active');
$t->is($page->Record, $domain, 'The page record is the domain');
$categ = dmDb::table('DmTestCateg')->create(array('name' => dmString::random(), 'is_active' => false))->saveGet();
$t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page');
$t->ok(!$categ->getDmPage(), 'Categ has a NO page');
$t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page');
$t->comment('link the categ to a domain');
$categ->Domains->add($domain);
$categ->save();
$t->is(dmDb::table('DmPage')->count(), $nbPage + 2, 'No new page');
$t->ok($page = $categ->getDmPage(), 'Categ has a page');
$t->is(dmDb::table('DmPage')->count(), $nbPage + 3, 'One new page');
$t->is($page->isActive, false, 'The page is not active');
$t->is($page->Record, $categ, 'The page record is the categ');
示例13: signIn
/**
* Signs in the user on the application.
*
* @param DmUser $user The DmUser id
* @param boolean $remember Whether or not to remember the user
* @param Doctrine_Connection $con A Doctrine_Connection object
*/
public function signIn(DmUser $user, $remember = false, $con = null)
{
// signin
$this->setAttribute('user_id', $user->get('id'), 'dmSecurityUser');
$this->setAuthenticated(true);
$this->clearCredentials();
$this->addCredentials($user->getAllPermissionNames());
$this->isSuperAdmin = $user->get('is_super_admin');
// save last login
dmDb::table('Dmuser')->createQuery()->update('Dmuser')->where('id = ?', $user->get('id'))->set('last_login', "'" . date('Y-m-d H:i:s') . "'")->execute();
$this->user = $user;
if ($remember) {
try {
$expirationAge = $this->getRememberKeyExpirationAge();
// remove old keys
Doctrine_Core::getTable('DmRememberKey')->createQuery()->delete()->where('created_at < ?', date('Y-m-d H:i:s', time() - $expirationAge))->execute();
// remove other keys from this user
Doctrine_Core::getTable('DmRememberKey')->createQuery()->delete()->where('dm_user_id = ?', $user->getId())->orWhere('ip_address = ?', $_SERVER['REMOTE_ADDR'])->execute();
// generate new keys
$key = md5(dmString::random(20));
// save key
$rk = new DmRememberKey();
$rk->setRememberKey($key);
$rk->setUser($user);
$rk->setIpAddress($_SERVER['REMOTE_ADDR']);
$rk->save($con);
$this->dispatcher->notify(new sfEvent($this, 'user.remember_me', array('remember_key' => $key, 'expiration_age' => $expirationAge)));
} catch (Exception $e) {
}
}
$this->dispatcher->notify(new sfEvent($this, 'user.sign_in'));
}
示例14:
$c1PageSlug = 'c1/' . $pageSlug;
$c2PageSlug = 'c2/' . $pageSlug;
$page->Translation['c1']->name = $c1PageSlug;
$page->Translation['c1']->slug = $c1PageSlug;
$page->Translation['c2']->name = $c2PageSlug;
$page->Translation['c2']->slug = $c2PageSlug;
$page->save();
$t->ok($page->hasCurrentTranslation(), 'page has a translation');
$t->is($page->slug, $pageSlug, 'page slug is ' . $pageSlug);
$t->diag('Find route for ' . $pageSlug);
$route = $routing->find($pageSlug);
$t->isa_ok($route, 'dmPageRoute', 'found a dmPageRoute instance for ' . $pageSlug);
$t->is($route->getSlug(), $pageSlug, 'route slug is ' . $pageSlug);
$t->is($route->getPage(), $page, 'route page is the good page');
$t->is($route->getCulture(), $user->getCulture(), 'route culture is user culture : ' . $route->getCulture());
$nonExistingSlug = dmString::random();
$t->diag('Find route for non existing slug ' . $nonExistingSlug);
$route = $routing->find($nonExistingSlug);
$t->is($route, false, 'found no route for non existing slug ' . $nonExistingSlug);
$t->diag('Switch user to c1 culture');
$user->setCulture('c1');
$t->is($helper->get('service_container')->getParameter('user.culture'), $user->getCulture(), 'service container user.culture synchronized');
$route = $routing->find($pageSlug);
$t->isa_ok($route, 'dmPageRoute', 'found a dmPageRoute instance for ' . $pageSlug);
$t->is($route->getSlug(), $pageSlug, 'route slug is ' . $pageSlug);
$t->is($route->getPage(), $page, 'route page is the good page');
$t->is($route->getCulture(), sfConfig::get('sf_default_culture'), 'route culture is default culture : ' . $route->getCulture());
$route = $routing->find($c1PageSlug);
$t->isa_ok($route, 'dmPageRoute', 'found a dmPageRoute instance for ' . $c1PageSlug);
$t->is($route->getSlug(), $c1PageSlug, 'route slug is ' . $c1PageSlug);
$t->is($route->getPage(), $page, 'route page is the good page');
示例15: array
$i18n = $helper->get('i18n');
/*
* configure i18n and add 2 cultures
*/
$i18n->setCultures(array_merge($i18n->getCultures(), array('c1', 'c2')));
$helper->get('service_container')->mergeParameter('page_i18n_builder.options', array('cultures' => $i18n->getCultures()));
$i18nBuilder = $helper->get('page_i18n_builder');
$i18nBuilder->setOption('cultures', $i18n->getCultures());
/*
* connect page_i18n_builder and set the new cultures
*/
if (!$i18nBuilder->isConnected()) {
$i18nBuilder->connect();
}
$t = new lime_test(2 + 7 * count($i18n->getCultures()));
$page = $randomCreatedPage = dmDb::create('DmPage', array('module' => 'test', 'action' => dmString::random(12), 'slug' => dmString::random(12), 'name' => dmString::random(12), 'title' => dmString::random(12), 'h1' => dmString::random(12), 'description' => dmString::random(12), 'keywords' => dmString::random(12)));
$page->getNode()->insertAsLastChildOf($root);
$t->ok($page->getCurrentTranslation()->exists(), 'The current translation exists');
$page->refreshRelated('Translation');
$pageTranslations = $page->get('Translation');
foreach ($i18n->getCultures() as $culture) {
$pageTranslation = $pageTranslations->get($culture);
$t->ok($pageTranslation->exists(), sprintf('The %s translation exists', $culture));
foreach (array('slug', 'name', 'title', 'h1', 'description', 'keywords') as $field) {
$t->is($pageTranslation->get($field), $page->get($field), sprintf('The %s translated page %s is %s', $culture, $field, $page->get($field)));
}
}
$i18nBuilder->createAllPagesTranslations();
$pages = dmDb::table('DmPage')->createQuery('p')->leftJoin('p.Translation')->fetchRecords();
$nbMissingTranslations = 0;
foreach ($pages as $page) {