Skip to content

Commit

Permalink
Internal responses have been corrected, the response class is obsolet…
Browse files Browse the repository at this point in the history
…e and deprecated for Lion-Routes.
  • Loading branch information
Sleon4 committed Mar 16, 2022
1 parent 3196bb0 commit 13fa553
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 78 deletions.
63 changes: 31 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ composer require lion-framework/lion-route
## Usage
```php
require_once("vendor/autoload.php");
spl_autoload_register(function($class_name) {
require_once(str_replace("\\", "/", $class_name) . '.php');
});

use LionRoute\Route;
use LionRoute\Request;

Route::init([
'class' => [
Expand All @@ -23,22 +19,13 @@ Route::init([
]);

Route::any('/', function() {
Route::processOutput(new Request(
'success',
'hello world'
));
return [
'status' => "success",
'message' => "Hello world"
];
});

// or

Route::any('/', function() {
Route::processOutput([
'status' => "warning",
'message' => "Hello world."
]);
});

// 1 is for production and 2 for local environment.
// 1 is for production and 2+ for local environment.
Route::processOutput(Route::dispatch(2));
```

Expand Down Expand Up @@ -80,7 +67,7 @@ is identical to filters, we change the name of `filter` to `middleware`.
`Route::newMiddleware('auth', Auth::class, 'auth')` is the basic syntax for adding a middleware to our RouteCollector object, The first parameter is the name of the middleware, The second parameter is the class to which that is referenced and the third parameter the name of the function to which it belongs.
```php
use LionRoute\Route;
use App\Http\Middleware\Auth;
use Example\Auth;

Route::init([
'class' => [
Expand All @@ -93,23 +80,23 @@ Route::init([
]);

Route::middleware(['before' => 'auth'], function() {
Route::post('/login', function() {
Route::processOutput([
Route::post('login', function() {
return [
'status' => "success",
'message' => "Hello world."
]);
];
});
});
```

### Prefix Groups:
```php
Route::prefix('/authenticate', function() {
Route::post('/login', function() {
Route::processOutput([
Route::prefix('authenticate', function() {
Route::post('login', function() {
return [
'status' => "success",
'message' => "Hello world."
]);
];
});
});
```
Expand All @@ -118,23 +105,35 @@ Route::prefix('/authenticate', function() {
#### POST
```php
Route::post('/example-url', function() {
$loginController = new App\Http\Controllers\Login();
$loginController->loginAuth();
$post = new Example();
$post->postMethod();
});

// or

Route::post('/example-url', [App\Http\Controllers\Login::class, 'loginAuth']);
Route::post('/example-url', [Example::class, 'postMethod']);
```

#### PUT
```php
Route::put('/example-url/{id}', function($id) {
$loginController = new App\Http\Controllers\Login();
$loginController->loginAuth();
$put = new Example();
$put->putMethod();
});

// or

Route::put('/example-url/{id}', [Example::class, 'putMethod']);
```

#### DELETE
```php
Route::delete('/example-url/{id}', function($id) {
$delete = new Example();
$delete->deleteMethod();
});

// or

Route::post('/example-url/{id}', [App\Http\Controllers\Login::class, 'loginAuth']);
Route::delete('/example-url/{id}', [Example::class, 'deleteMethod']);
```
44 changes: 0 additions & 44 deletions src/LionRoute/Request.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/LionRoute/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LionRoute;

use LionRoute\Middleware;
use LionRoute\Request;

class Route {

Expand Down Expand Up @@ -105,7 +104,7 @@ public static function dispatch($index) {
self::processInput($index)
);
} catch (\Exception $e) {
return new Request("error", $e->getMessage());
return ['status' => "error", 'message' => $e->getMessage()];
}
}

Expand Down

0 comments on commit 13fa553

Please sign in to comment.