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],
];
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
}
}
Key Files to Review
src/Context/ContextManager.php (Core logic)src/Context/ContextInterface.php (API contract)src/DependencyInjection/ (Configuration)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');
Event-Driven Context Attach listeners to context changes:
$context->addListener('user.id', function($old, $new) {
// Log or trigger side effects
});
Nested Contexts Create hierarchical contexts for modularity:
$moduleContext = $context->createChild('module');
$moduleContext->set('data', $payload);
kernel.request):
$eventDispatcher->addListener(KernelEvents::REQUEST, function(RequestEvent $event) {
$context->set('request.start', time());
});
$context->set('user.preferences', $preferencesRepo->find($userId));
ContextManager to isolate logic:
$this->mock(ContextManager::class)
->shouldReceive('getContext')
->andReturn($mockContext);
Deprecated Package
symfony/dependency-injection to v5+).No Built-in Persistence
$context->set('cart', $cartRepo->find($userId) ?? new Cart());
Thread Safety
Magic Methods
__get()/__set(); override cautiously to avoid conflicts.dump($context->all()); // Dump all stored values
$context->addListener('*', function($key, $value) {
error_log("Context change: $key => $value");
});
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) { /* ... */ }
}
Context Validators Add validation to context keys:
$context->addValidator('user.age', function($value) {
return is_int($value) && $value >= 0;
});
Global Context
Extend ContextManager to support application-wide contexts:
$globalContext = $contextManager->getGlobalContext();
How can I help you explore Laravel packages today?