Last active
August 29, 2015 13:56
-
-
Save jdecool/9288375 to your computer and use it in GitHub Desktop.
Silex Skeleton installation
This file contains hidden or 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
#!/usr/bin/env php | |
<?php | |
define('ARG_NAME', 1); | |
define('ARG_VERSION', 2); | |
define('ARG_DESTINATION', 3); | |
installSkeleton($argv); | |
function installSkeleton($argv) { | |
checkRequirements(); | |
checkOptions($argv); | |
downloadFiles($argv); | |
} | |
function checkRequirements() { | |
$extensionRequirements = array('zip'); | |
$missing = array(); | |
foreach ($extensionRequirements as $ext) { | |
if (false === phpversion($ext)) { | |
$missing[] = $ext; | |
} | |
} | |
if (count($missing) > 0) { | |
echo sprintf('This extensions are required : %s', implode(', ', $missing)), PHP_EOL; | |
die; | |
} | |
} | |
function checkOptions($argv) { | |
if (count($argv) < 4) { | |
usageHelp($argv); | |
exit; | |
} | |
$version = $argv[ARG_VERSION]; | |
$destination = $argv[ARG_DESTINATION]; | |
if (file_exists($destination) && !is_dir($destination)) { | |
echo 'Destination is not a folder', PHP_EOL; | |
exit; | |
} | |
if (!file_exists($destination) && !mkdir($destination, 0777, true)) { | |
echo 'Unable to create destination folder', PHP_EOL; | |
exit; | |
} | |
} | |
function downloadFiles($argv) { | |
$version = $argv[ARG_VERSION]; | |
$destination = $argv[ARG_DESTINATION]; | |
$tmpFilename = sprintf('/tmp/skeleton-%s.zip', md5(time())); | |
$url = sprintf('https://github.com/jdecool/SilexSkeleton/archive/%s.zip', $version); | |
if (false === copy($url, $tmpFilename)) { | |
echo sprintf('Unable to download project'), PHP_EOL; | |
exit; | |
} | |
$archive = new ZipArchive(); | |
if (false === ($code = $archive->open($tmpFilename))) { | |
echo sprintf('Unable to extract skeleton [%s]', $code), PHP_EOL; | |
exit; | |
} | |
if (false === $archive->extractTo($destination)) { | |
echo sprintf('Unable to extract archive to destination folder'), PHP_EOL; | |
exit; | |
} | |
$archive->close(); | |
} | |
function usageHelp($argv) { | |
echo sprintf('%s [name] [version] [destination]', $argv[0]), PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment