-
Couldn't load subscription status.
- Fork 6
374 Twig Extension Attributes #200
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
Conversation
Reviewer's GuideRefactors all Twig extensions to leverage native Twig attributes on readonly classes, consolidates pagination logic into a single attribute-based method, removes the deprecated runtime, and updates service tags to use twig.attribute_extension. Class diagram for refactored Twig extensionsclassDiagram
class ContentExtension {
<<readonly>>
+__construct(publicFolder: string)
+getContent(path: string): string
<<AsTwigFunction('content', isSafe: ['html'])>>
}
class FrameworkExtension {
<<readonly>>
+__construct(requestStack: RequestStack)
+ucfirst(string): string <<static>><<AsTwigFilter('ucfirst')>>
+determineTheme(): string <<AsTwigFunction('theme')>>
+sidebarIsOpen(): bool <<AsTwigFunction('sidebarIsOpen')>>
}
class PaginatorExtension {
<<readonly>>
+__construct(requestStack: RequestStack)
+renderPagination(env: Environment, paginator: Paginator): string <<AsTwigFunction('pagination', needsEnvironment: true, isSafe: ['html'])>>
-getRequest(): ?Request
}
class RequestStack
class Environment
class Paginator
class Request
ContentExtension --> RequestStack : uses
FrameworkExtension --> RequestStack : uses
PaginatorExtension --> RequestStack : uses
PaginatorExtension --> Environment : uses
PaginatorExtension --> Paginator : uses
PaginatorExtension --> Request : uses
Class diagram for removed PaginatorRuntimeclassDiagram
class PaginatorRuntime {
-renderPagination(env: Environment, paginator: Paginator): string
}
%% Note: PaginatorRuntime class has been removed in this PR.
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @absumo - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/Twig/ContentExtension.php:19` </location>
<code_context>
+ #[AsTwigFunction('content', isSafe: ['html'])]
public function getContent(string $path): string
{
return file_get_contents($this->publicFolder . $path);
</code_context>
<issue_to_address>
No error handling for missing or unreadable files.
Handle cases where file_get_contents returns false to prevent warnings and ensure consistent output.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Migrate existing Twig extensions to use native Twig attribute annotations, eliminate the PaginatorRuntime and legacy AbstractExtension/API, and update service configuration to register attribute-based extensions.
Enhancements:
Chores: