Skip to content

Commit c8af51e

Browse files
author
Tom Mitchelmore
committed
Tag v8.1
1 parent b1356be commit c8af51e

30 files changed

+5059
-1
lines changed

docs/upgrade-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 3
88

99
## Upgrading from v8 to v8.1
1010

11-
Estimated time for upgrade: 30 minutes
11+
Estimated time for upgrade: 5 minutes
1212

1313
### Minimum PHP version increased to PHP 8.3
1414

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
id: introduction
3+
title: Introduction
4+
description: Supercharge your WordPress Development
5+
sidebar_position: 1
6+
---
7+
8+
# Introduction
9+
10+
Lumberjack is a powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code.
11+
12+
### Who is Lumberjack for?
13+
14+
Coming from another PHP framework such as Laravel, have experience using Timber with WordPress but want more, or are just getting started with modern WordPress? Then Lumberjack is for you.
15+
16+
Use as little or as much as you need, it's beginner friendly!
17+
18+
### Beautiful code. Easy to maintain
19+
20+
Object orientated and MVC patterns help keep your code structured and DRY.
21+
22+
**index.php**
23+
24+
```php
25+
class IndexController
26+
{
27+
public function handle()
28+
{
29+
$context = Timber::context();
30+
$context['posts'] = Post::builder()
31+
->whereStatus('publish')
32+
->limit(5)
33+
->get();
34+
35+
return new TimberResponse('index.twig', $context);
36+
}
37+
}
38+
```
39+
40+
**index.twig**
41+
42+
```twig
43+
{% if posts is not empty %}
44+
<h4>Recent Articles</h4>
45+
<ul>
46+
{% for post in posts %}
47+
<li class="article">
48+
<h3>{{ $post->title }}</h3>
49+
{{ $post->preview }}
50+
<a href="{{ $post->link }}">Read the full story</a>
51+
</li>
52+
{% endfor %}
53+
</ul>
54+
{% endif %}
55+
```
56+
57+
### You're in good company
58+
59+
> Lumberjack is the deluxe version of what Modern WordPress should look like today. The team has done a great job of making it easy to build complicated custom applications while taking advantage of the best parts of WordPress.
60+
>
61+
> - _**Jared Novack - Timber creator**_
62+
63+
Standing on the shoulders of giants, Lumberjack proudly builds on the great work of other open source WordPress projects:
64+
65+
- [Timber](https://www.upstatement.com/timber/)
66+
- [Bedrock](https://roots.io/bedrock/)
67+
68+
### Made by [Rareloop](https://rareloop.com)
69+
70+
We're a Digital Product Studio based in Southampton (UK) with many years experience working on modern WordPress websites. We design and build digital products for a range of clients, take a look at what else we can do.
71+
72+
[Find out more](https://www.rareloop.com/)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Container",
3+
"position": 6
4+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# Facades
6+
7+
Lumberjack provides a custom implementation of Facades, based on the now-deprecated [Blast Facades](https://github.com/phpthinktank/blast-facades) library.
8+
9+
## Creating a Facade
10+
11+
Facades provide a simple static API to an object that has been registered into the container. For example to setup a facade you would first use a Service Provider to register an instance of your class into the container:
12+
13+
```php
14+
namespace Rareloop\Lumberjack\Providers;
15+
16+
use Monolog\Logger;
17+
use Rareloop\Lumberjack\Application;
18+
19+
class LogServiceProvider extends ServiceProvider
20+
{
21+
public function register()
22+
{
23+
// Create object instance and bind into container
24+
$this->app->bind('logger', new Logger('app'));
25+
}
26+
}
27+
```
28+
29+
Then create a Facade subclass and tell it which key to use to retrieve your class instance:
30+
31+
```php
32+
namespace Rareloop\Lumberjack\Facades;
33+
34+
use Rareloop\Lumberjack\Facades\AbstractFacade;
35+
36+
class Log extends AbstractFacade
37+
{
38+
protected static function accessor()
39+
{
40+
return 'logger';
41+
}
42+
}
43+
```
44+
45+
## Available Facades
46+
47+
Lumberjack comes with a handful of useful Facades. Below you can see which class the Facade references and what it is bound to the container under.
48+
49+
| Facade | Class Reference | Container binding |
50+
| :------ | :------------------------------------------- | :---------------- |
51+
| Config | `Rareloop\Lumberjack\Config` | `config` |
52+
| Log | `Monolog\Logger` | `logger` |
53+
| Router | `Rareloop\Lumberjack\Http\Route` | `router` |
54+
| Session | `Rareloop\Lumberjack\Session\SessionManager` | `session` |
55+
56+
### Example usage
57+
58+
All of Lumberjack's Facades live under the `Rareloop\Lumberjack\Facades` namespace.
59+
60+
#### Config
61+
62+
The `Config` facade allows you to get and set values from your config.
63+
64+
```php
65+
use Rareloop\Lumberjack\Facades\Config;
66+
67+
Config::set('app.debug', false);
68+
69+
$value = Config::get('app.debug');
70+
```
71+
72+
Config is also available as a [Helper](/the-basics/helpers#config)
73+
74+
#### Log
75+
76+
The `Log` facade allows you to use the [PSR-3](https://www.php-fig.org/psr/psr-3/) Logger [Monolog](https://github.com/Seldaek/monolog).
77+
78+
```php
79+
use Rareloop\Lumberjack\Facades\Log;
80+
81+
$value = Log::warning('Oops! Something went wrong');
82+
```
83+
84+
#### Router
85+
86+
The `Router` facade allows you to create custom routes or get the URLs for your routes.
87+
88+
```php
89+
use Rareloop\Lumberjack\Facades\Router;
90+
91+
Router::get('posts/all', function () {})->name('posts.index');
92+
93+
$url = Router::url('posts.index');
94+
```
95+
96+
See [Creating Routes](/the-basics/routing#creating-routes) for more information.
97+
98+
#### Session
99+
100+
The `Session` facade allows you to retrieve and store data in the current session.
101+
102+
```php
103+
use Rareloop\Lumberjack\Facades\Session;
104+
105+
Session::put('name', 'Chris');
106+
107+
$name = Session::get('name');
108+
```
109+
110+
Session is also available as a [Helper](/the-basics/helpers#session)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Service Providers
6+
7+
## Introduction
8+
9+
When Lumberjack bootstraps it creates an Application Container, which is responsible for resolving concrete classes that have been **bound** to the container in one way or another. This binding happens via Service Providers.
10+
11+
A Service Provider needs to be registered with Lumberjack. This can be done in `config/app.php` under the `providers` array.
12+
13+
Let's look at how to create a new Service Provider and register it to the container.
14+
15+
## Creating Service Providers
16+
17+
Service Providers can live anywhere within the `app/` directory, or even as packages that you bring in via composer. Let's create a new file within `app/Providers` called `PaymentGatewayProvider.php`.
18+
19+
This file must extend `Rareloop\Lumberjack\Providers\ServiceProvider`. This gives you access to the container via `$this->app`. There are 2 methods that Lumberjack looks for on a Service Providers: `register()` and `boot()`.
20+
21+
### Register
22+
23+
The `register` method should only be used to bind things to the container. You cannot rely on Lumberjack registering service providers in any order, so you should always assume no other provider had been registered.
24+
25+
You should not attempt to do anything other than binding things to the container in `register`. Do not try and add WordPress filters/actions, register routes, configure WordPress etc here. This is to prevent you from accidentally using a service provider which has not been loaded yet.
26+
27+
```php
28+
namespace App\Providers;
29+
30+
use Rareloop\Lumberjack\Providers\ServiceProvider;
31+
32+
class PaymentGatewayProvider extends ServiceProvider
33+
{
34+
public function register()
35+
{
36+
$this->app->bind('\App\PaymentGateway', '\App\StripePaymentGateway');
37+
}
38+
}
39+
```
40+
41+
Now, whenever we need to use a payment gateway in our application we can resolve it from the container. This, in theory, makes it really easy to swap out Stripe with another payment gateway.
42+
43+
#### Binding to the container
44+
45+
There are a number of different ways to bind things to the container. Head over to ['Using the Container'](using-the-container.md) for more information.
46+
47+
### Boot
48+
49+
Once all service providers have been registered, Lumberjack then attempts to call the `boot` method on each one. This means that you have access to everything that has been bound to the container and can access it using [dependency injection](using-the-container.md#dependency-injection) on the `boot` method.
50+
51+
```php
52+
namespace App\Providers;
53+
54+
use Rareloop\Lumberjack\Providers\ServiceProvider;
55+
use Rareloop\Lumberjack\Config;
56+
57+
/**
58+
* Add Option Pages to WP using the config, using ACF
59+
*/
60+
class OptionPagesProvider extends ServiceProvider
61+
{
62+
// Dependency inject Config from the container
63+
public function boot(Config $config)
64+
{
65+
$optionPages = $config->get('option-pages');
66+
67+
if (!is_array($optionPages)) {
68+
return;
69+
}
70+
71+
foreach ($optionPages as $optionPage) {
72+
acf_add_options_page($optionPage);
73+
}
74+
}
75+
}
76+
```
77+
78+
### Register Service Providers with Lumberjack
79+
80+
Once you have your service provider ready to go, you need to add the name of the class to the `providers` array in `config/app.php`.
81+
82+
```php
83+
return [
84+
'providers' => [
85+
// ...
86+
87+
App\Providers\TwitterProvider::class,
88+
],
89+
];
90+
```

0 commit comments

Comments
 (0)