mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX Update Restler API to 3.1.1 to fix error with php8
This commit is contained in:
parent
9007e7be2a
commit
93d309cdbc
|
|
@ -229,11 +229,21 @@ Change content of file htdocs/includes/restler/framework/Luracast/Restler/explor
|
|||
public static function getShortName($className)
|
||||
{
|
||||
// @CHANGE LDR
|
||||
if (! is_string($className)) return;
|
||||
if (!is_string($className)) return;
|
||||
//var_dump($className);
|
||||
|
||||
|
||||
|
||||
* Add line into Data/Text.php to complete function
|
||||
|
||||
public static function endsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
// @CHANGE LDR
|
||||
if (!is_string($haystack)) return false;
|
||||
|
||||
|
||||
PARSEDOWN
|
||||
---------
|
||||
|
||||
|
|
|
|||
|
|
@ -707,7 +707,7 @@ class Documents extends DolibarrApi
|
|||
|
||||
if (!empty($createdirifnotexists)) {
|
||||
if (dol_mkdir($upload_dir) < 0) { // needed by products
|
||||
throw new RestException(500, 'Error while trying to create directory.');
|
||||
throw new RestException(500, 'Error while trying to create directory '.$upload_dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class Login
|
|||
}
|
||||
|
||||
// Generate token for user
|
||||
$token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY, 1);
|
||||
$token = dol_hash($login.uniqid().(empty($conf->global->MAIN_API_KEY)?'':$conf->global->MAIN_API_KEY), 1);
|
||||
|
||||
// We store API token into database
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Luracast\Restler\iCache;
|
|||
* @copyright 2013 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class ApcCache implements iCache
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Luracast\Restler {
|
|||
* @subpackage helper
|
||||
* @author Nick Lombard <github@jigsoft.co.za>
|
||||
* @copyright 2012 Luracast
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class AutoLoader
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Luracast\Restler;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -14,7 +15,7 @@ use Luracast\Restler\Data\Text;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class CommentParser
|
||||
{
|
||||
|
|
@ -55,8 +56,8 @@ class CommentParser
|
|||
* @var array annotations that support array value
|
||||
*/
|
||||
public static $allowsArrayValue = array(
|
||||
'choice' => true,
|
||||
'select' => true,
|
||||
'choice' => true,
|
||||
'select' => true,
|
||||
'properties' => true,
|
||||
);
|
||||
|
||||
|
|
@ -220,7 +221,7 @@ class CommentParser
|
|||
*/
|
||||
private function parseParam($param, array $value, array $embedded)
|
||||
{
|
||||
$data = & $this->_data;
|
||||
$data = &$this->_data;
|
||||
$allowMultiple = false;
|
||||
switch ($param) {
|
||||
case 'param' :
|
||||
|
|
@ -237,7 +238,7 @@ class CommentParser
|
|||
$value = $this->formatReturn($value);
|
||||
break;
|
||||
case 'class' :
|
||||
$data = & $data[$param];
|
||||
$data = &$data[$param];
|
||||
list ($param, $value) = $this->formatClass($value);
|
||||
break;
|
||||
case 'access' :
|
||||
|
|
@ -294,7 +295,7 @@ class CommentParser
|
|||
+= $data[$param][self::$embeddedDataName];
|
||||
}
|
||||
if (!is_array($data[$param])) {
|
||||
$data[$param] = array('description' => (string) $data[$param]);
|
||||
$data[$param] = array('description' => (string)$data[$param]);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$data[$param] = $value + $data[$param];
|
||||
|
|
@ -320,19 +321,24 @@ class CommentParser
|
|||
$data['pattern'] = $matches[2];
|
||||
}
|
||||
while (preg_match('/{@(\w+)\s?([^}]*)}/ms', $subject, $matches)) {
|
||||
$name = $matches[1];
|
||||
$value = $matches[2];
|
||||
$subject = str_replace($matches[0], '', $subject);
|
||||
if ($matches[1] == 'pattern') {
|
||||
if ($name == 'pattern') {
|
||||
throw new Exception('Inline pattern tag should follow {@pattern /REGEX_PATTERN_HERE/} format and can optionally include PCRE modifiers following the ending `/`');
|
||||
} elseif (isset(static::$allowsArrayValue[$matches[1]])) {
|
||||
$matches[2] = explode(static::$arrayDelimiter, $matches[2]);
|
||||
} elseif ($matches[2] == 'true' || $matches[2] == 'false') {
|
||||
$matches[2] = $matches[2] == 'true';
|
||||
} elseif ($matches[2] == '') {
|
||||
$matches[2] = true;
|
||||
} elseif ($matches[1] == 'required') {
|
||||
$matches[2] = explode(static::$arrayDelimiter, $matches[2]);
|
||||
} elseif (isset(static::$allowsArrayValue[$name])) {
|
||||
$value = explode(static::$arrayDelimiter, $value);
|
||||
} elseif ($value == 'true' || $value == 'false') {
|
||||
$value = $value == 'true';
|
||||
} elseif ($value == '') {
|
||||
$value = true;
|
||||
} elseif ($name == 'required') {
|
||||
$value = explode(static::$arrayDelimiter, $value);
|
||||
}
|
||||
$data[$matches[1]] = $matches[2];
|
||||
if (defined('Luracast\\Restler\\UI\\HtmlForm::'.$name)) {
|
||||
$value = constant($value);
|
||||
}
|
||||
$data[$name] = $value;
|
||||
}
|
||||
|
||||
while (preg_match(self::$embeddedDataPattern, $subject, $matches)) {
|
||||
|
|
@ -340,9 +346,9 @@ class CommentParser
|
|||
$str = $matches[self::$embeddedDataIndex];
|
||||
if (isset ($this->restler)
|
||||
&& self::$embeddedDataIndex > 1
|
||||
&& !empty ($matches[1])
|
||||
&& !empty ($name)
|
||||
) {
|
||||
$extension = $matches[1];
|
||||
$extension = $name;
|
||||
$formatMap = $this->restler->getFormatMap();
|
||||
if (isset ($formatMap[$extension])) {
|
||||
/**
|
||||
|
|
@ -397,15 +403,15 @@ class CommentParser
|
|||
{
|
||||
$code = 500;
|
||||
$exception = 'Exception';
|
||||
if(count($value)>1){
|
||||
if (count($value) > 1) {
|
||||
$v1 = $value[0];
|
||||
$v2 = $value[1];
|
||||
if(is_numeric($v1)){
|
||||
if (is_numeric($v1)) {
|
||||
$code = $v1;
|
||||
$exception = $v2;
|
||||
array_shift($value);
|
||||
array_shift($value);
|
||||
} elseif(is_numeric($v2)){
|
||||
} elseif (is_numeric($v2)) {
|
||||
$code = $v2;
|
||||
$exception = $v1;
|
||||
array_shift($value);
|
||||
|
|
@ -414,17 +420,17 @@ class CommentParser
|
|||
$exception = $v1;
|
||||
array_shift($value);
|
||||
}
|
||||
} elseif(count($value) && is_numeric($value[0])) {
|
||||
} elseif (count($value) && is_numeric($value[0])) {
|
||||
$code = $value[0];
|
||||
array_shift($value);
|
||||
}
|
||||
$message = implode(' ', $value);
|
||||
if(!isset(RestException::$codes[$code])){
|
||||
if (!isset(RestException::$codes[$code])) {
|
||||
$code = 500;
|
||||
} elseif(empty($message)){
|
||||
} elseif (empty($message)) {
|
||||
$message = RestException::$codes[$code];
|
||||
}
|
||||
return compact('code','message','exception');
|
||||
return compact('code', 'message', 'exception');
|
||||
}
|
||||
|
||||
private function formatClass(array $value)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Compose implements iCompose
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class ApiMethodInfo extends ValueObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Arr
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Exception;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Invalid extends Exception
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Obj
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,87 +10,91 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Text
|
||||
{
|
||||
/**
|
||||
* Given haystack contains the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
* @param bool $caseSensitive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function contains($haystack, $needle, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needle))
|
||||
return true;
|
||||
return $caseSensitive
|
||||
? strpos($haystack, $needle) !== false
|
||||
: stripos($haystack, $needle) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given haystack begins with the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function beginsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
return (substr($haystack, 0, $length) === $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given haystack ends with the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function endsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert camelCased or underscored string in to a title
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title($name)
|
||||
{
|
||||
return
|
||||
ucwords(
|
||||
preg_replace(
|
||||
array('/(?<=[^A-Z])([A-Z])/', '/(?<=[^0-9])([0-9])/', '/([_-])/', '/[^a-zA-Z0-9\s]|\s\s+/'),
|
||||
array(' $0', ' $0', ' ', ' '),
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert given string to be used as a slug or css class
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public static function slug($name)
|
||||
{
|
||||
return preg_replace('/[^a-zA-Z]+/', '-', strtolower(strip_tags($name)));
|
||||
}
|
||||
/**
|
||||
* Given haystack contains the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
* @param bool $caseSensitive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function contains($haystack, $needle, $caseSensitive = true)
|
||||
{
|
||||
if (empty($needle))
|
||||
return true;
|
||||
return $caseSensitive
|
||||
? strpos($haystack, $needle) !== false
|
||||
: stripos($haystack, $needle) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given haystack begins with the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function beginsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
return (substr($haystack, 0, $length) === $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given haystack ends with the needle or not?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function endsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @CHANGE LDR
|
||||
if (!is_string($haystack)) return false;
|
||||
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert camelCased or underscored string in to a title
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title($name)
|
||||
{
|
||||
return
|
||||
ucwords(
|
||||
preg_replace(
|
||||
array('/(?<=[^A-Z])([A-Z])/', '/(?<=[^0-9])([0-9])/', '/([_-])/', '/[^a-zA-Z0-9\s]|\s\s+/'),
|
||||
array(' $0', ' $0', ' ', ' '),
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert given string to be used as a slug or css class
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public static function slug($name)
|
||||
{
|
||||
return preg_replace('/[^a-zA-Z]+/', '-', strtolower(strip_tags($name)));
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class ValidationInfo implements iValueObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Validator implements iValidate
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class ValueObject implements iValueObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iValidate {
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Data;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iValueObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Luracast\Restler\Data\Validator;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Defaults
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
use Closure;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Luracast\Restler\RestException;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class RateLimit implements iFilter, iUseAuthentication
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use ArrayAccess;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Flash implements ArrayAccess
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use ZendAmf\Parser\OutputStream;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class AmfFormat extends DependentFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Luracast\Restler\RestException;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class CsvFormat extends Format implements iDecodeStream
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
abstract class Format implements iFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Luracast\Restler\Format;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -6,8 +7,8 @@ use Illuminate\Events\Dispatcher;
|
|||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\View\Compilers\BladeCompiler;
|
||||
use Illuminate\View\Engines\CompilerEngine;
|
||||
use Illuminate\View\Engines\PhpEngine;
|
||||
use Illuminate\View\Engines\EngineResolver;
|
||||
use Illuminate\View\Engines\PhpEngine;
|
||||
use Illuminate\View\Factory;
|
||||
use Illuminate\View\FileViewFinder;
|
||||
use Illuminate\View\View;
|
||||
|
|
@ -18,6 +19,10 @@ use Luracast\Restler\Restler;
|
|||
use Luracast\Restler\Scope;
|
||||
use Luracast\Restler\UI\Nav;
|
||||
use Luracast\Restler\Util;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\DebugExtension;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Html template format
|
||||
|
|
@ -29,10 +34,14 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class HtmlFormat extends DependentFormat
|
||||
{
|
||||
const BLADE = 'Illuminate\View\View';
|
||||
const TWIG = 'Twig\Environment';
|
||||
const MUSTACHE = 'Mustache_Engine';
|
||||
|
||||
public static $mime = 'text/html';
|
||||
public static $extension = 'html';
|
||||
public static $view;
|
||||
|
|
@ -84,11 +93,12 @@ class HtmlFormat extends DependentFormat
|
|||
}
|
||||
}
|
||||
|
||||
public function getDependencyMap(){
|
||||
public function getDependencyMap()
|
||||
{
|
||||
return array(
|
||||
'Illuminate\View\View' => 'illuminate/view:4.2.*',
|
||||
'Twig_Environment' => 'twig/twig:v1.13.*',
|
||||
'Mustache_Engine' => 'mustache/mustache:dev-master',
|
||||
self::BLADE => 'illuminate/view:^8',
|
||||
self::TWIG => 'twig/twig:^3',
|
||||
self::MUSTACHE => 'mustache/mustache:dev-master',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +111,7 @@ class HtmlFormat extends DependentFormat
|
|||
$resolver->register('blade', function () use ($engine) {
|
||||
return $engine;
|
||||
});
|
||||
$phpEngine = new PhpEngine();
|
||||
$phpEngine = new PhpEngine($files);
|
||||
$resolver->register('php', function () use ($phpEngine) {
|
||||
return $phpEngine;
|
||||
});
|
||||
|
|
@ -128,32 +138,43 @@ class HtmlFormat extends DependentFormat
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
public static function twig(array $data, $debug = true)
|
||||
/**
|
||||
* @param array|object $data
|
||||
* @param bool $debug
|
||||
*
|
||||
* @return string
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
*/
|
||||
public static function twig($data, $debug = true)
|
||||
{
|
||||
$loader = new \Twig_Loader_Filesystem(static::$viewPath);
|
||||
$twig = new \Twig_Environment($loader, array(
|
||||
'cache' => static::$cacheDirectory,
|
||||
'debug' => $debug,
|
||||
$loader = new FilesystemLoader(static::$viewPath);
|
||||
$twig = new Environment($loader, array(
|
||||
'cache' => is_string(static::$cacheDirectory)
|
||||
? static::$cacheDirectory : false,
|
||||
'debug' => $debug,
|
||||
'use_strict_variables' => $debug,
|
||||
));
|
||||
if ($debug)
|
||||
$twig->addExtension(new \Twig_Extension_Debug());
|
||||
if ($debug) {
|
||||
$twig->addExtension(new DebugExtension());
|
||||
}
|
||||
|
||||
$twig->addFunction(
|
||||
new \Twig_SimpleFunction(
|
||||
new TwigFunction(
|
||||
'form',
|
||||
'Luracast\Restler\UI\Forms::get',
|
||||
array('is_safe' => array('html'))
|
||||
)
|
||||
);
|
||||
$twig->addFunction(
|
||||
new \Twig_SimpleFunction(
|
||||
new TwigFunction(
|
||||
'form_key',
|
||||
'Luracast\Restler\UI\Forms::key'
|
||||
)
|
||||
);
|
||||
$twig->addFunction(
|
||||
new \Twig_SimpleFunction(
|
||||
new TwigFunction(
|
||||
'nav',
|
||||
'Luracast\Restler\UI\Nav::get'
|
||||
)
|
||||
|
|
@ -164,7 +185,7 @@ class HtmlFormat extends DependentFormat
|
|||
isset(HtmlFormat::$data[$name]) &&
|
||||
is_callable(HtmlFormat::$data[$name])
|
||||
) {
|
||||
return new \Twig_SimpleFunction(
|
||||
return new TwigFunction(
|
||||
$name,
|
||||
HtmlFormat::$data[$name]
|
||||
);
|
||||
|
|
@ -172,21 +193,35 @@ class HtmlFormat extends DependentFormat
|
|||
return false;
|
||||
});
|
||||
|
||||
$template = $twig->loadTemplate(static::getViewFile());
|
||||
return $template->render($data);
|
||||
$template = $twig->load(static::getViewFile());
|
||||
return $template->render((array)$data);
|
||||
}
|
||||
|
||||
public static function handlebar(array $data, $debug = true)
|
||||
/**
|
||||
* @param array|object $data
|
||||
* @param bool $debug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function handlebar($data, $debug = true)
|
||||
{
|
||||
return static::mustache($data, $debug);
|
||||
}
|
||||
|
||||
public static function mustache(array $data, $debug = true)
|
||||
/**
|
||||
* @param array|object $data
|
||||
* @param bool $debug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function mustache($data, $debug = true)
|
||||
{
|
||||
if (!isset($data['nav']))
|
||||
$data = (array)$data;
|
||||
if (!isset($data['nav'])) {
|
||||
$data['nav'] = array_values(Nav::get());
|
||||
}
|
||||
$options = array(
|
||||
'loader' => new \Mustache_Loader_FilesystemLoader(
|
||||
'loader' => new \Mustache_Loader_FilesystemLoader(
|
||||
static::$viewPath,
|
||||
array('extension' => static::getViewExtension())
|
||||
),
|
||||
|
|
@ -200,16 +235,25 @@ class HtmlFormat extends DependentFormat
|
|||
},
|
||||
)
|
||||
);
|
||||
if (!$debug)
|
||||
if (!$debug) {
|
||||
$options['cache'] = static::$cacheDirectory;
|
||||
}
|
||||
$m = new \Mustache_Engine($options);
|
||||
return $m->render(static::getViewFile(), $data);
|
||||
}
|
||||
|
||||
public static function php(array $data, $debug = true)
|
||||
/**
|
||||
* @param array|object $data
|
||||
* @param bool $debug
|
||||
*
|
||||
* @return string
|
||||
* @throws RestException
|
||||
*/
|
||||
public static function php($data, $debug = true)
|
||||
{
|
||||
if (static::$view == 'debug')
|
||||
if (static::$view == 'debug') {
|
||||
static::$viewPath = dirname(__DIR__) . '/views';
|
||||
}
|
||||
$view = static::getViewFile(true);
|
||||
|
||||
if (!is_readable($view)) {
|
||||
|
|
@ -222,22 +266,26 @@ class HtmlFormat extends DependentFormat
|
|||
|
||||
$path = static::$viewPath . DIRECTORY_SEPARATOR;
|
||||
$template = function ($view) use ($data, $path) {
|
||||
$data = (array)$data;
|
||||
$form = function () {
|
||||
return call_user_func_array(
|
||||
'Luracast\Restler\UI\Forms::get',
|
||||
func_get_args()
|
||||
);
|
||||
};
|
||||
if (!isset($data['form']))
|
||||
if (!isset($data['form'])) {
|
||||
$data['form'] = $form;
|
||||
}
|
||||
$nav = function () {
|
||||
return call_user_func_array(
|
||||
'Luracast\Restler\UI\Nav::get',
|
||||
func_get_args()
|
||||
);
|
||||
};
|
||||
if (!isset($data['nav']))
|
||||
if (!isset($data['nav'])) {
|
||||
$data['nav'] = $nav;
|
||||
}
|
||||
|
||||
|
||||
$_ = function () use ($data, $path) {
|
||||
extract($data);
|
||||
|
|
@ -254,7 +302,7 @@ class HtmlFormat extends DependentFormat
|
|||
) {
|
||||
$str = '';
|
||||
foreach ($arrays as $arr) {
|
||||
extract($arr);
|
||||
extract((array)$arr);
|
||||
$str .= include $file;
|
||||
}
|
||||
return $str;
|
||||
|
|
@ -264,15 +312,18 @@ class HtmlFormat extends DependentFormat
|
|||
}
|
||||
break;
|
||||
case 'if':
|
||||
if (count($args) < 2)
|
||||
if (count($args) < 2) {
|
||||
$args[1] = '';
|
||||
if (count($args) < 3)
|
||||
}
|
||||
if (count($args) < 3) {
|
||||
$args[2] = '';
|
||||
}
|
||||
return $args[0] ? $args[1] : $args[2];
|
||||
break;
|
||||
default:
|
||||
if (isset($data[$task]) && is_callable($data[$task]))
|
||||
if (isset($data[$task]) && is_callable($data[$task])) {
|
||||
return call_user_func_array($data[$task], $args);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
|
@ -280,8 +331,9 @@ class HtmlFormat extends DependentFormat
|
|||
return @include $view;
|
||||
};
|
||||
$value = $template($view);
|
||||
if (is_string($value))
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -294,8 +346,8 @@ class HtmlFormat extends DependentFormat
|
|||
* Formatter has to make the encoded
|
||||
* output more human readable
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return string encoded string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function encode($data, $humanReadable = false)
|
||||
{
|
||||
|
|
@ -317,9 +369,9 @@ class HtmlFormat extends DependentFormat
|
|||
'response' => static::$convertResponseToArray
|
||||
? Obj::toArray($data)
|
||||
: $data,
|
||||
'stages' => $this->restler->getEvents(),
|
||||
'success' => $success,
|
||||
'error' => $error
|
||||
'stages' => $this->restler->getEvents(),
|
||||
'success' => $success,
|
||||
'error' => $error
|
||||
);
|
||||
$info = $data['api'] = $this->restler->apiMethodInfo;
|
||||
$metadata = Util::nestedValue(
|
||||
|
|
@ -358,7 +410,9 @@ class HtmlFormat extends DependentFormat
|
|||
if ($value) {
|
||||
$data = Util::nestedValue($data, explode('.', $value));
|
||||
}
|
||||
$data += static::$data;
|
||||
if (is_array($data)) {
|
||||
$data += static::$data;
|
||||
}
|
||||
if (false === ($i = strrpos(self::$view, '.'))) {
|
||||
$template = self::$template;
|
||||
} else {
|
||||
|
|
@ -369,17 +423,18 @@ class HtmlFormat extends DependentFormat
|
|||
static::$cacheDirectory = Defaults::$cacheDirectory . DIRECTORY_SEPARATOR . $template;
|
||||
if (!file_exists(static::$cacheDirectory)) {
|
||||
if (!mkdir(static::$cacheDirectory, 0770, true)) {
|
||||
throw new RestException(500, 'Unable to create cache directory `' . static::$cacheDirectory . '`');
|
||||
throw new RestException(500,
|
||||
'Unable to create cache directory `' . static::$cacheDirectory . '`');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (method_exists($class = get_called_class(), $template)) {
|
||||
if ($template == 'blade') {
|
||||
$this->checkDependency('Illuminate\View\View');
|
||||
$this->checkDependency(self::BLADE);
|
||||
} elseif ($template == 'twig') {
|
||||
$this->checkDependency('Twig_Environment');
|
||||
$this->checkDependency(self::TWIG);
|
||||
} elseif ($template == 'mustache' || $template == 'handlebar') {
|
||||
$this->checkDependency('Mustache_Engine');
|
||||
$this->checkDependency(self::MUSTACHE);
|
||||
}
|
||||
return call_user_func("$class::$template", $data, $humanReadable);
|
||||
}
|
||||
|
|
@ -416,8 +471,9 @@ class HtmlFormat extends DependentFormat
|
|||
{
|
||||
$v = $fullPath ? static::$viewPath . '/' : '';
|
||||
$v .= static::$view;
|
||||
if ($includeExtension)
|
||||
if ($includeExtension) {
|
||||
$v .= '.' . static::getViewExtension();
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class JsFormat extends JsonFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Luracast\Restler\RestException;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class JsonFormat extends Format
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
abstract class MultiFormat implements iFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use CFPropertyList\CFPropertyList;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class PlistFormat extends DependentMultiFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class TsvFormat extends CsvFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Luracast\Restler\RestException;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class UploadFormat extends Format
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class UrlEncodedFormat extends Format
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use XMLWriter;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class XmlFormat extends Format
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Luracast\Restler\Data\Obj;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class YamlFormat extends DependentFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iDecodeStream
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler\Format;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iFormat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class HumanReadableCache implements iCache
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class PassThrough
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Luracast\Restler\Format\JsonFormat;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Redirect
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use stdClass;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Resources implements iUseAuthentication, iProvideMultiVersionApi
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Exception;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
|
||||
class RestException extends Exception
|
||||
|
|
|
|||
|
|
@ -15,13 +15,14 @@ use Luracast\Restler\Format\UrlEncodedFormat;
|
|||
* inspired by the RestServer code from
|
||||
* <http://jacwright.com/blog/resources/RestServer.txt>
|
||||
*
|
||||
*
|
||||
* @category Framework
|
||||
* @package Restler
|
||||
* @author R.Arul Kumaran <arul@luracast.com>
|
||||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*
|
||||
* @method static void onGet() onGet(Callable $function) fired before reading the request details
|
||||
* @method static void onRoute() onRoute(Callable $function) fired before finding the api method
|
||||
|
|
@ -48,10 +49,13 @@ use Luracast\Restler\Format\UrlEncodedFormat;
|
|||
* @method void onRespond() onRespond(Callable $function) fired before sending response
|
||||
* @method void onComplete() onComplete(Callable $function) fired after sending response
|
||||
* @method void onMessage() onMessage(Callable $function) fired before composing error response
|
||||
*
|
||||
* @property bool|null _authenticated
|
||||
* @property bool _authVerified
|
||||
*/
|
||||
class Restler extends EventDispatcher
|
||||
{
|
||||
const VERSION = '3.0.0rc6';
|
||||
const VERSION = '3.1.0';
|
||||
|
||||
// ==================================================================
|
||||
//
|
||||
|
|
@ -693,6 +697,8 @@ class Restler extends EventDispatcher
|
|||
* - media type
|
||||
* - charset
|
||||
* - language
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
protected function negotiate()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use Exception;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Routes
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Luracast\Restler;
|
||||
|
||||
/**
|
||||
|
|
@ -11,7 +13,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Scope
|
||||
{
|
||||
|
|
@ -45,8 +47,8 @@ class Scope
|
|||
//API classes
|
||||
'Resources' => 'Luracast\Restler\Resources',
|
||||
'Explorer' => 'Luracast\Restler\Explorer\v2\Explorer',
|
||||
'Explorer1' => 'Luracast\Restler\Explorer\v1\Explorer',
|
||||
'Explorer2' => 'Luracast\Restler\Explorer\v2\Explorer',
|
||||
'Explorer1' => 'Luracast\Restler\Explorer\v1\Explorer',
|
||||
'Explorer2' => 'Luracast\Restler\Explorer\v2\Explorer',
|
||||
|
||||
//Cache classes
|
||||
'HumanReadableCache' => 'Luracast\Restler\HumanReadableCache',
|
||||
|
|
@ -120,6 +122,7 @@ class Scope
|
|||
$r = new $fullName();
|
||||
static::$instances[$name] = (object)array('instance' => $r);
|
||||
if ($name != 'Restler') {
|
||||
/** @var Restler restler */
|
||||
$r->restler = static::get('Restler');
|
||||
$m = Util::nestedValue($r->restler, 'apiMethodInfo', 'metadata');
|
||||
if ($m) {
|
||||
|
|
@ -138,15 +141,14 @@ class Scope
|
|||
}
|
||||
if (
|
||||
$r instanceof iUseAuthentication &&
|
||||
static::get('Restler')->_authVerified &&
|
||||
$r->restler && $r->restler->_authVerified &&
|
||||
!isset(static::$instances[$name]->authVerified)
|
||||
) {
|
||||
static::$instances[$name]->authVerified = true;
|
||||
$r->__setAuthenticationStatus
|
||||
(static::get('Restler')->_authenticated);
|
||||
$r->__setAuthenticationStatus($r->restler->_authenticated);
|
||||
}
|
||||
if (isset(static::$instances[$name]->initPending)) {
|
||||
$m = Util::nestedValue(static::get('Restler'), 'apiMethodInfo', 'metadata');
|
||||
$m = Util::nestedValue($r->restler, 'apiMethodInfo', 'metadata');
|
||||
$fullName = $name;
|
||||
if (class_exists($name)) {
|
||||
$shortName = Util::getShortName($name);
|
||||
|
|
@ -194,15 +196,15 @@ class Scope
|
|||
*/
|
||||
public static function resolve($className, array $scope)
|
||||
{
|
||||
if (empty($className) || !is_string($className))
|
||||
if (empty($className) || !is_string($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::isPrimitiveDataType($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$divider = '\\';
|
||||
$qualified = false;
|
||||
if ($className[0] == $divider) {
|
||||
$qualified = trim($className, $divider);
|
||||
} elseif (array_key_exists($className, $scope)) {
|
||||
|
|
@ -210,18 +212,21 @@ class Scope
|
|||
} else {
|
||||
$qualified = $scope['*'] . $className;
|
||||
}
|
||||
if (class_exists($qualified))
|
||||
if (class_exists($qualified)) {
|
||||
return $qualified;
|
||||
}
|
||||
if (isset(static::$classAliases[$className])) {
|
||||
$qualified = static::$classAliases[$className];
|
||||
if (class_exists($qualified))
|
||||
if (class_exists($qualified)) {
|
||||
return $qualified;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $stringName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function isPrimitiveDataType($stringName)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Luracast\Restler\Util;
|
|||
* Class Emmet
|
||||
* @package Luracast\Restler\UI
|
||||
*
|
||||
* @version 3.0.0rc6
|
||||
* @version 3.1.0
|
||||
*/
|
||||
class Emmet
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Luracast\Restler\UI;
|
||||
|
||||
use Luracast\Restler\CommentParser;
|
||||
|
|
@ -29,7 +30,7 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Forms implements iFilter
|
||||
{
|
||||
|
|
@ -38,7 +39,7 @@ class Forms implements iFilter
|
|||
|
||||
public static $excludedPaths = array();
|
||||
|
||||
public static $style;
|
||||
private static $style;
|
||||
/**
|
||||
* @var bool should we fill up the form using given data?
|
||||
*/
|
||||
|
|
@ -81,6 +82,11 @@ class Forms implements iFilter
|
|||
*/
|
||||
private static $info;
|
||||
|
||||
public static function setStyles(HtmlForm $style)
|
||||
{
|
||||
static::$style = get_class($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form
|
||||
*
|
||||
|
|
@ -95,18 +101,20 @@ class Forms implements iFilter
|
|||
*
|
||||
* @return array|T
|
||||
*
|
||||
* @throws \Luracast\Restler\RestException
|
||||
* @throws RestException
|
||||
*/
|
||||
public static function get($method = 'POST', $action = null, $dataOnly = false, $prefix = '', $indent = ' ')
|
||||
{
|
||||
if (!static::$style)
|
||||
static::$style = FormStyles::$html;
|
||||
if (!static::$style) {
|
||||
static::$style = 'Luracast\\Restler\\UI\HtmlForm';
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var Restler $restler */
|
||||
$restler = Scope::get('Restler');
|
||||
if (is_null($action))
|
||||
if (is_null($action)) {
|
||||
$action = $restler->url;
|
||||
}
|
||||
|
||||
$info = $restler->url == $action
|
||||
&& Util::getRequestMethod() == $method
|
||||
|
|
@ -126,23 +134,25 @@ class Forms implements iFilter
|
|||
//echo $e->getErrorMessage();
|
||||
$info = false;
|
||||
}
|
||||
if (!$info)
|
||||
if (!$info) {
|
||||
throw new RestException(500, 'invalid action path for form `' . $method . ' ' . $action . '`');
|
||||
}
|
||||
static::$info = $info;
|
||||
$m = $info->metadata;
|
||||
$r = static::fields($dataOnly);
|
||||
if ($method != 'GET' && $method != 'POST') {
|
||||
if (empty(Defaults::$httpMethodOverrideProperty))
|
||||
if (empty(Defaults::$httpMethodOverrideProperty)) {
|
||||
throw new RestException(
|
||||
500,
|
||||
'Forms require `Defaults::\$httpMethodOverrideProperty`' .
|
||||
"for supporting HTTP $method"
|
||||
);
|
||||
}
|
||||
if ($dataOnly) {
|
||||
$r[] = array(
|
||||
'tag' => 'input',
|
||||
'name' => Defaults::$httpMethodOverrideProperty,
|
||||
'type' => 'hidden',
|
||||
'tag' => 'input',
|
||||
'name' => Defaults::$httpMethodOverrideProperty,
|
||||
'type' => 'hidden',
|
||||
'value' => 'method',
|
||||
);
|
||||
} else {
|
||||
|
|
@ -158,9 +168,9 @@ class Forms implements iFilter
|
|||
$form_key = static::key($method, $action);
|
||||
if ($dataOnly) {
|
||||
$r[] = array(
|
||||
'tag' => 'input',
|
||||
'name' => static::FORM_KEY,
|
||||
'type' => 'hidden',
|
||||
'tag' => 'input',
|
||||
'name' => static::FORM_KEY,
|
||||
'type' => 'hidden',
|
||||
'value' => 'hidden',
|
||||
);
|
||||
} else {
|
||||
|
|
@ -173,15 +183,16 @@ class Forms implements iFilter
|
|||
}
|
||||
|
||||
$s = array(
|
||||
'tag' => 'button',
|
||||
'type' => 'submit',
|
||||
'tag' => 'button',
|
||||
'type' => 'submit',
|
||||
'label' =>
|
||||
Util::nestedValue($m, 'return', CommentParser::$embeddedDataName, 'label')
|
||||
? : 'Submit'
|
||||
?: 'Submit'
|
||||
);
|
||||
|
||||
if (!$dataOnly)
|
||||
if (!$dataOnly) {
|
||||
$s = Emmet::make(static::style('submit', $m), $s);
|
||||
}
|
||||
$r[] = $s;
|
||||
$t = array(
|
||||
'action' => $restler->getBaseUrl() . '/' . rtrim($action, '/'),
|
||||
|
|
@ -207,15 +218,18 @@ class Forms implements iFilter
|
|||
|
||||
public static function style($name, array $metadata, $type = '')
|
||||
{
|
||||
return isset($metadata[CommentParser::$embeddedDataName][$name])
|
||||
? $metadata[CommentParser::$embeddedDataName][$name]
|
||||
: (!empty($type) && isset(static::$style["$name-$type"])
|
||||
? static::$style["$name-$type"]
|
||||
: (isset(static::$style[$name])
|
||||
? static::$style[$name]
|
||||
: null
|
||||
)
|
||||
);
|
||||
if (isset($metadata[CommentParser::$embeddedDataName][$name])) {
|
||||
return $metadata[CommentParser::$embeddedDataName][$name];
|
||||
}
|
||||
$style = static::$style . '::' . $name;
|
||||
$typedStyle = $style . '_' . $type;
|
||||
if (defined($typedStyle)) {
|
||||
return constant($typedStyle);
|
||||
}
|
||||
if (defined($style)) {
|
||||
return constant($style);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function fields($dataOnly = false)
|
||||
|
|
@ -230,11 +244,13 @@ class Forms implements iFilter
|
|||
is_scalar($value) ||
|
||||
($p['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
|
||||
is_object($value) && $p['type'] == get_class($value)
|
||||
)
|
||||
) {
|
||||
$p['value'] = $value;
|
||||
}
|
||||
static::$validationInfo = $v = new ValidationInfo($p);
|
||||
if ($v->from == 'path')
|
||||
if ($v->from == 'path') {
|
||||
continue;
|
||||
}
|
||||
if (!empty($v->children)) {
|
||||
$t = Emmet::make(static::style('fieldset', $m), array('label' => $v->label));
|
||||
foreach ($v->children as $n => $c) {
|
||||
|
|
@ -243,11 +259,13 @@ class Forms implements iFilter
|
|||
is_scalar($value) ||
|
||||
($c['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
|
||||
is_object($value) && $c['type'] == get_class($value)
|
||||
)
|
||||
) {
|
||||
$c['value'] = $value;
|
||||
}
|
||||
static::$validationInfo = $vc = new ValidationInfo($c);
|
||||
if ($vc->from == 'path')
|
||||
if ($vc->from == 'path') {
|
||||
continue;
|
||||
}
|
||||
$vc->name = $v->name . '[' . $vc->name . ']';
|
||||
$t [] = static::field($vc, $dataOnly);
|
||||
}
|
||||
|
|
@ -275,7 +293,7 @@ class Forms implements iFilter
|
|||
//prevent XSS attacks
|
||||
$p->value = htmlspecialchars($p->value, ENT_QUOTES | ENT_HTML401, 'UTF-8');
|
||||
}
|
||||
$type = $p->field ? : static::guessFieldType($p);
|
||||
$type = $p->field ?: static::guessFieldType($p);
|
||||
$tag = in_array($type, static::$inputTypes)
|
||||
? 'input' : $type;
|
||||
$options = array();
|
||||
|
|
@ -291,25 +309,33 @@ class Forms implements iFilter
|
|||
$option['text'] = isset($p->rules['select'][$i])
|
||||
? $p->rules['select'][$i]
|
||||
: $choice;
|
||||
if ($choice == $p->value)
|
||||
if ($choice == $p->value) {
|
||||
$option['selected'] = true;
|
||||
}
|
||||
$options[] = $option;
|
||||
}
|
||||
} elseif ($p->type == 'boolean' || $p->type == 'bool') {
|
||||
if (Text::beginsWith($type, 'radio') || Text::beginsWith($type, 'select')) {
|
||||
$options[] = array('name' => $p->name, 'text' => ' Yes ',
|
||||
'value' => 'true');
|
||||
$options[] = array('name' => $p->name, 'text' => ' No ',
|
||||
'value' => 'false');
|
||||
if ($p->value || $p->default)
|
||||
$options[] = array(
|
||||
'name' => $p->name,
|
||||
'text' => ' Yes ',
|
||||
'value' => 'true'
|
||||
);
|
||||
$options[] = array(
|
||||
'name' => $p->name,
|
||||
'text' => ' No ',
|
||||
'value' => 'false'
|
||||
);
|
||||
if ($p->value || $p->default) {
|
||||
$options[0]['selected'] = true;
|
||||
}
|
||||
} else { //checkbox
|
||||
$r = array(
|
||||
'tag' => $tag,
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'label' => $p->label,
|
||||
'value' => 'true',
|
||||
'tag' => $tag,
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'label' => $p->label,
|
||||
'value' => 'true',
|
||||
'default' => $p->default,
|
||||
);
|
||||
$r['text'] = 'Yes';
|
||||
|
|
@ -323,13 +349,13 @@ class Forms implements iFilter
|
|||
}
|
||||
if (empty($r)) {
|
||||
$r = array(
|
||||
'tag' => $tag,
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'label' => $p->label,
|
||||
'value' => $p->value,
|
||||
'default' => $p->default,
|
||||
'options' => & $options,
|
||||
'tag' => $tag,
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'label' => $p->label,
|
||||
'value' => $p->value,
|
||||
'default' => $p->default,
|
||||
'options' => & $options,
|
||||
'multiple' => $multiple,
|
||||
);
|
||||
if (isset($p->rules)) {
|
||||
|
|
@ -347,30 +373,36 @@ class Forms implements iFilter
|
|||
$r['message'] = Validator::$exceptions[$p->name]->getMessage();
|
||||
}
|
||||
|
||||
if (true === $p->required)
|
||||
if (true === $p->required) {
|
||||
$r['required'] = 'required';
|
||||
if (isset($p->rules['autofocus']))
|
||||
}
|
||||
if (isset($p->rules['autofocus'])) {
|
||||
$r['autofocus'] = 'autofocus';
|
||||
}
|
||||
/*
|
||||
echo "<pre>";
|
||||
print_r($r);
|
||||
echo "</pre>";
|
||||
*/
|
||||
if ($dataOnly)
|
||||
if ($dataOnly) {
|
||||
return $r;
|
||||
if (isset($p->rules['form']))
|
||||
}
|
||||
if (isset($p->rules['form'])) {
|
||||
return Emmet::make($p->rules['form'], $r);
|
||||
}
|
||||
$m = static::$info->metadata;
|
||||
$t = Emmet::make(static::style($type, $m, $p->type) ? : static::style($tag, $m, $p->type), $r);
|
||||
$t = Emmet::make(static::style($type, $m, $p->type) ?: static::style($tag, $m, $p->type), $r);
|
||||
return $t;
|
||||
}
|
||||
|
||||
protected static function guessFieldType(ValidationInfo $p, $type = 'type')
|
||||
{
|
||||
if (in_array($p->$type, static::$inputTypes))
|
||||
if (in_array($p->$type, static::$inputTypes)) {
|
||||
return $p->$type;
|
||||
if ($p->choice)
|
||||
}
|
||||
if ($p->choice) {
|
||||
return $p->type == 'array' ? 'checkbox' : 'select';
|
||||
}
|
||||
switch ($p->$type) {
|
||||
case 'boolean':
|
||||
return 'radio';
|
||||
|
|
@ -381,8 +413,9 @@ class Forms implements iFilter
|
|||
case 'array':
|
||||
return static::guessFieldType($p, 'contentType');
|
||||
}
|
||||
if ($p->name == 'password')
|
||||
if ($p->name == 'password') {
|
||||
return 'password';
|
||||
}
|
||||
return 'text';
|
||||
}
|
||||
|
||||
|
|
@ -397,11 +430,13 @@ class Forms implements iFilter
|
|||
*/
|
||||
public static function key($method = 'POST', $action = null)
|
||||
{
|
||||
if (is_null($action))
|
||||
if (is_null($action)) {
|
||||
$action = Scope::get('Restler')->url;
|
||||
}
|
||||
$target = "$method $action";
|
||||
if (empty(static::$key[$target]))
|
||||
if (empty(static::$key[$target])) {
|
||||
static::$key[$target] = md5($target . User::getIpAddress() . uniqid(mt_rand()));
|
||||
}
|
||||
$_SESSION[static::FORM_KEY] = static::$key;
|
||||
return static::$key[$target];
|
||||
}
|
||||
|
|
@ -425,8 +460,9 @@ class Forms implements iFilter
|
|||
$url = $restler->url;
|
||||
foreach (static::$excludedPaths as $exclude) {
|
||||
if (empty($exclude)) {
|
||||
if ($url == $exclude)
|
||||
if ($url == $exclude) {
|
||||
return true;
|
||||
}
|
||||
} elseif (Text::beginsWith($url, $exclude)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -447,4 +483,4 @@ class Forms implements iFilter
|
|||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Nav
|
||||
{
|
||||
|
|
@ -130,7 +130,8 @@ class Nav
|
|||
} else {
|
||||
return $tree;
|
||||
}
|
||||
return null;
|
||||
$value = null;
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function addUrls(array $urls)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Luracast\Restler\Util;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*
|
||||
* ============================ magic properties ==============================
|
||||
* @property Tags parent parent tag
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class User implements iIdentifyUser
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Luracast\Restler;
|
||||
|
||||
/**
|
||||
* Describe the purpose of this class/interface/trait
|
||||
*
|
||||
|
|
@ -9,7 +11,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
class Util
|
||||
{
|
||||
|
|
@ -50,8 +52,8 @@ class Util
|
|||
* When the deeply nested property is found its value is returned, otherwise
|
||||
* false is returned.
|
||||
*
|
||||
* @param array $from array to extract the value from
|
||||
* @param string|array $key ... pass more to go deeply inside the array
|
||||
* @param array|object $from array to extract the value from
|
||||
* @param string|array $key ... pass more to go deeply inside the array
|
||||
* alternatively you can pass a single array
|
||||
*
|
||||
* @return null|mixed null when not found, value otherwise
|
||||
|
|
@ -77,24 +79,29 @@ class Util
|
|||
return $from;
|
||||
}
|
||||
|
||||
public static function getResourcePath($className,
|
||||
$resourcePath = null,
|
||||
$prefix = '')
|
||||
{
|
||||
public static function getResourcePath(
|
||||
$className,
|
||||
$resourcePath = null,
|
||||
$prefix = ''
|
||||
) {
|
||||
if (is_null($resourcePath)) {
|
||||
if (Defaults::$autoRoutingEnabled) {
|
||||
$resourcePath = strtolower($className);
|
||||
if (false !== ($index = strrpos($className, '\\')))
|
||||
if (false !== ($index = strrpos($className, '\\'))) {
|
||||
$resourcePath = substr($resourcePath, $index + 1);
|
||||
if (false !== ($index = strrpos($resourcePath, '_')))
|
||||
}
|
||||
if (false !== ($index = strrpos($resourcePath, '_'))) {
|
||||
$resourcePath = substr($resourcePath, $index + 1);
|
||||
}
|
||||
} else {
|
||||
$resourcePath = '';
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
$resourcePath = trim($resourcePath, '/');
|
||||
if (strlen($resourcePath) > 0)
|
||||
}
|
||||
if (strlen($resourcePath) > 0) {
|
||||
$resourcePath .= '/';
|
||||
}
|
||||
return $prefix . $resourcePath;
|
||||
}
|
||||
|
||||
|
|
@ -114,8 +121,9 @@ class Util
|
|||
*/
|
||||
public static function removeCommonPath($fromPath, $usingPath, $char = '/')
|
||||
{
|
||||
if (empty($fromPath))
|
||||
if (empty($fromPath)) {
|
||||
return '';
|
||||
}
|
||||
$fromPath = explode($char, $fromPath);
|
||||
$usingPath = explode($char, $usingPath);
|
||||
while (count($usingPath)) {
|
||||
|
|
@ -145,8 +153,9 @@ class Util
|
|||
*/
|
||||
public static function splitCommonPath($fromPath, $usingPath, $char = '/')
|
||||
{
|
||||
if (empty($fromPath))
|
||||
if (empty($fromPath)) {
|
||||
return array('', '');
|
||||
}
|
||||
$fromPath = explode($char, $fromPath);
|
||||
$usingPath = explode($char, $usingPath);
|
||||
$commonPath = array();
|
||||
|
|
@ -213,11 +222,18 @@ class Util
|
|||
$accepts = array($accepts);
|
||||
}
|
||||
foreach ($accepts as $pos => $accept) {
|
||||
$parts = explode(';q=', trim($accept));
|
||||
$type = array_shift($parts);
|
||||
$quality = count($parts) ?
|
||||
floatval(array_shift($parts)) :
|
||||
(1000 - $pos) / 1000;
|
||||
$parts = explode(';', $accept);
|
||||
$type = trim(array_shift($parts));
|
||||
$parameters = [];
|
||||
foreach ($parts as $part) {
|
||||
$part = explode('=', $part);
|
||||
if (2 !== count($part)) {
|
||||
continue;
|
||||
}
|
||||
$key = strtolower(trim($part[0]));
|
||||
$parameters[$key] = trim($part[1], ' "');
|
||||
}
|
||||
$quality = isset($parameters['q']) ? (float)$parameters['q'] : (1000 - $pos) / 1000;
|
||||
$acceptList[$type] = $quality;
|
||||
}
|
||||
arsort($acceptList);
|
||||
|
|
@ -227,8 +243,7 @@ class Util
|
|||
public static function getShortName($className)
|
||||
{
|
||||
// @CHANGE LDR
|
||||
if (! is_string($className)) return '';
|
||||
//var_dump($className);
|
||||
if (!is_string($className)) return;
|
||||
|
||||
$className = explode('\\', $className);
|
||||
return end($className);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iAuthenticate extends iFilter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iCache
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Exception;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iCompose {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iFilter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iIdentifyUser
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace Luracast\Restler;
|
|||
* Interface iProvideMultiVersionApi
|
||||
* @package Luracast\Restler
|
||||
*
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iProvideMultiVersionApi
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luracast\Restler;
|
|||
* @copyright 2010 Luracast
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://luracast.com/products/restler/
|
||||
* @version 3.0.0rc6
|
||||
*
|
||||
*/
|
||||
interface iUseAuthentication
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user