Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Performance: Twig runtime extensions and reduced sub-requests #159

Merged
merged 11 commits into from
Feb 7, 2021
2 changes: 2 additions & 0 deletions Controller/BreadcrumbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class BreadcrumbController extends EmitterController
*/
public function breadcrumbAction(Request $request): Response
{
@trigger_error('BreadcrumbController::breadcrumbAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(BreadcrumbMenuEvent::class)) {
return new Response();
}
Expand Down
30 changes: 14 additions & 16 deletions Controller/NavbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@
class NavbarController extends EmitterController
{
/**
* @var int|null
* @var ContextHelper
*/
private $maxNotifications;
/**
* @var int|null
*/
private $maxMessages;
/**
* @var int|null
*/
private $maxTasks;
private $helper;

public function __construct(EventDispatcherInterface $dispatcher, ContextHelper $helper)
{
parent::__construct($dispatcher);
$this->maxNotifications = $helper->getOption('max_navbar_notifications');
$this->maxMessages = $helper->getOption('max_navbar_messages');
$this->maxTasks = $helper->getOption('max_navbar_tasks');
$this->helper = $helper;
}

/**
Expand All @@ -47,12 +37,14 @@ public function __construct(EventDispatcherInterface $dispatcher, ContextHelper
*/
public function notificationsAction($max = null): Response
{
@trigger_error('NavbarController::notificationsAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(NotificationListEvent::class)) {
return new Response();
}

if (null === $max) {
$max = (int) $this->maxNotifications;
$max = (int) $this->helper->getOption('max_navbar_notifications');
}

/** @var NotificationListEvent $listEvent */
Expand All @@ -73,12 +65,14 @@ public function notificationsAction($max = null): Response
*/
public function messagesAction($max = null): Response
{
@trigger_error('NavbarController::messagesAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(MessageListEvent::class)) {
return new Response();
}

if (null === $max) {
$max = (int) $this->maxMessages;
$max = (int) $this->helper->getOption('max_navbar_messages');
}

/** @var MessageListEvent $listEvent */
Expand All @@ -99,12 +93,14 @@ public function messagesAction($max = null): Response
*/
public function tasksAction($max = null): Response
{
@trigger_error('NavbarController::tasksAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(TaskListEvent::class)) {
return new Response();
}

if (null === $max) {
$max = (int) $this->maxTasks;
$max = (int) $this->helper->getOption('max_navbar_tasks');
}

/** @var TaskListEvent $listEvent */
Expand All @@ -124,6 +120,8 @@ public function tasksAction($max = null): Response
*/
public function userAction(): Response
{
@trigger_error('NavbarController::userAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(NavbarUserEvent::class)) {
return new Response();
}
Expand Down
18 changes: 7 additions & 11 deletions Controller/SidebarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class SidebarController extends EmitterController
final class SidebarController extends EmitterController
{
/**
* @return Response
*/
public function userPanelAction(): Response
{
@trigger_error('SidebarController::userPanelAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(SidebarUserEvent::class)) {
return new Response();
}
Expand All @@ -37,20 +36,17 @@ public function userPanelAction(): Response
);
}

/**
* @return Response
*/
public function searchFormAction(): Response
{
@trigger_error('SidebarController::searchFormAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

return $this->render('@AdminLTE/Sidebar/search-form.html.twig', []);
}

/**
* @param Request $request
* @return Response
*/
public function menuAction(Request $request): Response
{
@trigger_error('SidebarController::menuAction() is deprecated and will be removed with 4.0', E_USER_DEPRECATED);

if (!$this->hasListener(SidebarMenuEvent::class)) {
return new Response();
}
Expand Down
2 changes: 1 addition & 1 deletion Event/MenuEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function removeItem($item): MenuEvent
*/
public function getRootItem($id)
{
return isset($this->menuRootItems[$id]) ? $this->menuRootItems[$id] : null;
return $this->menuRootItems[$id] ?? null;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Event/MessageListEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace KevinPapst\AdminLTEBundle\Event;

use KevinPapst\AdminLTEBundle\Model\MessageInterface;
use KevinPapst\AdminLTEBundle\Repository\MessageRepositoryInterface;

/**
* The MessageListEvent collects all MessageInterface objects that should be rendered in the messages section.
*/
class MessageListEvent extends ThemeEvent
class MessageListEvent extends ThemeEvent implements MessageRepositoryInterface
{
/**
* Stores the list of messages
Expand Down
3 changes: 2 additions & 1 deletion Event/NotificationListEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace KevinPapst\AdminLTEBundle\Event;

use KevinPapst\AdminLTEBundle\Model\NotificationInterface;
use KevinPapst\AdminLTEBundle\Repository\NotificationRepositoryInterface;

/**
* The NotificationListEvent collects all NotificationInterface objects that should be rendered in the notification section.
*/
class NotificationListEvent extends ThemeEvent
class NotificationListEvent extends ThemeEvent implements NotificationRepositoryInterface
{
/**
* @var array
Expand Down
3 changes: 2 additions & 1 deletion Event/ShowUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
namespace KevinPapst\AdminLTEBundle\Event;

use KevinPapst\AdminLTEBundle\Model\NavBarUserLink;
use KevinPapst\AdminLTEBundle\Model\UserDetailsInterface;
use KevinPapst\AdminLTEBundle\Model\UserInterface;

/**
* Collect the UserInterface object that should be rendered in the user section.
*/
abstract class ShowUserEvent extends ThemeEvent
abstract class ShowUserEvent extends ThemeEvent implements UserDetailsInterface
{
/**
* @var UserInterface
Expand Down
7 changes: 4 additions & 3 deletions Event/TaskListEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace KevinPapst\AdminLTEBundle\Event;

use KevinPapst\AdminLTEBundle\Model\TaskInterface;
use KevinPapst\AdminLTEBundle\Repository\TaskRepositoryInterface;

/**
* The TaskListEvent collects all TaskInterface objects that should be rendered in the tasks section.
*/
class TaskListEvent extends ThemeEvent
class TaskListEvent extends ThemeEvent implements TaskRepositoryInterface
{
/**
* @var TaskInterface[]
Expand All @@ -32,7 +33,7 @@ class TaskListEvent extends ThemeEvent
protected $total = 0;

/**
* @param int $max Maximun number of tasks displayed in panel
* @param int|null $max Maximum number of tasks displayed in panel
*/
public function __construct($max = null)
{
Expand All @@ -50,7 +51,7 @@ public function getMax()
}

/**
* @return array
* @return TaskInterface[]
*/
public function getTasks()
{
Expand Down
11 changes: 4 additions & 7 deletions Model/NotificationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
class NotificationModel implements NotificationInterface
{
/**
* @return string
* @var string
*/
protected $type = Constants::TYPE_INFO;

/**
* @return string
* @var string
*/
protected $message;

/**
* @return string
* @var string
*/
protected $icon;

/**
* @var string
*/
protected $id;

/**
* @param string $message
* @param string|null $message
* @param string $type
* @param string $icon
*/
Expand Down
24 changes: 24 additions & 0 deletions Model/UserDetailsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the AdminLTE bundle.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KevinPapst\AdminLTEBundle\Model;

interface UserDetailsInterface
{
/**
* @return NavBarUserLink[]
*/
public function getLinks(): array;

public function getUser(): ?UserInterface;

public function isShowProfileLink(): bool;

public function isShowLogoutLink(): bool;
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This repository contains an upgraded version of the AvanzuAdminThemeBundle, brin

**Compatibility:**

Version 3.x should be compatible with Symfony 5, [please leave your feedback](https://github.com/kevinpapst/AdminLTEBundle/issues/144).

- Version 3.x is only compatible with Symfony >= 4.3
- Version 2.x of this bundle is compatible with Symfony < 4.3

Expand Down
25 changes: 25 additions & 0 deletions Repository/MessageRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the AdminLTE bundle.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KevinPapst\AdminLTEBundle\Repository;

use KevinPapst\AdminLTEBundle\Model\MessageInterface;

interface MessageRepositoryInterface
{
/**
* @return int
*/
public function getTotal();

/**
* @return iterable<MessageInterface>
*/
public function getMessages();
}
25 changes: 25 additions & 0 deletions Repository/NotificationRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the AdminLTE bundle.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KevinPapst\AdminLTEBundle\Repository;

use KevinPapst\AdminLTEBundle\Model\NotificationInterface;

interface NotificationRepositoryInterface
{
/**
* @return int
*/
public function getTotal();

/**
* @return iterable<NotificationInterface>
*/
public function getNotifications();
}
25 changes: 25 additions & 0 deletions Repository/TaskRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the AdminLTE bundle.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KevinPapst\AdminLTEBundle\Repository;

use KevinPapst\AdminLTEBundle\Model\TaskInterface;

interface TaskRepositoryInterface
{
/**
* @return int
*/
public function getTotal();

/**
* @return iterable<TaskInterface>
*/
public function getTasks();
}
18 changes: 15 additions & 3 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ services:
tags: ['controller.service_arguments']
autowire: true

KevinPapst\AdminLTEBundle\Twig\AdminExtension:
class: KevinPapst\AdminLTEBundle\Twig\AdminExtension
KevinPapst\AdminLTEBundle\Twig\RuntimeExtension:
class: KevinPapst\AdminLTEBundle\Twig\RuntimeExtension
arguments:
- '@admin_lte_theme.context_helper'
- '%admin_lte_theme.routes%'
tags:
- { name: twig.runtime }

KevinPapst\AdminLTEBundle\Twig\EventsExtension:
class: KevinPapst\AdminLTEBundle\Twig\EventsExtension
arguments:
- '@event_dispatcher'
- '@admin_lte_theme.context_helper'
tags:
- { name: twig.runtime }

KevinPapst\AdminLTEBundle\Twig\AdminExtension:
class: KevinPapst\AdminLTEBundle\Twig\AdminExtension
tags:
- { name: twig.extension }

admin_lte_theme.context_helper:
class: KevinPapst\AdminLTEBundle\Helper\ContextHelper
alias:
arguments:
- '%admin_lte_theme.options%'

Expand Down
Loading