New Library
This commit is contained in:
parent
5c6f6c97b7
commit
c479658f0b
83 changed files with 5788 additions and 0 deletions
35
server/vendor/php-opencloud/common/src/Common/HydratorStrategyTrait.php
vendored
Normal file
35
server/vendor/php-opencloud/common/src/Common/HydratorStrategyTrait.php
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\Common;
|
||||
|
||||
/**
|
||||
* Represents common functionality for populating, or "hydrating", an object with arbitrary data.
|
||||
*
|
||||
* @package OpenCloud\Common
|
||||
*/
|
||||
trait HydratorStrategyTrait
|
||||
{
|
||||
/**
|
||||
* Hydrates an object with set data
|
||||
*
|
||||
* @param array $data The data to set
|
||||
* @param array $aliases Any aliases
|
||||
*/
|
||||
private function hydrate(array $data, array $aliases = [])
|
||||
{
|
||||
foreach ($data as $key => $val) {
|
||||
$key = isset($aliases[$key]) ? $aliases[$key] : $key;
|
||||
if (property_exists($this, $key)) {
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function set($key, $property, array $data, callable $fn = null)
|
||||
{
|
||||
if (isset($data[$key]) && property_exists($this, $property)) {
|
||||
$value = $fn ? call_user_func($fn, $data[$key]) : $data[$key];
|
||||
$this->$property = $value;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue