Skip to content

fix: resolve the source location for generators with --path - #592

Merged
ogorzalka merged 4 commits into
Pollora:developfrom
bfs2021:fix/generator-path-option
Nov 13, 2026
Merged

ogorzalka merged 4 commits into
Pollora:developfrom
bfs2021:fix/generator-path-option

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 7, 2026

Copy link
Copy Markdown

Problem

Running any generator that resolves its location with --path crashes with Undefined array key "source_path", e.g.:

php artisan pollora:make:action Foo --path=app/Custom

Found while checking the documentation against the code (Pollora/documentation#71), part 1 of #591.

Root cause

HasPathSupport::resolveCustomPath() returns only type, path and namespace, while ResolvesLocation::getResolvedFilePath() reads $location['source_path'] (and getResolvedNamespace() reads $location['source_namespace']) unconditionally. Every other resolver (resolveDefaultLocation(), the theme, plugin and module ones) sets both keys, so only the --path location crashes.

Fix

Set source_path (the resolved absolute path) and source_namespace in resolveCustomPath(), matching the shape the other resolvers return, so --path generates the file in the given folder again.

Testing

  • Added it generates the class in the custom path with --path to tests/Feature/Hook/ActionMakeCommandTest.php: it failed before the fix with Undefined array key "source_path" at ResolvesLocation.php:53 and passes after it, asserting the class file is created under the custom folder.
  • vendor/bin/pest tests/Feature/Hook/ActionMakeCommandTest.php: 4 passed (the 3 pre-existing tests still pass).
  • Full vendor/bin/pest run shows the same pre-existing (environment-related) failures as on a clean main; vendor/bin/pint --test passes on both changed files.

@ogorzalka
ogorzalka enabled auto-merge November 10, 2026 20:11
@ogorzalka
ogorzalka changed the base branch from main to develop November 12, 2026 08:24
@ogorzalka

Copy link
Copy Markdown
Member

Thanks @bfs2021, and thank you for taking on part 1 of #591. I changed the base branch to develop (fixes go through develop and reach main with a release).

The crash is gone and your diagnosis is right. One thing the test can't see: with --path, the generated file gets an invalid namespace, e.g. namespace AppCms\Hooks;. source_namespace is 'App' without a trailing backslash, while resolveDefaultLocation() returns app()->getNamespace() (App\) and getResolvedNamespace() concatenates the sub-path directly. I checked it with make:action, make:filter, make:post-type, make:taxonomy, make:wp-cli, make:role, make:model and make:binding.

Could you set 'source_namespace' => app()->getNamespace() and make the test assert the namespace line of the generated file, not just that the file exists? Whether the sub-path should be appended to --path is a design question I'll settle separately; no need to change it here.

@ogorzalka ogorzalka closed this Nov 12, 2026
auto-merge was automatically disabled November 12, 2026 08:25

Pull request was closed

@ogorzalka ogorzalka reopened this Nov 12, 2026
@bfs2021

bfs2021 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Done in 4c1a63f — resolveCustomPath() now uses app()->getNamespace() for source_namespace, so the sub-path concatenation yields App\Cms\Hooks instead of the invalid AppCms\Hooks.

The --path test now asserts the namespace line of the generated file (namespace App\Cms\Hooks; present, namespace AppCms\ absent) — it fails against the previous commit and passes with this one. Ran the full ActionMakeCommandTest locally (4 passed); the other generators sharing HasPathSupport get the same fix from this one line.

I left the namespace key untouched — the sub-path-vs---path design question stays with you as you proposed.

@ogorzalka
ogorzalka merged commit 2fad731 into Pollora:develop Nov 13, 2026
19 checks passed
@ogorzalka

Copy link
Copy Markdown
Member

Merged into develop, thank you @bfs2021: the crash of --path is gone, and the namespace fix and the test on the generated file are exactly what the change needed. It will reach main with the next release.

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.

2 participants