Download the PHP package kenny1911/twig-view without Composer

On this page you can find all versions of the php package kenny1911/twig-view. 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 twig-view

Twig View

[English][Русский]

A package for typing Twig templates and verifying their correctness during testing.

The Problem

When using Twig templates, errors are often discovered only at runtime because static analyzers cannot effectively verify the correctness of data passed to templates. Common issues include:

The Solution

This package provides a system of typed views that explicitly define data structures for templates, along with tools for testing these views.

Installation

Usage

Describe view class, using View attribute

Creating a view class, that implements View interface

DEPRECATED!!! This method is deprecated. It's recommended to use the View attribute instead.

Twig Template

hello.html.twig:

Rendering a View

Symfony Integration

The package includes an event subscriber for automatic integration with Symfony:

Now when a controller returns a View instance, it will automatically be rendered into a Response:

Testing

Use PHPUnit to verify the correctness of all views:

Testing Recommendations

  1. Use the Real Twig Environment - Tests should use the same Twig\Environment instance as in production

  2. Cover All Data Variants - The iterateViews method should return all possible data combinations for each template

  3. Test Edge Cases - Pay special attention to cases with null values and empty data

  4. Enable strict_variables - This ensures strict variable checking in Twig

Creating a Custom TestCase

In practice, it's recommended to create a base class for testing views that uses the same templates as in production:

Then your view test would look like this:

Benefits

Common Issues and Recommendations

  1. Always Check for null - This is the most common cause of errors in Twig templates
  2. Use strict_variables - Enable this option for strict variable checking
  3. Test All Data Variants - Ensure you cover all possible data states
  4. Use Real Templates - Tests should use the same templates as in production

License

MIT


All versions of twig-view with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
twig/twig Version ^1 || ^2 || ^3
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 kenny1911/twig-view contains the following files

Loading the files please wait ...