-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathExportable.php
More file actions
41 lines (32 loc) · 929 Bytes
/
Exportable.php
File metadata and controls
41 lines (32 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace ProcessMaker\Traits;
use ProcessMaker\Enums\ExporterMap;
use ProcessMaker\Exception\ExporterNotSupported;
use ProcessMaker\ImportExport\Exporter;
trait Exportable
{
use HasUuids;
private $_preventSavingDiscardedModel = false;
public static function bootPreventDiscardedModelsFromSaving()
{
static::saving(function ($model) {
if ($this->_preventSavingDiscardedModel) {
return false;
}
});
}
public function preventSavingDiscardedModel()
{
$this->_preventSavingDiscardedModel = true;
}
public function export()
{
$exporterClass = ExporterMap::getExporterClassForModel($this);
if (!$exporterClass) {
throw new ExporterNotSupported();
}
$exporter = new Exporter();
$exporter->export($this, $exporterClass);
return $exporter->payload();
}
}