/**
  * {@inheritdoc}
  */
 public function register(Engine $engine)
 {
     // Add app view data
     $engine->addData(['validation_errors' => [], 'base_js' => [], 'base_css' => []]);
     // Form helpers
     $engine->registerFunction('userPhoto', [$this, 'userPhoto']);
     $engine->registerFunction('requestBody', [$this, 'requestBody']);
     $engine->registerFunction('formFieldError', [$this, 'fieldError']);
     $engine->registerFunction('formInputSelect', [$this, 'inputSelect']);
     $engine->registerFunction('formInputMethod', [$this, 'inputMethod']);
     // Flash Message helpers
     $engine->registerFunction('flashMessages', [$this->flash, 'getMessages']);
     $engine->registerFunction('flashMessage', [$this->flash, 'getMessage']);
     // Register validation helpers
     $engine->registerFunction('validationErrors', function (array $errors = []) use($engine) {
         $engine->addData(['validation_errors' => $errors]);
     });
     // Register view js helpers
     $engine->registerFunction('appendJs', function (array $jsFiles = []) use($engine) {
         $engine->addData(['base_js' => $jsFiles]);
     });
     // Register view css helpers
     $engine->registerFunction('appendCss', function (array $cssFiles = []) use($engine) {
         $engine->addData(['base_css' => $cssFiles]);
     });
     // Pagination Helper
     $engine->registerFunction('viewPages', [$this, 'viewPages']);
 }
Example #2
0
 public function register()
 {
     $this->container->add('service.http.request', function () {
         return Request::createFromGlobals();
     });
     $this->container->add('service.http.route', function () {
         $route = new Route($this->container);
         foreach ($this->container->get('config')['http']['routes'] as $item) {
             $route->addRoute(strtoupper($item['method']), $item['path'], $item['target']);
         }
         return $route;
     });
     $this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () {
         return $this->container->get('service.http.request');
     });
     $this->container->add('service.view.view', function () {
         $view = new View();
         foreach ($this->container->get('config')['http']['views_path'] as $name => $path) {
             $view->addFolder($name, $path);
         }
         $request = $this->container->get('service.http.request');
         $view->loadExtension(new RequestExtension($request));
         $view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag()));
         $view->loadExtension(new BaseUrlExtension($request->getBasePath()));
         $assetBaseUrl = $this->container->get('config')['asset_base_url'];
         $view->loadExtension(new AssetUrlExtension($assetBaseUrl));
         if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) {
             $authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser();
             $view->loadExtension(new AuthenticatedUserExtension($authenticatedUser));
         }
         $view->addData(['applicationName' => $this->container->get('config')['application_name']]);
         return $view;
     });
 }
 protected function setUp()
 {
     $plates = new Engine(__DIR__ . '/Resources/views');
     $plates->setFileExtension(null);
     $plates->addData(['foo' => 'bar']);
     $this->engine = new PlatesEngineAdapter($plates);
 }
Example #4
0
 /**
  * @param string $tableName Table Name
  * @param string $viewDir User Template directory
  * @throws Exception
  * @throws TableNameException
  * @throws \RedBeanPHP\RedException
  */
 public function __construct($tableName = null, $viewDir = "view")
 {
     R::ext('xdispense', function ($type) {
         return R::getRedBean()->dispense($type);
     });
     if ($tableName != null) {
         $this->setTable($tableName);
     }
     try {
         $this->template = new Engine($viewDir);
     } catch (\LogicException $ex) {
         throw new Exception("The view folder is not existing.");
     }
     // Debug Bar
     $this->debugbar = new StandardDebugBar();
     $debugbarRenderer = $this->debugbar->getJavascriptRenderer(Util::res("vendor/maximebf/debugbar/src/DebugBar/Resources"));
     // Template Default Data
     $this->template->addData(["crud" => $this, "cacheVersion" => $this->cacheVersion, "debugbar" => $this->debugbar, "debugbarRenderer" => $debugbarRenderer]);
     $this->addTheme("adminlte", "vendor/{$this->packageName}/view/theme/AdminLTE");
     $this->setCurrentTheme("adminlte");
     // Enable helper?
     if (defined("ENABLE_CRUD_HELPER") && ENABLE_CRUD_HELPER) {
         //setGlobalCRUD($this);
     }
 }
Example #5
0
 public function __construct()
 {
     $this->setUrl(env('APP_URL'));
     $this->pipe(Middleware::formatNegotiator());
     $this->pipe(Middleware::whoops());
     $this->source(new StaticFiles('build/**/*'))->build(false);
     $this->source(new StaticFiles('source/img/**/*', '/img/**/*'));
     $plates = new Engine('source/templates');
     $plates->addData(['app' => $this]);
     $this->source(new YamlFiles('source/data/*.yml'))->templates($plates);
 }
Example #6
0
 public function register(Fol $app)
 {
     $app['templates'] = function ($app) {
         $root = dirname(dirname(__DIR__));
         $templates = new Engine($root . '/templates');
         $icons = new Collection(new MaterialDesignIcons($root . '/assets/icons'));
         $templates->addData(['app' => $app]);
         $templates->registerFunction('icon', function ($name) use($icons) {
             return $icons->get($name);
         });
         return $templates;
     };
 }
 /**
  * {@inheritDoc}
  *
  * Proxies to the Plate Engine's `addData()` method.
  *
  * {@inheritDoc}
  */
 public function addDefaultParam($templateName, $param, $value)
 {
     if (!is_string($templateName) || empty($templateName)) {
         throw new Exception\InvalidArgumentException(sprintf('$templateName must be a non-empty string; received %s', is_object($templateName) ? get_class($templateName) : gettype($templateName)));
     }
     if (!is_string($param) || empty($param)) {
         throw new Exception\InvalidArgumentException(sprintf('$param must be a non-empty string; received %s', is_object($param) ? get_class($param) : gettype($param)));
     }
     $params = [$param => $value];
     if ($templateName === self::TEMPLATE_ALL) {
         $templateName = null;
     }
     $this->template->addData($params, $templateName);
 }
 public function __invoke(array $input)
 {
     $name = 'world';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     ////////////////////
     $application = new Application();
     $application_data = $application->is_pjax();
     //print_r( '<pre>' );
     // print_r( $application_data );
     //print_r( '</pre>');
     ////////////////////
     // simple
     // Create new Plates instance
     //		$plates = new Engine(APPPATH.'templates');
     // Render a template
     // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]);
     //		$template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]);
     $data = ['friends' => ['mikka', 'makka', 'zorro']];
     //			$friends = [
     //			  ['name', 'zorro'],
     //			];
     ////////////////////
     // using folders
     // Create new Plates instance
     $plates = new Engine(APPPATH . 'templates');
     // Register a Plates extension
     $plates->loadExtension(new Utils());
     // Add folders
     $plates->addFolder('layout', APPPATH . 'templates');
     $plates->addFolder('partials', APPPATH . 'templates/partials');
     $plates->addFolder('static', APPPATH . 'templates/static');
     // assign data to plates
     $plates->addData($data, 'layout');
     // Render
     $template = $plates->render('partials::profile', ['name' => $name]);
     ////////////////////
     $invitation = 'I invite you';
     // return
     return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]);
 }
 /**
  * @param ResponseInterface $response
  * @param TemplateResult $templateResult
  * @return ResponseInterface
  */
 private function modifyResponseForTemplateResult(ResponseInterface $response, TemplateResult $templateResult)
 {
     $this->engine->addData(['host' => 'http://' . $this->serverRequest->getServerParams()['HTTP_HOST'] . '/']);
     $stream = \GuzzleHttp\Psr7\stream_for($this->engine->render($templateResult->getTemplate(), $templateResult->getData()));
     return $response->withHeader('Content-Type', 'text/html')->withBody($stream);
 }
 public function prepareTemplates(Engine $template, Injector $injector)
 {
     $template->addData(['pages' => $this->getPages()]);
     $template->setFileExtension('phtml');
     $template->loadExtension(new DirectoryExtension());
 }
Example #11
0
 /**
  * Add data to render.
  *
  * @param  array  $data      Data
  * @param  string $templates Template
  * @return $this
  */
 public function add_data(array $data, $templates = null)
 {
     $this->engine->addData($data, $templates);
     return $this;
 }
 /**
  * Share data to all templates.
  *
  * @param array $data
  */
 public function globalData(array $data)
 {
     $this->engine->addData($data);
 }
 /**
  * setup the template engine and sends the parsed content to the engine
  *
  * @uses    \League\Plates\Extension\Asset
  * @uses    \League\Plates\Engine
  * @uses    url
  * @since   1.0
  */
 public function setup()
 {
     $engine = new Engine($this->relativePath . "include" . DS . "styles" . DS . config::init()->style);
     $engine->loadExtension(new Asset($this->relativePath . "include" . DS . "styles" . DS . config::init()->style . DS . "assets", true));
     // add infos for theme
     $this->setStyleParameter("isZipEnabled", false);
     $this->setStyleParameter("showWarnings", false);
     $breadcrumbs = $this->generateBreadcrumbs(url::GET("dir"));
     $this->setStyleParameter("breadcrumbs", $breadcrumbs);
     $this->setStyleParameter("assetspath", common::getRelativePath(getcwd(), dirname(__FILE__)) . DS . "styles" . DS . config::init()->style . DS . "assets");
     $this->setStyleParameter("title", "SimpleDirLister | " . common::fixPaths(implode(DS, array_keys($breadcrumbs))));
     $this->setStyleParameter("path", common::fixPaths(implode(DS, array_keys($breadcrumbs))));
     $this->setStyleParameter("header", config::init()->header ? file::init(config::init()->header)->getFilename() : false);
     $this->setStyleParameter("footer", config::init()->footer ? file::init(config::init()->footer)->getFilename() : false);
     $engine->addFolder('static', $this->getBasePath() . DS . config::init()->headerFooterDir);
     try {
         $files = $this->getRawPaths();
         $files = $this->cleanArray($files);
         if (config::init()->showReadme) {
             $readmeContent = [];
             foreach (config::init()->readme as $readme) {
                 if (isset($files[$readme])) {
                     $c = file_get_contents($files[$readme]["path"]);
                     $ext = pathinfo($files[$readme]["path"], PATHINFO_EXTENSION);
                     if ($ext == "md") {
                         $md = new Parsedown();
                         $readmeContent[] = '<div class="md">' . $md->text($c) . '</div>';
                     } elseif ($ext == "php") {
                         $readmeContent[] = (require $files[$readme]["path"]);
                     } else {
                         $readmeContent[] = $c;
                     }
                     if (config::init()->removeReadme) {
                         unset($files[$readme]);
                     }
                 }
             }
             $this->setStyleParameter("readme", $readmeContent);
         }
     } catch (\Exception $e) {
         $this->setStyleParameter("showWarnings", true);
         $this->setStyleParameter("warnings", [["message" => "dir not found", "type" => "danger"]]);
         $files = [];
     } finally {
         $this->setStyleParameter("files", $files);
     }
     $engine->registerFunction('fileicon', [&$this, "getIconFromSet"]);
     $this->setStyleParameter("search", url::GET("s"));
     $engine->addData($this->styleParameter);
     if (!empty(url::GET("s"))) {
         echo $engine->render("search", $this->styleParameter);
     } else {
         echo $engine->render("index", $this->styleParameter);
     }
 }
Example #14
0
 /**
  * Add preassigned template data.
  *
  * @param  array         $data
  * @param  null|string[] $templates
  * @return \League\Plates\Engine
  */
 public function addData(array $data, $templates = null)
 {
     return $this->plates->addData($data, $templates);
 }