{"id":18773125,"url":"https://github.com/webfactory/slug-validation-bundle","last_synced_at":"2025-04-13T09:07:58.233Z","repository":{"id":9866784,"uuid":"63418503","full_name":"webfactory/slug-validation-bundle","owner":"webfactory","description":"Transparent validation of URL slugs in Symfony applications.","archived":false,"fork":false,"pushed_at":"2025-01-06T16:50:50.000Z","size":67,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-13T09:07:48.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webfactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-07-15T11:58:15.000Z","updated_at":"2025-01-06T16:50:52.000Z","dependencies_parsed_at":"2024-03-07T10:50:55.431Z","dependency_job_id":"1c85fc9a-3a13-4de6-80d4-9da3e93e0b44","html_url":"https://github.com/webfactory/slug-validation-bundle","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.21739130434782605","last_synced_commit":"ab522152cfab6f17a85a8a360c8f24a3b8bdb8f0"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fslug-validation-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fslug-validation-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fslug-validation-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fslug-validation-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webfactory","download_url":"https://codeload.github.com/webfactory/slug-validation-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688567,"owners_count":21145766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T19:32:55.291Z","updated_at":"2025-04-13T09:07:58.219Z","avatar_url":"https://github.com/webfactory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slug Validation Bundle\n\n![Tests](https://github.com/webfactory/slug-validation-bundle/workflows/Tests/badge.svg)\n![Dependencies](https://github.com/webfactory/slug-validation-bundle/workflows/Dependencies/badge.svg)\n\nDo not clutter your controller actions with URL slug validation: This Symfony bundle helps\nto validate object slugs in URLs transparently.\n\n- Checks if a slug is valid (if provided at all)\n- Redirects to the URL with the correct slug on failure (for example after a slug change)\n\n## Motivation\n\nHandling of URL Slugs is a part of many web applications. Although readable URLs are nice, they usually do not\ncontribute to your main functionality. Instead, slug validation and handling of redirects in case of failure generates\na lot of noise in your controller actions, is often cluttered over many parts of the application and makes it harder\nto see the core problems that are solved.\n\nAfter facing these problems several times, we decided to create a system that handles slug validation as part\nof the middleware, that keeps your controller actions clean and lets you concentrate on what is really important:\nYour domain problems.\n\n## Installation\n\nInstall the bundle via [Composer](https://getcomposer.org):\n\n    composer require webfactory/slug-validation-bundle\n\nEnable the bundle:\n\n    \u003c?php\n    // src/bundles.php\n\n    return [\n        // ...\n        Webfactory\\SlugValidationBundle\\WebfactorySlugValidationBundle::class =\u003e ['all' =\u003e true],\n        // ...\n    ];\n\n## Usage\n\n### Prerequisite: Sluggable object as controller action parameter\n\nDeclare your sluggable object as controller action parameter:\n\n    public function myAction(MyEntity $entity)\n    {\n    }\n\nAnd configure it to be resolved before the controller action is called, e.g. via\n[`#[MapEntity]`](https://symfony.com/doc/current/doctrine.html#mapentity-options) or\n[`@ParamConverter`](http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html) (deprecated).\n\n### Implement Sluggable\n\nProvide the hint that the entity has a slug that can be validated by implementing\n``\\Webfactory\\SlugValidationBundle\\Bridge\\SluggableInterface``:\n\n    class MyEntity implements SluggableInterface\n    {\n        public function getSlug(): ?string\n        {\n            return 'my-generated-slug';\n        }\n    }\n    \n### Add Slug Parameter to Routes\n    \nDeclare a route that contains an ``entitySlug`` parameter and points to your action: \n    \n    my_entity_route:\n        path: /entity/{entitySlug}.{entity}\n        defaults:\n            _controller: MyBundle:MyController:my\n\nThat's it! Whenever a sluggable entity is used together with a slug parameter in a route this bundle will\nstep in and perform a validation. If a slug is invalid, then a redirect to the same route with the \ncorrected slug will be initiated.\n\n### Additional Information\n\nEntity and slug parameters are matched by convention: The slug parameter must use the suffix ``Slug``.\nFor example the correct parameter name for a ``blogPost`` parameter is ``blogPostSlug``.\n\nIf a route contains a sluggable entity but no slug parameter, then nothing will happen, so the usual\nSymfony behavior is not changed.\n\n#### Slug Generation\n\nIf you are not sure how to create your slugs, then you might find [cocur/slugify](https://github.com/cocur/slugify)\nuseful. A component that generates URL slugs from any string.\n\n#### Simplified Routing\n\nPassing slug values during route generation can be a tedious and error-prone task.\n[webfactory/object-routing](https://github.com/webfactory/object-routing) and [webfactory/object-routing-bundle](https://github.com/webfactory/BGObjectRoutingBundle)\ncan ease that task by defining route construction rules directly with your entity:\n\n    /**\n     * @ObjectRoute(type=\"my_object_route\", name=\"my_entity_route\", params={\n     *     \"entity\": \"id\",\n     *     \"entitySlug\": \"slug\"\n     * })\n     */\n    class MyEntity implements SluggableInterface\n    {\n        public function getId(): int\n        {\n            // ...\n        }\n        \n        public function getSlug(): ?string\n        {\n            // ...\n        }\n        \n        // ...\n    }\n\nWhen generating the URL, you don't have to deal with passing these parameters anymore (example in Twig):\n\n    {{ object_path('my_object_route', myEntityInstance) }}\n\n## Credits, Copyright and License\n\nThis project was started at webfactory GmbH, Bonn.\n\n- \u003chttps://www.webfactory.de\u003e\n- \u003chttps://twitter.com/webfactory\u003e\n\nCopyright 2016-2025 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfactory%2Fslug-validation-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebfactory%2Fslug-validation-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfactory%2Fslug-validation-bundle/lists"}