Skip to content
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

Fix reserved keywords with underscore #616

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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>
6 changes: 3 additions & 3 deletions public/examples/_005_protected_api/SimpleAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class SimpleAuth implements iAuthenticate
{
const KEY = 'rEsTlEr2';

function __isAllowed()
function isAllowed()
{
return isset($_GET['key']) && $_GET['key'] == SimpleAuth::KEY ? TRUE : FALSE;
}

public function __getWWWAuthenticateString()
public function getWWWAuthenticateString()
{
return 'Query name="key"';
}
Expand All @@ -19,4 +19,4 @@ function key()
{
return SimpleAuth::KEY;
}
}
}
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
4 changes: 2 additions & 2 deletions public/examples/_009_rate_limiting/KeyAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

class KeyAuth implements iAuthenticate
{
public function __isAllowed()
public function isAllowed()
{
return isset($_GET['api_key']) && $_GET['api_key'] == 'r3rocks';
}

public function __getWWWAuthenticateString()
public function getWWWAuthenticateString()
{
return 'Query name="api_key"';
}
Expand Down
4 changes: 2 additions & 2 deletions public/examples/_010_access_control/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccessControl implements iAuthenticate
public static $requires = 'user';
public static $role = 'user';

public function __isAllowed()
public function isAllowed()
{
//hardcoded api_key=>role for brevity
$roles = array('12345' => 'user', '67890' => 'admin');
Expand All @@ -28,7 +28,7 @@ public function __isAllowed()
return static::$requires == static::$role || static::$role == 'admin';
}

public function __getWWWAuthenticateString()
public function getWWWAuthenticateString()
{
return 'Query name="api_key"';
}
Expand Down
4 changes: 2 additions & 2 deletions public/examples/_011_versioning/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Which will be `Luracast\WeightManagement\v2` for this example

If a class remains the same across few versions of the api, we can implement
`iProvideMultiVersionApi` interface which is simply defining `__getMaximumSupportedVersion`
`iProvideMultiVersionApi` interface which is simply defining `getMaximumSupportedVersion`
method which returns the maximum supported version. Take a look at `Resources`
class for a sample implementation.

Expand Down Expand Up @@ -111,4 +111,4 @@ class for a sample implementation.
$r->setAPIVersion(2);
$r->addAPIClass('BMI');
$r->addAPIClass('Resources');
$r->handle();
$r->handle();
4 changes: 2 additions & 2 deletions public/examples/_015_oauth2_server/Auth/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ public function access()
*
* @return boolean true when api access is allowed; false otherwise
*/
public function __isAllowed()
public function isAllowed()
{
return self::$server->verifyResourceRequest(static::$request);
}

public function __getWWWAuthenticateString()
public function getWWWAuthenticateString()
{
return 'Bearer realm="example"';
}
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
2 changes: 1 addition & 1 deletion vendor/Luracast/Restler/CommentParser.php
Original file line number Diff line number Diff line change
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
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
2 changes: 1 addition & 1 deletion vendor/Luracast/Restler/Data/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function __set_state(array $properties)
return $instance;
}

public function __toArray()
public function toArray()
{
$r = get_object_vars($this);
$methods = get_class_methods($this);
Expand Down
2 changes: 1 addition & 1 deletion vendor/Luracast/Restler/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Defaults
* @var string authentication method to be called in iAuthenticate
* Interface
*/
public static $authenticationMethod = '__isAllowed';
public static $authenticationMethod = 'isAllowed';

/**
* @var int time in milliseconds for bandwidth throttling,
Expand Down
6 changes: 3 additions & 3 deletions vendor/Luracast/Restler/Filter/RateLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public static function setLimit(
is_null($authenticatedUsagePerUnit) ? $usagePerUnit : $authenticatedUsagePerUnit;
}

public function __isAllowed()
public function isAllowed()
{
if (static::$authenticatedUsagePerUnit
== static::$usagePerUnit
) return $this->check();
return null;
}

public function __setAuthenticationStatus($isAuthenticated = false)
public function setAuthenticationStatus($isAuthenticated = false)
{
header('X-Auth-Status: ' . ($isAuthenticated ? 'true' : 'false'));
$this->check($isAuthenticated);
Expand Down Expand Up @@ -175,4 +175,4 @@ private function duration($secs)
}
return implode(' ', $ret); //." $unit.";
}
}
}
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
10 changes: 5 additions & 5 deletions vendor/Luracast/Restler/Format/JsonFormat.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Luracast\Restler\Format;

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

/**
Expand Down Expand Up @@ -66,11 +66,11 @@ public function encode($data, $humanReadable = false)
if (self::$bigIntAsString) $options |= JSON_BIGINT_AS_STRING;
if (self::$unEscapedUnicode) $options |= JSON_UNESCAPED_UNICODE;
return json_encode(
Object::toArray($data, true), $options
Obj::toArray($data, true), $options
);
}

$result = json_encode(Object::toArray($data, true));
$result = json_encode(Obj::toArray($data, true));
if ($humanReadable) $result = $this->formatJson($result);
if (self::$unEscapedUnicode) {
$result = preg_replace_callback('/\\\u(\w\w\w\w)/',
Expand Down Expand Up @@ -110,7 +110,7 @@ public function decode($data)
if (function_exists('json_last_error')) {
switch (json_last_error()) {
case JSON_ERROR_NONE :
return Object::toArray($decoded);
return Obj::toArray($decoded);
break;
case JSON_ERROR_DEPTH :
$message = 'maximum stack depth exceeded';
Expand All @@ -137,7 +137,7 @@ public function decode($data)
throw new RestException (400, 'Error parsing JSON');
}

return Object::toArray($decoded);
return Obj::toArray($decoded);
}

/**
Expand Down
Loading