Upgrade Guide

Upgrading to v6 from from v5

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.

Lumberjack v6 adds support for PHP 8.1.

Replacing "tightenco/collect"

Illuminate's collection package "collect" has been separated from the core Laravel codebase and therefore the Tightenco package is no longer necessary.

Update namespaces for any support Tightenco\Collect classes you are using.

For example, change these:

use Tightenco\Collect\Support\Collection;
use Tightenco\Collect\Support\Arr;

To these:

use Illuminate\Support\Collection;
use Illuminate\Support\Arr;

Upgrading "rareloop/lumberjack-primer"

If you are using Primer with Lumberjack, you will need to also upgrade the rareloop/lumberjack-primer package to v2. From:

"rareloop/lumberjack-primer": "^v1.0.0",

To:

"rareloop/lumberjack-primer": "^v2.0.0",

Upgrading from v4.3 to v5

There is nothing that requires upgrading between these versions.

Upgrading to v4.3 from v4.2

There is nothing that requires upgrading between these versions.

Upgrading to v4.2 from v4.1

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.

Extending controllers

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

Upgrading to v4.1 from v4.0

There is nothing that requires upgrading between these versions.

Upgrading to v4 from v3

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.

Composer

Update lumberjack-core to version 4.

"rareloop/lumberjack-core": "^4.0"

PHP Version

Likelihood Of Impact: High

Support for PHP 7.0 has been dropped, ensure you're running at least PHP 7.1.

Service Providers

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.

Exception Handler

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.

Container

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
pageUsing the Container

ServerRequest class (optional)

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:

Query Parameters

// 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');

Input

// 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');
pageHTTP Requests

View Models

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).

Upgrading existing ViewModels

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;
    }
}

Binding of the Exception Handler

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);

Helpers::app() helper

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);

Router class namespace

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

PSR-15 Middleware

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 updated