Hello there π β
Leaf is a slim and lightweight PHP framework focused on developer experience, usability, and high-performance code. It is a modern PHP framework built to be simple and elegant, yet extremely powerful.
<?php
require __DIR__ . '/vendor/autoload.php';
app()->get('/', function () {
response()->json(['message' => 'Hello World!']);
});
app()->run();
Writing code should be simple and fun, and that's what Leaf is all about.
Why Leaf? β
PHP frameworks often come with a steep learning curve, performance overhead, and strict conventions, which can complicate maintenance and limit flexibility amongst other issues like bloat. Leaf addresses these challenges by offering a range of features designed to make web development easier and more enjoyable:
Leaf is beginner-friendly, enabling PHP newcomers to build powerful apps within minutes. All you need is basic PHP knowledge and, optionally, some backend web dev familiarity.
Leaf is lightweight and blazing fast with a minimal core and a load of optional modules for building full apps and APIs efficiently, offering high performance and low memory usage.
Leaf is built to enhance developer focus, offering features like class-free initializers and global functions for easy access to classes across your app, creating an optimized PHP developer experience.
Leaf is designed for seamless integration with other libraries and frameworks, prioritizing simplicity over complex setups like providers needed by other frameworks.
Leaf is highly scalable, and grows with your project. Its core and ecosystem of libraries make it ideal for projects of any size.
How to Use These Docs β
On the left side of the screen, you'll find the docs navbar. The pages of the docs are organized sequentially, from basic to advanced, so you can follow them step-by-step when building your application. However, you can read them in any order or skip to the pages that apply to your use case.
On the right side of the screen, you'll see a table of contents that makes it easier to navigate between sections of a page. If you need to quickly find a page, you can use the search bar at the top, or the search shortcut (Ctrl+K or Cmd+K).
To get started, check out the Installation guide.
Pre-Requisite Knowledge β
Although our docs are designed to be beginner-friendly, we need to establish a baseline so that the docs can stay focused on Leaf's functionality. We assume you have a basic understanding of PHP and it's syntax, as well as a little familiarity with web development concepts like HTTP, routing, and middleware.
Don't worry if you're not familiar with these concepts, we'll provide videos and links to relevant documentation whenever we introduce a new concept like the one below:
Functions vs Class Mode β
Leaf is built with many classes and components, but for simpler apps or APIs, it also offers a functional mode. This lets you use Leaf and its modules without class imports, instantiation, or lengthy namespacesβkeeping things simple and streamlined.
Of course, you can still use Leaf in class mode if you prefer that. Here's an example of a simple Leaf app in functional mode:
<?php
use Leaf\App;
require __DIR__ . '/vendor/autoload.php';
$app = new App;
$app->get('/', function () use ($app) {
$app->response()->json(['message' => 'Leaf is amazing!']);
});
$app->run();
The documentation will usually show you how to use modules in functional mode as this is the default mode for Leaf. However, if you are migrating from another framework or you prefer to use Leaf in class mode, you can always instantiate the classes and use them as you would in any other framework.
Getting Started β
Ready to get started? Check out the installation guide to get Leaf up and running in no time. You can also check out the interactive tutorial to learn more about Leaf's core concepts and features.