Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0653ab5

Browse files
committed
add packages path resolution to Composer helper
1 parent 118eb5c commit 0653ab5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Builder/Concerns/CopiesCertificateAuthority.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace Native\Desktop\Builder\Concerns;
44

5-
use Composer\InstalledVersions;
6-
use Symfony\Component\Filesystem\Path;
5+
use Native\Desktop\Support\Composer;
76

87
use function Laravel\Prompts\error;
98
use function Laravel\Prompts\warning;
@@ -15,11 +14,7 @@ abstract public function buildPath(string $path = ''): string;
1514
public function copyCertificateAuthority(string $path): void
1615
{
1716
try {
18-
$vendorDirectory = realpath(InstalledVersions::getRootPackage()['install_path'].'/vendor');
19-
$phpBinaryDirectory = $vendorDirectory.'/nativephp/php-bin/';
20-
21-
$certificateFileName = 'cacert.pem';
22-
$certFilePath = Path::join($phpBinaryDirectory, $certificateFileName);
17+
$certFilePath = Composer::phpPackagePath('cacert.pem');
2318

2419
if (! file_exists($certFilePath)) {
2520
warning('CA Certificate not found at '.$certFilePath.'. Skipping copy.');
@@ -29,7 +24,7 @@ public function copyCertificateAuthority(string $path): void
2924

3025
$copied = copy(
3126
$certFilePath,
32-
"{$path}/{$certificateFileName}"
27+
"{$path}/cacert.pem"
3328
);
3429

3530
if (! $copied) {

src/Support/Composer.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22

33
namespace Native\Desktop\Support;
44

5+
use Composer\InstalledVersions;
56
use RuntimeException;
7+
use Symfony\Component\Filesystem\Path;
68

79
use function Laravel\Prompts\note;
810

911
class Composer
1012
{
13+
public static function desktopPackagePath(string $path = '')
14+
{
15+
return self::vendorPath("nativephp/desktop/{$path}");
16+
}
17+
18+
public static function phpPackagePath(string $path = '')
19+
{
20+
return self::vendorPath("nativephp/php-bin/{$path}");
21+
}
22+
23+
public static function vendorPath(string $path = '')
24+
{
25+
$vendorPath = realpath(InstalledVersions::getRootPackage()['install_path'].'/vendor');
26+
27+
return Path::join($vendorPath, $path);
28+
}
29+
1130
public static function installScripts()
1231
{
1332
$composer = json_decode(file_get_contents(base_path('composer.json')));

0 commit comments

Comments
 (0)