![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/SmsBundle/Sms/ |
<?php namespace Mautic\SmsBundle\Sms; use Mautic\LeadBundle\Entity\Lead; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\SmsBundle\Entity\Stat; use Mautic\SmsBundle\Exception\PrimaryTransportNotEnabledException; class TransportChain { /** * @var TransportInterface[] */ private array $transports; /** * @param string $primaryTransport */ public function __construct( private $primaryTransport, private IntegrationHelper $integrationHelper ) { $this->transports = []; } /** * @param string $alias * @param string $translatableAlias * @param string $integrationAlias * * @return $this */ public function addTransport($alias, TransportInterface $transport, $translatableAlias, $integrationAlias) { $this->transports[$alias]['alias'] = $translatableAlias; $this->transports[$alias]['integrationAlias'] = $integrationAlias; $this->transports[$alias]['service'] = $transport; return $this; } /** * Return the transport defined in parameters. * * @return TransportInterface * * @throws PrimaryTransportNotEnabledException */ public function getPrimaryTransport() { $enabled = $this->getEnabledTransports(); // If there no primary transport selected and there is just one available we will use it as primary if (1 === count($enabled)) { return array_shift($enabled); } if (0 === count($enabled)) { throw new PrimaryTransportNotEnabledException('Primary SMS transport is not enabled'); } if (!array_key_exists($this->primaryTransport, $enabled)) { throw new PrimaryTransportNotEnabledException('Primary SMS transport is not enabled. '.$this->primaryTransport); } return $enabled[$this->primaryTransport]; } /** * @param string $content * * @return mixed * * @throws \Exception */ public function sendSms(Lead $lead, $content, Stat $stat = null) { return $this->getPrimaryTransport()->sendSms($lead, $content, $stat); } /** * Get all transports registered in service container. * * @return TransportInterface[] */ public function getTransports() { return $this->transports; } /** * @param string $transport * * @return TransportInterface * * @throws PrimaryTransportNotEnabledException */ public function getTransport($transport) { $enabled = $this->getEnabledTransports(); if (!array_key_exists($transport, $enabled)) { throw new PrimaryTransportNotEnabledException($transport.' SMS transport is not enabled or does not exist'); } return $enabled[$transport]; } /** * Get published transports. * * @return TransportInterface[] */ public function getEnabledTransports(): array { $enabled = []; foreach ($this->transports as $alias => $transport) { if (!isset($transport['published'])) { $integration = $this->integrationHelper->getIntegrationObject($transport['integrationAlias']); if (!$integration) { continue; } $transport['published'] = $integration->getIntegrationSettings()->getIsPublished(); $this->transports[$alias] = $transport; } if ($transport['published']) { $enabled[$alias] = $transport['service']; } } return $enabled; } }