Removed comments that only shows steps

This steps was only helpful while implementing the algorithm. And could be useful while comparing with the W3C specification, but they take up too much space.
This commit is contained in:
Yusuf Kandemir 2018-11-11 21:00:12 +03:00
parent 793d596541
commit 65f35e747b
2 changed files with 0 additions and 39 deletions

View File

@ -6,15 +6,12 @@ class MicrodataDOMElement extends \DOMElement
{
public function getProperties()
{
// Step 1
$results = [];
$memory = [];
$pending = [];
// Step 2
$memory[] = $this;
// Step 3
if ($this->hasChildNodes()) {
$childNodes = iterator_to_array($this->childNodes);
@ -25,7 +22,6 @@ class MicrodataDOMElement extends \DOMElement
$pending = array_merge($pending, $childNodes);
}
// Step 4
if ($this->hasAttribute('itemref')) {
$tokens = preg_split('/\s+/', $this->getAttribute('itemref'));
@ -34,17 +30,9 @@ class MicrodataDOMElement extends \DOMElement
}
}
// Step 5
while ($pending) {
// Step 6
$current = array_pop($pending);
// Step 7
// in_array can't compare objects
/*if (in_array($current, $memory)) {
// There is MicrodataError
continue;
}*/
$error = false;
foreach ($memory as $memory_item) {
@ -59,10 +47,8 @@ class MicrodataDOMElement extends \DOMElement
continue;
}
// Step 8
$memory[] = $current;
// Step 9
if (! $current->hasAttribute('itemscope')) {
if ($current->hasChildNodes()) {
$childNodes = iterator_to_array($current->childNodes);
@ -75,32 +61,23 @@ class MicrodataDOMElement extends \DOMElement
}
}
// Step 10
if ($current->hasAttribute('itemprop') && /* hasPropertyNames */ $current->getPropertyNames()) {
$results[] = $current;
}
// Step 11: Return to loop
}
// Step 12: End of loop. Sort results in tree order.
$results = array_reverse($results);
// Step 13
return $results;
}
public function getPropertyNames()
{
// Step 1
$itemprop = $this->getAttribute('itemprop');
$tokens = $itemprop ? preg_split('/\s+/', $itemprop) : [];
// Step 2
$properties = [];
// Step 3
foreach ($tokens as $token) {
if ($this->isAbsoluteUri($token)) {
$properties[] = $token;

View File

@ -16,50 +16,36 @@ class MicrodataParser
public function extractMicrodata()
{
// Step 1
$result = new \stdClass;
// Step 2
$items = [];
// Step 3
foreach ($this->topLevelItems as $topLevelItem) {
$items[] = $this->getObject($topLevelItem);
}
// Step 4
$result->items = $items;
// Step 5
return $result;
}
protected function getObject(\DOMElement $item, $memory = [])
{
// Step 1
$result = new \stdClass;
// Step 2 in 2nd parameter of this function
// $memory = [];
// Step 3
$memory[] = $item;
// Step 4
$itemtype = $item->getAttribute('itemtype');
$result->type = $itemtype ? preg_split('/\s+/', $itemtype) : [];
// @todo Check if types are valid absolute urls
// Step 5
if ($itemId = $item->getAttribute('itemid')) {
$result->id = $itemId;
}
// @todo Check if item ids are valid absolute urls or like isbn:xxx
// Step 6
$properties = new \stdClass;
// Step 7
foreach ($item->getProperties() as $element) {
$value = $element->getPropertyValue();
@ -80,10 +66,8 @@ class MicrodataParser
}
}
// Step 8
$result->properties = $properties;
// Step 9
return $result;
}