Download the PHP package webfactory/slug-validation-bundle without Composer

On this page you can find all versions of the php package webfactory/slug-validation-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slug-validation-bundle

Slug Validation Bundle

Tests Dependencies

Do not clutter your controller actions with URL slug validation: This Symfony bundle helps to validate object slugs in URLs transparently.

Motivation

Handling of URL Slugs is a part of many web applications. Although readable URLs are nice, they usually do not contribute to your main functionality. Instead, slug validation and handling of redirects in case of failure generates a lot of noise in your controller actions, is often cluttered over many parts of the application and makes it harder to see the core problems that are solved.

After facing these problems several times, we decided to create a system that handles slug validation as part of the middleware, that keeps your controller actions clean and lets you concentrate on what is really important: Your domain problems.

Installation

Install the bundle via Composer:

composer require webfactory/slug-validation-bundle

Enable the bundle:

<?php
// src/bundles.php

return [
    // ...
    Webfactory\SlugValidationBundle\WebfactorySlugValidationBundle::class => ['all' => true],
    // ...
];

Usage

Prerequisite: Sluggable object as controller action parameter

Declare your sluggable object as controller action parameter:

public function myAction(MyEntity $entity)
{
}

And configure it to be resolved before the controller action is called, e.g. via #[MapEntity] or @ParamConverter (deprecated).

Implement Sluggable

Provide the hint that the entity has a slug that can be validated by implementing \Webfactory\SlugValidationBundle\Bridge\SluggableInterface:

class MyEntity implements SluggableInterface
{
    public function getSlug(): ?string
    {
        return 'my-generated-slug';
    }
}

Add Slug Parameter to Routes

Declare a route that contains an entitySlug parameter and points to your action:

my_entity_route:
    path: /entity/{entitySlug}.{entity}
    defaults:
        _controller: MyBundle:MyController:my

That's it! Whenever a sluggable entity is used together with a slug parameter in a route this bundle will step in and perform a validation. If a slug is invalid, then a redirect to the same route with the corrected slug will be initiated.

Additional Information

Entity and slug parameters are matched by convention: The slug parameter must use the suffix Slug. For example the correct parameter name for a blogPost parameter is blogPostSlug.

If a route contains a sluggable entity but no slug parameter, then nothing will happen, so the usual Symfony behavior is not changed.

Slug Generation

If you are not sure how to create your slugs, then you might find cocur/slugify useful. A component that generates URL slugs from any string.

Simplified Routing

Passing slug values during route generation can be a tedious and error-prone task. webfactory/object-routing and webfactory/object-routing-bundle can ease that task by defining route construction rules directly with your entity:

/**
 * @ObjectRoute(type="my_object_route", name="my_entity_route", params={
 *     "entity": "id",
 *     "entitySlug": "slug"
 * })
 */
class MyEntity implements SluggableInterface
{
    public function getId(): int
    {
        // ...
    }

    public function getSlug(): ?string
    {
        // ...
    }

    // ...
}

When generating the URL, you don't have to deal with passing these parameters anymore (example in Twig):

{{ object_path('my_object_route', myEntityInstance) }}

Credits, Copyright and License

This project was started at webfactory GmbH, Bonn.

Copyright 2016-2025 webfactory GmbH, Bonn. Code released under the MIT license.


All versions of slug-validation-bundle with dependencies

PHP Build Version
Package Version
Requires php Version 8.0.*|8.1.*|8.2.*|8.3.*
symfony/config Version ^6.0|^7.0
symfony/dependency-injection Version ^6.0|^7.0
symfony/event-dispatcher Version ^6.0|^7.0
symfony/http-foundation Version ^6.0|^7.0
symfony/http-kernel Version ^6.0|^7.0
symfony/routing Version ^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package webfactory/slug-validation-bundle contains the following files

Loading the files please wait ....