Git Product home page Git Product logo

slugifier-api's Introduction

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.

slugifier-api's People

Contributors

alexander-schranz avatar dantleech avatar dbu avatar wouterj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

slugifier-api's Issues

documentation?

the readme has a bullet point "Slugifier documentation" which is not linked to anywhere. we should provide a bit of documentation. given the nature of this thing as simply a contract hopefully to be replaced by a PSR one day, we could maybe simply include the documentation in the README and link from the cmf docs to the README in the places where people need that information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.