定制 jhoff/phpeditor 二次开发

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

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

jhoff/phpeditor

Composer 安装命令:

composer require jhoff/phpeditor

包简介

Library for editing PHP files

README 文档

README

Simplified, opinionated php-based editor for PSR-4 php files, leveraging the nikic/PHP-Parser library.

Latest Stable Version Total Downloads MIT License Build Status Code Coverage Scrutinizer Code Quality

About

The PHPEditor library is useful for making minor changes to existing PSR4 PHP files. It's assumed that each file will have a single namespaced class. New methods will be added to the end of the class. Use statements will automatically be de-duplicated and sorted by length.

Installation

Use composer to install:

composer require jhoff/phpeditor

Usage

There are a few static helpers to help you find the proper file to edit:

// Open an existing file using a relative or absolute path
File::open($filename)

// Create a new class with the provided filename, namespace and class
File::create($filename, $namespace, $class)

// Either open or create, based on if the file exists already
File::openOrCreate($filename, $namespace, $class)

// Use reflection to find the file that defines the provided class
File::fromClass($class)

Once you've opened or created the file, you can use fluent methods to make modifications and then write them to disk.

    $file = \Jhoff\PhpEditor\File::open('MyClass.php');

    $file->addUse('Awesome\Library\Tool')
        ->addPublicMethod(
            'newMethod',
            'return true;'
        )

    $file->write();

Additionally, you can use the getNewFileContents method if you don't want to write the changes to disk.

The underlying nikic/PHP-Parser library will attempt to preserve any existing formatting in the file, but you may need some additional processing to make small formatting tweaks.

Docblocks

The addMethod method ( or any of the variants ) accepts a final docblock argument in the form of an associative array. Optionally provide a message or description and any other properties will automatically be formatted into proper tags. Simple tags without any text can be added by setting their value to true.

    [
        'message' => 'This is the docblock message',
        'description' => 'Some information about the method',
        'param' => [
            'string $paramOne',
            'array $paramTwo',
        ],
        'return' => 'void',
        'internal' => true,
    ]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固