Apple_Exporter\Builders\Components::anchor_components PHP Метод

anchor_components() приватный Метод

Anchor components that are marked as can_be_anchor_target.
private anchor_components ( &$components )
    private function anchor_components(&$components)
    {
        $len = count($components);
        for ($i = 0; $i < $len; $i++) {
            if (!isset($components[$i])) {
                continue;
            }
            $component = $components[$i];
            if ($component->is_anchor_target() || Component::ANCHOR_NONE == $component->get_anchor_position()) {
                continue;
            }
            // Anchor this component to previous component. If there's no previous
            // component available, try with the next one.
            if (empty($components[$i - 1])) {
                // Check whether this is the only component of the article, if it is,
                // just ignore anchoring.
                if (empty($components[$i + 1])) {
                    return;
                } else {
                    $target_component = $components[$i + 1];
                }
            } else {
                $target_component = $components[$i - 1];
            }
            // Skip advertisement elements, they must span all width. If the previous
            // element is an ad, use next instead. If the element is already
            // anchoring something, also skip.
            $counter = 1;
            $len = count($components);
            while (!$target_component->can_be_anchor_target() && $i + $counter < $len) {
                $target_component = $components[$i + $counter];
                $counter++;
            }
            $this->anchor_together($component, $target_component);
        }
    }