Answer the question
In order to leave comments, you need to log in
How to separate business logic?
3 questions
Answer the question
In order to leave comments, you need to log in
1. Create a Services folder
2. Separate business logic parts into services
3. Write services and connect via Service Provider to Service Container
4. Write facades (optional)
5. ...
6. PROFIT
1. I would implement work with PayPal as a framework independent library (at least a minimum of dependencies) to start with in src/paypal after implementation I would connect via composer
2. The service level is not work with PayPal specifically, but work with the payment system, that is, Paypal would walked like a driver
use App\Services;
class Payment {
protected $payment;
public function __construct(\App\Contracts\PaymentDriverInterface $payment) {
$this->payment = $payment;
}
public function createPaymentUrl() {
return $this->payment->getUrl();
}
}
namespace PayPal;
class PayPalDriver implements \App\Contracts\PaymentDriverInterface {
public function getUrl() {
//реализация
}
}
Neither Yii nor Laravel follow DDD. Don't bother. Do it either within the framework, or if you know DDD, then within it. Only you will be driven "with a shovel on the back."
Now Peter's publishing house has published a yellow book with a bee. She is good. This is not an advertisement. Enough to stick with it.
I think you're overthinking. First, is it true that what you have in the models is business logic? If yes, then we create the Services folder and in it you can have some classes for processing something, let's say a class for unlinking or linking an account to a social network
class UserSocialServices
{
public function createOrGetUser() {}
public function associate() {}
}
// или можно
class PayPall {
public function createPaymentUrl() {}
}
1) business logic for 10,000 lines - I would be worried. scroll for a long time. and 1000 ....
here one customer told me that I have "large files" - I told him - "are we making changes to the TK and doing a reassessment?" he seemed to calm down.
2) paypal has never business logic
3) ask Taylor a question. he answers.
1. In general, a question from the category of "Criticizing offer." Who says what he says is already the third. If you yourself feel that the model can be thinned out, something thrown into the API class for this model, then do it.
2. There is no business logic in the PayPal integration, this is nonsense. But query methods can be stored in one class, and configurations in another, data usage in the third.
3. Why is there no folder? Because. This does not mean that you need to blindly follow any paradigm, it's just someone who came up with it.
You must feel for yourself where everything should lie and how. My middle class takes up to 500 lines.
Implement something like a command bus and add specific commands and handlers
Correctly fpinger writes. DDD is designed to address these issues. But you have to read books carefully.
I did it.
True, I thought that I would manage in a couple of months, but it took a couple of years: nextframework.ru
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question