c975l/exceptionchecker-bundle
Installation
composer require c975l/exceptionchecker-bundle
Add the bundle to config/bundles.php:
return [
// ...
C975L\ExceptionCheckerBundle\ExceptionCheckerBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console exceptionchecker:install
Update config/packages/exceptionchecker.yaml with your:
secret_code (optional, if not logged in)redirect_url (default: /)ignored_urls (wildcards supported, e.g., "/admin/*")First Use Case
https://your-site.com/nonexistent-page).Catching and Redirecting
kernel.exception and kernel.controller events.ExceptionChecker rules (case-insensitive, wildcards).redirect_url (default: /).GoneHttpException (HTTP 410).Admin Management
/_exceptionchecker (configurable).Integration with Symfony
{{ dump(exceptionchecker) }} to debug rules in templates.kernel.exception:
// src/EventListener/CustomExceptionListener.php
public function onKernelException(GetResponseForExceptionEvent $event) {
$exception = $event->getThrowable();
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
// Custom logic before ExceptionCheckerBundle processes it
}
}
# config/packages/monolog.yaml
handlers:
exceptionchecker:
type: stream
path: "%kernel.logs_dir%/exceptionchecker.log"
level: info
channels: ["exceptionchecker"]
Wildcard Rules
ignored_urls:
- "/old-*/" # Redirects /old-page1/, /old-page2/, etc.
- "/api/v1/*/delete" # Catches all DELETE endpoints under /api/v1/
Case Sensitivity
/YourFile.html and /yourfile.html are treated as the same rule.Secret Code Security
secret_code, ensure it’s stored securely (e.g., in parameters.yaml with encryption: true).Performance with Wildcards
"/**/*") may slow down exception handling.php bin/console debug:router to validate URL matching.Monolog Configuration
error level (or higher) to avoid missing broken-link alerts.# config/packages/monolog.yaml
handlers:
main:
level: error
type: fingers_crossed
action_level: error
handler: nested
GoneHttpException (410)
CSRF Protection
$this->denyAccessUnlessGranted('ROLE_EXCEPTIONCHECKER_EDIT');
Log Exceptions Enable debug mode to see raw exception data:
php bin/console debug:exception
Filter for C975L\ExceptionCheckerBundle\Exception\GoneHttpException.
Check Rule Matches
Use the debug toolbar to inspect ExceptionChecker rules:
// In a controller
$rules = $this->get('exceptionchecker.rule_manager')->getAllRules();
dd($rules);
Clear Cache After Config Changes
php bin/console cache:clear
Custom Exception Types Extend the bundle to handle non-Symfony exceptions:
// src/EventSubscriber/CustomExceptionSubscriber.php
public function onKernelException(GetResponseForExceptionEvent $event) {
$exception = $event->getThrowable();
if ($exception instanceof \Your\Custom\Exception) {
$ruleManager = $this->container->get('exceptionchecker.rule_manager');
if ($ruleManager->isUrlIgnored($exception->getUrl())) {
$event->setResponse(new RedirectResponse('/custom-redirect'));
}
}
}
Add Fields to Rules Override the form type:
// src/Form/ExceptionCheckerType.php
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('custom_field', TextType::class);
}
Hook into Rule Creation
Subscribe to the exceptionchecker.rule.created event:
// src/EventListener/RuleCreatedListener.php
public function onRuleCreated(RuleEvent $event) {
$rule = $event->getRule();
// Add metadata or trigger side effects
}
Override Templates
Copy the bundle’s templates to templates/bundles/exceptionchecker/ to customize:
rule_form.html.twig (admin form)redirect.html.twig (secret code form)How can I help you explore Laravel packages today?