<?php declare(strict_types=1);
namespace P2Lab\ProductVideo;
use P2Lab\ProductVideo\Bootstrap\Lifecycle;
use P2Lab\ProductVideo\Compatibility\DependencyLoader;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Filesystem\Filesystem;
use Shopware\Core\Kernel;
class P2LabProductVideo extends Plugin
{
public const PLUGIN_NAME = 'P2LabProductVideo';
public function install(InstallContext $context): void
{
parent::install($context);
$this->lifecycle()->install($context);
}
public function postInstall(InstallContext $context): void
{
parent::postInstall($context);
$this->lifecycle()->postInstall( $context );
}
public function update(UpdateContext $context): void
{
parent::update($context);
$this->lifecycle()->update( $context );
}
public function activate(ActivateContext $context): void
{
parent::activate($context);
$this->lifecycle()->activate( $context );
}
public function deactivate(DeactivateContext $context): void
{
parent::deactivate($context);
$this->lifecycle()->deactivate( $context );
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ( $context->keepUserData() ) {
return;
}
$this->lifecycle()->uninstall( $context );
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
$this->container = $container;
$this->dependencyLoader()->loadServices();
}
public function configureRoutes(RoutingConfigurator $routes, string $environment): void
{
if (!$this->isActive()) {
return;
}
/** @var string $routesPath */
$routesPath = $this->dependencyLoader()->getRoutesPath($this->getPath());
/** @var Filesystem $fileSystem */
$fileSystem = new Filesystem();
if ($fileSystem->exists($routesPath)) {
$routesPath .= '/{routes}';
$routes->import($routesPath . Kernel::CONFIG_EXTS, 'glob');
}
}
private function lifecycle() {
return new Lifecycle( $this->container );
}
private function dependencyLoader() {
return new DependencyLoader( $this->container );
}
}