NerdsAndCompany\Schematic\Services\Schematic::exportToYaml PHP Method

exportToYaml() public method

Export to Yaml file.
public exportToYaml ( string $file, $dataTypes = 'all', boolean $autoCreate = true ) : Result
$file string
$autoCreate boolean
return NerdsAndCompany\Schematic\Models\Result
    public function exportToYaml($file, $dataTypes = 'all', $autoCreate = true)
    {
        Craft::app()->config->maxPowerCaptain();
        Craft::app()->setComponent('userSession', $this);
        $result = new Result();
        $dataModel = $this->exportDataModel($dataTypes);
        $yaml = Data::toYaml($dataModel);
        if (!IOHelper::writeToFile($file, $yaml, $autoCreate)) {
            // Do not auto create
            $result->addError('errors', "Failed to write contents to \"{$file}\"");
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * Test export to yml with error writing to file.
  *
  * @covers ::exportToYaml
  */
 public function testExportFromYamlWithFileError()
 {
     $this->prepExportMockServices();
     $results = $this->schematicService->exportToYaml('non-existing-folder/not-a-file', false);
     $this->assertTrue($results->hasErrors());
 }