Download the PHP package oohology/gitignorewriter without Composer
On this page you can find all versions of the php package oohology/gitignorewriter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gitignorewriter
GitIgnoreWriter
Interface for editing .gitignore files in PHP
Basic Usage
In general, you will open a .gitignore file, use the add
, before
, or after
methods to append, or insert some
values, and then call the save
method to write the result.
Open a file and add a value:
Also supports fluent interface:
Output File
There are multiple ways to read from a source file, make some changes, and write the result to a different output file. The end result is the same, so choose whichever method best fits your use case:
Or alternately:
Or using the load()
method:
Adding and Inserting Values
The add
method appends lines starting at the current position in the file, which defaults to the end of the file.
The before
and after
methods first seek the current position to a given line, and then start inserting lines relative to that position
The add
, before
and after
methods each will accept the values to be inserted in multiple formats:
- a single-line string
- a multi-line string
- an array of strings
More examples:
Manually seeking
The rewind
, seek
and eof
methods allow you to manually seek the internal pointer
to a specific line in the file. Any subsequent add
will insert content relative
to that position.
rewind
: set the pointer to the beginning of the fileseek
: set the pointer to a specific line number starting at 0eof
: set the pointer to append to the end of the file
Deleting Lines
The delete
and deleteOffset
methods provide ways to remove lines from the file. Note that the remaining lines are renumbered after deletion.
delete($value)
: remove a matching line from the filedeleteOffset($offset, $count = 1)
: delete one or more lines, starting at a specific 0-based line number.
Examples:
Test if a line exists
The exists
method returns a boolean to test if a line exists in the file.
$result = $writer->exists('.env');