forked from deblan/side_menu
remove deprecated app.php file
This commit is contained in:
parent
2cb8c22be0
commit
4e0c7be2c6
|
@ -1,10 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use OCA\SideMenu\AppInfo\Application;
|
|
||||||
|
|
||||||
$app = new Application();
|
|
||||||
|
|
||||||
if ($app->isEnabled()) {
|
|
||||||
$app->registerAssets();
|
|
||||||
$app->registerServices();
|
|
||||||
}
|
|
|
@ -9,6 +9,9 @@ use OCA\SideMenu\Service\AppRepository;
|
||||||
use OCA\SideMenu\Service\CategoryRepository;
|
use OCA\SideMenu\Service\CategoryRepository;
|
||||||
use OCA\SideMenu\Service\ConfigProxy;
|
use OCA\SideMenu\Service\ConfigProxy;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
@ -18,7 +21,7 @@ use Psr\Container\ContainerInterface;
|
||||||
*
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class Application extends App
|
class Application extends App implements IBootstrap
|
||||||
{
|
{
|
||||||
public const APP_ID = 'side_menu';
|
public const APP_ID = 'side_menu';
|
||||||
|
|
||||||
|
@ -44,16 +47,9 @@ class Application extends App
|
||||||
public function __construct(array $urlParams = [])
|
public function __construct(array $urlParams = [])
|
||||||
{
|
{
|
||||||
parent::__construct(self::APP_ID, $urlParams);
|
parent::__construct(self::APP_ID, $urlParams);
|
||||||
|
|
||||||
$this->config = OC::$server->getConfig();
|
|
||||||
$this->cspnm = OC::$server->getContentSecurityPolicyNonceManager();
|
|
||||||
$this->user = OC::$server[IUserSession::class]->getUser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function isEnabled(): bool
|
||||||
* Checks if this app is enabled.
|
|
||||||
*/
|
|
||||||
public function isEnabled(): bool
|
|
||||||
{
|
{
|
||||||
$enabled = true;
|
$enabled = true;
|
||||||
$isForced = (bool) $this->config->getAppValue(self::APP_ID, 'force', '0');
|
$isForced = (bool) $this->config->getAppValue(self::APP_ID, 'force', '0');
|
||||||
|
@ -74,64 +70,65 @@ class Application extends App
|
||||||
return $enabled;
|
return $enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function addAssets()
|
||||||
* Registes services.
|
|
||||||
*/
|
|
||||||
public function registerServices()
|
|
||||||
{
|
|
||||||
$container = $this->getContainer();
|
|
||||||
|
|
||||||
$container->registerService('AppRepository', function (ContainerInterface $c) {
|
|
||||||
return new AppRepository();
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('CategoryRepository', function (ContainerInterface $c) {
|
|
||||||
return new CategoryRepository();
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService('ConfigProxy', function (ContainerInterface $c) {
|
|
||||||
return new ConfigProxy();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers assets.
|
|
||||||
*/
|
|
||||||
public function registerAssets()
|
|
||||||
{
|
{
|
||||||
Util::addScript(self::APP_ID, 'sideMenu');
|
Util::addScript(self::APP_ID, 'sideMenu');
|
||||||
Util::addStyle(self::APP_ID, 'sideMenu');
|
Util::addStyle(self::APP_ID, 'sideMenu');
|
||||||
|
|
||||||
$stylesheet = OC::$server->getURLGenerator()->linkToRoute(
|
$assets = [
|
||||||
'side_menu.Css.stylesheet',
|
'stylesheet' => [
|
||||||
[
|
'route' => 'side_menu.Css.stylesheet',
|
||||||
'v' => $this->config->getAppValue(self::APP_ID, 'cache', '0'),
|
'type' => 'link',
|
||||||
]
|
'route_attr' => 'href',
|
||||||
);
|
'attr' => [
|
||||||
|
'rel' => 'stylesheet',
|
||||||
$script = OC::$server->getURLGenerator()->linkToRoute(
|
],
|
||||||
'side_menu.Js.script',
|
|
||||||
[
|
|
||||||
'v' => $this->config->getAppValue(self::APP_ID, 'cache', '0'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
Util::addHeader(
|
|
||||||
'link',
|
|
||||||
[
|
|
||||||
'href' => $stylesheet,
|
|
||||||
'rel' => 'stylesheet',
|
|
||||||
],
|
],
|
||||||
''
|
'script' => [
|
||||||
);
|
'route' => 'side_menu.Js.script',
|
||||||
|
'type' => 'script',
|
||||||
Util::addHeader(
|
'route_attr' => 'src',
|
||||||
'script',
|
'attr' => [
|
||||||
[
|
'nonce' => $this->cspnm->getNonce(),
|
||||||
'src' => $script,
|
],
|
||||||
'nonce' => $this->cspnm->getNonce(),
|
|
||||||
],
|
],
|
||||||
''
|
];
|
||||||
);
|
|
||||||
|
$cache = $this->config->getAppValue(self::APP_ID, 'cache', '0');
|
||||||
|
|
||||||
|
foreach ($assets as $key => $value) {
|
||||||
|
$route = OC::$server->getURLGenerator()->linkToRoute($value['route'], ['v' => $cache]);
|
||||||
|
$value['attr'][$value['route_attr']] = $route;
|
||||||
|
|
||||||
|
Util::addHeader($value['type'], $value['attr'], '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register(IRegistrationContext $context): void
|
||||||
|
{
|
||||||
|
$context->registerService('AppRepository', function (ContainerInterface $c) {
|
||||||
|
return new AppRepository();
|
||||||
|
});
|
||||||
|
|
||||||
|
$context->registerService('CategoryRepository', function (ContainerInterface $c) {
|
||||||
|
return new CategoryRepository();
|
||||||
|
});
|
||||||
|
|
||||||
|
$context->registerService('ConfigProxy', function (ContainerInterface $c) {
|
||||||
|
return new ConfigProxy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(IBootContext $context): void
|
||||||
|
{
|
||||||
|
$this->config = OC::$server->getConfig();
|
||||||
|
$this->cspnm = OC::$server->getContentSecurityPolicyNonceManager();
|
||||||
|
$this->user = OC::$server[IUserSession::class]->getUser();
|
||||||
|
|
||||||
|
if (!$this->isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addAssets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue