Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API
@Arul- under app.php of laravel type structure ... i found this
'Cache' => 'Illuminate\Support\Facades\Cache',
but no corresponding service provider .. how it gonna work ?
Actually I have created my simple facade that is working in laravel framework but not on restler + laravel type structure ??
@Arul- I have created a class Users
under app/con troller
with one method protected
``/**
* @access protected
* @class AccessControl {@requires user}
*/
function index()
{
return User::all();
}``
and add authentication class AccessControl
( the one used in examples ).
error_log gives the following message
PHP Notice: Undefined index: AccessControl in /path/to/my/project/../vendor/restler/framework/Luracast/Restler/Restler.php on line 667, referer: http://api.laravel.com/explorer/
I tired to place AccessControl.php class under app/controller or under public folder where we have index.php .. but its still not working ..
am I doing anything wrong ?
@Arul- I try to debug the code & comparing the same code with working copy of example of restler ( core i.e without laravel structure ) .
I altered composer.json file in my existing code based on laravel type structure & removed "": "app/custom"
from autoload ( ps0 ) .. `
Now its not throwing that notice any more i.e PHP Notice: Undefined index: AccessControl ...
as described above ..
But what I figured out is $r->addAuthenticationClass('AccessControl');
does not have any impact on code. What am I trying to say is even writing die('aaa')
under __isAllowed
function of AccessControl does not print aaa
on screen/console log .
@Arul- is it possible that I can use https://packagist.org/packages/illuminate/hashing in restler + laravel DB structure ??
Here is what I done so far.
alter composer.json
file
"illuminate/hashing": "4.2.*"
alter app.php file under config
'providers' => array(
.........
'Illuminate\Hashing\HashServiceProvider'
),
'aliases' => array(
....
'Hash' => 'Illuminate\Support\Facades\Hash'
)`
& its not working here is the error
PHP Fatal error: Call to undefined method Illuminate\\Support\\Facades\\Hash::make() in /path/to/folder/engine/vendor/illuminate/support/Illuminate/Support/Facades/Facade.php on line 208
Is it possible or not ?
@anasanjaria here is how to make it work
require __DIR__ . '/../bootstrap/autoload.php';
$providers = $app['config']['app.providers'];
foreach ($providers as $class) {
/** @var ServiceProvider $instance */
$instance = new $class($app);
$instance->register();
}
Service providers are initialised only for artisan by default. using the above code in your index.php you can get them initialized. then Hash::make will start working!
@Arul- I need to know detail about access control / authentication layer
I have checked the code provided in examples (https://github.com/Luracast/Restler/blob/master/public/examples/_010_access_control/AccessControl.php) but still am a bit confused ...
I have following queries
Is $requires necessary for Authentication class ?
Actually I try to debug
dd($m['class']['AccessControl']['properties']);
under verifyAccess function, it shows requires param but when I add another property $level,dd($m['class']['AccessControl']['properties']);
does not have any impact.
Also when I altered the value ofpublic static $requires = 'user';
topublic static $requires = 'usdder';
it is not authenticating & gives the following response
`
@url http://localhost/restler/engine/public/resources.json?api_key=12345
@response
{
"apiVersion": "1",
"swaggerVersion": "1.1",
"basePath": "http://localhost/restler/engine/public",
"produces": [
"application/json",
"application/xml"
],
"consumes": [
"application/json",
"application/xml"
],
"apis": [
{
"path": "/resources/users.{format}",
"description": ""
}
]
}`
Also in the link ( http://restler3.luracast.com/annotations.html ) I found this sample code / annotations@class AccessControl {@requires user} {@level 5}
What is the usage of level ?
which is equal to calling
AccessControl::$requires = ‘user’;
AccessControl::$level = 5;
It just depends on what your own class supports!
@Arul- is it possible that I can alter response generated by validation class ... say email is not valid then it gives me something like this
{
"error": {
"code": 400,
"message": "Bad Request: Invalid value specified for
email. Expecting email in
name@example.comformat"
},
"debug": {
"source": "Validator.php:455 at validate stage",
"stages": {
"success": [
"get",
"route",
"negotiate"
],
"failure": [
"validate",
"message"
]
}
}
}
but I want something like
{
"header": {
"code": my_code,
"message": my_message_or_set_via_annotations
},
"body": my_body
}