Example #1
0
 public function __construct(Silex\Application $app, $packageRepo = null)
 {
     // Needed (for now) to log errors to the bolt_log table.
     $this->app = $app;
     $this->basedir = $app['resources']->getPath('extensions');
     $this->packageRepo = $packageRepo;
     $this->packageFile = $app['resources']->getPath('root') . '/extensions/composer.json';
     umask(00);
     putenv("COMPOSER_HOME=" . $app['resources']->getPath('cache') . '/composer');
     $this->wrapper = \evidev\composer\Wrapper::create();
     if (!is_file($this->packageFile)) {
         $this->execute('init');
     }
     if (is_file($this->packageFile) && !is_writable($this->packageFile)) {
         $this->messages[] = sprintf("The file '%s' is not writable. You will not be able to use this feature without changing the permissions.", $this->packageFile);
     }
     $this->execute('config repositories.bolt composer ' . $app['extend.site'] . 'satis/');
     $json = json_decode(file_get_contents($this->packageFile));
     $json->repositories->packagist = false;
     $basePackage = "bolt/bolt";
     $json->provide = new \stdClass();
     $json->provide->{$basePackage} = $app['bolt_version'];
     $json->scripts = array('post-package-install' => "Bolt\\Composer\\ScriptHandler::extensions", 'post-package-update' => "Bolt\\Composer\\ScriptHandler::extensions");
     $pathToWeb = $app['resources']->findRelativePath($this->app['resources']->getPath('extensions'), $this->app['resources']->getPath('web'));
     $json->extra = array('bolt-web-path' => $pathToWeb);
     file_put_contents($this->packageFile, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     try {
         $json = json_decode(file_get_contents($this->packageRepo));
         $this->available = $json->packages;
     } catch (\Exception $e) {
         $this->messages[] = sprintf($app['translator']->trans("The Bolt extensions Repo at %s is currently unavailable. Check your connection and try again shortly."), $this->packageRepo);
         $this->available = array();
     }
 }
 /**
  * @see https://github.com/eviweb/composer-wrapper/issues/7
  */
 public function testSelfupdateFixMustAlterHostScriptReferenceOnlyTemporarily()
 {
     $argv0 = $_SERVER['argv'][0];
     Wrapper::create(dirname($this->files['composer']))->run('self-update');
     $this->assertEquals($argv0, $_SERVER['argv'][0]);
 }
 /**
  * @covers \evidev\composer\Wrapper::run
  */
 public function testCLIRun()
 {
     $_SERVER['argv'][] = '-V';
     $file = static::$files['stream'];
     $cw = Wrapper::create();
     $rs = fopen($file, 'w', false);
     $stream = new \Symfony\Component\Console\Output\StreamOutput($rs);
     $this->assertEquals(0, $cw->run("", $stream));
     fclose($rs);
     $this->assertTrue((bool) preg_match('/^Composer version/', file_get_contents($file)));
 }