#!/usr/bin/env php * Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ process($argv); /** * processes the installer */ function process($argv) { $check = in_array('--check', $argv); $help = in_array('--help', $argv); $force = in_array('--force', $argv); if ($help) { displayHelp(); exit(0); } $ok = checkPlatform(); if ($check && !$ok) { exit(1); } if ($ok || $force) { installComposer(); } exit(0); } /** * displays the help */ function displayHelp() { echo << $actual) { switch ($error) { case 'unicode': $text = " detect_unicode = Off (actual: {$actual})".PHP_EOL; break; case 'readonly': $text = " phar.readonly = Off (actual: {$actual})".PHP_EOL; break; case 'require_hash': $text = " phar.require_hash = Off (actual: {$actual})".PHP_EOL; break; case 'suhosin': $text = " suhosin.executor.include.whitelist = phar (actual: {$actual})".PHP_EOL; break; case 'php': $text = " PHP_VERSION (actual: {$actual})".PHP_EOL; break; } out($text, 'info'); } echo PHP_EOL; return false; } out("All settings correct for using Composer".PHP_EOL,'success'); return true; } /** * installs composer to the current working directory */ function installComposer() { $installDir = getcwd(); $file = $installDir . DIRECTORY_SEPARATOR . 'composer.phar'; if (is_readable($file)) { @unlink($file); } $download = copy('http://getcomposer.org/composer.phar', $installDir.DIRECTORY_SEPARATOR.'composer.phar'); out(PHP_EOL."Composer successfully installed to: " . $file, 'success'); out(PHP_EOL."Use it: php composer.phar".PHP_EOL, 'info'); } /** * colorize output */ function out($text, $color = null) { $styles = array( 'success' => "\033[0;32m%s\033[0m", 'error' => "\033[31;31m%s\033[0m", 'info' => "\033[33;33m%s\033[0m" ); echo sprintf(isset($styles[$color]) ? $styles[$color] : "%s", $text); }