Merge specified segments

$segments is an array of SegmentInfo objects

@param array $segments
974930
private function _mergeSegments($segments)
    {
        $newName = $this->_newSegmentName();

        /**
 * Zend_Search_Lucene_Index_SegmentMerger 
*/
        include_once 'Zend/Search/Lucene/Index/SegmentMerger.php';
        $merger = new Zend_Search_Lucene_Index_SegmentMerger(
            $this->_directory,
            $newName
        );
        foreach ($segments as $segmentInfo) {
            $merger->addSource($segmentInfo);
            $this->_segmentsToDelete[$segmentInfo->getName()] = $segmentInfo->getName();
        }

        $newSegment = $merger->merge();
        if ($newSegment !== null) {
            $this->_newSegments[$newSegment->getName()] = $newSegment;
        }

        $this->commit();
    }
814017
public function addSegment(Segment $segment)
    {
        $this->segments[] = $segment;

        if ($segment->isDefault()) {
            $this->setDefaultSegment($segment);
        }
    }
258906
public function mergeParameters(array $params = null)
    {
        if (null !== $params) {
            $parameters = $this->getParameters();
            $out = [];
            $i = 1;
            foreach ($parameters as $key => $parameter) {
                $out["rule$i"] = $parameter;
                $i++;
            }
            foreach ($params as $key => $param) {
                $out["rule$i"] = $param;
                $i++;
            }

            $this->setParameters($out);
        }
    }
1175576
protected function createTree(array $segments) : array
    {
        $nodes = array_map(function (TextSegment $segment) {
            $text = new TextNode($segment->getText());

            // Wrap text node in each tag from the innermost to the outermost.
            $tags = array_reverse($segment->getTags());
            return array_reduce($tags, function (Node $child, Tag $tag) {
                return new TagNode($tag, [$child]);
            }, $text);
        }, $segments);

        return $this->optimizeTree($nodes);
    }
51337
public static function getFirstSegment($segments)
    {
        if (is_array($segments)) {
            $vars = $segments;
        } else {
            $vars = self::segmentUrl($segments);
        }

        return current($vars);
    }
1289284
public function initSegment($segment, $configId = false)
    {
        if (!count($segment->getOverviews()->toArray())) {
            if ($configId) {
                $config = $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->find($configId);
            } else {
                $config = $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->findFirst();
            }
            $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsOverview')->addOverviews($config, $segment);
        }
    }
1235715
public function mergeValuesBase(array $values): void
  {
    if (array_key_exists($this->name, $values))
    {
      $this->setValuesBase($values);
    }
  }
1158591
private function processService(array &$segments): array
    {
        // init
        $processed = [];

        foreach ($segments as &$seg) {
            $jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
            $processed[$jsonsegment['key']] = $jsonsegment['value'];
        }

        return $processed;
    }
426554
def merge_segments(segments, exif=b""):
    
    if segments[1][0:2] == b"\xff\xe0" and \
       segments[2][0:2] == b"\xff\xe1" and \
       segments[2][4:10] == b"Exif\x00\x00":
        if exif:
            segments[2] = exif
            segments.pop(1)
        elif exif is None:
            segments.pop(2)
        else:
            segments.pop(1)
    elif segments[1][0:2] == b"\xff\xe0":
        if exif:
            segments[1] = exif
    elif segments[1][0:2] == b"\xff\xe1" and \
         segments[1][4:10] == b"Exif\x00\x00":
        if exif:
            segments[1] = exif
        elif exif is None:
            segments.pop(1)
    else:
        if exif:
            segments.insert(1, exif)
    return b"".join(segments)
1363202
public function parse(&$segments)
    {
        $query = array();
        $path = implode('/', $segments);

        if ($path == 'signup') {
            return array('view' => 'person','layout' => 'signup');
        } elseif (
             !empty($segments) &&
             !is_numeric($segments[0]) &&
             !in_array(AnInflector::singularize($segments[0]), array('person', 'session', 'token'))
        ) {
            $query['username'] = $segments[0];
            //@TODO the parent::parse wants a numeric ID in order
            //to parse correctly. For now lets hack it
            $segments[0] = 10;
            $query['view'] = 'person';
            $query = array_merge(parent::parse($segments), $query);
            unset($query['id']);
        } else {
            if (preg_match('/tokens\/.*/', $path)) {
                $query['view'] = 'token';
                $query['id'] = array_pop($segments);
            } else {
                $query = parent::parse($segments);
            }
        }

        return $query;
    }
704124
protected function getTarget($target, array $segments)
    {
        foreach ($segments as $segment) {
            if (!$target) {
                return;
            }

            $target = $target->{$segment};
        }

        return $target;
    }
557495
protected function routeDefault($segments = array(), $route)
    {
        // If we don't have any segments left - try the default controller;
        // WARNING: Directories get shifted out of the segments array!
        if (empty($segments))
        {
            $segments[0] = $this->config->routing->default_controller;
        }

        if ($this->config->routing->translate_uri_dashes === true)
        {
            $segments[0] = str_replace('-', '_', $segments[0]);
            if (isset($segments[1]))
            {
                $segments[1] = str_replace('-', '_', $segments[1]);
            }
        }

        // Prepare the values for loading
        $controller = $segments[0];
        $function = (isset($segments[1]) ? $segments[1] : $this->config->routing->default_function);

        // And prepare the Router URI
        array_unshift($segments, null);
        unset($segments[0]);
        $this->uri->rsegments = $segments;

        // Now create a matches array
        $matches = array(
                'controller' => $controller,
                'function' => $function,
                'parameters' => array_slice($this->uri->rsegments, 2)
            );

        // And finally load the callable
        $this->callable = array('\FuzeWorks\Router', 'defaultCallable');
        $this->loadCallable($matches, $route);
    }
2225
public function merge(array $items)
    {
        $this->items = $this->arrayMergeRecursive($this->items, $items);
        $this->nestedKeyCache = [];
    }
1151884
public static function join(...$segments)
    {
        $path = array();
        foreach ($segments as $segment) {
            $path = array_merge($path, (array) $segment);
        }

        $path = array_map(function ($segment) {
            return trim($segment, DIRECTORY_SEPARATOR);
        }, $path);

        $path = array_filter($path);

        $path = implode(DIRECTORY_SEPARATOR, $path);

        // First segment slash.
        if ((is_array($segments[0]) && strpos($segments[0][0], DIRECTORY_SEPARATOR) === 0)
            || strpos($segments[0], DIRECTORY_SEPARATOR) === 0
        ) {
            return DIRECTORY_SEPARATOR . $path;
        }
        return $path;
    }
80034
protected function mergeHeader(array $keys)
    {
        foreach ($keys as $key) {
            if (!isset($this->header[$key])) {
                $this->header[$key] = '';
            }
        }
    }
965984
protected function addEncryptedSegment(SegmentInterface $segment)
    {
        $this->encryptedSegmentsCount++;
        $this->encryptedSegments[] = $segment;
        $encodedData = $this->encryptionEnvelop->getEncodedData()->getData();
        $encodedData .= (string) $segment;
        $this->encryptionEnvelop->setEncodedData($encodedData);
    }
1343918
public function append($segment)
    {
        $segments = is_array($segment) ? $segment : func_get_args();

        return $this->replicate(['path' => $this->path->copy()->extend($segments)]);
    }