forked from jamescowie/composer-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jamescowie#7 from nevvermind/shell-patching
Shell patching
- Loading branch information
Showing
8 changed files
with
500 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Inviqa; | ||
use Inviqa\Patch\Factory; | ||
use Inviqa\Patch\Shell; | ||
|
||
/** | ||
* Checks the validity of the environment before applying the patches. | ||
*/ | ||
class EnvChecker | ||
{ | ||
private $event; | ||
|
||
public function __construct(\Composer\Script\Event $event) | ||
{ | ||
$this->event = $event; | ||
} | ||
|
||
public function check() | ||
{ | ||
$this->clientDeclaredMageRootOnShellPatches(); | ||
} | ||
|
||
private function clientDeclaredMageRootOnShellPatches() | ||
{ | ||
$extra = $this->event->getComposer()->getPackage()->getExtra(); | ||
|
||
if (empty($extra['patches'])) { | ||
return; | ||
} | ||
|
||
$containsShellPatches = false; | ||
|
||
foreach ($extra['patches'] as $patchGroupName => $patchGroup) { | ||
foreach ($patchGroup as $patchName => $patchDetails) { | ||
$patch = Factory::create( | ||
$patchName, | ||
$patchGroupName, | ||
$patchDetails, | ||
array() | ||
); | ||
|
||
if ($patch instanceof Shell) { | ||
$containsShellPatches = true; | ||
break 2; | ||
} | ||
} | ||
} | ||
|
||
if ($containsShellPatches && empty($extra[Patcher::EXTRA_KEY_MAGE_ROOT_DIR])) { | ||
throw new \Exception( | ||
'When using shell patches, you must declare the Mage root using the extra key: ' . | ||
Patcher::EXTRA_KEY_MAGE_ROOT_DIR | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Inviqa\Patch; | ||
|
||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Process\ProcessUtils; | ||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
|
||
class DotPatch extends Patch | ||
{ | ||
const TYPE = 'patch'; | ||
|
||
/** | ||
* @throws ProcessFailedException | ||
* @return boolean | ||
*/ | ||
protected function doApply() | ||
{ | ||
$patchPath = ProcessUtils::escapeArgument($this->getPatchTemporaryPath()); | ||
$process = new Process("patch -p 1 < $patchPath"); | ||
$process->mustRun(); | ||
return $process->getExitCode() === 0; | ||
} | ||
|
||
protected function canApply() | ||
{ | ||
$patchPath = ProcessUtils::escapeArgument($this->getPatchTemporaryPath()); | ||
$process = new Process("patch --dry-run -p 1 < $patchPath"); | ||
try { | ||
$process->mustRun(); | ||
return $process->getExitCode() === 0; | ||
} catch (\Exception $e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Inviqa\Patch; | ||
|
||
class Factory | ||
{ | ||
/** | ||
* @param string $patchName | ||
* @param string $patchGroup | ||
* @param array $patchDetails | ||
* @param array $composerExtra | ||
* @return Patch | ||
*/ | ||
public static function create($patchName, $patchGroup, array $patchDetails, array $composerExtra) | ||
{ | ||
if (empty($patchDetails['type'])) { | ||
$patchDetails['type'] = DotPatch::TYPE; | ||
} | ||
|
||
$type = $patchDetails['type'] === DotPatch::TYPE ? 'DotPatch' : 'Shell'; | ||
$patchClass = '\\Inviqa\\Patch\\' . $type; | ||
|
||
$patch = new $patchClass($patchName, $patchGroup, $patchDetails, $composerExtra); | ||
|
||
return $patch; | ||
} | ||
} |
Oops, something went wrong.