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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.group | public function group() : Stage\Group
{
$stage = new Stage\Group($this);
$this->addStage($stage);
return $stage;
} | php | public function group() : Stage\Group
{
$stage = new Stage\Group($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"group",
"(",
")",
":",
"Stage",
"\\",
"Group",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Group",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Groups documents by some specified expression and outputs to the next
stage a document for each distinct grouping.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/group/ | [
"Groups",
"documents",
"by",
"some",
"specified",
"expression",
"and",
"outputs",
"to",
"the",
"next",
"stage",
"a",
"document",
"for",
"each",
"distinct",
"grouping",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L287-L293 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.indexStats | public function indexStats() : Stage\IndexStats
{
$stage = new Stage\IndexStats($this);
$this->addStage($stage);
return $stage;
} | php | public function indexStats() : Stage\IndexStats
{
$stage = new Stage\IndexStats($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"indexStats",
"(",
")",
":",
"Stage",
"\\",
"IndexStats",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"IndexStats",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Returns statistics regarding the use of each index for the collection.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/indexStats/ | [
"Returns",
"statistics",
"regarding",
"the",
"use",
"of",
"each",
"index",
"for",
"the",
"collection",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L310-L316 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.limit | public function limit(int $limit) : Stage\Limit
{
$stage = new Stage\Limit($this, $limit);
$this->addStage($stage);
return $stage;
} | php | public function limit(int $limit) : Stage\Limit
{
$stage = new Stage\Limit($this, $limit);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"limit",
"(",
"int",
"$",
"limit",
")",
":",
"Stage",
"\\",
"Limit",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Limit",
"(",
"$",
"this",
",",
"$",
"limit",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Limits the number of documents passed to the next stage in the pipeline.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/ | [
"Limits",
"the",
"number",
"of",
"documents",
"passed",
"to",
"the",
"next",
"stage",
"in",
"the",
"pipeline",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L323-L329 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.matchExpr | public function matchExpr() : QueryExpr
{
$expr = new QueryExpr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
} | php | public function matchExpr() : QueryExpr
{
$expr = new QueryExpr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
} | [
"public",
"function",
"matchExpr",
"(",
")",
":",
"QueryExpr",
"{",
"$",
"expr",
"=",
"new",
"QueryExpr",
"(",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"expr",
"->",
"setClassMetadata",
"(",
"$",
"this",
"->",
"class",
")",
";",
"return",
"$",
"expr",
";",
"}"
] | Returns a query expression to be used in match stages | [
"Returns",
"a",
"query",
"expression",
"to",
"be",
"used",
"in",
"match",
"stages"
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L363-L369 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.out | public function out(string $from) : Stage\Out
{
$stage = new Stage\Out($this, $from, $this->dm);
$this->addStage($stage);
return $stage;
} | php | public function out(string $from) : Stage\Out
{
$stage = new Stage\Out($this, $from, $this->dm);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"out",
"(",
"string",
"$",
"from",
")",
":",
"Stage",
"\\",
"Out",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Out",
"(",
"$",
"this",
",",
"$",
"from",
",",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Takes the documents returned by the aggregation pipeline and writes them
to a specified collection. This must be the last stage in the pipeline.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/out/ | [
"Takes",
"the",
"documents",
"returned",
"by",
"the",
"aggregation",
"pipeline",
"and",
"writes",
"them",
"to",
"a",
"specified",
"collection",
".",
"This",
"must",
"be",
"the",
"last",
"stage",
"in",
"the",
"pipeline",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L377-L383 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.project | public function project() : Stage\Project
{
$stage = new Stage\Project($this);
$this->addStage($stage);
return $stage;
} | php | public function project() : Stage\Project
{
$stage = new Stage\Project($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"project",
"(",
")",
":",
"Stage",
"\\",
"Project",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Project",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Passes along the documents with only the specified fields to the next
stage in the pipeline. The specified fields can be existing fields from
the input documents or newly computed fields.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/project/ | [
"Passes",
"along",
"the",
"documents",
"with",
"only",
"the",
"specified",
"fields",
"to",
"the",
"next",
"stage",
"in",
"the",
"pipeline",
".",
"The",
"specified",
"fields",
"can",
"be",
"existing",
"fields",
"from",
"the",
"input",
"documents",
"or",
"newly",
"computed",
"fields",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L392-L398 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.redact | public function redact() : Stage\Redact
{
$stage = new Stage\Redact($this);
$this->addStage($stage);
return $stage;
} | php | public function redact() : Stage\Redact
{
$stage = new Stage\Redact($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"redact",
"(",
")",
":",
"Stage",
"\\",
"Redact",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Redact",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Restricts the contents of the documents based on information stored in
the documents themselves.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/redact/ | [
"Restricts",
"the",
"contents",
"of",
"the",
"documents",
"based",
"on",
"information",
"stored",
"in",
"the",
"documents",
"themselves",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L406-L412 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.replaceRoot | public function replaceRoot($expression = null) : Stage\ReplaceRoot
{
$stage = new Stage\ReplaceRoot($this, $this->dm, $this->class, $expression);
$this->addStage($stage);
return $stage;
} | php | public function replaceRoot($expression = null) : Stage\ReplaceRoot
{
$stage = new Stage\ReplaceRoot($this, $this->dm, $this->class, $expression);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"replaceRoot",
"(",
"$",
"expression",
"=",
"null",
")",
":",
"Stage",
"\\",
"ReplaceRoot",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"ReplaceRoot",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
",",
"$",
"expression",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Promotes a specified document to the top level and replaces all other
fields.
The operation replaces all existing fields in the input document,
including the _id field. You can promote an existing embedded document to
the top level, or create a new document for promotion.
@param string|array|null $expression Optional. A replacement expression that
resolves to a document. | [
"Promotes",
"a",
"specified",
"document",
"to",
"the",
"top",
"level",
"and",
"replaces",
"all",
"other",
"fields",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L425-L431 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.sample | public function sample(int $size) : Stage\Sample
{
$stage = new Stage\Sample($this, $size);
$this->addStage($stage);
return $stage;
} | php | public function sample(int $size) : Stage\Sample
{
$stage = new Stage\Sample($this, $size);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"sample",
"(",
"int",
"$",
"size",
")",
":",
"Stage",
"\\",
"Sample",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Sample",
"(",
"$",
"this",
",",
"$",
"size",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Randomly selects the specified number of documents from its input.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/sample/ | [
"Randomly",
"selects",
"the",
"specified",
"number",
"of",
"documents",
"from",
"its",
"input",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L438-L444 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.skip | public function skip(int $skip) : Stage\Skip
{
$stage = new Stage\Skip($this, $skip);
$this->addStage($stage);
return $stage;
} | php | public function skip(int $skip) : Stage\Skip
{
$stage = new Stage\Skip($this, $skip);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"skip",
"(",
"int",
"$",
"skip",
")",
":",
"Stage",
"\\",
"Skip",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Skip",
"(",
"$",
"this",
",",
"$",
"skip",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Skips over the specified number of documents that pass into the stage and
passes the remaining documents to the next stage in the pipeline.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/ | [
"Skips",
"over",
"the",
"specified",
"number",
"of",
"documents",
"that",
"pass",
"into",
"the",
"stage",
"and",
"passes",
"the",
"remaining",
"documents",
"to",
"the",
"next",
"stage",
"in",
"the",
"pipeline",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L452-L458 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.sortByCount | public function sortByCount(string $expression) : Stage\SortByCount
{
$stage = new Stage\SortByCount($this, $expression, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | php | public function sortByCount(string $expression) : Stage\SortByCount
{
$stage = new Stage\SortByCount($this, $expression, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"sortByCount",
"(",
"string",
"$",
"expression",
")",
":",
"Stage",
"\\",
"SortByCount",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"SortByCount",
"(",
"$",
"this",
",",
"$",
"expression",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Groups incoming documents based on the value of a specified expression,
then computes the count of documents in each distinct group.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/sortByCount/ | [
"Groups",
"incoming",
"documents",
"based",
"on",
"the",
"value",
"of",
"a",
"specified",
"expression",
"then",
"computes",
"the",
"count",
"of",
"documents",
"in",
"each",
"distinct",
"group",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L488-L494 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.unwind | public function unwind(string $fieldName) : Stage\Unwind
{
// Fixme: move field name translation to stage
$stage = new Stage\Unwind($this, $this->getDocumentPersister()->prepareFieldName($fieldName));
$this->addStage($stage);
return $stage;
} | php | public function unwind(string $fieldName) : Stage\Unwind
{
// Fixme: move field name translation to stage
$stage = new Stage\Unwind($this, $this->getDocumentPersister()->prepareFieldName($fieldName));
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"unwind",
"(",
"string",
"$",
"fieldName",
")",
":",
"Stage",
"\\",
"Unwind",
"{",
"// Fixme: move field name translation to stage",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Unwind",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getDocumentPersister",
"(",
")",
"->",
"prepareFieldName",
"(",
"$",
"fieldName",
")",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Deconstructs an array field from the input documents to output a document
for each element. Each output document is the input document with the
value of the array field replaced by the element.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/ | [
"Deconstructs",
"an",
"array",
"field",
"from",
"the",
"input",
"documents",
"to",
"output",
"a",
"document",
"for",
"each",
"element",
".",
"Each",
"output",
"document",
"is",
"the",
"input",
"document",
"with",
"the",
"value",
"of",
"the",
"array",
"field",
"replaced",
"by",
"the",
"element",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L503-L510 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.applyFilters | private function applyFilters(array $query) : array
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$query = $documentPersister->addDiscriminatorToPreparedQuery($query);
$query = $documentPersister->addFilterToPreparedQuery($query);
return $query;
} | php | private function applyFilters(array $query) : array
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$query = $documentPersister->addDiscriminatorToPreparedQuery($query);
$query = $documentPersister->addFilterToPreparedQuery($query);
return $query;
} | [
"private",
"function",
"applyFilters",
"(",
"array",
"$",
"query",
")",
":",
"array",
"{",
"$",
"documentPersister",
"=",
"$",
"this",
"->",
"dm",
"->",
"getUnitOfWork",
"(",
")",
"->",
"getDocumentPersister",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
";",
"$",
"query",
"=",
"$",
"documentPersister",
"->",
"addDiscriminatorToPreparedQuery",
"(",
"$",
"query",
")",
";",
"$",
"query",
"=",
"$",
"documentPersister",
"->",
"addFilterToPreparedQuery",
"(",
"$",
"query",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Applies filters and discriminator queries to the pipeline | [
"Applies",
"filters",
"and",
"discriminator",
"queries",
"to",
"the",
"pipeline"
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L527-L535 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php | CachingIterator.storeCurrentItem | private function storeCurrentItem() : void
{
$key = $this->iterator->key();
if ($key === null) {
return;
}
$this->items[$key] = $this->iterator->current();
} | php | private function storeCurrentItem() : void
{
$key = $this->iterator->key();
if ($key === null) {
return;
}
$this->items[$key] = $this->iterator->current();
} | [
"private",
"function",
"storeCurrentItem",
"(",
")",
":",
"void",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"iterator",
"->",
"key",
"(",
")",
";",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"iterator",
"->",
"current",
"(",
")",
";",
"}"
] | Stores the current item in the cache. | [
"Stores",
"the",
"current",
"item",
"in",
"the",
"cache",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php#L126-L135 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php | Project.avg | public function avg($expression1, ...$expressions) : self
{
$this->expr->avg(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | php | public function avg($expression1, ...$expressions) : self
{
$this->expr->avg(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | [
"public",
"function",
"avg",
"(",
"$",
"expression1",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"avg",
"(",
"empty",
"(",
"$",
"expressions",
")",
"?",
"$",
"expression1",
":",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Returns the average value of the numeric values that result from applying
a specified expression to each document in a group of documents that
share the same group by key. Ignores nun-numeric values.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/
@see Expr::avg
@param mixed|Expr $expression1
@param mixed|Expr ...$expressions Additional expressions | [
"Returns",
"the",
"average",
"value",
"of",
"the",
"numeric",
"values",
"that",
"result",
"from",
"applying",
"a",
"specified",
"expression",
"to",
"each",
"document",
"in",
"a",
"group",
"of",
"documents",
"that",
"share",
"the",
"same",
"group",
"by",
"key",
".",
"Ignores",
"nun",
"-",
"numeric",
"values",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php#L36-L41 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php | Project.stdDevSamp | public function stdDevSamp($expression1, ...$expressions) : self
{
$this->expr->stdDevSamp(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | php | public function stdDevSamp($expression1, ...$expressions) : self
{
$this->expr->stdDevSamp(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | [
"public",
"function",
"stdDevSamp",
"(",
"$",
"expression1",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"stdDevSamp",
"(",
"empty",
"(",
"$",
"expressions",
")",
"?",
"$",
"expression1",
":",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Calculates the sample standard deviation of the input values.
The argument can be any expression as long as it resolves to an array.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/
@see Expr::stdDevSamp
@param mixed|Expr $expression1
@param mixed|Expr ...$expressions Additional expressions | [
"Calculates",
"the",
"sample",
"standard",
"deviation",
"of",
"the",
"input",
"values",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php#L133-L138 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php | Project.sum | public function sum($expression1, ...$expressions) : self
{
$this->expr->sum(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | php | public function sum($expression1, ...$expressions) : self
{
$this->expr->sum(empty($expressions) ? $expression1 : func_get_args());
return $this;
} | [
"public",
"function",
"sum",
"(",
"$",
"expression1",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"sum",
"(",
"empty",
"(",
"$",
"expressions",
")",
"?",
"$",
"expression1",
":",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Calculates and returns the sum of all the numeric values that result from
applying a specified expression to each document in a group of documents
that share the same group by key. Ignores nun-numeric values.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/
@see Expr::sum
@param mixed|Expr $expression1
@param mixed|Expr ...$expressions Additional expressions | [
"Calculates",
"and",
"returns",
"the",
"sum",
"of",
"all",
"the",
"numeric",
"values",
"that",
"result",
"from",
"applying",
"a",
"specified",
"expression",
"to",
"each",
"document",
"in",
"a",
"group",
"of",
"documents",
"that",
"share",
"the",
"same",
"group",
"by",
"key",
".",
"Ignores",
"nun",
"-",
"numeric",
"values",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Project.php#L151-L156 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php | Expr.expression | public function expression($value) : self
{
$this->requiresCurrentField(__METHOD__);
$this->expr[$this->currentField] = $this->ensureArray($value);
return $this;
} | php | public function expression($value) : self
{
$this->requiresCurrentField(__METHOD__);
$this->expr[$this->currentField] = $this->ensureArray($value);
return $this;
} | [
"public",
"function",
"expression",
"(",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"expr",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"this",
"->",
"ensureArray",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Allows any expression to be used as a field value.
@see http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-expressions
@param mixed|self $value | [
"Allows",
"any",
"expression",
"to",
"be",
"used",
"as",
"a",
"field",
"value",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php#L475-L481 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php | Expr.field | public function field(string $fieldName) : self
{
$fieldName = $this->getDocumentPersister()->prepareFieldName($fieldName);
$this->currentField = $fieldName;
return $this;
} | php | public function field(string $fieldName) : self
{
$fieldName = $this->getDocumentPersister()->prepareFieldName($fieldName);
$this->currentField = $fieldName;
return $this;
} | [
"public",
"function",
"field",
"(",
"string",
"$",
"fieldName",
")",
":",
"self",
"{",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"getDocumentPersister",
"(",
")",
"->",
"prepareFieldName",
"(",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"currentField",
"=",
"$",
"fieldName",
";",
"return",
"$",
"this",
";",
"}"
] | Set the current field for building the expression. | [
"Set",
"the",
"current",
"field",
"for",
"building",
"the",
"expression",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php#L486-L492 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.addToSet | public function addToSet($valueOrExpression) : self
{
if ($valueOrExpression instanceof Expr) {
$valueOrExpression = $valueOrExpression->getQuery();
}
$this->requiresCurrentField();
$this->newObj['$addToSet'][$this->currentField] = $valueOrExpression;
return $this;
} | php | public function addToSet($valueOrExpression) : self
{
if ($valueOrExpression instanceof Expr) {
$valueOrExpression = $valueOrExpression->getQuery();
}
$this->requiresCurrentField();
$this->newObj['$addToSet'][$this->currentField] = $valueOrExpression;
return $this;
} | [
"public",
"function",
"addToSet",
"(",
"$",
"valueOrExpression",
")",
":",
"self",
"{",
"if",
"(",
"$",
"valueOrExpression",
"instanceof",
"Expr",
")",
"{",
"$",
"valueOrExpression",
"=",
"$",
"valueOrExpression",
"->",
"getQuery",
"(",
")",
";",
"}",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$addToSet'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"valueOrExpression",
";",
"return",
"$",
"this",
";",
"}"
] | Append one or more values to the current array field only if they do not
already exist in the array.
If the field does not exist, it will be set to an array containing the
unique value(s) in the argument. If the field is not an array, the query
will yield an error.
Multiple values may be specified by provided an Expr object and using
{@link Expr::each()}.
@see Builder::addToSet()
@see http://docs.mongodb.org/manual/reference/operator/addToSet/
@see http://docs.mongodb.org/manual/reference/operator/each/
@param mixed|Expr $valueOrExpression | [
"Append",
"one",
"or",
"more",
"values",
"to",
"the",
"current",
"array",
"field",
"only",
"if",
"they",
"do",
"not",
"already",
"exist",
"in",
"the",
"array",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L175-L184 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.equals | public function equals($value) : self
{
if ($this->currentField) {
$this->query[$this->currentField] = $value;
} else {
$this->query = $value;
}
return $this;
} | php | public function equals($value) : self
{
if ($this->currentField) {
$this->query[$this->currentField] = $value;
} else {
$this->query = $value;
}
return $this;
} | [
"public",
"function",
"equals",
"(",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"currentField",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Specify an equality match for the current field.
@see Builder::equals()
@param mixed $value | [
"Specify",
"an",
"equality",
"match",
"for",
"the",
"current",
"field",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L418-L426 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.inc | public function inc($value) : self
{
$this->requiresCurrentField();
$this->newObj['$inc'][$this->currentField] = $value;
return $this;
} | php | public function inc($value) : self
{
$this->requiresCurrentField();
$this->newObj['$inc'][$this->currentField] = $value;
return $this;
} | [
"public",
"function",
"inc",
"(",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"this",
"->",
"newObj",
"[",
"'$inc'",
"]",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Increment the current field.
If the field does not exist, it will be set to this value.
@see Builder::inc()
@see http://docs.mongodb.org/manual/reference/operator/inc/
@param float|int $value | [
"Increment",
"the",
"current",
"field",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L643-L648 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.includesReferenceTo | public function includesReferenceTo(object $document) : self
{
$this->requiresCurrentField();
$mapping = $this->getReferenceMapping();
$reference = $this->dm->createReference($document, $mapping);
$storeAs = $mapping['storeAs'] ?? null;
$keys = [];
switch ($storeAs) {
case ClassMetadata::REFERENCE_STORE_AS_ID:
$this->query[$mapping['name']] = $reference;
return $this;
break;
case ClassMetadata::REFERENCE_STORE_AS_REF:
$keys = ['id' => true];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
$keys = ['$ref' => true, '$id' => true, '$db' => true];
if ($storeAs === ClassMetadata::REFERENCE_STORE_AS_DB_REF) {
unset($keys['$db']);
}
if (isset($mapping['targetDocument'])) {
unset($keys['$ref'], $keys['$db']);
}
break;
default:
throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
}
foreach ($keys as $key => $value) {
$this->query[$mapping['name']]['$elemMatch'][$key] = $reference[$key];
}
return $this;
} | php | public function includesReferenceTo(object $document) : self
{
$this->requiresCurrentField();
$mapping = $this->getReferenceMapping();
$reference = $this->dm->createReference($document, $mapping);
$storeAs = $mapping['storeAs'] ?? null;
$keys = [];
switch ($storeAs) {
case ClassMetadata::REFERENCE_STORE_AS_ID:
$this->query[$mapping['name']] = $reference;
return $this;
break;
case ClassMetadata::REFERENCE_STORE_AS_REF:
$keys = ['id' => true];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
$keys = ['$ref' => true, '$id' => true, '$db' => true];
if ($storeAs === ClassMetadata::REFERENCE_STORE_AS_DB_REF) {
unset($keys['$db']);
}
if (isset($mapping['targetDocument'])) {
unset($keys['$ref'], $keys['$db']);
}
break;
default:
throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
}
foreach ($keys as $key => $value) {
$this->query[$mapping['name']]['$elemMatch'][$key] = $reference[$key];
}
return $this;
} | [
"public",
"function",
"includesReferenceTo",
"(",
"object",
"$",
"document",
")",
":",
"self",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getReferenceMapping",
"(",
")",
";",
"$",
"reference",
"=",
"$",
"this",
"->",
"dm",
"->",
"createReference",
"(",
"$",
"document",
",",
"$",
"mapping",
")",
";",
"$",
"storeAs",
"=",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"??",
"null",
";",
"$",
"keys",
"=",
"[",
"]",
";",
"switch",
"(",
"$",
"storeAs",
")",
"{",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
":",
"$",
"this",
"->",
"query",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"reference",
";",
"return",
"$",
"this",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_REF",
":",
"$",
"keys",
"=",
"[",
"'id'",
"=>",
"true",
"]",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF",
":",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF_WITH_DB",
":",
"$",
"keys",
"=",
"[",
"'$ref'",
"=>",
"true",
",",
"'$id'",
"=>",
"true",
",",
"'$db'",
"=>",
"true",
"]",
";",
"if",
"(",
"$",
"storeAs",
"===",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF",
")",
"{",
"unset",
"(",
"$",
"keys",
"[",
"'$db'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"keys",
"[",
"'$ref'",
"]",
",",
"$",
"keys",
"[",
"'$db'",
"]",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Reference type %s is invalid.'",
",",
"$",
"storeAs",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"[",
"'$elemMatch'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"reference",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Checks that the current field includes a reference to the supplied document. | [
"Checks",
"that",
"the",
"current",
"field",
"includes",
"a",
"reference",
"to",
"the",
"supplied",
"document",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L653-L693 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.not | public function not($expression) : self
{
return $this->operator('$not', $expression instanceof Expr ? $expression->getQuery() : $expression);
} | php | public function not($expression) : self
{
return $this->operator('$not', $expression instanceof Expr ? $expression->getQuery() : $expression);
} | [
"public",
"function",
"not",
"(",
"$",
"expression",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"operator",
"(",
"'$not'",
",",
"$",
"expression",
"instanceof",
"Expr",
"?",
"$",
"expression",
"->",
"getQuery",
"(",
")",
":",
"$",
"expression",
")",
";",
"}"
] | Negates an expression for the current field.
@see Builder::not()
@see http://docs.mongodb.org/manual/reference/operator/not/
@param array|Expr $expression | [
"Negates",
"an",
"expression",
"for",
"the",
"current",
"field",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L863-L866 | train |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Expr.php | Expr.getReferenceMapping | private function getReferenceMapping() : array
{
$this->requiresCurrentField();
assert($this->currentField !== null);
try {
return $this->class->getFieldMapping($this->currentField);
} catch (MappingException $e) {
if (empty($this->class->discriminatorMap)) {
throw $e;
}
$mapping = null;
$foundIn = null;
foreach ($this->class->discriminatorMap as $child) {
$childClass = $this->dm->getClassMetadata($child);
if (! $childClass->hasAssociation($this->currentField)) {
continue;
}
if ($foundIn !== null && $mapping !== null && $mapping !== $childClass->getFieldMapping($this->currentField)) {
throw MappingException::referenceFieldConflict($this->currentField, $foundIn->name, $childClass->name);
}
$mapping = $childClass->getFieldMapping($this->currentField);
$foundIn = $childClass;
}
if ($mapping === null) {
throw MappingException::mappingNotFoundInClassNorDescendants($this->class->name, $this->currentField);
}
return $mapping;
}
} | php | private function getReferenceMapping() : array
{
$this->requiresCurrentField();
assert($this->currentField !== null);
try {
return $this->class->getFieldMapping($this->currentField);
} catch (MappingException $e) {
if (empty($this->class->discriminatorMap)) {
throw $e;
}
$mapping = null;
$foundIn = null;
foreach ($this->class->discriminatorMap as $child) {
$childClass = $this->dm->getClassMetadata($child);
if (! $childClass->hasAssociation($this->currentField)) {
continue;
}
if ($foundIn !== null && $mapping !== null && $mapping !== $childClass->getFieldMapping($this->currentField)) {
throw MappingException::referenceFieldConflict($this->currentField, $foundIn->name, $childClass->name);
}
$mapping = $childClass->getFieldMapping($this->currentField);
$foundIn = $childClass;
}
if ($mapping === null) {
throw MappingException::mappingNotFoundInClassNorDescendants($this->class->name, $this->currentField);
}
return $mapping;
}
} | [
"private",
"function",
"getReferenceMapping",
"(",
")",
":",
"array",
"{",
"$",
"this",
"->",
"requiresCurrentField",
"(",
")",
";",
"assert",
"(",
"$",
"this",
"->",
"currentField",
"!==",
"null",
")",
";",
"try",
"{",
"return",
"$",
"this",
"->",
"class",
"->",
"getFieldMapping",
"(",
"$",
"this",
"->",
"currentField",
")",
";",
"}",
"catch",
"(",
"MappingException",
"$",
"e",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"class",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"mapping",
"=",
"null",
";",
"$",
"foundIn",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"class",
"->",
"discriminatorMap",
"as",
"$",
"child",
")",
"{",
"$",
"childClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"child",
")",
";",
"if",
"(",
"!",
"$",
"childClass",
"->",
"hasAssociation",
"(",
"$",
"this",
"->",
"currentField",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"foundIn",
"!==",
"null",
"&&",
"$",
"mapping",
"!==",
"null",
"&&",
"$",
"mapping",
"!==",
"$",
"childClass",
"->",
"getFieldMapping",
"(",
"$",
"this",
"->",
"currentField",
")",
")",
"{",
"throw",
"MappingException",
"::",
"referenceFieldConflict",
"(",
"$",
"this",
"->",
"currentField",
",",
"$",
"foundIn",
"->",
"name",
",",
"$",
"childClass",
"->",
"name",
")",
";",
"}",
"$",
"mapping",
"=",
"$",
"childClass",
"->",
"getFieldMapping",
"(",
"$",
"this",
"->",
"currentField",
")",
";",
"$",
"foundIn",
"=",
"$",
"childClass",
";",
"}",
"if",
"(",
"$",
"mapping",
"===",
"null",
")",
"{",
"throw",
"MappingException",
"::",
"mappingNotFoundInClassNorDescendants",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
",",
"$",
"this",
"->",
"currentField",
")",
";",
"}",
"return",
"$",
"mapping",
";",
"}",
"}"
] | Gets reference mapping for current field from current class or its descendants.
@throws MappingException | [
"Gets",
"reference",
"mapping",
"for",
"current",
"field",
"from",
"current",
"class",
"or",
"its",
"descendants",
"."
] | e4971557a8200456d87e2f1def8bde7fb07bbb3f | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L1291-L1322 | train |
Torann/laravel-geoip | src/Cache.php | Cache.set | public function set($name, Location $location)
{
return $this->cache->put($name, $location->toArray(), $this->expires);
} | php | public function set($name, Location $location)
{
return $this->cache->put($name, $location->toArray(), $this->expires);
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"Location",
"$",
"location",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"->",
"put",
"(",
"$",
"name",
",",
"$",
"location",
"->",
"toArray",
"(",
")",
",",
"$",
"this",
"->",
"expires",
")",
";",
"}"
] | Store an item in cache.
@param string $name
@param Location $location
@return bool | [
"Store",
"an",
"item",
"in",
"cache",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/Cache.php#L60-L63 | train |
Torann/laravel-geoip | src/GeoIPServiceProvider.php | GeoIPServiceProvider.registerGeoIpService | public function registerGeoIpService()
{
$this->app->singleton('geoip', function ($app) {
return new GeoIP(
$app->config->get('geoip', []),
$app['cache']
);
});
} | php | public function registerGeoIpService()
{
$this->app->singleton('geoip', function ($app) {
return new GeoIP(
$app->config->get('geoip', []),
$app['cache']
);
});
} | [
"public",
"function",
"registerGeoIpService",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'geoip'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"GeoIP",
"(",
"$",
"app",
"->",
"config",
"->",
"get",
"(",
"'geoip'",
",",
"[",
"]",
")",
",",
"$",
"app",
"[",
"'cache'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register currency provider.
@return void | [
"Register",
"currency",
"provider",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/GeoIPServiceProvider.php#L33-L41 | train |
Torann/laravel-geoip | src/GeoIP.php | GeoIP.getService | public function getService()
{
if ($this->service === null) {
// Get service configuration
$config = $this->config('services.' . $this->config('service'), []);
// Get service class
$class = Arr::pull($config, 'class');
// Sanity check
if ($class === null) {
throw new Exception('The GeoIP service is not valid.');
}
// Create service instance
$this->service = new $class($config);
}
return $this->service;
} | php | public function getService()
{
if ($this->service === null) {
// Get service configuration
$config = $this->config('services.' . $this->config('service'), []);
// Get service class
$class = Arr::pull($config, 'class');
// Sanity check
if ($class === null) {
throw new Exception('The GeoIP service is not valid.');
}
// Create service instance
$this->service = new $class($config);
}
return $this->service;
} | [
"public",
"function",
"getService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"service",
"===",
"null",
")",
"{",
"// Get service configuration",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
"'services.'",
".",
"$",
"this",
"->",
"config",
"(",
"'service'",
")",
",",
"[",
"]",
")",
";",
"// Get service class",
"$",
"class",
"=",
"Arr",
"::",
"pull",
"(",
"$",
"config",
",",
"'class'",
")",
";",
"// Sanity check",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The GeoIP service is not valid.'",
")",
";",
"}",
"// Create service instance",
"$",
"this",
"->",
"service",
"=",
"new",
"$",
"class",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"service",
";",
"}"
] | Get service instance.
@return \Torann\GeoIP\Contracts\ServiceInterface
@throws Exception | [
"Get",
"service",
"instance",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/GeoIP.php#L194-L213 | train |
Torann/laravel-geoip | src/GeoIP.php | GeoIP.isValid | private function isValid($ip)
{
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
&& !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE)
) {
return false;
}
return true;
} | php | private function isValid($ip)
{
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
&& !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE)
) {
return false;
}
return true;
} | [
"private",
"function",
"isValid",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
"|",
"FILTER_FLAG_NO_PRIV_RANGE",
"|",
"FILTER_FLAG_NO_RES_RANGE",
")",
"&&",
"!",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
"|",
"FILTER_FLAG_NO_PRIV_RANGE",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if the ip is valid.
@param string $ip
@return bool | [
"Checks",
"if",
"the",
"ip",
"is",
"valid",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/GeoIP.php#L262-L271 | train |
Torann/laravel-geoip | src/Support/HttpClient.php | HttpClient.get | public function get($url, array $query = [], array $headers = [])
{
return $this->execute('GET', $this->buildGetUrl($url, $query), [], $headers);
} | php | public function get($url, array $query = [], array $headers = [])
{
return $this->execute('GET', $this->buildGetUrl($url, $query), [], $headers);
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"array",
"$",
"query",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"execute",
"(",
"'GET'",
",",
"$",
"this",
"->",
"buildGetUrl",
"(",
"$",
"url",
",",
"$",
"query",
")",
",",
"[",
"]",
",",
"$",
"headers",
")",
";",
"}"
] | Perform a get request.
@param string $url
@param array $query
@param array $headers
@return array | [
"Perform",
"a",
"get",
"request",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/Support/HttpClient.php#L60-L63 | train |
Torann/laravel-geoip | src/Support/HttpClient.php | HttpClient.parseHeaders | private function parseHeaders($headers)
{
$result = [];
foreach (preg_split("/\\r\\n|\\r|\\n/", $headers) as $row) {
$header = explode(':', $row, 2);
if (count($header) == 2) {
$result[$header[0]] = trim($header[1]);
}
else {
$result[] = $header[0];
}
}
return $result;
} | php | private function parseHeaders($headers)
{
$result = [];
foreach (preg_split("/\\r\\n|\\r|\\n/", $headers) as $row) {
$header = explode(':', $row, 2);
if (count($header) == 2) {
$result[$header[0]] = trim($header[1]);
}
else {
$result[] = $header[0];
}
}
return $result;
} | [
"private",
"function",
"parseHeaders",
"(",
"$",
"headers",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"preg_split",
"(",
"\"/\\\\r\\\\n|\\\\r|\\\\n/\"",
",",
"$",
"headers",
")",
"as",
"$",
"row",
")",
"{",
"$",
"header",
"=",
"explode",
"(",
"':'",
",",
"$",
"row",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"header",
")",
"==",
"2",
")",
"{",
"$",
"result",
"[",
"$",
"header",
"[",
"0",
"]",
"]",
"=",
"trim",
"(",
"$",
"header",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"header",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Parse string headers into array
@param string $headers
@return array | [
"Parse",
"string",
"headers",
"into",
"array"
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/Support/HttpClient.php#L187-L203 | train |
Torann/laravel-geoip | src/Support/HttpClient.php | HttpClient.getUrl | private function getUrl($url)
{
// Check for URL scheme
if (parse_url($url, PHP_URL_SCHEME) === null) {
$url = Arr::get($this->config, 'base_uri') . $url;
}
return $url;
} | php | private function getUrl($url)
{
// Check for URL scheme
if (parse_url($url, PHP_URL_SCHEME) === null) {
$url = Arr::get($this->config, 'base_uri') . $url;
}
return $url;
} | [
"private",
"function",
"getUrl",
"(",
"$",
"url",
")",
"{",
"// Check for URL scheme",
"if",
"(",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_SCHEME",
")",
"===",
"null",
")",
"{",
"$",
"url",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'base_uri'",
")",
".",
"$",
"url",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Get request URL.
@param string $url
@return string | [
"Get",
"request",
"URL",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/Support/HttpClient.php#L212-L220 | train |
Torann/laravel-geoip | src/Support/HttpClient.php | HttpClient.buildGetUrl | private function buildGetUrl($url, array $query = [])
{
// Merge global and request queries
$query = array_merge(
Arr::get($this->config, 'query', []),
$query
);
// Append query
if ($query = http_build_query($query)) {
$url .= strpos($url, '?') ? $query : "?{$query}";
}
return $url;
} | php | private function buildGetUrl($url, array $query = [])
{
// Merge global and request queries
$query = array_merge(
Arr::get($this->config, 'query', []),
$query
);
// Append query
if ($query = http_build_query($query)) {
$url .= strpos($url, '?') ? $query : "?{$query}";
}
return $url;
} | [
"private",
"function",
"buildGetUrl",
"(",
"$",
"url",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"// Merge global and request queries",
"$",
"query",
"=",
"array_merge",
"(",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'query'",
",",
"[",
"]",
")",
",",
"$",
"query",
")",
";",
"// Append query",
"if",
"(",
"$",
"query",
"=",
"http_build_query",
"(",
"$",
"query",
")",
")",
"{",
"$",
"url",
".=",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"?",
"$",
"query",
":",
"\"?{$query}\"",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Build a GET request string.
@param string $url
@param array $query
@return string | [
"Build",
"a",
"GET",
"request",
"string",
"."
] | b205c5897f632fb726494657aabc0699206ce38c | https://github.com/Torann/laravel-geoip/blob/b205c5897f632fb726494657aabc0699206ce38c/src/Support/HttpClient.php#L230-L244 | train |
mollie/mollie-api-php | src/Endpoints/CustomerPaymentsEndpoint.php | CustomerPaymentsEndpoint.createForId | public function createForId($customerId, array $options = [], array $filters = [])
{
$this->parentId = $customerId;
return parent::rest_create($options, $filters);
} | php | public function createForId($customerId, array $options = [], array $filters = [])
{
$this->parentId = $customerId;
return parent::rest_create($options, $filters);
} | [
"public",
"function",
"createForId",
"(",
"$",
"customerId",
",",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"array",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"parentId",
"=",
"$",
"customerId",
";",
"return",
"parent",
"::",
"rest_create",
"(",
"$",
"options",
",",
"$",
"filters",
")",
";",
"}"
] | Create a subscription for a Customer ID
@param string $customerId
@param array $options
@param array $filters
@return \Mollie\Api\Resources\BaseResource|\Mollie\Api\Resources\Payment
@throws \Mollie\Api\Exceptions\ApiException | [
"Create",
"a",
"subscription",
"for",
"a",
"Customer",
"ID"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/CustomerPaymentsEndpoint.php#L61-L66 | train |
mollie/mollie-api-php | src/Endpoints/ProfileMethodEndpoint.php | ProfileMethodEndpoint.createForId | public function createForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
$resource = $this->getResourcePath() . '/' . urlencode($methodId);
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Method($this->client));
} | php | public function createForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
$resource = $this->getResourcePath() . '/' . urlencode($methodId);
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Method($this->client));
} | [
"public",
"function",
"createForId",
"(",
"$",
"profileId",
",",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"parentId",
"=",
"$",
"profileId",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResourcePath",
"(",
")",
".",
"'/'",
".",
"urlencode",
"(",
"$",
"methodId",
")",
";",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_CREATE",
",",
"$",
"resource",
",",
"$",
"body",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"new",
"Method",
"(",
"$",
"this",
"->",
"client",
")",
")",
";",
"}"
] | Enable a method for the provided Profile ID.
@param $profileId
@param $methodId
@param array $data
@return \Mollie\Api\Resources\BaseResource
@throws \Mollie\Api\Exceptions\ApiException | [
"Enable",
"a",
"method",
"for",
"the",
"provided",
"Profile",
"ID",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ProfileMethodEndpoint.php#L46-L59 | train |
mollie/mollie-api-php | src/Endpoints/ProfileMethodEndpoint.php | ProfileMethodEndpoint.createFor | public function createFor($profile, $methodId, array $data = [])
{
return $this->createForId($profile->id, $methodId, $data);
} | php | public function createFor($profile, $methodId, array $data = [])
{
return $this->createForId($profile->id, $methodId, $data);
} | [
"public",
"function",
"createFor",
"(",
"$",
"profile",
",",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"createForId",
"(",
"$",
"profile",
"->",
"id",
",",
"$",
"methodId",
",",
"$",
"data",
")",
";",
"}"
] | Enable a method for the provided Profile object.
@param Profile $profile
@param string $methodId
@param array $data
@return Method
@throws \Mollie\Api\Exceptions\ApiException | [
"Enable",
"a",
"method",
"for",
"the",
"provided",
"Profile",
"object",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ProfileMethodEndpoint.php#L70-L73 | train |
mollie/mollie-api-php | src/Endpoints/ProfileMethodEndpoint.php | ProfileMethodEndpoint.deleteForId | public function deleteForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
return $this->rest_delete($methodId, $data);
} | php | public function deleteForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
return $this->rest_delete($methodId, $data);
} | [
"public",
"function",
"deleteForId",
"(",
"$",
"profileId",
",",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"parentId",
"=",
"$",
"profileId",
";",
"return",
"$",
"this",
"->",
"rest_delete",
"(",
"$",
"methodId",
",",
"$",
"data",
")",
";",
"}"
] | Disable a method for the provided Profile ID.
@param $profileId
@param $methodId
@param array $data
@return \Mollie\Api\Resources\BaseResource
@throws \Mollie\Api\Exceptions\ApiException | [
"Disable",
"a",
"method",
"for",
"the",
"provided",
"Profile",
"ID",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ProfileMethodEndpoint.php#L97-L102 | train |
mollie/mollie-api-php | src/Endpoints/ProfileMethodEndpoint.php | ProfileMethodEndpoint.deleteFor | public function deleteFor($profile, $methodId, array $data = [])
{
return $this->deleteForId($profile->id, $methodId, $data);
} | php | public function deleteFor($profile, $methodId, array $data = [])
{
return $this->deleteForId($profile->id, $methodId, $data);
} | [
"public",
"function",
"deleteFor",
"(",
"$",
"profile",
",",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"deleteForId",
"(",
"$",
"profile",
"->",
"id",
",",
"$",
"methodId",
",",
"$",
"data",
")",
";",
"}"
] | Disable a method for the provided Profile object.
@param $profile
@param $methodId
@param array $data
@return \Mollie\Api\Resources\BaseResource
@throws \Mollie\Api\Exceptions\ApiException | [
"Disable",
"a",
"method",
"for",
"the",
"provided",
"Profile",
"object",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ProfileMethodEndpoint.php#L113-L116 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.payments | public function payments()
{
return $this->client->customerPayments->listFor($this, null, null, $this->getPresetOptions());
} | php | public function payments()
{
return $this->client->customerPayments->listFor($this, null, null, $this->getPresetOptions());
} | [
"public",
"function",
"payments",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"customerPayments",
"->",
"listFor",
"(",
"$",
"this",
",",
"null",
",",
"null",
",",
"$",
"this",
"->",
"getPresetOptions",
"(",
")",
")",
";",
"}"
] | Get all payments for this customer
@return PaymentCollection | [
"Get",
"all",
"payments",
"for",
"this",
"customer"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L100-L103 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.subscriptions | public function subscriptions()
{
return $this->client->subscriptions->listFor($this, null, null, $this->getPresetOptions());
} | php | public function subscriptions()
{
return $this->client->subscriptions->listFor($this, null, null, $this->getPresetOptions());
} | [
"public",
"function",
"subscriptions",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"subscriptions",
"->",
"listFor",
"(",
"$",
"this",
",",
"null",
",",
"null",
",",
"$",
"this",
"->",
"getPresetOptions",
"(",
")",
")",
";",
"}"
] | Get all subscriptions for this customer
@return SubscriptionCollection | [
"Get",
"all",
"subscriptions",
"for",
"this",
"customer"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L142-L145 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.mandates | public function mandates()
{
return $this->client->mandates->listFor($this, null, null, $this->getPresetOptions());
} | php | public function mandates()
{
return $this->client->mandates->listFor($this, null, null, $this->getPresetOptions());
} | [
"public",
"function",
"mandates",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"mandates",
"->",
"listFor",
"(",
"$",
"this",
",",
"null",
",",
"null",
",",
"$",
"this",
"->",
"getPresetOptions",
"(",
")",
")",
";",
"}"
] | Get all mandates for this customer
@return MandateCollection | [
"Get",
"all",
"mandates",
"for",
"this",
"customer"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L184-L187 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.hasValidMandate | public function hasValidMandate()
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->isValid()) {
return true;
}
}
return false;
} | php | public function hasValidMandate()
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->isValid()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasValidMandate",
"(",
")",
"{",
"$",
"mandates",
"=",
"$",
"this",
"->",
"mandates",
"(",
")",
";",
"foreach",
"(",
"$",
"mandates",
"as",
"$",
"mandate",
")",
"{",
"if",
"(",
"$",
"mandate",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Helper function to check for mandate with status valid
@return bool | [
"Helper",
"function",
"to",
"check",
"for",
"mandate",
"with",
"status",
"valid"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L194-L204 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.hasValidMandateForMethod | public function hasValidMandateForMethod($method)
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->method === $method && $mandate->isValid()) {
return true;
}
}
return false;
} | php | public function hasValidMandateForMethod($method)
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->method === $method && $mandate->isValid()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasValidMandateForMethod",
"(",
"$",
"method",
")",
"{",
"$",
"mandates",
"=",
"$",
"this",
"->",
"mandates",
"(",
")",
";",
"foreach",
"(",
"$",
"mandates",
"as",
"$",
"mandate",
")",
"{",
"if",
"(",
"$",
"mandate",
"->",
"method",
"===",
"$",
"method",
"&&",
"$",
"mandate",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Helper function to check for specific payment method mandate with status valid
@return bool | [
"Helper",
"function",
"to",
"check",
"for",
"specific",
"payment",
"method",
"mandate",
"with",
"status",
"valid"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L211-L221 | train |
mollie/mollie-api-php | src/Resources/Customer.php | Customer.getPresetOptions | private function getPresetOptions()
{
$options = [];
if($this->client->usesOAuth()) {
$options["testmode"] = $this->mode === "test" ? true : false;
}
return $options;
} | php | private function getPresetOptions()
{
$options = [];
if($this->client->usesOAuth()) {
$options["testmode"] = $this->mode === "test" ? true : false;
}
return $options;
} | [
"private",
"function",
"getPresetOptions",
"(",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"client",
"->",
"usesOAuth",
"(",
")",
")",
"{",
"$",
"options",
"[",
"\"testmode\"",
"]",
"=",
"$",
"this",
"->",
"mode",
"===",
"\"test\"",
"?",
"true",
":",
"false",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | When accessed by oAuth we want to pass the testmode by default
@return array | [
"When",
"accessed",
"by",
"oAuth",
"we",
"want",
"to",
"pass",
"the",
"testmode",
"by",
"default"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Customer.php#L228-L236 | train |
mollie/mollie-api-php | src/Endpoints/ShipmentEndpoint.php | ShipmentEndpoint.listForId | public function listForId($orderId, array $parameters = [])
{
$this->parentId = $orderId;
return parent::rest_list(null, null, $parameters);
} | php | public function listForId($orderId, array $parameters = [])
{
$this->parentId = $orderId;
return parent::rest_list(null, null, $parameters);
} | [
"public",
"function",
"listForId",
"(",
"$",
"orderId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"parentId",
"=",
"$",
"orderId",
";",
"return",
"parent",
"::",
"rest_list",
"(",
"null",
",",
"null",
",",
"$",
"parameters",
")",
";",
"}"
] | Return all shipments for the provided Order id.
@param string $orderId
@param array $parameters
@return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\ShipmentCollection
@throws \Mollie\Api\Exceptions\ApiException | [
"Return",
"all",
"shipments",
"for",
"the",
"provided",
"Order",
"id",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ShipmentEndpoint.php#L131-L136 | train |
mollie/mollie-api-php | src/Resources/Profile.php | Profile.chargebacks | public function chargebacks()
{
if (!isset($this->_links->chargebacks->href)) {
return new ChargebackCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->chargebacks,
Chargeback::class,
$result->_links
);
} | php | public function chargebacks()
{
if (!isset($this->_links->chargebacks->href)) {
return new ChargebackCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->chargebacks,
Chargeback::class,
$result->_links
);
} | [
"public",
"function",
"chargebacks",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"chargebacks",
"->",
"href",
")",
")",
"{",
"return",
"new",
"ChargebackCollection",
"(",
"$",
"this",
"->",
"client",
",",
"0",
",",
"null",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_GET",
",",
"$",
"this",
"->",
"_links",
"->",
"chargebacks",
"->",
"href",
")",
";",
"return",
"ResourceFactory",
"::",
"createCursorResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"_embedded",
"->",
"chargebacks",
",",
"Chargeback",
"::",
"class",
",",
"$",
"result",
"->",
"_links",
")",
";",
"}"
] | Retrieves all chargebacks associated with this profile
@return ChargebackCollection
@throws ApiException | [
"Retrieves",
"all",
"chargebacks",
"associated",
"with",
"this",
"profile"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Profile.php#L132-L146 | train |
mollie/mollie-api-php | src/Resources/Profile.php | Profile.methods | public function methods()
{
if (!isset($this->_links->methods->href)) {
return new MethodCollection(0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->methods->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->methods,
Method::class,
$result->_links
);
} | php | public function methods()
{
if (!isset($this->_links->methods->href)) {
return new MethodCollection(0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->methods->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->methods,
Method::class,
$result->_links
);
} | [
"public",
"function",
"methods",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"methods",
"->",
"href",
")",
")",
"{",
"return",
"new",
"MethodCollection",
"(",
"0",
",",
"null",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_GET",
",",
"$",
"this",
"->",
"_links",
"->",
"methods",
"->",
"href",
")",
";",
"return",
"ResourceFactory",
"::",
"createCursorResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"_embedded",
"->",
"methods",
",",
"Method",
"::",
"class",
",",
"$",
"result",
"->",
"_links",
")",
";",
"}"
] | Retrieves all methods activated on this profile
@return MethodCollection
@throws ApiException | [
"Retrieves",
"all",
"methods",
"activated",
"on",
"this",
"profile"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Profile.php#L154-L168 | train |
mollie/mollie-api-php | src/Resources/Profile.php | Profile.enableMethod | public function enableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->createFor($this, $methodId, $data);
} | php | public function enableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->createFor($this, $methodId, $data);
} | [
"public",
"function",
"enableMethod",
"(",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"profileMethods",
"->",
"createFor",
"(",
"$",
"this",
",",
"$",
"methodId",
",",
"$",
"data",
")",
";",
"}"
] | Enable a payment method for this profile.
@param string $methodId
@param array $data
@return Method
@throws ApiException | [
"Enable",
"a",
"payment",
"method",
"for",
"this",
"profile",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Profile.php#L178-L181 | train |
mollie/mollie-api-php | src/Resources/Profile.php | Profile.disableMethod | public function disableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->deleteFor($this, $methodId, $data);
} | php | public function disableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->deleteFor($this, $methodId, $data);
} | [
"public",
"function",
"disableMethod",
"(",
"$",
"methodId",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"profileMethods",
"->",
"deleteFor",
"(",
"$",
"this",
",",
"$",
"methodId",
",",
"$",
"data",
")",
";",
"}"
] | Disable a payment method for this profile.
@param string $methodId
@param array $data
@return Method
@throws ApiException | [
"Disable",
"a",
"payment",
"method",
"for",
"this",
"profile",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Profile.php#L191-L194 | train |
mollie/mollie-api-php | src/Resources/Profile.php | Profile.refunds | public function refunds()
{
if (!isset($this->_links->refunds->href)) {
return new RefundCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->refunds,
Refund::class,
$result->_links
);
} | php | public function refunds()
{
if (!isset($this->_links->refunds->href)) {
return new RefundCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->refunds,
Refund::class,
$result->_links
);
} | [
"public",
"function",
"refunds",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"refunds",
"->",
"href",
")",
")",
"{",
"return",
"new",
"RefundCollection",
"(",
"$",
"this",
"->",
"client",
",",
"0",
",",
"null",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_GET",
",",
"$",
"this",
"->",
"_links",
"->",
"refunds",
"->",
"href",
")",
";",
"return",
"ResourceFactory",
"::",
"createCursorResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"_embedded",
"->",
"refunds",
",",
"Refund",
"::",
"class",
",",
"$",
"result",
"->",
"_links",
")",
";",
"}"
] | Retrieves all refunds associated with this profile
@return RefundCollection
@throws ApiException | [
"Retrieves",
"all",
"refunds",
"associated",
"with",
"this",
"profile"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Profile.php#L224-L238 | train |
mollie/mollie-api-php | src/Resources/Payment.php | Payment.getCheckoutUrl | public function getCheckoutUrl()
{
if (empty($this->_links->checkout)) {
return null;
}
return $this->_links->checkout->href;
} | php | public function getCheckoutUrl()
{
if (empty($this->_links->checkout)) {
return null;
}
return $this->_links->checkout->href;
} | [
"public",
"function",
"getCheckoutUrl",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_links",
"->",
"checkout",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"_links",
"->",
"checkout",
"->",
"href",
";",
"}"
] | Get the checkout URL where the customer can complete the payment.
@return string|null | [
"Get",
"the",
"checkout",
"URL",
"where",
"the",
"customer",
"can",
"complete",
"the",
"payment",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Payment.php#L348-L355 | train |
mollie/mollie-api-php | src/Resources/Payment.php | Payment.captures | public function captures()
{
if (!isset($this->_links->captures->href)) {
return new CaptureCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_GET,
$this->_links->captures->href
);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->captures,
Capture::class,
$result->_links
);
} | php | public function captures()
{
if (!isset($this->_links->captures->href)) {
return new CaptureCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_GET,
$this->_links->captures->href
);
return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->captures,
Capture::class,
$result->_links
);
} | [
"public",
"function",
"captures",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"captures",
"->",
"href",
")",
")",
"{",
"return",
"new",
"CaptureCollection",
"(",
"$",
"this",
"->",
"client",
",",
"0",
",",
"null",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_GET",
",",
"$",
"this",
"->",
"_links",
"->",
"captures",
"->",
"href",
")",
";",
"return",
"ResourceFactory",
"::",
"createCursorResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"_embedded",
"->",
"captures",
",",
"Capture",
"::",
"class",
",",
"$",
"result",
"->",
"_links",
")",
";",
"}"
] | Retrieves all captures associated with this payment
@return CaptureCollection
@throws ApiException | [
"Retrieves",
"all",
"captures",
"associated",
"with",
"this",
"payment"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Payment.php#L445-L462 | train |
mollie/mollie-api-php | src/Resources/Payment.php | Payment.getChargeback | public function getChargeback($chargebackId, array $parameters = [])
{
return $this->client->paymentChargebacks->getFor(
$this,
$chargebackId,
$parameters
);
} | php | public function getChargeback($chargebackId, array $parameters = [])
{
return $this->client->paymentChargebacks->getFor(
$this,
$chargebackId,
$parameters
);
} | [
"public",
"function",
"getChargeback",
"(",
"$",
"chargebackId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"paymentChargebacks",
"->",
"getFor",
"(",
"$",
"this",
",",
"$",
"chargebackId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieves a specific chargeback for this payment.
@param string $chargebackId
@param array $parameters
@return Chargeback | [
"Retrieves",
"a",
"specific",
"chargeback",
"for",
"this",
"payment",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Payment.php#L512-L519 | train |
mollie/mollie-api-php | src/Resources/Payment.php | Payment.refund | public function refund($data = [])
{
$resource = "payments/" . urlencode($this->id) . "/refunds";
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(
MollieApiClient::HTTP_POST,
$resource,
$body
);
return ResourceFactory::createFromApiResult(
$result,
new Refund($this->client)
);
} | php | public function refund($data = [])
{
$resource = "payments/" . urlencode($this->id) . "/refunds";
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(
MollieApiClient::HTTP_POST,
$resource,
$body
);
return ResourceFactory::createFromApiResult(
$result,
new Refund($this->client)
);
} | [
"public",
"function",
"refund",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"resource",
"=",
"\"payments/\"",
".",
"urlencode",
"(",
"$",
"this",
"->",
"id",
")",
".",
"\"/refunds\"",
";",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"MollieApiClient",
"::",
"HTTP_POST",
",",
"$",
"resource",
",",
"$",
"body",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"new",
"Refund",
"(",
"$",
"this",
"->",
"client",
")",
")",
";",
"}"
] | Issue a refund for this payment.
The $data parameter may either be an array of endpoint parameters or empty to
do a full refund.
@param array|null $data
@return BaseResource
@throws ApiException | [
"Issue",
"a",
"refund",
"for",
"this",
"payment",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Payment.php#L532-L551 | train |
mollie/mollie-api-php | src/Endpoints/PaymentEndpoint.php | PaymentEndpoint.get | public function get($paymentId, array $parameters = [])
{
if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '".self::RESOURCE_ID_PREFIX."'.");
}
return parent::rest_read($paymentId, $parameters);
} | php | public function get($paymentId, array $parameters = [])
{
if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '".self::RESOURCE_ID_PREFIX."'.");
}
return parent::rest_read($paymentId, $parameters);
} | [
"public",
"function",
"get",
"(",
"$",
"paymentId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"paymentId",
")",
"||",
"strpos",
"(",
"$",
"paymentId",
",",
"self",
"::",
"RESOURCE_ID_PREFIX",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Invalid payment ID: '{$paymentId}'. A payment ID should start with '\"",
".",
"self",
"::",
"RESOURCE_ID_PREFIX",
".",
"\"'.\"",
")",
";",
"}",
"return",
"parent",
"::",
"rest_read",
"(",
"$",
"paymentId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve a single payment from Mollie.
Will throw a ApiException if the payment id is invalid or the resource cannot be found.
@param string $paymentId
@param array $parameters
@return Payment
@throws ApiException | [
"Retrieve",
"a",
"single",
"payment",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/PaymentEndpoint.php#L65-L72 | train |
mollie/mollie-api-php | src/Endpoints/PaymentEndpoint.php | PaymentEndpoint.page | public function page($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
} | php | public function page($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
} | [
"public",
"function",
"page",
"(",
"$",
"from",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"rest_list",
"(",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieves a collection of Payments from Mollie.
@param string $from The first payment ID you want to include in your list.
@param int $limit
@param array $parameters
@return PaymentCollection
@throws ApiException | [
"Retrieves",
"a",
"collection",
"of",
"Payments",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/PaymentEndpoint.php#L118-L121 | train |
mollie/mollie-api-php | src/Endpoints/PaymentEndpoint.php | PaymentEndpoint.refund | public function refund(Payment $payment, $data = [])
{
$resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds";
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Refund($this->client));
} | php | public function refund(Payment $payment, $data = [])
{
$resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds";
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Refund($this->client));
} | [
"public",
"function",
"refund",
"(",
"Payment",
"$",
"payment",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"resource",
"=",
"\"{$this->getResourcePath()}/\"",
".",
"urlencode",
"(",
"$",
"payment",
"->",
"id",
")",
".",
"\"/refunds\"",
";",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_CREATE",
",",
"$",
"resource",
",",
"$",
"body",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"new",
"Refund",
"(",
"$",
"this",
"->",
"client",
")",
")",
";",
"}"
] | Issue a refund for the given payment.
The $data parameter may either be an array of endpoint parameters, a float value to
initiate a partial refund, or empty to do a full refund.
@param Payment $payment
@param array|float|null $data
@return Refund
@throws ApiException | [
"Issue",
"a",
"refund",
"for",
"the",
"given",
"payment",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/PaymentEndpoint.php#L135-L147 | train |
mollie/mollie-api-php | src/Resources/ResourceFactory.php | ResourceFactory.createFromApiResult | public static function createFromApiResult($apiResult, BaseResource $resource)
{
foreach ($apiResult as $property => $value) {
$resource->{$property} = $value;
}
return $resource;
} | php | public static function createFromApiResult($apiResult, BaseResource $resource)
{
foreach ($apiResult as $property => $value) {
$resource->{$property} = $value;
}
return $resource;
} | [
"public",
"static",
"function",
"createFromApiResult",
"(",
"$",
"apiResult",
",",
"BaseResource",
"$",
"resource",
")",
"{",
"foreach",
"(",
"$",
"apiResult",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"resource",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"resource",
";",
"}"
] | Create resource object from Api result
@param object $apiResult
@param BaseResource $resource
@return BaseResource | [
"Create",
"resource",
"object",
"from",
"Api",
"result"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/ResourceFactory.php#L17-L24 | train |
mollie/mollie-api-php | src/Resources/Mandate.php | Mandate.revoke | public function revoke()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = null;
if($this->client->usesOAuth()) {
$body = json_encode([
"testmode" => $this->mode === "test" ? true : false
]);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href,
$body
);
return $result;
} | php | public function revoke()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = null;
if($this->client->usesOAuth()) {
$body = json_encode([
"testmode" => $this->mode === "test" ? true : false
]);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href,
$body
);
return $result;
} | [
"public",
"function",
"revoke",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"client",
"->",
"usesOAuth",
"(",
")",
")",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"[",
"\"testmode\"",
"=>",
"$",
"this",
"->",
"mode",
"===",
"\"test\"",
"?",
"true",
":",
"false",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_DELETE",
",",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
",",
"$",
"body",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Revoke the mandate
@return null | [
"Revoke",
"the",
"mandate"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Mandate.php#L96-L116 | train |
mollie/mollie-api-php | src/Endpoints/MethodEndpoint.php | MethodEndpoint.allAvailable | public function allAvailable(array $parameters = [])
{
$url = 'methods/all' . $this->buildQueryString($parameters);
$result = $this->client->performHttpCall('GET', $url);
return ResourceFactory::createBaseResourceCollection(
$this->client,
$result->_embedded->methods,
Method::class,
$result->_links
);
} | php | public function allAvailable(array $parameters = [])
{
$url = 'methods/all' . $this->buildQueryString($parameters);
$result = $this->client->performHttpCall('GET', $url);
return ResourceFactory::createBaseResourceCollection(
$this->client,
$result->_embedded->methods,
Method::class,
$result->_links
);
} | [
"public",
"function",
"allAvailable",
"(",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"'methods/all'",
".",
"$",
"this",
"->",
"buildQueryString",
"(",
"$",
"parameters",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"'GET'",
",",
"$",
"url",
")",
";",
"return",
"ResourceFactory",
"::",
"createBaseResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"_embedded",
"->",
"methods",
",",
"Method",
"::",
"class",
",",
"$",
"result",
"->",
"_links",
")",
";",
"}"
] | Retrieve all available methods for the organization, including activated and not yet activated methods. The
results are not paginated. Make sure to include the profileId parameter if using an OAuth Access Token.
@param array $parameters Query string parameters.
@return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection
@throws \Mollie\Api\Exceptions\ApiException | [
"Retrieve",
"all",
"available",
"methods",
"for",
"the",
"organization",
"including",
"activated",
"and",
"not",
"yet",
"activated",
"methods",
".",
"The",
"results",
"are",
"not",
"paginated",
".",
"Make",
"sure",
"to",
"include",
"the",
"profileId",
"parameter",
"if",
"using",
"an",
"OAuth",
"Access",
"Token",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/MethodEndpoint.php#L58-L70 | train |
mollie/mollie-api-php | src/Endpoints/MethodEndpoint.php | MethodEndpoint.get | public function get($methodId, array $parameters = [])
{
if (empty($methodId)) {
throw new ApiException("Method ID is empty.");
}
return parent::rest_read($methodId, $parameters);
} | php | public function get($methodId, array $parameters = [])
{
if (empty($methodId)) {
throw new ApiException("Method ID is empty.");
}
return parent::rest_read($methodId, $parameters);
} | [
"public",
"function",
"get",
"(",
"$",
"methodId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"methodId",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Method ID is empty.\"",
")",
";",
"}",
"return",
"parent",
"::",
"rest_read",
"(",
"$",
"methodId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve a payment method from Mollie.
Will throw a ApiException if the method id is invalid or the resource cannot be found.
@param string $methodId
@param array $parameters
@return \Mollie\Api\Resources\BaseResource|\Mollie\Api\Resources\Method
@throws ApiException | [
"Retrieve",
"a",
"payment",
"method",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/MethodEndpoint.php#L95-L102 | train |
mollie/mollie-api-php | src/Endpoints/OrganizationEndpoint.php | OrganizationEndpoint.get | public function get($organizationId, array $parameters = [])
{
if (empty($organizationId)) {
throw new ApiException("Organization ID is empty.");
}
return parent::rest_read($organizationId, $parameters);
} | php | public function get($organizationId, array $parameters = [])
{
if (empty($organizationId)) {
throw new ApiException("Organization ID is empty.");
}
return parent::rest_read($organizationId, $parameters);
} | [
"public",
"function",
"get",
"(",
"$",
"organizationId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"organizationId",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Organization ID is empty.\"",
")",
";",
"}",
"return",
"parent",
"::",
"rest_read",
"(",
"$",
"organizationId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve an organization from Mollie.
Will throw a ApiException if the organization id is invalid or the resource cannot be found.
@param string $organizationId
@param array $parameters
@return Method
@throws ApiException | [
"Retrieve",
"an",
"organization",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/OrganizationEndpoint.php#L45-L52 | train |
mollie/mollie-api-php | src/Endpoints/EndpointAbstract.php | EndpointAbstract.rest_read | protected function rest_read($id, array $filters)
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_READ,
"{$this->getResourcePath()}/{$id}" . $this->buildQueryString($filters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
} | php | protected function rest_read($id, array $filters)
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_READ,
"{$this->getResourcePath()}/{$id}" . $this->buildQueryString($filters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
} | [
"protected",
"function",
"rest_read",
"(",
"$",
"id",
",",
"array",
"$",
"filters",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Invalid resource id.\"",
")",
";",
"}",
"$",
"id",
"=",
"urlencode",
"(",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_READ",
",",
"\"{$this->getResourcePath()}/{$id}\"",
".",
"$",
"this",
"->",
"buildQueryString",
"(",
"$",
"filters",
")",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getResourceObject",
"(",
")",
")",
";",
"}"
] | Retrieves a single object from the REST API.
@param string $id Id of the object to retrieve.
@param array $filters
@return BaseResource
@throws ApiException | [
"Retrieves",
"a",
"single",
"object",
"from",
"the",
"REST",
"API",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/EndpointAbstract.php#L90-L103 | train |
mollie/mollie-api-php | src/Endpoints/EndpointAbstract.php | EndpointAbstract.rest_delete | protected function rest_delete($id, array $body = [])
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}/{$id}",
$this->parseRequestBody($body)
);
if ($result === null) {
return null;
}
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
} | php | protected function rest_delete($id, array $body = [])
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}/{$id}",
$this->parseRequestBody($body)
);
if ($result === null) {
return null;
}
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
} | [
"protected",
"function",
"rest_delete",
"(",
"$",
"id",
",",
"array",
"$",
"body",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Invalid resource id.\"",
")",
";",
"}",
"$",
"id",
"=",
"urlencode",
"(",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_DELETE",
",",
"\"{$this->getResourcePath()}/{$id}\"",
",",
"$",
"this",
"->",
"parseRequestBody",
"(",
"$",
"body",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"getResourceObject",
"(",
")",
")",
";",
"}"
] | Sends a DELETE request to a single Molle API object.
@param string $id
@param array $body
@return BaseResource
@throws ApiException | [
"Sends",
"a",
"DELETE",
"request",
"to",
"a",
"single",
"Molle",
"API",
"object",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/EndpointAbstract.php#L114-L132 | train |
mollie/mollie-api-php | src/Endpoints/EndpointAbstract.php | EndpointAbstract.rest_list | protected function rest_list($from = null, $limit = null, array $filters)
{
$filters = array_merge(["from" => $from, "limit" => $limit], $filters);
$apiPath = $this->getResourcePath() . $this->buildQueryString($filters);
$result = $this->client->performHttpCall(self::REST_LIST, $apiPath);
/** @var BaseCollection $collection */
$collection = $this->getResourceCollectionObject($result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
return $collection;
} | php | protected function rest_list($from = null, $limit = null, array $filters)
{
$filters = array_merge(["from" => $from, "limit" => $limit], $filters);
$apiPath = $this->getResourcePath() . $this->buildQueryString($filters);
$result = $this->client->performHttpCall(self::REST_LIST, $apiPath);
/** @var BaseCollection $collection */
$collection = $this->getResourceCollectionObject($result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
return $collection;
} | [
"protected",
"function",
"rest_list",
"(",
"$",
"from",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"array",
"$",
"filters",
")",
"{",
"$",
"filters",
"=",
"array_merge",
"(",
"[",
"\"from\"",
"=>",
"$",
"from",
",",
"\"limit\"",
"=>",
"$",
"limit",
"]",
",",
"$",
"filters",
")",
";",
"$",
"apiPath",
"=",
"$",
"this",
"->",
"getResourcePath",
"(",
")",
".",
"$",
"this",
"->",
"buildQueryString",
"(",
"$",
"filters",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_LIST",
",",
"$",
"apiPath",
")",
";",
"/** @var BaseCollection $collection */",
"$",
"collection",
"=",
"$",
"this",
"->",
"getResourceCollectionObject",
"(",
"$",
"result",
"->",
"count",
",",
"$",
"result",
"->",
"_links",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"_embedded",
"->",
"{",
"$",
"collection",
"->",
"getCollectionResourceName",
"(",
")",
"}",
"as",
"$",
"dataResult",
")",
"{",
"$",
"collection",
"[",
"]",
"=",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"dataResult",
",",
"$",
"this",
"->",
"getResourceObject",
"(",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Get a collection of objects from the REST API.
@param string $from The first resource ID you want to include in your list.
@param int $limit
@param array $filters
@return BaseCollection
@throws ApiException | [
"Get",
"a",
"collection",
"of",
"objects",
"from",
"the",
"REST",
"API",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/EndpointAbstract.php#L144-L160 | train |
mollie/mollie-api-php | src/Resources/CursorCollection.php | CursorCollection.next | final public function next()
{
if (!$this->hasNext()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->next->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject());
}
return $collection;
} | php | final public function next()
{
if (!$this->hasNext()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->next->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject());
}
return $collection;
} | [
"final",
"public",
"function",
"next",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasNext",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_GET",
",",
"$",
"this",
"->",
"_links",
"->",
"next",
"->",
"href",
")",
";",
"$",
"collection",
"=",
"new",
"static",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"result",
"->",
"count",
",",
"$",
"result",
"->",
"_links",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"_embedded",
"->",
"{",
"$",
"collection",
"->",
"getCollectionResourceName",
"(",
")",
"}",
"as",
"$",
"dataResult",
")",
"{",
"$",
"collection",
"[",
"]",
"=",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"dataResult",
",",
"$",
"this",
"->",
"createResourceObject",
"(",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Return the next set of resources when available
@return CursorCollection|null
@throws \Mollie\Api\Exceptions\ApiException | [
"Return",
"the",
"next",
"set",
"of",
"resources",
"when",
"available"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/CursorCollection.php#L37-L52 | train |
mollie/mollie-api-php | src/Endpoints/ProfileEndpoint.php | ProfileEndpoint.get | public function get($profileId, array $parameters = [])
{
if($profileId === 'me') {
return $this->getCurrent($parameters);
}
return $this->rest_read($profileId, $parameters);
} | php | public function get($profileId, array $parameters = [])
{
if($profileId === 'me') {
return $this->getCurrent($parameters);
}
return $this->rest_read($profileId, $parameters);
} | [
"public",
"function",
"get",
"(",
"$",
"profileId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"profileId",
"===",
"'me'",
")",
"{",
"return",
"$",
"this",
"->",
"getCurrent",
"(",
"$",
"parameters",
")",
";",
"}",
"return",
"$",
"this",
"->",
"rest_read",
"(",
"$",
"profileId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve a Profile from Mollie.
Will throw an ApiException if the profile id is invalid or the resource cannot be found.
@param string $profileId
@param array $parameters
@return \Mollie\Api\Resources\BaseResource|\Mollie\Api\Resources\Profile
@throws ApiException | [
"Retrieve",
"a",
"Profile",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/ProfileEndpoint.php#L63-L70 | train |
mollie/mollie-api-php | src/Resources/OrderLineCollection.php | OrderLineCollection.get | public function get($lineId)
{
foreach ($this as $line) {
if ($line->id === $lineId) {
return $line;
}
}
return null;
} | php | public function get($lineId)
{
foreach ($this as $line) {
if ($line->id === $lineId) {
return $line;
}
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"lineId",
")",
"{",
"foreach",
"(",
"$",
"this",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"line",
"->",
"id",
"===",
"$",
"lineId",
")",
"{",
"return",
"$",
"line",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get a specific order line.
Returns null if the order line cannot be found.
@param string $lineId
@return OrderLine|null | [
"Get",
"a",
"specific",
"order",
"line",
".",
"Returns",
"null",
"if",
"the",
"order",
"line",
"cannot",
"be",
"found",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/OrderLineCollection.php#L22-L30 | train |
mollie/mollie-api-php | src/Resources/Subscription.php | Subscription.cancel | public function cancel()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = null;
if($this->client->usesOAuth()) {
$body = json_encode([
"testmode" => $this->mode === "test" ? true : false
]);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href,
$body
);
return ResourceFactory::createFromApiResult($result, new Subscription($this->client));
} | php | public function cancel()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = null;
if($this->client->usesOAuth()) {
$body = json_encode([
"testmode" => $this->mode === "test" ? true : false
]);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href,
$body
);
return ResourceFactory::createFromApiResult($result, new Subscription($this->client));
} | [
"public",
"function",
"cancel",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"body",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"client",
"->",
"usesOAuth",
"(",
")",
")",
"{",
"$",
"body",
"=",
"json_encode",
"(",
"[",
"\"testmode\"",
"=>",
"$",
"this",
"->",
"mode",
"===",
"\"test\"",
"?",
"true",
":",
"false",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_DELETE",
",",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
",",
"$",
"body",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"new",
"Subscription",
"(",
"$",
"this",
"->",
"client",
")",
")",
";",
"}"
] | Cancels this subscription
@return Subscription | [
"Cancels",
"this",
"subscription"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Subscription.php#L184-L204 | train |
mollie/mollie-api-php | src/Resources/Order.php | Order.getShipment | public function getShipment($shipmentId, array $parameters = [])
{
return $this->client->shipments->getFor($this, $shipmentId, $parameters);
} | php | public function getShipment($shipmentId, array $parameters = [])
{
return $this->client->shipments->getFor($this, $shipmentId, $parameters);
} | [
"public",
"function",
"getShipment",
"(",
"$",
"shipmentId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"shipments",
"->",
"getFor",
"(",
"$",
"this",
",",
"$",
"shipmentId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve a specific shipment for this order.
@param string $shipmentId
@param array $parameters
@return Shipment | [
"Retrieve",
"a",
"specific",
"shipment",
"for",
"this",
"order",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Order.php#L340-L343 | train |
mollie/mollie-api-php | src/Resources/Order.php | Order.createPayment | public function createPayment($data, $filters = [])
{
return $this->client->orderPayments->createFor($this, $data, $filters);
} | php | public function createPayment($data, $filters = [])
{
return $this->client->orderPayments->createFor($this, $data, $filters);
} | [
"public",
"function",
"createPayment",
"(",
"$",
"data",
",",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"orderPayments",
"->",
"createFor",
"(",
"$",
"this",
",",
"$",
"data",
",",
"$",
"filters",
")",
";",
"}"
] | Create a new payment for this Order.
@param $data
@param array $filters
@return \Mollie\Api\Resources\BaseResource|\Mollie\Api\Resources\Payment
@throws \Mollie\Api\Exceptions\ApiException | [
"Create",
"a",
"new",
"payment",
"for",
"this",
"Order",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Order.php#L446-L449 | train |
mollie/mollie-api-php | src/Resources/Order.php | Order.payments | public function payments()
{
if(! isset($this->_embedded, $this->_embedded->payments) ) {
return null;
}
return ResourceFactory::createCursorResourceCollection(
$this->client,
$this->_embedded->payments,
Payment::class
);
} | php | public function payments()
{
if(! isset($this->_embedded, $this->_embedded->payments) ) {
return null;
}
return ResourceFactory::createCursorResourceCollection(
$this->client,
$this->_embedded->payments,
Payment::class
);
} | [
"public",
"function",
"payments",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_embedded",
",",
"$",
"this",
"->",
"_embedded",
"->",
"payments",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"ResourceFactory",
"::",
"createCursorResourceCollection",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"this",
"->",
"_embedded",
"->",
"payments",
",",
"Payment",
"::",
"class",
")",
";",
"}"
] | Retrieve the payments for this order.
Requires the order to be retrieved using the embed payments parameter.
@return null|\Mollie\Api\Resources\PaymentCollection | [
"Retrieve",
"the",
"payments",
"for",
"this",
"order",
".",
"Requires",
"the",
"order",
"to",
"be",
"retrieved",
"using",
"the",
"embed",
"payments",
"parameter",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Order.php#L457-L468 | train |
mollie/mollie-api-php | src/Endpoints/OrderLineEndpoint.php | OrderLineEndpoint.cancelForId | public function cancelForId($orderId, array $data)
{
if(! isset($data, $data['lines']) || ! is_array($data['lines'])) {
throw new ApiException("A lines array is required.");
}
$this->parentId = $orderId;
$this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}",
$this->parseRequestBody($data)
);
return null;
} | php | public function cancelForId($orderId, array $data)
{
if(! isset($data, $data['lines']) || ! is_array($data['lines'])) {
throw new ApiException("A lines array is required.");
}
$this->parentId = $orderId;
$this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}",
$this->parseRequestBody($data)
);
return null;
} | [
"public",
"function",
"cancelForId",
"(",
"$",
"orderId",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
",",
"$",
"data",
"[",
"'lines'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'lines'",
"]",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"A lines array is required.\"",
")",
";",
"}",
"$",
"this",
"->",
"parentId",
"=",
"$",
"orderId",
";",
"$",
"this",
"->",
"client",
"->",
"performHttpCall",
"(",
"self",
"::",
"REST_DELETE",
",",
"\"{$this->getResourcePath()}\"",
",",
"$",
"this",
"->",
"parseRequestBody",
"(",
"$",
"data",
")",
")",
";",
"return",
"null",
";",
"}"
] | Cancel lines for the provided order id.
The data array must contain a lines array.
You can pass an empty lines array if you want to cancel all eligible lines.
Returns null if successful.
@param string $orderId
@param array $data
@return null
@throws ApiException | [
"Cancel",
"lines",
"for",
"the",
"provided",
"order",
"id",
".",
"The",
"data",
"array",
"must",
"contain",
"a",
"lines",
"array",
".",
"You",
"can",
"pass",
"an",
"empty",
"lines",
"array",
"if",
"you",
"want",
"to",
"cancel",
"all",
"eligible",
"lines",
".",
"Returns",
"null",
"if",
"successful",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/OrderLineEndpoint.php#L74-L88 | train |
mollie/mollie-api-php | src/Resources/Shipment.php | Shipment.update | public function update()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = json_encode([
"tracking" => $this->tracking,
]);
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_PATCH,
$this->_links->self->href,
$body
);
return ResourceFactory::createFromApiResult($result, new Shipment($this->client));
} | php | public function update()
{
if (!isset($this->_links->self->href)) {
return $this;
}
$body = json_encode([
"tracking" => $this->tracking,
]);
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_PATCH,
$this->_links->self->href,
$body
);
return ResourceFactory::createFromApiResult($result, new Shipment($this->client));
} | [
"public",
"function",
"update",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"body",
"=",
"json_encode",
"(",
"[",
"\"tracking\"",
"=>",
"$",
"this",
"->",
"tracking",
",",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_PATCH",
",",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
",",
"$",
"body",
")",
";",
"return",
"ResourceFactory",
"::",
"createFromApiResult",
"(",
"$",
"result",
",",
"new",
"Shipment",
"(",
"$",
"this",
"->",
"client",
")",
")",
";",
"}"
] | Save changes made to this shipment.
@return BaseResource|Shipment
@throws \Mollie\Api\Exceptions\ApiException | [
"Save",
"changes",
"made",
"to",
"this",
"shipment",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Shipment.php#L117-L134 | train |
mollie/mollie-api-php | src/Resources/Refund.php | Refund.cancel | public function cancel()
{
$this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href
);
return null;
} | php | public function cancel()
{
$this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href
);
return null;
} | [
"public",
"function",
"cancel",
"(",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"performHttpCallToFullUrl",
"(",
"MollieApiClient",
"::",
"HTTP_DELETE",
",",
"$",
"this",
"->",
"_links",
"->",
"self",
"->",
"href",
")",
";",
"return",
"null",
";",
"}"
] | Cancel the refund.
Returns null if successful.
@return null
@throws \Mollie\Api\Exceptions\ApiException | [
"Cancel",
"the",
"refund",
".",
"Returns",
"null",
"if",
"successful",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Resources/Refund.php#L133-L141 | train |
mollie/mollie-api-php | src/MollieApiClient.php | MollieApiClient.performHttpCallToFullUrl | public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null)
{
if (empty($this->apiKey)) {
throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.");
}
$userAgent = implode(' ', $this->versionStrings);
if ($this->usesOAuth()) {
$userAgent .= " OAuth/2.0";
}
$headers = [
'Accept' => "application/json",
'Authorization' => "Bearer {$this->apiKey}",
'User-Agent' => $userAgent,
];
if (function_exists("php_uname")) {
$headers['X-Mollie-Client-Info'] = php_uname();
}
$request = new Request($httpMethod, $url, $headers, $httpBody);
try {
$response = $this->httpClient->send($request, ['http_errors' => false]);
} catch (GuzzleException $e) {
throw ApiException::createFromGuzzleException($e);
}
if (!$response) {
throw new ApiException("Did not receive API response.");
}
return $this->parseResponseBody($response);
} | php | public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null)
{
if (empty($this->apiKey)) {
throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.");
}
$userAgent = implode(' ', $this->versionStrings);
if ($this->usesOAuth()) {
$userAgent .= " OAuth/2.0";
}
$headers = [
'Accept' => "application/json",
'Authorization' => "Bearer {$this->apiKey}",
'User-Agent' => $userAgent,
];
if (function_exists("php_uname")) {
$headers['X-Mollie-Client-Info'] = php_uname();
}
$request = new Request($httpMethod, $url, $headers, $httpBody);
try {
$response = $this->httpClient->send($request, ['http_errors' => false]);
} catch (GuzzleException $e) {
throw ApiException::createFromGuzzleException($e);
}
if (!$response) {
throw new ApiException("Did not receive API response.");
}
return $this->parseResponseBody($response);
} | [
"public",
"function",
"performHttpCallToFullUrl",
"(",
"$",
"httpMethod",
",",
"$",
"url",
",",
"$",
"httpBody",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"apiKey",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.\"",
")",
";",
"}",
"$",
"userAgent",
"=",
"implode",
"(",
"' '",
",",
"$",
"this",
"->",
"versionStrings",
")",
";",
"if",
"(",
"$",
"this",
"->",
"usesOAuth",
"(",
")",
")",
"{",
"$",
"userAgent",
".=",
"\" OAuth/2.0\"",
";",
"}",
"$",
"headers",
"=",
"[",
"'Accept'",
"=>",
"\"application/json\"",
",",
"'Authorization'",
"=>",
"\"Bearer {$this->apiKey}\"",
",",
"'User-Agent'",
"=>",
"$",
"userAgent",
",",
"]",
";",
"if",
"(",
"function_exists",
"(",
"\"php_uname\"",
")",
")",
"{",
"$",
"headers",
"[",
"'X-Mollie-Client-Info'",
"]",
"=",
"php_uname",
"(",
")",
";",
"}",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"httpMethod",
",",
"$",
"url",
",",
"$",
"headers",
",",
"$",
"httpBody",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"send",
"(",
"$",
"request",
",",
"[",
"'http_errors'",
"=>",
"false",
"]",
")",
";",
"}",
"catch",
"(",
"GuzzleException",
"$",
"e",
")",
"{",
"throw",
"ApiException",
"::",
"createFromGuzzleException",
"(",
"$",
"e",
")",
";",
"}",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Did not receive API response.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseResponseBody",
"(",
"$",
"response",
")",
";",
"}"
] | Perform an http call to a full url. This method is used by the resource specific classes.
@see $payments
@see $isuers
@param string $httpMethod
@param string $url
@param string|null|resource|StreamInterface $httpBody
@return object|null
@throws ApiException
@codeCoverageIgnore | [
"Perform",
"an",
"http",
"call",
"to",
"a",
"full",
"url",
".",
"This",
"method",
"is",
"used",
"by",
"the",
"resource",
"specific",
"classes",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/MollieApiClient.php#L422-L457 | train |
mollie/mollie-api-php | src/MollieApiClient.php | MollieApiClient.parseResponseBody | private function parseResponseBody(ResponseInterface $response)
{
$body = (string) $response->getBody();
if (empty($body)) {
if ($response->getStatusCode() === self::HTTP_NO_CONTENT) {
return null;
}
throw new ApiException("No response body found.");
}
$object = @json_decode($body);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ApiException("Unable to decode Mollie response: '{$body}'.");
}
if ($response->getStatusCode() >= 400) {
throw ApiException::createFromResponse($response);
}
return $object;
} | php | private function parseResponseBody(ResponseInterface $response)
{
$body = (string) $response->getBody();
if (empty($body)) {
if ($response->getStatusCode() === self::HTTP_NO_CONTENT) {
return null;
}
throw new ApiException("No response body found.");
}
$object = @json_decode($body);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ApiException("Unable to decode Mollie response: '{$body}'.");
}
if ($response->getStatusCode() >= 400) {
throw ApiException::createFromResponse($response);
}
return $object;
} | [
"private",
"function",
"parseResponseBody",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"body",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"===",
"self",
"::",
"HTTP_NO_CONTENT",
")",
"{",
"return",
"null",
";",
"}",
"throw",
"new",
"ApiException",
"(",
"\"No response body found.\"",
")",
";",
"}",
"$",
"object",
"=",
"@",
"json_decode",
"(",
"$",
"body",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Unable to decode Mollie response: '{$body}'.\"",
")",
";",
"}",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
">=",
"400",
")",
"{",
"throw",
"ApiException",
"::",
"createFromResponse",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Parse the PSR-7 Response body
@param ResponseInterface $response
@return object|null
@throws ApiException | [
"Parse",
"the",
"PSR",
"-",
"7",
"Response",
"body"
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/MollieApiClient.php#L466-L488 | train |
mollie/mollie-api-php | src/Endpoints/OrderEndpoint.php | OrderEndpoint.get | public function get($orderId, array $parameters = [])
{
if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '".self::RESOURCE_ID_PREFIX."'.");
}
return parent::rest_read($orderId, $parameters);
} | php | public function get($orderId, array $parameters = [])
{
if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '".self::RESOURCE_ID_PREFIX."'.");
}
return parent::rest_read($orderId, $parameters);
} | [
"public",
"function",
"get",
"(",
"$",
"orderId",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"orderId",
")",
"||",
"strpos",
"(",
"$",
"orderId",
",",
"self",
"::",
"RESOURCE_ID_PREFIX",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"\"Invalid order ID: '{$orderId}'. An order ID should start with '\"",
".",
"self",
"::",
"RESOURCE_ID_PREFIX",
".",
"\"'.\"",
")",
";",
"}",
"return",
"parent",
"::",
"rest_read",
"(",
"$",
"orderId",
",",
"$",
"parameters",
")",
";",
"}"
] | Retrieve a single order from Mollie.
Will throw a ApiException if the order id is invalid or the resource cannot
be found.
@param string $paymentId
@param array $parameters
@return Order
@throws ApiException | [
"Retrieve",
"a",
"single",
"order",
"from",
"Mollie",
"."
] | 370b61d22334657a4644bb9c74f5095f38df189b | https://github.com/mollie/mollie-api-php/blob/370b61d22334657a4644bb9c74f5095f38df189b/src/Endpoints/OrderEndpoint.php#L68-L75 | train |
govCMS/govCMS8 | modules/custom/core/govcms8_foundations/modules/govcms8_calendar_item/src/Plugin/Field/FieldFormatter/CalendarItemDateFormatter.php | CalendarItemDateFormatter.viewValue | protected function viewValue(FieldItemInterface $item) {
$field = $item->getFieldDefinition();
if ($field->get('field_type') == 'daterange') {
$value = $item->start_date;
}
else {
$value = $item->date;
}
$build = [
'#theme' => 'calendar_item_date',
'#datetime' => $value,
'#attached' => [
'library' => [
'govcms8_calendar_item/calendar_item',
],
],
];
return $build;
} | php | protected function viewValue(FieldItemInterface $item) {
$field = $item->getFieldDefinition();
if ($field->get('field_type') == 'daterange') {
$value = $item->start_date;
}
else {
$value = $item->date;
}
$build = [
'#theme' => 'calendar_item_date',
'#datetime' => $value,
'#attached' => [
'library' => [
'govcms8_calendar_item/calendar_item',
],
],
];
return $build;
} | [
"protected",
"function",
"viewValue",
"(",
"FieldItemInterface",
"$",
"item",
")",
"{",
"$",
"field",
"=",
"$",
"item",
"->",
"getFieldDefinition",
"(",
")",
";",
"if",
"(",
"$",
"field",
"->",
"get",
"(",
"'field_type'",
")",
"==",
"'daterange'",
")",
"{",
"$",
"value",
"=",
"$",
"item",
"->",
"start_date",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"item",
"->",
"date",
";",
"}",
"$",
"build",
"=",
"[",
"'#theme'",
"=>",
"'calendar_item_date'",
",",
"'#datetime'",
"=>",
"$",
"value",
",",
"'#attached'",
"=>",
"[",
"'library'",
"=>",
"[",
"'govcms8_calendar_item/calendar_item'",
",",
"]",
",",
"]",
",",
"]",
";",
"return",
"$",
"build",
";",
"}"
] | Generate the output appropriate for one field item.
@param \Drupal\Core\Field\FieldItemInterface $item
One field item.
@return array
The textual output generated. | [
"Generate",
"the",
"output",
"appropriate",
"for",
"one",
"field",
"item",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms8_foundations/modules/govcms8_calendar_item/src/Plugin/Field/FieldFormatter/CalendarItemDateFormatter.php#L45-L63 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Form/BulkUploadForm.php | BulkUploadForm.bytesToString | public static function bytesToString($bytes) {
$units = array_map('t', ['bytes', 'KB', 'MB', 'GB', 'TB']);
while ($bytes > 1024) {
$bytes /= 1024;
array_shift($units);
}
return $bytes . ' ' . reset($units);
} | php | public static function bytesToString($bytes) {
$units = array_map('t', ['bytes', 'KB', 'MB', 'GB', 'TB']);
while ($bytes > 1024) {
$bytes /= 1024;
array_shift($units);
}
return $bytes . ' ' . reset($units);
} | [
"public",
"static",
"function",
"bytesToString",
"(",
"$",
"bytes",
")",
"{",
"$",
"units",
"=",
"array_map",
"(",
"'t'",
",",
"[",
"'bytes'",
",",
"'KB'",
",",
"'MB'",
",",
"'GB'",
",",
"'TB'",
"]",
")",
";",
"while",
"(",
"$",
"bytes",
">",
"1024",
")",
"{",
"$",
"bytes",
"/=",
"1024",
";",
"array_shift",
"(",
"$",
"units",
")",
";",
"}",
"return",
"$",
"bytes",
".",
"' '",
".",
"reset",
"(",
"$",
"units",
")",
";",
"}"
] | Converts a number of bytes into a human-readable string.
@param int $bytes
A number of bytes.
@return string
The human-readable measurement, like '2 MB' or '10 GB'. | [
"Converts",
"a",
"number",
"of",
"bytes",
"into",
"a",
"human",
"-",
"readable",
"string",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Form/BulkUploadForm.php#L104-L112 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.getFileExtensions | public function getFileExtensions($check_access = FALSE, array $bundles = []) {
$extensions = '';
// GovCMS Media overrides the media_bundle storage handler with a special
// one that adds an optional second parameter to loadMultiple().
$storage = $this->entityTypeManager
->getStorage('media_type');
$media_types = $storage->loadMultiple($bundles ?: NULL, $check_access);
/** @var \Drupal\media\MediaTypeInterface $media_type */
foreach ($media_types as $media_type) {
$field = $media_type->getSource()->getSourceFieldDefinition($media_type);
// If the field is a FileItem or any of its descendants, we can consider
// it a file field. This will automatically include things like image
// fields, which extend file fields.
if (is_a($field->getItemDefinition()->getClass(), FileItem::class, TRUE)) {
$extensions .= $field->getSetting('file_extensions') . ' ';
}
}
$extensions = preg_split('/,?\s+/', rtrim($extensions));
return array_unique($extensions);
} | php | public function getFileExtensions($check_access = FALSE, array $bundles = []) {
$extensions = '';
// GovCMS Media overrides the media_bundle storage handler with a special
// one that adds an optional second parameter to loadMultiple().
$storage = $this->entityTypeManager
->getStorage('media_type');
$media_types = $storage->loadMultiple($bundles ?: NULL, $check_access);
/** @var \Drupal\media\MediaTypeInterface $media_type */
foreach ($media_types as $media_type) {
$field = $media_type->getSource()->getSourceFieldDefinition($media_type);
// If the field is a FileItem or any of its descendants, we can consider
// it a file field. This will automatically include things like image
// fields, which extend file fields.
if (is_a($field->getItemDefinition()->getClass(), FileItem::class, TRUE)) {
$extensions .= $field->getSetting('file_extensions') . ' ';
}
}
$extensions = preg_split('/,?\s+/', rtrim($extensions));
return array_unique($extensions);
} | [
"public",
"function",
"getFileExtensions",
"(",
"$",
"check_access",
"=",
"FALSE",
",",
"array",
"$",
"bundles",
"=",
"[",
"]",
")",
"{",
"$",
"extensions",
"=",
"''",
";",
"// GovCMS Media overrides the media_bundle storage handler with a special",
"// one that adds an optional second parameter to loadMultiple().",
"$",
"storage",
"=",
"$",
"this",
"->",
"entityTypeManager",
"->",
"getStorage",
"(",
"'media_type'",
")",
";",
"$",
"media_types",
"=",
"$",
"storage",
"->",
"loadMultiple",
"(",
"$",
"bundles",
"?",
":",
"NULL",
",",
"$",
"check_access",
")",
";",
"/** @var \\Drupal\\media\\MediaTypeInterface $media_type */",
"foreach",
"(",
"$",
"media_types",
"as",
"$",
"media_type",
")",
"{",
"$",
"field",
"=",
"$",
"media_type",
"->",
"getSource",
"(",
")",
"->",
"getSourceFieldDefinition",
"(",
"$",
"media_type",
")",
";",
"// If the field is a FileItem or any of its descendants, we can consider",
"// it a file field. This will automatically include things like image",
"// fields, which extend file fields.",
"if",
"(",
"is_a",
"(",
"$",
"field",
"->",
"getItemDefinition",
"(",
")",
"->",
"getClass",
"(",
")",
",",
"FileItem",
"::",
"class",
",",
"TRUE",
")",
")",
"{",
"$",
"extensions",
".=",
"$",
"field",
"->",
"getSetting",
"(",
"'file_extensions'",
")",
".",
"' '",
";",
"}",
"}",
"$",
"extensions",
"=",
"preg_split",
"(",
"'/,?\\s+/'",
",",
"rtrim",
"(",
"$",
"extensions",
")",
")",
";",
"return",
"array_unique",
"(",
"$",
"extensions",
")",
";",
"}"
] | Returns all file extensions accepted by bundles that use file fields.
@param bool $check_access
(optional) Whether to filter the bundles by create access for the current
user. Defaults to FALSE.
@param string[] $bundles
(optional) An array of bundle IDs from which to retrieve source field
extensions. If omitted, all available bundles are allowed.
@return string[]
The file extensions accepted by all available bundles. | [
"Returns",
"all",
"file",
"extensions",
"accepted",
"by",
"bundles",
"that",
"use",
"file",
"fields",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L49-L71 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.getBundleFromInput | public function getBundleFromInput($value, $check_access = TRUE, array $bundles = []) {
// GovCMS Media overrides the media_bundle storage handler with a special
// one that adds an optional second parameter to loadMultiple().
$media_types = $this->entityTypeManager
->getStorage('media_type')
->loadMultiple($bundles ?: NULL, $check_access);
ksort($media_types);
/** @var \Drupal\media\MediaTypeInterface $media_type */
foreach ($media_types as $media_type) {
$source = $media_type->getSource();
if ($source instanceof InputMatchInterface && $source->appliesTo($value, $media_type)) {
return $media_type;
}
}
throw new IndeterminateBundleException($value);
} | php | public function getBundleFromInput($value, $check_access = TRUE, array $bundles = []) {
// GovCMS Media overrides the media_bundle storage handler with a special
// one that adds an optional second parameter to loadMultiple().
$media_types = $this->entityTypeManager
->getStorage('media_type')
->loadMultiple($bundles ?: NULL, $check_access);
ksort($media_types);
/** @var \Drupal\media\MediaTypeInterface $media_type */
foreach ($media_types as $media_type) {
$source = $media_type->getSource();
if ($source instanceof InputMatchInterface && $source->appliesTo($value, $media_type)) {
return $media_type;
}
}
throw new IndeterminateBundleException($value);
} | [
"public",
"function",
"getBundleFromInput",
"(",
"$",
"value",
",",
"$",
"check_access",
"=",
"TRUE",
",",
"array",
"$",
"bundles",
"=",
"[",
"]",
")",
"{",
"// GovCMS Media overrides the media_bundle storage handler with a special",
"// one that adds an optional second parameter to loadMultiple().",
"$",
"media_types",
"=",
"$",
"this",
"->",
"entityTypeManager",
"->",
"getStorage",
"(",
"'media_type'",
")",
"->",
"loadMultiple",
"(",
"$",
"bundles",
"?",
":",
"NULL",
",",
"$",
"check_access",
")",
";",
"ksort",
"(",
"$",
"media_types",
")",
";",
"/** @var \\Drupal\\media\\MediaTypeInterface $media_type */",
"foreach",
"(",
"$",
"media_types",
"as",
"$",
"media_type",
")",
"{",
"$",
"source",
"=",
"$",
"media_type",
"->",
"getSource",
"(",
")",
";",
"if",
"(",
"$",
"source",
"instanceof",
"InputMatchInterface",
"&&",
"$",
"source",
"->",
"appliesTo",
"(",
"$",
"value",
",",
"$",
"media_type",
")",
")",
"{",
"return",
"$",
"media_type",
";",
"}",
"}",
"throw",
"new",
"IndeterminateBundleException",
"(",
"$",
"value",
")",
";",
"}"
] | Returns the first media bundle that can accept an input value.
@param mixed $value
The input value.
@param bool $check_access
(optional) Whether to filter the bundles by create access for the current
user. Defaults to TRUE.
@param string[] $bundles
(optional) A set of media bundle IDs which might match the input. If
omitted, all available bundles are checked.
@return \Drupal\media\MediaTypeInterface
A media bundle that can accept the input value.
@throws \Drupal\govcms_media\Exception\IndeterminateBundleException
If no bundle can be matched to the input value. | [
"Returns",
"the",
"first",
"media",
"bundle",
"that",
"can",
"accept",
"an",
"input",
"value",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L91-L108 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.createFromInput | public function createFromInput($value, array $bundles = []) {
/** @var \Drupal\media\MediaInterface $entity */
$entity = $this->entityTypeManager
->getStorage('media')
->create([
'bundle' => $this->getBundleFromInput($value, TRUE, $bundles)->id(),
]);
$field = static::getSourceField($entity);
if ($field) {
$field->setValue($value);
}
return $entity;
} | php | public function createFromInput($value, array $bundles = []) {
/** @var \Drupal\media\MediaInterface $entity */
$entity = $this->entityTypeManager
->getStorage('media')
->create([
'bundle' => $this->getBundleFromInput($value, TRUE, $bundles)->id(),
]);
$field = static::getSourceField($entity);
if ($field) {
$field->setValue($value);
}
return $entity;
} | [
"public",
"function",
"createFromInput",
"(",
"$",
"value",
",",
"array",
"$",
"bundles",
"=",
"[",
"]",
")",
"{",
"/** @var \\Drupal\\media\\MediaInterface $entity */",
"$",
"entity",
"=",
"$",
"this",
"->",
"entityTypeManager",
"->",
"getStorage",
"(",
"'media'",
")",
"->",
"create",
"(",
"[",
"'bundle'",
"=>",
"$",
"this",
"->",
"getBundleFromInput",
"(",
"$",
"value",
",",
"TRUE",
",",
"$",
"bundles",
")",
"->",
"id",
"(",
")",
",",
"]",
")",
";",
"$",
"field",
"=",
"static",
"::",
"getSourceField",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"$",
"field",
")",
"{",
"$",
"field",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Creates a media entity from an input value.
@param mixed $value
The input value.
@param string[] $bundles
(optional) A set of media bundle IDs which might match the input value.
If omitted, all bundles to which the user has create access are checked.
@return \Drupal\media\MediaInterface
The unsaved media entity. | [
"Creates",
"a",
"media",
"entity",
"from",
"an",
"input",
"value",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L122-L135 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.useFile | public static function useFile(MediaInterface $entity, FileInterface $file, $replace = FILE_EXISTS_RENAME) {
$field = static::getSourceField($entity);
$field->setValue($file);
$destination = '';
$destination .= static::prepareFileDestination($entity);
if (substr($destination, -1) != '/') {
$destination .= '/';
}
$destination .= $file->getFilename();
if ($destination == $file->getFileUri()) {
return $file;
}
else {
$file = file_move($file, $destination, $replace);
if ($file) {
$field->setValue($file);
return $file;
}
else {
return FALSE;
}
}
} | php | public static function useFile(MediaInterface $entity, FileInterface $file, $replace = FILE_EXISTS_RENAME) {
$field = static::getSourceField($entity);
$field->setValue($file);
$destination = '';
$destination .= static::prepareFileDestination($entity);
if (substr($destination, -1) != '/') {
$destination .= '/';
}
$destination .= $file->getFilename();
if ($destination == $file->getFileUri()) {
return $file;
}
else {
$file = file_move($file, $destination, $replace);
if ($file) {
$field->setValue($file);
return $file;
}
else {
return FALSE;
}
}
} | [
"public",
"static",
"function",
"useFile",
"(",
"MediaInterface",
"$",
"entity",
",",
"FileInterface",
"$",
"file",
",",
"$",
"replace",
"=",
"FILE_EXISTS_RENAME",
")",
"{",
"$",
"field",
"=",
"static",
"::",
"getSourceField",
"(",
"$",
"entity",
")",
";",
"$",
"field",
"->",
"setValue",
"(",
"$",
"file",
")",
";",
"$",
"destination",
"=",
"''",
";",
"$",
"destination",
".=",
"static",
"::",
"prepareFileDestination",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"destination",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"destination",
".=",
"'/'",
";",
"}",
"$",
"destination",
".=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"destination",
"==",
"$",
"file",
"->",
"getFileUri",
"(",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"file_move",
"(",
"$",
"file",
",",
"$",
"destination",
",",
"$",
"replace",
")",
";",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"field",
"->",
"setValue",
"(",
"$",
"file",
")",
";",
"return",
"$",
"file",
";",
"}",
"else",
"{",
"return",
"FALSE",
";",
"}",
"}",
"}"
] | Attaches a file entity to a media entity.
@param \Drupal\media\MediaInterface $entity
The media entity.
@param \Drupal\file\FileInterface $file
The file entity.
@param int $replace
(optional) What to do if the file already exists. Can be any of the
constants accepted by file_move().
@return \Drupal\file\FileInterface|false
The final file entity (unsaved), or FALSE if an error occurred. | [
"Attaches",
"a",
"file",
"entity",
"to",
"a",
"media",
"entity",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L151-L176 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.prepareFileDestination | public static function prepareFileDestination(MediaInterface $entity) {
/** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
$item = static::getSourceField($entity)->first();
$dir = $item->getUploadLocation();
$is_ready = file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
if ($is_ready) {
return $dir;
}
else {
throw new \RuntimeException('Could not prepare ' . $dir . ' for writing');
}
} | php | public static function prepareFileDestination(MediaInterface $entity) {
/** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
$item = static::getSourceField($entity)->first();
$dir = $item->getUploadLocation();
$is_ready = file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
if ($is_ready) {
return $dir;
}
else {
throw new \RuntimeException('Could not prepare ' . $dir . ' for writing');
}
} | [
"public",
"static",
"function",
"prepareFileDestination",
"(",
"MediaInterface",
"$",
"entity",
")",
"{",
"/** @var \\Drupal\\file\\Plugin\\Field\\FieldType\\FileItem $item */",
"$",
"item",
"=",
"static",
"::",
"getSourceField",
"(",
"$",
"entity",
")",
"->",
"first",
"(",
")",
";",
"$",
"dir",
"=",
"$",
"item",
"->",
"getUploadLocation",
"(",
")",
";",
"$",
"is_ready",
"=",
"file_prepare_directory",
"(",
"$",
"dir",
",",
"FILE_CREATE_DIRECTORY",
"|",
"FILE_MODIFY_PERMISSIONS",
")",
";",
"if",
"(",
"$",
"is_ready",
")",
"{",
"return",
"$",
"dir",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not prepare '",
".",
"$",
"dir",
".",
"' for writing'",
")",
";",
"}",
"}"
] | Prepares the destination directory for a file attached to a media entity.
@param \Drupal\media\MediaInterface $entity
The media entity.
@return string
The destination directory URI.
@throws \RuntimeException
If the destination directory is not writable. | [
"Prepares",
"the",
"destination",
"directory",
"for",
"a",
"file",
"attached",
"to",
"a",
"media",
"entity",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L190-L203 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/MediaHelper.php | MediaHelper.getSourceField | public static function getSourceField(MediaInterface $entity) {
$field = $entity->getSource()->getSourceFieldDefinition($entity->bundle->entity);
return $field
? $entity->get($field->getName())
: NULL;
} | php | public static function getSourceField(MediaInterface $entity) {
$field = $entity->getSource()->getSourceFieldDefinition($entity->bundle->entity);
return $field
? $entity->get($field->getName())
: NULL;
} | [
"public",
"static",
"function",
"getSourceField",
"(",
"MediaInterface",
"$",
"entity",
")",
"{",
"$",
"field",
"=",
"$",
"entity",
"->",
"getSource",
"(",
")",
"->",
"getSourceFieldDefinition",
"(",
"$",
"entity",
"->",
"bundle",
"->",
"entity",
")",
";",
"return",
"$",
"field",
"?",
"$",
"entity",
"->",
"get",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
")",
":",
"NULL",
";",
"}"
] | Returns the media entity's source field item list.
@param \Drupal\media\MediaInterface $entity
The media entity.
@return \Drupal\Core\Field\FieldItemListInterface|null
The media entity's source field item list, or NULL if the media type
plugin does not define a source field. | [
"Returns",
"the",
"media",
"entity",
"s",
"source",
"field",
"item",
"list",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/MediaHelper.php#L230-L236 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/Upload.php | Upload.validate | public static function validate(array &$element, FormStateInterface $form_state) {
if ($element['#value']) {
$file = File::load($element['#value']);
$errors = file_validate($file, $element['#upload_validators']);
if ($errors) {
foreach ($errors as $error) {
$form_state->setError($element, (string) $error);
}
static::delete($element);
}
}
} | php | public static function validate(array &$element, FormStateInterface $form_state) {
if ($element['#value']) {
$file = File::load($element['#value']);
$errors = file_validate($file, $element['#upload_validators']);
if ($errors) {
foreach ($errors as $error) {
$form_state->setError($element, (string) $error);
}
static::delete($element);
}
}
} | [
"public",
"static",
"function",
"validate",
"(",
"array",
"&",
"$",
"element",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"if",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
"{",
"$",
"file",
"=",
"File",
"::",
"load",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
";",
"$",
"errors",
"=",
"file_validate",
"(",
"$",
"file",
",",
"$",
"element",
"[",
"'#upload_validators'",
"]",
")",
";",
"if",
"(",
"$",
"errors",
")",
"{",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"form_state",
"->",
"setError",
"(",
"$",
"element",
",",
"(",
"string",
")",
"$",
"error",
")",
";",
"}",
"static",
"::",
"delete",
"(",
"$",
"element",
")",
";",
"}",
"}",
"}"
] | Validates the uploaded file.
@param array $element
The element.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state. | [
"Validates",
"the",
"uploaded",
"file",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/Upload.php#L43-L55 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/Upload.php | Upload.delete | public static function delete(array $element) {
if ($element['#value']) {
$file = File::load($element['#value']);
$file->delete();
// Clean up the file system if needed.
$uri = $file->getFileUri();
if (file_exists($uri)) {
\Drupal::service('file_system')->unlink($uri);
}
}
} | php | public static function delete(array $element) {
if ($element['#value']) {
$file = File::load($element['#value']);
$file->delete();
// Clean up the file system if needed.
$uri = $file->getFileUri();
if (file_exists($uri)) {
\Drupal::service('file_system')->unlink($uri);
}
}
} | [
"public",
"static",
"function",
"delete",
"(",
"array",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
"{",
"$",
"file",
"=",
"File",
"::",
"load",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
";",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"// Clean up the file system if needed.",
"$",
"uri",
"=",
"$",
"file",
"->",
"getFileUri",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"uri",
")",
")",
"{",
"\\",
"Drupal",
"::",
"service",
"(",
"'file_system'",
")",
"->",
"unlink",
"(",
"$",
"uri",
")",
";",
"}",
"}",
"}"
] | Deletes the file referenced by the element.
@param array $element
The element. If set, its value should be a file entity ID. | [
"Deletes",
"the",
"file",
"referenced",
"by",
"the",
"element",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/Upload.php#L63-L74 | train |
govCMS/govCMS8 | src/IniEncoder.php | IniEncoder.doEncode | protected function doEncode(array $input, array $keys = []) {
$output = [];
foreach ($input as $key => $value) {
$keys[] = $key;
if (is_array($value)) {
if ($this->isAssociative($value)) {
$output = array_merge($output, $this->doEncode($value, $keys));
}
else {
foreach ($value as $j) {
$output[] = $this->keysToString($keys) . '[] = ' . $j;
}
}
}
else {
$output[] = $this->keysToString($keys) . ' = ' . $value;
}
array_pop($keys);
}
return $output;
} | php | protected function doEncode(array $input, array $keys = []) {
$output = [];
foreach ($input as $key => $value) {
$keys[] = $key;
if (is_array($value)) {
if ($this->isAssociative($value)) {
$output = array_merge($output, $this->doEncode($value, $keys));
}
else {
foreach ($value as $j) {
$output[] = $this->keysToString($keys) . '[] = ' . $j;
}
}
}
else {
$output[] = $this->keysToString($keys) . ' = ' . $value;
}
array_pop($keys);
}
return $output;
} | [
"protected",
"function",
"doEncode",
"(",
"array",
"$",
"input",
",",
"array",
"$",
"keys",
"=",
"[",
"]",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAssociative",
"(",
"$",
"value",
")",
")",
"{",
"$",
"output",
"=",
"array_merge",
"(",
"$",
"output",
",",
"$",
"this",
"->",
"doEncode",
"(",
"$",
"value",
",",
"$",
"keys",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"j",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"keysToString",
"(",
"$",
"keys",
")",
".",
"'[] = '",
".",
"$",
"j",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"keysToString",
"(",
"$",
"keys",
")",
".",
"' = '",
".",
"$",
"value",
";",
"}",
"array_pop",
"(",
"$",
"keys",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Recursively serializes data to legacy make format.
@param array $input
The data to serialize.
@param array $keys
The current key path.
@return string[]
The serialized data as a flat array of lines. | [
"Recursively",
"serializes",
"data",
"to",
"legacy",
"make",
"format",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/src/IniEncoder.php#L36-L60 | train |
govCMS/govCMS8 | src/IniEncoder.php | IniEncoder.keysToString | protected function keysToString(array $keys) {
$head = array_shift($keys);
if ($keys) {
return $head . '[' . implode('][', $keys) . ']';
}
else {
return $head;
}
} | php | protected function keysToString(array $keys) {
$head = array_shift($keys);
if ($keys) {
return $head . '[' . implode('][', $keys) . ']';
}
else {
return $head;
}
} | [
"protected",
"function",
"keysToString",
"(",
"array",
"$",
"keys",
")",
"{",
"$",
"head",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"$",
"keys",
")",
"{",
"return",
"$",
"head",
".",
"'['",
".",
"implode",
"(",
"']['",
",",
"$",
"keys",
")",
".",
"']'",
";",
"}",
"else",
"{",
"return",
"$",
"head",
";",
"}",
"}"
] | Transforms an key path to a string.
@param string[] $keys
The key path.
@return string
The flattened key path. | [
"Transforms",
"an",
"key",
"path",
"to",
"a",
"string",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/src/IniEncoder.php#L71-L79 | train |
govCMS/govCMS8 | src/IniEncoder.php | IniEncoder.parse | public function parse($data) {
$info = [];
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx', $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
// Fetch the key and value string.
$i = 0;
foreach (['key', 'value1', 'value2', 'value3'] as $var) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
if (isset($key) && isset($value1) && isset($value2) && isset($value3)) {
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
// Parse array syntax.
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
// Create nested arrays.
foreach ($keys as $key) {
if ($key == '') {
$key = count($parent);
}
if (!isset($parent[$key]) || !is_array($parent[$key])) {
$parent[$key] = [];
}
$parent = &$parent[$key];
}
// Handle PHP constants.
if (preg_match('/^\w+$/i', $value) && defined($value)) {
$value = constant($value);
}
// Insert actual value.
if ($last == '') {
$last = count($parent);
}
$parent[$last] = $value;
}
}
}
return $info;
} | php | public function parse($data) {
$info = [];
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx', $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
// Fetch the key and value string.
$i = 0;
foreach (['key', 'value1', 'value2', 'value3'] as $var) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
if (isset($key) && isset($value1) && isset($value2) && isset($value3)) {
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
// Parse array syntax.
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
// Create nested arrays.
foreach ($keys as $key) {
if ($key == '') {
$key = count($parent);
}
if (!isset($parent[$key]) || !is_array($parent[$key])) {
$parent[$key] = [];
}
$parent = &$parent[$key];
}
// Handle PHP constants.
if (preg_match('/^\w+$/i', $value) && defined($value)) {
$value = constant($value);
}
// Insert actual value.
if ($last == '') {
$last = count($parent);
}
$parent[$last] = $value;
}
}
}
return $info;
} | [
"public",
"function",
"parse",
"(",
"$",
"data",
")",
"{",
"$",
"info",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'\n @^\\s* # Start at the beginning of a line, ignoring leading whitespace\n ((?:\n [^=;\\[\\]]| # Key names cannot contain equal signs, semi-colons or square brackets,\n \\[[^\\[\\]]*\\] # unless they are balanced and not nested\n )+?)\n \\s*=\\s* # Key/value pairs are separated by equal signs (ignoring white-space)\n (?:\n (\"(?:[^\"]|(?<=\\\\\\\\)\")*\")| # Double-quoted string, which may contain slash-escaped quotes/slashes\n (\\'(?:[^\\']|(?<=\\\\\\\\)\\')*\\')| # Single-quoted string, which may contain slash-escaped quotes/slashes\n ([^\\r\\n]*?) # Non-quoted string\n )\\s*$ # Stop at the next end of a line, ignoring trailing whitespace\n @msx'",
",",
"$",
"data",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"// Fetch the key and value string.",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"[",
"'key'",
",",
"'value1'",
",",
"'value2'",
",",
"'value3'",
"]",
"as",
"$",
"var",
")",
"{",
"$",
"$",
"var",
"=",
"isset",
"(",
"$",
"match",
"[",
"++",
"$",
"i",
"]",
")",
"?",
"$",
"match",
"[",
"$",
"i",
"]",
":",
"''",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"key",
")",
"&&",
"isset",
"(",
"$",
"value1",
")",
"&&",
"isset",
"(",
"$",
"value2",
")",
"&&",
"isset",
"(",
"$",
"value3",
")",
")",
"{",
"$",
"value",
"=",
"stripslashes",
"(",
"substr",
"(",
"$",
"value1",
",",
"1",
",",
"-",
"1",
")",
")",
".",
"stripslashes",
"(",
"substr",
"(",
"$",
"value2",
",",
"1",
",",
"-",
"1",
")",
")",
".",
"$",
"value3",
";",
"// Parse array syntax.",
"$",
"keys",
"=",
"preg_split",
"(",
"'/\\]?\\[/'",
",",
"rtrim",
"(",
"$",
"key",
",",
"']'",
")",
")",
";",
"$",
"last",
"=",
"array_pop",
"(",
"$",
"keys",
")",
";",
"$",
"parent",
"=",
"&",
"$",
"info",
";",
"// Create nested arrays.",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"''",
")",
"{",
"$",
"key",
"=",
"count",
"(",
"$",
"parent",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"parent",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"parent",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"parent",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"parent",
"=",
"&",
"$",
"parent",
"[",
"$",
"key",
"]",
";",
"}",
"// Handle PHP constants.",
"if",
"(",
"preg_match",
"(",
"'/^\\w+$/i'",
",",
"$",
"value",
")",
"&&",
"defined",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"constant",
"(",
"$",
"value",
")",
";",
"}",
"// Insert actual value.",
"if",
"(",
"$",
"last",
"==",
"''",
")",
"{",
"$",
"last",
"=",
"count",
"(",
"$",
"parent",
")",
";",
"}",
"$",
"parent",
"[",
"$",
"last",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"info",
";",
"}"
] | Parses data in Drupal's .info format.
@see https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_parse_info_format/7.x
@param string $data
A string to parse.
@return array
The parsed data. | [
"Parses",
"data",
"in",
"Drupal",
"s",
".",
"info",
"format",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/src/IniEncoder.php#L107-L164 | train |
govCMS/govCMS8 | src/Composer/Package.php | Package.isLibrary | protected function isLibrary(array $package) {
// Add Swiftmailer support.
if ($package['name'] == 'swiftmailer/swiftmailer') {
$package['type'] = 'drupal-library';
}
$package_types = [
'drupal-library',
'bower-asset',
'npm-asset',
];
return (
in_array($package['type'], $package_types) &&
array_key_exists($package['name'], $this->rootPackage->getRequires())
);
} | php | protected function isLibrary(array $package) {
// Add Swiftmailer support.
if ($package['name'] == 'swiftmailer/swiftmailer') {
$package['type'] = 'drupal-library';
}
$package_types = [
'drupal-library',
'bower-asset',
'npm-asset',
];
return (
in_array($package['type'], $package_types) &&
array_key_exists($package['name'], $this->rootPackage->getRequires())
);
} | [
"protected",
"function",
"isLibrary",
"(",
"array",
"$",
"package",
")",
"{",
"// Add Swiftmailer support.",
"if",
"(",
"$",
"package",
"[",
"'name'",
"]",
"==",
"'swiftmailer/swiftmailer'",
")",
"{",
"$",
"package",
"[",
"'type'",
"]",
"=",
"'drupal-library'",
";",
"}",
"$",
"package_types",
"=",
"[",
"'drupal-library'",
",",
"'bower-asset'",
",",
"'npm-asset'",
",",
"]",
";",
"return",
"(",
"in_array",
"(",
"$",
"package",
"[",
"'type'",
"]",
",",
"$",
"package_types",
")",
"&&",
"array_key_exists",
"(",
"$",
"package",
"[",
"'name'",
"]",
",",
"$",
"this",
"->",
"rootPackage",
"->",
"getRequires",
"(",
")",
")",
")",
";",
"}"
] | Determines if a package is an asset library.
@param array $package
The package info.
@return bool
TRUE if the package is an asset library, otherwise FALSE. | [
"Determines",
"if",
"a",
"package",
"is",
"an",
"asset",
"library",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/src/Composer/Package.php#L259-L274 | train |
govCMS/govCMS8 | src/Composer/Package.php | Package.isGovCMSTheme | protected function isGovCMSTheme(array $package) {
// Exlucde package theme from custom repos.
if ($package['name'] == 'govcms-custom/govcms8_uikit' || $package['name'] == 'govcms-custom/govcms8_uikit_starter') {
return FALSE;
}
$package_types = [
'drupal-theme',
];
return (
in_array($package['type'], $package_types) &&
array_key_exists($package['name'], $this->rootPackage->getRequires())
);
} | php | protected function isGovCMSTheme(array $package) {
// Exlucde package theme from custom repos.
if ($package['name'] == 'govcms-custom/govcms8_uikit' || $package['name'] == 'govcms-custom/govcms8_uikit_starter') {
return FALSE;
}
$package_types = [
'drupal-theme',
];
return (
in_array($package['type'], $package_types) &&
array_key_exists($package['name'], $this->rootPackage->getRequires())
);
} | [
"protected",
"function",
"isGovCMSTheme",
"(",
"array",
"$",
"package",
")",
"{",
"// Exlucde package theme from custom repos.",
"if",
"(",
"$",
"package",
"[",
"'name'",
"]",
"==",
"'govcms-custom/govcms8_uikit'",
"||",
"$",
"package",
"[",
"'name'",
"]",
"==",
"'govcms-custom/govcms8_uikit_starter'",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"package_types",
"=",
"[",
"'drupal-theme'",
",",
"]",
";",
"return",
"(",
"in_array",
"(",
"$",
"package",
"[",
"'type'",
"]",
",",
"$",
"package_types",
")",
"&&",
"array_key_exists",
"(",
"$",
"package",
"[",
"'name'",
"]",
",",
"$",
"this",
"->",
"rootPackage",
"->",
"getRequires",
"(",
")",
")",
")",
";",
"}"
] | Determines if a package is a GovCMS theme.
@param array $package
The package info.
@return bool
True if the package is a GovCMS theme, otherwise FALSE. | [
"Determines",
"if",
"a",
"package",
"is",
"a",
"GovCMS",
"theme",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/src/Composer/Package.php#L285-L298 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/InteractiveUpload.php | InteractiveUpload.process | public static function process(array $element, FormStateInterface $form_state) {
$element['fid'] = [
'#type' => 'hidden',
];
$element['upload'] = $element['remove'] = [
'#type' => 'submit',
'#is_button' => TRUE,
'#limit_validation_errors' => [
$element['#parents'],
],
'#weight' => 100,
];
$element['upload']['#value'] = t('Upload');
$element['upload']['#submit'][] = [static::class, 'upload'];
$element['remove']['#value'] = t('Remove');
$element['remove']['#submit'][] = [static::class, 'remove'];
$key = array_merge($element['#parents'], ['fid']);
// Don't use $form_state->hasValue(), because it will return TRUE if the
// value exists and is falsy. Valid file IDs will always be truthy.
$fid = $form_state->getValue($key);
if ($fid) {
$element['fid']['#value'] = $fid;
$element['file'] = [
'#theme' => 'file_link',
'#file' => File::load($fid),
];
$element['upload']['#access'] = FALSE;
}
else {
$element['file'] = [
'#type' => 'upload',
'#title' => $element['#title'],
'#upload_location' => $element['#upload_location'],
'#upload_validators' => $element['#upload_validators'],
];
$element['remove']['#access'] = FALSE;
}
return $element;
} | php | public static function process(array $element, FormStateInterface $form_state) {
$element['fid'] = [
'#type' => 'hidden',
];
$element['upload'] = $element['remove'] = [
'#type' => 'submit',
'#is_button' => TRUE,
'#limit_validation_errors' => [
$element['#parents'],
],
'#weight' => 100,
];
$element['upload']['#value'] = t('Upload');
$element['upload']['#submit'][] = [static::class, 'upload'];
$element['remove']['#value'] = t('Remove');
$element['remove']['#submit'][] = [static::class, 'remove'];
$key = array_merge($element['#parents'], ['fid']);
// Don't use $form_state->hasValue(), because it will return TRUE if the
// value exists and is falsy. Valid file IDs will always be truthy.
$fid = $form_state->getValue($key);
if ($fid) {
$element['fid']['#value'] = $fid;
$element['file'] = [
'#theme' => 'file_link',
'#file' => File::load($fid),
];
$element['upload']['#access'] = FALSE;
}
else {
$element['file'] = [
'#type' => 'upload',
'#title' => $element['#title'],
'#upload_location' => $element['#upload_location'],
'#upload_validators' => $element['#upload_validators'],
];
$element['remove']['#access'] = FALSE;
}
return $element;
} | [
"public",
"static",
"function",
"process",
"(",
"array",
"$",
"element",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"element",
"[",
"'fid'",
"]",
"=",
"[",
"'#type'",
"=>",
"'hidden'",
",",
"]",
";",
"$",
"element",
"[",
"'upload'",
"]",
"=",
"$",
"element",
"[",
"'remove'",
"]",
"=",
"[",
"'#type'",
"=>",
"'submit'",
",",
"'#is_button'",
"=>",
"TRUE",
",",
"'#limit_validation_errors'",
"=>",
"[",
"$",
"element",
"[",
"'#parents'",
"]",
",",
"]",
",",
"'#weight'",
"=>",
"100",
",",
"]",
";",
"$",
"element",
"[",
"'upload'",
"]",
"[",
"'#value'",
"]",
"=",
"t",
"(",
"'Upload'",
")",
";",
"$",
"element",
"[",
"'upload'",
"]",
"[",
"'#submit'",
"]",
"[",
"]",
"=",
"[",
"static",
"::",
"class",
",",
"'upload'",
"]",
";",
"$",
"element",
"[",
"'remove'",
"]",
"[",
"'#value'",
"]",
"=",
"t",
"(",
"'Remove'",
")",
";",
"$",
"element",
"[",
"'remove'",
"]",
"[",
"'#submit'",
"]",
"[",
"]",
"=",
"[",
"static",
"::",
"class",
",",
"'remove'",
"]",
";",
"$",
"key",
"=",
"array_merge",
"(",
"$",
"element",
"[",
"'#parents'",
"]",
",",
"[",
"'fid'",
"]",
")",
";",
"// Don't use $form_state->hasValue(), because it will return TRUE if the",
"// value exists and is falsy. Valid file IDs will always be truthy.",
"$",
"fid",
"=",
"$",
"form_state",
"->",
"getValue",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"fid",
")",
"{",
"$",
"element",
"[",
"'fid'",
"]",
"[",
"'#value'",
"]",
"=",
"$",
"fid",
";",
"$",
"element",
"[",
"'file'",
"]",
"=",
"[",
"'#theme'",
"=>",
"'file_link'",
",",
"'#file'",
"=>",
"File",
"::",
"load",
"(",
"$",
"fid",
")",
",",
"]",
";",
"$",
"element",
"[",
"'upload'",
"]",
"[",
"'#access'",
"]",
"=",
"FALSE",
";",
"}",
"else",
"{",
"$",
"element",
"[",
"'file'",
"]",
"=",
"[",
"'#type'",
"=>",
"'upload'",
",",
"'#title'",
"=>",
"$",
"element",
"[",
"'#title'",
"]",
",",
"'#upload_location'",
"=>",
"$",
"element",
"[",
"'#upload_location'",
"]",
",",
"'#upload_validators'",
"=>",
"$",
"element",
"[",
"'#upload_validators'",
"]",
",",
"]",
";",
"$",
"element",
"[",
"'remove'",
"]",
"[",
"'#access'",
"]",
"=",
"FALSE",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Processes the element.
@param array $element
The unprocessed element.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state.
@return array
The processed element. | [
"Processes",
"the",
"element",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/InteractiveUpload.php#L48-L91 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/InteractiveUpload.php | InteractiveUpload.el | public static function el(array &$form, FormStateInterface $form_state) {
$trigger = $form_state->getTriggeringElement();
return NestedArray::getValue($form, array_slice($trigger['#array_parents'], 0, -1));
} | php | public static function el(array &$form, FormStateInterface $form_state) {
$trigger = $form_state->getTriggeringElement();
return NestedArray::getValue($form, array_slice($trigger['#array_parents'], 0, -1));
} | [
"public",
"static",
"function",
"el",
"(",
"array",
"&",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"trigger",
"=",
"$",
"form_state",
"->",
"getTriggeringElement",
"(",
")",
";",
"return",
"NestedArray",
"::",
"getValue",
"(",
"$",
"form",
",",
"array_slice",
"(",
"$",
"trigger",
"[",
"'#array_parents'",
"]",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"}"
] | Returns the root element for a triggering element.
@param array $form
The complete form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state.
@return array
The root element that contains the triggering element. | [
"Returns",
"the",
"root",
"element",
"for",
"a",
"triggering",
"element",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/InteractiveUpload.php#L104-L107 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/InteractiveUpload.php | InteractiveUpload.upload | public static function upload(array &$form, FormStateInterface $form_state) {
$el = static::el($form, $form_state);
$form_state->setValueForElement($el['fid'], $el['file']['#value']);
NestedArray::setValue($form_state->getUserInput(), $el['fid']['#parents'], $el['file']['#value']);
$form_state->setRebuild();
} | php | public static function upload(array &$form, FormStateInterface $form_state) {
$el = static::el($form, $form_state);
$form_state->setValueForElement($el['fid'], $el['file']['#value']);
NestedArray::setValue($form_state->getUserInput(), $el['fid']['#parents'], $el['file']['#value']);
$form_state->setRebuild();
} | [
"public",
"static",
"function",
"upload",
"(",
"array",
"&",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"el",
"=",
"static",
"::",
"el",
"(",
"$",
"form",
",",
"$",
"form_state",
")",
";",
"$",
"form_state",
"->",
"setValueForElement",
"(",
"$",
"el",
"[",
"'fid'",
"]",
",",
"$",
"el",
"[",
"'file'",
"]",
"[",
"'#value'",
"]",
")",
";",
"NestedArray",
"::",
"setValue",
"(",
"$",
"form_state",
"->",
"getUserInput",
"(",
")",
",",
"$",
"el",
"[",
"'fid'",
"]",
"[",
"'#parents'",
"]",
",",
"$",
"el",
"[",
"'file'",
"]",
"[",
"'#value'",
"]",
")",
";",
"$",
"form_state",
"->",
"setRebuild",
"(",
")",
";",
"}"
] | Handles form submission when the Upload button is clicked.
@param array $form
The complete form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state. | [
"Handles",
"form",
"submission",
"when",
"the",
"Upload",
"button",
"is",
"clicked",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/InteractiveUpload.php#L117-L124 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element/InteractiveUpload.php | InteractiveUpload.remove | public static function remove(array &$form, FormStateInterface $form_state) {
$el = static::el($form, $form_state);
Upload::delete($el['fid']);
$form_state->setValueForElement($el['fid'], NULL);
NestedArray::setValue($form_state->getUserInput(), $el['fid']['#parents'], NULL);
$form_state->setRebuild();
} | php | public static function remove(array &$form, FormStateInterface $form_state) {
$el = static::el($form, $form_state);
Upload::delete($el['fid']);
$form_state->setValueForElement($el['fid'], NULL);
NestedArray::setValue($form_state->getUserInput(), $el['fid']['#parents'], NULL);
$form_state->setRebuild();
} | [
"public",
"static",
"function",
"remove",
"(",
"array",
"&",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"el",
"=",
"static",
"::",
"el",
"(",
"$",
"form",
",",
"$",
"form_state",
")",
";",
"Upload",
"::",
"delete",
"(",
"$",
"el",
"[",
"'fid'",
"]",
")",
";",
"$",
"form_state",
"->",
"setValueForElement",
"(",
"$",
"el",
"[",
"'fid'",
"]",
",",
"NULL",
")",
";",
"NestedArray",
"::",
"setValue",
"(",
"$",
"form_state",
"->",
"getUserInput",
"(",
")",
",",
"$",
"el",
"[",
"'fid'",
"]",
"[",
"'#parents'",
"]",
",",
"NULL",
")",
";",
"$",
"form_state",
"->",
"setRebuild",
"(",
")",
";",
"}"
] | Handles form submission when the Remove button is clicked.
@param array $form
The complete form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state. | [
"Handles",
"form",
"submission",
"when",
"the",
"Remove",
"button",
"is",
"clicked",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element/InteractiveUpload.php#L134-L143 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element.php | Element.mergeCanadian | public function mergeCanadian(array $a, array $b) {
$a += $b;
foreach ($a as $k => $v) {
if (is_array($v) && isset($b[$k]) && is_array($b[$k])) {
$a[$k] = static::mergeCanadian($a[$k], $b[$k]);
}
}
return $a;
} | php | public function mergeCanadian(array $a, array $b) {
$a += $b;
foreach ($a as $k => $v) {
if (is_array($v) && isset($b[$k]) && is_array($b[$k])) {
$a[$k] = static::mergeCanadian($a[$k], $b[$k]);
}
}
return $a;
} | [
"public",
"function",
"mergeCanadian",
"(",
"array",
"$",
"a",
",",
"array",
"$",
"b",
")",
"{",
"$",
"a",
"+=",
"$",
"b",
";",
"foreach",
"(",
"$",
"a",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
"&&",
"isset",
"(",
"$",
"b",
"[",
"$",
"k",
"]",
")",
"&&",
"is_array",
"(",
"$",
"b",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"a",
"[",
"$",
"k",
"]",
"=",
"static",
"::",
"mergeCanadian",
"(",
"$",
"a",
"[",
"$",
"k",
"]",
",",
"$",
"b",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"return",
"$",
"a",
";",
"}"
] | Recursively merges arrays using the + method.
Existing keys at all levels of $a, both numeric and associative, will
always be preserved. That's why I'm calling this a "Canadian" merge -- it
does not want to step on any toes.
@param array $a
The input array.
@param array $b
The array to merge into $a.
@return array
The merged array. | [
"Recursively",
"merges",
"arrays",
"using",
"the",
"+",
"method",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element.php#L29-L37 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element.php | Element.order | public static function order(array &$values, array $keys) {
$keys = array_values($keys);
uksort($values, function ($a, $b) use ($keys) {
return array_search($a, $keys) - array_search($b, $keys);
});
} | php | public static function order(array &$values, array $keys) {
$keys = array_values($keys);
uksort($values, function ($a, $b) use ($keys) {
return array_search($a, $keys) - array_search($b, $keys);
});
} | [
"public",
"static",
"function",
"order",
"(",
"array",
"&",
"$",
"values",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"keys",
"=",
"array_values",
"(",
"$",
"keys",
")",
";",
"uksort",
"(",
"$",
"values",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"keys",
")",
"{",
"return",
"array_search",
"(",
"$",
"a",
",",
"$",
"keys",
")",
"-",
"array_search",
"(",
"$",
"b",
",",
"$",
"keys",
")",
";",
"}",
")",
";",
"}"
] | Puts an associative array into an arbitrary order.
@param array $values
The array to reorder.
@param array $keys
The keys, in their desired order. | [
"Puts",
"an",
"associative",
"array",
"into",
"an",
"arbitrary",
"order",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element.php#L47-L53 | train |
govCMS/govCMS8 | modules/custom/core/govcms_media/src/Element.php | Element.disableButtons | public static function disableButtons(array $element) {
if (isset($element['#type'])) {
$element['#access'] = !in_array($element['#type'], [
'button',
'submit',
'image_button',
]);
}
// Recurse into child elements.
foreach (RenderElement::children($element) as $key) {
if (is_array($element[$key])) {
$element[$key] = static::disableButtons($element[$key]);
}
}
return $element;
} | php | public static function disableButtons(array $element) {
if (isset($element['#type'])) {
$element['#access'] = !in_array($element['#type'], [
'button',
'submit',
'image_button',
]);
}
// Recurse into child elements.
foreach (RenderElement::children($element) as $key) {
if (is_array($element[$key])) {
$element[$key] = static::disableButtons($element[$key]);
}
}
return $element;
} | [
"public",
"static",
"function",
"disableButtons",
"(",
"array",
"$",
"element",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"element",
"[",
"'#type'",
"]",
")",
")",
"{",
"$",
"element",
"[",
"'#access'",
"]",
"=",
"!",
"in_array",
"(",
"$",
"element",
"[",
"'#type'",
"]",
",",
"[",
"'button'",
",",
"'submit'",
",",
"'image_button'",
",",
"]",
")",
";",
"}",
"// Recurse into child elements.",
"foreach",
"(",
"RenderElement",
"::",
"children",
"(",
"$",
"element",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"element",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"element",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"disableButtons",
"(",
"$",
"element",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"element",
";",
"}"
] | Pre-render function to disable all buttons in a renderable element.
@param array $element
The renderable element.
@return array
The renderable element with all buttons (at all levels) disabled. | [
"Pre",
"-",
"render",
"function",
"to",
"disable",
"all",
"buttons",
"in",
"a",
"renderable",
"element",
"."
] | c5c5b69946bd2e0814a0e7ca3daec23280e33576 | https://github.com/govCMS/govCMS8/blob/c5c5b69946bd2e0814a0e7ca3daec23280e33576/modules/custom/core/govcms_media/src/Element.php#L82-L98 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.