You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,6 @@ $snippet = (new CodeSnippet())
39
39
Use the `surroundingLines($first, $last)` method to select a range of "target" lines, which will be returned as the middle lines of the snippet:
40
40
41
41
```php
42
-
use Permafrost\CodeSnippets\CodeSnippet;
43
-
44
42
$snippet = (new CodeSnippet())
45
43
->surroundingLines(4, 7)
46
44
->snippetLineCount(6)
@@ -50,37 +48,31 @@ $snippet = (new CodeSnippet())
50
48
Use the `linesBefore()` and `linesAfter()` methods to specify the number of context lines to display before and after the "target" lines:
51
49
52
50
```php
53
-
use Permafrost\CodeSnippets\CodeSnippet;
54
-
55
51
// the "target" line isn't displayed in the middle, but as the second line
56
52
$snippet = (new CodeSnippet())
57
53
->surroundingLine(4)
58
54
->linesBefore(1)
59
55
->linesAfter(3)
60
56
->fromFile('/path/to/a/file.php');
61
57
```
58
+
62
59
### Getting the snippet contents
63
60
64
61
The `getLines()` method returns an array of `SnippetLine` instances. The keys of the resulting array are the line numbers.
65
62
66
-
The `SnippetLine` instances may be cast to strings to display the value.
63
+
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.
67
64
68
-
```php
69
-
use Permafrost\CodeSnippets\CodeSnippet;
65
+
To get the value of a `SnippetLine`, use the `value()` method or cast the object to a string.
70
66
71
-
// the "target" line isn't displayed in the middle, but as the second line
67
+
```php
72
68
$snippet = (new CodeSnippet())
73
69
->surroundingLine(4)
74
70
->snippetLineCount(5)
75
71
->fromFile('/path/to/a/file.php');
76
72
77
73
foreach($snippet->getLines() as $lineNum => $line) {
78
-
// use ->isSelected() to determine if the line was selected using the
0 commit comments