Created
February 28, 2015 22:46
-
-
Save snipe/3e82c2c9288f761315eb to your computer and use it in GitHub Desktop.
Versioning.php Artisan command for generating a version config for Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class Versioning extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'versioning:update'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Generate and update app\'s version via git.'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function fire() | |
{ | |
// Path to the file containing your version | |
// This will be overwritten everything you commit a message | |
$versionFile = app_path().'/config/version.php'; | |
// The git's output | |
$version = $this->argument('version'); | |
// Here we save the version array in a variable | |
$array = var_export(array('latest' => $version), true); | |
// Construct our file content | |
$content = <<<CON | |
<?php | |
return $array; | |
CON; | |
// And finally write the file and output the current version | |
\File::put($versionFile, $content); | |
$this->line('Setting version: '. \Config::get('version.latest')); | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array( | |
array('version', InputArgument::REQUIRED, 'version number is required.'), | |
); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return array( | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment