20steps/placetel-bundle
Symfony2 bundle exposing Placetel monitoring as a configurable service. Supports API access with adjustable timeouts, response caching to avoid rate limits, and some derived KPIs. Early/incomplete implementation; docs and full API coverage pending.
Installation:
composer require 20steps/placetel-bundle:dev-master
Add to AppKernel.php:
new twentysteps\Bundle\PlacetelBundle\twentystepsPlacetelBundle(),
Import services in config.yml:
imports:
- { resource: "@twentystepsPlacetelBundle/Resources/config/services.yml" }
Configure:
Add to parameters.yml:
parameters:
twentysteps_placetel.url: "https://api.placetel.de/api/"
twentysteps_placetel.api_key: "your_api_key_here"
twentysteps_placetel.timeout: 10
twentysteps_placetel.connect_timeout: 5
twentysteps_placetel.cache_ttl: 3600
First Use Case: Inject the service in a controller or command:
use twentysteps\Bundle\PlacetelBundle\Services\PlacetelService;
class MyController extends Controller
{
public function indexAction(PlacetelService $placetel)
{
$services = $placetel->getServices();
return $this->render('template.html.twig', ['services' => $services]);
}
}
Service Injection: Prefer dependency injection over manual container access for better testability:
class MyService
{
private $placetel;
public function __construct(PlacetelService $placetel)
{
$this->placetel = $placetel;
}
}
Caching Strategy:
Leverage built-in caching (TTL: 3600 by default) to avoid rate limits:
$calls = $this->placetel->getCalls(); // Cached for 1 hour
Error Handling: Wrap API calls in try-catch blocks to handle timeouts/errors gracefully:
try {
$result = $this->placetel->getSomeData();
} catch (\RuntimeException $e) {
$this->addFlash('error', 'Placetel API error: ' . $e->getMessage());
}
KPI Derivation: Use derived KPIs (e.g., call durations, success rates) for dashboards:
$kpis = $this->placetel->getKpis();
$avgDuration = $kpis['avg_call_duration'];
# config.yml
services:
my.placetel.listener:
class: AppBundle\EventListener\PlacetelListener
tags:
- { name: kernel.event_listener, event: placetel.call.created, method: onCallCreated }
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncPlacetelDataCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$placetel = $this->getContainer()->get('twentysteps_placetel.service');
$output->writeln('Syncing services...');
$services = $placetel->getServices();
// Process data...
}
}
Rate Limiting:
cache_ttl), but aggressive polling (e.g., every minute) may still hit limits.cache_ttl or implement exponential backoff in custom wrappers.Deprecated Methods:
Services/PlacetelService.php for available methods before use.Timeouts:
timeout: 10 and connect_timeout: 5 may be too low for slow networks.parameters.yml if API responses are delayed.No Full API Coverage:
createCall).$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.placetel.de/api/calls', [
'auth' => ['api_key', ''],
]);
config.yml to log API requests:
twentysteps_placetel:
debug: true
php bin/console cache:clear
Custom Endpoints:
Extend PlacetelService to add missing methods:
// src/AppBundle/Service/ExtendedPlacetelService.php
class ExtendedPlacetelService extends \twentysteps\Bundle\PlacetelBundle\Services\PlacetelService
{
public function getCustomData()
{
return $this->callApi('GET', '/custom/endpoint');
}
}
Register as a service:
services:
app.placetel.extended:
class: AppBundle\Service\ExtendedPlacetelService
parent: twentysteps_placetel.service
Override Cache: Disable caching for specific methods by injecting a custom cache pool:
services:
app.placetel.no_cache:
class: AppBundle\Service\NoCachePlacetelService
arguments:
- '@twentysteps_placetel.http_client'
- null # Disable cache
Event Dispatching: Trigger Symfony events after API calls (e.g., for logging):
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class MyPlacetelService extends PlacetelService
{
private $dispatcher;
public function __construct(HttpClient $client, EventDispatcherInterface $dispatcher)
{
parent::__construct($client);
$this->dispatcher = $dispatcher;
}
protected function afterApiCall($response)
{
$this->dispatcher->dispatch('placetel.api.response', new PlacetelEvent($response));
}
}
How can I help you explore Laravel packages today?