dbp/relay-greenlight-connector-campusonline-bundle
Install the Bundle
composer require dbp/relay-greenlight-connector-campusonline-bundle
Ensure DbpRelayGreenlightBundle is already installed (this bundle extends it).
Configure the Bundle
Add to config/bundles.php:
return [
// ...
Dbp\Relay\GreenlightConnector\CampusOnlineBundle\DbpRelayGreenlightConnectorCampusonlineBundle::class => ['all' => true],
];
Environment Configuration
Define LDAP and CampusOnline API credentials in .env:
# LDAP (for fetching co-obfuscated-c-ident)
LDAP_HOST=ldap.example.com
LDAP_BASE_DN=ou=users,dc=example,dc=com
LDAP_USERNAME=cn=admin,dc=example,dc=com
LDAP_PASSWORD=your_ldap_password
# CampusOnline API (for fetching images)
CAMPUSONLINE_API_URL=https://campusonline.example.edu/api
CAMPUSONLINE_API_KEY=your_api_key
First Use Case: Fetching CampusOnline Images Trigger the connector via a command or event listener (e.g., after user registration):
use Dbp\Relay\GreenlightConnector\CampusOnlineBundle\Service\CampusOnlineConnector;
$connector = $this->container->get(CampusOnlineConnector::class);
$imageUrl = $connector->fetchCampusOnlineImage('co-obfuscated-c-ident-123');
LDAP Integration
Use the bundle’s LdapService to fetch co-obfuscated-c-ident for users:
$ldapService = $this->container->get(\Dbp\Relay\GreenlightConnector\CampusOnlineBundle\Service\LdapService::class);
$obfuscatedId = $ldapService->getObfuscatedId('user@example.com');
CampusOnline API Calls
Leverage the CampusOnlineConnector to fetch images or metadata:
$connector = $this->container->get(CampusOnlineConnector::class);
$imageData = $connector->fetchImageData($obfuscatedId);
Event-Driven Sync
Listen for user events (e.g., UserRegisteredEvent) to trigger syncs:
// src/EventListener/CampusOnlineSyncListener.php
public function onUserRegistered(UserRegisteredEvent $event)
{
$obfuscatedId = $this->ldapService->getObfuscatedId($event->getUser()->getEmail());
$this->campusOnlineConnector->syncUser($obfuscatedId);
}
Caching Responses
Cache API responses to avoid rate limits (e.g., using Symfony’s CacheInterface):
$cache = $this->container->get('cache.app');
$cachedData = $cache->get("campusonline_{$obfuscatedId}", function() use ($connector, $obfuscatedId) {
return $connector->fetchImageData($obfuscatedId);
});
CampusOnlineConnector and LdapService.CampusOnlineApiException:
try {
$data = $connector->fetchImageData($id);
} catch (CampusOnlineApiException $e) {
$this->logger->error('CampusOnline API failed', ['error' => $e->getMessage()]);
}
LdapService and CampusOnlineConnector in unit tests:
$mockConnector = $this->createMock(CampusOnlineConnector::class);
$mockConnector->method('fetchImageData')->willReturn(['url' => 'http://example.com/image.jpg']);
$this->container->set(CampusOnlineConnector::class, $mockConnector);
Deprecated Infrastructure
# config/services.yaml
Dbp\Relay\GreenlightConnector\CampusOnlineBundle\Service\CampusOnlineConnector:
arguments:
$apiClient: '@your_custom_api_client' # Replace with a mock
LDAP Configuration
LDAP_BASE_DN matches your directory structure. Test with:
$ldapService->testConnection(); // If available
LDAP_OPTIONS in .env:
LDAP_OPTIONS={'ssl' => ['verify_peer' => false]} # Disable for testing only!
Rate Limiting
use Symfony\Component\Stopwatch\Stopwatch;
$stopwatch = new Stopwatch();
$event = $stopwatch->lap('campusonline_request');
if ($event->getDuration() < 1000) { // 1s delay
sleep(1);
}
Image Processing
CampusOnlineConnector:
class CustomCampusOnlineConnector extends CampusOnlineConnector {
public function fetchImageData(string $obfuscatedId): array {
$rawData = parent::fetchImageData($obfuscatedId);
return ['url' => $this->extractImageUrlFromRawData($rawData)];
}
}
Enable Debug Logging
Add to config/packages/monolog.yaml:
handlers:
campusonline:
type: stream
path: "%kernel.logs_dir%/campusonline.log"
level: debug
channels: ["campusonline"]
Then tag logs in services:
$this->logger->debug('Fetching data', ['obfuscated_id' => $id], ['campusonline']);
API Response Inspection Dump raw responses to debug:
$response = $this->httpClient->request('GET', $apiUrl);
file_put_contents(
'debug/campusonline_response.json',
$response->getContent()
);
Custom LDAP Attributes
Extend LdapService to map custom attributes to co-obfuscated-c-ident:
class CustomLdapService extends LdapService {
protected function getObfuscatedIdFromEntry(Entry $entry): string {
return $entry->getAttribute('custom-obfuscated-id')[0];
}
}
Alternative Image Sources
Replace CampusOnlineConnector to fetch from other sources (e.g., S3):
class S3ImageConnector implements ImageConnectorInterface {
public function fetchImageData(string $obfuscatedId): array {
return ['url' => "https://bucket.s3.eu-central-1.amazonaws.com/{$obfuscatedId}.jpg"];
}
}
Event Dispatching
Dispatch custom events after syncing (e.g., CampusOnlineSyncEvent):
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
$event = new CampusOnlineSyncEvent($obfuscatedId, $imageData);
$this->eventDispatcher->dispatch($event);
Listen in another bundle:
$dispatcher->addListener(CampusOnlineSyncEvent::class, function ($event) {
// Process image data
});
How can I help you explore Laravel packages today?