repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ruflin/Elastica | lib/Elastica/Query/Terms.php | Terms.setTermsLookup | public function setTermsLookup(string $key, array $termsLookup): self
{
$this->_key = $key;
$this->_terms = $termsLookup;
return $this;
} | php | public function setTermsLookup(string $key, array $termsLookup): self
{
$this->_key = $key;
$this->_terms = $termsLookup;
return $this;
} | [
"public",
"function",
"setTermsLookup",
"(",
"string",
"$",
"key",
",",
"array",
"$",
"termsLookup",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_key",
"=",
"$",
"key",
";",
"$",
"this",
"->",
"_terms",
"=",
"$",
"termsLookup",
";",
"return",
"$",
"this",
";",
"}"
] | Sets key and terms lookup for the query.
@param string $key terms key
@param array $termsLookup terms lookup for the query
@return $this | [
"Sets",
"key",
"and",
"terms",
"lookup",
"for",
"the",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Terms.php#L66-L72 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.match | public function match(string $field = null, $values = null): Match
{
return new Match($field, $values);
} | php | public function match(string $field = null, $values = null): Match
{
return new Match($field, $values);
} | [
"public",
"function",
"match",
"(",
"string",
"$",
"field",
"=",
"null",
",",
"$",
"values",
"=",
"null",
")",
":",
"Match",
"{",
"return",
"new",
"Match",
"(",
"$",
"field",
",",
"$",
"values",
")",
";",
"}"
] | match query.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
@param string $field
@param mixed $values
@return Match | [
"match",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L77-L80 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.common_terms | public function common_terms(string $field, string $query, float $cutoffFrequency): Common
{
return new Common($field, $query, $cutoffFrequency);
} | php | public function common_terms(string $field, string $query, float $cutoffFrequency): Common
{
return new Common($field, $query, $cutoffFrequency);
} | [
"public",
"function",
"common_terms",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"query",
",",
"float",
"$",
"cutoffFrequency",
")",
":",
"Common",
"{",
"return",
"new",
"Common",
"(",
"$",
"field",
",",
"$",
"query",
",",
"$",
"cutoffFrequency",
")",
";",
"}"
] | common terms query.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
@param string $field
@param string $query
@param float $cutoffFrequency percentage in decimal form (.001 == 0.1%)
@return Common | [
"common",
"terms",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L129-L132 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.fuzzy | public function fuzzy(string $fieldName = null, string $value = null): Fuzzy
{
return new Fuzzy($fieldName, $value);
} | php | public function fuzzy(string $fieldName = null, string $value = null): Fuzzy
{
return new Fuzzy($fieldName, $value);
} | [
"public",
"function",
"fuzzy",
"(",
"string",
"$",
"fieldName",
"=",
"null",
",",
"string",
"$",
"value",
"=",
"null",
")",
":",
"Fuzzy",
"{",
"return",
"new",
"Fuzzy",
"(",
"$",
"fieldName",
",",
"$",
"value",
")",
";",
"}"
] | fuzzy query.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
@param string $fieldName Field name
@param string $value String to search for
@return Fuzzy | [
"fuzzy",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L182-L185 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.regexp | public function regexp(string $key = '', string $value = null, float $boost = 1.0): Regexp
{
return new Regexp($key, $value, $boost);
} | php | public function regexp(string $key = '', string $value = null, float $boost = 1.0): Regexp
{
return new Regexp($key, $value, $boost);
} | [
"public",
"function",
"regexp",
"(",
"string",
"$",
"key",
"=",
"''",
",",
"string",
"$",
"value",
"=",
"null",
",",
"float",
"$",
"boost",
"=",
"1.0",
")",
":",
"Regexp",
"{",
"return",
"new",
"Regexp",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"boost",
")",
";",
"}"
] | regexp query.
@param string $key
@param string $value
@param float $boost
@return Regexp
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html | [
"regexp",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L370-L373 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.span_first | public function span_first($match = null, int $end = null): SpanFirst
{
return new SpanFirst($match, $end);
} | php | public function span_first($match = null, int $end = null): SpanFirst
{
return new SpanFirst($match, $end);
} | [
"public",
"function",
"span_first",
"(",
"$",
"match",
"=",
"null",
",",
"int",
"$",
"end",
"=",
"null",
")",
":",
"SpanFirst",
"{",
"return",
"new",
"SpanFirst",
"(",
"$",
"match",
",",
"$",
"end",
")",
";",
"}"
] | span first query.
@param AbstractQuery|array $match
@param int $end
@return SpanFirst
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html | [
"span",
"first",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L385-L388 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.span_near | public function span_near(array $clauses = [], int $slop = 1, bool $inOrder = false): SpanNear
{
return new SpanNear($clauses, $slop, $inOrder);
} | php | public function span_near(array $clauses = [], int $slop = 1, bool $inOrder = false): SpanNear
{
return new SpanNear($clauses, $slop, $inOrder);
} | [
"public",
"function",
"span_near",
"(",
"array",
"$",
"clauses",
"=",
"[",
"]",
",",
"int",
"$",
"slop",
"=",
"1",
",",
"bool",
"$",
"inOrder",
"=",
"false",
")",
":",
"SpanNear",
"{",
"return",
"new",
"SpanNear",
"(",
"$",
"clauses",
",",
"$",
"slop",
",",
"$",
"inOrder",
")",
";",
"}"
] | span near query.
@param array $clauses
@param int $slop
@param bool $inOrder
@return SpanNear
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html | [
"span",
"near",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L415-L418 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.span_containing | public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanContaining
{
return new SpanContaining($little, $big);
} | php | public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanContaining
{
return new SpanContaining($little, $big);
} | [
"public",
"function",
"span_containing",
"(",
"AbstractSpanQuery",
"$",
"little",
"=",
"null",
",",
"AbstractSpanQuery",
"$",
"big",
"=",
"null",
")",
":",
"SpanContaining",
"{",
"return",
"new",
"SpanContaining",
"(",
"$",
"little",
",",
"$",
"big",
")",
";",
"}"
] | span_containing query.
@param AbstractSpanQuery|null $little
@param AbstractSpanQuery|null $big
@return SpanContaining
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-containing-query.html | [
"span_containing",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L473-L476 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.span_within | public function span_within(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanWithin
{
return new SpanWithin($little, $big);
} | php | public function span_within(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanWithin
{
return new SpanWithin($little, $big);
} | [
"public",
"function",
"span_within",
"(",
"AbstractSpanQuery",
"$",
"little",
"=",
"null",
",",
"AbstractSpanQuery",
"$",
"big",
"=",
"null",
")",
":",
"SpanWithin",
"{",
"return",
"new",
"SpanWithin",
"(",
"$",
"little",
",",
"$",
"big",
")",
";",
"}"
] | span_within query.
@param AbstractSpanQuery|null $little
@param AbstractSpanQuery|null $big
@return SpanWithin
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-within-query.html | [
"span_within",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L488-L491 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.wildcard | public function wildcard(string $key = '', string $value = null, float $boost = 1.0): Wildcard
{
return new Wildcard($key, $value, $boost);
} | php | public function wildcard(string $key = '', string $value = null, float $boost = 1.0): Wildcard
{
return new Wildcard($key, $value, $boost);
} | [
"public",
"function",
"wildcard",
"(",
"string",
"$",
"key",
"=",
"''",
",",
"string",
"$",
"value",
"=",
"null",
",",
"float",
"$",
"boost",
"=",
"1.0",
")",
":",
"Wildcard",
"{",
"return",
"new",
"Wildcard",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"boost",
")",
";",
"}"
] | wildcard query.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
@param string $key OPTIONAL Wildcard key
@param string $value OPTIONAL Wildcard value
@param float $boost OPTIONAL Boost value (default = 1)
@return Wildcard | [
"wildcard",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L533-L536 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder/DSL/Query.php | Query.geo_distance | public function geo_distance(string $key, $location, string $distance): GeoDistance
{
return new GeoDistance($key, $location, $distance);
} | php | public function geo_distance(string $key, $location, string $distance): GeoDistance
{
return new GeoDistance($key, $location, $distance);
} | [
"public",
"function",
"geo_distance",
"(",
"string",
"$",
"key",
",",
"$",
"location",
",",
"string",
"$",
"distance",
")",
":",
"GeoDistance",
"{",
"return",
"new",
"GeoDistance",
"(",
"$",
"key",
",",
"$",
"location",
",",
"$",
"distance",
")",
";",
"}"
] | geo distance query.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
@param string $key
@param array|string $location
@param string $distance
@return GeoDistance | [
"geo",
"distance",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder/DSL/Query.php#L549-L552 | train |
ruflin/Elastica | lib/Elastica/Transport/NullTransport.php | NullTransport.generateDefaultResponse | public function generateDefaultResponse(array $params): Response
{
$response = [
'took' => 0,
'timed_out' => false,
'_shards' => [
'total' => 0,
'successful' => 0,
'failed' => 0,
],
'hits' => [
'total' => 0,
'max_score' => null,
'hits' => [],
],
'params' => $params,
];
return new Response(JSON::stringify($response));
} | php | public function generateDefaultResponse(array $params): Response
{
$response = [
'took' => 0,
'timed_out' => false,
'_shards' => [
'total' => 0,
'successful' => 0,
'failed' => 0,
],
'hits' => [
'total' => 0,
'max_score' => null,
'hits' => [],
],
'params' => $params,
];
return new Response(JSON::stringify($response));
} | [
"public",
"function",
"generateDefaultResponse",
"(",
"array",
"$",
"params",
")",
":",
"Response",
"{",
"$",
"response",
"=",
"[",
"'took'",
"=>",
"0",
",",
"'timed_out'",
"=>",
"false",
",",
"'_shards'",
"=>",
"[",
"'total'",
"=>",
"0",
",",
"'successful'",
"=>",
"0",
",",
"'failed'",
"=>",
"0",
",",
"]",
",",
"'hits'",
"=>",
"[",
"'total'",
"=>",
"0",
",",
"'max_score'",
"=>",
"null",
",",
"'hits'",
"=>",
"[",
"]",
",",
"]",
",",
"'params'",
"=>",
"$",
"params",
",",
"]",
";",
"return",
"new",
"Response",
"(",
"JSON",
"::",
"stringify",
"(",
"$",
"response",
")",
")",
";",
"}"
] | Generate an example response object.
@param array $params Hostname, port, path, ...
@return Response $response | [
"Generate",
"an",
"example",
"response",
"object",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/NullTransport.php#L60-L79 | train |
ruflin/Elastica | lib/Elastica/Param.php | Param._convertArrayable | 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($value)) {
$arr[$key] = $this->_convertArrayable($value);
} else {
$arr[$key] = $value;
}
}
return $arr;
} | php | 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($value)) {
$arr[$key] = $this->_convertArrayable($value);
} else {
$arr[$key] = $value;
}
}
return $arr;
} | [
"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",
"(",
"$",
"value",
")",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_convertArrayable",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"arr",
";",
"}"
] | Cast objects to arrays.
@param array $array
@return array | [
"Cast",
"objects",
"to",
"arrays",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Param.php#L55-L70 | train |
ruflin/Elastica | lib/Elastica/Param.php | Param.getParam | public function getParam($key)
{
if (!$this->hasParam($key)) {
throw new InvalidException('Param '.$key.' does not exist');
}
return $this->_params[$key];
} | php | public function getParam($key)
{
if (!$this->hasParam($key)) {
throw new InvalidException('Param '.$key.' does not exist');
}
return $this->_params[$key];
} | [
"public",
"function",
"getParam",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasParam",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Param '",
".",
"$",
"key",
".",
"' does not exist'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
";",
"}"
] | Returns a specific param.
@param string $key Key to return
@throws \Elastica\Exception\InvalidException If requested key is not set
@return mixed Key value | [
"Returns",
"a",
"specific",
"param",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Param.php#L154-L161 | train |
ruflin/Elastica | lib/Elastica/Type/Mapping.php | Mapping.setParam | public function setParam(string $key, $value): Mapping
{
$this->_mapping[$key] = $value;
return $this;
} | php | public function setParam(string $key, $value): Mapping
{
$this->_mapping[$key] = $value;
return $this;
} | [
"public",
"function",
"setParam",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"Mapping",
"{",
"$",
"this",
"->",
"_mapping",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Sets raw parameters.
Possible options:
_uid
_id
_type
_source
_analyzer
_boost
_routing
_index
_size
properties
@param string $key Key name
@param mixed $value Key value
@return $this | [
"Sets",
"raw",
"parameters",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type/Mapping.php#L162-L167 | train |
ruflin/Elastica | lib/Elastica/Type/Mapping.php | Mapping.toArray | public function toArray(): array
{
$type = $this->getType();
if (empty($type)) {
throw new InvalidException('Type has to be set');
}
return [$type->getName() => $this->_mapping];
} | php | public function toArray(): array
{
$type = $this->getType();
if (empty($type)) {
throw new InvalidException('Type has to be set');
}
return [$type->getName() => $this->_mapping];
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Type has to be set'",
")",
";",
"}",
"return",
"[",
"$",
"type",
"->",
"getName",
"(",
")",
"=>",
"$",
"this",
"->",
"_mapping",
"]",
";",
"}"
] | Converts the mapping to an array.
@throws InvalidException
@return array Mapping as array | [
"Converts",
"the",
"mapping",
"to",
"an",
"array",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type/Mapping.php#L190-L199 | train |
ruflin/Elastica | lib/Elastica/Type/Mapping.php | Mapping.send | public function send(array $query = []): Response
{
$endpoint = new Put();
$endpoint->setBody($this->toArray());
$endpoint->setParams($query);
return $this->getType()->requestEndpoint($endpoint);
} | php | public function send(array $query = []): Response
{
$endpoint = new Put();
$endpoint->setBody($this->toArray());
$endpoint->setParams($query);
return $this->getType()->requestEndpoint($endpoint);
} | [
"public",
"function",
"send",
"(",
"array",
"$",
"query",
"=",
"[",
"]",
")",
":",
"Response",
"{",
"$",
"endpoint",
"=",
"new",
"Put",
"(",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
"->",
"getType",
"(",
")",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Submits the mapping and sends it to the server.
@param array $query Query string parameters to send with mapping
@return Response Response object | [
"Submits",
"the",
"mapping",
"and",
"sends",
"it",
"to",
"the",
"server",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type/Mapping.php#L208-L215 | train |
ruflin/Elastica | lib/Elastica/Type/Mapping.php | Mapping.create | public static function create($mapping): Mapping
{
if (\is_array($mapping)) {
$mappingObject = new self();
$mappingObject->setProperties($mapping);
return $mappingObject;
}
if ($mapping instanceof self) {
return $mapping;
}
throw new InvalidException('Invalid object type');
} | php | public static function create($mapping): Mapping
{
if (\is_array($mapping)) {
$mappingObject = new self();
$mappingObject->setProperties($mapping);
return $mappingObject;
}
if ($mapping instanceof self) {
return $mapping;
}
throw new InvalidException('Invalid object type');
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"mapping",
")",
":",
"Mapping",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"mapping",
")",
")",
"{",
"$",
"mappingObject",
"=",
"new",
"self",
"(",
")",
";",
"$",
"mappingObject",
"->",
"setProperties",
"(",
"$",
"mapping",
")",
";",
"return",
"$",
"mappingObject",
";",
"}",
"if",
"(",
"$",
"mapping",
"instanceof",
"self",
")",
"{",
"return",
"$",
"mapping",
";",
"}",
"throw",
"new",
"InvalidException",
"(",
"'Invalid object type'",
")",
";",
"}"
] | Creates a mapping object.
@param array|Mapping $mapping Mapping object or properties array
@throws InvalidException If invalid type
@return self | [
"Creates",
"a",
"mapping",
"object",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type/Mapping.php#L226-L240 | train |
ruflin/Elastica | lib/Elastica/ResultSet/ProcessingBuilder.php | ProcessingBuilder.buildResultSet | public function buildResultSet(Response $response, Query $query): ResultSet
{
$resultSet = $this->builder->buildResultSet($response, $query);
$this->processor->process($resultSet);
return $resultSet;
} | php | public function buildResultSet(Response $response, Query $query): ResultSet
{
$resultSet = $this->builder->buildResultSet($response, $query);
$this->processor->process($resultSet);
return $resultSet;
} | [
"public",
"function",
"buildResultSet",
"(",
"Response",
"$",
"response",
",",
"Query",
"$",
"query",
")",
":",
"ResultSet",
"{",
"$",
"resultSet",
"=",
"$",
"this",
"->",
"builder",
"->",
"buildResultSet",
"(",
"$",
"response",
",",
"$",
"query",
")",
";",
"$",
"this",
"->",
"processor",
"->",
"process",
"(",
"$",
"resultSet",
")",
";",
"return",
"$",
"resultSet",
";",
"}"
] | Runs any registered transformers on the ResultSet before
returning it, allowing the transformers to inject additional
data into each Result.
@param Response $response
@param Query $query
@return ResultSet | [
"Runs",
"any",
"registered",
"transformers",
"on",
"the",
"ResultSet",
"before",
"returning",
"it",
"allowing",
"the",
"transformers",
"to",
"inject",
"additional",
"data",
"into",
"each",
"Result",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/ResultSet/ProcessingBuilder.php#L41-L48 | train |
ruflin/Elastica | lib/Elastica/Aggregation/IpRange.php | IpRange.addRange | 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) {
$range['from'] = $fromValue;
}
if (null !== $toValue) {
$range['to'] = $toValue;
}
return $this->addParam('ranges', $range);
} | php | 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) {
$range['from'] = $fromValue;
}
if (null !== $toValue) {
$range['to'] = $toValue;
}
return $this->addParam('ranges', $range);
} | [
"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",
")",
"{",
"$",
"range",
"[",
"'from'",
"]",
"=",
"$",
"fromValue",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"toValue",
")",
"{",
"$",
"range",
"[",
"'to'",
"]",
"=",
"$",
"toValue",
";",
"}",
"return",
"$",
"this",
"->",
"addParam",
"(",
"'ranges'",
",",
"$",
"range",
")",
";",
"}"
] | Add an ip range to this aggregation.
@param string $fromValue a valid ipv4 address. Low end of this range, exclusive (greater than)
@param string $toValue a valid ipv4 address. High end of this range, exclusive (less than)
@throws \Elastica\Exception\InvalidException
@return $this | [
"Add",
"an",
"ip",
"range",
"to",
"this",
"aggregation",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/IpRange.php#L46-L62 | train |
ruflin/Elastica | lib/Elastica/Aggregation/AbstractAggregation.php | AbstractAggregation.addAggregation | 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 | 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;
} | [
"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",
";",
"}"
] | Add a sub-aggregation.
@param AbstractAggregation $aggregation
@throws \Elastica\Exception\InvalidException
@return $this | [
"Add",
"a",
"sub",
"-",
"aggregation",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/AbstractAggregation.php#L72-L81 | train |
ruflin/Elastica | lib/Elastica/Bulk/ResponseSet.php | ResponseSet.getError | public function getError(): string
{
foreach ($this->getBulkResponses() as $bulkResponse) {
if ($bulkResponse->hasError()) {
return $bulkResponse->getError();
}
}
return '';
} | php | public function getError(): string
{
foreach ($this->getBulkResponses() as $bulkResponse) {
if ($bulkResponse->hasError()) {
return $bulkResponse->getError();
}
}
return '';
} | [
"public",
"function",
"getError",
"(",
")",
":",
"string",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getBulkResponses",
"(",
")",
"as",
"$",
"bulkResponse",
")",
"{",
"if",
"(",
"$",
"bulkResponse",
"->",
"hasError",
"(",
")",
")",
"{",
"return",
"$",
"bulkResponse",
"->",
"getError",
"(",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Returns first found error.
@return string | [
"Returns",
"first",
"found",
"error",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Bulk/ResponseSet.php#L43-L52 | train |
ruflin/Elastica | lib/Elastica/Query/GeoBoundingBox.php | GeoBoundingBox.addCoordinates | 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' => $coordinates[0],
'bottom_right' => $coordinates[1],
]);
return $this;
} | php | 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' => $coordinates[0],
'bottom_right' => $coordinates[1],
]);
return $this;
} | [
"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'",
"=>",
"$",
"coordinates",
"[",
"0",
"]",
",",
"'bottom_right'",
"=>",
"$",
"coordinates",
"[",
"1",
"]",
",",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add coordinates.
@param string $key Key
@param array $coordinates Array with top left coordinate as first and bottom right coordinate as second element
@throws \Elastica\Exception\InvalidException If $coordinates doesn't have two elements
@return $this | [
"Add",
"coordinates",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/GeoBoundingBox.php#L37-L49 | train |
ruflin/Elastica | lib/Elastica/QueryBuilder.php | QueryBuilder.addDSL | public function addDSL(DSL $dsl)
{
$this->_facades[$dsl->getType()] = new Facade($dsl, $this->_version);
} | php | public function addDSL(DSL $dsl)
{
$this->_facades[$dsl->getType()] = new Facade($dsl, $this->_version);
} | [
"public",
"function",
"addDSL",
"(",
"DSL",
"$",
"dsl",
")",
"{",
"$",
"this",
"->",
"_facades",
"[",
"$",
"dsl",
"->",
"getType",
"(",
")",
"]",
"=",
"new",
"Facade",
"(",
"$",
"dsl",
",",
"$",
"this",
"->",
"_version",
")",
";",
"}"
] | Adds a new DSL object.
@param DSL $dsl | [
"Adds",
"a",
"new",
"DSL",
"object",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/QueryBuilder.php#L65-L68 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.updateByQuery | 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->toArray()['script'];
$endpoint->setBody($body);
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
} | php | 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->toArray()['script'];
$endpoint->setBody($body);
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
} | [
"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",
"->",
"toArray",
"(",
")",
"[",
"'script'",
"]",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Update entries in the db based on a query.
@param \Elastica\Query|string|array $query Query object or array
@param AbstractScript $script Script
@param array $options Optional params
@return \Elastica\Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html | [
"Update",
"entries",
"in",
"the",
"db",
"based",
"on",
"a",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L162-L176 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.forcemerge | public function forcemerge($args = [])
{
$endpoint = new ForceMerge();
$endpoint->setParams($args);
return $this->requestEndpoint($endpoint);
} | php | public function forcemerge($args = [])
{
$endpoint = new ForceMerge();
$endpoint->setParams($args);
return $this->requestEndpoint($endpoint);
} | [
"public",
"function",
"forcemerge",
"(",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"endpoint",
"=",
"new",
"ForceMerge",
"(",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Force merges index.
Detailed arguments can be found here in the link
@param array $args OPTIONAL Additional arguments
@return Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html | [
"Force",
"merges",
"index",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L257-L263 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.create | 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($options)) {
foreach ($options as $key => $value) {
switch ($key) {
case 'recreate':
try {
$this->delete();
} catch (ResponseException $e) {
// Table can't be deleted, because doesn't exist
}
break;
default:
throw new InvalidException('Invalid option '.$key);
break;
}
}
}
$endpoint = new Create();
$endpoint->setBody($args);
return $this->requestEndpoint($endpoint);
} | php | 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($options)) {
foreach ($options as $key => $value) {
switch ($key) {
case 'recreate':
try {
$this->delete();
} catch (ResponseException $e) {
// Table can't be deleted, because doesn't exist
}
break;
default:
throw new InvalidException('Invalid option '.$key);
break;
}
}
}
$endpoint = new Create();
$endpoint->setBody($args);
return $this->requestEndpoint($endpoint);
} | [
"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",
"(",
"$",
"options",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'recreate'",
":",
"try",
"{",
"$",
"this",
"->",
"delete",
"(",
")",
";",
"}",
"catch",
"(",
"ResponseException",
"$",
"e",
")",
"{",
"// Table can't be deleted, because doesn't exist",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidException",
"(",
"'Invalid option '",
".",
"$",
"key",
")",
";",
"break",
";",
"}",
"}",
"}",
"$",
"endpoint",
"=",
"new",
"Create",
"(",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Creates a new index with the given arguments.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
@param array $args OPTIONAL Arguments to use
@param bool|array $options OPTIONAL
bool=> Deletes index first if already exists (default = false).
array => Associative array of options (option=>value)
@throws \Elastica\Exception\InvalidException
@throws \Elastica\Exception\ResponseException
@return \Elastica\Response Server response | [
"Creates",
"a",
"new",
"index",
"with",
"the",
"given",
"arguments",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L292-L321 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.addAlias | 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(), 'alias' => $name]];
}
}
$data['actions'][] = ['add' => ['index' => $this->getName(), 'alias' => $name]];
$endpoint = new Update();
$endpoint->setBody($data);
return $this->getClient()->requestEndpoint($endpoint);
} | php | 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(), 'alias' => $name]];
}
}
$data['actions'][] = ['add' => ['index' => $this->getName(), 'alias' => $name]];
$endpoint = new Update();
$endpoint->setBody($data);
return $this->getClient()->requestEndpoint($endpoint);
} | [
"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",
"(",
")",
",",
"'alias'",
"=>",
"$",
"name",
"]",
"]",
";",
"}",
"}",
"$",
"data",
"[",
"'actions'",
"]",
"[",
"]",
"=",
"[",
"'add'",
"=>",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'alias'",
"=>",
"$",
"name",
"]",
"]",
";",
"$",
"endpoint",
"=",
"new",
"Update",
"(",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Adds an alias to the current index.
@param string $name Alias name
@param bool $replace OPTIONAL If set, an existing alias will be replaced
@return \Elastica\Response Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html | [
"Adds",
"an",
"alias",
"to",
"the",
"current",
"index",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L438-L455 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.removeAlias | public function removeAlias($name)
{
$endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Delete();
$endpoint->setName($name);
return $this->requestEndpoint($endpoint);
} | php | public function removeAlias($name)
{
$endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Delete();
$endpoint->setName($name);
return $this->requestEndpoint($endpoint);
} | [
"public",
"function",
"removeAlias",
"(",
"$",
"name",
")",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Indices",
"\\",
"Alias",
"\\",
"Delete",
"(",
")",
";",
"$",
"endpoint",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Removes an alias pointing to the current index.
@param string $name Alias name
@return \Elastica\Response Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html | [
"Removes",
"an",
"alias",
"pointing",
"to",
"the",
"current",
"index",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L466-L472 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.getAliases | public function getAliases()
{
$endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Get();
$endpoint->setName('*');
$responseData = $this->requestEndpoint($endpoint)->getData();
if (!isset($responseData[$this->getName()])) {
return [];
}
$data = $responseData[$this->getName()];
if (!empty($data['aliases'])) {
return \array_keys($data['aliases']);
}
return [];
} | php | public function getAliases()
{
$endpoint = new \Elasticsearch\Endpoints\Indices\Alias\Get();
$endpoint->setName('*');
$responseData = $this->requestEndpoint($endpoint)->getData();
if (!isset($responseData[$this->getName()])) {
return [];
}
$data = $responseData[$this->getName()];
if (!empty($data['aliases'])) {
return \array_keys($data['aliases']);
}
return [];
} | [
"public",
"function",
"getAliases",
"(",
")",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Indices",
"\\",
"Alias",
"\\",
"Get",
"(",
")",
";",
"$",
"endpoint",
"->",
"setName",
"(",
"'*'",
")",
";",
"$",
"responseData",
"=",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"responseData",
"[",
"$",
"this",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"data",
"=",
"$",
"responseData",
"[",
"$",
"this",
"->",
"getName",
"(",
")",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'aliases'",
"]",
")",
")",
"{",
"return",
"\\",
"array_keys",
"(",
"$",
"data",
"[",
"'aliases'",
"]",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Returns all index aliases.
@return array Aliases | [
"Returns",
"all",
"index",
"aliases",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L479-L496 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.flush | public function flush(array $options = [])
{
$endpoint = new Flush();
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
} | php | public function flush(array $options = [])
{
$endpoint = new Flush();
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
} | [
"public",
"function",
"flush",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"endpoint",
"=",
"new",
"Flush",
"(",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Flushes the index to storage.
@param array $options
@return Response Response object
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html | [
"Flushes",
"the",
"index",
"to",
"storage",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L532-L538 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.setSettings | public function setSettings(array $data)
{
$endpoint = new Put();
$endpoint->setBody($data);
return $this->requestEndpoint($endpoint);
} | php | public function setSettings(array $data)
{
$endpoint = new Put();
$endpoint->setBody($data);
return $this->requestEndpoint($endpoint);
} | [
"public",
"function",
"setSettings",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"endpoint",
"=",
"new",
"Put",
"(",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] | Can be used to change settings during runtime. One example is to use it for bulk updating.
@param array $data Data array
@return \Elastica\Response Response object
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html | [
"Can",
"be",
"used",
"to",
"change",
"settings",
"during",
"runtime",
".",
"One",
"example",
"is",
"to",
"use",
"it",
"for",
"bulk",
"updating",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L549-L555 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.requestEndpoint | public function requestEndpoint(AbstractEndpoint $endpoint)
{
$cloned = clone $endpoint;
$cloned->setIndex($this->getName());
return $this->getClient()->requestEndpoint($cloned);
} | php | public function requestEndpoint(AbstractEndpoint $endpoint)
{
$cloned = clone $endpoint;
$cloned->setIndex($this->getName());
return $this->getClient()->requestEndpoint($cloned);
} | [
"public",
"function",
"requestEndpoint",
"(",
"AbstractEndpoint",
"$",
"endpoint",
")",
"{",
"$",
"cloned",
"=",
"clone",
"$",
"endpoint",
";",
"$",
"cloned",
"->",
"setIndex",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"requestEndpoint",
"(",
"$",
"cloned",
")",
";",
"}"
] | Makes calls to the elasticsearch server with usage official client Endpoint based on this index.
@param AbstractEndpoint $endpoint
@return Response | [
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"with",
"usage",
"official",
"client",
"Endpoint",
"based",
"on",
"this",
"index",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L581-L587 | train |
ruflin/Elastica | lib/Elastica/Index.php | Index.analyze | 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 Elastic
// @see: https://www.elastic.co/guide/en/elasticsearch/reference/current/_explain_analyze.html
if (isset($body['explain']) && $body['explain']) {
return $data['detail'];
}
return $data['tokens'];
} | php | 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 Elastic
// @see: https://www.elastic.co/guide/en/elasticsearch/reference/current/_explain_analyze.html
if (isset($body['explain']) && $body['explain']) {
return $data['detail'];
}
return $data['tokens'];
} | [
"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 Elastic",
"// @see: https://www.elastic.co/guide/en/elasticsearch/reference/current/_explain_analyze.html",
"if",
"(",
"isset",
"(",
"$",
"body",
"[",
"'explain'",
"]",
")",
"&&",
"$",
"body",
"[",
"'explain'",
"]",
")",
"{",
"return",
"$",
"data",
"[",
"'detail'",
"]",
";",
"}",
"return",
"$",
"data",
"[",
"'tokens'",
"]",
";",
"}"
] | Analyzes a string.
Detailed arguments can be found here in the link
@param array $body String to be analyzed
@param array $args OPTIONAL Additional arguments
@return array Server response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html | [
"Analyzes",
"a",
"string",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index.php#L601-L616 | train |
ruflin/Elastica | lib/Elastica/ResultSet/DefaultBuilder.php | DefaultBuilder.buildResultSet | public function buildResultSet(Response $response, Query $query): ResultSet
{
$results = $this->buildResults($response);
$resultSet = new ResultSet($response, $query, $results);
return $resultSet;
} | php | public function buildResultSet(Response $response, Query $query): ResultSet
{
$results = $this->buildResults($response);
$resultSet = new ResultSet($response, $query, $results);
return $resultSet;
} | [
"public",
"function",
"buildResultSet",
"(",
"Response",
"$",
"response",
",",
"Query",
"$",
"query",
")",
":",
"ResultSet",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"buildResults",
"(",
"$",
"response",
")",
";",
"$",
"resultSet",
"=",
"new",
"ResultSet",
"(",
"$",
"response",
",",
"$",
"query",
",",
"$",
"results",
")",
";",
"return",
"$",
"resultSet",
";",
"}"
] | Builds a ResultSet for a given Response.
@param Response $response
@param Query $query
@return ResultSet | [
"Builds",
"a",
"ResultSet",
"for",
"a",
"given",
"Response",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/ResultSet/DefaultBuilder.php#L20-L26 | train |
ruflin/Elastica | lib/Elastica/ResultSet/DefaultBuilder.php | DefaultBuilder.buildResults | 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);
}
return $results;
} | php | 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);
}
return $results;
} | [
"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",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Builds individual result objects.
@param Response $response
@return Result[] | [
"Builds",
"individual",
"result",
"objects",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/ResultSet/DefaultBuilder.php#L35-L49 | train |
ruflin/Elastica | lib/Elastica/Query/Common.php | Common.setQueryParam | public function setQueryParam(string $key, $value): self
{
$this->_queryParams[$key] = $value;
return $this;
} | php | public function setQueryParam(string $key, $value): self
{
$this->_queryParams[$key] = $value;
return $this;
} | [
"public",
"function",
"setQueryParam",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_queryParams",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a parameter in the body of this query.
@param string $key parameter key
@param mixed $value parameter value
@return $this | [
"Set",
"a",
"parameter",
"in",
"the",
"body",
"of",
"this",
"query",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Common.php#L145-L150 | train |
ruflin/Elastica | lib/Elastica/Aggregation/AbstractTermsAggregation.php | AbstractTermsAggregation.setInclude | 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 | 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,
]);
} | [
"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",
",",
"]",
")",
";",
"}"
] | Filter documents to include based on a regular expression.
@param string $pattern a regular expression
@param string $flags Java Pattern flags
@return $this | [
"Filter",
"documents",
"to",
"include",
"based",
"on",
"a",
"regular",
"expression",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/AbstractTermsAggregation.php#L30-L40 | train |
ruflin/Elastica | lib/Elastica/Aggregation/AbstractTermsAggregation.php | AbstractTermsAggregation.setExclude | 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 | 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,
]);
} | [
"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",
",",
"]",
")",
";",
"}"
] | Filter documents to exclude based on a regular expression.
@param string $pattern a regular expression
@param string $flags Java Pattern flags
@return $this | [
"Filter",
"documents",
"to",
"exclude",
"based",
"on",
"a",
"regular",
"expression",
"."
] | 9bda1596f79a28534dfd7b3513443478ad152e4e | https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/AbstractTermsAggregation.php#L50-L60 | train |
ankitpokhrel/tus-php | src/Cache/FileStore.php | FileStore.createCacheFile | protected function createCacheFile()
{
$this->createCacheDir();
$cacheFilePath = $this->getCacheFile();
if ( ! file_exists($cacheFilePath)) {
touch($cacheFilePath);
}
} | php | protected function createCacheFile()
{
$this->createCacheDir();
$cacheFilePath = $this->getCacheFile();
if ( ! file_exists($cacheFilePath)) {
touch($cacheFilePath);
}
} | [
"protected",
"function",
"createCacheFile",
"(",
")",
"{",
"$",
"this",
"->",
"createCacheDir",
"(",
")",
";",
"$",
"cacheFilePath",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"cacheFilePath",
")",
")",
"{",
"touch",
"(",
"$",
"cacheFilePath",
")",
";",
"}",
"}"
] | Create a cache file.
@return void | [
"Create",
"a",
"cache",
"file",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/FileStore.php#L97-L106 | train |
ankitpokhrel/tus-php | src/Cache/FileStore.php | FileStore.put | public function put(string $path, string $contents) : int
{
return file_put_contents($path, $contents, LOCK_EX);
} | php | public function put(string $path, string $contents) : int
{
return file_put_contents($path, $contents, LOCK_EX);
} | [
"public",
"function",
"put",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"contents",
")",
":",
"int",
"{",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"contents",
",",
"LOCK_EX",
")",
";",
"}"
] | Write the contents of a file with exclusive lock.
@param string $path
@param string $contents
@return int | [
"Write",
"the",
"contents",
"of",
"a",
"file",
"with",
"exclusive",
"lock",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/FileStore.php#L166-L169 | train |
ankitpokhrel/tus-php | src/Cache/FileStore.php | FileStore.isValid | 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_at']);
} | php | 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_at']);
} | [
"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_at'",
"]",
")",
";",
"}"
] | Check if cache is still valid.
@param string $key
@return bool | [
"Check",
"if",
"cache",
"is",
"still",
"valid",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/FileStore.php#L232-L242 | train |
ankitpokhrel/tus-php | src/Cache/FileStore.php | FileStore.getCacheContents | public function getCacheContents()
{
$cacheFile = $this->getCacheFile();
if ( ! file_exists($cacheFile)) {
return false;
}
return json_decode($this->sharedGet($cacheFile), true) ?? [];
} | php | public function getCacheContents()
{
$cacheFile = $this->getCacheFile();
if ( ! file_exists($cacheFile)) {
return false;
}
return json_decode($this->sharedGet($cacheFile), true) ?? [];
} | [
"public",
"function",
"getCacheContents",
"(",
")",
"{",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"cacheFile",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"sharedGet",
"(",
"$",
"cacheFile",
")",
",",
"true",
")",
"??",
"[",
"]",
";",
"}"
] | Get cache contents.
@return array|bool | [
"Get",
"cache",
"contents",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/FileStore.php#L249-L258 | train |
ankitpokhrel/tus-php | src/Cache/FileStore.php | FileStore.getActualCacheKey | public function getActualCacheKey(string $key) : string
{
$prefix = $this->getPrefix();
if (false === strpos($key, $prefix)) {
$key = $prefix . $key;
}
return $key;
} | php | public function getActualCacheKey(string $key) : string
{
$prefix = $this->getPrefix();
if (false === strpos($key, $prefix)) {
$key = $prefix . $key;
}
return $key;
} | [
"public",
"function",
"getActualCacheKey",
"(",
"string",
"$",
"key",
")",
":",
"string",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"getPrefix",
"(",
")",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
")",
"{",
"$",
"key",
"=",
"$",
"prefix",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | Get actual cache key with prefix.
@param string $key
@return string | [
"Get",
"actual",
"cache",
"key",
"with",
"prefix",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/FileStore.php#L267-L276 | train |
ankitpokhrel/tus-php | src/Response.php | Response.send | 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, $status, $headers);
return $this->createOnly ? $response : $response->send();
} | php | 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, $status, $headers);
return $this->createOnly ? $response : $response->send();
} | [
"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",
",",
"$",
"status",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"createOnly",
"?",
"$",
"response",
":",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | Create and send a response.
@param mixed $content Response data.
@param int $status Http status code.
@param array $headers Headers.
@return HttpResponse | [
"Create",
"and",
"send",
"a",
"response",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Response.php#L100-L111 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.file | 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->fileSize = filesize($file);
return $this;
} | php | 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->fileSize = filesize($file);
return $this;
} | [
"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",
"->",
"fileSize",
"=",
"filesize",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set file properties.
@param string $file File path.
@param string $name File name.
@return Client | [
"Set",
"file",
"properties",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L79-L91 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.getChecksum | public function getChecksum() : string
{
if (empty($this->checksum)) {
$this->setChecksum(hash_file($this->getChecksumAlgorithm(), $this->getFilePath()));
}
return $this->checksum;
} | php | public function getChecksum() : string
{
if (empty($this->checksum)) {
$this->setChecksum(hash_file($this->getChecksumAlgorithm(), $this->getFilePath()));
}
return $this->checksum;
} | [
"public",
"function",
"getChecksum",
"(",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"checksum",
")",
")",
"{",
"$",
"this",
"->",
"setChecksum",
"(",
"hash_file",
"(",
"$",
"this",
"->",
"getChecksumAlgorithm",
"(",
")",
",",
"$",
"this",
"->",
"getFilePath",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"checksum",
";",
"}"
] | Get checksum.
@return string | [
"Get",
"checksum",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L166-L173 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.isExpired | public function isExpired() : bool
{
$expiresAt = $this->getCache()->get($this->getKey())['expires_at'] ?? null;
return empty($expiresAt) || Carbon::parse($expiresAt)->lt(Carbon::now());
} | php | public function isExpired() : bool
{
$expiresAt = $this->getCache()->get($this->getKey())['expires_at'] ?? null;
return empty($expiresAt) || Carbon::parse($expiresAt)->lt(Carbon::now());
} | [
"public",
"function",
"isExpired",
"(",
")",
":",
"bool",
"{",
"$",
"expiresAt",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
"[",
"'expires_at'",
"]",
"??",
"null",
";",
"return",
"empty",
"(",
"$",
"expiresAt",
")",
"||",
"Carbon",
"::",
"parse",
"(",
"$",
"expiresAt",
")",
"->",
"lt",
"(",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}"
] | Check if current upload is expired.
@return bool | [
"Check",
"if",
"current",
"upload",
"is",
"expired",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L244-L249 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.seek | public function seek(int $offset) : self
{
$this->partialOffset = $offset;
$this->partial();
return $this;
} | php | public function seek(int $offset) : self
{
$this->partialOffset = $offset;
$this->partial();
return $this;
} | [
"public",
"function",
"seek",
"(",
"int",
"$",
"offset",
")",
":",
"self",
"{",
"$",
"this",
"->",
"partialOffset",
"=",
"$",
"offset",
";",
"$",
"this",
"->",
"partial",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set offset and force this to be a partial upload request.
@param int $offset
@return self | [
"Set",
"offset",
"and",
"force",
"this",
"to",
"be",
"a",
"partial",
"upload",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L278-L285 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.create | 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),
];
if ($this->isPartial()) {
$headers += ['Upload-Concat' => 'partial'];
}
$response = $this->getClient()->post($this->apiPath, [
'headers' => $headers,
]);
$statusCode = $response->getStatusCode();
if (HttpResponse::HTTP_CREATED !== $statusCode) {
throw new FileException('Unable to create resource.');
}
$uploadLocation = current($response->getHeader('location'));
$this->getCache()->set($this->getKey(), [
'location' => $uploadLocation,
'expires_at' => Carbon::now()->addSeconds($this->getCache()->getTtl())->format($this->getCache()::RFC_7231),
]);
return $uploadLocation;
} | php | 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),
];
if ($this->isPartial()) {
$headers += ['Upload-Concat' => 'partial'];
}
$response = $this->getClient()->post($this->apiPath, [
'headers' => $headers,
]);
$statusCode = $response->getStatusCode();
if (HttpResponse::HTTP_CREATED !== $statusCode) {
throw new FileException('Unable to create resource.');
}
$uploadLocation = current($response->getHeader('location'));
$this->getCache()->set($this->getKey(), [
'location' => $uploadLocation,
'expires_at' => Carbon::now()->addSeconds($this->getCache()->getTtl())->format($this->getCache()::RFC_7231),
]);
return $uploadLocation;
} | [
"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",
")",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isPartial",
"(",
")",
")",
"{",
"$",
"headers",
"+=",
"[",
"'Upload-Concat'",
"=>",
"'partial'",
"]",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"post",
"(",
"$",
"this",
"->",
"apiPath",
",",
"[",
"'headers'",
"=>",
"$",
"headers",
",",
"]",
")",
";",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"HttpResponse",
"::",
"HTTP_CREATED",
"!==",
"$",
"statusCode",
")",
"{",
"throw",
"new",
"FileException",
"(",
"'Unable to create resource.'",
")",
";",
"}",
"$",
"uploadLocation",
"=",
"current",
"(",
"$",
"response",
"->",
"getHeader",
"(",
"'location'",
")",
")",
";",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"[",
"'location'",
"=>",
"$",
"uploadLocation",
",",
"'expires_at'",
"=>",
"Carbon",
"::",
"now",
"(",
")",
"->",
"addSeconds",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"getTtl",
"(",
")",
")",
"->",
"format",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
"::",
"RFC_7231",
")",
",",
"]",
")",
";",
"return",
"$",
"uploadLocation",
";",
"}"
] | Create resource with POST request.
@param string $key
@throws FileException
@return string | [
"Create",
"resource",
"with",
"POST",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L346-L377 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.concat | 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(),
'Upload-Metadata' => 'filename ' . base64_encode($this->fileName),
'Upload-Concat' => self::UPLOAD_TYPE_FINAL . ';' . implode(' ', $partials),
],
]);
$data = json_decode($response->getBody(), true);
$checksum = $data['data']['checksum'] ?? null;
$statusCode = $response->getStatusCode();
if (HttpResponse::HTTP_CREATED !== $statusCode || ! $checksum) {
throw new FileException('Unable to create resource.');
}
return $checksum;
} | php | 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(),
'Upload-Metadata' => 'filename ' . base64_encode($this->fileName),
'Upload-Concat' => self::UPLOAD_TYPE_FINAL . ';' . implode(' ', $partials),
],
]);
$data = json_decode($response->getBody(), true);
$checksum = $data['data']['checksum'] ?? null;
$statusCode = $response->getStatusCode();
if (HttpResponse::HTTP_CREATED !== $statusCode || ! $checksum) {
throw new FileException('Unable to create resource.');
}
return $checksum;
} | [
"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",
"(",
")",
",",
"'Upload-Metadata'",
"=>",
"'filename '",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"fileName",
")",
",",
"'Upload-Concat'",
"=>",
"self",
"::",
"UPLOAD_TYPE_FINAL",
".",
"';'",
".",
"implode",
"(",
"' '",
",",
"$",
"partials",
")",
",",
"]",
",",
"]",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"$",
"checksum",
"=",
"$",
"data",
"[",
"'data'",
"]",
"[",
"'checksum'",
"]",
"??",
"null",
";",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"HttpResponse",
"::",
"HTTP_CREATED",
"!==",
"$",
"statusCode",
"||",
"!",
"$",
"checksum",
")",
"{",
"throw",
"new",
"FileException",
"(",
"'Unable to create resource.'",
")",
";",
"}",
"return",
"$",
"checksum",
";",
"}"
] | Concatenate 2 or more partial uploads.
@param string $key
@param mixed $partials
@return string | [
"Concatenate",
"2",
"or",
"more",
"partial",
"uploads",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L387-L408 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.delete | 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) {
throw new FileException('File not found.');
}
}
} | php | 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) {
throw new FileException('File not found.');
}
}
} | [
"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",
")",
"{",
"throw",
"new",
"FileException",
"(",
"'File not found.'",
")",
";",
"}",
"}",
"}"
] | Send DELETE request.
@throws FileException
@return void | [
"Send",
"DELETE",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L417-L428 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.partial | 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::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
}
$this->key = $key . uniqid(self::PARTIAL_UPLOAD_NAME_SEPARATOR);
} | php | 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::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
}
$this->key = $key . uniqid(self::PARTIAL_UPLOAD_NAME_SEPARATOR);
} | [
"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",
"::",
"PARTIAL_UPLOAD_NAME_SEPARATOR",
",",
"$",
"key",
")",
";",
"}",
"$",
"this",
"->",
"key",
"=",
"$",
"key",
".",
"uniqid",
"(",
"self",
"::",
"PARTIAL_UPLOAD_NAME_SEPARATOR",
")",
";",
"}"
] | Set as partial request.
@param bool $state
@return void | [
"Set",
"as",
"partial",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L437-L452 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.handleClientException | 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_CONTINUE === $statusCode) {
return new ConnectionException('Connection aborted by user.');
}
if (HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE === $statusCode) {
return new TusException('Unsupported media types.');
}
return new TusException($e->getResponse()->getBody(), $statusCode);
} | php | 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_CONTINUE === $statusCode) {
return new ConnectionException('Connection aborted by user.');
}
if (HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE === $statusCode) {
return new TusException('Unsupported media types.');
}
return new TusException($e->getResponse()->getBody(), $statusCode);
} | [
"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_CONTINUE",
"===",
"$",
"statusCode",
")",
"{",
"return",
"new",
"ConnectionException",
"(",
"'Connection aborted by user.'",
")",
";",
"}",
"if",
"(",
"HttpResponse",
"::",
"HTTP_UNSUPPORTED_MEDIA_TYPE",
"===",
"$",
"statusCode",
")",
"{",
"return",
"new",
"TusException",
"(",
"'Unsupported media types.'",
")",
";",
"}",
"return",
"new",
"TusException",
"(",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"$",
"statusCode",
")",
";",
"}"
] | Handle client exception during patch request.
@param ClientException $e
@return mixed | [
"Handle",
"client",
"exception",
"during",
"patch",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L521-L538 | train |
ankitpokhrel/tus-php | src/Tus/Client.php | Client.getData | 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 | 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;
} | [
"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",
";",
"}"
] | Get X bytes of data from file.
@param int $offset
@param int $bytes
@return string | [
"Get",
"X",
"bytes",
"of",
"data",
"from",
"file",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Client.php#L548-L560 | train |
ankitpokhrel/tus-php | src/File.php | File.setMeta | 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 | 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;
} | [
"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",
";",
"}"
] | Set file meta.
@param int $offset
@param int $fileSize
@param string $filePath
@param string $location
@return File | [
"Set",
"file",
"meta",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L71-L79 | train |
ankitpokhrel/tus-php | src/File.php | File.details | 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->filePath,
'created_at' => $now->format($this->cache::RFC_7231),
'expires_at' => $now->addSeconds($this->cache->getTtl())->format($this->cache::RFC_7231),
];
} | php | 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->filePath,
'created_at' => $now->format($this->cache::RFC_7231),
'expires_at' => $now->addSeconds($this->cache->getTtl())->format($this->cache::RFC_7231),
];
} | [
"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",
"->",
"filePath",
",",
"'created_at'",
"=>",
"$",
"now",
"->",
"format",
"(",
"$",
"this",
"->",
"cache",
"::",
"RFC_7231",
")",
",",
"'expires_at'",
"=>",
"$",
"now",
"->",
"addSeconds",
"(",
"$",
"this",
"->",
"cache",
"->",
"getTtl",
"(",
")",
")",
"->",
"format",
"(",
"$",
"this",
"->",
"cache",
"::",
"RFC_7231",
")",
",",
"]",
";",
"}"
] | Get file meta.
@return array | [
"Get",
"file",
"meta",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L264-L278 | train |
ankitpokhrel/tus-php | src/File.php | File.upload | 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->getKey();
try {
$this->seek($output, $this->offset);
while ( ! feof($input)) {
if (CONNECTION_NORMAL !== connection_status()) {
throw new ConnectionException('Connection aborted by user.');
}
$data = $this->read($input, self::CHUNK_SIZE);
$bytes = $this->write($output, $data, self::CHUNK_SIZE);
$this->offset += $bytes;
$this->cache->set($key, ['offset' => $this->offset]);
if ($this->offset > $totalBytes) {
throw new OutOfRangeException('The uploaded file is corrupt.');
}
if ($this->offset === $totalBytes) {
break;
}
}
} finally {
$this->close($input);
$this->close($output);
}
return $this->offset;
} | php | 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->getKey();
try {
$this->seek($output, $this->offset);
while ( ! feof($input)) {
if (CONNECTION_NORMAL !== connection_status()) {
throw new ConnectionException('Connection aborted by user.');
}
$data = $this->read($input, self::CHUNK_SIZE);
$bytes = $this->write($output, $data, self::CHUNK_SIZE);
$this->offset += $bytes;
$this->cache->set($key, ['offset' => $this->offset]);
if ($this->offset > $totalBytes) {
throw new OutOfRangeException('The uploaded file is corrupt.');
}
if ($this->offset === $totalBytes) {
break;
}
}
} finally {
$this->close($input);
$this->close($output);
}
return $this->offset;
} | [
"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",
"->",
"getKey",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"seek",
"(",
"$",
"output",
",",
"$",
"this",
"->",
"offset",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"input",
")",
")",
"{",
"if",
"(",
"CONNECTION_NORMAL",
"!==",
"connection_status",
"(",
")",
")",
"{",
"throw",
"new",
"ConnectionException",
"(",
"'Connection aborted by user.'",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"input",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"$",
"bytes",
"=",
"$",
"this",
"->",
"write",
"(",
"$",
"output",
",",
"$",
"data",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"$",
"this",
"->",
"offset",
"+=",
"$",
"bytes",
";",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"key",
",",
"[",
"'offset'",
"=>",
"$",
"this",
"->",
"offset",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"offset",
">",
"$",
"totalBytes",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
"'The uploaded file is corrupt.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"offset",
"===",
"$",
"totalBytes",
")",
"{",
"break",
";",
"}",
"}",
"}",
"finally",
"{",
"$",
"this",
"->",
"close",
"(",
"$",
"input",
")",
";",
"$",
"this",
"->",
"close",
"(",
"$",
"output",
")",
";",
"}",
"return",
"$",
"this",
"->",
"offset",
";",
"}"
] | Upload file to server.
@param int $totalBytes
@throws ConnectionException
@return int | [
"Upload",
"file",
"to",
"server",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L289-L328 | train |
ankitpokhrel/tus-php | src/File.php | File.open | 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 | 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;
} | [
"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",
";",
"}"
] | Open file in given mode.
@param string $filePath
@param string $mode
@throws FileException
@return resource | [
"Open",
"file",
"in",
"given",
"mode",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L340-L351 | train |
ankitpokhrel/tus-php | src/File.php | File.exists | 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.');
}
return true;
} | php | 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.');
}
return true;
} | [
"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.'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Check if file to read exists.
@param string $filePath
@param string $mode
@throws FileException
@return bool | [
"Check",
"if",
"file",
"to",
"read",
"exists",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L363-L374 | train |
ankitpokhrel/tus-php | src/File.php | File.seek | 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 | 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;
} | [
"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",
";",
"}"
] | Move file pointer to given offset.
@param Resource $handle
@param int $offset
@param int $whence
@throws FileException
@return int | [
"Move",
"file",
"pointer",
"to",
"given",
"offset",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L387-L396 | train |
ankitpokhrel/tus-php | src/File.php | File.read | public function read($handle, int $chunkSize) : string
{
$data = fread($handle, $chunkSize);
if (false === $data) {
throw new FileException('Cannot read file.');
}
return (string) $data;
} | php | public function read($handle, int $chunkSize) : string
{
$data = fread($handle, $chunkSize);
if (false === $data) {
throw new FileException('Cannot read file.');
}
return (string) $data;
} | [
"public",
"function",
"read",
"(",
"$",
"handle",
",",
"int",
"$",
"chunkSize",
")",
":",
"string",
"{",
"$",
"data",
"=",
"fread",
"(",
"$",
"handle",
",",
"$",
"chunkSize",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"throw",
"new",
"FileException",
"(",
"'Cannot read file.'",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"data",
";",
"}"
] | Read data from file.
@param Resource $handle
@param int $chunkSize
@throws FileException
@return string | [
"Read",
"data",
"from",
"file",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L408-L417 | train |
ankitpokhrel/tus-php | src/File.php | File.write | 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 | 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;
} | [
"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",
";",
"}"
] | Write data to file.
@param Resource $handle
@param string $data
@param int|null $length
@throws FileException
@return int | [
"Write",
"data",
"to",
"file",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L430-L439 | train |
ankitpokhrel/tus-php | src/File.php | File.merge | 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->fileSize = filesize($firstFile['file_path']);
$handle = $this->open($destination, self::APPEND_BINARY);
foreach ($files as $file) {
if ( ! file_exists($file['file_path'])) {
throw new FileException('File to be merged not found.');
}
$this->fileSize += $this->write($handle, file_get_contents($file['file_path']));
$this->offset += $file['offset'];
}
$this->close($handle);
return $this->fileSize;
} | php | 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->fileSize = filesize($firstFile['file_path']);
$handle = $this->open($destination, self::APPEND_BINARY);
foreach ($files as $file) {
if ( ! file_exists($file['file_path'])) {
throw new FileException('File to be merged not found.');
}
$this->fileSize += $this->write($handle, file_get_contents($file['file_path']));
$this->offset += $file['offset'];
}
$this->close($handle);
return $this->fileSize;
} | [
"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",
"->",
"fileSize",
"=",
"filesize",
"(",
"$",
"firstFile",
"[",
"'file_path'",
"]",
")",
";",
"$",
"handle",
"=",
"$",
"this",
"->",
"open",
"(",
"$",
"destination",
",",
"self",
"::",
"APPEND_BINARY",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
"[",
"'file_path'",
"]",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"'File to be merged not found.'",
")",
";",
"}",
"$",
"this",
"->",
"fileSize",
"+=",
"$",
"this",
"->",
"write",
"(",
"$",
"handle",
",",
"file_get_contents",
"(",
"$",
"file",
"[",
"'file_path'",
"]",
")",
")",
";",
"$",
"this",
"->",
"offset",
"+=",
"$",
"file",
"[",
"'offset'",
"]",
";",
"}",
"$",
"this",
"->",
"close",
"(",
"$",
"handle",
")",
";",
"return",
"$",
"this",
"->",
"fileSize",
";",
"}"
] | Merge 2 or more files.
@param array $files File data with meta info.
@return int | [
"Merge",
"2",
"or",
"more",
"files",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L448-L474 | train |
ankitpokhrel/tus-php | src/File.php | File.copy | 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 | 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;
} | [
"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",
";",
"}"
] | Copy file from source to destination.
@param string $source
@param string $destination
@return bool | [
"Copy",
"file",
"from",
"source",
"to",
"destination",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L484-L493 | train |
ankitpokhrel/tus-php | src/File.php | File.deleteFiles | 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 | 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;
} | [
"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",
";",
"}"
] | Delete multiple files.
@param array $files
@return bool | [
"Delete",
"multiple",
"files",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/File.php#L521-L536 | train |
ankitpokhrel/tus-php | src/Request.php | Request.allowedHttpVerbs | public function allowedHttpVerbs() : array
{
return [
HttpRequest::METHOD_GET,
HttpRequest::METHOD_POST,
HttpRequest::METHOD_PATCH,
HttpRequest::METHOD_DELETE,
HttpRequest::METHOD_HEAD,
HttpRequest::METHOD_OPTIONS,
];
} | php | public function allowedHttpVerbs() : array
{
return [
HttpRequest::METHOD_GET,
HttpRequest::METHOD_POST,
HttpRequest::METHOD_PATCH,
HttpRequest::METHOD_DELETE,
HttpRequest::METHOD_HEAD,
HttpRequest::METHOD_OPTIONS,
];
} | [
"public",
"function",
"allowedHttpVerbs",
"(",
")",
":",
"array",
"{",
"return",
"[",
"HttpRequest",
"::",
"METHOD_GET",
",",
"HttpRequest",
"::",
"METHOD_POST",
",",
"HttpRequest",
"::",
"METHOD_PATCH",
",",
"HttpRequest",
"::",
"METHOD_DELETE",
",",
"HttpRequest",
"::",
"METHOD_HEAD",
",",
"HttpRequest",
"::",
"METHOD_OPTIONS",
",",
"]",
";",
"}"
] | Supported http requests.
@return array | [
"Supported",
"http",
"requests",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Request.php#L58-L68 | train |
ankitpokhrel/tus-php | src/Request.php | Request.extractFromHeader | 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 | 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 [];
} | [
"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",
"[",
"]",
";",
"}"
] | Extract metadata from header.
@param string $key
@param string $value
@return array | [
"Extract",
"metadata",
"from",
"header",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Request.php#L101-L112 | train |
ankitpokhrel/tus-php | src/Request.php | Request.extractMeta | public function extractMeta(string $requestedKey) : string
{
$uploadMetaData = $this->request->headers->get('Upload-Metadata');
if (empty($uploadMetaData)) {
return '';
}
$uploadMetaDataChunks = explode(',', $uploadMetaData);
foreach ($uploadMetaDataChunks as $chunk) {
list($key, $value) = explode(' ', $chunk);
if ($key === $requestedKey) {
return base64_decode($value);
}
}
return '';
} | php | public function extractMeta(string $requestedKey) : string
{
$uploadMetaData = $this->request->headers->get('Upload-Metadata');
if (empty($uploadMetaData)) {
return '';
}
$uploadMetaDataChunks = explode(',', $uploadMetaData);
foreach ($uploadMetaDataChunks as $chunk) {
list($key, $value) = explode(' ', $chunk);
if ($key === $requestedKey) {
return base64_decode($value);
}
}
return '';
} | [
"public",
"function",
"extractMeta",
"(",
"string",
"$",
"requestedKey",
")",
":",
"string",
"{",
"$",
"uploadMetaData",
"=",
"$",
"this",
"->",
"request",
"->",
"headers",
"->",
"get",
"(",
"'Upload-Metadata'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uploadMetaData",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"uploadMetaDataChunks",
"=",
"explode",
"(",
"','",
",",
"$",
"uploadMetaData",
")",
";",
"foreach",
"(",
"$",
"uploadMetaDataChunks",
"as",
"$",
"chunk",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"chunk",
")",
";",
"if",
"(",
"$",
"key",
"===",
"$",
"requestedKey",
")",
"{",
"return",
"base64_decode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Extracts the meta data from the request header.
@param string $requestedKey
@return string | [
"Extracts",
"the",
"meta",
"data",
"from",
"the",
"request",
"header",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Request.php#L131-L150 | train |
ankitpokhrel/tus-php | src/Cache/AbstractCache.php | AbstractCache.deleteAll | 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 | public function deleteAll(array $keys) : bool
{
if (empty($keys)) {
return false;
}
$status = true;
foreach ($keys as $key) {
$status = $status && $this->delete($key);
}
return $status;
} | [
"public",
"function",
"deleteAll",
"(",
"array",
"$",
"keys",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"status",
"=",
"true",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"status",
"=",
"$",
"status",
"&&",
"$",
"this",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"status",
";",
"}"
] | Delete all keys.
@param array $keys
@return bool | [
"Delete",
"all",
"keys",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Cache/AbstractCache.php#L66-L79 | train |
ankitpokhrel/tus-php | src/Middleware/Middleware.php | Middleware.add | 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;
}
}
return $this;
} | php | 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;
}
}
return $this;
} | [
"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",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set middleware.
@param array $middleware
@return Middleware | [
"Set",
"middleware",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Middleware/Middleware.php#L38-L49 | train |
ankitpokhrel/tus-php | src/Middleware/Middleware.php | Middleware.skip | public function skip(...$middleware) : self
{
foreach ($middleware as $m) {
unset($this->globalMiddleware[$m]);
}
return $this;
} | php | public function skip(...$middleware) : self
{
foreach ($middleware as $m) {
unset($this->globalMiddleware[$m]);
}
return $this;
} | [
"public",
"function",
"skip",
"(",
"...",
"$",
"middleware",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"middleware",
"as",
"$",
"m",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"globalMiddleware",
"[",
"$",
"m",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Skip middleware.
@param array ...$middleware
@return Middleware | [
"Skip",
"middleware",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Middleware/Middleware.php#L58-L65 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getChecksumAlgorithm | public function getChecksumAlgorithm() : ?string
{
$checksumHeader = $this->getRequest()->header('Upload-Checksum');
if (empty($checksumHeader)) {
return self::DEFAULT_CHECKSUM_ALGORITHM;
}
list($checksumAlgorithm, /* $checksum */) = explode(' ', $checksumHeader);
return $checksumAlgorithm;
} | php | public function getChecksumAlgorithm() : ?string
{
$checksumHeader = $this->getRequest()->header('Upload-Checksum');
if (empty($checksumHeader)) {
return self::DEFAULT_CHECKSUM_ALGORITHM;
}
list($checksumAlgorithm, /* $checksum */) = explode(' ', $checksumHeader);
return $checksumAlgorithm;
} | [
"public",
"function",
"getChecksumAlgorithm",
"(",
")",
":",
"?",
"string",
"{",
"$",
"checksumHeader",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"header",
"(",
"'Upload-Checksum'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"checksumHeader",
")",
")",
"{",
"return",
"self",
"::",
"DEFAULT_CHECKSUM_ALGORITHM",
";",
"}",
"list",
"(",
"$",
"checksumAlgorithm",
",",
"/* $checksum */",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"checksumHeader",
")",
";",
"return",
"$",
"checksumAlgorithm",
";",
"}"
] | Get checksum algorithm.
@return string|null | [
"Get",
"checksum",
"algorithm",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L153-L164 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getUploadKey | 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);
}
$this->uploadKey = $key;
return $this->uploadKey;
} | php | 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);
}
$this->uploadKey = $key;
return $this->uploadKey;
} | [
"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",
")",
";",
"}",
"$",
"this",
"->",
"uploadKey",
"=",
"$",
"key",
";",
"return",
"$",
"this",
"->",
"uploadKey",
";",
"}"
] | Get upload key from header.
@return string|HttpResponse | [
"Get",
"upload",
"key",
"from",
"header",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L185-L200 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.serve | 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);
}
$clientVersion = $this->getRequest()->header('Tus-Resumable');
if ($clientVersion && $clientVersion !== self::TUS_PROTOCOL_VERSION) {
return $this->response->send(null, HttpResponse::HTTP_PRECONDITION_FAILED, [
'Tus-Version' => self::TUS_PROTOCOL_VERSION,
]);
}
$method = 'handle' . ucfirst(strtolower($requestMethod));
return $this->{$method}();
} | php | 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);
}
$clientVersion = $this->getRequest()->header('Tus-Resumable');
if ($clientVersion && $clientVersion !== self::TUS_PROTOCOL_VERSION) {
return $this->response->send(null, HttpResponse::HTTP_PRECONDITION_FAILED, [
'Tus-Version' => self::TUS_PROTOCOL_VERSION,
]);
}
$method = 'handle' . ucfirst(strtolower($requestMethod));
return $this->{$method}();
} | [
"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",
")",
";",
"}",
"$",
"clientVersion",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"header",
"(",
"'Tus-Resumable'",
")",
";",
"if",
"(",
"$",
"clientVersion",
"&&",
"$",
"clientVersion",
"!==",
"self",
"::",
"TUS_PROTOCOL_VERSION",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_PRECONDITION_FAILED",
",",
"[",
"'Tus-Version'",
"=>",
"self",
"::",
"TUS_PROTOCOL_VERSION",
",",
"]",
")",
";",
"}",
"$",
"method",
"=",
"'handle'",
".",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"requestMethod",
")",
")",
";",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"}"
] | Handle all HTTP request.
@return HttpResponse|BinaryFileResponse | [
"Handle",
"all",
"HTTP",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L255-L276 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.applyMiddleware | protected function applyMiddleware()
{
$middleware = $this->middleware()->list();
foreach ($middleware as $m) {
$m->handle($this->getRequest(), $this->getResponse());
}
} | php | protected function applyMiddleware()
{
$middleware = $this->middleware()->list();
foreach ($middleware as $m) {
$m->handle($this->getRequest(), $this->getResponse());
}
} | [
"protected",
"function",
"applyMiddleware",
"(",
")",
"{",
"$",
"middleware",
"=",
"$",
"this",
"->",
"middleware",
"(",
")",
"->",
"list",
"(",
")",
";",
"foreach",
"(",
"$",
"middleware",
"as",
"$",
"m",
")",
"{",
"$",
"m",
"->",
"handle",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
";",
"}",
"}"
] | Apply middleware.
@return void | [
"Apply",
"middleware",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L283-L290 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleOptions | 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->getSupportedHashAlgorithms(),
];
$maxUploadSize = $this->getMaxUploadSize();
if ($maxUploadSize > 0) {
$headers['Tus-Max-Size'] = $maxUploadSize;
}
return $this->response->send(null, HttpResponse::HTTP_OK, $headers);
} | php | 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->getSupportedHashAlgorithms(),
];
$maxUploadSize = $this->getMaxUploadSize();
if ($maxUploadSize > 0) {
$headers['Tus-Max-Size'] = $maxUploadSize;
}
return $this->response->send(null, HttpResponse::HTTP_OK, $headers);
} | [
"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",
"->",
"getSupportedHashAlgorithms",
"(",
")",
",",
"]",
";",
"$",
"maxUploadSize",
"=",
"$",
"this",
"->",
"getMaxUploadSize",
"(",
")",
";",
"if",
"(",
"$",
"maxUploadSize",
">",
"0",
")",
"{",
"$",
"headers",
"[",
"'Tus-Max-Size'",
"]",
"=",
"$",
"maxUploadSize",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_OK",
",",
"$",
"headers",
")",
";",
"}"
] | Handle OPTIONS request.
@return HttpResponse | [
"Handle",
"OPTIONS",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L297-L313 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleHead | 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) {
return $this->response->send(null, HttpResponse::HTTP_GONE);
}
return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
} | php | 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) {
return $this->response->send(null, HttpResponse::HTTP_GONE);
}
return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
} | [
"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",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_GONE",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_OK",
",",
"$",
"this",
"->",
"getHeadersForHeadRequest",
"(",
"$",
"fileMeta",
")",
")",
";",
"}"
] | Handle HEAD request.
@return HttpResponse | [
"Handle",
"HEAD",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L320-L335 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handlePost | 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->verifyUploadSize()) {
return $this->response->send(null, HttpResponse::HTTP_REQUEST_ENTITY_TOO_LARGE);
}
$uploadKey = $this->getUploadKey();
$filePath = $this->uploadDir . DIRECTORY_SEPARATOR . $fileName;
if ($this->getRequest()->isFinal()) {
return $this->handleConcatenation($fileName, $filePath);
}
if ($this->getRequest()->isPartial()) {
$filePath = $this->getPathForPartialUpload($uploadKey) . $fileName;
$uploadType = self::UPLOAD_TYPE_PARTIAL;
}
$checksum = $this->getClientChecksum();
$location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
$file = $this->buildFile([
'name' => $fileName,
'offset' => 0,
'size' => $this->getRequest()->header('Upload-Length'),
'file_path' => $filePath,
'location' => $location,
])->setKey($uploadKey)->setChecksum($checksum);
$this->cache->set($uploadKey, $file->details() + ['upload_type' => $uploadType]);
$this->event()->dispatch(
UploadCreated::NAME,
new UploadCreated($file, $this->getRequest(), $this->getResponse())
);
return $this->response->send(
null,
HttpResponse::HTTP_CREATED,
[
'Location' => $location,
'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
]
);
} | php | 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->verifyUploadSize()) {
return $this->response->send(null, HttpResponse::HTTP_REQUEST_ENTITY_TOO_LARGE);
}
$uploadKey = $this->getUploadKey();
$filePath = $this->uploadDir . DIRECTORY_SEPARATOR . $fileName;
if ($this->getRequest()->isFinal()) {
return $this->handleConcatenation($fileName, $filePath);
}
if ($this->getRequest()->isPartial()) {
$filePath = $this->getPathForPartialUpload($uploadKey) . $fileName;
$uploadType = self::UPLOAD_TYPE_PARTIAL;
}
$checksum = $this->getClientChecksum();
$location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
$file = $this->buildFile([
'name' => $fileName,
'offset' => 0,
'size' => $this->getRequest()->header('Upload-Length'),
'file_path' => $filePath,
'location' => $location,
])->setKey($uploadKey)->setChecksum($checksum);
$this->cache->set($uploadKey, $file->details() + ['upload_type' => $uploadType]);
$this->event()->dispatch(
UploadCreated::NAME,
new UploadCreated($file, $this->getRequest(), $this->getResponse())
);
return $this->response->send(
null,
HttpResponse::HTTP_CREATED,
[
'Location' => $location,
'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
]
);
} | [
"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",
"->",
"verifyUploadSize",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_REQUEST_ENTITY_TOO_LARGE",
")",
";",
"}",
"$",
"uploadKey",
"=",
"$",
"this",
"->",
"getUploadKey",
"(",
")",
";",
"$",
"filePath",
"=",
"$",
"this",
"->",
"uploadDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
";",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isFinal",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleConcatenation",
"(",
"$",
"fileName",
",",
"$",
"filePath",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isPartial",
"(",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"getPathForPartialUpload",
"(",
"$",
"uploadKey",
")",
".",
"$",
"fileName",
";",
"$",
"uploadType",
"=",
"self",
"::",
"UPLOAD_TYPE_PARTIAL",
";",
"}",
"$",
"checksum",
"=",
"$",
"this",
"->",
"getClientChecksum",
"(",
")",
";",
"$",
"location",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"url",
"(",
")",
".",
"$",
"this",
"->",
"getApiPath",
"(",
")",
".",
"'/'",
".",
"$",
"uploadKey",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"buildFile",
"(",
"[",
"'name'",
"=>",
"$",
"fileName",
",",
"'offset'",
"=>",
"0",
",",
"'size'",
"=>",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"header",
"(",
"'Upload-Length'",
")",
",",
"'file_path'",
"=>",
"$",
"filePath",
",",
"'location'",
"=>",
"$",
"location",
",",
"]",
")",
"->",
"setKey",
"(",
"$",
"uploadKey",
")",
"->",
"setChecksum",
"(",
"$",
"checksum",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"uploadKey",
",",
"$",
"file",
"->",
"details",
"(",
")",
"+",
"[",
"'upload_type'",
"=>",
"$",
"uploadType",
"]",
")",
";",
"$",
"this",
"->",
"event",
"(",
")",
"->",
"dispatch",
"(",
"UploadCreated",
"::",
"NAME",
",",
"new",
"UploadCreated",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_CREATED",
",",
"[",
"'Location'",
"=>",
"$",
"location",
",",
"'Upload-Expires'",
"=>",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"uploadKey",
")",
"[",
"'expires_at'",
"]",
",",
"]",
")",
";",
"}"
] | Handle POST request.
@return HttpResponse | [
"Handle",
"POST",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L342-L393 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleConcatenation | 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');
$location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
$file = $this->buildFile([
'name' => $fileName,
'offset' => 0,
'size' => 0,
'file_path' => $filePath,
'location' => $location,
])->setFilePath($filePath)->setKey($uploadKey);
$file->setOffset($file->merge($files));
// Verify checksum.
$checksum = $this->getServerChecksum($filePath);
if ($checksum !== $this->getClientChecksum()) {
return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
}
$file->setChecksum($checksum);
$this->cache->set($uploadKey, $file->details() + ['upload_type' => self::UPLOAD_TYPE_FINAL]);
// Cleanup.
if ($file->delete($filePaths, true)) {
$this->cache->deleteAll($partials);
}
$this->event()->dispatch(
UploadMerged::NAME,
new UploadMerged($file, $this->getRequest(), $this->getResponse())
);
return $this->response->send(
['data' => ['checksum' => $checksum]],
HttpResponse::HTTP_CREATED,
[
'Location' => $location,
]
);
} | php | 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');
$location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
$file = $this->buildFile([
'name' => $fileName,
'offset' => 0,
'size' => 0,
'file_path' => $filePath,
'location' => $location,
])->setFilePath($filePath)->setKey($uploadKey);
$file->setOffset($file->merge($files));
// Verify checksum.
$checksum = $this->getServerChecksum($filePath);
if ($checksum !== $this->getClientChecksum()) {
return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
}
$file->setChecksum($checksum);
$this->cache->set($uploadKey, $file->details() + ['upload_type' => self::UPLOAD_TYPE_FINAL]);
// Cleanup.
if ($file->delete($filePaths, true)) {
$this->cache->deleteAll($partials);
}
$this->event()->dispatch(
UploadMerged::NAME,
new UploadMerged($file, $this->getRequest(), $this->getResponse())
);
return $this->response->send(
['data' => ['checksum' => $checksum]],
HttpResponse::HTTP_CREATED,
[
'Location' => $location,
]
);
} | [
"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'",
")",
";",
"$",
"location",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"url",
"(",
")",
".",
"$",
"this",
"->",
"getApiPath",
"(",
")",
".",
"'/'",
".",
"$",
"uploadKey",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"buildFile",
"(",
"[",
"'name'",
"=>",
"$",
"fileName",
",",
"'offset'",
"=>",
"0",
",",
"'size'",
"=>",
"0",
",",
"'file_path'",
"=>",
"$",
"filePath",
",",
"'location'",
"=>",
"$",
"location",
",",
"]",
")",
"->",
"setFilePath",
"(",
"$",
"filePath",
")",
"->",
"setKey",
"(",
"$",
"uploadKey",
")",
";",
"$",
"file",
"->",
"setOffset",
"(",
"$",
"file",
"->",
"merge",
"(",
"$",
"files",
")",
")",
";",
"// Verify checksum.",
"$",
"checksum",
"=",
"$",
"this",
"->",
"getServerChecksum",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"$",
"checksum",
"!==",
"$",
"this",
"->",
"getClientChecksum",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"self",
"::",
"HTTP_CHECKSUM_MISMATCH",
")",
";",
"}",
"$",
"file",
"->",
"setChecksum",
"(",
"$",
"checksum",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"uploadKey",
",",
"$",
"file",
"->",
"details",
"(",
")",
"+",
"[",
"'upload_type'",
"=>",
"self",
"::",
"UPLOAD_TYPE_FINAL",
"]",
")",
";",
"// Cleanup.",
"if",
"(",
"$",
"file",
"->",
"delete",
"(",
"$",
"filePaths",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"deleteAll",
"(",
"$",
"partials",
")",
";",
"}",
"$",
"this",
"->",
"event",
"(",
")",
"->",
"dispatch",
"(",
"UploadMerged",
"::",
"NAME",
",",
"new",
"UploadMerged",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"[",
"'data'",
"=>",
"[",
"'checksum'",
"=>",
"$",
"checksum",
"]",
"]",
",",
"HttpResponse",
"::",
"HTTP_CREATED",
",",
"[",
"'Location'",
"=>",
"$",
"location",
",",
"]",
")",
";",
"}"
] | Handle file concatenation.
@param string $fileName
@param string $filePath
@return HttpResponse | [
"Handle",
"file",
"concatenation",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L403-L448 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handlePatch | 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::HTTP_OK !== $status) {
return $this->response->send(null, $status);
}
$file = $this->buildFile($meta);
$checksum = $meta['checksum'];
try {
$fileSize = $file->getFileSize();
$offset = $file->setKey($uploadKey)->setChecksum($checksum)->upload($fileSize);
// If upload is done, verify checksum.
if ($offset === $fileSize) {
if ( ! $this->verifyChecksum($checksum, $meta['file_path'])) {
return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
}
$this->event()->dispatch(
UploadComplete::NAME,
new UploadComplete($file, $this->getRequest(), $this->getResponse())
);
} else {
$this->event()->dispatch(
UploadProgress::NAME,
new UploadProgress($file, $this->getRequest(), $this->getResponse())
);
}
} catch (FileException $e) {
return $this->response->send($e->getMessage(), HttpResponse::HTTP_UNPROCESSABLE_ENTITY);
} catch (OutOfRangeException $e) {
return $this->response->send(null, HttpResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE);
} catch (ConnectionException $e) {
return $this->response->send(null, HttpResponse::HTTP_CONTINUE);
}
return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
'Content-Type' => self::HEADER_CONTENT_TYPE,
'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
'Upload-Offset' => $offset,
]);
} | php | 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::HTTP_OK !== $status) {
return $this->response->send(null, $status);
}
$file = $this->buildFile($meta);
$checksum = $meta['checksum'];
try {
$fileSize = $file->getFileSize();
$offset = $file->setKey($uploadKey)->setChecksum($checksum)->upload($fileSize);
// If upload is done, verify checksum.
if ($offset === $fileSize) {
if ( ! $this->verifyChecksum($checksum, $meta['file_path'])) {
return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
}
$this->event()->dispatch(
UploadComplete::NAME,
new UploadComplete($file, $this->getRequest(), $this->getResponse())
);
} else {
$this->event()->dispatch(
UploadProgress::NAME,
new UploadProgress($file, $this->getRequest(), $this->getResponse())
);
}
} catch (FileException $e) {
return $this->response->send($e->getMessage(), HttpResponse::HTTP_UNPROCESSABLE_ENTITY);
} catch (OutOfRangeException $e) {
return $this->response->send(null, HttpResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE);
} catch (ConnectionException $e) {
return $this->response->send(null, HttpResponse::HTTP_CONTINUE);
}
return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
'Content-Type' => self::HEADER_CONTENT_TYPE,
'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
'Upload-Offset' => $offset,
]);
} | [
"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",
"::",
"HTTP_OK",
"!==",
"$",
"status",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"$",
"status",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"buildFile",
"(",
"$",
"meta",
")",
";",
"$",
"checksum",
"=",
"$",
"meta",
"[",
"'checksum'",
"]",
";",
"try",
"{",
"$",
"fileSize",
"=",
"$",
"file",
"->",
"getFileSize",
"(",
")",
";",
"$",
"offset",
"=",
"$",
"file",
"->",
"setKey",
"(",
"$",
"uploadKey",
")",
"->",
"setChecksum",
"(",
"$",
"checksum",
")",
"->",
"upload",
"(",
"$",
"fileSize",
")",
";",
"// If upload is done, verify checksum.",
"if",
"(",
"$",
"offset",
"===",
"$",
"fileSize",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"verifyChecksum",
"(",
"$",
"checksum",
",",
"$",
"meta",
"[",
"'file_path'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"self",
"::",
"HTTP_CHECKSUM_MISMATCH",
")",
";",
"}",
"$",
"this",
"->",
"event",
"(",
")",
"->",
"dispatch",
"(",
"UploadComplete",
"::",
"NAME",
",",
"new",
"UploadComplete",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"event",
"(",
")",
"->",
"dispatch",
"(",
"UploadProgress",
"::",
"NAME",
",",
"new",
"UploadProgress",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
",",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
")",
";",
"}",
"}",
"catch",
"(",
"FileException",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"HttpResponse",
"::",
"HTTP_UNPROCESSABLE_ENTITY",
")",
";",
"}",
"catch",
"(",
"OutOfRangeException",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_REQUESTED_RANGE_NOT_SATISFIABLE",
")",
";",
"}",
"catch",
"(",
"ConnectionException",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_CONTINUE",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_NO_CONTENT",
",",
"[",
"'Content-Type'",
"=>",
"self",
"::",
"HEADER_CONTENT_TYPE",
",",
"'Upload-Expires'",
"=>",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"uploadKey",
")",
"[",
"'expires_at'",
"]",
",",
"'Upload-Offset'",
"=>",
"$",
"offset",
",",
"]",
")",
";",
"}"
] | Handle PATCH request.
@return HttpResponse | [
"Handle",
"PATCH",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L455-L505 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.verifyPatchRequest | 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['offset']) {
return HttpResponse::HTTP_CONFLICT;
}
$contentType = $this->request->header('Content-Type');
if ($contentType !== self::HEADER_CONTENT_TYPE) {
return HTTPRESPONSE::HTTP_UNSUPPORTED_MEDIA_TYPE;
}
return HttpResponse::HTTP_OK;
} | php | 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['offset']) {
return HttpResponse::HTTP_CONFLICT;
}
$contentType = $this->request->header('Content-Type');
if ($contentType !== self::HEADER_CONTENT_TYPE) {
return HTTPRESPONSE::HTTP_UNSUPPORTED_MEDIA_TYPE;
}
return HttpResponse::HTTP_OK;
} | [
"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",
"[",
"'offset'",
"]",
")",
"{",
"return",
"HttpResponse",
"::",
"HTTP_CONFLICT",
";",
"}",
"$",
"contentType",
"=",
"$",
"this",
"->",
"request",
"->",
"header",
"(",
"'Content-Type'",
")",
";",
"if",
"(",
"$",
"contentType",
"!==",
"self",
"::",
"HEADER_CONTENT_TYPE",
")",
"{",
"return",
"HTTPRESPONSE",
"::",
"HTTP_UNSUPPORTED_MEDIA_TYPE",
";",
"}",
"return",
"HttpResponse",
"::",
"HTTP_OK",
";",
"}"
] | Verify PATCH request.
@param array $meta
@return int | [
"Verify",
"PATCH",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L514-L533 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleDownload | 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);
}
$resource = $fileMeta['file_path'] ?? null;
$fileName = $fileMeta['name'] ?? null;
if ( ! $resource || ! file_exists($resource)) {
return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
}
return $this->response->download($resource, $fileName);
} | php | 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);
}
$resource = $fileMeta['file_path'] ?? null;
$fileName = $fileMeta['name'] ?? null;
if ( ! $resource || ! file_exists($resource)) {
return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
}
return $this->response->download($resource, $fileName);
} | [
"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",
")",
";",
"}",
"$",
"resource",
"=",
"$",
"fileMeta",
"[",
"'file_path'",
"]",
"??",
"null",
";",
"$",
"fileName",
"=",
"$",
"fileMeta",
"[",
"'name'",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"$",
"resource",
"||",
"!",
"file_exists",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"'404 upload not found.'",
",",
"HttpResponse",
"::",
"HTTP_NOT_FOUND",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"download",
"(",
"$",
"resource",
",",
"$",
"fileName",
")",
";",
"}"
] | Handle Download request.
@return BinaryFileResponse|HttpResponse | [
"Handle",
"Download",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L559-L576 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleDelete | 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);
}
$isDeleted = $this->cache->delete($key);
if ( ! $isDeleted || ! file_exists($resource)) {
return $this->response->send(null, HttpResponse::HTTP_GONE);
}
unlink($resource);
return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
'Tus-Extension' => self::TUS_EXTENSION_TERMINATION,
]);
} | php | 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);
}
$isDeleted = $this->cache->delete($key);
if ( ! $isDeleted || ! file_exists($resource)) {
return $this->response->send(null, HttpResponse::HTTP_GONE);
}
unlink($resource);
return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
'Tus-Extension' => self::TUS_EXTENSION_TERMINATION,
]);
} | [
"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",
")",
";",
"}",
"$",
"isDeleted",
"=",
"$",
"this",
"->",
"cache",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"isDeleted",
"||",
"!",
"file_exists",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_GONE",
")",
";",
"}",
"unlink",
"(",
"$",
"resource",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_NO_CONTENT",
",",
"[",
"'Tus-Extension'",
"=>",
"self",
"::",
"TUS_EXTENSION_TERMINATION",
",",
"]",
")",
";",
"}"
] | Handle DELETE request.
@return HttpResponse | [
"Handle",
"DELETE",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L583-L604 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getHeadersForHeadRequest | 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['upload_type'] && $fileMeta['size'] !== $fileMeta['offset']) {
unset($headers['Upload-Offset']);
}
if (self::UPLOAD_TYPE_NORMAL !== $fileMeta['upload_type']) {
$headers += ['Upload-Concat' => $fileMeta['upload_type']];
}
return $headers;
} | php | 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['upload_type'] && $fileMeta['size'] !== $fileMeta['offset']) {
unset($headers['Upload-Offset']);
}
if (self::UPLOAD_TYPE_NORMAL !== $fileMeta['upload_type']) {
$headers += ['Upload-Concat' => $fileMeta['upload_type']];
}
return $headers;
} | [
"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",
"[",
"'upload_type'",
"]",
"&&",
"$",
"fileMeta",
"[",
"'size'",
"]",
"!==",
"$",
"fileMeta",
"[",
"'offset'",
"]",
")",
"{",
"unset",
"(",
"$",
"headers",
"[",
"'Upload-Offset'",
"]",
")",
";",
"}",
"if",
"(",
"self",
"::",
"UPLOAD_TYPE_NORMAL",
"!==",
"$",
"fileMeta",
"[",
"'upload_type'",
"]",
")",
"{",
"$",
"headers",
"+=",
"[",
"'Upload-Concat'",
"=>",
"$",
"fileMeta",
"[",
"'upload_type'",
"]",
"]",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Get required headers for head request.
@param array $fileMeta
@return array | [
"Get",
"required",
"headers",
"for",
"head",
"request",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L613-L630 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.buildFile | 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 | 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;
} | [
"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",
";",
"}"
] | Build file object.
@param array $meta
@return File | [
"Build",
"file",
"object",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L639-L648 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getSupportedHashAlgorithms | protected function getSupportedHashAlgorithms() : string
{
$supportedAlgorithms = hash_algos();
$algorithms = [];
foreach ($supportedAlgorithms as $hashAlgo) {
if (false !== strpos($hashAlgo, ',')) {
$algorithms[] = "'{$hashAlgo}'";
} else {
$algorithms[] = $hashAlgo;
}
}
return implode(',', $algorithms);
} | php | protected function getSupportedHashAlgorithms() : string
{
$supportedAlgorithms = hash_algos();
$algorithms = [];
foreach ($supportedAlgorithms as $hashAlgo) {
if (false !== strpos($hashAlgo, ',')) {
$algorithms[] = "'{$hashAlgo}'";
} else {
$algorithms[] = $hashAlgo;
}
}
return implode(',', $algorithms);
} | [
"protected",
"function",
"getSupportedHashAlgorithms",
"(",
")",
":",
"string",
"{",
"$",
"supportedAlgorithms",
"=",
"hash_algos",
"(",
")",
";",
"$",
"algorithms",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"supportedAlgorithms",
"as",
"$",
"hashAlgo",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"hashAlgo",
",",
"','",
")",
")",
"{",
"$",
"algorithms",
"[",
"]",
"=",
"\"'{$hashAlgo}'\"",
";",
"}",
"else",
"{",
"$",
"algorithms",
"[",
"]",
"=",
"$",
"hashAlgo",
";",
"}",
"}",
"return",
"implode",
"(",
"','",
",",
"$",
"algorithms",
")",
";",
"}"
] | Get list of supported hash algorithms.
@return string | [
"Get",
"list",
"of",
"supported",
"hash",
"algorithms",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L655-L669 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getClientChecksum | protected function getClientChecksum()
{
$checksumHeader = $this->getRequest()->header('Upload-Checksum');
if (empty($checksumHeader)) {
return '';
}
list($checksumAlgorithm, $checksum) = explode(' ', $checksumHeader);
$checksum = base64_decode($checksum);
if ( ! in_array($checksumAlgorithm, hash_algos()) || false === $checksum) {
return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
}
return $checksum;
} | php | protected function getClientChecksum()
{
$checksumHeader = $this->getRequest()->header('Upload-Checksum');
if (empty($checksumHeader)) {
return '';
}
list($checksumAlgorithm, $checksum) = explode(' ', $checksumHeader);
$checksum = base64_decode($checksum);
if ( ! in_array($checksumAlgorithm, hash_algos()) || false === $checksum) {
return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
}
return $checksum;
} | [
"protected",
"function",
"getClientChecksum",
"(",
")",
"{",
"$",
"checksumHeader",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"header",
"(",
"'Upload-Checksum'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"checksumHeader",
")",
")",
"{",
"return",
"''",
";",
"}",
"list",
"(",
"$",
"checksumAlgorithm",
",",
"$",
"checksum",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"checksumHeader",
")",
";",
"$",
"checksum",
"=",
"base64_decode",
"(",
"$",
"checksum",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"checksumAlgorithm",
",",
"hash_algos",
"(",
")",
")",
"||",
"false",
"===",
"$",
"checksum",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"send",
"(",
"null",
",",
"HttpResponse",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}",
"return",
"$",
"checksum",
";",
"}"
] | Verify and get upload checksum from header.
@return string|HttpResponse | [
"Verify",
"and",
"get",
"upload",
"checksum",
"from",
"header",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L676-L693 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.isExpired | protected function isExpired($contents) : bool
{
$isExpired = empty($contents['expires_at']) || Carbon::parse($contents['expires_at'])->lt(Carbon::now());
if ($isExpired && $contents['offset'] !== $contents['size']) {
return true;
}
return false;
} | php | protected function isExpired($contents) : bool
{
$isExpired = empty($contents['expires_at']) || Carbon::parse($contents['expires_at'])->lt(Carbon::now());
if ($isExpired && $contents['offset'] !== $contents['size']) {
return true;
}
return false;
} | [
"protected",
"function",
"isExpired",
"(",
"$",
"contents",
")",
":",
"bool",
"{",
"$",
"isExpired",
"=",
"empty",
"(",
"$",
"contents",
"[",
"'expires_at'",
"]",
")",
"||",
"Carbon",
"::",
"parse",
"(",
"$",
"contents",
"[",
"'expires_at'",
"]",
")",
"->",
"lt",
"(",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"if",
"(",
"$",
"isExpired",
"&&",
"$",
"contents",
"[",
"'offset'",
"]",
"!==",
"$",
"contents",
"[",
"'size'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Get expired but incomplete uploads.
@param array|null $contents
@return bool | [
"Get",
"expired",
"but",
"incomplete",
"uploads",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L702-L711 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getPathForPartialUpload | protected function getPathForPartialUpload(string $key) : string
{
list($actualKey, /* $partialUploadKey */) = explode(self::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
$path = $this->uploadDir . DIRECTORY_SEPARATOR . $actualKey . DIRECTORY_SEPARATOR;
if ( ! file_exists($path)) {
mkdir($path);
}
return $path;
} | php | protected function getPathForPartialUpload(string $key) : string
{
list($actualKey, /* $partialUploadKey */) = explode(self::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
$path = $this->uploadDir . DIRECTORY_SEPARATOR . $actualKey . DIRECTORY_SEPARATOR;
if ( ! file_exists($path)) {
mkdir($path);
}
return $path;
} | [
"protected",
"function",
"getPathForPartialUpload",
"(",
"string",
"$",
"key",
")",
":",
"string",
"{",
"list",
"(",
"$",
"actualKey",
",",
"/* $partialUploadKey */",
")",
"=",
"explode",
"(",
"self",
"::",
"PARTIAL_UPLOAD_NAME_SEPARATOR",
",",
"$",
"key",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"uploadDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"actualKey",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"mkdir",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Get path for partial upload.
@param string $key
@return string | [
"Get",
"path",
"for",
"partial",
"upload",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L720-L731 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.getPartialsMeta | protected function getPartialsMeta(array $partials) : array
{
$files = [];
foreach ($partials as $partial) {
$fileMeta = $this->getCache()->get($partial);
$files[] = $fileMeta;
}
return $files;
} | php | protected function getPartialsMeta(array $partials) : array
{
$files = [];
foreach ($partials as $partial) {
$fileMeta = $this->getCache()->get($partial);
$files[] = $fileMeta;
}
return $files;
} | [
"protected",
"function",
"getPartialsMeta",
"(",
"array",
"$",
"partials",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"partials",
"as",
"$",
"partial",
")",
"{",
"$",
"fileMeta",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"get",
"(",
"$",
"partial",
")",
";",
"$",
"files",
"[",
"]",
"=",
"$",
"fileMeta",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Get metadata of partials.
@param array $partials
@return array | [
"Get",
"metadata",
"of",
"partials",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L740-L751 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.handleExpiration | public function handleExpiration() : array
{
$deleted = [];
$cacheKeys = $this->cache->keys();
foreach ($cacheKeys as $key) {
$fileMeta = $this->cache->get($key, true);
if ( ! $this->isExpired($fileMeta)) {
continue;
}
if ( ! $this->cache->delete($key)) {
continue;
}
if (is_writable($fileMeta['file_path'])) {
unlink($fileMeta['file_path']);
}
$deleted[] = $fileMeta;
}
return $deleted;
} | php | public function handleExpiration() : array
{
$deleted = [];
$cacheKeys = $this->cache->keys();
foreach ($cacheKeys as $key) {
$fileMeta = $this->cache->get($key, true);
if ( ! $this->isExpired($fileMeta)) {
continue;
}
if ( ! $this->cache->delete($key)) {
continue;
}
if (is_writable($fileMeta['file_path'])) {
unlink($fileMeta['file_path']);
}
$deleted[] = $fileMeta;
}
return $deleted;
} | [
"public",
"function",
"handleExpiration",
"(",
")",
":",
"array",
"{",
"$",
"deleted",
"=",
"[",
"]",
";",
"$",
"cacheKeys",
"=",
"$",
"this",
"->",
"cache",
"->",
"keys",
"(",
")",
";",
"foreach",
"(",
"$",
"cacheKeys",
"as",
"$",
"key",
")",
"{",
"$",
"fileMeta",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"key",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isExpired",
"(",
"$",
"fileMeta",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"cache",
"->",
"delete",
"(",
"$",
"key",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_writable",
"(",
"$",
"fileMeta",
"[",
"'file_path'",
"]",
")",
")",
"{",
"unlink",
"(",
"$",
"fileMeta",
"[",
"'file_path'",
"]",
")",
";",
"}",
"$",
"deleted",
"[",
"]",
"=",
"$",
"fileMeta",
";",
"}",
"return",
"$",
"deleted",
";",
"}"
] | Delete expired resources.
@return array | [
"Delete",
"expired",
"resources",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L758-L782 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.verifyUploadSize | protected function verifyUploadSize() : bool
{
$maxUploadSize = $this->getMaxUploadSize();
if ($maxUploadSize > 0 && $this->getRequest()->header('Upload-Length') > $maxUploadSize) {
return false;
}
return true;
} | php | protected function verifyUploadSize() : bool
{
$maxUploadSize = $this->getMaxUploadSize();
if ($maxUploadSize > 0 && $this->getRequest()->header('Upload-Length') > $maxUploadSize) {
return false;
}
return true;
} | [
"protected",
"function",
"verifyUploadSize",
"(",
")",
":",
"bool",
"{",
"$",
"maxUploadSize",
"=",
"$",
"this",
"->",
"getMaxUploadSize",
"(",
")",
";",
"if",
"(",
"$",
"maxUploadSize",
">",
"0",
"&&",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"header",
"(",
"'Upload-Length'",
")",
">",
"$",
"maxUploadSize",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Verify max upload size.
@return bool | [
"Verify",
"max",
"upload",
"size",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L789-L798 | train |
ankitpokhrel/tus-php | src/Tus/Server.php | Server.verifyChecksum | protected function verifyChecksum(string $checksum, string $filePath) : bool
{
// Skip if checksum is empty.
if (empty($checksum)) {
return true;
}
return $checksum === $this->getServerChecksum($filePath);
} | php | protected function verifyChecksum(string $checksum, string $filePath) : bool
{
// Skip if checksum is empty.
if (empty($checksum)) {
return true;
}
return $checksum === $this->getServerChecksum($filePath);
} | [
"protected",
"function",
"verifyChecksum",
"(",
"string",
"$",
"checksum",
",",
"string",
"$",
"filePath",
")",
":",
"bool",
"{",
"// Skip if checksum is empty.",
"if",
"(",
"empty",
"(",
"$",
"checksum",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"checksum",
"===",
"$",
"this",
"->",
"getServerChecksum",
"(",
"$",
"filePath",
")",
";",
"}"
] | Verify checksum if available.
@param string $checksum
@param string $filePath
@return bool | [
"Verify",
"checksum",
"if",
"available",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Tus/Server.php#L808-L816 | train |
ankitpokhrel/tus-php | src/Config.php | Config.set | public static function set($config = null, bool $force = false)
{
if ( ! $force && ! empty(self::$config)) {
return;
}
if (is_array($config)) {
self::$config = $config;
} else {
self::$config = require $config ?? self::DEFAULT_CONFIG_PATH;
}
} | php | public static function set($config = null, bool $force = false)
{
if ( ! $force && ! empty(self::$config)) {
return;
}
if (is_array($config)) {
self::$config = $config;
} else {
self::$config = require $config ?? self::DEFAULT_CONFIG_PATH;
}
} | [
"public",
"static",
"function",
"set",
"(",
"$",
"config",
"=",
"null",
",",
"bool",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"force",
"&&",
"!",
"empty",
"(",
"self",
"::",
"$",
"config",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"self",
"::",
"$",
"config",
"=",
"$",
"config",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"config",
"=",
"require",
"$",
"config",
"??",
"self",
"::",
"DEFAULT_CONFIG_PATH",
";",
"}",
"}"
] | Load default application configs.
@param string|array $config
@param bool $force
@return void | [
"Load",
"default",
"application",
"configs",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Config.php#L21-L32 | train |
ankitpokhrel/tus-php | src/Config.php | Config.get | public static function get(string $key = null)
{
self::set();
if (empty($key)) {
return self::$config;
}
$keys = explode('.', $key);
$value = self::$config;
foreach ($keys as $key) {
if ( ! isset($value[$key])) {
return null;
}
$value = $value[$key];
}
return $value;
} | php | public static function get(string $key = null)
{
self::set();
if (empty($key)) {
return self::$config;
}
$keys = explode('.', $key);
$value = self::$config;
foreach ($keys as $key) {
if ( ! isset($value[$key])) {
return null;
}
$value = $value[$key];
}
return $value;
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"key",
"=",
"null",
")",
"{",
"self",
"::",
"set",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"return",
"self",
"::",
"$",
"config",
";",
"}",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"value",
"=",
"self",
"::",
"$",
"config",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"value",
"=",
"$",
"value",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get config.
@param string|null $key Key to extract.
@return mixed | [
"Get",
"config",
"."
] | 3a271299538252bbba6566c8afe7cd1baa18efe5 | https://github.com/ankitpokhrel/tus-php/blob/3a271299538252bbba6566c8afe7cd1baa18efe5/src/Config.php#L41-L61 | train |
matthiasmullie/minify | src/JS.php | JS.stripComments | protected function stripComments()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
$placeholder = '/*'.$count.'*/';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
};
// multi-line comments
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
$this->registerPattern('/\/\*.*?\*\//s', '');
// single-line comments
$this->registerPattern('/\/\/.*$/m', '');
} | php | protected function stripComments()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
$placeholder = '/*'.$count.'*/';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
};
// multi-line comments
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
$this->registerPattern('/\/\*.*?\*\//s', '');
// single-line comments
$this->registerPattern('/\/\/.*$/m', '');
} | [
"protected",
"function",
"stripComments",
"(",
")",
"{",
"// PHP only supports $this inside anonymous functions since 5.4",
"$",
"minifier",
"=",
"$",
"this",
";",
"$",
"callback",
"=",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"minifier",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"minifier",
"->",
"extracted",
")",
";",
"$",
"placeholder",
"=",
"'/*'",
".",
"$",
"count",
".",
"'*/'",
";",
"$",
"minifier",
"->",
"extracted",
"[",
"$",
"placeholder",
"]",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"return",
"$",
"placeholder",
";",
"}",
";",
"// multi-line comments",
"$",
"this",
"->",
"registerPattern",
"(",
"'/\\n?\\/\\*(!|.*?@license|.*?@preserve).*?\\*\\/\\n?/s'",
",",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"registerPattern",
"(",
"'/\\/\\*.*?\\*\\//s'",
",",
"''",
")",
";",
"// single-line comments",
"$",
"this",
"->",
"registerPattern",
"(",
"'/\\/\\/.*$/m'",
",",
"''",
")",
";",
"}"
] | Strip comments from source code. | [
"Strip",
"comments",
"from",
"source",
"code",
"."
] | e87effb29f23aa98538b49049d85259c718d77ae | https://github.com/matthiasmullie/minify/blob/e87effb29f23aa98538b49049d85259c718d77ae/src/JS.php#L196-L213 | train |
matthiasmullie/minify | src/Minify.php | Minify.canImportFile | protected function canImportFile($path)
{
$parsed = parse_url($path);
if (
// file is elsewhere
isset($parsed['host']) ||
// file responds to queries (may change, or need to bypass cache)
isset($parsed['query'])
) {
return false;
}
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
} | php | protected function canImportFile($path)
{
$parsed = parse_url($path);
if (
// file is elsewhere
isset($parsed['host']) ||
// file responds to queries (may change, or need to bypass cache)
isset($parsed['query'])
) {
return false;
}
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
} | [
"protected",
"function",
"canImportFile",
"(",
"$",
"path",
")",
"{",
"$",
"parsed",
"=",
"parse_url",
"(",
"$",
"path",
")",
";",
"if",
"(",
"// file is elsewhere",
"isset",
"(",
"$",
"parsed",
"[",
"'host'",
"]",
")",
"||",
"// file responds to queries (may change, or need to bypass cache)",
"isset",
"(",
"$",
"parsed",
"[",
"'query'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"strlen",
"(",
"$",
"path",
")",
"<",
"PHP_MAXPATHLEN",
"&&",
"@",
"is_file",
"(",
"$",
"path",
")",
"&&",
"is_readable",
"(",
"$",
"path",
")",
";",
"}"
] | Check if the path is a regular file and can be read.
@param string $path
@return bool | [
"Check",
"if",
"the",
"path",
"is",
"a",
"regular",
"file",
"and",
"can",
"be",
"read",
"."
] | e87effb29f23aa98538b49049d85259c718d77ae | https://github.com/matthiasmullie/minify/blob/e87effb29f23aa98538b49049d85259c718d77ae/src/Minify.php#L411-L424 | train |
Tucker-Eric/EloquentFilter | src/Commands/MakeEloquentFilter.php | MakeEloquentFilter.makeClassName | public function makeClassName()
{
$parts = array_map('studly_case', explode('\\', $this->argument('name')));
$className = array_pop($parts);
$ns = count($parts) > 0 ? implode('\\', $parts).'\\' : '';
$fqClass = config('eloquentfilter.namespace', 'App\\ModelFilters\\').$ns.$className;
if (substr($fqClass, -6, 6) !== 'Filter') {
$fqClass .= 'Filter';
}
if (class_exists($fqClass)) {
$this->error("\n\n\t$fqClass Already Exists!\n");
die;
}
$this->setClassName($fqClass);
return $this;
} | php | public function makeClassName()
{
$parts = array_map('studly_case', explode('\\', $this->argument('name')));
$className = array_pop($parts);
$ns = count($parts) > 0 ? implode('\\', $parts).'\\' : '';
$fqClass = config('eloquentfilter.namespace', 'App\\ModelFilters\\').$ns.$className;
if (substr($fqClass, -6, 6) !== 'Filter') {
$fqClass .= 'Filter';
}
if (class_exists($fqClass)) {
$this->error("\n\n\t$fqClass Already Exists!\n");
die;
}
$this->setClassName($fqClass);
return $this;
} | [
"public",
"function",
"makeClassName",
"(",
")",
"{",
"$",
"parts",
"=",
"array_map",
"(",
"'studly_case'",
",",
"explode",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
")",
")",
";",
"$",
"className",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"ns",
"=",
"count",
"(",
"$",
"parts",
")",
">",
"0",
"?",
"implode",
"(",
"'\\\\'",
",",
"$",
"parts",
")",
".",
"'\\\\'",
":",
"''",
";",
"$",
"fqClass",
"=",
"config",
"(",
"'eloquentfilter.namespace'",
",",
"'App\\\\ModelFilters\\\\'",
")",
".",
"$",
"ns",
".",
"$",
"className",
";",
"if",
"(",
"substr",
"(",
"$",
"fqClass",
",",
"-",
"6",
",",
"6",
")",
"!==",
"'Filter'",
")",
"{",
"$",
"fqClass",
".=",
"'Filter'",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"fqClass",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"\\n\\n\\t$fqClass Already Exists!\\n\"",
")",
";",
"die",
";",
"}",
"$",
"this",
"->",
"setClassName",
"(",
"$",
"fqClass",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Create Filter Class Name.
@return $this | [
"Create",
"Filter",
"Class",
"Name",
"."
] | 85edfce2e0497f8570d9a8d36a3ad32eb261216f | https://github.com/Tucker-Eric/EloquentFilter/blob/85edfce2e0497f8570d9a8d36a3ad32eb261216f/src/Commands/MakeEloquentFilter.php#L122-L142 | train |
Tucker-Eric/EloquentFilter | src/ModelFilter.php | ModelFilter.removeEmptyInput | public function removeEmptyInput($input)
{
$filterableInput = [];
foreach ($input as $key => $val) {
if ($val !== '' && $val !== null) {
$filterableInput[$key] = $val;
}
}
return $filterableInput;
} | php | public function removeEmptyInput($input)
{
$filterableInput = [];
foreach ($input as $key => $val) {
if ($val !== '' && $val !== null) {
$filterableInput[$key] = $val;
}
}
return $filterableInput;
} | [
"public",
"function",
"removeEmptyInput",
"(",
"$",
"input",
")",
"{",
"$",
"filterableInput",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"!==",
"''",
"&&",
"$",
"val",
"!==",
"null",
")",
"{",
"$",
"filterableInput",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"filterableInput",
";",
"}"
] | Remove empty strings from the input array.
@param array $input
@return array | [
"Remove",
"empty",
"strings",
"from",
"the",
"input",
"array",
"."
] | 85edfce2e0497f8570d9a8d36a3ad32eb261216f | https://github.com/Tucker-Eric/EloquentFilter/blob/85edfce2e0497f8570d9a8d36a3ad32eb261216f/src/ModelFilter.php#L118-L129 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.