コード例 #1
0
ファイル: MySQL.php プロジェクト: totten/amp
 /**
  * Create a datasource representing a new user and database
  *
  * @param string $hint an advisory string; ideally included in $db/$user
  * @return Datasource;
  */
 public function createDatasource($hint)
 {
     $pass = \Amp\Util\StringUtil::createRandom(16);
     $user = \Amp\Util\StringUtil::createHintedRandom($hint, 16, 5, 'abcdefghijklmnopqrstuvwxyz0123456789');
     $datasource = new Datasource();
     $datasource->setDriver($this->adminDatasource->getDriver());
     $datasource->setHost($this->adminDatasource->getHost());
     $datasource->setPort($this->adminDatasource->getPort());
     $datasource->setSocketPath($this->adminDatasource->getSocketPath());
     $datasource->setUsername($user);
     $datasource->setPassword($pass);
     $datasource->setDatabase($user);
     return $datasource;
 }
コード例 #2
0
ファイル: StringUtil.php プロジェクト: totten/amp
 /**
  * @param string $hint a string that should appear in the name
  * @param int $fullLen total max# chars. must be at least +1 over $randLen
  * @param int $randLen #random chars
  * @return string
  */
 public static function createHintedRandom($hint, $fullLen, $randLen, $randAlphabet = self::ALPHANUMERIC)
 {
     $hint = preg_replace('/[^a-zA-Z0-9]/', '', $hint);
     return substr($hint, 0, $fullLen - 1 - $randLen) . '_' . \Amp\Util\StringUtil::createRandom($randLen, $randAlphabet);
 }
コード例 #3
0
ファイル: ConfigCommand.php プロジェクト: totten/amp
 protected function askPermCommand()
 {
     return $this->createPrompt('perm_custom_command')->setAsk(function ($default, InputInterface $input, OutputInterface $output, DialogHelper $dialog) {
         $value = $dialog->askAndValidate($output, "Enter perm_custom_command> ", function ($command) use($output) {
             $testDir = $this->getContainer()->getParameter('app_dir') . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . \Amp\Util\StringUtil::createRandom(16);
             $output->writeln("<info>Executing against test directory ({$testDir})</info>");
             $result = \Amp\Permission\External::validateDirCommand($testDir, $command);
             $output->writeln("<info>OK (Executed without error)</info>");
             return $result;
         }, FALSE, $default);
         return empty($value) ? FALSE : $value;
     });
 }
コード例 #4
0
ファイル: TestCommand.php プロジェクト: totten/amp
 /**
  * @param string $template path of the example canary script
  * @return string, root path of the canary web app
  */
 protected function createCanaryFiles(OutputInterface $output)
 {
     // Create empty web dir
     $root = $this->getContainer()->getParameter('app_dir') . DIRECTORY_SEPARATOR . 'canary';
     if (!$this->fs->exists($root)) {
         $this->fs->mkdir($root);
     }
     // Create empty data dir
     $dataDirCode = \Amp\Util\StringUtil::createRandom(32);
     $dataDir = $root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . $dataDirCode;
     $this->doCommand($output, OutputInterface::VERBOSITY_NORMAL, 'datadir', array('path' => array($dataDir)));
     // Create PHP code
     $content = $this->templateEngine->render('canary.php', array('expectedResponse' => $this->expectedResponse, 'dataDir' => $dataDir));
     $this->fs->dumpFile($root . DIRECTORY_SEPARATOR . 'index.php', $content);
     return array($root, $dataDir);
 }