adadgio/gear-bundle
Symfony bundle providing API endpoint annotations with pluggable authentication (basic or custom provider services). Includes utilities like Node-RED connectors/loops, CSV export/import, entity hydration from data, and serializer helpers.
Installation:
composer require adadgio/gear-bundle
Register the bundle in config/bundles.php:
return [
// ...
Adadgio\GearBundle\AdadgioGearBundle::class => ['all' => true],
];
Basic API Auth (Basic Auth):
Configure config/packages/adadgio_gear.yaml:
adadgio_gear:
auth:
type: Basic
user: "admin"
password: "secure123"
First Use Case: Annotate a controller method to secure an API endpoint:
use Adadgio\GearBundle\Component\Api\Annotation\ApiAuth;
class MyController extends AbstractController
{
/**
* @ApiAuth()
*/
public function secureEndpoint()
{
return new JsonResponse(['data' => 'protected']);
}
}
Workflow:
@ApiAuth().Basic, custom service, etc.) in adadgio_gear.yaml.Example: Custom Auth Provider:
adadgio_gear:
auth:
type: ~
provider: "adadgio_gear.api.authenticator_db_service"
Define the service in services.yaml:
services:
adadgio_gear.api.authenticator_db_service:
class: App\Service\CustomAuthProvider
arguments: ['@doctrine.orm.entity_manager']
CSV Export:
Use the CsvExporter service to generate CSV files from arrays or Doctrine collections:
$exporter = $this->get('adadgio_gear.csv.exporter');
$csvData = $exporter->export($arrayOfData, ['header1', 'header2']);
file_put_contents('output.csv', $csvData);
CSV Import: Parse CSV files into arrays or hydrate entities:
$reader = $this->get('adadgio_gear.csv.reader');
$csvData = $reader->read('input.csv');
$hydrator = $this->get('adadgio_gear.entity.hydrator');
$entity = $hydrator->hydrate($arrayData, User::class);
adadgio_gear:
nodered:
url: "http://nodered.local:1880"
auth:
type: Basic
user: "nodered"
password: "password"
FlowExecutor service to send data to Node-RED:
$executor = $this->get('adadgio_gear.nodered.flow_executor');
$executor->execute('my-flow-id', ['key' => 'value']);
lexik/jwt-authentication-bundle or nelmio/api-doc-bundle.league/csv or php-console/csv.Annotation Parsing:
framework:
annotations: true
tags: ['adadgio_gear.authenticator']
CSV Encoding:
CsvReader/CsvExporter to avoid UTF-8/BOM issues:
$reader->setEncoding('UTF-8');
Entity Hydration:
setPropertyMapping():
$hydrator->setPropertyMapping([
'user_email' => 'email', // Map array key to entity property
]);
Auth Failures:
Enable debug mode and check Symfony’s profiler for 401 Unauthorized errors. Verify:
adadgio_gear.yaml.Node-RED Connectivity:
Test the Node-RED URL manually (e.g., curl http://nodered.local:1880). Use GuzzleHttp for debugging:
$client = new \GuzzleHttp\Client();
$response = $client->get('http://nodered.local:1880');
Custom Auth Logic:
Extend Adadgio\GearBundle\Component\Api\Authenticator\AbstractAuthenticator for bespoke auth:
class DatabaseAuthenticator extends AbstractAuthenticator
{
public function authenticate(Request $request)
{
// Custom logic (e.g., check DB for API keys)
}
}
Serializer Extensions: Override the default serializer by configuring a custom service:
adadgio_gear:
serializer:
class: App\Service\CustomSerializer
How can I help you explore Laravel packages today?