Skip to content

Commit

Permalink
Updated the view renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Apr 20, 2022
1 parent 023bbd6 commit 40fcacc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
21 changes: 11 additions & 10 deletions src/App/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,27 @@ public function setSessionManager(Closure $xClosure);
public function setContainer(ContainerInterface $xContainer);

/**
* Add a view namespace, and set the corresponding renderer.
* Add a view renderer with an id
*
* @param string $sNamespace The namespace name
* @param string $sDirectory The namespace directory
* @param string $sRenderer The renderer name
* @param string $sExtension The extension to append to template names
* @param string $sRenderer The corresponding renderer name
* @param Closure $xClosure A closure to create the view instance
*
* @return void
*/
public function addViewNamespace(string $sNamespace, string $sDirectory, string $sExtension, string $sRenderer);
public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure);

/**
* Add a view renderer with an id
* Set the javascript asset
*
* @param string $sId The unique identifier of the view renderer
* @param Closure $xClosure A closure to create the view instance
* @param bool $bExport Whether to export the js code in a file
* @param bool $bMinify Whether to minify the exported js file
* @param string $sUri The URI to access the js file
* @param string $sDir The directory where to create the js file
*
* @return void
* @return AppInterface
*/
public function addViewRenderer(string $sId, Closure $xClosure);
public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): AppInterface;

/**
* Read config options from a config file and set up the library
Expand Down
2 changes: 1 addition & 1 deletion src/App/Traits/AjaxSendTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function sendResponse()
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
}
header('content-type: ' . $this->xResponseManager->getContentType());
header('Content-Type: ' . $this->xResponseManager->getContentType());

print $sContent;
}
Expand Down
29 changes: 9 additions & 20 deletions src/App/Traits/AppTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace Jaxon\App\Traits;

use Closure;
use Jaxon\App\AppInterface;
use Jaxon\App\Bootstrap;
use Jaxon\App\Config\ConfigManager;
Expand All @@ -25,10 +24,12 @@
use Jaxon\Response\Manager\ResponseManager;
use Psr\Container\ContainerInterface;

use Closure;

trait AppTrait
{
use AjaxTrait {
getResponse as protected ajaxResponse;
AjaxTrait::getResponse as public ajaxResponse;
}

/**
Expand Down Expand Up @@ -120,32 +121,20 @@ public function setContainer(ContainerInterface $xContainer)
$this->di()->setContainer($xContainer);
}

/**
* Add a view namespace, and set the corresponding renderer.
*
* @param string $sNamespace The namespace name
* @param string $sDirectory The namespace directory
* @param string $sExtension The extension to append to template names
* @param string $sRenderer The corresponding renderer name
*
* @return void
*/
public function addViewNamespace(string $sNamespace, string $sDirectory, string $sExtension, string $sRenderer)
{
$this->di()->getViewRenderer()->addNamespace($sNamespace, $sDirectory, $sExtension, $sRenderer);
}

/**
* Add a view renderer with an id
*
* @param string $sId The unique identifier of the view renderer
* @param string $sRenderer The renderer name
* @param string $sExtension The extension to append to template names
* @param Closure $xClosure A closure to create the view instance
*
* @return void
*/
public function addViewRenderer(string $sId, Closure $xClosure)
public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure)
{
$this->di()->getViewRenderer()->addRenderer($sId, $xClosure);
$xViewRenderer = $this->di->getViewRenderer();
$xViewRenderer->addNamespace('default', '', $sExtension, $sRenderer);
$xViewRenderer->addRenderer($sRenderer, $xClosure);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Request/Factory/Psr/PsrFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

use Closure;

class PsrFactory
{
/**
Expand Down Expand Up @@ -66,6 +68,22 @@ public function container(ContainerInterface $xContainer): PsrFactory
return $this;
}

/**
* Add a view renderer with an id
*
* @param string $sRenderer The renderer name
* @param string $sExtension The extension to append to template names
* @param Closure $xClosure A closure to create the view instance
*
* @return void
*/
public function view(string $sRenderer, string $sExtension, Closure $xClosure)
{
$xViewRenderer = $this->di->getViewRenderer();
$xViewRenderer->addNamespace('default', '', $sExtension, $sRenderer);
$xViewRenderer->addRenderer($sRenderer, $xClosure);
}

/**
* Get the Jaxon ajax PSR request handler
*
Expand Down

0 comments on commit 40fcacc

Please sign in to comment.