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

48 行
1.1KB

  1. <?php
  2. namespace Lc\SovBundle\Solver\Setting;
  3. use Lc\SovBundle\Doctrine\EntityInterface;
  4. use Lc\SovBundle\Model\Setting\SettingInterface;
  5. use Lc\SovBundle\Model\Setting\SettingModel;
  6. class SettingSolver
  7. {
  8. public function getSetting(EntityInterface $entity, string $name): ?SettingModel
  9. {
  10. if ($entity->getSettings()) {
  11. foreach ($entity->getSettings() as $setting) {
  12. if ($setting->getName() == $name) {
  13. return $setting;
  14. }
  15. }
  16. }
  17. return null;
  18. }
  19. public function getSettingValue(EntityInterface $entity, string $name): ?string
  20. {
  21. $setting = $this->getSetting($entity, $name);
  22. if($setting) {
  23. return $this->getValue($setting);
  24. }
  25. return null;
  26. }
  27. public function getValue(SettingInterface $setting): ?string
  28. {
  29. if ($setting->getText()) {
  30. return $setting->getText();
  31. } elseif ($setting->getDate()) {
  32. return $setting->getDate();
  33. } elseif ($setting->getFile()) {
  34. return $setting->getFile();
  35. }
  36. return null;
  37. }
  38. }