Update Restler to 3.0RC6 (last bug fixes of branch v3)

This commit is contained in:
Laurent Destailleur 2019-10-08 11:14:53 +02:00
parent f9f8cf9627
commit 0cf014b01f
6 changed files with 93 additions and 49 deletions

View File

@ -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:

View File

@ -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)

View File

@ -1,4 +1,5 @@
<?php
namespace Luracast\Restler\Data;
use Luracast\Restler\CommentParser;
@ -25,7 +26,8 @@ class Validator implements iValidate
public static $exceptions = array();
public static $preFilters = array(
'*' => '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);

View File

@ -1,4 +1,5 @@
<?php
namespace Luracast\Restler\Format;
use Luracast\Restler\Data\Obj;
@ -127,9 +128,9 @@ class JsonFormat extends Format
public function decode($data)
{
if(empty($data)){
return null;
}
if (empty($data)) {
return null;
}
$options = 0;
if (self::$bigIntAsString) {
@ -147,7 +148,7 @@ class JsonFormat extends Format
}
try {
$decoded = json_decode($data, $options);
$decoded = json_decode($data, true, 512, $options);
$this->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);
}
}
}

View File

@ -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',

View File

@ -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);
}
}