Skip to content

Commit

Permalink
merge release/v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hummer2k committed Mar 26, 2016
2 parents 5b79dee + 217c7b5 commit 0145583
Show file tree
Hide file tree
Showing 40 changed files with 796 additions and 271 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
- composer self-update
- composer update --prefer-source
- composer update --prefer-dist

script:
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- ./vendor/bin/phpcs --standard=PSR2 ./src/
- ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/

after_script:
- ./vendor/bin/coveralls -v

matrix:
allow_failures:
- php: 7.0
- php: hhvm
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Develop:

Install via composer:

`$ composer require hummerk2/convarnish:dev-master`
`$ composer require hummerk2/convarnish:~2.0`

Enable module in your application.config.php

Expand All @@ -28,5 +28,5 @@ $config = [
];
````

Copy `vendor/hummer2k/convarnish/config/con-varnish.config.php.dist` to
Copy `convarnish/config/con-varnish.config.php.dist` to
`config/autoload/con-varnish.global.php`
24 changes: 17 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@
}
],
"require": {
"php": ">=5.4.0",
"zendframework/zendframework": "2.*",
"hummer2k/conlayout": "~1.1"
"php": ">=5.5.0",
"zendframework/zend-mvc": "2.*",
"zendframework/zend-eventmanager": "2.*",
"zendframework/zend-modulemanager": "2.*",
"zendframework/zend-servicemanager": "2.*",
"zendframework/zend-view": "2.*",
"zendframework/zend-console": "2.*"
},
"require-dev": {
"zendframework/zend-developer-tools": "dev-master",
"phpunit/phpunit": "4.5.0",
"squizlabs/php_codesniffer": "1.4.*",
"satooshi/php-coveralls": "~0.6"
"zendframework/zend-serializer": "2.*",
"zendframework/zend-log": "2.*",
"zendframework/zend-i18n": "2.*",
"hummer2k/conlayout": "3.*",
"satooshi/php-coveralls": "~0.6",
"squizlabs/php_codesniffer": "~2.0",
"phpunit/phpunit": "4.*"
},
"suggest": {
"hummer2k/conlayout": "To use ESI processing feature."
},
"autoload": {
"psr-0": {
Expand Down
61 changes: 42 additions & 19 deletions config/con-varnish.global.php.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
return [
'varnish' => [
/**
* deny: do not cache if no match
*/
'policy' => \ConVarnish\Options\VarnishOptions::POLICY_DENY,
/**
* enable caching
*/
Expand All @@ -10,7 +14,7 @@ return [
*/
'use_esi' => false,
/**
* default ttl when no specified in 'cacheable_routes'
* default ttl if policy == allow
*/
'default_ttl' => 14400,
/**
Expand All @@ -23,28 +27,47 @@ return [
'servers' => [
'default' => [
'ip' => '127.0.0.1',
'port' => 80
'port' => 6081
]
],
/**
* list of uncacheable routes
* set ttl per controller action.
*
* use false as ttl to disable caching for this action *
*
* supports wildcard (*)
*
* [
* 'Application\Controller\Index::view' => 120,
* 'Application\Controller\Index*' => 240,
* 'User\Controller\Account*' => false
* ]
*/
'uncacheable_routes' => [
'application*',
//'home'
],
'cacheable_routes' => [
/**
* format:
*
* routeName => ttl
*
* cache all routes that start with application* for 120 seconds
* 'application*' => 120
*
* cache this route for 1 hour
* 'application/default' => 3600
*/
'cacheable_actions' => [],
/**
* set ttl per matched route name
*
* use false as ttl to disable caching for this route
*
* suports wildcard (*)
*
* [
* 'application/default' => 120,
* 'application/*' => 3600,
* 'user/account*' => false
* ]
*/
'cacheable_routes' => [],
/**
* registered caching strategies
*
* [service name => priority]
*/
'caching_strategies' => [
\ConVarnish\Strategy\ActionStrategy::class => 2000,
\ConVarnish\Strategy\RouteStrategy::class => 1500,
\ConVarnish\Strategy\EsiStrategy::class => 1000,
\ConVarnish\Strategy\DefaultStrategy::class => 500
]
]
];
2 changes: 1 addition & 1 deletion config/default-3.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sub vcl_recv {
}

# not cacheable by default
if (req.http.Authorization || req.http.Https) {
if (req.http.Authorization) {
return (pass);
}

Expand Down
5 changes: 2 additions & 3 deletions config/default-4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import std;

backend default {
.host = "localhost";
.port = "8080";
.port = "80";
}

acl ban {
Expand Down Expand Up @@ -62,7 +62,7 @@ sub vcl_recv {
}

# not cacheable by default
if (req.http.Authorization || req.http.Https) {
if (req.http.Authorization) {
return (pass);
}

Expand Down Expand Up @@ -145,6 +145,5 @@ sub vcl_deliver {
set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
set resp.http.Pragma = "no-cache";
set resp.http.Expires = "Mon, 31 Mar 2008 10:00:00 GMT";
set resp.http.Age = "0";
}
}
8 changes: 4 additions & 4 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
],
],
'view_helpers' => [
'factories' => [
'ConVarnish\View\Helper\EsiUrl' => 'ConVarnish\View\Helper\EsiUrlFactory'
'invokables' => [
'ConVarnish\View\Helper\EsiUrl' => 'ConVarnish\View\Helper\EsiUrl'
],
'aliases' => [
'esiUrl' => 'ConVarnish\View\Helper\EsiUrl'
]
],
'controllers' => [
'factories' => [
'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiControllerFactory'
'invokables' => [
'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiController'
]
],
'router' => [
Expand Down
28 changes: 20 additions & 8 deletions config/service.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@

return [
'factories' => [
'ConVarnish\Listener\InjectCacheHeaderListener'
=> 'ConVarnish\Listener\InjectCacheHeaderListenerFactory',
'ConVarnish\Options\VarnishOptions'
=> 'ConVarnish\Options\VarnishOptionsFactory',
'ConVarnish\Service\VarnishService'
=> 'ConVarnish\Service\VarnishServiceFactory',
\ConVarnish\Listener\InjectCacheHeaderListener::class
=> \ConVarnish\Listener\InjectCacheHeaderListenerFactory::class,
\ConVarnish\Service\VarnishService::class
=> \ConVarnish\Service\VarnishServiceFactory::class,
\ConVarnish\Options\VarnishOptions::class
=> \ConVarnish\Options\VarnishOptionsFactory::class,
\ConVarnish\Strategy\DefaultStrategy::class
=> \ConVarnish\Strategy\CachingStrategyFactory::class,
\ConVarnish\Strategy\ActionStrategy::class
=> \ConVarnish\Strategy\CachingStrategyFactory::class,
\ConVarnish\Strategy\RouteStrategy::class
=> \ConVarnish\Strategy\CachingStrategyFactory::class,
\ConVarnish\Strategy\EsiStrategy::class
=> \ConVarnish\Strategy\CachingStrategyFactory::class
],
'invokables' => [
'ConVarnish\Listener\InjectTagsHeaderListener'
=> 'ConVarnish\Listener\InjectTagsHeaderListener'
\ConVarnish\Listener\InjectTagsHeaderListener::class
=> \ConVarnish\Listener\InjectTagsHeaderListener::class
],
'aliases' => [
\ConVarnish\Service\VarnishServiceInterface::class
=> \ConVarnish\Service\VarnishService::class
]
];
21 changes: 21 additions & 0 deletions docs/esi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Edge Side Includes (ESI)

https://en.wikipedia.org/wiki/Edge_Side_Includes

## Example with ConLayout

````xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<reference>
<my.widget>
<esi ttl="120">
<handles handle="application/index/index" />
</esi>
</my.widget>
</reference>
</layout>
````

Note: The `handles` option is only necessary if the block was not defined within the `default` handle.

14 changes: 13 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./tests/Bootstrap.php" colors="true" verbose="true">
<phpunit
bootstrap="./tests/Bootstrap.php"
colors="true"
verbose="true"
backupGlobals = "false"
backupStaticAttributes = "false"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
Expand Down
25 changes: 14 additions & 11 deletions src/ConVarnish/Controller/EsiController.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php
/**
* @package ConVarnish
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
*/

namespace ConVarnish\Controller;

use ConLayout\Controller\Plugin\LayoutManager;
use ConLayout\Generator\BlocksGenerator;
use ConLayout\Handle\Handle;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

/**
* @package ConVarnish
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
*/
class EsiController extends AbstractActionController
{
/**
* return single block for esi processing
*
* @codeCoverageIgnore
* @return ViewModel
*/
public function blockAction()
Expand All @@ -23,12 +26,12 @@ public function blockAction()
/* @var $layoutManager LayoutManager */
$layoutManager = $this->layoutManager();
foreach ($handles as $handle => $priority) {
$layoutManager->addHandle($handle, $priority);
$layoutManager->addHandle(new Handle($handle, $priority));
}
if (!$blockId) {
return $this->blockNotFound($blockId);
}
$layoutManager->load();
$layoutManager->generate([BlocksGenerator::NAME => true]);
if (!$block = $layoutManager->getBlock($blockId)) {
$block = $this->blockNotFound($blockId);
}
Expand All @@ -38,14 +41,14 @@ public function blockAction()
}

/**
*
* @param string $blockName
* @codeCoverageIgnore
* @param string $blockId
* @return ViewModel
*/
protected function blockNotFound($blockName)
protected function blockNotFound($blockId)
{
$viewModel = new ViewModel(array(
'blockName' => $blockName
'blockId' => $blockId
));
$viewModel->setTemplate('con-varnish/block-not-found');
return $viewModel;
Expand Down
19 changes: 0 additions & 19 deletions src/ConVarnish/Controller/EsiControllerFactory.php

This file was deleted.

Loading

0 comments on commit 0145583

Please sign in to comment.