Skip to content

Commit

Permalink
Merge pull request jamescowie#5 from nevvermind/use-method-invoke-script
Browse files Browse the repository at this point in the history
Use script callbacks instead of system commands to access config and disregard bin path
  • Loading branch information
James Cowie committed May 7, 2015
2 parents cbc0b6a + 176fe77 commit 5d693ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 58 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,19 @@ a) Patches need to be declared in the `extra` config area of Composer (root pack
}
```

b) Additional scripts need to be added for automatic patching on `install` or `update` (root package only):
b) Additional scripts callbacks need to be added for automatic patching on `install` or `update` (root package only):
```json
"scripts": {
"post-install-cmd": [
"php bin/autoloader-patcher"
"Inviqa\\Command::patch"
],
"post-update-cmd": [
"php bin/autoloader-patcher"
"Inviqa\\Command::patch"
]
}
```
Theoretically, you can use whatever [Composer event](https://getcomposer.org/doc/articles/scripts.md#event-names) you want,
or even [trigger the events manually](https://getcomposer.org/doc/articles/scripts.md#running-scripts-manually).
You can use whatever [Composer *Command* event](https://getcomposer.org/doc/articles/scripts.md#event-names) you want,
or even [trigger the events manually](https://getcomposer.org/doc/articles/scripts.md#running-scripts-manually).
Again, note that only *Command events* are supported. Please check the above link to see which ones are they.

c) explicitly setting the bin dir at the root level (root package only):
```json
"config": {
"bin-dir": "bin"
}
```

d) the `patch` tool must be available
c) the `patch` tool must be available
23 changes: 0 additions & 23 deletions bin/composer-patcher

This file was deleted.

15 changes: 1 addition & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@
}
],
"require": {
"eloquent/composer-config-reader": "2.*",
"symfony/console": "2.6.*",
"symfony/process": "*"
},
"autoload": {
"psr-0": {
"Inviqa\\": "src/"
}
},
"extra": {
"patches": {
"magento": {
"autoloader-patch": {
"name": "Autoloader-patcher",
"title": "Allow composer autoloader to be applied to Mage.php",
"url": "https://raw.githubusercontent.com/inviqa/magento-patches/magento-composer-autoloader-patch/composer-autoloader/0001-Adding-Composer-autoloader-to-Mage.patch?token=AA3sXKf7NEkV25PjHZcpYlQOsUezdD7Rks5VUkqNwA%3D%3D"
}
}
}
},
"bin": ["bin/composer-patcher"]
}
}
23 changes: 23 additions & 0 deletions src/Inviqa/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Inviqa;

class Command
{
/**
* Mehotd used as Composer script callback.
* E.g. { "scripts": { "post-update-cmd": "Inviqa\\Command::patch" } }
*
* The \Composer\Script\Event type is accessible only for Composer's "Command Events".
* These are the only events when the "Composer" object (hence its package config)
* is available.
*
* @link https://getcomposer.org/doc/articles/scripts.md#event-names
* @param \Composer\Script\Event $event
*/
public static function patch(\Composer\Script\Event $event)
{
$patcher = new Patcher;
$patcher->patch($event);
}
}
13 changes: 5 additions & 8 deletions src/Inviqa/Patcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ class Patcher
/** @var ConsoleOutput */
private $output;

public function patchMage()
public function patch(\Composer\Script\Event $event)
{
$this->output = new ConsoleOutput();

$reader = new \Eloquent\Composer\Configuration\ConfigurationReader;
$configuration = $reader->read('composer.json');
$extra = $event->getComposer()->getPackage()->getExtra();

foreach ($configuration->extra()->patches->magento as $option) {
$options = json_decode(json_encode($option), true);
$this->output->writeln("<info>Downloading patch: " . $options['name'] . "</info>");
foreach ($extra['patches']['magento'] as $option) {
$this->output->writeln("<info>Downloading patch: " . $option['name'] . "</info>");
$downloader = new composerDownloader();
$this->patchFiles[] = $downloader->getContents($options['url'], $options['name']);
$this->patchFiles[] = $downloader->getContents($option['url'], $option['name']);
}

//var_dump($this->patchFiles);
$this->applyPatch();
}

Expand Down

0 comments on commit 5d693ca

Please sign in to comment.