Remvoving dependence on String class in Inflector::slug.

This commit is contained in:
jperras 2009-04-10 14:15:27 -04:00
parent d72dad581a
commit 7902f6838b

View file

@ -429,9 +429,8 @@ class Inflector extends Object {
* @link http://book.cakephp.org/view/572/Class-methods * @link http://book.cakephp.org/view/572/Class-methods
*/ */
function slug($string, $replacement = '_') { function slug($string, $replacement = '_') {
if (!class_exists('String')) { $quotedReplacement = preg_quote($replacement, '/');
require LIBS . 'string.php';
}
$map = array( $map = array(
'/à|á|å|â/' => 'a', '/à|á|å|â/' => 'a',
'/è|é|ê|ẽ|ë/' => 'e', '/è|é|ê|ẽ|ë/' => 'e',
@ -449,7 +448,7 @@ class Inflector extends Object {
'/ß/' => 'ss', '/ß/' => 'ss',
'/[^\w\s]/' => ' ', '/[^\w\s]/' => ' ',
'/\\s+/' => $replacement, '/\\s+/' => $replacement,
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '', sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
); );
return preg_replace(array_keys($map), array_values($map), $string); return preg_replace(array_keys($map), array_values($map), $string);
} }