Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Relay Greenlight Connector Campusonline Bundle Laravel Package

dbp/relay-greenlight-connector-campusonline-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require dbp/relay-greenlight-connector-campusonline-bundle
    

    Ensure DbpRelayGreenlightBundle is already installed (this bundle extends it).

  2. Configure the Bundle Add to config/bundles.php:

    return [
        // ...
        Dbp\Relay\GreenlightConnector\CampusOnlineBundle\DbpRelayGreenlightConnectorCampusonlineBundle::class => ['all' => true],
    ];
    
  3. 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
    
  4. 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');
    

Implementation Patterns

Workflow: Syncing User Data with CampusOnline

  1. 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');
    
  2. CampusOnline API Calls Leverage the CampusOnlineConnector to fetch images or metadata:

    $connector = $this->container->get(CampusOnlineConnector::class);
    $imageData = $connector->fetchImageData($obfuscatedId);
    
  3. 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);
    }
    
  4. 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);
    });
    

Integration Tips

  • Dependency Injection: Prefer constructor injection for CampusOnlineConnector and LdapService.
  • Error Handling: Wrap API calls in try-catch blocks to handle CampusOnlineApiException:
    try {
        $data = $connector->fetchImageData($id);
    } catch (CampusOnlineApiException $e) {
        $this->logger->error('CampusOnline API failed', ['error' => $e->getMessage()]);
    }
    
  • Testing: Mock 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);
    

Gotchas and Tips

Pitfalls

  1. Deprecated Infrastructure

    • The bundle relies on discontinued Austrian DCC infrastructure (LDAP + CampusOnline API). Verify endpoints and credentials are still valid.
    • Workaround: Override services to mock responses if APIs are unavailable:
      # config/services.yaml
      Dbp\Relay\GreenlightConnector\CampusOnlineBundle\Service\CampusOnlineConnector:
          arguments:
              $apiClient: '@your_custom_api_client' # Replace with a mock
      
  2. LDAP Configuration

    • Base DN Mismatch: Ensure LDAP_BASE_DN matches your directory structure. Test with:
      $ldapService->testConnection(); // If available
      
    • TLS Issues: LDAP over plaintext may fail. Use LDAP_OPTIONS in .env:
      LDAP_OPTIONS={'ssl' => ['verify_peer' => false]} # Disable for testing only!
      
  3. Rate Limiting

    • CampusOnline APIs may throttle requests. Implement exponential backoff:
      use Symfony\Component\Stopwatch\Stopwatch;
      
      $stopwatch = new Stopwatch();
      $event = $stopwatch->lap('campusonline_request');
      if ($event->getDuration() < 1000) { // 1s delay
          sleep(1);
      }
      
  4. Image Processing

    • The bundle assumes CampusOnline returns image URLs directly. If not, extend CampusOnlineConnector:
      class CustomCampusOnlineConnector extends CampusOnlineConnector {
          public function fetchImageData(string $obfuscatedId): array {
              $rawData = parent::fetchImageData($obfuscatedId);
              return ['url' => $this->extractImageUrlFromRawData($rawData)];
          }
      }
      

Debugging Tips

  • 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()
    );
    

Extension Points

  1. 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];
        }
    }
    
  2. 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"];
        }
    }
    
  3. 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
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware