- 🇫🇷France andypost
it needs new profiling in a light of https://wiki.php.net/rfc/opt_in_dom_spec_compliance
Drupal\Core\Template\Attribute has become a bit of a God class with too many responsibilities. Move CSS Class parsing code off to its own class and apply some speed improvements to the logic of the class.
This issue ticket was began over two years ago with the Twig rendering system. There are references in the older patches to Twig Environment and the then concurrently being developed assertion system. As of the most recent patch these references are removed. This issue thread is maintained for needed context for the code reviewers. The remaining Twig issues have their own issues.
<?php
use Drupal\Core\Template\Attribute;
require_once 'autoload.php';
function providerTestAttributeData() {
return [
['&"\'<>' => 'value'],
['title' => '&"\'<>'],
['class' => ['first', 'last']],
['disabled' => TRUE],
['disabled' => FALSE],
['alt' => ''],
['alt' => NULL],
[
'id' => 'id-test',
'class' => ['first', 'last'],
'alt' => 'Alternate',
],
[],
];
}
$startTime = microtime(true);
// Your content to test
$attributesData = providerTestAttributeData();
for ($i=0; $i < 10000; $i++) {
foreach ($attributesData as $attributes) {
// Convert array to attribute object.
$attribute = new Attribute($attributes);
// Change Attribute.
$attribute->addClass(array('orange', 'blue'));
$attribute->removeAttribute('id');
// Cast to string.
$value = (string) $attribute;
}
}
$endTime = microtime(true);
$elapsed = $endTime - $startTime;
echo "Execution time : $elapsed seconds";
Needs work
11.0 🔥
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
it needs new profiling in a light of https://wiki.php.net/rfc/opt_in_dom_spec_compliance