1
0
mirror of synced 2024-12-01 23:36:02 +03:00
mg-bot-api-client-php/src/Serializer.php

63 lines
1.3 KiB
PHP
Raw Normal View History

2019-06-10 16:24:22 +03:00
<?php
/**
* PHP version 7.0
*
* Serializer
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common;
/**
* PHP version 7.0
*
* Serializer class
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Serializer
{
2019-06-17 12:43:54 +03:00
/**
* Serialization flag: serialize object to PHP Array
*/
2019-06-10 16:24:22 +03:00
const S_ARRAY = 0;
2019-06-17 12:43:54 +03:00
/**
* Serialization flag: serialize object to JSON string
*/
2019-06-10 16:24:22 +03:00
const S_JSON = 1;
/**
* Serialize given object to JSON or Array
*
* @param object $request
* @param int $serialize
*
* @return array|string
*/
public static function serialize($request, $serialize = self::S_JSON)
{
$serialized = null;
switch ($serialize) {
case self::S_ARRAY:
2019-06-17 12:43:54 +03:00
$serialized = $request->asArray();
2019-06-10 16:24:22 +03:00
break;
case self::S_JSON:
default:
2019-06-17 12:43:54 +03:00
$serialized = $request->asJson();
2019-06-10 16:24:22 +03:00
break;
}
return $serialized;
}
}