Skip to content

leafsphp/leaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation




Leaf 3

Latest Stable Version Total Downloads License



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.

πŸ—‚ Basic Usage

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

🍁 Why Leaf?

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.

The problems

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

How Leaf tackles these

Leaf 3 provides a bunch of features that aim to tackle these common problems found in just about every PHP framework out there.

  • Low barrier to entry

    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.

  • Lightweight

    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.

    image

    a comparison with slim - slim (left) - leaf (right)

  • Enables high developer productivity

    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.

  • Easy to use features

    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.

  • Library/Framework compatibility

    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.

  • Scalability

    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.

πŸ“¦ Installation

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

✈️ The Leaf Ecosystem (Libs & Frameworks)

Project Status Description
leaf Latest Stable Version Total Downloads Create websites and APIs quickly
leafmvc Latest Stable Version Total Downloads An MVC wrapper for leaf (for general development)
leafapi Latest Stable Version Total Downloads An MVC wrapper for leaf geared towards API development
skeleton Latest Stable Version Total Downloads Leaf boilerplate for rapid development
leaf-ui Latest Stable Version Total Downloads A PHP library for building user interfaces
cli Latest Stable Version Total Downloads CLI for creating & interacting with your leaf apps

🧩 The Leaf Ecosystem (Modules)

Project Status Description
alchemy Latest Stable Version Total Downloads A test runner for your Leaf apps
aloe Latest Stable Version Total Downloads Smart console helper for leaf mvc, leaf api and skeleton
anchor Latest Stable Version Total Downloads Basic security tools
auth Latest Stable Version Total Downloads Simple but powerful authentication system for your apps
bareui Latest Stable Version Total Downloads Dead simple templating engine with no compilation (blazing speed)
blade Latest Stable Version Total Downloads Laravel blade templating port for leaf
cookie Latest Stable Version Total Downloads Cookie management without the tears
cors Latest Stable Version Total Downloads CORS operations made simple
csrf Latest Stable Version Total Downloads Basic CSRF protection
date Latest Stable Version Total Downloads PHP dates for humans
devtools Latest Stable Version Total Downloads Devtools for your Leaf app
db Latest Stable Version Total Downloads Leaf Db from v2 (actively maintained)
db-old Latest Stable Version Total Downloads Leaf Db from v1 (still maintained)
exception Latest Stable Version Total Downloads Leaf's exception wrapper (fork of whoops)
experiments Latest Stable Version Total Downloads collection of experimental modules
fetch Latest Stable Version Total Downloads HTTP requests made simple
form Latest Stable Version Total Downloads Form processes and validation
fs Latest Stable Version Total Downloads Awesome filesystem operations + file uploads
http Latest Stable Version Total Downloads Http operations made simple (request, response, ...)
logger Latest Stable Version Total Downloads leaf logger module
mail Latest Stable Version Total Downloads Mailing made easy with leaf
mvc-core Latest Stable Version Total Downloads Core MVC tools powering our MVC wrappers
password Latest Stable Version Total Downloads Password encryption/validation/hashing in one box
redis Latest Stable Version Total Downloads Redis module
router Latest Stable Version Total Downloads Default router for leaf php
session Latest Stable Version Total Downloads PHP sessions made simple
tilly Latest Stable Version Total Downloads Simple utility 'toolkit' for PHP applications
veins Latest Stable Version Total Downloads Leaf veins templating engine
viewi Latest Stable Version Total Downloads Leaf integration with Viewi PHP

πŸ’¬ Stay In Touch

πŸ““ Learning Leaf 3

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

πŸ˜‡ Contributing

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.

🀩 Sponsoring Leaf

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 ❀️

🀯 Links/Projects