Skip to content

Commit

Permalink
Update Restler to 3.0RC6 (last bug fixes of branch v3)
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 8, 2019
1 parent f9f8cf9 commit 0cf014b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 49 deletions.
15 changes: 1 addition & 14 deletions dev/dolibarr_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
33 changes: 20 additions & 13 deletions htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ private function loadAliases($className)
* @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;
Expand All @@ -291,11 +291,20 @@ private function loadLastResort($className, $loader = null) {
*
* @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;
}

Expand All @@ -307,10 +316,8 @@ private function loadThisLoader($className, $loader) {
*/
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Luracast\Restler\Data;

use Luracast\Restler\CommentParser;
Expand All @@ -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',
Expand Down Expand Up @@ -59,6 +61,29 @@ public static function alpha($input, ValidationInfo $info = null)
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.
*
Expand Down Expand Up @@ -141,7 +166,7 @@ public static function hex($input, ValidationInfo $info = null)
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.');
}
Expand Down Expand Up @@ -204,8 +229,9 @@ public static function email($input, ValidationInfo $info = null)
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');
}
Expand Down Expand Up @@ -471,8 +497,7 @@ public static function validate($input, ValidationInfo $info, $full = null)
}

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;
}
Expand Down Expand Up @@ -524,6 +549,7 @@ public static function validate($input, ValidationInfo $info, $full = null)
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;
Expand Down Expand Up @@ -555,22 +581,41 @@ public static function validate($input, ValidationInfo $info, $full = null)

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' &&
Expand Down Expand Up @@ -609,6 +654,8 @@ public static function validate($input, ValidationInfo $info, $full = null)
$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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Luracast\Restler\Format;

use Luracast\Restler\Data\Obj;
Expand Down Expand Up @@ -127,9 +128,9 @@ function ($matches) {

public function decode($data)
{
if(empty($data)){
return null;
}
if (empty($data)) {
return null;
}

$options = 0;
if (self::$bigIntAsString) {
Expand All @@ -147,7 +148,7 @@ public function decode($data)
}

try {
$decoded = json_decode($data, $options);
$decoded = json_decode($data, true, 512, $options);
$this->handleJsonError();
} catch (\RuntimeException $e) {
throw new RestException(400, $e->getMessage());
Expand All @@ -157,13 +158,13 @@ public function decode($data)
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
*/
Expand Down Expand Up @@ -271,7 +272,7 @@ protected function handleJsonError()
}

if (isset($message)) {
throw new \RuntimeException('Error encoding/decoding JSON: '. $message);
throw new \RuntimeException('Error encoding/decoding JSON: ' . $message);
}
}
}
6 changes: 4 additions & 2 deletions htdocs/includes/restler/framework/Luracast/Restler/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ 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',
'ApcCache' => 'Luracast\Restler\ApcCache',
'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',

Expand Down
4 changes: 2 additions & 2 deletions htdocs/includes/restler/framework/Luracast/Restler/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ public static function getShortName($className)
// @CHANGE LDR
if (! is_string($className)) return '';
//var_dump($className);

$className = explode('\\', $className);
$className = explode('\\', $className);
return end($className);
}
}
Expand Down

0 comments on commit 0cf014b

Please sign in to comment.