2017 © Pedro Peláez
 

library php-renderer

Render PHP view scripts into a PSR-7 Response object.

image

chiron/php-renderer

Render PHP view scripts into a PSR-7 Response object.

  • Monday, April 16, 2018
  • by ncou
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 33 % Grown

The README.md

Build Status Coverage Status CodeCov, (*1)

Total Downloads Monthly Downloads, (*2)

StyleCI PHP-Eye PHPStan, (*3)

PHP Renderer

This is a renderer for rendering PHP view scripts into a PSR-7 Response object. It works well with Chiron Framework., (*4)

Cross-site scripting (XSS) risks

Note that PHP-View has no built-in mitigation from XSS attacks. It is the developer's responsibility to use htmlspecialchars() or a component like zend-escaper. Alternatively, consider Twig-View., (*5)

Templates

You may use $this inside your php templates. $this will be the actual PhpRenderer object will allow you to render sub-templates, (*6)

Installation

Install with Composer:, (*7)

composer require chiron/php-renderer

Usage with Chiron

use Chiron\Views\PhpRenderer;

include "vendor/autoload.php";

$app = new Chiron\App();
$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./templates");

$app->get('/hello/{name}', function ($request, $response, $args) use ($container) {
    $text = $container->get('renderer')->render("/hello.php", $args);
    return $response->write($text);
});

$app->run();

Usage with any PSR-7 Project

//Construct the View
$phpView = new PhpRenderer("./path/to/templates");

//Render a Template
$text = $phpView->render("/path/to/template.php", $yourData);
$response = $response->write($text);

Template Variables

You can now add variables to your renderer that will be available to all templates you render., (*8)

// via the constructor
$templateVariables = [
    "title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables);

// or setter
$phpView->setAttributes($templateVariables);

// or individually
$phpView->addAttribute($key, $value);

Data passed in via ->render() takes precedence over attributes., (*9)

$templateVariables = [
    "title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables);

//...

$phpView->render($template, [
    "title" => "My Title"
]);
// In the view above, the $title will be "My Title" and not "Title"

Exceptions

\RuntimeException - if template does not exist, (*10)

The Versions

16/04 2018

dev-master

9999999-dev

Render PHP view scripts into a PSR-7 Response object.

  Sources   Download

MIT

The Development Requires

framework template php renderer view phtml chiron

16/04 2018

0.3

0.3.0.0

Render PHP view scripts into a PSR-7 Response object.

  Sources   Download

MIT

The Development Requires

framework template php renderer view phtml chiron

02/04 2018

0.2

0.2.0.0

Render PHP view scripts into a PSR-7 Response object.

  Sources   Download

MIT

The Development Requires

framework template php renderer view phtml chiron

02/04 2018

0.1

0.1.0.0

Render PHP view scripts into a PSR-7 Response object.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework template php renderer view phtml chiron