PHPackages                             hnrazevedo/viewer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hnrazevedo/viewer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hnrazevedo/viewer
=================

Tools for developing personal projects

v2.0.5(5y ago)0250MITPHPPHP &gt;=7.4

Since Aug 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/hnrazevedo/Viewer)[ Packagist](https://packagist.org/packages/hnrazevedo/viewer)[ RSS](/packages/hnrazevedo-viewer/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)Dependencies (1)Versions (23)Used By (0)

Viewer @HnrAzevedo
==================

[](#viewer-hnrazevedo)

[![Maintainer](https://camo.githubusercontent.com/635097b3bfe7b55e89a425855fb0567f79aea687d3f7176a187b388ed7c99d56/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d40686e72617a657665646f2d626c75653f7374796c653d666c61742d737175617265)](https://github.com/hnrazevedo)[![Latest Version](https://camo.githubusercontent.com/3d281264be73f017cbfe9999f246106e7f7e66853b650ecebbc83ef038a5fd9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f686e72617a657665646f2f5669657765723f6c6162656c3d76657273696f6e267374796c653d666c61742d737175617265)](https://github.com/hnrazevedo/Viewer/releases)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ee6133da7864b13ca62085ce470a5520c8da9976a1bc2b65fab2c6a41d0e9646/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f686e72617a657665646f2f5669657765723f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hnrazevedo/Viewer/?branch=master)[![Build Status](https://camo.githubusercontent.com/13093d2993b3e81cf356f36be8a6bfbf309260c091a7f29b5c96f7d04691f51e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f686e72617a657665646f2f5669657765723f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hnrazevedo/Viewer/build-status/master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP from Packagist](https://camo.githubusercontent.com/675c149c8df02b80f32b29afe4d8a4168b6eb2fded1097749ecf417611982cd4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f686e72617a657665646f2f5669657765723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hnrazevedo/Viewer)[![Total Downloads](https://camo.githubusercontent.com/caa7e68de4d537446481f20cdd38dd52ef3ee5d78d408e5984f933d0b3704c9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686e72617a657665646f2f5669657765723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hnrazevedo/Viewer)

###### The Viewer is a simple component of managing the MVC project visualization layer. It can be used individually statically or together as middleware. Its author is not a professional in the development area, just someone in the Technology area who is improving his knowledge.

[](#the-viewer-is-a-simple-component-of-managing-the-mvc-project-visualization-layer-it-can-be-used-individually-statically-or-together-as-middleware-its-author-is-not-a-professional-in-the-development-area-just-someone-in-the-technology-area-who-is-improving-his-knowledge)

O Viewer é um simples componente de administração da camada de visualização de projetos MVC. Ele pode ser utilizado de forma individualmente de forma estática ou em conjunto como middleware. Seu autor não é profissional da área de desenvolvimento, apenas alguem da área de Tecnologia que está aperfeiçoando seus conhecimentos.

### Highlights

[](#highlights)

- Easy to set up (Fácil de configurar)
- Follows standard PSR-15 (Segue padrão o PSR-15)
- Composer ready (Pronto para o composer)

Installation
------------

[](#installation)

Viewer is available via Composer:

```
"hnrazevedo/Viewer": "^2.0"
```

or in at terminal

```
composer require hnrazevedo/Viewer
```

Methods
-------

[](#methods)

### Extensions

[](#extensions)

- View files: view.php
- Imported files: inc.php

### Basic use

[](#basic-use)

```
require __DIR__.'/../vendor/autoload.php';

use HnrAzevedo\Viewer\Viewer;

/**
 * Render method:
 * string $filename
 * ?array $data
 * ?bool $return
*/

Viewer::path(__DIR__.'/Views/')
      ->render('default');
```

### Return rendering

[](#return-rendering)

###### To return the content in a variable instead of being rendered, use the optional parameter of the render method

[](#to-return-the-content-in-a-variable-instead-of-being-rendered-use-the-optional-parameter-of-the-render-method)

Para retornar em uma váriavel o conteúdo ao invés de ser renderizado, utilize o parametro opcional do método render

```
require __DIR__.'/../vendor/autoload.php';

use HnrAzevedo\Viewer\Viewer;

/**
 * Render method:
 * string $filename
 * ?array $data
 * ?bool $return
*/

$html = Viewer::path(__DIR__.'/Views/')->render('default', null, true);
```

### Data transfer between the view and the controller

[](#data-transfer-between-the-view-and-the-controller)

```
require __DIR__.'/../vendor/autoload.php';

use HnrAzevedo\Viewer\Viewer;

$data = [
    'parameter'=>
        [
            'param1' => 1,
            'param2' => 'param2Value'
            'param3' => 'Parameter3'
        ]
    ];

Viewer::path(__DIR__.'/Views/')
      ->render('default', $data);
```

Returning data in the view
--------------------------

[](#returning-data-in-the-view)

#### The htmlspecialchars function is used by default as an escape to prevent XSS attacks.

[](#the-htmlspecialchars-function-is-used-by-default-as-an-escape-to-prevent-xss-attacks)

É utilizado de forma padrão a função htmlspecialchars como escape para evitar ataques XSS.

#### Sintax:

[](#sintax)

Sintaxe:

```
{{ $var }} htmlspecialchars

```

#### To display information without space use the syntax:

[](#to-display-information-without-space-use-the-syntax)

Para exibir informações sem espace utilize a sintaxe:

```
{{!! $var !!}} NO htmlspecialchars

```

#### HTML file example

[](#html-file-example)

```

    {{ $parameter }}
    {{ $parameter.param2 }}
    {{ $parameter.param3 }}
    {{!! $parameter.param3 !!}}

```

#### Note: If there is no variable to replace the value defined in the view, the text will be visible

[](#note-if-there-is-no-variable-to-replace-the-value-defined-in-the-view-the-text-will-be-visible)

#### HTML file result example:

[](#html-file-result-example)

```

    {{ $parameter }}
    param2Value
    Parameter3
    Parameter

```

Returning object properties
---------------------------

[](#returning-object-properties)

### IMPORTANT: to return any property of an object, the property must be public, to be returned with the "get\_object\_vars" function, or a function with the name "getVars" must be defined, returning an array with the properties that need to be executed \_\_get.

[](#important-to-return-any-property-of-an-object-the-property-must-be-public-to-be-returned-with-the-get_object_vars-function-or-a-function-with-the-name-getvars-must-be-defined-returning-an-array-with-the-properties-that-need-to-be-executed-__get)

#### Models\\User.php

[](#modelsuserphp)

```
namespace Model;

class User{
    public string $name = '';
    private string $lastname = 'Azevedo';
    private string $testValue = '123';

    public array $data = [];

    public function __construct()
    {
        $this->data = ['email','password','birth','username','testValue'];
    }

    public function getVars(): array
    {
        $vars = [];
        foreach($this->data as $var => $value){
            $vars[$var] = null;
        }
        return $vars;
    }

    public function __set(string $field, $value)
    {
        $this->data[$field] = $value;
    }

    public function __get(string $field)
    {
        return $this->data[$field];
    }
}
```

#### Example\\User.php

[](#exampleuserphp)

```
$user = new Model\User();

$user->name = 'Henri';
$user->email = 'hnr.azevedo@gmail.com';
$user->birth = '28/09/1996';
$user->username = 'hnrazevedo';
$user->testValue = '321';

Viewer::path(__DIR__.'/Views/')->render('default', ['user'=>$user]);
```

#### default.view.php

[](#defaultviewphp)

```
{{ $user.name }} -> execute $user->name -> $user->name
{{ $user.email }} -> execute $user->email -> $user->__get('email')
{{ $user.bitrh }} -> execute $user->bitrh -> $user->__get('bitrh')
{{ $user.username }} -> execute $user->bitrh -> $user->__get('username')
{{ $user.lastname }} -> It is not executed, as private properties are not returned in the "get_object_vars" function
{{ $user.testValue }} -> execute $user->testValue -> $user->__get('testValue')
```

#### Result of default.view.php

[](#result-of-defaultviewphp)

```
Henri Azevedo
hnr.azevedo@gmail.com
28/09/1996
hnrazevedo
{{ $user.lastname }}
321
```

### Import content within the view.

[](#import-content-within-the-view)

### NOTE: File extension inc.php

[](#note-file-extension-incphp)

### NOTE: File path is from the defined view path in question

[](#note-file-path-is-from-the-defined-view-path-in-question)

```

        import('../Imports/header'); ?>

            ...

        import('../Imports/footer'); ?>

```

### If the file is not found, in order to avoid a page break, a div results with an error message instead of include.

[](#if-the-file-is-not-found-in-order-to-avoid-a-page-break-a-div-results-with-an-error-message-instead-of-include)

Caso o arquivo não seja encontrado, para não haver quebra de página, é resultado uma div com a mensagem de erro no lugar do include.

```

        Component error: Impotation file does not exist: header.inc.php .

            ...

            ...

```

HTML compression
----------------

[](#html-compression)

### All code returned from a view or include is compressed. Thus, to avoid code problems, all comments are ignored when rendering the content.

[](#all-code-returned-from-a-view-or-include-is-compressed-thus-to-avoid-code-problems-all-comments-are-ignored-when-rendering-the-content)

Todo código retornado de uma view ou include é compressado. Com isto, para evitar problemas de código, todos os comentários são ignorados na renderização do conteúdo.

#### Source code

[](#source-code)

```

             ...

            ...

        ...; // Single line comment
        /* comments */ ...; /* comments */
        /*
            Multi-line
            commnets
        */
        ...;

```

#### Rendered code

[](#rendered-code)

```
.........;...;...;
```

Support
-------

[](#support)

###### Security: If you discover any security related issues, please email  instead of using the issue tracker.

[](#security-if-you-discover-any-security-related-issues-please-email-hnrazevedogmailcom-instead-of-using-the-issue-tracker)

Se você descobrir algum problema relacionado à segurança, envie um e-mail para  em vez de usar o rastreador de problemas.

Credits
-------

[](#credits)

- [Henri Azevedo](https://github.com/hnrazevedo) (Developer)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/hnrazevedo/Viewer/blob/master/LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Recently: every ~14 days

Total

22

Last Release

1992d ago

Major Versions

v1.3.7 → v2.0.02020-10-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/b13ce2d74efc0fe548fc01fa5334a00d9f836a65f42f18c64d3129f7bf1495e3?d=identicon)[hnrazevedo](/maintainers/hnrazevedo)

---

Top Contributors

[![hnrazevedo](https://avatars.githubusercontent.com/u/56831533?v=4)](https://github.com/hnrazevedo "hnrazevedo (45 commits)")

### Embed Badge

![Health badge](/badges/hnrazevedo-viewer/health.svg)

```
[![Health](https://phpackages.com/badges/hnrazevedo-viewer/health.svg)](https://phpackages.com/packages/hnrazevedo-viewer)
```

###  Alternatives

[ishanvyas22/asset-mix

Asset Mix plugin for CakePHP

3375.4k2](/packages/ishanvyas22-asset-mix)[prgayman/laravel-zatca

Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

2926.9k1](/packages/prgayman-laravel-zatca)[ducks-project/spl-types

Polyfill Module for SplType PHP extension. This extension aims at helping people making PHP a stronger typed language and can be a good alternative to scalar type hinting. It provides different typehandling classes as such as integer, float, bool, enum and string

1032.4k](/packages/ducks-project-spl-types)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
