Source of file DataSource.php
Size: 1,453 Bytes - Last Modified: 2021-12-23T10:56:30+00:00
/var/www/docs.ssmods.com/process/src/code/DataSource.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php namespace UncleCheese\Green; use \Exception; use \DBField; /** * Class DataSource * * Defines a file of serialised data (e.g. JSON, YAML) that can be used * to populate a template * * @package UncleCheese\Green * @author UncleCheese <unclecheese@leftandmain.com> */ class DataSource { /** * @var string */ protected $path; /** * DataSource constructor. * @param $path */ public function __construct($path) { if (!file_exists($path)) { throw new Exception("$path doesn't exist."); } $this->path = $path; } /** * Converts the file content into a SerialisedDBField * * @return SerialisedDBField|null */ public function toDBObject() { $info = pathinfo($this->path); switch ($info['extension']) { case 'yaml': case 'yml': return DBField::create_field('YAMLField', file_get_contents($this->path)); case 'json': return DBField::create_field('JSONField', file_get_contents($this->path)); default: return null; } } /** * A simple name for the data source * * @return string */ public function getName() { return basename($this->path); } /** * @return string */ public function getPath() { return $this->path; } } |