Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Anas Anjaria
    @anasanjaria

    @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 of public static $requires = 'user'; to public 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 ?

    Arul
    @Arul-
    let me answer the last question first, requires and level are public properties of AccessControl, they can be static as well

    which is equal to calling

    AccessControl::$requires = ‘user’;
    AccessControl::$level = 5;

    It just depends on what your own class supports!

    Anas Anjaria
    @anasanjaria

    @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 foremail. Expecting email inname@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 }

    actually my whole application has generic response
    Arul
    @Arul-
    @anasanjaria thats very easy
    Composer class is responsible for that
    create your own Composer class by implementing iCompose interface
    use the Composer class that comes with Restler as an example
    just alter the error response structure
    Then set
    Luracast\Restler\Defaults::$composeClass = ‘MyOwnCompose’;
    thats all
    Anas Anjaria
    @anasanjaria
    thanks @Arul-
    Csiszár Attila
    @csiszarattila

    hi
    i need little advise on annotations:

    Is it possible to annotate that i'm returning an array of models, and show model attributes on explorer under "Response Class"

    Eg:

    /** 
     * @return array (@class Users)
     */
    public function index()
    {
        return [
            new User(),
            new User(),
        ];
    }

    Thanks!

    Arul
    @Arul-
    /** 
     * @return array {@type User}
     */
    public function index()
    {
        return [
            new User(),
            new User(),
        ];
    }
    Csiszár Attila
    @csiszarattila
    Okay, thanks, it working.
    And what about showing the model attributes in the explorer, is it possible?
    Arul
    @Arul-
    which version of restler is being used? RC5 or RC6?
    Csiszár Attila
    @csiszarattila
    RC6
    Csiszár Attila
    @csiszarattila

    Okay, another problem: I cant get to show a blank request on POST/PUT in explorer

    in Restler i use:
    /**

     * @param string $name {@from body}
     */
    public function put($name)
    {    
    }

    in explorer i want to appear a blank json request under parameters:

    {
        "name" : ""
    }
    Sean Goresht
    @srsgores
    hey guys
    anyone there?
    Arul
    @Arul-
    @csiszarattila not sure I understand what you want! Could you explain a bit more?
    @srsgores even if you dont find any one when you are trying just post your question, it will be answered soon!
    Oleg Melnik
    @olegmelnik
    "debug": {
    "source": "Routes.php:431 at route stage",
    "stages": {
    "success": [
    "get"
    ],
    Arul
    @Arul-
    @olezko46 I guess you are getting 404 as Routes class could not find a route for the given url
    Matt Grosse
    @mattgrosse
    i'm getting undefined index notices here: vendor/Luracast/Restler/Routes.php on line 242
    which seems to be related to this: Luracast/Restler#416
    i'm using php 5.4
    Kit Sunde
    @kitsunde

    Looking at the live examples it doesn't seem like they are using require_once to import the APIClasses, but in my application I have to otherwise it seems like $r->addAPIClass('Foo') doesn't make that routable. How do I prevent this from happening:

    <?php
    include_once './vendor/autoload.php';
    include_once 'Foo.php';
    include_once 'Bar.php';
    include_once 'Baz.php';
    
    use Luracast\Restler\Restler;
    $r = new Restler();
    $r->addAPIClass('Foo');
    $r->addAPIClass('Bar');
    $r->addAPIClass('Baz');
    $r->handle();

    i.e. how do I stop needing to include every one of my API classes.

    Also I really wish that addAPIClass threw an exception if it can't find an APIClass. I probably spent 2 hours going through the source trying to figure out why it wasn't routing until I realized the include was missing.
    Arul
    @Arul-
    @kitsunde noted! will get back to you on the possibilities soon!
    byte.it
    @letsbyteit
    Did I get this right? Swagger 2.0 requires 'Schema'-Array for parameters located in the body? And this is currently missing in the S2-FeatureBranche, right?
    byte.it
    @letsbyteit
    Btw, I made it Swagger 2.0 compatible by adding the schema-array and change the defaultValue property to default. My code isn't really nice, but I'm going to fork the feature branch. And also, I think it's important to disable the HTML markup in the Swagger-Spec.
    Kit Sunde
    @kitsunde
    I'm using @format UploadFormat, but I can't for the life of me get it to respond with anything. I end up doing this:
      /**
       * @status 201
       * @url POST upload
       * @format UploadFormat
       * @access public
       * @throws RestException
       */
      function upload()
      {
        $media = CmsMedias::createMedia($_FILES['file']);
        header("Content-Type: application/json");
        echo json_encode(["media_id" => $media->getMediaId()]);
        exit();
      }
    While I actually want to do this:
    return ["media_id" => $media->getMediaId()];
    Kit Sunde
    @kitsunde
    Can I make Restler not eat the stack trace? I'd like to see my exceptions.
    Arul
    @Arul-
    Use your own Composer class to do that
    Jesse Weigert
    @jesseweigert
    @kitsunde I have one if you would like it.
    Jesse Weigert
    @jesseweigert
    This message was deleted
    Arul
    @Arul-
    Nice work @jesseweigert :+1:
    devnoname120
    @devnoname120

    Hello, I cannot access the command line on my server so I cannot install Composer and Restler in a conventional way. I created a local web server and I set up everything. Accessing http://localhost/HomebrewLand/public/examples/_001_helloworld/index.php/say/hello works correctly.

    Now I uploaded the project to my server, and when I write the same URL, I have the following error:

    
    Warning: Class 'Luracast\Restler\Restler' not found in /var/www/legtux.org/users/devnoname120/www/HomebrewLand/vendor/restler.php on line 6
    
    Fatal error: Class 'Luracast\Restler\Restler' not found in /var/www/legtux.org/users/devnoname120/www/HomebrewLand/public/examples/_001_helloworld/index.php on line 18

    Do you know how I could fix it?

    devnoname120
    @devnoname120

    If I modify the following line of vendor/restler.php

    if (is_readable(__DIR__ . '/autoload.php')) {

    to

    if (false && is_readable(__DIR__ . '/autoload.php')) {

    then it uses the other loader and it works. But it doesn't seem to be a proper solution (and could create issues later), so I would like to fix my issue anyway.

    byte.it
    @letsbyteit
    Anything about documentation for model-usage yet?

    I got this model-code so far:

    <?php
    
    namespace API\Models;
    
    
    use Luracast\Restler\Data\ValueObject;
    
    
    /**
     * Class Client
     *
     * A demo for model usage
     *
     * @package API\Models
     */
    class Client extends ValueObject
    {
        /**
         * @var int $id The id of the client
         */
        public $id;
    
        /**
         * @var string $surname The surname of the client
         */
        public $surname;
    
        /**
         * @var string $firstName The first name of the client
         */
        public $firstName;
    
        /**
         * @var string $emailAddress The e-mail address of the client {@type email}
         */
        public $emailAddress;
    
        /**
         * @var int $age The age of the client
         */
        public $age;
    }

    Then the API Class very simple:

    <?php
    
    namespace API\Clients;
    
    
    use API\Models\Client;
    
    
    /**
     * Class Clients
     *
     * Demonstrate the Model Usage
     *
     * @package API\Clients
     */
    class Clients
    {
        /**
         * Retrieves a client by using the Client-Model
         *
         * @param int $id
         *
         * @return Client
         */
        public function getClient($id)
        {
            $client = new Client();
            $client->id = $id;
            $client->age = 42;
            $client->surname = "Doe";
            $client->firstName = "John";
            $client->emailAddress = "john.doe@umbrella.inc";
    
            return $client;
        }
    
        /**
         * Creates client by using the Client-Model
         *
         * @param Client $client
         *
         * @return Client
         *
         * @status 201
         */
        public function postClient($client)
        {
            return $client;
        }
    
    }

    This "works", but there is no validation done on the Model-Object passed by the POST?

    byte.it
    @letsbyteit
    Screen Shot 2016-09-28 at 19.39.20.png
    You see? I passed an invalid email address and a string as ID