for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace iamsaint\yml;
use DateTimeImmutable;
use Exception;
use XMLWriter;
/**
* Class Writer
* @package iamsaint\yml
*/
class Writer
{
* @param string $fileName
* @param BaseObject $object
* @return bool|int
* @throws Exception
public function write(string $fileName, BaseObject $object)
return file_put_contents($fileName, $this->writeToString($object));
}
* @return mixed
private function writeToString($object): string
$writer = new XMLWriter();
$writer->openMemory();
$writer->startDocument('1.0', 'UTF-8');
$writer->setIndent(true);
$writer->startElement('yml_catalog');
$writer->writeAttribute('date', (new DateTimeImmutable('now'))->format('Y-m-d H:i'));
if (null !== $object) {
$object->write($writer);
$writer->endElement();
return $writer->flush();