repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_KeyValueMessage._getExtensionKpublicgs | function _getExtensionKpublicgs($aliases)
{
if ($aliases === null) {
$aliases = new Auth_OpenID_NamespaceMap();
}
$ax_args = array();
foreach ($this->data as $type_uri => $values) {
$alias = $aliases->add($type_uri);
$ax_args['type.' . $alias] = $type_uri;
$ax_args['count.' . $alias] = strval(count($values));
foreach ($values as $i => $value) {
$key = sprintf('value.%s.%d', $alias, $i + 1);
$ax_args[$key] = $value;
}
}
return $ax_args;
} | php | function _getExtensionKpublicgs($aliases)
{
if ($aliases === null) {
$aliases = new Auth_OpenID_NamespaceMap();
}
$ax_args = array();
foreach ($this->data as $type_uri => $values) {
$alias = $aliases->add($type_uri);
$ax_args['type.' . $alias] = $type_uri;
$ax_args['count.' . $alias] = strval(count($values));
foreach ($values as $i => $value) {
$key = sprintf('value.%s.%d', $alias, $i + 1);
$ax_args[$key] = $value;
}
}
return $ax_args;
} | [
"function",
"_getExtensionKpublicgs",
"(",
"$",
"aliases",
")",
"{",
"if",
"(",
"$",
"aliases",
"===",
"null",
")",
"{",
"$",
"aliases",
"=",
"new",
"Auth_OpenID_NamespaceMap",
"(",
")",
";",
"}",
"$",
"ax_args",
"=",
"array",
"(",
")",
";",
"foreach",
... | Get the extension arguments for the key/value pairs contained
in this message.
@param Auth_OpenID_NamespaceMap $aliases An alias mapping. Set to None if you don't care
about the aliases for this request.
@access private
@return array | [
"Get",
"the",
"extension",
"arguments",
"for",
"the",
"key",
"/",
"value",
"pairs",
"contained",
"in",
"this",
"message",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L606-L627 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_KeyValueMessage.parseExtensionArgs | function parseExtensionArgs($ax_args)
{
$result = $this->_checkMode($ax_args);
if (Auth_OpenID_AX::isError($result)) {
return $result;
}
$aliases = new Auth_OpenID_NamespaceMap();
foreach ($ax_args as $key => $value) {
if (strpos($key, 'type.') === 0) {
$type_uri = $value;
$alias = substr($key, 5);
$result = Auth_OpenID_AX_checkAlias($alias);
if (Auth_OpenID_AX::isError($result)) {
return $result;
}
$alias = $aliases->addAlias($type_uri, $alias);
if ($alias === null) {
return new Auth_OpenID_AX_Error(
sprintf("Could not add alias %s for URI %s",
$alias, $type_uri)
);
}
}
}
foreach ($aliases->iteritems() as $pair) {
list($type_uri, $alias) = $pair;
if (array_key_exists('count.' . $alias, $ax_args) && ($ax_args['count.' . $alias] !== Auth_OpenID_AX_UNLIMITED_VALUES)) {
$count_key = 'count.' . $alias;
$count_s = $ax_args[$count_key];
$count = Auth_OpenID::intval($count_s);
if ($count === false) {
return new Auth_OpenID_AX_Error(
sprintf("Integer value expected for %s, got %s",
'count. %s' . $alias, $count_s,
Auth_OpenID_AX_UNLIMITED_VALUES)
);
}
$values = array();
for ($i = 1; $i < $count + 1; $i++) {
$value_key = sprintf('value.%s.%d', $alias, $i);
if (!array_key_exists($value_key, $ax_args)) {
return new Auth_OpenID_AX_Error(
sprintf(
"No value found for key %s",
$value_key));
}
$value = $ax_args[$value_key];
$values[] = $value;
}
} else {
$key = 'value.' . $alias;
if (!array_key_exists($key, $ax_args)) {
return new Auth_OpenID_AX_Error(
sprintf(
"No value found for key %s",
$key));
}
$value = $ax_args['value.' . $alias];
if ($value == '') {
$values = array();
} else {
$values = array($value);
}
}
$this->data[$type_uri] = $values;
}
return true;
} | php | function parseExtensionArgs($ax_args)
{
$result = $this->_checkMode($ax_args);
if (Auth_OpenID_AX::isError($result)) {
return $result;
}
$aliases = new Auth_OpenID_NamespaceMap();
foreach ($ax_args as $key => $value) {
if (strpos($key, 'type.') === 0) {
$type_uri = $value;
$alias = substr($key, 5);
$result = Auth_OpenID_AX_checkAlias($alias);
if (Auth_OpenID_AX::isError($result)) {
return $result;
}
$alias = $aliases->addAlias($type_uri, $alias);
if ($alias === null) {
return new Auth_OpenID_AX_Error(
sprintf("Could not add alias %s for URI %s",
$alias, $type_uri)
);
}
}
}
foreach ($aliases->iteritems() as $pair) {
list($type_uri, $alias) = $pair;
if (array_key_exists('count.' . $alias, $ax_args) && ($ax_args['count.' . $alias] !== Auth_OpenID_AX_UNLIMITED_VALUES)) {
$count_key = 'count.' . $alias;
$count_s = $ax_args[$count_key];
$count = Auth_OpenID::intval($count_s);
if ($count === false) {
return new Auth_OpenID_AX_Error(
sprintf("Integer value expected for %s, got %s",
'count. %s' . $alias, $count_s,
Auth_OpenID_AX_UNLIMITED_VALUES)
);
}
$values = array();
for ($i = 1; $i < $count + 1; $i++) {
$value_key = sprintf('value.%s.%d', $alias, $i);
if (!array_key_exists($value_key, $ax_args)) {
return new Auth_OpenID_AX_Error(
sprintf(
"No value found for key %s",
$value_key));
}
$value = $ax_args[$value_key];
$values[] = $value;
}
} else {
$key = 'value.' . $alias;
if (!array_key_exists($key, $ax_args)) {
return new Auth_OpenID_AX_Error(
sprintf(
"No value found for key %s",
$key));
}
$value = $ax_args['value.' . $alias];
if ($value == '') {
$values = array();
} else {
$values = array($value);
}
}
$this->data[$type_uri] = $values;
}
return true;
} | [
"function",
"parseExtensionArgs",
"(",
"$",
"ax_args",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_checkMode",
"(",
"$",
"ax_args",
")",
";",
"if",
"(",
"Auth_OpenID_AX",
"::",
"isError",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result... | Parse attribute exchange key/value arguments into this object.
@param array $ax_args The attribute exchange fetch_response
arguments, with namespacing removed.
@return Auth_OpenID_AX_Error|bool | [
"Parse",
"attribute",
"exchange",
"key",
"/",
"value",
"arguments",
"into",
"this",
"object",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L637-L723 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_KeyValueMessage.getSingle | function getSingle($type_uri, $default=null)
{
$values = Auth_OpenID::arrayGet($this->data, $type_uri);
if (!$values) {
return $default;
} else if (count($values) == 1) {
return $values[0];
} else {
return new Auth_OpenID_AX_Error(
sprintf('More than one value present for %s',
$type_uri)
);
}
} | php | function getSingle($type_uri, $default=null)
{
$values = Auth_OpenID::arrayGet($this->data, $type_uri);
if (!$values) {
return $default;
} else if (count($values) == 1) {
return $values[0];
} else {
return new Auth_OpenID_AX_Error(
sprintf('More than one value present for %s',
$type_uri)
);
}
} | [
"function",
"getSingle",
"(",
"$",
"type_uri",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"Auth_OpenID",
"::",
"arrayGet",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"type_uri",
")",
";",
"if",
"(",
"!",
"$",
"values",
")",
"{",... | Get a single value for an attribute. If no value was sent for
this attribute, use the supplied default. If there is more than
one value for this attribute, this method will fail.
@param string $type_uri The URI for the attribute
@param mixed $default The value to return if the attribute was not
sent in the fetch_response.
@return Auth_OpenID_AX_Error|mixed | [
"Get",
"a",
"single",
"value",
"for",
"an",
"attribute",
".",
"If",
"no",
"value",
"was",
"sent",
"for",
"this",
"attribute",
"use",
"the",
"supplied",
"default",
".",
"If",
"there",
"is",
"more",
"than",
"one",
"value",
"for",
"this",
"attribute",
"this... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L736-L749 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_KeyValueMessage.get | function get($type_uri)
{
if (array_key_exists($type_uri, $this->data)) {
return $this->data[$type_uri];
} else {
return new Auth_OpenID_AX_Error(
sprintf("Type URI %s not found in response",
$type_uri)
);
}
} | php | function get($type_uri)
{
if (array_key_exists($type_uri, $this->data)) {
return $this->data[$type_uri];
} else {
return new Auth_OpenID_AX_Error(
sprintf("Type URI %s not found in response",
$type_uri)
);
}
} | [
"function",
"get",
"(",
"$",
"type_uri",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type_uri",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"type_uri",
"]",
";",
"}",
"else",
"{",
"return",
... | Get the list of values for this attribute in the
fetch_response.
XXX: what to do if the values are not present? default
parameter? this is funny because it's always supposed to return
a list, so the default may break that, though it's provided by
the user's code, so it might be okay. If no default is
supplied, should the return be None or []?
@param string $type_uri The URI of the attribute
@return Auth_OpenID_AX_Error|array The list of values for this attribute in the
response. May be an empty list. If the attribute was not sent
in the response, returns Auth_OpenID_AX_Error. | [
"Get",
"the",
"list",
"of",
"values",
"for",
"this",
"attribute",
"in",
"the",
"fetch_response",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L767-L777 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_FetchResponse.getExtensionArgs | function getExtensionArgs($request=null)
{
$aliases = new Auth_OpenID_NamespaceMap();
$zero_value_types = array();
if ($request !== null) {
// Validate the data in the context of the request (the
// same attributes should be present in each, and the
// counts in the response must be no more than the counts
// in the request)
foreach ($this->data as $type_uri => $unused) {
if (!$request->contains($type_uri)) {
return new Auth_OpenID_AX_Error(
sprintf("Response attribute not present in request: %s",
$type_uri)
);
}
}
foreach ($request->iterAttrs() as $attr_info) {
// Copy the aliases from the request so that reading
// the response in light of the request is easier
if ($attr_info->alias === null) {
$aliases->add($attr_info->type_uri);
} else {
$alias = $aliases->addAlias($attr_info->type_uri,
$attr_info->alias);
if ($alias === null) {
return new Auth_OpenID_AX_Error(
sprintf("Could not add alias %s for URI %s",
$attr_info->alias, $attr_info->type_uri)
);
}
}
if (array_key_exists($attr_info->type_uri, $this->data)) {
$values = $this->data[$attr_info->type_uri];
} else {
$values = array();
$zero_value_types[] = $attr_info;
}
if (($attr_info->count != Auth_OpenID_AX_UNLIMITED_VALUES) &&
($attr_info->count < count($values))) {
return new Auth_OpenID_AX_Error(
sprintf("More than the number of requested values " .
"were specified for %s",
$attr_info->type_uri)
);
}
}
}
$kv_args = $this->_getExtensionKpublicgs($aliases);
// Add the KV args into the response with the args that are
// unique to the fetch_response
$ax_args = $this->_newArgs();
// For each requested attribute, put its type/alias and count
// into the response even if no data were returned.
foreach ($zero_value_types as $attr_info) {
$alias = $aliases->getAlias($attr_info->type_uri);
$kv_args['type.' . $alias] = $attr_info->type_uri;
$kv_args['count.' . $alias] = '0';
}
$update_url = null;
if ($request) {
$update_url = $request->update_url;
} else {
$update_url = $this->update_url;
}
if ($update_url) {
$ax_args['update_url'] = $update_url;
}
Auth_OpenID::update($ax_args, $kv_args);
return $ax_args;
} | php | function getExtensionArgs($request=null)
{
$aliases = new Auth_OpenID_NamespaceMap();
$zero_value_types = array();
if ($request !== null) {
// Validate the data in the context of the request (the
// same attributes should be present in each, and the
// counts in the response must be no more than the counts
// in the request)
foreach ($this->data as $type_uri => $unused) {
if (!$request->contains($type_uri)) {
return new Auth_OpenID_AX_Error(
sprintf("Response attribute not present in request: %s",
$type_uri)
);
}
}
foreach ($request->iterAttrs() as $attr_info) {
// Copy the aliases from the request so that reading
// the response in light of the request is easier
if ($attr_info->alias === null) {
$aliases->add($attr_info->type_uri);
} else {
$alias = $aliases->addAlias($attr_info->type_uri,
$attr_info->alias);
if ($alias === null) {
return new Auth_OpenID_AX_Error(
sprintf("Could not add alias %s for URI %s",
$attr_info->alias, $attr_info->type_uri)
);
}
}
if (array_key_exists($attr_info->type_uri, $this->data)) {
$values = $this->data[$attr_info->type_uri];
} else {
$values = array();
$zero_value_types[] = $attr_info;
}
if (($attr_info->count != Auth_OpenID_AX_UNLIMITED_VALUES) &&
($attr_info->count < count($values))) {
return new Auth_OpenID_AX_Error(
sprintf("More than the number of requested values " .
"were specified for %s",
$attr_info->type_uri)
);
}
}
}
$kv_args = $this->_getExtensionKpublicgs($aliases);
// Add the KV args into the response with the args that are
// unique to the fetch_response
$ax_args = $this->_newArgs();
// For each requested attribute, put its type/alias and count
// into the response even if no data were returned.
foreach ($zero_value_types as $attr_info) {
$alias = $aliases->getAlias($attr_info->type_uri);
$kv_args['type.' . $alias] = $attr_info->type_uri;
$kv_args['count.' . $alias] = '0';
}
$update_url = null;
if ($request) {
$update_url = $request->update_url;
} else {
$update_url = $this->update_url;
}
if ($update_url) {
$ax_args['update_url'] = $update_url;
}
Auth_OpenID::update($ax_args, $kv_args);
return $ax_args;
} | [
"function",
"getExtensionArgs",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"aliases",
"=",
"new",
"Auth_OpenID_NamespaceMap",
"(",
")",
";",
"$",
"zero_value_types",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"request",
"!==",
"null",
")",
"{",
... | Serialize this object into arguments in the attribute exchange
namespace
@param Auth_OpenID_AX_FetchRequest|null $request
@return Auth_OpenID_AX_Error|array|null $args The dictionary of unqualified attribute exchange
arguments that represent this fetch_response, or
Auth_OpenID_AX_Error on error. | [
"Serialize",
"this",
"object",
"into",
"arguments",
"in",
"the",
"attribute",
"exchange",
"namespace"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L827-L911 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_FetchResponse.fromSuccessResponse | static function fromSuccessResponse($success_response, $signed=true)
{
$obj = new Auth_OpenID_AX_FetchResponse();
if ($signed) {
$ax_args = $success_response->getSignedNS($obj->ns_uri);
} else {
$ax_args = $success_response->message->getArgs($obj->ns_uri);
}
if ($ax_args === null || Auth_OpenID::isFailure($ax_args) ||
sizeof($ax_args) == 0) {
return null;
}
$result = $obj->parseExtensionArgs($ax_args);
if (Auth_OpenID_AX::isError($result)) {
#XXX log me
return null;
}
return $obj;
} | php | static function fromSuccessResponse($success_response, $signed=true)
{
$obj = new Auth_OpenID_AX_FetchResponse();
if ($signed) {
$ax_args = $success_response->getSignedNS($obj->ns_uri);
} else {
$ax_args = $success_response->message->getArgs($obj->ns_uri);
}
if ($ax_args === null || Auth_OpenID::isFailure($ax_args) ||
sizeof($ax_args) == 0) {
return null;
}
$result = $obj->parseExtensionArgs($ax_args);
if (Auth_OpenID_AX::isError($result)) {
#XXX log me
return null;
}
return $obj;
} | [
"static",
"function",
"fromSuccessResponse",
"(",
"$",
"success_response",
",",
"$",
"signed",
"=",
"true",
")",
"{",
"$",
"obj",
"=",
"new",
"Auth_OpenID_AX_FetchResponse",
"(",
")",
";",
"if",
"(",
"$",
"signed",
")",
"{",
"$",
"ax_args",
"=",
"$",
"su... | Construct a FetchResponse object from an OpenID library
SuccessResponse object.
@param Auth_OpenID_SuccessResponse $success_response A successful id_res response object
@param bool $signed Whether non-signed args should be processsed. If
True (the default), only signed arguments will be processsed.
@return Auth_OpenID_AX_FetchResponse|null A FetchResponse containing the data from the
OpenID message | [
"Construct",
"a",
"FetchResponse",
"object",
"from",
"an",
"OpenID",
"library",
"SuccessResponse",
"object",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L943-L962 |
openid/php-openid | Auth/OpenID/AX.php | Auth_OpenID_AX_StoreResponse.getExtensionArgs | function getExtensionArgs($request = null)
{
$ax_args = $this->_newArgs();
if ((!$this->succeeded()) && $this->error_message) {
$ax_args['error'] = $this->error_message;
}
return $ax_args;
} | php | function getExtensionArgs($request = null)
{
$ax_args = $this->_newArgs();
if ((!$this->succeeded()) && $this->error_message) {
$ax_args['error'] = $this->error_message;
}
return $ax_args;
} | [
"function",
"getExtensionArgs",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"ax_args",
"=",
"$",
"this",
"->",
"_newArgs",
"(",
")",
";",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"succeeded",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"error_messa... | Get the string arguments that should be added to an OpenID
message for this extension.
@param Auth_OpenID_Request|null $request
@return null | [
"Get",
"the",
"string",
"arguments",
"that",
"should",
"be",
"added",
"to",
"an",
"OpenID",
"message",
"for",
"this",
"extension",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/AX.php#L1044-L1052 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_PHPSession.get | function get($name, $default=null)
{
if (isset($_SESSION) && array_key_exists($name, $_SESSION)) {
return $_SESSION[$name];
} else {
return $default;
}
} | php | function get($name, $default=null)
{
if (isset($_SESSION) && array_key_exists($name, $_SESSION)) {
return $_SESSION[$name];
} else {
return $default;
}
} | [
"function",
"get",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
")",
"&&",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"_SESSION",
")",
")",
"{",
"return",
"$",
"_SESSION",
"[",
"$",
... | Get a key's value from the session.
@param string $name The name of the key to retrieve.
@param string $default The optional value to return if the key
is not found in the session.
@return mixed $result The key's value in the session or
$default if it isn't found. | [
"Get",
"a",
"key",
"s",
"value",
"from",
"the",
"session",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L38-L45 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_SessionLoader.fromSession | function fromSession($data)
{
if (!$data) {
return null;
}
$required = $this->requiredKeys();
foreach ($required as $k) {
if (!array_key_exists($k, $data)) {
return null;
}
}
if (!$this->check($data)) {
return null;
}
$data = array_merge($data, $this->prepareForLoad($data));
$obj = $this->newObject($data);
if (!$obj) {
return null;
}
foreach ($required as $k) {
$obj->$k = $data[$k];
}
return $obj;
} | php | function fromSession($data)
{
if (!$data) {
return null;
}
$required = $this->requiredKeys();
foreach ($required as $k) {
if (!array_key_exists($k, $data)) {
return null;
}
}
if (!$this->check($data)) {
return null;
}
$data = array_merge($data, $this->prepareForLoad($data));
$obj = $this->newObject($data);
if (!$obj) {
return null;
}
foreach ($required as $k) {
$obj->$k = $data[$k];
}
return $obj;
} | [
"function",
"fromSession",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"null",
";",
"}",
"$",
"required",
"=",
"$",
"this",
"->",
"requiredKeys",
"(",
")",
";",
"foreach",
"(",
"$",
"required",
"as",
"$",
"k",
")"... | Given a session data value (an array), this creates an object
(returned by $this->newObject()) whose attributes and values
are those in $data. Returns null if $data lacks keys found in
$this->requiredKeys(). Returns null if $this->check($data)
evaluates to false. Returns null if $this->newObject()
evaluates to false.
@access private
@param array $data
@return null | [
"Given",
"a",
"session",
"data",
"value",
"(",
"an",
"array",
")",
"this",
"creates",
"an",
"object",
"(",
"returned",
"by",
"$this",
"-",
">",
"newObject",
"()",
")",
"whose",
"attributes",
"and",
"values",
"are",
"those",
"in",
"$data",
".",
"Returns",... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L103-L133 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_SessionLoader.toSession | function toSession($obj)
{
$data = array();
foreach ($obj as $k => $v) {
$data[$k] = $v;
}
$extra = $this->prepareForSave($obj);
if ($extra && is_array($extra)) {
foreach ($extra as $k => $v) {
$data[$k] = $v;
}
}
return $data;
} | php | function toSession($obj)
{
$data = array();
foreach ($obj as $k => $v) {
$data[$k] = $v;
}
$extra = $this->prepareForSave($obj);
if ($extra && is_array($extra)) {
foreach ($extra as $k => $v) {
$data[$k] = $v;
}
}
return $data;
} | [
"function",
"toSession",
"(",
"$",
"obj",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"obj",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"extra",
"=... | Returns an array of keys and values built from the attributes
of $obj. If $this->prepareForSave($obj) returns an array, its keys
and values are used to update the $data array of attributes
from $obj.
@access private
@param object $obj
@return array | [
"Returns",
"an",
"array",
"of",
"keys",
"and",
"values",
"built",
"from",
"the",
"attributes",
"of",
"$obj",
".",
"If",
"$this",
"-",
">",
"prepareForSave",
"(",
"$obj",
")",
"returns",
"an",
"array",
"its",
"keys",
"and",
"values",
"are",
"used",
"to",
... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L174-L190 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_Manager.nextService | function nextService()
{
if ($this->services) {
$this->_current = array_shift($this->services);
} else {
$this->_current = null;
}
return $this->_current;
} | php | function nextService()
{
if ($this->services) {
$this->_current = array_shift($this->services);
} else {
$this->_current = null;
}
return $this->_current;
} | [
"function",
"nextService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"services",
")",
"{",
"$",
"this",
"->",
"_current",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"services",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_current",
"=",
"nu... | Return the next service
$this->current() will continue to return that service until the
next call to this method. | [
"Return",
"the",
"next",
"service"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L352-L362 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_Discovery.getNextService | function getNextService($discover_cb, $fetcher)
{
$manager = $this->getManager();
if (!$manager || (!$manager->services)) {
$this->destroyManager();
list($yadis_url, $services) = call_user_func_array($discover_cb,
array(
$this->url,
$fetcher,
));
$manager = $this->createManager($services, $yadis_url);
}
if ($manager) {
$loader = new Auth_Yadis_ManagerLoader();
$service = $manager->nextService();
$this->session->set($this->session_key,
serialize($loader->toSession($manager)));
} else {
$service = null;
}
return $service;
} | php | function getNextService($discover_cb, $fetcher)
{
$manager = $this->getManager();
if (!$manager || (!$manager->services)) {
$this->destroyManager();
list($yadis_url, $services) = call_user_func_array($discover_cb,
array(
$this->url,
$fetcher,
));
$manager = $this->createManager($services, $yadis_url);
}
if ($manager) {
$loader = new Auth_Yadis_ManagerLoader();
$service = $manager->nextService();
$this->session->set($this->session_key,
serialize($loader->toSession($manager)));
} else {
$service = null;
}
return $service;
} | [
"function",
"getNextService",
"(",
"$",
"discover_cb",
",",
"$",
"fetcher",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
";",
"if",
"(",
"!",
"$",
"manager",
"||",
"(",
"!",
"$",
"manager",
"->",
"services",
")",
")",
"... | Return the next authentication service for the pair of
user_input and session. This function handles fallback.
@param callback $discover_cb
@param object $fetcher
@return null|Auth_OpenID_ServiceEndpoint | [
"Return",
"the",
"next",
"authentication",
"service",
"for",
"the",
"pair",
"of",
"user_input",
"and",
"session",
".",
"This",
"function",
"handles",
"fallback",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L447-L472 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_Discovery.cleanup | function cleanup($force=false)
{
$manager = $this->getManager($force);
if ($manager) {
$service = $manager->current();
$this->destroyManager($force);
} else {
$service = null;
}
return $service;
} | php | function cleanup($force=false)
{
$manager = $this->getManager($force);
if ($manager) {
$service = $manager->current();
$this->destroyManager($force);
} else {
$service = null;
}
return $service;
} | [
"function",
"cleanup",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
"$",
"force",
")",
";",
"if",
"(",
"$",
"manager",
")",
"{",
"$",
"service",
"=",
"$",
"manager",
"->",
"current",
"(",
"... | Clean up Yadis-related services in the session and return the
most-recently-attempted service from the manager, if one
exists.
@param bool $force True if the manager should be deleted regardless
of whether it's a manager for $this->url.
@return null|Auth_OpenID_ServiceEndpoint | [
"Clean",
"up",
"Yadis",
"-",
"related",
"services",
"in",
"the",
"session",
"and",
"return",
"the",
"most",
"-",
"recently",
"-",
"attempted",
"service",
"from",
"the",
"manager",
"if",
"one",
"exists",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L483-L494 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_Discovery.getManager | function getManager($force=false)
{
// Extract the YadisServiceManager for this object's URL and
// suffix from the session.
$manager_str = $this->session->get($this->getSessionKey());
/** @var Auth_Yadis_Manager $manager */
$manager = null;
if ($manager_str !== null) {
$loader = new Auth_Yadis_ManagerLoader();
$manager = $loader->fromSession(unserialize($manager_str));
}
if ($manager && ($manager->forURL($this->url) || $force)) {
return $manager;
}
return null;
} | php | function getManager($force=false)
{
// Extract the YadisServiceManager for this object's URL and
// suffix from the session.
$manager_str = $this->session->get($this->getSessionKey());
/** @var Auth_Yadis_Manager $manager */
$manager = null;
if ($manager_str !== null) {
$loader = new Auth_Yadis_ManagerLoader();
$manager = $loader->fromSession(unserialize($manager_str));
}
if ($manager && ($manager->forURL($this->url) || $force)) {
return $manager;
}
return null;
} | [
"function",
"getManager",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"// Extract the YadisServiceManager for this object's URL and",
"// suffix from the session.",
"$",
"manager_str",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"this",
"->",
"getSessionK... | @access private
@param bool $force True if the manager should be returned regardless
of whether it's a manager for $this->url.
@return null|Auth_Yadis_Manager | [
"@access",
"private"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L512-L530 |
openid/php-openid | Auth/Yadis/Manager.php | Auth_Yadis_Discovery.destroyManager | function destroyManager($force=false)
{
if ($this->getManager($force) !== null) {
$key = $this->getSessionKey();
$this->session->del($key);
}
} | php | function destroyManager($force=false)
{
if ($this->getManager($force) !== null) {
$key = $this->getSessionKey();
$this->session->del($key);
}
} | [
"function",
"destroyManager",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getManager",
"(",
"$",
"force",
")",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getSessionKey",
"(",
")",
";",
"$",
"this",
... | @access private
@param bool $force True if the manager should be deleted regardless
of whether it's a manager for $this->url. | [
"@access",
"private"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Manager.php#L562-L568 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegBase._getSRegNS | static function _getSRegNS($message)
{
$alias = null;
$found_ns_uri = null;
// See if there exists an alias for one of the two defined
// simple registration types.
foreach (array(Auth_OpenID_SREG_NS_URI_1_1,
Auth_OpenID_SREG_NS_URI_1_0) as $sreg_ns_uri) {
$alias = $message->namespaces->getAlias($sreg_ns_uri);
if ($alias !== null) {
$found_ns_uri = $sreg_ns_uri;
break;
}
}
if ($alias === null) {
// There is no alias for either of the types, so try to
// add one. We default to using the modern value (1.1)
$found_ns_uri = Auth_OpenID_SREG_NS_URI_1_1;
if ($message->namespaces->addAlias(Auth_OpenID_SREG_NS_URI_1_1,
'sreg') === null) {
// An alias for the string 'sreg' already exists, but
// it's defined for something other than simple
// registration
return null;
}
}
return $found_ns_uri;
} | php | static function _getSRegNS($message)
{
$alias = null;
$found_ns_uri = null;
// See if there exists an alias for one of the two defined
// simple registration types.
foreach (array(Auth_OpenID_SREG_NS_URI_1_1,
Auth_OpenID_SREG_NS_URI_1_0) as $sreg_ns_uri) {
$alias = $message->namespaces->getAlias($sreg_ns_uri);
if ($alias !== null) {
$found_ns_uri = $sreg_ns_uri;
break;
}
}
if ($alias === null) {
// There is no alias for either of the types, so try to
// add one. We default to using the modern value (1.1)
$found_ns_uri = Auth_OpenID_SREG_NS_URI_1_1;
if ($message->namespaces->addAlias(Auth_OpenID_SREG_NS_URI_1_1,
'sreg') === null) {
// An alias for the string 'sreg' already exists, but
// it's defined for something other than simple
// registration
return null;
}
}
return $found_ns_uri;
} | [
"static",
"function",
"_getSRegNS",
"(",
"$",
"message",
")",
"{",
"$",
"alias",
"=",
"null",
";",
"$",
"found_ns_uri",
"=",
"null",
";",
"// See if there exists an alias for one of the two defined",
"// simple registration types.",
"foreach",
"(",
"array",
"(",
"Auth... | Extract the simple registration namespace URI from the given
OpenID message. Handles OpenID 1 and 2, as well as both sreg
namespace URIs found in the wild, as well as missing namespace
definitions (for OpenID 1)
$message: The OpenID message from which to parse simple
registration fields. This may be a request or response message.
Returns the sreg namespace URI for the supplied message. The
message may be modified to define a simple registration
namespace.
@access private
@param Auth_OpenID_Message $message
@return mixed|null|string | [
"Extract",
"the",
"simple",
"registration",
"namespace",
"URI",
"from",
"the",
"given",
"OpenID",
"message",
".",
"Handles",
"OpenID",
"1",
"and",
"2",
"as",
"well",
"as",
"both",
"sreg",
"namespace",
"URIs",
"found",
"in",
"the",
"wild",
"as",
"well",
"as... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L131-L161 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.build | static function build($required=null, $optional=null,
$policy_url=null,
$sreg_ns_uri=Auth_OpenID_SREG_NS_URI,
$cls='Auth_OpenID_SRegRequest')
{
/** @var Auth_OpenID_SRegRequest $obj */
$obj = new $cls();
$obj->required = array();
$obj->optional = array();
$obj->policy_url = $policy_url;
$obj->ns_uri = $sreg_ns_uri;
if ($required) {
if (!$obj->requestFields($required, true, true)) {
return null;
}
}
if ($optional) {
if (!$obj->requestFields($optional, false, true)) {
return null;
}
}
return $obj;
} | php | static function build($required=null, $optional=null,
$policy_url=null,
$sreg_ns_uri=Auth_OpenID_SREG_NS_URI,
$cls='Auth_OpenID_SRegRequest')
{
/** @var Auth_OpenID_SRegRequest $obj */
$obj = new $cls();
$obj->required = array();
$obj->optional = array();
$obj->policy_url = $policy_url;
$obj->ns_uri = $sreg_ns_uri;
if ($required) {
if (!$obj->requestFields($required, true, true)) {
return null;
}
}
if ($optional) {
if (!$obj->requestFields($optional, false, true)) {
return null;
}
}
return $obj;
} | [
"static",
"function",
"build",
"(",
"$",
"required",
"=",
"null",
",",
"$",
"optional",
"=",
"null",
",",
"$",
"policy_url",
"=",
"null",
",",
"$",
"sreg_ns_uri",
"=",
"Auth_OpenID_SREG_NS_URI",
",",
"$",
"cls",
"=",
"'Auth_OpenID_SRegRequest'",
")",
"{",
... | Initialize an empty simple registration request.
@param null $required
@param null $optional
@param null $policy_url
@param string $sreg_ns_uri
@param string $cls
@return null | [
"Initialize",
"an",
"empty",
"simple",
"registration",
"request",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L196-L222 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.fromOpenIDRequest | static function fromOpenIDRequest($request, $cls='Auth_OpenID_SRegRequest')
{
$obj = call_user_func_array(array($cls, 'build'),
array(null, null, null, Auth_OpenID_SREG_NS_URI, $cls));
// Since we're going to mess with namespace URI mapping, don't
// mutate the object that was passed in.
$m = $request->message;
$obj->ns_uri = $obj->_getSRegNS($m);
$args = $m->getArgs($obj->ns_uri);
if ($args === null || Auth_OpenID::isFailure($args)) {
return null;
}
$obj->parseExtensionArgs($args);
return $obj;
} | php | static function fromOpenIDRequest($request, $cls='Auth_OpenID_SRegRequest')
{
$obj = call_user_func_array(array($cls, 'build'),
array(null, null, null, Auth_OpenID_SREG_NS_URI, $cls));
// Since we're going to mess with namespace URI mapping, don't
// mutate the object that was passed in.
$m = $request->message;
$obj->ns_uri = $obj->_getSRegNS($m);
$args = $m->getArgs($obj->ns_uri);
if ($args === null || Auth_OpenID::isFailure($args)) {
return null;
}
$obj->parseExtensionArgs($args);
return $obj;
} | [
"static",
"function",
"fromOpenIDRequest",
"(",
"$",
"request",
",",
"$",
"cls",
"=",
"'Auth_OpenID_SRegRequest'",
")",
"{",
"$",
"obj",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"cls",
",",
"'build'",
")",
",",
"array",
"(",
"null",
",",
"null"... | Create a simple registration request that contains the fields
that were requested in the OpenID request with the given
arguments
$request: The OpenID authentication request from which to
extract an sreg request.
$cls: name of class to use when creating sreg request object.
Used for testing.
Returns the newly created simple registration request
@param Auth_OpenID_Request $request
@param string $cls
@return Auth_OpenID_SRegRequest|null | [
"Create",
"a",
"simple",
"registration",
"request",
"that",
"contains",
"the",
"fields",
"that",
"were",
"requested",
"in",
"the",
"OpenID",
"request",
"with",
"the",
"given",
"arguments"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L241-L261 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.parseExtensionArgs | function parseExtensionArgs($args, $strict=false)
{
foreach (array('required', 'optional') as $list_name) {
$required = ($list_name == 'required');
$items = Auth_OpenID::arrayGet($args, $list_name);
if ($items) {
foreach (explode(',', $items) as $field_name) {
if (!$this->requestField($field_name, $required, $strict)) {
if ($strict) {
return false;
}
}
}
}
}
$this->policy_url = Auth_OpenID::arrayGet($args, 'policy_url');
return true;
} | php | function parseExtensionArgs($args, $strict=false)
{
foreach (array('required', 'optional') as $list_name) {
$required = ($list_name == 'required');
$items = Auth_OpenID::arrayGet($args, $list_name);
if ($items) {
foreach (explode(',', $items) as $field_name) {
if (!$this->requestField($field_name, $required, $strict)) {
if ($strict) {
return false;
}
}
}
}
}
$this->policy_url = Auth_OpenID::arrayGet($args, 'policy_url');
return true;
} | [
"function",
"parseExtensionArgs",
"(",
"$",
"args",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"foreach",
"(",
"array",
"(",
"'required'",
",",
"'optional'",
")",
"as",
"$",
"list_name",
")",
"{",
"$",
"required",
"=",
"(",
"$",
"list_name",
"==",
"'r... | Parse the unqualified simple registration request parameters
and add them to this object.
This method is essentially the inverse of
getExtensionArgs. This method restores the serialized simple
registration request fields.
If you are extracting arguments from a standard OpenID
checkid_* request, you probably want to use fromOpenIDRequest,
which will extract the sreg namespace and arguments from the
OpenID request. This method is intended for cases where the
OpenID server needs more control over how the arguments are
parsed than that method provides.
$args == $message->getArgs($ns_uri);
$request->parseExtensionArgs($args);
$args: The unqualified simple registration arguments
strict: Whether requests with fields that are not defined in
the simple registration specification should be tolerated (and
ignored)
@param array $args
@param bool $strict
@return bool | [
"Parse",
"the",
"unqualified",
"simple",
"registration",
"request",
"parameters",
"and",
"add",
"them",
"to",
"this",
"object",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L291-L310 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.contains | function contains($field_name)
{
return (in_array($field_name, $this->required) ||
in_array($field_name, $this->optional));
} | php | function contains($field_name)
{
return (in_array($field_name, $this->required) ||
in_array($field_name, $this->optional));
} | [
"function",
"contains",
"(",
"$",
"field_name",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"field_name",
",",
"$",
"this",
"->",
"required",
")",
"||",
"in_array",
"(",
"$",
"field_name",
",",
"$",
"this",
"->",
"optional",
")",
")",
";",
"}"
] | Was this field in the request?
@param string $field_name
@return bool | [
"Was",
"this",
"field",
"in",
"the",
"request?"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L335-L339 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.requestField | function requestField($field_name,
$required=false, $strict=false)
{
if (!Auth_OpenID_checkFieldName($field_name)) {
return false;
}
if ($strict) {
if ($this->contains($field_name)) {
return false;
}
} else {
if (in_array($field_name, $this->required)) {
return true;
}
if (in_array($field_name, $this->optional)) {
if ($required) {
unset($this->optional[array_search($field_name,
$this->optional)]);
} else {
return true;
}
}
}
if ($required) {
$this->required[] = $field_name;
} else {
$this->optional[] = $field_name;
}
return true;
} | php | function requestField($field_name,
$required=false, $strict=false)
{
if (!Auth_OpenID_checkFieldName($field_name)) {
return false;
}
if ($strict) {
if ($this->contains($field_name)) {
return false;
}
} else {
if (in_array($field_name, $this->required)) {
return true;
}
if (in_array($field_name, $this->optional)) {
if ($required) {
unset($this->optional[array_search($field_name,
$this->optional)]);
} else {
return true;
}
}
}
if ($required) {
$this->required[] = $field_name;
} else {
$this->optional[] = $field_name;
}
return true;
} | [
"function",
"requestField",
"(",
"$",
"field_name",
",",
"$",
"required",
"=",
"false",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"Auth_OpenID_checkFieldName",
"(",
"$",
"field_name",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
... | Request the specified field from the OpenID user
$field_name: the unqualified simple registration field name
required: whether the given field should be presented to the
user as being a required to successfully complete the request
strict: whether to raise an exception when a field is added to
a request more than once
@param string $field_name
@param bool $required
@param bool $strict
@return bool | [
"Request",
"the",
"specified",
"field",
"from",
"the",
"OpenID",
"user"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L357-L390 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.requestFields | function requestFields($field_names, $required=false, $strict=false)
{
if (!is_array($field_names)) {
return false;
}
foreach ($field_names as $field_name) {
if (!$this->requestField($field_name, $required, $strict)) {
return false;
}
}
return true;
} | php | function requestFields($field_names, $required=false, $strict=false)
{
if (!is_array($field_names)) {
return false;
}
foreach ($field_names as $field_name) {
if (!$this->requestField($field_name, $required, $strict)) {
return false;
}
}
return true;
} | [
"function",
"requestFields",
"(",
"$",
"field_names",
",",
"$",
"required",
"=",
"false",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"field_names",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$"... | Add the given list of fields to the request
field_names: The simple registration data fields to request
required: Whether these values should be presented to the user
as required
strict: whether to raise an exception when a field is added to
a request more than once
@param string $field_names
@param bool $required
@param bool $strict
@return bool | [
"Add",
"the",
"given",
"list",
"of",
"fields",
"to",
"the",
"request"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L408-L421 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegRequest.getExtensionArgs | function getExtensionArgs($request = null)
{
$args = array();
if ($this->required) {
$args['required'] = implode(',', $this->required);
}
if ($this->optional) {
$args['optional'] = implode(',', $this->optional);
}
if ($this->policy_url) {
$args['policy_url'] = $this->policy_url;
}
return $args;
} | php | function getExtensionArgs($request = null)
{
$args = array();
if ($this->required) {
$args['required'] = implode(',', $this->required);
}
if ($this->optional) {
$args['optional'] = implode(',', $this->optional);
}
if ($this->policy_url) {
$args['policy_url'] = $this->policy_url;
}
return $args;
} | [
"function",
"getExtensionArgs",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"required",
")",
"{",
"$",
"args",
"[",
"'required'",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"... | Get a dictionary of unqualified simple registration arguments
representing this request.
This method is essentially the inverse of
C{L{parseExtensionArgs}}. This method serializes the simple
registration request fields.
@param Auth_OpenID_Request|null $request
@return array|null | [
"Get",
"a",
"dictionary",
"of",
"unqualified",
"simple",
"registration",
"arguments",
"representing",
"this",
"request",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L434-L451 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegResponse.extractResponse | static function extractResponse($request, $data)
{
$obj = new Auth_OpenID_SRegResponse();
$obj->ns_uri = $request->ns_uri;
foreach ($request->allRequestedFields() as $field) {
$value = Auth_OpenID::arrayGet($data, $field);
if ($value !== null) {
$obj->data[$field] = $value;
}
}
return $obj;
} | php | static function extractResponse($request, $data)
{
$obj = new Auth_OpenID_SRegResponse();
$obj->ns_uri = $request->ns_uri;
foreach ($request->allRequestedFields() as $field) {
$value = Auth_OpenID::arrayGet($data, $field);
if ($value !== null) {
$obj->data[$field] = $value;
}
}
return $obj;
} | [
"static",
"function",
"extractResponse",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"$",
"obj",
"=",
"new",
"Auth_OpenID_SRegResponse",
"(",
")",
";",
"$",
"obj",
"->",
"ns_uri",
"=",
"$",
"request",
"->",
"ns_uri",
";",
"foreach",
"(",
"$",
"req... | Take a C{L{SRegRequest}} and a dictionary of simple
registration values and create a C{L{SRegResponse}} object
containing that data.
request: The simple registration request object
data: The simple registration data for this response, as a
dictionary from unqualified simple registration field name to
string (unicode) value. For instance, the nickname should be
stored under the key 'nickname'.
@param Auth_OpenID_SRegRequest $request
@param array $data
@return Auth_OpenID_SRegResponse | [
"Take",
"a",
"C",
"{",
"L",
"{",
"SRegRequest",
"}}",
"and",
"a",
"dictionary",
"of",
"simple",
"registration",
"values",
"and",
"create",
"a",
"C",
"{",
"L",
"{",
"SRegResponse",
"}}",
"object",
"containing",
"that",
"data",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L495-L508 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegResponse.fromSuccessResponse | static function fromSuccessResponse($success_response, $signed_only=true)
{
global $Auth_OpenID_sreg_data_fields;
$obj = new Auth_OpenID_SRegResponse();
$obj->ns_uri = $obj->_getSRegNS($success_response->message);
if ($signed_only) {
$args = $success_response->getSignedNS($obj->ns_uri);
} else {
$args = $success_response->message->getArgs($obj->ns_uri);
}
if ($args === null || Auth_OpenID::isFailure($args)) {
return null;
}
foreach ($Auth_OpenID_sreg_data_fields as $field_name => $desc) {
if (in_array($field_name, array_keys($args))) {
$obj->data[$field_name] = $args[$field_name];
}
}
return $obj;
} | php | static function fromSuccessResponse($success_response, $signed_only=true)
{
global $Auth_OpenID_sreg_data_fields;
$obj = new Auth_OpenID_SRegResponse();
$obj->ns_uri = $obj->_getSRegNS($success_response->message);
if ($signed_only) {
$args = $success_response->getSignedNS($obj->ns_uri);
} else {
$args = $success_response->message->getArgs($obj->ns_uri);
}
if ($args === null || Auth_OpenID::isFailure($args)) {
return null;
}
foreach ($Auth_OpenID_sreg_data_fields as $field_name => $desc) {
if (in_array($field_name, array_keys($args))) {
$obj->data[$field_name] = $args[$field_name];
}
}
return $obj;
} | [
"static",
"function",
"fromSuccessResponse",
"(",
"$",
"success_response",
",",
"$",
"signed_only",
"=",
"true",
")",
"{",
"global",
"$",
"Auth_OpenID_sreg_data_fields",
";",
"$",
"obj",
"=",
"new",
"Auth_OpenID_SRegResponse",
"(",
")",
";",
"$",
"obj",
"->",
... | Create a C{L{SRegResponse}} object from a successful OpenID
library response
(C{L{openid.consumer.consumer.SuccessResponse}}) response
message
success_response: A SuccessResponse from consumer.complete()
signed_only: Whether to process only data that was
signed in the id_res message from the server.
Returns a simple registration response containing the data that
was supplied with the C{id_res} response.
@param Auth_OpenID_SuccessResponse $success_response
@param bool $signed_only
@return Auth_OpenID_SRegResponse|null | [
"Create",
"a",
"C",
"{",
"L",
"{",
"SRegResponse",
"}}",
"object",
"from",
"a",
"successful",
"OpenID",
"library",
"response",
"(",
"C",
"{",
"L",
"{",
"openid",
".",
"consumer",
".",
"consumer",
".",
"SuccessResponse",
"}}",
")",
"response",
"message"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L528-L552 |
openid/php-openid | Auth/OpenID/SReg.php | Auth_OpenID_SRegResponse.get | function get($field_name, $default=null)
{
if (!Auth_OpenID_checkFieldName($field_name)) {
return null;
}
return Auth_OpenID::arrayGet($this->data, $field_name, $default);
} | php | function get($field_name, $default=null)
{
if (!Auth_OpenID_checkFieldName($field_name)) {
return null;
}
return Auth_OpenID::arrayGet($this->data, $field_name, $default);
} | [
"function",
"get",
"(",
"$",
"field_name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"Auth_OpenID_checkFieldName",
"(",
"$",
"field_name",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"Auth_OpenID",
"::",
"arrayGet",
"(",
"$",
... | Read-only dictionary interface | [
"Read",
"-",
"only",
"dictionary",
"interface"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/SReg.php#L567-L574 |
openid/php-openid | Auth/Yadis/ParseHTML.php | Auth_Yadis_ParseHTML.tagPattern | function tagPattern($tag_names, $close, $self_close)
{
if (is_array($tag_names)) {
$tag_names = '(?:'.implode('|',$tag_names).')';
}
if ($close) {
$close = '\/' . (($close == 1)? '' : '?');
} else {
$close = '';
}
if ($self_close) {
$self_close = '(?:\/\s*)' . (($self_close == 1)? '' : '?');
} else {
$self_close = '';
}
$expr = sprintf($this->_tag_expr, $close, $tag_names, $self_close);
return sprintf("/%s/%s", $expr, $this->_re_flags);
} | php | function tagPattern($tag_names, $close, $self_close)
{
if (is_array($tag_names)) {
$tag_names = '(?:'.implode('|',$tag_names).')';
}
if ($close) {
$close = '\/' . (($close == 1)? '' : '?');
} else {
$close = '';
}
if ($self_close) {
$self_close = '(?:\/\s*)' . (($self_close == 1)? '' : '?');
} else {
$self_close = '';
}
$expr = sprintf($this->_tag_expr, $close, $tag_names, $self_close);
return sprintf("/%s/%s", $expr, $this->_re_flags);
} | [
"function",
"tagPattern",
"(",
"$",
"tag_names",
",",
"$",
"close",
",",
"$",
"self_close",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tag_names",
")",
")",
"{",
"$",
"tag_names",
"=",
"'(?:'",
".",
"implode",
"(",
"'|'",
",",
"$",
"tag_names",
")",... | Create a regular expression that will match an opening
or closing tag from a set of names.
@access private
@param mixed $tag_names Tag names to match
@param mixed $close false/0 = no, true/1 = yes, other = maybe
@param mixed $self_close false/0 = no, true/1 = yes, other = maybe
@return string $regex A regular expression string to be used
in, say, preg_match. | [
"Create",
"a",
"regular",
"expression",
"that",
"will",
"match",
"an",
"opening",
"or",
"closing",
"tag",
"from",
"a",
"set",
"of",
"names",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/ParseHTML.php#L102-L120 |
openid/php-openid | Auth/Yadis/ParseHTML.php | Auth_Yadis_ParseHTML.getMetaTags | function getMetaTags($html_string)
{
$html_string = preg_replace($this->_removed_re,
"",
$html_string);
$key_tags = array($this->tagPattern('html', false, false),
$this->tagPattern('head', false, false),
$this->tagPattern('head', true, false),
$this->tagPattern('html', true, false),
$this->tagPattern(array(
'body', 'frameset', 'frame', 'p', 'div',
'table','span','a'), 'maybe', 'maybe'));
$key_tags_pos = array();
foreach ($key_tags as $pat) {
$matches = array();
preg_match($pat, $html_string, $matches, PREG_OFFSET_CAPTURE);
if($matches) {
$key_tags_pos[] = $matches[0][1];
} else {
$key_tags_pos[] = null;
}
}
// no opening head tag
if (is_null($key_tags_pos[1])) {
return array();
}
// the effective </head> is the min of the following
if (is_null($key_tags_pos[2])) {
$key_tags_pos[2] = strlen($html_string);
}
foreach (array($key_tags_pos[3], $key_tags_pos[4]) as $pos) {
if (!is_null($pos) && $pos < $key_tags_pos[2]) {
$key_tags_pos[2] = $pos;
}
}
// closing head tag comes before opening head tag
if ($key_tags_pos[1] > $key_tags_pos[2]) {
return array();
}
// if there is an opening html tag, make sure the opening head tag
// comes after it
if (!is_null($key_tags_pos[0]) && $key_tags_pos[1] < $key_tags_pos[0]) {
return array();
}
$html_string = substr($html_string, $key_tags_pos[1],
($key_tags_pos[2]-$key_tags_pos[1]));
$link_data = array();
$link_matches = array();
if (!preg_match_all($this->tagPattern('meta', false, 'maybe'),
$html_string, $link_matches)) {
return array();
}
foreach ($link_matches[0] as $link) {
$attr_matches = array();
preg_match_all($this->_attr_find, $link, $attr_matches);
$link_attrs = array();
foreach ($attr_matches[0] as $index => $full_match) {
$name = $attr_matches[1][$index];
$value = html_entity_decode(
$this->removeQuotes($attr_matches[2][$index]));
$link_attrs[strtolower($name)] = $value;
}
$link_data[] = $link_attrs;
}
return $link_data;
} | php | function getMetaTags($html_string)
{
$html_string = preg_replace($this->_removed_re,
"",
$html_string);
$key_tags = array($this->tagPattern('html', false, false),
$this->tagPattern('head', false, false),
$this->tagPattern('head', true, false),
$this->tagPattern('html', true, false),
$this->tagPattern(array(
'body', 'frameset', 'frame', 'p', 'div',
'table','span','a'), 'maybe', 'maybe'));
$key_tags_pos = array();
foreach ($key_tags as $pat) {
$matches = array();
preg_match($pat, $html_string, $matches, PREG_OFFSET_CAPTURE);
if($matches) {
$key_tags_pos[] = $matches[0][1];
} else {
$key_tags_pos[] = null;
}
}
// no opening head tag
if (is_null($key_tags_pos[1])) {
return array();
}
// the effective </head> is the min of the following
if (is_null($key_tags_pos[2])) {
$key_tags_pos[2] = strlen($html_string);
}
foreach (array($key_tags_pos[3], $key_tags_pos[4]) as $pos) {
if (!is_null($pos) && $pos < $key_tags_pos[2]) {
$key_tags_pos[2] = $pos;
}
}
// closing head tag comes before opening head tag
if ($key_tags_pos[1] > $key_tags_pos[2]) {
return array();
}
// if there is an opening html tag, make sure the opening head tag
// comes after it
if (!is_null($key_tags_pos[0]) && $key_tags_pos[1] < $key_tags_pos[0]) {
return array();
}
$html_string = substr($html_string, $key_tags_pos[1],
($key_tags_pos[2]-$key_tags_pos[1]));
$link_data = array();
$link_matches = array();
if (!preg_match_all($this->tagPattern('meta', false, 'maybe'),
$html_string, $link_matches)) {
return array();
}
foreach ($link_matches[0] as $link) {
$attr_matches = array();
preg_match_all($this->_attr_find, $link, $attr_matches);
$link_attrs = array();
foreach ($attr_matches[0] as $index => $full_match) {
$name = $attr_matches[1][$index];
$value = html_entity_decode(
$this->removeQuotes($attr_matches[2][$index]));
$link_attrs[strtolower($name)] = $value;
}
$link_data[] = $link_attrs;
}
return $link_data;
} | [
"function",
"getMetaTags",
"(",
"$",
"html_string",
")",
"{",
"$",
"html_string",
"=",
"preg_replace",
"(",
"$",
"this",
"->",
"_removed_re",
",",
"\"\"",
",",
"$",
"html_string",
")",
";",
"$",
"key_tags",
"=",
"array",
"(",
"$",
"this",
"->",
"tagPatte... | Given an HTML document string, this finds all the META tags in
the document, provided they are found in the
<HTML><HEAD>...</HEAD> section of the document. The <HTML> tag
may be missing.
@access private
@param string $html_string An HTMl document string
@return array $tag_list Array of tags; each tag is an array of
attribute -> value. | [
"Given",
"an",
"HTML",
"document",
"string",
"this",
"finds",
"all",
"the",
"META",
"tags",
"in",
"the",
"document",
"provided",
"they",
"are",
"found",
"in",
"the",
"<HTML",
">",
"<HEAD",
">",
"...",
"<",
"/",
"HEAD",
">",
"section",
"of",
"the",
"doc... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/ParseHTML.php#L133-L204 |
openid/php-openid | Auth/Yadis/ParseHTML.php | Auth_Yadis_ParseHTML.getHTTPEquiv | function getHTTPEquiv($html_string)
{
$meta_tags = $this->getMetaTags($html_string);
if ($meta_tags) {
foreach ($meta_tags as $tag) {
if (array_key_exists('http-equiv', $tag) &&
(in_array(strtolower($tag['http-equiv']),
array('x-xrds-location', 'x-yadis-location'))) &&
array_key_exists('content', $tag)) {
return $tag['content'];
}
}
}
return null;
} | php | function getHTTPEquiv($html_string)
{
$meta_tags = $this->getMetaTags($html_string);
if ($meta_tags) {
foreach ($meta_tags as $tag) {
if (array_key_exists('http-equiv', $tag) &&
(in_array(strtolower($tag['http-equiv']),
array('x-xrds-location', 'x-yadis-location'))) &&
array_key_exists('content', $tag)) {
return $tag['content'];
}
}
}
return null;
} | [
"function",
"getHTTPEquiv",
"(",
"$",
"html_string",
")",
"{",
"$",
"meta_tags",
"=",
"$",
"this",
"->",
"getMetaTags",
"(",
"$",
"html_string",
")",
";",
"if",
"(",
"$",
"meta_tags",
")",
"{",
"foreach",
"(",
"$",
"meta_tags",
"as",
"$",
"tag",
")",
... | Looks for a META tag with an "http-equiv" attribute whose value
is one of ("x-xrds-location", "x-yadis-location"), ignoring
case. If such a META tag is found, its "content" attribute
value is returned.
@param string $html_string An HTML document in string format
@return mixed $content The "content" attribute value of the
META tag, if found, or null if no such tag was found. | [
"Looks",
"for",
"a",
"META",
"tag",
"with",
"an",
"http",
"-",
"equiv",
"attribute",
"whose",
"value",
"is",
"one",
"of",
"(",
"x",
"-",
"xrds",
"-",
"location",
"x",
"-",
"yadis",
"-",
"location",
")",
"ignoring",
"case",
".",
"If",
"such",
"a",
"... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/ParseHTML.php#L216-L232 |
openid/php-openid | Auth/OpenID/Extension.php | Auth_OpenID_Extension.toMessage | function toMessage($message, $request = null)
{
$implicit = $message->isOpenID1();
$added = $message->namespaces->addAlias($this->ns_uri,
$this->ns_alias,
$implicit);
if ($added === null) {
if ($message->namespaces->getAlias($this->ns_uri) !=
$this->ns_alias) {
return null;
}
}
if ($request !== null) {
$message->updateArgs($this->ns_uri,
$this->getExtensionArgs($request));
} else {
$message->updateArgs($this->ns_uri,
$this->getExtensionArgs());
}
return $message;
} | php | function toMessage($message, $request = null)
{
$implicit = $message->isOpenID1();
$added = $message->namespaces->addAlias($this->ns_uri,
$this->ns_alias,
$implicit);
if ($added === null) {
if ($message->namespaces->getAlias($this->ns_uri) !=
$this->ns_alias) {
return null;
}
}
if ($request !== null) {
$message->updateArgs($this->ns_uri,
$this->getExtensionArgs($request));
} else {
$message->updateArgs($this->ns_uri,
$this->getExtensionArgs());
}
return $message;
} | [
"function",
"toMessage",
"(",
"$",
"message",
",",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"implicit",
"=",
"$",
"message",
"->",
"isOpenID1",
"(",
")",
";",
"$",
"added",
"=",
"$",
"message",
"->",
"namespaces",
"->",
"addAlias",
"(",
"$",
"this... | Add the arguments from this extension to the provided message.
Returns the message with the extension arguments added.
@param Auth_OpenID_Message $message
@param Auth_OpenID_Request $request
@return null | [
"Add",
"the",
"arguments",
"from",
"this",
"extension",
"to",
"the",
"provided",
"message",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Extension.php#L49-L71 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.storeAssociation | function storeAssociation($server_url, $association)
{
// create Redis keys for association itself
// and list of associations for this server
$associationKey = $this->associationKey($server_url,
$association->handle);
$serverKey = $this->associationServerKey($server_url);
// save association to server's associations' keys list
$this->redis->lpush(
$serverKey,
$associationKey
);
// Will touch the association list expiration, to avoid filling up
$newExpiration = ($association->issued + $association->lifetime);
$expirationKey = $serverKey.'_expires_at';
$expiration = $this->redis->get($expirationKey);
if (!$expiration || $newExpiration > $expiration) {
$this->redis->set($expirationKey, $newExpiration);
$this->redis->expireat($serverKey, $newExpiration);
$this->redis->expireat($expirationKey, $newExpiration);
}
// save association itself, will automatically expire
$this->redis->setex(
$associationKey,
$newExpiration - time(),
serialize($association)
);
} | php | function storeAssociation($server_url, $association)
{
// create Redis keys for association itself
// and list of associations for this server
$associationKey = $this->associationKey($server_url,
$association->handle);
$serverKey = $this->associationServerKey($server_url);
// save association to server's associations' keys list
$this->redis->lpush(
$serverKey,
$associationKey
);
// Will touch the association list expiration, to avoid filling up
$newExpiration = ($association->issued + $association->lifetime);
$expirationKey = $serverKey.'_expires_at';
$expiration = $this->redis->get($expirationKey);
if (!$expiration || $newExpiration > $expiration) {
$this->redis->set($expirationKey, $newExpiration);
$this->redis->expireat($serverKey, $newExpiration);
$this->redis->expireat($expirationKey, $newExpiration);
}
// save association itself, will automatically expire
$this->redis->setex(
$associationKey,
$newExpiration - time(),
serialize($association)
);
} | [
"function",
"storeAssociation",
"(",
"$",
"server_url",
",",
"$",
"association",
")",
"{",
"// create Redis keys for association itself ",
"// and list of associations for this server",
"$",
"associationKey",
"=",
"$",
"this",
"->",
"associationKey",
"(",
"$",
"server_url",... | Store association until its expiration time in Redis server.
Overwrites any existing association with same server_url and
handle. Handles list of associations for every server. | [
"Store",
"association",
"until",
"its",
"expiration",
"time",
"in",
"Redis",
"server",
".",
"Overwrites",
"any",
"existing",
"association",
"with",
"same",
"server_url",
"and",
"handle",
".",
"Handles",
"list",
"of",
"associations",
"for",
"every",
"server",
"."... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L59-L90 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.getAssociation | function getAssociation($server_url, $handle = null)
{
// simple case: handle given
if ($handle !== null) {
return $this->getAssociationFromServer(
$this->associationKey($server_url, $handle)
);
}
// no handle given, receiving the latest issued
$serverKey = $this->associationServerKey($server_url);
$lastKey = $this->redis->lindex($serverKey, -1);
if (!$lastKey) {
// no previous association with this server
return null;
}
// get association, return null if failed
return $this->getAssociationFromServer($lastKey);
} | php | function getAssociation($server_url, $handle = null)
{
// simple case: handle given
if ($handle !== null) {
return $this->getAssociationFromServer(
$this->associationKey($server_url, $handle)
);
}
// no handle given, receiving the latest issued
$serverKey = $this->associationServerKey($server_url);
$lastKey = $this->redis->lindex($serverKey, -1);
if (!$lastKey) {
// no previous association with this server
return null;
}
// get association, return null if failed
return $this->getAssociationFromServer($lastKey);
} | [
"function",
"getAssociation",
"(",
"$",
"server_url",
",",
"$",
"handle",
"=",
"null",
")",
"{",
"// simple case: handle given",
"if",
"(",
"$",
"handle",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getAssociationFromServer",
"(",
"$",
"this",
"->... | Read association from Redis. If no handle given
and multiple associations found, returns latest issued | [
"Read",
"association",
"from",
"Redis",
".",
"If",
"no",
"handle",
"given",
"and",
"multiple",
"associations",
"found",
"returns",
"latest",
"issued"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L96-L115 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.getAssociationFromServer | private function getAssociationFromServer($associationKey)
{
$association = $this->redis->get($associationKey);
return $association ? unserialize($association) : null;
} | php | private function getAssociationFromServer($associationKey)
{
$association = $this->redis->get($associationKey);
return $association ? unserialize($association) : null;
} | [
"private",
"function",
"getAssociationFromServer",
"(",
"$",
"associationKey",
")",
"{",
"$",
"association",
"=",
"$",
"this",
"->",
"redis",
"->",
"get",
"(",
"$",
"associationKey",
")",
";",
"return",
"$",
"association",
"?",
"unserialize",
"(",
"$",
"asso... | Function to actually receive and unserialize the association
from the server. | [
"Function",
"to",
"actually",
"receive",
"and",
"unserialize",
"the",
"association",
"from",
"the",
"server",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L121-L125 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.removeAssociation | function removeAssociation($server_url, $handle)
{
// create Redis keys
$serverKey = $this->associationServerKey($server_url);
$associationKey = $this->associationKey($server_url,
$handle);
// Removing the association from the server's association list
$removed = $this->redis->lrem($serverKey, 0, $associationKey);
if ($removed < 1) {
return false;
}
// Delete the association itself
return $this->redis->del($associationKey);
} | php | function removeAssociation($server_url, $handle)
{
// create Redis keys
$serverKey = $this->associationServerKey($server_url);
$associationKey = $this->associationKey($server_url,
$handle);
// Removing the association from the server's association list
$removed = $this->redis->lrem($serverKey, 0, $associationKey);
if ($removed < 1) {
return false;
}
// Delete the association itself
return $this->redis->del($associationKey);
} | [
"function",
"removeAssociation",
"(",
"$",
"server_url",
",",
"$",
"handle",
")",
"{",
"// create Redis keys",
"$",
"serverKey",
"=",
"$",
"this",
"->",
"associationServerKey",
"(",
"$",
"server_url",
")",
";",
"$",
"associationKey",
"=",
"$",
"this",
"->",
... | Immediately delete association from Redis. | [
"Immediately",
"delete",
"association",
"from",
"Redis",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L130-L145 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.useNonce | function useNonce($server_url, $timestamp, $salt)
{
global $Auth_OpenID_SKEW;
// save one request to memcache when nonce obviously expired
if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
return false;
}
// SETNX will set the value only of the key doesn't exist yet.
$nonceKey = $this->nonceKey($server_url, $salt);
$added = $this->redis->setnx($nonceKey, "1");
if ($added) {
// Will set expiration
$this->redis->expire($nonceKey, $Auth_OpenID_SKEW);
return true;
} else {
return false;
}
} | php | function useNonce($server_url, $timestamp, $salt)
{
global $Auth_OpenID_SKEW;
// save one request to memcache when nonce obviously expired
if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
return false;
}
// SETNX will set the value only of the key doesn't exist yet.
$nonceKey = $this->nonceKey($server_url, $salt);
$added = $this->redis->setnx($nonceKey, "1");
if ($added) {
// Will set expiration
$this->redis->expire($nonceKey, $Auth_OpenID_SKEW);
return true;
} else {
return false;
}
} | [
"function",
"useNonce",
"(",
"$",
"server_url",
",",
"$",
"timestamp",
",",
"$",
"salt",
")",
"{",
"global",
"$",
"Auth_OpenID_SKEW",
";",
"// save one request to memcache when nonce obviously expired ",
"if",
"(",
"abs",
"(",
"$",
"timestamp",
"-",
"time",
"(",
... | Create nonce for server and salt, expiring after
$Auth_OpenID_SKEW seconds. | [
"Create",
"nonce",
"for",
"server",
"and",
"salt",
"expiring",
"after",
"$Auth_OpenID_SKEW",
"seconds",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L151-L170 |
openid/php-openid | Auth/OpenID/PredisStore.php | Auth_OpenID_PredisStore.associationKey | function associationKey($server_url, $handle = null)
{
return $this->prefix .
'openid_association_' .
sha1($server_url) . '_' . sha1($handle);
} | php | function associationKey($server_url, $handle = null)
{
return $this->prefix .
'openid_association_' .
sha1($server_url) . '_' . sha1($handle);
} | [
"function",
"associationKey",
"(",
"$",
"server_url",
",",
"$",
"handle",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"prefix",
".",
"'openid_association_'",
".",
"sha1",
"(",
"$",
"server_url",
")",
".",
"'_'",
".",
"sha1",
"(",
"$",
"handle",
... | Key is prefixed with $prefix and 'openid_association_' string | [
"Key",
"is",
"prefixed",
"with",
"$prefix",
"and",
"openid_association_",
"string"
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/PredisStore.php#L185-L190 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_Service.getTypes | function getTypes()
{
$t = array();
foreach ($this->getElements('xrd:Type') as $elem) {
$c = $this->parser->content($elem);
if ($c) {
$t[] = $c;
}
}
return $t;
} | php | function getTypes()
{
$t = array();
foreach ($this->getElements('xrd:Type') as $elem) {
$c = $this->parser->content($elem);
if ($c) {
$t[] = $c;
}
}
return $t;
} | [
"function",
"getTypes",
"(",
")",
"{",
"$",
"t",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getElements",
"(",
"'xrd:Type'",
")",
"as",
"$",
"elem",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"parser",
"->",
"content",
"(",... | Return the URIs in the "Type" elements, if any, of this Service
element.
@return array $type_uris An array of Type URI strings. | [
"Return",
"the",
"URIs",
"in",
"the",
"Type",
"elements",
"if",
"any",
"of",
"this",
"Service",
"element",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L98-L108 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_Service.getURIs | function getURIs()
{
$uris = array();
$last = array();
foreach ($this->getElements('xrd:URI') as $elem) {
$uri_string = $this->parser->content($elem);
$attrs = $this->parser->attributes($elem);
if ($attrs &&
array_key_exists('priority', $attrs)) {
$priority = intval($attrs['priority']);
if (!array_key_exists($priority, $uris)) {
$uris[$priority] = array();
}
$uris[$priority][] = $uri_string;
} else {
$last[] = $uri_string;
}
}
$keys = array_keys($uris);
sort($keys);
// Rebuild array of URIs.
$result = array();
foreach ($keys as $k) {
$new_uris = Auth_Yadis_array_scramble($uris[$k]);
$result = array_merge($result, $new_uris);
}
$result = array_merge($result,
Auth_Yadis_array_scramble($last));
return $result;
} | php | function getURIs()
{
$uris = array();
$last = array();
foreach ($this->getElements('xrd:URI') as $elem) {
$uri_string = $this->parser->content($elem);
$attrs = $this->parser->attributes($elem);
if ($attrs &&
array_key_exists('priority', $attrs)) {
$priority = intval($attrs['priority']);
if (!array_key_exists($priority, $uris)) {
$uris[$priority] = array();
}
$uris[$priority][] = $uri_string;
} else {
$last[] = $uri_string;
}
}
$keys = array_keys($uris);
sort($keys);
// Rebuild array of URIs.
$result = array();
foreach ($keys as $k) {
$new_uris = Auth_Yadis_array_scramble($uris[$k]);
$result = array_merge($result, $new_uris);
}
$result = array_merge($result,
Auth_Yadis_array_scramble($last));
return $result;
} | [
"function",
"getURIs",
"(",
")",
"{",
"$",
"uris",
"=",
"array",
"(",
")",
";",
"$",
"last",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getElements",
"(",
"'xrd:URI'",
")",
"as",
"$",
"elem",
")",
"{",
"$",
"uri_string",
"="... | Return the URIs in the "URI" elements, if any, of this Service
element. The URIs are returned sorted in priority order.
@return array $uris An array of URI strings. | [
"Return",
"the",
"URIs",
"in",
"the",
"URI",
"elements",
"if",
"any",
"of",
"this",
"Service",
"element",
".",
"The",
"URIs",
"are",
"returned",
"sorted",
"in",
"priority",
"order",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L129-L164 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_Service.getPriority | function getPriority()
{
$attributes = $this->parser->attributes($this->element);
if (array_key_exists('priority', $attributes)) {
return intval($attributes['priority']);
}
return null;
} | php | function getPriority()
{
$attributes = $this->parser->attributes($this->element);
if (array_key_exists('priority', $attributes)) {
return intval($attributes['priority']);
}
return null;
} | [
"function",
"getPriority",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"parser",
"->",
"attributes",
"(",
"$",
"this",
"->",
"element",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'priority'",
",",
"$",
"attributes",
")",
")",
"{",
"re... | Returns the "priority" attribute value of this <Service>
element, if the attribute is present. Returns null if not.
@return mixed $result Null or integer, depending on whether
this Service element has a 'priority' attribute. | [
"Returns",
"the",
"priority",
"attribute",
"value",
"of",
"this",
"<Service",
">",
"element",
"if",
"the",
"attribute",
"is",
"present",
".",
"Returns",
"null",
"if",
"not",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L173-L182 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_XRDS.parseXRDS | static function parseXRDS($xml_string, $extra_ns_map = null)
{
$_null = null;
if (!$xml_string) {
return $_null;
}
$parser = Auth_Yadis_getXMLParser();
$ns_map = Auth_Yadis_getNSMap();
if ($extra_ns_map && is_array($extra_ns_map)) {
$ns_map = array_merge($ns_map, $extra_ns_map);
}
if (!($parser && $parser->init($xml_string, $ns_map))) {
return $_null;
}
// Try to get root element.
$root = $parser->evalXPath('/xrds:XRDS[1]');
if (!$root) {
return $_null;
}
if (is_array($root)) {
$root = $root[0];
}
$attrs = $parser->attributes($root);
if (array_key_exists('xmlns:xrd', $attrs) &&
$attrs['xmlns:xrd'] != Auth_Yadis_XMLNS_XRDS) {
return $_null;
} else if (array_key_exists('xmlns', $attrs) &&
preg_match('/xri/', $attrs['xmlns']) &&
$attrs['xmlns'] != Auth_Yadis_XMLNS_XRD_2_0) {
return $_null;
}
// Get the last XRD node.
$xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD');
if (!$xrd_nodes) {
return $_null;
}
return new Auth_Yadis_XRDS($parser, $xrd_nodes);
} | php | static function parseXRDS($xml_string, $extra_ns_map = null)
{
$_null = null;
if (!$xml_string) {
return $_null;
}
$parser = Auth_Yadis_getXMLParser();
$ns_map = Auth_Yadis_getNSMap();
if ($extra_ns_map && is_array($extra_ns_map)) {
$ns_map = array_merge($ns_map, $extra_ns_map);
}
if (!($parser && $parser->init($xml_string, $ns_map))) {
return $_null;
}
// Try to get root element.
$root = $parser->evalXPath('/xrds:XRDS[1]');
if (!$root) {
return $_null;
}
if (is_array($root)) {
$root = $root[0];
}
$attrs = $parser->attributes($root);
if (array_key_exists('xmlns:xrd', $attrs) &&
$attrs['xmlns:xrd'] != Auth_Yadis_XMLNS_XRDS) {
return $_null;
} else if (array_key_exists('xmlns', $attrs) &&
preg_match('/xri/', $attrs['xmlns']) &&
$attrs['xmlns'] != Auth_Yadis_XMLNS_XRD_2_0) {
return $_null;
}
// Get the last XRD node.
$xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD');
if (!$xrd_nodes) {
return $_null;
}
return new Auth_Yadis_XRDS($parser, $xrd_nodes);
} | [
"static",
"function",
"parseXRDS",
"(",
"$",
"xml_string",
",",
"$",
"extra_ns_map",
"=",
"null",
")",
"{",
"$",
"_null",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"xml_string",
")",
"{",
"return",
"$",
"_null",
";",
"}",
"$",
"parser",
"=",
"Auth_Yadis... | Parse an XML string (XRDS document) and return either a
Auth_Yadis_XRDS object or null, depending on whether the
XRDS XML is valid.
@param string $xml_string An XRDS XML string.
@param array|null $extra_ns_map
@return mixed $xrds An instance of Auth_Yadis_XRDS or null,
depending on the validity of $xml_string | [
"Parse",
"an",
"XML",
"string",
"(",
"XRDS",
"document",
")",
"and",
"return",
"either",
"a",
"Auth_Yadis_XRDS",
"object",
"or",
"null",
"depending",
"on",
"whether",
"the",
"XRDS",
"XML",
"is",
"valid",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L288-L337 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_XRDS._parse | function _parse()
{
$this->serviceList = array();
$services = $this->parser->evalXPath('xrd:Service', $this->xrdNode);
foreach ($services as $node) {
$s = new Auth_Yadis_Service();
$s->element = $node;
$s->parser = $this->parser;
$priority = $s->getPriority();
if ($priority === null) {
$priority = SERVICES_YADIS_MAX_PRIORITY;
}
$this->_addService($priority, $s);
}
} | php | function _parse()
{
$this->serviceList = array();
$services = $this->parser->evalXPath('xrd:Service', $this->xrdNode);
foreach ($services as $node) {
$s = new Auth_Yadis_Service();
$s->element = $node;
$s->parser = $this->parser;
$priority = $s->getPriority();
if ($priority === null) {
$priority = SERVICES_YADIS_MAX_PRIORITY;
}
$this->_addService($priority, $s);
}
} | [
"function",
"_parse",
"(",
")",
"{",
"$",
"this",
"->",
"serviceList",
"=",
"array",
"(",
")",
";",
"$",
"services",
"=",
"$",
"this",
"->",
"parser",
"->",
"evalXPath",
"(",
"'xrd:Service'",
",",
"$",
"this",
"->",
"xrdNode",
")",
";",
"foreach",
"(... | Creates the service list using nodes from the XRDS XML
document.
@access private | [
"Creates",
"the",
"service",
"list",
"using",
"nodes",
"from",
"the",
"XRDS",
"XML",
"document",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L361-L380 |
openid/php-openid | Auth/Yadis/XRDS.php | Auth_Yadis_XRDS.services | function services($filters = null,
$filter_mode = SERVICES_YADIS_MATCH_ANY)
{
$pri_keys = array_keys($this->serviceList);
sort($pri_keys, SORT_NUMERIC);
// If no filters are specified, return the entire service
// list, ordered by priority.
if (!$filters ||
(!is_array($filters))) {
$result = array();
foreach ($pri_keys as $pri) {
$result = array_merge($result, $this->serviceList[$pri]);
}
return $result;
}
// If a bad filter mode is specified, return null.
if (!in_array($filter_mode, array(SERVICES_YADIS_MATCH_ANY,
SERVICES_YADIS_MATCH_ALL))) {
return null;
}
// Otherwise, use the callbacks in the filter list to
// determine which services are returned.
$filtered = array();
foreach ($pri_keys as $priority_value) {
$service_obj_list = $this->serviceList[$priority_value];
foreach ($service_obj_list as $service) {
$matches = 0;
foreach ($filters as $filter) {
if (call_user_func_array($filter, array($service))) {
$matches++;
if ($filter_mode == SERVICES_YADIS_MATCH_ANY) {
$pri = $service->getPriority();
if ($pri === null) {
$pri = SERVICES_YADIS_MAX_PRIORITY;
}
if (!array_key_exists($pri, $filtered)) {
$filtered[$pri] = array();
}
$filtered[$pri][] = $service;
break;
}
}
}
if (($filter_mode == SERVICES_YADIS_MATCH_ALL) &&
($matches == count($filters))) {
$pri = $service->getPriority();
if ($pri === null) {
$pri = SERVICES_YADIS_MAX_PRIORITY;
}
if (!array_key_exists($pri, $filtered)) {
$filtered[$pri] = array();
}
$filtered[$pri][] = $service;
}
}
}
$pri_keys = array_keys($filtered);
sort($pri_keys, SORT_NUMERIC);
$result = array();
foreach ($pri_keys as $pri) {
$result = array_merge($result, $filtered[$pri]);
}
return $result;
} | php | function services($filters = null,
$filter_mode = SERVICES_YADIS_MATCH_ANY)
{
$pri_keys = array_keys($this->serviceList);
sort($pri_keys, SORT_NUMERIC);
// If no filters are specified, return the entire service
// list, ordered by priority.
if (!$filters ||
(!is_array($filters))) {
$result = array();
foreach ($pri_keys as $pri) {
$result = array_merge($result, $this->serviceList[$pri]);
}
return $result;
}
// If a bad filter mode is specified, return null.
if (!in_array($filter_mode, array(SERVICES_YADIS_MATCH_ANY,
SERVICES_YADIS_MATCH_ALL))) {
return null;
}
// Otherwise, use the callbacks in the filter list to
// determine which services are returned.
$filtered = array();
foreach ($pri_keys as $priority_value) {
$service_obj_list = $this->serviceList[$priority_value];
foreach ($service_obj_list as $service) {
$matches = 0;
foreach ($filters as $filter) {
if (call_user_func_array($filter, array($service))) {
$matches++;
if ($filter_mode == SERVICES_YADIS_MATCH_ANY) {
$pri = $service->getPriority();
if ($pri === null) {
$pri = SERVICES_YADIS_MAX_PRIORITY;
}
if (!array_key_exists($pri, $filtered)) {
$filtered[$pri] = array();
}
$filtered[$pri][] = $service;
break;
}
}
}
if (($filter_mode == SERVICES_YADIS_MATCH_ALL) &&
($matches == count($filters))) {
$pri = $service->getPriority();
if ($pri === null) {
$pri = SERVICES_YADIS_MAX_PRIORITY;
}
if (!array_key_exists($pri, $filtered)) {
$filtered[$pri] = array();
}
$filtered[$pri][] = $service;
}
}
}
$pri_keys = array_keys($filtered);
sort($pri_keys, SORT_NUMERIC);
$result = array();
foreach ($pri_keys as $pri) {
$result = array_merge($result, $filtered[$pri]);
}
return $result;
} | [
"function",
"services",
"(",
"$",
"filters",
"=",
"null",
",",
"$",
"filter_mode",
"=",
"SERVICES_YADIS_MATCH_ANY",
")",
"{",
"$",
"pri_keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"serviceList",
")",
";",
"sort",
"(",
"$",
"pri_keys",
",",
"SORT_NUME... | Returns a list of service objects which correspond to <Service>
elements in the XRDS XML document for this object.
Optionally, an array of filter callbacks may be given to limit
the list of returned service objects. Furthermore, the default
mode is to return all service objects which match ANY of the
specified filters, but $filter_mode may be
SERVICES_YADIS_MATCH_ALL if you want to be sure that the
returned services match all the given filters. See {@link
Auth_Yadis_Yadis} for detailed usage information on filter
functions.
@param mixed $filters An array of callbacks to filter the
returned services, or null if all services are to be returned.
@param integer $filter_mode SERVICES_YADIS_MATCH_ALL or
SERVICES_YADIS_MATCH_ANY, depending on whether the returned
services should match ALL or ANY of the specified filters,
respectively.
@return mixed $services An array of {@link
Auth_Yadis_Service} objects if $filter_mode is a valid
mode; null if $filter_mode is an invalid mode (i.e., not
SERVICES_YADIS_MATCH_ANY or SERVICES_YADIS_MATCH_ALL). | [
"Returns",
"a",
"list",
"of",
"service",
"objects",
"which",
"correspond",
"to",
"<Service",
">",
"elements",
"in",
"the",
"XRDS",
"XML",
"document",
"for",
"this",
"object",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/XRDS.php#L406-L489 |
openid/php-openid | Auth/OpenID/Parse.php | Auth_OpenID_Parse.tagMatcher | function tagMatcher($tag_name, $close_tags = null)
{
$expr = $this->_tag_expr;
if ($close_tags) {
$options = implode("|", array_merge(array($tag_name), $close_tags));
$closer = sprintf("(?:%s)", $options);
} else {
$closer = $tag_name;
}
$expr = sprintf($expr, $tag_name, $closer);
return sprintf("/%s/%s", $expr, $this->_re_flags);
} | php | function tagMatcher($tag_name, $close_tags = null)
{
$expr = $this->_tag_expr;
if ($close_tags) {
$options = implode("|", array_merge(array($tag_name), $close_tags));
$closer = sprintf("(?:%s)", $options);
} else {
$closer = $tag_name;
}
$expr = sprintf($expr, $tag_name, $closer);
return sprintf("/%s/%s", $expr, $this->_re_flags);
} | [
"function",
"tagMatcher",
"(",
"$",
"tag_name",
",",
"$",
"close_tags",
"=",
"null",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"_tag_expr",
";",
"if",
"(",
"$",
"close_tags",
")",
"{",
"$",
"options",
"=",
"implode",
"(",
"\"|\"",
",",
"array_me... | Returns a regular expression that will match a given tag in an
SGML string.
@param string $tag_name
@param array $close_tags
@return string | [
"Returns",
"a",
"regular",
"expression",
"that",
"will",
"match",
"a",
"given",
"tag",
"in",
"an",
"SGML",
"string",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Parse.php#L144-L157 |
openid/php-openid | Auth/OpenID/Parse.php | Auth_OpenID_Parse.parseLinkAttrs | function parseLinkAttrs($html)
{
$stripped = preg_replace($this->_removed_re,
"",
$html);
$html_begin = $this->htmlBegin($stripped);
$html_end = $this->htmlEnd($stripped);
if ($html_begin === false) {
return array();
}
if ($html_end === false) {
$html_end = strlen($stripped);
}
$stripped = substr($stripped, $html_begin,
$html_end - $html_begin);
// Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR:
$old_btlimit = ini_set( 'pcre.backtrack_limit', -1 );
// Try to find the <HEAD> tag.
$head_re = $this->headFind();
$head_match = array();
if (!$this->match($head_re, $stripped, $head_match)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
$link_data = array();
$link_matches = array();
if (!preg_match_all($this->_link_find, $head_match[0],
$link_matches)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
foreach ($link_matches[0] as $link) {
$attr_matches = array();
preg_match_all($this->_attr_find, $link, $attr_matches);
$link_attrs = array();
foreach ($attr_matches[0] as $index => $full_match) {
$name = $attr_matches[1][$index];
$value = $this->replaceEntities(
$this->removeQuotes($attr_matches[2][$index]));
$link_attrs[strtolower($name)] = $value;
}
$link_data[] = $link_attrs;
}
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return $link_data;
} | php | function parseLinkAttrs($html)
{
$stripped = preg_replace($this->_removed_re,
"",
$html);
$html_begin = $this->htmlBegin($stripped);
$html_end = $this->htmlEnd($stripped);
if ($html_begin === false) {
return array();
}
if ($html_end === false) {
$html_end = strlen($stripped);
}
$stripped = substr($stripped, $html_begin,
$html_end - $html_begin);
// Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR:
$old_btlimit = ini_set( 'pcre.backtrack_limit', -1 );
// Try to find the <HEAD> tag.
$head_re = $this->headFind();
$head_match = array();
if (!$this->match($head_re, $stripped, $head_match)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
$link_data = array();
$link_matches = array();
if (!preg_match_all($this->_link_find, $head_match[0],
$link_matches)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
foreach ($link_matches[0] as $link) {
$attr_matches = array();
preg_match_all($this->_attr_find, $link, $attr_matches);
$link_attrs = array();
foreach ($attr_matches[0] as $index => $full_match) {
$name = $attr_matches[1][$index];
$value = $this->replaceEntities(
$this->removeQuotes($attr_matches[2][$index]));
$link_attrs[strtolower($name)] = $value;
}
$link_data[] = $link_attrs;
}
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return $link_data;
} | [
"function",
"parseLinkAttrs",
"(",
"$",
"html",
")",
"{",
"$",
"stripped",
"=",
"preg_replace",
"(",
"$",
"this",
"->",
"_removed_re",
",",
"\"\"",
",",
"$",
"html",
")",
";",
"$",
"html_begin",
"=",
"$",
"this",
"->",
"htmlBegin",
"(",
"$",
"stripped"... | Find all link tags in a string representing a HTML document and
return a list of their attributes.
@todo This is quite ineffective and may fail with the default
pcre.backtrack_limit of 100000 in PHP 5.2, if $html is big.
It should rather use stripos (in PHP5) or strpos()+strtoupper()
in PHP4 to manage this.
@param string $html The text to parse
@return array $list An array of arrays of attributes, one for each
link tag | [
"Find",
"all",
"link",
"tags",
"in",
"a",
"string",
"representing",
"a",
"HTML",
"document",
"and",
"return",
"a",
"list",
"of",
"their",
"attributes",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Parse.php#L244-L300 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_Consumer.begin | function begin($user_url, $anonymous=false)
{
$openid_url = $user_url;
$disco = $this->getDiscoveryObject($this->session,
$openid_url,
$this->session_key_prefix);
// Set the 'stale' attribute of the manager. If discovery
// fails in a fatal way, the stale flag will cause the manager
// to be cleaned up next time discovery is attempted.
$m = $disco->getManager();
$loader = new Auth_Yadis_ManagerLoader();
if ($m) {
if ($m->stale) {
$disco->destroyManager();
} else {
$m->stale = true;
$disco->session->set($disco->session_key,
serialize($loader->toSession($m)));
}
}
$endpoint = $disco->getNextService($this->discoverMethod,
$this->consumer->fetcher);
// Reset the 'stale' attribute of the manager.
$m = $disco->getManager();
if ($m) {
$m->stale = false;
$disco->session->set($disco->session_key,
serialize($loader->toSession($m)));
}
if ($endpoint === null) {
return null;
} else {
return $this->beginWithoutDiscovery($endpoint,
$anonymous);
}
} | php | function begin($user_url, $anonymous=false)
{
$openid_url = $user_url;
$disco = $this->getDiscoveryObject($this->session,
$openid_url,
$this->session_key_prefix);
// Set the 'stale' attribute of the manager. If discovery
// fails in a fatal way, the stale flag will cause the manager
// to be cleaned up next time discovery is attempted.
$m = $disco->getManager();
$loader = new Auth_Yadis_ManagerLoader();
if ($m) {
if ($m->stale) {
$disco->destroyManager();
} else {
$m->stale = true;
$disco->session->set($disco->session_key,
serialize($loader->toSession($m)));
}
}
$endpoint = $disco->getNextService($this->discoverMethod,
$this->consumer->fetcher);
// Reset the 'stale' attribute of the manager.
$m = $disco->getManager();
if ($m) {
$m->stale = false;
$disco->session->set($disco->session_key,
serialize($loader->toSession($m)));
}
if ($endpoint === null) {
return null;
} else {
return $this->beginWithoutDiscovery($endpoint,
$anonymous);
}
} | [
"function",
"begin",
"(",
"$",
"user_url",
",",
"$",
"anonymous",
"=",
"false",
")",
"{",
"$",
"openid_url",
"=",
"$",
"user_url",
";",
"$",
"disco",
"=",
"$",
"this",
"->",
"getDiscoveryObject",
"(",
"$",
"this",
"->",
"session",
",",
"$",
"openid_url... | Start the OpenID authentication process. See steps 1-2 in the
overview at the top of this file.
@param string $user_url Identity URL given by the user. This
method performs a textual transformation of the URL to try and
make sure it is normalized. For example, a user_url of
example.com will be normalized to http://example.com/
normalizing and resolving any redirects the server might issue.
@param bool $anonymous True if the OpenID request is to be sent
to the server without any identifier information. Use this
when you want to transport data but don't want to do OpenID
authentication with identifiers.
@return Auth_OpenID_AuthRequest $auth_request An object
containing the discovered information will be returned, with a
method for building a redirect URL to the server, as described
in step 3 of the overview. This object may also be used to add
extension arguments to the request, using its 'addExtensionArg'
method. | [
"Start",
"the",
"OpenID",
"authentication",
"process",
".",
"See",
"steps",
"1",
"-",
"2",
"in",
"the",
"overview",
"at",
"the",
"top",
"of",
"this",
"file",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L308-L350 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_Consumer.beginWithoutDiscovery | function beginWithoutDiscovery($endpoint, $anonymous=false)
{
$loader = new Auth_OpenID_ServiceEndpointLoader();
$auth_req = $this->consumer->begin($endpoint);
$this->session->set($this->_token_key,
$loader->toSession($auth_req->endpoint));
if (!$auth_req->setAnonymous($anonymous)) {
return new Auth_OpenID_FailureResponse(null,
"OpenID 1 requests MUST include the identifier " .
"in the request.");
}
return $auth_req;
} | php | function beginWithoutDiscovery($endpoint, $anonymous=false)
{
$loader = new Auth_OpenID_ServiceEndpointLoader();
$auth_req = $this->consumer->begin($endpoint);
$this->session->set($this->_token_key,
$loader->toSession($auth_req->endpoint));
if (!$auth_req->setAnonymous($anonymous)) {
return new Auth_OpenID_FailureResponse(null,
"OpenID 1 requests MUST include the identifier " .
"in the request.");
}
return $auth_req;
} | [
"function",
"beginWithoutDiscovery",
"(",
"$",
"endpoint",
",",
"$",
"anonymous",
"=",
"false",
")",
"{",
"$",
"loader",
"=",
"new",
"Auth_OpenID_ServiceEndpointLoader",
"(",
")",
";",
"$",
"auth_req",
"=",
"$",
"this",
"->",
"consumer",
"->",
"begin",
"(",
... | Start OpenID verification without doing OpenID server
discovery. This method is used internally by Consumer.begin
after discovery is performed, and exists to provide an
interface for library users needing to perform their own
discovery.
@param Auth_OpenID_ServiceEndpoint $endpoint an OpenID service
endpoint descriptor.
@param bool $anonymous Set to true if you want to perform OpenID
without identifiers.
@return Auth_OpenID_AuthRequest|Auth_OpenID_FailureResponse $auth_request An OpenID
authentication request object. | [
"Start",
"OpenID",
"verification",
"without",
"doing",
"OpenID",
"server",
"discovery",
".",
"This",
"method",
"is",
"used",
"internally",
"by",
"Consumer",
".",
"begin",
"after",
"discovery",
"is",
"performed",
"and",
"exists",
"to",
"provide",
"an",
"interface... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L368-L380 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_Consumer.complete | function complete($current_url, $query=null)
{
if ($current_url && !is_string($current_url)) {
// This is ugly, but we need to complain loudly when
// someone uses the API incorrectly.
trigger_error("current_url must be a string; see NEWS file " .
"for upgrading notes.",
E_USER_ERROR);
}
if ($query === null) {
$query = Auth_OpenID::getQuery();
}
$loader = new Auth_OpenID_ServiceEndpointLoader();
$endpoint_data = $this->session->get($this->_token_key);
$endpoint =
$loader->fromSession($endpoint_data);
$message = Auth_OpenID_Message::fromPostArgs($query);
$response = $this->consumer->complete($message, $endpoint,
$current_url);
$this->session->del($this->_token_key);
if (in_array($response->status, array(Auth_OpenID_SUCCESS,
Auth_OpenID_CANCEL))) {
if ($response->identity_url !== null) {
$disco = $this->getDiscoveryObject($this->session,
$response->identity_url,
$this->session_key_prefix);
$disco->cleanup(true);
}
}
return $response;
} | php | function complete($current_url, $query=null)
{
if ($current_url && !is_string($current_url)) {
// This is ugly, but we need to complain loudly when
// someone uses the API incorrectly.
trigger_error("current_url must be a string; see NEWS file " .
"for upgrading notes.",
E_USER_ERROR);
}
if ($query === null) {
$query = Auth_OpenID::getQuery();
}
$loader = new Auth_OpenID_ServiceEndpointLoader();
$endpoint_data = $this->session->get($this->_token_key);
$endpoint =
$loader->fromSession($endpoint_data);
$message = Auth_OpenID_Message::fromPostArgs($query);
$response = $this->consumer->complete($message, $endpoint,
$current_url);
$this->session->del($this->_token_key);
if (in_array($response->status, array(Auth_OpenID_SUCCESS,
Auth_OpenID_CANCEL))) {
if ($response->identity_url !== null) {
$disco = $this->getDiscoveryObject($this->session,
$response->identity_url,
$this->session_key_prefix);
$disco->cleanup(true);
}
}
return $response;
} | [
"function",
"complete",
"(",
"$",
"current_url",
",",
"$",
"query",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"current_url",
"&&",
"!",
"is_string",
"(",
"$",
"current_url",
")",
")",
"{",
"// This is ugly, but we need to complain loudly when",
"// someone uses the A... | Called to interpret the server's response to an OpenID
request. It is called in step 4 of the flow described in the
consumer overview.
@param string $current_url The URL used to invoke the application.
Extract the URL from your application's web
request framework and specify it here to have it checked
against the openid.current_url value in the response. If
the current_url URL check fails, the status of the
completion will be FAILURE.
@param array $query An array of the query parameters (key =>
value pairs) for this HTTP request. Defaults to null. If
null, the GET or POST data are automatically gotten from the
PHP environment. It is only useful to override $query for
testing.
@return Auth_OpenID_ConsumerResponse $response A instance of an
Auth_OpenID_ConsumerResponse subclass. The type of response is
indicated by the status attribute, which will be one of
SUCCESS, CANCEL, FAILURE, or SETUP_NEEDED. | [
"Called",
"to",
"interpret",
"the",
"server",
"s",
"response",
"to",
"an",
"OpenID",
"request",
".",
"It",
"is",
"called",
"in",
"step",
"4",
"of",
"the",
"flow",
"described",
"in",
"the",
"consumer",
"overview",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L405-L440 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_GenericConsumer.begin | function begin($service_endpoint)
{
$assoc = $this->_getAssociation($service_endpoint);
$r = new Auth_OpenID_AuthRequest($service_endpoint, $assoc);
$r->return_to_args[$this->openid1_nonce_query_arg_name] =
Auth_OpenID_mkNonce();
if ($r->message->isOpenID1()) {
$r->return_to_args[$this->openid1_return_to_identifier_name] =
$r->endpoint->claimed_id;
}
return $r;
} | php | function begin($service_endpoint)
{
$assoc = $this->_getAssociation($service_endpoint);
$r = new Auth_OpenID_AuthRequest($service_endpoint, $assoc);
$r->return_to_args[$this->openid1_nonce_query_arg_name] =
Auth_OpenID_mkNonce();
if ($r->message->isOpenID1()) {
$r->return_to_args[$this->openid1_return_to_identifier_name] =
$r->endpoint->claimed_id;
}
return $r;
} | [
"function",
"begin",
"(",
"$",
"service_endpoint",
")",
"{",
"$",
"assoc",
"=",
"$",
"this",
"->",
"_getAssociation",
"(",
"$",
"service_endpoint",
")",
";",
"$",
"r",
"=",
"new",
"Auth_OpenID_AuthRequest",
"(",
"$",
"service_endpoint",
",",
"$",
"assoc",
... | Called to begin OpenID authentication using the specified
{@link Auth_OpenID_ServiceEndpoint}.
@access private
@param Auth_OpenID_ServiceEndpoint $service_endpoint
@return Auth_OpenID_AuthRequest | [
"Called",
"to",
"begin",
"OpenID",
"authentication",
"using",
"the",
"specified",
"{",
"@link",
"Auth_OpenID_ServiceEndpoint",
"}",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L634-L647 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_GenericConsumer.complete | function complete($message, $endpoint, $return_to)
{
$mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode',
'<no mode set>');
$mode_methods = array(
'cancel' => '_complete_cancel',
'error' => '_complete_error',
'setup_needed' => '_complete_setup_needed',
'id_res' => '_complete_id_res',
);
$method = Auth_OpenID::arrayGet($mode_methods, $mode,
'_completeInvalid');
return call_user_func_array(array($this, $method),
array($message, $endpoint, $return_to));
} | php | function complete($message, $endpoint, $return_to)
{
$mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode',
'<no mode set>');
$mode_methods = array(
'cancel' => '_complete_cancel',
'error' => '_complete_error',
'setup_needed' => '_complete_setup_needed',
'id_res' => '_complete_id_res',
);
$method = Auth_OpenID::arrayGet($mode_methods, $mode,
'_completeInvalid');
return call_user_func_array(array($this, $method),
array($message, $endpoint, $return_to));
} | [
"function",
"complete",
"(",
"$",
"message",
",",
"$",
"endpoint",
",",
"$",
"return_to",
")",
"{",
"$",
"mode",
"=",
"$",
"message",
"->",
"getArg",
"(",
"Auth_OpenID_OPENID_NS",
",",
"'mode'",
",",
"'<no mode set>'",
")",
";",
"$",
"mode_methods",
"=",
... | Given an {@link Auth_OpenID_Message}, {@link
Auth_OpenID_ServiceEndpoint} and optional return_to URL,
complete OpenID authentication.
@access private
@param Auth_OpenID_Message $message
@param Auth_OpenID_ServiceEndpoint $endpoint
@param string $return_to
@return Auth_OpenID_SuccessResponse | [
"Given",
"an",
"{",
"@link",
"Auth_OpenID_Message",
"}",
"{",
"@link",
"Auth_OpenID_ServiceEndpoint",
"}",
"and",
"optional",
"return_to",
"URL",
"complete",
"OpenID",
"authentication",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L660-L677 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_GenericConsumer._httpResponseToMessage | static function _httpResponseToMessage($response)
{
// Should this function be named Message.fromHTTPResponse instead?
$response_message = Auth_OpenID_Message::fromKVForm($response->body);
if ($response->status == 400) {
return Auth_OpenID_ServerErrorContainer::fromMessage(
$response_message);
} else if ($response->status != 200 and $response->status != 206) {
return null;
}
return $response_message;
} | php | static function _httpResponseToMessage($response)
{
// Should this function be named Message.fromHTTPResponse instead?
$response_message = Auth_OpenID_Message::fromKVForm($response->body);
if ($response->status == 400) {
return Auth_OpenID_ServerErrorContainer::fromMessage(
$response_message);
} else if ($response->status != 200 and $response->status != 206) {
return null;
}
return $response_message;
} | [
"static",
"function",
"_httpResponseToMessage",
"(",
"$",
"response",
")",
"{",
"// Should this function be named Message.fromHTTPResponse instead?",
"$",
"response_message",
"=",
"Auth_OpenID_Message",
"::",
"fromKVForm",
"(",
"$",
"response",
"->",
"body",
")",
";",
"if... | Adapt a POST response to a Message.
@param Auth_Yadis_HTTPResponse $response Result of a POST to an OpenID endpoint.
@access private
@return Auth_OpenID_Message|Auth_OpenID_ServerErrorContainer|null | [
"Adapt",
"a",
"POST",
"response",
"to",
"a",
"Message",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L1470-L1483 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_GenericConsumer._extractSupportedAssociationType | function _extractSupportedAssociationType($server_error)
{
// Any error message whose code is not 'unsupported-type'
// should be considered a total failure.
if (($server_error->error_code != 'unsupported-type') ||
($server_error->message->isOpenID1())) {
return null;
}
// The server didn't like the association/session type that we
// sent, and it sent us back a message that might tell us how
// to handle it.
// Extract the session_type and assoc_type from the error
// message
$assoc_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
'assoc_type');
$session_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
'session_type');
if (($assoc_type === null) || ($session_type === null)) {
return null;
} else if (!$this->negotiator->isAllowed($assoc_type,
$session_type)) {
return null;
} else {
return array($assoc_type, $session_type);
}
} | php | function _extractSupportedAssociationType($server_error)
{
// Any error message whose code is not 'unsupported-type'
// should be considered a total failure.
if (($server_error->error_code != 'unsupported-type') ||
($server_error->message->isOpenID1())) {
return null;
}
// The server didn't like the association/session type that we
// sent, and it sent us back a message that might tell us how
// to handle it.
// Extract the session_type and assoc_type from the error
// message
$assoc_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
'assoc_type');
$session_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
'session_type');
if (($assoc_type === null) || ($session_type === null)) {
return null;
} else if (!$this->negotiator->isAllowed($assoc_type,
$session_type)) {
return null;
} else {
return array($assoc_type, $session_type);
}
} | [
"function",
"_extractSupportedAssociationType",
"(",
"$",
"server_error",
")",
"{",
"// Any error message whose code is not 'unsupported-type'",
"// should be considered a total failure.",
"if",
"(",
"(",
"$",
"server_error",
"->",
"error_code",
"!=",
"'unsupported-type'",
")",
... | Handle ServerErrors resulting from association requests.
@param $server_error
@return array|null $result If server replied with an C{unsupported-type}
error, return a tuple of supported C{association_type},
C{session_type}. Otherwise logs the error and returns null.
@access private | [
"Handle",
"ServerErrors",
"resulting",
"from",
"association",
"requests",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L1538-L1567 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_GenericConsumer._getOpenID1SessionType | function _getOpenID1SessionType($assoc_response)
{
// If it's an OpenID 1 message, allow session_type to default
// to None (which signifies "no-encryption")
$session_type = $assoc_response->getArg(Auth_OpenID_OPENID1_NS,
'session_type');
// Handle the differences between no-encryption association
// respones in OpenID 1 and 2:
// no-encryption is not really a valid session type for OpenID
// 1, but we'll accept it anyway, while issuing a warning.
if ($session_type == 'no-encryption') {
// oidutil.log('WARNING: OpenID server sent "no-encryption"'
// 'for OpenID 1.X')
} else if (($session_type == '') || ($session_type === null)) {
// Missing or empty session type is the way to flag a
// 'no-encryption' response. Change the session type to
// 'no-encryption' so that it can be handled in the same
// way as OpenID 2 'no-encryption' respones.
$session_type = 'no-encryption';
}
return $session_type;
} | php | function _getOpenID1SessionType($assoc_response)
{
// If it's an OpenID 1 message, allow session_type to default
// to None (which signifies "no-encryption")
$session_type = $assoc_response->getArg(Auth_OpenID_OPENID1_NS,
'session_type');
// Handle the differences between no-encryption association
// respones in OpenID 1 and 2:
// no-encryption is not really a valid session type for OpenID
// 1, but we'll accept it anyway, while issuing a warning.
if ($session_type == 'no-encryption') {
// oidutil.log('WARNING: OpenID server sent "no-encryption"'
// 'for OpenID 1.X')
} else if (($session_type == '') || ($session_type === null)) {
// Missing or empty session type is the way to flag a
// 'no-encryption' response. Change the session type to
// 'no-encryption' so that it can be handled in the same
// way as OpenID 2 'no-encryption' respones.
$session_type = 'no-encryption';
}
return $session_type;
} | [
"function",
"_getOpenID1SessionType",
"(",
"$",
"assoc_response",
")",
"{",
"// If it's an OpenID 1 message, allow session_type to default",
"// to None (which signifies \"no-encryption\")",
"$",
"session_type",
"=",
"$",
"assoc_response",
"->",
"getArg",
"(",
"Auth_OpenID_OPENID1_... | Given an association response message, extract the OpenID 1.X
session type.
This function mostly takes care of the 'no-encryption' default
behavior in OpenID 1.
If the association type is plain-text, this function will
return 'no-encryption'
@access private
@param Auth_OpenID_Message $assoc_response
@return string The association type for this message | [
"Given",
"an",
"association",
"response",
"message",
"extract",
"the",
"OpenID",
"1",
".",
"X",
"session",
"type",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L1793-L1817 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_AuthRequest.setAnonymous | function setAnonymous($is_anonymous)
{
if ($is_anonymous && $this->message->isOpenID1()) {
return false;
} else {
$this->_anonymous = $is_anonymous;
return true;
}
} | php | function setAnonymous($is_anonymous)
{
if ($is_anonymous && $this->message->isOpenID1()) {
return false;
} else {
$this->_anonymous = $is_anonymous;
return true;
}
} | [
"function",
"setAnonymous",
"(",
"$",
"is_anonymous",
")",
"{",
"if",
"(",
"$",
"is_anonymous",
"&&",
"$",
"this",
"->",
"message",
"->",
"isOpenID1",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_anonymous",
"=",
... | Set whether this request should be made anonymously. If a
request is anonymous, the identifier will not be sent in the
request. This is only useful if you are making another kind of
request with an extension in this request.
Anonymous requests are not allowed when the request is made
with OpenID 1.
@param bool $is_anonymous
@return bool | [
"Set",
"whether",
"this",
"request",
"should",
"be",
"made",
"anonymously",
".",
"If",
"a",
"request",
"is",
"anonymous",
"the",
"identifier",
"will",
"not",
"be",
"sent",
"in",
"the",
"request",
".",
"This",
"is",
"only",
"useful",
"if",
"you",
"are",
"... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L1897-L1905 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_AuthRequest.getMessage | function getMessage($realm, $return_to=null, $immediate=false)
{
if ($return_to) {
$return_to = Auth_OpenID::appendArgs($return_to,
$this->return_to_args);
} else if ($immediate) {
// raise ValueError(
// '"return_to" is mandatory when
//using "checkid_immediate"')
return new Auth_OpenID_FailureResponse(null,
"'return_to' is mandatory when using checkid_immediate");
} else if ($this->message->isOpenID1()) {
// raise ValueError('"return_to" is
// mandatory for OpenID 1 requests')
return new Auth_OpenID_FailureResponse(null,
"'return_to' is mandatory for OpenID 1 requests");
} else if ($this->return_to_args) {
// raise ValueError('extra "return_to" arguments
// were specified, but no return_to was specified')
return new Auth_OpenID_FailureResponse(null,
"extra 'return_to' arguments where specified, " .
"but no return_to was specified");
}
if ($immediate) {
$mode = 'checkid_immediate';
} else {
$mode = 'checkid_setup';
}
$message = $this->message->copy();
if ($message->isOpenID1()) {
$realm_key = 'trust_root';
} else {
$realm_key = 'realm';
}
$message->updateArgs(Auth_OpenID_OPENID_NS,
array(
$realm_key => $realm,
'mode' => $mode,
'return_to' => $return_to));
if (!$this->_anonymous) {
if ($this->endpoint->isOPIdentifier()) {
// This will never happen when we're in compatibility
// mode, as long as isOPIdentifier() returns False
// whenever preferredNamespace() returns OPENID1_NS.
$claimed_id = $request_identity =
Auth_OpenID_IDENTIFIER_SELECT;
} else {
$request_identity = $this->endpoint->getLocalID();
$claimed_id = $this->endpoint->claimed_id;
}
// This is true for both OpenID 1 and 2
$message->setArg(Auth_OpenID_OPENID_NS, 'identity',
$request_identity);
if ($message->isOpenID2()) {
$message->setArg(Auth_OpenID_OPENID2_NS, 'claimed_id',
$claimed_id);
}
}
if ($this->assoc) {
$message->setArg(Auth_OpenID_OPENID_NS, 'assoc_handle',
$this->assoc->handle);
}
return $message;
} | php | function getMessage($realm, $return_to=null, $immediate=false)
{
if ($return_to) {
$return_to = Auth_OpenID::appendArgs($return_to,
$this->return_to_args);
} else if ($immediate) {
// raise ValueError(
// '"return_to" is mandatory when
//using "checkid_immediate"')
return new Auth_OpenID_FailureResponse(null,
"'return_to' is mandatory when using checkid_immediate");
} else if ($this->message->isOpenID1()) {
// raise ValueError('"return_to" is
// mandatory for OpenID 1 requests')
return new Auth_OpenID_FailureResponse(null,
"'return_to' is mandatory for OpenID 1 requests");
} else if ($this->return_to_args) {
// raise ValueError('extra "return_to" arguments
// were specified, but no return_to was specified')
return new Auth_OpenID_FailureResponse(null,
"extra 'return_to' arguments where specified, " .
"but no return_to was specified");
}
if ($immediate) {
$mode = 'checkid_immediate';
} else {
$mode = 'checkid_setup';
}
$message = $this->message->copy();
if ($message->isOpenID1()) {
$realm_key = 'trust_root';
} else {
$realm_key = 'realm';
}
$message->updateArgs(Auth_OpenID_OPENID_NS,
array(
$realm_key => $realm,
'mode' => $mode,
'return_to' => $return_to));
if (!$this->_anonymous) {
if ($this->endpoint->isOPIdentifier()) {
// This will never happen when we're in compatibility
// mode, as long as isOPIdentifier() returns False
// whenever preferredNamespace() returns OPENID1_NS.
$claimed_id = $request_identity =
Auth_OpenID_IDENTIFIER_SELECT;
} else {
$request_identity = $this->endpoint->getLocalID();
$claimed_id = $this->endpoint->claimed_id;
}
// This is true for both OpenID 1 and 2
$message->setArg(Auth_OpenID_OPENID_NS, 'identity',
$request_identity);
if ($message->isOpenID2()) {
$message->setArg(Auth_OpenID_OPENID2_NS, 'claimed_id',
$claimed_id);
}
}
if ($this->assoc) {
$message->setArg(Auth_OpenID_OPENID_NS, 'assoc_handle',
$this->assoc->handle);
}
return $message;
} | [
"function",
"getMessage",
"(",
"$",
"realm",
",",
"$",
"return_to",
"=",
"null",
",",
"$",
"immediate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"return_to",
")",
"{",
"$",
"return_to",
"=",
"Auth_OpenID",
"::",
"appendArgs",
"(",
"$",
"return_to",
",",... | Produce a {@link Auth_OpenID_Message} representing this
request.
@param string $realm The URL (or URL pattern) that identifies
your web site to the user when she is authorizing it.
@param string $return_to The URL that the OpenID provider will
send the user back to after attempting to verify her identity.
Not specifying a return_to URL means that the user will not be
returned to the site issuing the request upon its completion.
@param bool $immediate If true, the OpenID provider is to send
back a response immediately, useful for behind-the-scenes
authentication attempts. Otherwise the OpenID provider may
engage the user before providing a response. This is the
default case, as the user may need to provide credentials or
approve the request before a positive response can be sent.
@return Auth_OpenID_Message|Auth_OpenID_FailureResponse | [
"Produce",
"a",
"{",
"@link",
"Auth_OpenID_Message",
"}",
"representing",
"this",
"request",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L1929-L2000 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_AuthRequest.formMarkup | function formMarkup($realm, $return_to=null, $immediate=false,
$form_tag_attrs=null)
{
$message = $this->getMessage($realm, $return_to, $immediate);
if (Auth_OpenID::isFailure($message)) {
return $message;
}
return $message->toFormMarkup($this->endpoint->server_url, $form_tag_attrs);
} | php | function formMarkup($realm, $return_to=null, $immediate=false,
$form_tag_attrs=null)
{
$message = $this->getMessage($realm, $return_to, $immediate);
if (Auth_OpenID::isFailure($message)) {
return $message;
}
return $message->toFormMarkup($this->endpoint->server_url, $form_tag_attrs);
} | [
"function",
"formMarkup",
"(",
"$",
"realm",
",",
"$",
"return_to",
"=",
"null",
",",
"$",
"immediate",
"=",
"false",
",",
"$",
"form_tag_attrs",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"realm",
",",
"$"... | Get html for a form to submit this request to the IDP.
form_tag_attrs: An array of attributes to be added to the form
tag. 'accept-charset' and 'enctype' have defaults that can be
overridden. If a value is supplied for 'action' or 'method', it
will be replaced.
@param string $realm
@param null|string $return_to
@param bool $immediate
@param null|array $form_tag_attrs
@return Auth_OpenID_FailureResponse|Auth_OpenID_Message|string | [
"Get",
"html",
"for",
"a",
"form",
"to",
"submit",
"this",
"request",
"to",
"the",
"IDP",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L2028-L2038 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_AuthRequest.htmlMarkup | function htmlMarkup($realm, $return_to=null, $immediate=false,
$form_tag_attrs=null)
{
$form = $this->formMarkup($realm, $return_to, $immediate,
$form_tag_attrs);
if (Auth_OpenID::isFailure($form)) {
return $form;
}
return Auth_OpenID::autoSubmitHTML($form);
} | php | function htmlMarkup($realm, $return_to=null, $immediate=false,
$form_tag_attrs=null)
{
$form = $this->formMarkup($realm, $return_to, $immediate,
$form_tag_attrs);
if (Auth_OpenID::isFailure($form)) {
return $form;
}
return Auth_OpenID::autoSubmitHTML($form);
} | [
"function",
"htmlMarkup",
"(",
"$",
"realm",
",",
"$",
"return_to",
"=",
"null",
",",
"$",
"immediate",
"=",
"false",
",",
"$",
"form_tag_attrs",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"formMarkup",
"(",
"$",
"realm",
",",
"$",
... | Get a complete html document that will autosubmit the request
to the IDP.
Wraps formMarkup. See the documentation for that function.
@param string $realm
@param string $return_to
@param bool $immediate
@param array $form_tag_attrs
@return Auth_OpenID_FailureResponse|Auth_OpenID_Message|string | [
"Get",
"a",
"complete",
"html",
"document",
"that",
"will",
"autosubmit",
"the",
"request",
"to",
"the",
"IDP",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L2052-L2062 |
openid/php-openid | Auth/OpenID/Consumer.php | Auth_OpenID_SuccessResponse.extensionResponse | function extensionResponse($namespace_uri, $require_signed)
{
if ($require_signed) {
return $this->getSignedNS($namespace_uri);
} else {
return $this->message->getArgs($namespace_uri);
}
} | php | function extensionResponse($namespace_uri, $require_signed)
{
if ($require_signed) {
return $this->getSignedNS($namespace_uri);
} else {
return $this->message->getArgs($namespace_uri);
}
} | [
"function",
"extensionResponse",
"(",
"$",
"namespace_uri",
",",
"$",
"require_signed",
")",
"{",
"if",
"(",
"$",
"require_signed",
")",
"{",
"return",
"$",
"this",
"->",
"getSignedNS",
"(",
"$",
"namespace_uri",
")",
";",
"}",
"else",
"{",
"return",
"$",
... | Extract signed extension data from the server's response.
@param $namespace_uri
@param $require_signed
@return array|Auth_OpenID_FailureResponse|null|string
@internal param string $prefix The extension namespace from which to
extract the extension data. | [
"Extract",
"signed",
"extension",
"data",
"from",
"the",
"server",
"s",
"response",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/OpenID/Consumer.php#L2172-L2179 |
openid/php-openid | Auth/Yadis/Yadis.php | Auth_Yadis_Yadis.getHTTPFetcher | static function getHTTPFetcher($timeout = 20)
{
if (Auth_Yadis_Yadis::curlPresent() &&
(!defined('Auth_Yadis_CURL_OVERRIDE'))) {
$fetcher = new Auth_Yadis_ParanoidHTTPFetcher($timeout);
} else {
$fetcher = new Auth_Yadis_PlainHTTPFetcher($timeout);
}
return $fetcher;
} | php | static function getHTTPFetcher($timeout = 20)
{
if (Auth_Yadis_Yadis::curlPresent() &&
(!defined('Auth_Yadis_CURL_OVERRIDE'))) {
$fetcher = new Auth_Yadis_ParanoidHTTPFetcher($timeout);
} else {
$fetcher = new Auth_Yadis_PlainHTTPFetcher($timeout);
}
return $fetcher;
} | [
"static",
"function",
"getHTTPFetcher",
"(",
"$",
"timeout",
"=",
"20",
")",
"{",
"if",
"(",
"Auth_Yadis_Yadis",
"::",
"curlPresent",
"(",
")",
"&&",
"(",
"!",
"defined",
"(",
"'Auth_Yadis_CURL_OVERRIDE'",
")",
")",
")",
"{",
"$",
"fetcher",
"=",
"new",
... | Returns an HTTP fetcher object. If the CURL extension is
present, an instance of {@link Auth_Yadis_ParanoidHTTPFetcher}
is returned. If not, an instance of
{@link Auth_Yadis_PlainHTTPFetcher} is returned.
If Auth_Yadis_CURL_OVERRIDE is defined, this method will always
return a {@link Auth_Yadis_PlainHTTPFetcher}.
@param int $timeout
@return Auth_Yadis_ParanoidHTTPFetcher|Auth_Yadis_PlainHTTPFetcher | [
"Returns",
"an",
"HTTP",
"fetcher",
"object",
".",
"If",
"the",
"CURL",
"extension",
"is",
"present",
"an",
"instance",
"of",
"{",
"@link",
"Auth_Yadis_ParanoidHTTPFetcher",
"}",
"is",
"returned",
".",
"If",
"not",
"an",
"instance",
"of",
"{",
"@link",
"Auth... | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Yadis.php#L263-L272 |
openid/php-openid | Auth/Yadis/Yadis.php | Auth_Yadis_Yadis.discover | static function discover($uri, $fetcher,
$extra_ns_map = null, $timeout = 20)
{
$result = new Auth_Yadis_DiscoveryResult($uri);
$headers = array("Accept: " . Auth_Yadis_CONTENT_TYPE .
', text/html; q=0.3, application/xhtml+xml; q=0.5');
if ($fetcher === null) {
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher($timeout);
}
$response = $fetcher->get($uri, $headers);
if (!$response || ($response->status != 200 and
$response->status != 206)) {
$result->fail();
return $result;
}
$result->normalized_uri = $response->final_url;
$result->content_type = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array('content-type'));
if ($result->content_type &&
(Auth_Yadis_Yadis::_getContentType($result->content_type) ==
Auth_Yadis_CONTENT_TYPE)) {
$result->xrds_uri = $result->normalized_uri;
} else {
$yadis_location = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array(Auth_Yadis_HEADER_NAME));
if (!$yadis_location) {
$parser = new Auth_Yadis_ParseHTML();
$yadis_location = $parser->getHTTPEquiv($response->body);
}
if ($yadis_location) {
$result->xrds_uri = $yadis_location;
$response = $fetcher->get($yadis_location);
if ((!$response) || ($response->status != 200 and
$response->status != 206)) {
$result->fail();
return $result;
}
$result->content_type = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array('content-type'));
}
}
$result->response_text = $response->body;
return $result;
} | php | static function discover($uri, $fetcher,
$extra_ns_map = null, $timeout = 20)
{
$result = new Auth_Yadis_DiscoveryResult($uri);
$headers = array("Accept: " . Auth_Yadis_CONTENT_TYPE .
', text/html; q=0.3, application/xhtml+xml; q=0.5');
if ($fetcher === null) {
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher($timeout);
}
$response = $fetcher->get($uri, $headers);
if (!$response || ($response->status != 200 and
$response->status != 206)) {
$result->fail();
return $result;
}
$result->normalized_uri = $response->final_url;
$result->content_type = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array('content-type'));
if ($result->content_type &&
(Auth_Yadis_Yadis::_getContentType($result->content_type) ==
Auth_Yadis_CONTENT_TYPE)) {
$result->xrds_uri = $result->normalized_uri;
} else {
$yadis_location = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array(Auth_Yadis_HEADER_NAME));
if (!$yadis_location) {
$parser = new Auth_Yadis_ParseHTML();
$yadis_location = $parser->getHTTPEquiv($response->body);
}
if ($yadis_location) {
$result->xrds_uri = $yadis_location;
$response = $fetcher->get($yadis_location);
if ((!$response) || ($response->status != 200 and
$response->status != 206)) {
$result->fail();
return $result;
}
$result->content_type = Auth_Yadis_Yadis::_getHeader(
$response->headers,
array('content-type'));
}
}
$result->response_text = $response->body;
return $result;
} | [
"static",
"function",
"discover",
"(",
"$",
"uri",
",",
"$",
"fetcher",
",",
"$",
"extra_ns_map",
"=",
"null",
",",
"$",
"timeout",
"=",
"20",
")",
"{",
"$",
"result",
"=",
"new",
"Auth_Yadis_DiscoveryResult",
"(",
"$",
"uri",
")",
";",
"$",
"headers",... | This should be called statically and will build a Yadis
instance if the discovery process succeeds. This implements
Yadis discovery as specified in the Yadis specification.
@param string $uri The URI on which to perform Yadis discovery.
@param Auth_Yadis_HTTPFetcher $fetcher An instance of a
Auth_Yadis_HTTPFetcher subclass.
@param array $extra_ns_map An array which maps namespace names
to namespace URIs to be used when parsing the Yadis XRDS
document. UNUSED.
@param integer $timeout An optional fetcher timeout, in seconds.
@return mixed $obj Either null or an instance of
Auth_Yadis_Yadis, depending on whether the discovery
succeeded. | [
"This",
"should",
"be",
"called",
"statically",
"and",
"will",
"build",
"a",
"Yadis",
"instance",
"if",
"the",
"discovery",
"process",
"succeeds",
".",
"This",
"implements",
"Yadis",
"discovery",
"as",
"specified",
"in",
"the",
"Yadis",
"specification",
"."
] | train | https://github.com/openid/php-openid/blob/99d24177dbad21d13878ac653bbfb1ed18b66114/Auth/Yadis/Yadis.php#L332-L390 |
sngrl/php-firebase-cloud-messaging | src/Client.php | Client.processTopicSubscription | protected function processTopicSubscription($topic_id, $recipients_tokens, $url)
{
if (!is_array($recipients_tokens))
$recipients_tokens = [$recipients_tokens];
return $this->guzzleClient->post(
$url,
[
'headers' => [
'Authorization' => sprintf('key=%s', $this->apiKey),
'Content-Type' => 'application/json'
],
'body' => json_encode([
'to' => '/topics/' . $topic_id,
'registration_tokens' => $recipients_tokens,
])
]
);
} | php | protected function processTopicSubscription($topic_id, $recipients_tokens, $url)
{
if (!is_array($recipients_tokens))
$recipients_tokens = [$recipients_tokens];
return $this->guzzleClient->post(
$url,
[
'headers' => [
'Authorization' => sprintf('key=%s', $this->apiKey),
'Content-Type' => 'application/json'
],
'body' => json_encode([
'to' => '/topics/' . $topic_id,
'registration_tokens' => $recipients_tokens,
])
]
);
} | [
"protected",
"function",
"processTopicSubscription",
"(",
"$",
"topic_id",
",",
"$",
"recipients_tokens",
",",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"recipients_tokens",
")",
")",
"$",
"recipients_tokens",
"=",
"[",
"$",
"recipients_token... | @param integer $topic_id
@param array|string $recipients_tokens
@param string $url
@return \Psr\Http\Message\ResponseInterface | [
"@param",
"integer",
"$topic_id",
"@param",
"array|string",
"$recipients_tokens",
"@param",
"string",
"$url"
] | train | https://github.com/sngrl/php-firebase-cloud-messaging/blob/e1a344c20c6d7dc4f89dcc5a56b17129d007d2b2/src/Client.php#L105-L123 |
sngrl/php-firebase-cloud-messaging | src/Message.php | Message.addRecipient | public function addRecipient(Recipient $recipient)
{
$this->recipients[] = $recipient;
if (!isset($this->recipientType)) {
$this->recipientType = get_class($recipient);
}
if ($this->recipientType !== get_class($recipient)) {
throw new \InvalidArgumentException('mixed recepient types are not supported by FCM');
}
return $this;
} | php | public function addRecipient(Recipient $recipient)
{
$this->recipients[] = $recipient;
if (!isset($this->recipientType)) {
$this->recipientType = get_class($recipient);
}
if ($this->recipientType !== get_class($recipient)) {
throw new \InvalidArgumentException('mixed recepient types are not supported by FCM');
}
return $this;
} | [
"public",
"function",
"addRecipient",
"(",
"Recipient",
"$",
"recipient",
")",
"{",
"$",
"this",
"->",
"recipients",
"[",
"]",
"=",
"$",
"recipient",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"recipientType",
")",
")",
"{",
"$",
"this",
"... | where should the message go
@param Recipient $recipient
@return \sngrl\PhpFirebaseCloudMessaging\Message | [
"where",
"should",
"the",
"message",
"go"
] | train | https://github.com/sngrl/php-firebase-cloud-messaging/blob/e1a344c20c6d7dc4f89dcc5a56b17129d007d2b2/src/Message.php#L40-L52 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.getSignature | public function getSignature(RequestInterface $request, array $params)
{
// Remove oauth_signature if present
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
unset($params['oauth_signature']);
// Add POST fields if the request uses POST fields and no files
if ($request->getHeaderLine('Content-Type') == 'application/x-www-form-urlencoded') {
$body = \GuzzleHttp\Psr7\parse_query($request->getBody()->getContents());
$params += $body;
}
// Parse & add query string parameters as base string parameters
$query = $request->getUri()->getQuery();
$params += \GuzzleHttp\Psr7\parse_query($query);
$baseString = $this->createBaseString(
$request,
$this->prepareParameters($params)
);
// Implements double-dispatch to sign requests
switch ($this->config['signature_method']) {
case Oauth1::SIGNATURE_METHOD_HMAC:
$signature = $this->signUsingHmacSha1($baseString);
break;
case Oauth1::SIGNATURE_METHOD_RSA:
$signature = $this->signUsingRsaSha1($baseString);
break;
case Oauth1::SIGNATURE_METHOD_PLAINTEXT:
$signature = $this->signUsingPlaintext($baseString);
break;
default:
throw new \RuntimeException('Unknown signature method: ' . $this->config['signature_method']);
break;
}
return base64_encode($signature);
} | php | public function getSignature(RequestInterface $request, array $params)
{
// Remove oauth_signature if present
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
unset($params['oauth_signature']);
// Add POST fields if the request uses POST fields and no files
if ($request->getHeaderLine('Content-Type') == 'application/x-www-form-urlencoded') {
$body = \GuzzleHttp\Psr7\parse_query($request->getBody()->getContents());
$params += $body;
}
// Parse & add query string parameters as base string parameters
$query = $request->getUri()->getQuery();
$params += \GuzzleHttp\Psr7\parse_query($query);
$baseString = $this->createBaseString(
$request,
$this->prepareParameters($params)
);
// Implements double-dispatch to sign requests
switch ($this->config['signature_method']) {
case Oauth1::SIGNATURE_METHOD_HMAC:
$signature = $this->signUsingHmacSha1($baseString);
break;
case Oauth1::SIGNATURE_METHOD_RSA:
$signature = $this->signUsingRsaSha1($baseString);
break;
case Oauth1::SIGNATURE_METHOD_PLAINTEXT:
$signature = $this->signUsingPlaintext($baseString);
break;
default:
throw new \RuntimeException('Unknown signature method: ' . $this->config['signature_method']);
break;
}
return base64_encode($signature);
} | [
"public",
"function",
"getSignature",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"params",
")",
"{",
"// Remove oauth_signature if present",
"// Ref: Spec: 9.1.1 (\"The oauth_signature parameter MUST be excluded.\")",
"unset",
"(",
"$",
"params",
"[",
"'oauth... | Calculate signature for request
@param RequestInterface $request Request to generate a signature for
@param array $params Oauth parameters.
@return string
@throws \RuntimeException | [
"Calculate",
"signature",
"for",
"request"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L134-L172 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.generateNonce | public function generateNonce(RequestInterface $request)
{
return sha1(uniqid('', true) . $request->getUri()->getHost() . $request->getUri()->getPath());
} | php | public function generateNonce(RequestInterface $request)
{
return sha1(uniqid('', true) . $request->getUri()->getHost() . $request->getUri()->getPath());
} | [
"public",
"function",
"generateNonce",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"return",
"sha1",
"(",
"uniqid",
"(",
"''",
",",
"true",
")",
".",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getHost",
"(",
")",
".",
"$",
"request",
"->",... | Returns a Nonce Based on the unique id and URL.
This will allow for multiple requests in parallel with the same exact
timestamp to use separate nonce's.
@param RequestInterface $request Request to generate a nonce for
@return string | [
"Returns",
"a",
"Nonce",
"Based",
"on",
"the",
"unique",
"id",
"and",
"URL",
"."
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L184-L187 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.createBaseString | protected function createBaseString(RequestInterface $request, array $params)
{
// Remove query params from URL. Ref: Spec: 9.1.2.
$url = $request->getUri()->withQuery('');
$query = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
return strtoupper($request->getMethod())
. '&' . rawurlencode($url)
. '&' . rawurlencode($query);
} | php | protected function createBaseString(RequestInterface $request, array $params)
{
// Remove query params from URL. Ref: Spec: 9.1.2.
$url = $request->getUri()->withQuery('');
$query = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
return strtoupper($request->getMethod())
. '&' . rawurlencode($url)
. '&' . rawurlencode($query);
} | [
"protected",
"function",
"createBaseString",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"params",
")",
"{",
"// Remove query params from URL. Ref: Spec: 9.1.2.",
"$",
"url",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"withQuery",
"(",
"'... | Creates the Signature Base String.
The Signature Base String is a consistent reproducible concatenation of
the request elements into a single string. The string is used as an
input in hashing or signing algorithms.
@param RequestInterface $request Request being signed
@param array $params Associative array of OAuth parameters
@return string Returns the base string
@link http://oauth.net/core/1.0/#sig_base_example | [
"Creates",
"the",
"Signature",
"Base",
"String",
"."
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L202-L211 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.prepareParameters | private function prepareParameters($data)
{
// Parameters are sorted by name, using lexicographical byte value
// ordering. Ref: Spec: 9.1.1 (1).
uksort($data, 'strcmp');
foreach ($data as $key => $value) {
if ($value === null) {
unset($data[$key]);
}
}
return $data;
} | php | private function prepareParameters($data)
{
// Parameters are sorted by name, using lexicographical byte value
// ordering. Ref: Spec: 9.1.1 (1).
uksort($data, 'strcmp');
foreach ($data as $key => $value) {
if ($value === null) {
unset($data[$key]);
}
}
return $data;
} | [
"private",
"function",
"prepareParameters",
"(",
"$",
"data",
")",
"{",
"// Parameters are sorted by name, using lexicographical byte value",
"// ordering. Ref: Spec: 9.1.1 (1).",
"uksort",
"(",
"$",
"data",
",",
"'strcmp'",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
... | Convert booleans to strings, removed unset parameters, and sorts the array
@param array $data Data array
@return array | [
"Convert",
"booleans",
"to",
"strings",
"removed",
"unset",
"parameters",
"and",
"sorts",
"the",
"array"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L220-L233 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.signUsingHmacSha1 | private function signUsingHmacSha1($baseString)
{
$key = rawurlencode($this->config['consumer_secret'])
. '&' . rawurlencode($this->config['token_secret']);
return hash_hmac('sha1', $baseString, $key, true);
} | php | private function signUsingHmacSha1($baseString)
{
$key = rawurlencode($this->config['consumer_secret'])
. '&' . rawurlencode($this->config['token_secret']);
return hash_hmac('sha1', $baseString, $key, true);
} | [
"private",
"function",
"signUsingHmacSha1",
"(",
"$",
"baseString",
")",
"{",
"$",
"key",
"=",
"rawurlencode",
"(",
"$",
"this",
"->",
"config",
"[",
"'consumer_secret'",
"]",
")",
".",
"'&'",
".",
"rawurlencode",
"(",
"$",
"this",
"->",
"config",
"[",
"... | @param string $baseString
@return string | [
"@param",
"string",
"$baseString"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L240-L246 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.signUsingRsaSha1 | private function signUsingRsaSha1($baseString)
{
if (!function_exists('openssl_pkey_get_private')) {
throw new \RuntimeException('RSA-SHA1 signature method '
. 'requires the OpenSSL extension.');
}
$privateKey = openssl_pkey_get_private(
file_get_contents($this->config['private_key_file']),
$this->config['private_key_passphrase']
);
$signature = '';
openssl_sign($baseString, $signature, $privateKey);
openssl_free_key($privateKey);
return $signature;
} | php | private function signUsingRsaSha1($baseString)
{
if (!function_exists('openssl_pkey_get_private')) {
throw new \RuntimeException('RSA-SHA1 signature method '
. 'requires the OpenSSL extension.');
}
$privateKey = openssl_pkey_get_private(
file_get_contents($this->config['private_key_file']),
$this->config['private_key_passphrase']
);
$signature = '';
openssl_sign($baseString, $signature, $privateKey);
openssl_free_key($privateKey);
return $signature;
} | [
"private",
"function",
"signUsingRsaSha1",
"(",
"$",
"baseString",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'openssl_pkey_get_private'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'RSA-SHA1 signature method '",
".",
"'requires the OpenSSL... | @param string $baseString
@return string | [
"@param",
"string",
"$baseString"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L253-L270 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.buildAuthorizationHeader | private function buildAuthorizationHeader(array $params)
{
foreach ($params as $key => $value) {
$params[$key] = $key . '="' . rawurlencode($value) . '"';
}
if (isset($this->config['realm'])) {
array_unshift(
$params,
'realm="' . rawurlencode($this->config['realm']) . '"'
);
}
return ['Authorization', 'OAuth ' . implode(', ', $params)];
} | php | private function buildAuthorizationHeader(array $params)
{
foreach ($params as $key => $value) {
$params[$key] = $key . '="' . rawurlencode($value) . '"';
}
if (isset($this->config['realm'])) {
array_unshift(
$params,
'realm="' . rawurlencode($this->config['realm']) . '"'
);
}
return ['Authorization', 'OAuth ' . implode(', ', $params)];
} | [
"private",
"function",
"buildAuthorizationHeader",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
".",
"'=\"'",
".",
"rawurle... | Builds the Authorization header for a request
@param array $params Associative array of authorization parameters.
@return array | [
"Builds",
"the",
"Authorization",
"header",
"for",
"a",
"request"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L289-L303 |
guzzle/oauth-subscriber | src/Oauth1.php | Oauth1.getOauthParams | private function getOauthParams($nonce, array $config)
{
$params = [
'oauth_consumer_key' => $config['consumer_key'],
'oauth_nonce' => $nonce,
'oauth_signature_method' => $config['signature_method'],
'oauth_timestamp' => time(),
];
// Optional parameters should not be set if they have not been set in
// the config as the parameter may be considered invalid by the Oauth
// service.
$optionalParams = [
'callback' => 'oauth_callback',
'token' => 'oauth_token',
'verifier' => 'oauth_verifier',
'version' => 'oauth_version'
];
foreach ($optionalParams as $optionName => $oauthName) {
if (isset($config[$optionName])) {
$params[$oauthName] = $config[$optionName];
}
}
return $params;
} | php | private function getOauthParams($nonce, array $config)
{
$params = [
'oauth_consumer_key' => $config['consumer_key'],
'oauth_nonce' => $nonce,
'oauth_signature_method' => $config['signature_method'],
'oauth_timestamp' => time(),
];
// Optional parameters should not be set if they have not been set in
// the config as the parameter may be considered invalid by the Oauth
// service.
$optionalParams = [
'callback' => 'oauth_callback',
'token' => 'oauth_token',
'verifier' => 'oauth_verifier',
'version' => 'oauth_version'
];
foreach ($optionalParams as $optionName => $oauthName) {
if (isset($config[$optionName])) {
$params[$oauthName] = $config[$optionName];
}
}
return $params;
} | [
"private",
"function",
"getOauthParams",
"(",
"$",
"nonce",
",",
"array",
"$",
"config",
")",
"{",
"$",
"params",
"=",
"[",
"'oauth_consumer_key'",
"=>",
"$",
"config",
"[",
"'consumer_key'",
"]",
",",
"'oauth_nonce'",
"=>",
"$",
"nonce",
",",
"'oauth_signat... | Get the oauth parameters as named by the oauth spec
@param string $nonce Unique nonce
@param array $config Configuration options of the plugin.
@return array | [
"Get",
"the",
"oauth",
"parameters",
"as",
"named",
"by",
"the",
"oauth",
"spec"
] | train | https://github.com/guzzle/oauth-subscriber/blob/8b2f3f924d46ac187b0d8df1ed3e96c5ccfd3d85/src/Oauth1.php#L313-L339 |
supervisorphp/supervisor | src/Exception/Fault.php | Fault.create | public static function create($faultString, $faultCode)
{
if (!isset(self::$exceptionMap[$faultCode])) {
return new self($faultString, $faultCode);
}
return new self::$exceptionMap[$faultCode]($faultString, $faultCode);
} | php | public static function create($faultString, $faultCode)
{
if (!isset(self::$exceptionMap[$faultCode])) {
return new self($faultString, $faultCode);
}
return new self::$exceptionMap[$faultCode]($faultString, $faultCode);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"faultString",
",",
"$",
"faultCode",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"exceptionMap",
"[",
"$",
"faultCode",
"]",
")",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"faultS... | Creates a new Fault.
If there is a mach for the fault code in the exception map then the matched exception will be returned
@param string $faultString
@param int $faultCode
@return self | [
"Creates",
"a",
"new",
"Fault",
"."
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/src/Exception/Fault.php#L71-L78 |
supervisorphp/supervisor | RoboFile.php | RoboFile.faults | public function faults()
{
$faultReflection = new \ReflectionClass('Supervisor\Exception\Fault');
$faults = array_flip($faultReflection->getConstants());
$this->taskCleanDir([__DIR__.'/src/Exception/Fault'])->run();
foreach ($faults as $code => $name) {
$exName = $this->createExceptionName($name);
$file = sprintf(__DIR__.'/src/Exception/Fault/%s.php', $exName);
$this->taskWriteToFile($file)
->textFromFile(__DIR__.'/resources/FaultTemplate.php')
->place('FAULT_NAME', $name)
->place('FaultName', $exName)
->run();
}
} | php | public function faults()
{
$faultReflection = new \ReflectionClass('Supervisor\Exception\Fault');
$faults = array_flip($faultReflection->getConstants());
$this->taskCleanDir([__DIR__.'/src/Exception/Fault'])->run();
foreach ($faults as $code => $name) {
$exName = $this->createExceptionName($name);
$file = sprintf(__DIR__.'/src/Exception/Fault/%s.php', $exName);
$this->taskWriteToFile($file)
->textFromFile(__DIR__.'/resources/FaultTemplate.php')
->place('FAULT_NAME', $name)
->place('FaultName', $exName)
->run();
}
} | [
"public",
"function",
"faults",
"(",
")",
"{",
"$",
"faultReflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"'Supervisor\\Exception\\Fault'",
")",
";",
"$",
"faults",
"=",
"array_flip",
"(",
"$",
"faultReflection",
"->",
"getConstants",
"(",
")",
")",
";"... | Generates fault exception classes | [
"Generates",
"fault",
"exception",
"classes"
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/RoboFile.php#L15-L32 |
supervisorphp/supervisor | RoboFile.php | RoboFile.createExceptionName | protected function createExceptionName($faultString)
{
$parts = explode('_', $faultString);
$parts = array_map(function($el) { return ucfirst(strtolower($el)); }, $parts);
return implode('', $parts);
} | php | protected function createExceptionName($faultString)
{
$parts = explode('_', $faultString);
$parts = array_map(function($el) { return ucfirst(strtolower($el)); }, $parts);
return implode('', $parts);
} | [
"protected",
"function",
"createExceptionName",
"(",
"$",
"faultString",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"faultString",
")",
";",
"$",
"parts",
"=",
"array_map",
"(",
"function",
"(",
"$",
"el",
")",
"{",
"return",
"ucfirst"... | Returns a CamelCased exception name from UNDER_SCORED fault string
@param string $faultString
@return string | [
"Returns",
"a",
"CamelCased",
"exception",
"name",
"from",
"UNDER_SCORED",
"fault",
"string"
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/RoboFile.php#L41-L48 |
supervisorphp/supervisor | src/Process.php | Process.offsetGet | public function offsetGet($offset)
{
return isset($this->payload[$offset]) ? $this->payload[$offset] : null;
} | php | public function offsetGet($offset)
{
return isset($this->payload[$offset]) ? $this->payload[$offset] : null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"payload",
"[",
"$",
"offset",
"]",
")",
"?",
"$",
"this",
"->",
"payload",
"[",
"$",
"offset",
"]",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/src/Process.php#L94-L97 |
supervisorphp/supervisor | src/Connector/XmlRpc.php | XmlRpc.call | public function call($namespace, $method, array $arguments = [])
{
try {
return $this->client->call($namespace.'.'.$method, $arguments);
} catch (ResponseException $e) {
throw Fault::create($e->getFaultString(), $e->getFaultCode());
}
} | php | public function call($namespace, $method, array $arguments = [])
{
try {
return $this->client->call($namespace.'.'.$method, $arguments);
} catch (ResponseException $e) {
throw Fault::create($e->getFaultString(), $e->getFaultCode());
}
} | [
"public",
"function",
"call",
"(",
"$",
"namespace",
",",
"$",
"method",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"call",
"(",
"$",
"namespace",
".",
"'.'",
".",
"$",
"method"... | {@inheritdoc} | [
"{"
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/src/Connector/XmlRpc.php#L33-L40 |
supervisorphp/supervisor | src/Supervisor.php | Supervisor.getAllProcesses | public function getAllProcesses()
{
$processes = $this->getAllProcessInfo();
foreach ($processes as $key => $processInfo) {
$processes[$key] = new Process($processInfo);
}
return $processes;
} | php | public function getAllProcesses()
{
$processes = $this->getAllProcessInfo();
foreach ($processes as $key => $processInfo) {
$processes[$key] = new Process($processInfo);
}
return $processes;
} | [
"public",
"function",
"getAllProcesses",
"(",
")",
"{",
"$",
"processes",
"=",
"$",
"this",
"->",
"getAllProcessInfo",
"(",
")",
";",
"foreach",
"(",
"$",
"processes",
"as",
"$",
"key",
"=>",
"$",
"processInfo",
")",
"{",
"$",
"processes",
"[",
"$",
"k... | Returns all processes as Process objects.
@return array Array of Process objects | [
"Returns",
"all",
"processes",
"as",
"Process",
"objects",
"."
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/src/Supervisor.php#L133-L142 |
supervisorphp/supervisor | src/Connector/Zend.php | Zend.call | public function call($namespace, $method, array $arguments = [])
{
try {
return $this->client->call($namespace.'.'.$method, $arguments);
} catch (FaultException $e) {
throw Fault::create($e->getMessage(), $e->getCode());
}
} | php | public function call($namespace, $method, array $arguments = [])
{
try {
return $this->client->call($namespace.'.'.$method, $arguments);
} catch (FaultException $e) {
throw Fault::create($e->getMessage(), $e->getCode());
}
} | [
"public",
"function",
"call",
"(",
"$",
"namespace",
",",
"$",
"method",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"call",
"(",
"$",
"namespace",
".",
"'.'",
".",
"$",
"method"... | {@inheritdoc} | [
"{"
] | train | https://github.com/supervisorphp/supervisor/blob/f1f42c3e86411ae929e6af88f61a59e2f95efc2b/src/Connector/Zend.php#L37-L44 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.add | public function add($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
if ('' === $password) {
return -1;
}
$db = $this->initDb();
$args = [
':password' => $password,
':created_at' => time(),
];
try {
if ($this->isBlacklisted($password)) {
$status = -1;
} else {
$this->exec($db, 'INSERT INTO rollerworks_passdbl (passwd, created_at) VALUES (:password, :created_at)', $args);
$status = true;
}
} catch (\Exception $e) {
$status = false;
}
if (!$status) {
$this->close($db);
}
return $status;
} | php | public function add($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
if ('' === $password) {
return -1;
}
$db = $this->initDb();
$args = [
':password' => $password,
':created_at' => time(),
];
try {
if ($this->isBlacklisted($password)) {
$status = -1;
} else {
$this->exec($db, 'INSERT INTO rollerworks_passdbl (passwd, created_at) VALUES (:password, :created_at)', $args);
$status = true;
}
} catch (\Exception $e) {
$status = false;
}
if (!$status) {
$this->close($db);
}
return $status;
} | [
"public",
"function",
"add",
"(",
"$",
"password",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"password",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Only scalar values are accepted.'",
")",
";",
"}",
"if",
"(",
"''",
"===... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L43-L75 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.delete | public function delete($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
$db = $this->initDb();
$args = [
':password' => $password,
];
try {
$this->exec($db, 'DELETE FROM rollerworks_passdbl WHERE passwd = :password', $args);
$status = true;
} catch (\Exception $e) {
$status = false;
}
if (!$status) {
$this->close($db);
}
return $status;
} | php | public function delete($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
$db = $this->initDb();
$args = [
':password' => $password,
];
try {
$this->exec($db, 'DELETE FROM rollerworks_passdbl WHERE passwd = :password', $args);
$status = true;
} catch (\Exception $e) {
$status = false;
}
if (!$status) {
$this->close($db);
}
return $status;
} | [
"public",
"function",
"delete",
"(",
"$",
"password",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"password",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Only scalar values are accepted.'",
")",
";",
"}",
"$",
"db",
"=",
"$... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L80-L103 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.purge | public function purge()
{
$db = $this->initDb();
$this->exec($db, 'DELETE FROM rollerworks_passdbl');
$this->close($db);
} | php | public function purge()
{
$db = $this->initDb();
$this->exec($db, 'DELETE FROM rollerworks_passdbl');
$this->close($db);
} | [
"public",
"function",
"purge",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"initDb",
"(",
")",
";",
"$",
"this",
"->",
"exec",
"(",
"$",
"db",
",",
"'DELETE FROM rollerworks_passdbl'",
")",
";",
"$",
"this",
"->",
"close",
"(",
"$",
"db",
")"... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L118-L123 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.isBlacklisted | public function isBlacklisted($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
$db = $this->initDb();
$tokenExists = $this->fetch($db, 'SELECT 1 FROM rollerworks_passdbl WHERE passwd = :password LIMIT 1', [':password' => $password]);
return !empty($tokenExists);
} | php | public function isBlacklisted($password)
{
if (!is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}
$db = $this->initDb();
$tokenExists = $this->fetch($db, 'SELECT 1 FROM rollerworks_passdbl WHERE passwd = :password LIMIT 1', [':password' => $password]);
return !empty($tokenExists);
} | [
"public",
"function",
"isBlacklisted",
"(",
"$",
"password",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"password",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Only scalar values are accepted.'",
")",
";",
"}",
"$",
"db",
"=... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L128-L138 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.fetch | protected function fetch($db, $query, array $args = [])
{
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
} | php | protected function fetch($db, $query, array $args = [])
{
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
} | [
"protected",
"function",
"fetch",
"(",
"$",
"db",
",",
"$",
"query",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"prepareStatement",
"(",
"$",
"db",
",",
"$",
"query",
")",
";",
"foreach",
"(",
"$",
... | @param object $db
@param string $query
@param array $args
@return mixed | [
"@param",
"object",
"$db",
"@param",
"string",
"$query",
"@param",
"array",
"$args"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L154-L164 |
rollerworks/PasswordStrengthValidator | src/Blacklist/PdoProvider.php | PdoProvider.exec | protected function exec($db, $query, array $args = [])
{
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$success = $stmt->execute();
if (!$success) {
throw new \RuntimeException(sprintf('Error executing query "%s".', $query));
}
} | php | protected function exec($db, $query, array $args = [])
{
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$success = $stmt->execute();
if (!$success) {
throw new \RuntimeException(sprintf('Error executing query "%s".', $query));
}
} | [
"protected",
"function",
"exec",
"(",
"$",
"db",
",",
"$",
"query",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"prepareStatement",
"(",
"$",
"db",
",",
"$",
"query",
")",
";",
"foreach",
"(",
"$",
"... | @param object $db
@param string $query
@param array $args
@throws \RuntimeException | [
"@param",
"object",
"$db",
"@param",
"string",
"$query",
"@param",
"array",
"$args"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/PdoProvider.php#L173-L185 |
rollerworks/PasswordStrengthValidator | src/P0wnedPassword/Request/Client.php | Client.check | public function check($password)
{
$hashedPassword = strtoupper(sha1($password));
$checkHash = substr($hashedPassword, 0, 5);
try {
$response = $this->client->sendRequest(new Request('GET', 'https://api.pwnedpasswords.com/range/'.$checkHash));
if ($response->getStatusCode() === 200) {
$rowResults = explode("\n", (string) $response->getBody());
$searchHash = substr($hashedPassword, 5);
foreach ($rowResults as $result) {
if (strpos($result, $searchHash) !== false) {
$res = explode(':', $result);
return new Result(trim($res[1]));
}
}
}
} catch (HttpException $exception) {
$this->logger->error('HTTP Exception: '.$exception->getMessage());
} catch (HttpException2 $exception) {
$this->logger->error('HTTP Exception: '.$exception->getMessage());
} catch (\Exception $exception) {
$this->logger->error('Exception: '.$exception->getMessage());
}
return new Result(0);
} | php | public function check($password)
{
$hashedPassword = strtoupper(sha1($password));
$checkHash = substr($hashedPassword, 0, 5);
try {
$response = $this->client->sendRequest(new Request('GET', 'https://api.pwnedpasswords.com/range/'.$checkHash));
if ($response->getStatusCode() === 200) {
$rowResults = explode("\n", (string) $response->getBody());
$searchHash = substr($hashedPassword, 5);
foreach ($rowResults as $result) {
if (strpos($result, $searchHash) !== false) {
$res = explode(':', $result);
return new Result(trim($res[1]));
}
}
}
} catch (HttpException $exception) {
$this->logger->error('HTTP Exception: '.$exception->getMessage());
} catch (HttpException2 $exception) {
$this->logger->error('HTTP Exception: '.$exception->getMessage());
} catch (\Exception $exception) {
$this->logger->error('Exception: '.$exception->getMessage());
}
return new Result(0);
} | [
"public",
"function",
"check",
"(",
"$",
"password",
")",
"{",
"$",
"hashedPassword",
"=",
"strtoupper",
"(",
"sha1",
"(",
"$",
"password",
")",
")",
";",
"$",
"checkHash",
"=",
"substr",
"(",
"$",
"hashedPassword",
",",
"0",
",",
"5",
")",
";",
"try... | @param $password
@return Result
@throws \Http\Client\Exception | [
"@param",
"$password"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/P0wnedPassword/Request/Client.php#L41-L68 |
rollerworks/PasswordStrengthValidator | src/Blacklist/ChainProvider.php | ChainProvider.addProvider | public function addProvider(BlacklistProviderInterface $provider)
{
if ($provider === $this) {
throw new \RuntimeException('Unable to add ChainProvider to itself.');
}
$this->providers[] = $provider;
return $this;
} | php | public function addProvider(BlacklistProviderInterface $provider)
{
if ($provider === $this) {
throw new \RuntimeException('Unable to add ChainProvider to itself.');
}
$this->providers[] = $provider;
return $this;
} | [
"public",
"function",
"addProvider",
"(",
"BlacklistProviderInterface",
"$",
"provider",
")",
"{",
"if",
"(",
"$",
"provider",
"===",
"$",
"this",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to add ChainProvider to itself.'",
")",
";",
"}",
... | Adds a new blacklist provider.
@param BlacklistProviderInterface $provider
@throws \RuntimeException
@return self | [
"Adds",
"a",
"new",
"blacklist",
"provider",
"."
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/ChainProvider.php#L47-L56 |
rollerworks/PasswordStrengthValidator | src/Blacklist/ChainProvider.php | ChainProvider.isBlacklisted | public function isBlacklisted($password)
{
foreach ($this->providers as $provider) {
if (true === $provider->isBlacklisted($password)) {
return true;
}
}
return false;
} | php | public function isBlacklisted($password)
{
foreach ($this->providers as $provider) {
if (true === $provider->isBlacklisted($password)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isBlacklisted",
"(",
"$",
"password",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"providers",
"as",
"$",
"provider",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"provider",
"->",
"isBlacklisted",
"(",
"$",
"password",
")",
")",
"{... | Runs trough all the providers until one returns true.
{@inheritdoc} | [
"Runs",
"trough",
"all",
"the",
"providers",
"until",
"one",
"returns",
"true",
"."
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/ChainProvider.php#L73-L82 |
rollerworks/PasswordStrengthValidator | src/Validator/Constraints/P0wnedPasswordValidator.php | P0wnedPasswordValidator.validate | public function validate($password, Constraint $constraint)
{
if (null === $password) {
return;
}
if (!is_scalar($password) && !(is_object($password) && method_exists($password, '__toString'))) {
throw new UnexpectedTypeException($password, 'string');
}
$password = (string) $password;
$result = $this->client->check($password);
if ($result->wasFound()) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ used }}', number_format($result->getUseCount()))
->addViolation();
}
} | php | public function validate($password, Constraint $constraint)
{
if (null === $password) {
return;
}
if (!is_scalar($password) && !(is_object($password) && method_exists($password, '__toString'))) {
throw new UnexpectedTypeException($password, 'string');
}
$password = (string) $password;
$result = $this->client->check($password);
if ($result->wasFound()) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ used }}', number_format($result->getUseCount()))
->addViolation();
}
} | [
"public",
"function",
"validate",
"(",
"$",
"password",
",",
"Constraint",
"$",
"constraint",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"password",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"password",
")",
"&&",
"!",
"(",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Validator/Constraints/P0wnedPasswordValidator.php#L37-L56 |
rollerworks/PasswordStrengthValidator | src/Command/BlacklistPurgeCommand.php | BlacklistPurgeCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$input->getOption('no-ask')) {
$io->warning('This will remove all the passwords from your blacklist.');
if (!$io->confirm('Are you sure you want to purge the blacklist?', false)) {
return 1;
}
}
$this->blacklistProvider->purge();
$io->success('Successfully removed all passwords from your blacklist.');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$input->getOption('no-ask')) {
$io->warning('This will remove all the passwords from your blacklist.');
if (!$io->confirm('Are you sure you want to purge the blacklist?', false)) {
return 1;
}
}
$this->blacklistProvider->purge();
$io->success('Successfully removed all passwords from your blacklist.');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"if",
"(",
"!",
"$",
"input",
"->",
"getOp... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Command/BlacklistPurgeCommand.php#L36-L51 |
rollerworks/PasswordStrengthValidator | src/Blacklist/SqliteProvider.php | SqliteProvider.all | public function all()
{
$db = $this->initDb();
if ($db instanceof \SQLite3) {
return $this->fetch($db, 'SELECT passwd FROM rollerworks_passdbl');
}
return $this->exec($db, 'SELECT passwd FROM rollerworks_passdbl');
} | php | public function all()
{
$db = $this->initDb();
if ($db instanceof \SQLite3) {
return $this->fetch($db, 'SELECT passwd FROM rollerworks_passdbl');
}
return $this->exec($db, 'SELECT passwd FROM rollerworks_passdbl');
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"initDb",
"(",
")",
";",
"if",
"(",
"$",
"db",
"instanceof",
"\\",
"SQLite3",
")",
"{",
"return",
"$",
"this",
"->",
"fetch",
"(",
"$",
"db",
",",
"'SELECT passwd FROM r... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/SqliteProvider.php#L25-L34 |
rollerworks/PasswordStrengthValidator | src/Blacklist/SqliteProvider.php | SqliteProvider.initDb | protected function initDb()
{
if (null === $this->db || $this->db instanceof \SQLite3) {
if (0 !== strpos($this->dsn, 'sqlite')) {
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Sqlite with an invalid dsn "%s". The expected format is "sqlite:/path/to/the/db/file".', $this->dsn));
}
if (class_exists('SQLite3')) {
$db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE);
$db->busyTimeout(1000);
} elseif (class_exists('PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) {
$db = new \PDO($this->dsn);
} else {
throw new \RuntimeException('You need to enable either the SQLite3 or PDO_SQLite extension for the profiler to run properly.');
}
$db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
$db->exec('CREATE TABLE IF NOT EXISTS rollerworks_passdbl (passwd STRING, created_at INTEGER)');
$db->exec('CREATE UNIQUE INDEX IF NOT EXISTS passwd_idx ON rollerworks_passdbl (passwd)');
$this->db = $db;
}
return $this->db;
} | php | protected function initDb()
{
if (null === $this->db || $this->db instanceof \SQLite3) {
if (0 !== strpos($this->dsn, 'sqlite')) {
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Sqlite with an invalid dsn "%s". The expected format is "sqlite:/path/to/the/db/file".', $this->dsn));
}
if (class_exists('SQLite3')) {
$db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE);
$db->busyTimeout(1000);
} elseif (class_exists('PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) {
$db = new \PDO($this->dsn);
} else {
throw new \RuntimeException('You need to enable either the SQLite3 or PDO_SQLite extension for the profiler to run properly.');
}
$db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
$db->exec('CREATE TABLE IF NOT EXISTS rollerworks_passdbl (passwd STRING, created_at INTEGER)');
$db->exec('CREATE UNIQUE INDEX IF NOT EXISTS passwd_idx ON rollerworks_passdbl (passwd)');
$this->db = $db;
}
return $this->db;
} | [
"protected",
"function",
"initDb",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"db",
"||",
"$",
"this",
"->",
"db",
"instanceof",
"\\",
"SQLite3",
")",
"{",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"this",
"->",
"dsn",
",",
"'sq... | {@inheritdoc}
@throws \RuntimeException When neither of SQLite3 or PDO_SQLite extension is enabled | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/SqliteProvider.php#L52-L75 |
rollerworks/PasswordStrengthValidator | src/Blacklist/SqliteProvider.php | SqliteProvider.exec | protected function exec($db, $query, array $args = [])
{
if ($db instanceof \SQLite3) {
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
}
$res = $stmt->execute();
if (false === $res) {
throw new \RuntimeException(sprintf('Error executing SQLite query "%s".', $query));
}
$res->finalize();
} else {
parent::exec($db, $query, $args);
}
} | php | protected function exec($db, $query, array $args = [])
{
if ($db instanceof \SQLite3) {
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
}
$res = $stmt->execute();
if (false === $res) {
throw new \RuntimeException(sprintf('Error executing SQLite query "%s".', $query));
}
$res->finalize();
} else {
parent::exec($db, $query, $args);
}
} | [
"protected",
"function",
"exec",
"(",
"$",
"db",
",",
"$",
"query",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"db",
"instanceof",
"\\",
"SQLite3",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"prepareStatement",
"(",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/SqliteProvider.php#L80-L96 |
rollerworks/PasswordStrengthValidator | src/Blacklist/SqliteProvider.php | SqliteProvider.fetch | protected function fetch($db, $query, array $args = [])
{
$return = [];
if ($db instanceof \SQLite3) {
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
}
$res = $stmt->execute();
while ($row = $res->fetchArray(\SQLITE3_ASSOC)) {
$return[] = $row;
}
$res->finalize();
$stmt->close();
} else {
$return = parent::fetch($db, $query, $args);
}
return $return;
} | php | protected function fetch($db, $query, array $args = [])
{
$return = [];
if ($db instanceof \SQLite3) {
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
}
$res = $stmt->execute();
while ($row = $res->fetchArray(\SQLITE3_ASSOC)) {
$return[] = $row;
}
$res->finalize();
$stmt->close();
} else {
$return = parent::fetch($db, $query, $args);
}
return $return;
} | [
"protected",
"function",
"fetch",
"(",
"$",
"db",
",",
"$",
"query",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"db",
"instanceof",
"\\",
"SQLite3",
")",
"{",
"$",
"stmt",
"=",
"$",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/rollerworks/PasswordStrengthValidator/blob/428a7bf3e74fcb50fb7225a3f4b451ae2e61d864/src/Blacklist/SqliteProvider.php#L101-L121 |
yiisoft/yii2-mongodb | src/console/controllers/MigrateController.php | MigrateController.createMigration | protected function createMigration($class)
{
// since Yii 2.0.12 includeMigrationFile() exists, which replaced the code below
// remove this construct when composer requirement raises above 2.0.12
if (method_exists($this, 'includeMigrationFile')) {
$this->includeMigrationFile($class);
} else {
$class = trim($class, '\\');
if (strpos($class, '\\') === false) {
$file = $this->migrationPath . DIRECTORY_SEPARATOR . $class . '.php';
require_once($file);
}
}
return new $class(['db' => $this->db, 'compact' => isset($this->compact) ? $this->compact : false]);
} | php | protected function createMigration($class)
{
// since Yii 2.0.12 includeMigrationFile() exists, which replaced the code below
// remove this construct when composer requirement raises above 2.0.12
if (method_exists($this, 'includeMigrationFile')) {
$this->includeMigrationFile($class);
} else {
$class = trim($class, '\\');
if (strpos($class, '\\') === false) {
$file = $this->migrationPath . DIRECTORY_SEPARATOR . $class . '.php';
require_once($file);
}
}
return new $class(['db' => $this->db, 'compact' => isset($this->compact) ? $this->compact : false]);
} | [
"protected",
"function",
"createMigration",
"(",
"$",
"class",
")",
"{",
"// since Yii 2.0.12 includeMigrationFile() exists, which replaced the code below",
"// remove this construct when composer requirement raises above 2.0.12",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
... | Creates a new migration instance.
@param string $class the migration class name
@return \yii\mongodb\Migration the migration instance | [
"Creates",
"a",
"new",
"migration",
"instance",
"."
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/console/controllers/MigrateController.php#L130-L145 |
yiisoft/yii2-mongodb | src/console/controllers/MigrateController.php | MigrateController.ensureBaseMigrationHistory | protected function ensureBaseMigrationHistory()
{
if (!$this->baseMigrationEnsured) {
$query = new Query;
$row = $query->select(['version'])
->from($this->migrationCollection)
->andWhere(['version' => self::BASE_MIGRATION])
->limit(1)
->one($this->db);
if (empty($row)) {
$this->addMigrationHistory(self::BASE_MIGRATION);
}
$this->baseMigrationEnsured = true;
}
} | php | protected function ensureBaseMigrationHistory()
{
if (!$this->baseMigrationEnsured) {
$query = new Query;
$row = $query->select(['version'])
->from($this->migrationCollection)
->andWhere(['version' => self::BASE_MIGRATION])
->limit(1)
->one($this->db);
if (empty($row)) {
$this->addMigrationHistory(self::BASE_MIGRATION);
}
$this->baseMigrationEnsured = true;
}
} | [
"protected",
"function",
"ensureBaseMigrationHistory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"baseMigrationEnsured",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
";",
"$",
"row",
"=",
"$",
"query",
"->",
"select",
"(",
"[",
"'version'",
"]",
... | Ensures migration history contains at least base migration entry. | [
"Ensures",
"migration",
"history",
"contains",
"at",
"least",
"base",
"migration",
"entry",
"."
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/console/controllers/MigrateController.php#L206-L220 |
yiisoft/yii2-mongodb | src/console/controllers/MigrateController.php | MigrateController.addMigrationHistory | protected function addMigrationHistory($version)
{
$this->db->getCollection($this->migrationCollection)->insert([
'version' => $version,
'apply_time' => time(),
]);
} | php | protected function addMigrationHistory($version)
{
$this->db->getCollection($this->migrationCollection)->insert([
'version' => $version,
'apply_time' => time(),
]);
} | [
"protected",
"function",
"addMigrationHistory",
"(",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"getCollection",
"(",
"$",
"this",
"->",
"migrationCollection",
")",
"->",
"insert",
"(",
"[",
"'version'",
"=>",
"$",
"version",
",",
"'apply_time'... | {@inheritdoc} | [
"{"
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/console/controllers/MigrateController.php#L225-L231 |
yiisoft/yii2-mongodb | src/console/controllers/MigrateController.php | MigrateController.truncateDatabase | protected function truncateDatabase()
{
$collections = $this->db->getDatabase()->createCommand()->listCollections();
foreach ($collections as $collection) {
if (in_array($collection['name'], ['system.roles', 'system.users', 'system.indexes'])) {
// prevent deleting database auth data
// access to 'system.indexes' is more likely to be restricted, thus indexes will be dropped manually per collection
$this->stdout("System collection {$collection['name']} skipped.\n");
continue;
}
if (in_array($collection['name'], ['system.profile', 'system.js'])) {
// dropping of system collection is unlikely to be permitted, attempt to clear them out instead
$this->db->getDatabase()->createCommand()->delete($collection['name'], []);
$this->stdout("System collection {$collection['name']} truncated.\n");
continue;
}
$this->db->getDatabase()->createCommand()->dropIndexes($collection['name'], '*');
$this->db->getDatabase()->dropCollection($collection['name']);
$this->stdout("Collection {$collection['name']} dropped.\n");
}
} | php | protected function truncateDatabase()
{
$collections = $this->db->getDatabase()->createCommand()->listCollections();
foreach ($collections as $collection) {
if (in_array($collection['name'], ['system.roles', 'system.users', 'system.indexes'])) {
// prevent deleting database auth data
// access to 'system.indexes' is more likely to be restricted, thus indexes will be dropped manually per collection
$this->stdout("System collection {$collection['name']} skipped.\n");
continue;
}
if (in_array($collection['name'], ['system.profile', 'system.js'])) {
// dropping of system collection is unlikely to be permitted, attempt to clear them out instead
$this->db->getDatabase()->createCommand()->delete($collection['name'], []);
$this->stdout("System collection {$collection['name']} truncated.\n");
continue;
}
$this->db->getDatabase()->createCommand()->dropIndexes($collection['name'], '*');
$this->db->getDatabase()->dropCollection($collection['name']);
$this->stdout("Collection {$collection['name']} dropped.\n");
}
} | [
"protected",
"function",
"truncateDatabase",
"(",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"db",
"->",
"getDatabase",
"(",
")",
"->",
"createCommand",
"(",
")",
"->",
"listCollections",
"(",
")",
";",
"foreach",
"(",
"$",
"collections",
"as",
... | {@inheritdoc}
@since 2.1.5 | [
"{"
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/console/controllers/MigrateController.php#L247-L270 |
yiisoft/yii2-mongodb | src/Collection.php | Collection.dropIndexes | public function dropIndexes($indexes)
{
$result = $this->database->createCommand()->dropIndexes($this->name, $indexes);
return $result['nIndexesWas'];
} | php | public function dropIndexes($indexes)
{
$result = $this->database->createCommand()->dropIndexes($this->name, $indexes);
return $result['nIndexesWas'];
} | [
"public",
"function",
"dropIndexes",
"(",
"$",
"indexes",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"database",
"->",
"createCommand",
"(",
")",
"->",
"dropIndexes",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"indexes",
")",
";",
"return",
"$",
... | Drops collection indexes by name.
@param string $indexes wildcard for name of the indexes to be dropped.
You can use `*` to drop all indexes.
@return int count of dropped indexes. | [
"Drops",
"collection",
"indexes",
"by",
"name",
"."
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L124-L128 |
yiisoft/yii2-mongodb | src/Collection.php | Collection.createIndex | public function createIndex($columns, $options = [])
{
$index = array_merge(['key' => $columns], $options);
return $this->database->createCommand()->createIndexes($this->name, [$index]);
} | php | public function createIndex($columns, $options = [])
{
$index = array_merge(['key' => $columns], $options);
return $this->database->createCommand()->createIndexes($this->name, [$index]);
} | [
"public",
"function",
"createIndex",
"(",
"$",
"columns",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"index",
"=",
"array_merge",
"(",
"[",
"'key'",
"=>",
"$",
"columns",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"dat... | Creates an index on the collection and the specified fields.
@param array|string $columns column name or list of column names.
If array is given, each element in the array has as key the field name, and as
value either 1 for ascending sort, or -1 for descending sort.
You can specify field using native numeric key with the field name as a value,
in this case ascending sort will be used.
For example:
```php
[
'name',
'status' => -1,
]
```
@param array $options list of options in format: optionName => optionValue.
@throws Exception on failure.
@return bool whether the operation successful. | [
"Creates",
"an",
"index",
"on",
"the",
"collection",
"and",
"the",
"specified",
"fields",
".",
"@param",
"array|string",
"$columns",
"column",
"name",
"or",
"list",
"of",
"column",
"names",
".",
"If",
"array",
"is",
"given",
"each",
"element",
"in",
"the",
... | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L150-L154 |
yiisoft/yii2-mongodb | src/Collection.php | Collection.dropIndex | public function dropIndex($columns)
{
$existingIndexes = $this->listIndexes();
$indexKey = $this->database->connection->getQueryBuilder()->buildSortFields($columns);
foreach ($existingIndexes as $index) {
if ($index['key'] == $indexKey) {
$this->database->createCommand()->dropIndexes($this->name, $index['name']);
return true;
}
}
// Index plugin usage such as 'text' may cause unpredictable index 'key' structure, thus index name should be used
$indexName = $this->database->connection->getQueryBuilder()->generateIndexName($indexKey);
foreach ($existingIndexes as $index) {
if ($index['name'] === $indexName) {
$this->database->createCommand()->dropIndexes($this->name, $index['name']);
return true;
}
}
throw new Exception('Index to be dropped does not exist.');
} | php | public function dropIndex($columns)
{
$existingIndexes = $this->listIndexes();
$indexKey = $this->database->connection->getQueryBuilder()->buildSortFields($columns);
foreach ($existingIndexes as $index) {
if ($index['key'] == $indexKey) {
$this->database->createCommand()->dropIndexes($this->name, $index['name']);
return true;
}
}
// Index plugin usage such as 'text' may cause unpredictable index 'key' structure, thus index name should be used
$indexName = $this->database->connection->getQueryBuilder()->generateIndexName($indexKey);
foreach ($existingIndexes as $index) {
if ($index['name'] === $indexName) {
$this->database->createCommand()->dropIndexes($this->name, $index['name']);
return true;
}
}
throw new Exception('Index to be dropped does not exist.');
} | [
"public",
"function",
"dropIndex",
"(",
"$",
"columns",
")",
"{",
"$",
"existingIndexes",
"=",
"$",
"this",
"->",
"listIndexes",
"(",
")",
";",
"$",
"indexKey",
"=",
"$",
"this",
"->",
"database",
"->",
"connection",
"->",
"getQueryBuilder",
"(",
")",
"-... | Drop indexes for specified column(s).
@param string|array $columns column name or list of column names.
If array is given, each element in the array has as key the field name, and as
value either 1 for ascending sort, or -1 for descending sort.
Use value 'text' to specify text index.
You can specify field using native numeric key with the field name as a value,
in this case ascending sort will be used.
For example:
```php
[
'name',
'status' => -1,
'description' => 'text',
]
```
@throws Exception on failure.
@return bool whether the operation successful. | [
"Drop",
"indexes",
"for",
"specified",
"column",
"(",
"s",
")",
".",
"@param",
"string|array",
"$columns",
"column",
"name",
"or",
"list",
"of",
"column",
"names",
".",
"If",
"array",
"is",
"given",
"each",
"element",
"in",
"the",
"array",
"has",
"as",
"... | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L177-L199 |
yiisoft/yii2-mongodb | src/Collection.php | Collection.find | public function find($condition = [], $fields = [], $options = [])
{
if (!empty($fields)) {
$options['projection'] = $fields;
}
return $this->database->createCommand()->find($this->name, $condition, $options);
} | php | public function find($condition = [], $fields = [], $options = [])
{
if (!empty($fields)) {
$options['projection'] = $fields;
}
return $this->database->createCommand()->find($this->name, $condition, $options);
} | [
"public",
"function",
"find",
"(",
"$",
"condition",
"=",
"[",
"]",
",",
"$",
"fields",
"=",
"[",
"]",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"options",
"[",
"'projection'"... | Returns a cursor for the search results.
In order to perform "find" queries use [[Query]] class.
@param array $condition query condition
@param array $fields fields to be selected
@param array $options query options (available since 2.1).
@return \MongoDB\Driver\Cursor cursor for the search results
@see Query | [
"Returns",
"a",
"cursor",
"for",
"the",
"search",
"results",
".",
"In",
"order",
"to",
"perform",
"find",
"queries",
"use",
"[[",
"Query",
"]]",
"class",
"."
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L221-L227 |
yiisoft/yii2-mongodb | src/Collection.php | Collection.findOne | public function findOne($condition = [], $fields = [], $options = [])
{
$options['limit'] = 1;
$cursor = $this->find($condition, $fields, $options);
$rows = $cursor->toArray();
return empty($rows) ? null : current($rows);
} | php | public function findOne($condition = [], $fields = [], $options = [])
{
$options['limit'] = 1;
$cursor = $this->find($condition, $fields, $options);
$rows = $cursor->toArray();
return empty($rows) ? null : current($rows);
} | [
"public",
"function",
"findOne",
"(",
"$",
"condition",
"=",
"[",
"]",
",",
"$",
"fields",
"=",
"[",
"]",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"[",
"'limit'",
"]",
"=",
"1",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
... | Returns a single document.
@param array $condition query condition
@param array $fields fields to be selected
@param array $options query options (available since 2.1).
@return array|null the single document. Null is returned if the query results in nothing. | [
"Returns",
"a",
"single",
"document",
"."
] | train | https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L236-L242 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.