0.15.0
The release of 0.15.0 is a major stepping stone towards a stable 1.0.0 release. As such, it includes a number of minor breaking changes aimed at extensibility and consistency across the board.
What's New
-
Defining routes and route groups has been completely rewritten (docs).
-
You can now define Web, Admin and AJAX routes each with their own global middleware.
-
Automatic namespace prefixes have been added for Controllers, View Composers and Middleware.
This allows you to define controllers like this:HomeController@home
which will be automatically prefixed like this:
\App\Controllers\HomeController@home
Note: you can still use fully qualified class names - the prefix is only added if the class does not exist.
-
Route namespace prefixes can be adjusted on a per-group or per-route basis.
For example this:Route::setNamespace( '\\App\\Controllers\\Dashboard\\')->group( function () { Route::get()->url( '/dashboard/profile' )->handle( 'Profile@view' ); } );
will result in this:
\App\Controllers\Dashboard\Profile@view
-
Added a new
Route::view()
shortcut to directly rendering a view in response to a request.
Example:Route::get()->url( '/' )->view( 'index.php' );
-
Middlewares now use string aliases that you need to register in your configuration (docs).
Example:// Configuration: 'middleware' => [ 'foo' => FooMiddleware::class, ], // Routes: Route::middleware( 'foo' )->...
-
Added ability to pass basic parameters to middleware (docs).
Example:Route::middleware( 'user.can:manage_options' )->...
-
Arbitrary middleware groups can now be created and assigned as middleware to routes by utilizing the new aliases functionality. You can even reference groups within groups (docs).
Example:// Configuration: 'middleware_groups' => [ 'privileged' => [ 'user.logged_in', 'user.can:manage_options', ], ], // Routes: Route::middleware( 'privileged' )->...
-
Middleware ordering has been simplified and made consistent in cases where priority has not been specified (docs).
-
Middleware classes are now instantiated through the container allowing for dependency injection.
-
Introduced several new built-in middlewares to deal with authentication and authorization:
user.logged_in
,user.logged_out
anduser.can
(docs). -
Introduced
WPEmerge\run()
which allows you to run a full middleware + controller pipeline and get a response object independently from defined routes.
Running this:$response = \WPEmerge\run( \WPEmerge\Requests\Request::fromGlobals(), ['user.logged_in'], function ( $request, $foo ) { return 'Hello ' . $foo; }, ['World'] );
will result in a PSR-7 response object be it a redirect response if the user is not logged in due to the middleware supplied or a 200 OK response with a body of 'Hello World'.
If you want to output the response as usual you can use\WPEmerge\Facades\Response::respond( $response )
; -
Added support for multiple views directories for all view engines.
You can now specify a single path or an array of paths. -
Fixed a race condition in Blade and Twig which caused global variables to not be available if registered too early.
-
The URL condition now has full regular expression support through a new parameter (docs).
Example:Route::get()->url( '/year/{year}', ['year' => '/^\d+$/'] )->...
-
Added
@method
annotations for every facade class for improved IDE support. -
Various codebase-covering improvements targeting consistency and simplicity.
-
Various improvements to the documentation including a new
CONTRIBUTING.md
file in the repository.
Breaking Changes
-
Routes now must be defined in a separate file and then referenced in the configuration (docs):
// Configuration: 'routes' => [ 'web' => 'routes/web.php', 'admin' => 'routes/admin.php', 'ajax' => 'routes/ajax.php', ],
All groups are optional so you do not need to create an admin routes file if you have no admin routes.
-
Fixed PHP layout hierarchy being executed in the incorrect order (inside-out instead of outside-in).
-
Direct
\WPEmerge\Requests\Request
references have been replaced with a new\WPEmerge\Requests\RequestInterface
interface. -
app_response()
is now\WPEmerge\response()
. -
app_output
is now\WPEmerge\output()
. -
app_json
is now\WPEmerge\json()
. -
app_redirect
is now\WPEmerge\redirect()
. -
app_view
is now\WPEmerge\view()
. -
app_error
is now\WPEmerge\error()
. -
app_partial
is now\WPEmerge\render()
. -
app_layout_content
is now\WPEmerge\layout_content()
. -
->add()
is now->middleware()
-
Routes are no longer declared using
Router::
. See here for more information. -
Router::handleAll()
is nowRoute::all()
. -
The ability to specify a regular expresson inline for a URL condition parameter has been removed. Use the new separate URL condition parameter instead (docs).
-
The RouteCondition facade has been removed.
-
ServiceProviderInterface::boot()
is nowServiceProviderInterface::bootstrap()
. -
WPEmerge::boot()
is nowWPEmerge::bootstrap()
. -
Framework
facade is nowWPEmerge
. -
WPEMERGE_FRAMEWORK_KEY
constant is nowWPEMERGE_APPLICATION_KEY
. -
WPEmerge::facade()
is nowWPEmerge::alias()
. -
MiddlewareInterface has been removed and is no longer required for middleware.
-
Blade and Twig extensions will now proxy
.php
view rendering to the default view engine by default. -
An exception will no longer be thrown if
manifest.json
is missing.