Skip to content
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

feat: loading model from remote url #69

Merged
merged 2 commits into from
Jun 15, 2024

Conversation

rev3z
Copy link
Contributor

@rev3z rev3z commented Jun 11, 2024

Description

This PR introduces an enhancement to enhance the flexibility of the Enforcer's model management:

  1. Remote Model Initialization via URL: This feature enables the Enforcer to fetch its model configuration from a remote URL at startup.

  2. Refactoring with Factory Pattern for Model Loading: To streamline and abstract the complexity of model loading processes, a new ModelLoaderFactory class has been introduced.

Upon initialization, the system not only supports fetching plain text model configurations from URLs but also sets the stage for more sophisticated content handling through custom implementations of \Lauthz\Loaders\ModelLoader, catering to diverse content types like JSON.

Related Issues

[Question] Loading model from a remote URL #15

Details

  • Remote Model Support: Adds the capability to load the model configuration directly from remote URLs.
  • Initialization Process: The remote model is fetched only once during the Enforcer's setup phase [See ref].
  • HTTP request: Utilizes file_get_contents() to ensure broad compatibility and straightforward implementation for fetching remote model definitions.
  • Refactored Loader Infrastructure: Implemented a ModelLoaderFactory to encapsulate the creation and management of model loaders, including the FileLoader、TextLoader、UrlLoader.

@hsluoyz
Copy link
Member

hsluoyz commented Jun 11, 2024

@leeqvip plz review

Copy link
Member

@leeqvip leeqvip left a comment

Choose a reason for hiding this comment

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

And please add unit tests

src/EnforcerManager.php Outdated Show resolved Hide resolved
@rev3z rev3z force-pushed the feat-remote-model branch from ab5288f to b699776 Compare June 12, 2024 14:34
@rev3z
Copy link
Contributor Author

rev3z commented Jun 12, 2024

Unit tests added.

@rev3z rev3z requested a review from leeqvip June 12, 2024 15:11
@leeqvip
Copy link
Member

leeqvip commented Jun 12, 2024

@rev3z Please fix the ci check error.

@rev3z
Copy link
Contributor Author

rev3z commented Jun 12, 2024

I'll fix it!

@rev3z rev3z force-pushed the feat-remote-model branch 2 times, most recently from ed659e0 to 419859d Compare June 14, 2024 13:54
@rev3z rev3z force-pushed the feat-remote-model branch from 419859d to 4be7849 Compare June 14, 2024 16:00
@rev3z
Copy link
Contributor Author

rev3z commented Jun 14, 2024

CI error fixed, PR contents updated.

@hsluoyz
Copy link
Member

hsluoyz commented Jun 15, 2024

@leeqvip plz review

src/Loaders/TextLoader.php Outdated Show resolved Hide resolved
@leeqvip leeqvip merged commit 259a389 into php-casbin:master Jun 15, 2024
49 checks passed
@leeqvip
Copy link
Member

leeqvip commented Jun 15, 2024

🎉 This PR is included in version 3.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants