Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'cache_internals' of https://github.com/marc-mabe/zf2 in…
Browse files Browse the repository at this point in the history
…to hotfix/cache-internals
  • Loading branch information
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 125 deletions.
53 changes: 34 additions & 19 deletions src/Helper/Doctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
namespace Zend\View\Helper;

use Zend\View\Exception;
use Zend\View\Exception,
Zend\Registry,
ArrayObject;

/**
* Helper for setting and retrieving the doctype
Expand All @@ -44,6 +46,7 @@ class Doctype extends AbstractHelper
* DocType constants
*/
const XHTML11 = 'XHTML11';
const XHTML1_RDFA1 = 'XHTML_RDFA1';
const XHTML1_STRICT = 'XHTML1_STRICT';
const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
Expand All @@ -65,7 +68,7 @@ class Doctype extends AbstractHelper

/**
* Registry containing current doctype and mappings
* @var ArrayObject
* @var \ArrayObject
*/
protected $_registry;

Expand All @@ -79,15 +82,14 @@ class Doctype extends AbstractHelper
* Constructor
*
* Map constants to doctype strings, and set default doctype
*
* @return void
*/
public function __construct()
{
if (!\Zend\Registry::isRegistered($this->_regKey)) {
$this->_registry = new \ArrayObject(array(
if (!Registry::isRegistered($this->_regKey)) {
$this->_registry = new ArrayObject(array(
'doctypes' => array(
self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
self::XHTML1_RDFA1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
Expand All @@ -99,25 +101,27 @@ public function __construct()
self::HTML5 => '<!DOCTYPE html>',
)
));
\Zend\Registry::set($this->_regKey, $this->_registry);

Registry::set($this->_regKey, $this->_registry);
$this->setDoctype($this->_defaultDoctype);
} else {
$this->_registry = \Zend\Registry::get($this->_regKey);
$this->_registry = Registry::get($this->_regKey);
}
}

/**
* Set or retrieve doctype
*
* @param string $doctype
* @return \Zend\View\Helper\Doctype
* @return Doctype Provides a fluent interface
* @throws Exception\DomainException
*/
public function __invoke($doctype = null)
{
if (null !== $doctype) {
switch ($doctype) {
case self::XHTML11:
case self::XHTML1_RDFA1:
case self::XHTML1_STRICT:
case self::XHTML1_TRANSITIONAL:
case self::XHTML1_FRAMESET:
Expand Down Expand Up @@ -151,7 +155,7 @@ public function __invoke($doctype = null)
* Set doctype
*
* @param string $doctype
* @return \Zend\View\Helper\Doctype
* @return Doctype
*/
public function setDoctype($doctype)
{
Expand Down Expand Up @@ -188,15 +192,26 @@ public function isXhtml()
{
return (stristr($this->getDoctype(), 'xhtml') ? true : false);
}

/**
* Is doctype HTML5? (HeadMeta uses this for validation)
*
* @return booleean
*/
public function isHtml5() {
return (stristr($this->__invoke(), '<!DOCTYPE html>') ? true : false);
}

/**
* Is doctype HTML5? (HeadMeta uses this for validation)
*
* @return boolean
*/
public function isHtml5()
{
return (stristr($this->__invoke(), '<!DOCTYPE html>') ? true : false);
}

/**
* Is doctype RDFa?
*
* @return boolean
*/
public function isRdfa()
{
return (stristr($this->getDoctype(), 'rdfa') ? true : false);
}

/**
* String representation of doctype
Expand Down
32 changes: 16 additions & 16 deletions src/Strategy/FeedStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class FeedStrategy implements ListenerAggregate

/**
* Constructor
*
* @param FeedRenderer $renderer
*
* @param FeedRenderer $renderer
* @return void
*/
public function __construct(FeedRenderer $renderer)
Expand All @@ -62,21 +62,21 @@ public function __construct(FeedRenderer $renderer)

/**
* Attach the aggregate to the specified event manager
*
* @param EventCollection $events
* @param int $priority
*
* @param EventCollection $events
* @param int $priority
* @return void
*/
public function attach(EventCollection $events, $priority = 1)
{
$this->listeners[] = $events->attach('renderer', array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach('response', array($this, 'injectResponse'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RENDERER, array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RESPONSE, array($this, 'injectResponse'), $priority);
}

/**
* Detach aggregate listeners from the specified event manager
*
* @param EventCollection $events
*
* @param EventCollection $events
* @return void
*/
public function detach(EventCollection $events)
Expand All @@ -89,10 +89,10 @@ public function detach(EventCollection $events)
}

/**
* Detect if we should use the FeedRenderer based on model type and/or
* Detect if we should use the FeedRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
*
* @param ViewEvent $e
* @return null|FeedRenderer
*/
public function selectRenderer(ViewEvent $e)
Expand Down Expand Up @@ -133,8 +133,8 @@ public function selectRenderer(ViewEvent $e)

/**
* Inject the response with the feed payload and appropriate Content-Type header
*
* @param ViewEvent $e
*
* @param ViewEvent $e
* @return void
*/
public function injectResponse(ViewEvent $e)
Expand All @@ -155,10 +155,10 @@ public function injectResponse(ViewEvent $e)
if ($result instanceof Feed) {
$result = $result->export($renderer->getFeedType());
}

// Get the content-type header based on feed type
$feedType = $renderer->getFeedType();
$feedType = ('rss' == $feedType)
$feedType = ('rss' == $feedType)
? 'application/rss+xml'
: 'application/atom+xml';

Expand Down
24 changes: 12 additions & 12 deletions src/Strategy/JsonStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class JsonStrategy implements ListenerAggregate

/**
* Constructor
*
* @param JsonRenderer $renderer
*
* @param JsonRenderer $renderer
* @return void
*/
public function __construct(JsonRenderer $renderer)
Expand All @@ -61,21 +61,21 @@ public function __construct(JsonRenderer $renderer)

/**
* Attach the aggregate to the specified event manager
*
* @param EventCollection $events
*
* @param EventCollection $events
* @param int $priority
* @return void
*/
public function attach(EventCollection $events, $priority = 1)
{
$this->listeners[] = $events->attach('renderer', array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach('response', array($this, 'injectResponse'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RENDERER, array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RESPONSE, array($this, 'injectResponse'), $priority);
}

/**
* Detach aggregate listeners from the specified event manager
*
* @param EventCollection $events
*
* @param EventCollection $events
* @return void
*/
public function detach(EventCollection $events)
Expand All @@ -90,8 +90,8 @@ public function detach(EventCollection $events)
/**
* Detect if we should use the JsonRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
*
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
Expand Down Expand Up @@ -126,8 +126,8 @@ public function selectRenderer(ViewEvent $e)

/**
* Inject the response with the JSON payload and appropriate Content-Type header
*
* @param ViewEvent $e
*
* @param ViewEvent $e
* @return void
*/
public function injectResponse(ViewEvent $e)
Expand Down
34 changes: 17 additions & 17 deletions src/Strategy/PhpRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PhpRendererStrategy implements ListenerAggregate

/**
* Placeholders that may hold content
*
*
* @var array
*/
protected $contentPlaceholders = array('article', 'content');
Expand All @@ -57,8 +57,8 @@ class PhpRendererStrategy implements ListenerAggregate

/**
* Constructor
*
* @param PhpRenderer $renderer
*
* @param PhpRenderer $renderer
* @return void
*/
public function __construct(PhpRenderer $renderer)
Expand All @@ -68,7 +68,7 @@ public function __construct(PhpRenderer $renderer)

/**
* Retrieve the composed renderer
*
*
* @return PhpRenderer
*/
public function getRenderer()
Expand All @@ -87,7 +87,7 @@ public function setContentPlaceholders(array $contentPlaceholders)
$this->contentPlaceholders = $contentPlaceholders;
return $this;
}

/**
* Get list of possible content placeholders
*
Expand All @@ -100,21 +100,21 @@ public function getContentPlaceholders()

/**
* Attach the aggregate to the specified event manager
*
* @param EventCollection $events
*
* @param EventCollection $events
* @param int $priority
* @return void
*/
public function attach(EventCollection $events, $priority = 1)
{
$this->listeners[] = $events->attach('renderer', array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach('response', array($this, 'injectResponse'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RENDERER, array($this, 'selectRenderer'), $priority);
$this->listeners[] = $events->attach(ViewEvent::EVENT_RESPONSE, array($this, 'injectResponse'), $priority);
}

/**
* Detach aggregate listeners from the specified event manager
*
* @param EventCollection $events
*
* @param EventCollection $events
* @return void
*/
public function detach(EventCollection $events)
Expand All @@ -127,10 +127,10 @@ public function detach(EventCollection $events)
}

/**
* Select the PhpRenderer; typically, this will be registered last or at
* Select the PhpRenderer; typically, this will be registered last or at
* low priority.
*
* @param ViewEvent $e
*
* @param ViewEvent $e
* @return PhpRenderer
*/
public function selectRenderer(ViewEvent $e)
Expand All @@ -142,9 +142,9 @@ public function selectRenderer(ViewEvent $e)
* Populate the response object from the View
*
* Populates the content of the response object from the view rendering
* results.
*
* @param ViewEvent $e
* results.
*
* @param ViewEvent $e
* @return void
*/
public function injectResponse(ViewEvent $e)
Expand Down
Loading

0 comments on commit 555b02b

Please sign in to comment.