3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller
;
7 use Shaarli\Bookmark\BookmarkFilter
;
8 use Shaarli\Container\ShaarliContainer
;
10 abstract class ShaarliController
12 /** @var ShaarliContainer */
15 /** @param ShaarliContainer $container Slim container (extended for attribute completion). */
16 public function __construct(ShaarliContainer
$container)
18 $this->container
= $container;
22 * Assign variables to RainTPL template through the PageBuilder.
24 * @param mixed $value Value to assign to the template
26 protected function assignView(string $name, $value): self
28 $this->container
->pageBuilder
->assign($name, $value);
34 * Assign variables to RainTPL template through the PageBuilder.
36 * @param mixed $data Values to assign to the template and their keys
38 protected function assignAllView(array $data): self
40 foreach ($data as $key => $value) {
41 $this->assignView($key, $value);
47 protected function render(string $template): string
49 $this->assignView('linkcount', $this->container
->bookmarkService
->count(BookmarkFilter
::$ALL));
50 $this->assignView('privateLinkcount', $this->container
->bookmarkService
->count(BookmarkFilter
::$PRIVATE));
51 $this->assignView('plugin_errors', $this->container
->pluginManager
->getErrors());
53 $this->executeDefaultHooks($template);
55 return $this->container
->pageBuilder
->render($template);
59 * Call plugin hooks for header, footer and includes, specifying which page will be rendered.
60 * Then assign generated data to RainTPL.
62 protected function executeDefaultHooks(string $template): void
70 foreach ($common_hooks as $name) {
72 $this->container
->pluginManager
->executeHooks(
76 'target' => $template,
77 'loggedin' => $this->container
->loginManager
->isLoggedIn()
80 $this->assignView('plugins_' . $name, $plugin_data);