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

Issue Type: Improvement Created: 2008-06-19T06:03:02.000+0000 Last Updated: 2008-09-02T10:39:23.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Marc Bennewitz (GIATA mbH) (mben) Assignee: Thomas Weidner (thomas) Tags: - Zend_Translate

Related issues: Attachments:


-> 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


Posted by Thomas Weidner (thomas) on 2008-06-19T06:40:44.000+0000

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.

Posted by Marc Bennewitz (GIATA mbH) (mben) on 2008-06-19T08:17:17.000+0000

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.


<pre class="highlight">
    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) {
        // ...

Posted by Thomas Weidner (thomas) on 2008-06-20T02:07:47.000+0000

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

Posted by Thomas Weidner (thomas) on 2008-06-20T13:15:42.000+0000

Added 'limit' and 'enclosure' with r9745

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:22.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.