https://github.com/marcinorlowski/lombok-php
Put your PHP8+ project on a diet by reducing total number of boilerplate code.
https://github.com/marcinorlowski/lombok-php
lombok lombok-php php-attributes php8
Last synced: 6 months ago
JSON representation
Put your PHP8+ project on a diet by reducing total number of boilerplate code.
- Host: GitHub
- URL: https://github.com/marcinorlowski/lombok-php
- Owner: MarcinOrlowski
- License: lgpl-3.0
- Created: 2022-04-14T21:49:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-01T08:50:23.000Z (almost 2 years ago)
- Last Synced: 2025-03-29T08:02:22.709Z (6 months ago)
- Topics: lombok, lombok-php, php-attributes, php8
- Language: PHP
- Homepage:
- Size: 228 KB
- Stars: 32
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README

---
[](https://packagist.org/packages/marcin-orlowski/lombok-php)
[](https://codecov.io/gh/MarcinOrlowski/lombok-php)
[](https://packagist.org/packages/marcin-orlowski/lombok-php)---
# Table of contents #
* [Introduction](#introduction)
* [Why should I use it?](#benefits)
* [Usage examples](#examples)
* [Documentation](docs/README.md)
* [License](#license)
* [Changelog](CHANGES.md)---
## Introduction ##
`Lombok PHP` is a package offering a growing set
of [PHP attributes](https://www.php.net/manual/en/language.attributes.php) (a
feature [introduced in PHP 8.0](https://www.php.net/releases/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](https://projectlombok.org/). 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](https://www.doctrine-project.org/), etc.),
* No code generation (all handled on-the-fly),
* No additional dependencies,
* Supports object cloning,
* Production ready.## Examples ##
Vanilla PHP:
```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](docs/README.md#manual-wiring)):```php
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](docs/README.md) to see setup instruction and all the technical details.
## License ##
* Written and copyrighted ©2022-2023 by Marcin Orlowski
* `Lombok PHP` is open-sourced software licensed under
the [LGPL 3.0](https://opensource.org/licenses/LGPL-3.0)