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 | 7 | public function __construct(array $options = []) |
|
30 | |||
31 | 7 | protected function setOptions(array $options) |
|
36 | |||
37 | protected function setOption($option, $value) |
||
44 | |||
45 | 6 | 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. |
||
56 | * |
||
57 | * @param string $data The string to do the replacements on |
||
58 | * @param string $delim The delimiter character to replace |
||
59 | * |
||
60 | * @return string The data with replacements performed |
||
61 | */ |
||
62 | 2 | protected function replaceQuotedSpecialChars($data, $delim = null, $eol = null) |
|
75 | |||
76 | /** |
||
77 | * Replaces all quoted columns with a blank string. I was using this method |
||
78 | * to prevent explode() from incorrectly splitting at delimiters and newlines |
||
79 | * within quotes when parsing a file. But this was before I wrote the |
||
80 | * replaceQuotedSpecialChars method which (at least to me) makes more sense. |
||
81 | * |
||
82 | * @param string $data The string to replace quoted strings within |
||
83 | * |
||
84 | * @return string The input string with quoted strings removed |
||
85 | */ |
||
86 | 3 | protected function removeQuotedStrings($data) |
|
90 | |||
91 | 1 | protected function unQuote($string) |
|
95 | |||
96 | /** |
||
97 | * Analyze data (sniff) |
||
98 | * |
||
99 | * @param string $data The data to analyze (sniff) |
||
100 | * |
||
101 | * @return string|string[] |
||
102 | */ |
||
103 | abstract public function sniff($data); |
||
104 | } |