Write entity populate method.

@see \Zend\Stdlib\Hydrator\ArraySerializable::extract()
@param \MwbExporter\Writer\WriterInterface $writer
@return \MwbExporter\Formatter\Doctrine2\AnnotationZF2InputFilter\Model\Table
551032
public function writePopulate(WriterInterface $writer)
    {
        $writer
            ->write('/**')
            ->write(' * Populate entity with the given data.')
            ->write(' * The set* method will be used to set the data.')
            ->write(' *')
            ->write(' * @param array $data')
            ->write(' * @return boolean')
            ->write(' */')
            ->write('public function populate(array $data = array())')
            ->write('{')
            ->indent()
                ->write('foreach ($data as $field => $value) {')
                ->indent()
                    ->write('$setter = sprintf(\'set%s\', ucfirst(')
                    ->indent()
                        ->write('str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $field)))')
                    ->outdent()
                    ->write('));')
                    ->write('if (method_exists($this, $setter)) {')
                    ->indent()
                        ->write('$this->{$setter}($value);')
                    ->outdent()
                    ->write('}')
                ->outdent()
                ->write('}')
                ->write('')
                ->write('return true;')
            ->outdent()
            ->write('}')
            ->write('')
        ;

        return $this;
    }
841195
public function setWriter(\Parable\Log\Writer\WriterInterface $writer)
    {
        $this->writer = $writer;
        return $this;
    }
1259683
public function generate() : WriterInterface
    {
        // Disable time limit (generation is done within a few seconds, but if data have to be
        // downloaded it can take some more time)
        set_time_limit(0);

        $this->initializeDatabase();

        foreach ($this->getSource()->getDataSets() as $dataSet) {
            $this->processDataSet($dataSet);
        }

        $this->finalizeDatabase();

        return $this;
    }
290911
protected function generateKeyAttribute(\XmlWriter $writer, $key = null)
    {
        if ($key !== null) {
            $writer->startAttribute('key');
            $writer->text($key);
            $writer->endAttribute();
        }
    }
1324198
public function extract($entity)
    {
        //if entity is required then delete the entity
        $property = $this->getRepository()
                         ->getDescription()
                         ->getProperty($this->_property);
                         
        if ($property->isRequired()) {
            $entity->delete();
        } else {
            $entity->set($this->_property, null);
        }
    }
829182
public function extractArchive(File $file, ArchiverInterface $archiver)
    {
        $archiver->open($file->getPathname());

        $extractpath = dirname($archiver->getArchivePath()) . DS . uniqid();

        $archiver->extract($extractpath);

        /** @var \DirectoryIterator $item */
        foreach (new \DirectoryIterator($extractpath) as $item) {
            if (!$item->isDot() && $item->isFile()) {
                $file = new File($item->getPathname());

                break;
            }
        }

        return $file;
    }
430839
public function xmlSerializeFull(Writer $writer)
    {
        $cs = '{'.Plugin::NS_CALENDARSERVER.'}';
        switch ($this->type) {
            case self::TYPE_LOW:
                $type = 'low';
                break;
            case self::TYPE_MEDIUM:
                $type = 'medium';
                break;
            default:
            case self::TYPE_HIGH:
                $type = 'high';
                break;
        }

        $writer->startElement($cs.'systemstatus');
        $writer->writeAttribute('type', $type);

        if ($this->description) {
            $writer->writeElement($cs.'description', $this->description);
        }
        if ($this->href) {
            $writer->writeElement('{DAV:}href', $this->href);
        }

        $writer->endElement(); // systemstatus
    }
1132058
public function extract(array $data)
    {
        if (!array_key_exists('class', $data)) {
            throw new \RuntimeException('Unable to extract class name from data');
        }

        if (!array_key_exists('data', $data)) {
            throw new \RuntimeException('Unable to extract message body from data');
        }

        if (!is_array($data['data'])) {
            throw new \RuntimeException('Message body from data must be an array');
        }

        if (!class_exists($data['class'])) {
            throw new \RuntimeException(sprintf('Class %s does\'nt exist', $data['class']));
        }

        if (!in_array(MessageInterface::class, class_implements($data['class']))) {
            throw new \RuntimeException(sprintf('Class must implement %s', MessageInterface::class));
        }

        $message = new $data['class'];

        if (is_subclass_of($data['class'], MessageAwareInterface::class)) {
            $message->setMessage($this->extract($data['data']));

            unset($data['data']['class']);
            unset($data['data']['data']);
        }

        return $this->getHydrator()->hydrate($message, $data['data']);
    }
1087186
public function addRowWithCount($row, $writer, $rowNumber)
    {
        $exportRow   = $this->filterRow($row);
        $labeledCols = $this->getLabeledColumns();
        $exportRow   = array_replace(array_flip($labeledCols), $exportRow);
        $writer->startElement('o');
        $writer->writeAttribute('num', $rowNumber);

        if ($this->batch) {
            $stringSizes = $this->batch->getSessionVariable('stringSizes');
        } else {
            $stringSizes = $this->_session->stringSizes;
        }

        foreach($labeledCols as $columnName) {

            $variableName = $this->model->get($columnName, 'variableName');
            $type = $this->model->get($columnName, 'type');

            if (($type == \MUtil_Model::TYPE_DATE || $type == \MUtil_Model::TYPE_DATETIME) && $exportRow[$columnName] !== null) {

                if (!empty($exportRow[$columnName])) {
                    if ($exportRow[$columnName] instanceof \Zend_Date) {
                        if ($type == \MUtil_Model::TYPE_DATE) {
                            $exportRow[$columnName] = floor(($exportRow[$columnName]->getTimestamp() + 315619200) / 86400);
                        } else {
                            $exportRow[$columnName] = ($exportRow[$columnName]->getTimestamp() + 315619200) * 1000;
                        }

                    } else {
                        if ($type == \MUtil_Model::TYPE_DATE) {
                            $exportRow[$columnName] = floor((strtotime($exportRow[$columnName] . ' GMT') + 315619200) / 86400);
                        } else {
                            $exportRow[$columnName] = (strtotime($exportRow[$columnName] . ' GMT') + 315619200) * 1000 ;
                        }
                    }
                }
            }
            if ($type == \MUtil_Model::TYPE_STRING && !$this->model->get($columnName, 'multiOptions')) {
                $size = strlen($exportRow[$columnName]);

                if ((!isset($stringSizes[$variableName]) || ($stringSizes[$variableName] < $size)) && $size > 0) {
                    $stringSizes[$variableName] = $size;

                    if ($this->batch) {
                        $this->batch->setSessionVariable('stringSizes', $stringSizes);
                    } else {
                        $this->_session->stringSizes = $stringSizes;
                    }
                }
            }

            if ($multiOptions = $this->model->get($columnName, 'multiOptions')) {
                if ($exportRow[$columnName] !== null) {

                    $numeric = true;
                    $newValue = 0;
                    $i=0;



                    foreach($multiOptions as $key=>$value) {
                        if (!is_numeric($key)) {
                            $numeric = false;
                        }
                        if ($key == $exportRow[$columnName]) {
                            $newValue = $i;
                        }
                    }

                    if($numeric) {

                        $newValue = $exportRow[$columnName];
                        $exportRow[$columnName] = $newValue;
                    } else {
                        $newMultiOptions = array_keys($multiOptions);
                        $newValue = array_search($exportRow[$columnName], $newMultiOptions);
                        $exportRow[$columnName] = $newValue;
                    }

                }
            }

            $writer->startElement('v');
            $writer->writeAttribute('varname', $variableName);
            if (is_array($exportRow[$columnName])) {
                $exportRow[$columnName] = join(', ', $exportRow[$columnName]);
            }
            $writer->text($exportRow[$columnName]);
            // End v
            $writer->endElement();

        }
        // End o
        $writer->endElement();

    }
1034305
protected function entityToArray(UserEntityInterface $entity, HydratorInterface $hydrator = null)
    {
        if (!$hydrator) {
            $hydrator = $this->getHydrator();
        }

        return $hydrator->extract($entity);
    }
381649
function xmlSerialize(Writer $writer) {
        // TODO: Implement xmlSerialize() method.
        $cbc = '{urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2}';
        $cac = '{urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2}';

        $writer->write([
            Schema::CBC.'StreetName' => $this->streetName,
            Schema::CBC.'BuildingNumber' => $this->buildingNumber,
            Schema::CBC.'CityName' => $this->cityName,
            Schema::CBC.'PostalZone' => $this->postalZone,
            Schema::CAC.'Country' => $this->country,
        ]);
    }
838933
public function getWriter(int $writer = Output::STANDARD): WriterInterface
	{
		return ($writer === static::STANDARD) ? $this->standard : $this->error;
	}
1305606
public function getWriter() : WriterInterface
    {
        if ($this->writer === null) {
            $directory = $this->getDataDirectory();

            if (!$this->isDirectoryWritable($directory)) {
                throw new ParserConfigurationException("Directory '$directory' is not writable.", 1458974129);
            }

            $this->writer = new Writer($directory, $this->getSource());
            $this->writer->setPropertyFilter($this->getPropertyFilter());
            $this->writer->setDataVersionHash($this->getDataVersionHash());
        }

        return $this->writer;
    }
1046547
protected static function makeWriter($target): WriterInterface
    {
        if (is_array($target) || $target instanceof \ArrayAccess) {
            return new ArrayWriter();
        }

        if (is_object($target)) {
            return new ObjectWriter();
        }

        throw new InvalidTargetException(
            sprintf('Cannot find suitable writer for target type "%s"', gettype($target))
        );
    }
962686
public function write(WriterInterface $writer)
    {
        $this->writer = $writer;
        $this->error  = null;
        $writer->setDocument($this);
        $writer->begin();
        try {
            $this->addLog(sprintf('Start writing document "%s"', basename($this->filename)));
            $this->physicalModel->write($writer);
            $this->addLog('Done writing document');
        } catch (\Exception $e) {
            $this->error = $e;
            $this->addLog($e->getMessage(), LoggerInterface::ERROR);
        }
        $writer->end();

        return $this;
    }
1335841
public function xmlSerialize(Xml\Writer $writer)
    {
        $parameters = [];

        foreach ($this->parameters as $parameter) {
            if ('VALUE' === $parameter->name) {
                continue;
            }

            $parameters[] = $parameter;
        }

        $writer->startElement(strtolower($this->name));

        if (!empty($parameters)) {
            $writer->startElement('parameters');

            foreach ($parameters as $parameter) {
                $writer->startElement(strtolower($parameter->name));
                $writer->write($parameter);
                $writer->endElement();
            }

            $writer->endElement();
        }

        $this->xmlSerializeValue($writer);
        $writer->endElement();
    }
680712
protected function writer()
    {
        if (empty($this->writer)) {
            $this->writer = $this->factory()->writer();
        }

        return $this->writer;
    }