Skip to content

Instantly share code, notes, and snippets.

@thomascube
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomascube/9495566 to your computer and use it in GitHub Desktop.
Save thomascube/9495566 to your computer and use it in GitHub Desktop.
Patches and additions for creating a PHP Composer RPM module from source
<?php
/*
* Minimal autoloader configuration to load Composer dependencies
* from distribution package locations.
*
* (c) Thomas Bruederli <bruederli@kolabsys.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$srcDir = __DIR__;
$pearDir = '/usr/local/php5/lib/php';
$libDir = '/usr/share/php';
require $srcDir . '/Composer/Autoload/ClassLoader.php';
# configure a minimal autoloader for Composer classes
$loader = new Composer\Autoload\ClassLoader();
$loader->setUseIncludePath(true);
$loader->set('Composer', array($srcDir));
$loader->set('JsonSchema', array($libDir));
$loader->set('Seld\\JsonLint', array($libDir));
$loader->set('Symfony\\Component\\Finder\\', array($pearDir));
$loader->set('Symfony\\Component\\Process\\', array($pearDir));
$loader->set('Symfony\\Component\\Console\\', array($pearDir));
$loader->register();
diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php
index 41c30d6..72ae343 100644
--- a/src/Composer/Compiler.php
+++ b/src/Composer/Compiler.php
@@ -85,31 +85,7 @@ class Compiler
foreach ($finder as $file) {
$this->addFile($phar, $file, false);
}
- $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../src/Composer/IO/hiddeninput.exe'), false);
- $finder = new Finder();
- $finder->files()
- ->ignoreVCS(true)
- ->name('*.php')
- ->exclude('Tests')
- ->in(__DIR__.'/../../vendor/symfony/')
- ->in(__DIR__.'/../../vendor/seld/jsonlint/src/')
- ->in(__DIR__.'/../../vendor/justinrainbow/json-schema/src/')
- ;
-
- foreach ($finder as $file) {
- $this->addFile($phar, $file);
- }
-
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload.php'));
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_namespaces.php'));
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_psr4.php'));
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_classmap.php'));
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_real.php'));
- if (file_exists(__DIR__.'/../../vendor/composer/include_paths.php')) {
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/include_paths.php'));
- }
- $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/ClassLoader.php'));
$this->addComposerBin($phar);
// Stubs
diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php
index 4e2fa14..8f7b61e 100644
--- a/src/Composer/Console/Application.php
+++ b/src/Composer/Console/Application.php
@@ -246,10 +246,7 @@ class Application extends BaseApplication
$commands[] = new Command\ClearCacheCommand();
$commands[] = new Command\RemoveCommand();
$commands[] = new Command\HomeCommand();
-
- if ('phar:' === substr(__FILE__, 0, 5)) {
- $commands[] = new Command\SelfUpdateCommand();
- }
+ $commands[] = new Command\RegisterCommand();
return $commands;
}
<?php
/*
* This file is part of Composer.
*
* (c) Thomas Bruederli <bruederli@kolabsys.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Command;
use Composer\Json;
use Composer\Factory;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @author Thomas Bruederli <bruederli@kolabsys.com>
*/
class RegisterCommand extends Command
{
protected function configure()
{
$this
->setName('register')
->setDescription('Registers a distribution packages to to the local installation registry')
->setDefinition(array(
new InputArgument('path', InputArgument::REQUIRED, 'Path to module\'s composer.json file, e.g. vendor/foo/bar/composer.json'),
new InputArgument('version', InputArgument::OPTIONAL, 'Version of the registered package e.g "1.0.0" or "dev-master"'),
))
->setHelp(<<<EOT
Registers the given composer module to the local installation registry
in order to let composer build autoloader files for installed modules.
EOT
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer(true);
$config = $composer->getConfig();
$modfile = $input->getArgument('path');
$version = $input->getArgument('version');
if (empty($version)) {
$version = "dev-master";
}
if (!file_exists($modfile)) {
$output->writeln("<error>$modfile not found.</error>");
return 1;
}
try {
$instfile = new Json\JsonFile($config->get('vendor-dir') . '/composer/installed.json');
$installed = $instfile->read();
}
catch (Exception $e) {
$installed = array();
}
$io = $this->getIO();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'register', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
try {
$j = new Json\JsonFile($modfile);
$modconf = $j->read();
}
catch (Exception $e) {
$output->writeln("<error>Failed to load module composer file: $modfile</error>");
return 1;
}
$modname = $modconf['name'];
$modconf['version'] = $version;
$modconf['version_normalized'] = $version;
foreach ($installed as $i => $m) {
if ($m['name'] == $modname) {
$output->writeln('<info> replacing ' . $m['name'] . ':' . $m['version'] . '</info>');
unset($installed[$i]);
break;
}
}
$output->writeln('<info> adding ' . $modname . ':' . $version . '</info>');
$installed[] = $modconf;
try {
$instfile->write(array_values($installed));
}
catch (Exception $e) {
$output->writeln("<error>Failed to write vendor/composer/installed.json</error>");
return 1;
}
//// add module to the composer.json registry, really?
try {
$regfile = new Json\JsonFile(Factory::getComposerFile());
$composer = $regfile->read();
}
catch (Exception $e) {
$composer = array();
}
$composer['require'][$modname] = $version;
try {
$regfile->write($composer);
$output->writeln('<info>composer.json has been updated</info>');
}
catch (Exception $e) {
$output->writeln("<error>Failed to write composer.json</error>");
return 1;
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment