1 | <?php |
||
15 | abstract class AbstractSniffer |
||
16 | { |
||
17 | /** |
||
18 | * Placeholder strings -- hold the place of newlines and delimiters contained |
||
19 | * within quoted text so that the explode method doesn't split incorrectly. |
||
20 | */ |
||
21 | const PLACEHOLDER_NEWLINE = '[__NEWLINE__]'; |
||
22 | const PLACEHOLDER_DELIM = '[__DELIMIT__]'; |
||
23 | |||
24 | protected $options = []; |
||
25 | |||
26 | 5 | public function __construct(array $options = []) |
|
30 | |||
31 | 5 | protected function setOptions(array $options) |
|
36 | |||
37 | protected function setOption($option, $value) |
||
44 | |||
45 | 4 | protected function getOption($option) |
|
51 | |||
52 | /** |
||
53 | * Replace all instances of newlines and whatever character you specify (as |
||
54 | * the delimiter) that are contained within quoted text. The replacements are |
||
55 | * simply a special placeholder string. This is done so that I can use the |
||
56 | * very unsmart "explode" function and not have to worry about it exploding |
||
57 | * on delimiters or newlines within quotes. Once I have exploded, I typically |
||
58 | * sub back in the real characters before doing anything else. Although |
||
59 | * currently there is no dedicated method for doing so I just use str_replace. |
||
60 | * |
||
61 | * @param string $data The string to do the replacements on |
||
62 | * @param string $delim The delimiter character to replace |
||
63 | * |
||
64 | * @return string The data with replacements performed |
||
65 | */ |
||
66 | 1 | protected function replaceQuotedSpecialChars($data, $delim = null, $eol = null) |
|
79 | |||
80 | /** |
||
81 | * Replaces all quoted columns with a blank string. I was using this method |
||
82 | * to prevent explode() from incorrectly splitting at delimiters and newlines |
||
83 | * within quotes when parsing a file. But this was before I wrote the |
||
84 | * replaceQuotedSpecialChars method which (at least to me) makes more sense. |
||
85 | * |
||
86 | * @param string $data The string to replace quoted strings within |
||
87 | * |
||
88 | * @return string The input string with quoted strings removed |
||
89 | */ |
||
90 | 3 | protected function removeQuotedStrings($data) |
|
94 | |||
95 | /** |
||
96 | * Analyze data (sniff) |
||
97 | * |
||
98 | * @param string $data The data to analyze (sniff) |
||
99 | * |
||
100 | * @return string|string[] |
||
101 | */ |
||
102 | abstract public function sniff($data); |
||
103 | } |