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.
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
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-16