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

Pumukit Stats Ui Bundle Laravel Package

teltek/pumukit-stats-ui-bundle

Symfony bundle providing a web UI for PuMuKIT platform statistics. Adds pages and assets to visualize key metrics for your PuMuKIT installation; install via Composer and update assets/clear cache to enable in your Symfony app.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps for Laravel Integration

  1. Symfony Compatibility Layer Since this is a Symfony bundle, create a Laravel-compatible facade to interact with its services:

    composer require symfony/console symfony/dependency-injection symfony/http-client
    
  2. Basic Service Proxy Create a Laravel service to wrap the bundle’s functionality:

    // app/Services/PumukitStatsService.php
    namespace App\Services;
    
    use Symfony\Component\HttpClient\HttpClient;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class PumukitStatsService
    {
        protected $container;
    
        public function __construct(ContainerInterface $container)
        {
            $this->container = $container;
        }
    
        public function getVideoStats($videoId)
        {
            // Simulate bundle call via Symfony's HttpClient
            $client = HttpClient::create();
            $response = $client->request('GET', config('pumukit.api_url') . "/stats/{$videoId}");
            return json_decode($response->getContent(), true);
        }
    }
    
  3. Register the Service Bind the service in AppServiceProvider:

    public function register()
    {
        $this->app->singleton(PumukitStatsService::class, function ($app) {
            return new PumukitStatsService($app);
        });
    }
    
  4. First Controller Usage

    // routes/web.php
    use App\Http\Controllers\StatsController;
    
    Route::get('/stats/{videoId}', [StatsController::class, 'show']);
    
    // app/Http/Controllers/StatsController.php
    namespace App\Http\Controllers;
    
    use App\Services\PumukitStatsService;
    
    class StatsController extends Controller
    {
        public function show($videoId, PumukitStatsService $statsService)
        {
            $data = $statsService->getVideoStats($videoId);
            return view('stats.show', compact('data'));
        }
    }
    
  5. Basic Blade View

    <!-- resources/views/stats/show.blade.php -->
    <h1>Video Stats</h1>
    <pre>{{ print_r($data, true) }}</pre>
    

Implementation Patterns

Workflow: Data-Driven Stats Dashboard

  1. API-First Approach

    • Use PuMuKIT’s native API (if available) instead of the bundle’s Symfony-specific logic.
    • Example:
      // app/Services/PumukitApiService.php
      public function fetchStats($params)
      {
          $client = HttpClient::create();
          $response = $client->request('GET', config('pumukit.api_url') . '/api/stats', [
              'query' => $params,
              'headers' => ['Authorization' => 'Bearer ' . config('pumukit.api_token')]
          ]);
          return json_decode($response->getContent(), true);
      }
      
  2. Livewire Integration for Reactivity

    • Replace the bundle’s static UI with a Livewire component:
      composer require livewire/livewire
      
    • Example:
      // app/Http/Livewire/VideoStats.php
      namespace App\Http\Livewire;
      
      use Livewire\Component;
      use App\Services\PumukitApiService;
      
      class VideoStats extends Component
      {
          public $videoId;
          public $stats;
      
          protected $listeners = ['refreshStats' => 'loadStats'];
      
          public function mount($videoId)
          {
              $this->videoId = $videoId;
              $this->loadStats();
          }
      
          public function loadStats()
          {
              $this->stats = app(PumukitApiService::class)->fetchStats(['video_id' => $this->videoId]);
          }
      
          public function render()
          {
              return view('livewire.video-stats');
          }
      }
      
  3. Charting with Laravel Charts

    • Integrate Laravel Charts for visualization:
      composer require beyondcode/laravel-charts
      
    • Example:
      use BeyondCode\Charts\Chart;
      
      public function getChart()
      {
          $chart = Chart::create()
              ->title('Video Views Over Time')
              ->dataset('Views', $this->stats['views_by_date'])
              ->type('line');
      
          return $chart;
      }
      
  4. Caching for Performance

    • Cache API responses to reduce load:
      public function fetchStats($params)
      {
          $cacheKey = 'pumukit_stats_' . md5(serialize($params));
          return Cache::remember($cacheKey, now()->addHours(1), function () use ($params) {
              return $client->request(...)->getContent();
          });
      }
      

Integration Tips

  1. Symfony Bundle as a Black Box

    • Treat the bundle as a legacy dependency and interact only via its public API (if documented).
    • Avoid extending Symfony-specific classes (e.g., PumukitStatsUIBundle\Service\StatsService).
  2. Asset Pipeline Migration

    • Copy the bundle’s CSS/JS from vendor/teltek/pumukit-stats-ui-bundle/Resources/public/ to public/bundle-stats/.
    • Rebuild assets with Laravel Mix:
      // webpack.mix.js
      mix.copy('public/bundle-stats', 'public/dist/bundle-stats');
      
  3. Twig to Blade Conversion

    • Use a templating bridge like twig/bridge or manually rewrite templates:
      composer require twig/bridge
      
    • Example Blade template for a Twig-like structure:
      @foreach($stats['videos'] as $video)
          <div class="video-stat">
              <h3>{{ $video->title }}</h3>
              <p>Views: {{ $video->views }}</p>
          </div>
      @endforeach
      
  4. Event-Driven Stats Updates

    • Use Laravel’s queues to process stats asynchronously:
      // app/Console/Commands/FetchPumukitStats.php
      namespace App\Console\Commands;
      
      use Illuminate\Console\Command;
      use App\Jobs\ProcessPumukitStats;
      
      class FetchPumukitStats extends Command
      {
          public function handle()
          {
              ProcessPumukitStats::dispatch()->onQueue('stats');
          }
      }
      
  5. Multi-Tenancy Support

    • Extend the service to support tenant-aware stats:
      public function getTenantStats($tenantId, $params)
      {
          $params['tenant_id'] = $tenantId;
          return $this->fetchStats($params);
      }
      

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel DI Conflicts

    • Gotcha: The bundle’s services assume Symfony’s container. Directly instantiating them will fail.
    • Fix: Use manual instantiation or a Symfony container wrapper:
      $container = new ContainerBuilder();
      $container->register('stats_service', StatsService::class);
      $container->compile();
      $service = $container->get('stats_service');
      
  2. Deprecated Symfony Components

    • Gotcha: The bundle may use old Symfony components (e.g., symfony/swiftmailer, symfony/monolog).
    • Fix: Replace with Laravel equivalents or update dependencies:
      composer require symfony/mailer monolog/monolog
      
  3. Asset Path Hardcoding

    • Gotcha: The bundle hardcodes asset paths (e.g., /bundles/pumukitstats/).
    • Fix: Override paths in config/packages/teltek_pumukit_stats_ui.yaml:
      assets:
          base_urls: ['%kernel.project_dir%/public/dist/bundle-stats']
      
  4. Twig Security Restrictions

    • Gotcha: Twig templates may use unsafe filters (e.g., raw, json_encode).
    • Fix: Sanitize data before passing to Blade or use {{ json_encode($data) }}.
  5. PuMuKIT API Version Mismatch

    • Gotcha: The bundle expects PuMuKIT v5.0+ but your instance uses a newer version with breaking changes.
    • Fix: Check vendor/pumukit/pumukit/PuMuKIT/Api/ for version-specific logic and adapt.
  6. Database Schema Assumptions

    • Gotcha: The bundle assumes PuMuKIT’s default schema. Custom schemas will break queries.
    • Fix: Use raw API calls instead of ORM queries:
      $response = $client->request('GET', '/api/stats?video_id=123&fields=views,errors');
      
  7. Cache Invalidation Issues

    • Gotcha: Symfony’s cache system (cache:clear) may
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity