Skip to content

Commit

Permalink
[Common] Composer Autoload Scripts When All of PHPGenesis is Present (#…
Browse files Browse the repository at this point in the history
…21)

Co-authored-by: onairmarc <[email protected]>
  • Loading branch information
onairmarc and onairmarc authored Aug 21, 2024
1 parent 032b6b8 commit d0f6e8e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ eb2793b4c08a4aae2ff7cefc61c336778a33d6a8
0c213c750e950f6e9ee4e8f2632ec41ac29a70e0
f4e014138ae1c12a4f8a7f9778535ccb7bf1c440
8e8e706c5f9ccd0aff6641ccac231dc12088af02
7e9c40547e404268d95e36e6b2ba197ae86a60bd
19 changes: 17 additions & 2 deletions src/Common/phpgenesis_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@
*/

if (!function_exists('phpgenesis_vendor_dir')) {
function phpgenesis_vendor_dir(?string $path = null): string
function phpgenesis_vendor_dir(?string $path = null, bool $usingPhpGenesis = false): string
{
if ($usingPhpGenesis) {
if ($path == null) {
return __DIR__ . '/../../';
}

return __DIR__ . '/../../' . $path;
}

return phpgenesis_module_vendor_dir($path);
}
}

if (!function_exists('phpgenesis_module_vendor_dir')) {
function phpgenesis_module_vendor_dir(?string $path = null): string
{
if ($path == null) {
return __DIR__ . '/../';
Expand All @@ -24,4 +39,4 @@ function phpgenesis_common_src(?string $path = null): string

return __DIR__ . '/src/' . $path;
}
}
}
26 changes: 21 additions & 5 deletions src/Common/src/Composer/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ public static function postAutoloadDump(Event $event): void
$packageName = $event->getComposer()->getPackage()->getName();

$isPhpGenesis = false;
$usingPhpGenesis = false;

if ($packageName == 'phpgenesis/phpgenesis') {
$isPhpGenesis = true;
echo 'Package is PHPGenesis Monorepo. Modifying IdeHelper::updateEditorConfig() behavior' . PHP_EOL;
}
$composer = file_get_contents('composer.json');

if (is_string($composer)) {
$composer = json_decode($composer);

$requires = $composer->require;

IdeHelper::updateEditorConfig($isPhpGenesis);
foreach ($requires as $package => $version) {
if ($package == 'phpgenesis/phpgenesis') {
$usingPhpGenesis = true;
break;
}
}

if ($packageName == 'phpgenesis/phpgenesis') {
$isPhpGenesis = true;
echo 'Package is PHPGenesis Monorepo. Modifying IdeHelper::updateEditorConfig() behavior' . PHP_EOL;
}

IdeHelper::updateEditorConfig($isPhpGenesis, $usingPhpGenesis);
}
}
}
10 changes: 7 additions & 3 deletions src/Common/src/Helpers/IdeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

class IdeHelper
{
public static function updateEditorConfig(bool $isPhpGenesis): void
private const string EDITOR_CONFIG_PATH = 'Resources/.editorconfig';

public static function updateEditorConfig(bool $isPhpGenesis, bool $usingPhpGenesis = false): void
{
if ($isPhpGenesis) {
file_copy(phpgenesis_common_src('Resources/.editorconfig'), phpgenesis_common_src('../../../.editorconfig'));
file_copy(phpgenesis_common_src(self::EDITOR_CONFIG_PATH), phpgenesis_common_src('../../../.editorconfig'));
} elseif ($usingPhpGenesis) {
file_copy(phpgenesis_common_src(self::EDITOR_CONFIG_PATH), phpgenesis_vendor_dir('../../../.editorconfig', $usingPhpGenesis));
} else {
file_copy(phpgenesis_common_src('Resources/.editorconfig'), phpgenesis_vendor_dir('../../.editorconfig'));
file_copy(phpgenesis_common_src(self::EDITOR_CONFIG_PATH), phpgenesis_vendor_dir('../../.editorconfig', $usingPhpGenesis));
}

}
Expand Down

0 comments on commit d0f6e8e

Please sign in to comment.