您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FeatureProducerBuilder.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace domain\Feature\FeatureProducer;
  3. use domain\Feature\Feature\Feature;
  4. use domain\_\AbstractBuilder;
  5. class FeatureProducerBuilder extends AbstractBuilder
  6. {
  7. protected FeatureProducerRepository $featureProducerRepository;
  8. public function loadDependencies(): void
  9. {
  10. $this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class);
  11. }
  12. public function instanciateFeatureProducer(
  13. Feature $feature,
  14. bool $status = null
  15. ): FeatureProducer
  16. {
  17. $featureProducer = new FeatureProducer();
  18. $featureProducer->populateFeature($feature);
  19. $featureProducer->populateProducer($this->getProducerContext());
  20. $featureProducer->status = $status;
  21. return $featureProducer;
  22. }
  23. public function createFeatureProducer(
  24. Feature $feature,
  25. bool $status = null
  26. ): FeatureProducer
  27. {
  28. $featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature);
  29. if(!$featureProducer) {
  30. $featureProducer = $this->instanciateFeatureProducer($feature, $status);
  31. $this->create($featureProducer);
  32. }
  33. return $featureProducer;
  34. }
  35. public function updateStatus(FeatureProducer $featureProducer, bool $status = null)
  36. {
  37. $featureProducer->status = $status;
  38. $this->update($featureProducer);
  39. }
  40. public function updateStatusByFeature(Feature $feature, bool $status = null)
  41. {
  42. $featureProducer = $this->createFeatureProducer($feature, $status);
  43. $this->updateStatus($featureProducer, $status);
  44. }
  45. }