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

Commit

Permalink
Merging develop to master in preparation for 2.11.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 6, 2018
2 parents 8c36d2a + 4b284f2 commit fe669f5
Show file tree
Hide file tree
Showing 25 changed files with 444 additions and 116 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.11.0 - 2018-12-06

### Added

- [#168](https://github.com/zendframework/zend-view/pull/168) adds two new methods to `Zend\View\Helper\Placeholder` (and thus any
helper extending it):

- `deleteContainer(string $name)` can be used to delete a placeholder container.
- `clearContainers()` can be used to clear all placeholder containers.

These new features are particularly useful when in long-running server
environments, such as Swoole, where you may need to clear the contents on each
request.

### Changed

- [#155](https://github.com/zendframework/zend-view/pull/155) modifies the `Zend\View\Helper\Service\IdentifyFactory` such that it will
now also look for the service `Zend\Authentication\AuthenticationServiceInterface`
if the service `Zend\Authentication\AuthenticationService` is not found. This
allows using a service named after the interface instead of the
implementation if desired.

- [#158](https://github.com/zendframework/zend-view/pull/158) modifies how a `ViewModel` (and all extensions) is cloned; the `$variables`
property, if it is an object, is now cloned as well to ensure changes in the
new instance do not affect the current one.

- [#153](https://github.com/zendframework/zend-view/pull/153) updates the `ConsoleModel::setErrorLevel()` method to implement a fluent
interface.

### Deprecated

- Nothing.

### Removed

- [#147](https://github.com/zendframework/zend-view/pull/147) removes the property `$regKey` from a number of helpers; these were a
remnant of ZF1, and have not been used internally since the initial 2.0.0
release.

### Fixed

- [#164](https://github.com/zendframework/zend-view/pull/164) fixes the various `Head*` view helpers such that they will now properly
escape attributes as HTML attributes (instead of as HTML content).

## 2.10.1 - 2018-12-06

### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.10.x-dev",
"dev-develop": "2.11.x-dev"
"dev-master": "2.11.x-dev",
"dev-develop": "2.12.x-dev"
}
},
"autoload-dev": {
Expand Down
6 changes: 5 additions & 1 deletion doc/book/helpers/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The `Identity` helper allows retrieving the identity from the
`AuthenticationService`.

For the `Identity` helper to work, a `Zend\Authentication\AuthenticationService`
name or alias must be defined and recognized by the `ServiceManager`.
or `Zend\Authentication\AuthenticationServiceInterface` name or alias must be
defined and recognized by the `ServiceManager`.

`Identity` returns the identity discovered in the `AuthenticationService`, or
`null` if no identity is available.
Expand Down Expand Up @@ -43,3 +44,6 @@ return [
],
];
```

If that service is not registered, the plugin will then look for a service named
`Zend\Authentication\AuthenticationServiceInterface`, and use that if found.
20 changes: 19 additions & 1 deletion doc/book/helpers/placeholder.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $this->placeholder('foo')
<?= $this->placeholder('foo') ?>
```

The above results in an unodered list with pretty indentation.
The above results in an unordered list with pretty indentation.

Because the `Placeholder` container objects extend `ArrayObject`, you can also
assign content to a specific key in the container easily, instead of simply
Expand Down Expand Up @@ -131,6 +131,24 @@ foreach ($this->data as $datum): ?>
<?= $this->placeholder('foo')->data ?>
```

## Clearing Content

In certain situations it is desirable to remove or clear containers and
aggregated content. The placeholder view helper provides two methods to either
delete a specific container or clear all containers at once:

### Delete a single container

```php
$this->plugin('placeholder')->deleteContainer('myNamedContainer');
```

### Clear all containers

```php
$this->plugin('placeholder')->clearContainers();
```

## Concrete Implementations

zend-view ships with a number of "concrete" placeholder implementations. These
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/AbstractHtmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function htmlAttribs($attribs)
foreach ((array) $attribs as $key => $val) {
$key = $escaper($key);

if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) {
if (0 === strpos($key, 'on') || ('constraints' == $key)) {
// Don't escape event attributes; _do_ substitute double quotes with singles
if (! is_scalar($val)) {
// non-scalar data should be cast to JSON first
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function htmlAttribs($attribs)
*/
protected function normalizeId($value)
{
if (strstr($value, '[')) {
if (false !== strpos($value, '[')) {
if ('[]' == substr($value, -2)) {
$value = substr($value, 0, strlen($value) - 2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Doctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __invoke($doctype = null)
$this->setDoctype($doctype);
break;
default:
if (substr($doctype, 0, 9) != '<!DOCTYPE') {
if (0 !== strpos($doctype, '<!DOCTYPE')) {
throw new Exception\DomainException('The specified doctype is malformed');
}
if (stristr($doctype, 'xhtml')) {
Expand Down
16 changes: 6 additions & 10 deletions src/Helper/HeadLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\View\Helper;

use stdClass;
use Zend\View;
use Zend\View\Exception;

// @codingStandardsIgnoreStart
Expand Down Expand Up @@ -55,13 +54,6 @@ class HeadLink extends Placeholder\Container\AbstractStandalone
'as',
];

/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_HeadLink';

/**
* Constructor
*
Expand Down Expand Up @@ -302,13 +294,17 @@ public function itemToString(stdClass $item)
if (isset($attributes[$itemKey])) {
if (is_array($attributes[$itemKey])) {
foreach ($attributes[$itemKey] as $key => $value) {
$link .= sprintf(' %s="%s"', $key, ($this->autoEscape) ? $this->escape($value) : $value);
$link .= sprintf(
' %s="%s"',
$key,
($this->autoEscape) ? $this->escapeAttribute($value) : $value
);
}
} else {
$link .= sprintf(
' %s="%s"',
$itemKey,
($this->autoEscape) ? $this->escape($attributes[$itemKey]) : $attributes[$itemKey]
($this->autoEscape) ? $this->escapeAttribute($attributes[$itemKey]) : $attributes[$itemKey]
);
}
}
Expand Down
13 changes: 3 additions & 10 deletions src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ class HeadMeta extends Placeholder\Container\AbstractStandalone
*/
protected $modifierKeys = ['lang', 'scheme'];

/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_HeadMeta';

/**
* Constructor
*
Expand Down Expand Up @@ -250,7 +243,7 @@ public function itemToString(stdClass $item)
if (! in_array($key, $this->modifierKeys)) {
continue;
}
$modifiersString .= $key . '="' . $this->escape($value) . '" ';
$modifiersString .= $key . '="' . $this->escapeAttribute($value) . '" ';
}

$modifiersString = rtrim($modifiersString);
Expand Down Expand Up @@ -278,8 +271,8 @@ public function itemToString(stdClass $item)
$meta = sprintf(
$tpl,
$type,
$this->escape($item->$type),
$this->escape($item->content),
$this->escapeAttribute($item->$type),
$this->escapeAttribute($item->content),
$modifiersString
);

Expand Down
16 changes: 6 additions & 10 deletions src/Helper/HeadScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\View\Helper;

use stdClass;
use Zend\View;
use Zend\View\Exception;

/**
Expand All @@ -36,13 +35,6 @@ class HeadScript extends Placeholder\Container\AbstractStandalone
const FILE = 'FILE';
const SCRIPT = 'SCRIPT';

/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_HeadScript';

/**
* Are arbitrary attributes allowed?
*
Expand Down Expand Up @@ -399,7 +391,11 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
if ('async' == $key) {
$value = 'async';
}
$attrString .= sprintf(' %s="%s"', $key, ($this->autoEscape) ? $this->escape($value) : $value);
$attrString .= sprintf(
' %s="%s"',
$key,
($this->autoEscape) ? $this->escapeAttribute($value) : $value
);
}
}

Expand All @@ -409,7 +405,7 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
if (empty($item->type) && $this->view && $this->view->plugin('doctype')->isHtml5()) {
$html = '<script ' . $attrString . '>';
} else {
$type = ($this->autoEscape) ? $this->escape($item->type) : $item->type;
$type = ($this->autoEscape) ? $this->escapeAttribute($item->type) : $item->type;
$html = '<script type="' . $type . '"' . $attrString . '>';
}
if (! empty($item->source)) {
Expand Down
7 changes: 0 additions & 7 deletions src/Helper/HeadStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
*/
class HeadStyle extends Placeholder\Container\AbstractStandalone
{
/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_HeadStyle';

/**
* Allowed optional attributes
*
Expand Down
7 changes: 0 additions & 7 deletions src/Helper/HeadTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class HeadTitle extends Placeholder\Container\AbstractStandalone
{
use TranslatorAwareTrait;

/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_HeadTitle';

/**
* Default title rendering order (i.e. order in which each title attached)
*
Expand Down
7 changes: 0 additions & 7 deletions src/Helper/InlineScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
*/
class InlineScript extends HeadScript
{
/**
* Registry key for placeholder
*
* @var string
*/
protected $regKey = 'Zend_View_Helper_InlineScript';

/**
* Return InlineScript object
*
Expand Down
24 changes: 23 additions & 1 deletion src/Helper/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Placeholder extends AbstractHelper
/**
* Placeholder items
*
* @var array
* @var Container\AbstractContainer[]
*/
protected $items = [];

Expand Down Expand Up @@ -97,4 +97,26 @@ public function containerExists($key)
$return = array_key_exists($key, $this->items);
return $return;
}

/**
* Delete a specific container by name
*
* @param string $key
* @return void
*/
public function deleteContainer($key)
{
$key = (string) $key;
unset($this->items[$key]);
}

/**
* Remove all containers
*
* @return void
*/
public function clearContainers()
{
$this->items = [];
}
}
18 changes: 11 additions & 7 deletions src/Helper/Placeholder/Container/AbstractStandalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,20 @@ public function toString()
*/
protected function escape($string)
{
if ($this->getView() instanceof RendererInterface
&& method_exists($this->getView(), 'getEncoding')
) {
$escaper = $this->getView()->plugin('escapeHtml');
return $escaper((string) $string);
}

return $this->getEscaper()->escapeHtml((string) $string);
}

/**
* Escape an attribute value
*
* @param string $string
* @return string
*/
protected function escapeAttribute($string)
{
return $this->getEscaper()->escapeHtmlAttr((string) $string);
}

/**
* Set whether or not auto escaping should be used
*
Expand Down
Loading

0 comments on commit fe669f5

Please sign in to comment.