本文整理汇总了PHP中Cocur\Slugify\Slugify::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Slugify::addRule方法的具体用法?PHP Slugify::addRule怎么用?PHP Slugify::addRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cocur\Slugify\Slugify
的用法示例。
在下文中一共展示了Slugify::addRule方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: customizeSlugEngine
/**
* @param \Cocur\Slugify\Slugify $engine
* @param string $attribute
* @return \Cocur\Slugify\Slugify
*/
public function customizeSlugEngine(Slugify $engine, $attribute)
{
$engine->addRule('e', 'a');
$engine->addRule('i', 'a');
$engine->addRule('o', 'a');
$engine->addRule('u', 'a');
return $engine;
}
示例2: getSlugEngine
protected function getSlugEngine()
{
$engine = new Slugify();
$engine->addRule('e', 'a');
$engine->addRule('i', 'a');
$engine->addRule('o', 'a');
$engine->addRule('u', 'a');
return $engine;
}
示例3: genSlug
/**
* @param $string
* @return string
*/
public static function genSlug($string)
{
// return $string;
//$accepted = implode(self::$MY_RULE);
//$replace_char = "/([^a-zA-Z0-9" . $accepted . "]|-)+/u";
//echo $replace_char;
$slug_engine = new Slugify();
//new Slugify($replace_char);
$slug_engine->addRules(self::$MY_RULE);
$slug_engine->addRule('#', '-sharp-');
$slug_engine->addRule('+', '-plus-');
return $slug_engine->slugify($string);
}
示例4: registerServices
/**
* @inheritdoc
*/
protected function registerServices(Application $app)
{
$config = $this->getConfig();
$app['slugify'] = $app->share(function ($app) use($config) {
if (!isset($config['regexp'])) {
$config['regexp'] = '/([^A-Za-z0-9]|-)+/';
}
if (!isset($config['lowercase'])) {
$config['lowercase'] = true;
}
$slugify = new Slugify($config['regexp'], array('lowercase' => $config['lowercase']));
foreach ($config['rules'] as $key => $value) {
$slugify->addRule($key, $value);
}
return $slugify;
});
}
示例5: getTurkishEngine
/**
* @param \Cocur\Slugify\Slugify $engine
*
* @return \Cocur\Slugify\Slugify
*/
protected function getTurkishEngine(Slugify $engine)
{
$engine->addRule('Ç', 'C');
$engine->addRule('Ğ', 'G');
$engine->addRule('İ', 'I');
$engine->addRule('Ş', 'S');
$engine->addRule('Ö', 'O');
$engine->addRule('Ü', 'U');
$engine->addRule('ğ', 'g');
$engine->addRule('ı', 'i');
$engine->addRule('ş', 's');
$engine->addRule('ö', 'o');
$engine->addRule('ü', 'u');
return $engine;
}
示例6: addRuleAddsRule
/**
* @test
* @covers Cocur\Slugify\Slugify::addRule()
* @covers Cocur\Slugify\Slugify::slugify()
*/
public function addRuleAddsRule()
{
$this->assertInstanceOf('Cocur\\Slugify\\Slugify', $this->slugify->addRule('X', 'y'));
$this->assertEquals('y', $this->slugify->slugify('X'));
}
示例7: addRule
/**
* Adds a custom rule to Slugify.
*
* @param string $character Character
* @param string $replacement Replacement character
* @return \Cocur\Slugify\Slugify
* @static
*/
public static function addRule($character, $replacement)
{
return \Cocur\Slugify\Slugify::addRule($character, $replacement);
}