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

Commit af4a5d3

Browse files
committed
Merge pull request #22 from FabianKoestring/patch-async
Added optional attribute 'async'
2 parents 8fe98ad + e60144d commit af4a5d3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Helper/HeadScript.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class HeadScript extends Placeholder\Container\AbstractStandalone
8787
'charset',
8888
'crossorigin',
8989
'defer',
90+
'async',
9091
'language',
9192
'src',
9293
];
@@ -393,6 +394,9 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
393394
if ('defer' == $key) {
394395
$value = 'defer';
395396
}
397+
if ('async' == $key) {
398+
$value = 'async';
399+
}
396400
$attrString .= sprintf(' %s="%s"', $key, ($this->autoEscape) ? $this->escape($value) : $value);
397401
}
398402
}

test/Helper/HeadScriptTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,15 @@ public function testOmitsTypeAttributeIfEmptyValueAndHtml5Doctype()
491491
$test = $this->helper->__invoke()->toString();
492492
$this->assertNotContains('type', $test);
493493
}
494+
495+
public function testSupportsAsyncAttribute()
496+
{
497+
$this->helper->__invoke()->appendScript(
498+
'// some script' . PHP_EOL,
499+
'text/javascript',
500+
['async' => true]
501+
);
502+
$test = $this->helper->__invoke()->toString();
503+
$this->assertContains('async="', $test);
504+
}
494505
}

0 commit comments

Comments
 (0)