AdadgioGearBundle
Installation
Install with composer.
composer require adadgio/gear-bundle
Add the bundle to your app kernel.
new Adadgio\GearBundle\AdadgioGearBundle();
Table of contents
Api annotations and auth
Its very easy to create API endpoints and secure them through any kind of authentication system.
Configuration
adadgio_gear:
auth:
type: Basic
class: ~
user: benny
password: test
adadgio_gear:
auth:
provider: my_bundle.api.my_client_auth
Annotation usage
use Adadgio\GearBundle\Component\Api\ApiRequest;
use Adadgio\GearBundle\Component\Api\ApiResponse;
use Adadgio\GearBundle\Component\Api\Annotation\Api;
public function myApiEndpointAction(Request $request, ApiRequest $apiRequest)
{
return new ApiResponse(array('yes' => 'sir'));
}
Example using custom authenticator service.
use Adadgio\GearBundle\Component\Api\Authenticator\AuthProvider;
use Adadgio\GearBundle\Component\Api\Authenticator\AuthProviderInterface;
class ExampleAuthProviderService extends AuthProvider implements AuthProviderInterface
{
public function __construct()
{
}
public function authenticate()
{
$request = $this->getRequest();
$headers = $request->getHeaders();
return true;
}
}
NodeRed connector(s) and loops
Configuration
_adadgio_gear:
resource: "@AdadgioGearBundle/Resources/config/routing.yml"
adadgio_gear:
nodered:
host: 127.0.0.1
port: 1880
protocol: http://
http_auth:
user: ~
pass: ~
Then you need to install the flows in your NodeRed app.
$ php app/console adadgio:nodered:install --output=/destination/folder
You will need to manually import the flows in your NodeRed app (or use flows directory config in NodeRed settings.js).

Usage
To trigger a loop (or just a delayed message), you need to create a \Payload that node red will send back to the AdagagioGearBundle loop controller (see routing.yml for more info). The controller dispatches an event when it receives back the payload. You can listen to the event and modify the payload to achieve your goal.
use Adadgio\GearBundle\Connector\NodeRed\Payload;
$payload = new Payload();
$payload->setParameter('my_name', 'Romain');
$this->get('adadgio_gear.nodered.connector')->send('POST', '/adadgio/gear/loop/start', $payload);
The loop will never stop until you change the payload kill property. Now listen to the loop callbacks. Nodered will indefinitaly call it unless you kill the payload.
public function onPayloadReceived(\Adadgio\GearBundle\Connector\NodeRed\Event\PayloadEvent $event)
{
$request = $event->getRequest();
$payload = $event->Payload();
if ($payload->getIteration() > 3) {
$payload->kill();
}
$name = $payload->getParameter('my_name');
$name = ...
$payload->setParameter('my_name', $name);
}
CSV exporter
use Adadgio\GearBundle\Component\Reader\CsvExporter;
$exporter = $this->get('adadgio_gear.csv_exporter')
->setName("exportFileName")
->setColumns(array('label', 'views'))
->setData(array(array('one','two'),array('three','for')))
->generate();
CSV reader
use Adadgio\GearBundle\Component\Reader\CsvReader;
$csv = new CsvReader('data/test.csv');
$data = $csv
->setDelimiter(';')
->read(5, 15)
->getData();
Entity hydration from data
```php
use Adadgio\GearBundle\Component\Hydration\EntityHydrator;
$hydrator = new EntityHydrator();
// $data = ... data from the previous example
$hydrator
->hydrate('Adadgio\DoctrineDQLBundle\Entity\TestEntity')
->with($data)
->map(0, 'id') // map array column index to entity property
->map(1, 'name');
$entities = $hydrator->getEntities();
</sub>
## <a name="serializer"></a>Serializer
Transform an object in array. Possibilty to transform one object or a collection of objects.
```php
use Adadgio\GearBundle\Component\Serialization\EntitySerializer;
$entities = $em->getRepository('AppBundle:Product')->findAll();
$serializer = $this->get('adadgio_gear.entity_serializer');
$dataSerialized = $serializer->serialize($entitiesÂ);
Others
Starting NodeRed with custom settings file in dev environment (with Ngrok in this case).
pm2 start /usr/local/bin/node-red -- -v --settings=/Library/WebServer/home/symfony/360medical-v3/app/data/nodered/settings.js