Apple_Exporter\Component_Factory::get_components_from_node PHP Method

get_components_from_node() public static method

Given a node, returns an array of all the components inside that node. If the node is a component itself, returns an array of only one element.
public static get_components_from_node ( DomNode $node ) : array
$node DomNode
return array
    public static function get_components_from_node($node)
    {
        $result = array();
        foreach (self::$components as $shortname => $class) {
            $matched_node = $class::node_matches($node);
            // Nothing matched? Skip to next match.
            if (!$matched_node) {
                continue;
            }
            // Did we match several components? If so, a hash is returned. Both the
            // body and heading components can returns this, in the case they find
            // non-markdown-able elements inside.
            if (is_array($matched_node)) {
                foreach ($matched_node as $base_component) {
                    $result[] = self::get_component($base_component['name'], $base_component['value']);
                }
                return $result;
            }
            // We matched a single node
            $html = $node->ownerDocument->saveXML($matched_node);
            $result[] = self::get_component($shortname, $html);
            return $result;
        }
        // Nothing found. Maybe it's a container element?
        if ($node->hasChildNodes()) {
            foreach ($node->childNodes as $child) {
                $result = array_merge($result, self::get_components_from_node($child, $node));
            }
            // Remove all nulls from the array
            $result = array_filter($result);
        }
        // If nothing was found, log this as a component error by recording the node name.
        // Only record components with a tagName since otherwise there is nothing to report.
        // Others nodes without a match are almost always just stray empty text nodes
        // that are always safe to remove. Paragraphs should also be ignored for this reason.
        if (empty($result) && (!empty($node->tagName) && 'p' !== $node->tagName)) {
            self::$workspace->log_error('component_errors', $node->tagName);
        }
        return $result;
    }

Usage Example

 /**
  * Get a component from a node.
  *
  * @param DomNode $node
  * @return Component
  * @access private
  */
 private function get_components_from_node($node)
 {
     return Component_Factory::get_components_from_node($node);
 }