webspanner/sourcemonkey

There is no license information available for the latest version (1.1.3) of this package.

1.1.3 2018-08-01 07:36 UTC

This package is not auto-updated.

Last update: 2024-06-09 02:20:45 UTC


README

SourceMonkey is a package for working with source code, or text files on your local filesystem. SourceMonkey is useful for automated code generation and modification within your application.

Installation

To install with composer use the following command:

composer install webspanner/sourcemonkey

Usage

Instantiating the class

Pass the fully qualified path to the file which you are editing into the constructor.

$sourceMonkey = new SourceMonkey('/tmp/my-file.php');

Methods

insertLineAfter()

To insert a string into a file after a given line number, moving all later text further down the page use the insertLineAfter() method

$sourceMonkey->insertLineAfter('some string', 42);

write()

To write a string to a file, overwriting it's existing contents use the write() method.

$sourceMonkey->write('some string');

getLines()

To read the contents of a file into a 1-indexed array of strings, without line breaks use the getLines() method.

$sourceMonkey->getLines();

getPath()

Get the path of the SourceMonkey instance

$sourceMonkey->getPath();

firstLineWithString()

Returns the line number of the first line which contains the given string

$sourceMonkey->firstLineWithString($string);
{

deleteLine()

Delete the line at the given number

$sourceMonkey->deleteLine($lineNumber);

replaceLine()

Replace the contents of the given line number with the given string

$sourceMonkey->replaceLine($lineNumber, $string);

getProperty()

Get the PHP class property matching the given name from the class in the given source file and return it as a Property model object or null if it does not exist

$sourceMonkey->getProperty($propertyName);

getClass()

Get the PHP class in the given file name

$sourceMonkey->getClass()