PHP code example of didix16 / php-apidataobject
1. Go to this page and download the library: Download didix16/php-apidataobject library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
didix16 / php-apidataobject example snippets
composer
class ApiPlatformDataObject extends ApiDataObject {}
...
class AWebHookProcessor {
/**
* @var array|object
*/
$data;
public function process()
{
$apiData = new ApiPlatformDataObject($this->data);
/**
* data =
* [
* 'property1' => 'value1',
* 'property2' => 'value2',
* 'property3' => 'value3',
* 'property4' => 'value4',
* ...
* ]
*/
/**
* Different accessors
*/
$apiData['property1'];
$apiData->property1;
$apiData->property1();
/**
* Different setters
*/
$apiData['property1'] = 'value5';
$apiData->property1 = 'value5';
// chainable setter properties
$apiData
->property1('value5')
->property2('value6')
...
}
public function processJson(string $json)
{
$apiData = ApiPlatformDataObject::fromJson($json);
/**
* Different accessors
*/
$apiData['property1'];
$apiData->property1;
$apiData->property1();
/**
* Different setters
*/
$apiData['property1'] = 'value5';
$apiData->property1 = 'value5';
// chainable setter properties
$apiData
->property1('value5')
->property2('value6')
...
}
}