Last active
July 20, 2016 14:45
-
-
Save jeroendesloovere/b0025118bb029e6c94c2351f3f0bc0e5 to your computer and use it in GitHub Desktop.
Fork CMS ExtensionsBundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ForkCMS\Bundle\ExtensionsBundle\Installer\ModuleInstaller; | |
/** | |
* Module Installer | |
*/ | |
class ModuleInstaller | |
{ | |
/** | |
* @var ModuleFactory | |
*/ | |
protected $moduleFactory; | |
/** | |
* @var ModuleManager | |
*/ | |
protected $moduleManager; | |
/** | |
* @var ModuleRepository | |
*/ | |
protected $moduleRepository; | |
/** | |
* @var ModuleSettingFactory | |
*/ | |
protected $moduleSettingFactory; | |
/** | |
* Construct | |
* | |
* @param ModuleManager $moduleManager | |
* @param ModuleRepository $moduleRepository | |
* @param ModuleFactory $moduleFactory | |
* @param ModuleSettingFactory $moduleSettingFactory | |
*/ | |
public function __construct( | |
ModuleManager $moduleManager, | |
ModuleRepository $moduleRepository, | |
ModuleFactory $moduleFactory, | |
ModuleSettingFactory $moduleFactory | |
) { | |
$this->moduleManager = $moduleManager; | |
$this->moduleRepository = $moduleRepository; | |
$this->moduleFactory = $moduleFactory; | |
$this->moduleSettingFactory = $moduleSettingFactory; | |
} | |
public function getModule($name) | |
{ | |
$module = $this->moduleRepository->getOneByName($name); | |
// Module already exists | |
if ($module) { | |
return $module; | |
} | |
// Otherwise create new module | |
return $this->moduleFactory->create($name); | |
} | |
public function setActionRights($groupId, Module $module, $action) | |
{ | |
// todo | |
} | |
public function setSetting(Module $module, $name, $value) | |
{ | |
return $this->moduleSettingFactory->create($module, $name, $value); | |
} | |
public function executeInstall(Module $module) | |
{ | |
$this->moduleManager->install($module); | |
} | |
public function executeUninstall(Module $module) | |
{ | |
$this->moduleManager->uninstall($module); | |
} | |
} | |
namespace ForkCMS\Bundle\JobsBundle\Installer\Installer; | |
use ForkCMS\Bundle\ExtensionsBundle\Installer\ModuleInstaller; | |
/** | |
* Example of an installer for a Jobs module | |
*/ | |
class Installer extends ModuleInstaller | |
{ | |
public function install() | |
{ | |
// Define jobs module | |
$jobs = $this->getModule('Jobs'); | |
$this->setSetting($jobs, 'allow_file1', true); | |
$this->setSetting($jobs, 'allow_file2', true); | |
$this->setSetting($jobs, 'allow_file3', true); | |
$this->setSetting($jobs, 'allow_file4', true); | |
$this->setActionRights(1, $jobs, 'Add'); | |
$this->setActionRights(1, $jobs, 'Edit'); | |
$this->executeInstall($jobs); | |
} | |
public function uninstall() | |
{ | |
// Define jobs module | |
$jobs = $this->getModule('Jobs'); | |
$this->executeUninstall($jobs); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ForkCMS\Bundle\ExtensionsBundle\Entity\ModuleSetting; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\Module; | |
/** | |
* ModuleSetting Entity | |
*/ | |
class ModuleSetting | |
{ | |
/** | |
* @var integer | |
*/ | |
protected $id; | |
/** | |
* @var Module | |
*/ | |
protected $module; | |
/** | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* @var string | |
*/ | |
protected $value; | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Repository\ModuleSettingRepository; | |
/** | |
* ModuleSetting Repository | |
*/ | |
class ModuleSettingRepository | |
{ | |
public function getAll() | |
{ | |
} | |
/** | |
* Add ModuleSetting | |
* | |
* @param ModuleSetting $moduleSetting | |
*/ | |
public function add(ModuleSetting $moduleSetting) | |
{ | |
} | |
/** | |
* Delete ModuleSetting | |
* | |
* @param ModuleSetting $moduleSetting | |
*/ | |
public function delete(ModuleSetting $moduleSetting) | |
{ | |
} | |
/** | |
* Update ModuleSetting | |
* | |
* @param ModuleSetting $moduleSetting | |
*/ | |
public function update(ModuleSetting $moduleSetting) | |
{ | |
} | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Factory\ModuleSettingFactory; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\ModuleSetting; | |
/** | |
* ModuleSetting Factory | |
*/ | |
class ModuleSettingFactory | |
{ | |
/** | |
* Create | |
*/ | |
public function create($name, $value) | |
{ | |
return new ModuleSetting($name, $value); | |
} | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Manager\ModuleSettingManager; | |
/** | |
* ModuleSetting Manager | |
* Service: "fork.module.setting" | |
*/ | |
class ModuleSettingManager | |
{ | |
public function get() | |
{ | |
// Integrate everything from "fork.settings" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ForkCMS\Bundle\ExtensionsBundle\Entity\Module; | |
/** | |
* Module Entity | |
*/ | |
class Module | |
{ | |
/** | |
* @var integer | |
*/ | |
protected $id; | |
/** | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* @var \DateTime | |
*/ | |
protected $installedOn; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $settings; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $extras; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $backendNavigation; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $groupRightActions; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $groupRightModules; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $backendLocale; | |
/** | |
* @var ArrayCollection | |
*/ | |
protected $frontendLocale; | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Repository\ModuleRepository; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\Module; | |
/** | |
* Module Repository | |
*/ | |
class ModuleRepository | |
{ | |
/** | |
* Add Module | |
* | |
* @param Module $module | |
*/ | |
public function add(Module $module) | |
{ | |
} | |
/** | |
* Delete Module | |
* | |
* @param Module $module | |
*/ | |
public function delete(Module $module) | |
{ | |
} | |
/** | |
* Get one by name | |
* | |
* @param string $name | |
*/ | |
public function getOneByName($name) | |
{ | |
} | |
/** | |
* Update Module | |
* | |
* @param Module $module | |
*/ | |
public function update(Module $module) | |
{ | |
} | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Factory\ModuleFactory; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\Module; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\ModuleSetting; | |
/** | |
* Module Factory | |
*/ | |
class ModuleFactory | |
{ | |
/** | |
* Create | |
* | |
* @param string $name | |
* @return Module | |
*/ | |
public function create( | |
$name | |
) { | |
return new Module($moduleName); | |
} | |
} | |
namespace ForkCMS\Bundle\ExtensionsBundle\Manager\ModuleManager; | |
use ForkCMS\Bundle\ExtensionsBundle\Repository\ModuleRepository; | |
use ForkCMS\Bundle\ExtensionsBundle\Entity\Module; | |
use ForkCMS\Bundle\ExtensionsBundle\Event\PreInstallModuleEvent; | |
use ForkCMS\Bundle\ExtensionsBundle\Event\PostInstallModuleEvent; | |
use ForkCMS\Bundle\ExtensionsBundle\Event\PreUninstallModuleEvent; | |
use ForkCMS\Bundle\ExtensionsBundle\Event\PostUninstallModuleEvent; | |
/** | |
* Module Manager | |
* Service: "fork.manager.module" | |
*/ | |
class ModuleManager | |
{ | |
/** | |
* @var EventDispatcher | |
*/ | |
protected $eventDispatcher; | |
/** | |
* @var ModuleRepository | |
*/ | |
protected $moduleRepository; | |
/** | |
* Construct | |
* | |
* @param EventDispatcher $eventDispatcher | |
* @param ModuleRepository $moduleRepository | |
*/ | |
public function __construct( | |
EventDispatcher $eventDispatcher, | |
ModuleRepository $moduleRepository | |
) { | |
$this->eventDispatcher = $eventDispatcher; | |
$this->moduleRepository = $moduleRepository; | |
} | |
/** | |
* Install | |
* | |
* @param Module $module | |
*/ | |
public function install(Module $module) | |
{ | |
// Dispatch PreInstallModule Event | |
$this->eventDispatcher->dispatch( | |
ForkCMSExtensionsBundleEvents::PRE_INSTALL_MODULE, | |
new PreInstallModuleEvent( | |
$module | |
) | |
); | |
// Add Module to the Repository | |
$this->moduleRepository->add($module); | |
// Dispatch PostInstallModule Event | |
$this->eventDispatcher->dispatch( | |
ForkCMSExtensionsBundleEvents::POST_INSTALL_MODULE, | |
new PostInstallModuleEvent( | |
$module | |
) | |
); | |
} | |
/** | |
* Uninstall | |
* | |
* @param Module $module | |
*/ | |
public function uninstall(Module $module) | |
{ | |
// Dispatch PreUninstallModule Event | |
$this->eventDispatcher->dispatch( | |
ForkCMSExtensionsBundleEvents::PRE_UNINSTALL_MODULE, | |
new PreUninstallModuleEvent( | |
$module | |
) | |
); | |
// Delete the Module from the Repository | |
$this->moduleRepository->delete($module); | |
// Dispatch PostUninstallModule Event | |
$this->eventDispatcher->dispatch( | |
ForkCMSExtensionsBundleEvents::POST_UNINSTALL_MODULE, | |
new PostUninstallModuleEvent( | |
$module | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment