As far as I understand, a valid template:
- FooControllerFactory, which creates the necessary services (FooService)
- FooController with __construct constructor (FooService $ fooService)
- The controller receives some basic data and receives the result from the service.
- The service contains all the necessary business logic. This is a basic service. This service may require other services for various activities. For example, CacheService, SomeOtherDataService.
The question is, what is the right / appropriate template for including / injecting these other related services?
The reallife example we currently have is extremely simplified:
AuctionController
public function getVehiclesAction ()
{
$auctionService = $this->getAuctionService();
$auctionID = (int) $this->params('auction-id');
$auction = $auctionService->getAuctionVehicle($auctionID);
return $auction->getVehicles();
}
AuctionService
public function getAuctionVehicles($auctionID) {
$auction = $this->getAuction($auctionID);
if ($auction) {
$vehicleService = $this->getVehicleService();
$vehicleService->getVehicles($params);
}
return false;
}
VehicleService
public function getVehicles($params) {
$cache = $this->getCache();
$vehicles = $cache->getItem($params);
if (!$vehicles) {
$vehicleDB = $this->getVehicleDB();
$vehicles = $vehicleDB->getVehicles($params);
}
return $vehicles;
}
An example of the proposed template
AuctionController
public function __construct(AuctionService $auctionService) {
$this->auctionService = $auctionService;
}
public function getVehiclesAction ()
{
$auctionID = (int) $this->params('auction-id');
$auction = $this->auctionService->getAuctionVehicle($auctionID);
return $auction->getVehicles();
}
**AuctionService**
public function getAuctionVehicles($auctionID) {
$auction = $this->getAuction($auctionID);
if ($auction) {
$vehicleService = $this->getVehicleService();
$vehicleService->getVehicles($params);
}
return false;
}
VehicleService
public function getVehicles($params) {
$cache = $this->getCache();
$vehicles = $cache->getItem($params);
if (!$vehicles) {
$vehicleDB = $this->getVehicleDB();
$vehicles = $vehicleDB->getVehicles($params);
}
return $vehicles;
}
Some notes:
- , 95%
- , Vehicle
- VehicleController VehicleService, , , .
- , ( , ).
- - , , , .