Visitar URL original
[4.x] Make Folder::listFolderTree() work without JPATH_ROOT by Hackwar · Pull Request #92 · joomla-framework/filesystem · GitHub
Skip to content

[4.x] Make Folder::listFolderTree() work without JPATH_ROOT - #92

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-listfoldertree-without-jpath-root
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-listfoldertree-without-jpath-root

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Folder::listFolderTree() computed each folder's relname with str_replace(JPATH_ROOT, '', $fullName). Outside the Joomla CMS the constant does not exist, so the method failed with Error: Undefined constant "Joomla\Filesystem\JPATH_ROOT" as soon as it found a folder. It also kept its running id in $GLOBALS['_JFolder_folder_tree_index'].

relname now strips JPATH_ROOT when that constant is defined (unchanged behaviour in the CMS) and the listed $path otherwise. The recursion moved to a private helper that passes the id counter by reference, so no global state is left behind. The public signature is unchanged.

Testing Instructions

FolderTest::testListFolderTreeWithoutJpathRoot lists a temporary a/b tree in a separate PHP process without JPATH_ROOT. Before: Fatal error: Uncaught Error: Undefined constant "Joomla\Filesystem\JPATH_ROOT" in Folder.php. After: 1 0 /a, 2 1 /a/b, and $GLOBALS['_JFolder_folder_tree_index'] is not set. The existing testListFolderTree* tests pass unchanged.

Documentation Changes Required

docs/overview.md gets a "Folder trees" section describing the entries and how relname is computed.

#88 rewrites docs/overview.md; whichever of the two is merged second has to resolve the conflict there. In #88's "Things to know before you build on this", the paragraph "Folder::listFolderTree(), Path::removeRoot() and Stream::getStream() need JPATH_ROOT" has to drop Folder::listFolderTree().

Related to #90 and #91 (the same problem in Path::removeRoot() and Stream::getStream(); expect a trivial conflict in docs/overview.md, where each PR adds a section at the end).

🤖 Generated with Claude Code

listFolderTree() computed the relative name of every folder with the CMS
constant JPATH_ROOT, so outside the CMS it failed with "Undefined
constant JPATH_ROOT" as soon as it found a folder. Without the constant
the names are now relative to the listed path. The running id is passed
by reference to a private helper instead of being kept in $GLOBALS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

The CI failures are unrelated to this change and occur on 4.x-dev as well (see its scheduled runs):

  • Unit tests: the only failing test is HelperTest::testRemotefsize. https://www.example.org no longer sends a Content-Length header, so Helper::remotefsize() returns false. [4.x] Fix Stream reads at EOF, of "0" chunks and of Windows paths #88 makes that test skip when the header is missing.
  • Unit tests (Windows) (8.3): composer install --ignore-platform-reqs installs a PHPUnit release that requires PHP 8.4, so PHPUnit refuses to start ("This version of PHPUnit requires PHP >= 8.4.1"). Whichever Windows job fails first cancels the other (fail-fast).
  • PHPStan (non-blocking, continue-on-error): reports the existing errors in FtpClient and File::isSafeFile(). This change adds no new ones.

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.

1 participant