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

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

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

memio/memio

最新稳定版本:v3.0.0

Composer 安装命令:

composer require memio/memio

包简介

A highly opinionated PHP code generator library

README 文档

README

Memio is a library, it allows you to describe PHP code by building "Model" classes (e.g. new Method('__construct')) and then to generate it using a PrettyPrinter!

Note: The actual generation logic is held in Twig templates. If the coding style provided doesn't appeal to you, you can overwrite those templates easily.

Installation

Install using Composer:

$ composer require memio/memio:^3.0

Full example

We're going to generate a class with a constructor and two attributes:

<?php

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

use Memio\Memio\Config\Build;
use Memio\Model\File;
use Memio\Model\Object;
use Memio\Model\Property;
use Memio\Model\Method;
use Memio\Model\Argument;

// Describe the code you want to generate using "Models"
$file = (new File('src/Vendor/Project/MyService.php'))
    ->setStructure(
        (new Object('Vendor\Project\MyService'))
            ->addProperty(new Property('createdAt'))
            ->addProperty(new Property('filename'))
            ->addMethod(
                (new Method('__construct'))
                    ->addArgument(new Argument('DateTime', 'createdAt'))
                    ->addArgument(new Argument('string', 'filename'))
            )
    )
;

// Generate the code and display in the console
$prettyPrinter = Build::prettyPrinter();
$generatedCode = $prettyPrinter->generateCode($file);
echo $generatedCode;

// Or display it in a browser
// echo '<pre>'.htmlspecialchars($prettyPrinter->generateCode($file)).'</pre>';

With this simple example, we get the following output:

<?php

namespace Vendor\Project;

class MyService
{
    private $createdAt;
    private $filename;

    public function __construct(DateTime $createdAt, string $filename)
    {
    }
}

Want to know more?

Memio can be quite powerful, discover how by reading the docs:

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

And finally some meta documentation:

Roadmap

  • commands (e.g. add use statement, add PHPdoc, injecting dependency, etc)
  • parsing existing code (using nikic's PHP-Parser)

统计信息

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

GitHub 信息

  • Stars: 336
  • Watchers: 13
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-31