gnugat / redaktilo
Find, insert, replace and remove lines with an Editor-like object
Installs: 217 826
Dependents: 6
Suggesters: 0
Security: 0
Stars: 81
Watchers: 7
Forks: 11
Open Issues: 5
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-11-12 20:50:16 UTC
README
Redaktilo allows you to find, insert, replace and remove lines using an editor-like object.
Because your code too needs an editor to manipulate files.
Getting started
Use Composer to install Redaktilo in your projects:
$ composer require "gnugat/redaktilo:^2.0"
Redaktilo provides an Editor
class which can be instanciated using
EditorFactory
:
<?php require_once __DIR__.'/vendor/autoload.php'; use Gnugat\Redaktilo\EditorFactory; $editor = EditorFactory::createEditor();
Real life example
For our example, we will create a KernelManipulator
similar to the one we can find in SensioGeneratorBundle.
It takes a bundle's fully qualified classname and inserts it in the AppKernel
file:
<?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; } }
As you can see it's easier to read and to understand than the original PHP token parsing.
Further documentation
You can see the current and past versions using one of the following:
- the
git tag
command - the releases page on Github
- the file listing the changes between versions
You can find more documentation at the following links:
- copyright and MIT license
- versioning and branching models
- contribution instructions
- migration to 2.0 instructions
Next readings: