Skip to content

Commit

Permalink
Merge pull request mautic#740 from alanhartless/addon-to-plugin-conve…
Browse files Browse the repository at this point in the history
…rsion

Addon to plugin conversion
  • Loading branch information
David Hurley committed Aug 11, 2015
2 parents 361306c + fefda1c commit 368d336
Show file tree
Hide file tree
Showing 157 changed files with 1,991 additions and 1,752 deletions.
2 changes: 1 addition & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^(?!/(index\.php|index_dev\.php|app|addons|media|upgrade))(/(.*))$ /index.php$2
RedirectMatch 302 ^(?!/(index\.php|index_dev\.php|app|addons|plugins|media|upgrade))(/(.*))$ /index.php$2
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
115 changes: 44 additions & 71 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AppKernel extends Kernel
/**
* @var array
*/
private $addonBundles = array();
private $pluginBundles = array();

/**
* {@inheritdoc}
Expand Down Expand Up @@ -146,17 +146,38 @@ public function registerBundles()
$class = '\\Mautic' . '\\' . $dirname . '\\' . $filename;
if (class_exists($class)) {
$bundleInstance = new $class();
if (method_exists($bundleInstance, 'isEnabled')) {
if ($bundleInstance->isEnabled()) {
$bundles[] = $bundleInstance;
}
} else {
$bundles[] = $bundleInstance;
$bundles[] = $bundleInstance;

unset($bundleInstance);
}
}

//dynamically register Mautic Plugin Bundles
$searchPath = dirname(__DIR__) . '/plugins';
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()
->followLinks()
->depth('1')
->in($searchPath)
->name('*Bundle.php');

foreach ($finder as $file) {
$dirname = basename($file->getRelativePath());
$filename = substr($file->getFilename(), 0, -4);

$class = '\\MauticPlugin' . '\\' . $dirname . '\\' . $filename;
if (class_exists($class)) {
$plugin = new $class();

if ($plugin instanceof \Symfony\Component\HttpKernel\Bundle\Bundle) {
$bundles[] = $plugin;
}

unset($plugin);
}
}

//dynamically register Mautic Addon Bundles
// @deprecated 1.1.4; bc support for MauticAddon namespace; to be removed in 2.0
$searchPath = dirname(__DIR__) . '/addons';
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()
Expand All @@ -168,9 +189,16 @@ public function registerBundles()
foreach ($finder as $file) {
$dirname = basename($file->getRelativePath());
$filename = substr($file->getFilename(), 0, -4);
$class = '\\MauticAddon' . '\\' . $dirname . '\\' . $filename;

$class = '\\MauticAddon' . '\\' . $dirname . '\\' . $filename;
if (class_exists($class)) {
$bundles[] = new $class();
$addon = new $class();

if ($addon instanceof \Symfony\Component\HttpKernel\Bundle\Bundle) {
$bundles[] = $addon;
}

unset($addon);
}
}

Expand Down Expand Up @@ -227,69 +255,14 @@ public function boot()
define('MAUTIC_TABLE_PREFIX', $prefix);
}

$registeredAddonBundles = $this->container->getParameter('mautic.addon.bundles');
$registeredPluginBundles = $this->container->getParameter('mautic.plugin.bundles');

$addonBundles = array();
foreach ($this->getBundles() as $name => $bundle) {
if ($bundle instanceof \Mautic\AddonBundle\Bundle\AddonBundleBase) {
//boot after it's been check to see if it's enabled
$addonBundles[$name] = $bundle;

//set the container for the addon helper
$bundle->setContainer($this->container);
} else {
$bundle->setContainer($this->container);
$bundle->boot();
}
}

/** @var \Mautic\CoreBundle\Factory\MauticFactory $factory */
$factory = $this->container->get('mautic.factory');

$dispatcher = $factory->getDispatcher();

// It's only after we've booted that we have access to the container, so here is where we will check if addon bundles are enabled then deal with them accordingly
foreach ($addonBundles as $name => $bundle) {
if (!$bundle->isEnabled()) {
unset($this->bundles[$name]);
unset($this->bundleMap[$name]);

// remove listeners as well
if (isset($registeredAddonBundles[$name]['config']['services'])) {
foreach ($registeredAddonBundles[$name]['config']['services'] as $serviceGroup => $services) {
foreach ($services as $serviceName => $details) {
if ($serviceGroup == 'events') {
$details['tag'] = 'kernel.event_subscriber';
}

if (isset($details['tag'])) {
if ($details['tag'] == 'kernel.event_subscriber') {
$service = $this->container->get($serviceName);
$dispatcher->removeSubscriber($service);
} elseif ($details['tag'] == 'kernel.event_listener') {
$service = $this->container->get($serviceName);
$dispatcher->removeListener($details['tagArguments']['event'], $service);
}
} elseif (isset($details['tags'])) {
foreach ($details['tags'] as $k => $tag) {
if ($tag == 'kernel.event_listener') {
$service = $this->container->get($serviceName);
$dispatcher->removeListener($details['tagArguments'][$k]['event'], $service);
}
}
}
}
}
}

unset($registeredAddonBundles[$name]);
} else {
// boot the bundle
$bundle->boot();
}
$bundle->setContainer($this->container);
$bundle->boot();
}

$this->addonBundles = $registeredAddonBundles;
$this->pluginBundles = $registeredPluginBundles;

$this->booted = true;
}
Expand All @@ -299,9 +272,9 @@ public function boot()
*
* @return array
*/
public function getAddonBundles()
public function getPluginBundles()
{
return $this->addonBundles;
return $this->pluginBundles;
}

/**
Expand Down
67 changes: 0 additions & 67 deletions app/bundles/AddonBundle/Bundle/AddonBundleBase.php

This file was deleted.

105 changes: 0 additions & 105 deletions app/bundles/AddonBundle/Config/config.php

This file was deleted.

Loading

0 comments on commit 368d336

Please sign in to comment.