Giter VIP home page Giter VIP logo

lombok-php's Introduction

Lombok PHP - write less code!


Latest Stable Version codecov License


Table of contents


Introduction

Lombok PHP is a package offering a growing set of PHP attributes (a feature introduced in PHP 8.0) designed to help reduce boilerplate code in your project by providing commonly used functionality that can be easily applied.

The main goal is to provide all the functionality at runtime, without any intermediate steps needed and without code generation.

And yes, the project name is shamelessly borrowed from the beloved Java's Project Lombok. However, it is not affiliated in any way; it's merely a nod to the scope and (target) functionality.

Benefits

  • Less code to write and maintain,
  • No more repetitive boilerplate code,
  • Can coexist with other attributes (i.e., Doctrine, etc.),
  • No code generation (all handled on-the-fly),
  • No additional dependencies,
  • Supports object cloning,
  • Production ready.

Examples

Vanilla PHP:

class Entity {
    protected int    $id;
    protected string $name;
    protected ?int   $age;

    public function getId(): int
    {
      return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
    public function setName(string $name): static
    {
        $this->name = $name;
        return $this;
    }

    public function getAge(): ?int
    {
        return $this->age;
    }
    public function setAge(?int $age): static
    {
        $this->age = $age;
        return $this;
    }
}

Using Lombok PHP (inheritance from \Lombok\Helper is helpful but optional):

use Lombok\Getter;
use Lombok\Setter;

#[Setter, Getter]
class Entity extends \Lombok\Helper {
    #[Getter]
    protected int $id;

    protected string $name;
    protected ?int $age;
}

Click here to see setup instruction and all the technical details.

License

  • Written and copyrighted ©2022-2023 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
  • Lombok PHP is open-sourced software licensed under the LGPL 3.0

lombok-php's People

Contributors

marcinorlowski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

thecoderraman

lombok-php's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.