marcj / php-rest-service

Php-Rest-Service is a very simple and fast PHP class for server-side RESTful JSON APIs.
MIT License
216 stars 74 forks source link

Wrapper on __construct() #10

Closed ntvsx193 closed 10 years ago

ntvsx193 commented 10 years ago

Hello! I have class Router with __contructor(); My app build:

core.php

Server::create(API_URL, new Router)
    ->setDebugMode(DEBUG)
    ->collectRoutes()
    ->run();

router.php

class Router {
    function __construct(){
        DB::initialize();
        Transl::initialize();
        $this->user = new User();
....
    }

If i give exeption in DB or User (contructer's) result to api view as:

Fatal error: Uncaught exception 'App\ExDB' with message 'EXEC_QUERY' in 

ie I'm don't have wrapper error as:

{
    "status": 500,
    "error": "App\\ExDB",
    "message": "EXEC_QUERY",
    "file": "[file]",
    "line": [number],
    "trace": ....
}

What do you think about this?

ntvsx193 commented 10 years ago

Hm.... Solution is found!

Server::create(API_URL, 'App\Router')
    ->setDebugMode(DEBUG)
    ->collectRoutes()
    ->run();
marcj commented 10 years ago

So, issue settled? :)

ntvsx193 commented 10 years ago

Yes)