# Symfony Service Example

Service layer with Symfony

## Code Example

```php
<?php
// Symfony Service Example
namespace App\Service;

use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Product;
use App\Repository\ProductRepository;

class ProductService
{
    private EntityManagerInterface $em;
    private ProductRepository $productRepository;

    public function __construct(
        EntityManagerInterface $em,
        ProductRepository $productRepository
    ) {
        $this->em = $em;
        $this->productRepository = $productRepository;
    }

    public function createProduct(array $data): Product
    {
        $product = new Product();
        $product->setName($data['name']);
        $product->setPrice($data['price']);
        $product->setDescription($data['description'] ?? '');

        $this->em->persist($product);
        $this->em->flush();

        return $product;
    }

    public function getProductsByCategory(string $category): array
    {
        return $this->productRepository->findBy(['category' => $category]);
    }
}
```

## Files

- src/Service/ProductService.php
- src/Entity/Product.php
- src/Repository/ProductRepository.php

## Usage

```bash
# Install dependencies
npm install

# Run the example
npm start
```
