Download the PHP package jakesee/slim-template-response without Composer

On this page you can find all versions of the php package jakesee/slim-template-response. 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 slim-template-response

Slim-Template-Response

A Slim Framework add-on that allows deferred parsing and rendering of template so that template data can be examined or modified.

Install

composer require jakesee/slim-template-response ^1.0.1

Detailed Explanation

Due to the way Slim Framework is designed, the templating engines suggested by Slim Framework all write directly to the ResponseInterface stream directly in the controller, as such, there is no way to examine the template data variables or modify them after the controller exits, for example, during the outgoing middleware pathway. For this reason, this Slim-Template-Response adds a simple way to hold the template variables until the very end before finally writing the data to the stream.

Without modifying how Slim works, we can use the following to defer the writing:

$app->respond($app->run(true)->render());

instead of

$app->run();

Middleware

As a result, you can modify the template variables in any middleware after the controller exits:

class MyMiddleware
{
    function __invoke($request, $response, $next)
    {
        // incoming loop
        ...

        // call the next middleware
        $response = $next($request, $response);

        // controller is called eventually and returns:
        // return $response->withTemplate(...);

        // outgoing loop, modify template data
        $response->getTemplate()->data['total'] = 50;

        return $response;
    }
}

Unit Testing

In unit testing you can now also test the results directly by examining the data variables

function testDisplayTotal()
{
    // setup ...

    // Run Slim App
    $response = $app($request, $response);

    // Get the template data
    $data = $response->getTemplate()->data;

    $this->assertEquals(50, $data['total']);
}

Usage

This addon consists of a Response class (which is extended from the Slim Response class) and a Template class. Simply inject the Response class into the dependency container so that Slim App will use our extended Response class.

$app = new \Slim\App(); // default Slim Response is initialized by this constructor
$container = $app->getContainer();

// We just replace the Response object by injecting our extended Response into the container
$container['response'] = function($container) {

    // This is how Slim sets up the default Response object in vendor/slim/slim/Slim/DefaultServicesProvide.php.
    // We simply replicate it here as closely as possible.
    $headers = new \Slim\Http\Headers(['Content-Type' => 'text/html; charset=UTF-8']);
    $template = new \Braincase\Slim\Template($container, __DIR__ . '/../resources/views/');
    $response = new \Braincase\Slim\Response($template, 200, $headers);

    return $response->withProtocolVersion($container->get('settings')['httpVersion']);
};

// create a route
$app->get('/test', function($request, $response) {
    $response->withTemplate('default.php', [
        'firstName' => 'Jake',
        'lastName' => 'See'
    ]);
});

The Template class uses plain PHP for templating and does not have advance features like Twig or Blade, but it is possible to use your own Template class as long as your Template class implements the TemplateInterface.

Compatibility

This works with Slim Framework 3 at this time of writing. There is a Slim Framework 4 upcoming and I have not tested against the newer versions.


All versions of slim-template-response with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.4
slim/slim Version ^3.8
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 jakesee/slim-template-response contains the following files

Loading the files please wait ....