mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 10:57:40 +02:00
Introduce common DataExtractor
trait
This commit is contained in:
parent
3c55422fa7
commit
26f2f73510
37
library/Icinga/Common/DataExtractor.php
Normal file
37
library/Icinga/Common/DataExtractor.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Common;
|
||||
|
||||
trait DataExtractor
|
||||
{
|
||||
/**
|
||||
* Extract data from array to this class's properties
|
||||
*
|
||||
* Unknown properties (no matching setter) are ignored
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fromArray(array $data)
|
||||
{
|
||||
foreach ($data as $name => $value) {
|
||||
$func = 'set'. ucfirst($name);
|
||||
if (method_exists($this, $func)) {
|
||||
$this->$func($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this class's structure as array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user