1 | <?php |
||
30 | class EncloseField extends php_user_filter |
||
31 | { |
||
32 | const FILTERNAME = 'convert.league.csv.enclosure'; |
||
33 | |||
34 | /** |
||
35 | * the filter name used to instantiate the class with |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | public $filtername; |
||
40 | |||
41 | /** |
||
42 | * Contents of the params parameter passed to stream_filter_append |
||
43 | * or stream_filter_prepend functions |
||
44 | * |
||
45 | * @var mixed |
||
46 | */ |
||
47 | public $params; |
||
48 | |||
49 | /** |
||
50 | * Default sequence |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $sequence; |
||
55 | |||
56 | /** |
||
57 | * Characters that triggers enclosure in PHP |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected static $force_enclosure = "\n\r\t "; |
||
62 | |||
63 | /** |
||
64 | * Static method to return the stream filter filtername |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 2 | public static function getFiltername(): string |
|
72 | |||
73 | /** |
||
74 | * Static method to register the class as a stream filter |
||
75 | */ |
||
76 | 2 | public static function register() |
|
82 | |||
83 | /** |
||
84 | * Static method to add the stream filter to a {@link Writer} object |
||
85 | * |
||
86 | * @param Writer $csv |
||
87 | * @param string $sequence |
||
88 | * |
||
89 | * @throws InvalidArgumentException if the sequence is malformed |
||
90 | * |
||
91 | * @return AbstractCsv |
||
92 | */ |
||
93 | 4 | public static function addTo(Writer $csv, string $sequence): Writer |
|
114 | |||
115 | /** |
||
116 | * Filter type and sequence parameters |
||
117 | * |
||
118 | * - The sequence to force enclosure MUST contains one of the following character ("\n\r\t ") |
||
119 | * |
||
120 | * @param string $sequence |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | 4 | protected static function isValidSequence(string $sequence): bool |
|
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | 8 | public function onCreate() |
|
137 | |||
138 | /** |
||
139 | * @inheritdoc |
||
140 | */ |
||
141 | 2 | public function filter($in, $out, &$consumed, $closing) |
|
151 | } |
||
152 |