<?php
namespace App\Components;
use App\Service\ProductService;
use App\Service\ShoppingCartService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent('shopping_cart_toggle')]
final class ShoppingCartBadgeComponent extends AbstractController {
use DefaultActionTrait;
/** @var ProductService */
protected $productService;
/** @var ShoppingCartService */
private $shoppingCartService;
public function __construct(ProductService $productService, ShoppingCartService $shoppingCartService) {
$this->productService = $productService;
$this->shoppingCartService = $shoppingCartService;
}
public function getNumberOfItems(): int {
return $this->shoppingCartService->getNumberOfItems();
}
}