Upgrade Guide
We migrated away from the deprecated Zend Diactoros package to the replacement Laminas Diactoros and also took the opportunity to upgrade to v2.
This migration introduces new default namespaces but also includes a bridge package that creates aliases meaning there should be no need to upgrade namespaces in any of your app code. We plan to migrate all the namespaces used internally by Lumberjack in a future major release.
The upgrade to v2 of Diactoros also adds some additional typehints to some of their classes. We expect that for most apps these will not cause any issues. If however you have extended any of the core Diactoros classes, you may need to add additional typehints and return types to some methods. More information on what has changed in Diactoros can be found here.
There is nothing that requires upgrading between these versions.
There is nothing that requires upgrading between these versions.
We aim to document all the changes that could impact your theme, and there may only be a portion that are applicable to your theme.
Create
app/Http/Controllers/Controller.php
with the following contents:<?php
â
namespace App\Http\Controllers;
â
use Rareloop\Lumberjack\Http\Controller as BaseController;
â
class Controller extends BaseController
{
â
}
In all of your controllers, extend from this new base controller. For example:
/**
* The Template for displaying all single posts
*/
â
namespace App;
â
use App\Http\Controllers\Controller;
// ...
â
class SingleController extends Controller
{
Here are the list of controllers that come out of the box:
404.php
archive.php
author.php
index.php
page.php
search.php
single.php
There is nothing that requires upgrading between these versions.
We aim to document all the changes that could impact your theme, and there may only be a portion that are applicable to your theme.
Update
lumberjack-core
to version 4."rareloop/lumberjack-core": "^4.0"
Likelihood Of Impact: High
Support for PHP 7.0 has been dropped, ensure you're running at least PHP 7.1.
Likelihood Of Impact: Critical
Add the following providers to
config/app.php
:'providers' => [
...
Rareloop\Lumberjack\Providers\QueryBuilderServiceProvider::class,
Rareloop\Lumberjack\Providers\SessionServiceProvider::class,
Rareloop\Lumberjack\Providers\EncryptionServiceProvider::class,
],
The query builder is now part of the core, rather than an external package. If you were using the package, you will need to remove its service provider from your list of
providers
above.Likelihood Of Impact: Critical
The type hint on the
render()
function has changed to the PSR interface from the concrete Zend implementation.Make the following change in
app/Exceptions/Handler.php
:From:
use Zend\Diactoros\ServerRequest;
â
public function render(ServerRequest $request, Exception $e) : ResponseInterface
{
â
}
To:
use Psr\Http\Message\ServerRequestInterface;
â
public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface
{
â
}
No changes should be required to your application logic as Zend subclasses will already comply with the new interface.
Likelihood Of Impact: Medium
The
bind()
method on the Application
container is no longer a singleton by default when the value (2nd param) is not a primitive or object instance.When binding a concrete implementation to an interface, using singletons by default can create unexpected side affects as state is maintained across instances.
A new
singleton()
method has been provided to enable the previous behaviour. This enables the app developer to be more intentional about the behaviour they desire.For example:
// Singleton
$app->singleton(App\AppInterface::class, App\AppImplementation::class);
$object1 = $app->get(App\AppInterface::class);
$object2 = $app->get(App\AppInterface::class);
â
// The same object is resolved from the container
$object1 === $object2; // true
â
// Bind
$app->bind(App\AppInterface::class, App\AppImplementation::class);
$object1 = $app->get(App\AppInterface::class);
$object2 = $app->get(App\AppInterface::class);
â
// The container resolves new instances, so the objects are not the same
$object1 === $object2; // false
Likelihood Of Impact: Optional, but recommended
If you're injecting an instance of the Diactoros
ServerRequest
class into a Controller, you can now switch this out for the following class if you want to benefit from some of the new helper functions:Rareloop\Lumberjack\Http\ServerRequest
For example:
use Rareloop\Lumberjack\Http\ServerRequest;
â
class MyController
{
public function show(ServerRequest $request)
{
$name = $request->input('name');
}
}
If you have enabled global helpers, you can use access the current
ServerRequest
instance using the request()
helper instead of using dependency injection. For example:class MyController
{
public function show()
{
$name = $request->input('name');
}
}
Here's a quick overview of what the new
ServerRequest
object can do. If you are using global helpers, you can replace $request
with request()
instead in the examples below:// Get all query parameters
$request->query();
â
// Get a specific query parameter
$request->query('name');
â
// Get a specific query parameter with a default
$request->query('name', 'Jane');
// Get all input params (from $_GET and $_POST)
$request->input();
â
// Get a specific input parameter
$request->input('name');
â
// Get a specific input parameter, with a default
$request->input('name', 'Jane');
â
// Check if the request has a key
$request->has('name');
Likelihood Of Impact: Medium
This is a previously undocumented feature. If you are using ViewModels, this is a major change to how they work. However, if you are not using ViewModels you do not need to do anything.
View Models are simple classes that allow you to transform data that would otherwise be defined in your controller. This allows for better encapsulation of code and allows your code to be re-used across your controllers (and even across themes).
The
ViewModel
base class no longer extends from stdClass
and so can no longer have arbitrary properties set on it.We'd suggest upgrading your existing ViewModels to either use public methods or public properties. If your project has a large number of ViewModel's, the simplest change is to specifically name all properties in the class.
For example:
// Lumberjack v3
use Rareloop\Lumberjack\ViewModel;
â
class MyViewModel extends ViewModel
{
public function __construct($post)
{
$this->title = $post->title;
$this->link = $post->link;
}
}
To:
// Lumberjack v4
use Rareloop\Lumberjack\ViewModel;
â
class MyViewModel extends ViewModel
{
// Declare the class properties
public $title;
public $link;
â
public function __construct($post)
{
$this->title = $post->title;
$this->link = $post->link;
}
}
Likelihood Of Impact: Very low
In
bootstrap/app.php
you should change how the exception handler is bound to Rareloop\Lumberjack\Exceptions\HandlerInterface
.From:
$app->bind(HandlerInterface::class, $app->make(Handler::class));
To:
$app->singleton(HandlerInterface::class, Handler::class);
Likelihood Of Impact: Very low
Helpers::app()
(and the app()
global counterpart) no longer use the make()
method of the Application instance and now rely on get()
. This provides much more consistent behaviour with other uses of the Container. If you still want to use the helpers to get make()
behaviour you can change your code.From:
Helpers::app(MyClassName::class);
To:
Helpers::app()->make(MyClassName::class);
Likelihood Of Impact: Very low
If you resolve an instance of the
Router
class from the container, you'll need to change the class reference.If you're just using the Router Facade, you do not need to change anything.
From:
use Rareloop\Router\Router
To:
Rareloop\Lumberjack\Http\Router
Likelihood Of Impact: Very low
The
http-interop/http-server-middleware
package has been deprecated in favour of the now official PSR-15 interfaces found in psr/http-server-middleware
.Make sure any middleware used now complies with the
Psr\Http\Server\MiddlewareInterface
interface.Last modified 2yr ago