Normalize the part array and split it block part size.

This will make all parts the same length and a multiple
of the part size

@param array $parts The parts to normalize

@return array The normalized and split parts
497560
protected function normalizeParts(array $parts)
    {
        $blockSize = $this->getPartSize();
        $callback  = function ($value) {
            return Util::safeStrlen($value);
        };
        $maxSize = max(array_map($callback, $parts));
        if ($maxSize % $blockSize != 0) {
            $maxSize += $blockSize - ($maxSize % $blockSize);
        }
        foreach ($parts as &$part) {
            $part = $this->str_pad($part, $maxSize, chr(0));
            $part = str_split($part, $blockSize);
        }

        return $parts;
    }
1017532
protected function split($path)
  {
    if (is_array($path)) {
      $parts = $path;
    } else {
      $parts = explode("/", $path);
    }
    return $parts;
  }
110445
protected function flattenParts(array $parts, array $flattened = [], $pre = '', $idx = 1, $full = true)
    {
        foreach ($parts as $part) {
            $key = $pre.$idx;
            $flattened[$key] = $part;
            if (isset($part->parts)) {
    			if ($part->type == TYPEMULTIPART) {
    				$flattened = $this->flattenParts($part->parts, $flattened, $key.'.', 1, false);
    			} elseif ($full) {
    				$flattened = $this->flattenParts($part->parts, $flattened, $key.'.');
    			} else {
    				$flattened = $this->flattenParts($part->parts, $flattened, $pre);
    			}
    			unset($flattened[$key]->parts);
    		}
    		$idx++;
        }

        return $flattened;
    }
1165845
public function setParts(array $parts)
    {
        $this->parts = array();

        foreach($parts as $part) {
            $this->add($part);
        }
        return $this;
    }
715809
public function addParts($parts): CompositeBuilder
    {
        foreach ($parts as $part) {
            $this->addPart($part);
        }

        return $this;
    }
231780
private function removeSplit($key, $parts)
    {
        $keys   = array();
        $keys[] = $key;
        for ($i = 0; $i < $parts; $i++) {
            $keys[] = $key.$i;
        }

        if (false === $this->memcached->deleteMulti($keys)) {
            $msg = sprintf(
                'Unable to remove split values for key "%s": %s.',
                $key,
                $this->memcached->getResultMessage()
            );

            $this->getLogger()->log(LogLevel::NOTICE, $msg);
            throw new \RuntimeException($msg);
        }
    }
491772
public function normalizeArray($objects)
    {
        $normal = [];
        foreach ($objects as $i => $objectName) {
            $config = [];
            if (!is_int($i)) {
                $config = (array)$objectName;
                $objectName = $i;
            }
            list(, $name) = pluginSplit($objectName);
            if (isset($config['class'])) {
                $normal[$name] = $config;
            } else {
                $normal[$name] = ['class' => $objectName, 'config' => $config];
            }
        }

        return $normal;
    }
559569
protected function prepareRestRequest(array &$parts)
    {
        if (!empty($parts) && in_array($parts[0], $this->restPrefixes)) {
            /*
             * if the request is something like /_/posts/1/comments/2
             * it will convert it to something like /posts/comments/1/2
             */

            // first remove the REST prefix
            array_shift($parts);

            $restRoute = $restParams = [];
            $i = 1;

            foreach ($parts as $part) {
                if ($i % 2) {
                    $restRoute[] = $part;
                } else {
                    $restParams[] = $part;
                }

                $i++;
            }

            $parts = array_merge($restRoute, $restParams);
        }
    }
123848
protected function dataArrayGet(array $array, array $parts, $default = null)
    {
        if ($parts === null) {
            return $array;
        }

        if (count($parts) === 1) {
            $key = array_shift($parts);
            if (isset($array[$key])) {
                return $array[$key];
            }

            return $default;
        }

        foreach ($parts as $segment) {
            if (!is_array($array) || !array_key_exists($segment, $array)) {
                return $default;
            }

            $array = $array[$segment];
        }

        return $array;
    }
670792
public function extract($parts = null) {
        if ($this->isEmpty()) {
            return false;
        }

        if ($parts === null) {
            return $this->content;
        }

        if (is_array($parts)) {
            $result = array();
            foreach ($parts as $key) {
                if (isset($this->content[$key])) {
                    $result[$key] = $this->content[$key];
                }
            }

            return $result;
        }

        return isset($this->content[$parts])?$this->content[$parts]:false;
    }
444159
private function fromCompactSerializationRecipientToSerialization(array $parts)
    {
        $recipient = [];
        if (!empty($parts[1])) {
            $recipient['encrypted_key'] = $parts[1];
        }

        $recipients = [
            'recipients' => [$recipient],
        ];
        foreach ([0 => 'protected', 2 => 'iv', 3 => 'ciphertext', 4 => 'tag'] as $part => $key) {
            if (!empty($parts[$part])) {
                $recipients[$key] = $parts[$part];
            }
        }

        $this->log(LogLevel::INFO, 'JWE in Compact JSON Serialization mode loaded.');

        return $recipients;
    }
263759
protected function processParts(array $parts)
    {
        return array_values(array_filter($parts, function ($part) {
            if (empty($part) || $part instanceof CommentPart) {
                return false;
            }
            return true;
        }));
    }
954744
private function splitSimpleAndNormalTransformations(array $transformations)
    {
        return array_reduce($transformations, function ($acc, $t) {
            return array(
                $t instanceof SimpleArgumentTransformation ? array_merge($acc[0], array($t)) : $acc[0],
                !$t instanceof SimpleArgumentTransformation ? array_merge($acc[1], array($t)) : $acc[1],
            );
        }, array(array(), array()));
    }
1142299
public function mix(array $parts)
    {
        if (empty($parts)) {
            return '';
        }
        $len        = Util::safeStrlen($parts[0]);
        $parts      = $this->normalizeParts($parts);
        $stringSize = count($parts[0]);
        $partsSize  = count($parts);
        $result     = '';
        $offset     = 0;
        for ($i = 0; $i < $stringSize; $i++) {
            $stub = $parts[$offset][$i];
            for ($j = 1; $j < $partsSize; $j++) {
                $newKey = $parts[($j + $offset) % $partsSize][$i];
                //Alternately mix the output for each source
                if ($j % 2 == 1) {
                    $stub ^= $this->mixParts1($stub, $newKey);
                } else {
                    $stub ^= $this->mixParts2($stub, $newKey);
                }
            }
            $result .= $stub;
            $offset  = ($offset + 1) % $partsSize;
        }

        return Util::safeSubstr($result, 0, $len);
    }
936425
protected function parseCustomSegments(array $segments)
    {
        if (\count($segments) >= 2) {
            $group = "{$segments[0]}/{$segments[1]}";

            if ($this->getLoader()->exists($group)) {
                return [null, $group, \implode('.', \array_slice($segments, 2))];
            }
        }

        return $this->parseBasicSegments($segments);
    }
231983
public function setParts(array $parts): self
    {
        $this->parts = [];
        foreach ($parts as $part) {
            $this->addPart($part);
        }

        return $this;
    }
576012
protected function _normalize($url, array $parts = []) {
        if (!is_string($url)) {
            $url = Router::url($url);
        }
        if (!$this->_matchHost($url)) {
            return null;
        }
        if (!$this->_matchRelative($url)) {
            return null;
        }
        $url = Router::parseRequest(new ServerRequest($this->_removeRelative($url)));
        $arr = [];
        foreach ($this->_parts as $part) {
            if (!isset($url[$part]) || (isset($parts[$part]) && !$parts[$part])) {
                continue;
            }
            if (is_array($url[$part])) {
                $url[$part] = implode('/', $url[$part]);
            }
            if ($part != 'pass') {
                $url[$part] = strtolower($url[$part]);
            }
            $arr[] = $url[$part];
        }
        return $this->_removeRelative(Router::normalize('/'.implode('/', $arr)));
    }