Skip to content

Commit

Permalink
Add support for optional parameters
Browse files Browse the repository at this point in the history
Add more tests
Update documentation
  • Loading branch information
gigili committed Aug 22, 2024
1 parent 3c67bc7 commit 7a99129
Show file tree
Hide file tree
Showing 5 changed files with 861 additions and 587 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
charset = utf-8
end_of_line = crlf
indent_size = 4
indent_style = space
indent_style = tab
insert_final_newline = false
max_line_length = 120
tab_width = 4
Expand Down
32 changes: 21 additions & 11 deletions sample/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

/** @noinspection PhpUnusedParameterInspection */

use Gac\Routing\Exceptions\CallbackNotFound;
use Gac\Routing\Exceptions\RouteNotFoundException;
use Gac\Routing\Request;
use Gac\Routing\Routes;
use Gac\Routing\sample\HomeController;
use Gac\Routing\sample\InjectController;
use Gac\Routing\sample\InjectedClass;
use Gac\Routing\sample\Middleware;

#include_once "../Routes.php"; # IF YOU'RE NOT USING composer
use Gac\Routing\Exceptions\CallbackNotFound;
use Gac\Routing\Exceptions\RouteNotFoundException;
use Gac\Routing\Request;
use Gac\Routing\Routes;
use Gac\Routing\sample\HomeController;
use Gac\Routing\sample\InjectController;
use Gac\Routing\sample\InjectedClass;
use Gac\Routing\sample\Middleware;

#include_once "../Routes.php"; # IF YOU'RE NOT USING composer
#include_once "HomeController.php"; # IF YOU'RE NOT USING composer

include_once '../vendor/autoload.php'; # IF YOU'RE USING composer
Expand Down Expand Up @@ -160,7 +160,9 @@
//This $otherRoutes variable could be defined in a different file and included here only via require or include
$otherRoutes = new Routes();
$otherRoutes->prefix("/sample")
->get("/", function (Request $request) { })
->get("/", function (Request $request) {
echo "hello";
})
->get("/sample1", function (Request $request) { })
->get("/sample2", function (Request $request) { })
->save();
Expand All @@ -187,6 +189,14 @@
[ InjectController::class ]
);

#echo "<pre>";
#print_r($routes->get_routes());
#die(1);

$routes->get("/optional/{id?}", function (Request $request, $id = -999) {
echo "Optional route here with id: $id";
});

$routes->handle();
} catch ( RouteNotFoundException $ex ) {
$routes->request->status(404, 'Route not found')->send([ 'error' => [ 'message' => $ex->getMessage() ] ]);
Expand Down
7 changes: 5 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ private function parse_patch_and_put_request_data(): array
/* Close the streams */
fclose($putData);

// Fetch content and determine boundary
$boundary = substr($raw_data, 0, strpos($raw_data, "\r\n"));
$index = strpos($raw_data, "\r\n");
$index = $index === false ? 0 : $index;

// Fetch content and determine boundary
$boundary = substr($raw_data, 0, $index);

if ( empty($boundary) ) {
parse_str($raw_data, $data);
Expand Down
Loading

0 comments on commit 7a99129

Please sign in to comment.