hkwak/phpgen 问题修复 & 功能扩展

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

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

hkwak/phpgen

最新稳定版本:1.4.1

Composer 安装命令:

composer require hkwak/phpgen

包简介

PHP Generator

README 文档

README

Installation

composer require hkwak/phpgen

Usage example

// 1. Creating some properties

$nameProperty = (new PropertyModel('name', 'string', AccessEnum::PROTECTED()))
    ->setDescription('The name of something')
    ->setDefaultValue('Default name');

$dobProperty = new PropertyModel('dob', 'string', AccessEnum::PROTECTED());
    
// 2. Creating the public setName method

// initializing the method body
$methodBody = '$this->name = $name;';

$setNameMethod =(new MethodModel('setName'))
    ->setAccess(AccessEnum::PUBLIC())
    ->setDescription('This is a method description')
    ->setReturn('self')
    ->addParameter(new ParameterModel('name', 'string'))    
    ->addThrows(InvalidArgumentException::class)    
    ->setBody($methodBody);

$classModel = (new ClassModel('TestClass'))
    ->addTrait(SomeTrait::class)
    ->addProperty($nameProperty)
    ->addProperty($dobProperty)
    ->addMethod($setNameMethod)
    ->addAnnotation('some Class Annotation')
    ->setDescription('This is a description of the class')
    ->setNamespace('\\Some\Namespace\\')
    ->addUse('\\Some\\Namespace\\Class')
    ->addUse('\\Some\\Namespace\\Class2')
    ->setExtends('\\Some\\Namespace\\BaseClass');

// generating the code
$classGenerator = new ClassGenerator(
            new MethodGenerator(),
            new PropertyGenerator(),
            new NamespaceManager()
        );
        
$classCode = $classGenerator->generate($classModel, new PhpCodeStream());

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-02-18