@@ -5,10 +5,7 @@

namespace Papertowel\Framework\Modules\Plugin\Struct;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\Bundle\Bundle;

abstract class Plugin extends Bundle implements PluginInterface
@@ -73,34 +70,25 @@ public function getDescription(): string
return $this->description;
}

/**
* @param ContainerInterface $container
*/
public function onInstall(ContainerInterface $container): void
public function onInstall(): void
{
// Nothing to do
}

/**
* @param ContainerInterface $container
*/
public function onEnable(ContainerInterface $container): void
public function onEnable(): void
{
// Nothing to do
}

/**
* @param ContainerInterface $container
*/
public function onDisable(ContainerInterface $container): void
public function onDisable(): void
{
// Nothing to do
}

/**
* @param ContainerInterface $container
*/
public function onUninstall(ContainerInterface $container): void
public function onUninstall(): void
{
// Nothing to do
}
@@ -111,4 +99,4 @@ private function camelCaseToUnderscore(string $string): string
{
return strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $string), '_'));
}
}
}
@@ -37,9 +37,9 @@ public function setEnabled(bool $enabled): void;

public function onInstall(): void;

public function onEnable(): void;
public function onEnable(): void;

public function onDisable(): void;

public function onUninstall(): void;
}
}
@@ -5,6 +5,6 @@

namespace Papertowel\Framework\Modules\Theme\Exception;

class ThemeNotFoundException extends \Exception {

}
class ThemeNotFoundException extends \Exception
{
}
@@ -75,4 +75,4 @@ public function getJavascript(): array
{
return $this->javascript;
}
}
}
@@ -2,7 +2,6 @@

namespace Papertowel\Framework\Modules\Theme\Struct;


interface ThemeInterface
{
public function getName(): string;
@@ -14,4 +13,4 @@ public function getDependencies(): array;
public function getCss(): array;

public function getJavascript(): array;
}
}
@@ -83,7 +83,6 @@ public function getDependencyThemes(ThemeInterface $theme): array
*/
public function getTemplatePath($theme): string
{

$themeName = $theme;
if ($theme instanceof ThemeInterface) {
$themeName = $theme->getName();
@@ -169,4 +168,4 @@ private function loadTheme(string $themeName): ?ThemeInterface

return $class;
}
}
}
@@ -67,4 +67,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
$doctrine->getManager()->persist($language);
$doctrine->getManager()->flush();
}
}
}
@@ -48,6 +48,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($languages as $language) {
var_dump($language);
}

}
}
}
@@ -78,4 +78,4 @@ private function getNameForLanguage(Language $language, Language $languageLangua

$this->registry->getRepository(Translation::class)->getTranslationForLanguage($languageLanguage, $translationId);
}
}
}
@@ -43,7 +43,4 @@ public function __construct(WebsiteProvider $websiteProvider, LanguageProvider $
$this->languageProvider = $languageProvider;
$this->container = $container;
}



}
}
@@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$doctrine = $this->container->get('doctrine');

if ($domain === null || $websiteName === null || $themeName=== null ) {
if ($domain === null || $websiteName === null || $themeName=== null) {
throw new InvalidArgumentException();
}

@@ -73,4 +73,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
$doctrine->getManager()->persist($website);
$doctrine->getManager()->flush();
}
}
}
@@ -48,6 +48,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($websites as $website) {
var_dump($website->getPluginStates()->isEmpty());
}

}
}
}
@@ -89,4 +89,4 @@ private function extractSubDomains(string $fullDomain)

return rtrim(strstr($fullDomain, $domain, true), '.');
}
}
}
@@ -6,7 +6,6 @@

namespace Papertowel\Framework\Struct;


class ArrayList implements ListInterface
{
protected $data = [];
@@ -119,4 +118,4 @@ public function getArray(): array
{
return $this->data;
}
}
}
@@ -60,4 +60,4 @@ public function remove(int $index);
* @return mixed
*/
public function set($object, int $index);
}
}
@@ -2,157 +2,136 @@

namespace Papertowel;

use Papertowel\Framework\Entity\Website\Website;
use Papertowel\Framework\Modules\Plugin\PluginList;
use Papertowel\Framework\Modules\Plugin\PluginProvider;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
/**
* @var Request
*/
private $request;

use MicroKernelTrait;

public const CONFIG_EXTS = '.{php,xml,yaml,yml}';

private static $plugins;
/**
* @var PluginList
*/
private $plugins;

/**
* @var PluginProvider
*/
private $pluginProvider;

/**
* Kernel constructor.
* @param string $environment
* @param bool $debug
*/
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);

self::$plugins = new PluginList();
$this->plugins = new PluginList();
}

/**
* @return string
*/
public function getCacheDir()
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
}

/**
* @return string
*/
public function getLogDir()
{
return $this->getProjectDir() . '/var/log';
}

/** @var Request */
private $request;

/**
* @param Request $request
* @param int $type
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$this->request = $request;

return parent::handle($request, $type, $catch); // TODO: Change the autogenerated stub
return parent::handle($request, $type, $catch);
}

/**
* TODO: ITS SO CRAPPY FIX IT PLS!!!
* @throws Framework\Modules\Theme\Exception\ThemeNotFoundException
* @deprecated FIX THIS CRAPPY SHIT!!!
* @return \Generator|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
*/
public function boot()
public function registerBundles()
{
parent::boot();

try {
/** @var ContainerInterface $container */
$container = $this->container;

$websiteProvider = $container->get('papertowel.framework.website.website_provider');
$pluginProvider = $container->get('papertowel.framework.plugin.plugin_provider');
$themeProvider = $container->get('papertowel.framework.theme.theme_provider');

$host = $this->request === null ? 'localhost' : $this->request->getHost();

{
/** @var Website|null $requestedWebsite */
$requestedWebsite = $websiteProvider->getWebsiteByHost($host);

if ($requestedWebsite === null) {
throw new \Exception('Website cannot be found');
}

$container->set('website', $requestedWebsite);
}

{
$websitePluginStates = $requestedWebsite->getPluginStates();
$existingPlugins = $pluginProvider->getPluginNames();

foreach ($websitePluginStates as $pluginState) {
if (!$pluginState->isInstalled() || !$pluginState->isEnabled()) {
continue;
}

$plugin = $pluginState->getPlugin();

if (!in_array($plugin->getName(), $existingPlugins, true)) {
throw new \RuntimeException('Missing Plugin: ' . $plugin->getName());
}

if ($pluginState->isInstalled() || $pluginState->isEnabled()) {
$pluginProvider->loadPlugin($plugin->getName());
}
$contents = require $this->getProjectDir() . '/config/bundles.php';
$contents = array_merge($contents, []);

$pluginInstance = $pluginProvider->getPlugin($plugin->getName());
if ($pluginInstance !== null && $pluginState->isEnabled()) {
$pluginInstance->setEnabled(true);
}
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}

self::$plugins->addAll($pluginProvider->getPluginList());
}

{
$reqestedTheme = $themeProvider->getThemeByName($requestedWebsite->getThemeName());

if ($reqestedTheme === null) {
throw new \Exception('Theme cannot be found');
}

$container->set('theme', $reqestedTheme);
}
} catch (\Exception $ignored) {
/** @noinspection ForgottenDebugOutputInspection */
var_dump($ignored->getTraceAsString());
foreach ($this->getPlugins() as $plugin) {
yield $plugin;
}
}

$this->booted = false;
/**
*
* @throws \RuntimeException
*/
private function getPlugins() : array
{
$connection = DatabaseConnector::createPdoConnection();

// init bundles
$this->initializeBundles();
$enabledPluginsPrepared = $connection->prepare('SELECT plugin.name FROM plugin_state
INNER JOIN plugin ON(plugin.id = plugin_state.plugin_id)
WHERE website_id = (SELECT id FROM website WHERE `domain` = ?) AND plugin_state.enabled = 1 AND plugin_state.installed = 1');
$enabledPluginsPrepared->execute([$this->request->getHost()]);
$enabledPlugins = $enabledPluginsPrepared->fetchAll(\PDO::FETCH_COLUMN);

// init container
$this->initializeContainer();
$this->pluginProvider = new PluginProvider($this->getProjectDir() . '/plugins');
$this->pluginProvider->loadPlugins($enabledPlugins);
$loadedPlugins = $this->pluginProvider->getPluginList();

foreach ($this->getBundles() as $bundle) {
$bundle->setContainer($this->container);
$bundle->boot();
foreach ($enabledPlugins as $pluginName) {
if (!array_key_exists($pluginName, $loadedPlugins)) {
throw new \RuntimeException('Missing Plugin: ' . $pluginName);
}
}

$this->booted = true;
return $loadedPlugins;
}


public function registerBundles()
protected function initializeContainer()
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
$contents = array_merge($contents, []);
parent::initializeContainer();
$this->container->set('papertowel.framework.plugin.plugin_provider', $this->pluginProvider);

foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}

foreach (self::$plugins->getActivePlugins() as $plugin) {
yield $plugin;
foreach ($this->plugins->getActivePlugins() as $plugin) {
$plugin->setContainer($this->container);
}
}


protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$container->setParameter('container.autowiring.strict_mode', true);
@@ -179,4 +158,4 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
}
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
}
}
}
@@ -1,14 +1,7 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: Fionera
* Date: 17.01.2018
* Time: 20:24
*/

namespace Papertowel;


use Papertowel\Framework\Entity\Website\Website;
use Papertowel\Framework\Modules\Theme\Struct\ThemeInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;
@@ -91,4 +84,4 @@ function Papertowel($instance = null): Papertowel
}

return Papertowel::getInstance();
}
}