From 61eae97e2ce79bc2b7e590ecf7439d2cd0ecc7dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=B9=E5=92=8C=E5=A5=B9=E7=9A=84=E7=8C=AB?= Date: Thu, 8 Aug 2019 23:24:50 +0800 Subject: [PATCH] fix "Undefined function camel_case()" (#93) --- src/ModelFilter.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ModelFilter.php b/src/ModelFilter.php index cfdba85..1711bd5 100644 --- a/src/ModelFilter.php +++ b/src/ModelFilter.php @@ -199,7 +199,24 @@ public function getFilterMethod($key) $methodName = str_replace('.', '', $this->drop_id ? preg_replace('/^(.*)_id$/', '$1', $key) : $key); // Convert key to camelCase? - return $this->camel_cased_methods ? camel_case($methodName) : $methodName; + return $this->camel_cased_methods ? $this->convertToCamelCase($methodName) : $methodName; + } + + /** + * Convert a string to camel case. + * + * @param $value + * @return string + */ + protected function convertToCamelCase($value) + { + if (function_exists('camel_case')) { + return camel_case($value); + } + + $value = ucwords(str_replace(['-', '_'], ' ', $value)); + + return lcfirst(str_replace(' ', '', $value)); } /**