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

Cnc Bundle Laravel Package

docroms/cnc-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

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

Implementation Patterns

Core Workflows

  1. Authentication Handling: Use the bundle’s OAuth integration for secure API calls. Example:

    $this->cncService->authenticate(); // Likely auto-handled; check docs for manual triggers
    
  2. Movie Data Sync:

    • Fetching: Retrieve movies from CNC (e.g., getMovies()).
    • Pushing: Send local movies to CNC (e.g., sendMovies($movies)).
    • Batch Processing: Use chunking for large datasets:
      $this->cncService->sendMoviesInBatches($movies, 50);
      
  3. 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 }
    
  4. Configuration Switching: Toggle between recette and production modes dynamically:

    $this->cncService->setMode('production'); // If supported
    

Integration Tips

  • 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
    

Gotchas and Tips

Pitfalls

  1. Environment Variables:

    • Hardcoding credentials in config.yml is unsafe. Use .env:
      cnc:
          production_consumer_key: "%env(CNC_PROD_KEY)%"
      
    • Fix: Add .env to .gitignore and document required variables.
  2. Rate Limiting:

    • CNC may throttle requests. Implement exponential backoff:
      try {
          $this->cncService->sendMovies($movies);
      } catch (RateLimitException $e) {
          sleep($e->getRetryAfter());
          retry();
      }
      
  3. Data Mismatches:

    • CNC’s API may return unexpected fields. Validate responses:
      $movies = $this->cncService->getMovies();
      foreach ($movies as $movie) {
          assert($movie->id !== null, 'Missing movie ID');
      }
      
  4. Deprecation Risk:

    • The bundle is in dev-master. Pin the version in composer.json:
      "docroms/cnc-bundle": "dev-master#1234567890"
      

Debugging

  • API Errors: Enable verbose logging to trace failed requests:

    $this->cncService->setDebug(true);
    
  • OAuth Issues:

    • Verify tokens/secrets in recette vs. production modes.
    • Test OAuth flows manually using Postman with CNC’s endpoints.

Extension Points

  1. Custom Services: Decorate the CncService to add logic:

    class CustomCncService extends CncService
    {
        public function getMoviesWithMetadata()
        {
            $movies = parent::getMovies();
            // Add custom metadata...
            return $movies;
        }
    }
    
  2. 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; }
    }
    
  3. Testing: Mock the CncService in PHPUnit:

    $mock = $this->createMock(CncService::class);
    $mock->method('getMovies')->willReturn([new CncMovie()]);
    $this->container->set('cnc.service', $mock);
    
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.
iio/libmergepdf
redaxo/project
zatona-eg/zatona-eg-api
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
ardenexal/fhir-models
ardenexal/fhir-validation
dpfx/laravel-livewire-wizards
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
crudly/encrypted
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony