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

Context Bundle Laravel Package

bigfoot/context-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer (if still functional):

    composer require c2is/bigfoot-context-bundle
    

    Enable in config/bundles.php (Symfony 4+):

    return [
        // ...
        C2is\BigfootContextBundle\BigfootContextBundle::class => ['all' => true],
    ];
    
  2. First Use Case Inject the ContextManager service into a controller or service:

    use C2is\BigfootContextBundle\Context\ContextManager;
    
    class MyController extends AbstractController {
        public function __construct(private ContextManager $contextManager) {}
    
        public function index() {
            $context = $this->contextManager->getContext();
            $context->set('user.id', 123); // Store a value
            $context->get('user.id');     // Retrieve it
        }
    }
    
  3. Key Files to Review

    • src/Context/ContextManager.php (Core logic)
    • src/Context/ContextInterface.php (API contract)
    • src/DependencyInjection/ (Configuration)

Implementation Patterns

Core Workflows

  1. Request-Scoped Context Useful for passing data across middleware, controllers, and services without global state:

    // Middleware
    $context->set('auth.user', $user);
    
    // Controller
    $user = $context->get('auth.user');
    
  2. Event-Driven Context Attach listeners to context changes:

    $context->addListener('user.id', function($old, $new) {
        // Log or trigger side effects
    });
    
  3. Nested Contexts Create hierarchical contexts for modularity:

    $moduleContext = $context->createChild('module');
    $moduleContext->set('data', $payload);
    

Integration Tips

  • Symfony Events: Tie context changes to Symfony events (e.g., kernel.request):
    $eventDispatcher->addListener(KernelEvents::REQUEST, function(RequestEvent $event) {
        $context->set('request.start', time());
    });
    
  • Doctrine Integration: Store context in a session or database for persistence:
    $context->set('user.preferences', $preferencesRepo->find($userId));
    
  • Testing: Mock ContextManager to isolate logic:
    $this->mock(ContextManager::class)
         ->shouldReceive('getContext')
         ->andReturn($mockContext);
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package

    • Last release in 2014; verify compatibility with modern PHP/Symfony (e.g., PSR-11 containers).
    • Workaround: Fork and update dependencies (e.g., symfony/dependency-injection to v5+).
  2. No Built-in Persistence

    • Context is request-scoped by default; explicitly save to session/DB if needed:
      $context->set('cart', $cartRepo->find($userId) ?? new Cart());
      
  3. Thread Safety

    • Not thread-safe; avoid in CLI workers or concurrent environments.
  4. Magic Methods

    • Uses __get()/__set(); override cautiously to avoid conflicts.

Debugging Tips

  • Inspect Context:
    dump($context->all()); // Dump all stored values
    
  • Listener Debugging: Add a listener to log changes:
    $context->addListener('*', function($key, $value) {
        error_log("Context change: $key => $value");
    });
    

Extension Points

  1. Custom Context Storage Implement C2is\BigfootContextBundle\Context\ContextStorageInterface for alternative backends (e.g., Redis):

    class RedisContextStorage implements ContextStorageInterface {
        public function load() { /* ... */ }
        public function save(array $data) { /* ... */ }
    }
    
  2. Context Validators Add validation to context keys:

    $context->addValidator('user.age', function($value) {
        return is_int($value) && $value >= 0;
    });
    
  3. Global Context Extend ContextManager to support application-wide contexts:

    $globalContext = $contextManager->getGlobalContext();
    
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony