src/Api/Service/Base.php
public static function toObject(Model $model)
    {
        if (null === static::MODEL) {
            throw new LogicException('Model class is not defined.');
        }

        $object = new stdClass;

        foreach (static::$map as $local => $remote) {
            if (is_int($local)) {
                $local = $remote;
            }

            $value = $model->{'get'.ucfirst($local)}();

            switch ($local) {
                case 'createdAt':
                case 'updatedAt':
                    if ($value) {
                        $object->$remote = $value->format('Y-m-d\TH:i:sP');
                    }

                    break;

                case 'lastLogin':
                    $object->$remote = null;

                    if ($value) {
                        $object->$remote = $value->format('Y-m-d\TH:i:sP');
                    }

                    break;

                case 'individual':
                    $object->$remote = '/individuals/'.$value->getUuid();
                    break;

                case 'organization':
                    $object->$remote = '/organizations/'.$value->getUuid();
                    break;

                case 'permissions':
                    $object->$remote = [];

                    foreach ($value as $permission) {
                        $object->$remote[] = PermissionService::toObject($permission);
                    }

                    break;

                default:
                    $object->$remote = $value;
            }
        }

        return $object;
    }
public static function toObject(Model $model)
    {
        if (null === static::MODEL) {
            throw new LogicException('Model class is not defined.');
        }

        $object = new stdClass;

        foreach (static::$map as $local => $remote) {
            if (is_int($local)) {
                $local = $remote;
            }

            $value = $model->{'get'.ucfirst($local)}();

            switch ($local) {
                case 'createdAt':
                case 'updatedAt':
                    if ($value) {
                        $object->$remote = $value->format('Y-m-d\TH:i:sP');
                    }

                    break;

                case 'lastLogin':
                    $object->$remote = null;

                    if ($value) {
                        $object->$remote = $value->format('Y-m-d\TH:i:sP');
                    }

                    break;

                case 'individual':
                    $object->$remote = '/individuals/'.$value->getUuid();
                    break;

                case 'organization':
                    $object->$remote = '/organizations/'.$value->getUuid();
                    break;

                case 'permissions':
                    $object->$remote = [];

                    foreach ($value as $permission) {
                        $object->$remote[] = PermissionService::toObject($permission);
                    }

                    break;

                default:
                    $object->$remote = $value;
            }
        }

        return $object;
    }
Cast model to object

@param \Ds\Component\Api\Model\Model $model
@return stdClass
@throws \LogicException