All Projects → symfony-cmf → slugifier-api

symfony-cmf / slugifier-api

Licence: other
Provides a basic interface to implement for third party slugifiers packages

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to slugifier-api

standard-edition
The "Symfony CMF Standard Edition" distribution
Stars: ✭ 117 (+457.14%)
Mutual labels:  symfony-cmf
routing-auto-bundle
Adding automatic route generating on top of the symfony cmf routing
Stars: ✭ 14 (-33.33%)
Mutual labels:  symfony-cmf
block-bundle
Extends the SonataBlockBundle to integrate with PHPCR ODM
Stars: ✭ 20 (-4.76%)
Mutual labels:  symfony-cmf
menu-bundle
Extends the KnpMenuBundle to work with PHPCR ODM
Stars: ✭ 32 (+52.38%)
Mutual labels:  symfony-cmf
Slugify
Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.
Stars: ✭ 53 (+152.38%)
Mutual labels:  slugifier

Symfony CMF Slugifier API

Build Status Latest Stable Version Total Downloads

This package is part of the Symfony Content Management Framework (CMF) and licensed under the MIT License.

A "slugifier" is a function which transforms a string such as this into a URL-friendly string such-as-this. Slugifiers are also known as "urlizers".

This package does not contain a slugifier implementation, it provides a standard interface (SlugifierInterface) for use by third party slugifiers and a CallbackSlugifier that is capable of wrapping most non-implementing third-party slugifiers to the SlugifierInterface.

Requirements

Documentation

Perhaps the best way to document this simple component is with a demonstration. You have an event subscriber which slugifies the title of a blog post:

<?php

use Symfony\Cmf\Api\Slugifier\SlugifierInterface;

class FooSubscriber
{
    private $slugifier;

    public function __construct(SlugifierInterface $slugifier)
    {
        $this->slugifier = $slugifier;
    }

    public function onEntitySave(\Some\Event $event)
    {
         $entity = $event->getEntity();
         $entity->setSlug($this->slugifier->slugify($entity->getTitle());
    }
}

You can then inject either a slugifier which already implements the CMF SlugifierInterface or you can use non-implementing libraries using the CallbackSlugifier. Using non-implementing libraries is very easy, assume you want to use the aferrandini/urlizer package (which is also used by the RoutingAutoBundle), you can configure the CallbackSlugifier object to call the Ferrandini\Urlizer::urlize() method:

$slugifier = new CallbackSlugifier('Ferrandini\Urlizer::urlize');
$fooSubscriber = new FooSubscriber($slugifier);

By using the Slugifier package you decouple your application from the slugifier implementation.

See also:

FIG Proposal

We proposed this to FIG but unfortunately the proposal did not get enough interest. We would still be happy to contribute this to a PSR should the interest come up and deprecate this package in favor of the PSR one.

Contributing

Pull requests are welcome. Please see our CONTRIBUTING guide.

Unit and/or functional tests exist for this bundle. See the Testing documentation for a guide to running the tests.

Thanks to everyone who has contributed already.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].