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

Commit 895f222

Browse files
committed
move isXhtml with type = charset check in HeadMeta::isValid() and call isValid() in HeadMeta::setCharset() before set()
1 parent b80a013 commit 895f222

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Helper/HeadMeta.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ protected function normalizeType($type)
323323
* Determine if item is valid
324324
*
325325
* @param mixed $item
326+
* @throws Exception\RuntimeException
326327
* @return bool
327328
*/
328329
protected function isValid($item)
@@ -334,22 +335,27 @@ protected function isValid($item)
334335
return false;
335336
}
336337

338+
$doctype = $this->view->plugin('doctype');
339+
if ($item->type === 'charset' && $doctype->isXhtml()) {
340+
throw new Exception\RuntimeException('XHTML* doctype has no attribute charset; please use appendHttpEquiv()');
341+
}
342+
337343
if (! isset($item->content)
338-
&& (! $this->view->plugin('doctype')->isHtml5()
339-
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))
344+
&& (! $doctype->isHtml5()
345+
|| (! $doctype->isHtml5() && $item->type !== 'charset'))
340346
) {
341347
return false;
342348
}
343349

344350
// <meta itemprop= ... /> is only supported with doctype html
345-
if (! $this->view->plugin('doctype')->isHtml5()
351+
if (! $doctype->isHtml5()
346352
&& $item->type === 'itemprop'
347353
) {
348354
return false;
349355
}
350356

351357
// <meta property= ... /> is only supported with doctype RDFa
352-
if (! $this->view->plugin('doctype')->isRdfa()
358+
if (! $doctype->isRdfa()
353359
&& $item->type === 'property'
354360
) {
355361
return false;
@@ -458,20 +464,17 @@ public function set($value)
458464
* Not valid in a non-HTML5 doctype
459465
*
460466
* @param string $charset
461-
* @throws Exception\RuntimeException
467+
* @param Exception\RuntimeException
462468
* @return HeadMeta Provides a fluent interface
463469
*/
464470
public function setCharset($charset)
465471
{
466-
if ($this->view->plugin('doctype')->isXhtml()) {
467-
throw new Exception\RuntimeException('XHTML* doctype has no attribute charset');
468-
}
469-
470472
$item = new stdClass;
471473
$item->type = 'charset';
472474
$item->charset = $charset;
473475
$item->content = null;
474476
$item->modifiers = [];
477+
$this->isValid($item);
475478
$this->set($item);
476479

477480
return $this;

test/Helper/HeadMetaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function testCharsetPosition()
443443
public function testCarsetWithXhtmlDoctypeGotException()
444444
{
445445
$this->expectException(Exception\RuntimeException::class);
446-
$this->expectExceptionMessage('XHTML* doctype has no attribute charset');
446+
$this->expectExceptionMessage('XHTML* doctype has no attribute charset; please use appendHttpEquiv()');
447447

448448
$view = new View();
449449
$view->plugin('doctype')->__invoke('XHTML1_RDFA');

0 commit comments

Comments
 (0)