2017-25 © Pedro Peláez
 

library phpeditor

Library for editing PHP files

image

jhoff/phpeditor

Library for editing PHP files

  • Wednesday, May 16, 2018
  • by jhoff
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 100 % Grown

The README.md

PHP Editor

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

Latest Stable Version Total Downloads MIT License Build Status Code Coverage Scrutinizer Code Quality, (*2)

, (*3)

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., (*4)

, (*5)

Installation

Use composer to install:, (*6)

composer require jhoff/phpeditor

, (*7)

Usage

There are a few static helpers to help you find the proper file to edit:, (*8)

// 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., (*9)

    $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., (*10)

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., (*11)

, (*12)

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., (*13)

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

The Versions

16/05 2018

dev-master

9999999-dev

Library for editing PHP files

  Sources   Download

MIT

The Requires

 

The Development Requires

16/05 2018

0.0.2

0.0.2.0

Library for editing PHP files

  Sources   Download

MIT

The Requires

 

The Development Requires

16/05 2018

0.0.1

0.0.1.0

Library for editing PHP files

  Sources   Download

MIT

The Requires

 

The Development Requires