PHP Route v1.0.7 Release
Release Date: December 6, 2024
π What's New
Major Features
1οΈβ£ Multiple Middleware Format Support
Three ways to define middleware - choose what works best for you:
// Closure Route::get('/path', $handler, [ function($req, $res) { return true; } ]);// Static class
Route::get('/path', $handler, ['AuthMiddleware@check']);
// Instance
Route::get('/path', $handler, [new RateLimitMiddleware(100), 'check']);
2οΈβ£ Middleware Attribute Persistence
Middleware can now set attributes that are accessible in route handlers:
// Middleware sets attribute $req->withAttribute('user_id', 123);
// Handler accesses it
$userId = $req->getAttribute('user_id'); // 123
3οΈβ£ Fixed Optional Route Parameters
Optional parameters {?paramName} now work correctly:
Route::get('/post/{?slug}', function($req, $res) { $slug = $req->getAttribute('slug') ?? 'default'; $res->json(['slug' => $slug]); });
// All these work now:
// GET /post β slug = null
// GET /post/hello β slug = "hello"
// GET /post/2 β slug = "2" β FIXED!
4οΈβ£ Middleware Control Flow
Middleware now supports proper return value control:
function($req, $res) {
if (!$req->getHeaderLine('Authorization')) {
$res->json(['error' => 'Unauthorized'], 401);
return false; // Stop request
}
return true; // Continue
}
π§ Technical Improvements
Request Class
- Direct attribute modification (no more cloning)
- Custom attribute storage for faster access
- Merged attribute access from all sources
Route Class
- Improved regex generation for optional parameters
- Better middleware execution pipeline
- Proper attribute persistence across chain
- Query string removal in URI normalization
π Regex Pattern Examples
Optional parameters now generate correct regex:
{?slug} β #^/post(?:/(?P<slug>[^/]+))?/?$#
{?page:\d+} β #^/page(?:/(?P<page>\d+))?/?$#
{id}/posts/{?tag} β #^/user/(?P<id>[^/]+)/posts(?:/(?P<tag>[^/]+))?/?$#
β¨ Example: Complete Feature Showcase
<?php class AuthMiddleware { public static function check(Request $req, Response $res) { $token = $req->getHeaderLine('Authorization'); if (empty($token)) { $res->json(['error' => 'Unauthorized'], 401); return false; }// Set user attributes $req->withAttribute('user_id', 123); $req->withAttribute('user_role', 'admin'); return true; }}
// Route with optional parameter and middleware
Route::get('/user/{?filter}', function($req, $res) {
$userId = $req->getAttribute('user_id'); // From middleware
$filter = $req->getAttribute('filter'); // From URL$res->json([ 'user_id' => $userId, 'filter' => $filter ?? 'none' ]);}, ['AuthMiddleware@check']);
// URLs that now work:
// GET /user β user_id=123, filter=null β
// GET /user/active β user_id=123, filter="active" β
β What's Fixed
| Issue | Before | After |
|---|---|---|
| Optional params | β 404 error | β Works correctly |
| Middleware attributes | β Lost between middleware | β Persist to handler |
| Middleware formats | β Closures only | β 3 format types |
| Middleware control | β Full control (true/false) |
π Backward Compatibility
β 100% Backward Compatible
- No breaking changes
- All v1.0.6 code works as-is
- Just add new features where needed
π Documentation
New guides added:
- Optional parameters complete guide
- Request attributes explanation
- Middleware attribute usage examples
- Route regex pattern testing utility
- Troubleshooting section
π Bug Fixes
- Optional parameters returning 404 - FIXED
- Middleware attributes not persisting - FIXED
- Query string interference - FIXED
- Multiple trailing slash handling - FIXED
π Installation & Upgrade
Fresh Install
composer require refkinscallv/php-route
Upgrade from v1.0.6
composer update refkinscallv/php-route
No code changes required - just works!
π Learn More
π€ Feedback
Found issues? Have suggestions?
- π Report Bugs
- π‘ Request Features
- β Star us on GitHub
π Release Checklist
- β Features implemented and tested
- β Documentation updated
- β Examples provided
- β Backward compatibility verified
- β No breaking changes
Thank you for using PHP Route! Happy routing! π
For detailed changelog, see CHANGELOG.md
# PHP Route v1.0.7 ReleaseRelease Date: December 6, 2024
π What's New
Major Features
1οΈβ£ Multiple Middleware Format Support
Three ways to define middleware - choose what works best for you:
// Closure
Route::get('/path', $handler, [
function($req, $res) { return true; }
]);
// Static class
Route::get('/path', $handler, ['AuthMiddleware@check']);
// Instance
Route::get('/path', $handler, [new RateLimitMiddleware(100), 'check']);2οΈβ£ Middleware Attribute Persistence
Middleware can now set attributes that are accessible in route handlers:
// Middleware sets attribute
$req->withAttribute('user_id', 123);
// Handler accesses it
$userId = $req->getAttribute('user_id'); // 1233οΈβ£ Fixed Optional Route Parameters
Optional parameters {?paramName} now work correctly:
Route::get('/post/{?slug}', function($req, $res) {
$slug = $req->getAttribute('slug') ?? 'default';
$res->json(['slug' => $slug]);
});
// All these work now:
// GET /post β slug = null
// GET /post/hello β slug = "hello"
// GET /post/2 β slug = "2" β
FIXED!4οΈβ£ Middleware Control Flow
Middleware now supports proper return value control:
function($req, $res) {
if (!$req->getHeaderLine('Authorization')) {
$res->json(['error' => 'Unauthorized'], 401);
return false; // Stop request
}
return true; // Continue
}π§ Technical Improvements
Request Class
- Direct attribute modification (no more cloning)
- Custom attribute storage for faster access
- Merged attribute access from all sources
Route Class
- Improved regex generation for optional parameters
- Better middleware execution pipeline
- Proper attribute persistence across chain
- Query string removal in URI normalization
π Regex Pattern Examples
Optional parameters now generate correct regex:
{?slug} β #^/post(?:/(?P<slug>[^/]+))?/?$#
{?page:\d+} β #^/page(?:/(?P<page>\d+))?/?$#
{id}/posts/{?tag} β #^/user/(?P<id>[^/]+)/posts(?:/(?P<tag>[^/]+))?/?$#
β¨ Example: Complete Feature Showcase
<?php
class AuthMiddleware {
public static function check(Request $req, Response $res) {
$token = $req->getHeaderLine('Authorization');
if (empty($token)) {
$res->json(['error' => 'Unauthorized'], 401);
return false;
}
// Set user attributes
$req->withAttribute('user_id', 123);
$req->withAttribute('user_role', 'admin');
return true;
}
}
// Route with optional parameter and middleware
Route::get('/user/{?filter}', function($req, $res) {
$userId = $req->getAttribute('user_id'); // From middleware
$filter = $req->getAttribute('filter'); // From URL
$res->json([
'user_id' => $userId,
'filter' => $filter ?? 'none'
]);
}, ['AuthMiddleware@check']);
// URLs that now work:
// GET /user β user_id=123, filter=null β
// GET /user/active β user_id=123, filter="active" β
β What's Fixed
| Issue | Before | After |
|---|---|---|
| Optional params | β 404 error | β Works correctly |
| Middleware attributes | β Lost between middleware | β Persist to handler |
| Middleware formats | β Closures only | β 3 format types |
| Middleware control | β Full control (true/false) |
π Backward Compatibility
β 100% Backward Compatible
- No breaking changes
- All v1.0.6 code works as-is
- Just add new features where needed
π Documentation
New guides added:
- Optional parameters complete guide
- Request attributes explanation
- Middleware attribute usage examples
- Route regex pattern testing utility
- Troubleshooting section
π Bug Fixes
- Optional parameters returning 404 - FIXED
- Middleware attributes not persisting - FIXED
- Query string interference - FIXED
- Multiple trailing slash handling - FIXED
π Installation & Upgrade
Fresh Install
composer require refkinscallv/php-routeUpgrade from v1.0.6
composer update refkinscallv/php-routeNo code changes required - just works!
π Learn More
- [Full Documentation](https://github.com/refkinscallv/php-route)
- [Optional Parameters Guide](https://github.com/refkinscallv/php-route#optional-parameters)
- [Middleware Guide](https://github.com/refkinscallv/php-route#middleware-system)
- [Request Attributes](https://github.com/refkinscallv/php-route#request-attributes)
π€ Feedback
Found issues? Have suggestions?
- π [Report Bugs](https://github.com/refkinscallv/php-route/issues)
- π‘ [Request Features](https://github.com/refkinscallv/php-route/discussions)
- β [Star us on GitHub](https://github.com/refkinscallv/php-route)
π Release Checklist
- β Features implemented and tested
- β Documentation updated
- β Examples provided
- β Backward compatibility verified
- β No breaking changes
Thank you for using PHP Route! Happy routing! π