<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chrispenny / silverstripe-data-object-to-fixture example snippets
// Instantiate the Service.
$service = new FixtureService();
// Fetch the DataObject that you wish to generate a fixture for.
/** @var Page $page */
$page = Page::get()->byID(1);
// Add the DataObject to the Service.
$service->addDataObject($dataObject);
// Generating the fixture can also generate new warnings
$output = $service->outputFixture();
// Check for warnings? This is somewhat important, because if you have looping relationships (which we have no way of
// creating fixtures for at the moment) this is how you'll know about it.
if (count($service->getWarnings()) > 0) {
Debug::dump($service->getWarnings());
}
// Do something with the fixture output.
highlight_string($output);
// Or maybe save the output to a file?
$fixture = Director::baseFolder() . '/app/resources/fixture.yml';
file_put_contents($fixture, $service->outputFixture());