id int32 0 241k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
29,900 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.getResourceByIds | public function getResourceByIds(array $ids, bool $checkIfExist = true): FedoraResource {
echo self::$debug ? "[Fedora] searching for " . implode(', ', $ids) . "\n" : '';
$matches = array();
foreach ($ids as $id) {
try {
$res = $this->getResourceById($id, $checkIfExist);
$matches[$res->getUri(true)] = $res;
} catch (NotFound $e) {
}
}
switch (count($matches)) {
case 0:
echo self::$debug ? " not found\n" : '';
throw new NotFound();
case 1:
echo self::$debug ? " found\n" : '';
return array_pop($matches);
default:
echo self::$debug ? " ambiguosus match: " . implode(', ', array_keys($matches)) . "\n" : '';
throw new AmbiguousMatch();
}
} | php | public function getResourceByIds(array $ids, bool $checkIfExist = true): FedoraResource {
echo self::$debug ? "[Fedora] searching for " . implode(', ', $ids) . "\n" : '';
$matches = array();
foreach ($ids as $id) {
try {
$res = $this->getResourceById($id, $checkIfExist);
$matches[$res->getUri(true)] = $res;
} catch (NotFound $e) {
}
}
switch (count($matches)) {
case 0:
echo self::$debug ? " not found\n" : '';
throw new NotFound();
case 1:
echo self::$debug ? " found\n" : '';
return array_pop($matches);
default:
echo self::$debug ? " ambiguosus match: " . implode(', ', array_keys($matches)) . "\n" : '';
throw new AmbiguousMatch();
}
} | [
"public",
"function",
"getResourceByIds",
"(",
"array",
"$",
"ids",
",",
"bool",
"$",
"checkIfExist",
"=",
"true",
")",
":",
"FedoraResource",
"{",
"echo",
"self",
"::",
"$",
"debug",
"?",
"\"[Fedora] searching for \"",
".",
"implode",
"(",
"', '",
",",
"$",
"ids",
")",
".",
"\"\\n\"",
":",
"''",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"getResourceById",
"(",
"$",
"id",
",",
"$",
"checkIfExist",
")",
";",
"$",
"matches",
"[",
"$",
"res",
"->",
"getUri",
"(",
"true",
")",
"]",
"=",
"$",
"res",
";",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"}",
"}",
"switch",
"(",
"count",
"(",
"$",
"matches",
")",
")",
"{",
"case",
"0",
":",
"echo",
"self",
"::",
"$",
"debug",
"?",
"\" not found\\n\"",
":",
"''",
";",
"throw",
"new",
"NotFound",
"(",
")",
";",
"case",
"1",
":",
"echo",
"self",
"::",
"$",
"debug",
"?",
"\" found\\n\"",
":",
"''",
";",
"return",
"array_pop",
"(",
"$",
"matches",
")",
";",
"default",
":",
"echo",
"self",
"::",
"$",
"debug",
"?",
"\" ambiguosus match: \"",
".",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"matches",
")",
")",
".",
"\"\\n\"",
":",
"''",
";",
"throw",
"new",
"AmbiguousMatch",
"(",
")",
";",
"}",
"}"
] | Finds Fedora resources matching any of provided ids.
@param array $ids
@param bool $checkIfExist should we make sure resource was not deleted
during the current transaction
@return \acdhOeaw\fedora\FedoraResource
@throws NotFound
@throws AmbiguousMatch | [
"Finds",
"Fedora",
"resources",
"matching",
"any",
"of",
"provided",
"ids",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L428-L452 |
29,901 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.getResourcesByProperty | public function getResourcesByProperty(string $property, string $value = '',
bool $checkIfExist = true): array {
$query = new Query();
if ($value != '') {
$param = new HasValue($property, $value);
} else {
$param = new HasProperty($property);
}
$query->addParameter($param);
return $this->getResourcesByQuery($query, '?res', $checkIfExist);
} | php | public function getResourcesByProperty(string $property, string $value = '',
bool $checkIfExist = true): array {
$query = new Query();
if ($value != '') {
$param = new HasValue($property, $value);
} else {
$param = new HasProperty($property);
}
$query->addParameter($param);
return $this->getResourcesByQuery($query, '?res', $checkIfExist);
} | [
"public",
"function",
"getResourcesByProperty",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"value",
"=",
"''",
",",
"bool",
"$",
"checkIfExist",
"=",
"true",
")",
":",
"array",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
")",
";",
"if",
"(",
"$",
"value",
"!=",
"''",
")",
"{",
"$",
"param",
"=",
"new",
"HasValue",
"(",
"$",
"property",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"new",
"HasProperty",
"(",
"$",
"property",
")",
";",
"}",
"$",
"query",
"->",
"addParameter",
"(",
"$",
"param",
")",
";",
"return",
"$",
"this",
"->",
"getResourcesByQuery",
"(",
"$",
"query",
",",
"'?res'",
",",
"$",
"checkIfExist",
")",
";",
"}"
] | Finds all Fedora resources having a given RDF property value.
If the value is not provided, all resources with a given property set
(to any value) are returned.
Be aware that all property values introduced during the transaction
are not taken into account (see documentation of the begin() method)
@param string $property fully qualified property URI
@param string $value optional property value
@param bool $checkIfExist should we make sure resource was not deleted
during the current transaction
@return array
@see begin() | [
"Finds",
"all",
"Fedora",
"resources",
"having",
"a",
"given",
"RDF",
"property",
"value",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L470-L480 |
29,902 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.getResourcesByPropertyRegEx | public function getResourcesByPropertyRegEx(string $property, string $regEx,
string $flags = 'i',
bool $checkIfExist = true): array {
$query = new Query();
$query->addParameter(new MatchesRegEx($property, $regEx, $flags));
return $this->getResourcesByQuery($query, '?res', $checkIfExist);
} | php | public function getResourcesByPropertyRegEx(string $property, string $regEx,
string $flags = 'i',
bool $checkIfExist = true): array {
$query = new Query();
$query->addParameter(new MatchesRegEx($property, $regEx, $flags));
return $this->getResourcesByQuery($query, '?res', $checkIfExist);
} | [
"public",
"function",
"getResourcesByPropertyRegEx",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"regEx",
",",
"string",
"$",
"flags",
"=",
"'i'",
",",
"bool",
"$",
"checkIfExist",
"=",
"true",
")",
":",
"array",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
")",
";",
"$",
"query",
"->",
"addParameter",
"(",
"new",
"MatchesRegEx",
"(",
"$",
"property",
",",
"$",
"regEx",
",",
"$",
"flags",
")",
")",
";",
"return",
"$",
"this",
"->",
"getResourcesByQuery",
"(",
"$",
"query",
",",
"'?res'",
",",
"$",
"checkIfExist",
")",
";",
"}"
] | Finds all Fedora resources with a given RDF property matching given regular expression.
Be aware that all property values introduced during the transaction
are not taken into account (see documentation of the begin() method)
@param string $property fully qualified property URI
@param string $regEx regular expression to match against
@param string $flags regular expression flags (by default "i" - case insensitive)
@param bool $checkIfExist should we make sure resource was not deleted
during the current transaction
@return array
@see begin() | [
"Finds",
"all",
"Fedora",
"resources",
"with",
"a",
"given",
"RDF",
"property",
"matching",
"given",
"regular",
"expression",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L496-L502 |
29,903 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.getResourcesByQuery | public function getResourcesByQuery(Query $query, string $resVar = '?res',
bool $checkIfExist = true): array {
$resVar = preg_replace('|^[?]|', '', $resVar);
$results = $this->runQuery($query);
$resources = array();
foreach ($results as $i) {
try {
$resources[] = $this->getResourceByUri($i->$resVar);
} catch (Deleted $e) {
}
}
if ($checkIfExist) {
$resources = $this->verifyResources($resources);
}
return $resources;
} | php | public function getResourcesByQuery(Query $query, string $resVar = '?res',
bool $checkIfExist = true): array {
$resVar = preg_replace('|^[?]|', '', $resVar);
$results = $this->runQuery($query);
$resources = array();
foreach ($results as $i) {
try {
$resources[] = $this->getResourceByUri($i->$resVar);
} catch (Deleted $e) {
}
}
if ($checkIfExist) {
$resources = $this->verifyResources($resources);
}
return $resources;
} | [
"public",
"function",
"getResourcesByQuery",
"(",
"Query",
"$",
"query",
",",
"string",
"$",
"resVar",
"=",
"'?res'",
",",
"bool",
"$",
"checkIfExist",
"=",
"true",
")",
":",
"array",
"{",
"$",
"resVar",
"=",
"preg_replace",
"(",
"'|^[?]|'",
",",
"''",
",",
"$",
"resVar",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"runQuery",
"(",
"$",
"query",
")",
";",
"$",
"resources",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"i",
")",
"{",
"try",
"{",
"$",
"resources",
"[",
"]",
"=",
"$",
"this",
"->",
"getResourceByUri",
"(",
"$",
"i",
"->",
"$",
"resVar",
")",
";",
"}",
"catch",
"(",
"Deleted",
"$",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"$",
"checkIfExist",
")",
"{",
"$",
"resources",
"=",
"$",
"this",
"->",
"verifyResources",
"(",
"$",
"resources",
")",
";",
"}",
"return",
"$",
"resources",
";",
"}"
] | Finds all Fedora resources satisfying a given SPARQL query.
Be aware that the triplestore state is not affected by all actions
performed during the active transaction.
@param Query $query SPARQL query fetching resources from the triplestore
@param string $resVar name of the SPARQL variable containing resource
URIs
@param bool $checkIfExist should we make sure resource was not deleted
during the current transaction
@return array
@see begin() | [
"Finds",
"all",
"Fedora",
"resources",
"satisfying",
"a",
"given",
"SPARQL",
"query",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L518-L534 |
29,904 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.verifyResources | private function verifyResources(array $resources, bool $force = false): array {
$passed = array();
foreach ($resources as $key => $res) {
try {
$res->getMetadata($force);
$passed[$key] = $res;
} catch (ClientException $e) {
// "410 gone" means the resource was deleted during current transaction
if ($e->getCode() !== 410) {
throw $e;
} else {
$this->cache->delete($res);
}
}
}
return $passed;
} | php | private function verifyResources(array $resources, bool $force = false): array {
$passed = array();
foreach ($resources as $key => $res) {
try {
$res->getMetadata($force);
$passed[$key] = $res;
} catch (ClientException $e) {
// "410 gone" means the resource was deleted during current transaction
if ($e->getCode() !== 410) {
throw $e;
} else {
$this->cache->delete($res);
}
}
}
return $passed;
} | [
"private",
"function",
"verifyResources",
"(",
"array",
"$",
"resources",
",",
"bool",
"$",
"force",
"=",
"false",
")",
":",
"array",
"{",
"$",
"passed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"key",
"=>",
"$",
"res",
")",
"{",
"try",
"{",
"$",
"res",
"->",
"getMetadata",
"(",
"$",
"force",
")",
";",
"$",
"passed",
"[",
"$",
"key",
"]",
"=",
"$",
"res",
";",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"// \"410 gone\" means the resource was deleted during current transaction",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"!==",
"410",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"->",
"delete",
"(",
"$",
"res",
")",
";",
"}",
"}",
"}",
"return",
"$",
"passed",
";",
"}"
] | Removes from an array resources which do not exist anymore.
@param array $resources
@param bool $force should resource be always checked (true) or maybe it
is enough if metadata were already fetched during this session (false)
@return array
@throws \acdhOeaw\fedora\ClientException | [
"Removes",
"from",
"an",
"array",
"resources",
"which",
"do",
"not",
"exist",
"anymore",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L544-L560 |
29,905 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.runQuery | public function runQuery(Query $query): Result {
$query = $query->getQuery();
echo self::$debugSparql ? $query . "\n" : '';
return $this->runSparql($query);
} | php | public function runQuery(Query $query): Result {
$query = $query->getQuery();
echo self::$debugSparql ? $query . "\n" : '';
return $this->runSparql($query);
} | [
"public",
"function",
"runQuery",
"(",
"Query",
"$",
"query",
")",
":",
"Result",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"getQuery",
"(",
")",
";",
"echo",
"self",
"::",
"$",
"debugSparql",
"?",
"$",
"query",
".",
"\"\\n\"",
":",
"''",
";",
"return",
"$",
"this",
"->",
"runSparql",
"(",
"$",
"query",
")",
";",
"}"
] | Runs a SPARQL query defined by a Query object against repository
triplestore.
@param Query $query query to run
@return \EasyRdf\Sparql\Result | [
"Runs",
"a",
"SPARQL",
"query",
"defined",
"by",
"a",
"Query",
"object",
"against",
"repository",
"triplestore",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L569-L575 |
29,906 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.runSparql | public function runSparql(string $query, int $nTries = null): Result {
return $this->sparqlClient->query($query, $nTries ?? $this->sparqlNTries);
} | php | public function runSparql(string $query, int $nTries = null): Result {
return $this->sparqlClient->query($query, $nTries ?? $this->sparqlNTries);
} | [
"public",
"function",
"runSparql",
"(",
"string",
"$",
"query",
",",
"int",
"$",
"nTries",
"=",
"null",
")",
":",
"Result",
"{",
"return",
"$",
"this",
"->",
"sparqlClient",
"->",
"query",
"(",
"$",
"query",
",",
"$",
"nTries",
"??",
"$",
"this",
"->",
"sparqlNTries",
")",
";",
"}"
] | Runs a SPARQL against repository triplestore.
@param string $query SPARQL query to run
@param int $nTries how many times request should be repeated in case of
error before giving up
@return \EasyRdf\Sparql\Result | [
"Runs",
"a",
"SPARQL",
"against",
"repository",
"triplestore",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L585-L587 |
29,907 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.sanitizeUri | public function sanitizeUri(string $uri): string {
if ($uri == '') {
throw new BadMethodCallException('URI is empty');
}
$baseUrl = !$this->txUrl ? $this->apiUrl : $this->txUrl;
$uri = preg_replace('|^/|', '', $uri);
$uri = preg_replace('|^https?://[^/]+/rest/?(tx:[-0-9a-zA-Z]+/)?|', '', $uri);
$uri = $baseUrl . '/' . $uri;
return $uri;
} | php | public function sanitizeUri(string $uri): string {
if ($uri == '') {
throw new BadMethodCallException('URI is empty');
}
$baseUrl = !$this->txUrl ? $this->apiUrl : $this->txUrl;
$uri = preg_replace('|^/|', '', $uri);
$uri = preg_replace('|^https?://[^/]+/rest/?(tx:[-0-9a-zA-Z]+/)?|', '', $uri);
$uri = $baseUrl . '/' . $uri;
return $uri;
} | [
"public",
"function",
"sanitizeUri",
"(",
"string",
"$",
"uri",
")",
":",
"string",
"{",
"if",
"(",
"$",
"uri",
"==",
"''",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'URI is empty'",
")",
";",
"}",
"$",
"baseUrl",
"=",
"!",
"$",
"this",
"->",
"txUrl",
"?",
"$",
"this",
"->",
"apiUrl",
":",
"$",
"this",
"->",
"txUrl",
";",
"$",
"uri",
"=",
"preg_replace",
"(",
"'|^/|'",
",",
"''",
",",
"$",
"uri",
")",
";",
"$",
"uri",
"=",
"preg_replace",
"(",
"'|^https?://[^/]+/rest/?(tx:[-0-9a-zA-Z]+/)?|'",
",",
"''",
",",
"$",
"uri",
")",
";",
"$",
"uri",
"=",
"$",
"baseUrl",
".",
"'/'",
".",
"$",
"uri",
";",
"return",
"$",
"uri",
";",
"}"
] | Adjusts URI to the current object state by setting up the proper base
URL and the transaction id.
@param string $uri resource URI
@return string | [
"Adjusts",
"URI",
"to",
"the",
"current",
"object",
"state",
"by",
"setting",
"up",
"the",
"proper",
"base",
"URL",
"and",
"the",
"transaction",
"id",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L596-L605 |
29,908 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.standardizeUri | public function standardizeUri(string $uri): string {
if ($uri == '') {
throw new BadMethodCallException('URI is empty');
}
if (substr($uri, 0, 1) === '/') {
$uri = substr($uri, 1);
}
$uri = preg_replace('|^https?://[^/]+/rest/(tx:[-0-9a-zA-Z]+/)?|', '', $uri);
$uri = $this->apiUrl . '/' . $uri;
return $uri;
} | php | public function standardizeUri(string $uri): string {
if ($uri == '') {
throw new BadMethodCallException('URI is empty');
}
if (substr($uri, 0, 1) === '/') {
$uri = substr($uri, 1);
}
$uri = preg_replace('|^https?://[^/]+/rest/(tx:[-0-9a-zA-Z]+/)?|', '', $uri);
$uri = $this->apiUrl . '/' . $uri;
return $uri;
} | [
"public",
"function",
"standardizeUri",
"(",
"string",
"$",
"uri",
")",
":",
"string",
"{",
"if",
"(",
"$",
"uri",
"==",
"''",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'URI is empty'",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"1",
")",
"===",
"'/'",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"1",
")",
";",
"}",
"$",
"uri",
"=",
"preg_replace",
"(",
"'|^https?://[^/]+/rest/(tx:[-0-9a-zA-Z]+/)?|'",
",",
"''",
",",
"$",
"uri",
")",
";",
"$",
"uri",
"=",
"$",
"this",
"->",
"apiUrl",
".",
"'/'",
".",
"$",
"uri",
";",
"return",
"$",
"uri",
";",
"}"
] | Transforms an URI into "a canonical form" used in the triplestore to
denote triples subject.
@param string $uri URI to transform
@return string | [
"Transforms",
"an",
"URI",
"into",
"a",
"canonical",
"form",
"used",
"in",
"the",
"triplestore",
"to",
"denote",
"triples",
"subject",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L614-L624 |
29,909 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.begin | public function begin(int $keepAliveTimeout = 90) {
$this->txKeepAlive = $keepAliveTimeout;
$this->txTimestamp = time();
$resp = $this->client->post($this->apiUrl . '/fcr:tx');
$loc = $resp->getHeader('Location');
if (count($loc) == 0) {
throw new RuntimeException('wrong response from fedora');
}
$this->txUrl = $loc[0];
if (function_exists('pcntl_fork')) {
$this->txProcPid = pcntl_fork();
if ($this->txProcPid === 0) {
$this->keepTransactionAlive();
}
} else if (defined('STDIN')) {
if (!function_exists('curl_init')) {
throw new RuntimeException('Please enable the curl extension in your php.ini');
}
$this->txProc = new KeepTransactionAlive($this->txUrl, RC::get('fedoraUser'), RC::get('fedoraPswd'), $this->txKeepAlive);
}
} | php | public function begin(int $keepAliveTimeout = 90) {
$this->txKeepAlive = $keepAliveTimeout;
$this->txTimestamp = time();
$resp = $this->client->post($this->apiUrl . '/fcr:tx');
$loc = $resp->getHeader('Location');
if (count($loc) == 0) {
throw new RuntimeException('wrong response from fedora');
}
$this->txUrl = $loc[0];
if (function_exists('pcntl_fork')) {
$this->txProcPid = pcntl_fork();
if ($this->txProcPid === 0) {
$this->keepTransactionAlive();
}
} else if (defined('STDIN')) {
if (!function_exists('curl_init')) {
throw new RuntimeException('Please enable the curl extension in your php.ini');
}
$this->txProc = new KeepTransactionAlive($this->txUrl, RC::get('fedoraUser'), RC::get('fedoraPswd'), $this->txKeepAlive);
}
} | [
"public",
"function",
"begin",
"(",
"int",
"$",
"keepAliveTimeout",
"=",
"90",
")",
"{",
"$",
"this",
"->",
"txKeepAlive",
"=",
"$",
"keepAliveTimeout",
";",
"$",
"this",
"->",
"txTimestamp",
"=",
"time",
"(",
")",
";",
"$",
"resp",
"=",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"$",
"this",
"->",
"apiUrl",
".",
"'/fcr:tx'",
")",
";",
"$",
"loc",
"=",
"$",
"resp",
"->",
"getHeader",
"(",
"'Location'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"loc",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'wrong response from fedora'",
")",
";",
"}",
"$",
"this",
"->",
"txUrl",
"=",
"$",
"loc",
"[",
"0",
"]",
";",
"if",
"(",
"function_exists",
"(",
"'pcntl_fork'",
")",
")",
"{",
"$",
"this",
"->",
"txProcPid",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"txProcPid",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"keepTransactionAlive",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"defined",
"(",
"'STDIN'",
")",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'curl_init'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Please enable the curl extension in your php.ini'",
")",
";",
"}",
"$",
"this",
"->",
"txProc",
"=",
"new",
"KeepTransactionAlive",
"(",
"$",
"this",
"->",
"txUrl",
",",
"RC",
"::",
"get",
"(",
"'fedoraUser'",
")",
",",
"RC",
"::",
"get",
"(",
"'fedoraPswd'",
")",
",",
"$",
"this",
"->",
"txKeepAlive",
")",
";",
"}",
"}"
] | Starts new Fedora transaction.
Only one transaction can be opened at the same time,
so make sure you committed previous transactions before starting a new one.
Be aware that all metadata modified during the transaction will be not
visible in the triplestore coupled with the Fedora until the transaction
is committed.
@param int $keepAliveTimeout Automatic transaction prolongment timeout
(see the `prolong()` method) - if a Fedora REST API is called and at
least `$keepAliveTimeout` seconds passed since last prolongation, the
transaction will be automatically prolonged.
@see rollback()
@see commit()
@see prolong() | [
"Starts",
"new",
"Fedora",
"transaction",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L644-L666 |
29,910 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.rollback | public function rollback() {
if ($this->txUrl) {
$this->client->post($this->txUrl . '/fcr:tx/fcr:rollback');
$this->txUrl = null;
$this->killKeepTransactionAlive();
}
} | php | public function rollback() {
if ($this->txUrl) {
$this->client->post($this->txUrl . '/fcr:tx/fcr:rollback');
$this->txUrl = null;
$this->killKeepTransactionAlive();
}
} | [
"public",
"function",
"rollback",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"txUrl",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"$",
"this",
"->",
"txUrl",
".",
"'/fcr:tx/fcr:rollback'",
")",
";",
"$",
"this",
"->",
"txUrl",
"=",
"null",
";",
"$",
"this",
"->",
"killKeepTransactionAlive",
"(",
")",
";",
"}",
"}"
] | Rolls back the current Fedora transaction.
@see begin()
@see commit() | [
"Rolls",
"back",
"the",
"current",
"Fedora",
"transaction",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L674-L680 |
29,911 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.prolong | public function prolong(string $txUrl = null) {
$url = $txUrl ?? $this->txUrl;
if ($url) {
if ($url === $this->txUrl) {
$this->txTimestamp = time();
}
$this->client->post($url . '/fcr:tx');
}
} | php | public function prolong(string $txUrl = null) {
$url = $txUrl ?? $this->txUrl;
if ($url) {
if ($url === $this->txUrl) {
$this->txTimestamp = time();
}
$this->client->post($url . '/fcr:tx');
}
} | [
"public",
"function",
"prolong",
"(",
"string",
"$",
"txUrl",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"txUrl",
"??",
"$",
"this",
"->",
"txUrl",
";",
"if",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"url",
"===",
"$",
"this",
"->",
"txUrl",
")",
"{",
"$",
"this",
"->",
"txTimestamp",
"=",
"time",
"(",
")",
";",
"}",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"$",
"url",
".",
"'/fcr:tx'",
")",
";",
"}",
"}"
] | Fedora transactions automatically expire after 3 minutes. If you want
a transaction to be kept longer it must be manually prolonged. This
method does it for you.
@param string $txUrl optional transaction URL. If not provided, current
transaction URL is used.
@see begin() | [
"Fedora",
"transactions",
"automatically",
"expire",
"after",
"3",
"minutes",
".",
"If",
"you",
"want",
"a",
"transaction",
"to",
"be",
"kept",
"longer",
"it",
"must",
"be",
"manually",
"prolonged",
".",
"This",
"method",
"does",
"it",
"for",
"you",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L690-L698 |
29,912 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.commit | public function commit() {
if ($this->txUrl) {
$this->client->post($this->txUrl . '/fcr:tx/fcr:commit');
$this->txUrl = null;
$this->killKeepTransactionAlive();
$this->reindexResources();
}
} | php | public function commit() {
if ($this->txUrl) {
$this->client->post($this->txUrl . '/fcr:tx/fcr:commit');
$this->txUrl = null;
$this->killKeepTransactionAlive();
$this->reindexResources();
}
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"txUrl",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"$",
"this",
"->",
"txUrl",
".",
"'/fcr:tx/fcr:commit'",
")",
";",
"$",
"this",
"->",
"txUrl",
"=",
"null",
";",
"$",
"this",
"->",
"killKeepTransactionAlive",
"(",
")",
";",
"$",
"this",
"->",
"reindexResources",
"(",
")",
";",
"}",
"}"
] | Commits the current Fedora transaction.
After the commit all the metadata modified during the transaction
will be finally available in the triplestore associated with the Fedora.
@see begin()
@see rollback() | [
"Commits",
"the",
"current",
"Fedora",
"transaction",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L720-L728 |
29,913 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.reindexResources | private function reindexResources() {
if (count($this->resToReindex) == 0) {
return;
}
$this->begin();
foreach (array_unique($this->resToReindex) as $i) {
try {
$res = $this->getResourceByUri($i);
$res->setMetadata($res->getMetadata());
$res->updateMetadata();
} catch (Deleted $e) {
} catch (NotFound $e) {
}
}
$this->resToReindex = [];
$this->commit();
} | php | private function reindexResources() {
if (count($this->resToReindex) == 0) {
return;
}
$this->begin();
foreach (array_unique($this->resToReindex) as $i) {
try {
$res = $this->getResourceByUri($i);
$res->setMetadata($res->getMetadata());
$res->updateMetadata();
} catch (Deleted $e) {
} catch (NotFound $e) {
}
}
$this->resToReindex = [];
$this->commit();
} | [
"private",
"function",
"reindexResources",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"resToReindex",
")",
"==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"begin",
"(",
")",
";",
"foreach",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"resToReindex",
")",
"as",
"$",
"i",
")",
"{",
"try",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"getResourceByUri",
"(",
"$",
"i",
")",
";",
"$",
"res",
"->",
"setMetadata",
"(",
"$",
"res",
"->",
"getMetadata",
"(",
")",
")",
";",
"$",
"res",
"->",
"updateMetadata",
"(",
")",
";",
"}",
"catch",
"(",
"Deleted",
"$",
"e",
")",
"{",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"}",
"}",
"$",
"this",
"->",
"resToReindex",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"}"
] | Reindexes resources scheduled for reindexing by issuing a dummy metadata
update. | [
"Reindexes",
"resources",
"scheduled",
"for",
"reindexing",
"by",
"issuing",
"a",
"dummy",
"metadata",
"update",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L734-L753 |
29,914 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.killKeepTransactionAlive | private function killKeepTransactionAlive() {
if ($this->txProcPid > 0) {
posix_kill($this->txProcPid, \SIGKILL);
$status = null;
pcntl_wait($status);
$this->txProcPid = null;
}
if ($this->txProc) {
$this->txProc = null;
}
} | php | private function killKeepTransactionAlive() {
if ($this->txProcPid > 0) {
posix_kill($this->txProcPid, \SIGKILL);
$status = null;
pcntl_wait($status);
$this->txProcPid = null;
}
if ($this->txProc) {
$this->txProc = null;
}
} | [
"private",
"function",
"killKeepTransactionAlive",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"txProcPid",
">",
"0",
")",
"{",
"posix_kill",
"(",
"$",
"this",
"->",
"txProcPid",
",",
"\\",
"SIGKILL",
")",
";",
"$",
"status",
"=",
"null",
";",
"pcntl_wait",
"(",
"$",
"status",
")",
";",
"$",
"this",
"->",
"txProcPid",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"txProc",
")",
"{",
"$",
"this",
"->",
"txProc",
"=",
"null",
";",
"}",
"}"
] | Ends process keeping transaction alive | [
"Ends",
"process",
"keeping",
"transaction",
"alive"
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L772-L782 |
29,915 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/Fedora.php | Fedora.fixMetadataReferences | public function fixMetadataReferences(Resource $meta): Resource {
$properties = array_diff($meta->propertyUris(), array(RC::idProp()));
foreach ($properties as $p) {
foreach ($meta->allResources($p) as $obj) {
$id = null;
$uri = $obj->getUri();
try {
$res = $this->getResourceById($uri);
$id = $res->getId();
} catch (NotFound $e) {
try {
$res = $this->getResourceByUri($uri);
$id = $res->getId();
} catch (NotFound $e) {
} catch (NoAcdhId $e) {
} catch (ClientException $e) {
}
} catch (NoAcdhId $e) {
} catch (ClientException $e) {
}
if ($id !== null && $id !== $obj->getUri()) {
$meta->delete($p, $obj);
$meta->addResource($p, $id);
}
}
}
return $meta;
} | php | public function fixMetadataReferences(Resource $meta): Resource {
$properties = array_diff($meta->propertyUris(), array(RC::idProp()));
foreach ($properties as $p) {
foreach ($meta->allResources($p) as $obj) {
$id = null;
$uri = $obj->getUri();
try {
$res = $this->getResourceById($uri);
$id = $res->getId();
} catch (NotFound $e) {
try {
$res = $this->getResourceByUri($uri);
$id = $res->getId();
} catch (NotFound $e) {
} catch (NoAcdhId $e) {
} catch (ClientException $e) {
}
} catch (NoAcdhId $e) {
} catch (ClientException $e) {
}
if ($id !== null && $id !== $obj->getUri()) {
$meta->delete($p, $obj);
$meta->addResource($p, $id);
}
}
}
return $meta;
} | [
"public",
"function",
"fixMetadataReferences",
"(",
"Resource",
"$",
"meta",
")",
":",
"Resource",
"{",
"$",
"properties",
"=",
"array_diff",
"(",
"$",
"meta",
"->",
"propertyUris",
"(",
")",
",",
"array",
"(",
"RC",
"::",
"idProp",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"p",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"allResources",
"(",
"$",
"p",
")",
"as",
"$",
"obj",
")",
"{",
"$",
"id",
"=",
"null",
";",
"$",
"uri",
"=",
"$",
"obj",
"->",
"getUri",
"(",
")",
";",
"try",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"getResourceById",
"(",
"$",
"uri",
")",
";",
"$",
"id",
"=",
"$",
"res",
"->",
"getId",
"(",
")",
";",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"try",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"getResourceByUri",
"(",
"$",
"uri",
")",
";",
"$",
"id",
"=",
"$",
"res",
"->",
"getId",
"(",
")",
";",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"}",
"catch",
"(",
"NoAcdhId",
"$",
"e",
")",
"{",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"}",
"}",
"catch",
"(",
"NoAcdhId",
"$",
"e",
")",
"{",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"}",
"if",
"(",
"$",
"id",
"!==",
"null",
"&&",
"$",
"id",
"!==",
"$",
"obj",
"->",
"getUri",
"(",
")",
")",
"{",
"$",
"meta",
"->",
"delete",
"(",
"$",
"p",
",",
"$",
"obj",
")",
";",
"$",
"meta",
"->",
"addResource",
"(",
"$",
"p",
",",
"$",
"id",
")",
";",
"}",
"}",
"}",
"return",
"$",
"meta",
";",
"}"
] | Tries to switch references to all repository resources into their UUIDs.
Changes are done in-place!
@param Resource $meta metadata to apply changes to
@return Resource | [
"Tries",
"to",
"switch",
"references",
"to",
"all",
"repository",
"resources",
"into",
"their",
"UUIDs",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/Fedora.php#L800-L833 |
29,916 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/dissemination/Service.php | Service.getFormats | public function getFormats(): array {
$meta = $this->getMetadata();
$formats = array();
foreach ($meta->all(RC::get('fedoraServiceRetFormatProp')) as $i) {
$formats[] = new Format((string) $i);
}
return $formats;
} | php | public function getFormats(): array {
$meta = $this->getMetadata();
$formats = array();
foreach ($meta->all(RC::get('fedoraServiceRetFormatProp')) as $i) {
$formats[] = new Format((string) $i);
}
return $formats;
} | [
"public",
"function",
"getFormats",
"(",
")",
":",
"array",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
")",
";",
"$",
"formats",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"meta",
"->",
"all",
"(",
"RC",
"::",
"get",
"(",
"'fedoraServiceRetFormatProp'",
")",
")",
"as",
"$",
"i",
")",
"{",
"$",
"formats",
"[",
"]",
"=",
"new",
"Format",
"(",
"(",
"string",
")",
"$",
"i",
")",
";",
"}",
"return",
"$",
"formats",
";",
"}"
] | Returns all return formats provided by the dissemination service.
Technically return formats are nothing more then strings. There is no
requirement forcing them to be mime types, etc.
@return array | [
"Returns",
"all",
"return",
"formats",
"provided",
"by",
"the",
"dissemination",
"service",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Service.php#L78-L85 |
29,917 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/dissemination/Service.php | Service.getRequest | public function getRequest(FedoraResource $res): Request {
$uri = $this->getLocation();
$param = $this->getUrlParameters();
$values = $this->getParameterValues($param, $res);
foreach ($values as $k => $v) {
$uri = str_replace($k, $v, $uri);
}
return new Request('GET', $uri);
} | php | public function getRequest(FedoraResource $res): Request {
$uri = $this->getLocation();
$param = $this->getUrlParameters();
$values = $this->getParameterValues($param, $res);
foreach ($values as $k => $v) {
$uri = str_replace($k, $v, $uri);
}
return new Request('GET', $uri);
} | [
"public",
"function",
"getRequest",
"(",
"FedoraResource",
"$",
"res",
")",
":",
"Request",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getLocation",
"(",
")",
";",
"$",
"param",
"=",
"$",
"this",
"->",
"getUrlParameters",
"(",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getParameterValues",
"(",
"$",
"param",
",",
"$",
"res",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"uri",
"=",
"str_replace",
"(",
"$",
"k",
",",
"$",
"v",
",",
"$",
"uri",
")",
";",
"}",
"return",
"new",
"Request",
"(",
"'GET'",
",",
"$",
"uri",
")",
";",
"}"
] | Returns PSR-7 HTTP request disseminating a given resource.
@param FedoraResource $res repository resource to be disseminated
@return Request
@throws RuntimeException | [
"Returns",
"PSR",
"-",
"7",
"HTTP",
"request",
"disseminating",
"a",
"given",
"resource",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Service.php#L93-L103 |
29,918 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/dissemination/Service.php | Service.getRevProxy | public function getRevProxy(): bool {
$meta = $this->getMetadata();
$value = $meta->getLiteral(RC::get('fedoraServiceRevProxyProp'))->getValue();
return $value ?? false;
} | php | public function getRevProxy(): bool {
$meta = $this->getMetadata();
$value = $meta->getLiteral(RC::get('fedoraServiceRevProxyProp'))->getValue();
return $value ?? false;
} | [
"public",
"function",
"getRevProxy",
"(",
")",
":",
"bool",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
")",
";",
"$",
"value",
"=",
"$",
"meta",
"->",
"getLiteral",
"(",
"RC",
"::",
"get",
"(",
"'fedoraServiceRevProxyProp'",
")",
")",
"->",
"getValue",
"(",
")",
";",
"return",
"$",
"value",
"??",
"false",
";",
"}"
] | Should the dissemination service request be reverse-proxied?
If it's not set in the metadata, false is assumed.
@return bool | [
"Should",
"the",
"dissemination",
"service",
"request",
"be",
"reverse",
"-",
"proxied?"
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Service.php#L120-L124 |
29,919 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/dissemination/Service.php | Service.getParameterValues | private function getParameterValues(array $param, FedoraResource $res): array {
$this->getParameters();
$values = [];
foreach ($param as $i) {
$ii = explode('|', substr($i, 1, -1));
$name = array_shift($ii);
if ($name === 'RES_URI') {
$value = Parameter::value($res, '', $res->getUri(true), $ii);
} else if ($name === 'RES_ID') {
$value = Parameter::value($res, '', $res->getId(), $ii);
} else if (isset($this->param[$name])) {
$value = $this->param[$name]->getValue($res, $ii);
} else {
throw new RuntimeException('unknown parameter ' . $name);
}
$values[$i] = $value;
}
return $values;
} | php | private function getParameterValues(array $param, FedoraResource $res): array {
$this->getParameters();
$values = [];
foreach ($param as $i) {
$ii = explode('|', substr($i, 1, -1));
$name = array_shift($ii);
if ($name === 'RES_URI') {
$value = Parameter::value($res, '', $res->getUri(true), $ii);
} else if ($name === 'RES_ID') {
$value = Parameter::value($res, '', $res->getId(), $ii);
} else if (isset($this->param[$name])) {
$value = $this->param[$name]->getValue($res, $ii);
} else {
throw new RuntimeException('unknown parameter ' . $name);
}
$values[$i] = $value;
}
return $values;
} | [
"private",
"function",
"getParameterValues",
"(",
"array",
"$",
"param",
",",
"FedoraResource",
"$",
"res",
")",
":",
"array",
"{",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"param",
"as",
"$",
"i",
")",
"{",
"$",
"ii",
"=",
"explode",
"(",
"'|'",
",",
"substr",
"(",
"$",
"i",
",",
"1",
",",
"-",
"1",
")",
")",
";",
"$",
"name",
"=",
"array_shift",
"(",
"$",
"ii",
")",
";",
"if",
"(",
"$",
"name",
"===",
"'RES_URI'",
")",
"{",
"$",
"value",
"=",
"Parameter",
"::",
"value",
"(",
"$",
"res",
",",
"''",
",",
"$",
"res",
"->",
"getUri",
"(",
"true",
")",
",",
"$",
"ii",
")",
";",
"}",
"else",
"if",
"(",
"$",
"name",
"===",
"'RES_ID'",
")",
"{",
"$",
"value",
"=",
"Parameter",
"::",
"value",
"(",
"$",
"res",
",",
"''",
",",
"$",
"res",
"->",
"getId",
"(",
")",
",",
"$",
"ii",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"param",
"[",
"$",
"name",
"]",
"->",
"getValue",
"(",
"$",
"res",
",",
"$",
"ii",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'unknown parameter '",
".",
"$",
"name",
")",
";",
"}",
"$",
"values",
"[",
"$",
"i",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Evaluates parameter values for a given resource.
@param array $param list of parameters
@param FedoraResource $res repository resource to be disseminated
@return array associative array with parameter values
@throws RuntimeException | [
"Evaluates",
"parameter",
"values",
"for",
"a",
"given",
"resource",
"."
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/Service.php#L144-L165 |
29,920 | diff-sniffer/core | src/Application.php | Application.printVersion | private function printVersion(Command $command)
{
$version = PrettyVersions::getVersion($command->getPackageName());
printf(
'%s version %s' . PHP_EOL,
$command->getName(),
$version->getPrettyVersion()
);
} | php | private function printVersion(Command $command)
{
$version = PrettyVersions::getVersion($command->getPackageName());
printf(
'%s version %s' . PHP_EOL,
$command->getName(),
$version->getPrettyVersion()
);
} | [
"private",
"function",
"printVersion",
"(",
"Command",
"$",
"command",
")",
"{",
"$",
"version",
"=",
"PrettyVersions",
"::",
"getVersion",
"(",
"$",
"command",
"->",
"getPackageName",
"(",
")",
")",
";",
"printf",
"(",
"'%s version %s'",
".",
"PHP_EOL",
",",
"$",
"command",
"->",
"getName",
"(",
")",
",",
"$",
"version",
"->",
"getPrettyVersion",
"(",
")",
")",
";",
"}"
] | Prints command version
@param Command $command | [
"Prints",
"command",
"version"
] | 583369a5f5c91496862f6bdf60b69565da4bc05d | https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/Application.php#L99-L108 |
29,921 | ventoviro/windwalker-core | src/Core/Cache/RuntimeCacheTrait.php | RuntimeCacheTrait.once | protected function once($id, $closure, $refresh = false)
{
$key = $this->getCacheId($id);
$cache = $this->getCacheInstance();
if ($refresh) {
$cache->remove($key);
}
return $cache->call($key, $closure);
} | php | protected function once($id, $closure, $refresh = false)
{
$key = $this->getCacheId($id);
$cache = $this->getCacheInstance();
if ($refresh) {
$cache->remove($key);
}
return $cache->call($key, $closure);
} | [
"protected",
"function",
"once",
"(",
"$",
"id",
",",
"$",
"closure",
",",
"$",
"refresh",
"=",
"false",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getCacheId",
"(",
"$",
"id",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCacheInstance",
"(",
")",
";",
"if",
"(",
"$",
"refresh",
")",
"{",
"$",
"cache",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"cache",
"->",
"call",
"(",
"$",
"key",
",",
"$",
"closure",
")",
";",
"}"
] | Only get once if ID is same.
@param string $id
@param callable $closure
@param bool $refresh
@return mixed
@throws \Psr\Cache\InvalidArgumentException | [
"Only",
"get",
"once",
"if",
"ID",
"is",
"same",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Cache/RuntimeCacheTrait.php#L121-L131 |
29,922 | polyfony-inc/polyfony | Private/Polyfony/HttpRequest.php | HttpRequest.file | public function file($key, $path=null) :self {
// if we have an array of data
if(is_array($key)) {
// for each of those
foreach($key as $index => $path) {
// set them
$this->file($index, $path);
}
}
else {
// add to the list of files
$this->data[$key] = '@'.$path;
}
// return self
return $this;
} | php | public function file($key, $path=null) :self {
// if we have an array of data
if(is_array($key)) {
// for each of those
foreach($key as $index => $path) {
// set them
$this->file($index, $path);
}
}
else {
// add to the list of files
$this->data[$key] = '@'.$path;
}
// return self
return $this;
} | [
"public",
"function",
"file",
"(",
"$",
"key",
",",
"$",
"path",
"=",
"null",
")",
":",
"self",
"{",
"// if we have an array of data",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"// for each of those",
"foreach",
"(",
"$",
"key",
"as",
"$",
"index",
"=>",
"$",
"path",
")",
"{",
"// set them",
"$",
"this",
"->",
"file",
"(",
"$",
"index",
",",
"$",
"path",
")",
";",
"}",
"}",
"else",
"{",
"// add to the list of files",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"'@'",
".",
"$",
"path",
";",
"}",
"// return self",
"return",
"$",
"this",
";",
"}"
] | set a file to be posted | [
"set",
"a",
"file",
"to",
"be",
"posted"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/HttpRequest.php#L96-L111 |
29,923 | polyfony-inc/polyfony | Private/Polyfony/HttpRequest.php | HttpRequest.cookie | public function cookie($key, $value) :self {
// if we have an array of data
if(is_array($key)) {
// for each of those
foreach($key as $index => $value) {
// set them
$this->cookie($index, $value);
}
}
else {
// add to the list of files
$this->cookie[$key] = '@'.$value;
}
// return self
return $this;
} | php | public function cookie($key, $value) :self {
// if we have an array of data
if(is_array($key)) {
// for each of those
foreach($key as $index => $value) {
// set them
$this->cookie($index, $value);
}
}
else {
// add to the list of files
$this->cookie[$key] = '@'.$value;
}
// return self
return $this;
} | [
"public",
"function",
"cookie",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"self",
"{",
"// if we have an array of data",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"// for each of those",
"foreach",
"(",
"$",
"key",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"// set them",
"$",
"this",
"->",
"cookie",
"(",
"$",
"index",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"// add to the list of files",
"$",
"this",
"->",
"cookie",
"[",
"$",
"key",
"]",
"=",
"'@'",
".",
"$",
"value",
";",
"}",
"// return self",
"return",
"$",
"this",
";",
"}"
] | set a cookie | [
"set",
"a",
"cookie"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/HttpRequest.php#L114-L129 |
29,924 | polyfony-inc/polyfony | Private/Polyfony/HttpRequest.php | HttpRequest.send | public function send() :bool {
// initialize
$this->initializeCurl();
$this->configureCurl();
// run & parse
return $this->parseCurl($this->executeCurl());
} | php | public function send() :bool {
// initialize
$this->initializeCurl();
$this->configureCurl();
// run & parse
return $this->parseCurl($this->executeCurl());
} | [
"public",
"function",
"send",
"(",
")",
":",
"bool",
"{",
"// initialize",
"$",
"this",
"->",
"initializeCurl",
"(",
")",
";",
"$",
"this",
"->",
"configureCurl",
"(",
")",
";",
"// run & parse",
"return",
"$",
"this",
"->",
"parseCurl",
"(",
"$",
"this",
"->",
"executeCurl",
"(",
")",
")",
";",
"}"
] | build and send the request | [
"build",
"and",
"send",
"the",
"request"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/HttpRequest.php#L298-L307 |
29,925 | polyfony-inc/polyfony | Private/Polyfony/HttpRequest.php | HttpRequest.getHeader | public function getHeader(string $key) {
// return the header of null if missing
return isset($this->response['headers'][$key]) ?
$this->response['headers'][$key] : null;
} | php | public function getHeader(string $key) {
// return the header of null if missing
return isset($this->response['headers'][$key]) ?
$this->response['headers'][$key] : null;
} | [
"public",
"function",
"getHeader",
"(",
"string",
"$",
"key",
")",
"{",
"// return the header of null if missing",
"return",
"isset",
"(",
"$",
"this",
"->",
"response",
"[",
"'headers'",
"]",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"response",
"[",
"'headers'",
"]",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | get a specific response header | [
"get",
"a",
"specific",
"response",
"header"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/HttpRequest.php#L328-L332 |
29,926 | Blobfolio/blob-common | lib/blobfolio/common/ref/file.php | file.leadingslash | public static function leadingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::leadingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unleadingslash($path);
$path = "/$path";
}
} | php | public static function leadingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::leadingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unleadingslash($path);
$path = "/$path";
}
} | [
"public",
"static",
"function",
"leadingslash",
"(",
"&",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"static",
"::",
"leadingslash",
"(",
"$",
"path",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"else",
"{",
"cast",
"::",
"string",
"(",
"$",
"path",
",",
"true",
")",
";",
"static",
"::",
"unleadingslash",
"(",
"$",
"path",
")",
";",
"$",
"path",
"=",
"\"/$path\"",
";",
"}",
"}"
] | Add Leading Slash
@param string $path Path.
@return void Nothing. | [
"Add",
"Leading",
"Slash"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/ref/file.php#L89-L101 |
29,927 | Blobfolio/blob-common | lib/blobfolio/common/ref/file.php | file.trailingslash | public static function trailingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::trailingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::untrailingslash($path);
$path .= '/';
}
} | php | public static function trailingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::trailingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::untrailingslash($path);
$path .= '/';
}
} | [
"public",
"static",
"function",
"trailingslash",
"(",
"&",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"static",
"::",
"trailingslash",
"(",
"$",
"path",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"else",
"{",
"cast",
"::",
"string",
"(",
"$",
"path",
",",
"true",
")",
";",
"static",
"::",
"untrailingslash",
"(",
"$",
"path",
")",
";",
"$",
"path",
".=",
"'/'",
";",
"}",
"}"
] | Add Trailing Slash
@param string $path Path.
@return void Nothing. | [
"Add",
"Trailing",
"Slash"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/ref/file.php#L179-L191 |
29,928 | Blobfolio/blob-common | lib/blobfolio/common/ref/file.php | file.unixslash | public static function unixslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::unixslash($path[$k]);
}
}
else {
cast::string($path, true);
$path = \str_replace('\\', '/', $path);
$path = \str_replace('/./', '//', $path);
$path = \preg_replace('/\/{2,}/u', '/', $path);
}
} | php | public static function unixslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::unixslash($path[$k]);
}
}
else {
cast::string($path, true);
$path = \str_replace('\\', '/', $path);
$path = \str_replace('/./', '//', $path);
$path = \preg_replace('/\/{2,}/u', '/', $path);
}
} | [
"public",
"static",
"function",
"unixslash",
"(",
"&",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"static",
"::",
"unixslash",
"(",
"$",
"path",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"else",
"{",
"cast",
"::",
"string",
"(",
"$",
"path",
",",
"true",
")",
";",
"$",
"path",
"=",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"\\",
"str_replace",
"(",
"'/./'",
",",
"'//'",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"\\",
"preg_replace",
"(",
"'/\\/{2,}/u'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"}",
"}"
] | Fix Path Slashes
@param string $path Path.
@return void Nothing. | [
"Fix",
"Path",
"Slashes"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/ref/file.php#L199-L212 |
29,929 | Blobfolio/blob-common | lib/blobfolio/common/ref/file.php | file.unleadingslash | public static function unleadingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::unleadingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unixslash($path);
$path = \ltrim($path, '/');
}
} | php | public static function unleadingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::unleadingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unixslash($path);
$path = \ltrim($path, '/');
}
} | [
"public",
"static",
"function",
"unleadingslash",
"(",
"&",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"static",
"::",
"unleadingslash",
"(",
"$",
"path",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"else",
"{",
"cast",
"::",
"string",
"(",
"$",
"path",
",",
"true",
")",
";",
"static",
"::",
"unixslash",
"(",
"$",
"path",
")",
";",
"$",
"path",
"=",
"\\",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"}"
] | Strip Leading Slash
@param string $path Path.
@return void Nothing. | [
"Strip",
"Leading",
"Slash"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/ref/file.php#L220-L232 |
29,930 | Blobfolio/blob-common | lib/blobfolio/common/ref/file.php | file.untrailingslash | public static function untrailingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::untrailingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unixslash($path);
$path = \rtrim($path, '/');
}
} | php | public static function untrailingslash(&$path) {
if (\is_array($path)) {
foreach ($path as $k=>$v) {
static::untrailingslash($path[$k]);
}
}
else {
cast::string($path, true);
static::unixslash($path);
$path = \rtrim($path, '/');
}
} | [
"public",
"static",
"function",
"untrailingslash",
"(",
"&",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"static",
"::",
"untrailingslash",
"(",
"$",
"path",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"else",
"{",
"cast",
"::",
"string",
"(",
"$",
"path",
",",
"true",
")",
";",
"static",
"::",
"unixslash",
"(",
"$",
"path",
")",
";",
"$",
"path",
"=",
"\\",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"}"
] | Strip Trailing Slash
@param string $path Path.
@return void Nothing. | [
"Strip",
"Trailing",
"Slash"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/ref/file.php#L240-L252 |
29,931 | acdh-oeaw/repo-php-util | src/acdhOeaw/fedora/metadataQuery/SimpleQuery.php | SimpleQuery.getQuery | public function getQuery(): string {
$query = $this->query;
$values = $this->values;
$matches = null;
preg_match_all('/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/', $query, $matches);
$matches = count($matches) > 0 ? $matches[0] : array();
foreach ($matches as $i) {
$varName = substr($i, 2);
if ($varName != '') {
if (!isset($this->values[$varName])) {
throw new RuntimeException('no value for variable ' . $varName);
}
$value = $values[$varName];
unset($values[$varName]);
} else {
if (count($values) == 0) {
throw new RuntimeException('number of values lower then the number of variables in the query');
}
$value = array_shift($values);
}
$value = substr($i, 1, 1) == '#' ? QueryParameter::escapeLiteral($value) : QueryParameter::escapeUri($value);
$value = str_replace(array('\\', '$'), array('\\\\', '\\$'), $value); // preg replace special chars escape
$query = preg_replace('/[?][#@]' . $varName . '/', $value, $query, 1);
}
if (count($values) > 0) {
throw new RuntimeException('number of values greater then the number of variables in the query');
}
return $query;
} | php | public function getQuery(): string {
$query = $this->query;
$values = $this->values;
$matches = null;
preg_match_all('/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/', $query, $matches);
$matches = count($matches) > 0 ? $matches[0] : array();
foreach ($matches as $i) {
$varName = substr($i, 2);
if ($varName != '') {
if (!isset($this->values[$varName])) {
throw new RuntimeException('no value for variable ' . $varName);
}
$value = $values[$varName];
unset($values[$varName]);
} else {
if (count($values) == 0) {
throw new RuntimeException('number of values lower then the number of variables in the query');
}
$value = array_shift($values);
}
$value = substr($i, 1, 1) == '#' ? QueryParameter::escapeLiteral($value) : QueryParameter::escapeUri($value);
$value = str_replace(array('\\', '$'), array('\\\\', '\\$'), $value); // preg replace special chars escape
$query = preg_replace('/[?][#@]' . $varName . '/', $value, $query, 1);
}
if (count($values) > 0) {
throw new RuntimeException('number of values greater then the number of variables in the query');
}
return $query;
} | [
"public",
"function",
"getQuery",
"(",
")",
":",
"string",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"values",
";",
"$",
"matches",
"=",
"null",
";",
"preg_match_all",
"(",
"'/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/'",
",",
"$",
"query",
",",
"$",
"matches",
")",
";",
"$",
"matches",
"=",
"count",
"(",
"$",
"matches",
")",
">",
"0",
"?",
"$",
"matches",
"[",
"0",
"]",
":",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"i",
")",
"{",
"$",
"varName",
"=",
"substr",
"(",
"$",
"i",
",",
"2",
")",
";",
"if",
"(",
"$",
"varName",
"!=",
"''",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"varName",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'no value for variable '",
".",
"$",
"varName",
")",
";",
"}",
"$",
"value",
"=",
"$",
"values",
"[",
"$",
"varName",
"]",
";",
"unset",
"(",
"$",
"values",
"[",
"$",
"varName",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'number of values lower then the number of variables in the query'",
")",
";",
"}",
"$",
"value",
"=",
"array_shift",
"(",
"$",
"values",
")",
";",
"}",
"$",
"value",
"=",
"substr",
"(",
"$",
"i",
",",
"1",
",",
"1",
")",
"==",
"'#'",
"?",
"QueryParameter",
"::",
"escapeLiteral",
"(",
"$",
"value",
")",
":",
"QueryParameter",
"::",
"escapeUri",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'$'",
")",
",",
"array",
"(",
"'\\\\\\\\'",
",",
"'\\\\$'",
")",
",",
"$",
"value",
")",
";",
"// preg replace special chars escape",
"$",
"query",
"=",
"preg_replace",
"(",
"'/[?][#@]'",
".",
"$",
"varName",
".",
"'/'",
",",
"$",
"value",
",",
"$",
"query",
",",
"1",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'number of values greater then the number of variables in the query'",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Returns query string ready to send to the SPRAQL endpoint
@return string
@throws RuntimeException | [
"Returns",
"query",
"string",
"ready",
"to",
"send",
"to",
"the",
"SPRAQL",
"endpoint"
] | e22c7cd2613f3c8daf0deee879896d9cd7f61b41 | https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/metadataQuery/SimpleQuery.php#L94-L125 |
29,932 | ventoviro/windwalker-core | src/Core/Mvc/AbstractClassResolver.php | AbstractClassResolver.resolve | public function resolve($name)
{
if (class_exists($name)) {
return $name;
}
$name = static::normalise($name);
$namespaces = clone $this->namespaces;
$this->registerDefaultNamespace($namespaces);
foreach (clone $namespaces as $ns) {
$class = $ns . '\\' . $name;
if (class_exists($class = $this->resolveClassAlias($class))) {
if ($this->baseClass && !is_subclass_of($class, $this->baseClass)) {
throw new \DomainException(sprintf(
'Class: "%s" should be sub class of %s',
$class,
$this->baseClass
));
}
return $class;
}
}
throw new \DomainException(sprintf(
'Can not find any classes with name: "%s" in package: "%s", namespaces: ( %s ).',
$name,
$this->package->getName(),
implode(" |\n ", $namespaces->toArray())
));
} | php | public function resolve($name)
{
if (class_exists($name)) {
return $name;
}
$name = static::normalise($name);
$namespaces = clone $this->namespaces;
$this->registerDefaultNamespace($namespaces);
foreach (clone $namespaces as $ns) {
$class = $ns . '\\' . $name;
if (class_exists($class = $this->resolveClassAlias($class))) {
if ($this->baseClass && !is_subclass_of($class, $this->baseClass)) {
throw new \DomainException(sprintf(
'Class: "%s" should be sub class of %s',
$class,
$this->baseClass
));
}
return $class;
}
}
throw new \DomainException(sprintf(
'Can not find any classes with name: "%s" in package: "%s", namespaces: ( %s ).',
$name,
$this->package->getName(),
implode(" |\n ", $namespaces->toArray())
));
} | [
"public",
"function",
"resolve",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"$",
"name",
"=",
"static",
"::",
"normalise",
"(",
"$",
"name",
")",
";",
"$",
"namespaces",
"=",
"clone",
"$",
"this",
"->",
"namespaces",
";",
"$",
"this",
"->",
"registerDefaultNamespace",
"(",
"$",
"namespaces",
")",
";",
"foreach",
"(",
"clone",
"$",
"namespaces",
"as",
"$",
"ns",
")",
"{",
"$",
"class",
"=",
"$",
"ns",
".",
"'\\\\'",
".",
"$",
"name",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
"=",
"$",
"this",
"->",
"resolveClassAlias",
"(",
"$",
"class",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"baseClass",
"&&",
"!",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"baseClass",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"sprintf",
"(",
"'Class: \"%s\" should be sub class of %s'",
",",
"$",
"class",
",",
"$",
"this",
"->",
"baseClass",
")",
")",
";",
"}",
"return",
"$",
"class",
";",
"}",
"}",
"throw",
"new",
"\\",
"DomainException",
"(",
"sprintf",
"(",
"'Can not find any classes with name: \"%s\" in package: \"%s\", namespaces: ( %s ).'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"package",
"->",
"getName",
"(",
")",
",",
"implode",
"(",
"\" |\\n \"",
",",
"$",
"namespaces",
"->",
"toArray",
"(",
")",
")",
")",
")",
";",
"}"
] | Resolve class path.
@param string $name
@return string
@throws \DomainException | [
"Resolve",
"class",
"path",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Mvc/AbstractClassResolver.php#L73-L107 |
29,933 | Blobfolio/blob-common | lib/blobfolio/common/image.php | image.has_webp | public static function has_webp($cwebp=null, $gif2webp=null) {
// Gotta set it first?
if (null === static::$_webp_gd) {
$image_types = \imagetypes();
static::$_webp_gd = (
(0 !== ($image_types & \IMG_WEBP)) &&
\function_exists('imagewebp') &&
\function_exists('imagecreatefromwebp')
);
}
// See if this system supports the binary method. In general
// we'll just check this once, but if a previous check failed
// and binary paths are supplied, we'll check again.
if (
(null === static::$_webp_binary) ||
(
(false === static::$_webp_binary) &&
$cwebp &&
$gif2webp
)
) {
static::$_webp_binary = false;
// We're using proc_open() to handle execution; if this is
// missing or disabled, we're done.
if (\function_exists('proc_open') && \is_callable('proc_open')) {
// Resolve the binary paths.
if (null === $cwebp) {
$cwebp = constants::CWEBP;
}
else {
$cwebp = (string) $cwebp;
}
if (null === $gif2webp) {
$gif2webp = constants::GIF2WEBP;
}
else {
$gif2webp = (string) $gif2webp;
}
ref\file::path($cwebp, true);
ref\file::path($gif2webp, true);
if (
$cwebp &&
$gif2webp &&
@\is_file($cwebp) &&
@\is_executable($cwebp) &&
@\is_file($gif2webp) &&
@\is_executable($gif2webp)
) {
static::$_webp_binary = array(
'cwebp'=>$cwebp,
'gif2webp'=>$gif2webp,
);
}
}
}
return (static::$_webp_gd || (false !== static::$_webp_binary));
} | php | public static function has_webp($cwebp=null, $gif2webp=null) {
// Gotta set it first?
if (null === static::$_webp_gd) {
$image_types = \imagetypes();
static::$_webp_gd = (
(0 !== ($image_types & \IMG_WEBP)) &&
\function_exists('imagewebp') &&
\function_exists('imagecreatefromwebp')
);
}
// See if this system supports the binary method. In general
// we'll just check this once, but if a previous check failed
// and binary paths are supplied, we'll check again.
if (
(null === static::$_webp_binary) ||
(
(false === static::$_webp_binary) &&
$cwebp &&
$gif2webp
)
) {
static::$_webp_binary = false;
// We're using proc_open() to handle execution; if this is
// missing or disabled, we're done.
if (\function_exists('proc_open') && \is_callable('proc_open')) {
// Resolve the binary paths.
if (null === $cwebp) {
$cwebp = constants::CWEBP;
}
else {
$cwebp = (string) $cwebp;
}
if (null === $gif2webp) {
$gif2webp = constants::GIF2WEBP;
}
else {
$gif2webp = (string) $gif2webp;
}
ref\file::path($cwebp, true);
ref\file::path($gif2webp, true);
if (
$cwebp &&
$gif2webp &&
@\is_file($cwebp) &&
@\is_executable($cwebp) &&
@\is_file($gif2webp) &&
@\is_executable($gif2webp)
) {
static::$_webp_binary = array(
'cwebp'=>$cwebp,
'gif2webp'=>$gif2webp,
);
}
}
}
return (static::$_webp_gd || (false !== static::$_webp_binary));
} | [
"public",
"static",
"function",
"has_webp",
"(",
"$",
"cwebp",
"=",
"null",
",",
"$",
"gif2webp",
"=",
"null",
")",
"{",
"// Gotta set it first?",
"if",
"(",
"null",
"===",
"static",
"::",
"$",
"_webp_gd",
")",
"{",
"$",
"image_types",
"=",
"\\",
"imagetypes",
"(",
")",
";",
"static",
"::",
"$",
"_webp_gd",
"=",
"(",
"(",
"0",
"!==",
"(",
"$",
"image_types",
"&",
"\\",
"IMG_WEBP",
")",
")",
"&&",
"\\",
"function_exists",
"(",
"'imagewebp'",
")",
"&&",
"\\",
"function_exists",
"(",
"'imagecreatefromwebp'",
")",
")",
";",
"}",
"// See if this system supports the binary method. In general",
"// we'll just check this once, but if a previous check failed",
"// and binary paths are supplied, we'll check again.",
"if",
"(",
"(",
"null",
"===",
"static",
"::",
"$",
"_webp_binary",
")",
"||",
"(",
"(",
"false",
"===",
"static",
"::",
"$",
"_webp_binary",
")",
"&&",
"$",
"cwebp",
"&&",
"$",
"gif2webp",
")",
")",
"{",
"static",
"::",
"$",
"_webp_binary",
"=",
"false",
";",
"// We're using proc_open() to handle execution; if this is",
"// missing or disabled, we're done.",
"if",
"(",
"\\",
"function_exists",
"(",
"'proc_open'",
")",
"&&",
"\\",
"is_callable",
"(",
"'proc_open'",
")",
")",
"{",
"// Resolve the binary paths.",
"if",
"(",
"null",
"===",
"$",
"cwebp",
")",
"{",
"$",
"cwebp",
"=",
"constants",
"::",
"CWEBP",
";",
"}",
"else",
"{",
"$",
"cwebp",
"=",
"(",
"string",
")",
"$",
"cwebp",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"gif2webp",
")",
"{",
"$",
"gif2webp",
"=",
"constants",
"::",
"GIF2WEBP",
";",
"}",
"else",
"{",
"$",
"gif2webp",
"=",
"(",
"string",
")",
"$",
"gif2webp",
";",
"}",
"ref",
"\\",
"file",
"::",
"path",
"(",
"$",
"cwebp",
",",
"true",
")",
";",
"ref",
"\\",
"file",
"::",
"path",
"(",
"$",
"gif2webp",
",",
"true",
")",
";",
"if",
"(",
"$",
"cwebp",
"&&",
"$",
"gif2webp",
"&&",
"@",
"\\",
"is_file",
"(",
"$",
"cwebp",
")",
"&&",
"@",
"\\",
"is_executable",
"(",
"$",
"cwebp",
")",
"&&",
"@",
"\\",
"is_file",
"(",
"$",
"gif2webp",
")",
"&&",
"@",
"\\",
"is_executable",
"(",
"$",
"gif2webp",
")",
")",
"{",
"static",
"::",
"$",
"_webp_binary",
"=",
"array",
"(",
"'cwebp'",
"=>",
"$",
"cwebp",
",",
"'gif2webp'",
"=>",
"$",
"gif2webp",
",",
")",
";",
"}",
"}",
"}",
"return",
"(",
"static",
"::",
"$",
"_webp_gd",
"||",
"(",
"false",
"!==",
"static",
"::",
"$",
"_webp_binary",
")",
")",
";",
"}"
] | Check Probable WebP Support
This attempts to check whether PHP natively supports WebP, or
if maybe third-party binaries are installed on the system.
@param string $cwebp Path to cwebp.
@param string $gif2webp Path to gif2webp.
@return bool True/false. | [
"Check",
"Probable",
"WebP",
"Support"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/image.php#L590-L651 |
29,934 | Blobfolio/blob-common | lib/blobfolio/common/image.php | image.svg_dimensions | public static function svg_dimensions($svg) {
ref\cast::string($svg, true);
// Make sure this is SVG-looking.
if (false === ($start = \strpos(\strtolower($svg), '<svg'))) {
if (@\is_file($svg)) {
$svg = \file_get_contents($svg);
if (false === ($start = \strpos(\strtolower($svg), '<svg'))) {
return false;
}
}
else {
return false;
}
}
// Chop the code to the first tag.
$svg = \substr($svg, $start);
if (false === ($end = \strpos($svg, '>'))) {
return false;
}
$svg = \strtolower(\substr($svg, 0, $end + 1));
// Hold our values.
$out = array(
'width'=>null,
'height'=>null,
);
$viewbox = null;
// Search for width, height, and viewbox.
ref\sanitize::whitespace($svg, 0);
\preg_match_all(
'/(height|width|viewbox)\s*=\s*(["\'])((?:(?!\2).)*)\2/',
$svg,
$match,
\PREG_SET_ORDER
);
if (\is_array($match) && \count($match)) {
foreach ($match as $v) {
switch ($v[1]) {
case 'width':
case 'height':
ref\cast::float($v[3], true);
ref\sanitize::to_range($v[3], 0.0);
if ($v[3]) {
$out[$v[1]] = $v[3];
}
break;
case 'viewbox':
// Defer processing for later.
$viewbox = $v[3];
break;
}
}
}
// If we have a width and height, we're done!
if ($out['width'] && $out['height']) {
return $out;
}
// Maybe pull from viewbox?
if (isset($viewbox)) {
$viewbox = \trim(\str_replace(',', ' ', $viewbox));
$viewbox = \explode(' ', $viewbox);
foreach ($viewbox as $k=>$v) {
ref\cast::float($viewbox[$k], true);
ref\sanitize::to_range($viewbox[$k], 0.0);
}
if (\count($viewbox) === 4) {
$out['width'] = $viewbox[2];
$out['height'] = $viewbox[3];
return $out;
}
}
return false;
} | php | public static function svg_dimensions($svg) {
ref\cast::string($svg, true);
// Make sure this is SVG-looking.
if (false === ($start = \strpos(\strtolower($svg), '<svg'))) {
if (@\is_file($svg)) {
$svg = \file_get_contents($svg);
if (false === ($start = \strpos(\strtolower($svg), '<svg'))) {
return false;
}
}
else {
return false;
}
}
// Chop the code to the first tag.
$svg = \substr($svg, $start);
if (false === ($end = \strpos($svg, '>'))) {
return false;
}
$svg = \strtolower(\substr($svg, 0, $end + 1));
// Hold our values.
$out = array(
'width'=>null,
'height'=>null,
);
$viewbox = null;
// Search for width, height, and viewbox.
ref\sanitize::whitespace($svg, 0);
\preg_match_all(
'/(height|width|viewbox)\s*=\s*(["\'])((?:(?!\2).)*)\2/',
$svg,
$match,
\PREG_SET_ORDER
);
if (\is_array($match) && \count($match)) {
foreach ($match as $v) {
switch ($v[1]) {
case 'width':
case 'height':
ref\cast::float($v[3], true);
ref\sanitize::to_range($v[3], 0.0);
if ($v[3]) {
$out[$v[1]] = $v[3];
}
break;
case 'viewbox':
// Defer processing for later.
$viewbox = $v[3];
break;
}
}
}
// If we have a width and height, we're done!
if ($out['width'] && $out['height']) {
return $out;
}
// Maybe pull from viewbox?
if (isset($viewbox)) {
$viewbox = \trim(\str_replace(',', ' ', $viewbox));
$viewbox = \explode(' ', $viewbox);
foreach ($viewbox as $k=>$v) {
ref\cast::float($viewbox[$k], true);
ref\sanitize::to_range($viewbox[$k], 0.0);
}
if (\count($viewbox) === 4) {
$out['width'] = $viewbox[2];
$out['height'] = $viewbox[3];
return $out;
}
}
return false;
} | [
"public",
"static",
"function",
"svg_dimensions",
"(",
"$",
"svg",
")",
"{",
"ref",
"\\",
"cast",
"::",
"string",
"(",
"$",
"svg",
",",
"true",
")",
";",
"// Make sure this is SVG-looking.",
"if",
"(",
"false",
"===",
"(",
"$",
"start",
"=",
"\\",
"strpos",
"(",
"\\",
"strtolower",
"(",
"$",
"svg",
")",
",",
"'<svg'",
")",
")",
")",
"{",
"if",
"(",
"@",
"\\",
"is_file",
"(",
"$",
"svg",
")",
")",
"{",
"$",
"svg",
"=",
"\\",
"file_get_contents",
"(",
"$",
"svg",
")",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"start",
"=",
"\\",
"strpos",
"(",
"\\",
"strtolower",
"(",
"$",
"svg",
")",
",",
"'<svg'",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"// Chop the code to the first tag.",
"$",
"svg",
"=",
"\\",
"substr",
"(",
"$",
"svg",
",",
"$",
"start",
")",
";",
"if",
"(",
"false",
"===",
"(",
"$",
"end",
"=",
"\\",
"strpos",
"(",
"$",
"svg",
",",
"'>'",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"svg",
"=",
"\\",
"strtolower",
"(",
"\\",
"substr",
"(",
"$",
"svg",
",",
"0",
",",
"$",
"end",
"+",
"1",
")",
")",
";",
"// Hold our values.",
"$",
"out",
"=",
"array",
"(",
"'width'",
"=>",
"null",
",",
"'height'",
"=>",
"null",
",",
")",
";",
"$",
"viewbox",
"=",
"null",
";",
"// Search for width, height, and viewbox.",
"ref",
"\\",
"sanitize",
"::",
"whitespace",
"(",
"$",
"svg",
",",
"0",
")",
";",
"\\",
"preg_match_all",
"(",
"'/(height|width|viewbox)\\s*=\\s*([\"\\'])((?:(?!\\2).)*)\\2/'",
",",
"$",
"svg",
",",
"$",
"match",
",",
"\\",
"PREG_SET_ORDER",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"match",
")",
"&&",
"\\",
"count",
"(",
"$",
"match",
")",
")",
"{",
"foreach",
"(",
"$",
"match",
"as",
"$",
"v",
")",
"{",
"switch",
"(",
"$",
"v",
"[",
"1",
"]",
")",
"{",
"case",
"'width'",
":",
"case",
"'height'",
":",
"ref",
"\\",
"cast",
"::",
"float",
"(",
"$",
"v",
"[",
"3",
"]",
",",
"true",
")",
";",
"ref",
"\\",
"sanitize",
"::",
"to_range",
"(",
"$",
"v",
"[",
"3",
"]",
",",
"0.0",
")",
";",
"if",
"(",
"$",
"v",
"[",
"3",
"]",
")",
"{",
"$",
"out",
"[",
"$",
"v",
"[",
"1",
"]",
"]",
"=",
"$",
"v",
"[",
"3",
"]",
";",
"}",
"break",
";",
"case",
"'viewbox'",
":",
"// Defer processing for later.",
"$",
"viewbox",
"=",
"$",
"v",
"[",
"3",
"]",
";",
"break",
";",
"}",
"}",
"}",
"// If we have a width and height, we're done!",
"if",
"(",
"$",
"out",
"[",
"'width'",
"]",
"&&",
"$",
"out",
"[",
"'height'",
"]",
")",
"{",
"return",
"$",
"out",
";",
"}",
"// Maybe pull from viewbox?",
"if",
"(",
"isset",
"(",
"$",
"viewbox",
")",
")",
"{",
"$",
"viewbox",
"=",
"\\",
"trim",
"(",
"\\",
"str_replace",
"(",
"','",
",",
"' '",
",",
"$",
"viewbox",
")",
")",
";",
"$",
"viewbox",
"=",
"\\",
"explode",
"(",
"' '",
",",
"$",
"viewbox",
")",
";",
"foreach",
"(",
"$",
"viewbox",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"ref",
"\\",
"cast",
"::",
"float",
"(",
"$",
"viewbox",
"[",
"$",
"k",
"]",
",",
"true",
")",
";",
"ref",
"\\",
"sanitize",
"::",
"to_range",
"(",
"$",
"viewbox",
"[",
"$",
"k",
"]",
",",
"0.0",
")",
";",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"viewbox",
")",
"===",
"4",
")",
"{",
"$",
"out",
"[",
"'width'",
"]",
"=",
"$",
"viewbox",
"[",
"2",
"]",
";",
"$",
"out",
"[",
"'height'",
"]",
"=",
"$",
"viewbox",
"[",
"3",
"]",
";",
"return",
"$",
"out",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determine SVG Dimensions
@param string $svg SVG content or file path.
@return array|bool Dimensions or false. | [
"Determine",
"SVG",
"Dimensions"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/image.php#L659-L739 |
29,935 | Blobfolio/blob-common | lib/blobfolio/common/image.php | image.to_webp | public static function to_webp(string $from, $to=null, $cwebp=null, $gif2webp=null, bool $refresh=false) {
// Try binaries first, fallback to GD.
return (
static::to_webp_binary($from, $to, $cwebp, $gif2webp, $refresh) ||
static::to_webp_gd($from, $to, $refresh)
);
} | php | public static function to_webp(string $from, $to=null, $cwebp=null, $gif2webp=null, bool $refresh=false) {
// Try binaries first, fallback to GD.
return (
static::to_webp_binary($from, $to, $cwebp, $gif2webp, $refresh) ||
static::to_webp_gd($from, $to, $refresh)
);
} | [
"public",
"static",
"function",
"to_webp",
"(",
"string",
"$",
"from",
",",
"$",
"to",
"=",
"null",
",",
"$",
"cwebp",
"=",
"null",
",",
"$",
"gif2webp",
"=",
"null",
",",
"bool",
"$",
"refresh",
"=",
"false",
")",
"{",
"// Try binaries first, fallback to GD.",
"return",
"(",
"static",
"::",
"to_webp_binary",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"cwebp",
",",
"$",
"gif2webp",
",",
"$",
"refresh",
")",
"||",
"static",
"::",
"to_webp_gd",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"refresh",
")",
")",
";",
"}"
] | Generate WebP From Source
This is a wrapper for the more specific GD and Binary methods
to generate a WebP sister file.
PHP isn't known for its performance, so the binaries are
preferred when available.
@param string $from Source file.
@param string $to Output file.
@param string $cwebp Path to cwebp.
@param string $gif2webp Path to gif2webp.
@param bool $refresh Recreate it.
@return bool True/false. | [
"Generate",
"WebP",
"From",
"Source"
] | 7b43d5526cc9d09853771d950b2956e98e680db1 | https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/image.php#L805-L811 |
29,936 | ventoviro/windwalker-core | src/Core/DateTime/DateTimeTrait.php | DateTimeTrait.convert | public static function convert($date, $from = 'UTC', $to = 'UTC', $format = null)
{
$format = $format ?: self::$format;
$from = new \DateTimeZone($from);
$to = new \DateTimeZone($to);
$date = new static($date, $from);
$date = $date->setTimezone($to);
return $date->format($format, true);
} | php | public static function convert($date, $from = 'UTC', $to = 'UTC', $format = null)
{
$format = $format ?: self::$format;
$from = new \DateTimeZone($from);
$to = new \DateTimeZone($to);
$date = new static($date, $from);
$date = $date->setTimezone($to);
return $date->format($format, true);
} | [
"public",
"static",
"function",
"convert",
"(",
"$",
"date",
",",
"$",
"from",
"=",
"'UTC'",
",",
"$",
"to",
"=",
"'UTC'",
",",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"format",
"=",
"$",
"format",
"?",
":",
"self",
"::",
"$",
"format",
";",
"$",
"from",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"from",
")",
";",
"$",
"to",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"to",
")",
";",
"$",
"date",
"=",
"new",
"static",
"(",
"$",
"date",
",",
"$",
"from",
")",
";",
"$",
"date",
"=",
"$",
"date",
"->",
"setTimezone",
"(",
"$",
"to",
")",
";",
"return",
"$",
"date",
"->",
"format",
"(",
"$",
"format",
",",
"true",
")",
";",
"}"
] | Convert a date string to another timezone.
@param string $date
@param string $from
@param string $to
@param string $format
@return string
@throws \Exception | [
"Convert",
"a",
"date",
"string",
"to",
"another",
"timezone",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/DateTime/DateTimeTrait.php#L150-L161 |
29,937 | ventoviro/windwalker-core | src/Core/DateTime/DateTimeTrait.php | DateTimeTrait.useServerDefaultTimezone | public static function useServerDefaultTimezone($boolean = null)
{
if ($boolean !== null) {
self::$useStz = (bool) $boolean;
return self::$useStz;
}
return self::$useStz;
} | php | public static function useServerDefaultTimezone($boolean = null)
{
if ($boolean !== null) {
self::$useStz = (bool) $boolean;
return self::$useStz;
}
return self::$useStz;
} | [
"public",
"static",
"function",
"useServerDefaultTimezone",
"(",
"$",
"boolean",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"boolean",
"!==",
"null",
")",
"{",
"self",
"::",
"$",
"useStz",
"=",
"(",
"bool",
")",
"$",
"boolean",
";",
"return",
"self",
"::",
"$",
"useStz",
";",
"}",
"return",
"self",
"::",
"$",
"useStz",
";",
"}"
] | Method to set property useServerDefaultTimezone
@param boolean $boolean
@return boolean | [
"Method",
"to",
"set",
"property",
"useServerDefaultTimezone"
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/DateTime/DateTimeTrait.php#L325-L334 |
29,938 | ventoviro/windwalker-core | src/Core/DateTime/DateTimeTrait.php | DateTimeTrait.getNullDate | public static function getNullDate(AbstractDatabaseDriver $db = null)
{
$db = $db ?: Ioc::getDatabase();
return $db->getQuery(true)->getNullDate();
} | php | public static function getNullDate(AbstractDatabaseDriver $db = null)
{
$db = $db ?: Ioc::getDatabase();
return $db->getQuery(true)->getNullDate();
} | [
"public",
"static",
"function",
"getNullDate",
"(",
"AbstractDatabaseDriver",
"$",
"db",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"$",
"db",
"?",
":",
"Ioc",
"::",
"getDatabase",
"(",
")",
";",
"return",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"getNullDate",
"(",
")",
";",
"}"
] | Get NULL date.
@param AbstractDatabaseDriver $db
@return string
@since 3.2.6.1 | [
"Get",
"NULL",
"date",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/DateTime/DateTimeTrait.php#L546-L551 |
29,939 | ventoviro/windwalker-core | src/Core/Console/ConsoleHelper.php | ConsoleHelper.executePackage | public static function executePackage(
$package,
$task,
Request $request,
$config = [],
$appClass = 'Windwalker\Web\Application'
) {
$profile = Ioc::getProfile();
Ioc::setProfile('web');
if (!class_exists($appClass)) {
throw new \LogicException($appClass . ' not found, you have to provide an exists Application class name.');
}
if (!is_subclass_of($appClass, WebApplication::class)) {
throw new \LogicException('Application class should be sub class of ' . WebApplication::class);
}
/** @var WebApplication $app */
$app = new $appClass($request);
$app->boot();
$app->getRouter();
$package = $app->getPackage($package);
$container = $app->getContainer();
$container->share('current.package', $package);
$container->get('config')->load($config);
$response = $package->execute($task, $request, new \Windwalker\Http\Response\Response());
Ioc::setProfile($profile);
return $response;
} | php | public static function executePackage(
$package,
$task,
Request $request,
$config = [],
$appClass = 'Windwalker\Web\Application'
) {
$profile = Ioc::getProfile();
Ioc::setProfile('web');
if (!class_exists($appClass)) {
throw new \LogicException($appClass . ' not found, you have to provide an exists Application class name.');
}
if (!is_subclass_of($appClass, WebApplication::class)) {
throw new \LogicException('Application class should be sub class of ' . WebApplication::class);
}
/** @var WebApplication $app */
$app = new $appClass($request);
$app->boot();
$app->getRouter();
$package = $app->getPackage($package);
$container = $app->getContainer();
$container->share('current.package', $package);
$container->get('config')->load($config);
$response = $package->execute($task, $request, new \Windwalker\Http\Response\Response());
Ioc::setProfile($profile);
return $response;
} | [
"public",
"static",
"function",
"executePackage",
"(",
"$",
"package",
",",
"$",
"task",
",",
"Request",
"$",
"request",
",",
"$",
"config",
"=",
"[",
"]",
",",
"$",
"appClass",
"=",
"'Windwalker\\Web\\Application'",
")",
"{",
"$",
"profile",
"=",
"Ioc",
"::",
"getProfile",
"(",
")",
";",
"Ioc",
"::",
"setProfile",
"(",
"'web'",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"appClass",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"$",
"appClass",
".",
"' not found, you have to provide an exists Application class name.'",
")",
";",
"}",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"appClass",
",",
"WebApplication",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Application class should be sub class of '",
".",
"WebApplication",
"::",
"class",
")",
";",
"}",
"/** @var WebApplication $app */",
"$",
"app",
"=",
"new",
"$",
"appClass",
"(",
"$",
"request",
")",
";",
"$",
"app",
"->",
"boot",
"(",
")",
";",
"$",
"app",
"->",
"getRouter",
"(",
")",
";",
"$",
"package",
"=",
"$",
"app",
"->",
"getPackage",
"(",
"$",
"package",
")",
";",
"$",
"container",
"=",
"$",
"app",
"->",
"getContainer",
"(",
")",
";",
"$",
"container",
"->",
"share",
"(",
"'current.package'",
",",
"$",
"package",
")",
";",
"$",
"container",
"->",
"get",
"(",
"'config'",
")",
"->",
"load",
"(",
"$",
"config",
")",
";",
"$",
"response",
"=",
"$",
"package",
"->",
"execute",
"(",
"$",
"task",
",",
"$",
"request",
",",
"new",
"\\",
"Windwalker",
"\\",
"Http",
"\\",
"Response",
"\\",
"Response",
"(",
")",
")",
";",
"Ioc",
"::",
"setProfile",
"(",
"$",
"profile",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Execute a package in CLI environment.
@param string $package
@param string $task
@param Request $request
@param array $config
@param string $appClass
@return Response
@throws \ReflectionException
@throws \Windwalker\DI\Exception\DependencyResolutionException | [
"Execute",
"a",
"package",
"in",
"CLI",
"environment",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Console/ConsoleHelper.php#L134-L170 |
29,940 | polyfony-inc/polyfony | Private/Polyfony/Format.php | Format.wrap | public static function wrap($text, $phrase, $wrapper = '<strong class="highlight">\\1</strong>') {
if(empty($text)) {
return '';
}
if(empty($phrase)) {
return $text;
}
if(is_array($phrase)) {
foreach ($phrase as $word) {
$pattern[] = '/(' . preg_quote($word, '/') . ')/i';
$replacement[] = $wrapper;
}
}
else {
$pattern = '/('.preg_quote($phrase, '/').')/i';
$replacement = $wrapper;
}
return preg_replace($pattern, $replacement, $text);
} | php | public static function wrap($text, $phrase, $wrapper = '<strong class="highlight">\\1</strong>') {
if(empty($text)) {
return '';
}
if(empty($phrase)) {
return $text;
}
if(is_array($phrase)) {
foreach ($phrase as $word) {
$pattern[] = '/(' . preg_quote($word, '/') . ')/i';
$replacement[] = $wrapper;
}
}
else {
$pattern = '/('.preg_quote($phrase, '/').')/i';
$replacement = $wrapper;
}
return preg_replace($pattern, $replacement, $text);
} | [
"public",
"static",
"function",
"wrap",
"(",
"$",
"text",
",",
"$",
"phrase",
",",
"$",
"wrapper",
"=",
"'<strong class=\"highlight\">\\\\1</strong>'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"text",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"phrase",
")",
")",
"{",
"return",
"$",
"text",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"phrase",
")",
")",
"{",
"foreach",
"(",
"$",
"phrase",
"as",
"$",
"word",
")",
"{",
"$",
"pattern",
"[",
"]",
"=",
"'/('",
".",
"preg_quote",
"(",
"$",
"word",
",",
"'/'",
")",
".",
"')/i'",
";",
"$",
"replacement",
"[",
"]",
"=",
"$",
"wrapper",
";",
"}",
"}",
"else",
"{",
"$",
"pattern",
"=",
"'/('",
".",
"preg_quote",
"(",
"$",
"phrase",
",",
"'/'",
")",
".",
"')/i'",
";",
"$",
"replacement",
"=",
"$",
"wrapper",
";",
"}",
"return",
"preg_replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"text",
")",
";",
"}"
] | will wrap a portion of text in another | [
"will",
"wrap",
"a",
"portion",
"of",
"text",
"in",
"another"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Format.php#L165-L183 |
29,941 | polyfony-inc/polyfony | Private/Polyfony/Format.php | Format.integer | public static function integer($value) :int {
if(strrpos($value, '.')) {
$value = str_replace(',', '' , $value);
}
elseif(strrpos($value, ',')) {
$value = str_replace('.', '' , $value);
}
return(intval(preg_replace('/[^0-9.\-]/', '', str_replace(',', '.' , $value))));
} | php | public static function integer($value) :int {
if(strrpos($value, '.')) {
$value = str_replace(',', '' , $value);
}
elseif(strrpos($value, ',')) {
$value = str_replace('.', '' , $value);
}
return(intval(preg_replace('/[^0-9.\-]/', '', str_replace(',', '.' , $value))));
} | [
"public",
"static",
"function",
"integer",
"(",
"$",
"value",
")",
":",
"int",
"{",
"if",
"(",
"strrpos",
"(",
"$",
"value",
",",
"'.'",
")",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"','",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"strrpos",
"(",
"$",
"value",
",",
"','",
")",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"return",
"(",
"intval",
"(",
"preg_replace",
"(",
"'/[^0-9.\\-]/'",
",",
"''",
",",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"value",
")",
")",
")",
")",
";",
"}"
] | will clean the value of anything but 0-9 and minus preserve sign return integer | [
"will",
"clean",
"the",
"value",
"of",
"anything",
"but",
"0",
"-",
"9",
"and",
"minus",
"preserve",
"sign",
"return",
"integer"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Format.php#L192-L200 |
29,942 | polyfony-inc/polyfony | Private/Polyfony/Format.php | Format.float | public static function float($value, int $precision = 2) :float {
if(strrpos($value, '.')) {
$value = str_replace(',', '' , $value);
}
elseif(strrpos($value, ',')) {
$value = str_replace('.', '' , $value);
}
return(floatval(
round(preg_replace('/[^0-9.\-]/', '', str_replace(',', '.' , $value)), $precision)
));
} | php | public static function float($value, int $precision = 2) :float {
if(strrpos($value, '.')) {
$value = str_replace(',', '' , $value);
}
elseif(strrpos($value, ',')) {
$value = str_replace('.', '' , $value);
}
return(floatval(
round(preg_replace('/[^0-9.\-]/', '', str_replace(',', '.' , $value)), $precision)
));
} | [
"public",
"static",
"function",
"float",
"(",
"$",
"value",
",",
"int",
"$",
"precision",
"=",
"2",
")",
":",
"float",
"{",
"if",
"(",
"strrpos",
"(",
"$",
"value",
",",
"'.'",
")",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"','",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"strrpos",
"(",
"$",
"value",
",",
"','",
")",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"return",
"(",
"floatval",
"(",
"round",
"(",
"preg_replace",
"(",
"'/[^0-9.\\-]/'",
",",
"''",
",",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"value",
")",
")",
",",
"$",
"precision",
")",
")",
")",
";",
"}"
] | will clean the value of anything but 0-9\.- preserve sign return float | [
"will",
"clean",
"the",
"value",
"of",
"anything",
"but",
"0",
"-",
"9",
"\\",
".",
"-",
"preserve",
"sign",
"return",
"float"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Format.php#L203-L213 |
29,943 | polyfony-inc/polyfony | Private/Polyfony/Format.php | Format.csv | public static function csv(array $array, string $separator = "\t", string $encapsulate_cells = '"') :string {
// declare our csv
$csv = '';
// for each line of the array
foreach($array as $cells) {
// for each cell of that line
foreach($cells as $cell) {
// protect the cell's value, encapsulate it, and separate it,
$csv .= $encapsulate_cells . str_replace($encapsulate_cells, '\\'.$encapsulate_cells, $cell) . $encapsulate_cells . $separator;
}
// skip to the next line
$csv .= "\n";
}
// return the formatted csv
return $csv;
} | php | public static function csv(array $array, string $separator = "\t", string $encapsulate_cells = '"') :string {
// declare our csv
$csv = '';
// for each line of the array
foreach($array as $cells) {
// for each cell of that line
foreach($cells as $cell) {
// protect the cell's value, encapsulate it, and separate it,
$csv .= $encapsulate_cells . str_replace($encapsulate_cells, '\\'.$encapsulate_cells, $cell) . $encapsulate_cells . $separator;
}
// skip to the next line
$csv .= "\n";
}
// return the formatted csv
return $csv;
} | [
"public",
"static",
"function",
"csv",
"(",
"array",
"$",
"array",
",",
"string",
"$",
"separator",
"=",
"\"\\t\"",
",",
"string",
"$",
"encapsulate_cells",
"=",
"'\"'",
")",
":",
"string",
"{",
"// declare our csv",
"$",
"csv",
"=",
"''",
";",
"// for each line of the array",
"foreach",
"(",
"$",
"array",
"as",
"$",
"cells",
")",
"{",
"// for each cell of that line",
"foreach",
"(",
"$",
"cells",
"as",
"$",
"cell",
")",
"{",
"// protect the cell's value, encapsulate it, and separate it,",
"$",
"csv",
".=",
"$",
"encapsulate_cells",
".",
"str_replace",
"(",
"$",
"encapsulate_cells",
",",
"'\\\\'",
".",
"$",
"encapsulate_cells",
",",
"$",
"cell",
")",
".",
"$",
"encapsulate_cells",
".",
"$",
"separator",
";",
"}",
"// skip to the next line",
"$",
"csv",
".=",
"\"\\n\"",
";",
"}",
"// return the formatted csv",
"return",
"$",
"csv",
";",
"}"
] | convert an array to a csv | [
"convert",
"an",
"array",
"to",
"a",
"csv"
] | 76dac2f4141c8f480370236295c07dfa52e5c589 | https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Format.php#L216-L233 |
29,944 | secucard/secucard-connect-php-sdk | src/SecucardConnect/Util/MapperUtil.php | MapperUtil.map | public static function map($json, $class, LoggerInterface $logger = null)
{
$mapper = new JsonMapper();
// FIX optional parameters can be null (no phpdoc NULL tag needed)
$mapper->bStrictNullTypes = false;
if (!is_object($json)) {
// must set when json is assoc array
$mapper->bEnforceMapType = false;
}
if (!empty($logger)) {
$mapper->setLogger($logger);
}
return $mapper->map($json, new $class());
} | php | public static function map($json, $class, LoggerInterface $logger = null)
{
$mapper = new JsonMapper();
// FIX optional parameters can be null (no phpdoc NULL tag needed)
$mapper->bStrictNullTypes = false;
if (!is_object($json)) {
// must set when json is assoc array
$mapper->bEnforceMapType = false;
}
if (!empty($logger)) {
$mapper->setLogger($logger);
}
return $mapper->map($json, new $class());
} | [
"public",
"static",
"function",
"map",
"(",
"$",
"json",
",",
"$",
"class",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
"{",
"$",
"mapper",
"=",
"new",
"JsonMapper",
"(",
")",
";",
"// FIX optional parameters can be null (no phpdoc NULL tag needed)",
"$",
"mapper",
"->",
"bStrictNullTypes",
"=",
"false",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"json",
")",
")",
"{",
"// must set when json is assoc array",
"$",
"mapper",
"->",
"bEnforceMapType",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"logger",
")",
")",
"{",
"$",
"mapper",
"->",
"setLogger",
"(",
"$",
"logger",
")",
";",
"}",
"return",
"$",
"mapper",
"->",
"map",
"(",
"$",
"json",
",",
"new",
"$",
"class",
"(",
")",
")",
";",
"}"
] | Mapping JSON string to a instance of a given class.
@param array | object $json The JSON to map, either an assoc. array or object (stdClass), never a string.
@param string $class The full qualified name of the class to map to.
@param LoggerInterface|null $logger
@return mixed The created instance, never null-
@throws \Exception If the mapping could not completed. | [
"Mapping",
"JSON",
"string",
"to",
"a",
"instance",
"of",
"a",
"given",
"class",
"."
] | d990686095e4e02d0924fc12b9bf60140fe8efab | https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/MapperUtil.php#L31-L46 |
29,945 | secucard/secucard-connect-php-sdk | src/SecucardConnect/Util/MapperUtil.php | MapperUtil.jsonEncode | public static function jsonEncode($object, $filter = null, $nullFilter = null)
{
if (!empty($filter) || !empty($nullFilter)) {
$object = clone $object;
$vars = get_object_vars($object);
if (!empty ($filter)) {
foreach ($filter as $prop) {
if (array_key_exists($prop, $vars)) {
unset($object->{$prop});
}
}
}
if (!empty ($nullFilter)) {
foreach ($nullFilter as $prop) {
if (array_key_exists($prop, $vars) && $vars[$prop] === null) {
unset($object->{$prop});
}
}
}
}
return json_encode($object);
} | php | public static function jsonEncode($object, $filter = null, $nullFilter = null)
{
if (!empty($filter) || !empty($nullFilter)) {
$object = clone $object;
$vars = get_object_vars($object);
if (!empty ($filter)) {
foreach ($filter as $prop) {
if (array_key_exists($prop, $vars)) {
unset($object->{$prop});
}
}
}
if (!empty ($nullFilter)) {
foreach ($nullFilter as $prop) {
if (array_key_exists($prop, $vars) && $vars[$prop] === null) {
unset($object->{$prop});
}
}
}
}
return json_encode($object);
} | [
"public",
"static",
"function",
"jsonEncode",
"(",
"$",
"object",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"nullFilter",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
")",
"||",
"!",
"empty",
"(",
"$",
"nullFilter",
")",
")",
"{",
"$",
"object",
"=",
"clone",
"$",
"object",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
")",
")",
"{",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"prop",
",",
"$",
"vars",
")",
")",
"{",
"unset",
"(",
"$",
"object",
"->",
"{",
"$",
"prop",
"}",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"nullFilter",
")",
")",
"{",
"foreach",
"(",
"$",
"nullFilter",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"prop",
",",
"$",
"vars",
")",
"&&",
"$",
"vars",
"[",
"$",
"prop",
"]",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"object",
"->",
"{",
"$",
"prop",
"}",
")",
";",
"}",
"}",
"}",
"}",
"return",
"json_encode",
"(",
"$",
"object",
")",
";",
"}"
] | Encodes the given instance to a JSON string.
@param mixed $object The instance to encode.
@param array|null $filter Array with properties of the given instance to filter.
@param array|null $nullFilter Array with properties of the given instance to filter when null.
@return string The encoded string or false on failure. | [
"Encodes",
"the",
"given",
"instance",
"to",
"a",
"JSON",
"string",
"."
] | d990686095e4e02d0924fc12b9bf60140fe8efab | https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/MapperUtil.php#L55-L79 |
29,946 | secucard/secucard-connect-php-sdk | src/SecucardConnect/Util/MapperUtil.php | MapperUtil.mapResponse | public static function mapResponse(ResponseInterface $response, $class = null, LoggerInterface $logger = null)
{
$dec = self::jsonDecode((string)$response->getBody());
if ($class != null) {
return self::map($dec, $class, $logger);
}
return $dec;
} | php | public static function mapResponse(ResponseInterface $response, $class = null, LoggerInterface $logger = null)
{
$dec = self::jsonDecode((string)$response->getBody());
if ($class != null) {
return self::map($dec, $class, $logger);
}
return $dec;
} | [
"public",
"static",
"function",
"mapResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"class",
"=",
"null",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
"{",
"$",
"dec",
"=",
"self",
"::",
"jsonDecode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"if",
"(",
"$",
"class",
"!=",
"null",
")",
"{",
"return",
"self",
"::",
"map",
"(",
"$",
"dec",
",",
"$",
"class",
",",
"$",
"logger",
")",
";",
"}",
"return",
"$",
"dec",
";",
"}"
] | Maps a response body which contains JSON to an object of a given class or to default PHP types.
@param ResponseInterface $response The response
@param string $class The full qualified name of the class to map to or null to map to default types.
@param LoggerInterface|null $logger
@return mixed The created instance, never null.
@throws \Exception If the mapping could not completed. | [
"Maps",
"a",
"response",
"body",
"which",
"contains",
"JSON",
"to",
"an",
"object",
"of",
"a",
"given",
"class",
"or",
"to",
"default",
"PHP",
"types",
"."
] | d990686095e4e02d0924fc12b9bf60140fe8efab | https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/MapperUtil.php#L89-L96 |
29,947 | secucard/secucard-connect-php-sdk | src/SecucardConnect/Util/MapperUtil.php | MapperUtil.jsonDecode | public static function jsonDecode($json, $assoc = false)
{
$data = \json_decode($json, $assoc);
if (JSON_ERROR_NONE !== json_last_error()) {
$last = json_last_error();
throw new \InvalidArgumentException(
'Unable to parse JSON data: '
. (isset(self::$jsonErrors[$last])
? self::$jsonErrors[$last]
: 'Unknown error')
);
}
return $data;
} | php | public static function jsonDecode($json, $assoc = false)
{
$data = \json_decode($json, $assoc);
if (JSON_ERROR_NONE !== json_last_error()) {
$last = json_last_error();
throw new \InvalidArgumentException(
'Unable to parse JSON data: '
. (isset(self::$jsonErrors[$last])
? self::$jsonErrors[$last]
: 'Unknown error')
);
}
return $data;
} | [
"public",
"static",
"function",
"jsonDecode",
"(",
"$",
"json",
",",
"$",
"assoc",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"\\",
"json_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
")",
";",
"if",
"(",
"JSON_ERROR_NONE",
"!==",
"json_last_error",
"(",
")",
")",
"{",
"$",
"last",
"=",
"json_last_error",
"(",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to parse JSON data: '",
".",
"(",
"isset",
"(",
"self",
"::",
"$",
"jsonErrors",
"[",
"$",
"last",
"]",
")",
"?",
"self",
"::",
"$",
"jsonErrors",
"[",
"$",
"last",
"]",
":",
"'Unknown error'",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Decodes an JSON string into a object with properties of standard PHP types, including stdClass or assoc array.
@param string $json The string to decode.
@param boolean $assoc If true a assoc array is returned.
@return mixed The created object, never null or other. | [
"Decodes",
"an",
"JSON",
"string",
"into",
"a",
"object",
"with",
"properties",
"of",
"standard",
"PHP",
"types",
"including",
"stdClass",
"or",
"assoc",
"array",
"."
] | d990686095e4e02d0924fc12b9bf60140fe8efab | https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Util/MapperUtil.php#L104-L117 |
29,948 | diff-sniffer/core | src/ProjectLoader.php | ProjectLoader.registerClassLoader | public function registerClassLoader() : void
{
if ($this->root === null) {
return;
}
$path = sprintf('%s/%s/autoload.php', $this->root, $this->getVendorDirectory());
if (!is_file($path)) {
return;
}
require $path;
} | php | public function registerClassLoader() : void
{
if ($this->root === null) {
return;
}
$path = sprintf('%s/%s/autoload.php', $this->root, $this->getVendorDirectory());
if (!is_file($path)) {
return;
}
require $path;
} | [
"public",
"function",
"registerClassLoader",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"root",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"path",
"=",
"sprintf",
"(",
"'%s/%s/autoload.php'",
",",
"$",
"this",
"->",
"root",
",",
"$",
"this",
"->",
"getVendorDirectory",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"return",
";",
"}",
"require",
"$",
"path",
";",
"}"
] | Registers class loader if it's defined in the project | [
"Registers",
"class",
"loader",
"if",
"it",
"s",
"defined",
"in",
"the",
"project"
] | 583369a5f5c91496862f6bdf60b69565da4bc05d | https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/ProjectLoader.php#L64-L77 |
29,949 | diff-sniffer/core | src/ProjectLoader.php | ProjectLoader.findProjectRoot | private function findProjectRoot(string $dir) : ?string
{
do {
$path = $dir . '/composer.json';
if (file_exists($path)) {
return $dir;
}
$prev = $dir;
$dir = dirname($dir);
} while ($dir !== $prev);
return null;
} | php | private function findProjectRoot(string $dir) : ?string
{
do {
$path = $dir . '/composer.json';
if (file_exists($path)) {
return $dir;
}
$prev = $dir;
$dir = dirname($dir);
} while ($dir !== $prev);
return null;
} | [
"private",
"function",
"findProjectRoot",
"(",
"string",
"$",
"dir",
")",
":",
"?",
"string",
"{",
"do",
"{",
"$",
"path",
"=",
"$",
"dir",
".",
"'/composer.json'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"dir",
";",
"}",
"$",
"prev",
"=",
"$",
"dir",
";",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"dir",
")",
";",
"}",
"while",
"(",
"$",
"dir",
"!==",
"$",
"prev",
")",
";",
"return",
"null",
";",
"}"
] | Finds project root by locating composer.json located in the current working directory or its closest parent
@param string $dir Current working directory
@return string|null | [
"Finds",
"project",
"root",
"by",
"locating",
"composer",
".",
"json",
"located",
"in",
"the",
"current",
"working",
"directory",
"or",
"its",
"closest",
"parent"
] | 583369a5f5c91496862f6bdf60b69565da4bc05d | https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/ProjectLoader.php#L85-L99 |
29,950 | diff-sniffer/core | src/ProjectLoader.php | ProjectLoader.loadComposerConfiguration | private function loadComposerConfiguration() : array
{
$contents = file_get_contents($this->root . '/composer.json');
$config = json_decode($contents, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException(json_last_error_msg());
}
return $config;
} | php | private function loadComposerConfiguration() : array
{
$contents = file_get_contents($this->root . '/composer.json');
$config = json_decode($contents, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException(json_last_error_msg());
}
return $config;
} | [
"private",
"function",
"loadComposerConfiguration",
"(",
")",
":",
"array",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"root",
".",
"'/composer.json'",
")",
";",
"$",
"config",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"json_last_error_msg",
"(",
")",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Loads composer configuration from the given file
@return array Configuration parameters | [
"Loads",
"composer",
"configuration",
"from",
"the",
"given",
"file"
] | 583369a5f5c91496862f6bdf60b69565da4bc05d | https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/ProjectLoader.php#L121-L131 |
29,951 | diff-sniffer/core | src/ProjectLoader.php | ProjectLoader.massageConfig | private function massageConfig(array $config, string $configPath) : array
{
if (!isset($config['installed_paths'])) {
return $config;
}
$config['installed_paths'] = implode(',', array_map(function ($path) use ($configPath) {
return dirname($configPath) . '/' . $path;
}, explode(',', $config['installed_paths'])));
return $config;
} | php | private function massageConfig(array $config, string $configPath) : array
{
if (!isset($config['installed_paths'])) {
return $config;
}
$config['installed_paths'] = implode(',', array_map(function ($path) use ($configPath) {
return dirname($configPath) . '/' . $path;
}, explode(',', $config['installed_paths'])));
return $config;
} | [
"private",
"function",
"massageConfig",
"(",
"array",
"$",
"config",
",",
"string",
"$",
"configPath",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'installed_paths'",
"]",
")",
")",
"{",
"return",
"$",
"config",
";",
"}",
"$",
"config",
"[",
"'installed_paths'",
"]",
"=",
"implode",
"(",
"','",
",",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"configPath",
")",
"{",
"return",
"dirname",
"(",
"$",
"configPath",
")",
".",
"'/'",
".",
"$",
"path",
";",
"}",
",",
"explode",
"(",
"','",
",",
"$",
"config",
"[",
"'installed_paths'",
"]",
")",
")",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Resolves relative installed paths against the configuration file path
@param array $config Configuration parameters
@param string $configPath Configuration file paths
@return array Configuration parameters | [
"Resolves",
"relative",
"installed",
"paths",
"against",
"the",
"configuration",
"file",
"path"
] | 583369a5f5c91496862f6bdf60b69565da4bc05d | https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/ProjectLoader.php#L155-L166 |
29,952 | ventoviro/windwalker-core | src/Core/Form/AbstractFieldDefinition.php | AbstractFieldDefinition.define | public function define(Form $form)
{
$this->namespaces = new PriorityQueue();
$this->namespaces->insert('Windwalker\Form\Field', PriorityQueue::NORMAL);
$this->bootTraits($this);
$this->form = $form;
$this->doDefine($form);
} | php | public function define(Form $form)
{
$this->namespaces = new PriorityQueue();
$this->namespaces->insert('Windwalker\Form\Field', PriorityQueue::NORMAL);
$this->bootTraits($this);
$this->form = $form;
$this->doDefine($form);
} | [
"public",
"function",
"define",
"(",
"Form",
"$",
"form",
")",
"{",
"$",
"this",
"->",
"namespaces",
"=",
"new",
"PriorityQueue",
"(",
")",
";",
"$",
"this",
"->",
"namespaces",
"->",
"insert",
"(",
"'Windwalker\\Form\\Field'",
",",
"PriorityQueue",
"::",
"NORMAL",
")",
";",
"$",
"this",
"->",
"bootTraits",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"form",
"=",
"$",
"form",
";",
"$",
"this",
"->",
"doDefine",
"(",
"$",
"form",
")",
";",
"}"
] | Define the form fields.
@param Form $form The Windwalker form object.
@return void | [
"Define",
"the",
"form",
"fields",
"."
] | 0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074 | https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Form/AbstractFieldDefinition.php#L99-L109 |
29,953 | elvetemedve/behat-screenshot | src/Bex/Behat/ScreenshotExtension/Service/ScreenshotTaker.php | ScreenshotTaker.takeScreenshot | public function takeScreenshot()
{
try {
$this->screenshots[] = $this->mink->getSession()->getScreenshot();
} catch (UnsupportedDriverActionException $e) {
return;
} catch (\Exception $e) {
$this->output->writeln($e->getMessage());
}
} | php | public function takeScreenshot()
{
try {
$this->screenshots[] = $this->mink->getSession()->getScreenshot();
} catch (UnsupportedDriverActionException $e) {
return;
} catch (\Exception $e) {
$this->output->writeln($e->getMessage());
}
} | [
"public",
"function",
"takeScreenshot",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"screenshots",
"[",
"]",
"=",
"$",
"this",
"->",
"mink",
"->",
"getSession",
"(",
")",
"->",
"getScreenshot",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"return",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Save the screenshot into a local buffer | [
"Save",
"the",
"screenshot",
"into",
"a",
"local",
"buffer"
] | 9860b8d825dab027d0fc975914131fc758561674 | https://github.com/elvetemedve/behat-screenshot/blob/9860b8d825dab027d0fc975914131fc758561674/src/Bex/Behat/ScreenshotExtension/Service/ScreenshotTaker.php#L50-L59 |
29,954 | elvetemedve/behat-screenshot | src/Bex/Behat/ScreenshotExtension/Listener/ScreenshotListener.php | ScreenshotListener.saveScreenshot | public function saveScreenshot(AfterScenarioTested $event)
{
if ($this->shouldSaveScreenshot($event)) {
$fileName = $this->filenameGenerator->generateFileName($event->getFeature(), $event->getScenario());
$image = $this->screenshotTaker->getImage();
$this->screenshotUploader->upload($image, $fileName);
}
$this->screenshotTaker->reset();
} | php | public function saveScreenshot(AfterScenarioTested $event)
{
if ($this->shouldSaveScreenshot($event)) {
$fileName = $this->filenameGenerator->generateFileName($event->getFeature(), $event->getScenario());
$image = $this->screenshotTaker->getImage();
$this->screenshotUploader->upload($image, $fileName);
}
$this->screenshotTaker->reset();
} | [
"public",
"function",
"saveScreenshot",
"(",
"AfterScenarioTested",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldSaveScreenshot",
"(",
"$",
"event",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"filenameGenerator",
"->",
"generateFileName",
"(",
"$",
"event",
"->",
"getFeature",
"(",
")",
",",
"$",
"event",
"->",
"getScenario",
"(",
")",
")",
";",
"$",
"image",
"=",
"$",
"this",
"->",
"screenshotTaker",
"->",
"getImage",
"(",
")",
";",
"$",
"this",
"->",
"screenshotUploader",
"->",
"upload",
"(",
"$",
"image",
",",
"$",
"fileName",
")",
";",
"}",
"$",
"this",
"->",
"screenshotTaker",
"->",
"reset",
"(",
")",
";",
"}"
] | Save screenshot after scanerio if required
@param AfterScenarioTested $event | [
"Save",
"screenshot",
"after",
"scanerio",
"if",
"required"
] | 9860b8d825dab027d0fc975914131fc758561674 | https://github.com/elvetemedve/behat-screenshot/blob/9860b8d825dab027d0fc975914131fc758561674/src/Bex/Behat/ScreenshotExtension/Listener/ScreenshotListener.php#L92-L101 |
29,955 | elvetemedve/behat-screenshot | src/Bex/Behat/ScreenshotExtension/Output/IndentedOutput.php | IndentedOutput.setFormatter | public function setFormatter(\Symfony\Component\Console\Formatter\OutputFormatterInterface $formatter)
{
$this->decoratedOutput->setFormatter($formatter);
} | php | public function setFormatter(\Symfony\Component\Console\Formatter\OutputFormatterInterface $formatter)
{
$this->decoratedOutput->setFormatter($formatter);
} | [
"public",
"function",
"setFormatter",
"(",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Formatter",
"\\",
"OutputFormatterInterface",
"$",
"formatter",
")",
"{",
"$",
"this",
"->",
"decoratedOutput",
"->",
"setFormatter",
"(",
"$",
"formatter",
")",
";",
"}"
] | Sets output formatter.
@param \Symfony\Component\Console\Formatter\OutputFormatterInterface $formatter | [
"Sets",
"output",
"formatter",
"."
] | 9860b8d825dab027d0fc975914131fc758561674 | https://github.com/elvetemedve/behat-screenshot/blob/9860b8d825dab027d0fc975914131fc758561674/src/Bex/Behat/ScreenshotExtension/Output/IndentedOutput.php#L160-L163 |
29,956 | elvetemedve/behat-screenshot | src/Bex/Behat/ScreenshotExtension/Output/IndentedOutput.php | IndentedOutput.addIndentationToMessages | private function addIndentationToMessages($messages)
{
if (is_array($messages)) {
array_walk(
$messages,
function ($message) {
return $this->indentation . $message;
}
);
return $messages;
} else {
$messages = $this->indentation . $messages;
return $messages;
}
} | php | private function addIndentationToMessages($messages)
{
if (is_array($messages)) {
array_walk(
$messages,
function ($message) {
return $this->indentation . $message;
}
);
return $messages;
} else {
$messages = $this->indentation . $messages;
return $messages;
}
} | [
"private",
"function",
"addIndentationToMessages",
"(",
"$",
"messages",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"messages",
")",
")",
"{",
"array_walk",
"(",
"$",
"messages",
",",
"function",
"(",
"$",
"message",
")",
"{",
"return",
"$",
"this",
"->",
"indentation",
".",
"$",
"message",
";",
"}",
")",
";",
"return",
"$",
"messages",
";",
"}",
"else",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"indentation",
".",
"$",
"messages",
";",
"return",
"$",
"messages",
";",
"}",
"}"
] | Prepend message with padding
@param $messages
@return array|string | [
"Prepend",
"message",
"with",
"padding"
] | 9860b8d825dab027d0fc975914131fc758561674 | https://github.com/elvetemedve/behat-screenshot/blob/9860b8d825dab027d0fc975914131fc758561674/src/Bex/Behat/ScreenshotExtension/Output/IndentedOutput.php#L182-L196 |
29,957 | elvetemedve/behat-screenshot | src/Bex/Behat/ScreenshotExtension/ServiceContainer/Config.php | Config.loadServices | public function loadServices(ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.xml');
$this->imageDrivers = $this->driverLocator->findDrivers(
$container,
$this->imageDriverKeys,
$this->imageDriverConfigs
);
} | php | public function loadServices(ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.xml');
$this->imageDrivers = $this->driverLocator->findDrivers(
$container,
$this->imageDriverKeys,
$this->imageDriverConfigs
);
} | [
"public",
"function",
"loadServices",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"loader",
"=",
"new",
"XmlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.xml'",
")",
";",
"$",
"this",
"->",
"imageDrivers",
"=",
"$",
"this",
"->",
"driverLocator",
"->",
"findDrivers",
"(",
"$",
"container",
",",
"$",
"this",
"->",
"imageDriverKeys",
",",
"$",
"this",
"->",
"imageDriverConfigs",
")",
";",
"}"
] | Init service container and load image drivers
@param ContainerBuilder $container | [
"Init",
"service",
"container",
"and",
"load",
"image",
"drivers"
] | 9860b8d825dab027d0fc975914131fc758561674 | https://github.com/elvetemedve/behat-screenshot/blob/9860b8d825dab027d0fc975914131fc758561674/src/Bex/Behat/ScreenshotExtension/ServiceContainer/Config.php#L120-L129 |
29,958 | flash-global/connect-client | src/MetadataProvider.php | MetadataProvider.getSPEntityConfiguration | public function getSPEntityConfiguration($entityID)
{
$url = $this->buildUrl(self::API_IDP . '?entityID=' . $entityID);
$request = (new RequestDescriptor())
->setMethod('GET')
->setUrl($url);
$response = $this->send($request);
$extractor = (new MessageExtractor())->setHydrator(new MessageHydrator());
/** @var SignedMessageDecorator $message */
$message = $extractor->extract(\json_decode($response->getBody(), true));
return $message->getMessage();
} | php | public function getSPEntityConfiguration($entityID)
{
$url = $this->buildUrl(self::API_IDP . '?entityID=' . $entityID);
$request = (new RequestDescriptor())
->setMethod('GET')
->setUrl($url);
$response = $this->send($request);
$extractor = (new MessageExtractor())->setHydrator(new MessageHydrator());
/** @var SignedMessageDecorator $message */
$message = $extractor->extract(\json_decode($response->getBody(), true));
return $message->getMessage();
} | [
"public",
"function",
"getSPEntityConfiguration",
"(",
"$",
"entityID",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"buildUrl",
"(",
"self",
"::",
"API_IDP",
".",
"'?entityID='",
".",
"$",
"entityID",
")",
";",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setMethod",
"(",
"'GET'",
")",
"->",
"setUrl",
"(",
"$",
"url",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
";",
"$",
"extractor",
"=",
"(",
"new",
"MessageExtractor",
"(",
")",
")",
"->",
"setHydrator",
"(",
"new",
"MessageHydrator",
"(",
")",
")",
";",
"/** @var SignedMessageDecorator $message */",
"$",
"message",
"=",
"$",
"extractor",
"->",
"extract",
"(",
"\\",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
")",
";",
"return",
"$",
"message",
"->",
"getMessage",
"(",
")",
";",
"}"
] | Get the SP entity configuration from Connect IdP
@param string $entityID
@return SpEntityConfigurationMessage | [
"Get",
"the",
"SP",
"entity",
"configuration",
"from",
"Connect",
"IdP"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/MetadataProvider.php#L86-L102 |
29,959 | flash-global/connect-client | src/Config/ConfigConsistency.php | ConfigConsistency.createRSAPrivateKey | public function createRSAPrivateKey()
{
$path = $this->getConfig()->getPrivateKeyFilePath();
$this->createDir($path);
$this->getConfig()->setPrivateKey((new RsaKeyGen())->createPrivateKey());
if (@file_put_contents($path, $this->getConfig()->getPrivateKey()) === false) {
throw new \Exception('Error when writing the RSA private key');
}
} | php | public function createRSAPrivateKey()
{
$path = $this->getConfig()->getPrivateKeyFilePath();
$this->createDir($path);
$this->getConfig()->setPrivateKey((new RsaKeyGen())->createPrivateKey());
if (@file_put_contents($path, $this->getConfig()->getPrivateKey()) === false) {
throw new \Exception('Error when writing the RSA private key');
}
} | [
"public",
"function",
"createRSAPrivateKey",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getPrivateKeyFilePath",
"(",
")",
";",
"$",
"this",
"->",
"createDir",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"setPrivateKey",
"(",
"(",
"new",
"RsaKeyGen",
"(",
")",
")",
"->",
"createPrivateKey",
"(",
")",
")",
";",
"if",
"(",
"@",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getPrivateKey",
"(",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Error when writing the RSA private key'",
")",
";",
"}",
"}"
] | Create and write the RSA private file
@throws \Exception | [
"Create",
"and",
"write",
"the",
"RSA",
"private",
"file"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Config/ConfigConsistency.php#L107-L116 |
29,960 | flash-global/connect-client | src/Config/ConfigConsistency.php | ConfigConsistency.createIdpMetadataFile | protected function createIdpMetadataFile()
{
$url = $this->getConfig()->getIdpEntityID() . $this->getConfig()->getIdpMetadataFileTarget();
try {
$idp = file_get_contents($url);
$path = $this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getIdpMetadataFile();
$this->createDir($path);
if (@file_put_contents($path, $idp) === false) {
throw new \Exception(sprintf('Unable to write IdP Metadata on %s', $path));
}
} catch (\Exception $e) {
throw new \Exception(sprintf('Unable to fetch IdP Metadata on %s', $url));
}
} | php | protected function createIdpMetadataFile()
{
$url = $this->getConfig()->getIdpEntityID() . $this->getConfig()->getIdpMetadataFileTarget();
try {
$idp = file_get_contents($url);
$path = $this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getIdpMetadataFile();
$this->createDir($path);
if (@file_put_contents($path, $idp) === false) {
throw new \Exception(sprintf('Unable to write IdP Metadata on %s', $path));
}
} catch (\Exception $e) {
throw new \Exception(sprintf('Unable to fetch IdP Metadata on %s', $url));
}
} | [
"protected",
"function",
"createIdpMetadataFile",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getIdpEntityID",
"(",
")",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getIdpMetadataFileTarget",
"(",
")",
";",
"try",
"{",
"$",
"idp",
"=",
"file_get_contents",
"(",
"$",
"url",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getSamlMetadataBaseDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getIdpMetadataFile",
"(",
")",
";",
"$",
"this",
"->",
"createDir",
"(",
"$",
"path",
")",
";",
"if",
"(",
"@",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"idp",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to write IdP Metadata on %s'",
",",
"$",
"path",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to fetch IdP Metadata on %s'",
",",
"$",
"url",
")",
")",
";",
"}",
"}"
] | Create and write the IdP metadata XML file
@throws \Exception | [
"Create",
"and",
"write",
"the",
"IdP",
"metadata",
"XML",
"file"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Config/ConfigConsistency.php#L123-L138 |
29,961 | flash-global/connect-client | src/Config/ConfigConsistency.php | ConfigConsistency.createSpMetadataFile | protected function createSpMetadataFile()
{
$url = $this->getConfig()->getIdpEntityID();
$entityID = $this->getConfig()->getEntityID();
$metadataProvider = new MetadataProvider([MetadataProvider::OPTION_BASEURL => $url]);
try {
$message = $metadataProvider->getSPEntityConfiguration($entityID);
} catch (\Exception $e) {
$message = new SpEntityConfigurationMessage();
}
if (empty($message->getXml())) {
if (!$message->getId()) {
if (!$this->validateIdpMetadata()) {
throw new \Exception('Unable to send registration request due to not found IdP metadata file');
}
$idp = (new Metadata())->createEntityDescriptor(
file_get_contents(
$this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getIdpMetadataFile()
)
)->getFirstIdpSsoDescriptor();
$metadataProvider->subscribeApplication($this->getConfig(), $idp);
}
return false;
}
$path = $this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getSpMetadataFile();
$this->createDir($path);
if (@file_put_contents($path, $message->getXml()) === false) {
throw new \Exception('Error in Sp MetadataFile writing');
}
return true;
} | php | protected function createSpMetadataFile()
{
$url = $this->getConfig()->getIdpEntityID();
$entityID = $this->getConfig()->getEntityID();
$metadataProvider = new MetadataProvider([MetadataProvider::OPTION_BASEURL => $url]);
try {
$message = $metadataProvider->getSPEntityConfiguration($entityID);
} catch (\Exception $e) {
$message = new SpEntityConfigurationMessage();
}
if (empty($message->getXml())) {
if (!$message->getId()) {
if (!$this->validateIdpMetadata()) {
throw new \Exception('Unable to send registration request due to not found IdP metadata file');
}
$idp = (new Metadata())->createEntityDescriptor(
file_get_contents(
$this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getIdpMetadataFile()
)
)->getFirstIdpSsoDescriptor();
$metadataProvider->subscribeApplication($this->getConfig(), $idp);
}
return false;
}
$path = $this->getConfig()->getSamlMetadataBaseDir() . '/' . $this->getConfig()->getSpMetadataFile();
$this->createDir($path);
if (@file_put_contents($path, $message->getXml()) === false) {
throw new \Exception('Error in Sp MetadataFile writing');
}
return true;
} | [
"protected",
"function",
"createSpMetadataFile",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getIdpEntityID",
"(",
")",
";",
"$",
"entityID",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getEntityID",
"(",
")",
";",
"$",
"metadataProvider",
"=",
"new",
"MetadataProvider",
"(",
"[",
"MetadataProvider",
"::",
"OPTION_BASEURL",
"=>",
"$",
"url",
"]",
")",
";",
"try",
"{",
"$",
"message",
"=",
"$",
"metadataProvider",
"->",
"getSPEntityConfiguration",
"(",
"$",
"entityID",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"new",
"SpEntityConfigurationMessage",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"message",
"->",
"getXml",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"message",
"->",
"getId",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateIdpMetadata",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unable to send registration request due to not found IdP metadata file'",
")",
";",
"}",
"$",
"idp",
"=",
"(",
"new",
"Metadata",
"(",
")",
")",
"->",
"createEntityDescriptor",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getSamlMetadataBaseDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getIdpMetadataFile",
"(",
")",
")",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
";",
"$",
"metadataProvider",
"->",
"subscribeApplication",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
",",
"$",
"idp",
")",
";",
"}",
"return",
"false",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getSamlMetadataBaseDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getSpMetadataFile",
"(",
")",
";",
"$",
"this",
"->",
"createDir",
"(",
"$",
"path",
")",
";",
"if",
"(",
"@",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"message",
"->",
"getXml",
"(",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Error in Sp MetadataFile writing'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Create and write the SP metadata XML file
@throws \Exception | [
"Create",
"and",
"write",
"the",
"SP",
"metadata",
"XML",
"file"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Config/ConfigConsistency.php#L145-L184 |
29,962 | flash-global/connect-client | src/Exception/PingException.php | PingException.getResponse | public function getResponse()
{
$response = new Response();
$message = new Message();
$message->setData(['message' => $this->getMessage()]);
if (!empty($this->getPrivateKey())) {
$message->setCertificate($this->getCertificate());
$message->sign($this->getPrivateKey());
}
$response->getBody()->write(json_encode($message));
return $response
->withStatus($this->getCode())
->withAddedHeader('Content-Type', 'application/json');
} | php | public function getResponse()
{
$response = new Response();
$message = new Message();
$message->setData(['message' => $this->getMessage()]);
if (!empty($this->getPrivateKey())) {
$message->setCertificate($this->getCertificate());
$message->sign($this->getPrivateKey());
}
$response->getBody()->write(json_encode($message));
return $response
->withStatus($this->getCode())
->withAddedHeader('Content-Type', 'application/json');
} | [
"public",
"function",
"getResponse",
"(",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"message",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"message",
"->",
"setData",
"(",
"[",
"'message'",
"=>",
"$",
"this",
"->",
"getMessage",
"(",
")",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
")",
")",
"{",
"$",
"message",
"->",
"setCertificate",
"(",
"$",
"this",
"->",
"getCertificate",
"(",
")",
")",
";",
"$",
"message",
"->",
"sign",
"(",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
")",
";",
"}",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"message",
")",
")",
";",
"return",
"$",
"response",
"->",
"withStatus",
"(",
"$",
"this",
"->",
"getCode",
"(",
")",
")",
"->",
"withAddedHeader",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
";",
"}"
] | Returns a ResponseInterface method
@return \Psr\Http\Message\ResponseInterface | [
"Returns",
"a",
"ResponseInterface",
"method"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Exception/PingException.php#L79-L96 |
29,963 | flash-global/connect-client | src/Config/Config.php | Config.registerProfileAssociation | public function registerProfileAssociation(
callable $callback,
$profileAssociationPath = '/connect/profile-association'
) {
$this->profileAssociationCallback = $callback;
$this->profileAssociationPath = $profileAssociationPath;
return $this;
} | php | public function registerProfileAssociation(
callable $callback,
$profileAssociationPath = '/connect/profile-association'
) {
$this->profileAssociationCallback = $callback;
$this->profileAssociationPath = $profileAssociationPath;
return $this;
} | [
"public",
"function",
"registerProfileAssociation",
"(",
"callable",
"$",
"callback",
",",
"$",
"profileAssociationPath",
"=",
"'/connect/profile-association'",
")",
"{",
"$",
"this",
"->",
"profileAssociationCallback",
"=",
"$",
"callback",
";",
"$",
"this",
"->",
"profileAssociationPath",
"=",
"$",
"profileAssociationPath",
";",
"return",
"$",
"this",
";",
"}"
] | Register a profile association callback
@param callable $callback
@param string $profileAssociationPath
@return $this | [
"Register",
"a",
"profile",
"association",
"callback"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Config/Config.php#L345-L353 |
29,964 | flash-global/connect-client | src/Metadata.php | Metadata.load | public static function load($idpMetadataFilePath, $spMetadataFilePath)
{
$metadata = (new static());
return $metadata
->setIdentityProvider($metadata->createEntityDescriptor(file_get_contents($idpMetadataFilePath)))
->setServiceProvider($metadata->createEntityDescriptor(file_get_contents($spMetadataFilePath)));
} | php | public static function load($idpMetadataFilePath, $spMetadataFilePath)
{
$metadata = (new static());
return $metadata
->setIdentityProvider($metadata->createEntityDescriptor(file_get_contents($idpMetadataFilePath)))
->setServiceProvider($metadata->createEntityDescriptor(file_get_contents($spMetadataFilePath)));
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"idpMetadataFilePath",
",",
"$",
"spMetadataFilePath",
")",
"{",
"$",
"metadata",
"=",
"(",
"new",
"static",
"(",
")",
")",
";",
"return",
"$",
"metadata",
"->",
"setIdentityProvider",
"(",
"$",
"metadata",
"->",
"createEntityDescriptor",
"(",
"file_get_contents",
"(",
"$",
"idpMetadataFilePath",
")",
")",
")",
"->",
"setServiceProvider",
"(",
"$",
"metadata",
"->",
"createEntityDescriptor",
"(",
"file_get_contents",
"(",
"$",
"spMetadataFilePath",
")",
")",
")",
";",
"}"
] | Create an instance of Metadata
@param string $idpMetadataFilePath
@param string $spMetadataFilePath
@return Metadata | [
"Create",
"an",
"instance",
"of",
"Metadata"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Metadata.php#L33-L40 |
29,965 | flash-global/connect-client | src/Metadata.php | Metadata.createEntityDescriptor | public function createEntityDescriptor($xml)
{
$deserializationContext = new DeserializationContext();
$deserializationContext->getDocument()->loadXML($xml);
$ed = new EntityDescriptor();
$ed->deserialize($deserializationContext->getDocument(), $deserializationContext);
return $ed;
} | php | public function createEntityDescriptor($xml)
{
$deserializationContext = new DeserializationContext();
$deserializationContext->getDocument()->loadXML($xml);
$ed = new EntityDescriptor();
$ed->deserialize($deserializationContext->getDocument(), $deserializationContext);
return $ed;
} | [
"public",
"function",
"createEntityDescriptor",
"(",
"$",
"xml",
")",
"{",
"$",
"deserializationContext",
"=",
"new",
"DeserializationContext",
"(",
")",
";",
"$",
"deserializationContext",
"->",
"getDocument",
"(",
")",
"->",
"loadXML",
"(",
"$",
"xml",
")",
";",
"$",
"ed",
"=",
"new",
"EntityDescriptor",
"(",
")",
";",
"$",
"ed",
"->",
"deserialize",
"(",
"$",
"deserializationContext",
"->",
"getDocument",
"(",
")",
",",
"$",
"deserializationContext",
")",
";",
"return",
"$",
"ed",
";",
"}"
] | Create an EntityDescriptor instance with its XML metadata contents
@param string $xml
@return EntityDescriptor | [
"Create",
"an",
"EntityDescriptor",
"instance",
"with",
"its",
"XML",
"metadata",
"contents"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Metadata.php#L175-L184 |
29,966 | flash-global/connect-client | src/Connect.php | Connect.handleRequest | public function handleRequest($requestUri = null, $requestMethod = null)
{
if (!$this->isConfigConsistent() && false) {
throw new \LogicException('The client configuration is not consistent');
}
$pathInfo = $requestUri;
if (false !== $pos = strpos($pathInfo, '?')) {
$pathInfo = substr($pathInfo, 0, $pos);
}
$pathInfo = rawurldecode($pathInfo);
$info = $this->getDispatcher()->dispatch($requestMethod, $pathInfo);
if ($info[0] == Dispatcher::FOUND) {
try {
$response = $info[1]($this);
if ($response instanceof ResponseInterface) {
$this->setResponse($response);
}
} catch (ResponseExceptionInterface $e) {
$this->setResponse($e->getResponse());
}
} elseif (!$this->isAuthenticated()) {
if (strtoupper($requestMethod) == 'GET') {
$_SESSION[self::class][$this->getConfig()->getEntityID()]['targeted_path'] = $requestUri;
}
$request = $this->getSaml()->buildAuthnRequest();
$_SESSION[self::class][$this->getConfig()->getEntityID()]['SAML_RelayState'] = $request->getRelayState();
$this->setResponse($this->getSaml()->getHttpRedirectBindingResponse($request));
}
return $this;
} | php | public function handleRequest($requestUri = null, $requestMethod = null)
{
if (!$this->isConfigConsistent() && false) {
throw new \LogicException('The client configuration is not consistent');
}
$pathInfo = $requestUri;
if (false !== $pos = strpos($pathInfo, '?')) {
$pathInfo = substr($pathInfo, 0, $pos);
}
$pathInfo = rawurldecode($pathInfo);
$info = $this->getDispatcher()->dispatch($requestMethod, $pathInfo);
if ($info[0] == Dispatcher::FOUND) {
try {
$response = $info[1]($this);
if ($response instanceof ResponseInterface) {
$this->setResponse($response);
}
} catch (ResponseExceptionInterface $e) {
$this->setResponse($e->getResponse());
}
} elseif (!$this->isAuthenticated()) {
if (strtoupper($requestMethod) == 'GET') {
$_SESSION[self::class][$this->getConfig()->getEntityID()]['targeted_path'] = $requestUri;
}
$request = $this->getSaml()->buildAuthnRequest();
$_SESSION[self::class][$this->getConfig()->getEntityID()]['SAML_RelayState'] = $request->getRelayState();
$this->setResponse($this->getSaml()->getHttpRedirectBindingResponse($request));
}
return $this;
} | [
"public",
"function",
"handleRequest",
"(",
"$",
"requestUri",
"=",
"null",
",",
"$",
"requestMethod",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isConfigConsistent",
"(",
")",
"&&",
"false",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'The client configuration is not consistent'",
")",
";",
"}",
"$",
"pathInfo",
"=",
"$",
"requestUri",
";",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"pathInfo",
",",
"'?'",
")",
")",
"{",
"$",
"pathInfo",
"=",
"substr",
"(",
"$",
"pathInfo",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"$",
"pathInfo",
"=",
"rawurldecode",
"(",
"$",
"pathInfo",
")",
";",
"$",
"info",
"=",
"$",
"this",
"->",
"getDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"requestMethod",
",",
"$",
"pathInfo",
")",
";",
"if",
"(",
"$",
"info",
"[",
"0",
"]",
"==",
"Dispatcher",
"::",
"FOUND",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"info",
"[",
"1",
"]",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
"{",
"$",
"this",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}",
"}",
"catch",
"(",
"ResponseExceptionInterface",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"setResponse",
"(",
"$",
"e",
"->",
"getResponse",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"if",
"(",
"strtoupper",
"(",
"$",
"requestMethod",
")",
"==",
"'GET'",
")",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"class",
"]",
"[",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getEntityID",
"(",
")",
"]",
"[",
"'targeted_path'",
"]",
"=",
"$",
"requestUri",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"getSaml",
"(",
")",
"->",
"buildAuthnRequest",
"(",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"class",
"]",
"[",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getEntityID",
"(",
")",
"]",
"[",
"'SAML_RelayState'",
"]",
"=",
"$",
"request",
"->",
"getRelayState",
"(",
")",
";",
"$",
"this",
"->",
"setResponse",
"(",
"$",
"this",
"->",
"getSaml",
"(",
")",
"->",
"getHttpRedirectBindingResponse",
"(",
"$",
"request",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Handle connect request
@param string $requestUri
@param string $requestMethod
@return $this
@throws \Exception | [
"Handle",
"connect",
"request"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Connect.php#L373-L411 |
29,967 | flash-global/connect-client | src/Connect.php | Connect.emit | public function emit()
{
if (headers_sent($file, $line)) {
throw new \LogicException('Headers already sent in %s on line %d', $file, $line);
}
if ($this->getResponse()) {
(new Response\SapiEmitter())->emit($this->getResponse());
exit();
}
} | php | public function emit()
{
if (headers_sent($file, $line)) {
throw new \LogicException('Headers already sent in %s on line %d', $file, $line);
}
if ($this->getResponse()) {
(new Response\SapiEmitter())->emit($this->getResponse());
exit();
}
} | [
"public",
"function",
"emit",
"(",
")",
"{",
"if",
"(",
"headers_sent",
"(",
"$",
"file",
",",
"$",
"line",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Headers already sent in %s on line %d'",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
"{",
"(",
"new",
"Response",
"\\",
"SapiEmitter",
"(",
")",
")",
"->",
"emit",
"(",
"$",
"this",
"->",
"getResponse",
"(",
")",
")",
";",
"exit",
"(",
")",
";",
"}",
"}"
] | Emit the client response if exists and die... | [
"Emit",
"the",
"client",
"response",
"if",
"exists",
"and",
"die",
"..."
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Connect.php#L416-L426 |
29,968 | flash-global/connect-client | src/Connect.php | Connect.switchRole | public function switchRole($role)
{
if ($this->isAuthenticated()) {
$entityId = $this->getConfig()->getEntityID();
try {
$isRole = false;
/** @var Attribution $attribution **/
foreach ($this->getUser()->getAttributions() as $attribution) {
if ($attribution->getRole()->getRole() == $role
&& $attribution->getTarget()->getUrl() == $entityId
) {
$isRole = true;
}
}
if ($isRole) {
$this->setUser($this->getUser()->setCurrentRole($role));
} else {
throw new UserAttributionException('Role not found.', 400);
}
} catch (\Exception $e) {
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} else {
throw new UserAttributionException('User not found.', 400);
}
} | php | public function switchRole($role)
{
if ($this->isAuthenticated()) {
$entityId = $this->getConfig()->getEntityID();
try {
$isRole = false;
/** @var Attribution $attribution **/
foreach ($this->getUser()->getAttributions() as $attribution) {
if ($attribution->getRole()->getRole() == $role
&& $attribution->getTarget()->getUrl() == $entityId
) {
$isRole = true;
}
}
if ($isRole) {
$this->setUser($this->getUser()->setCurrentRole($role));
} else {
throw new UserAttributionException('Role not found.', 400);
}
} catch (\Exception $e) {
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} else {
throw new UserAttributionException('User not found.', 400);
}
} | [
"public",
"function",
"switchRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"$",
"entityId",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getEntityID",
"(",
")",
";",
"try",
"{",
"$",
"isRole",
"=",
"false",
";",
"/** @var Attribution $attribution **/",
"foreach",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getAttributions",
"(",
")",
"as",
"$",
"attribution",
")",
"{",
"if",
"(",
"$",
"attribution",
"->",
"getRole",
"(",
")",
"->",
"getRole",
"(",
")",
"==",
"$",
"role",
"&&",
"$",
"attribution",
"->",
"getTarget",
"(",
")",
"->",
"getUrl",
"(",
")",
"==",
"$",
"entityId",
")",
"{",
"$",
"isRole",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"isRole",
")",
"{",
"$",
"this",
"->",
"setUser",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"setCurrentRole",
"(",
"$",
"role",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"'Role not found.'",
",",
"400",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"'User not found.'",
",",
"400",
")",
";",
"}",
"}"
] | Switch the User role
@param string $role | [
"Switch",
"the",
"User",
"role"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Connect.php#L481-L509 |
29,969 | flash-global/connect-client | src/Connect.php | Connect.switchLocalUsername | public function switchLocalUsername($localUsername, $role, $application = null)
{
if ($this->isAuthenticated()) {
// If no Application, get current Application
if (!$application) {
$application = $this->getConfig()->getEntityID();
}
try {
$switchedRole = null;
/** @var Attribution $attribution **/
foreach ($this->getUser()->getAttributions() as $attribution) {
$pattern = '/:' . $role . ':' . $localUsername . '/';
if ($application == $attribution->getTarget()->getUrl()
&& preg_match($pattern, $attribution->getRole()->getRole())
) {
$switchedRole = $attribution->getRole();
}
}
if ($switchedRole) {
$roles = explode(':', $switchedRole->getRole());
if (count($roles) == 3) {
$role = $roles[1];
$this->getUser()->setCurrentRole($role);
$this->getUser()->setLocalUsername($roles[2]);
$this->setUser($this->getUser());
} else {
$this->setUser($this->getUser()->setCurrentRole($switchedRole->getRole()));
}
} else {
throw new UserAttributionException('Role not found.', 400);
}
} catch (\Exception $e) {
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} else {
throw new UserAttributionException('User not found.', 400);
}
} | php | public function switchLocalUsername($localUsername, $role, $application = null)
{
if ($this->isAuthenticated()) {
// If no Application, get current Application
if (!$application) {
$application = $this->getConfig()->getEntityID();
}
try {
$switchedRole = null;
/** @var Attribution $attribution **/
foreach ($this->getUser()->getAttributions() as $attribution) {
$pattern = '/:' . $role . ':' . $localUsername . '/';
if ($application == $attribution->getTarget()->getUrl()
&& preg_match($pattern, $attribution->getRole()->getRole())
) {
$switchedRole = $attribution->getRole();
}
}
if ($switchedRole) {
$roles = explode(':', $switchedRole->getRole());
if (count($roles) == 3) {
$role = $roles[1];
$this->getUser()->setCurrentRole($role);
$this->getUser()->setLocalUsername($roles[2]);
$this->setUser($this->getUser());
} else {
$this->setUser($this->getUser()->setCurrentRole($switchedRole->getRole()));
}
} else {
throw new UserAttributionException('Role not found.', 400);
}
} catch (\Exception $e) {
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} else {
throw new UserAttributionException('User not found.', 400);
}
} | [
"public",
"function",
"switchLocalUsername",
"(",
"$",
"localUsername",
",",
"$",
"role",
",",
"$",
"application",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"// If no Application, get current Application",
"if",
"(",
"!",
"$",
"application",
")",
"{",
"$",
"application",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getEntityID",
"(",
")",
";",
"}",
"try",
"{",
"$",
"switchedRole",
"=",
"null",
";",
"/** @var Attribution $attribution **/",
"foreach",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getAttributions",
"(",
")",
"as",
"$",
"attribution",
")",
"{",
"$",
"pattern",
"=",
"'/:'",
".",
"$",
"role",
".",
"':'",
".",
"$",
"localUsername",
".",
"'/'",
";",
"if",
"(",
"$",
"application",
"==",
"$",
"attribution",
"->",
"getTarget",
"(",
")",
"->",
"getUrl",
"(",
")",
"&&",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"attribution",
"->",
"getRole",
"(",
")",
"->",
"getRole",
"(",
")",
")",
")",
"{",
"$",
"switchedRole",
"=",
"$",
"attribution",
"->",
"getRole",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"switchedRole",
")",
"{",
"$",
"roles",
"=",
"explode",
"(",
"':'",
",",
"$",
"switchedRole",
"->",
"getRole",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"roles",
")",
"==",
"3",
")",
"{",
"$",
"role",
"=",
"$",
"roles",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"setCurrentRole",
"(",
"$",
"role",
")",
";",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"setLocalUsername",
"(",
"$",
"roles",
"[",
"2",
"]",
")",
";",
"$",
"this",
"->",
"setUser",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setUser",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"setCurrentRole",
"(",
"$",
"switchedRole",
"->",
"getRole",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"'Role not found.'",
",",
"400",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UserAttributionException",
"(",
"'User not found.'",
",",
"400",
")",
";",
"}",
"}"
] | Switch the User role by localUsername
@param string $localUsername
@param string $role
@param null $application | [
"Switch",
"the",
"User",
"role",
"by",
"localUsername"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Connect.php#L518-L559 |
29,970 | flash-global/connect-client | src/Exception/SamlException.php | SamlException.getContent | protected function getContent()
{
$response = new SamlResponse();
$response->setStatus(new Status(new StatusCode($this->status)));
$context = new SerializationContext();
$response->serialize($context->getDocument(), $context);
return $context->getDocument()->saveXML();
} | php | protected function getContent()
{
$response = new SamlResponse();
$response->setStatus(new Status(new StatusCode($this->status)));
$context = new SerializationContext();
$response->serialize($context->getDocument(), $context);
return $context->getDocument()->saveXML();
} | [
"protected",
"function",
"getContent",
"(",
")",
"{",
"$",
"response",
"=",
"new",
"SamlResponse",
"(",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"new",
"Status",
"(",
"new",
"StatusCode",
"(",
"$",
"this",
"->",
"status",
")",
")",
")",
";",
"$",
"context",
"=",
"new",
"SerializationContext",
"(",
")",
";",
"$",
"response",
"->",
"serialize",
"(",
"$",
"context",
"->",
"getDocument",
"(",
")",
",",
"$",
"context",
")",
";",
"return",
"$",
"context",
"->",
"getDocument",
"(",
")",
"->",
"saveXML",
"(",
")",
";",
"}"
] | Returns the Saml error reporting
@return string | [
"Returns",
"the",
"Saml",
"error",
"reporting"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Exception/SamlException.php#L53-L62 |
29,971 | flash-global/connect-client | src/UserAttribution.php | UserAttribution.add | public function add($sourceId, $targetId, $roleId)
{
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
->setMethod('POST');
$request->setBodyParams([
'data' => json_encode([
'source_id' => $sourceId,
'target_id' => $targetId,
'role_id' => $roleId,
])
]);
try {
$response = json_decode($this->send($request)->getBody(), true);
return (count($response['added']) > 0 ? reset($response['added']) : null);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function add($sourceId, $targetId, $roleId)
{
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
->setMethod('POST');
$request->setBodyParams([
'data' => json_encode([
'source_id' => $sourceId,
'target_id' => $targetId,
'role_id' => $roleId,
])
]);
try {
$response = json_decode($this->send($request)->getBody(), true);
return (count($response['added']) > 0 ? reset($response['added']) : null);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"add",
"(",
"$",
"sourceId",
",",
"$",
"targetId",
",",
"$",
"roleId",
")",
"{",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"self",
"::",
"IDP_ATTRIBUTIONS_API",
")",
")",
"->",
"setMethod",
"(",
"'POST'",
")",
";",
"$",
"request",
"->",
"setBodyParams",
"(",
"[",
"'data'",
"=>",
"json_encode",
"(",
"[",
"'source_id'",
"=>",
"$",
"sourceId",
",",
"'target_id'",
"=>",
"$",
"targetId",
",",
"'role_id'",
"=>",
"$",
"roleId",
",",
"]",
")",
"]",
")",
";",
"try",
"{",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"return",
"(",
"count",
"(",
"$",
"response",
"[",
"'added'",
"]",
")",
">",
"0",
"?",
"reset",
"(",
"$",
"response",
"[",
"'added'",
"]",
")",
":",
"null",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Add an Attribution
@param int $sourceId
@param int $targetId
@param int $roleId
@return Attribution|null | [
"Add",
"an",
"Attribution"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/UserAttribution.php#L47-L75 |
29,972 | flash-global/connect-client | src/UserAttribution.php | UserAttribution.get | public function get($sourceId, $targetId = null)
{
$url = self::IDP_ATTRIBUTIONS_API . '/' . $sourceId;
if ($targetId) {
$url .= '?target=' . urlencode($targetId);
}
$request = (new RequestDescriptor())
->setUrl($this->buildUrl($url))
->setMethod('GET');
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function get($sourceId, $targetId = null)
{
$url = self::IDP_ATTRIBUTIONS_API . '/' . $sourceId;
if ($targetId) {
$url .= '?target=' . urlencode($targetId);
}
$request = (new RequestDescriptor())
->setUrl($this->buildUrl($url))
->setMethod('GET');
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"get",
"(",
"$",
"sourceId",
",",
"$",
"targetId",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"IDP_ATTRIBUTIONS_API",
".",
"'/'",
".",
"$",
"sourceId",
";",
"if",
"(",
"$",
"targetId",
")",
"{",
"$",
"url",
".=",
"'?target='",
".",
"urlencode",
"(",
"$",
"targetId",
")",
";",
"}",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"$",
"url",
")",
")",
"->",
"setMethod",
"(",
"'GET'",
")",
";",
"try",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Get an User Attributions
@param int $sourceId
@param int|null $targetId
@return Attribution[] | [
"Get",
"an",
"User",
"Attributions"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/UserAttribution.php#L85-L109 |
29,973 | flash-global/connect-client | src/UserAttribution.php | UserAttribution.remove | public function remove($sourceId, $targetId = null, $roleId = null)
{
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
->setMethod('DELETE')
->setRawData(json_encode([
'source_id' => $sourceId,
'target_id' => $targetId,
'role_id' => $roleId,
]));
try {
$this->send($request);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function remove($sourceId, $targetId = null, $roleId = null)
{
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
->setMethod('DELETE')
->setRawData(json_encode([
'source_id' => $sourceId,
'target_id' => $targetId,
'role_id' => $roleId,
]));
try {
$this->send($request);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(), true);
throw new UserAttributionException($error['error'], $error['code'], $previous);
}
throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"remove",
"(",
"$",
"sourceId",
",",
"$",
"targetId",
"=",
"null",
",",
"$",
"roleId",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"self",
"::",
"IDP_ATTRIBUTIONS_API",
")",
")",
"->",
"setMethod",
"(",
"'DELETE'",
")",
"->",
"setRawData",
"(",
"json_encode",
"(",
"[",
"'source_id'",
"=>",
"$",
"sourceId",
",",
"'target_id'",
"=>",
"$",
"targetId",
",",
"'role_id'",
"=>",
"$",
"roleId",
",",
"]",
")",
")",
";",
"try",
"{",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"UserAttributionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Remove attributions for a user. An application and a role can be defined to target more attributions more
precisely.
@param int $sourceId
@param int $targetId
@param int $roleId
If omitted, all attributions link to this source / target will be deleted. | [
"Remove",
"attributions",
"for",
"a",
"user",
".",
"An",
"application",
"and",
"a",
"role",
"can",
"be",
"defined",
"to",
"target",
"more",
"attributions",
"more",
"precisely",
"."
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/UserAttribution.php#L120-L144 |
29,974 | flash-global/connect-client | src/Handler/RegisterAdminHandler.php | RegisterAdminHandler.generateXml | protected function generateXml(Connect $connect, $privateKey, $data)
{
$certificateGen = (new X509CertificateGen())->createX509Certificate($privateKey);
$certificate = new X509Certificate();
$certificate->loadPem($certificateGen);
$builder = new MetadataBuilder();
$xml = $builder->build($data['entityID'], $data['acs'], $data['logout'], $certificate);
$path = $connect->getConfig()->getSamlMetadataBaseDir().'/'.$connect->getConfig()->getSpMetadataFile();
file_put_contents($path, $xml);
$message = (new SpEntityConfigurationMessage())
->setXml($xml);
$message = (new SignedMessageDecorator($message))
->setCertificate((new X509CertificateGen())->createX509Certificate($privateKey))
->sign($privateKey);
$certificate = $connect->getSaml()
->getMetadata()
->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
->getCertificate()
->toPem();
return (new MessageResponse($message))->buildEncrypted($certificate);
} | php | protected function generateXml(Connect $connect, $privateKey, $data)
{
$certificateGen = (new X509CertificateGen())->createX509Certificate($privateKey);
$certificate = new X509Certificate();
$certificate->loadPem($certificateGen);
$builder = new MetadataBuilder();
$xml = $builder->build($data['entityID'], $data['acs'], $data['logout'], $certificate);
$path = $connect->getConfig()->getSamlMetadataBaseDir().'/'.$connect->getConfig()->getSpMetadataFile();
file_put_contents($path, $xml);
$message = (new SpEntityConfigurationMessage())
->setXml($xml);
$message = (new SignedMessageDecorator($message))
->setCertificate((new X509CertificateGen())->createX509Certificate($privateKey))
->sign($privateKey);
$certificate = $connect->getSaml()
->getMetadata()
->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
->getCertificate()
->toPem();
return (new MessageResponse($message))->buildEncrypted($certificate);
} | [
"protected",
"function",
"generateXml",
"(",
"Connect",
"$",
"connect",
",",
"$",
"privateKey",
",",
"$",
"data",
")",
"{",
"$",
"certificateGen",
"=",
"(",
"new",
"X509CertificateGen",
"(",
")",
")",
"->",
"createX509Certificate",
"(",
"$",
"privateKey",
")",
";",
"$",
"certificate",
"=",
"new",
"X509Certificate",
"(",
")",
";",
"$",
"certificate",
"->",
"loadPem",
"(",
"$",
"certificateGen",
")",
";",
"$",
"builder",
"=",
"new",
"MetadataBuilder",
"(",
")",
";",
"$",
"xml",
"=",
"$",
"builder",
"->",
"build",
"(",
"$",
"data",
"[",
"'entityID'",
"]",
",",
"$",
"data",
"[",
"'acs'",
"]",
",",
"$",
"data",
"[",
"'logout'",
"]",
",",
"$",
"certificate",
")",
";",
"$",
"path",
"=",
"$",
"connect",
"->",
"getConfig",
"(",
")",
"->",
"getSamlMetadataBaseDir",
"(",
")",
".",
"'/'",
".",
"$",
"connect",
"->",
"getConfig",
"(",
")",
"->",
"getSpMetadataFile",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"xml",
")",
";",
"$",
"message",
"=",
"(",
"new",
"SpEntityConfigurationMessage",
"(",
")",
")",
"->",
"setXml",
"(",
"$",
"xml",
")",
";",
"$",
"message",
"=",
"(",
"new",
"SignedMessageDecorator",
"(",
"$",
"message",
")",
")",
"->",
"setCertificate",
"(",
"(",
"new",
"X509CertificateGen",
"(",
")",
")",
"->",
"createX509Certificate",
"(",
"$",
"privateKey",
")",
")",
"->",
"sign",
"(",
"$",
"privateKey",
")",
";",
"$",
"certificate",
"=",
"$",
"connect",
"->",
"getSaml",
"(",
")",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_ENCRYPTION",
")",
"->",
"getCertificate",
"(",
")",
"->",
"toPem",
"(",
")",
";",
"return",
"(",
"new",
"MessageResponse",
"(",
"$",
"message",
")",
")",
"->",
"buildEncrypted",
"(",
"$",
"certificate",
")",
";",
"}"
] | Generate the SP metadata XML file
@param Connect $connect
@param string $privateKey
@param array $data
@return MessageResponse | [
"Generate",
"the",
"SP",
"metadata",
"XML",
"file"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Handler/RegisterAdminHandler.php#L84-L112 |
29,975 | flash-global/connect-client | src/UserAdmin.php | UserAdmin.fetchCertificate | protected function fetchCertificate()
{
$metadata = file_get_contents($this->getBaseUrl() . $this->getAdminSpMetadataFile());
$deserializationContext = new DeserializationContext();
$deserializationContext->getDocument()->loadXML($metadata);
$ed = new EntityDescriptor();
$ed->deserialize($deserializationContext->getDocument(), $deserializationContext);
$certificate = $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
? $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
->getCertificate()
->toPem()
: $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
->toPem();
return $certificate;
} | php | protected function fetchCertificate()
{
$metadata = file_get_contents($this->getBaseUrl() . $this->getAdminSpMetadataFile());
$deserializationContext = new DeserializationContext();
$deserializationContext->getDocument()->loadXML($metadata);
$ed = new EntityDescriptor();
$ed->deserialize($deserializationContext->getDocument(), $deserializationContext);
$certificate = $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
? $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_ENCRYPTION)
->getCertificate()
->toPem()
: $ed->getFirstSpSsoDescriptor()->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
->toPem();
return $certificate;
} | [
"protected",
"function",
"fetchCertificate",
"(",
")",
"{",
"$",
"metadata",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
".",
"$",
"this",
"->",
"getAdminSpMetadataFile",
"(",
")",
")",
";",
"$",
"deserializationContext",
"=",
"new",
"DeserializationContext",
"(",
")",
";",
"$",
"deserializationContext",
"->",
"getDocument",
"(",
")",
"->",
"loadXML",
"(",
"$",
"metadata",
")",
";",
"$",
"ed",
"=",
"new",
"EntityDescriptor",
"(",
")",
";",
"$",
"ed",
"->",
"deserialize",
"(",
"$",
"deserializationContext",
"->",
"getDocument",
"(",
")",
",",
"$",
"deserializationContext",
")",
";",
"$",
"certificate",
"=",
"$",
"ed",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_ENCRYPTION",
")",
"?",
"$",
"ed",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_ENCRYPTION",
")",
"->",
"getCertificate",
"(",
")",
"->",
"toPem",
"(",
")",
":",
"$",
"ed",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
"->",
"toPem",
"(",
")",
";",
"return",
"$",
"certificate",
";",
"}"
] | Fetch Connect Admin SP metadata an return encryption certificate
@return string | [
"Fetch",
"Connect",
"Admin",
"SP",
"metadata",
"an",
"return",
"encryption",
"certificate"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/UserAdmin.php#L316-L335 |
29,976 | flash-global/connect-client | src/UserAdmin.php | UserAdmin.createToken | protected function createToken()
{
$token = $this->getToken()->createApplicationToken(
$this->connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID(),
$this->connect->getSaml()->getPrivateKey()
);
return $token['token'];
} | php | protected function createToken()
{
$token = $this->getToken()->createApplicationToken(
$this->connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID(),
$this->connect->getSaml()->getPrivateKey()
);
return $token['token'];
} | [
"protected",
"function",
"createToken",
"(",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getToken",
"(",
")",
"->",
"createApplicationToken",
"(",
"$",
"this",
"->",
"connect",
"->",
"getSaml",
"(",
")",
"->",
"getMetadata",
"(",
")",
"->",
"getServiceProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
",",
"$",
"this",
"->",
"connect",
"->",
"getSaml",
"(",
")",
"->",
"getPrivateKey",
"(",
")",
")",
";",
"return",
"$",
"token",
"[",
"'token'",
"]",
";",
"}"
] | Get a token
@return string | [
"Get",
"a",
"token"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/UserAdmin.php#L342-L349 |
29,977 | flash-global/connect-client | src/MetadataBuilder.php | MetadataBuilder.build | public function build($entityID, $acs, $logout, $certificate)
{
$entityDescriptor = (new EntityDescriptor())
->setEntityID($entityID)
->setID(Helper::generateID());
$spSsoDescriptor = (new SpSsoDescriptor())
->addKeyDescriptor(
(new KeyDescriptor())
->setUse(KeyDescriptor::USE_SIGNING)
->setCertificate($certificate)
)
->addKeyDescriptor(
(new KeyDescriptor())
->setUse(KeyDescriptor::USE_ENCRYPTION)
->setCertificate($certificate)
)
->setWantAssertionsSigned(true)
->setAuthnRequestsSigned(true)
->addSingleLogoutService(
$logout = (new SingleLogoutService())
->setBinding(SamlConstants::BINDING_SAML2_HTTP_REDIRECT)
->setLocation($logout)
)
->addAssertionConsumerService(
$acs = (new AssertionConsumerService())
->setBinding(SamlConstants::BINDING_SAML2_HTTP_POST)
->setLocation($acs)
);
$entityDescriptor->addItem($spSsoDescriptor);
$serializationContext = new SerializationContext();
$entityDescriptor->serialize($serializationContext->getDocument(), $serializationContext);
$data = $serializationContext->getDocument()->saveXML();
return $data;
} | php | public function build($entityID, $acs, $logout, $certificate)
{
$entityDescriptor = (new EntityDescriptor())
->setEntityID($entityID)
->setID(Helper::generateID());
$spSsoDescriptor = (new SpSsoDescriptor())
->addKeyDescriptor(
(new KeyDescriptor())
->setUse(KeyDescriptor::USE_SIGNING)
->setCertificate($certificate)
)
->addKeyDescriptor(
(new KeyDescriptor())
->setUse(KeyDescriptor::USE_ENCRYPTION)
->setCertificate($certificate)
)
->setWantAssertionsSigned(true)
->setAuthnRequestsSigned(true)
->addSingleLogoutService(
$logout = (new SingleLogoutService())
->setBinding(SamlConstants::BINDING_SAML2_HTTP_REDIRECT)
->setLocation($logout)
)
->addAssertionConsumerService(
$acs = (new AssertionConsumerService())
->setBinding(SamlConstants::BINDING_SAML2_HTTP_POST)
->setLocation($acs)
);
$entityDescriptor->addItem($spSsoDescriptor);
$serializationContext = new SerializationContext();
$entityDescriptor->serialize($serializationContext->getDocument(), $serializationContext);
$data = $serializationContext->getDocument()->saveXML();
return $data;
} | [
"public",
"function",
"build",
"(",
"$",
"entityID",
",",
"$",
"acs",
",",
"$",
"logout",
",",
"$",
"certificate",
")",
"{",
"$",
"entityDescriptor",
"=",
"(",
"new",
"EntityDescriptor",
"(",
")",
")",
"->",
"setEntityID",
"(",
"$",
"entityID",
")",
"->",
"setID",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
";",
"$",
"spSsoDescriptor",
"=",
"(",
"new",
"SpSsoDescriptor",
"(",
")",
")",
"->",
"addKeyDescriptor",
"(",
"(",
"new",
"KeyDescriptor",
"(",
")",
")",
"->",
"setUse",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"setCertificate",
"(",
"$",
"certificate",
")",
")",
"->",
"addKeyDescriptor",
"(",
"(",
"new",
"KeyDescriptor",
"(",
")",
")",
"->",
"setUse",
"(",
"KeyDescriptor",
"::",
"USE_ENCRYPTION",
")",
"->",
"setCertificate",
"(",
"$",
"certificate",
")",
")",
"->",
"setWantAssertionsSigned",
"(",
"true",
")",
"->",
"setAuthnRequestsSigned",
"(",
"true",
")",
"->",
"addSingleLogoutService",
"(",
"$",
"logout",
"=",
"(",
"new",
"SingleLogoutService",
"(",
")",
")",
"->",
"setBinding",
"(",
"SamlConstants",
"::",
"BINDING_SAML2_HTTP_REDIRECT",
")",
"->",
"setLocation",
"(",
"$",
"logout",
")",
")",
"->",
"addAssertionConsumerService",
"(",
"$",
"acs",
"=",
"(",
"new",
"AssertionConsumerService",
"(",
")",
")",
"->",
"setBinding",
"(",
"SamlConstants",
"::",
"BINDING_SAML2_HTTP_POST",
")",
"->",
"setLocation",
"(",
"$",
"acs",
")",
")",
";",
"$",
"entityDescriptor",
"->",
"addItem",
"(",
"$",
"spSsoDescriptor",
")",
";",
"$",
"serializationContext",
"=",
"new",
"SerializationContext",
"(",
")",
";",
"$",
"entityDescriptor",
"->",
"serialize",
"(",
"$",
"serializationContext",
"->",
"getDocument",
"(",
")",
",",
"$",
"serializationContext",
")",
";",
"$",
"data",
"=",
"$",
"serializationContext",
"->",
"getDocument",
"(",
")",
"->",
"saveXML",
"(",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Build the SP SAML metadata
@param $entityID
@param $acs
@param $logout
@param $certificate
@return string | [
"Build",
"the",
"SP",
"SAML",
"metadata"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/MetadataBuilder.php#L57-L96 |
29,978 | flash-global/connect-client | src/Token.php | Token.create | public function create(Connect $connect)
{
$tokenRequest = $this->getTokenizer()->signTokenRequest(
$this->getTokenizer()->createTokenRequest(
$connect->getUser(),
$connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID()
),
$connect->getSaml()->getPrivateKey()
);
$request = (new RequestDescriptor())
->setUrl($this->buildUrl('/api/token'))
->setMethod('POST');
$request->setBodyParams(['token-request' => json_encode($tokenRequest->toArray())]);
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function create(Connect $connect)
{
$tokenRequest = $this->getTokenizer()->signTokenRequest(
$this->getTokenizer()->createTokenRequest(
$connect->getUser(),
$connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID()
),
$connect->getSaml()->getPrivateKey()
);
$request = (new RequestDescriptor())
->setUrl($this->buildUrl('/api/token'))
->setMethod('POST');
$request->setBodyParams(['token-request' => json_encode($tokenRequest->toArray())]);
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"create",
"(",
"Connect",
"$",
"connect",
")",
"{",
"$",
"tokenRequest",
"=",
"$",
"this",
"->",
"getTokenizer",
"(",
")",
"->",
"signTokenRequest",
"(",
"$",
"this",
"->",
"getTokenizer",
"(",
")",
"->",
"createTokenRequest",
"(",
"$",
"connect",
"->",
"getUser",
"(",
")",
",",
"$",
"connect",
"->",
"getSaml",
"(",
")",
"->",
"getMetadata",
"(",
")",
"->",
"getServiceProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
")",
",",
"$",
"connect",
"->",
"getSaml",
"(",
")",
"->",
"getPrivateKey",
"(",
")",
")",
";",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"'/api/token'",
")",
")",
"->",
"setMethod",
"(",
"'POST'",
")",
";",
"$",
"request",
"->",
"setBodyParams",
"(",
"[",
"'token-request'",
"=>",
"json_encode",
"(",
"$",
"tokenRequest",
"->",
"toArray",
"(",
")",
")",
"]",
")",
";",
"try",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
"true",
")",
",",
"true",
")",
";",
"throw",
"new",
"TokenException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"TokenException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Create a Token
@param Connect $connect
@return string | [
"Create",
"a",
"Token"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Token.php#L101-L129 |
29,979 | flash-global/connect-client | src/Token.php | Token.createApplicationToken | public function createApplicationToken($application, $privateKey)
{
$tokenRequest = $this->getTokenizer()->signTokenRequest(
$this->getTokenizer()->createApplicationTokenRequest(
$application
),
$privateKey
);
$request = (new RequestDescriptor())
->setUrl($this->buildUrl('/api/token'))
->setMethod('POST');
$request->setBodyParams([
'token-request' => json_encode($tokenRequest->toArray())
]);
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function createApplicationToken($application, $privateKey)
{
$tokenRequest = $this->getTokenizer()->signTokenRequest(
$this->getTokenizer()->createApplicationTokenRequest(
$application
),
$privateKey
);
$request = (new RequestDescriptor())
->setUrl($this->buildUrl('/api/token'))
->setMethod('POST');
$request->setBodyParams([
'token-request' => json_encode($tokenRequest->toArray())
]);
try {
return json_decode($this->send($request)->getBody(), true);
} catch (\Exception $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"createApplicationToken",
"(",
"$",
"application",
",",
"$",
"privateKey",
")",
"{",
"$",
"tokenRequest",
"=",
"$",
"this",
"->",
"getTokenizer",
"(",
")",
"->",
"signTokenRequest",
"(",
"$",
"this",
"->",
"getTokenizer",
"(",
")",
"->",
"createApplicationTokenRequest",
"(",
"$",
"application",
")",
",",
"$",
"privateKey",
")",
";",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"'/api/token'",
")",
")",
"->",
"setMethod",
"(",
"'POST'",
")",
";",
"$",
"request",
"->",
"setBodyParams",
"(",
"[",
"'token-request'",
"=>",
"json_encode",
"(",
"$",
"tokenRequest",
"->",
"toArray",
"(",
")",
")",
"]",
")",
";",
"try",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
"true",
")",
",",
"true",
")",
";",
"throw",
"new",
"TokenException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"TokenException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Create an application token
@param string $application
@param resource|string $privateKey
@return string | [
"Create",
"an",
"application",
"token"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Token.php#L139-L168 |
29,980 | flash-global/connect-client | src/Token.php | Token.validate | public function validate($token)
{
if ($this->hasCache()) {
$body = $this->getCache()->get($token);
// Check if token is expired
if (!is_null($body)) {
$body = json_decode($body, true);
if (new \DateTime($body['expire_at']) >= new \DateTime()) {
return $this->buildValidationReturn($body);
} else {
$this->getCache()->delete($token);
throw new TokenException('The provided token is expired');
}
}
}
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(sprintf('/api/token/validate?token=%s', (string) $token)))
->setMethod('GET');
try {
$body = json_decode($this->send($request)->getBody(), true);
if ($this->hasCache()) {
$this->getCache()->set(
$token,
json_encode($body),
(new \DateTime())->diff(new \DateTime($body['expire_at']))
);
}
return $this->buildValidationReturn($body);
} catch (ApiClientException $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | php | public function validate($token)
{
if ($this->hasCache()) {
$body = $this->getCache()->get($token);
// Check if token is expired
if (!is_null($body)) {
$body = json_decode($body, true);
if (new \DateTime($body['expire_at']) >= new \DateTime()) {
return $this->buildValidationReturn($body);
} else {
$this->getCache()->delete($token);
throw new TokenException('The provided token is expired');
}
}
}
$request = (new RequestDescriptor())
->setUrl($this->buildUrl(sprintf('/api/token/validate?token=%s', (string) $token)))
->setMethod('GET');
try {
$body = json_decode($this->send($request)->getBody(), true);
if ($this->hasCache()) {
$this->getCache()->set(
$token,
json_encode($body),
(new \DateTime())->diff(new \DateTime($body['expire_at']))
);
}
return $this->buildValidationReturn($body);
} catch (ApiClientException $e) {
$previous = $e->getPrevious();
if ($previous instanceof BadResponseException) {
$error = json_decode($previous->getResponse()->getBody(true), true);
throw new TokenException($error['error'], $error['code'], $previous);
}
throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
} | [
"public",
"function",
"validate",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCache",
"(",
")",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"get",
"(",
"$",
"token",
")",
";",
"// Check if token is expired",
"if",
"(",
"!",
"is_null",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"json_decode",
"(",
"$",
"body",
",",
"true",
")",
";",
"if",
"(",
"new",
"\\",
"DateTime",
"(",
"$",
"body",
"[",
"'expire_at'",
"]",
")",
">=",
"new",
"\\",
"DateTime",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"buildValidationReturn",
"(",
"$",
"body",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"delete",
"(",
"$",
"token",
")",
";",
"throw",
"new",
"TokenException",
"(",
"'The provided token is expired'",
")",
";",
"}",
"}",
"}",
"$",
"request",
"=",
"(",
"new",
"RequestDescriptor",
"(",
")",
")",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
"sprintf",
"(",
"'/api/token/validate?token=%s'",
",",
"(",
"string",
")",
"$",
"token",
")",
")",
")",
"->",
"setMethod",
"(",
"'GET'",
")",
";",
"try",
"{",
"$",
"body",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasCache",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"set",
"(",
"$",
"token",
",",
"json_encode",
"(",
"$",
"body",
")",
",",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"diff",
"(",
"new",
"\\",
"DateTime",
"(",
"$",
"body",
"[",
"'expire_at'",
"]",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildValidationReturn",
"(",
"$",
"body",
")",
";",
"}",
"catch",
"(",
"ApiClientException",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"instanceof",
"BadResponseException",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"previous",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
"true",
")",
",",
"true",
")",
";",
"throw",
"new",
"TokenException",
"(",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"error",
"[",
"'code'",
"]",
",",
"$",
"previous",
")",
";",
"}",
"throw",
"new",
"TokenException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
";",
"}",
"}"
] | Validate a Token
@param string $token
@return array
@throws ApiClientException | [
"Validate",
"a",
"Token"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Token.php#L179-L223 |
29,981 | flash-global/connect-client | src/Token.php | Token.buildValidationReturn | protected function buildValidationReturn(array $body)
{
if (isset($body['user'])) {
$body['user'] = new User($body['user']);
}
$body['application'] = new Application($body['application']);
$body['expire_at'] = new \DateTime($body['expire_at']);
return $body;
} | php | protected function buildValidationReturn(array $body)
{
if (isset($body['user'])) {
$body['user'] = new User($body['user']);
}
$body['application'] = new Application($body['application']);
$body['expire_at'] = new \DateTime($body['expire_at']);
return $body;
} | [
"protected",
"function",
"buildValidationReturn",
"(",
"array",
"$",
"body",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"body",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"body",
"[",
"'user'",
"]",
"=",
"new",
"User",
"(",
"$",
"body",
"[",
"'user'",
"]",
")",
";",
"}",
"$",
"body",
"[",
"'application'",
"]",
"=",
"new",
"Application",
"(",
"$",
"body",
"[",
"'application'",
"]",
")",
";",
"$",
"body",
"[",
"'expire_at'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"body",
"[",
"'expire_at'",
"]",
")",
";",
"return",
"$",
"body",
";",
"}"
] | Build the validation return
@param array $body
@return array | [
"Build",
"the",
"validation",
"return"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Token.php#L232-L242 |
29,982 | flash-global/connect-client | src/Saml.php | Saml.buildAuthnRequest | public function buildAuthnRequest()
{
$authnRequest = (new AuthnRequest())
->setAssertionConsumerServiceURL($this->getMetadata()->getFirstAcs()->getLocation())
->setProtocolBinding($this->getMetadata()->getFirstAcs()->getBinding())
->setID(Helper::generateID())
->setIssueInstant(new \DateTime())
->setDestination($this->getMetadata()->getFirstSso()->getLocation())
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()))
->setRelayState(Helper::generateID());
if ($this->getMetadata()->getFirstIdpSsoDescriptor()->getWantAuthnRequestsSigned()) {
$authnRequest->setSignature(
new SignatureWriter(
$this->getMetadata()
->getFirstSpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate(),
KeyHelper::createPrivateKey($this->getPrivateKey(), '')
)
);
}
return $authnRequest;
} | php | public function buildAuthnRequest()
{
$authnRequest = (new AuthnRequest())
->setAssertionConsumerServiceURL($this->getMetadata()->getFirstAcs()->getLocation())
->setProtocolBinding($this->getMetadata()->getFirstAcs()->getBinding())
->setID(Helper::generateID())
->setIssueInstant(new \DateTime())
->setDestination($this->getMetadata()->getFirstSso()->getLocation())
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()))
->setRelayState(Helper::generateID());
if ($this->getMetadata()->getFirstIdpSsoDescriptor()->getWantAuthnRequestsSigned()) {
$authnRequest->setSignature(
new SignatureWriter(
$this->getMetadata()
->getFirstSpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate(),
KeyHelper::createPrivateKey($this->getPrivateKey(), '')
)
);
}
return $authnRequest;
} | [
"public",
"function",
"buildAuthnRequest",
"(",
")",
"{",
"$",
"authnRequest",
"=",
"(",
"new",
"AuthnRequest",
"(",
")",
")",
"->",
"setAssertionConsumerServiceURL",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstAcs",
"(",
")",
"->",
"getLocation",
"(",
")",
")",
"->",
"setProtocolBinding",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstAcs",
"(",
")",
"->",
"getBinding",
"(",
")",
")",
"->",
"setID",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
"->",
"setIssueInstant",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"setDestination",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstSso",
"(",
")",
"->",
"getLocation",
"(",
")",
")",
"->",
"setIssuer",
"(",
"new",
"Issuer",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getServiceProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
")",
")",
"->",
"setRelayState",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getWantAuthnRequestsSigned",
"(",
")",
")",
"{",
"$",
"authnRequest",
"->",
"setSignature",
"(",
"new",
"SignatureWriter",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
",",
"KeyHelper",
"::",
"createPrivateKey",
"(",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
",",
"''",
")",
")",
")",
";",
"}",
"return",
"$",
"authnRequest",
";",
"}"
] | Returns a AuthnRequest
@return \LightSaml\Model\Protocol\SamlMessage | [
"Returns",
"a",
"AuthnRequest"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L173-L197 |
29,983 | flash-global/connect-client | src/Saml.php | Saml.createLogoutResponse | public function createLogoutResponse()
{
return (new LogoutResponse())
->setStatus(new Status(new StatusCode(SamlConstants::STATUS_SUCCESS)))
->setID(Helper::generateID())
->setVersion(SamlConstants::VERSION_20)
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()))
->setIssueInstant(new \DateTime());
} | php | public function createLogoutResponse()
{
return (new LogoutResponse())
->setStatus(new Status(new StatusCode(SamlConstants::STATUS_SUCCESS)))
->setID(Helper::generateID())
->setVersion(SamlConstants::VERSION_20)
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()))
->setIssueInstant(new \DateTime());
} | [
"public",
"function",
"createLogoutResponse",
"(",
")",
"{",
"return",
"(",
"new",
"LogoutResponse",
"(",
")",
")",
"->",
"setStatus",
"(",
"new",
"Status",
"(",
"new",
"StatusCode",
"(",
"SamlConstants",
"::",
"STATUS_SUCCESS",
")",
")",
")",
"->",
"setID",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
"->",
"setVersion",
"(",
"SamlConstants",
"::",
"VERSION_20",
")",
"->",
"setIssuer",
"(",
"new",
"Issuer",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getServiceProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
")",
")",
"->",
"setIssueInstant",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}"
] | Create a Saml Logout Response
@return LogoutResponse|SamlMessage | [
"Create",
"a",
"Saml",
"Logout",
"Response"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L204-L212 |
29,984 | flash-global/connect-client | src/Saml.php | Saml.prepareLogoutResponse | public function prepareLogoutResponse(LogoutRequest $request)
{
$response = $this->createLogoutResponse();
$idp = $this->getMetadata()->getFirstIdpSsoDescriptor();
$location = $idp->getFirstSingleLogoutService()->getResponseLocation()
? $idp->getFirstSingleLogoutService()->getResponseLocation()
: $idp->getFirstSingleLogoutService()->getLocation();
$response->setDestination($location);
$response->setRelayState($request->getRelayState());
$this->signMessage($response);
return $response;
} | php | public function prepareLogoutResponse(LogoutRequest $request)
{
$response = $this->createLogoutResponse();
$idp = $this->getMetadata()->getFirstIdpSsoDescriptor();
$location = $idp->getFirstSingleLogoutService()->getResponseLocation()
? $idp->getFirstSingleLogoutService()->getResponseLocation()
: $idp->getFirstSingleLogoutService()->getLocation();
$response->setDestination($location);
$response->setRelayState($request->getRelayState());
$this->signMessage($response);
return $response;
} | [
"public",
"function",
"prepareLogoutResponse",
"(",
"LogoutRequest",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"createLogoutResponse",
"(",
")",
";",
"$",
"idp",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
";",
"$",
"location",
"=",
"$",
"idp",
"->",
"getFirstSingleLogoutService",
"(",
")",
"->",
"getResponseLocation",
"(",
")",
"?",
"$",
"idp",
"->",
"getFirstSingleLogoutService",
"(",
")",
"->",
"getResponseLocation",
"(",
")",
":",
"$",
"idp",
"->",
"getFirstSingleLogoutService",
"(",
")",
"->",
"getLocation",
"(",
")",
";",
"$",
"response",
"->",
"setDestination",
"(",
"$",
"location",
")",
";",
"$",
"response",
"->",
"setRelayState",
"(",
"$",
"request",
"->",
"getRelayState",
"(",
")",
")",
";",
"$",
"this",
"->",
"signMessage",
"(",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Prepare a LogoutResponse to be send
@param LogoutRequest $request
@return LogoutResponse | [
"Prepare",
"a",
"LogoutResponse",
"to",
"be",
"send"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L221-L237 |
29,985 | flash-global/connect-client | src/Saml.php | Saml.createLogoutRequest | public function createLogoutRequest()
{
return (new LogoutRequest())
->setID(Helper::generateID())
->setVersion(SamlConstants::VERSION_20)
->setIssueInstant(new \DateTime())
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()));
} | php | public function createLogoutRequest()
{
return (new LogoutRequest())
->setID(Helper::generateID())
->setVersion(SamlConstants::VERSION_20)
->setIssueInstant(new \DateTime())
->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()));
} | [
"public",
"function",
"createLogoutRequest",
"(",
")",
"{",
"return",
"(",
"new",
"LogoutRequest",
"(",
")",
")",
"->",
"setID",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
"->",
"setVersion",
"(",
"SamlConstants",
"::",
"VERSION_20",
")",
"->",
"setIssueInstant",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"setIssuer",
"(",
"new",
"Issuer",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getServiceProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
")",
")",
";",
"}"
] | Create a Saml Logout Request
@return LogoutRequest|SamlMessage | [
"Create",
"a",
"Saml",
"Logout",
"Request"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L244-L251 |
29,986 | flash-global/connect-client | src/Saml.php | Saml.prepareLogoutRequest | public function prepareLogoutRequest(User $user, $sessionIndex = null)
{
$request = $this->createLogoutRequest();
$request->setNameID(
new NameID(
$user->getUserName(),
SamlConstants::NAME_ID_FORMAT_UNSPECIFIED
)
);
if (!is_null($sessionIndex)) {
$request->setSessionIndex($sessionIndex);
}
$request->setDestination(
$this->getMetadata()->getFirstIdpSsoDescriptor()->getFirstSingleLogoutService()->getLocation()
);
$request->setRelayState(Helper::generateID());
$this->signMessage($request);
return $request;
} | php | public function prepareLogoutRequest(User $user, $sessionIndex = null)
{
$request = $this->createLogoutRequest();
$request->setNameID(
new NameID(
$user->getUserName(),
SamlConstants::NAME_ID_FORMAT_UNSPECIFIED
)
);
if (!is_null($sessionIndex)) {
$request->setSessionIndex($sessionIndex);
}
$request->setDestination(
$this->getMetadata()->getFirstIdpSsoDescriptor()->getFirstSingleLogoutService()->getLocation()
);
$request->setRelayState(Helper::generateID());
$this->signMessage($request);
return $request;
} | [
"public",
"function",
"prepareLogoutRequest",
"(",
"User",
"$",
"user",
",",
"$",
"sessionIndex",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createLogoutRequest",
"(",
")",
";",
"$",
"request",
"->",
"setNameID",
"(",
"new",
"NameID",
"(",
"$",
"user",
"->",
"getUserName",
"(",
")",
",",
"SamlConstants",
"::",
"NAME_ID_FORMAT_UNSPECIFIED",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"sessionIndex",
")",
")",
"{",
"$",
"request",
"->",
"setSessionIndex",
"(",
"$",
"sessionIndex",
")",
";",
"}",
"$",
"request",
"->",
"setDestination",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getFirstSingleLogoutService",
"(",
")",
"->",
"getLocation",
"(",
")",
")",
";",
"$",
"request",
"->",
"setRelayState",
"(",
"Helper",
"::",
"generateID",
"(",
")",
")",
";",
"$",
"this",
"->",
"signMessage",
"(",
"$",
"request",
")",
";",
"return",
"$",
"request",
";",
"}"
] | Prepare LogoutRequest before sending
@param User $user
@param null $sessionIndex
@return LogoutRequest|SamlMessage | [
"Prepare",
"LogoutRequest",
"before",
"sending"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L261-L285 |
29,987 | flash-global/connect-client | src/Saml.php | Saml.getHttpRedirectBindingResponse | public function getHttpRedirectBindingResponse(AuthnRequest $request = null)
{
if (is_null($request)) {
$request = $this->buildAuthnRequest();
}
$context = new MessageContext();
$context->setMessage($request);
$binding = (new BindingFactory())->create(SamlConstants::BINDING_SAML2_HTTP_REDIRECT);
return new RedirectResponse($binding->send($context)->getTargetUrl());
} | php | public function getHttpRedirectBindingResponse(AuthnRequest $request = null)
{
if (is_null($request)) {
$request = $this->buildAuthnRequest();
}
$context = new MessageContext();
$context->setMessage($request);
$binding = (new BindingFactory())->create(SamlConstants::BINDING_SAML2_HTTP_REDIRECT);
return new RedirectResponse($binding->send($context)->getTargetUrl());
} | [
"public",
"function",
"getHttpRedirectBindingResponse",
"(",
"AuthnRequest",
"$",
"request",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"buildAuthnRequest",
"(",
")",
";",
"}",
"$",
"context",
"=",
"new",
"MessageContext",
"(",
")",
";",
"$",
"context",
"->",
"setMessage",
"(",
"$",
"request",
")",
";",
"$",
"binding",
"=",
"(",
"new",
"BindingFactory",
"(",
")",
")",
"->",
"create",
"(",
"SamlConstants",
"::",
"BINDING_SAML2_HTTP_REDIRECT",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"binding",
"->",
"send",
"(",
"$",
"context",
")",
"->",
"getTargetUrl",
"(",
")",
")",
";",
"}"
] | Returns the AuthnRequest using HTTP Redirect Binding to Identity Provider SSO location
@param AuthnRequest $request
@return RedirectResponse | [
"Returns",
"the",
"AuthnRequest",
"using",
"HTTP",
"Redirect",
"Binding",
"to",
"Identity",
"Provider",
"SSO",
"location"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L294-L306 |
29,988 | flash-global/connect-client | src/Saml.php | Saml.getHttpPostBindingResponse | public function getHttpPostBindingResponse(SamlMessage $message)
{
$bindingFactory = new BindingFactory();
$postBinding = $bindingFactory->create(SamlConstants::BINDING_SAML2_HTTP_POST);
$messageContext = new MessageContext();
$messageContext->setMessage($message);
$httpResponse = $postBinding->send($messageContext);
return new HtmlResponse($httpResponse->getContent());
} | php | public function getHttpPostBindingResponse(SamlMessage $message)
{
$bindingFactory = new BindingFactory();
$postBinding = $bindingFactory->create(SamlConstants::BINDING_SAML2_HTTP_POST);
$messageContext = new MessageContext();
$messageContext->setMessage($message);
$httpResponse = $postBinding->send($messageContext);
return new HtmlResponse($httpResponse->getContent());
} | [
"public",
"function",
"getHttpPostBindingResponse",
"(",
"SamlMessage",
"$",
"message",
")",
"{",
"$",
"bindingFactory",
"=",
"new",
"BindingFactory",
"(",
")",
";",
"$",
"postBinding",
"=",
"$",
"bindingFactory",
"->",
"create",
"(",
"SamlConstants",
"::",
"BINDING_SAML2_HTTP_POST",
")",
";",
"$",
"messageContext",
"=",
"new",
"MessageContext",
"(",
")",
";",
"$",
"messageContext",
"->",
"setMessage",
"(",
"$",
"message",
")",
";",
"$",
"httpResponse",
"=",
"$",
"postBinding",
"->",
"send",
"(",
"$",
"messageContext",
")",
";",
"return",
"new",
"HtmlResponse",
"(",
"$",
"httpResponse",
"->",
"getContent",
"(",
")",
")",
";",
"}"
] | Returns the HtmlResponse with the form of PostBinding as content
@param SamlMessage $message
@return HtmlResponse | [
"Returns",
"the",
"HtmlResponse",
"with",
"the",
"form",
"of",
"PostBinding",
"as",
"content"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L315-L326 |
29,989 | flash-global/connect-client | src/Saml.php | Saml.signMessage | public function signMessage(SamlMessage $message)
{
return $message->setSignature(
new SignatureWriter(
$this->getMetadata()
->getFirstSpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate(),
KeyHelper::createPrivateKey($this->getPrivateKey(), '')
)
);
} | php | public function signMessage(SamlMessage $message)
{
return $message->setSignature(
new SignatureWriter(
$this->getMetadata()
->getFirstSpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate(),
KeyHelper::createPrivateKey($this->getPrivateKey(), '')
)
);
} | [
"public",
"function",
"signMessage",
"(",
"SamlMessage",
"$",
"message",
")",
"{",
"return",
"$",
"message",
"->",
"setSignature",
"(",
"new",
"SignatureWriter",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
",",
"KeyHelper",
"::",
"createPrivateKey",
"(",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
",",
"''",
")",
")",
")",
";",
"}"
] | Sign a Saml Message
@param SamlMessage $message
@return SamlMessage | [
"Sign",
"a",
"Saml",
"Message"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L335-L346 |
29,990 | flash-global/connect-client | src/Saml.php | Saml.validateSignature | public function validateSignature($message, XMLSecurityKey $key)
{
$reader = $message->getSignature();
if ($reader instanceof AbstractSignatureReader) {
try {
return $reader->validate($key);
} catch (\Exception $e) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied', $e);
}
} else {
throw new SecurityException('Saml message signature is not specified');
}
} | php | public function validateSignature($message, XMLSecurityKey $key)
{
$reader = $message->getSignature();
if ($reader instanceof AbstractSignatureReader) {
try {
return $reader->validate($key);
} catch (\Exception $e) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied', $e);
}
} else {
throw new SecurityException('Saml message signature is not specified');
}
} | [
"public",
"function",
"validateSignature",
"(",
"$",
"message",
",",
"XMLSecurityKey",
"$",
"key",
")",
"{",
"$",
"reader",
"=",
"$",
"message",
"->",
"getSignature",
"(",
")",
";",
"if",
"(",
"$",
"reader",
"instanceof",
"AbstractSignatureReader",
")",
"{",
"try",
"{",
"return",
"$",
"reader",
"->",
"validate",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SamlException",
"(",
"'urn:oasis:names:tc:SAML:2.0:status:RequestDenied'",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"SecurityException",
"(",
"'Saml message signature is not specified'",
")",
";",
"}",
"}"
] | Validate a signed message
@param SamlMessage|Assertion $message
@param XMLSecurityKey $key
@return bool
@throws SamlException|SecurityException | [
"Validate",
"a",
"signed",
"message"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L358-L370 |
29,991 | flash-global/connect-client | src/Saml.php | Saml.validateIssuer | public function validateIssuer(SamlMessage $message)
{
if ($this->getMetadata()->getIdentityProvider()->getEntityID() != $message->getIssuer()->getValue()) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | php | public function validateIssuer(SamlMessage $message)
{
if ($this->getMetadata()->getIdentityProvider()->getEntityID() != $message->getIssuer()->getValue()) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | [
"public",
"function",
"validateIssuer",
"(",
"SamlMessage",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getIdentityProvider",
"(",
")",
"->",
"getEntityID",
"(",
")",
"!=",
"$",
"message",
"->",
"getIssuer",
"(",
")",
"->",
"getValue",
"(",
")",
")",
"{",
"throw",
"new",
"SamlException",
"(",
"'urn:oasis:names:tc:SAML:2.0:status:RequestDenied'",
")",
";",
"}",
"}"
] | Validate IdP Response issuer
@param SamlMessage $message
@throws SamlException | [
"Validate",
"IdP",
"Response",
"issuer"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L391-L396 |
29,992 | flash-global/connect-client | src/Saml.php | Saml.validateDestination | public function validateDestination(Response $response)
{
if ($this->getMetadata()->getFirstSpSsoDescriptor()->getFirstAssertionConsumerService()->getLocation()
!= $response->getDestination()
) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | php | public function validateDestination(Response $response)
{
if ($this->getMetadata()->getFirstSpSsoDescriptor()->getFirstAssertionConsumerService()->getLocation()
!= $response->getDestination()
) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | [
"public",
"function",
"validateDestination",
"(",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstSpSsoDescriptor",
"(",
")",
"->",
"getFirstAssertionConsumerService",
"(",
")",
"->",
"getLocation",
"(",
")",
"!=",
"$",
"response",
"->",
"getDestination",
"(",
")",
")",
"{",
"throw",
"new",
"SamlException",
"(",
"'urn:oasis:names:tc:SAML:2.0:status:RequestDenied'",
")",
";",
"}",
"}"
] | Validate IdP Response destination
@param Response $response
@throws SamlException | [
"Validate",
"IdP",
"Response",
"destination"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L405-L412 |
29,993 | flash-global/connect-client | src/Saml.php | Saml.validateRelayState | public function validateRelayState(Response $response, $relayState)
{
if ($response->getRelayState() != null && $response->getRelayState() != $relayState) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | php | public function validateRelayState(Response $response, $relayState)
{
if ($response->getRelayState() != null && $response->getRelayState() != $relayState) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | [
"public",
"function",
"validateRelayState",
"(",
"Response",
"$",
"response",
",",
"$",
"relayState",
")",
"{",
"if",
"(",
"$",
"response",
"->",
"getRelayState",
"(",
")",
"!=",
"null",
"&&",
"$",
"response",
"->",
"getRelayState",
"(",
")",
"!=",
"$",
"relayState",
")",
"{",
"throw",
"new",
"SamlException",
"(",
"'urn:oasis:names:tc:SAML:2.0:status:RequestDenied'",
")",
";",
"}",
"}"
] | Validate IdP Response RelayState
@param Response $response
@param string $relayState
@throws SamlException | [
"Validate",
"IdP",
"Response",
"RelayState"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L422-L427 |
29,994 | flash-global/connect-client | src/Saml.php | Saml.validateNameId | public function validateNameId(LogoutRequest $request, User $user)
{
if ($request->getNameID()->getValue() != $user->getUserName()) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | php | public function validateNameId(LogoutRequest $request, User $user)
{
if ($request->getNameID()->getValue() != $user->getUserName()) {
throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied');
}
} | [
"public",
"function",
"validateNameId",
"(",
"LogoutRequest",
"$",
"request",
",",
"User",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"getNameID",
"(",
")",
"->",
"getValue",
"(",
")",
"!=",
"$",
"user",
"->",
"getUserName",
"(",
")",
")",
"{",
"throw",
"new",
"SamlException",
"(",
"'urn:oasis:names:tc:SAML:2.0:status:RequestDenied'",
")",
";",
"}",
"}"
] | Validate a LogoutRequest NameId
@param LogoutRequest $request
@param User $user
@throws SamlException | [
"Validate",
"a",
"LogoutRequest",
"NameId"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L437-L442 |
29,995 | flash-global/connect-client | src/Saml.php | Saml.validateResponse | public function validateResponse(Response $response, $relayState)
{
$this->validateIssuer($response);
$this->validateDestination($response);
if ($relayState) {
$this->validateRelayState($response, $relayState);
}
$public = KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
);
if ($this->hasSignature($response)) {
$this->validateSignature($response, $public);
}
if ($response->getAllEncryptedAssertions()) {
$private = KeyHelper::createPrivateKey($this->getPrivateKey(), null);
/** @var EncryptedAssertionReader $encryptedAssertion */
foreach ($response->getAllEncryptedAssertions() as $encryptedAssertion) {
$assertion = $encryptedAssertion->decryptAssertion($private, new DeserializationContext());
if ($this->hasSignature($assertion)) {
$this->validateSignature($assertion, $public);
}
$response->addAssertion($assertion);
}
}
} | php | public function validateResponse(Response $response, $relayState)
{
$this->validateIssuer($response);
$this->validateDestination($response);
if ($relayState) {
$this->validateRelayState($response, $relayState);
}
$public = KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
);
if ($this->hasSignature($response)) {
$this->validateSignature($response, $public);
}
if ($response->getAllEncryptedAssertions()) {
$private = KeyHelper::createPrivateKey($this->getPrivateKey(), null);
/** @var EncryptedAssertionReader $encryptedAssertion */
foreach ($response->getAllEncryptedAssertions() as $encryptedAssertion) {
$assertion = $encryptedAssertion->decryptAssertion($private, new DeserializationContext());
if ($this->hasSignature($assertion)) {
$this->validateSignature($assertion, $public);
}
$response->addAssertion($assertion);
}
}
} | [
"public",
"function",
"validateResponse",
"(",
"Response",
"$",
"response",
",",
"$",
"relayState",
")",
"{",
"$",
"this",
"->",
"validateIssuer",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"validateDestination",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"relayState",
")",
"{",
"$",
"this",
"->",
"validateRelayState",
"(",
"$",
"response",
",",
"$",
"relayState",
")",
";",
"}",
"$",
"public",
"=",
"KeyHelper",
"::",
"createPublicKey",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasSignature",
"(",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"validateSignature",
"(",
"$",
"response",
",",
"$",
"public",
")",
";",
"}",
"if",
"(",
"$",
"response",
"->",
"getAllEncryptedAssertions",
"(",
")",
")",
"{",
"$",
"private",
"=",
"KeyHelper",
"::",
"createPrivateKey",
"(",
"$",
"this",
"->",
"getPrivateKey",
"(",
")",
",",
"null",
")",
";",
"/** @var EncryptedAssertionReader $encryptedAssertion */",
"foreach",
"(",
"$",
"response",
"->",
"getAllEncryptedAssertions",
"(",
")",
"as",
"$",
"encryptedAssertion",
")",
"{",
"$",
"assertion",
"=",
"$",
"encryptedAssertion",
"->",
"decryptAssertion",
"(",
"$",
"private",
",",
"new",
"DeserializationContext",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasSignature",
"(",
"$",
"assertion",
")",
")",
"{",
"$",
"this",
"->",
"validateSignature",
"(",
"$",
"assertion",
",",
"$",
"public",
")",
";",
"}",
"$",
"response",
"->",
"addAssertion",
"(",
"$",
"assertion",
")",
";",
"}",
"}",
"}"
] | Validate a IdP Response
@param Response $response
@param $relayState | [
"Validate",
"a",
"IdP",
"Response"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L450-L482 |
29,996 | flash-global/connect-client | src/Saml.php | Saml.validateLogoutRequest | public function validateLogoutRequest(LogoutRequest $request, User $user)
{
$this->validateIssuer($request);
$this->validateNameId($request, $user);
if ($this->hasSignature($request)) {
$this->validateSignature(
$request,
KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
)
);
}
} | php | public function validateLogoutRequest(LogoutRequest $request, User $user)
{
$this->validateIssuer($request);
$this->validateNameId($request, $user);
if ($this->hasSignature($request)) {
$this->validateSignature(
$request,
KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
)
);
}
} | [
"public",
"function",
"validateLogoutRequest",
"(",
"LogoutRequest",
"$",
"request",
",",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"validateIssuer",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"validateNameId",
"(",
"$",
"request",
",",
"$",
"user",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasSignature",
"(",
"$",
"request",
")",
")",
"{",
"$",
"this",
"->",
"validateSignature",
"(",
"$",
"request",
",",
"KeyHelper",
"::",
"createPublicKey",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
")",
")",
";",
"}",
"}"
] | Validate a LogoutRequest
@param LogoutRequest $request
@param User $user | [
"Validate",
"a",
"LogoutRequest"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L490-L505 |
29,997 | flash-global/connect-client | src/Saml.php | Saml.validateLogoutResponse | public function validateLogoutResponse(LogoutResponse $response)
{
$this->validateIssuer($response);
if ($this->hasSignature($response)) {
$this->validateSignature(
$response,
KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
)
);
}
} | php | public function validateLogoutResponse(LogoutResponse $response)
{
$this->validateIssuer($response);
if ($this->hasSignature($response)) {
$this->validateSignature(
$response,
KeyHelper::createPublicKey(
$this->getMetadata()->getFirstIdpSsoDescriptor()
->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
->getCertificate()
)
);
}
} | [
"public",
"function",
"validateLogoutResponse",
"(",
"LogoutResponse",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"validateIssuer",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasSignature",
"(",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"validateSignature",
"(",
"$",
"response",
",",
"KeyHelper",
"::",
"createPublicKey",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getFirstIdpSsoDescriptor",
"(",
")",
"->",
"getFirstKeyDescriptor",
"(",
"KeyDescriptor",
"::",
"USE_SIGNING",
")",
"->",
"getCertificate",
"(",
")",
")",
")",
";",
"}",
"}"
] | Validate a LogoutResponse
@param LogoutResponse $response | [
"Validate",
"a",
"LogoutResponse"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L512-L526 |
29,998 | flash-global/connect-client | src/Saml.php | Saml.retrieveUserFromAssertion | public function retrieveUserFromAssertion(Assertion $assertion)
{
$user = null;
$role = null;
foreach ($assertion->getAllAttributeStatements() as $attributeStatement) {
foreach ($attributeStatement->getAllAttributes() as $attribute) {
switch ($attribute->getName()) {
case 'user_entity':
$user = new User(\json_decode($attribute->getFirstAttributeValue(), true));
break;
case ClaimTypes::ROLE:
$role = $attribute->getFirstAttributeValue();
}
}
}
if ($user instanceof User) {
$user->setCurrentRole($role);
}
return $user;
} | php | public function retrieveUserFromAssertion(Assertion $assertion)
{
$user = null;
$role = null;
foreach ($assertion->getAllAttributeStatements() as $attributeStatement) {
foreach ($attributeStatement->getAllAttributes() as $attribute) {
switch ($attribute->getName()) {
case 'user_entity':
$user = new User(\json_decode($attribute->getFirstAttributeValue(), true));
break;
case ClaimTypes::ROLE:
$role = $attribute->getFirstAttributeValue();
}
}
}
if ($user instanceof User) {
$user->setCurrentRole($role);
}
return $user;
} | [
"public",
"function",
"retrieveUserFromAssertion",
"(",
"Assertion",
"$",
"assertion",
")",
"{",
"$",
"user",
"=",
"null",
";",
"$",
"role",
"=",
"null",
";",
"foreach",
"(",
"$",
"assertion",
"->",
"getAllAttributeStatements",
"(",
")",
"as",
"$",
"attributeStatement",
")",
"{",
"foreach",
"(",
"$",
"attributeStatement",
"->",
"getAllAttributes",
"(",
")",
"as",
"$",
"attribute",
")",
"{",
"switch",
"(",
"$",
"attribute",
"->",
"getName",
"(",
")",
")",
"{",
"case",
"'user_entity'",
":",
"$",
"user",
"=",
"new",
"User",
"(",
"\\",
"json_decode",
"(",
"$",
"attribute",
"->",
"getFirstAttributeValue",
"(",
")",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"ClaimTypes",
"::",
"ROLE",
":",
"$",
"role",
"=",
"$",
"attribute",
"->",
"getFirstAttributeValue",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"user",
"instanceof",
"User",
")",
"{",
"$",
"user",
"->",
"setCurrentRole",
"(",
"$",
"role",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Retrieves a User instance from Response Assertion send by IdP
@param Assertion $assertion
@return User | [
"Retrieves",
"a",
"User",
"instance",
"from",
"Response",
"Assertion",
"send",
"by",
"IdP"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L535-L557 |
29,999 | flash-global/connect-client | src/Saml.php | Saml.receiveMessage | protected function receiveMessage()
{
if (empty($_POST)) {
$_POST = $this->retrievePostWithInputStream();
}
$request = Request::createFromGlobals();
try {
$binding = (new BindingFactory())->getBindingByRequest($request);
} catch (\Exception $e) {
return null;
}
$context = new MessageContext();
$binding->receive($request, $context);
return $context;
} | php | protected function receiveMessage()
{
if (empty($_POST)) {
$_POST = $this->retrievePostWithInputStream();
}
$request = Request::createFromGlobals();
try {
$binding = (new BindingFactory())->getBindingByRequest($request);
} catch (\Exception $e) {
return null;
}
$context = new MessageContext();
$binding->receive($request, $context);
return $context;
} | [
"protected",
"function",
"receiveMessage",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_POST",
")",
")",
"{",
"$",
"_POST",
"=",
"$",
"this",
"->",
"retrievePostWithInputStream",
"(",
")",
";",
"}",
"$",
"request",
"=",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"try",
"{",
"$",
"binding",
"=",
"(",
"new",
"BindingFactory",
"(",
")",
")",
"->",
"getBindingByRequest",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"$",
"context",
"=",
"new",
"MessageContext",
"(",
")",
";",
"$",
"binding",
"->",
"receive",
"(",
"$",
"request",
",",
"$",
"context",
")",
";",
"return",
"$",
"context",
";",
"}"
] | Receive Saml message from globals variables
@return MessageContext | [
"Receive",
"Saml",
"message",
"from",
"globals",
"variables"
] | 003db4187fbba0c0b7bd7a1c53d8487da06748bd | https://github.com/flash-global/connect-client/blob/003db4187fbba0c0b7bd7a1c53d8487da06748bd/src/Saml.php#L564-L582 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.