Process the parts of the file to server.

@param array             $parts          array of parts to process

@throws FilestackException   if API call fails

@return json
195272
protected function processParts($parts)
    {
        $num_parts = count($parts);
        $parts_etags = [];
        $parts_completed = 0;

        $max_retries = FilestackConfig::MAX_RETRIES;

        $current_part_index = 0;
        while($parts_completed < $num_parts) {
            $part = $parts[$current_part_index];
            $part['part_size'] = 0;
            $chunks = $part['chunks'];

            // process chunks of current part
            $promises = $this->processChunks($part, $chunks);

            // sends s3 chunks asyncronously
            $s3_results = $this->settlePromises($promises);
            $this->handleS3PromisesResult($s3_results);

            // handle fulfilled promises
            if ($this->intelligent) {
                // commit part
                $this->commitPart($part);
            }
            else {
                $part_num = array_key_exists('part_num', $part) ?
                    $part['part_num'] : 1;

                $this->multipartGetTags($part_num, $s3_results, $parts_etags);
            }

            unset($promises);
            unset($s3_results);

            $current_part_index++;
            $parts_completed++;
        }

        if (!$this->intelligent) {
            return implode(';', $parts_etags);
        }

        return $parts_completed;
    }
755367
public static function convert($files)
    {
        $result = array();
        foreach ($files as $key => $file) {
            if (isset($file['tmp_name'])) {
                if (is_string($file['tmp_name'])) {
                    $result[$key] = new UploadedFile($file);
                    continue;
                }
                if (is_array($file['tmp_name'])) {
                    if (isset($file['tmp_name'][0]) and is_string($file['tmp_name'][0])) {
                        $result[$key] = array();
                        foreach ($file['tmp_name'] as $offset => $tmpName) {
                            $result[$key][] = new UploadedFile($file, $offset);
                        }
                        continue;
                    }
                }
            }
            $result[$key] = self::convert($file);
        }
        return $result;
    }
1192534
public function prepend(string ...$parts): self
    {
        array_push($parts, $this->path);

        return self::make(...$parts);
    }
830284
private function processComponentSections($sections)
	{
		// var to hold output
		$output = array();

		// loop through each component grouping
		foreach ($sections as $component => $files)
		{
			// if we dont have an array for that component let's create it
			if (!isset($output[$component]))
			{
				$output[$component] = [];
			}

			// loop through each file
			foreach ($files as $file)
			{
				if (!preg_match('/(.*)v[0-9]+_[0-9]+.php$/', $file))
				{
					continue;
				}
				$output[$component] = array_merge($output[$component], $this->processFile($file));
			}
		}

		// return output
		return $output;
	}
510338
protected function multipartFinalize(Array $multiparts = []) {
    $contents = '';
    foreach ($multiparts as $multipart) {
      $contents .= $multipart;
    }
    $contents .= '--' . $this->boundary  . '--';
    $contents .= static::EOL;
    return $contents;
  }
140139
protected function processParts(array $parts)
    {
        $strValue = '';
        $filtered = $this->filterIgnoredSpaces($parts);
        foreach ($filtered as $part) {
            $strValue .= $part->getValue();
        }
        return [$this->partFactory->newLiteralPart($strValue)];
    }
21060
private function getRequestBody(array $parameters, array $files)
    {
        $body = array();
        foreach ($parameters as $parameterName => $parameterValue) {
            if (is_scalar($parameterValue) || (is_null($parameterValue) && $parameterName !== 'id')) {
                $body[] = array(
                    'name' => $parameterName,
                    'contents' => strval($parameterValue),
                );
            }
        }

        foreach ($files as $parameterName => $fileResource) {
            if (is_resource($fileResource)) {
                $metaData = stream_get_meta_data($fileResource);

                $body[] = array(
                    'name' => $parameterName,
                    'contents' => $fileResource,
                    'filename' => basename($metaData['uri']),
                );
            }
        }

        return new MultipartStream($body);
    }
69234
public static function process($assets)
    {
        if ($directory = self::getOutputDirectory()) {
            $relativeDirectory = self::getRelativeOutputDirectory();
            $filename = '';
            $sourceFiles = array();
            for ($i = 0; $i < count($assets); ++$i) {
                $asset = $assets[$i];
                $filename .= $asset->getAssetHashKey();
                $sourceFiles[] = $asset->getAssetURL();
            }
            $filename = sha1($filename);
            $cacheFile = $directory.'/'.$filename.'.js';
            if (!file_exists($cacheFile)) {
                $js = '';
                foreach ($assets as $asset) {
                    $contents = $asset->getAssetContents();
                    if (isset($contents)) {
                        if ($asset->assetSupportsMinification()) {
                            $contents = \JShrink\Minifier::minify($contents);
                        }
                        $js .= $contents.";\n\n";
                    }
                }
                @file_put_contents($cacheFile, $js);
            }

            $asset = new self();
            $asset->setAssetURL($relativeDirectory.'/'.$filename.'.js');
            $asset->setAssetPath($directory.'/'.$filename.'.js');
            $asset->setCombinedAssetSourceFiles($sourceFiles);

            return array($asset);
        }

        return $assets;
    }
445987
private function writeData($data, $files)
    {
        // Initialise:
        
        $result = true;
        
        // Check Parameters:
        
        if (is_array($data) && is_array($files)) {
            
            // Iterate Files:
            
            foreach ($files as $file) {
                
                // Attempt to Process File:
                
                try {
                    
                    // Read File Contents:
                    
                    $contents = file_get_contents($file);
                    
                    // Replace Tokens in Contents:
                    
                    $contents = $this->replace($contents, $data);
                    
                    // Write File Contents:
                    
                    file_put_contents($file, $contents);
                    
                    // Define Status:
                    
                    $status = 'success';
                    
                } catch (ErrorException $e) {
                    
                    // Write Debug Info:
                    
                    $this->io()->writeError(
                        sprintf(
                            '<warning>Exception: %s</warning>',
                            $e->getMessage()
                        ),
                        true,
                        IOInterface::DEBUG
                    );
                    
                    // Define Result:
                    
                    $result = false;
                    
                    // Define Status:
                    
                    $status = 'failure';
                    
                }
                
                // Output Status:
                
                $this->io()->write(
                    sprintf(
                        '[%s] %s',
                        $this->color($this->getConfig("text-file-{$status}"), $this->getConfig("fg-{$status}")),
                        $this->color("Writing to '{$file}'...", $this->getConfig('fg-writing'))
                    )
                );
                
            }
            
        }
        
        // Answer Result:
        
        return $result;
    }
320874
protected function commitPart($part)
    {
        $commit_url = FilestackConfig::UPLOAD_URL . '/multipart/commit';
        $commit_data = $this->buildCommitData($part);

        $response = $this->sendRequest('POST', $commit_url,
                                       ['multipart' => $commit_data]);

        $status_code = $response->getStatusCode();
        if ($status_code !== 200) {
            throw new FilestackException($response->getBody(),
                $status_code);
        }
        return $status_code;
    }
1316791
public function updateFiles(string $commit, array $files)
    {
        $path = $this->buildFilesPath($commit);

        $builder = new MultipartStreamBuilder();

        foreach ($files as $file) {
            $builder->addResource($file->getName(), $file->getResource(), $file->getOptions());
        }

        $headers = ['Content-Type' => sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())];

        return $this->postRaw($path, $builder->build(), $headers);
    }
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;
    }
1266192
public function goWriteFile(string $filename, string $fileContent, int $flags = 0)
    {
        $this->__filename  = $filename;
        $this->__type      = self::WRITE_FILE;
        $this->__content   = $fileContent;
        $this->__flags     = $flags;

        $this->requestId   = $this->getContext()->getRequestId();
        $requestId         = $this->requestId;

        getInstance()->scheduler->IOCallBack[$this->requestId][] = $this;
        $keys = array_keys(getInstance()->scheduler->IOCallBack[$this->requestId]);
        $this->ioBackKey = array_pop($keys);

        $this->send(function ($filename) use ($requestId) {
            if (empty($this->getContext()) || ($requestId != $this->getContext()->getRequestId())) {
                return;
            }

            if (empty(getInstance()->scheduler->taskMap[$this->requestId])) {
                return;
            }

            $this->result = true;
            $this->ioBack = true;
            $this->nextRun();
        });

        return $this;
    }
1329992
private static function setServerData($parts, $params, $server)
    {
        foreach ($params as $key => $value) {
            if (isset($parts[$key])) {
                $server[$value] = $parts[$key];
            }
        }

        return $server;
    }
965136
public function performPost(array $components)
    {
        $response = $this->httpClient->post('', [
            'json' => ['components' => $components]
        ]);

        return (string) $response->getBody();
    }
994422
protected function marshalInstance(array $parts)
    {
        $this->scheme = array_key_exists('scheme', $parts)
            ? $this->marshalScheme($parts['scheme'])
            : ''
        ;

        $this->userInfo = $parts['user'] ?? null;

        if ( array_key_exists('pass', $parts) ) {
            $this->userInfo .= ':'.$parts['pass'];
        }

        $this->host = array_key_exists('host', $parts)
            ? $this->marshalHost($parts['host'])
            : $this->host
        ;

        $this->port = array_key_exists('port', $parts)
            ? $this->marshalPort($parts['port'])
            : null
        ;

        $this->path = array_key_exists('path', $parts)
            ? $this->marshalPath($parts['path'])
            : '/'
        ;

        $this->query = array_key_exists('query', $parts)
            ? $this->marshalQueryAndFragment($parts['query'])
            : null
        ;

        $this->fragment = array_key_exists('fragment', $parts)
            ? $this->marshalQueryAndFragment($parts['fragment'])
            : null
        ;

        if ( empty($this->scheme) && ! array_key_exists('host', $parts) && ! array_key_exists('port', $parts) ) {
            $this->scheme = 'http';
        }

        $this->calibratePort();
    }
311378
public function post($uri, array $headers = [], $datas = [], array $files = [])
    {
        return $this->send($uri, InternalRequestInterface::METHOD_POST, $headers, $datas, $files);
    }