Skip to content

Enhancements URL and Pages #3674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

GIGABAIT93
Copy link

Enhancements to Pages class (core/classes/Core/Pages.php):

  • Added a new method getPageByName to retrieve page details by name. This method iterates through _pages to find a matching name and returns the page information or null if not found.
  • Introduced getPagesByModule to fetch all pages associated with a specific module, using array_filter for efficient filtering.
  • Updated return types for getPageById and getPageByURL methods to explicitly allow null when no page is found, improving type safety. [1] [2]
  • Added the url key to the page array in the add and addCustom methods, ensuring the URL is explicitly stored for each page. [1] [2]

Enhancements to URL class (core/classes/Core/URL.php):

  • Added getSegments, a utility to break a URI into an array of segments, removing leading/trailing slashes and empty segments. This simplifies URI parsing.
  • Introduced segment, a method to retrieve a specific URI segment by index, with an optional default value if the segment is absent.

@tadhgboyle
Copy link
Member

Thanks for the contribution! Did you have specific use cases in mind for these? I'm hesitant to add more methods which aren't used at least internally

@GIGABAIT93
Copy link
Author

GIGABAIT93 commented May 22, 2025

Thanks for the contribution! Did you have specific use cases in mind for these? I'm hesitant to add more methods which aren't used at least internally

I use it in my module eg getting a segment to determine slug $slug = URL::segment(2);
Also in my module I for pages I give the names so it would be convenient to get a page by name
if($pages->getActivePage()['name'] === $pages->getPageByName('index')['name']){}
Also as an example you can get all the pages of the module and automatically add them to navigation
I think it would be useful methods

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.

4 participants