getRoot() public static method

public static getRoot ( )
コード例 #1
0
ファイル: GetCommand.php プロジェクト: phpbrew/phpbrew
 public function execute($appName)
 {
     $apps = AppStore::all();
     if (!isset($apps[$appName])) {
         throw new Exception("App {$appName} not found.");
     }
     $app = $apps[$appName];
     $targetDir = Config::getRoot() . DIRECTORY_SEPARATOR . 'bin';
     $target = $targetDir . DIRECTORY_SEPARATOR . $app['as'];
     DownloadFactory::getInstance($this->logger, $this->options)->download($app['url'], $target);
     $this->logger->info('Changing permissions to 0755');
     if ($mod = $this->options->chmod) {
         chmod($target, octdec($mod));
     } else {
         chmod($target, 0755);
     }
     $this->logger->info("Downloaded at {$target}");
 }
コード例 #2
0
 public function run(Build $build = null)
 {
     $dirs = array();
     $dirs[] = Config::getRoot();
     $dirs[] = Config::getHome();
     $dirs[] = Config::getBuildDir();
     $dirs[] = Config::getDistFileDir();
     $dirs[] = Config::getVariantsDir();
     if ($build) {
         $dirs[] = Config::getInstallPrefix() . DIRECTORY_SEPARATOR . $build->getName();
     }
     foreach ($dirs as $dir) {
         if (!file_exists($dir)) {
             $this->logger->debug("Creating directory {$dir}");
             mkdir($dir, 0755, true);
         }
     }
 }
コード例 #3
0
ファイル: UseCommand.php プロジェクト: phpbrew/phpbrew
 public function execute($buildName)
 {
     if (!$buildName) {
         // This exception is used for tracing tests
         throw new Exception('build name is required.');
     }
     // this block is important for tests only
     $root = Config::getRoot();
     $home = Config::getHome();
     if (!file_exists("{$root}/php/{$buildName}")) {
         throw new Exception("build {$buildName} doesn't exist.");
     }
     putenv("PHPBREW_ROOT={$root}");
     putenv("PHPBREW_HOME={$home}");
     putenv("PHPBREW_PHP={$buildName}") or die('putenv failed');
     putenv("PHPBREW_PATH={$root}/php/{$buildName}/bin");
     putenv("PHPBREW_BIN={$home}/bin");
     if (!getenv('TRAVIS')) {
         $this->logger->warning("You should not see this, if you see this, it means you didn't load the ~/.phpbrew/bashrc script, please check if bashrc is sourced in your shell.");
     }
 }
コード例 #4
0
ファイル: CtagsCommand.php プロジェクト: phpbrew/phpbrew
 public function execute($versionName = null)
 {
     $args = func_get_args();
     array_shift($args);
     // $currentVersion;
     $root = Config::getRoot();
     $home = Config::getHome();
     if ($versionName) {
         $sourceDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . $versionName;
     } else {
         if (!getenv('PHPBREW_PHP')) {
             $this->logger->error('Error: PHPBREW_PHP environment variable is not defined.');
             $this->logger->error('  This command requires you specify a PHP version from your build list.');
             $this->logger->error("  And it looks like you haven't switched to a version from the builds that were built with PHPBrew.");
             $this->logger->error('Suggestion: Please install at least one PHP with your prefered version and switch to it.');
             return false;
         }
         $sourceDir = Config::getCurrentBuildDir();
     }
     if (!file_exists($sourceDir)) {
         return $this->logger->error("{$sourceDir} does not exist.");
     }
     $this->logger->info('Scanning ' . $sourceDir);
     $cmd = new CommandBuilder('ctags');
     $cmd->arg('-R');
     $cmd->arg('-a');
     $cmd->arg('-h');
     $cmd->arg('.c.h.cpp');
     $cmd->arg($sourceDir . DIRECTORY_SEPARATOR . 'main');
     $cmd->arg($sourceDir . DIRECTORY_SEPARATOR . 'ext');
     $cmd->arg($sourceDir . DIRECTORY_SEPARATOR . 'Zend');
     foreach ($args as $a) {
         $cmd->arg($a);
     }
     $this->logger->debug($cmd->__toString());
     $cmd->execute();
     $this->logger->info('Done');
 }
コード例 #5
0
ファイル: PathCommand.php プロジェクト: phpbrew/phpbrew
 public function execute($name)
 {
     switch ($name) {
         case 'root':
             echo Config::getRoot();
             break;
         case 'home':
             echo Config::getHome();
             break;
         case 'config-scan':
             echo Config::getCurrentPhpConfigScanPath();
             break;
         case 'dist':
             echo Config::getDistFileDir();
             break;
         case 'build':
             echo Config::getCurrentBuildDir();
             break;
         case 'bin':
             echo Config::getCurrentPhpBin();
             break;
         case 'include':
             echo Config::getVersionInstallPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'include';
             break;
         case 'extension-src':
         case 'ext-src':
             echo Config::getCurrentBuildDir() . DIRECTORY_SEPARATOR . 'ext';
             break;
         case 'extension-dir':
         case 'ext-dir':
         case 'ext':
             echo ini_get('extension_dir');
             break;
         case 'etc':
             echo Config::getVersionInstallPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'etc';
             break;
     }
 }
コード例 #6
0
ファイル: EnvCommand.php プロジェクト: phpbrew/phpbrew
 public function execute($buildName = null)
 {
     // get current version
     if (!$buildName) {
         $buildName = getenv('PHPBREW_PHP');
     }
     // $currentVersion;
     $root = Config::getRoot();
     $home = Config::getHome();
     $lookup = getenv('PHPBREW_LOOKUP_PREFIX');
     $this->logger->writeln("export PHPBREW_ROOT={$root}");
     $this->logger->writeln("export PHPBREW_HOME={$home}");
     $this->logger->writeln("export PHPBREW_LOOKUP_PREFIX={$lookup}");
     if ($buildName !== false) {
         // checking php version existence
         $targetPhpBinPath = Config::getVersionBinPath($buildName);
         if (is_dir($targetPhpBinPath)) {
             echo 'export PHPBREW_PHP=' . $buildName . "\n";
             echo 'export PHPBREW_PATH=' . ($buildName ? Config::getVersionBinPath($buildName) : '') . "\n";
         }
     }
     $this->logger->writeln('# Run this command to configure your shell:');
     $this->logger->writeln('# # eval "$(phpbrew env)"');
 }
コード例 #7
0
ファイル: SetupCommand.php プロジェクト: phpbrew/phpbrew
    protected function generateInitD($buildName, $fpmBin)
    {
        $root = Config::getRoot();
        $phpdir = "{$root}/php/{$buildName}";
        $pidFile = $phpdir . '/var/run/php-fpm.pid';
        $config = <<<EOS
#!/bin/sh
### BEGIN INIT INFO
# Provides:          phpbrew-fpm
# Required-Start:    \$remote_fs \$network
# Required-Stop:     \$remote_fs \$network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts phpbrew-fpm
# Description:       Starts The PHP FastCGI Process Manager Daemon
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHPBrew FastCGI Process Manager"
NAME=phpbrew-fpm
PHP_VERSION={$buildName}
PHPBREW_ROOT={$root}
CONFFILE={$phpdir}/etc/php-fpm.conf
DAEMON={$fpmBin}
DAEMON_ARGS="--daemonize --fpm-config \$CONFFILE --pid {$pidFile}"
PIDFILE={$pidFile}
TIMEOUT=30
SCRIPTNAME=/etc/init.d/\$NAME

# Exit if the package is not installed
[ -x "\$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/\$NAME ] && . /etc/default/\$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function to check the correctness of the config file
#
do_check()
{
    # FIXME
    # /usr/lib/php/phpbrew-fpm-checkconf || return 1
    return 0
}

#
# Function that starts the daemon/service
#
do_start()
{
\t# Return
\t#   0 if daemon has been started
\t#   1 if daemon was already running
\t#   2 if daemon could not be started
\tstart-stop-daemon --start --quiet --pidfile \$PIDFILE --exec \$DAEMON --test > /dev/null \\
\t\t|| return 1
\tstart-stop-daemon --start --quiet --pidfile \$PIDFILE --exec \$DAEMON -- \\
\t\t\$DAEMON_ARGS 2>/dev/null \\
\t\t|| return 2
\t# Add code here, if necessary, that waits for the process to be ready
\t# to handle requests from services started subsequently which depend
\t# on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
\t# Return
\t#   0 if daemon has been stopped
\t#   1 if daemon was already stopped
\t#   2 if daemon could not be stopped
\t#   other if a failure occurred
\tstart-stop-daemon --stop --quiet --retry=QUIT/\$TIMEOUT/TERM/5/KILL/5 --pidfile \$PIDFILE --name \$NAME
\tRETVAL="\$?"
\t[ "\$RETVAL" = 2 ] && return 2
\t# Wait for children to finish too if this is a daemon that forks
\t# and if the daemon is only ever run from this initscript.
\t# If the above conditions are not satisfied then add some other code
\t# that waits for the process to drop all resources that could be
\t# needed by services started subsequently.  A last resort is to
\t# sleep for some time.
\tstart-stop-daemon --stop --quiet --oknodo --retry=0/30/TERM/5/KILL/5 --exec \$DAEMON
\t[ "\$?" = 2 ] && return 2
\t# Many daemons don't delete their pidfiles when they exit.
\trm -f \$PIDFILE
\treturn "\$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
\t#
\t# If the daemon can reload its configuration without
\t# restarting (for example, when it is sent a SIGHUP),
\t# then implement that here.
\t#
\tstart-stop-daemon --stop --signal USR2 --quiet --pidfile \$PIDFILE --name \$NAME
\treturn 0
}

do_tmpfiles() {
    local type path mode user group

    [ "\$1" != no ] && V=-v

    TMPFILES=/usr/lib/tmpfiles.d/phpbrew-fpm.conf

    if [ -r "\$TMPFILES" ]; then
\twhile read type path mode user group age argument; do
\t    if [ "\$type" = "d" ]; then
\t\tmkdir \$V -p "\$path"
\t\tchmod \$V "\$mode" "\$path"
\t\tchown \$V "\$user:\$group" "\$path"
\t    fi
\tdone < "\$TMPFILES"
    fi
}

case "\$1" in
    start)
\tif init_is_upstart; then
\t    exit 1
\tfi
\t[ "\$VERBOSE" != no ] && log_daemon_msg "Starting \$DESC" "\$NAME"
\tdo_tmpfiles \$VERBOSE
\tdo_check \$VERBOSE
\tcase "\$?" in
\t    0)
\t\tdo_start
\t\tcase "\$?" in
\t\t    0|1) [ "\$VERBOSE" != no ] && log_end_msg 0 ;;
\t\t    2) [ "\$VERBOSE" != no ] && log_end_msg 1 ;;
\t\tesac
\t\t;;
\t    1) [ "\$VERBOSE" != no ] && log_end_msg 1 ;;
\tesac
\t;;
    stop)
\tif init_is_upstart; then
\t    exit 0
\tfi
\t[ "\$VERBOSE" != no ] && log_daemon_msg "Stopping \$DESC" "\$NAME"
\tdo_stop
\tcase "\$?" in
\t\t0|1) [ "\$VERBOSE" != no ] && log_end_msg 0 ;;
\t\t2) [ "\$VERBOSE" != no ] && log_end_msg 1 ;;
\tesac
\t;;
    status)
        status_of_proc "\$DAEMON" "\$NAME" && exit 0 || exit \$?
        ;;
    check)
        do_check yes
\t;;
    reload|force-reload)
\tif init_is_upstart; then
\t    exit 1
\tfi
    \tlog_daemon_msg "Reloading \$DESC" "\$NAME"
\tdo_reload
\tlog_end_msg \$?
\t;;
    reopen-logs)
\tlog_daemon_msg "Reopening \$DESC logs" \$NAME
\tif start-stop-daemon --stop --signal USR1 --oknodo --quiet \\
\t    --pidfile \$PIDFILE --exec \$DAEMON
\tthen
\t    log_end_msg 0
\telse
\t    log_end_msg 1
\tfi
\t;;
    restart)
\tif init_is_upstart; then
\t    exit 1
\tfi
\tlog_daemon_msg "Restarting \$DESC" "\$NAME"
\tdo_stop
\tcase "\$?" in
\t  0|1)
\t\tdo_start
\t\tcase "\$?" in
\t\t\t0) log_end_msg 0 ;;
\t\t\t1) log_end_msg 1 ;; # Old process is still running
\t\t\t*) log_end_msg 1 ;; # Failed to start
\t\tesac
\t\t;;
\t  *)
\t  \t# Failed to stop
\t\tlog_end_msg 1
\t\t;;
\tesac
\t;;
    *)
\techo "Usage: \$SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
\texit 1
    ;;
esac
:
EOS;
        return $config;
    }
コード例 #8
0
ファイル: InitCommand.php プロジェクト: phpbrew/phpbrew
    public function execute()
    {
        // $currentVersion;
        $root = $this->options->root ?: Config::getRoot();
        $home = Config::getHome();
        $buildDir = Config::getBuildDir();
        $buildPrefix = Config::getInstallPrefix();
        // $versionBuildPrefix = Config::getVersionInstallPrefix($version);
        // $versionBinPath     = Config::getVersionBinPath($version);
        $this->logger->info("Using root: {$root}");
        if (!file_exists($root)) {
            mkdir($root, 0755, true);
        }
        $paths = array();
        $paths[] = $home;
        $paths[] = $root;
        $paths[] = $root . DIRECTORY_SEPARATOR . 'register';
        $paths[] = $buildDir;
        $paths[] = $buildPrefix;
        foreach ($paths as $p) {
            $this->logger->debug("Checking directory {$p}");
            if (!file_exists($p)) {
                $this->logger->debug("Creating directory {$p}");
                mkdir($p, 0755, true);
            } else {
                $this->logger->debug("Directory {$p} is already created.");
            }
        }
        $this->logger->debug('Creating .metadata_never_index to prevent SpotLight indexing');
        $indexFiles = array($root . DIRECTORY_SEPARATOR . '.metadata_never_index', $home . DIRECTORY_SEPARATOR . '.metadata_never_index');
        foreach ($indexFiles as $indexFile) {
            if (!file_exists($indexFile)) {
                touch($indexFile);
                // prevent spotlight index here
            }
        }
        if ($configFile = $this->options->{'config'}) {
            if (!file_exists($configFile)) {
                return $this->logger->error("config file '{$configFile}' does not exist.");
            }
            $this->logger->debug("Using yaml config from '{$configFile}'");
            copy($configFile, $root . DIRECTORY_SEPARATOR . 'config.yaml');
        }
        $this->logger->writeln($this->formatter->format('Initialization successfully finished!', 'strong_green'));
        $this->logger->writeln($this->formatter->format('<=====================================================>', 'strong_white'));
        // write bashrc script to phpbrew home
        file_put_contents($home . '/bashrc', $this->getBashScriptPath());
        // write phpbrew.fish script to phpbrew home
        file_put_contents($home . '/phpbrew.fish', $this->getFishScriptPath());
        if (strpos(getenv('SHELL'), 'fish') !== false) {
            $initConfig = <<<EOS
Paste the following line(s) to the end of your ~/.config/fish/config.fish and start a
new shell, phpbrew should be up and fully functional from there:

    source {$home}/phpbrew.fish
EOS;
        } else {
            $initConfig = <<<EOS
Paste the following line(s) to the end of your ~/.bashrc and start a
new shell, phpbrew should be up and fully functional from there:

    source {$home}/bashrc

To enable PHP version info in your shell prompt, please set PHPBREW_SET_PROMPT=1
in your `~/.bashrc` before you source `~/.phpbrew/bashrc`

    export PHPBREW_SET_PROMPT=1

To enable .phpbrewrc file searching, please export the following variable:

    export PHPBREW_RC_ENABLE=1

EOS;
        }
        echo <<<EOS
Phpbrew environment is initialized, required directories are created under

    {$home}

{$initConfig}

For further instructions, simply run `phpbrew` to see the help message.

Enjoy phpbrew at \$HOME!!


EOS;
        $this->logger->writeln($this->formatter->format('<=====================================================>', 'strong_white'));
    }
コード例 #9
0
ファイル: RemoveTask.php プロジェクト: phpbrew/phpbrew
 public function removeByVersion($version, $verbose = false)
 {
     $home = Config::getRoot();
     $buildPrefix = Config::getVersionInstallPrefix($version);
     $this->remove($buildPrefix);
 }