iflrandevu/engine/Api/V1/Parsers/Customers.php

104 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2016-07-10 13:52:21 +03:00
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
2016-07-10 13:52:21 +03:00
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.2.0
* ---------------------------------------------------------------------------- */
namespace EA\Engine\Api\V1\Parsers;
2016-07-10 13:52:21 +03:00
/**
* Customers Parser
2016-07-10 13:52:21 +03:00
*
* This class will handle the encoding and decoding from the API requests.
*
* @deprecated
2016-07-10 13:52:21 +03:00
*/
class Customers implements ParsersInterface {
/**
* Encode Response Array
*
2016-07-10 13:52:21 +03:00
* @param array &$response The response to be encoded.
*/
public function encode(array &$response)
{
$encoded_response = [
'id' => $response['id'] !== NULL ? (int)$response['id'] : NULL,
'firstName' => $response['first_name'],
'lastName' => $response['last_name'],
2016-07-10 13:52:21 +03:00
'email' => $response['email'],
'phone' => $response['phone_number'],
'address' => $response['address'],
'city' => $response['city'],
'zip' => $response['zip_code'],
'notes' => $response['notes']
];
$response = $encoded_response;
2016-07-10 13:52:21 +03:00
}
/**
* Decode Request
*
* @param array &$request The request to be decoded.
* @param array $base Optional (null), if provided it will be used as a base array.
2016-07-10 13:52:21 +03:00
*/
public function decode(array &$request, array $base = NULL)
{
$decoded_request = $base ?: [];
2016-07-10 13:52:21 +03:00
if ( ! empty($request['id']))
{
$decoded_request['id'] = $request['id'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['firstName']))
{
$decoded_request['first_name'] = $request['firstName'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['lastName']))
{
$decoded_request['last_name'] = $request['lastName'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['email']))
{
$decoded_request['email'] = $request['email'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['phone']))
{
$decoded_request['phone_number'] = $request['phone'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['address']))
{
$decoded_request['address'] = $request['address'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['city']))
{
$decoded_request['city'] = $request['city'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['zip']))
{
$decoded_request['zip_code'] = $request['zip'];
2016-07-10 13:52:21 +03:00
}
if ( ! empty($request['notes']))
{
$decoded_request['notes'] = $request['notes'];
2016-07-10 13:52:21 +03:00
}
$request = $decoded_request;
2016-07-10 13:52:21 +03:00
}
}