CsvView\View\CsvView::_renderContent PHP Method

_renderContent() protected method

Renders the body of the data to the csv
protected _renderContent ( ) : void
return void
    protected function _renderContent()
    {
        $extract = $this->viewVars['_extract'];
        $serialize = $this->viewVars['_serialize'];
        if ($serialize === true) {
            $serialize = array_diff(array_keys($this->viewVars), $this->_specialVars);
        }
        foreach ((array) $serialize as $viewVar) {
            if (is_scalar($this->viewVars[$viewVar])) {
                throw new Exception("'" . $viewVar . "' is not an array or iteratable object.");
            }
            foreach ($this->viewVars[$viewVar] as $_data) {
                if ($_data instanceof EntityInterface) {
                    $_data = $_data->toArray();
                }
                if ($extract === null) {
                    $this->_renderRow($_data);
                    continue;
                }
                $values = [];
                foreach ($extract as $formatter) {
                    if (!is_string($formatter) && is_callable($formatter)) {
                        $value = $formatter($_data);
                    } else {
                        $path = $formatter;
                        $format = null;
                        if (is_array($formatter)) {
                            list($path, $format) = $formatter;
                        }
                        if (strpos($path, '.') === false) {
                            $value = $_data[$path];
                        } else {
                            $value = Hash::get($_data, $path);
                        }
                        if ($format) {
                            $value = sprintf($format, $value);
                        }
                    }
                    $values[] = $value;
                }
                $this->_renderRow($values);
            }
        }
    }