File tree Expand file tree Collapse file tree 8 files changed +224
-0
lines changed Expand file tree Collapse file tree 8 files changed +224
-0
lines changed Original file line number Diff line number Diff line change 1+ phpunit.xml
2+ composer.lock
3+ vendor
Original file line number Diff line number Diff line change 1+ language : php
2+
3+ php :
4+ - 5.3
5+ - 5.4
6+ - 5.5
7+ - 5.6
8+ - 7.0
9+ - hhvm
10+
11+ sudo : false
12+
13+ before_install : phpenv config-rm xdebug.ini || true
14+
15+ install : composer dump-autoload
16+
17+ script : phpunit
18+
19+ notifications :
20+ irc : " irc.freenode.org#symfony-cmf"
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony CMF package.
5+ *
6+ * (c) 2016 Symfony CMF
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Cmf \Api \Slugifier ;
13+
14+ /**
15+ * Slugifier service which uses a callback.
16+ *
17+ * @author Daniel Leech <daniel@dantleech.com>
18+ */
19+ class CallbackSlugifier implements SlugifierInterface
20+ {
21+ protected $ callback ;
22+
23+ /**
24+ * @param callable $callback
25+ */
26+ public function __construct ($ callback )
27+ {
28+ if (!is_callable ($ callback )) {
29+ throw new \InvalidArgumentException (sprintf ('Expected a valid callable as callback, %s given. ' , gettype ($ callback )));
30+ }
31+
32+ $ this ->callback = $ callback ;
33+ }
34+
35+ /**
36+ * {@inheritdoc}
37+ */
38+ public function slugify ($ string )
39+ {
40+ return call_user_func ($ this ->callback , $ string );
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ # Symfony CMF Slugifier API
2+
3+ [ ![ Build Status] ( https://travis-ci.org/symfony-cmf/slugifier-api.svg?branch=master )] ( https://travis-ci.org/symfony-cmf/slugifier-api )
4+ [ ![ Latest Stable Version] ( https://poser.pugx.org/symfony-cmf/slugifier-api/version.png )] ( https://packagist.org/packages/symfony-cmf/slugifier-api )
5+ [ ![ Total Downloads] ( https://poser.pugx.org/symfony-cmf/slugifier-api/d/total.png )] ( https://packagist.org/packages/symfony-cmf/slugifier-api )
6+
7+ This package is part of the [ Symfony Content Management Framework (CMF)] ( http://cmf.symfony.com/ )
8+ and licensed under the [ MIT License] ( LICENSE ) .
9+
10+ The Slugifier API provides a basic interface to use for third party slugifiers.
11+ Besides this, it comes with a usefull ` CallbackSlugifier ` which is capable of
12+ handling most third party slugifiers.
13+
14+
15+ ## Requirements
16+
17+ * See also the ` require ` section of [ composer.json] ( composer.json )
18+
19+
20+ ## Documentation
21+
22+ For the install guide and reference, see:
23+
24+ * Slugifier documentation
25+
26+ See also:
27+
28+ * [ All Symfony CMF documentation] ( http://symfony.com/doc/master/cmf/index.html ) - complete Symfony CMF reference
29+ * [ Symfony CMF Website] ( http://cmf.symfony.com/ ) - introduction, live demo, support and community links
30+
31+
32+ ## Contributing
33+
34+ Pull requests are welcome. Please see our
35+ [ CONTRIBUTING] ( https://github.com/symfony-cmf/symfony-cmf/blob/master/CONTRIBUTING.md )
36+ guide.
37+
38+ Unit and/or functional tests exist for this bundle. See the
39+ [ Testing documentation] ( http://symfony.com/doc/master/cmf/components/testing.html )
40+ for a guide to running the tests.
41+
42+ Thanks to
43+ [ everyone who has contributed] ( https://github.com/symfony-cmf/RoutingBundle/contributors ) already.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony CMF package.
5+ *
6+ * (c) 2016 Symfony CMF
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Cmf \Api \Slugifier ;
13+
14+ /**
15+ * Slugifier interface.
16+ *
17+ * @author Daniel Leech <daniel@dantleech.com>
18+ */
19+ interface SlugifierInterface
20+ {
21+ /**
22+ * Return a slugified (or urlized) representation of a given string.
23+ *
24+ * @param string $string
25+ *
26+ * @return string
27+ */
28+ public function slugify ($ string );
29+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony CMF package.
5+ *
6+ * (c) 2011-2015 Symfony CMF
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Cmf \Api \Slugifier \Tests ;
13+
14+ use Symfony \Cmf \Api \Slugifier \CallbackSlugifier ;
15+
16+ class CallbackSlugifierTest extends \PHPUnit_Framework_TestCase
17+ {
18+ private $ slugifier ;
19+
20+ protected function setUp ()
21+ {
22+ $ this ->slugifier = new CallbackSlugifier (
23+ 'Symfony\Cmf\Api\Slugifier\Tests\CallbackSlugifierTest::slugify '
24+ );
25+ }
26+
27+ public function testSlugify ()
28+ {
29+ $ this ->assertEquals ('this-is-slugified ' , $ this ->slugifier ->slugify ('this is slugified ' ));
30+ }
31+
32+ public static function slugify ($ val )
33+ {
34+ return str_replace (' ' , '- ' , $ val );
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " symfony-cmf/slugifier-api" ,
3+ "description" : " Provides a basic slugifier interface" ,
4+ "keywords" : [" slugify" ],
5+ "homepage" : " http://cmf.symfony.com" ,
6+ "license" : " MIT" ,
7+ "authors" : [
8+ {
9+ "name" : " Symfony CMF Community" ,
10+ "homepage" : " https://github.com/symfony-cmf/RoutingBundle/contributors"
11+ }
12+ ],
13+ "require" : {
14+ "php" : " ^5.3.9|^7.0"
15+ },
16+ "autoload" : {
17+ "psr-4" : {
18+ "Symfony\\ Cmf\\ Api\\ Slugifier\\ " : " "
19+ }
20+ },
21+ "extra" : {
22+ "branch-alias" : {
23+ "dev-master" : " 1.0-dev"
24+ }
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+
3+ <!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
4+ <phpunit
5+ colors =" true"
6+ bootstrap =" vendor/autoload.php"
7+ >
8+
9+ <testsuites >
10+ <testsuite name =" Symfony Slugifier Api Test Suite" >
11+ <directory >./Tests/</directory >
12+ </testsuite >
13+ </testsuites >
14+
15+ <filter >
16+ <whitelist addUncoveredFilesFromWhitelist =" true" >
17+ <directory >.</directory >
18+ <exclude >
19+ <directory >Tests/</directory >
20+ <directory >vendor/</directory >
21+ </exclude >
22+ </whitelist >
23+ </filter >
24+
25+ </phpunit >
You can’t perform that action at this time.
0 commit comments