symkit / redirect-bundle
This bundle allows you to manage internal and external redirects directly from your database
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/symkit/redirect-bundle
Requires
- php: >=8.2
- doctrine/orm: ^2.14 || ^3.6
- symfony/framework-bundle: ^7.0 || ^8.0
- symkit/crud-bundle: ~0.0.1
- symkit/form-bundle: ~0.0.1
- symkit/menu-bundle: ~0.0.1
- symkit/metadata-bundle: ~0.0.1
- symkit/routing-bundle: ~0.0.1
- symkit/search-bundle: ~0.0.1
Requires (Dev)
- deptrac/deptrac: ^2.0
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.29
- nyholm/symfony-bundle-test: ^3.0
- phpro/grumphp: ^2.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- symfony/browser-kit: ^7.0 || ^8.0
- symkit/bundle-ai-kit: ~0.0.1
This package is auto-updated.
Last update: 2026-02-22 20:05:59 UTC
README
Symfony bundle to manage URL redirects (internal and external) from the database, with validation, route integration, and global search.
Requirements
- PHP 8.2+
- Symfony 7.0 or 8.0
- Doctrine ORM
- For the admin UI:
symkit/crud-bundle,symkit/metadata-bundle,symkit/menu-bundle - To link redirects to routes:
symkit/routing-bundle - For global search:
symkit/search-bundle
Installation
composer require symkit/redirect-bundle
Register the bundle in config/bundles.php (automatic with Flex):
return [ Symkit\RedirectBundle\RedirectBundle::class => ['all' => true], ];
Configuration
All options are enabled by default. Example with explicit values:
# config/packages/symkit_redirect.yaml symkit_redirect: enabled: true doctrine: entity_class: Symkit\RedirectBundle\Entity\Redirect repository_class: Symkit\RedirectBundle\Repository\RedirectRepository admin: enabled: true route_prefix: admin_redirect path_prefix: /admin/redirects listener: enabled: true search: enabled: true
- enabled: Enable or disable the whole bundle.
- doctrine.entity_class: FQCN of the redirect entity (see "Custom entity").
- doctrine.repository_class: FQCN of the redirect repository.
- admin.enabled: Register the CRUD controller and admin routes.
- admin.route_prefix: Prefix for route names (e.g.
admin_redirect_list,admin_redirect_edit). - admin.path_prefix: URL path prefix (e.g.
/admin/redirects). - listener.enabled: Register the listener that performs redirects on each request.
- search.enabled: Register the redirect search provider for global search.
Routes
Include the admin routes in your application (e.g. config/routes.yaml):
symkit_redirect: resource: '@SymkitRedirectBundle/config/routes.yaml' prefix: '%symkit_redirect.admin.path_prefix%'
This registers: admin_redirect_list, admin_redirect_create, admin_redirect_edit, admin_redirect_delete.
Usage
Manual creation
use Symkit\RedirectBundle\Entity\Redirect; $redirect = new Redirect(); $redirect->setUrlFrom('/old-page'); $redirect->setUrlTo('/new-page'); $entityManager->persist($redirect); $entityManager->flush();
Admin interface
With admin.enabled: true and symkit/crud-bundle, symkit/metadata-bundle, and symkit/menu-bundle installed, the CRUD interface is available at the configured URL (default /admin/redirects).
Redirects to an internal route
If symkit/routing-bundle is installed, you can choose an internal route as the destination instead of an external URL ("Internal Route" field in the form).
Custom entity
To use your own entity (extra fields, behaviour, etc.):
- Extend
Symkit\RedirectBundle\Entity\Redirector implementSymkit\RedirectBundle\Contract\RedirectEntityInterfacewith the same Doctrine mapping. - Configure the FQCN:
symkit_redirect: doctrine: entity_class: App\Entity\MyRedirect
- Map your entity in Doctrine (XML or attributes) as usual.
Validation
The bundle validates in particular:
- Relative URLs starting with
/. - No redirect from an URL to itself.
- Unique source (one redirect per source URL).
- A destination must be set (URL or internal route).
Validation messages live in the validators domain (bundle files validators.*.xlf).
Global search
With search.enabled: true and symkit/search-bundle, redirects are indexed in global search (by source or destination URL). The displayed category is translated (domain SymkitRedirectBundle).
Translations
- Domain: SymkitRedirectBundle.
- XLIFF files in
translations/:SymkitRedirectBundle.en.xlf,SymkitRedirectBundle.fr.xlf. - Constraint messages:
validators.en.xlf,validators.fr.xlf(domainvalidators).
Form labels, admin list, and search use this domain.
Tests
The bundle is covered by unit tests (services, form, validation), integration tests (bundle boot with TestKernel, Doctrine repository), and functional tests (HTTP request → 308 redirect). Run the suite with make test. Full quality (style, static analysis, architecture, mutation) runs via make quality; the mutation score (Infection) target is at least 64% on covered code.
Contributing
make install make cs-fix make phpstan make test make quality # cs-check + phpstan + deptrac + lint + test + infection make ci # security-check + quality
License
MIT.