memio/model 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

memio/model

Composer 安装命令:

composer require memio/model

包简介

Memio's models, used to describe the code to generate

README 文档

README

Describe PHP code (classes/interfaces with their constants, properties, methods, method arguments and even PHPdoc) by constructing "Model" objects.

Note: This package is part of Memio, a highly opinionated PHP code generator. Have a look at the main repository.

Installation

Install it using Composer:

composer require memio/model:^3.0

Example

Let's say we want to describe the following method:

    /**
     * @api
     */
    public function doSomething(ValueObject $valueObject, int $type = self::TYPE_ONE, bool $option = true);

In order to do so, we'd need to write the following:

<?php

require __DIR__.'/vendor/autoload.php';

use Memio\Model\Argument;
use Memio\Model\Method;
use Memio\Model\Phpdoc\ApiTag;
use Memio\Model\Phpdoc\MethodPhpdoc;
use Memio\Model\Phpdoc\ParameterTag;

$method = (new Method('doSomething'))
    ->setPhpdoc((new MethodPhpdoc())
        ->addParameterTag(new ParameterTag('Vendor\Project\ValueObject', 'valueObject'))
        ->addParameterTag(new ParameterTag('int', 'type'))
        ->addParameterTag(new ParameterTag('bool', 'option'))

        ->addApiTag(new ApiTag())
    )
    ->addArgument(new Argument('Vendor\Project\ValueObject', 'valueObject'))
    ->addArgument((new Argument('int', 'type'))
        ->setDefaultValue('self::TYPE_ONE')
    )
    ->addArgument((new Argument('bool', 'option'))
        ->setDefaultValue('true')
    )
;

Usually models aren't described manually like this, they would be built dynamically:

// Let's say we've received the following two parameters:
$methodName = 'doSomething';
$arguments = [new \Vendor\Project\ValueObject(), ValueObject::TYPE_ONE, true];

$method = new Method($methodName);
$phpdoc = (new MethodPhpdoc())->setApiTag(new ApiTag());
$index = 1;
foreach ($arguments as $rawArgument) {
    $type = is_object($rawArgument) ? get_class($argument) : gettype($rawArgument);
    $name = 'argument'.$index++;
    $argument = new Argument($type, $name);

    $method->addArgument($argument);
    $phpdoc->addParameterTag(new ParameterTag($type, $name));
}
$method->setPhpdoc($phpdoc);

We can build dynamically the models using a configuration file, user input, existing source code... Possibilities are endless!

Once built these models can be further tweaked, and converted to another format: an array, source code, etc... Again, the possibilities are endless!

Have a look at the main respository to discover the full power of Medio.

Want to know more?

Memio uses phpspec, which means the tests also provide the documentation. Not convinced? Then clone this repository and run the following commands:

make lib-init                        # Set up Docker environment
make phpspec arg='--format pretty'   # Run the specifications

Note: Run make or make help to see all available commands.

You can see the current and past versions using one of the following:

And finally some meta documentation:

Roadmap

  • get rid of Type
  • extract Import (use statement) from FullyQualifiedName
  • get rid of FullyQualifiedName
  • support more PHPdoc stuff
  • support annotations

memio/model 适用场景与选型建议

memio/model 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 313.5k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 313.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 11
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-02