Deployee /
plugin-shopware
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Deployee\Plugins\ShopwareTasks; |
||
| 4 | |||
| 5 | use Deployee\Components\Config\ConfigInterface; |
||
| 6 | use Deployee\Components\Container\ContainerInterface; |
||
| 7 | use Deployee\Components\Dependency\ContainerResolver; |
||
| 8 | use Deployee\Components\Environment\EnvironmentInterface; |
||
| 9 | use Deployee\Components\Persistence\LazyPDO; |
||
| 10 | use Deployee\Components\Plugins\PluginInterface; |
||
| 11 | use Deployee\Plugins\Deploy\Dispatcher\DispatcherCollection; |
||
| 12 | use Deployee\Plugins\Deploy\Helper\TaskCreationHelper; |
||
| 13 | use Deployee\Plugins\ShellTasks\Helper\ExecutableFinder; |
||
| 14 | use Deployee\Plugins\ShopwareTasks\Definitions\CacheClearDefinition; |
||
| 15 | use Deployee\Plugins\ShopwareTasks\Definitions\CreateAdminUserDefinition; |
||
| 16 | use Deployee\Plugins\ShopwareTasks\Definitions\GenerateThemeCacheDefinition; |
||
| 17 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginActivateDefinition; |
||
| 18 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginConfigSetDefinition; |
||
| 19 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginDeactivateDefinition; |
||
| 20 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginInstallDefinition; |
||
| 21 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginRefreshDefinition; |
||
| 22 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginUninstallDefinition; |
||
| 23 | use Deployee\Plugins\ShopwareTasks\Definitions\PluginUpdateDefinition; |
||
| 24 | use Deployee\Plugins\ShopwareTasks\Definitions\ShopwareCommandDefinition; |
||
| 25 | use Deployee\Plugins\ShopwareTasks\Dispatcher\CacheClearDispatcher; |
||
| 26 | use Deployee\Plugins\ShopwareTasks\Dispatcher\CreateAdminUserDispatcher; |
||
| 27 | use Deployee\Plugins\ShopwareTasks\Dispatcher\GenerateThemeCacheDispatcher; |
||
| 28 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginActivateDispatcher; |
||
| 29 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginConfigSetDispatcher; |
||
| 30 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginDeactivateDispatcher; |
||
| 31 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginInstallDispatcher; |
||
| 32 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginRefreshDispatcher; |
||
| 33 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginUninstallDispatcher; |
||
| 34 | use Deployee\Plugins\ShopwareTasks\Dispatcher\PluginUpdateDispatcher; |
||
| 35 | use Deployee\Plugins\ShopwareTasks\Dispatcher\ShopwareCommandDispatcher; |
||
| 36 | use Deployee\Plugins\ShopwareTasks\Shop\ShopConfig; |
||
| 37 | |||
| 38 | class ShopwareTasksPlugin implements PluginInterface |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * @param ContainerInterface $container |
||
| 42 | */ |
||
| 43 | public function boot(ContainerInterface $container) |
||
| 44 | { |
||
| 45 | /* @var EnvironmentInterface $env */ |
||
| 46 | $env = $container->get(EnvironmentInterface::class); |
||
| 47 | /* @var ConfigInterface $config */ |
||
| 48 | $config = $container->get(ConfigInterface::class); |
||
| 49 | $path = $config->get('shopware.path', ''); |
||
| 50 | $path = strpos($path, '/') !== 0 && strpos($path, ':') !== 1 |
||
| 51 | ? $env->getWorkDir() . DIRECTORY_SEPARATOR . $path |
||
| 52 | : $path; |
||
| 53 | $container->set('shopware.path', $path); |
||
| 54 | |||
| 55 | $container->set(ShopConfig::class, function (ContainerInterface $container) { |
||
| 56 | $envFile = getenv('APP_ENV') |
||
| 57 | ? ShopConfig::BASE_ENV_FILE . '.' . getenv('APP_ENV') |
||
| 58 | : ShopConfig::BASE_ENV_FILE; |
||
| 59 | |||
| 60 | return new ShopConfig( |
||
| 61 | $container->get('shopware.path') . DIRECTORY_SEPARATOR . $envFile |
||
| 62 | ); |
||
| 63 | }); |
||
| 64 | |||
| 65 | $container->extend(LazyPDO::class, function (LazyPDO $lazyPDO) use ($container) { |
||
| 66 | /* @var ConfigInterface $config */ |
||
| 67 | $config = $container->get(ConfigInterface::class); |
||
| 68 | |||
| 69 | /* @var ShopConfig $shopConfig */ |
||
| 70 | $shopConfig = $container->get(ShopConfig::class); |
||
| 71 | |||
| 72 | $config->set('db.type', 'mysql' ?? $shopConfig->get('type')); |
||
| 73 | $config->set('db.host', $config->get('db.host') ?? $shopConfig->get('host')); |
||
| 74 | $config->set('db.port', $config->get('db.port') ?? $shopConfig->get('port')); |
||
| 75 | $config->set('db.database', $config->get('db.database') ?? $shopConfig->get('dbname')); |
||
| 76 | $config->set('db.user', $config->get('db.user') ?? $shopConfig->get('username')); |
||
| 77 | $config->set('db.password', $config->get('db.password') ?? $shopConfig->get('password')); |
||
| 78 | |||
| 79 | $lazyPDO->changeConnection( |
||
| 80 | sprintf( |
||
| 81 | '%s:host=%s;port=%d;dbname=%s', |
||
| 82 | 'mysql', |
||
| 83 | $config->get('db.host'), |
||
| 84 | $config->get('db.port'), |
||
| 85 | $config->get('db.database') |
||
| 86 | ), |
||
| 87 | $config->get('db.user'), |
||
| 88 | $config->get('db.password'), |
||
| 89 | [ |
||
| 90 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | |||
| 94 | return $lazyPDO; |
||
| 95 | }); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param ContainerInterface $container |
||
| 100 | * @throws \ReflectionException |
||
| 101 | */ |
||
| 102 | public function configure(ContainerInterface $container) |
||
| 103 | { |
||
| 104 | /* @var ConfigInterface $config */ |
||
| 105 | $config = $container->get(ConfigInterface::class); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 106 | |||
| 107 | /* @var ExecutableFinder $execFinder */ |
||
| 108 | $execFinder = $container->get(ExecutableFinder::class); |
||
| 109 | $execFinder->addAlias('swconsole', $container->get('shopware.path') . '/bin/console'); |
||
| 110 | |||
| 111 | /* @var TaskCreationHelper $helper */ |
||
| 112 | $helper = $container->get(TaskCreationHelper::class); |
||
| 113 | $helper->addAlias('swCommand', ShopwareCommandDefinition::class); |
||
| 114 | $helper->addAlias('swCacheClear', CacheClearDefinition::class); |
||
| 115 | $helper->addAlias('swCreateAdmin', CreateAdminUserDefinition::class); |
||
| 116 | $helper->addAlias('swGenerateThemeCache', GenerateThemeCacheDefinition::class); |
||
| 117 | $helper->addAlias('swPluginInstall', PluginInstallDefinition::class); |
||
| 118 | $helper->addAlias('swPluginUninstall', PluginUninstallDefinition::class); |
||
| 119 | $helper->addAlias('swPluginUpdate', PluginUpdateDefinition::class); |
||
| 120 | $helper->addAlias('swPluginActivate', PluginActivateDefinition::class); |
||
| 121 | $helper->addAlias('swPluginDeactivate', PluginDeactivateDefinition::class); |
||
| 122 | $helper->addAlias('swPluginRefresh', PluginRefreshDefinition::class); |
||
| 123 | |||
| 124 | /* @var DispatcherCollection $dispatcherCollection */ |
||
| 125 | $dispatcherCollection = $container->get(DispatcherCollection::class); |
||
| 126 | /* @var ContainerResolver $resolver */ |
||
| 127 | $resolver = $container->get(ContainerResolver::class); |
||
| 128 | |||
| 129 | $dispatcherArray = [ |
||
| 130 | $resolver->createInstance(ShopwareCommandDispatcher::class), |
||
| 131 | $resolver->createInstance(CreateAdminUserDispatcher::class), |
||
| 132 | $resolver->createInstance(CacheClearDispatcher::class), |
||
| 133 | $resolver->createInstance(GenerateThemeCacheDispatcher::class), |
||
| 134 | $resolver->createInstance(PluginInstallDispatcher::class), |
||
| 135 | $resolver->createInstance(PluginUninstallDispatcher::class), |
||
| 136 | $resolver->createInstance(PluginUpdateDispatcher::class), |
||
| 137 | $resolver->createInstance(PluginActivateDispatcher::class), |
||
| 138 | $resolver->createInstance(PluginDeactivateDispatcher::class), |
||
| 139 | $resolver->createInstance(PluginRefreshDispatcher::class), |
||
| 140 | ]; |
||
| 141 | |||
| 142 | $dispatcherCollection->addDispatcherArray($dispatcherArray); |
||
| 143 | } |
||
| 144 | } |