Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
installer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vnp-framework
installer
Commits
4a8483ce
Commit
4a8483ce
authored
Feb 25, 2015
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conversion to psr2
parent
ab1b243f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
139 deletions
+136
-139
NewCommand.php
src/NewCommand.php
+136
-139
No files found.
src/NewCommand.php
View file @
4a8483ce
...
...
@@ -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'
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment