PHPackages                             merophp/view-engine - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. merophp/view-engine

ActiveLibrary[HTTP &amp; Networking](/categories/http)

merophp/view-engine
===================

Simple plugin based view engine for complexity hiding.

0.1-alpha(4y ago)0374↓50%6MITPHPPHP &gt;=7.4

Since Dec 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Merophp/view-engine)[ Packagist](https://packagist.org/packages/merophp/view-engine)[ RSS](/packages/merophp-view-engine/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (6)

Introduction
============

[](#introduction)

Easy to use view engine with complexity hiding for view plugins.

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

[](#installation)

Via composer:

`composer require merophp/view-engine`Basic Usage
-----------

[](#basic-usage)

To use the view engine you have to create or use external view plugins.

Example:

```
require_once 'vendor/autoload.php';

use MyPackage\HtmlPlugin\HtmlView;
use MyPackage\TextPlugin\TextView;
use MyPackage\JsonPlugin\JsonView;
use MyPackage\TemplatePlugin\TemplateView;
use MyPackage\TemplatePlugin\TemplateViewConfiguration;

use Merophp\ViewEngine\ViewEngine;
use Merophp\ViewEngine\ViewPlugin\Collection\ViewPluginCollection;
use Merophp\ViewEngine\ViewPlugin\Provider\ViewPluginProvider;
use Merophp\ViewEngine\ViewPlugin\ViewPlugin;

$templateViewConfiguration = new TemplateViewConfiguration();
$templateViewConfiguration->setViewDir('.');

$collection = new ViewPluginCollection();
$collection->addMultiple([
    new ViewPlugin(TextView::class),
    new ViewPlugin(HtmlView::class),
    new ViewPlugin(JsonView::class),
    new ViewPlugin(TemplateView::class, $templateViewConfiguration)
]);

$provider = new ViewPluginProvider($collection);

$viewEngine = new ViewEngine($provider);

$view = $viewEngine->initializeView();
$view->json(['test' => 1]);
echo $viewEngine->renderView($view);

```

### View Proxy

[](#view-proxy)

The view engine uses a proxy for view classes. The specialty is that you get a view proxy instance without a real view by calling *$viewEngine-&gt;initializeView()*. The view to wrap will be determined by the next called method.

For Example:

```
$view = $viewEngine->initializeView();
echo $view->getViewType(); //Will print 'undefined'
$view->json(['test' => 1]);
echo $view->getViewType(); //Will print 'Json'
echo $viewEngine->renderView($view);

```

Once determined the view type can not be changed for that instance.

### View Plugins

[](#view-plugins)

A view plugin consists at minimum of a view class that implements Merophp\\ViewEngine\\ViewPlugin\\ViewInterface and has at least one public non-magic &amp; non-static method tagged with *@api*.

```
use Merophp\ViewEngine\ViewPlugin\ViewInterface;

class DummyView implements ViewInterface{

    public function render(): string
    {
        return 'test';
    }

    /**
     * Method calls are forwarded by the view proxy
     * @param $value
     * @api
     */
    public function dummy($value)
    {
        return 'foo';
    }

    /**
     * Method calls are not forwarded by the view proxy due to their static type
     * @param $value
     * @api
     */
    public static function dummy2($value)
    {
        echo 'foo';
    }

    public function getContentType(): string
    {
        return '';
    }
}

```

The Aim
=======

[](#the-aim)

The aim is to use the view engine as part of a framework to simplify the creation of views for the framework users. So you can provide an empty view proxy instance inside a controller action so the user can choose between some view types by calling methods on the proxy instance.

Be Aware of the Cons
--------------------

[](#be-aware-of-the-cons)

Cause of the mechanic it isn't possible to use IDE functionality such as auto-fill or interface hints. In some cases, it also can be a little confusing cause of the dynamic interface of the proxy. As a framework developer using this library, you should document the possible view interfaces of the proxy well.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Unknown

Total

1

Last Release

1608d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f873869f98cb1bdf9edb5847f987dfd216e5bc44f934d87875dca5ee20fbefb?d=identicon)[Robert.Becker](/maintainers/Robert.Becker)

---

Tags

httpview

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/merophp-view-engine/health.svg)

```
[![Health](https://phpackages.com/badges/merophp-view-engine/health.svg)](https://phpackages.com/packages/merophp-view-engine)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[php-http/httplug

HTTPlug, the HTTP client abstraction for PHP

2.6k307.6M679](/packages/php-http-httplug)[psr/http-client

Common interface for HTTP clients

1.7k680.7M2.1k](/packages/psr-http-client)[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.0k314.0M3.4k](/packages/symfony-http-client)

PHPackages © 2026

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