承接 lukaszmakuch/class-based-registry 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lukaszmakuch/class-based-registry

最新稳定版本:v0.0.2

Composer 安装命令:

composer require lukaszmakuch/class-based-registry

包简介

Registry that allows to associate a value to one ore more classes and then fetch this value by passing objects that implements these classes

README 文档

README

Allows to associate a value to one or more classes and then fetch this value by passing objects that implement these classes.

Usage

Environment

Let's assume that we have classes like these:

class Animal {}
class Elephant extends Animal {}
class Plant {}

To get a new instance of the registry create it:

$r = new \lukaszmakuch\ClassBasedRegistry\ClassBasedRegistry();

Simple example

Associate 42 with the Animal class:

$r->associateValueWithClasses(
    42,
    [Animal::class]
);

Fetch it by providing any animal...

$r->fetchValueByObjects([new Animal()]); //42

... that may be an elephant!

$r->fetchValueByObjects([new Elephant()]); //42

Multiple classes

It is possible to associate value with many classes:

$r->associateValueWithClasses(
    1970,
    [Animal::class, Plant::class]
);

While fetching objects may be passed in any order:

$r->fetchValueByObjects([new Plant(), new Elephant()]); //1970

Throwing exceptions

When it's not possible to obtain any value, then a \lukaszmakuch\ClassBasedRegistry\Exception\ValueNotFound exception is thrown:

try {
    $r->fetchValueByObjects([new Plant()]);
} catch (\lukaszmakuch\ClassBasedRegistry\Exception\ValueNotFound $e) {
  //it was not possible to fetch any value by a plant
}

Installation

Use composer to get the latest version:

$ composer require lukaszmakuch/class-based-registry

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-12