|
4 | 4 | namespace CommonGateway\CoreBundle\Subscriber; |
5 | 5 |
|
6 | 6 | use App\Entity\ObjectEntity; |
| 7 | +use App\Exception\GatewayException; |
| 8 | +use App\Service\ApplicationService; |
7 | 9 | use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface; |
8 | 10 | use Doctrine\ORM\Events; |
9 | 11 | use Doctrine\Persistence\Event\LifecycleEventArgs; |
@@ -40,7 +42,8 @@ class ObjectUriSubscriber implements EventSubscriberInterface |
40 | 42 | */ |
41 | 43 | public function __construct( |
42 | 44 | ParameterBagInterface $parameterBag, |
43 | | - SessionInterface $session |
| 45 | + SessionInterface $session, |
| 46 | + private ApplicationService $applicationService |
44 | 47 | ) { |
45 | 48 | $this->parameterBag = $parameterBag; |
46 | 49 | $this->session = $session; |
@@ -80,8 +83,19 @@ public function postPersist(LifecycleEventArgs $args): void |
80 | 83 | $object = $args->getObject(); |
81 | 84 | // if this subscriber only applies to certain entity types, |
82 | 85 | if ($object instanceof ObjectEntity) { |
83 | | - if ($object->getUri() === null || str_contains($object->getUri(), $object->getSelf()) === false) { |
84 | | - $object->setUri(rtrim($this->parameterBag->get('app_url'), '/').$object->getSelf()); |
| 86 | + try { |
| 87 | + $application = $this->applicationService->getApplication(); |
| 88 | + if ($object->getUri() === null |
| 89 | + || str_contains($object->getUri(), $object->getSelf()) === false |
| 90 | + ) { |
| 91 | + $object->setUri('https://'.$application->getDomains()[0].$object->getSelf()); |
| 92 | + } |
| 93 | + } catch (GatewayException $exception) { |
| 94 | + if ($object->getUri() === null |
| 95 | + || str_contains($object->getUri(), $object->getSelf()) === false |
| 96 | + ) { |
| 97 | + $object->setUri(rtrim($this->parameterBag->get('app_url'), '/').$object->getSelf()); |
| 98 | + } |
85 | 99 | } |
86 | 100 |
|
87 | 101 | return; |
|
0 commit comments