定制 itrocks/extend 二次开发

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

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

itrocks/extend

Composer 安装命令:

composer require itrocks/extend

包简介

Some annotations to simulate more multi-inheritance in PHP

README 文档

README

Hopelessly, PHP does not allow simple multiple inheritance.

Furthermore, there is no mechanism for declaring that a trait is designed to enhance a given class (or some given classes).

This little library adds a repetitive attribute named ITRocks\Extend, which allows to declare additional extends:

  • to a class: you will be able to simulate some multi-inheritance mechanisms based on them,
  • to an interface or trait: to reserve the implement/use of this to a given class,
  • to a trait: tells that the trait is designed to be used in a class that inherits a class or a class using a given trait.

Another attribute, ITRocks\Extend\Implement, allows to declare that a trait is designed to implement the methods prototyped into given interfaces.

Examples

it.rocks widely use the ITRocks\Extend attribute to declare traits that are designed to extend base classes at will, depending on your use case deployment configuration.

use ITRocks\Extend;

class My_Expandable
{
	public string $a_property;
}

interface My_Interface
{
	public function getSomething() : string;
}

#[Extend(My_Expandable::class), Implement(My_Interface::class)]
trait My_Extension
{
	public string $additional_optional_property;
	public function getSomething() : string { return $this->additional_optional_property; }
}

Application example

You may use the additional itrocks/build library to apply these inheritance mechanisms.

With the previous example code and the following configuration :

$configuration = [My_Expandable::class => [My_Extension::class]];

itrocks/build will replace all instantiations of My_Expandable into your source code by instantiations of the following built class:

class My_Expandable\B extends My_Expandable implements My_Interface
{
  use My_Extension;
}

Refer to the documentation of itrocks/build to see how.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2023-04-24