承接 muffin/sti 相关项目开发

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

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

muffin/sti

Composer 安装命令:

composer require muffin/sti

包简介

Single Table Inheritance for CakePHP ORM

README 文档

README

Build Status Coverage Total Downloads License

Single Table Inheritance for CakePHP ORM.

[...] a way to emulate object-oriented inheritance in a relational database. When mapping from a database table to an object in an object-oriented language, a field in the database identifies what class in the hierarchy the object belongs to.

(source: Wikipedia)

Install

Using Composer:

composer require muffin/sti

You then need to load the plugin. You can use the console command:

bin/cake plugin load Muffin/Sti

Usage

<?php // src/Model/Table/CooksTable.php
namespace App\Model\Table;

use Cake\ORM\Table;

class CooksTable extends Table
{
    public function initialize($config)
    {
        $this->setTable('sti_cooks');
        $this->addBehavior('Muffin/Sti.Sti', [
            'typeMap' => [
                'chef' => 'App\Model\Entity\Chef',
                'baker' => 'App\Model\Entity\Baker',
                'assistant_chef' => 'App\Model\Entity\AssistantChef',
            ]
        ]);

        // Optionally, set the default type. If none is defined, the
        // first one (i.e. `chef`) will be used.
        $this->setEntityClass('App\Model\Entity\AssistantChef');
    }
}

Then create a class for every type of entity:

  • Chef
  • Baker
  • AssistantChef

The entity that was previously defined to be the 'default' one will need to use the StiAwareTrait:

<?php // src/Model/Entity/AssistantChef.php
namespace App\Model\Entity;

use Cake\ORM\Entity;
use Muffin\Sti\Model\Entity\StiAwareTrait;

class AssistantChef extends Entity
{
    use StiAwareTrait;
}

Optionally, you can create classes for your tables that extend the parent table to encapsulate business logic:

<?php // src/Model/Table/ChefsTable.php
namespace App\Model\Table;

class ChefsTable extends CooksTable
{
  // ...
}

I said optionally, because if the only thing you need is some extra validation rules, you could define those on the parent table. For example, to add custom rules to chefs:

// src/Model/Table/CooksTable.php
public function validationChefs(Validator $validator)
{
    // ...
    return $validator;
}

New entities

The behavior will automatically add helper methods for creating entities of different types (i.e. newChef()). There are different ways of creating new entities, all are valid and depending on the cases, you might need one or the other:

// using the parent table
$cooks->newChef([...]);

// or, using the parent table again
$cooks->newEntity(['type' => 'chef', ...]);

// or, using the child table
$chefs->newEntity([...]);

Note

For the above examples to work using (*chef), you need to add a custom rule to the Inflector:

Cake\Utility\Inflector::rules('plural', ['/chef$/i' => '\1Chefs']);

Patches & Features

  • Fork
  • Mod, fix
  • Test - this is important, so it's not unintentionally broken
  • Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
  • Pull request - bonus point for topic branches

To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.

Bugs & Feedback

http://github.com/usemuffin/sti/issues

License

Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License.

muffin/sti 适用场景与选型建议

muffin/sti 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 811 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cakephp」 「sti」 「muffin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 muffin/sti 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 muffin/sti 我们能提供哪些服务?
定制开发 / 二次开发

基于 muffin/sti 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-20