Download the PHP package permafrost-dev/code-snippets without Composer
On this page you can find all versions of the php package permafrost-dev/code-snippets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download permafrost-dev/code-snippets
More information about permafrost-dev/code-snippets
Files in permafrost-dev/code-snippets
Package code-snippets
Short Description Easily work with code snippets in PHP
License MIT
Homepage https://github.com/permafrost-dev/code-snippets
Informations about the package code-snippets
code-snippets
Easily create and work with code snippets from source code files of any type in PHP.
The original code this package is based on was borrowed from the spatie/backtrace
package.
Installation
You can install the package via composer:
Usage
Note: Although the examples here reference php files, any file type can be used when creating a CodeSnippet
.
Creating a snippet
Use the surroundingLine($num)
method to select the "target" line, which will be returned as the middle line of the snippet:
Use the surroundingLines($first, $last)
method to select a range of "target" lines, which will be returned as the middle lines of the snippet:
Use the linesBefore()
and linesAfter()
methods to specify the number of context lines to display before and after the "target" lines:
Getting the snippet contents
The getLines()
method returns an array of SnippetLine
instances. The keys of the resulting array are the line numbers.
The SnippetLine
instances may be cast to strings to display the value. When working with SnippetLine
instances, use isSelected()
to determine if the line was selected using either the surroundingLine()
or surroundingLines()
method on the CodeSnippet
instance.
To get the value of a SnippetLine
, use the value()
method or cast the object to a string.
Snippet line count
To determine the number of lines in the snippet, use the getSnippetLineCount()
method:
You can also use count()
on the result of the getLines()
method:
To return an array containing the line numbers for the snippet, use getLineNumbers()
:
Returning the snippet as a string
Return the contents of the snippet as as string using the toString()
method or by casting the snippet to a string directly:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Patrick Organ
- All Contributors
License
The MIT License (MIT). Please see License File for more information.