public function fire()
 {
     $key = Tiny::generate_set();
     //Parse Laravel Version
     $pattern = '/(?P<major>\\d+)\\.(?P<minor>\\d+)(?:\\.(?P<hotfix>\\d+))/';
     if (!preg_match($pattern, Application::VERSION, $version)) {
         $this->warning('Could not detect a version of Laravel. Pre-Laravel 5 behaviour assumed. Writing Key to config file.');
     }
     if (is_array($version) && $version['major'] >= '5') {
         //Laravel 5 integrates vlucas' dotenv, so store key in .ENV file.
         $path = base_path('.env');
         if (file_exists($path) && getenv('LEAGUE_TINY_KEY') !== false) {
             //Already set, so replace it.
             file_put_contents($path, str_replace('LEAGUE_TINY_KEY=' . getenv('LEAGUE_TINY_KEY'), 'LEAGUE_TINY_KEY=' . $key, file_get_contents($path)));
         } else {
             //Append it to the bottom
             $fp = fopen($path, 'a');
             fwrite($fp, "\nLEAGUE_TINY_KEY={$key}\n");
             fclose($fp);
         }
     } else {
         //If Version 4, or default, store file in config file, as per before.
         list($path, $contents) = $this->getKeyFile();
         $contents = str_replace($this->laravel['config']['league/tiny::key'], $key, $contents);
         $this->files->put($path, $contents);
         $this->laravel['config']['league/tiny::key'] = $key;
     }
     $this->info("Tiny key [{$key}] has been set.");
 }
 public function fire()
 {
     list($path, $contents) = $this->getKeyFile();
     $key = Tiny::generate_set();
     $contents = str_replace($this->laravel['config']['league/tiny::key'], $key, $contents);
     $this->files->put($path, $contents);
     $this->laravel['config']['league/tiny::key'] = $key;
     $this->info("Tiny key [{$key}] has been set.");
 }
Beispiel #3
0
 public function testGenerateSetUnique()
 {
     $set = Tiny::generate_set();
     $set_parts = str_split($set);
     $used = array();
     foreach ($set_parts as $char) {
         $this->assertArrayNotHasKey($char, $used);
         $used[$char] = $char;
     }
 }