diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 35a2d6f6418..668db97a0c7 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -137,20 +137,7 @@ with: RESTLER: -------- - -* Add 2 lines into file AutoLoader.php to complete function - private function alias($className, $currentClass) - { - ... -to get - - private function alias($className, $currentClass) - { - if ($className == 'Luracast\Restler\string') return; - if ($className == 'Luracast\Restler\mixed') return; - ... - -Change also content of file htdocs/includes/restler/framework/Luracast/Restler/explorer/index.html +Change content of file htdocs/includes/restler/framework/Luracast/Restler/explorer/index.html +With swagger 2: diff --git a/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php b/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php index 300eadb0f70..eff8bb61f29 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php @@ -263,13 +263,13 @@ class AutoLoader * @return bool false unless className now exists */ private function loadLastResort($className, $loader = null) { - // @CHANGE LDR Add protection to avoid conflict with other autoloader - /*print 'Try to load '.$className."\n"; - if (in_array($className, array('Google_Client'))) - { - return false; - }*/ - $loaders = array_unique(static::$rogueLoaders); + // @CHANGE LDR Add protection to avoid conflict with other autoloader + /*print 'Try to load '.$className."\n"; + if (in_array($className, array('Google_Client'))) + { + return false; + }*/ + $loaders = array_unique(static::$rogueLoaders); if (isset($loader)) { if (false === array_search($loader, $loaders)) static::$rogueLoaders[] = $loader; @@ -291,11 +291,20 @@ class AutoLoader * * @return bool false unless className exists */ - private function loadThisLoader($className, $loader) { - if (is_callable($loader) - && false !== $file = $loader($className) - && $this->exists($className, $loader)) + private function loadThisLoader($className, $loader) + { + if (is_array($loader) + && is_callable($loader)) { + $b = new $loader[0]; + if (false !== $file = $b::$loader[1]($className) + && $this->exists($className, $b::$loader[1])) { return $file; + } + } elseif (is_callable($loader) + && false !== $file = $loader($className) + && $this->exists($className, $loader)) { + return $file; + } return false; } @@ -307,10 +316,8 @@ class AutoLoader */ private function alias($className, $currentClass) { - // @CHANGE LDR if ($className == 'Luracast\Restler\string') return; if ($className == 'Luracast\Restler\mixed') return; - if ($className != $currentClass && false !== strpos($className, $currentClass)) if (!class_exists($currentClass, false) diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php index 28202efb7ad..c98a17a62d6 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php @@ -1,4 +1,5 @@ 'trim', + //'*' => 'some_global_filter', //applied to all parameters + 'string' => 'trim', //apply filter function by type (string) //'string' => 'strip_tags', //'string' => 'htmlspecialchars', //'int' => 'abs', @@ -59,6 +61,29 @@ class Validator implements iValidate throw new Invalid('Expecting only alphabetic characters.'); } + /** + * Validate UUID strings. + * + * Check that given value contains only alpha numeric characters and the length is 36 chars. + * + * @param $input + * @param ValidationInfo $info + * + * @return string + * + * @throws Invalid + */ + public static function uuid($input, ValidationInfo $info = null) + { + if (is_string($input) && preg_match( + '/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', + $input + )) { + return strtolower($input); + } + throw new Invalid('Expecting a Universally Unique IDentifier (UUID) string.'); + } + /** * Validate alpha numeric characters. * @@ -141,7 +166,7 @@ class Validator implements iValidate public static function color($input, ValidationInfo $info = null) { if (preg_match('/^#[a-f0-9]{6}$/i', $input)) { - return $input; + return $input; } throw new Invalid('Expecting color as hexadecimal digits.'); } @@ -204,8 +229,9 @@ class Validator implements iValidate public static function ip($input, ValidationInfo $info = null) { $r = filter_var($input, FILTER_VALIDATE_IP); - if ($r) + if ($r) { return $r; + } throw new Invalid('Expecting IP address in IPV6 or IPV4 format'); } @@ -471,8 +497,7 @@ class Validator implements iValidate } if (method_exists($class = get_called_class(), $info->type) && $info->type != 'validate') { - if(!$info->required && empty($input)) - { + if (!$info->required && empty($input)) { //optional parameter with a empty value assume null return null; } @@ -524,6 +549,7 @@ class Validator implements iValidate case 'string' : case 'password' : //password fields with string case 'search' : //search field with string + if (is_bool($input)) $input = $input ? 'true' : 'false'; if (!is_string($input)) { $error .= '. Expecting alpha numeric value'; break; @@ -555,22 +581,41 @@ class Validator implements iValidate case 'bool': case 'boolean': - if ($input === 'true' || $input === true) return true; - if (is_numeric($input)) return $input > 0; - return false; - + if (is_bool($input)) { + return $input; + } + if (is_numeric($input)) { + if ($input == 1) { + return true; + } + if ($input == 0) { + return false; + } + } elseif (is_string($input)) { + switch (strtolower($input)) { + case 'true': + return true; + case 'false': + return false; + } + } + if ($info->fix) { + return $input ? true : false; + } + $error .= '. Expecting boolean value'; + break; case 'array': if ($info->fix && is_string($input)) { $input = explode(CommentParser::$arrayDelimiter, $input); } if (is_array($input)) { $contentType = - Util::nestedValue($info, 'contentType') ? : null; + Util::nestedValue($info, 'contentType') ?: null; if ($info->fix) { if ($contentType == 'indexed') { $input = $info->filterArray($input, true); } elseif ($contentType == 'associative') { - $input = $info->filterArray($input, true); + $input = $info->filterArray($input, false); } } elseif ( $contentType == 'indexed' && @@ -609,6 +654,8 @@ class Validator implements iValidate $name = $info->name; $info->type = $contentType; unset($info->contentType); + unset($info->min); + unset($info->max); foreach ($input as $key => $chinput) { $info->name = "{$name}[$key]"; $input[$key] = static::validate($chinput, $info); diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php index 28dfd560969..00c763e8ff5 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php @@ -1,4 +1,5 @@ handleJsonError(); } catch (\RuntimeException $e) { throw new RestException(400, $e->getMessage()); @@ -157,13 +158,13 @@ class JsonFormat extends Format throw new RestException(400, 'Error parsing JSON'); } - return Obj::toArray($decoded); + return $decoded; //Obj::toArray($decoded); } /** * Pretty print JSON string * - * @param string $json + * @param string $json * * @return string formatted json */ @@ -271,7 +272,7 @@ class JsonFormat extends Format } if (isset($message)) { - throw new \RuntimeException('Error encoding/decoding JSON: '. $message); + throw new \RuntimeException('Error encoding/decoding JSON: ' . $message); } } } diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Scope.php b/htdocs/includes/restler/framework/Luracast/Restler/Scope.php index fd4b41ff98d..251262017c3 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Scope.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Scope.php @@ -44,7 +44,9 @@ class Scope //API classes 'Resources' => 'Luracast\Restler\Resources', - 'Explorer' => 'Luracast\Restler\Explorer', + 'Explorer' => 'Luracast\Restler\Explorer\v2\Explorer', + 'Explorer1' => 'Luracast\Restler\Explorer\v1\Explorer', + 'Explorer2' => 'Luracast\Restler\Explorer\v2\Explorer', //Cache classes 'HumanReadableCache' => 'Luracast\Restler\HumanReadableCache', @@ -52,7 +54,7 @@ class Scope 'MemcacheCache' => 'Luracast\Restler\MemcacheCache', //Utility classes - 'Obj' => 'Luracast\Restler\Data\Obj', + 'Object' => 'Luracast\Restler\Data\Obj', 'Text' => 'Luracast\Restler\Data\Text', 'Arr' => 'Luracast\Restler\Data\Arr', diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Util.php b/htdocs/includes/restler/framework/Luracast/Restler/Util.php index e7324a3a620..9674550814f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Util.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Util.php @@ -229,8 +229,8 @@ class Util // @CHANGE LDR if (! is_string($className)) return ''; //var_dump($className); - - $className = explode('\\', $className); + + $className = explode('\\', $className); return end($className); } }