Skip to content

Fix for POST/PUT/PATCH calls without bodies #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5f05cdb
UTF8 error
diversen Sep 7, 2015
e04e596
Merge pull request #481 from diversen/master
Arul- Sep 7, 2015
673dcf5
Fix: typos
Oct 20, 2015
a1b76c7
fix library typo
Oct 20, 2015
fb8bed7
Merge pull request #498 from tomahock/master
Arul- Oct 20, 2015
ac780ed
Fix for #357
mankms Jan 9, 2016
0593eff
Merge pull request #515 from mankms/patch-1
Arul- Jan 9, 2016
d7b76ba
Fix typo @pformat => @format
tmotyl Oct 12, 2016
30bd367
Merge pull request #560 from tmotyl/patch-1
Arul- Oct 26, 2016
581d8d6
Fix: PHP 7 compatibility by renaming String class as Text
Arul- Jan 11, 2017
e94da23
Fix typo
PowerKiKi Mar 20, 2017
3da57f4
Merge pull request #572 from PowerKiKi/patch-1
Arul- Mar 20, 2017
3d454c8
Fix for Notice: Only variables should be passed by reference in publi…
Arul- Nov 16, 2017
097608f
[BUGFIX] Fix PHP 7.2 compatibility. Object is a reserved keyword. Fi…
Arul- Nov 16, 2017
cd0c21b
[BUGFIX] making sure get source.php is not allow access files outside…
Arul- Jan 17, 2018
188968f
[BUGFIX] Fixes CommentParser to leave out 0 in @param and @var commen…
Arul- Mar 16, 2018
80a17c1
[BUGFIX] Fixes CommentParser to confirm value before treating it as a…
logical-steps May 5, 2019
87197eb
[BUGFIX] Fixes JsonFormat to use decode parameters properly and optim…
logical-steps May 12, 2019
9b2a8cc
Fixes associative array fixing logic to keep only their non numeric i…
logical-steps May 23, 2019
75c984c
Update Validator.php
iva3682 Nov 14, 2019
f1d88c9
Merge pull request #626 from iva3682/patch-1
Arul- Nov 14, 2019
b3400cf
Remove curly brace syntax for PHP 7.4 support
TheMY3 Feb 3, 2020
9a040cd
Merge pull request #628 from YaroslavMolchan/add-php74-support
Arul- Feb 4, 2020
3dc110b
Fix PHP 7.4 support.
TheMY3 Feb 13, 2020
e82d562
Merge pull request #630 from YaroslavMolchan/add-php7.4-support-to-ma…
Arul- Feb 13, 2020
c5ddd70
Fix for POST/PUT/PATCH calls without bodies
igorsantos07 Mar 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ANNOTATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ iValueObject.
@var int policy age {@min 18} {@max 100}

When an api method is returning or having one of the parameters as an instance
of a custom class @var comments can be used with properties of that class.
of a custom class @var comments can be used with properties of that class.
They will be used for validation and documentation. Supported child attributes
are same as that of @param so they are documented under [@param](PARAM.md)

Expand Down Expand Up @@ -223,4 +223,4 @@ Specify the view file to be loaded by HtmlFormat for the given api method as rel
Similar to the `@view` but only used when an exception is thrown


---------------
---------------
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ They are documented in detail under [Annotations](ANNOTATIONS.md)

### 6. Authorize

In order to protect your api, authenticate and allow valid users
In order to protect your api, authenticate and allow valid users

```php
<?php
Expand Down
4 changes: 2 additions & 2 deletions features/bootstrap/RestContext.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use Behat\Behat\Context\BehatContext;
use Behat\Gherkin\Node\PyStringNode;
use Luracast\Restler\Data\String;
use Luracast\Restler\Data\Text;

/**
* Rest context.
Expand Down Expand Up @@ -127,7 +127,7 @@ public function thatISendPyString(PyStringNode $data)
public function theResponseContains($response)
{
$data = json_encode($this->_data);
if (!String::contains($data, $response))
if (!Text::contains($data, $response))
throw new Exception("Response value does not contain '$response' only\n\n"
. $this->echoLastResponse());
}
Expand Down
4 changes: 2 additions & 2 deletions public/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ <h2>@format</h2>

<p><strong>Example:</strong></p>

<pre><code>@pformat HtmlFormat
<pre><code>@format HtmlFormat
</code></pre>

<p>IF you want to force the request and or response format for a specific api method @format comment can be used</p>
Expand Down Expand Up @@ -364,4 +364,4 @@ <h2>@errorView</h2>

</article>
</body>
</html>
</html>
3 changes: 2 additions & 1 deletion public/examples/_007_crud/DB/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function delete ($id)
$index = $this->find($id);
if ($index === FALSE)
return FALSE;
return array_shift(array_splice($_SESSION['rs'], $index, 1));
$record = array_splice($_SESSION['rs'], $index, 1);
return array_shift($record);
}
private function install ()
{
Expand Down
6 changes: 3 additions & 3 deletions public/examples/_015_oauth2_server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

1. run composer update to make sure you have
- twig template library
- bshaffer's oauth2 libaray
- bshaffer's oauth2 library
2. make sure `public/examples/_015_oauth2_server/cache` has write permissions to create the compiled template files
3. make sure `public/examples/_015_oauth2_server/Auth/db` has write permission, this is where `oauth.sqlite` file be
created at run time
Expand Down Expand Up @@ -51,7 +51,7 @@

- **Implicit**: typically for browser based or mobile apps
- **Authorization Code**: typically for apps running on a server
- **Password Credentials**: typically used for apps that are owned by the same organisation as the OAuth service
- **Password Credentials**: typically used for apps that are owned by the same organization as the OAuth service
provider (aka, the Twitter client, etc.)
- **Client Credentials**: used by client's who want to update meta information about their site (URL's, logo's, etc.)
- **JWT Auth Grant**: the client submits a *JSON Web Token* in a request to the token endpoint. An access token
Expand Down Expand Up @@ -136,4 +136,4 @@
$r = new Restler();
$r->addAuthenticationClass('Auth\\Server', '');
$r->setOverridingFormats('JsonFormat', 'HtmlFormat', 'UploadFormat');
$r->handle();
$r->handle();
12 changes: 8 additions & 4 deletions public/examples/resources/getsource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
$require_comments = $file[0] == '.';
$file = '../' . $file;
$filepath = realpath($file);
$basepath = realpath('../../');
if (strpos($basepath, $filepath) === 0) {
$basepath = realpath('../../examples');
if (strpos($filepath, $basepath) !== 0) {
#trying to get the source outside restler examples
die('not allowed');
}
if (!file_exists($file)) die('file not found');
if (!file_exists($file)) {
die('file not found');
}
$text = file_get_contents($file);
$file = pathinfo($file, PATHINFO_FILENAME) . '.php';
if (!$require_comments) $text = strip_comments($text);
if (!$require_comments) {
$text = strip_comments($text);
}
die($file . '<pre id="php">' . htmlspecialchars($text) . "</pre>");
} else {
die('no file specified');
Expand Down
2 changes: 1 addition & 1 deletion vendor/Luracast/Restler/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function loadAliases($className)
* @return bool false unless className now exists
*/
private function loadLastResort($className, $loader = null) {
$loaders = array_unique(static::$rogueLoaders);
$loaders = array_unique(static::$rogueLoaders, SORT_REGULAR);
if (isset($loader)) {
if (false === array_search($loader, $loaders))
static::$rogueLoaders[] = $loader;
Expand Down
24 changes: 10 additions & 14 deletions vendor/Luracast/Restler/CommentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function extractData($comment)
$addNewline = true;
}
continue;
} elseif ($line{0} == '@') {
} elseif ($line[0] == '@') {
$mode = 2;
$newParam = true;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ private function extractData($comment)
list(, $param, $value) = preg_split('/\@|\s/', $line, 3)
+ array('', '', '');
list($value, $embedded) = $this->parseEmbeddedData($value);
$value = array_filter(preg_split('/\s+/msu', $value));
$value = array_filter(preg_split('/\s+/msu', $value),'strlen');
$this->parseParam($param, $value, $embedded);
}
return $this->_data;
Expand Down Expand Up @@ -273,13 +273,9 @@ private function parseParam($param, array $value, array $embedded)
$value
);
$data[$param] = $arr;
} else {
if (!is_string($value) && isset($value[self::$embeddedDataName])
&& isset($data[$param][self::$embeddedDataName])
) {
$value[self::$embeddedDataName]
+= $data[$param][self::$embeddedDataName];
}
} elseif (!is_string($value) && isset($value[self::$embeddedDataName]) &&
isset($data[$param][self::$embeddedDataName])) {
$value[self::$embeddedDataName] += $data[$param][self::$embeddedDataName];
$data[$param] = $value + $data[$param];
}
}
Expand Down Expand Up @@ -334,7 +330,7 @@ private function parseEmbeddedData($subject)
$data = $format->decode($str);
}
} else { // auto detect
if ($str{0} == '{') {
if ($str[0] == '{') {
$d = json_decode($str, true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new Exception('Error parsing embedded JSON data'
Expand Down Expand Up @@ -402,7 +398,7 @@ private function formatAuthor(array $value)
{
$r = array();
$email = end($value);
if ($email{0} == '<') {
if ($email[0] == '<') {
$email = substr($email, 1, -1);
array_pop($value);
$r['email'] = $email;
Expand All @@ -427,15 +423,15 @@ private function formatParam(array $value)
$data = array_shift($value);
if (empty($data)) {
$r['type'] = 'mixed';
} elseif ($data{0} == '$') {
} elseif ($data[0] == '$') {
$r['name'] = substr($data, 1);
$r['type'] = 'mixed';
} else {
$data = explode('|', $data);
$r['type'] = count($data) == 1 ? $data[0] : $data;

$data = array_shift($value);
if (!empty($data) && $data{0} == '$') {
if (!empty($data) && $data[0] == '$') {
$r['name'] = substr($data, 1);
}
}
Expand All @@ -451,7 +447,7 @@ private function formatVar(array $value)
$data = array_shift($value);
if (empty($data)) {
$r['type'] = 'mixed';
} elseif ($data{0} == '$') {
} elseif ($data[0] == '$') {
$r['name'] = substr($data, 1);
$r['type'] = 'mixed';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @link http://luracast.com/products/restler/
* @version 3.0.0rc5
*/
class Object
class Obj
{
/**
* @var bool|string|callable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://luracast.com/products/restler/
*/
class String
class Text
{
/**
* Given haystack contains the needle or not?
Expand Down
12 changes: 8 additions & 4 deletions vendor/Luracast/Restler/Data/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,12 @@ public static function validate($input, ValidationInfo $info, $full = null)

case 'string' :
if (!is_string($input)) {
$error .= '. Expecting alpha numeric value';
break;
if ($info->fix) {
$input = strval($input);
} else {
$error .= '. Expecting alpha numeric value';
break;
}
}
if ($info->required && $input === '') {
$error = "$name is required.";
Expand Down Expand Up @@ -516,7 +520,7 @@ public static function validate($input, ValidationInfo $info, $full = null)
if ($contentType == 'indexed') {
$input = $info->filterArray($input, true);
} elseif ($contentType == 'associative') {
$input = $info->filterArray($input, true);
$input = $info->filterArray($input, false);
}
} elseif (
$contentType == 'indexed' &&
Expand Down Expand Up @@ -623,4 +627,4 @@ public static function validate($input, ValidationInfo $info, $full = null)
throw $e;
}
}
}
}
26 changes: 13 additions & 13 deletions vendor/Luracast/Restler/Format/CsvFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Luracast\Restler\Format;


use Luracast\Restler\Data\Object;
use Luracast\Restler\Data\Obj;
use Luracast\Restler\RestException;

/**
Expand Down Expand Up @@ -44,10 +44,10 @@ class CsvFormat extends Format implements iDecodeStream
*/
public function encode($data, $humanReadable = false)
{
$char = Object::$separatorChar;
Object::$separatorChar = false;
$data = Object::toArray($data);
Object::$separatorChar = $char;
$char = Obj::$separatorChar;
Obj::$separatorChar = false;
$data = Obj::toArray($data);
Obj::$separatorChar = $char;
if (is_array($data) && array_values($data) == $data) {
//if indexed array
$lines = array();
Expand Down Expand Up @@ -109,10 +109,10 @@ public function decode($data)
while (($row = static::getRow(array_shift($lines), $keys)) !== FALSE)
$decoded [] = $row;

$char = Object::$separatorChar;
Object::$separatorChar = false;
$decoded = Object::toArray($decoded);
Object::$separatorChar = $char;
$char = Obj::$separatorChar;
Obj::$separatorChar = false;
$decoded = Obj::toArray($decoded);
Obj::$separatorChar = $char;
return $decoded;
}

Expand Down Expand Up @@ -172,10 +172,10 @@ public function decodeStream($stream)
while (($row = static::getRow(stream_get_line($stream, 0, PHP_EOL), $keys)) !== FALSE)
$decoded [] = $row;

$char = Object::$separatorChar;
Object::$separatorChar = false;
$decoded = Object::toArray($decoded);
Object::$separatorChar = $char;
$char = Obj::$separatorChar;
Obj::$separatorChar = false;
$decoded = Obj::toArray($decoded);
Obj::$separatorChar = $char;
return $decoded;
}
}
4 changes: 2 additions & 2 deletions vendor/Luracast/Restler/Format/HtmlFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Illuminate\View\FileViewFinder;
use Illuminate\View\View;
use Luracast\Restler\Data\ApiMethodInfo;
use Luracast\Restler\Data\Object;
use Luracast\Restler\Data\Obj;
use Luracast\Restler\Defaults;
use Luracast\Restler\RestException;
use Luracast\Restler\Restler;
Expand Down Expand Up @@ -313,7 +313,7 @@ public function encode($data, $humanReadable = false)
$success = is_null($exception);
$error = $success ? null : $exception->getMessage();
$data = array(
'response' => Object::toArray($data),
'response' => Obj::toArray($data),
'stages' => $this->restler->getEvents(),
'success' => $success,
'error' => $error
Expand Down
Loading