/**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  */
 public function execute(Application $application, FileSystem $fileSystem)
 {
     $configFile = $application->getPath() . '/config/application.php';
     if (!$fileSystem->isWritable($configFile)) {
         $this->error('Unable to generate a new secret. Make sure that the [ app/config/application.php ] file is writable.');
         return;
     }
     if (function_exists('openssl_random_pseudo_bytes')) {
         $secret = bin2hex(openssl_random_pseudo_bytes(32));
     } else {
         $secret = str_replace(['"', '\''], ['|', '/'], Str::random(Str::ALNUM . Str::SYMBOLS, 64));
     }
     $contents = $fileSystem->getContents($configFile);
     $contents = preg_replace('/\'secret\'(\\s*)=>(\\s*)\'(.*)\',/', '\'secret\'$1=>$2\'' . $secret . '\',', $contents);
     $fileSystem->putContents($configFile, $contents);
     $this->write('A new application secret has been generated.');
 }
Esempio n. 2
0
 /**
  * Sends command to Redis server and returns response.
  *
  * @access  public
  * @param   string  $name       Command name
  * @param   array   $arguments  Command arguments
  * @return  mixed
  */
 public function __call($name, $arguments)
 {
     // Build command
     $arguments = array_merge(explode(' ', strtoupper(str_replace('_', ' ', Str::camel2underscored($name)))), $arguments);
     $command = '*' . count($arguments) . static::CRLF;
     foreach ($arguments as $argument) {
         $command .= '$' . strlen($argument) . static::CRLF . $argument . static::CRLF;
     }
     if ($this->pipelined) {
         // Pipeline commands
         $this->commands[] = $command;
         return $this;
     } else {
         // Send command to server and return response
         $this->connection->write($command);
         return $this->response();
     }
 }
Esempio n. 3
0
 /**
  * Returns the table name of the model.
  *
  * @access  public
  * @return  string
  */
 public function getTable()
 {
     if (empty($this->tableName)) {
         $this->tableName = Str::pluralize(Str::camel2underscored($this->getClassShortName()));
     }
     return $this->tableName;
 }
Esempio n. 4
0
 /**
  * Excecutes the chosen validation rule.
  *
  * @access  protected
  * @param   string     $field      Name of the field that we're validating
  * @param   array      $validator  Validator
  * @return  boolean
  */
 public function validate($field, $validator)
 {
     $parameters = array_merge([$this->input[$field]], $validator['parameters']);
     if (method_exists($this, $rule = 'validate' . Str::underscored2camel($validator['name']))) {
         return $this->{$rule}(...$parameters);
     } elseif (isset($this->plugins[$rule = $validator['package'] . $validator['name']])) {
         return $this->plugins[$rule]->validate(...$parameters);
     } else {
         throw new RuntimeException(vsprintf("%s(): Call to undefined validation rule '%s'.", [__METHOD__, trim($validator['package'] . '::' . $validator['name'], '::')]));
     }
 }
Esempio n. 5
0
 /**
  *
  */
 public function testRandom()
 {
     $this->assertEquals(32, mb_strlen(Str::random()));
     $this->assertEquals(16, mb_strlen(Str::random(Str::ALNUM, 16)));
 }