_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q20000
Query.setRescore
train
public function setRescore($rescore) { if (\is_array($rescore)) { $buffer = []; foreach ($rescore as $rescoreQuery) { $buffer[] = $rescoreQuery; } } else { $buffer = $rescore; } return $this->setParam('rescore', $buffe...
php
{ "resource": "" }
q20001
Stats.refresh
train
public function refresh() { $this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats()); $this->_data = $this->getResponse()->getData(); }
php
{ "resource": "" }
q20002
Query.setRescoreQuery
train
public function setRescoreQuery($rescoreQuery): Query { $rescoreQuery = BaseQuery::create($rescoreQuery); $query = $this->getParam('query'); $query['rescore_query'] = $rescoreQuery; return $this->setParam('query', $query); }
php
{ "resource": "" }
q20003
Query.setQueryWeight
train
public function setQueryWeight(float $weight): Query { $query = $this->getParam('query'); $query['query_weight'] = $weight; return $this->setParam('query', $query); }
php
{ "resource": "" }
q20004
Query.setRescoreQueryWeight
train
public function setRescoreQueryWeight(float $weight): Query { $query = $this->getParam('query'); $query['rescore_query_weight'] = $weight; return $this->setParam('query', $query); }
php
{ "resource": "" }
q20005
Util.escapeDateMath
train
public static function escapeDateMath($requestUri) { if (empty($requestUri)) { return $requestUri; } // Check if date math if used at all. Find last '>'. E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh $pos1 = \strrpos($requestUri, '>'); if (false === $pos1) { ...
php
{ "resource": "" }
q20006
Util.convertRequestToCurlCommand
train
public static function convertRequestToCurlCommand(Request $request) { $message = 'curl -X'.\strtoupper($request->getMethod()).' '; $message .= '\'http://'.$request->getConnection()->getHost().':'.$request->getConnection()->getPort().'/'; $message .= $request->getPath(); $query = $r...
php
{ "resource": "" }
q20007
Response.getError
train
public function getError() { $error = $this->getFullError(); if (!$error) { return ''; } if (\is_string($error)) { return $error; } $rootError = $error; if (isset($error['root_cause'][0])) { $rootError = $error['root_caus...
php
{ "resource": "" }
q20008
Response.isOk
train
public function isOk() { $data = $this->getData(); // Bulk insert checks. Check every item if (isset($data['status'])) { return $data['status'] >= 200 && $data['status'] <= 300; } if (isset($data['items'])) { if (isset($data['errors']) && true === $d...
php
{ "resource": "" }
q20009
Response.getData
train
public function getData() { if (null == $this->_response) { $response = $this->_responseString; try { if ($this->getJsonBigintConversion()) { $response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING); } else { ...
php
{ "resource": "" }
q20010
JSON.parse
train
public static function parse($args/* inherit from json_decode */) { // extract arguments $args = \func_get_args(); // default to decoding into an assoc array if (1 === \count($args)) { $args[] = true; } // run decode $array = \call_user_func_arra...
php
{ "resource": "" }
q20011
JSON.stringify
train
public static function stringify($args/* inherit from json_encode */) { // extract arguments $args = \func_get_args(); // run encode and output $string = \call_user_func_array('json_encode', $args); // turn errors into exceptions for easier catching if ($error = sel...
php
{ "resource": "" }
q20012
Histogram.setOrder
train
public function setOrder(string $order, string $direction): self { return $this->setParam('order', [$order => $direction]); }
php
{ "resource": "" }
q20013
Terms.setTerms
train
public function setTerms(string $key, array $terms): self { $this->_key = $key; $this->_terms = \array_values($terms); return $this; }
php
{ "resource": "" }
q20014
Terms.setTermsLookup
train
public function setTermsLookup(string $key, array $termsLookup): self { $this->_key = $key; $this->_terms = $termsLookup; return $this; }
php
{ "resource": "" }
q20015
Query.match
train
public function match(string $field = null, $values = null): Match { return new Match($field, $values); }
php
{ "resource": "" }
q20016
Query.common_terms
train
public function common_terms(string $field, string $query, float $cutoffFrequency): Common { return new Common($field, $query, $cutoffFrequency); }
php
{ "resource": "" }
q20017
Query.fuzzy
train
public function fuzzy(string $fieldName = null, string $value = null): Fuzzy { return new Fuzzy($fieldName, $value); }
php
{ "resource": "" }
q20018
Query.regexp
train
public function regexp(string $key = '', string $value = null, float $boost = 1.0): Regexp { return new Regexp($key, $value, $boost); }
php
{ "resource": "" }
q20019
Query.span_first
train
public function span_first($match = null, int $end = null): SpanFirst { return new SpanFirst($match, $end); }
php
{ "resource": "" }
q20020
Query.span_near
train
public function span_near(array $clauses = [], int $slop = 1, bool $inOrder = false): SpanNear { return new SpanNear($clauses, $slop, $inOrder); }
php
{ "resource": "" }
q20021
Query.span_containing
train
public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanContaining { return new SpanContaining($little, $big); }
php
{ "resource": "" }
q20022
Query.span_within
train
public function span_within(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanWithin { return new SpanWithin($little, $big); }
php
{ "resource": "" }
q20023
Query.wildcard
train
public function wildcard(string $key = '', string $value = null, float $boost = 1.0): Wildcard { return new Wildcard($key, $value, $boost); }
php
{ "resource": "" }
q20024
Query.geo_distance
train
public function geo_distance(string $key, $location, string $distance): GeoDistance { return new GeoDistance($key, $location, $distance); }
php
{ "resource": "" }
q20025
NullTransport.generateDefaultResponse
train
public function generateDefaultResponse(array $params): Response { $response = [ 'took' => 0, 'timed_out' => false, '_shards' => [ 'total' => 0, 'successful' => 0, 'failed' => 0, ], 'hits' => [ ...
php
{ "resource": "" }
q20026
Param._convertArrayable
train
protected function _convertArrayable(array $array) { $arr = []; foreach ($array as $key => $value) { if ($value instanceof ArrayableInterface) { $arr[$value instanceof NameableInterface ? $value->getName() : $key] = $value->toArray(); } elseif (\is_array($val...
php
{ "resource": "" }
q20027
Param.getParam
train
public function getParam($key) { if (!$this->hasParam($key)) { throw new InvalidException('Param '.$key.' does not exist'); } return $this->_params[$key]; }
php
{ "resource": "" }
q20028
Mapping.setParam
train
public function setParam(string $key, $value): Mapping { $this->_mapping[$key] = $value; return $this; }
php
{ "resource": "" }
q20029
Mapping.toArray
train
public function toArray(): array { $type = $this->getType(); if (empty($type)) { throw new InvalidException('Type has to be set'); } return [$type->getName() => $this->_mapping]; }
php
{ "resource": "" }
q20030
Mapping.send
train
public function send(array $query = []): Response { $endpoint = new Put(); $endpoint->setBody($this->toArray()); $endpoint->setParams($query); return $this->getType()->requestEndpoint($endpoint); }
php
{ "resource": "" }
q20031
Mapping.create
train
public static function create($mapping): Mapping { if (\is_array($mapping)) { $mappingObject = new self(); $mappingObject->setProperties($mapping); return $mappingObject; } if ($mapping instanceof self) { return $mapping; } t...
php
{ "resource": "" }
q20032
ProcessingBuilder.buildResultSet
train
public function buildResultSet(Response $response, Query $query): ResultSet { $resultSet = $this->builder->buildResultSet($response, $query); $this->processor->process($resultSet); return $resultSet; }
php
{ "resource": "" }
q20033
IpRange.addRange
train
public function addRange(string $fromValue = null, string $toValue = null): self { if (null === $fromValue && null === $toValue) { throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); } $range = []; if (null !== $fromValue) { ...
php
{ "resource": "" }
q20034
AbstractAggregation.addAggregation
train
public function addAggregation(AbstractAggregation $aggregation): self { if ($aggregation instanceof GlobalAggregation) { throw new InvalidException('Global aggregators can only be placed as top level aggregators'); } $this->_aggs[] = $aggregation; return $this; }
php
{ "resource": "" }
q20035
ResponseSet.getError
train
public function getError(): string { foreach ($this->getBulkResponses() as $bulkResponse) { if ($bulkResponse->hasError()) { return $bulkResponse->getError(); } } return ''; }
php
{ "resource": "" }
q20036
GeoBoundingBox.addCoordinates
train
public function addCoordinates(string $key, array $coordinates): self { if (!isset($coordinates[0]) || !isset($coordinates[1])) { throw new InvalidException('expected $coordinates to be an array with two elements'); } $this->setParam($key, [ 'top_left' => $coordinate...
php
{ "resource": "" }
q20037
QueryBuilder.addDSL
train
public function addDSL(DSL $dsl) { $this->_facades[$dsl->getType()] = new Facade($dsl, $this->_version); }
php
{ "resource": "" }
q20038
Index.updateByQuery
train
public function updateByQuery($query, AbstractScript $script, array $options = []) { $query = Query::create($query)->getQuery(); $endpoint = new UpdateByQuery(); $body = ['query' => \is_array($query) ? $query : $query->toArray(), ]; $body['script'] = $script...
php
{ "resource": "" }
q20039
Index.forcemerge
train
public function forcemerge($args = []) { $endpoint = new ForceMerge(); $endpoint->setParams($args); return $this->requestEndpoint($endpoint); }
php
{ "resource": "" }
q20040
Index.create
train
public function create(array $args = [], $options = null) { if (\is_bool($options) && $options) { try { $this->delete(); } catch (ResponseException $e) { // Table can't be deleted, because doesn't exist } } elseif (\is_array($option...
php
{ "resource": "" }
q20041
Index.addAlias
train
public function addAlias($name, $replace = false) { $data = ['actions' => []]; if ($replace) { $status = new Status($this->getClient()); foreach ($status->getIndicesWithAlias($name) as $index) { $data['actions'][] = ['remove' => ['index' => $index->getName(),...
php
{ "resource": "" }
q20042
Index.removeAlias
train
public function removeAlias($name) { $endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Delete(); $endpoint->setName($name); return $this->requestEndpoint($endpoint); }
php
{ "resource": "" }
q20043
Index.getAliases
train
public function getAliases() { $endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Get(); $endpoint->setName('*'); $responseData = $this->requestEndpoint($endpoint)->getData(); if (!isset($responseData[$this->getName()])) { return []; } $data = $resp...
php
{ "resource": "" }
q20044
Index.flush
train
public function flush(array $options = []) { $endpoint = new Flush(); $endpoint->setParams($options); return $this->requestEndpoint($endpoint); }
php
{ "resource": "" }
q20045
Index.setSettings
train
public function setSettings(array $data) { $endpoint = new Put(); $endpoint->setBody($data); return $this->requestEndpoint($endpoint); }
php
{ "resource": "" }
q20046
Index.requestEndpoint
train
public function requestEndpoint(AbstractEndpoint $endpoint) { $cloned = clone $endpoint; $cloned->setIndex($this->getName()); return $this->getClient()->requestEndpoint($cloned); }
php
{ "resource": "" }
q20047
Index.analyze
train
public function analyze(array $body, $args = []) { $endpoint = new Analyze(); $endpoint->setBody($body); $endpoint->setParams($args); $data = $this->requestEndpoint($endpoint)->getData(); // Support for "Explain" parameter, that returns a different response structure from E...
php
{ "resource": "" }
q20048
DefaultBuilder.buildResultSet
train
public function buildResultSet(Response $response, Query $query): ResultSet { $results = $this->buildResults($response); $resultSet = new ResultSet($response, $query, $results); return $resultSet; }
php
{ "resource": "" }
q20049
DefaultBuilder.buildResults
train
private function buildResults(Response $response): array { $data = $response->getData(); $results = []; if (!isset($data['hits']['hits'])) { return $results; } foreach ($data['hits']['hits'] as $hit) { $results[] = new Result($hit); } ...
php
{ "resource": "" }
q20050
Common.setQueryParam
train
public function setQueryParam(string $key, $value): self { $this->_queryParams[$key] = $value; return $this; }
php
{ "resource": "" }
q20051
AbstractTermsAggregation.setInclude
train
public function setInclude(string $pattern, string $flags = null): self { if (null === $flags) { return $this->setParam('include', $pattern); } return $this->setParam('include', [ 'pattern' => $pattern, 'flags' => $flags, ]); }
php
{ "resource": "" }
q20052
AbstractTermsAggregation.setExclude
train
public function setExclude(string $pattern, string $flags = null): self { if (null === $flags) { return $this->setParam('exclude', $pattern); } return $this->setParam('exclude', [ 'pattern' => $pattern, 'flags' => $flags, ]); }
php
{ "resource": "" }
q20053
FileStore.createCacheFile
train
protected function createCacheFile() { $this->createCacheDir(); $cacheFilePath = $this->getCacheFile(); if ( ! file_exists($cacheFilePath)) { touch($cacheFilePath); } }
php
{ "resource": "" }
q20054
FileStore.put
train
public function put(string $path, string $contents) : int { return file_put_contents($path, $contents, LOCK_EX); }
php
{ "resource": "" }
q20055
FileStore.isValid
train
public function isValid(string $key) : bool { $key = $this->getActualCacheKey($key); $meta = $this->getCacheContents()[$key] ?? []; if (empty($meta['expires_at'])) { return false; } return Carbon::now() < Carbon::createFromFormat(self::RFC_7231, $meta['expires_...
php
{ "resource": "" }
q20056
FileStore.getCacheContents
train
public function getCacheContents() { $cacheFile = $this->getCacheFile(); if ( ! file_exists($cacheFile)) { return false; } return json_decode($this->sharedGet($cacheFile), true) ?? []; }
php
{ "resource": "" }
q20057
FileStore.getActualCacheKey
train
public function getActualCacheKey(string $key) : string { $prefix = $this->getPrefix(); if (false === strpos($key, $prefix)) { $key = $prefix . $key; } return $key; }
php
{ "resource": "" }
q20058
Response.send
train
public function send($content, int $status = HttpResponse::HTTP_OK, array $headers = []) : HttpResponse { $headers = array_merge($this->headers, $headers); if (is_array($content)) { $content = json_encode($content); } $response = $this->response->create($content, $statu...
php
{ "resource": "" }
q20059
Client.file
train
public function file(string $file, string $name = null) : self { $this->filePath = $file; if ( ! file_exists($file) || ! is_readable($file)) { throw new FileException('Cannot read file: ' . $file); } $this->fileName = $name ?? basename($this->filePath); $this->f...
php
{ "resource": "" }
q20060
Client.getChecksum
train
public function getChecksum() : string { if (empty($this->checksum)) { $this->setChecksum(hash_file($this->getChecksumAlgorithm(), $this->getFilePath())); } return $this->checksum; }
php
{ "resource": "" }
q20061
Client.isExpired
train
public function isExpired() : bool { $expiresAt = $this->getCache()->get($this->getKey())['expires_at'] ?? null; return empty($expiresAt) || Carbon::parse($expiresAt)->lt(Carbon::now()); }
php
{ "resource": "" }
q20062
Client.seek
train
public function seek(int $offset) : self { $this->partialOffset = $offset; $this->partial(); return $this; }
php
{ "resource": "" }
q20063
Client.create
train
public function create(string $key) : string { $headers = [ 'Upload-Length' => $this->fileSize, 'Upload-Key' => $key, 'Upload-Checksum' => $this->getUploadChecksumHeader(), 'Upload-Metadata' => 'filename ' . base64_encode($this->fileName), ]; ...
php
{ "resource": "" }
q20064
Client.concat
train
public function concat(string $key, ...$partials) : string { $response = $this->getClient()->post($this->apiPath, [ 'headers' => [ 'Upload-Length' => $this->fileSize, 'Upload-Key' => $key, 'Upload-Checksum' => $this->getUploadChecksumHeader(), ...
php
{ "resource": "" }
q20065
Client.delete
train
public function delete() { try { $this->getClient()->delete($this->getUrl()); } catch (ClientException $e) { $statusCode = $e->getResponse()->getStatusCode(); if (HttpResponse::HTTP_NOT_FOUND === $statusCode || HttpResponse::HTTP_GONE === $statusCode) { ...
php
{ "resource": "" }
q20066
Client.partial
train
protected function partial(bool $state = true) { $this->partial = $state; if ( ! $this->partial) { return; } $key = $this->getKey(); if (false !== strpos($key, self::PARTIAL_UPLOAD_NAME_SEPARATOR)) { list($key, /* $partialKey */) = explode(self::PAR...
php
{ "resource": "" }
q20067
Client.handleClientException
train
protected function handleClientException(ClientException $e) { $statusCode = $e->getResponse()->getStatusCode(); if (HttpResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE === $statusCode) { return new FileException('The uploaded file is corrupt.'); } if (HttpResponse::HTTP...
php
{ "resource": "" }
q20068
Client.getData
train
protected function getData(int $offset, int $bytes) : string { $file = new File; $handle = $file->open($this->getFilePath(), $file::READ_BINARY); $file->seek($handle, $offset); $data = $file->read($handle, $bytes); $file->close($handle); return (string) $data; ...
php
{ "resource": "" }
q20069
File.setMeta
train
public function setMeta(int $offset, int $fileSize, string $filePath, string $location = null) : self { $this->offset = $offset; $this->fileSize = $fileSize; $this->filePath = $filePath; $this->location = $location; return $this; }
php
{ "resource": "" }
q20070
File.details
train
public function details() : array { $now = Carbon::now(); return [ 'name' => $this->name, 'size' => $this->fileSize, 'offset' => $this->offset, 'checksum' => $this->checksum, 'location' => $this->location, 'file_path' => $this-...
php
{ "resource": "" }
q20071
File.upload
train
public function upload(int $totalBytes) : int { if ($this->offset === $totalBytes) { return $this->offset; } $input = $this->open($this->getInputStream(), self::READ_BINARY); $output = $this->open($this->getFilePath(), self::APPEND_BINARY); $key = $this->getK...
php
{ "resource": "" }
q20072
File.open
train
public function open(string $filePath, string $mode) { $this->exists($filePath, $mode); $ptr = @fopen($filePath, $mode); if (false === $ptr) { throw new FileException("Unable to open $filePath."); } return $ptr; }
php
{ "resource": "" }
q20073
File.exists
train
public function exists(string $filePath, string $mode = self::READ_BINARY) : bool { if (self::INPUT_STREAM === $filePath) { return true; } if (self::READ_BINARY === $mode && ! file_exists($filePath)) { throw new FileException('File not found.'); } re...
php
{ "resource": "" }
q20074
File.seek
train
public function seek($handle, int $offset, int $whence = SEEK_SET) : int { $position = fseek($handle, $offset, $whence); if (-1 === $position) { throw new FileException('Cannot move pointer to desired position.'); } return $position; }
php
{ "resource": "" }
q20075
File.read
train
public function read($handle, int $chunkSize) : string { $data = fread($handle, $chunkSize); if (false === $data) { throw new FileException('Cannot read file.'); } return (string) $data; }
php
{ "resource": "" }
q20076
File.write
train
public function write($handle, string $data, $length = null) : int { $bytesWritten = is_int($length) ? fwrite($handle, $data, $length) : fwrite($handle, $data); if (false === $bytesWritten) { throw new FileException('Cannot write to a file.'); } return $bytesWritten; ...
php
{ "resource": "" }
q20077
File.merge
train
public function merge(array $files) : int { $destination = $this->getFilePath(); $firstFile = array_shift($files); // First partial file can directly be copied. $this->copy($firstFile['file_path'], $destination); $this->offset = $firstFile['offset']; $this->file...
php
{ "resource": "" }
q20078
File.copy
train
public function copy(string $source, string $destination) : bool { $status = @copy($source, $destination); if (false === $status) { throw new FileException('Cannot copy source to destination.'); } return $status; }
php
{ "resource": "" }
q20079
File.deleteFiles
train
public function deleteFiles(array $files) : bool { if (empty($files)) { return false; } $status = true; foreach ($files as $file) { if (file_exists($file)) { $status = $status && unlink($file); } } return $status;...
php
{ "resource": "" }
q20080
Request.allowedHttpVerbs
train
public function allowedHttpVerbs() : array { return [ HttpRequest::METHOD_GET, HttpRequest::METHOD_POST, HttpRequest::METHOD_PATCH, HttpRequest::METHOD_DELETE, HttpRequest::METHOD_HEAD, HttpRequest::METHOD_OPTIONS, ]; }
php
{ "resource": "" }
q20081
Request.extractFromHeader
train
public function extractFromHeader(string $key, string $value) : array { $meta = $this->header($key); if (false !== strpos($meta, $value)) { $meta = trim(str_replace($value, '', $meta)); return explode(' ', $meta) ?? []; } return []; }
php
{ "resource": "" }
q20082
Request.extractMeta
train
public function extractMeta(string $requestedKey) : string { $uploadMetaData = $this->request->headers->get('Upload-Metadata'); if (empty($uploadMetaData)) { return ''; } $uploadMetaDataChunks = explode(',', $uploadMetaData); foreach ($uploadMetaDataChunks as $...
php
{ "resource": "" }
q20083
AbstractCache.deleteAll
train
public function deleteAll(array $keys) : bool { if (empty($keys)) { return false; } $status = true; foreach ($keys as $key) { $status = $status && $this->delete($key); } return $status; }
php
{ "resource": "" }
q20084
Middleware.add
train
public function add(...$middleware) : self { foreach ($middleware as $m) { if ($m instanceof TusMiddleware) { $this->globalMiddleware[get_class($m)] = $m; } elseif (is_string($m)) { $this->globalMiddleware[$m] = new $m; } } ...
php
{ "resource": "" }
q20085
Middleware.skip
train
public function skip(...$middleware) : self { foreach ($middleware as $m) { unset($this->globalMiddleware[$m]); } return $this; }
php
{ "resource": "" }
q20086
Server.getChecksumAlgorithm
train
public function getChecksumAlgorithm() : ?string { $checksumHeader = $this->getRequest()->header('Upload-Checksum'); if (empty($checksumHeader)) { return self::DEFAULT_CHECKSUM_ALGORITHM; } list($checksumAlgorithm, /* $checksum */) = explode(' ', $checksumHeader); ...
php
{ "resource": "" }
q20087
Server.getUploadKey
train
public function getUploadKey() { if ( ! empty($this->uploadKey)) { return $this->uploadKey; } $key = $this->getRequest()->header('Upload-Key') ?? Uuid::uuid4()->toString(); if (empty($key)) { return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST)...
php
{ "resource": "" }
q20088
Server.serve
train
public function serve() { $this->applyMiddleware(); $requestMethod = $this->getRequest()->method(); if ( ! in_array($requestMethod, $this->getRequest()->allowedHttpVerbs())) { return $this->response->send(null, HttpResponse::HTTP_METHOD_NOT_ALLOWED); } $clientV...
php
{ "resource": "" }
q20089
Server.applyMiddleware
train
protected function applyMiddleware() { $middleware = $this->middleware()->list(); foreach ($middleware as $m) { $m->handle($this->getRequest(), $this->getResponse()); } }
php
{ "resource": "" }
q20090
Server.handleOptions
train
protected function handleOptions() : HttpResponse { $headers = [ 'Allow' => implode(',', $this->request->allowedHttpVerbs()), 'Tus-Version' => self::TUS_PROTOCOL_VERSION, 'Tus-Extension' => implode(',', self::TUS_EXTENSIONS), 'Tus-Checksum-Algorithm' => $this-...
php
{ "resource": "" }
q20091
Server.handleHead
train
protected function handleHead() : HttpResponse { $key = $this->request->key(); if ( ! $fileMeta = $this->cache->get($key)) { return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND); } $offset = $fileMeta['offset'] ?? false; if (false === $offset) { ...
php
{ "resource": "" }
q20092
Server.handlePost
train
protected function handlePost() : HttpResponse { $fileName = $this->getRequest()->extractFileName(); $uploadType = self::UPLOAD_TYPE_NORMAL; if (empty($fileName)) { return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST); } if ( ! $this->verifyUploa...
php
{ "resource": "" }
q20093
Server.handleConcatenation
train
protected function handleConcatenation(string $fileName, string $filePath) : HttpResponse { $partials = $this->getRequest()->extractPartials(); $uploadKey = $this->getUploadKey(); $files = $this->getPartialsMeta($partials); $filePaths = array_column($files, 'file_path'); ...
php
{ "resource": "" }
q20094
Server.handlePatch
train
protected function handlePatch() : HttpResponse { $uploadKey = $this->request->key(); if ( ! $meta = $this->cache->get($uploadKey)) { return $this->response->send(null, HttpResponse::HTTP_GONE); } $status = $this->verifyPatchRequest($meta); if (HttpResponse::HT...
php
{ "resource": "" }
q20095
Server.verifyPatchRequest
train
protected function verifyPatchRequest(array $meta) : int { if (self::UPLOAD_TYPE_FINAL === $meta['upload_type']) { return HttpResponse::HTTP_FORBIDDEN; } $uploadOffset = $this->request->header('upload-offset'); if ($uploadOffset && $uploadOffset !== (string) $meta['offs...
php
{ "resource": "" }
q20096
Server.handleDownload
train
protected function handleDownload() { $path = explode('/', str_replace('/get', '', $this->request->path())); $key = end($path); if ( ! $fileMeta = $this->cache->get($key)) { return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND); } ...
php
{ "resource": "" }
q20097
Server.handleDelete
train
protected function handleDelete() : HttpResponse { $key = $this->request->key(); $fileMeta = $this->cache->get($key); $resource = $fileMeta['file_path'] ?? null; if ( ! $resource) { return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND); } ...
php
{ "resource": "" }
q20098
Server.getHeadersForHeadRequest
train
protected function getHeadersForHeadRequest(array $fileMeta) : array { $headers = [ 'Upload-Length' => (int) $fileMeta['size'], 'Upload-Offset' => (int) $fileMeta['offset'], 'Cache-Control' => 'no-store', ]; if (self::UPLOAD_TYPE_FINAL === $fileMeta['uplo...
php
{ "resource": "" }
q20099
Server.buildFile
train
protected function buildFile(array $meta) : File { $file = new File($meta['name'], $this->cache); if (array_key_exists('offset', $meta)) { $file->setMeta($meta['offset'], $meta['size'], $meta['file_path'], $meta['location']); } return $file; }
php
{ "resource": "" }