| 1 |
<?php |
| 2 |
namespace Depicter\DataSources; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Arr; |
| 5 |
|
| 6 |
class DataSourceBase |
| 7 |
{ |
| 8 |
/** |
| 9 |
* DataSource name |
| 10 |
* |
| 11 |
* @var string |
| 12 |
*/ |
| 13 |
protected $type = 'base'; |
| 14 |
|
| 15 |
/** |
| 16 |
* DataSource properties |
| 17 |
* |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
protected $properties = []; |
| 21 |
|
| 22 |
/** |
| 23 |
* Default input params for retrieving dataSource records |
| 24 |
* |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
protected $defaultInputParams = []; |
| 28 |
|
| 29 |
/** |
| 30 |
* Asset groups of this DataSource |
| 31 |
* |
| 32 |
* @var array |
| 33 |
*/ |
| 34 |
protected $assetGroupNames = []; |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* Prepares arguments for retrieving dataSource records |
| 39 |
* |
| 40 |
* @param array|object $args |
| 41 |
* |
| 42 |
* @return array |
| 43 |
*/ |
| 44 |
protected function prepare( $args ){ |
| 45 |
$defaultParams = Arr::merge( $this->defaultInputParams, $this->getProperties() ); |
| 46 |
return Arr::merge( $args, $defaultParams ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get a property value |
| 51 |
* |
| 52 |
* @param string $name |
| 53 |
* |
| 54 |
* @return string|null |
| 55 |
*/ |
| 56 |
public function getProperty( string $name ){ |
| 57 |
return $this->properties[ $name ] ?? null; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get all dataSource properties |
| 62 |
* |
| 63 |
* @return array|string[] |
| 64 |
*/ |
| 65 |
public function getProperties(){ |
| 66 |
return $this->properties; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get asset groups of this DataSource |
| 71 |
* |
| 72 |
* @return array |
| 73 |
*/ |
| 74 |
public function getAssetGroupNames(){ |
| 75 |
return $this->assetGroupNames; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
} |
| 80 |
|