Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sweetchuck/robo-serialize


https://github.com/sweetchuck/robo-serialize

robo robo-tasks serializer

Last synced: 24 days ago
JSON representation

Awesome Lists containing this project

README

        

# Robo task to serialize data structures

[![CircleCI](https://circleci.com/gh/Sweetchuck/robo-serialize/tree/3.x.svg?style=svg)](https://circleci.com/gh/Sweetchuck/robo-serialize/?branch=3.x)
[![codecov](https://codecov.io/gh/Sweetchuck/robo-serialize/branch/3.x/graph/badge.svg?token=M7avP9BiV1)](https://app.codecov.io/gh/Sweetchuck/robo-serialize/branch/3.x)

## Install

Run `composer require sweetchuck/robo-serialize`

## Usage example

```php
getSerializer('json');
$writer = new StreamOutput(fopen($dstFileName, 'w+'));

return $this
->collectionBuilder()
->addCode(function (RoboStateData $data): int {
$data['my_config.json'] = [
'description' => 'this is the initial value of the my_config.json',
];

return 0;
})
->addCode($this->getTaskIndependentConfigManipulator1('my_config.json'))
->addCode($this->getTaskIndependentConfigManipulator2('my_config.json'))
->addTask($this
->taskSerialize()
->setSerializer($serializer)
->setWriter($writer)
->deferTaskConfiguration('setValue', 'my_config.json')
);
}

protected function getTaskIndependentConfigManipulator1(string $stateKey): \Closure
{
return function (RoboStateData $data) use ($stateKey): int {
$data[$stateKey]['manipulator_1'] = 'foo';

return 0;
};
}

protected function getTaskIndependentConfigManipulator2(string $stateKey): \Closure
{
return function (RoboStateData $data) use ($stateKey): int {
$data[$stateKey]['manipulator_2'] = 'bar';

return 0;
};
}
}
```