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:
<?php
namespace Baguette\Mastodon\Entity
{
const DATETIME_FORMAT = 'Y-m-d\TH:i:s.uO';
function toArrayValue($value)
{
if ($value instanceof \DateTimeInterface) {
return $value->format(\DateTime::W3C);
}
return \Teto\Object\Helper::toArray($value);
}
function map($class, $values)
{
if (!is_array($class)) {
return ($values instanceof $class) ? $values : new $class($values);
}
$class = array_pop($class);
$retval = [];
foreach ($values as $obj) {
$retval[] = ($obj instanceof $class) ? $obj : new $class($obj);
}
return $retval;
}
function mapValues($input_values, $class_map)
{
foreach ($class_map as $prop_name => $class) {
if (isset($input_values[$prop_name])) {
$input_values[$prop_name] = map($class, $input_values[$prop_name]);
}
}
return $input_values;
}
}