Skip to content

A simple utility to create payloads in an easy object oriented construct and transform it into different data structures viz. array, objects, string(json).

License

Notifications You must be signed in to change notification settings

shahburhan/payload-struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

payload-struct

A simple utility to create payloads in an easy object oriented construct and transform it into different structures viz. array, objects, string(json).

Usage:

Create a new PayloadStruct instance

$payload = new PayloadStruct;

Set Items:

$payload->setName('Jane Doe');
$payload->setEmail('[email protected]');
$payload->setPhone('1234567890');
$payload->setWebsite('example.com');

You can also chain the setters:

$payload->setName('Jane Doe')
  ->setEmail('[email protected]')
  ->setPhone('1234567890')
  ->setWebsite('example.com');

Or use assignment notation:

$payload->language = 'English';

And get the final payload in different structures:

$payload->getArray();

Output:

Array
(
    [name] => Jane Doe
    [email] => [email protected]
    [phone] => 1234567890
    [website] => example.com
    [language] => English
)

$payload->getJson();

Output:

{"name":"Jane Doe","email":"[email protected]","phone":"1234567890","website":"example.com","language":"English"}

$payload->getObject();

Output:

stdClass Object
(
    [name] => Jane Doe
    [email] => [email protected]
    [phone] => 1234567890
    [website] => example.com
    [language] => English
)

You can also access individual items with getter notation or direct property access notation as follows:

$payload->getName(); //Outputs Jane Doe
$payload->name; //Outputs Jane Doe

Reset payload data:

$payload->flush();

You can chain on to add new data items:

$payload->flush()
  ->setNewName('John Doe');

About

A simple utility to create payloads in an easy object oriented construct and transform it into different data structures viz. array, objects, string(json).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages