mercredi 11 mai 2016

Does every class in symfony2 need to be a service?

Intro moved to the bottom:

Right now I'm working on a small system, that manages orders and products. I'm trying to refactor chunks of code from the controller and into business and service classes, here's what I'm trying to pull

/src/domain/bundle/Business/
/src/domain/bundle/Services/

So in the Business, I will have an Order Class, that does some calculations, some of these calculations required data from the database (on the fly).

Here's exactly the problem I have:

  1. The controller loads an array of Orders that needs processing
  2. The controller sends orders that needs processing to the "OrderBusiness" class
  3. The "OrderBusiness" class needs to get the product(s) price from the database

Now I'm stuck.. What I'm attempting to do, is I made a ProductsService class, that returns the required product and price from the database, but how can I call this class from my "OrderBusiness" class without defining my "OrderBusiness" class as a service and injecting it with the ProductsService class

Intro:

I'm quiet sorry if my questions seems to be a little general and ignorant. I've been using Symfony2 for less than a year now, and some things I can't wrap my mind around, even after reading the documentations, and a lot of the questions.

Aucun commentaire:

Enregistrer un commentaire