Skip to content

Commit

Permalink
Use Symfony mb_* polyfill for string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Dec 17, 2016
1 parent a5ec42a commit dd90686
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Configuration/ActionConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private function isValidMethodName($name)
*/
private function humanizeString($content)
{
return ucfirst(trim(strtolower(preg_replace(array('/([A-Z])/', '/[_\s]+/'), array('_$1', ' '), $content))));
return ucfirst(trim(mb_strtolower(preg_replace(array('/([A-Z])/', '/[_\s]+/'), array('_$1', ' '), $content))));
}

private function reorderArrayItems(array $originalArray, array $newKeyOrder)
Expand Down
4 changes: 2 additions & 2 deletions Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function editAction()
$entity = $easyadmin['item'];

if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) {
$newValue = 'true' === strtolower($this->request->query->get('newValue'));
$newValue = 'true' === mb_strtolower($this->request->query->get('newValue'));
$fieldsMetadata = $this->entity['list']['fields'];

if (!isset($fieldsMetadata[$property]) || 'toggle' !== $fieldsMetadata[$property]['dataType']) {
Expand Down Expand Up @@ -589,7 +589,7 @@ protected function createEntityFormBuilder($entity, $view)

$formType = LegacyFormHelper::useLegacyFormComponent() ? 'easyadmin' : 'JavierEguiluz\\Bundle\\EasyAdminBundle\\Form\\Type\\EasyAdminFormType';

return $this->get('form.factory')->createNamedBuilder(strtolower($this->entity['name']), $formType, $entity, $formOptions);
return $this->get('form.factory')->createNamedBuilder(mb_strtolower($this->entity['name']), $formType, $entity, $formOptions);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Form/Type/EasyAdminFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function getAttributesNormalizer()
{
return function (Options $options, $value) {
return array_replace(array(
'id' => sprintf('%s-%s-form', $options['view'], strtolower($options['entity'])),
'id' => sprintf('%s-%s-form', $options['view'], mb_strtolower($options['entity'])),
), $value);
};
}
Expand Down
2 changes: 1 addition & 1 deletion Search/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function createSearchQueryBuilder(array $entityConfig, $searchQuery, $sor
$queryBuilder->orWhere(sprintf('entity.%s IN (:words_query)', $name));
$queryParameters['words_query'] = explode(' ', $searchQuery);
} elseif ($isTextField) {
$searchQuery = strtolower($searchQuery);
$searchQuery = mb_strtolower($searchQuery);

$queryBuilder->orWhere(sprintf('LOWER(entity.%s) LIKE :fuzzy_query', $name));
$queryParameters['fuzzy_query'] = '%'.$searchQuery.'%';
Expand Down
28 changes: 7 additions & 21 deletions Twig/EasyAdminTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,31 +287,17 @@ public function truncateText(\Twig_Environment $env, $value, $length = 64, $pres
$value = '';
}

if (function_exists('mb_get_info')) {
if (mb_strlen($value, $env->getCharset()) > $length) {
if ($preserve) {
// If breakpoint is on the last word, return the value without separator.
if (false === ($breakpoint = mb_strpos($value, ' ', $length, $env->getCharset()))) {
return $value;
}

$length = $breakpoint;
}

return rtrim(mb_substr($value, 0, $length, $env->getCharset())).$separator;
}

return $value;
}

if (strlen($value) > $length) {
if (mb_strlen($value, $env->getCharset()) > $length) {
if ($preserve) {
if (false !== ($breakpoint = strpos($value, ' ', $length))) {
$length = $breakpoint;
// If breakpoint is on the last word, return the value without separator.
if (false === ($breakpoint = mb_strpos($value, ' ', $length, $env->getCharset()))) {
return $value;
}

$length = $breakpoint;
}

return rtrim(substr($value, 0, $length)).$separator;
return rtrim(mb_substr($value, 0, $length, $env->getCharset())).$separator;
}

return $value;
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"symfony/framework-bundle" : "~2.3|~3.0",
"symfony/http-foundation" : "~2.3|~3.0",
"symfony/http-kernel" : "~2.3|~3.0",
"symfony/polyfill-mbstring" : "^1.0",
"symfony/property-access" : "~2.3|~3.0",
"symfony/security-bundle" : "~2.3|~3.0",
"symfony/twig-bridge" : "^2.3.4|~3.0",
Expand Down

0 comments on commit dd90686

Please sign in to comment.