Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily. Leaf introduces a cleaner and much simpler structure to the PHP language while maintaining it's flexibility. With a simple structure and a shallow learning curve, it's an excellent way to rapidly build powerful and high performant web apps and APIs.
This is a "hello world" application created using Leaf. After installing Leaf, create an index.php file.
<?php
require __DIR__ . '/vendor/autoload.php';
app()->get('/', function () {
response()->json([
'message' => 'Welcome!'
]);
});
app()->run();
You may quickly test this using the Leaf CLI:
leaf serve
Or with the built-in PHP server:
php -S localhost:8000
When it comes to building web applications, there are numerous tools and frameworks at your disposal. Nevertheless, we are convinced that Leaf is the optimal selection for developing powerful, web applications and APIs.
While PHP frameworks can make web development faster and more efficient, there are some potential challenges or drawbacks to using them, including:
- Learning curve: Most PHP frameworks have a steep learning curve, especially for developers who are new to the language or the framework's conventions.
- Performance overhead: Some PHP frameworks can add unnecessary performance overhead, due to the additional abstraction layers and features they provide.
- Code maintenance: Most frameworks require adhering to specific coding standards and conventions, which can make maintenance and updates more challenging if you are not already familiar with those standards.
- Limited flexibility: PHP frameworks can be more rigid than writing code from scratch, as they may require you to adhere to specific coding standards and conventions. This can limit your flexibility in terms of how you structure your code and handle specific use cases.
- Compatibility with other systems: Most PHP frameworks are bound to a particular ecosystem and make it difficult to randomly pick and use packages which don't have support for the framework you are using.
- Packing a ton of unused code/packages: Just about every PHP framework out there adds a ton of complexity to your applications in the form of unused code, classes and packages. This in turn leads to bloat and ultimately a drop in performance
Leaf 3 provides a bunch of features that aim to tackle these common problems found in just about every PHP framework out there.
-
Leaf is the easiest framework to learn with PHP newbies building powerful leaf apps in a few minutes of reading the docs/watching out tutorial videos. All you truly need to get started with Leaf is basic PHP knowledge and optional but recommended knowledge on some backend concepts like JWT auth and more.
-
Leaf 2 was lightweight and fast enough to be considered one of the most lightweight but powerful frameworks around, and Leaf 3 makes leaf 2 look like a joke. Leaf 3 can now be considered the most lightweight PHP framework with a source of about 30kb and allows you to build full apps and APIs which end up less than 20mb including user dependencies (leaf api). This is a big haul compared to other frameworks that require dependencies and tons of files which end up more than 200mb.
a comparison with slim - slim (left) - leaf (right)
-
A whole lot of research and testing has been done to build amazing features which allow developers to focus on only what they need: their apps. Leaf 3 has put tons of strategies together to create the best developer experience known to PHP. From things like removing class initializers and creating global functions which allow you call classes from anywhere in your application, modules and other amazing leaf features.
-
Powered by modules
Leaf 3 and its ecosystem are heavily powered by modules, which are simply pieces of leaf's functionality shipped into independently installable libraries. Modules help make leaf even more lightweight and help developers only deal with features which they need in their applications. This means that you only install what you need.
-
As mentioned above, a lot of research has gone into the developer experience for leaf 3 and one aspect was to make our existing features more performant and easier to use. We employed various strategies like modeling some features after popular libraries in other languages and frameworks. For instance, the API for leaf cors is almost an exact replica of the expressjs cors middleware.
-
Since the beginning of Leaf, we've set out to create code which could easily be integrated with other libraries and frameworks. No matter how powerful leaf is, we try to base of everything we do on simple concepts as opposed to other frameworks which need things like providers in order to access framework features in libraries.
-
One of the most beautiful things about leaf is that, no matter what package you're using with leaf, if it works in development, it will definitely work in production with near zero config, unless you want some special features. Leaf provides a core and other frameworks/libraries that build around leaf. This makes leaf appropriate for almost any project no matter it's size.
You can create a Leaf 3 app with the Leaf CLI
leaf create <project-name> --basic
<project-name>
is the name of your project
You can also use Composer to install Leaf 3 in your project quickly.
composer require leafs/leaf
Project | Status | Description |
---|---|---|
leaf | Create websites and APIs quickly | |
leafmvc | An MVC wrapper for leaf (for general development) | |
leafapi | An MVC wrapper for leaf geared towards API development | |
skeleton | Leaf boilerplate for rapid development | |
leaf-ui | A PHP library for building user interfaces | |
cli | CLI for creating & interacting with your leaf apps |
Project | Status | Description |
---|---|---|
alchemy | A test runner for your Leaf apps | |
aloe | Smart console helper for leaf mvc, leaf api and skeleton | |
anchor | Basic security tools | |
auth | Simple but powerful authentication system for your apps | |
bareui | Dead simple templating engine with no compilation (blazing speed) | |
blade | Laravel blade templating port for leaf | |
cookie | Cookie management without the tears | |
cors | CORS operations made simple | |
csrf | Basic CSRF protection | |
date | PHP dates for humans | |
devtools | Devtools for your Leaf app | |
db | Leaf Db from v2 (actively maintained) | |
db-old | Leaf Db from v1 (still maintained) | |
exception | Leaf's exception wrapper (fork of whoops) | |
experiments | collection of experimental modules | |
fetch | HTTP requests made simple | |
form | Form processes and validation | |
fs | Awesome filesystem operations + file uploads | |
http | Http operations made simple (request, response, ...) | |
logger | leaf logger module | |
Mailing made easy with leaf | ||
mvc-core | Core MVC tools powering our MVC wrappers | |
password | Password encryption/validation/hashing in one box | |
redis | Redis module | |
router | Default router for leaf php | |
session | PHP sessions made simple | |
tilly | Simple utility 'toolkit' for PHP applications | |
veins | Leaf veins templating engine | |
viewi | Leaf integration with Viewi PHP |
- Leaf has a very easy to understand documentation which contains information on all operations in Leaf.
- You can also check out our youtube channel which has video tutorials on different topics
- You can also learn from codelabs and contribute as well.
We are glad to have you. All contributions are welcome! To get started, familiarize yourself with our contribution guide and you'll be ready to make your first pull request π.
To report a security vulnerability, you can reach out to @mychidarko or @leafphp on twitter. We will coordinate the fix and eventually commit the solution in this project.
Your cash contributions go a long way to help us make Leaf even better for you. You can sponsor Leaf and any of our packages on open collective or check the contribution page for a list of ways to contribute.
And to all our existing cash/code contributors, we love you all β€οΈ