Example #1
0
 public function __construct($file, array $options = array())
 {
     $defaultOptions = array('length' => 0, 'fromEncoding' => null);
     $this->options = array_merge($defaultOptions, $options);
     if ($file instanceof SplFileInfo) {
         $file = $file->getPathname();
     }
     if ($file instanceof \Guzzle\Stream\StreamInterface) {
         $this->guzzleStream = $file;
         $file = $file->getStream();
     }
     if (is_resource($file)) {
         $this->fileHandle = $file;
         $this->closeFileHandleOnDestruct = false;
         if (null !== $this->options['fromEncoding']) {
             throw new Exception('Source encoding can only be specified if constructed with file path');
         }
     } else {
         if (is_string($file)) {
             $this->fileHandle = @fopen($file, 'r');
             if ($this->fileHandle === false) {
                 throw new InvalidArgumentException("Could not open csv file with path: '{$file}'");
             }
             if (null !== $this->options['fromEncoding']) {
                 stream_filter_append($this->fileHandle, 'convert.iconv.' . $this->options['fromEncoding'] . '/UTF-8');
             }
             $this->closeFileHandleOnDestruct = true;
         } else {
             throw new InvalidArgumentException('You must provide either a stream or filename to the csv iterator, you provided a ' . gettype($file));
         }
     }
     parent::__construct(array_diff_key($options, $defaultOptions));
 }
Example #2
0
 public function __construct($input, array $options = array())
 {
     if (is_string($input)) {
         $input = new ArrayIterator(preg_split('/\\r\\n|\\n|\\r/', $input));
     }
     $this->lines = IterUtil::asIterator($input);
     $this->lines->rewind();
     parent::__construct($options);
 }
Example #3
0
 public function __construct($cmd, array $options = array(), $cwd = null, $env = null, array $otherOptions = null)
 {
     $defaultOptions = array('length' => 0);
     $this->options = array_merge($defaultOptions, $options);
     $this->cmd = $cmd;
     $this->cwd = $cwd;
     $this->env = $env;
     $this->otherOptions = $otherOptions;
     parent::__construct(array_diff_key($options, $defaultOptions));
 }