Write getArrayCopy method.

@see \Zend\Stdlib\Hydrator\ArraySerializable::hydrate()
@param \MwbExporter\Writer\WriterInterface $writer
@return \MwbExporter\Formatter\Doctrine2\AnnotationZF2InputFilter\Model\Table
519290
public function writeGetArrayCopy(WriterInterface $writer)
    {
        $columns   = $this->getColumns();
        $relations = $this->getTableRelations();

        $writer
            ->write('/**')
            ->write(' * Return a array with all fields and data.')
            ->write(' * Default the relations will be ignored.')
            ->write(' * ')
            ->write(' * @param array $fields')
            ->write(' * @return array')
            ->write(' */')
            ->write('public function getArrayCopy(array $fields = array())')
            ->write('{')
            ->indent()
                ->write('$dataFields = array(%s);', implode(', ', array_map(function($column) {
                    return sprintf('\'%s\'', $column);
                }, $columns->getColumnNames())))
                ->write('$relationFields = array(%s);', implode(', ', array_map(function($relation) {
                    return sprintf('\'%s\'', lcfirst($relation->getReferencedTable()->getModelName()));
                }, $relations)))
                ->write('$copiedFields = array();')
                ->write('foreach ($relationFields as $relationField) {')
                ->indent()
                    ->write('$map = null;')
                    ->write('if (array_key_exists($relationField, $fields)) {')
                    ->indent()
                        ->write('$map = $fields[$relationField];')
                        ->write('$fields[] = $relationField;')
                        ->write('unset($fields[$relationField]);')
                    ->outdent()
                    ->write('}')
                    ->write('if (!in_array($relationField, $fields)) {')
                    ->indent()
                        ->write('continue;')
                    ->outdent()
                    ->write('}')
                    ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $relationField)))));')
                    ->write('$relationEntity = $this->{$getter}();')
                    ->write('$copiedFields[$relationField] = (!is_null($map))')
                    ->indent()
                        ->write('? $relationEntity->getArrayCopy($map)')
                        ->write(': $relationEntity->getArrayCopy();')
                    ->outdent()
                    ->write('$fields = array_diff($fields, array($relationField));')
                ->outdent()
                ->write('}')
                ->write('foreach ($dataFields as $dataField) {')
                ->indent()
                    ->write('if (!in_array($dataField, $fields) && !empty($fields)) {')
                    ->indent()
                        ->write('continue;')
                    ->outdent()
                    ->write('}')
                    ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $dataField)))));')
                    ->write('$copiedFields[$dataField] = $this->{$getter}();')
                ->outdent()
                ->write('}')
                ->write('')
                ->write('return $copiedFields;')
            ->outdent()
            ->write('}')
            ->write('')
        ;

        return $this;
    }
490678
public function extractManipulationWriteState(&$writes)
    {
        $self = get_class($this);
        $tableName = DataObject::getSchema()->tableName(Subsite::class);
        $query = SQLSelect::create('"ID"', '"' . $tableName . '"');
        $subsites = array_merge(['0'], $query->execute()->column());

        foreach ($writes as $key => $write) {
            $applies = $this->appliesTo($write['class'], true);
            if (!$applies) {
                continue;
            }

            if (isset($write['fields'][SiteTree::class . ':SubsiteID'])) {
                $subsitesForWrite = [$write['fields'][SiteTree::class . ':SubsiteID']];
            } elseif (isset($write['fields'][File::class . ':SubsiteID'])
                && (int) $write['fields'][File::class . ':SubsiteID'] !== 0
            ) {
                // files in subsite 0 should be in all subsites as they are global
                $subsitesForWrite = [$write['fields'][File::class . ':SubsiteID']];
            } else {
                $subsitesForWrite = $subsites;
            }

            $next = [];
            foreach ($write['statefulids'] as $i => $statefulid) {
                foreach ($subsitesForWrite as $subsiteID) {
                    $next[] = [
                        'id' => $statefulid['id'],
                        'state' => array_merge(
                            $statefulid['state'],
                            [$self => (string) $subsiteID]
                        ),
                    ];
                }
            }
            $writes[$key]['statefulids'] = $next;
        }
    }
1049077
public function hydrate(array $data, $object)
    {
        if (!isset($data['track'])) {
            return $object;
        }

        $hydrators = new AggregateHydrator();
        $hydrators->add(new TrackHydrator());
        $hydrators->add(new AlbumAwareHydrator());
        $hydrators->add(new ArtistCollectionAwareHydrator());
        $hydrators->add(new ImageCollectionAwareHydrator());

        $object->setTrack($hydrators->hydrate($data['track'], new Track()));

        return $object;
    }
23174
public function createWriter(bool $append = true): CsvWriterInterface
    {
        $stream = $this->openStream($append ? 'a+' : 'w+');

        $writer = new CsvStreamWriter($stream);
        $writer->setCsvControl($this->delimiter, $this->enclosure, $this->escape);

        if ($this->associativeRows) {
            $writer = new AssociativeWriterDecorator($writer);
            if ($this->headers) {
                $writer->setHeaders($this->headers);
            }
        }

        return $writer;
    }
268535
function xmlSerialize(Writer $writer) {
        $this->validate();

        $writer->write([
                [
                    'name' => Schema::CBC . 'TaxableAmount',
                    'value' => number_format($this->taxableAmount, 2, '.', ''),
                    'attributes' => [
                        'currencyID' => Generator::$currencyID
                    ]

                ],
                [
                    'name' => Schema::CBC . 'TaxAmount',
                    'value' => number_format($this->taxAmount, 2, '.', ''),
                    'attributes' => [
                        'currencyID' => Generator::$currencyID
                    ]

                ],
                Schema::CAC.'TaxCategory' => $this->taxCategory
            ]
        );
    }
541460
public static function addTo(Writer $csv, string $sequence): Writer
    {
        self::register();

        if (!self::isValidSequence($sequence)) {
            throw new InvalidArgumentException('The sequence must contain at least one character to force enclosure');
        }

        $formatter = static function (array $record) use ($sequence) {
            foreach ($record as &$value) {
                $value = $sequence.$value;
            }
            unset($value);

            return $record;
        };

        return $csv
            ->addFormatter($formatter)
            ->addStreamFilter(self::FILTERNAME, ['sequence' => $sequence]);
    }
629056
protected function writeHeader(BaseWriterInterface $writer): void
    {
        if ($this->hasMeta() === true) {
            $writer->setMeta($this->getMeta());
        }

        if ($this->hasJsonApiVersion() === true) {
            $writer->setJsonApiVersion($this->getJsonApiVersion());
        }

        if ($this->hasJsonApiMeta() === true) {
            $writer->setJsonApiMeta($this->getJsonApiMeta());
        }

        if ($this->hasLinks() === true) {
            $writer->setLinks($this->getLinks());
        }

        if ($this->hasProfile() === true) {
            $writer->setProfile($this->getProfile());
        }
    }
745477
public static function addWriter(Log_Interface $writer)
  {
    if (is_null(self::$_writers)) {
      self::$_writers = array();
    }
    
    $key = get_class($writer);
    if (!isset(self::$_writers[$key])) {
      self::$_writers[$key] = $writer;
      $result = true;
    } else {
      $result = false;
    }
    
    return $result;
  }
426673
protected function getReadable(array $writer)
    {
        $classes = array_map('get_class', $writer);

        if (count($classes) == 1) {
            return reset($classes);
        }

        return $classes;
    }
114436
public function xmlSerialize(Xml\Writer $writer)
    {
        $propertiesByGroup = [];

        foreach ($this->children() as $property) {
            $group = $property->group;

            if (!isset($propertiesByGroup[$group])) {
                $propertiesByGroup[$group] = [];
            }

            $propertiesByGroup[$group][] = $property;
        }

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

        foreach ($propertiesByGroup as $group => $properties) {
            if (!empty($group)) {
                $writer->startElement('group');
                $writer->writeAttribute('name', strtolower($group));
            }

            foreach ($properties as $property) {
                switch ($property->name) {
                    case 'VERSION':
                        break;

                    case 'XML':
                        $value = $property->getParts();
                        $fragment = new Xml\Element\XmlFragment($value[0]);
                        $writer->write($fragment);
                        break;

                    default:
                        $property->xmlSerialize($writer);
                        break;
                }
            }

            if (!empty($group)) {
                $writer->endElement();
            }
        }

        $writer->endElement();
    }
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();
    }
1035502
public function getBulkWriteBuilder(string $documentClass): BulkWriteBuilder
    {
        $metadata = $this->metadataFactory->getClassMetadata($documentClass);

        return $this->bulkWriteBuilderFactory->getBulkWriteBuilder($this, $metadata->getCollectionName());
    }
340026
public static function getResource(StreamInterface $stream)
    {
        self::register();

        if ($stream->isReadable()) {
            $mode = $stream->isWritable() ? 'r+' : 'r';
        } elseif ($stream->isWritable()) {
            $mode = 'w';
        } else {
            throw new \InvalidArgumentException('The stream must be readable, '
                .'writable, or both.');
        }

        return fopen('phmessage://stream', $mode, null, stream_context_create([
            'phmessage' => ['stream' => $stream],
        ]));
    }
1273434
function xmlSerialize(Writer $writer) {
        $writer->write([
            Schema::CBC . 'ID' => $this->id,
            [
                'name' => Schema::CBC . 'InvoicedQuantity',
                'value' => $this->invoicedQuantity,
                'attributes' => [
                    'unitCode' => $this->unitCode
                ]
            ],
            [
                'name' => Schema::CBC . 'LineExtensionAmount',
                'value' => number_format($this->lineExtensionAmount, 2, '.', ''),
                'attributes' => [
                    'currencyID' => Generator::$currencyID
                ]
            ],
            Schema::CAC . 'TaxTotal' => $this->taxTotal,
            Schema::CAC . 'Item' => $this->item,
        ]);

        if ($this->price !== null) {
            $writer->write(
                [
                    Schema::CAC . 'Price' => $this->price
                ]
            );
        }
    }
912763
public function write(WriterInterface $writer)
    {
        foreach ($this->childs as $indice) {
            $indice->write($writer);
        }

        return $this;
    }
442038
function xmlSerialize(Writer $writer) {
        $this->validate();

        $writer->write([
            [
                'name' => Schema::CBC . 'TaxAmount',
                'value' => number_format($this->taxAmount, 2, '.', ''),
                'attributes' => [
                    'currencyID' => Generator::$currencyID
                ]
            ],
        ]);

        foreach($this->taxSubTotals as $taxSubTotal){
            $writer->write([Schema::CAC . 'TaxSubtotal' => $taxSubTotal]);
        }
    }
84970
public function write(WriterInterface $writer)
    {
        try {
            if (strlen($category = $this->getConfig()->get(FormatterInterface::CFG_EXPORT_TABLE_CATEGORY)) && 
                $this->getCategory() != $category) {
                $status = 'skipped, not in category';
            } else {
                switch ($this->writeTable($writer)) {
                    case self::WRITE_OK:
                        $status = 'OK';
                        break;

                    case self::WRITE_EXTERNAL:
                        $status = 'skipped, marked as external';
                        break;

                    case self::WRITE_M2M:
                        $status = 'skipped, M2M table';
                        break;

                    default:
                        $status = 'unsupported';
                        break;
                }
            }
            $this->getDocument()->addLog(sprintf('* %s: %s', $this->getRawTableName(), $status));
        } catch (\Exception $e) {
            $this->getDocument()->addLog(sprintf('* %s: ERROR', $this->getRawTableName()));
            throw $e;
        }

        return $this;
    }