Commit 4a8483ce authored by Taylor Otwell's avatar Taylor Otwell

conversion to psr2

parent ab1b243f
......@@ -6,146 +6,143 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class NewCommand extends \Symfony\Component\Console\Command\Command {
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this->setName('new')
->setDescription('Create a new Laravel application.')
->addArgument('name', InputArgument::REQUIRED);
}
/**
* Execute the command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->verifyApplicationDoesntExist(
$directory = getcwd().'/'.$input->getArgument('name'),
$output
);
$output->writeln('<info>Crafting application...</info>');
$this->download($zipFile = $this->makeFilename())
class NewCommand extends \Symfony\Component\Console\Command\Command
{
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this->setName('new')
->setDescription('Create a new Laravel application.')
->addArgument('name', InputArgument::REQUIRED);
}
/**
* Execute the command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->verifyApplicationDoesntExist(
$directory = getcwd().'/'.$input->getArgument('name'),
$output
);
$output->writeln('<info>Crafting application...</info>');
$this->download($zipFile = $this->makeFilename())
->extract($zipFile, $directory)
->cleanUp($zipFile);
$composer = $this->findComposer();
$commands = array(
$composer.' run-script post-install-cmd',
$composer.' run-script post-create-project-cmd',
);
$process = new Process(implode(' && ', $commands), $directory, null, null, null);
$process->run(function($type, $line) use ($output)
{
$output->write($line);
});
$output->writeln('<comment>Application ready! Build something amazing.</comment>');
}
/**
* Verify that the application does not already exist.
*
* @param string $directory
* @return void
*/
protected function verifyApplicationDoesntExist($directory, OutputInterface $output)
{
if (is_dir($directory))
{
$output->writeln('<error>Application already exists!</error>');
exit(1);
}
}
/**
* Generate a random temporary filename.
*
* @return string
*/
protected function makeFilename()
{
return getcwd().'/laravel_'.md5(time().uniqid()).'.zip';
}
/**
* Download the temporary Zip to the given file.
*
* @param string $zipFile
* @return $this
*/
protected function download($zipFile)
{
$response = \GuzzleHttp\get('http://cabinet.laravel.com/latest.zip')->getBody();
file_put_contents($zipFile, $response);
return $this;
}
/**
* Extract the zip file into the given directory.
*
* @param string $zipFile
* @param string $directory
* @return $this
*/
protected function extract($zipFile, $directory)
{
$archive = new ZipArchive;
$archive->open($zipFile);
$archive->extractTo($directory);
$archive->close();
return $this;
}
/**
* Clean-up the Zip file.
*
* @param string $zipFile
* @return $this
*/
protected function cleanUp($zipFile)
{
@chmod($zipFile, 0777);
@unlink($zipFile);
return $this;
}
/**
* Get the composer command for the environment.
*
* @return string
*/
protected function findComposer()
{
if (file_exists(getcwd().'/composer.phar'))
{
return '"'.PHP_BINARY.'" composer.phar';
}
return 'composer';
}
$composer = $this->findComposer();
$commands = array(
$composer.' run-script post-install-cmd',
$composer.' run-script post-create-project-cmd',
);
$process = new Process(implode(' && ', $commands), $directory, null, null, null);
$process->run(function ($type, $line) use ($output) {
$output->write($line);
});
$output->writeln('<comment>Application ready! Build something amazing.</comment>');
}
/**
* Verify that the application does not already exist.
*
* @param string $directory
* @return void
*/
protected function verifyApplicationDoesntExist($directory, OutputInterface $output)
{
if (is_dir($directory)) {
$output->writeln('<error>Application already exists!</error>');
exit(1);
}
}
/**
* Generate a random temporary filename.
*
* @return string
*/
protected function makeFilename()
{
return getcwd().'/laravel_'.md5(time().uniqid()).'.zip';
}
/**
* Download the temporary Zip to the given file.
*
* @param string $zipFile
* @return $this
*/
protected function download($zipFile)
{
$response = \GuzzleHttp\get('http://cabinet.laravel.com/latest.zip')->getBody();
file_put_contents($zipFile, $response);
return $this;
}
/**
* Extract the zip file into the given directory.
*
* @param string $zipFile
* @param string $directory
* @return $this
*/
protected function extract($zipFile, $directory)
{
$archive = new ZipArchive;
$archive->open($zipFile);
$archive->extractTo($directory);
$archive->close();
return $this;
}
/**
* Clean-up the Zip file.
*
* @param string $zipFile
* @return $this
*/
protected function cleanUp($zipFile)
{
@chmod($zipFile, 0777);
@unlink($zipFile);
return $this;
}
/**
* Get the composer command for the environment.
*
* @return string
*/
protected function findComposer()
{
if (file_exists(getcwd().'/composer.phar')) {
return '"'.PHP_BINARY.'" composer.phar';
}
return 'composer';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment