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.
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
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);
}
}
Register the Service
Bind the service in AppServiceProvider:
public function register()
{
$this->app->singleton(PumukitStatsService::class, function ($app) {
return new PumukitStatsService($app);
});
}
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'));
}
}
Basic Blade View
<!-- resources/views/stats/show.blade.php -->
<h1>Video Stats</h1>
<pre>{{ print_r($data, true) }}</pre>
API-First Approach
// 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);
}
Livewire Integration for Reactivity
composer require livewire/livewire
// 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');
}
}
Charting with Laravel Charts
composer require beyondcode/laravel-charts
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;
}
Caching for Performance
public function fetchStats($params)
{
$cacheKey = 'pumukit_stats_' . md5(serialize($params));
return Cache::remember($cacheKey, now()->addHours(1), function () use ($params) {
return $client->request(...)->getContent();
});
}
Symfony Bundle as a Black Box
PumukitStatsUIBundle\Service\StatsService).Asset Pipeline Migration
vendor/teltek/pumukit-stats-ui-bundle/Resources/public/ to public/bundle-stats/.// webpack.mix.js
mix.copy('public/bundle-stats', 'public/dist/bundle-stats');
Twig to Blade Conversion
twig/bridge or manually rewrite templates:
composer require twig/bridge
@foreach($stats['videos'] as $video)
<div class="video-stat">
<h3>{{ $video->title }}</h3>
<p>Views: {{ $video->views }}</p>
</div>
@endforeach
Event-Driven Stats Updates
// 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');
}
}
Multi-Tenancy Support
public function getTenantStats($tenantId, $params)
{
$params['tenant_id'] = $tenantId;
return $this->fetchStats($params);
}
Symfony vs. Laravel DI Conflicts
$container = new ContainerBuilder();
$container->register('stats_service', StatsService::class);
$container->compile();
$service = $container->get('stats_service');
Deprecated Symfony Components
symfony/swiftmailer, symfony/monolog).composer require symfony/mailer monolog/monolog
Asset Path Hardcoding
/bundles/pumukitstats/).config/packages/teltek_pumukit_stats_ui.yaml:
assets:
base_urls: ['%kernel.project_dir%/public/dist/bundle-stats']
Twig Security Restrictions
raw, json_encode).{{ json_encode($data) }}.PuMuKIT API Version Mismatch
vendor/pumukit/pumukit/PuMuKIT/Api/ for version-specific logic and adapt.Database Schema Assumptions
$response = $client->request('GET', '/api/stats?video_id=123&fields=views,errors');
Cache Invalidation Issues
cache:clear) mayHow can I help you explore Laravel packages today?