/**
  * Gets a builded slugifier to sanitize strings.
  *
  * @param boolean $renew whether to reload the slugifier.
  * @return Slugifier
  */
 protected static function getSlugifier($renew = false)
 {
     if (self::$_slugifier === null || $renew) {
         $factory = new RangeFactory();
         self::$_slugifier = new Slugifier();
         foreach ($factory->getRangesFromScript(RangeScript::ALL()) as $range) {
             self::$_slugifier->handleRange($range, true);
         }
         self::$_slugifier->setFlag(Flag::IGNORE_NONSTRINGS, true);
         self::$_slugifier->setFlag(Flag::IGNORE_NOTLOADED, true);
     }
     return self::$_slugifier;
 }
예제 #2
0
<?php

use Anastaszor\Slugify\Slugifier;
use Anastaszor\Slugify\RangeFactory;
use Anastaszor\Slugify\RangeScript;
echo "This is a test script to tests the slugification results of a given string.\n";
echo "Give a string :\n";
$input = fgets(STDIN);
echo "You gave : " . $input . "\n";
require __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$slugifier = new Slugifier();
$factory = new RangeFactory();
foreach ($factory->getRangesFromScript(RangeScript::ALL()) as $range) {
    $slugifier->handleRange($range, true);
}
echo "Result: " . $slugifier->slugify($input);
echo "\n";
echo "Script ending.";
예제 #3
0
 /**
  * Specific test method. This slugifies the $actual value and compares it
  * to the expected value.
  *
  * @param string $expected
  * @param string $actual
  */
 public function assertSlug($expected, $actual)
 {
     $slug = $this->_slugifier->slugify($actual);
     $this->assertEquals($expected, $slug);
 }