mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-22 19:02:12 +00:00
Added EntityManager support
This commit is contained in:
parent
20d4d58a00
commit
5c48243306
117
src/AdminPanel/AdminPanel.php
Normal file
117
src/AdminPanel/AdminPanel.php
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Avior <florian.bouillon@delta-wings.net>
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace AdminPanel;
|
||||||
|
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
use AdminPanel\Cache\FileCache;
|
||||||
|
use Doctrine\ORM\Tools\Setup;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use AdminPanel\Logger;
|
||||||
|
|
||||||
|
class AdminPanel
|
||||||
|
{
|
||||||
|
/** @var AdminPanel $instance */
|
||||||
|
private static $instance = null;
|
||||||
|
|
||||||
|
/** @var string $root */
|
||||||
|
private $root = null;
|
||||||
|
|
||||||
|
private $settings = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get actual AdminPanel instance
|
||||||
|
*
|
||||||
|
* @param array $settings
|
||||||
|
* Settings to set to the software
|
||||||
|
*
|
||||||
|
* @return AdminPanel
|
||||||
|
*/
|
||||||
|
public static function getInstance()
|
||||||
|
{
|
||||||
|
if (!isset(AdminPanel::$instance)) {
|
||||||
|
define("ROOT", dirname(dirname(__DIR__)));
|
||||||
|
$ap = AdminPanel::$instance = new self();
|
||||||
|
$ap->root = dirname(__DIR__);
|
||||||
|
$ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false);
|
||||||
|
$ap->loader = new FilesystemLoader();
|
||||||
|
$ap->addLoaderFolder($ap->root . "/AdminPanel/Twig");
|
||||||
|
// $ap->setLoader(new FilesystemLoader());
|
||||||
|
}
|
||||||
|
return AdminPanel::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Logger $logger */
|
||||||
|
private $logger;
|
||||||
|
public function getLogger(): Logger
|
||||||
|
{
|
||||||
|
return isset($this->logger) ? $this->logger : $this->logger = new Logger(dirname($this->root));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Twig\Loader\FileSystemLoader $loader */
|
||||||
|
private $loader;
|
||||||
|
// private function setLoader(FilesystemLoader $loader)
|
||||||
|
// {
|
||||||
|
// $this->loader = $loader;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function addLoaderFolder(string $path, string $prefix = "AdminPanel")
|
||||||
|
{
|
||||||
|
$this->loader->addPath($path, $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Twig\Environment $twig */
|
||||||
|
private $twig;
|
||||||
|
public function getTwig()
|
||||||
|
{
|
||||||
|
return isset($this->twig) ? $this->twig : $this->twig = new Environment($this->loader, [
|
||||||
|
'cache' => $this->isCacheEnabled() ? dirname($this->root) . $this->settings->cache->path . '/twig/' : false
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private $cache;
|
||||||
|
public function getCache()
|
||||||
|
{
|
||||||
|
if (!$this->cache) {
|
||||||
|
$driver = $this->settings->cache->driver;
|
||||||
|
$options = $this->settings->cache->options;
|
||||||
|
$options->path = dirname($this->root) . $this->settings->cache->path;
|
||||||
|
$this->cache = new $driver($this->settings->cache->options);
|
||||||
|
}
|
||||||
|
// dd($this->cache);
|
||||||
|
return $this->cache;
|
||||||
|
// return $this->cache ? $this->cache : $this->cache = new FileCache(dirname($this->root) . "/cache/fs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCacheEnabled()
|
||||||
|
{
|
||||||
|
return $this->settings->cache->enabled == "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
private $em;
|
||||||
|
public function getEm()
|
||||||
|
{
|
||||||
|
if (!isset($this->em)) {
|
||||||
|
$config = Setup::createAnnotationMetadataConfiguration(array(
|
||||||
|
$this->root . "/Modules/Aptatio/DB"
|
||||||
|
), true);
|
||||||
|
|
||||||
|
$db = $this->settings->database;
|
||||||
|
$conn = array(
|
||||||
|
'driver' => $db->driver,
|
||||||
|
'host' => $db->host,
|
||||||
|
'dbname' => $db->dbname,
|
||||||
|
'user' => $db->user,
|
||||||
|
'password' => $db->password
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->em = EntityManager::create($conn, $config);
|
||||||
|
}
|
||||||
|
return $this->em;
|
||||||
|
}
|
||||||
|
}
|
@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Avior <florian.bouillon@delta-wings.net>
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace AdminPanel\Classes;
|
|
||||||
|
|
||||||
use Twig\Loader\FilesystemLoader;
|
|
||||||
use Twig\Environment;
|
|
||||||
use AdminPanel\Cache\FileCache;
|
|
||||||
use AdminPanel\Logger\Logger;
|
|
||||||
|
|
||||||
class AdminPanel
|
|
||||||
{
|
|
||||||
/** @var AdminPanel $instance */
|
|
||||||
private static $instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return AdminPanel
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if (!isset(AdminPanel::$instance)) {
|
|
||||||
define("ROOT", dirname(dirname(__DIR__)));
|
|
||||||
AdminPanel::$instance = new self();
|
|
||||||
AdminPanel::$instance->addLoaderFolder(ROOT . "/AdminPanel/Twig");
|
|
||||||
}
|
|
||||||
return AdminPanel::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Logger $logger */
|
|
||||||
private $logger;
|
|
||||||
public function setLogger(Logger $logger)
|
|
||||||
{
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
|
||||||
public function getLogger(): Logger
|
|
||||||
{
|
|
||||||
return $this->logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \Twig\Loader\FileSystemLoader $loader */
|
|
||||||
private $loader;
|
|
||||||
|
|
||||||
public function addLoaderFolder(string $path, string $prefix = "AdminPanel")
|
|
||||||
{
|
|
||||||
$this->loader->addPath($path, $prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \Twig\Environment $twig */
|
|
||||||
private $twig;
|
|
||||||
public function getTwig()
|
|
||||||
{
|
|
||||||
return isset($this->twig) ? $this->twig : $this->twig = new Environment($this->loader, [
|
|
||||||
'cache' => false //dirname(ROOT) . '/cache/twig/'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private $cache;
|
|
||||||
public function getCache()
|
|
||||||
{
|
|
||||||
return $this->cache ? $this->cache : $this->cache = new FileCache(dirname(ROOT) . "/cache/fs");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->loader = new FilesystemLoader();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Classes;
|
namespace AdminPanel;
|
||||||
|
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
@ -54,6 +54,11 @@ class Controller
|
|||||||
return AdminPanel::getInstance()->getTwig()->render($template, $args);
|
return AdminPanel::getInstance()->getTwig()->render($template, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getEM()
|
||||||
|
{
|
||||||
|
return AdminPanel::getInstance()->getEM();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: implements functions and variables to add functionnalities to controllers
|
//TODO: implements functions and variables to add functionnalities to controllers
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user