diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 98a6d2176aa..5648381ff49 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -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 --------- diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index bdf86a5c2c9..2d6a598398c 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -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); } } diff --git a/htdocs/api/class/api_login.class.php b/htdocs/api/class/api_login.class.php index 75fa4b60b89..25765e7f7e5 100644 --- a/htdocs/api/class/api_login.class.php +++ b/htdocs/api/class/api_login.class.php @@ -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"; diff --git a/htdocs/includes/restler/framework/Luracast/Restler/ApcCache.php b/htdocs/includes/restler/framework/Luracast/Restler/ApcCache.php index b8cdd95b373..a2ddc83c44f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/ApcCache.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/ApcCache.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php b/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php index d8445fdc70c..5ed160a070a 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php @@ -12,7 +12,7 @@ namespace Luracast\Restler { * @subpackage helper * @author Nick Lombard * @copyright 2012 Luracast - * @version 3.0.0rc6 + * */ class AutoLoader { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/CommentParser.php b/htdocs/includes/restler/framework/Luracast/Restler/CommentParser.php index 2815f1f6c70..6b8b9178f6b 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/CommentParser.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/CommentParser.php @@ -1,4 +1,5 @@ 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) diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Compose.php b/htdocs/includes/restler/framework/Luracast/Restler/Compose.php index 594e5902004..141aa8bcb2f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Compose.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Compose.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/ApiMethodInfo.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/ApiMethodInfo.php index 4d0fa4bfd48..f4dea84df97 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/ApiMethodInfo.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/ApiMethodInfo.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Arr.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Arr.php index 6e98a4132ea..8ae18c7003d 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Arr.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Arr.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Invalid.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Invalid.php index 6b06d266f13..832dd30850e 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Invalid.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Invalid.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Obj.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Obj.php index 003f1df8794..8fe2a79ab63 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Obj.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Obj.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Text.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Text.php index 506ea25fb20..d0b39896c8e 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Text.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Text.php @@ -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))); + } } \ No newline at end of file diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/ValidationInfo.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/ValidationInfo.php index 298b72ec125..fc05c5386df 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/ValidationInfo.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/ValidationInfo.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php index c98a17a62d6..023fc7c4d1e 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/Validator.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/ValueObject.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/ValueObject.php index 46857b45329..5a2b001e841 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/ValueObject.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/ValueObject.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/iValidate.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/iValidate.php index 66688b066ba..923fc79b1ce 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/iValidate.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/iValidate.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Data/iValueObject.php b/htdocs/includes/restler/framework/Luracast/Restler/Data/iValueObject.php index dbf36cb744c..dcce824a655 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Data/iValueObject.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Data/iValueObject.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Defaults.php b/htdocs/includes/restler/framework/Luracast/Restler/Defaults.php index 8913db316b5..803c8b3177a 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Defaults.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Defaults.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php b/htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php index f8cd883af46..0c5d0fa676c 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php @@ -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; diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Filter/RateLimit.php b/htdocs/includes/restler/framework/Luracast/Restler/Filter/RateLimit.php index 5dce8591bba..e5705136fce 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Filter/RateLimit.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Filter/RateLimit.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Flash.php b/htdocs/includes/restler/framework/Luracast/Restler/Flash.php index 3ab04aa745e..41d097f312d 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Flash.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Flash.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/AmfFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/AmfFormat.php index 3d146fbcfac..181d95bea46 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/AmfFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/AmfFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/CsvFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/CsvFormat.php index 4bed88251c8..c33557f8463 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/CsvFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/CsvFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/Format.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/Format.php index 10b2c5834e6..edc2cbde719 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/Format.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/Format.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/HtmlFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/HtmlFormat.php index e871186c446..493e3e44061 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/HtmlFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/HtmlFormat.php @@ -1,4 +1,5 @@ '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; } diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsFormat.php index 0f04b7f0ee5..913dc272e19 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php index 00c763e8ff5..170676c071b 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/JsonFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/MultiFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/MultiFormat.php index 18fdd54b842..64afa3b3ea4 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/MultiFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/MultiFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/PlistFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/PlistFormat.php index cc07066a33c..f1eca01933d 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/PlistFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/PlistFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/TsvFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/TsvFormat.php index 502b02d2758..4eb3006f363 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/TsvFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/TsvFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/UploadFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/UploadFormat.php index de41bf98c71..b58b0f02b49 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/UploadFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/UploadFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/UrlEncodedFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/UrlEncodedFormat.php index 12d5a410333..6d141230d82 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/UrlEncodedFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/UrlEncodedFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/XmlFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/XmlFormat.php index ceec32e4cb5..6f8606eb111 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/XmlFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/XmlFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/YamlFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/YamlFormat.php index 07baae88b6f..4ff643de65f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/YamlFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/YamlFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/iDecodeStream.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/iDecodeStream.php index 080e3da506c..ec29330ed1f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/iDecodeStream.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/iDecodeStream.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Format/iFormat.php b/htdocs/includes/restler/framework/Luracast/Restler/Format/iFormat.php index d70d2019a94..0f4173d5b74 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Format/iFormat.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Format/iFormat.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php b/htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php index 6e1c22b432c..2546e30a4ee 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/InvalidAuthCredentials.php b/htdocs/includes/restler/framework/Luracast/Restler/InvalidAuthCredentials.php index 233e543e0aa..1b402238bf3 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/InvalidAuthCredentials.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/InvalidAuthCredentials.php @@ -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 + * */ diff --git a/htdocs/includes/restler/framework/Luracast/Restler/PassThrough.php b/htdocs/includes/restler/framework/Luracast/Restler/PassThrough.php index a77e533b722..2d265fb0fba 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/PassThrough.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/PassThrough.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Redirect.php b/htdocs/includes/restler/framework/Luracast/Restler/Redirect.php index 63319106759..8203b8eb18d 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Redirect.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Redirect.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Resources.php b/htdocs/includes/restler/framework/Luracast/Restler/Resources.php index 2986968a990..dfb547d287b 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Resources.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Resources.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/RestException.php b/htdocs/includes/restler/framework/Luracast/Restler/RestException.php index b2e51f8b122..4291381661c 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/RestException.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/RestException.php @@ -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 diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Restler.php b/htdocs/includes/restler/framework/Luracast/Restler/Restler.php index fcb5388726c..0c8f44a3864 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Restler.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Restler.php @@ -15,13 +15,14 @@ use Luracast\Restler\Format\UrlEncodedFormat; * inspired by the RestServer code from * * + * * @category Framework * @package Restler * @author R.Arul Kumaran * @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() { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Routes.php b/htdocs/includes/restler/framework/Luracast/Restler/Routes.php index 999094dec4c..d59b27d4418 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Routes.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Routes.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Scope.php b/htdocs/includes/restler/framework/Luracast/Restler/Scope.php index 16ccdd33561..6f7b49daf40 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Scope.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Scope.php @@ -1,4 +1,6 @@ '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) diff --git a/htdocs/includes/restler/framework/Luracast/Restler/UI/Emmet.php b/htdocs/includes/restler/framework/Luracast/Restler/UI/Emmet.php index 435804b4469..66090568a47 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/UI/Emmet.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/UI/Emmet.php @@ -8,7 +8,7 @@ use Luracast\Restler\Util; * Class Emmet * @package Luracast\Restler\UI * - * @version 3.0.0rc6 + * @version 3.1.0 */ class Emmet { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/UI/Forms.php b/htdocs/includes/restler/framework/Luracast/Restler/UI/Forms.php index 7073bfcf837..20749a2e691 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/UI/Forms.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/UI/Forms.php @@ -1,4 +1,5 @@ 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 "
";
         print_r($r);
         echo "
"; */ - 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; } -} \ No newline at end of file +} diff --git a/htdocs/includes/restler/framework/Luracast/Restler/UI/Nav.php b/htdocs/includes/restler/framework/Luracast/Restler/UI/Nav.php index b74054a99c5..4a7445ccbe6 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/UI/Nav.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/UI/Nav.php @@ -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) diff --git a/htdocs/includes/restler/framework/Luracast/Restler/UI/Tags.php b/htdocs/includes/restler/framework/Luracast/Restler/UI/Tags.php index 2c194cdbd1b..27e90bc89b5 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/UI/Tags.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/UI/Tags.php @@ -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 diff --git a/htdocs/includes/restler/framework/Luracast/Restler/User.php b/htdocs/includes/restler/framework/Luracast/Restler/User.php index 57465e26e46..463fd46867c 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/User.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/User.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/Util.php b/htdocs/includes/restler/framework/Luracast/Restler/Util.php index 9674550814f..a181a0e0da9 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/Util.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/Util.php @@ -1,5 +1,7 @@ 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); diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iAuthenticate.php b/htdocs/includes/restler/framework/Luracast/Restler/iAuthenticate.php index 6bacb8cec09..954055343e4 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iAuthenticate.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iAuthenticate.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iCache.php b/htdocs/includes/restler/framework/Luracast/Restler/iCache.php index 37d6aaea261..3b6504340b6 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iCache.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iCache.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iCompose.php b/htdocs/includes/restler/framework/Luracast/Restler/iCompose.php index b06b2c3bc6c..2bc0579befe 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iCompose.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iCompose.php @@ -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 { /** diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iFilter.php b/htdocs/includes/restler/framework/Luracast/Restler/iFilter.php index 89b50ce9812..dc1b355db0f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iFilter.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iFilter.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iIdentifyUser.php b/htdocs/includes/restler/framework/Luracast/Restler/iIdentifyUser.php index d3dd4a5d8c5..834897668db 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iIdentifyUser.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iIdentifyUser.php @@ -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 { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php b/htdocs/includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php index c7afe11fcb7..b57fc876f41 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php @@ -5,7 +5,7 @@ namespace Luracast\Restler; * Interface iProvideMultiVersionApi * @package Luracast\Restler * - * @version 3.0.0rc6 + * */ interface iProvideMultiVersionApi { diff --git a/htdocs/includes/restler/framework/Luracast/Restler/iUseAuthentication.php b/htdocs/includes/restler/framework/Luracast/Restler/iUseAuthentication.php index 611d909b305..ee3a9e0bcca 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/iUseAuthentication.php +++ b/htdocs/includes/restler/framework/Luracast/Restler/iUseAuthentication.php @@ -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 {