Skip to content

Commit b01a0ec

Browse files
committed
Merge branch 'pr-218' into develop-new
2 parents b7fbdea + 27b3599 commit b01a0ec

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Patch.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class Patch implements \JsonSerializable
4141
*/
4242
public $depth;
4343

44+
/**
45+
* The package that provides the patch.
46+
*
47+
* @var \Composer\Package\PackageInterface $provider
48+
*/
49+
public $provider;
50+
4451
/**
4552
* Create a Patch from a serialized representation.
4653
*

src/Plugin/Patches.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ public function checkPatches(Event $event)
286286
}
287287
}
288288

289+
/**
290+
* Check whether a given path is relative.
291+
*
292+
* @param string $url
293+
* @return bool
294+
*/
295+
protected function isRelativeUrl($url) {
296+
if (parse_url($url, PHP_URL_SCHEME) != '') {
297+
return FALSE;
298+
}
299+
300+
if ($url[0] == '/') {
301+
return FALSE;
302+
}
303+
304+
return TRUE;
305+
}
306+
289307
/**
290308
* @param PackageEvent $event
291309
* @throws \Exception
@@ -327,6 +345,16 @@ public function postInstall(PackageEvent $event)
327345
null,
328346
new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $patch->url, $patch->description)
329347
);
348+
349+
if ($this->isRelativeUrl($patch->url) && !empty($patch->provider)) {
350+
if (!$manager->isPackageInstalled($localRepository, $patch->provider)) {
351+
$this->io->write(' - <info>Installing '.$patch->provider->getName().'</info> to ensure access to relative patches.');
352+
$manager->getInstaller($patch->provider->getType())->install($localRepository, $patch->provider);
353+
}
354+
$providing_install_path = $manager->getInstallPath($patch->provider);
355+
$patch->url = $providing_install_path.'/'.$patch->url;
356+
}
357+
330358
$this->getAndApplyPatch($downloader, $install_path, $patch->url);
331359
$this->eventDispatcher->dispatch(
332360
null,

src/Resolvers/DependencyPatches.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public function resolve(PatchCollection $collection, PackageEvent $event)
3434
$extra = $package->getExtra();
3535
if (isset($extra['patches'])) {
3636
$patches = $this->findPatchesInJson($extra['patches']);
37-
foreach ($patches as $package => $patch_list) {
37+
foreach ($patches as $patch_package => $patch_list) {
3838
foreach ($patch_list as $patch) {
39+
$patch->provider = $package;
3940
$collection->addPatch($patch);
4041
}
4142
}

0 commit comments

Comments
 (0)