1. Go to this page and download the library: Download adadgio/rocket-bundle 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/ */
adadgio / rocket-bundle example snippets
new Adadgio\GearBundle\AdadgioGearBundle();
use Adadgio\GearBundle\Component\Api\ApiRequest;
use Adadgio\GearBundle\Component\Api\ApiResponse;
use Adadgio\GearBundle\Component\Api\Annotation\Api;
/**
* @Route("/test/gear/api", name="test_gear_api")
* @Api(method={"POST","GET"}, enabled=true)
*/
public function myApiEndpointAction(Request $request, ApiRequest $apiRequest)
{
return new ApiResponse(array('yes' => 'sir'));
}
use Adadgio\GearBundle\Component\Api\Authenticator\AuthProvider;
use Adadgio\GearBundle\Component\Api\Authenticator\AuthProviderInterface;
class ExampleAuthProviderService extends AuthProvider implements AuthProviderInterface
{
/**
* Build your service like you build services every day!
*/
public function __construct()
{
// inject anything in here, like doctrien.orm.entity_manager, or whatever.
}
/**
* Checks auth. You could get request headers key and check that
* the secret key and client id are in your database for example...
*
* @return boolean
*/
public function authenticate()
{
// your owns logic here
$request = $this->getRequest();
$headers = $request->getHeaders();
return true;
}
}
use Adadgio\GearBundle\Connector\NodeRed\Payload;
// payload contains 3 initial params you cannot override (pid, kill, iteration)
// and they change automatically during the loop lifecycle
$payload = new Payload();
// add more params
$payload->setParameter('my_name', 'Romain'); // nb: 3 params are here by default
// use the connector to start (trigger) the loop
$this->get('adadgio_gear.nodered.connector')->send('POST', '/adadgio/gear/loop/start', $payload); // @todo pass this more transparently
// in some listener, far, far away, a long long time ago
// the listener must listen to "adadgio_gear.nodered.payload_received"
public function onPayloadReceived(\Adadgio\GearBundle\Connector\NodeRed\Event\PayloadEvent $event)
{
// you might need the request, who knows
$request = $event->getRequest();
$payload = $event->Payload();
// notice iteration changed to +1, pid always stays the same (unless you trigger another process)
// otherwise you get back the parameters you defined earlier
// if you wanna stop the flow
if ($payload->getIteration() > 3) {
$payload->kill();
}
// process... something, or modify your input params at runtime
$name = $payload->getParameter('my_name');
$name = ... // change your name!
$payload->setParameter('my_name', $name);
}
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();
use Adadgio\GearBundle\Component\Reader\CsvReader;
$csv = new CsvReader('data/test.csv');
$data = $csv
->setDelimiter(';')
->read(5, 15) // reads rows from 5 to 15
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();