Maslosoft Signals API
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/signals
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/signals/
*/
namespace Maslosoft\Signals\Builder\IO;
use Maslosoft\Cli\Shared\Helpers\PhpExporter;
use Maslosoft\Signals\Interfaces\BuilderIOInterface;
use Maslosoft\Signals\Signal;
/**
* PhpFileOutput
* @codeCoverageIgnore
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class PhpFile implements BuilderIOInterface
{
/**
* Generated path is directory, where signals definition will be stored.
* Path is relative to project root.
*
* **This directory must be writable by command line user**
*
* **This directory should be committed and distributed along with the project code**
*
* @var string
*/
public $generatedPath = 'generated';
/**
* File name for file containing signals definitions, in most cases
* leaving default value is fine.
*
* @var string
*/
public $configFilename = 'signals-definition.php';
/**
* Signal instance
* @var Signal
*/
private $signal = null;
public function read()
{
$file = $this->generatedPath . '/' . $this->configFilename;
if (file_exists($file))
{
return (array) require $file;
}
else
{
$this->signal->getLogger()->debug('Config file "{file}" does not exists, have you generated signals config file?', ['file' => $file]);
}
}
public function setSignal(Signal $signal)
{
$this->signal = $signal;
return $this;
}
public function write($data)
{
$path = sprintf("%s/%s", $this->generatedPath, $this->configFilename);
// Use dirname here in case configFilename contains dir
$dir = dirname($path);
if (!is_dir($dir))
{
mkdir($dir, 0777, true);
}
return file_put_contents($path, PhpExporter::export($data, 'Auto generated, any changes will be lost'));
}
}
API documentation generated by ApiGen