Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Reactor Laravel Package

spiral/reactor

Spiral Reactor is a small PHP package for building and running reactive pipelines in Spiral apps. It helps compose transformations and event-driven flows with a simple API, aimed at lightweight orchestration and experimentation in Spiral-based projects.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require spiral/reactor) and examining the spiral/reactor namespace in the original spiral/framework repo (this is a read-only subtree split). Key entry points are the Spiral\Reactor classes like ClassDecorator, MethodDecorator, and PropertyDecorator, which let you programmatically generate or modify PHP classes using an object-oriented, declarative API. The most basic use case is scaffolding new classes or modifying existing ones (e.g., adding traits, methods, or attributes) at build time—commonly used in command-line tools or framework bootstrappers.

Implementation Patterns

  • Declarative Class Building: Extend Spiral\Reactor\ClassDecorator to define class templates with methods, properties, and attributes in PHP, then call generate() to produce raw PHP source code.
  • Incremental Class Modification: Use ClassDecorator::fromClassReflection() to load an existing class, apply decorators (e.g., addMethod(), addTrait()), and output the updated source—useful for code transformations in CLI tools.
  • Integration with CLI Commands: Pair with Symfony Console or Spiral Console to expose class generation as custom Artisan commands (e.g., php app make:api-resource).
  • Template Reusability: Define reusable base decorators (e.g., ApiResourceDecorator that sets up @resource attributes, toArray(), and validation rules) and extend them for domain-specific scaffolding.

Gotchas and Tips

  • PHP Version Support: Ensure your environment matches the package’s PHP requirements (this package targets ~7.2–7.4); mixing with PHP 8+ code may generate invalid source due to missing reflection updates.
  • Reflection Limitations: fromClassReflection() can’t infer docblock annotations not present in compiled reflection—custom decorators may require duplicating annotation parsing logic.
  • Source Generation Fragility: Generated code lacks formatting tools by default; pipe output through php-cs-fixer or phpfmt to ensure PSR compliance.
  • Subtree Split Warning: Since this is a read-only subtree split, no new features/bug fixes are released here—watch spiral/framework for updates and patch manually if needed.
  • Testing Tip: Unit-test decorators in isolation by asserting on generate() output with PHPUnit::assertStringContainsString() or snapshot testing.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport