Installation:
composer require docroms/cnc-bundle:dev-master
Add the bundle to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
return [
// ...
DocRoms\CncBundle\CncBundle::class => ['all' => true],
];
Configuration:
Create config/packages/cnc.yaml (Symfony 4+) or add to config/config.yml:
cnc:
mode: recette # or 'production'
production_oauth_url: "http://vad.cnc.fr"
production_consumer_key: "%env(CNC_PROD_CONSUMER_KEY)%"
production_consumer_secret: "%env(CNC_PROD_CONSUMER_SECRET)%"
# ... (fill remaining keys)
recette_oauth_url: "http://int-cncvod.integra.fr"
# ... (fill recette keys)
First Use Case: Inject the CNC service in a controller to fetch or send movie data:
use DocRoms\CncBundle\Service\CncService;
class MovieController extends AbstractController
{
public function __construct(private CncService $cncService) {}
public function syncMovies()
{
$movies = $this->cncService->getMovies(); // Hypothetical method
// Process movies...
}
}
Authentication Handling: Use the bundle’s OAuth integration for secure API calls. Example:
$this->cncService->authenticate(); // Likely auto-handled; check docs for manual triggers
Movie Data Sync:
getMovies()).sendMovies($movies)).$this->cncService->sendMoviesInBatches($movies, 50);
Event-Driven Updates: Listen for CNC webhooks (if supported) to trigger real-time syncs:
# config/services.yaml
DocRoms\CncBundle\EventListener\CncWebhookListener:
tags:
- { name: kernel.event_listener, event: cnc.webhook, method: onWebhook }
Configuration Switching:
Toggle between recette and production modes dynamically:
$this->cncService->setMode('production'); // If supported
Laravel-Symfony Bridge:
Use Symfony’s HttpClient or Serializer components via the bundle’s services.
Example:
$client = $this->cncService->getHttpClient();
$response = $client->request('GET', '/api/movies');
Custom Data Mapping:
Extend the bundle’s entity classes (e.g., CncMovie) to match your schema:
class ExtendedCncMovie extends CncMovie
{
public function getCustomField()
{
return $this->custom_field ?? null;
}
}
Logging:
Enable debug logs for API calls in config/packages/monolog.yaml:
handlers:
cnc:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.cnc.log"
level: debug
Environment Variables:
config.yml is unsafe. Use .env:
cnc:
production_consumer_key: "%env(CNC_PROD_KEY)%"
.env to .gitignore and document required variables.Rate Limiting:
try {
$this->cncService->sendMovies($movies);
} catch (RateLimitException $e) {
sleep($e->getRetryAfter());
retry();
}
Data Mismatches:
$movies = $this->cncService->getMovies();
foreach ($movies as $movie) {
assert($movie->id !== null, 'Missing movie ID');
}
Deprecation Risk:
dev-master. Pin the version in composer.json:
"docroms/cnc-bundle": "dev-master#1234567890"
API Errors: Enable verbose logging to trace failed requests:
$this->cncService->setDebug(true);
OAuth Issues:
recette vs. production modes.Custom Services:
Decorate the CncService to add logic:
class CustomCncService extends CncService
{
public function getMoviesWithMetadata()
{
$movies = parent::getMovies();
// Add custom metadata...
return $movies;
}
}
Event Dispatching: Extend the bundle’s events (if any) or create your own:
// src/Event/CncMovieSyncedEvent.php
class CncMovieSyncedEvent extends Event
{
public function __construct(private array $syncedMovies) {}
public function getSyncedMovies(): array { return $this->syncedMovies; }
}
Testing:
Mock the CncService in PHPUnit:
$mock = $this->createMock(CncService::class);
$mock->method('getMovies')->willReturn([new CncMovie()]);
$this->container->set('cnc.service', $mock);
How can I help you explore Laravel packages today?