/** * Open file and detect column names * * There must be column names in the first line * * @param string $fileOrStream * @param string $delimiter * @param string $enclosure * @throws LogicException */ public function __construct($fileOrStream, $delimiter = ',', $enclosure = '"') { $this->_file = @fopen($fileOrStream, 'r'); if (false === $this->_file) { throw new LogicException("Unable to open file or stream: '{$fileOrStream}'"); } $this->_delimiter = $delimiter; $this->_enclosure = $enclosure; parent::__construct($this->_getNextRow()); }
/** * Read the row pattern to determine which columns are dynamic, set the collection size * * @param array $rowPattern * @param int $limit how many records to generate */ public function __construct(array $rowPattern, $limit) { foreach ($rowPattern as $key => $value) { if (is_callable($value) || is_string($value) && false !== strpos($value, '%s')) { $this->_dynamicColumns[$key] = $value; } } $this->_pattern = $rowPattern; $this->_limit = (int) $limit; parent::__construct(array_keys($rowPattern)); }