Download the PHP package merophp/view-engine without Composer

On this page you can find all versions of the php package merophp/view-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package view-engine

Introduction

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

Installation

Via composer:

composer require merophp/view-engine

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

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->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

A view plugin consists at minimum of a view class that implements Merophp\ViewEngine\ViewPlugin\ViewInterface and has at least one public non-magic & non-static method tagged with i>@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 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

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.


All versions of view-engine with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-dom Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package merophp/view-engine contains the following files

Loading the files please wait ...