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

Components Laravel Package

alterphp/components

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer (if available in a private repo or fork):

    composer require alterphp/components
    

    Note: Since the repo is archived, ensure you have a fork or local copy.

  2. First Use Case: Dependency Injection The package leverages Symfony’s DI container. Start by bootstrapping it in a Laravel app:

    // In a service provider (e.g., AppServiceProvider.php)
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    
    public function register()
    {
        $container = new ContainerBuilder();
        // Register services/components here (see Implementation Patterns)
        $this->app->singleton('symfony.container', function () use ($container) {
            return $container;
        });
    }
    
  3. Key Entry Points

    • Component Base Class: Extend Alterphp\Component\Component for reusable logic.
    • EventDispatcher: Use Symfony’s event system via Alterphp\Component\EventDispatcher.
    • Configuration: Check for config/alterphp.php (if provided) or define your own.

Implementation Patterns

1. Component-Based Workflows

  • Create a Component:
    namespace App\Components;
    
    use Alterphp\Component\Component;
    
    class UserValidator extends Component
    {
        public function validate(array $data): bool
        {
            // Validation logic
            return true;
        }
    }
    
  • Register in DI Container:
    $container->register('user.validator', UserValidator::class)
              ->addArgument(new Reference('some.dependency'));
    

2. Event-Driven Architecture

  • Dispatch Events:
    $dispatcher = $container->get('event_dispatcher');
    $dispatcher->dispatch('user.created', new UserCreatedEvent($user));
    
  • Listen for Events (Laravel-style):
    $dispatcher->addListener('user.created', function ($event) {
        // Handle event
    });
    

3. Integration with Laravel Services

  • Bind Symfony Services to Laravel:
    $this->app->bind('some.service', function ($app) {
        return $app->make('symfony.container')->get('some.service');
    });
    
  • Use in Controllers:
    public function store(Request $request)
    {
        $validator = $this->app->make('user.validator');
        if (!$validator->validate($request->all())) {
            // Handle error
        }
    }
    

4. Configuration Management

  • Load Config:
    $config = $container->getParameter('app.config');
    
  • Define Parameters:
    $container->setParameter('app.config', [
        'max_retries' => 3,
    ]);
    

Gotchas and Tips

Pitfalls

  1. Archived Package Risks

    • No active maintenance; fork or patch locally if bugs arise.
    • Check for breaking changes in Symfony 2+ dependencies (e.g., symfony/event-dispatcher).
  2. DI Container Conflicts

    • Avoid naming collisions with Laravel’s container. Prefix services (e.g., alterphp.user.validator).
    • Clear the container cache if services misbehave:
      php artisan config:clear
      
  3. PHP 5.3+ Constraints

    • Test on PHP 5.6+ for compatibility with modern Laravel (some features may require PHP 7+).

Debugging Tips

  • Service Not Found? Verify the service is registered in the ContainerBuilder and the container is bound in Laravel:
    $this->app->has('symfony.container'); // Should return true
    
  • Event Not Triggered? Check listener registration order and event names (case-sensitive).

Extension Points

  1. Custom Components Extend Alterphp\Component\Component to add shared logic (e.g., logging, caching).

  2. Event Subscribers Create a subscriber class:

    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class LoggingSubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return ['user.created' => 'logEvent'];
        }
    
        public function logEvent($event) { /* ... */ }
    }
    

    Register it with the dispatcher:

    $dispatcher->addSubscriber(new LoggingSubscriber());
    
  3. Configuration Overrides Override Symfony parameters in Laravel’s config/services.php:

    'alterphp' => [
        'parameters' => [
            'app.timeout' => env('APP_TIMEOUT', 30),
        ],
    ],
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui