libraryPath = dirname(__DIR__, 3); // Add layout component path /** @var Layout $layouts */ $layouts = Factory::getInstance('layouts'); $layouts->addComponentPath($this->libraryPath . DS . 'layouts', Priority::LOWEST); } /** * Retrieve a new Form object with the given $name and $label. * * @param string $name * @param string $label * @return Form */ public function getForm(string $name, string $label = ""): Form { return new Form($name, $label); } /** * Build and retrieve a Form object, and save the result into Cache to save time on next instantiation. * * The $callable must return a Form object. * * $name and $label will be passed to the Form constructor. * * @param callable $callable * @param string $name * @param string $label * @return Form */ public function getCachedForm(callable $callable, string $name, string $label = ""): Form { // Fetch storage component /** @var ObjectStorageComponent $storage */ $storage = Factory::getInstance('storage'); // Fetch object storage /** @var ObjectStorageCache $cache */ $cache = $storage->getCache(); // Find form in storage $key = "formStorage" . $name; if ($cache->has($key)) { Logger::log("Returning cached Form '".$name."'"); /** @var Form $form */ $form = $cache->get($key); $csrf = $form->getCsrfField(); if (!is_null($csrf)) { /** @var Security $security */ $security = Factory::getInstance("security"); $hash = $security->get_csrf_hash(); $csrf->setValue($hash); } return $form; } // Otherwise, create the form Logger::log("Generating new Form '".$name."'"); $form = call_user_func($callable, $this->getForm($name, $label)); // Save the form $cache->set($key, $form, 3600); return $form; } public function getClassesPrefix(): ?string { return null; } public function getSourceDirectory(): ?string { return null; } }