定制 marcin-orlowski/lombok-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marcin-orlowski/lombok-php

最新稳定版本:1.1.1

Composer 安装命令:

composer require marcin-orlowski/lombok-php

包简介

Write less code!

README 文档

README

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

统计信息

  • 总下载量: 17.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2022-04-16