gnugat / redaktilo
使用类似于编辑器的对象查找、插入、替换和删除行
2.0.1
2024-08-12 20:19 UTC
Requires
- php: ^7.2 || ^8.0
- symfony/filesystem: ^5.0
Requires (Dev)
- friends-of-phpspec/phpspec-expect: ^3.1 || ^4.0
- friendsofphp/php-cs-fixer: ^2.16
- phpspec/phpspec: ^6.1 || ^7.0
- phpunit/phpunit: ^8.4
- dev-main / 2.0.x-dev
- 2.0.1
- v2.0.0
- 1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v1.0.0-rc3
- v1.0.0-rc2
- v1.0.0-rc1
- v1.0.0-beta2
- v1.0.0-beta1
- v1.0.0-alpha7
- v1.0.0-alpha6
- v1.0.0-alpha5
- v1.0.0-alpha4
- v1.0.0-alpha3
- v1.0.0-alpha2
- v1.0.0-alpha1
- v0.9.0
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- dev-fix-notice
- dev-release-2.0.0
This package is auto-updated.
Last update: 2024-09-12 20:26:12 UTC
README
Redaktilo 允许您使用类似编辑器的对象查找、插入、替换和删除行。
因为您的代码也需要编辑器来操作文件.
入门
使用Composer在项目中安装 Redaktilo
$ composer require "gnugat/redaktilo:^2.0"
Redaktilo 提供了一个 Editor
类,可以使用 EditorFactory
实例化
<?php require_once __DIR__.'/vendor/autoload.php'; use Gnugat\Redaktilo\EditorFactory; $editor = EditorFactory::createEditor();
真实案例
在我们的示例中,我们将创建一个类似于KernelManipulator
的SensioGeneratorBundle
它接受一个捆绑的全限定类名并在 AppKernel
文件中插入它
<?php namespace Sensio\Bundle\GeneratorBundle\Manipulator; use Gnugat\Redaktilo\Editor; class KernelManipulator extends Manipulator { protected $editor; protected $appKernelFilename; public function __construct(Editor $editor, $appKernelFilename) { $this->editor = $editor; $this->appKernelFilename = $appKernelFilename; } public function addBundle($bundle) { $appKernel = $this->editor->open($this->appKernelFilename); $newBundle = " new $bundle(),"; if ($this->editor->hasBelow($appKernel, $newBundle)) { $message = sprintf('Bundle "%s" is already defined in "AppKernel::registerBundles()".', $bundle); throw new \RuntimeException($message); } $this->editor->jumpBelow($appKernel, ' );'); $this->editor->insertAbove($appKernel, $newBundle); $this->editor->save($appKernel); return true; } }
如您所见,它比原始的 PHP 标记解析更容易阅读和理解。
更多文档
您可以使用以下方式查看当前和过去的版本:
git tag
命令- Github 上的发行页面
- 列出版本之间变更的文件变更日志
您可以在以下链接中找到更多文档:
下一部分