Ejemplo n.º 1
0
 /**
  * @return array
  */
 protected function getAddonBundles()
 {
     return $this->factory->getEnabledAddons();
 }
Ejemplo n.º 2
0
 /**
  * Get a list of integration helper classes
  *
  * @param array|string $services
  * @param array        $withFeatures
  * @param bool         $alphabetical
  * @param null|int     $addonFilter
  *
  * @return mixed
  */
 public function getIntegrationObjects($services = null, $withFeatures = null, $alphabetical = false, $addonFilter = null)
 {
     static $integrations, $available;
     if (empty($integrations)) {
         $em = $this->factory->getEntityManager();
         $available = $integrations = array();
         // And we'll be scanning the addon bundles for additional classes, so have that data on standby
         $addons = $this->factory->getEnabledAddons();
         // Quickly figure out which addons are enabled so we only process those
         /** @var \Mautic\AddonBundle\Entity\AddonRepository $addonRepo */
         $addonRepo = $em->getRepository('MauticAddonBundle:Addon');
         $addonStatuses = $addonRepo->getBundleStatus(true);
         // Scan the addons for integration classes
         foreach ($addons as $addon) {
             if (is_dir($addon['directory'] . '/Integration')) {
                 $finder = new Finder();
                 $finder->files()->name('*Integration.php')->in($addon['directory'] . '/Integration')->ignoreDotFiles(true);
                 if ($alphabetical) {
                     $finder->sortByName();
                 }
                 $id = $addonStatuses[$addon['bundle']]['id'];
                 foreach ($finder as $file) {
                     $available[] = array('addon' => $em->getReference('MauticAddonBundle:Addon', $id), 'integration' => substr($file->getBaseName(), 0, -15), 'namespace' => str_replace('MauticAddon', '', $addon['bundle']));
                 }
             }
         }
         $integrationSettings = $this->getIntegrationSettings();
         // Get all the addon integrations
         foreach ($available as $id => $a) {
             if ($addonFilter && $a['addon']->getId() != $addonFilter) {
                 continue;
             }
             if (!isset($integrations[$a['integration']])) {
                 $class = "\\MauticAddon\\" . $a['namespace'] . "\\Integration\\" . $a['integration'] . "Integration";
                 $reflectionClass = new \ReflectionClass($class);
                 if ($reflectionClass->isInstantiable()) {
                     $integrations[$a['integration']] = new $class($this->factory);
                     if (!isset($integrationSettings[$a['integration']])) {
                         $integrationSettings[$a['integration']] = new Integration();
                         $integrationSettings[$a['integration']]->setName($a['integration']);
                     }
                     $integrationSettings[$a['integration']]->setAddon($a['addon']);
                     $integrations[$a['integration']]->setIntegrationSettings($integrationSettings[$a['integration']]);
                 }
             }
         }
         if (empty($alphabetical)) {
             // Sort by priority
             uasort($integrations, function ($a, $b) {
                 $aP = (int) $a->getPriority();
                 $bP = (int) $b->getPriority();
                 if ($aP === $bP) {
                     return 0;
                 }
                 return $aP < $bP ? -1 : 1;
             });
         }
     }
     if (!empty($services)) {
         if (!is_array($services) && isset($integrations[$services])) {
             return array($services => $integrations[$services]);
         } elseif (is_array($services)) {
             $specific = array();
             foreach ($services as $s) {
                 if (isset($integrations[$s])) {
                     $specific[$s] = $integrations[$s];
                 }
             }
             return $specific;
         } else {
             throw new MethodNotAllowedHttpException(array_keys($available));
         }
     } elseif (!empty($withFeatures)) {
         if (!is_array($withFeatures)) {
             $withFeatures = array($withFeatures);
         }
         $specific = array();
         foreach ($integrations as $n => $d) {
             $settings = $d->getIntegrationSettings();
             $features = $settings->getSupportedFeatures();
             foreach ($withFeatures as $f) {
                 if (in_array($f, $features)) {
                     $specific[$n] = $d;
                     break;
                 }
             }
         }
         return $specific;
     }
     return $integrations;
 }