2017 © Pedro Peláez
 

library view

More secure and easy to use templating system for php5.4+

image

rkr/view

More secure and easy to use templating system for php5.4+

  • Friday, March 3, 2017
  • by rkr
  • Repository
  • 2 Watchers
  • 1 Stars
  • 283 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 23 Versions
  • 2 % Grown

The README.md

php-view

SensioLabsInsight Build Status Scrutinizer Code Quality, (*1)

More secure and easy to use templating system for php5.4+., (*2)

Design goals:, (*3)

  • Interface-driven and dependency-injection-friendly
  • Secure by default, unsecure if needed
  • Lightweight, easy to understand and stable
  • No extra scripting language. Use PHP to write templates.

Jumpstart

You will need this somewhere to convert a template-file into a string:, (*4)

$factory = new FileViewFactory(__DIR__.'/path/to/my/template/folder');
$renderer = $factory->create('module');
$renderer->add('myVar', 1234);
$content = $renderer->render('action');
echo $content;

FileViewFactory implements an interface called ViewFactory. You can use this interface to Build your very own Factories that create different renderers and so on. This is especially useful, if you need a way to change the change the implementation some day. This is also useful it you use a Dependency Injection Container to wire your components together:, (*5)

class MyCtrl {
    /** @var ViewFactory */
    private $viewFactory;

    /**
     * @param ViewFactory $viewFactory
     */
    public function __construct(ViewFactory $viewFactory) {
        $this->viewFactory = $viewFactory;
    }

    /**
     * @return string
     */
    public function someAction() {
        $content = $this->viewFactory->create('module')
        ->add('myVar', 1234)
        ->render('action');
        return $content;
    }
}

Use typehinting

In PHP-Templates, you can use typehinting which is recognized by IDEs like PHPStorm, ZendStudio or PDT (and maybe others)., (*6)

index.phtml, (*7)



get('obj') ?>



= $obj->getName() ?>

Enable escaping even for objects and method-calls

Instead of using $renderer->get('obj'), just use $renderer->getObject('obj')., (*8)

index.phtml, (*9)



getObject('obj') ?>



= $obj->getName() ?>

Layout-Support

index.phtml, (*10)



layout('layout', ['title' => 'My Site']) ?>

This will be part of the region "content".

region('left') ?>
This will be part of the region "left".
end() ?>

layout.phtml, (*11)



<html>
    <head>
        <title>MySite<?php if($this->has('title')): ?> - <?= $this->getString('title') ?><?php endif ?></title>
    </head>
    <body>
        <div id="content">
            <?= $this->get('content') ?>
        </div>
        <div id="left">
            <?= $this->get('left') ?>
        </div>
    </body>
</html>

The Versions

03/03 2017

dev-master

9999999-dev

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

03/03 2017

0.2.7

0.2.7.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/05 2016

0.2.6.4

0.2.6.4

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/05 2016

0.2.6.3

0.2.6.3

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

06/05 2016

0.2.6.2

0.2.6.2

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

06/05 2016

0.2.6.1

0.2.6.1

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

06/05 2016

0.2.6

0.2.6.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

06/05 2016

0.2.5

0.2.5.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

06/05 2016

0.2.4

0.2.4.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/12 2015

0.2.3

0.2.3.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/12 2015

0.2.2

0.2.2.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

29/09 2015

0.2.1

0.2.1.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

29/09 2015

0.2

0.2.0.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

01/07 2015

0.1.3.2

0.1.3.2

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/06 2015

0.1.3.1

0.1.3.1

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/06 2015

0.1.3

0.1.3.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/06 2015

0.1.2

0.1.2.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

10/06 2015

0.1.1

0.1.1.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

05/05 2015

0.1

0.1.0.0

More secure and easy to use templating system for php5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

26/04 2015

0.0.2

0.0.2.0

  Sources   Download

The Requires

  • php >=5.4

 

The Development Requires

26/04 2015

0.0.1

0.0.1.0

  Sources   Download

The Requires

  • php >=5.4

 

The Development Requires

01/09 2014

dev-test

dev-test

  Sources   Download

The Requires

  • php >=5.4

 

01/09 2014

dev-test2

dev-test2

  Sources   Download

MIT

The Requires

 

The Development Requires