Skip to content

Updates to autoloader.#733

Merged
mauteri merged 4 commits intomainfrom
update-autoloader
Jul 17, 2024
Merged

Updates to autoloader.#733
mauteri merged 4 commits intomainfrom
update-autoloader

Conversation

@mauteri
Copy link
Copy Markdown
Contributor

@mauteri mauteri commented Jul 17, 2024

Description of the Change

Changes to autoloader to allow companion plugins to register and utilize the autoloader via the gatherpress_autoloader filter. This filter is an array where the key is the namespace (eg GatherPress) and the value is the root directory (eg __DIR__).

How to test the Change

Everything in GatherPress should work normally.

Changelog Entry

Changed - Existing functionality

Credits

Props @mauteri

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Jul 17, 2024

PR Summary

  • Improvements to the Autoloader Class
    The class-autoloader.php file underwent multiple enhancements to ensure more accurate and efficient automatic class loading. These changes refine the way classes are recognized and loaded by introducing additional checks and refinement techniques.

    • The method responsible for registering classes now strictly accepts string values, to make sure we are handling correct data type.

    • We introduced a default array to handle specific default behaviors in the auto-loading process. This helps us manage package behavior more effectively.

    • We adopted an application of filters to our gatherpress_autoloader hook. It allows us to modify certain elements during the auto-loading process, giving us more flexibility in control and execution.

    • We implemented a loop to oversee registered autoloaders. This means that we've made provisions to manage multiple autoloaders smartly.

    • With application of the trim function, we are ensuring there are no leading or trailing backslashes disrupting class string manipulations.

    • We've applied checks to ensure that the class string is neither empty nor excluding backslashes. This helps us keep our data uniform and valid.

    • The class string is broken down into smaller strings. This process aids in managing and determining the different components of a given class path.

    • These small strings (or array elements) are converted to lowercase and standardized by replacing underscores with hyphens. This promotes consistency and effective pattern recognition in the class path naming schema.

    • The type of file and class gets derived from this array, breaking down complex identification into smaller, manageable parts.

    • Further, the array is manipulated according to the class type. This ensures each class type is handled in a manner conducive to its specifics.

    • The array elements and the path are used to generate the final file path. This results in an organized directory structure ensuring faster and easier file access.

    • We use the validate_file function to ensure the designated file path is valid and reliable, helping us avoid inefficiencies or errors due to faulty paths.

    • If the file is confirmed to exist and its validity verified, it is included within the current script. This guarantees accurate class loading and improved script execution.

    • Lastly, the registration of autoload mechanisms now uses a static anonymous function with a definite void type. It guarantees better manageability and cleaner code since we are making sure what kind of data (in this case, no data or void) is being returned by our function.

The changes to this autoloader are designed to make your application's class loading process more precise, efficient, and flexible.

@mauteri mauteri merged commit 448ebdf into main Jul 17, 2024
@mauteri mauteri deleted the update-autoloader branch July 17, 2024 20:31
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