定制 jgswift/qub 二次开发

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

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

jgswift/qub

Composer 安装命令:

composer require jgswift/qub

包简介

PHP 5.5+ magic mediator and native state transformation utility

README 文档

README

PHP 5.5+ magic mediator and native state transformation utility

Build Status Scrutinizer Code Quality

Installation

Install via composer:

php composer.phar require jgswift/qub:dev-master

Description

qub is a relatively simple utility that mediates state machines for any given object

qub constitutes a flexible and non-invasive way to associate potentially disparate (well formed) systems

qub is conceptually similar to the many-to-many or joint-table pattern found in relational database theory

qub adds conceptually barely anything to object-oriented programming in php but has many conceivable applications

qub uses 3 transformations to modify state and they are ASK, TELL, and TRANSLATE respectively

qub provides 4 drivers to run transformations immediately (run-time) or from stored lists (collections/queues/stacks)

qub can mediate both object and arrayaccess magic with comparable performance

Transformations

Ask - requests state information from mediator

Tell - instructs mediator to update it's internal state

Translate - requests translated information. should always result in identical output given the same arguments

Usage

This is minimal example of a user being asked what it's name is using the run-time state driver

<?php
class User {
    function getName() {
        return 'Bob';
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = $system->mediate(new User);

$name = $user->getName();

var_dump($name); // returns "Bob"

Following that, here is an expanded example that also tells the user to update it's own internal state

<?php
class User {
    private $name;

    function getName() {
        return $this->name;
    }

    function setName($name) {
        $this->name = $name;
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = $system->mediate(new User);

$user->setName('Bob');

$name = $user->getName();

var_dump($name); // returns "Bob"

Most patterns can be addressed using qub, for example the view pattern commonly found in Model-View-Controller. This example relies on the TRANSLATE transformation for view rendering and the result should be identical given the same input

<?php
class UserView {
    function render(User $user) {
        return '<html>';
    }
}

$system = new qub\System(new qub\Driver\Immediate);

$user = new User;

$view = $system->mediate(new UserView);

$html = $view('render',[$user]);

var_dump($html); // returns "<html>"

Note: TRANSLATE transformations are mediated by default through __invoke magic for both object and array mediators.

Note: Once PHP adds support for variadic arguments, TRANSLATE magic will be updated accordingly

Note: All of the above examples use the run-time driver, please consult the unit tests for implementation details regarding delayed drivers

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固