Skip to content

Adding composer_bin_dir path expander#2753

Merged
dantleech merged 3 commits intophpactor:masterfrom
mamazu:phpactor-2749
Oct 11, 2024
Merged

Adding composer_bin_dir path expander#2753
dantleech merged 3 commits intophpactor:masterfrom
mamazu:phpactor-2749

Conversation

@mamazu
Copy link
Contributor

@mamazu mamazu commented Oct 3, 2024

However, when I run phpactor locally with this enabled it doesn't load anymore. It's stuck in some kind of cycle of allocating stuff (at least that's what I can tell from the strace).

And when trying to debug it with xdebug it freezes on a proc_close call.

Closes #2749

@mamazu mamazu changed the title Adding composer_bin_dir path expander Adding composer_bin_dir path expander Oct 3, 2024
@mamazu mamazu force-pushed the phpactor-2749 branch 3 times, most recently from 70db756 to 937396b Compare October 3, 2024 15:18
@mamazu
Copy link
Contributor Author

mamazu commented Oct 7, 2024

Found the problem, you can't have a service tagged as a value expander and depend a service that resolves paths. But I don't know how to solve that.

}

private function readFile(): void
public function getBinDir(): string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can rename to binDir

{
if ($this->loaded) {
if ($this->loaded || !file_exists($this->lockFile) || !file_exists($this->composerFile)) {
$this->loaded = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both files are now optional...

Copy link
Contributor Author

@mamazu mamazu Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, before the lock file was optional before and I don't know if you don't use composer in your project this inspector shouldn't crash.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you could have a JSON file but not a lock file or vice versa potentially but this requires thatbyiu have both. We should allow it to work with only a JSON file

@dantleech
Copy link
Collaborator

you can use a lazy/callback expander as follows:

diff --git a/lib/Extension/ComposerInspector/ComposerInspectorExtension.php b/lib/Extension/ComposerInspector/ComposerInspectorExtension.php
index f289fa3e..3abef5ea 100644
--- a/lib/Extension/ComposerInspector/ComposerInspectorExtension.php
+++ b/lib/Extension/ComposerInspector/ComposerInspectorExtension.php
@@ -7,6 +7,7 @@ use Phpactor\Container\Container;
 use Phpactor\Container\ContainerBuilder;
 use Phpactor\Container\Extension;
 use Phpactor\Extension\FilePathResolver\FilePathResolverExtension;
+use Phpactor\FilePathResolver\Expander\CallbackExpander;
 use Phpactor\FilePathResolver\Expander\ValueExpander;
 use Phpactor\FilePathResolver\PathResolver;
 use Phpactor\MapResolver\Resolver;
@@ -24,8 +25,10 @@ class ComposerInspectorExtension implements Extension
         });
 
         $container->register('composer.bin_path_expander', function (Container $container) {
-            $path = $container->get(ComposerInspector::class)->getBinDir();
-            return new ValueExpander('composer_bin_dir', $path);
+            return new CallbackExpander('composer_bin_dir', function () use ($container) {
+                $path = $container->get(ComposerInspector::class)->getBinDir();
+                return $path;
+            });
         }, [ FilePathResolverExtension::TAG_EXPANDER => [] ]);
     }

@dantleech dantleech force-pushed the phpactor-2749 branch 2 times, most recently from ddf7e0c to 571025f Compare October 8, 2024 21:42
@mamazu mamazu force-pushed the phpactor-2749 branch 2 times, most recently from 040ebf3 to 71711f7 Compare October 9, 2024 22:52
@dantleech dantleech merged commit 216a094 into phpactor:master Oct 11, 2024
@dantleech
Copy link
Collaborator

thanks!

@mamazu mamazu deleted the phpactor-2749 branch October 13, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP-CS-Fixer fails to start with non-default bindir

2 participants