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 |
|---|---|---|---|---|---|---|---|---|---|---|
paragonie/sapient | src/Traits/StringSugar.php | StringSugar.unsealStringResponse | public function unsealStringResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): string {
$body = Base64UrlSafe::decode((string) $response->getBody());
return Simple::unseal(
$body,
$secretKey
);
} | php | public function unsealStringResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): string {
$body = Base64UrlSafe::decode((string) $response->getBody());
return Simple::unseal(
$body,
$secretKey
);
} | [
"public",
"function",
"unsealStringResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"string",
"{",
"$",
"body",
"=",
"Base64UrlSafe",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"get... | Decrypt a message with your secret key, that had been encrypted with
your public key by the other endpoint, then get the body as a string.
@param ResponseInterface $response
@param SealingSecretKey $secretKey
@return string
@throws InvalidMessageException | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"that",
"had",
"been",
"encrypted",
"with",
"your",
"public",
"key",
"by",
"the",
"other",
"endpoint",
"then",
"get",
"the",
"body",
"as",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/StringSugar.php#L110-L119 |
paragonie/sapient | src/Traits/StringSugar.php | StringSugar.verifySymmetricAuthenticatedStringRequest | public function verifySymmetricAuthenticatedStringRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): string {
$verified = $this->verifySymmetricAuthenticatedRequest($request, $key);
return (string) $verified->getBody();
} | php | public function verifySymmetricAuthenticatedStringRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): string {
$verified = $this->verifySymmetricAuthenticatedRequest($request, $key);
return (string) $verified->getBody();
} | [
"public",
"function",
"verifySymmetricAuthenticatedStringRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"string",
"{",
"$",
"verified",
"=",
"$",
"this",
"->",
"verifySymmetricAuthenticatedRequest",
"(",
"$",
"... | Verify the Body-HMAC-SHA512256 header, and then return the body as
a string.
@param RequestInterface $request
@param SharedAuthenticationKey $key
@return string | [
"Verify",
"the",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"header",
"and",
"then",
"return",
"the",
"body",
"as",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/StringSugar.php#L129-L135 |
paragonie/sapient | src/Traits/StringSugar.php | StringSugar.verifySymmetricAuthenticatedStringResponse | public function verifySymmetricAuthenticatedStringResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): string {
$verified = $this->verifySymmetricAuthenticatedResponse($response, $key);
return (string) $verified->getBody();
} | php | public function verifySymmetricAuthenticatedStringResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): string {
$verified = $this->verifySymmetricAuthenticatedResponse($response, $key);
return (string) $verified->getBody();
} | [
"public",
"function",
"verifySymmetricAuthenticatedStringResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"string",
"{",
"$",
"verified",
"=",
"$",
"this",
"->",
"verifySymmetricAuthenticatedResponse",
"(",
"$",... | Verify the Body-HMAC-SHA512256 header, and then return the body as
a string.
@param ResponseInterface $response
@param SharedAuthenticationKey $key
@return string | [
"Verify",
"the",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"header",
"and",
"then",
"return",
"the",
"body",
"as",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/StringSugar.php#L145-L151 |
paragonie/sapient | src/Traits/StringSugar.php | StringSugar.verifySignedStringRequest | public function verifySignedStringRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): string {
$verified = $this->verifySignedRequest($request, $publicKey);
return (string) $verified->getBody();
} | php | public function verifySignedStringRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): string {
$verified = $this->verifySignedRequest($request, $publicKey);
return (string) $verified->getBody();
} | [
"public",
"function",
"verifySignedStringRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"string",
"{",
"$",
"verified",
"=",
"$",
"this",
"->",
"verifySignedRequest",
"(",
"$",
"request",
",",
"$",
"public... | Verify the Body-Signature-Ed25519 header, and then return the body as
a string.
@param RequestInterface $request
@param SigningPublicKey $publicKey
@return string | [
"Verify",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"and",
"then",
"return",
"the",
"body",
"as",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/StringSugar.php#L161-L167 |
paragonie/sapient | src/Traits/StringSugar.php | StringSugar.verifySignedStringResponse | public function verifySignedStringResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): string {
$verified = $this->verifySignedResponse($response, $publicKey);
return (string) $verified->getBody();
} | php | public function verifySignedStringResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): string {
$verified = $this->verifySignedResponse($response, $publicKey);
return (string) $verified->getBody();
} | [
"public",
"function",
"verifySignedStringResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"string",
"{",
"$",
"verified",
"=",
"$",
"this",
"->",
"verifySignedResponse",
"(",
"$",
"response",
",",
"$",
"p... | Verify the Body-Signature-Ed25519 header, and then return the body as
a string.
@param ResponseInterface $response
@param SigningPublicKey $publicKey
@return string | [
"Verify",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"and",
"then",
"return",
"the",
"body",
"as",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/StringSugar.php#L177-L183 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricAuthenticatedJsonRequest | public function createSymmetricAuthenticatedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricAuthenticatedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | public function createSymmetricAuthenticatedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricAuthenticatedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | [
"public",
"function",
"createSymmetricAuthenticatedJsonRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"array",
"$",
"arrayToJsonify",
",",
"SharedAuthenticationKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"R... | Create an HTTP request object with a JSON body that is authenticated
with a pre-shared key. The authentication tag is stored in a
Body-HMAC-SHA512256 header.
@param string $method
@param string $uri
@param array $arrayToJsonify
@param SharedAuthenticationKey $key
@param array $headers
@return RequestInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"request",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"authenticated",
"with",
"a",
"pre",
"-",
"shared",
"key",
".",
"The",
"authentication",
"tag",
"is",
"stored",
"in",
"a",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"hea... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L65-L84 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricAuthenticatedJsonResponse | public function createSymmetricAuthenticatedJsonResponse(
int $status,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricAuthenticatedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | public function createSymmetricAuthenticatedJsonResponse(
int $status,
array $arrayToJsonify,
SharedAuthenticationKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricAuthenticatedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | [
"public",
"function",
"createSymmetricAuthenticatedJsonResponse",
"(",
"int",
"$",
"status",
",",
"array",
"$",
"arrayToJsonify",
",",
"SharedAuthenticationKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'"... | Create an HTTP response object with a JSON body that is authenticated
with a pre-shared key. The authentication tag is stored in a
Body-HMAC-SHA512256 header.
@param int $status
@param array $arrayToJsonify
@param SharedAuthenticationKey $key
@param array $headers
@param string $version
@return ResponseInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"response",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"authenticated",
"with",
"a",
"pre",
"-",
"shared",
"key",
".",
"The",
"authentication",
"tag",
"is",
"stored",
"in",
"a",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"he... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L99-L118 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricEncryptedJsonRequest | public function createSymmetricEncryptedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricEncryptedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | public function createSymmetricEncryptedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricEncryptedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | [
"public",
"function",
"createSymmetricEncryptedJsonRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"array",
"$",
"arrayToJsonify",
",",
"SharedEncryptionKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestIn... | Create an HTTP request object with a JSON body that is encrypted
with a pre-shared key.
@param string $method
@param string $uri
@param array $arrayToJsonify
@param SharedEncryptionKey $key
@param array $headers
@return RequestInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"request",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"encrypted",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L132-L151 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricEncryptedJsonResponse | public function createSymmetricEncryptedJsonResponse(
int $status,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricEncryptedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | public function createSymmetricEncryptedJsonResponse(
int $status,
array $arrayToJsonify,
SharedEncryptionKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSymmetricEncryptedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | [
"public",
"function",
"createSymmetricEncryptedJsonResponse",
"(",
"int",
"$",
"status",
",",
"array",
"$",
"arrayToJsonify",
",",
"SharedEncryptionKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",... | Create an HTTP response object with a JSON body that is encrypted
with a pre-shared key.
@param int $status
@param array $arrayToJsonify
@param SharedEncryptionKey $key
@param array $headers
@param string $version
@return ResponseInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"response",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"encrypted",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L165-L184 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSealedJsonRequest | public function createSealedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSealedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | public function createSealedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSealedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | [
"public",
"function",
"createSealedJsonRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"array",
"$",
"arrayToJsonify",
",",
"SealingPublicKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestInterface",
"{"... | Create an HTTP request object with a JSON body that is encrypted
with the server's public key.
@param string $method
@param string $uri
@param array $arrayToJsonify
@param SealingPublicKey $key
@param array $headers
@return RequestInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"request",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"encrypted",
"with",
"the",
"server",
"s",
"public",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L198-L217 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSealedJsonResponse | public function createSealedJsonResponse(
int $status,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSealedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | public function createSealedJsonResponse(
int $status,
array $arrayToJsonify,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSealedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | [
"public",
"function",
"createSealedJsonResponse",
"(",
"int",
"$",
"status",
",",
"array",
"$",
"arrayToJsonify",
",",
"SealingPublicKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",
":",
"Resp... | Create an HTTP response object with a JSON body that is encrypted
with the server's public key.
@param int $status
@param array $arrayToJsonify
@param SealingPublicKey $key
@param array $headers
@param string $version
@return ResponseInterface
@throws InvalidMessageException | [
"Create",
"an",
"HTTP",
"response",
"object",
"with",
"a",
"JSON",
"body",
"that",
"is",
"encrypted",
"with",
"the",
"server",
"s",
"public",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L231-L250 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSignedJsonRequest | public function createSignedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSignedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | php | public function createSignedJsonRequest(
string $method,
string $uri,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = []
): RequestInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSignedRequest(
$method,
$uri,
$body,
$key,
$headers
);
} | [
"public",
"function",
"createSignedJsonRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"array",
"$",
"arrayToJsonify",
",",
"SigningSecretKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestInterface",
"{"... | Creates a JSON-signed API request to be sent to an API.
Enforces hard-coded Ed25519 keys.
@param string $method
@param string $uri
@param array $arrayToJsonify
@param SigningSecretKey $key
@param array $headers
@return RequestInterface
@throws InvalidMessageException | [
"Creates",
"a",
"JSON",
"-",
"signed",
"API",
"request",
"to",
"be",
"sent",
"to",
"an",
"API",
".",
"Enforces",
"hard",
"-",
"coded",
"Ed25519",
"keys",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L264-L283 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSignedJsonResponse | public function createSignedJsonResponse(
int $status,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSignedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | php | public function createSignedJsonResponse(
int $status,
array $arrayToJsonify,
SigningSecretKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
list ($body, $headers) = $this->makeJSON($arrayToJsonify, $headers);
if (!\is_string($body)) {
throw new InvalidMessageException('Cannot JSON-encode this message.');
}
/** @var array $headers */
return $this->createSignedResponse(
$status,
$body,
$key,
$headers,
$version
);
} | [
"public",
"function",
"createSignedJsonResponse",
"(",
"int",
"$",
"status",
",",
"array",
"$",
"arrayToJsonify",
",",
"SigningSecretKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",
":",
"Resp... | Creates a JSON-signed API response to be returned from an API.
Enforces hard-coded Ed25519 keys.
@param int $status
@param array $arrayToJsonify
@param SigningSecretKey $key
@param array $headers
@param string $version
@return ResponseInterface
@throws InvalidMessageException | [
"Creates",
"a",
"JSON",
"-",
"signed",
"API",
"response",
"to",
"be",
"returned",
"from",
"an",
"API",
".",
"Enforces",
"hard",
"-",
"coded",
"Ed25519",
"keys",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L297-L316 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricAuthenticatedRequest | public function createSymmetricAuthenticatedRequest(
string $method,
string $uri,
string $body,
SharedAuthenticationKey $key,
array $headers = []
): RequestInterface {
/** @var array<string, array<int|string, string>> $headers */
$mac = \ParagonIE_Sodium_Compat::crypto_auth($body, $key->getString(true));
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_AUTH_NAME][] = Base64UrlSafe::encode($mac);
} else {
$headers[Sapient::HEADER_AUTH_NAME] = Base64UrlSafe::encode($mac);
}
return new Request(
$method,
$uri,
$headers,
$body
);
} | php | public function createSymmetricAuthenticatedRequest(
string $method,
string $uri,
string $body,
SharedAuthenticationKey $key,
array $headers = []
): RequestInterface {
/** @var array<string, array<int|string, string>> $headers */
$mac = \ParagonIE_Sodium_Compat::crypto_auth($body, $key->getString(true));
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_AUTH_NAME][] = Base64UrlSafe::encode($mac);
} else {
$headers[Sapient::HEADER_AUTH_NAME] = Base64UrlSafe::encode($mac);
}
return new Request(
$method,
$uri,
$headers,
$body
);
} | [
"public",
"function",
"createSymmetricAuthenticatedRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"string",
"$",
"body",
",",
"SharedAuthenticationKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestInterfa... | Authenticate your HTTP request with a pre-shared key.
@param string $method
@param string $uri
@param string $body
@param SharedAuthenticationKey $key
@param array $headers
@return RequestInterface | [
"Authenticate",
"your",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L328-L348 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricAuthenticatedResponse | public function createSymmetricAuthenticatedResponse(
int $status,
string $body,
SharedAuthenticationKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
/** @var array<string, array> $headers */
$mac = \ParagonIE_Sodium_Compat::crypto_auth($body, $key->getString(true));
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_AUTH_NAME][] = Base64UrlSafe::encode($mac);
} else {
$headers[Sapient::HEADER_AUTH_NAME] = Base64UrlSafe::encode($mac);
}
return new Response(
$status,
$headers,
$body,
$version
);
} | php | public function createSymmetricAuthenticatedResponse(
int $status,
string $body,
SharedAuthenticationKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
/** @var array<string, array> $headers */
$mac = \ParagonIE_Sodium_Compat::crypto_auth($body, $key->getString(true));
if (isset($headers[Sapient::HEADER_SIGNATURE_NAME])) {
$headers[Sapient::HEADER_AUTH_NAME][] = Base64UrlSafe::encode($mac);
} else {
$headers[Sapient::HEADER_AUTH_NAME] = Base64UrlSafe::encode($mac);
}
return new Response(
$status,
$headers,
$body,
$version
);
} | [
"public",
"function",
"createSymmetricAuthenticatedResponse",
"(",
"int",
"$",
"status",
",",
"string",
"$",
"body",
",",
"SharedAuthenticationKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",
":... | Authenticate your HTTP response with a pre-shared key.
@param int $status
@param string $body
@param SharedAuthenticationKey $key
@param array $headers
@param string $version
@return ResponseInterface | [
"Authenticate",
"your",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L360-L380 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricEncryptedRequest | public function createSymmetricEncryptedRequest(
string $method,
string $uri,
string $body,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
return new Request(
$method,
$uri,
$headers,
Base64UrlSafe::encode(Simple::encrypt($body, $key))
);
} | php | public function createSymmetricEncryptedRequest(
string $method,
string $uri,
string $body,
SharedEncryptionKey $key,
array $headers = []
): RequestInterface {
return new Request(
$method,
$uri,
$headers,
Base64UrlSafe::encode(Simple::encrypt($body, $key))
);
} | [
"public",
"function",
"createSymmetricEncryptedRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"string",
"$",
"body",
",",
"SharedEncryptionKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestInterface",
"... | Encrypt your HTTP request with a pre-shared key.
@param string $method
@param string $uri
@param string $body
@param SharedEncryptionKey $key
@param array $headers
@return RequestInterface | [
"Encrypt",
"your",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L392-L405 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSymmetricEncryptedResponse | public function createSymmetricEncryptedResponse(
int $status,
string $body,
SharedEncryptionKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
return new Response(
$status,
$headers,
Base64UrlSafe::encode(Simple::encrypt($body, $key)),
$version
);
} | php | public function createSymmetricEncryptedResponse(
int $status,
string $body,
SharedEncryptionKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
return new Response(
$status,
$headers,
Base64UrlSafe::encode(Simple::encrypt($body, $key)),
$version
);
} | [
"public",
"function",
"createSymmetricEncryptedResponse",
"(",
"int",
"$",
"status",
",",
"string",
"$",
"body",
",",
"SharedEncryptionKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",
":",
"Re... | Encrypt your HTTP response with a pre-shared key.
@param int $status
@param string $body
@param SharedEncryptionKey $key
@param array $headers
@param string $version
@return ResponseInterface | [
"Encrypt",
"your",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L417-L430 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSealedRequest | public function createSealedRequest(
string $method,
string $uri,
string $body,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
$sealed = Simple::seal(
$body,
$key
);
return new Request(
$method,
$uri,
$headers,
Base64UrlSafe::encode($sealed)
);
} | php | public function createSealedRequest(
string $method,
string $uri,
string $body,
SealingPublicKey $key,
array $headers = []
): RequestInterface {
$sealed = Simple::seal(
$body,
$key
);
return new Request(
$method,
$uri,
$headers,
Base64UrlSafe::encode($sealed)
);
} | [
"public",
"function",
"createSealedRequest",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"uri",
",",
"string",
"$",
"body",
",",
"SealingPublicKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"RequestInterface",
"{",
"$",
"s... | Encrypt your HTTP request with the server's public key, so that only
the server can decrypt the message.
@param string $method
@param string $uri
@param string $body
@param SealingPublicKey $key
@param array $headers
@return RequestInterface | [
"Encrypt",
"your",
"HTTP",
"request",
"with",
"the",
"server",
"s",
"public",
"key",
"so",
"that",
"only",
"the",
"server",
"can",
"decrypt",
"the",
"message",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L443-L460 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.createSealedResponse | public function createSealedResponse(
int $status,
string $body,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
$sealed = Simple::seal(
$body,
$key
);
return new Response(
$status,
$headers,
Base64UrlSafe::encode($sealed),
$version
);
} | php | public function createSealedResponse(
int $status,
string $body,
SealingPublicKey $key,
array $headers = [],
string $version = '1.1'
): ResponseInterface {
$sealed = Simple::seal(
$body,
$key
);
return new Response(
$status,
$headers,
Base64UrlSafe::encode($sealed),
$version
);
} | [
"public",
"function",
"createSealedResponse",
"(",
"int",
"$",
"status",
",",
"string",
"$",
"body",
",",
"SealingPublicKey",
"$",
"key",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"string",
"$",
"version",
"=",
"'1.1'",
")",
":",
"ResponseInterface... | Encrypt your HTTP response with the client's public key, so that only
the client can decrypt the message.
@param int $status
@param string $body
@param SealingPublicKey $key
@param array $headers
@param string $version
@return ResponseInterface | [
"Encrypt",
"your",
"HTTP",
"response",
"with",
"the",
"client",
"s",
"public",
"key",
"so",
"that",
"only",
"the",
"client",
"can",
"decrypt",
"the",
"message",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L473-L490 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.stringToStream | public function stringToStream(string $input): StreamInterface
{
/** @var StreamInterface|null $stream */
$stream = stream_for($input);
if (!($stream instanceof StreamInterface)) {
throw new \TypeError('Could not convert string to a stream');
}
return $stream;
} | php | public function stringToStream(string $input): StreamInterface
{
/** @var StreamInterface|null $stream */
$stream = stream_for($input);
if (!($stream instanceof StreamInterface)) {
throw new \TypeError('Could not convert string to a stream');
}
return $stream;
} | [
"public",
"function",
"stringToStream",
"(",
"string",
"$",
"input",
")",
":",
"StreamInterface",
"{",
"/** @var StreamInterface|null $stream */",
"$",
"stream",
"=",
"stream_for",
"(",
"$",
"input",
")",
";",
"if",
"(",
"!",
"(",
"$",
"stream",
"instanceof",
... | Adapter-specific way of converting a string into a StreamInterface
@param string $input
@return StreamInterface
@throws \TypeError | [
"Adapter",
"-",
"specific",
"way",
"of",
"converting",
"a",
"string",
"into",
"a",
"StreamInterface"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L586-L594 |
paragonie/sapient | src/Adapter/Guzzle.php | Guzzle.makeJSON | protected function makeJSON(array $arrayToJsonify, array $headers): array
{
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
return [$body, $headers];
} | php | protected function makeJSON(array $arrayToJsonify, array $headers): array
{
if (empty($headers['Content-Type'])) {
$headers['Content-Type'] = 'application/json';
}
/** @var string $body */
$body = \json_encode($arrayToJsonify, JSON_PRETTY_PRINT);
return [$body, $headers];
} | [
"protected",
"function",
"makeJSON",
"(",
"array",
"$",
"arrayToJsonify",
",",
"array",
"$",
"headers",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"headers",
"[",
"'Content-Type'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"'Content-Type'",
"]"... | JSON encode body, add Content-Type header.
@param array $arrayToJsonify
@param array $headers
@return array | [
"JSON",
"encode",
"body",
"add",
"Content",
"-",
"Type",
"header",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Guzzle.php#L603-L611 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.getSize | public function getSize()
{
if (!$this->size && $this->isAttached() === true) {
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
$stats = \fstat($this->stream);
/** @var int|null size */
$this->size = isset($stats['size']) && !$this->isPipe() ? (int) $stats['size'] : null;
}
return $this->size;
} | php | public function getSize()
{
if (!$this->size && $this->isAttached() === true) {
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
$stats = \fstat($this->stream);
/** @var int|null size */
$this->size = isset($stats['size']) && !$this->isPipe() ? (int) $stats['size'] : null;
}
return $this->size;
} | [
"public",
"function",
"getSize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"size",
"&&",
"$",
"this",
"->",
"isAttached",
"(",
")",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
... | Get the size of the stream if known.
@return int|null Returns the size in bytes if known, or null if unknown.
@throws \TypeError | [
"Get",
"the",
"size",
"of",
"the",
"stream",
"if",
"known",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L242-L254 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.tell | public function tell()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isAttached() || ($position = \ftell($this->stream)) === false || $this->isPipe()) {
throw new \RuntimeException('Could not get the position of the pointer in stream');
}
if (!isset($position)) {
$position = 0;
}
return (int) $position;
} | php | public function tell()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isAttached() || ($position = \ftell($this->stream)) === false || $this->isPipe()) {
throw new \RuntimeException('Could not get the position of the pointer in stream');
}
if (!isset($position)) {
$position = 0;
}
return (int) $position;
} | [
"public",
"function",
"tell",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isAttached",
"(",
")",
... | Returns the current position of the file read/write pointer
@return int Position of the file pointer
@throws \RuntimeException on error.
@throws \TypeError | [
"Returns",
"the",
"current",
"position",
"of",
"the",
"file",
"read",
"/",
"write",
"pointer"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L264-L277 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.eof | public function eof()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
return $this->isAttached() ? \feof($this->stream) : true;
} | php | public function eof()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
return $this->isAttached() ? \feof($this->stream) : true;
} | [
"public",
"function",
"eof",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"isAttached",
"(",
")",
"?",
"\\... | Returns true if the stream is at the end of the stream.
@return bool
@throws \TypeError | [
"Returns",
"true",
"if",
"the",
"stream",
"is",
"at",
"the",
"end",
"of",
"the",
"stream",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L285-L291 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.rewind | public function rewind()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isSeekable() || \rewind($this->stream) === false) {
throw new \RuntimeException('Could not rewind stream');
}
} | php | public function rewind()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isSeekable() || \rewind($this->stream) === false) {
throw new \RuntimeException('Could not rewind stream');
}
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isSeekable",
"(",
")",... | Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception;
otherwise, it will perform a seek(0).
@see seek()
@link http://www.php.net/manual/en/function.fseek.php
@return void
@throws \RuntimeException on failure.
@throws \TypeError | [
"Seek",
"to",
"the",
"beginning",
"of",
"the",
"stream",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L407-L415 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.read | public function read($length)
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isReadable() || ($data = \fread($this->stream, $length)) === false) {
throw new \RuntimeException('Could not read from stream');
}
if (!isset($data)) {
$data = '';
}
return (string) $data;
} | php | public function read($length)
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isReadable() || ($data = \fread($this->stream, $length)) === false) {
throw new \RuntimeException('Could not read from stream');
}
if (!isset($data)) {
$data = '';
}
return (string) $data;
} | [
"public",
"function",
"read",
"(",
"$",
"length",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isReadabl... | Read data from the stream.
@param int $length Read up to $length bytes from the object and return
them. Fewer than $length bytes may be returned if underlying stream
call returns fewer bytes.
@return string Returns the data read from the stream, or an empty string
if no bytes are available.
@throws \RuntimeException if an error occurs.
@throws \TypeError | [
"Read",
"data",
"from",
"the",
"stream",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L430-L443 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.write | public function write($string)
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isWritable() || ($written = \fwrite($this->stream, $string)) === false) {
throw new \RuntimeException('Could not write to stream');
}
if (!isset($written)) {
$written = 0;
}
// reset size so that it will be recalculated on next call to getSize()
$this->size = null;
return (int) $written;
} | php | public function write($string)
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isWritable() || ($written = \fwrite($this->stream, $string)) === false) {
throw new \RuntimeException('Could not write to stream');
}
if (!isset($written)) {
$written = 0;
}
// reset size so that it will be recalculated on next call to getSize()
$this->size = null;
return (int) $written;
} | [
"public",
"function",
"write",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isWritab... | Write data to the stream.
@param string $string The string that is to be written.
@return int Returns the number of bytes written to the stream.
@throws \RuntimeException on failure.
@throws \TypeError | [
"Write",
"data",
"to",
"the",
"stream",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L455-L471 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.getContents | public function getContents()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isReadable() || ($contents = \stream_get_contents($this->stream)) === false) {
throw new \RuntimeException('Could not get contents of stream');
}
if (!isset($contents)) {
$contents = '';
}
return (string) $contents;
} | php | public function getContents()
{
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
if (!$this->isReadable() || ($contents = \stream_get_contents($this->stream)) === false) {
throw new \RuntimeException('Could not get contents of stream');
}
if (!isset($contents)) {
$contents = '';
}
return (string) $contents;
} | [
"public",
"function",
"getContents",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"throw",
"new",
"\\",
"TypeError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isReadable",
"(",
... | Returns the remaining contents in a string
@return string
@throws \RuntimeException if unable to read or an error occurs while
reading.
@throws \TypeError | [
"Returns",
"the",
"remaining",
"contents",
"in",
"a",
"string"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L482-L495 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.isPipe | public function isPipe()
{
if ($this->isPipe === null) {
$this->isPipe = false;
if ($this->isAttached()) {
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
$mode = (int) \fstat($this->stream)['mode'];
$this->isPipe = ($mode & self::FSTAT_MODE_S_IFIFO) !== 0;
}
}
return $this->isPipe;
} | php | public function isPipe()
{
if ($this->isPipe === null) {
$this->isPipe = false;
if ($this->isAttached()) {
if (!\is_resource($this->stream)) {
throw new \TypeError();
}
$mode = (int) \fstat($this->stream)['mode'];
$this->isPipe = ($mode & self::FSTAT_MODE_S_IFIFO) !== 0;
}
}
return $this->isPipe;
} | [
"public",
"function",
"isPipe",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPipe",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"isPipe",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isAttached",
"(",
")",
")",
"{",
"if",
"(",
"!",
"\\"... | Returns whether or not the stream is a pipe.
@return bool
@throws \TypeError | [
"Returns",
"whether",
"or",
"not",
"the",
"stream",
"is",
"a",
"pipe",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L503-L517 |
paragonie/sapient | src/Adapter/Generic/Stream.php | Stream.fromString | public static function fromString(string $input): StreamInterface
{
/** @var resource $stream */
$stream = \fopen('php://temp', 'w+');
if (!\is_resource($stream)) {
throw new \Error('Could not create stream');
}
\fwrite($stream, $input);
\rewind($stream);
return new static($stream);
} | php | public static function fromString(string $input): StreamInterface
{
/** @var resource $stream */
$stream = \fopen('php://temp', 'w+');
if (!\is_resource($stream)) {
throw new \Error('Could not create stream');
}
\fwrite($stream, $input);
\rewind($stream);
return new static($stream);
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"input",
")",
":",
"StreamInterface",
"{",
"/** @var resource $stream */",
"$",
"stream",
"=",
"\\",
"fopen",
"(",
"'php://temp'",
",",
"'w+'",
")",
";",
"if",
"(",
"!",
"\\",
"is_resource",
"... | Create a Stream object from a string.
@param string $input
@return StreamInterface
@throws \Error | [
"Create",
"a",
"Stream",
"object",
"from",
"a",
"string",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Adapter/Generic/Stream.php#L526-L536 |
paragonie/sapient | src/Simple.php | Simple.encrypt | public static function encrypt(
string $plaintext,
SharedEncryptionKey $key
): string {
$nonce = random_bytes(\ParagonIE_Sodium_Compat::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
return $nonce .
\ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
$plaintext,
$nonce,
$nonce,
$key->getString(true)
);
} | php | public static function encrypt(
string $plaintext,
SharedEncryptionKey $key
): string {
$nonce = random_bytes(\ParagonIE_Sodium_Compat::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
return $nonce .
\ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
$plaintext,
$nonce,
$nonce,
$key->getString(true)
);
} | [
"public",
"static",
"function",
"encrypt",
"(",
"string",
"$",
"plaintext",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"string",
"{",
"$",
"nonce",
"=",
"random_bytes",
"(",
"\\",
"ParagonIE_Sodium_Compat",
"::",
"CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES",
... | Simple authenticated encryption
XChaCha20-Poly1305
@param string $plaintext
@param SharedEncryptionKey $key
@return string | [
"Simple",
"authenticated",
"encryption",
"XChaCha20",
"-",
"Poly1305"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Simple.php#L26-L38 |
paragonie/sapient | src/Simple.php | Simple.decrypt | public static function decrypt(
string $ciphertext,
SharedEncryptionKey $key
): string {
$nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
$result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
\ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
$nonce,
$nonce,
$key->getString(true)
);
if (!\is_string($result)) {
throw new InvalidMessageException('Message authentication failed.');
}
return $result;
} | php | public static function decrypt(
string $ciphertext,
SharedEncryptionKey $key
): string {
$nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
$result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
\ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
$nonce,
$nonce,
$key->getString(true)
);
if (!\is_string($result)) {
throw new InvalidMessageException('Message authentication failed.');
}
return $result;
} | [
"public",
"static",
"function",
"decrypt",
"(",
"string",
"$",
"ciphertext",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"string",
"{",
"$",
"nonce",
"=",
"\\",
"ParagonIE_Sodium_Core_Util",
"::",
"substr",
"(",
"$",
"ciphertext",
",",
"0",
",",
"24",
... | Simple authenticated decryption
XChaCha20-Poly1305
@param string $ciphertext
@param SharedEncryptionKey $key
@return string
@throws InvalidMessageException | [
"Simple",
"authenticated",
"decryption",
"XChaCha20",
"-",
"Poly1305"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Simple.php#L49-L64 |
paragonie/sapient | src/Simple.php | Simple.keyExchange | public static function keyExchange(
SealingSecretKey $secretKey,
SealingPublicKey $publicKey,
bool $serverSide,
int $outputLength = 32
): string {
if ($serverSide) {
$suffix = $publicKey->getString(true) .
$secretKey->getPublickey()->getString(true);
} else {
$suffix = $secretKey->getPublickey()->getString(true) .
$publicKey->getString(true);
}
return \ParagonIE_Sodium_Compat::crypto_generichash(
\ParagonIE_Sodium_Compat::crypto_scalarmult(
$secretKey->getString(true),
$publicKey->getString(true)
) . $suffix,
'',
$outputLength
);
} | php | public static function keyExchange(
SealingSecretKey $secretKey,
SealingPublicKey $publicKey,
bool $serverSide,
int $outputLength = 32
): string {
if ($serverSide) {
$suffix = $publicKey->getString(true) .
$secretKey->getPublickey()->getString(true);
} else {
$suffix = $secretKey->getPublickey()->getString(true) .
$publicKey->getString(true);
}
return \ParagonIE_Sodium_Compat::crypto_generichash(
\ParagonIE_Sodium_Compat::crypto_scalarmult(
$secretKey->getString(true),
$publicKey->getString(true)
) . $suffix,
'',
$outputLength
);
} | [
"public",
"static",
"function",
"keyExchange",
"(",
"SealingSecretKey",
"$",
"secretKey",
",",
"SealingPublicKey",
"$",
"publicKey",
",",
"bool",
"$",
"serverSide",
",",
"int",
"$",
"outputLength",
"=",
"32",
")",
":",
"string",
"{",
"if",
"(",
"$",
"serverS... | Like libsodium's crypto_kx() but supports an arbitrary output length
in the range (16 <= N <= 64).
@param SealingSecretKey $secretKey
@param SealingPublicKey $publicKey
@param bool $serverSide
@param int $outputLength
@return string | [
"Like",
"libsodium",
"s",
"crypto_kx",
"()",
"but",
"supports",
"an",
"arbitrary",
"output",
"length",
"in",
"the",
"range",
"(",
"16",
"<",
"=",
"N",
"<",
"=",
"64",
")",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Simple.php#L76-L97 |
paragonie/sapient | src/Simple.php | Simple.seal | public static function seal(
string $plaintext,
SealingPublicKey $publicKey
): string {
$ephemeralSecret = SealingSecretKey::generate();
$sharedSecret = static::keyExchange(
$ephemeralSecret,
$publicKey,
false,
56
);
$ephemeralPublicKey = $ephemeralSecret->getPublickey()->getString(true);
$sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
$nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
try {
\ParagonIE_Sodium_Compat::memzero($sharedSecret);
} catch (\Throwable $ex) {
}
return $ephemeralPublicKey. \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
$plaintext,
$ephemeralPublicKey,
$nonce,
$sharedKey
);
} | php | public static function seal(
string $plaintext,
SealingPublicKey $publicKey
): string {
$ephemeralSecret = SealingSecretKey::generate();
$sharedSecret = static::keyExchange(
$ephemeralSecret,
$publicKey,
false,
56
);
$ephemeralPublicKey = $ephemeralSecret->getPublickey()->getString(true);
$sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
$nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
try {
\ParagonIE_Sodium_Compat::memzero($sharedSecret);
} catch (\Throwable $ex) {
}
return $ephemeralPublicKey. \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
$plaintext,
$ephemeralPublicKey,
$nonce,
$sharedKey
);
} | [
"public",
"static",
"function",
"seal",
"(",
"string",
"$",
"plaintext",
",",
"SealingPublicKey",
"$",
"publicKey",
")",
":",
"string",
"{",
"$",
"ephemeralSecret",
"=",
"SealingSecretKey",
"::",
"generate",
"(",
")",
";",
"$",
"sharedSecret",
"=",
"static",
... | Encrypt a message with a public key, so that it can only be decrypted
with the corresponding secret key.
@param string $plaintext
@param SealingPublicKey $publicKey
@return string | [
"Encrypt",
"a",
"message",
"with",
"a",
"public",
"key",
"so",
"that",
"it",
"can",
"only",
"be",
"decrypted",
"with",
"the",
"corresponding",
"secret",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Simple.php#L107-L132 |
paragonie/sapient | src/Simple.php | Simple.unseal | public static function unseal(
string $ciphertext,
SealingSecretKey $secretKey
): string {
$ephemeralPublicKey = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 32);
$sharedSecret = static::keyExchange(
$secretKey,
new SealingPublicKey($ephemeralPublicKey),
true,
56
);
$sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
$nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
try {
\ParagonIE_Sodium_Compat::memzero($sharedSecret);
} catch (\Throwable $ex) {
}
$plaintext = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
\ParagonIE_Sodium_Core_Util::substr($ciphertext, 32),
$ephemeralPublicKey,
$nonce,
$sharedKey
);
if (!\is_string($plaintext)) {
throw new InvalidMessageException('Incorrect message authentication tag');
}
return $plaintext;
} | php | public static function unseal(
string $ciphertext,
SealingSecretKey $secretKey
): string {
$ephemeralPublicKey = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 32);
$sharedSecret = static::keyExchange(
$secretKey,
new SealingPublicKey($ephemeralPublicKey),
true,
56
);
$sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
$nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
try {
\ParagonIE_Sodium_Compat::memzero($sharedSecret);
} catch (\Throwable $ex) {
}
$plaintext = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
\ParagonIE_Sodium_Core_Util::substr($ciphertext, 32),
$ephemeralPublicKey,
$nonce,
$sharedKey
);
if (!\is_string($plaintext)) {
throw new InvalidMessageException('Incorrect message authentication tag');
}
return $plaintext;
} | [
"public",
"static",
"function",
"unseal",
"(",
"string",
"$",
"ciphertext",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"string",
"{",
"$",
"ephemeralPublicKey",
"=",
"\\",
"ParagonIE_Sodium_Core_Util",
"::",
"substr",
"(",
"$",
"ciphertext",
",",
"0",
... | Decrypt a message with your secret key.
@param string $ciphertext
@param SealingSecretKey $secretKey
@return string
@throws InvalidMessageException | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Simple.php#L142-L171 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decodeSymmetricAuthenticatedJsonRequest | public function decodeSymmetricAuthenticatedJsonRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySymmetricAuthenticatedStringRequest($request, $key),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decodeSymmetricAuthenticatedJsonRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySymmetricAuthenticatedStringRequest($request, $key),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decodeSymmetricAuthenticatedJsonRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->... | @param RequestInterface $request
@param SharedAuthenticationKey $key
@return array
@throws InvalidMessageException | [
"@param",
"RequestInterface",
"$request",
"@param",
"SharedAuthenticationKey",
"$key"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L52-L65 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decodeSymmetricAuthenticatedJsonResponse | public function decodeSymmetricAuthenticatedJsonResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySymmetricAuthenticatedStringResponse($response, $key),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decodeSymmetricAuthenticatedJsonResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySymmetricAuthenticatedStringResponse($response, $key),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decodeSymmetricAuthenticatedJsonResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
... | @param ResponseInterface $response
@param SharedAuthenticationKey $key
@return array
@throws InvalidMessageException | [
"@param",
"ResponseInterface",
"$response",
"@param",
"SharedAuthenticationKey",
"$key"
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L74-L87 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decodeSignedJsonRequest | public function decodeSignedJsonRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySignedStringRequest($request, $publicKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decodeSignedJsonRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySignedStringRequest($request, $publicKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decodeSignedJsonRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"verifySigne... | Verify the Body-Signature-Ed25519 header, and then decode the HTTP
Request body into an array (assuming the body is a valid JSON string).
@param RequestInterface $request
@param SigningPublicKey $publicKey
@return array
@throws InvalidMessageException | [
"Verify",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"and",
"then",
"decode",
"the",
"HTTP",
"Request",
"body",
"into",
"an",
"array",
"(",
"assuming",
"the",
"body",
"is",
"a",
"valid",
"JSON",
"string",
")",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L98-L111 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decodeSignedJsonResponse | public function decodeSignedJsonResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySignedStringResponse($response, $publicKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decodeSignedJsonResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->verifySignedStringResponse($response, $publicKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decodeSignedJsonResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"verifySi... | Verify the Body-Signature-Ed25519 header, and then decode the HTTP
Response body into an array (assuming the body is a valid JSON string).
@param ResponseInterface $response
@param SigningPublicKey $publicKey
@return array
@throws InvalidMessageException | [
"Verify",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"and",
"then",
"decode",
"the",
"HTTP",
"Response",
"body",
"into",
"an",
"array",
"(",
"assuming",
"the",
"body",
"is",
"a",
"valid",
"JSON",
"string",
")",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L123-L136 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decryptJsonRequestWithSharedKey | public function decryptJsonRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): array {
$decrypted = $this->decryptRequestWithSharedKey(
$request,
$key
);
/** @var array|bool $array */
$array = \json_decode(
(string) $decrypted->getBody(),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decryptJsonRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): array {
$decrypted = $this->decryptRequestWithSharedKey(
$request,
$key
);
/** @var array|bool $array */
$array = \json_decode(
(string) $decrypted->getBody(),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decryptJsonRequestWithSharedKey",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"array",
"{",
"$",
"decrypted",
"=",
"$",
"this",
"->",
"decryptRequestWithSharedKey",
"(",
"$",
"request",
",",
"$"... | Decrypt an HTTP request with a pre-shared key, then decode into an
array (assuming the body is a valid JSON string).
@param RequestInterface $request
@param SharedEncryptionKey $key
@return array
@throws InvalidMessageException | [
"Decrypt",
"an",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"then",
"decode",
"into",
"an",
"array",
"(",
"assuming",
"the",
"body",
"is",
"a",
"valid",
"JSON",
"string",
")",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L148-L166 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.decryptJsonResponseWithSharedKey | public function decryptJsonResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): array {
$decrypted = $this->decryptResponseWithSharedKey(
$response,
$key
);
/** @var array|bool $array */
$array = \json_decode(
(string) $decrypted->getBody(),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function decryptJsonResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): array {
$decrypted = $this->decryptResponseWithSharedKey(
$response,
$key
);
/** @var array|bool $array */
$array = \json_decode(
(string) $decrypted->getBody(),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"decryptJsonResponseWithSharedKey",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"array",
"{",
"$",
"decrypted",
"=",
"$",
"this",
"->",
"decryptResponseWithSharedKey",
"(",
"$",
"response",
",",
... | Decrypt an HTTP response with a pre-shared key, then decode into an
array (assuming the body is a valid JSON string).
@param ResponseInterface $response
@param SharedEncryptionKey $key
@return array
@throws InvalidMessageException | [
"Decrypt",
"an",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"then",
"decode",
"into",
"an",
"array",
"(",
"assuming",
"the",
"body",
"is",
"a",
"valid",
"JSON",
"string",
")",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L178-L196 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.unsealJsonRequest | public function unsealJsonRequest(
RequestInterface $request,
SealingSecretKey $secretKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->unsealStringRequest($request, $secretKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function unsealJsonRequest(
RequestInterface $request,
SealingSecretKey $secretKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->unsealStringRequest($request, $secretKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"unsealJsonRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"unsealStringReque... | Decrypt a message with your secret key, that had been encrypted with
your public key by the other endpoint, then decode into an array.
@param RequestInterface $request
@param SealingSecretKey $secretKey
@return array | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"that",
"had",
"been",
"encrypted",
"with",
"your",
"public",
"key",
"by",
"the",
"other",
"endpoint",
"then",
"decode",
"into",
"an",
"array",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L206-L219 |
paragonie/sapient | src/Traits/JsonSugar.php | JsonSugar.unsealJsonResponse | public function unsealJsonResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->unsealStringResponse($response, $secretKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | php | public function unsealJsonResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): array {
/** @var array|bool $array */
$array = \json_decode(
$this->unsealStringResponse($response, $secretKey),
true
);
if (!\is_array($array)) {
throw new InvalidMessageException('Could not decode JSON');
}
return $array;
} | [
"public",
"function",
"unsealJsonResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"array",
"{",
"/** @var array|bool $array */",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"unsealStringRe... | Decrypt a message with your secret key, that had been encrypted with
your public key by the other endpoint, then decode into an array.
@param ResponseInterface $response
@param SealingSecretKey $secretKey
@return array
@throws InvalidMessageException | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"that",
"had",
"been",
"encrypted",
"with",
"your",
"public",
"key",
"by",
"the",
"other",
"endpoint",
"then",
"decode",
"into",
"an",
"array",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Traits/JsonSugar.php#L230-L243 |
paragonie/sapient | src/Sapient.php | Sapient.authenticateRequestWithSharedKey | public function authenticateRequestWithSharedKey(
RequestInterface $request,
SharedAuthenticationKey $key
): RequestInterface {
$mac = \ParagonIE_Sodium_Compat::crypto_auth(
(string) $request->getBody(),
$key->getString(true)
);
return $request->withAddedHeader(
self::HEADER_AUTH_NAME,
Base64UrlSafe::encode($mac)
);
} | php | public function authenticateRequestWithSharedKey(
RequestInterface $request,
SharedAuthenticationKey $key
): RequestInterface {
$mac = \ParagonIE_Sodium_Compat::crypto_auth(
(string) $request->getBody(),
$key->getString(true)
);
return $request->withAddedHeader(
self::HEADER_AUTH_NAME,
Base64UrlSafe::encode($mac)
);
} | [
"public",
"function",
"authenticateRequestWithSharedKey",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"RequestInterface",
"{",
"$",
"mac",
"=",
"\\",
"ParagonIE_Sodium_Compat",
"::",
"crypto_auth",
"(",
"(",
"string",... | Authenticate an HTTP request with a pre-shared key.
@param RequestInterface $request
@param SharedAuthenticationKey $key
@return RequestInterface | [
"Authenticate",
"an",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L82-L94 |
paragonie/sapient | src/Sapient.php | Sapient.authenticateResponseWithSharedKey | public function authenticateResponseWithSharedKey(
ResponseInterface $response,
SharedAuthenticationKey $key
): ResponseInterface {
$mac = \ParagonIE_Sodium_Compat::crypto_auth(
(string) $response->getBody(),
$key->getString(true)
);
return $response->withAddedHeader(
self::HEADER_AUTH_NAME,
Base64UrlSafe::encode($mac)
);
} | php | public function authenticateResponseWithSharedKey(
ResponseInterface $response,
SharedAuthenticationKey $key
): ResponseInterface {
$mac = \ParagonIE_Sodium_Compat::crypto_auth(
(string) $response->getBody(),
$key->getString(true)
);
return $response->withAddedHeader(
self::HEADER_AUTH_NAME,
Base64UrlSafe::encode($mac)
);
} | [
"public",
"function",
"authenticateResponseWithSharedKey",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"ResponseInterface",
"{",
"$",
"mac",
"=",
"\\",
"ParagonIE_Sodium_Compat",
"::",
"crypto_auth",
"(",
"(",
"stri... | Authenticate an HTTP response with a pre-shared key.
@param ResponseInterface $response
@param SharedAuthenticationKey $key
@return ResponseInterface | [
"Authenticate",
"an",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L103-L115 |
paragonie/sapient | src/Sapient.php | Sapient.decryptRequestWithSharedKey | public function decryptRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): RequestInterface {
$encrypted = Base64UrlSafe::decode((string) $request->getBody());
return $request->withBody(
$this->adapter->stringToStream(
Simple::decrypt($encrypted, $key)
)
);
} | php | public function decryptRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): RequestInterface {
$encrypted = Base64UrlSafe::decode((string) $request->getBody());
return $request->withBody(
$this->adapter->stringToStream(
Simple::decrypt($encrypted, $key)
)
);
} | [
"public",
"function",
"decryptRequestWithSharedKey",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"RequestInterface",
"{",
"$",
"encrypted",
"=",
"Base64UrlSafe",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"request"... | Decrypt an HTTP request with a pre-shared key.
@param RequestInterface $request
@param SharedEncryptionKey $key
@return RequestInterface | [
"Decrypt",
"an",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L124-L134 |
paragonie/sapient | src/Sapient.php | Sapient.decryptResponseWithSharedKey | public function decryptResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): ResponseInterface {
$encrypted = Base64UrlSafe::decode((string) $response->getBody());
return $response->withBody(
$this->adapter->stringToStream(
Simple::decrypt($encrypted, $key)
)
);
} | php | public function decryptResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): ResponseInterface {
$encrypted = Base64UrlSafe::decode((string) $response->getBody());
return $response->withBody(
$this->adapter->stringToStream(
Simple::decrypt($encrypted, $key)
)
);
} | [
"public",
"function",
"decryptResponseWithSharedKey",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"ResponseInterface",
"{",
"$",
"encrypted",
"=",
"Base64UrlSafe",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"resp... | Decrypt an HTTP response with a pre-shared key.
@param ResponseInterface $response
@param SharedEncryptionKey $key
@return ResponseInterface | [
"Decrypt",
"an",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L143-L153 |
paragonie/sapient | src/Sapient.php | Sapient.encryptRequestWithSharedKey | public function encryptRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): RequestInterface {
$encrypted = Base64UrlSafe::encode(
Simple::encrypt((string) $request->getBody(), $key)
);
return $request->withBody(
$this->adapter->stringToStream($encrypted)
);
} | php | public function encryptRequestWithSharedKey(
RequestInterface $request,
SharedEncryptionKey $key
): RequestInterface {
$encrypted = Base64UrlSafe::encode(
Simple::encrypt((string) $request->getBody(), $key)
);
return $request->withBody(
$this->adapter->stringToStream($encrypted)
);
} | [
"public",
"function",
"encryptRequestWithSharedKey",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"RequestInterface",
"{",
"$",
"encrypted",
"=",
"Base64UrlSafe",
"::",
"encode",
"(",
"Simple",
"::",
"encrypt",
"(",
"(... | Encrypt an HTTP request with a pre-shared key.
@param RequestInterface $request
@param SharedEncryptionKey $key
@return RequestInterface | [
"Encrypt",
"an",
"HTTP",
"request",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L162-L172 |
paragonie/sapient | src/Sapient.php | Sapient.encryptResponseWithSharedKey | public function encryptResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): ResponseInterface {
$encrypted = Base64UrlSafe::encode(
Simple::encrypt((string) $response->getBody(), $key)
);
return $response->withBody(
$this->adapter->stringToStream($encrypted)
);
} | php | public function encryptResponseWithSharedKey(
ResponseInterface $response,
SharedEncryptionKey $key
): ResponseInterface {
$encrypted = Base64UrlSafe::encode(
Simple::encrypt((string) $response->getBody(), $key)
);
return $response->withBody(
$this->adapter->stringToStream($encrypted)
);
} | [
"public",
"function",
"encryptResponseWithSharedKey",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedEncryptionKey",
"$",
"key",
")",
":",
"ResponseInterface",
"{",
"$",
"encrypted",
"=",
"Base64UrlSafe",
"::",
"encode",
"(",
"Simple",
"::",
"encrypt",
"(",
... | Encrypt an HTTP response with a pre-shared key.
@param ResponseInterface $response
@param SharedEncryptionKey $key
@return ResponseInterface | [
"Encrypt",
"an",
"HTTP",
"response",
"with",
"a",
"pre",
"-",
"shared",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L181-L191 |
paragonie/sapient | src/Sapient.php | Sapient.sealRequest | public function sealRequest(
RequestInterface $request,
SealingPublicKey $publicKey
): RequestInterface {
$sealed = Simple::seal(
(string) $request->getBody(),
$publicKey
);
return $request->withBody(
$this->adapter->stringToStream(
Base64UrlSafe::encode($sealed)
)
);
} | php | public function sealRequest(
RequestInterface $request,
SealingPublicKey $publicKey
): RequestInterface {
$sealed = Simple::seal(
(string) $request->getBody(),
$publicKey
);
return $request->withBody(
$this->adapter->stringToStream(
Base64UrlSafe::encode($sealed)
)
);
} | [
"public",
"function",
"sealRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SealingPublicKey",
"$",
"publicKey",
")",
":",
"RequestInterface",
"{",
"$",
"sealed",
"=",
"Simple",
"::",
"seal",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"getBody",
... | Encrypt an HTTP request body with a public key.
@param RequestInterface $request
@param SealingPublicKey $publicKey
@return RequestInterface | [
"Encrypt",
"an",
"HTTP",
"request",
"body",
"with",
"a",
"public",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L208-L221 |
paragonie/sapient | src/Sapient.php | Sapient.sealResponse | public function sealResponse(
ResponseInterface $response,
SealingPublicKey $publicKey
): ResponseInterface {
$sealed = Simple::seal(
(string) $response->getBody(),
$publicKey
);
return $response->withBody(
$this->adapter->stringToStream(
Base64UrlSafe::encode($sealed)
)
);
} | php | public function sealResponse(
ResponseInterface $response,
SealingPublicKey $publicKey
): ResponseInterface {
$sealed = Simple::seal(
(string) $response->getBody(),
$publicKey
);
return $response->withBody(
$this->adapter->stringToStream(
Base64UrlSafe::encode($sealed)
)
);
} | [
"public",
"function",
"sealResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SealingPublicKey",
"$",
"publicKey",
")",
":",
"ResponseInterface",
"{",
"$",
"sealed",
"=",
"Simple",
"::",
"seal",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody... | Encrypt an HTTP response body with a public key.
@param ResponseInterface $response
@param SealingPublicKey $publicKey
@return ResponseInterface | [
"Encrypt",
"an",
"HTTP",
"response",
"body",
"with",
"a",
"public",
"key",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L230-L243 |
paragonie/sapient | src/Sapient.php | Sapient.signRequest | public function signRequest(
RequestInterface $request,
SigningSecretKey $secretKey
): RequestInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
(string) $request->getBody(),
$secretKey->getString(true)
);
return $request->withAddedHeader(
(string) static::HEADER_SIGNATURE_NAME,
Base64UrlSafe::encode($signature)
);
} | php | public function signRequest(
RequestInterface $request,
SigningSecretKey $secretKey
): RequestInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
(string) $request->getBody(),
$secretKey->getString(true)
);
return $request->withAddedHeader(
(string) static::HEADER_SIGNATURE_NAME,
Base64UrlSafe::encode($signature)
);
} | [
"public",
"function",
"signRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SigningSecretKey",
"$",
"secretKey",
")",
":",
"RequestInterface",
"{",
"$",
"signature",
"=",
"\\",
"ParagonIE_Sodium_Compat",
"::",
"crypto_sign_detached",
"(",
"(",
"string",
")",... | Add an Ed25519 signature to an HTTP request object.
@param RequestInterface $request
@param SigningSecretKey $secretKey
@return RequestInterface | [
"Add",
"an",
"Ed25519",
"signature",
"to",
"an",
"HTTP",
"request",
"object",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L252-L264 |
paragonie/sapient | src/Sapient.php | Sapient.signResponse | public function signResponse(
ResponseInterface $response,
SigningSecretKey $secretKey
): ResponseInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
(string) $response->getBody(),
$secretKey->getString(true)
);
return $response->withAddedHeader(
(string) static::HEADER_SIGNATURE_NAME,
Base64UrlSafe::encode($signature)
);
} | php | public function signResponse(
ResponseInterface $response,
SigningSecretKey $secretKey
): ResponseInterface {
$signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
(string) $response->getBody(),
$secretKey->getString(true)
);
return $response->withAddedHeader(
(string) static::HEADER_SIGNATURE_NAME,
Base64UrlSafe::encode($signature)
);
} | [
"public",
"function",
"signResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SigningSecretKey",
"$",
"secretKey",
")",
":",
"ResponseInterface",
"{",
"$",
"signature",
"=",
"\\",
"ParagonIE_Sodium_Compat",
"::",
"crypto_sign_detached",
"(",
"(",
"string",
... | Add an Ed25519 signature to an HTTP response object.
@param ResponseInterface $response
@param SigningSecretKey $secretKey
@return ResponseInterface | [
"Add",
"an",
"Ed25519",
"signature",
"to",
"an",
"HTTP",
"response",
"object",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L273-L285 |
paragonie/sapient | src/Sapient.php | Sapient.unsealRequest | public function unsealRequest(
RequestInterface $request,
SealingSecretKey $secretKey
): RequestInterface {
$body = Base64UrlSafe::decode((string) $request->getBody());
$unsealed = Simple::unseal(
$body,
$secretKey
);
return $request->withBody($this->adapter->stringToStream($unsealed));
} | php | public function unsealRequest(
RequestInterface $request,
SealingSecretKey $secretKey
): RequestInterface {
$body = Base64UrlSafe::decode((string) $request->getBody());
$unsealed = Simple::unseal(
$body,
$secretKey
);
return $request->withBody($this->adapter->stringToStream($unsealed));
} | [
"public",
"function",
"unsealRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"RequestInterface",
"{",
"$",
"body",
"=",
"Base64UrlSafe",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"get... | Decrypt a message with your secret key, that had been encrypted with
your public key by the other endpoint.
@param RequestInterface $request
@param SealingSecretKey $secretKey
@return RequestInterface
@throws InvalidMessageException | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"that",
"had",
"been",
"encrypted",
"with",
"your",
"public",
"key",
"by",
"the",
"other",
"endpoint",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L296-L306 |
paragonie/sapient | src/Sapient.php | Sapient.unsealResponse | public function unsealResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): ResponseInterface {
$body = Base64UrlSafe::decode((string) $response->getBody());
$unsealed = Simple::unseal(
$body,
$secretKey
);
return $response->withBody($this->adapter->stringToStream($unsealed));
} | php | public function unsealResponse(
ResponseInterface $response,
SealingSecretKey $secretKey
): ResponseInterface {
$body = Base64UrlSafe::decode((string) $response->getBody());
$unsealed = Simple::unseal(
$body,
$secretKey
);
return $response->withBody($this->adapter->stringToStream($unsealed));
} | [
"public",
"function",
"unsealResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SealingSecretKey",
"$",
"secretKey",
")",
":",
"ResponseInterface",
"{",
"$",
"body",
"=",
"Base64UrlSafe",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
... | Decrypt a message with your secret key, that had been encrypted with
your public key by the other endpoint.
@param ResponseInterface $response
@param SealingSecretKey $secretKey
@return ResponseInterface
@throws InvalidMessageException | [
"Decrypt",
"a",
"message",
"with",
"your",
"secret",
"key",
"that",
"had",
"been",
"encrypted",
"with",
"your",
"public",
"key",
"by",
"the",
"other",
"endpoint",
"."
] | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L317-L327 |
paragonie/sapient | src/Sapient.php | Sapient.verifySignedRequest | public function verifySignedRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): RequestInterface {
/** @var array<int, string> */
$headers = $request->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed request header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $request->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_sign_verify_detached(
Base64UrlSafe::decode($head),
$body,
$publicKey->getString(true)
);
if ($result) {
return $request;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP request');
} | php | public function verifySignedRequest(
RequestInterface $request,
SigningPublicKey $publicKey
): RequestInterface {
/** @var array<int, string> */
$headers = $request->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed request header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $request->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_sign_verify_detached(
Base64UrlSafe::decode($head),
$body,
$publicKey->getString(true)
);
if ($result) {
return $request;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP request');
} | [
"public",
"function",
"verifySignedRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"RequestInterface",
"{",
"/** @var array<int, string> */",
"$",
"headers",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"(",
"s... | Verifies the signature contained in the Body-Signature-Ed25519 header
is valid for the HTTP Request body provided. Will either return the
request given, or throw an InvalidMessageException if the signature
is invalid. Will also throw a HeaderMissingException is there is no
Body-Signature-Ed25519 header.
@param RequestInterface $request
@param SigningPublicKey $publicKey
@return RequestInterface
@throws HeaderMissingException
@throws InvalidMessageException | [
"Verifies",
"the",
"signature",
"contained",
"in",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"is",
"valid",
"for",
"the",
"HTTP",
"Request",
"body",
"provided",
".",
"Will",
"either",
"return",
"the",
"request",
"given",
"or",
"throw",
"an",... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L342-L366 |
paragonie/sapient | src/Sapient.php | Sapient.verifySignedResponse | public function verifySignedResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): ResponseInterface {
/** @var array<int, string> */
$headers = $response->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed response header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $response->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_sign_verify_detached(
Base64UrlSafe::decode($head),
$body,
$publicKey->getString(true)
);
if ($result) {
return $response;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP response');
} | php | public function verifySignedResponse(
ResponseInterface $response,
SigningPublicKey $publicKey
): ResponseInterface {
/** @var array<int, string> */
$headers = $response->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed response header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $response->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_sign_verify_detached(
Base64UrlSafe::decode($head),
$body,
$publicKey->getString(true)
);
if ($result) {
return $response;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP response');
} | [
"public",
"function",
"verifySignedResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SigningPublicKey",
"$",
"publicKey",
")",
":",
"ResponseInterface",
"{",
"/** @var array<int, string> */",
"$",
"headers",
"=",
"$",
"response",
"->",
"getHeader",
"(",
"(",... | Verifies the signature contained in the Body-Signature-Ed25519 header
is valid for the HTTP Response body provided. Will either return the
response given, or throw an InvalidMessageException if the signature
is invalid. Will also throw a HeaderMissingException is there is no
Body-Signature-Ed25519 header.
@param ResponseInterface $response
@param SigningPublicKey $publicKey
@return ResponseInterface
@throws HeaderMissingException
@throws InvalidMessageException | [
"Verifies",
"the",
"signature",
"contained",
"in",
"the",
"Body",
"-",
"Signature",
"-",
"Ed25519",
"header",
"is",
"valid",
"for",
"the",
"HTTP",
"Response",
"body",
"provided",
".",
"Will",
"either",
"return",
"the",
"response",
"given",
"or",
"throw",
"an... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L381-L405 |
paragonie/sapient | src/Sapient.php | Sapient.verifySymmetricAuthenticatedRequest | public function verifySymmetricAuthenticatedRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): RequestInterface {
/** @var array<int, string> */
$headers = $request->getHeader((string) static::HEADER_AUTH_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed request header (' . (string) static::HEADER_AUTH_NAME . ') found.'
);
}
$body = (string) $request->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_auth_verify(
Base64UrlSafe::decode($head),
$body,
$key->getString(true)
);
if ($result) {
return $request;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP request');
} | php | public function verifySymmetricAuthenticatedRequest(
RequestInterface $request,
SharedAuthenticationKey $key
): RequestInterface {
/** @var array<int, string> */
$headers = $request->getHeader((string) static::HEADER_AUTH_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed request header (' . (string) static::HEADER_AUTH_NAME . ') found.'
);
}
$body = (string) $request->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_auth_verify(
Base64UrlSafe::decode($head),
$body,
$key->getString(true)
);
if ($result) {
return $request;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP request');
} | [
"public",
"function",
"verifySymmetricAuthenticatedRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"RequestInterface",
"{",
"/** @var array<int, string> */",
"$",
"headers",
"=",
"$",
"request",
"->",
"getHeader",
... | Verify that the Body-HMAC-SHA512256 header correctly authenticates the
HTTP Request. Will either return the request given, or throw an
InvalidMessageException if the signature is invalid. Will also throw a
HeaderMissingException is there is no Body-HMAC-SHA512256 header.
@param RequestInterface $request
@param SharedAuthenticationKey $key
@return RequestInterface
@throws HeaderMissingException
@throws InvalidMessageException | [
"Verify",
"that",
"the",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"header",
"correctly",
"authenticates",
"the",
"HTTP",
"Request",
".",
"Will",
"either",
"return",
"the",
"request",
"given",
"or",
"throw",
"an",
"InvalidMessageException",
"if",
"the",
"signature"... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L420-L444 |
paragonie/sapient | src/Sapient.php | Sapient.verifySymmetricAuthenticatedResponse | public function verifySymmetricAuthenticatedResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): ResponseInterface {
/** @var array<int, string> */
$headers = $response->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed response header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $response->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_auth_verify(
Base64UrlSafe::decode($head),
$body,
$key->getString(true)
);
if ($result) {
return $response;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP response');
} | php | public function verifySymmetricAuthenticatedResponse(
ResponseInterface $response,
SharedAuthenticationKey $key
): ResponseInterface {
/** @var array<int, string> */
$headers = $response->getHeader((string) static::HEADER_SIGNATURE_NAME);
if (!$headers) {
throw new HeaderMissingException(
'No signed response header (' . (string) static::HEADER_SIGNATURE_NAME . ') found.'
);
}
$body = (string) $response->getBody();
foreach ($headers as $head) {
$result = \ParagonIE_Sodium_Compat::crypto_auth_verify(
Base64UrlSafe::decode($head),
$body,
$key->getString(true)
);
if ($result) {
return $response;
}
}
throw new InvalidMessageException('No valid signature given for this HTTP response');
} | [
"public",
"function",
"verifySymmetricAuthenticatedResponse",
"(",
"ResponseInterface",
"$",
"response",
",",
"SharedAuthenticationKey",
"$",
"key",
")",
":",
"ResponseInterface",
"{",
"/** @var array<int, string> */",
"$",
"headers",
"=",
"$",
"response",
"->",
"getHeade... | Verify that the Body-HMAC-SHA512256 header correctly authenticates the
HTTP Response. Will either return the response given, or throw an
InvalidMessageException if the signature is invalid. Will also throw a
HeaderMissingException is there is no Body-HMAC-SHA512256 header.
@param ResponseInterface $response
@param SharedAuthenticationKey $key
@return ResponseInterface
@throws HeaderMissingException
@throws InvalidMessageException | [
"Verify",
"that",
"the",
"Body",
"-",
"HMAC",
"-",
"SHA512256",
"header",
"correctly",
"authenticates",
"the",
"HTTP",
"Response",
".",
"Will",
"either",
"return",
"the",
"response",
"given",
"or",
"throw",
"an",
"InvalidMessageException",
"if",
"the",
"signatur... | train | https://github.com/paragonie/sapient/blob/8d1f560ce3adc04497efde2673157ad057898e38/src/Sapient.php#L458-L482 |
larapack/doctrine-support | src/Types/EnumType.php | EnumType.getSQLDeclaration | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$options = array_get($fieldDeclaration, 'options', []);
$optionsString = count($options) ? "'".implode("','", $options)."'" : "''";
return "ENUM({$optionsString})";
} | php | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$options = array_get($fieldDeclaration, 'options', []);
$optionsString = count($options) ? "'".implode("','", $options)."'" : "''";
return "ENUM({$optionsString})";
} | [
"public",
"function",
"getSQLDeclaration",
"(",
"array",
"$",
"fieldDeclaration",
",",
"AbstractPlatform",
"$",
"platform",
")",
"{",
"$",
"options",
"=",
"array_get",
"(",
"$",
"fieldDeclaration",
",",
"'options'",
",",
"[",
"]",
")",
";",
"$",
"optionsString... | {@inheritdoc} | [
"{"
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/Types/EnumType.php#L15-L21 |
larapack/doctrine-support | src/DoctrineSupportServiceProvider.php | DoctrineSupportServiceProvider.register | public function register()
{
// Set resolver for MySQL
Connection::resolverFor('mysql', function ($connection, $database, $prefix = '', array $config = []) {
$connection = new MySqlConnection($connection, $database, $prefix, $config);
// Add Doctrine types for better support
$this->addDoctrineTypes($connection);
return $connection;
});
} | php | public function register()
{
// Set resolver for MySQL
Connection::resolverFor('mysql', function ($connection, $database, $prefix = '', array $config = []) {
$connection = new MySqlConnection($connection, $database, $prefix, $config);
// Add Doctrine types for better support
$this->addDoctrineTypes($connection);
return $connection;
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"// Set resolver for MySQL",
"Connection",
"::",
"resolverFor",
"(",
"'mysql'",
",",
"function",
"(",
"$",
"connection",
",",
"$",
"database",
",",
"$",
"prefix",
"=",
"''",
",",
"array",
"$",
"config",
"=",
... | Register the application services. | [
"Register",
"the",
"application",
"services",
"."
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/DoctrineSupportServiceProvider.php#L27-L38 |
larapack/doctrine-support | src/DoctrineSupportServiceProvider.php | DoctrineSupportServiceProvider.addDoctrineTypes | protected function addDoctrineTypes(Connection $connection)
{
$name = $connection->getDriverName();
foreach (array_get($this->types, $name, []) as $type => $handler) {
if (!Type::hasType($type)) {
Type::addType($type, $handler);
}
$connection->getDoctrineConnection()
->getDatabasePlatform()
->registerDoctrineTypeMapping($type, $type);
}
} | php | protected function addDoctrineTypes(Connection $connection)
{
$name = $connection->getDriverName();
foreach (array_get($this->types, $name, []) as $type => $handler) {
if (!Type::hasType($type)) {
Type::addType($type, $handler);
}
$connection->getDoctrineConnection()
->getDatabasePlatform()
->registerDoctrineTypeMapping($type, $type);
}
} | [
"protected",
"function",
"addDoctrineTypes",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"name",
"=",
"$",
"connection",
"->",
"getDriverName",
"(",
")",
";",
"foreach",
"(",
"array_get",
"(",
"$",
"this",
"->",
"types",
",",
"$",
"name",
",",
"... | Add Doctrine types for the connection.
@param Connection $connection | [
"Add",
"Doctrine",
"types",
"for",
"the",
"connection",
"."
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/DoctrineSupportServiceProvider.php#L45-L58 |
larapack/doctrine-support | src/Managers/MySqlSchemaManager.php | MySqlSchemaManager.getPortableTableEnumColumnDefinition | protected function getPortableTableEnumColumnDefinition(array $tableColumn)
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$dbType = strtolower($tableColumn['type']);
$dbType = strtok($dbType, '(), ');
$type = $this->_platform->getDoctrineTypeMapping($dbType);
// In cases where not connected to a database DESCRIBE $table does not return 'Comment'
if (isset($tableColumn['comment'])) {
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
}
$options = [
'length' => null,
'unsigned' => false,
'fixed' => null,
'default' => isset($tableColumn['default']) ? $tableColumn['default'] : null,
'notnull' => (bool) ($tableColumn['null'] != 'YES'),
'scale' => null,
'precision' => null,
'autoincrement' => false,
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
];
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['collation'])) {
$column->setPlatformOption('collation', $tableColumn['collation']);
}
$column->setCustomSchemaOption('options', $this->getEnumOptions($tableColumn));
return $column;
} | php | protected function getPortableTableEnumColumnDefinition(array $tableColumn)
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$dbType = strtolower($tableColumn['type']);
$dbType = strtok($dbType, '(), ');
$type = $this->_platform->getDoctrineTypeMapping($dbType);
// In cases where not connected to a database DESCRIBE $table does not return 'Comment'
if (isset($tableColumn['comment'])) {
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
}
$options = [
'length' => null,
'unsigned' => false,
'fixed' => null,
'default' => isset($tableColumn['default']) ? $tableColumn['default'] : null,
'notnull' => (bool) ($tableColumn['null'] != 'YES'),
'scale' => null,
'precision' => null,
'autoincrement' => false,
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
? $tableColumn['comment']
: null,
];
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['collation'])) {
$column->setPlatformOption('collation', $tableColumn['collation']);
}
$column->setCustomSchemaOption('options', $this->getEnumOptions($tableColumn));
return $column;
} | [
"protected",
"function",
"getPortableTableEnumColumnDefinition",
"(",
"array",
"$",
"tableColumn",
")",
"{",
"$",
"tableColumn",
"=",
"array_change_key_case",
"(",
"$",
"tableColumn",
",",
"CASE_LOWER",
")",
";",
"$",
"dbType",
"=",
"strtolower",
"(",
"$",
"tableC... | Gets Table Column Definition for Enum Column Type.
@param array $tableColumn
@return \Doctrine\DBAL\Schema\Column | [
"Gets",
"Table",
"Column",
"Definition",
"for",
"Enum",
"Column",
"Type",
"."
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/Managers/MySqlSchemaManager.php#L18-L56 |
larapack/doctrine-support | src/Managers/MySqlSchemaManager.php | MySqlSchemaManager._getPortableTableColumnDefinition | protected function _getPortableTableColumnDefinition($tableColumn)
{
$keys = array_change_key_case($tableColumn, CASE_LOWER);
$type = strtolower($keys['type']);
$type = strtok($type, '(), ');
$method = camel_case("get_portable_table_{$type}_column_definition");
if (method_exists($this, $method)) {
return $this->$method($tableColumn);
}
return parent::_getPortableTableColumnDefinition($tableColumn);
} | php | protected function _getPortableTableColumnDefinition($tableColumn)
{
$keys = array_change_key_case($tableColumn, CASE_LOWER);
$type = strtolower($keys['type']);
$type = strtok($type, '(), ');
$method = camel_case("get_portable_table_{$type}_column_definition");
if (method_exists($this, $method)) {
return $this->$method($tableColumn);
}
return parent::_getPortableTableColumnDefinition($tableColumn);
} | [
"protected",
"function",
"_getPortableTableColumnDefinition",
"(",
"$",
"tableColumn",
")",
"{",
"$",
"keys",
"=",
"array_change_key_case",
"(",
"$",
"tableColumn",
",",
"CASE_LOWER",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"keys",
"[",
"'type'",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/Managers/MySqlSchemaManager.php#L61-L75 |
larapack/doctrine-support | src/Managers/MySqlSchemaManager.php | MySqlSchemaManager.getEnumOptions | protected function getEnumOptions($tableColumn)
{
$type = $tableColumn['type'];
if (starts_with($type, 'enum(') && ends_with($type, ')')) {
return explode("','", trim(substr($type, strlen('enum('), -1), "'"));
}
return [];
} | php | protected function getEnumOptions($tableColumn)
{
$type = $tableColumn['type'];
if (starts_with($type, 'enum(') && ends_with($type, ')')) {
return explode("','", trim(substr($type, strlen('enum('), -1), "'"));
}
return [];
} | [
"protected",
"function",
"getEnumOptions",
"(",
"$",
"tableColumn",
")",
"{",
"$",
"type",
"=",
"$",
"tableColumn",
"[",
"'type'",
"]",
";",
"if",
"(",
"starts_with",
"(",
"$",
"type",
",",
"'enum('",
")",
"&&",
"ends_with",
"(",
"$",
"type",
",",
"')'... | Get enum options from the column.
@param $tableColumn
@return array | [
"Get",
"enum",
"options",
"from",
"the",
"column",
"."
] | train | https://github.com/larapack/doctrine-support/blob/9f4330c6c9a4efc7172104a72ea9ed7d8a1518aa/src/Managers/MySqlSchemaManager.php#L84-L93 |
silverstripe/silverstripe-userforms | code/Form/UserForm.php | UserForm.getFormFields | public function getFormFields()
{
$fields = new UserFormsFieldList();
$target = $fields;
foreach ($this->controller->data()->Fields() as $field) {
$target = $target->processNext($field);
}
$fields->clearEmptySteps();
$this->extend('updateFormFields', $fields);
$fields->setForm($this);
return $fields;
} | php | public function getFormFields()
{
$fields = new UserFormsFieldList();
$target = $fields;
foreach ($this->controller->data()->Fields() as $field) {
$target = $target->processNext($field);
}
$fields->clearEmptySteps();
$this->extend('updateFormFields', $fields);
$fields->setForm($this);
return $fields;
} | [
"public",
"function",
"getFormFields",
"(",
")",
"{",
"$",
"fields",
"=",
"new",
"UserFormsFieldList",
"(",
")",
";",
"$",
"target",
"=",
"$",
"fields",
";",
"foreach",
"(",
"$",
"this",
"->",
"controller",
"->",
"data",
"(",
")",
"->",
"Fields",
"(",
... | Get the form fields for the form on this page. Can modify this FieldSet
by using {@link updateFormFields()} on an {@link Extension} subclass which
is applied to this controller.
This will be a list of top level composite steps
@return FieldList | [
"Get",
"the",
"form",
"fields",
"for",
"the",
"form",
"on",
"this",
"page",
".",
"Can",
"modify",
"this",
"FieldSet",
"by",
"using",
"{",
"@link",
"updateFormFields",
"()",
"}",
"on",
"an",
"{",
"@link",
"Extension",
"}",
"subclass",
"which",
"is",
"appl... | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Form/UserForm.php#L120-L132 |
silverstripe/silverstripe-userforms | code/Form/UserForm.php | UserForm.getFormActions | public function getFormActions()
{
$submitText = ($this->controller->SubmitButtonText)
? $this->controller->SubmitButtonText
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMITBUTTON', 'Submit');
$clearText = ($this->controller->ClearButtonText)
? $this->controller->ClearButtonText
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CLEARBUTTON', 'Clear');
$actions = FieldList::create(FormAction::create('process', $submitText));
if ($this->controller->ShowClearButton) {
$actions->push(FormAction::create('clearForm', $clearText)->setAttribute('type', 'reset'));
}
$this->extend('updateFormActions', $actions);
$actions->setForm($this);
return $actions;
} | php | public function getFormActions()
{
$submitText = ($this->controller->SubmitButtonText)
? $this->controller->SubmitButtonText
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMITBUTTON', 'Submit');
$clearText = ($this->controller->ClearButtonText)
? $this->controller->ClearButtonText
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CLEARBUTTON', 'Clear');
$actions = FieldList::create(FormAction::create('process', $submitText));
if ($this->controller->ShowClearButton) {
$actions->push(FormAction::create('clearForm', $clearText)->setAttribute('type', 'reset'));
}
$this->extend('updateFormActions', $actions);
$actions->setForm($this);
return $actions;
} | [
"public",
"function",
"getFormActions",
"(",
")",
"{",
"$",
"submitText",
"=",
"(",
"$",
"this",
"->",
"controller",
"->",
"SubmitButtonText",
")",
"?",
"$",
"this",
"->",
"controller",
"->",
"SubmitButtonText",
":",
"_t",
"(",
"'SilverStripe\\\\UserForms\\\\Mod... | Generate the form actions for the UserDefinedForm. You
can manipulate these by using {@link updateFormActions()} on
a decorator.
@todo Make form actions editable via their own field editor.
@return FieldList | [
"Generate",
"the",
"form",
"actions",
"for",
"the",
"UserDefinedForm",
".",
"You",
"can",
"manipulate",
"these",
"by",
"using",
"{",
"@link",
"updateFormActions",
"()",
"}",
"on",
"a",
"decorator",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Form/UserForm.php#L143-L161 |
silverstripe/silverstripe-userforms | code/Form/UserForm.php | UserForm.getRequiredFields | public function getRequiredFields()
{
// Generate required field validator
$requiredNames = $this
->getController()
->data()
->Fields()
->filter('Required', true)
->column('Name');
$requiredNames = array_merge($requiredNames, $this->getEmailRecipientRequiredFields());
$required = new RequiredFields($requiredNames);
$this->extend('updateRequiredFields', $required);
$required->setForm($this);
return $required;
} | php | public function getRequiredFields()
{
// Generate required field validator
$requiredNames = $this
->getController()
->data()
->Fields()
->filter('Required', true)
->column('Name');
$requiredNames = array_merge($requiredNames, $this->getEmailRecipientRequiredFields());
$required = new RequiredFields($requiredNames);
$this->extend('updateRequiredFields', $required);
$required->setForm($this);
return $required;
} | [
"public",
"function",
"getRequiredFields",
"(",
")",
"{",
"// Generate required field validator",
"$",
"requiredNames",
"=",
"$",
"this",
"->",
"getController",
"(",
")",
"->",
"data",
"(",
")",
"->",
"Fields",
"(",
")",
"->",
"filter",
"(",
"'Required'",
",",... | Get the required form fields for this form.
@return RequiredFields | [
"Get",
"the",
"required",
"form",
"fields",
"for",
"this",
"form",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Form/UserForm.php#L168-L182 |
silverstripe/silverstripe-userforms | code/Form/UserForm.php | UserForm.getAttributes | public function getAttributes()
{
$attrs = parent::getAttributes();
$attrs['class'] = $attrs['class'] . ' userform';
$attrs['data-livevalidation'] = (bool)$this->controller->EnableLiveValidation;
$attrs['data-toperrors'] = (bool)$this->controller->DisplayErrorMessagesAtTop;
return $attrs;
} | php | public function getAttributes()
{
$attrs = parent::getAttributes();
$attrs['class'] = $attrs['class'] . ' userform';
$attrs['data-livevalidation'] = (bool)$this->controller->EnableLiveValidation;
$attrs['data-toperrors'] = (bool)$this->controller->DisplayErrorMessagesAtTop;
return $attrs;
} | [
"public",
"function",
"getAttributes",
"(",
")",
"{",
"$",
"attrs",
"=",
"parent",
"::",
"getAttributes",
"(",
")",
";",
"$",
"attrs",
"[",
"'class'",
"]",
"=",
"$",
"attrs",
"[",
"'class'",
"]",
".",
"' userform'",
";",
"$",
"attrs",
"[",
"'data-livev... | Override some we can add UserForm specific attributes to the form.
@return array | [
"Override",
"some",
"we",
"can",
"add",
"UserForm",
"specific",
"attributes",
"to",
"the",
"form",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Form/UserForm.php#L189-L198 |
silverstripe/silverstripe-userforms | code/Form/UserForm.php | UserForm.getEmailRecipientRequiredFields | protected function getEmailRecipientRequiredFields()
{
$requiredFields = [];
$recipientFieldsMap = [
'EmailAddress' => 'SendEmailToField',
'EmailSubject' => 'SendEmailSubjectField',
'EmailReplyTo' => 'SendEmailFromField'
];
foreach ($this->getController()->data()->EmailRecipients() as $recipient) {
foreach ($recipientFieldsMap as $textField => $dynamicFormField) {
if (empty($recipient->$textField) && $recipient->getComponent($dynamicFormField)->exists()) {
$requiredFields[] = $recipient->getComponent($dynamicFormField)->Name;
}
}
}
return $requiredFields;
} | php | protected function getEmailRecipientRequiredFields()
{
$requiredFields = [];
$recipientFieldsMap = [
'EmailAddress' => 'SendEmailToField',
'EmailSubject' => 'SendEmailSubjectField',
'EmailReplyTo' => 'SendEmailFromField'
];
foreach ($this->getController()->data()->EmailRecipients() as $recipient) {
foreach ($recipientFieldsMap as $textField => $dynamicFormField) {
if (empty($recipient->$textField) && $recipient->getComponent($dynamicFormField)->exists()) {
$requiredFields[] = $recipient->getComponent($dynamicFormField)->Name;
}
}
}
return $requiredFields;
} | [
"protected",
"function",
"getEmailRecipientRequiredFields",
"(",
")",
"{",
"$",
"requiredFields",
"=",
"[",
"]",
";",
"$",
"recipientFieldsMap",
"=",
"[",
"'EmailAddress'",
"=>",
"'SendEmailToField'",
",",
"'EmailSubject'",
"=>",
"'SendEmailSubjectField'",
",",
"'Emai... | Push fields into the RequiredFields array if they are used by any Email recipients.
Ignore if there is a backup i.e. the plain string field is set
@return array required fields names | [
"Push",
"fields",
"into",
"the",
"RequiredFields",
"array",
"if",
"they",
"are",
"used",
"by",
"any",
"Email",
"recipients",
".",
"Ignore",
"if",
"there",
"is",
"a",
"backup",
"i",
".",
"e",
".",
"the",
"plain",
"string",
"field",
"is",
"set"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Form/UserForm.php#L214-L232 |
silverstripe/silverstripe-userforms | code/FormField/UserFormsFieldList.php | UserFormsFieldList.clearEmptySteps | public function clearEmptySteps()
{
foreach ($this as $field) {
if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
$this->remove($field);
}
}
} | php | public function clearEmptySteps()
{
foreach ($this as $field) {
if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
$this->remove($field);
}
}
} | [
"public",
"function",
"clearEmptySteps",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"UserFormsStepField",
"&&",
"count",
"(",
"$",
"field",
"->",
"getChildren",
"(",
")",
")",
"===",
... | Remove all empty steps | [
"Remove",
"all",
"empty",
"steps"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/FormField/UserFormsFieldList.php#L43-L50 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableMultipleOptionField.php | EditableMultipleOptionField.duplicate | public function duplicate($doWrite = true, $manyMany = 'many_many')
{
// Versioned 1.0 has a bug where [] will result in _all_ relations being duplicated
if ($manyMany === 'many_many' && !$this->manyMany()) {
$manyMany = null;
}
$clonedNode = parent::duplicate(true, $manyMany);
foreach ($this->Options() as $field) {
/** @var EditableOption $newField */
$newField = $field->duplicate(false);
$newField->ParentID = $clonedNode->ID;
$newField->Version = 0;
$newField->write();
}
return $clonedNode;
} | php | public function duplicate($doWrite = true, $manyMany = 'many_many')
{
// Versioned 1.0 has a bug where [] will result in _all_ relations being duplicated
if ($manyMany === 'many_many' && !$this->manyMany()) {
$manyMany = null;
}
$clonedNode = parent::duplicate(true, $manyMany);
foreach ($this->Options() as $field) {
/** @var EditableOption $newField */
$newField = $field->duplicate(false);
$newField->ParentID = $clonedNode->ID;
$newField->Version = 0;
$newField->write();
}
return $clonedNode;
} | [
"public",
"function",
"duplicate",
"(",
"$",
"doWrite",
"=",
"true",
",",
"$",
"manyMany",
"=",
"'many_many'",
")",
"{",
"// Versioned 1.0 has a bug where [] will result in _all_ relations being duplicated",
"if",
"(",
"$",
"manyMany",
"===",
"'many_many'",
"&&",
"!",
... | Duplicate a pages content. We need to make sure all the fields attached
to that page go with it
{@inheritDoc} | [
"Duplicate",
"a",
"pages",
"content",
".",
"We",
"need",
"to",
"make",
"sure",
"all",
"the",
"fields",
"attached",
"to",
"that",
"page",
"go",
"with",
"it"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableMultipleOptionField.php#L119-L137 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableMultipleOptionField.php | EditableMultipleOptionField.getOptionsMap | protected function getOptionsMap()
{
$optionSet = $this->Options();
$optionMap = $optionSet->map('Value', 'Title');
if ($optionMap instanceof Map) {
return $optionMap->toArray();
}
return $optionMap;
} | php | protected function getOptionsMap()
{
$optionSet = $this->Options();
$optionMap = $optionSet->map('Value', 'Title');
if ($optionMap instanceof Map) {
return $optionMap->toArray();
}
return $optionMap;
} | [
"protected",
"function",
"getOptionsMap",
"(",
")",
"{",
"$",
"optionSet",
"=",
"$",
"this",
"->",
"Options",
"(",
")",
";",
"$",
"optionMap",
"=",
"$",
"optionSet",
"->",
"map",
"(",
"'Value'",
",",
"'Title'",
")",
";",
"if",
"(",
"$",
"optionMap",
... | Gets map of field options suitable for use in a form
@return array | [
"Gets",
"map",
"of",
"field",
"options",
"suitable",
"for",
"use",
"in",
"a",
"form"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableMultipleOptionField.php#L155-L163 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipientCondition.php | EmailRecipientCondition.canCreate | public function canCreate($member = null, $context = [])
{
// Check parent page
$parent = $this->getCanCreateContext(func_get_args());
if ($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
} | php | public function canCreate($member = null, $context = [])
{
// Check parent page
$parent = $this->getCanCreateContext(func_get_args());
if ($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
} | [
"public",
"function",
"canCreate",
"(",
"$",
"member",
"=",
"null",
",",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// Check parent page",
"$",
"parent",
"=",
"$",
"this",
"->",
"getCanCreateContext",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
... | Return whether a user can create an object of this type
@param Member $member
@param array $context Virtual parameter to allow context to be passed in to check
@return bool | [
"Return",
"whether",
"a",
"user",
"can",
"create",
"an",
"object",
"of",
"this",
"type"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipientCondition.php#L114-L124 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipientCondition.php | EmailRecipientCondition.getCanCreateContext | protected function getCanCreateContext($args)
{
// Inspect second parameter to canCreate for a 'Parent' context
if (isset($args[1]['Parent'])) {
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentPage();
}
// No page being edited
return null;
} | php | protected function getCanCreateContext($args)
{
// Inspect second parameter to canCreate for a 'Parent' context
if (isset($args[1]['Parent'])) {
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentPage();
}
// No page being edited
return null;
} | [
"protected",
"function",
"getCanCreateContext",
"(",
"$",
"args",
")",
"{",
"// Inspect second parameter to canCreate for a 'Parent' context",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
"[",
"'Parent'",
"]",
")",
")",
"{",
"return",
"$",
"args",
"[",
... | Helper method to check the parent for this object
@param array $args List of arguments passed to canCreate
@return SiteTree Parent page instance | [
"Helper",
"method",
"to",
"check",
"the",
"parent",
"for",
"this",
"object"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipientCondition.php#L132-L145 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getDisplayRuleFields | protected function getDisplayRuleFields()
{
// Check display rules
if ($this->Required) {
return FieldList::create(
LiteralField::create(
'DisplayRulesNotEnabled',
'<div class="alert alert-warning">' . _t(
__CLASS__.'.DISPLAY_RULES_DISABLED',
'Display rules are not enabled for required fields. Please uncheck "Is this field Required?" under "Validation" to re-enable.'
) . '</div>'
)
);
}
$allowedClasses = array_keys($this->getEditableFieldClasses(false));
$editableColumns = new GridFieldEditableColumns();
$editableColumns->setDisplayFields([
'ConditionFieldID' => function ($record, $column, $grid) use ($allowedClasses) {
return DropdownField::create($column, '', EditableFormField::get()->filter([
'ParentID' => $this->ParentID,
'ClassName' => $allowedClasses,
])->exclude([
'ID' => $this->ID,
])->map('ID', 'Title'));
},
'ConditionOption' => function ($record, $column, $grid) {
$options = Config::inst()->get(EditableCustomRule::class, 'condition_options');
return DropdownField::create($column, '', $options);
},
'FieldValue' => function ($record, $column, $grid) {
return TextField::create($column);
}
]);
// Custom rules
$customRulesConfig = GridFieldConfig::create()
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
new GridFieldToolbarHeader(),
new GridFieldAddNewInlineButton(),
new GridFieldDeleteAction()
);
return new FieldList(
DropdownField::create(
'ShowOnLoad',
_t(__CLASS__.'.INITIALVISIBILITY', 'Initial visibility'),
[
1 => 'Show',
0 => 'Hide',
]
),
DropdownField::create(
'DisplayRulesConjunction',
_t(__CLASS__.'.DISPLAYIF', 'Toggle visibility when'),
[
'Or' => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFOR', 'Any conditions are true'),
'And' => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFAND', 'All conditions are true'),
]
),
GridField::create(
'DisplayRules',
_t(__CLASS__.'.CUSTOMRULES', 'Custom Rules'),
$this->DisplayRules(),
$customRulesConfig
)
);
} | php | protected function getDisplayRuleFields()
{
// Check display rules
if ($this->Required) {
return FieldList::create(
LiteralField::create(
'DisplayRulesNotEnabled',
'<div class="alert alert-warning">' . _t(
__CLASS__.'.DISPLAY_RULES_DISABLED',
'Display rules are not enabled for required fields. Please uncheck "Is this field Required?" under "Validation" to re-enable.'
) . '</div>'
)
);
}
$allowedClasses = array_keys($this->getEditableFieldClasses(false));
$editableColumns = new GridFieldEditableColumns();
$editableColumns->setDisplayFields([
'ConditionFieldID' => function ($record, $column, $grid) use ($allowedClasses) {
return DropdownField::create($column, '', EditableFormField::get()->filter([
'ParentID' => $this->ParentID,
'ClassName' => $allowedClasses,
])->exclude([
'ID' => $this->ID,
])->map('ID', 'Title'));
},
'ConditionOption' => function ($record, $column, $grid) {
$options = Config::inst()->get(EditableCustomRule::class, 'condition_options');
return DropdownField::create($column, '', $options);
},
'FieldValue' => function ($record, $column, $grid) {
return TextField::create($column);
}
]);
// Custom rules
$customRulesConfig = GridFieldConfig::create()
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
new GridFieldToolbarHeader(),
new GridFieldAddNewInlineButton(),
new GridFieldDeleteAction()
);
return new FieldList(
DropdownField::create(
'ShowOnLoad',
_t(__CLASS__.'.INITIALVISIBILITY', 'Initial visibility'),
[
1 => 'Show',
0 => 'Hide',
]
),
DropdownField::create(
'DisplayRulesConjunction',
_t(__CLASS__.'.DISPLAYIF', 'Toggle visibility when'),
[
'Or' => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFOR', 'Any conditions are true'),
'And' => _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SENDIFAND', 'All conditions are true'),
]
),
GridField::create(
'DisplayRules',
_t(__CLASS__.'.CUSTOMRULES', 'Custom Rules'),
$this->DisplayRules(),
$customRulesConfig
)
);
} | [
"protected",
"function",
"getDisplayRuleFields",
"(",
")",
"{",
"// Check display rules",
"if",
"(",
"$",
"this",
"->",
"Required",
")",
"{",
"return",
"FieldList",
"::",
"create",
"(",
"LiteralField",
"::",
"create",
"(",
"'DisplayRulesNotEnabled'",
",",
"'<div c... | Return fields to display on the 'Display Rules' tab
@return FieldList | [
"Return",
"fields",
"to",
"display",
"on",
"the",
"Display",
"Rules",
"tab"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L343-L413 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.generateName | protected function generateName()
{
do {
// Generate a new random name after this class (handles namespaces)
$classNamePieces = explode('\\', static::class);
$class = array_pop($classNamePieces);
$entropy = substr(sha1(uniqid()), 0, 5);
$name = "{$class}_{$entropy}";
// Check if it conflicts
$exists = EditableFormField::get()->filter('Name', $name)->count() > 0;
} while ($exists);
return $name;
} | php | protected function generateName()
{
do {
// Generate a new random name after this class (handles namespaces)
$classNamePieces = explode('\\', static::class);
$class = array_pop($classNamePieces);
$entropy = substr(sha1(uniqid()), 0, 5);
$name = "{$class}_{$entropy}";
// Check if it conflicts
$exists = EditableFormField::get()->filter('Name', $name)->count() > 0;
} while ($exists);
return $name;
} | [
"protected",
"function",
"generateName",
"(",
")",
"{",
"do",
"{",
"// Generate a new random name after this class (handles namespaces)",
"$",
"classNamePieces",
"=",
"explode",
"(",
"'\\\\'",
",",
"static",
"::",
"class",
")",
";",
"$",
"class",
"=",
"array_pop",
"... | Generate a new non-conflicting Name value
@return string | [
"Generate",
"a",
"new",
"non",
"-",
"conflicting",
"Name",
"value"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L440-L453 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.canEdit | public function canEdit($member = null)
{
$parent = $this->Parent();
if ($parent && $parent->exists()) {
return $parent->canEdit($member) && !$this->isReadonly();
} elseif (!$this->exists() && Controller::has_curr()) {
// This is for GridFieldOrderableRows support as it checks edit permissions on
// singleton of the class. Allows editing of User Defined Form pages by
// 'Content Authors' and those with permission to edit the UDF page. (ie. CanEditType/EditorGroups)
// This is to restore User Forms 2.x backwards compatibility.
$controller = Controller::curr();
if ($controller && $controller instanceof CMSPageEditController) {
$parent = $controller->getRecord($controller->currentPageID());
// Only allow this behaviour on pages using UserFormFieldEditorExtension, such
// as UserDefinedForm page type.
if ($parent && $parent->hasExtension(UserFormFieldEditorExtension::class)) {
return $parent->canEdit($member);
}
}
}
// Fallback to secure admin permissions
return parent::canEdit($member);
} | php | public function canEdit($member = null)
{
$parent = $this->Parent();
if ($parent && $parent->exists()) {
return $parent->canEdit($member) && !$this->isReadonly();
} elseif (!$this->exists() && Controller::has_curr()) {
// This is for GridFieldOrderableRows support as it checks edit permissions on
// singleton of the class. Allows editing of User Defined Form pages by
// 'Content Authors' and those with permission to edit the UDF page. (ie. CanEditType/EditorGroups)
// This is to restore User Forms 2.x backwards compatibility.
$controller = Controller::curr();
if ($controller && $controller instanceof CMSPageEditController) {
$parent = $controller->getRecord($controller->currentPageID());
// Only allow this behaviour on pages using UserFormFieldEditorExtension, such
// as UserDefinedForm page type.
if ($parent && $parent->hasExtension(UserFormFieldEditorExtension::class)) {
return $parent->canEdit($member);
}
}
}
// Fallback to secure admin permissions
return parent::canEdit($member);
} | [
"public",
"function",
"canEdit",
"(",
"$",
"member",
"=",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"Parent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
"&&",
"$",
"parent",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"$",
"parent"... | Return whether a user can edit this form field
based on whether they can edit the page
@param Member $member
@return bool | [
"Return",
"whether",
"a",
"user",
"can",
"edit",
"this",
"form",
"field",
"based",
"on",
"whether",
"they",
"can",
"edit",
"the",
"page"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L484-L507 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.canView | public function canView($member = null)
{
$parent = $this->Parent();
if ($parent && $parent->exists()) {
return $parent->canView($member);
}
return true;
} | php | public function canView($member = null)
{
$parent = $this->Parent();
if ($parent && $parent->exists()) {
return $parent->canView($member);
}
return true;
} | [
"public",
"function",
"canView",
"(",
"$",
"member",
"=",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"Parent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
"&&",
"$",
"parent",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"$",
"parent"... | Return whether a user can view this form field
based on whether they can view the page, regardless of the ReadOnly status of the field
@param Member $member
@return bool | [
"Return",
"whether",
"a",
"user",
"can",
"view",
"this",
"form",
"field",
"based",
"on",
"whether",
"they",
"can",
"view",
"the",
"page",
"regardless",
"of",
"the",
"ReadOnly",
"status",
"of",
"the",
"field"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L516-L524 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.setAllowedCss | public function setAllowedCss(array $allowed)
{
if (is_array($allowed)) {
foreach ($allowed as $k => $v) {
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
}
}
} | php | public function setAllowedCss(array $allowed)
{
if (is_array($allowed)) {
foreach ($allowed as $k => $v) {
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
}
}
} | [
"public",
"function",
"setAllowedCss",
"(",
"array",
"$",
"allowed",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"allowed",
")",
")",
"{",
"foreach",
"(",
"$",
"allowed",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"self",
"::",
"$",
"allowed_css",
"[... | Set the allowed css classes for the extraClass custom setting
@param array $allowed The permissible CSS classes to add | [
"Set",
"the",
"allowed",
"css",
"classes",
"for",
"the",
"extraClass",
"custom",
"setting"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L587-L594 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getIcon | public function getIcon()
{
$classNamespaces = explode("\\", static::class);
$shortClass = end($classNamespaces);
$resource = ModuleLoader::getModule('silverstripe/userforms')
->getResource('images/' . strtolower($shortClass) . '.png');
if (!$resource->exists()) {
return '';
}
return $resource->getURL();
} | php | public function getIcon()
{
$classNamespaces = explode("\\", static::class);
$shortClass = end($classNamespaces);
$resource = ModuleLoader::getModule('silverstripe/userforms')
->getResource('images/' . strtolower($shortClass) . '.png');
if (!$resource->exists()) {
return '';
}
return $resource->getURL();
} | [
"public",
"function",
"getIcon",
"(",
")",
"{",
"$",
"classNamespaces",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"static",
"::",
"class",
")",
";",
"$",
"shortClass",
"=",
"end",
"(",
"$",
"classNamespaces",
")",
";",
"$",
"resource",
"=",
"ModuleLoader",
"... | Get the path to the icon for this field type, relative to the site root.
@return string | [
"Get",
"the",
"path",
"to",
"the",
"icon",
"for",
"this",
"field",
"type",
"relative",
"to",
"the",
"site",
"root",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L601-L614 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getFieldNumber | public function getFieldNumber()
{
// Check if exists
if (!$this->exists()) {
return null;
}
// Check parent
$form = $this->Parent();
if (!$form || !$form->exists() || !($fields = $form->Fields())) {
return null;
}
$prior = 0; // Number of prior group at this level
$stack = []; // Current stack of nested groups, where the top level = the page
foreach ($fields->map('ID', 'ClassName') as $id => $className) {
if ($className === EditableFormStep::class) {
$priorPage = empty($stack) ? $prior : $stack[0];
$stack = array($priorPage + 1);
$prior = 0;
} elseif ($className === EditableFieldGroup::class) {
$stack[] = $prior + 1;
$prior = 0;
} elseif ($className === EditableFieldGroupEnd::class) {
$prior = array_pop($stack);
}
if ($id == $this->ID) {
return implode('.', $stack);
}
}
return null;
} | php | public function getFieldNumber()
{
// Check if exists
if (!$this->exists()) {
return null;
}
// Check parent
$form = $this->Parent();
if (!$form || !$form->exists() || !($fields = $form->Fields())) {
return null;
}
$prior = 0; // Number of prior group at this level
$stack = []; // Current stack of nested groups, where the top level = the page
foreach ($fields->map('ID', 'ClassName') as $id => $className) {
if ($className === EditableFormStep::class) {
$priorPage = empty($stack) ? $prior : $stack[0];
$stack = array($priorPage + 1);
$prior = 0;
} elseif ($className === EditableFieldGroup::class) {
$stack[] = $prior + 1;
$prior = 0;
} elseif ($className === EditableFieldGroupEnd::class) {
$prior = array_pop($stack);
}
if ($id == $this->ID) {
return implode('.', $stack);
}
}
return null;
} | [
"public",
"function",
"getFieldNumber",
"(",
")",
"{",
"// Check if exists",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Check parent",
"$",
"form",
"=",
"$",
"this",
"->",
"Parent",
"(",
")",
";",
... | Find the numeric indicator (1.1.2) that represents it's nesting value
Only useful for fields attached to a current page, and that contain other fields such as pages
or groups
@return string | [
"Find",
"the",
"numeric",
"indicator",
"(",
"1",
".",
"1",
".",
"2",
")",
"that",
"represents",
"it",
"s",
"nesting",
"value"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L658-L688 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getFieldValidationOptions | public function getFieldValidationOptions()
{
$fields = new FieldList(
CheckboxField::create('Required', _t(__CLASS__.'.REQUIRED', 'Is this field Required?'))
->setDescription(_t(__CLASS__.'.REQUIRED_DESCRIPTION', 'Please note that conditional fields can\'t be required')),
TextField::create('CustomErrorMessage', _t(__CLASS__.'.CUSTOMERROR', 'Custom Error Message'))
);
$this->extend('updateFieldValidationOptions', $fields);
return $fields;
} | php | public function getFieldValidationOptions()
{
$fields = new FieldList(
CheckboxField::create('Required', _t(__CLASS__.'.REQUIRED', 'Is this field Required?'))
->setDescription(_t(__CLASS__.'.REQUIRED_DESCRIPTION', 'Please note that conditional fields can\'t be required')),
TextField::create('CustomErrorMessage', _t(__CLASS__.'.CUSTOMERROR', 'Custom Error Message'))
);
$this->extend('updateFieldValidationOptions', $fields);
return $fields;
} | [
"public",
"function",
"getFieldValidationOptions",
"(",
")",
"{",
"$",
"fields",
"=",
"new",
"FieldList",
"(",
"CheckboxField",
"::",
"create",
"(",
"'Required'",
",",
"_t",
"(",
"__CLASS__",
".",
"'.REQUIRED'",
",",
"'Is this field Required?'",
")",
")",
"->",
... | Append custom validation fields to the default 'Validation'
section in the editable options view
@return FieldList | [
"Append",
"custom",
"validation",
"fields",
"to",
"the",
"default",
"Validation",
"section",
"in",
"the",
"editable",
"options",
"view"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L701-L712 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.doUpdateFormField | public function doUpdateFormField($field)
{
$this->extend('beforeUpdateFormField', $field);
$this->updateFormField($field);
$this->extend('afterUpdateFormField', $field);
} | php | public function doUpdateFormField($field)
{
$this->extend('beforeUpdateFormField', $field);
$this->updateFormField($field);
$this->extend('afterUpdateFormField', $field);
} | [
"public",
"function",
"doUpdateFormField",
"(",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"extend",
"(",
"'beforeUpdateFormField'",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"updateFormField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"exten... | Updates a formfield with extensions
@param FormField $field | [
"Updates",
"a",
"formfield",
"with",
"extensions"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L730-L735 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.updateFormField | protected function updateFormField($field)
{
// set the error / formatting messages
$field->setCustomValidationMessage($this->getErrorMessage()->RAW());
// set the right title on this field
if ($this->RightTitle) {
$field->setRightTitle($this->RightTitle);
}
// if this field is required add some
if ($this->Required) {
// Required validation can conflict so add the Required validation messages as input attributes
$errorMessage = $this->getErrorMessage()->HTML();
$field->addExtraClass('requiredField');
$field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-msg-required', $errorMessage);
if ($identifier = UserDefinedForm::config()->required_identifier) {
$title = $field->Title() . " <span class='required-identifier'>". $identifier . "</span>";
$field->setTitle(DBField::create_field('HTMLText', $title));
}
}
// if this field has an extra class
if ($this->ExtraClass) {
$field->addExtraClass($this->ExtraClass);
}
// if ShowOnLoad is false hide the field
if (!$this->ShowOnLoad) {
$field->addExtraClass($this->ShowOnLoadNice());
}
// if this field has a placeholder
if (strlen($this->Placeholder) >= 0) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} | php | protected function updateFormField($field)
{
// set the error / formatting messages
$field->setCustomValidationMessage($this->getErrorMessage()->RAW());
// set the right title on this field
if ($this->RightTitle) {
$field->setRightTitle($this->RightTitle);
}
// if this field is required add some
if ($this->Required) {
// Required validation can conflict so add the Required validation messages as input attributes
$errorMessage = $this->getErrorMessage()->HTML();
$field->addExtraClass('requiredField');
$field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-msg-required', $errorMessage);
if ($identifier = UserDefinedForm::config()->required_identifier) {
$title = $field->Title() . " <span class='required-identifier'>". $identifier . "</span>";
$field->setTitle(DBField::create_field('HTMLText', $title));
}
}
// if this field has an extra class
if ($this->ExtraClass) {
$field->addExtraClass($this->ExtraClass);
}
// if ShowOnLoad is false hide the field
if (!$this->ShowOnLoad) {
$field->addExtraClass($this->ShowOnLoadNice());
}
// if this field has a placeholder
if (strlen($this->Placeholder) >= 0) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} | [
"protected",
"function",
"updateFormField",
"(",
"$",
"field",
")",
"{",
"// set the error / formatting messages",
"$",
"field",
"->",
"setCustomValidationMessage",
"(",
"$",
"this",
"->",
"getErrorMessage",
"(",
")",
"->",
"RAW",
"(",
")",
")",
";",
"// set the r... | Updates a formfield with the additional metadata specified by this field
@param FormField $field | [
"Updates",
"a",
"formfield",
"with",
"the",
"additional",
"metadata",
"specified",
"by",
"this",
"field"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L742-L780 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getErrorMessage | public function getErrorMessage()
{
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
$standard = _t(__CLASS__ . '.FIELDISREQUIRED', '{name} is required', ['name' => $title]);
// only use CustomErrorMessage if it has a non empty value
$errorMessage = (!empty($this->CustomErrorMessage)) ? $this->CustomErrorMessage : $standard;
return DBField::create_field('Varchar', $errorMessage);
} | php | public function getErrorMessage()
{
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
$standard = _t(__CLASS__ . '.FIELDISREQUIRED', '{name} is required', ['name' => $title]);
// only use CustomErrorMessage if it has a non empty value
$errorMessage = (!empty($this->CustomErrorMessage)) ? $this->CustomErrorMessage : $standard;
return DBField::create_field('Varchar', $errorMessage);
} | [
"public",
"function",
"getErrorMessage",
"(",
")",
"{",
"$",
"title",
"=",
"strip_tags",
"(",
"\"'\"",
".",
"(",
"$",
"this",
"->",
"Title",
"?",
"$",
"this",
"->",
"Title",
":",
"$",
"this",
"->",
"Name",
")",
".",
"\"'\"",
")",
";",
"$",
"standar... | Return the error message for this field. Either uses the custom
one (if provided) or the default SilverStripe message
@return DBVarchar | [
"Return",
"the",
"error",
"message",
"for",
"this",
"field",
".",
"Either",
"uses",
"the",
"custom",
"one",
"(",
"if",
"provided",
")",
"or",
"the",
"default",
"SilverStripe",
"message"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L809-L818 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getInlineTitleField | public function getInlineTitleField($column)
{
return TextField::create($column, false)
->setAttribute('placeholder', _t(__CLASS__.'.TITLE', 'Title'))
->setAttribute('data-placeholder', _t(__CLASS__.'.TITLE', 'Title'));
} | php | public function getInlineTitleField($column)
{
return TextField::create($column, false)
->setAttribute('placeholder', _t(__CLASS__.'.TITLE', 'Title'))
->setAttribute('data-placeholder', _t(__CLASS__.'.TITLE', 'Title'));
} | [
"public",
"function",
"getInlineTitleField",
"(",
"$",
"column",
")",
"{",
"return",
"TextField",
"::",
"create",
"(",
"$",
"column",
",",
"false",
")",
"->",
"setAttribute",
"(",
"'placeholder'",
",",
"_t",
"(",
"__CLASS__",
".",
"'.TITLE'",
",",
"'Title'",... | Get the formfield to use when editing the title inline
@param string $column
@return FormField | [
"Get",
"the",
"formfield",
"to",
"use",
"when",
"editing",
"the",
"title",
"inline"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L838-L843 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.getEditableFieldClasses | public function getEditableFieldClasses($includeLiterals = true)
{
$classes = ClassInfo::getValidSubClasses(EditableFormField::class);
// Remove classes we don't want to display in the dropdown.
$editableFieldClasses = [];
foreach ($classes as $class) {
// Skip abstract / hidden classes
if (Config::inst()->get($class, 'abstract', Config::UNINHERITED)
|| Config::inst()->get($class, 'hidden')
) {
continue;
}
if (!$includeLiterals && Config::inst()->get($class, 'literal')) {
continue;
}
$singleton = singleton($class);
if (!$singleton->canCreate()) {
continue;
}
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
}
asort($editableFieldClasses);
return $editableFieldClasses;
} | php | public function getEditableFieldClasses($includeLiterals = true)
{
$classes = ClassInfo::getValidSubClasses(EditableFormField::class);
// Remove classes we don't want to display in the dropdown.
$editableFieldClasses = [];
foreach ($classes as $class) {
// Skip abstract / hidden classes
if (Config::inst()->get($class, 'abstract', Config::UNINHERITED)
|| Config::inst()->get($class, 'hidden')
) {
continue;
}
if (!$includeLiterals && Config::inst()->get($class, 'literal')) {
continue;
}
$singleton = singleton($class);
if (!$singleton->canCreate()) {
continue;
}
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
}
asort($editableFieldClasses);
return $editableFieldClasses;
} | [
"public",
"function",
"getEditableFieldClasses",
"(",
"$",
"includeLiterals",
"=",
"true",
")",
"{",
"$",
"classes",
"=",
"ClassInfo",
"::",
"getValidSubClasses",
"(",
"EditableFormField",
"::",
"class",
")",
";",
"// Remove classes we don't want to display in the dropdow... | Get the list of classes that can be selected and used as data-values
@param $includeLiterals Set to false to exclude non-data fields
@return array | [
"Get",
"the",
"list",
"of",
"classes",
"that",
"can",
"be",
"selected",
"and",
"used",
"as",
"data",
"-",
"values"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L893-L921 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField.php | EditableFormField.formatDisplayRules | public function formatDisplayRules()
{
$holderSelector = $this->getSelectorOnly();
$result = [
'targetFieldID' => $holderSelector,
'conjunction' => $this->DisplayRulesConjunctionNice(),
'selectors' => [],
'events' => [],
'operations' => [],
'initialState' => $this->ShowOnLoadNice(),
'view' => [],
'opposite' => [],
];
// Check for field dependencies / default
/** @var EditableCustomRule $rule */
foreach ($this->EffectiveDisplayRules() as $rule) {
// Get the field which is effected
/** @var EditableFormField $formFieldWatch */
$formFieldWatch = DataObject::get_by_id(EditableFormField::class, $rule->ConditionFieldID);
// Skip deleted fields
if (!$formFieldWatch) {
continue;
}
$fieldToWatch = $formFieldWatch->getSelectorFieldOnly();
$expression = $rule->buildExpression();
if (!in_array($fieldToWatch, $result['selectors'])) {
$result['selectors'][] = $fieldToWatch;
}
if (!in_array($expression['event'], $result['events'])) {
$result['events'][] = $expression['event'];
}
$result['operations'][] = $expression['operation'];
// View/Show should read
$result['view'] = $rule->toggleDisplayText($result['initialState']);
$result['opposite'] = $rule->toggleDisplayText($result['initialState'], true);
$result['holder'] = $this->getSelectorHolder();
$result['holder_event'] = $rule->toggleDisplayEvent($result['initialState']);
$result['holder_event_opposite'] = $rule->toggleDisplayEvent($result['initialState'], true);
}
return (count($result['selectors'])) ? $result : null;
} | php | public function formatDisplayRules()
{
$holderSelector = $this->getSelectorOnly();
$result = [
'targetFieldID' => $holderSelector,
'conjunction' => $this->DisplayRulesConjunctionNice(),
'selectors' => [],
'events' => [],
'operations' => [],
'initialState' => $this->ShowOnLoadNice(),
'view' => [],
'opposite' => [],
];
// Check for field dependencies / default
/** @var EditableCustomRule $rule */
foreach ($this->EffectiveDisplayRules() as $rule) {
// Get the field which is effected
/** @var EditableFormField $formFieldWatch */
$formFieldWatch = DataObject::get_by_id(EditableFormField::class, $rule->ConditionFieldID);
// Skip deleted fields
if (!$formFieldWatch) {
continue;
}
$fieldToWatch = $formFieldWatch->getSelectorFieldOnly();
$expression = $rule->buildExpression();
if (!in_array($fieldToWatch, $result['selectors'])) {
$result['selectors'][] = $fieldToWatch;
}
if (!in_array($expression['event'], $result['events'])) {
$result['events'][] = $expression['event'];
}
$result['operations'][] = $expression['operation'];
// View/Show should read
$result['view'] = $rule->toggleDisplayText($result['initialState']);
$result['opposite'] = $rule->toggleDisplayText($result['initialState'], true);
$result['holder'] = $this->getSelectorHolder();
$result['holder_event'] = $rule->toggleDisplayEvent($result['initialState']);
$result['holder_event_opposite'] = $rule->toggleDisplayEvent($result['initialState'], true);
}
return (count($result['selectors'])) ? $result : null;
} | [
"public",
"function",
"formatDisplayRules",
"(",
")",
"{",
"$",
"holderSelector",
"=",
"$",
"this",
"->",
"getSelectorOnly",
"(",
")",
";",
"$",
"result",
"=",
"[",
"'targetFieldID'",
"=>",
"$",
"holderSelector",
",",
"'conjunction'",
"=>",
"$",
"this",
"->"... | Extracts info from DisplayRules into array so UserDefinedForm->buildWatchJS can run through it.
@return array|null | [
"Extracts",
"info",
"from",
"DisplayRules",
"into",
"array",
"so",
"UserDefinedForm",
"-",
">",
"buildWatchJS",
"can",
"run",
"through",
"it",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField.php#L949-L994 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableTextField.php | EditableTextField.updateFormField | protected function updateFormField($field)
{
parent::updateFormField($field);
if (is_numeric($this->MinLength) && $this->MinLength > 0) {
$field->setAttribute('data-rule-minlength', intval($this->MinLength));
}
if (is_numeric($this->MaxLength) && $this->MaxLength > 0) {
if ($field instanceof TextField) {
$field->setMaxLength(intval($this->MaxLength));
}
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
}
if ($this->Autocomplete) {
$field->setAttribute('autocomplete', $this->Autocomplete);
}
} | php | protected function updateFormField($field)
{
parent::updateFormField($field);
if (is_numeric($this->MinLength) && $this->MinLength > 0) {
$field->setAttribute('data-rule-minlength', intval($this->MinLength));
}
if (is_numeric($this->MaxLength) && $this->MaxLength > 0) {
if ($field instanceof TextField) {
$field->setMaxLength(intval($this->MaxLength));
}
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
}
if ($this->Autocomplete) {
$field->setAttribute('autocomplete', $this->Autocomplete);
}
} | [
"protected",
"function",
"updateFormField",
"(",
"$",
"field",
")",
"{",
"parent",
"::",
"updateFormField",
"(",
"$",
"field",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"this",
"->",
"MinLength",
")",
"&&",
"$",
"this",
"->",
"MinLength",
">",
"0",
... | Updates a formfield with the additional metadata specified by this field
@param FormField $field | [
"Updates",
"a",
"formfield",
"with",
"the",
"additional",
"metadata",
"specified",
"by",
"this",
"field"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableTextField.php#L169-L187 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.getFormParent | protected function getFormParent()
{
// If polymorphic relationship is actually defined, use it
if ($this->FormID && $this->FormClass) {
$formClass = $this->FormClass;
return $formClass::get()->byID($this->FormID);
}
// Revert to checking for a form from the session
// LeftAndMain::sessionNamespace is protected. @todo replace this with a non-deprecated equivalent.
$sessionNamespace = $this->config()->get('session_namespace') ?: CMSMain::class;
$formID = Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage');
if ($formID) {
return UserDefinedForm::get()->byID($formID);
}
} | php | protected function getFormParent()
{
// If polymorphic relationship is actually defined, use it
if ($this->FormID && $this->FormClass) {
$formClass = $this->FormClass;
return $formClass::get()->byID($this->FormID);
}
// Revert to checking for a form from the session
// LeftAndMain::sessionNamespace is protected. @todo replace this with a non-deprecated equivalent.
$sessionNamespace = $this->config()->get('session_namespace') ?: CMSMain::class;
$formID = Controller::curr()->getRequest()->getSession()->get($sessionNamespace . '.currentPage');
if ($formID) {
return UserDefinedForm::get()->byID($formID);
}
} | [
"protected",
"function",
"getFormParent",
"(",
")",
"{",
"// If polymorphic relationship is actually defined, use it",
"if",
"(",
"$",
"this",
"->",
"FormID",
"&&",
"$",
"this",
"->",
"FormClass",
")",
"{",
"$",
"formClass",
"=",
"$",
"this",
"->",
"FormClass",
... | Get instance of UserForm when editing in getCMSFields
@return UserDefinedForm|UserForm|null | [
"Get",
"instance",
"of",
"UserForm",
"when",
"editing",
"in",
"getCMSFields"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L140-L156 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.getRulesConfig | protected function getRulesConfig()
{
if (!$this->getFormParent()) {
return null;
}
$formFields = $this->getFormParent()->Fields();
$config = GridFieldConfig::create()
->addComponents(
new GridFieldButtonRow('before'),
new GridFieldToolbarHeader(),
new GridFieldAddNewInlineButton(),
new GridFieldDeleteAction(),
$columns = new GridFieldEditableColumns()
);
$columns->setDisplayFields(array(
'ConditionFieldID' => function ($record, $column, $grid) use ($formFields) {
return DropdownField::create($column, false, $formFields->map('ID', 'Title'));
},
'ConditionOption' => function ($record, $column, $grid) {
$options = EmailRecipientCondition::config()->condition_options;
return DropdownField::create($column, false, $options);
},
'ConditionValue' => function ($record, $column, $grid) {
return TextField::create($column);
}
));
return $config;
} | php | protected function getRulesConfig()
{
if (!$this->getFormParent()) {
return null;
}
$formFields = $this->getFormParent()->Fields();
$config = GridFieldConfig::create()
->addComponents(
new GridFieldButtonRow('before'),
new GridFieldToolbarHeader(),
new GridFieldAddNewInlineButton(),
new GridFieldDeleteAction(),
$columns = new GridFieldEditableColumns()
);
$columns->setDisplayFields(array(
'ConditionFieldID' => function ($record, $column, $grid) use ($formFields) {
return DropdownField::create($column, false, $formFields->map('ID', 'Title'));
},
'ConditionOption' => function ($record, $column, $grid) {
$options = EmailRecipientCondition::config()->condition_options;
return DropdownField::create($column, false, $options);
},
'ConditionValue' => function ($record, $column, $grid) {
return TextField::create($column);
}
));
return $config;
} | [
"protected",
"function",
"getRulesConfig",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getFormParent",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"formFields",
"=",
"$",
"this",
"->",
"getFormParent",
"(",
")",
"->",
"Fields",
"(",
"... | Generate a gridfield config for editing filter rules
@return GridFieldConfig | [
"Generate",
"a",
"gridfield",
"config",
"for",
"editing",
"filter",
"rules"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L174-L204 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.canSend | public function canSend($data, $form)
{
// Skip if no rules configured
$customRules = $this->CustomRules();
if (!$customRules->count()) {
return true;
}
// Check all rules
$isAnd = $this->CustomRulesCondition === 'And';
foreach ($customRules as $customRule) {
/** @var EmailRecipientCondition $customRule */
$matches = $customRule->matches($data);
if ($isAnd && !$matches) {
return false;
}
if (!$isAnd && $matches) {
return true;
}
}
// Once all rules are checked
return $isAnd;
} | php | public function canSend($data, $form)
{
// Skip if no rules configured
$customRules = $this->CustomRules();
if (!$customRules->count()) {
return true;
}
// Check all rules
$isAnd = $this->CustomRulesCondition === 'And';
foreach ($customRules as $customRule) {
/** @var EmailRecipientCondition $customRule */
$matches = $customRule->matches($data);
if ($isAnd && !$matches) {
return false;
}
if (!$isAnd && $matches) {
return true;
}
}
// Once all rules are checked
return $isAnd;
} | [
"public",
"function",
"canSend",
"(",
"$",
"data",
",",
"$",
"form",
")",
"{",
"// Skip if no rules configured",
"$",
"customRules",
"=",
"$",
"this",
"->",
"CustomRules",
"(",
")",
";",
"if",
"(",
"!",
"$",
"customRules",
"->",
"count",
"(",
")",
")",
... | Determine if this recipient may receive notifications for this submission
@param array $data
@param Form $form
@return bool | [
"Determine",
"if",
"this",
"recipient",
"may",
"receive",
"notifications",
"for",
"this",
"submission"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L416-L439 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.emailTemplateExists | public function emailTemplateExists($template = '')
{
$t = ($template ? $template : $this->EmailTemplate);
return array_key_exists($t, (array) $this->getEmailTemplateDropdownValues());
} | php | public function emailTemplateExists($template = '')
{
$t = ($template ? $template : $this->EmailTemplate);
return array_key_exists($t, (array) $this->getEmailTemplateDropdownValues());
} | [
"public",
"function",
"emailTemplateExists",
"(",
"$",
"template",
"=",
"''",
")",
"{",
"$",
"t",
"=",
"(",
"$",
"template",
"?",
"$",
"template",
":",
"$",
"this",
"->",
"EmailTemplate",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"t",
",",
"(",... | Make sure the email template saved against the recipient exists on the file system.
@param string
@return boolean | [
"Make",
"sure",
"the",
"email",
"template",
"saved",
"against",
"the",
"recipient",
"exists",
"on",
"the",
"file",
"system",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L448-L453 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.getEmailBodyContent | public function getEmailBodyContent()
{
if ($this->SendPlain) {
return DBField::create_field('HTMLText', $this->EmailBody)->Plain();
}
return DBField::create_field('HTMLText', $this->EmailBodyHtml);
} | php | public function getEmailBodyContent()
{
if ($this->SendPlain) {
return DBField::create_field('HTMLText', $this->EmailBody)->Plain();
}
return DBField::create_field('HTMLText', $this->EmailBodyHtml);
} | [
"public",
"function",
"getEmailBodyContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"SendPlain",
")",
"{",
"return",
"DBField",
"::",
"create_field",
"(",
"'HTMLText'",
",",
"$",
"this",
"->",
"EmailBody",
")",
"->",
"Plain",
"(",
")",
";",
"}",
... | Get the email body for the current email format
@return string | [
"Get",
"the",
"email",
"body",
"for",
"the",
"current",
"email",
"format"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L460-L466 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.getEmailTemplateDropdownValues | public function getEmailTemplateDropdownValues()
{
$templates = [];
$finder = new FileFinder();
$finder->setOption('name_regex', '/^.*\.ss$/');
$parent = $this->getFormParent();
if (!$parent) {
return [];
}
$emailTemplateDirectory = $parent->config()->get('email_template_directory');
$templateDirectory = ModuleResourceLoader::resourcePath($emailTemplateDirectory);
if (!$templateDirectory) {
return [];
}
$found = $finder->find(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory);
foreach ($found as $key => $value) {
$template = pathinfo($value);
$absoluteFilename = $template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'];
// Optionally remove vendor/ path prefixes
$resource = ModuleResourceLoader::singleton()->resolveResource($emailTemplateDirectory);
if ($resource instanceof ModuleResource && $resource->getModule()) {
$prefixToStrip = $resource->getModule()->getPath();
} else {
$prefixToStrip = BASE_PATH;
}
$templatePath = substr($absoluteFilename, strlen($prefixToStrip) + 1);
// Optionally remove "templates/" prefixes
if (preg_match('/(?<=templates\/).*$/', $templatePath, $matches)) {
$templatePath = $matches[0];
}
$templates[$templatePath] = $template['filename'];
}
return $templates;
} | php | public function getEmailTemplateDropdownValues()
{
$templates = [];
$finder = new FileFinder();
$finder->setOption('name_regex', '/^.*\.ss$/');
$parent = $this->getFormParent();
if (!$parent) {
return [];
}
$emailTemplateDirectory = $parent->config()->get('email_template_directory');
$templateDirectory = ModuleResourceLoader::resourcePath($emailTemplateDirectory);
if (!$templateDirectory) {
return [];
}
$found = $finder->find(BASE_PATH . DIRECTORY_SEPARATOR . $templateDirectory);
foreach ($found as $key => $value) {
$template = pathinfo($value);
$absoluteFilename = $template['dirname'] . DIRECTORY_SEPARATOR . $template['filename'];
// Optionally remove vendor/ path prefixes
$resource = ModuleResourceLoader::singleton()->resolveResource($emailTemplateDirectory);
if ($resource instanceof ModuleResource && $resource->getModule()) {
$prefixToStrip = $resource->getModule()->getPath();
} else {
$prefixToStrip = BASE_PATH;
}
$templatePath = substr($absoluteFilename, strlen($prefixToStrip) + 1);
// Optionally remove "templates/" prefixes
if (preg_match('/(?<=templates\/).*$/', $templatePath, $matches)) {
$templatePath = $matches[0];
}
$templates[$templatePath] = $template['filename'];
}
return $templates;
} | [
"public",
"function",
"getEmailTemplateDropdownValues",
"(",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"$",
"finder",
"=",
"new",
"FileFinder",
"(",
")",
";",
"$",
"finder",
"->",
"setOption",
"(",
"'name_regex'",
",",
"'/^.*\\.ss$/'",
")",
";",
"$",... | Gets a list of email templates suitable for populating the email template dropdown.
@return array | [
"Gets",
"a",
"list",
"of",
"email",
"templates",
"suitable",
"for",
"populating",
"the",
"email",
"template",
"dropdown",
"."
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L473-L517 |
silverstripe/silverstripe-userforms | code/Model/Recipient/EmailRecipient.php | EmailRecipient.validate | public function validate()
{
$result = parent::validate();
$checkEmail = [
'EmailAddress' => 'EMAILADDRESSINVALID',
'EmailFrom' => 'EMAILFROMINVALID',
'EmailReplyTo' => 'EMAILREPLYTOINVALID',
];
foreach ($checkEmail as $check => $translation) {
if ($this->$check) {
//may be a comma separated list of emails
$addresses = explode(',', $this->$check);
foreach ($addresses as $address) {
$trimAddress = trim($address);
if ($trimAddress && !Email::is_valid_address($trimAddress)) {
$error = _t(
__CLASS__.".$translation",
"Invalid email address $trimAddress"
);
$result->addError($error . " ($trimAddress)");
}
}
}
}
// if there is no from address and no fallback, you'll have errors if this isn't defined
if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
$result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
}
return $result;
} | php | public function validate()
{
$result = parent::validate();
$checkEmail = [
'EmailAddress' => 'EMAILADDRESSINVALID',
'EmailFrom' => 'EMAILFROMINVALID',
'EmailReplyTo' => 'EMAILREPLYTOINVALID',
];
foreach ($checkEmail as $check => $translation) {
if ($this->$check) {
//may be a comma separated list of emails
$addresses = explode(',', $this->$check);
foreach ($addresses as $address) {
$trimAddress = trim($address);
if ($trimAddress && !Email::is_valid_address($trimAddress)) {
$error = _t(
__CLASS__.".$translation",
"Invalid email address $trimAddress"
);
$result->addError($error . " ($trimAddress)");
}
}
}
}
// if there is no from address and no fallback, you'll have errors if this isn't defined
if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
$result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
}
return $result;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"validate",
"(",
")",
";",
"$",
"checkEmail",
"=",
"[",
"'EmailAddress'",
"=>",
"'EMAILADDRESSINVALID'",
",",
"'EmailFrom'",
"=>",
"'EMAILFROMINVALID'",
",",
"'EmailReplyTo'",
... | Validate that valid email addresses are being used
@return ValidationResult | [
"Validate",
"that",
"valid",
"email",
"addresses",
"are",
"being",
"used"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/Recipient/EmailRecipient.php#L524-L554 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableLiteralField.php | EditableLiteralField.getEditorConfig | protected function getEditorConfig()
{
$editorConfig = $this->config()->get('editor_config');
if ($editorConfig) {
return HTMLEditorConfig::get($editorConfig);
}
return HTMLEditorConfig::get_active();
} | php | protected function getEditorConfig()
{
$editorConfig = $this->config()->get('editor_config');
if ($editorConfig) {
return HTMLEditorConfig::get($editorConfig);
}
return HTMLEditorConfig::get_active();
} | [
"protected",
"function",
"getEditorConfig",
"(",
")",
"{",
"$",
"editorConfig",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'editor_config'",
")",
";",
"if",
"(",
"$",
"editorConfig",
")",
"{",
"return",
"HTMLEditorConfig",
"::",
"get",
... | Returns the {@see HTMLEditorConfig} instance to use for sanitisation
@return HTMLEditorConfig | [
"Returns",
"the",
"{",
"@see",
"HTMLEditorConfig",
"}",
"instance",
"to",
"use",
"for",
"sanitisation"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableLiteralField.php#L59-L66 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableLiteralField.php | EditableLiteralField.sanitiseContent | protected function sanitiseContent($content)
{
// Check if sanitisation is enabled
if (!HTMLEditorField::config()->get('sanitise_server_side')) {
return $content;
}
// Perform sanitisation
$htmlValue = Injector::inst()->create('HTMLValue', $content);
$santiser = Injector::inst()->create(HTMLEditorSanitiser::class, $this->getEditorConfig());
$santiser->sanitise($htmlValue);
return $htmlValue->getContent();
} | php | protected function sanitiseContent($content)
{
// Check if sanitisation is enabled
if (!HTMLEditorField::config()->get('sanitise_server_side')) {
return $content;
}
// Perform sanitisation
$htmlValue = Injector::inst()->create('HTMLValue', $content);
$santiser = Injector::inst()->create(HTMLEditorSanitiser::class, $this->getEditorConfig());
$santiser->sanitise($htmlValue);
return $htmlValue->getContent();
} | [
"protected",
"function",
"sanitiseContent",
"(",
"$",
"content",
")",
"{",
"// Check if sanitisation is enabled",
"if",
"(",
"!",
"HTMLEditorField",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'sanitise_server_side'",
")",
")",
"{",
"return",
"$",
"content",
";... | Safely sanitise html content, if enabled
@param string $content Raw html
@return string Safely sanitised html | [
"Safely",
"sanitise",
"html",
"content",
"if",
"enabled"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableLiteralField.php#L74-L86 |
silverstripe/silverstripe-userforms | code/Model/EditableFormField/EditableNumericField.php | EditableNumericField.updateFormField | protected function updateFormField($field)
{
parent::updateFormField($field);
if ($this->MinValue) {
$field->setAttribute('data-rule-min', $this->MinValue);
}
if ($this->MaxValue) {
$field->setAttribute('data-rule-max', $this->MaxValue);
}
} | php | protected function updateFormField($field)
{
parent::updateFormField($field);
if ($this->MinValue) {
$field->setAttribute('data-rule-min', $this->MinValue);
}
if ($this->MaxValue) {
$field->setAttribute('data-rule-max', $this->MaxValue);
}
} | [
"protected",
"function",
"updateFormField",
"(",
"$",
"field",
")",
"{",
"parent",
"::",
"updateFormField",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"this",
"->",
"MinValue",
")",
"{",
"$",
"field",
"->",
"setAttribute",
"(",
"'data-rule-min'",
",",
... | Updates a formfield with the additional metadata specified by this field
@param FormField $field | [
"Updates",
"a",
"formfield",
"with",
"the",
"additional",
"metadata",
"specified",
"by",
"this",
"field"
] | train | https://github.com/silverstripe/silverstripe-userforms/blob/6eb661fedf5f1cb70a814a1c2354e627b28273e3/code/Model/EditableFormField/EditableNumericField.php#L73-L84 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.