ZF-3480: Add options "line length" & "enclosure" for csv adapter


-> see:

  • line length set default to 0: -> Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. omitting this parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum line length is not limited, which is slightly slower.

AND: - throw Exception if invalid options values will be set


Actually the limit is hardcoded set to 4000 and not to 0. Having CSV Sources with more than 4000 characters per line is anyway something which should not be done. When setting this to 0 then we will get another problem... the key which is used as source should also not be longer than 2000 characters... all above will slow arrays emminent.

Secondly: As stated somewhere in the manual you can set your OWN OPTIONS to use with Zend_Translate. When we restrict this and do only allow the fixed options from the adapters, then this would be a BC break. This is not allowed and I would make a discussion within the mailinglist if this is even wished to change and restrict this behaviour.

Now you can create your own adapter using your own options. Restricting it does negotate this behaviour which is not wished for now.

With the line length option I only would tell that the length of the longest line can specified by user, because the max line length can less than 4000 and greather than 4000 ( even if it should not be done ). The default option value have not set to 0 it can set to 4000, too.

  1. -> OK I understand

Right, I can write my own Adapter but this would only implement the missing options for the standard to parse a csv file and therefor I must complete rewrite the method _loadTranslationData only to set the enclosure and/or length param to fgetcsv. I think this is better places directly in Zend_Translate_Adapter_Csv and to implement it only have to replace the the hard coded 4000 with the options variable and add the enclosure param to the fgetcsv function.


    public function __construct($data, $locale = null, array $options = array())
        $this->_options['separator'] = ";";
        $this->_options['length'] = 4000;
        $this->_options['enclosure'] = '"';
        parent::__construct($data, $locale, $options);

    protected function _loadTranslationData($filename, $locale, array $options = array())
        // ...
        while(($data = fgetcsv($this->_file, $options['length'], $options['separator'], $options['enclosure'])) !== false) {
        // ...

There is no patch and this is no failure as the adapter itself works. Reassigning type from patch to improvement

Added 'limit' and 'enclosure' with r9745

Updating for the 1.6.0 release.