Example #1
0
 public function execute()
 {
     $root = Config::getPhpbrewRoot();
     $php = Config::getCurrentPhpName();
     $file = "{$root}/php/{$php}/etc/php.ini";
     Utils::editor($file);
 }
Example #2
0
 public function execute()
 {
     $args = func_get_args();
     // $currentVersion;
     $root = Config::getPhpbrewRoot();
     $home = Config::getPhpbrewHome();
     $buildDir = Config::getBuildDir();
     $version = getenv('PHPBREW_PHP');
     // XXX: get source dir from current build information
     $sourceDir = $buildDir . DIRECTORY_SEPARATOR . $version;
     $this->logger->info($sourceDir);
     $cmd = new CommandBuilder('ctags');
     $cmd->arg('--recurse');
     $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->info($cmd->__toString());
     $cmd->execute();
     $this->logger->info("Done");
 }
Example #3
0
 public function execute($version = null)
 {
     // get current version
     if (!$version) {
         $version = getenv('PHPBREW_PHP');
     }
     // $currentVersion;
     $root = Config::getPhpbrewRoot();
     $home = Config::getPhpbrewHome();
     $lookup = getenv('PHPBREW_LOOKUP_PREFIX');
     // $versionBuildPrefix = Config::getVersionBuildPrefix($version);
     // $versionBinPath     = Config::getVersionBinPath($version);
     echo "export PHPBREW_ROOT={$root}\n";
     echo "export PHPBREW_HOME={$home}\n";
     echo "export PHPBREW_LOOKUP_PREFIX={$lookup}\n";
     if ($version !== false) {
         // checking php version exists
         $version = Utils::findLatestPhpVersion($version);
         $targetPhpBinPath = Config::getVersionBinPath($version);
         if (!is_dir($targetPhpBinPath)) {
             throw new Exception("# php version: " . $version . " not exists.");
         }
         echo 'export PHPBREW_PHP=' . $version . "\n";
         echo 'export PHPBREW_PATH=' . ($version ? Config::getVersionBinPath($version) : '') . "\n";
     }
 }
Example #4
0
 public function __construct()
 {
     $this->root = Config::getPhpbrewRoot();
     $this->baseDir = $this->root . DIRECTORY_SEPARATOR . 'register';
     if (!file_exists($this->baseDir)) {
         mkdir($this->baseDir, 0755, true);
     }
 }
Example #5
0
 public static function runUse($version)
 {
     putenv("PHPBREW_BIN=" . Config::getPhpbrewHome() . '/bin');
     putenv("PHPBREW_HOME=" . Config::getPhpbrewHome());
     putenv("PHPBREW_LOOKUP_PREFIX=/usr/local/Cellar:/usr/local");
     putenv("PHPBREW_PATH=" . Config::getPhpbrewHome() . "/php/php-{$version}/bin");
     putenv("PHPBREW_PHP=php-{$version}");
     putenv("PHPBREW_ROOT=" . Config::getPhpbrewRoot());
     putenv('PATH=' . getenv('PHPBREW_PATH') . ':' . self::getCleanPath());
 }
Example #6
0
 public function execute($buildName)
 {
     // this block is important for tests only
     $root = Config::getPhpbrewRoot();
     $home = Config::getPhpbrewHome();
     putenv("PHPBREW_ROOT={$root}");
     putenv("PHPBREW_HOME={$home}");
     putenv("PHPBREW_PHP={$buildName}");
     putenv("PHPBREW_PATH={$root}/{$buildName}/bin");
     putenv("PHPBREW_BIN={$home}/bin");
     $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.");
 }
Example #7
0
    public function execute()
    {
        // $currentVersion;
        $root = Config::getPhpbrewRoot();
        $home = Config::getPhpbrewHome();
        $buildDir = Config::getBuildDir();
        $buildPrefix = Config::getBuildPrefix();
        // $versionBuildPrefix = Config::getVersionBuildPrefix($version);
        // $versionBinPath     = Config::getVersionBinPath($version);
        if (!file_exists($root)) {
            mkdir($root, 0755, true);
        }
        touch($root . DIRECTORY_SEPARATOR . '.metadata_never_index');
        // prevent spotlight index here
        if ($root != $home) {
            touch($home . DIRECTORY_SEPARATOR . '.metadata_never_index');
        }
        if ($this->options->{'config'} !== null) {
            copy($this->options->{'config'}, $root . DIRECTORY_SEPARATOR . 'config.yaml');
        }
        if (!file_exists($home)) {
            mkdir($home, 0755, true);
        }
        if (!file_exists($buildPrefix)) {
            mkdir($buildPrefix, 0755, true);
        }
        if (!file_exists($buildDir)) {
            mkdir($buildDir, 0755, true);
        }
        // write bashrc script to phpbrew home
        file_put_contents($home . '/bashrc', $this->getBashScript());
        echo <<<EOS
Phpbrew environment is initialized, required directories are created under

    {$home}

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

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

Enjoy phpbrew at \$HOME!!

EOS;
    }
Example #8
0
 public function prepareForVersion($version)
 {
     $home = Config::getPhpbrewRoot();
     $buildDir = Config::getBuildDir();
     $variantsDir = Config::getVariantsDir();
     $buildPrefix = Config::getVersionBuildPrefix($version);
     if (!file_exists($variantsDir)) {
         mkdir($variantsDir, 0755, true);
     }
     if (!file_exists($buildDir)) {
         mkdir($buildDir, 0755, true);
     }
     if (!file_exists($buildPrefix)) {
         mkdir($buildPrefix, 0755, true);
     }
 }
 public function run(Build $build = NULL)
 {
     $dirs = array();
     $dirs[] = Config::getPhpbrewRoot();
     $dirs[] = Config::getPhpbrewHome();
     $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);
         }
     }
 }
Example #10
0
 public function execute($appName)
 {
     $apps = AppStore::all();
     if (!isset($apps[$appName])) {
         throw new Exception("App {$appName} not found.");
     }
     $app = $apps[$appName];
     $targetDir = Config::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'bin';
     $target = $targetDir . DIRECTORY_SEPARATOR . $app['as'];
     $downloader = new UrlDownloader($this->logger, $this->options);
     $downloader->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}");
 }
Example #11
0
 public function execute($name)
 {
     switch ($name) {
         case 'home':
             echo Config::getPhpbrewRoot();
             break;
         case 'build':
             echo Config::getBuildDir();
             break;
         case 'bin':
             echo Config::getCurrentPhpBin();
             break;
         case 'include':
             echo Config::getVersionBuildPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'include';
             break;
         case 'etc':
             echo Config::getVersionBuildPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'etc';
             break;
     }
 }
Example #12
0
 public function execute($buildName = NULL)
 {
     // get current version
     if (!$buildName) {
         $buildName = getenv('PHPBREW_PHP');
     }
     // $currentVersion;
     $root = Config::getPhpbrewRoot();
     $home = Config::getPhpbrewHome();
     $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";
         }
     }
 }
Example #13
0
 public function execute($name)
 {
     switch ($name) {
         case 'root':
             echo Config::getPhpbrewRoot();
             break;
         case 'home':
             echo Config::getPhpbrewHome();
             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;
     }
 }
Example #14
0
 public function execute($versionName = NULL)
 {
     $args = func_get_args();
     array_shift($args);
     // $currentVersion;
     $root = Config::getPhpbrewRoot();
     $home = Config::getPhpbrewHome();
     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('--recurse');
     $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");
 }
Example #15
0
 public static function putPathEnvFor($buildName)
 {
     $root = Config::getPhpbrewRoot();
     $buildDir = $root . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . $buildName;
     // re-build path
     $paths = explode(':', getenv('PATH'));
     $paths = array_filter($paths, function ($p) use($root) {
         return strpos($p, $root) === False;
     });
     array_unshift($paths, $buildDir . DIRECTORY_SEPARATOR . 'bin');
     putenv('PATH=' . join(':', $paths));
 }
Example #16
0
    public function execute()
    {
        // $currentVersion;
        $root = Config::getPhpbrewRoot();
        $home = Config::getPhpbrewHome();
        $buildDir = Config::getBuildDir();
        $buildPrefix = Config::getInstallPrefix();
        // $versionBuildPrefix = Config::getVersionInstallPrefix($version);
        // $versionBinPath     = Config::getVersionBinPath($version);
        if (!file_exists($root)) {
            mkdir($root, 0755, true);
        }
        $paths = array();
        $paths[] = $home;
        $paths[] = $root;
        $paths[] = $buildDir;
        $paths[] = $buildPrefix;
        foreach ($paths as $p) {
            $this->logger->info("Checking directory {$p}");
            if (!file_exists($p)) {
                $this->logger->info("Creating directory {$p}");
                mkdir($p, 0755, true);
            }
        }
        $this->logger->info('Creating .metadata_never_index to prevent SpotLight indexing');
        touch($root . DIRECTORY_SEPARATOR . '.metadata_never_index');
        // prevent spotlight index here
        touch($home . DIRECTORY_SEPARATOR . '.metadata_never_index');
        if ($configFile = $this->options->{'config'}) {
            if (!file_exists($configFile)) {
                return $this->logger->error("{$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->getBashScript());
        // write phpbrew.fish script to phpbrew home
        file_put_contents($home . '/phpbrew.fish', $this->getFishScript());
        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
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'));
    }
Example #17
0
 public function configure(Build $build, $options)
 {
     $root = Config::getPhpbrewRoot();
     $buildDir = Config::getBuildDir();
     $variantBuilder = new VariantBuilder();
     $extra = $build->getExtraOptions();
     if (!file_exists('configure')) {
         $this->debug("configure file not found, running buildconf script...");
         system('./buildconf') !== false or die('buildconf error');
     }
     $prefix = $build->getInstallPrefix();
     // append cflags
     if ($this->optimizationLevel) {
         $o = $this->optimizationLevel;
         $cflags = getenv('CFLAGS');
         putenv("CFLAGS={$cflags} -O{$o}");
         $_ENV['CFLAGS'] = "{$cflags} -O{$o}";
     }
     $args = array();
     $args[] = "--prefix=" . $prefix;
     $args[] = "--with-config-file-path={$prefix}/etc";
     $args[] = "--with-config-file-scan-dir={$prefix}/var/db";
     $args[] = "--with-pear={$prefix}/lib/php";
     $variantOptions = $variantBuilder->build($build);
     if ($variantOptions) {
         $args = array_merge($args, $variantOptions);
     }
     $this->debug('Enabled variants: ' . join(', ', array_keys($build->getVariants())));
     $this->debug('Disabled variants: ' . join(', ', array_keys($build->getDisabledVariants())));
     foreach ((array) $options->patch as $patchPath) {
         // copy patch file to here
         $this->info("===> Applying patch file from {$patchPath} ...");
         // Search for strip parameter
         for ($i = 0; $i <= 16; $i++) {
             ob_start();
             system("patch -p{$i} --dry-run < {$patchPath}", $return);
             ob_clean();
             if ($return === 0) {
                 system("patch -p{$i} < {$patchPath}");
                 break;
             }
         }
     }
     // let's apply patch for libphp{php version}.so (apxs)
     if ($build->isEnabledVariant('apxs2')) {
         $apxs2Checker = new \PhpBrew\Tasks\Apxs2CheckTask($this->logger);
         $apxs2Checker->check($build, $options);
         $apxs2Patch = new \PhpBrew\Tasks\Apxs2PatchTask($this->logger);
         $apxs2Patch->patch($build, $options);
     }
     foreach ($extra as $a) {
         $args[] = $a;
     }
     $cmd = new CommandBuilder('./configure');
     $cmd->args($args);
     $this->info("===> Configuring {$build->version}...");
     $cmd->append = false;
     $cmd->stdout = Config::getVersionBuildLogPath($build->name);
     echo "\n\n";
     echo "Use tail command to see what's going on:\n";
     echo "   \$ tail -f {$cmd->stdout}\n\n\n";
     $this->debug($cmd->getCommand());
     if ($options->nice) {
         $cmd->nice($options->nice);
     }
     if (!$options->dryrun) {
         $cmd->execute() !== false or die('Configure failed.');
     }
     $patch64bit = new \PhpBrew\Tasks\Patch64BitSupportTask($this->logger, $options);
     $patch64bit->patch($build, $options);
 }
Example #18
0
 public function removeByVersion($version, $verbose = false)
 {
     $home = Config::getPhpbrewRoot();
     $buildPrefix = Config::getVersionBuildPrefix($version);
     $this->remove($buildPrefix);
 }
Example #19
0
 public function __construct()
 {
     $this->root = Config::getPhpbrewRoot();
     $this->baseDir = $this->root . DIRECTORY_SEPARATOR . 'register';
 }
Example #20
0
 public function cleanByVersion($version, $verbose = false)
 {
     $home = Config::getPhpbrewRoot();
     $buildPrefix = Config::getVersionBuildPrefix($version);
     return $this->clean($buildPrefix);
 }