Skip to content

Commit 7950884

Browse files
committed
use preg_replace_callback as /e modifier deprecated in php 5.5
1 parent 5b55945 commit 7950884

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Twig/Extension/NetworkingHelperExtension.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ public function getFieldValue($object, $fieldName, $method = null)
751751
$getters[] = $method;
752752
}
753753

754-
$camelizedFieldName = self::camelize($fieldName);
754+
$camelizedFieldName = self::camelize($fieldName, true);
755755
$getters[] = 'get' . $camelizedFieldName;
756756
$getters[] = 'is' . $camelizedFieldName;
757757

@@ -768,16 +768,18 @@ public function getFieldValue($object, $fieldName, $method = null)
768768
* Camelize a string
769769
*
770770
* @static
771-
* @param string $property
772-
* @return string
771+
* @param $str
772+
* @param bool $firstToCapital
773+
* @return mixed
773774
*/
774-
public static function camelize($property)
775+
public static function camelize($str, $firstToCapital = false)
775776
{
776-
return preg_replace(
777-
array('/(^|_| )+(.)/e', '/\.(.)/e'),
778-
array("strtoupper('\\2')", "'_'.strtoupper('\\1')"),
779-
$property
780-
);
777+
if($firstToCapital) {
778+
$str[0] = strtoupper($str[0]);
779+
}
780+
return preg_replace_callback('/_([a-z])/', function($s){
781+
return strtoupper($s[1]);
782+
}, $str);
781783
}
782784

783785
/**

0 commit comments

Comments
 (0)