knplabs/php-valid

A HTTP cache validation toolkit

dev-master / 0.x-dev 2013-10-15 16:08 UTC

This package is auto-updated.

Last update: 2020-11-04 13:09:41 UTC


README

What

A php 5.3+ library to help manage HTTP/1.1 cache validation headers, using the symfony/HttpFoundation layer.

Why

Because there is no known library that provides a clean, decoupled way to manage them. The actual docs just shows dirty controller examples.

How

By observing requests and asking Rule instances if response has changed since last time client asked, either using If-Modified-Since or ETag headers.

Install

composer require "knplabs/valid=~0.1@dev"

Use

<?php

class CustomRule implements Knp\Valid\Rule\LastModified, Knp\Valid\Rule\ETag
{
    public function supports(Request $request)
    {
        return true;
    }

    public function getETag(Request $request)
    {
        return 'something';
    }

    public function getLastModified(Request $request)
    {
        return new \DateTime;
    }
}

$kernel = new AppCache(
    new Knp\Valid\Kernel(
        new AppKernel('prod', false),
        new Knp\Valid\ResponseManipulator(array(
            new Knp\Valid\Doctrine\ListenerRule,
            new CustomRule,
        ))
    )
);

$kernel->handle(Request::createFromGlobals())->send();

Contribute

composer install --dev --prefer-dist

vim features/**/*.feature
behat
phpspec desc Knp\Valid\*
phpspec run