Service
The services used
1. App\Service\AuthHelperService
2. App\Service\ProductService
These classes likely live in your src/Service/ directory. They are:
- Plain PHP classes containing business logic
- Registered automatically if autowire: true and autoconfigure: true are enabled (default in Symfony)
For example, ProductService may have:
<?php
namespace App\Service;
use App\Utils\CoreDataService;
use App\Utils\DBManager;
class ProductService extends CoreDataService
{
public function __construct(private DBManager $dbmanager)
{
parent::__construct($dbmanager);
}
/**
* Get all my procust list
*/
public function getProductList()
{
$get_all_products_sql = "SELECT id,name,price,color FROM products";
$product_list = $this->executeSQL($get_all_products_sql);
return $product_list;
}
}
Now let's understand this service by breaking down each piece.
Namespace
namespace App\Service;
- This places the service in Symfony’s src/Service/ folder — part of the autowired service architecture.
Extends CoreDataService
class ProductService extends CoreDataService
- CoreDataService is likely a custom abstract or base class that provides reusable data access methods, such as executeSQL().
Constructor
public function __construct(private DBManager $dbmanager)
{
parent::__construct($dbmanager);
}
- Uses PHP 8+ constructor property promotion: private DBManager $dbmanager creates and assigns the class property.
- Injects DBManager — likely a service that abstracts database access (e.g. using PDO, Doctrine DBAL, or raw queries).
- Calls the parent constructor to ensure CoreDataService has access to the DBManager.
getProductList() Method
$get_all_products_sql = "SELECT id,name,price,color FROM products";
$product_list = $this->executeSQL($get_all_products_sql);
- Runs a raw SQL query to fetch product details from the products table.
- Uses executeSQL() — presumably defined in CoreDataService — to run the query via DBManager.
Symfony Integration(Dependancy injection) configuration
As long as you have autowiring enabled in services.yaml (which is default): This services.yaml file is available inside config directory at root level.
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
As we can see from above configuration that src directory always accepts the PHP classes only. Also what ever classes declared insdie src directory are autowired and autoconfigured. What is autowire means let's understand. Autowiring means Symfony automatically injects (i.e., "wires") dependencies into your services by looking at the type hints in constructors or methods.