From 65f35e747b44de5a3ba25cee27cf0b9176c79246 Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Sun, 11 Nov 2018 21:00:12 +0300 Subject: [PATCH] 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. --- src/MicrodataDOMElement.php | 23 ----------------------- src/MicrodataParser.php | 16 ---------------- 2 files changed, 39 deletions(-) diff --git a/src/MicrodataDOMElement.php b/src/MicrodataDOMElement.php index bdab108..a6a1c99 100644 --- a/src/MicrodataDOMElement.php +++ b/src/MicrodataDOMElement.php @@ -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; diff --git a/src/MicrodataParser.php b/src/MicrodataParser.php index c20ce69..074a34e 100644 --- a/src/MicrodataParser.php +++ b/src/MicrodataParser.php @@ -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; }