id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
27,800
|
RhubarbPHP/Rhubarb
|
src/Mime/MimePartBinaryFile.php
|
MimePartBinaryFile.fromLocalPath
|
public static function fromLocalPath($path, $name = "")
{
if ($name == "") {
$name = basename($path);
}
$part = new MimePartBinaryFile();
$part->setTransformedBody(file_get_contents($path));
$part->addHeader("Content-Disposition", "attachment; filename=\"" . $name . "\"");
return $part;
}
|
php
|
public static function fromLocalPath($path, $name = "")
{
if ($name == "") {
$name = basename($path);
}
$part = new MimePartBinaryFile();
$part->setTransformedBody(file_get_contents($path));
$part->addHeader("Content-Disposition", "attachment; filename=\"" . $name . "\"");
return $part;
}
|
[
"public",
"static",
"function",
"fromLocalPath",
"(",
"$",
"path",
",",
"$",
"name",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"\"\"",
")",
"{",
"$",
"name",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"}",
"$",
"part",
"=",
"new",
"MimePartBinaryFile",
"(",
")",
";",
"$",
"part",
"->",
"setTransformedBody",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
")",
";",
"$",
"part",
"->",
"addHeader",
"(",
"\"Content-Disposition\"",
",",
"\"attachment; filename=\\\"\"",
".",
"$",
"name",
".",
"\"\\\"\"",
")",
";",
"return",
"$",
"part",
";",
"}"
] |
Creates an instance to represent a file stored locally.
@param $path
@param string $name
@return MimePartBinaryFile
|
[
"Creates",
"an",
"instance",
"to",
"represent",
"a",
"file",
"stored",
"locally",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePartBinaryFile.php#L38-L49
|
27,801
|
RhubarbPHP/Rhubarb
|
src/Assets/LocalStorageAssetCatalogueProvider.php
|
LocalStorageAssetCatalogueProvider.getCategoryDirectory
|
private function getCategoryDirectory()
{
if (!$this->category){
return "_default";
}
$category = preg_replace("/\\W/","-",$this->category);
$category = preg_replace("/-+/","-",$category);
$category .= crc32($this->category);
return $category;
}
|
php
|
private function getCategoryDirectory()
{
if (!$this->category){
return "_default";
}
$category = preg_replace("/\\W/","-",$this->category);
$category = preg_replace("/-+/","-",$category);
$category .= crc32($this->category);
return $category;
}
|
[
"private",
"function",
"getCategoryDirectory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"category",
")",
"{",
"return",
"\"_default\"",
";",
"}",
"$",
"category",
"=",
"preg_replace",
"(",
"\"/\\\\W/\"",
",",
"\"-\"",
",",
"$",
"this",
"->",
"category",
")",
";",
"$",
"category",
"=",
"preg_replace",
"(",
"\"/-+/\"",
",",
"\"-\"",
",",
"$",
"category",
")",
";",
"$",
"category",
".=",
"crc32",
"(",
"$",
"this",
"->",
"category",
")",
";",
"return",
"$",
"category",
";",
"}"
] |
Makes the category name safe to use for a file path but guaranteed unique.
e.g. This! and This@ should both work.
|
[
"Makes",
"the",
"category",
"name",
"safe",
"to",
"use",
"for",
"a",
"file",
"path",
"but",
"guaranteed",
"unique",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/LocalStorageAssetCatalogueProvider.php#L61-L72
|
27,802
|
RhubarbPHP/Rhubarb
|
src/Assets/LocalStorageAssetCatalogueProvider.php
|
LocalStorageAssetCatalogueProvider.getAssetPath
|
protected function getAssetPath(Asset $asset):string
{
// Get the file name from the provider data
$data = $asset->getProviderData();
$path = $this->getRootPath() . "/" . $this->getCategoryDirectory() . "/" . $data["file"];
return $path;
}
|
php
|
protected function getAssetPath(Asset $asset):string
{
// Get the file name from the provider data
$data = $asset->getProviderData();
$path = $this->getRootPath() . "/" . $this->getCategoryDirectory() . "/" . $data["file"];
return $path;
}
|
[
"protected",
"function",
"getAssetPath",
"(",
"Asset",
"$",
"asset",
")",
":",
"string",
"{",
"// Get the file name from the provider data",
"$",
"data",
"=",
"$",
"asset",
"->",
"getProviderData",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getRootPath",
"(",
")",
".",
"\"/\"",
".",
"$",
"this",
"->",
"getCategoryDirectory",
"(",
")",
".",
"\"/\"",
".",
"$",
"data",
"[",
"\"file\"",
"]",
";",
"return",
"$",
"path",
";",
"}"
] |
Returns the local path for the given asset.
@param Asset $asset
@return string
|
[
"Returns",
"the",
"local",
"path",
"for",
"the",
"given",
"asset",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/LocalStorageAssetCatalogueProvider.php#L144-L150
|
27,803
|
RhubarbPHP/Rhubarb
|
src/Encryption/Sha512HashProvider.php
|
Sha512HashProvider.createHash
|
public function createHash($data, $salt = false)
{
if ($salt === false) {
$salt = sha1(uniqid("sillystring", true) . microtime());
}
$raw = crypt($data, '$6$rounds=10000$' . $salt . '$');
return $raw;
}
|
php
|
public function createHash($data, $salt = false)
{
if ($salt === false) {
$salt = sha1(uniqid("sillystring", true) . microtime());
}
$raw = crypt($data, '$6$rounds=10000$' . $salt . '$');
return $raw;
}
|
[
"public",
"function",
"createHash",
"(",
"$",
"data",
",",
"$",
"salt",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"salt",
"===",
"false",
")",
"{",
"$",
"salt",
"=",
"sha1",
"(",
"uniqid",
"(",
"\"sillystring\"",
",",
"true",
")",
".",
"microtime",
"(",
")",
")",
";",
"}",
"$",
"raw",
"=",
"crypt",
"(",
"$",
"data",
",",
"'$6$rounds=10000$'",
".",
"$",
"salt",
".",
"'$'",
")",
";",
"return",
"$",
"raw",
";",
"}"
] |
Create's a new hash of the supplied data using the optionally supplied salt.
It's expected that the salt can be randomised if not supplied. This is fact
preferable in nearly all occasions as the salt should be included in the return
value.
@param string $data
@param string|bool $salt
@return string
|
[
"Create",
"s",
"a",
"new",
"hash",
"of",
"the",
"supplied",
"data",
"using",
"the",
"optionally",
"supplied",
"salt",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Encryption/Sha512HashProvider.php#L37-L46
|
27,804
|
RhubarbPHP/Rhubarb
|
src/Encryption/Sha512HashProvider.php
|
Sha512HashProvider.compareHash
|
public function compareHash($data, $hash)
{
$salt = $this->extractSalt($hash);
$newHash = $this->createHash($data, $salt);
return ($newHash == $hash);
}
|
php
|
public function compareHash($data, $hash)
{
$salt = $this->extractSalt($hash);
$newHash = $this->createHash($data, $salt);
return ($newHash == $hash);
}
|
[
"public",
"function",
"compareHash",
"(",
"$",
"data",
",",
"$",
"hash",
")",
"{",
"$",
"salt",
"=",
"$",
"this",
"->",
"extractSalt",
"(",
"$",
"hash",
")",
";",
"$",
"newHash",
"=",
"$",
"this",
"->",
"createHash",
"(",
"$",
"data",
",",
"$",
"salt",
")",
";",
"return",
"(",
"$",
"newHash",
"==",
"$",
"hash",
")",
";",
"}"
] |
Computes the hash of the supplied data using the salt contained within an existing hash.
If the resultant value matches the hash the hash and data are equivilant.
@param $data
@param $hash
@return bool
|
[
"Computes",
"the",
"hash",
"of",
"the",
"supplied",
"data",
"using",
"the",
"salt",
"contained",
"within",
"an",
"existing",
"hash",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Encryption/Sha512HashProvider.php#L70-L77
|
27,805
|
RhubarbPHP/Rhubarb
|
src/Assets/AssetCatalogueProvider.php
|
AssetCatalogueProvider.storeAsset
|
public static function storeAsset($filePath, $category, $storeAs = "")
{
// A sane default
$mime = "application/octet-stream";
$name = ($storeAs == "") ? basename($filePath) : $storeAs;
// CSV is detected as text/plain - change this if.
if (preg_match("/\\.csv$/i", $name)){
$mime = "text/csv";
} else {
if (function_exists("finfo_open")) {
$info = new \finfo(FILEINFO_MIME);
$mime = $info->file($filePath);
}
}
$provider = self::getProvider($category);
try {
$asset = $provider->createAssetFromFile($filePath, [
"name" => $name,
"size" => filesize($filePath),
"mimeType" => $mime,
"category" => $category
]);
$asset->mimeType = $mime;
return $asset;
} catch (AssetException $er){
Log::error("Error creating asset from file '$filePath': ".$er->getPrivateMessage());
throw $er;
}
return null;
}
|
php
|
public static function storeAsset($filePath, $category, $storeAs = "")
{
// A sane default
$mime = "application/octet-stream";
$name = ($storeAs == "") ? basename($filePath) : $storeAs;
// CSV is detected as text/plain - change this if.
if (preg_match("/\\.csv$/i", $name)){
$mime = "text/csv";
} else {
if (function_exists("finfo_open")) {
$info = new \finfo(FILEINFO_MIME);
$mime = $info->file($filePath);
}
}
$provider = self::getProvider($category);
try {
$asset = $provider->createAssetFromFile($filePath, [
"name" => $name,
"size" => filesize($filePath),
"mimeType" => $mime,
"category" => $category
]);
$asset->mimeType = $mime;
return $asset;
} catch (AssetException $er){
Log::error("Error creating asset from file '$filePath': ".$er->getPrivateMessage());
throw $er;
}
return null;
}
|
[
"public",
"static",
"function",
"storeAsset",
"(",
"$",
"filePath",
",",
"$",
"category",
",",
"$",
"storeAs",
"=",
"\"\"",
")",
"{",
"// A sane default",
"$",
"mime",
"=",
"\"application/octet-stream\"",
";",
"$",
"name",
"=",
"(",
"$",
"storeAs",
"==",
"\"\"",
")",
"?",
"basename",
"(",
"$",
"filePath",
")",
":",
"$",
"storeAs",
";",
"// CSV is detected as text/plain - change this if.",
"if",
"(",
"preg_match",
"(",
"\"/\\\\.csv$/i\"",
",",
"$",
"name",
")",
")",
"{",
"$",
"mime",
"=",
"\"text/csv\"",
";",
"}",
"else",
"{",
"if",
"(",
"function_exists",
"(",
"\"finfo_open\"",
")",
")",
"{",
"$",
"info",
"=",
"new",
"\\",
"finfo",
"(",
"FILEINFO_MIME",
")",
";",
"$",
"mime",
"=",
"$",
"info",
"->",
"file",
"(",
"$",
"filePath",
")",
";",
"}",
"}",
"$",
"provider",
"=",
"self",
"::",
"getProvider",
"(",
"$",
"category",
")",
";",
"try",
"{",
"$",
"asset",
"=",
"$",
"provider",
"->",
"createAssetFromFile",
"(",
"$",
"filePath",
",",
"[",
"\"name\"",
"=>",
"$",
"name",
",",
"\"size\"",
"=>",
"filesize",
"(",
"$",
"filePath",
")",
",",
"\"mimeType\"",
"=>",
"$",
"mime",
",",
"\"category\"",
"=>",
"$",
"category",
"]",
")",
";",
"$",
"asset",
"->",
"mimeType",
"=",
"$",
"mime",
";",
"return",
"$",
"asset",
";",
"}",
"catch",
"(",
"AssetException",
"$",
"er",
")",
"{",
"Log",
"::",
"error",
"(",
"\"Error creating asset from file '$filePath': \"",
".",
"$",
"er",
"->",
"getPrivateMessage",
"(",
")",
")",
";",
"throw",
"$",
"er",
";",
"}",
"return",
"null",
";",
"}"
] |
Stores an asset currently held in a local file in a given asset category
@param string $filePath
@param string $category
@return Asset
|
[
"Stores",
"an",
"asset",
"currently",
"held",
"in",
"a",
"local",
"file",
"in",
"a",
"given",
"asset",
"category"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L49-L84
|
27,806
|
RhubarbPHP/Rhubarb
|
src/Assets/AssetCatalogueProvider.php
|
AssetCatalogueProvider.getJwtKey
|
private static function getJwtKey()
{
$settings = AssetCatalogueSettings::singleton();
$key = $settings->jwtKey;
if ($key == "") {
throw new AssetException("", "No token key is defined in AssetCatalogueSettings");
}
return $key;
}
|
php
|
private static function getJwtKey()
{
$settings = AssetCatalogueSettings::singleton();
$key = $settings->jwtKey;
if ($key == "") {
throw new AssetException("", "No token key is defined in AssetCatalogueSettings");
}
return $key;
}
|
[
"private",
"static",
"function",
"getJwtKey",
"(",
")",
"{",
"$",
"settings",
"=",
"AssetCatalogueSettings",
"::",
"singleton",
"(",
")",
";",
"$",
"key",
"=",
"$",
"settings",
"->",
"jwtKey",
";",
"if",
"(",
"$",
"key",
"==",
"\"\"",
")",
"{",
"throw",
"new",
"AssetException",
"(",
"\"\"",
",",
"\"No token key is defined in AssetCatalogueSettings\"",
")",
";",
"}",
"return",
"$",
"key",
";",
"}"
] |
Gets the key used to sign JWT tokens.
@return string
@throws AssetException
|
[
"Gets",
"the",
"key",
"used",
"to",
"sign",
"JWT",
"tokens",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L99-L109
|
27,807
|
RhubarbPHP/Rhubarb
|
src/Assets/AssetCatalogueProvider.php
|
AssetCatalogueProvider.createToken
|
protected function createToken($data)
{
$key = self::getJwtKey();
$token = array(
"iat" => time(),
"provider" => get_class($this),
"category" => $this->category,
"data" => $data
);
$jwt = JWT::encode($token, $key);
return $jwt;
}
|
php
|
protected function createToken($data)
{
$key = self::getJwtKey();
$token = array(
"iat" => time(),
"provider" => get_class($this),
"category" => $this->category,
"data" => $data
);
$jwt = JWT::encode($token, $key);
return $jwt;
}
|
[
"protected",
"function",
"createToken",
"(",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"self",
"::",
"getJwtKey",
"(",
")",
";",
"$",
"token",
"=",
"array",
"(",
"\"iat\"",
"=>",
"time",
"(",
")",
",",
"\"provider\"",
"=>",
"get_class",
"(",
"$",
"this",
")",
",",
"\"category\"",
"=>",
"$",
"this",
"->",
"category",
",",
"\"data\"",
"=>",
"$",
"data",
")",
";",
"$",
"jwt",
"=",
"JWT",
"::",
"encode",
"(",
"$",
"token",
",",
"$",
"key",
")",
";",
"return",
"$",
"jwt",
";",
"}"
] |
Creates a JWT token to encode an asset using the passed data array.
@param $data
@return string
@throws AssetException
|
[
"Creates",
"a",
"JWT",
"token",
"to",
"encode",
"an",
"asset",
"using",
"the",
"passed",
"data",
"array",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L142-L156
|
27,808
|
RhubarbPHP/Rhubarb
|
src/Assets/AssetCatalogueProvider.php
|
AssetCatalogueProvider.getAsset
|
public static function getAsset($token)
{
$key = self::getJwtKey();
$payload = JWT::decode($token, $key, array('HS256'));
$providerClass = $payload->provider;
$category = $payload->category;
$data = (array) $payload->data;
$provider = new $providerClass($category);
return new Asset($token, $provider, $data);
}
|
php
|
public static function getAsset($token)
{
$key = self::getJwtKey();
$payload = JWT::decode($token, $key, array('HS256'));
$providerClass = $payload->provider;
$category = $payload->category;
$data = (array) $payload->data;
$provider = new $providerClass($category);
return new Asset($token, $provider, $data);
}
|
[
"public",
"static",
"function",
"getAsset",
"(",
"$",
"token",
")",
"{",
"$",
"key",
"=",
"self",
"::",
"getJwtKey",
"(",
")",
";",
"$",
"payload",
"=",
"JWT",
"::",
"decode",
"(",
"$",
"token",
",",
"$",
"key",
",",
"array",
"(",
"'HS256'",
")",
")",
";",
"$",
"providerClass",
"=",
"$",
"payload",
"->",
"provider",
";",
"$",
"category",
"=",
"$",
"payload",
"->",
"category",
";",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"payload",
"->",
"data",
";",
"$",
"provider",
"=",
"new",
"$",
"providerClass",
"(",
"$",
"category",
")",
";",
"return",
"new",
"Asset",
"(",
"$",
"token",
",",
"$",
"provider",
",",
"$",
"data",
")",
";",
"}"
] |
Recreates an asset from the data in the passed token.
@param $token
@return Asset
@throws AssetException
|
[
"Recreates",
"an",
"asset",
"from",
"the",
"data",
"in",
"the",
"passed",
"token",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L165-L178
|
27,809
|
RhubarbPHP/Rhubarb
|
src/Assets/AssetCatalogueProvider.php
|
AssetCatalogueProvider.getProvider
|
public static function getProvider($assetCategory = "")
{
if (isset(self::$providerMap[$assetCategory])) {
$class = self::$providerMap[$assetCategory];
} elseif (isset(self::$providerMap[""])){
$class = self::$providerMap[""];
} else {
throw new AssetException("", "No provider mapping could be found for category '".$assetCategory."'");
}
$provider = new $class($assetCategory);
return $provider;
}
|
php
|
public static function getProvider($assetCategory = "")
{
if (isset(self::$providerMap[$assetCategory])) {
$class = self::$providerMap[$assetCategory];
} elseif (isset(self::$providerMap[""])){
$class = self::$providerMap[""];
} else {
throw new AssetException("", "No provider mapping could be found for category '".$assetCategory."'");
}
$provider = new $class($assetCategory);
return $provider;
}
|
[
"public",
"static",
"function",
"getProvider",
"(",
"$",
"assetCategory",
"=",
"\"\"",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"providerMap",
"[",
"$",
"assetCategory",
"]",
")",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"$",
"providerMap",
"[",
"$",
"assetCategory",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"self",
"::",
"$",
"providerMap",
"[",
"\"\"",
"]",
")",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"$",
"providerMap",
"[",
"\"\"",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"AssetException",
"(",
"\"\"",
",",
"\"No provider mapping could be found for category '\"",
".",
"$",
"assetCategory",
".",
"\"'\"",
")",
";",
"}",
"$",
"provider",
"=",
"new",
"$",
"class",
"(",
"$",
"assetCategory",
")",
";",
"return",
"$",
"provider",
";",
"}"
] |
Returns an instance of the correct provider for a given category
@param string $assetCategory The category of provider - or empty for the default provider
@return AssetCatalogueProvider
@throws AssetException Thrown if a provider could not be found for the given category
|
[
"Returns",
"an",
"instance",
"of",
"the",
"correct",
"provider",
"for",
"a",
"given",
"category"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L198-L211
|
27,810
|
duncan3dc/cache
|
src/CacheKeyTrait.php
|
CacheKeyTrait.validateKey
|
protected function validateKey($key)
{
if (!is_string($key)) {
throw new CacheKeyException("Cache key must be a string, " . gettype($key) . " given");
}
if (preg_match("/[^A-Za-z0-9\._-]/", $key)) {
throw new CacheKeyException("Cache key contains invalid characters: {$key}");
}
if (strlen($key) > 64) {
throw new CacheKeyException("Cache key cannot be longer than 64 characters: {$key}");
}
}
|
php
|
protected function validateKey($key)
{
if (!is_string($key)) {
throw new CacheKeyException("Cache key must be a string, " . gettype($key) . " given");
}
if (preg_match("/[^A-Za-z0-9\._-]/", $key)) {
throw new CacheKeyException("Cache key contains invalid characters: {$key}");
}
if (strlen($key) > 64) {
throw new CacheKeyException("Cache key cannot be longer than 64 characters: {$key}");
}
}
|
[
"protected",
"function",
"validateKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"CacheKeyException",
"(",
"\"Cache key must be a string, \"",
".",
"gettype",
"(",
"$",
"key",
")",
".",
"\" given\"",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"\"/[^A-Za-z0-9\\._-]/\"",
",",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"CacheKeyException",
"(",
"\"Cache key contains invalid characters: {$key}\"",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"key",
")",
">",
"64",
")",
"{",
"throw",
"new",
"CacheKeyException",
"(",
"\"Cache key cannot be longer than 64 characters: {$key}\"",
")",
";",
"}",
"}"
] |
Check the passed key to ensure it's a valid cache key.
@param string $key
@return void
@throws CacheKeyException
|
[
"Check",
"the",
"passed",
"key",
"to",
"ensure",
"it",
"s",
"a",
"valid",
"cache",
"key",
"."
] |
826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0
|
https://github.com/duncan3dc/cache/blob/826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0/src/CacheKeyTrait.php#L21-L34
|
27,811
|
duncan3dc/cache
|
src/SimpleCacheTrait.php
|
SimpleCacheTrait.set
|
public function set($key, $value, $ttl = null)
{
$item = new Item($key, $value);
if ($ttl !== null) {
$item->expiresAfter($ttl);
}
return $this->save($item);
}
|
php
|
public function set($key, $value, $ttl = null)
{
$item = new Item($key, $value);
if ($ttl !== null) {
$item->expiresAfter($ttl);
}
return $this->save($item);
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ttl",
"=",
"null",
")",
"{",
"$",
"item",
"=",
"new",
"Item",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"ttl",
"!==",
"null",
")",
"{",
"$",
"item",
"->",
"expiresAfter",
"(",
"$",
"ttl",
")",
";",
"}",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"item",
")",
";",
"}"
] |
Persists data in the cache, uniquely referenced by a key.
@param string $key The key of the item to store
@param mixed $value The value of the item to store, must be serializable
@param \DateInterval|int|null $ttl The TTL value of this item
@return bool
|
[
"Persists",
"data",
"in",
"the",
"cache",
"uniquely",
"referenced",
"by",
"a",
"key",
"."
] |
826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0
|
https://github.com/duncan3dc/cache/blob/826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0/src/SimpleCacheTrait.php#L41-L48
|
27,812
|
RhubarbPHP/Rhubarb
|
src/Module.php
|
Module.getUrlHandlers
|
protected final function getUrlHandlers()
{
if (!$this->urlHandlersRegistered){
$this->registerUrlHandlers();
$this->urlHandlersRegistered = true;
}
return $this->urlHandlers;
}
|
php
|
protected final function getUrlHandlers()
{
if (!$this->urlHandlersRegistered){
$this->registerUrlHandlers();
$this->urlHandlersRegistered = true;
}
return $this->urlHandlers;
}
|
[
"protected",
"final",
"function",
"getUrlHandlers",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"urlHandlersRegistered",
")",
"{",
"$",
"this",
"->",
"registerUrlHandlers",
"(",
")",
";",
"$",
"this",
"->",
"urlHandlersRegistered",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"urlHandlers",
";",
"}"
] |
Get the finalised collection of url handlers for the module
@return UrlHandlers\UrlHandler[]
|
[
"Get",
"the",
"finalised",
"collection",
"of",
"url",
"handlers",
"for",
"the",
"module"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Module.php#L142-L150
|
27,813
|
RhubarbPHP/Rhubarb
|
src/Sendables/Email/Email.php
|
Email.addAttachment
|
public function addAttachment($path, $newName = "")
{
if ($newName == "") {
$newName = basename($path);
}
$file = new \stdClass();
$file->path = $path;
$file->name = $newName;
$this->attachments[] = $file;
return $this;
}
|
php
|
public function addAttachment($path, $newName = "")
{
if ($newName == "") {
$newName = basename($path);
}
$file = new \stdClass();
$file->path = $path;
$file->name = $newName;
$this->attachments[] = $file;
return $this;
}
|
[
"public",
"function",
"addAttachment",
"(",
"$",
"path",
",",
"$",
"newName",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"newName",
"==",
"\"\"",
")",
"{",
"$",
"newName",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"}",
"$",
"file",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"file",
"->",
"path",
"=",
"$",
"path",
";",
"$",
"file",
"->",
"name",
"=",
"$",
"newName",
";",
"$",
"this",
"->",
"attachments",
"[",
"]",
"=",
"$",
"file",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds an attachment
@param string $path The path to the local file
@param string $newName Optionally specify a new name for the file.
@return $this
|
[
"Adds",
"an",
"attachment"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L46-L59
|
27,814
|
RhubarbPHP/Rhubarb
|
src/Sendables/Email/Email.php
|
Email.getMimeDocument
|
public function getMimeDocument()
{
$textPart = false;
$htmlPart = false;
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
/**
* @var string|bool Tracks which part should contain the text and html parts.
*/
$alternativePart = false;
if (count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/mixed", crc32($html) . crc32($text) . crc32($subject));
} else {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
// The outer mime part is our alternative part
$alternativePart = $mime;
}
if ($text != "") {
$textPart = new MimePartText("text/plain");
$textPart->setTransformedBody($text);
}
if ($html != "") {
$htmlPart = new MimePartText("text/html");
$htmlPart->setTransformedBody($html);
}
if ($text != "" && $html != "") {
if (count($this->attachments) > 0) {
// As this email has attachments we need to create an alternative part to store the text and html
$alternativePart = new MimeDocument("multipart/alternative");
$mime->addPart($alternativePart);
}
$alternativePart->addPart($textPart);
$alternativePart->addPart($htmlPart);
} else {
if ($text != "") {
$mime->addPart($textPart);
}
if ($html != "") {
$mime->addPart($htmlPart);
}
}
foreach ($this->attachments as $attachment) {
$mime->addPart(MimePartBinaryFile::fromLocalPath($attachment->path, $attachment->name));
}
$mime->addHeader("To", $this->getRecipientList());
$mime->addHeader("From", $this->getSender()->getRfcFormat());
$mime->addHeader("Subject", $this->getSubject());
$mime->addHeader("Reply-To", $this->getReplyToRecipient());
return $mime;
}
|
php
|
public function getMimeDocument()
{
$textPart = false;
$htmlPart = false;
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
/**
* @var string|bool Tracks which part should contain the text and html parts.
*/
$alternativePart = false;
if (count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/mixed", crc32($html) . crc32($text) . crc32($subject));
} else {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
// The outer mime part is our alternative part
$alternativePart = $mime;
}
if ($text != "") {
$textPart = new MimePartText("text/plain");
$textPart->setTransformedBody($text);
}
if ($html != "") {
$htmlPart = new MimePartText("text/html");
$htmlPart->setTransformedBody($html);
}
if ($text != "" && $html != "") {
if (count($this->attachments) > 0) {
// As this email has attachments we need to create an alternative part to store the text and html
$alternativePart = new MimeDocument("multipart/alternative");
$mime->addPart($alternativePart);
}
$alternativePart->addPart($textPart);
$alternativePart->addPart($htmlPart);
} else {
if ($text != "") {
$mime->addPart($textPart);
}
if ($html != "") {
$mime->addPart($htmlPart);
}
}
foreach ($this->attachments as $attachment) {
$mime->addPart(MimePartBinaryFile::fromLocalPath($attachment->path, $attachment->name));
}
$mime->addHeader("To", $this->getRecipientList());
$mime->addHeader("From", $this->getSender()->getRfcFormat());
$mime->addHeader("Subject", $this->getSubject());
$mime->addHeader("Reply-To", $this->getReplyToRecipient());
return $mime;
}
|
[
"public",
"function",
"getMimeDocument",
"(",
")",
"{",
"$",
"textPart",
"=",
"false",
";",
"$",
"htmlPart",
"=",
"false",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtml",
"(",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"getText",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"this",
"->",
"getSubject",
"(",
")",
";",
"/**\n * @var string|bool Tracks which part should contain the text and html parts.\n */",
"$",
"alternativePart",
"=",
"false",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"attachments",
")",
">",
"0",
")",
"{",
"$",
"mime",
"=",
"new",
"MimeDocument",
"(",
"\"multipart/mixed\"",
",",
"crc32",
"(",
"$",
"html",
")",
".",
"crc32",
"(",
"$",
"text",
")",
".",
"crc32",
"(",
"$",
"subject",
")",
")",
";",
"}",
"else",
"{",
"$",
"mime",
"=",
"new",
"MimeDocument",
"(",
"\"multipart/alternative\"",
",",
"crc32",
"(",
"$",
"html",
")",
".",
"crc32",
"(",
"$",
"text",
")",
".",
"crc32",
"(",
"$",
"subject",
")",
")",
";",
"// The outer mime part is our alternative part",
"$",
"alternativePart",
"=",
"$",
"mime",
";",
"}",
"if",
"(",
"$",
"text",
"!=",
"\"\"",
")",
"{",
"$",
"textPart",
"=",
"new",
"MimePartText",
"(",
"\"text/plain\"",
")",
";",
"$",
"textPart",
"->",
"setTransformedBody",
"(",
"$",
"text",
")",
";",
"}",
"if",
"(",
"$",
"html",
"!=",
"\"\"",
")",
"{",
"$",
"htmlPart",
"=",
"new",
"MimePartText",
"(",
"\"text/html\"",
")",
";",
"$",
"htmlPart",
"->",
"setTransformedBody",
"(",
"$",
"html",
")",
";",
"}",
"if",
"(",
"$",
"text",
"!=",
"\"\"",
"&&",
"$",
"html",
"!=",
"\"\"",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"attachments",
")",
">",
"0",
")",
"{",
"// As this email has attachments we need to create an alternative part to store the text and html",
"$",
"alternativePart",
"=",
"new",
"MimeDocument",
"(",
"\"multipart/alternative\"",
")",
";",
"$",
"mime",
"->",
"addPart",
"(",
"$",
"alternativePart",
")",
";",
"}",
"$",
"alternativePart",
"->",
"addPart",
"(",
"$",
"textPart",
")",
";",
"$",
"alternativePart",
"->",
"addPart",
"(",
"$",
"htmlPart",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"text",
"!=",
"\"\"",
")",
"{",
"$",
"mime",
"->",
"addPart",
"(",
"$",
"textPart",
")",
";",
"}",
"if",
"(",
"$",
"html",
"!=",
"\"\"",
")",
"{",
"$",
"mime",
"->",
"addPart",
"(",
"$",
"htmlPart",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"attachments",
"as",
"$",
"attachment",
")",
"{",
"$",
"mime",
"->",
"addPart",
"(",
"MimePartBinaryFile",
"::",
"fromLocalPath",
"(",
"$",
"attachment",
"->",
"path",
",",
"$",
"attachment",
"->",
"name",
")",
")",
";",
"}",
"$",
"mime",
"->",
"addHeader",
"(",
"\"To\"",
",",
"$",
"this",
"->",
"getRecipientList",
"(",
")",
")",
";",
"$",
"mime",
"->",
"addHeader",
"(",
"\"From\"",
",",
"$",
"this",
"->",
"getSender",
"(",
")",
"->",
"getRfcFormat",
"(",
")",
")",
";",
"$",
"mime",
"->",
"addHeader",
"(",
"\"Subject\"",
",",
"$",
"this",
"->",
"getSubject",
"(",
")",
")",
";",
"$",
"mime",
"->",
"addHeader",
"(",
"\"Reply-To\"",
",",
"$",
"this",
"->",
"getReplyToRecipient",
"(",
")",
")",
";",
"return",
"$",
"mime",
";",
"}"
] |
Gets a MimeDocument to represent this email.
@return MimeDocument
|
[
"Gets",
"a",
"MimeDocument",
"to",
"represent",
"this",
"email",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L176-L239
|
27,815
|
RhubarbPHP/Rhubarb
|
src/Sendables/Email/Email.php
|
Email.getMailHeaders
|
public function getMailHeaders()
{
$headers = [];
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
if ($html != "" || count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
$headers = $mime->getHeaders();
} else {
$headers["Content-Type"] = "text/plain; charset=utf-8";
}
$headers["From"] = (string)$this->getSender();
$headers["Subject"] = $subject;
return $headers;
}
|
php
|
public function getMailHeaders()
{
$headers = [];
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
if ($html != "" || count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
$headers = $mime->getHeaders();
} else {
$headers["Content-Type"] = "text/plain; charset=utf-8";
}
$headers["From"] = (string)$this->getSender();
$headers["Subject"] = $subject;
return $headers;
}
|
[
"public",
"function",
"getMailHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtml",
"(",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"getText",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"this",
"->",
"getSubject",
"(",
")",
";",
"if",
"(",
"$",
"html",
"!=",
"\"\"",
"||",
"count",
"(",
"$",
"this",
"->",
"attachments",
")",
">",
"0",
")",
"{",
"$",
"mime",
"=",
"new",
"MimeDocument",
"(",
"\"multipart/alternative\"",
",",
"crc32",
"(",
"$",
"html",
")",
".",
"crc32",
"(",
"$",
"text",
")",
".",
"crc32",
"(",
"$",
"subject",
")",
")",
";",
"$",
"headers",
"=",
"$",
"mime",
"->",
"getHeaders",
"(",
")",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"\"Content-Type\"",
"]",
"=",
"\"text/plain; charset=utf-8\"",
";",
"}",
"$",
"headers",
"[",
"\"From\"",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"getSender",
"(",
")",
";",
"$",
"headers",
"[",
"\"Subject\"",
"]",
"=",
"$",
"subject",
";",
"return",
"$",
"headers",
";",
"}"
] |
Returns the mail headers as an array of key value pairs.
@return array
|
[
"Returns",
"the",
"mail",
"headers",
"as",
"an",
"array",
"of",
"key",
"value",
"pairs",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L274-L293
|
27,816
|
rchouinard/bencode
|
src/Decoder.php
|
Decoder.doDecode
|
private function doDecode()
{
switch ($this->getChar()) {
case "i":
++$this->offset;
return $this->decodeInteger();
case "l":
++$this->offset;
return $this->decodeList();
case "d":
++$this->offset;
return $this->decodeDict();
default:
if (ctype_digit($this->getChar())) {
return $this->decodeString();
}
}
throw new RuntimeException("Unknown entity found at offset $this->offset");
}
|
php
|
private function doDecode()
{
switch ($this->getChar()) {
case "i":
++$this->offset;
return $this->decodeInteger();
case "l":
++$this->offset;
return $this->decodeList();
case "d":
++$this->offset;
return $this->decodeDict();
default:
if (ctype_digit($this->getChar())) {
return $this->decodeString();
}
}
throw new RuntimeException("Unknown entity found at offset $this->offset");
}
|
[
"private",
"function",
"doDecode",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"case",
"\"i\"",
":",
"++",
"$",
"this",
"->",
"offset",
";",
"return",
"$",
"this",
"->",
"decodeInteger",
"(",
")",
";",
"case",
"\"l\"",
":",
"++",
"$",
"this",
"->",
"offset",
";",
"return",
"$",
"this",
"->",
"decodeList",
"(",
")",
";",
"case",
"\"d\"",
":",
"++",
"$",
"this",
"->",
"offset",
";",
"return",
"$",
"this",
"->",
"decodeDict",
"(",
")",
";",
"default",
":",
"if",
"(",
"ctype_digit",
"(",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"decodeString",
"(",
")",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Unknown entity found at offset $this->offset\"",
")",
";",
"}"
] |
Iterate over encoded entities in the source string and decode them
@return mixed Returns the decoded value.
@throws RuntimeException
|
[
"Iterate",
"over",
"encoded",
"entities",
"in",
"the",
"source",
"string",
"and",
"decode",
"them"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L101-L125
|
27,817
|
rchouinard/bencode
|
src/Decoder.php
|
Decoder.decodeInteger
|
private function decodeInteger()
{
$offsetOfE = strpos($this->source, "e", $this->offset);
if (false === $offsetOfE) {
throw new RuntimeException("Unterminated integer entity at offset $this->offset");
}
$currentOffset = $this->offset;
if ("-" == $this->getChar($currentOffset)) {
++$currentOffset;
}
if ($offsetOfE === $currentOffset) {
throw new RuntimeException("Empty integer entity at offset $this->offset");
}
while ($currentOffset < $offsetOfE) {
if (!ctype_digit($this->getChar($currentOffset))) {
throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
}
++$currentOffset;
}
$value = substr($this->source, $this->offset, $offsetOfE - $this->offset);
// One last check to make sure zero-padded integers don't slip by, as
// they're not allowed per bencode specification.
$absoluteValue = (string) abs($value);
if (1 < strlen($absoluteValue) && "0" == $value[0]) {
throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
}
$this->offset = $offsetOfE + 1;
// The +0 auto-casts the chunk to either an integer or a float(in cases
// where an integer would overrun the max limits of integer types)
return $value + 0;
}
|
php
|
private function decodeInteger()
{
$offsetOfE = strpos($this->source, "e", $this->offset);
if (false === $offsetOfE) {
throw new RuntimeException("Unterminated integer entity at offset $this->offset");
}
$currentOffset = $this->offset;
if ("-" == $this->getChar($currentOffset)) {
++$currentOffset;
}
if ($offsetOfE === $currentOffset) {
throw new RuntimeException("Empty integer entity at offset $this->offset");
}
while ($currentOffset < $offsetOfE) {
if (!ctype_digit($this->getChar($currentOffset))) {
throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
}
++$currentOffset;
}
$value = substr($this->source, $this->offset, $offsetOfE - $this->offset);
// One last check to make sure zero-padded integers don't slip by, as
// they're not allowed per bencode specification.
$absoluteValue = (string) abs($value);
if (1 < strlen($absoluteValue) && "0" == $value[0]) {
throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
}
$this->offset = $offsetOfE + 1;
// The +0 auto-casts the chunk to either an integer or a float(in cases
// where an integer would overrun the max limits of integer types)
return $value + 0;
}
|
[
"private",
"function",
"decodeInteger",
"(",
")",
"{",
"$",
"offsetOfE",
"=",
"strpos",
"(",
"$",
"this",
"->",
"source",
",",
"\"e\"",
",",
"$",
"this",
"->",
"offset",
")",
";",
"if",
"(",
"false",
"===",
"$",
"offsetOfE",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unterminated integer entity at offset $this->offset\"",
")",
";",
"}",
"$",
"currentOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"if",
"(",
"\"-\"",
"==",
"$",
"this",
"->",
"getChar",
"(",
"$",
"currentOffset",
")",
")",
"{",
"++",
"$",
"currentOffset",
";",
"}",
"if",
"(",
"$",
"offsetOfE",
"===",
"$",
"currentOffset",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Empty integer entity at offset $this->offset\"",
")",
";",
"}",
"while",
"(",
"$",
"currentOffset",
"<",
"$",
"offsetOfE",
")",
"{",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"this",
"->",
"getChar",
"(",
"$",
"currentOffset",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Non-numeric character found in integer entity at offset $this->offset\"",
")",
";",
"}",
"++",
"$",
"currentOffset",
";",
"}",
"$",
"value",
"=",
"substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"this",
"->",
"offset",
",",
"$",
"offsetOfE",
"-",
"$",
"this",
"->",
"offset",
")",
";",
"// One last check to make sure zero-padded integers don't slip by, as",
"// they're not allowed per bencode specification.",
"$",
"absoluteValue",
"=",
"(",
"string",
")",
"abs",
"(",
"$",
"value",
")",
";",
"if",
"(",
"1",
"<",
"strlen",
"(",
"$",
"absoluteValue",
")",
"&&",
"\"0\"",
"==",
"$",
"value",
"[",
"0",
"]",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Illegal zero-padding found in integer entity at offset $this->offset\"",
")",
";",
"}",
"$",
"this",
"->",
"offset",
"=",
"$",
"offsetOfE",
"+",
"1",
";",
"// The +0 auto-casts the chunk to either an integer or a float(in cases",
"// where an integer would overrun the max limits of integer types)",
"return",
"$",
"value",
"+",
"0",
";",
"}"
] |
Decode a bencode encoded integer
@return integer Returns the decoded integer.
@throws RuntimeException
|
[
"Decode",
"a",
"bencode",
"encoded",
"integer"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L133-L170
|
27,818
|
rchouinard/bencode
|
src/Decoder.php
|
Decoder.decodeList
|
private function decodeList()
{
$list = array();
$terminated = false;
$listOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$list[] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated list definition at offset $listOffset");
}
$this->offset++;
return $list;
}
|
php
|
private function decodeList()
{
$list = array();
$terminated = false;
$listOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$list[] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated list definition at offset $listOffset");
}
$this->offset++;
return $list;
}
|
[
"private",
"function",
"decodeList",
"(",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"terminated",
"=",
"false",
";",
"$",
"listOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"while",
"(",
"false",
"!==",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"if",
"(",
"\"e\"",
"==",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"$",
"terminated",
"=",
"true",
";",
"break",
";",
"}",
"$",
"list",
"[",
"]",
"=",
"$",
"this",
"->",
"doDecode",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"terminated",
"&&",
"false",
"===",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unterminated list definition at offset $listOffset\"",
")",
";",
"}",
"$",
"this",
"->",
"offset",
"++",
";",
"return",
"$",
"list",
";",
"}"
] |
Decode a bencode encoded list
@return array Returns the decoded array.
@throws RuntimeException
|
[
"Decode",
"a",
"bencode",
"encoded",
"list"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L206-L228
|
27,819
|
rchouinard/bencode
|
src/Decoder.php
|
Decoder.decodeDict
|
private function decodeDict()
{
$dict = array();
$terminated = false;
$dictOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$keyOffset = $this->offset;
if (!ctype_digit($this->getChar())) {
throw new RuntimeException("Invalid dictionary key at offset $keyOffset");
}
$key = $this->decodeString();
if (isset ($dict[$key])) {
throw new RuntimeException("Duplicate dictionary key at offset $keyOffset");
}
$dict[$key] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated dictionary definition at offset $dictOffset");
}
$this->offset++;
return $dict;
}
|
php
|
private function decodeDict()
{
$dict = array();
$terminated = false;
$dictOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$keyOffset = $this->offset;
if (!ctype_digit($this->getChar())) {
throw new RuntimeException("Invalid dictionary key at offset $keyOffset");
}
$key = $this->decodeString();
if (isset ($dict[$key])) {
throw new RuntimeException("Duplicate dictionary key at offset $keyOffset");
}
$dict[$key] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated dictionary definition at offset $dictOffset");
}
$this->offset++;
return $dict;
}
|
[
"private",
"function",
"decodeDict",
"(",
")",
"{",
"$",
"dict",
"=",
"array",
"(",
")",
";",
"$",
"terminated",
"=",
"false",
";",
"$",
"dictOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"while",
"(",
"false",
"!==",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"if",
"(",
"\"e\"",
"==",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"$",
"terminated",
"=",
"true",
";",
"break",
";",
"}",
"$",
"keyOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Invalid dictionary key at offset $keyOffset\"",
")",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"decodeString",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dict",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Duplicate dictionary key at offset $keyOffset\"",
")",
";",
"}",
"$",
"dict",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"doDecode",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"terminated",
"&&",
"false",
"===",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unterminated dictionary definition at offset $dictOffset\"",
")",
";",
"}",
"$",
"this",
"->",
"offset",
"++",
";",
"return",
"$",
"dict",
";",
"}"
] |
Decode a bencode encoded dictionary
@return array Returns the decoded array.
@throws RuntimeException
|
[
"Decode",
"a",
"bencode",
"encoded",
"dictionary"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L236-L268
|
27,820
|
rchouinard/bencode
|
src/Decoder.php
|
Decoder.getChar
|
private function getChar($offset = null)
{
if (null === $offset) {
$offset = $this->offset;
}
if (empty ($this->source) || $this->offset >= $this->sourceLength) {
return false;
}
return $this->source[$offset];
}
|
php
|
private function getChar($offset = null)
{
if (null === $offset) {
$offset = $this->offset;
}
if (empty ($this->source) || $this->offset >= $this->sourceLength) {
return false;
}
return $this->source[$offset];
}
|
[
"private",
"function",
"getChar",
"(",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"$",
"this",
"->",
"offset",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"source",
")",
"||",
"$",
"this",
"->",
"offset",
">=",
"$",
"this",
"->",
"sourceLength",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"source",
"[",
"$",
"offset",
"]",
";",
"}"
] |
Fetch the character at the specified source offset
If offset is not provided, the current offset is used.
@param integer $offset The offset to retrieve from the source string.
@return string|false Returns the character found at the specified
offset. If the specified offset is out of range, FALSE is returned.
|
[
"Fetch",
"the",
"character",
"at",
"the",
"specified",
"source",
"offset"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L279-L290
|
27,821
|
RhubarbPHP/Rhubarb
|
src/Mime/MimePart.php
|
MimePart.getTransformedBody
|
final public function getTransformedBody()
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
$rawBody = $this->getRawBody();
switch ($encoding) {
case "quoted-printable":
return quoted_printable_decode($rawBody);
break;
case "base64":
return base64_decode($rawBody);
break;
default:
return $rawBody;
}
}
|
php
|
final public function getTransformedBody()
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
$rawBody = $this->getRawBody();
switch ($encoding) {
case "quoted-printable":
return quoted_printable_decode($rawBody);
break;
case "base64":
return base64_decode($rawBody);
break;
default:
return $rawBody;
}
}
|
[
"final",
"public",
"function",
"getTransformedBody",
"(",
")",
"{",
"$",
"encoding",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
")",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
":",
"\"\"",
";",
"$",
"rawBody",
"=",
"$",
"this",
"->",
"getRawBody",
"(",
")",
";",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"\"quoted-printable\"",
":",
"return",
"quoted_printable_decode",
"(",
"$",
"rawBody",
")",
";",
"break",
";",
"case",
"\"base64\"",
":",
"return",
"base64_decode",
"(",
"$",
"rawBody",
")",
";",
"break",
";",
"default",
":",
"return",
"$",
"rawBody",
";",
"}",
"}"
] |
Transforms the part as per the transform encoding header and returns the transformed result.
|
[
"Transforms",
"the",
"part",
"as",
"per",
"the",
"transform",
"encoding",
"header",
"and",
"returns",
"the",
"transformed",
"result",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePart.php#L70-L86
|
27,822
|
RhubarbPHP/Rhubarb
|
src/Mime/MimePart.php
|
MimePart.setTransformedBody
|
final public function setTransformedBody($transformedBody)
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
switch ($encoding) {
case "quoted-printable":
$this->setRawBody(quoted_printable_encode($transformedBody));
break;
case "base64":
$this->setRawBody(chunk_split(base64_encode($transformedBody), 76));
break;
default:
$this->setRawBody($transformedBody);
}
}
|
php
|
final public function setTransformedBody($transformedBody)
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
switch ($encoding) {
case "quoted-printable":
$this->setRawBody(quoted_printable_encode($transformedBody));
break;
case "base64":
$this->setRawBody(chunk_split(base64_encode($transformedBody), 76));
break;
default:
$this->setRawBody($transformedBody);
}
}
|
[
"final",
"public",
"function",
"setTransformedBody",
"(",
"$",
"transformedBody",
")",
"{",
"$",
"encoding",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
")",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
":",
"\"\"",
";",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"\"quoted-printable\"",
":",
"$",
"this",
"->",
"setRawBody",
"(",
"quoted_printable_encode",
"(",
"$",
"transformedBody",
")",
")",
";",
"break",
";",
"case",
"\"base64\"",
":",
"$",
"this",
"->",
"setRawBody",
"(",
"chunk_split",
"(",
"base64_encode",
"(",
"$",
"transformedBody",
")",
",",
"76",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"setRawBody",
"(",
"$",
"transformedBody",
")",
";",
"}",
"}"
] |
Takes a transformed body and turns it into the raw body string needed for the mime encoding.
@param $transformedBody
|
[
"Takes",
"a",
"transformed",
"body",
"and",
"turns",
"it",
"into",
"the",
"raw",
"body",
"string",
"needed",
"for",
"the",
"mime",
"encoding",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePart.php#L93-L107
|
27,823
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.encode
|
public static function encode($data)
{
if (is_object($data)) {
if (method_exists($data, "toArray")) {
$data = $data->toArray();
} else {
$data = (array) $data;
}
}
$encoder = new self($data);
$encoded = $encoder->doEncode();
return $encoded;
}
|
php
|
public static function encode($data)
{
if (is_object($data)) {
if (method_exists($data, "toArray")) {
$data = $data->toArray();
} else {
$data = (array) $data;
}
}
$encoder = new self($data);
$encoded = $encoder->doEncode();
return $encoded;
}
|
[
"public",
"static",
"function",
"encode",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"data",
",",
"\"toArray\"",
")",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"}",
"}",
"$",
"encoder",
"=",
"new",
"self",
"(",
"$",
"data",
")",
";",
"$",
"encoded",
"=",
"$",
"encoder",
"->",
"doEncode",
"(",
")",
";",
"return",
"$",
"encoded",
";",
"}"
] |
Encode a value into a bencode encoded string
@param mixed $data The value to encode.
@return string Returns the bencode encoded string.
|
[
"Encode",
"a",
"value",
"into",
"a",
"bencode",
"encoded",
"string"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L47-L61
|
27,824
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.doEncode
|
private function doEncode($data = null)
{
$data = is_null($data) ? $this->data : $data;
if (is_array($data) && (isset ($data[0]) || empty ($data))) {
return $this->encodeList($data);
} elseif (is_array($data)) {
return $this->encodeDict($data);
} elseif (is_integer($data) || is_float($data)) {
$data = sprintf("%.0f", round($data, 0));
return $this->encodeInteger($data);
} else {
return $this->encodeString($data);
}
}
|
php
|
private function doEncode($data = null)
{
$data = is_null($data) ? $this->data : $data;
if (is_array($data) && (isset ($data[0]) || empty ($data))) {
return $this->encodeList($data);
} elseif (is_array($data)) {
return $this->encodeDict($data);
} elseif (is_integer($data) || is_float($data)) {
$data = sprintf("%.0f", round($data, 0));
return $this->encodeInteger($data);
} else {
return $this->encodeString($data);
}
}
|
[
"private",
"function",
"doEncode",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"(",
"isset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
"||",
"empty",
"(",
"$",
"data",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"encodeList",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"encodeDict",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_integer",
"(",
"$",
"data",
")",
"||",
"is_float",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"sprintf",
"(",
"\"%.0f\"",
",",
"round",
"(",
"$",
"data",
",",
"0",
")",
")",
";",
"return",
"$",
"this",
"->",
"encodeInteger",
"(",
"$",
"data",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"encodeString",
"(",
"$",
"data",
")",
";",
"}",
"}"
] |
Iterate over values and encode them
@param mixed $data The value to encode.
@return string Returns the bencode encoded string.
|
[
"Iterate",
"over",
"values",
"and",
"encode",
"them"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L69-L83
|
27,825
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.encodeInteger
|
private function encodeInteger($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("i%.0fe", $data);
}
|
php
|
private function encodeInteger($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("i%.0fe", $data);
}
|
[
"private",
"function",
"encodeInteger",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"return",
"sprintf",
"(",
"\"i%.0fe\"",
",",
"$",
"data",
")",
";",
"}"
] |
Encode an integer
@param integer $data The integer to be encoded.
@return string Returns the bencode encoded integer.
|
[
"Encode",
"an",
"integer"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L91-L95
|
27,826
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.encodeString
|
private function encodeString($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("%d:%s", strlen($data), $data);
}
|
php
|
private function encodeString($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("%d:%s", strlen($data), $data);
}
|
[
"private",
"function",
"encodeString",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"return",
"sprintf",
"(",
"\"%d:%s\"",
",",
"strlen",
"(",
"$",
"data",
")",
",",
"$",
"data",
")",
";",
"}"
] |
Encode a string
@param string $data The string to be encoded.
@return string Returns the bencode encoded string.
|
[
"Encode",
"a",
"string"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L103-L107
|
27,827
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.encodeList
|
private function encodeList(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
$list = "";
foreach ($data as $value) {
$list .= $this->doEncode($value);
}
return "l{$list}e";
}
|
php
|
private function encodeList(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
$list = "";
foreach ($data as $value) {
$list .= $this->doEncode($value);
}
return "l{$list}e";
}
|
[
"private",
"function",
"encodeList",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"$",
"list",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"$",
"list",
".=",
"$",
"this",
"->",
"doEncode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"\"l{$list}e\"",
";",
"}"
] |
Encode a list
@param array $data The list to be encoded.
@return string Returns the bencode encoded list.
|
[
"Encode",
"a",
"list"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L115-L125
|
27,828
|
rchouinard/bencode
|
src/Encoder.php
|
Encoder.encodeDict
|
private function encodeDict(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
ksort($data); // bencode spec requires dicts to be sorted alphabetically
$dict = "";
foreach ($data as $key => $value) {
$dict .= $this->encodeString($key) . $this->doEncode($value);
}
return "d{$dict}e";
}
|
php
|
private function encodeDict(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
ksort($data); // bencode spec requires dicts to be sorted alphabetically
$dict = "";
foreach ($data as $key => $value) {
$dict .= $this->encodeString($key) . $this->doEncode($value);
}
return "d{$dict}e";
}
|
[
"private",
"function",
"encodeDict",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"ksort",
"(",
"$",
"data",
")",
";",
"// bencode spec requires dicts to be sorted alphabetically",
"$",
"dict",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"dict",
".=",
"$",
"this",
"->",
"encodeString",
"(",
"$",
"key",
")",
".",
"$",
"this",
"->",
"doEncode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"\"d{$dict}e\"",
";",
"}"
] |
Encode a dictionary
@param array $data The dictionary to be encoded.
@return string Returns the bencode encoded dictionary.
|
[
"Encode",
"a",
"dictionary"
] |
7caeb1d9823897701a5901369cfdc326696c679c
|
https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L133-L144
|
27,829
|
RhubarbPHP/Rhubarb
|
src/Mime/MimeDocument.php
|
MimeDocument.fromString
|
public static function fromString($documentString)
{
$document = new MimeDocument($documentString);
$lines = explode("\n", $documentString);
$boundary = false;
$nextPartLines = [];
$firstBoundaryFound = false;
$mimeMessage = "";
foreach ($lines as $line) {
$line = trim($line);
if (!$boundary) {
if (preg_match("/Content-Type: (multipart\/.+);\s+boundary=\"?([^\"]+)\"?/i", $line, $match)) {
$document->boundary = $match[2];
$document->setContentType($match[1]);
$boundary = $match[2];
continue;
}
} else {
if ($line == "--" . $boundary . "--") {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
break;
}
if ($line == "--" . $boundary) {
if (!$firstBoundaryFound) {
$firstBoundaryFound = true;
} else {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
$nextPartLines = [];
}
} else {
if ($firstBoundaryFound) {
$nextPartLines[] = $line;
} else {
$mimeMessage .= $line . "\r\n";
}
}
}
}
$document->setMessage(trim($mimeMessage));
return $document;
}
|
php
|
public static function fromString($documentString)
{
$document = new MimeDocument($documentString);
$lines = explode("\n", $documentString);
$boundary = false;
$nextPartLines = [];
$firstBoundaryFound = false;
$mimeMessage = "";
foreach ($lines as $line) {
$line = trim($line);
if (!$boundary) {
if (preg_match("/Content-Type: (multipart\/.+);\s+boundary=\"?([^\"]+)\"?/i", $line, $match)) {
$document->boundary = $match[2];
$document->setContentType($match[1]);
$boundary = $match[2];
continue;
}
} else {
if ($line == "--" . $boundary . "--") {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
break;
}
if ($line == "--" . $boundary) {
if (!$firstBoundaryFound) {
$firstBoundaryFound = true;
} else {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
$nextPartLines = [];
}
} else {
if ($firstBoundaryFound) {
$nextPartLines[] = $line;
} else {
$mimeMessage .= $line . "\r\n";
}
}
}
}
$document->setMessage(trim($mimeMessage));
return $document;
}
|
[
"public",
"static",
"function",
"fromString",
"(",
"$",
"documentString",
")",
"{",
"$",
"document",
"=",
"new",
"MimeDocument",
"(",
"$",
"documentString",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"documentString",
")",
";",
"$",
"boundary",
"=",
"false",
";",
"$",
"nextPartLines",
"=",
"[",
"]",
";",
"$",
"firstBoundaryFound",
"=",
"false",
";",
"$",
"mimeMessage",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"!",
"$",
"boundary",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/Content-Type: (multipart\\/.+);\\s+boundary=\\\"?([^\\\"]+)\\\"?/i\"",
",",
"$",
"line",
",",
"$",
"match",
")",
")",
"{",
"$",
"document",
"->",
"boundary",
"=",
"$",
"match",
"[",
"2",
"]",
";",
"$",
"document",
"->",
"setContentType",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"$",
"boundary",
"=",
"$",
"match",
"[",
"2",
"]",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"line",
"==",
"\"--\"",
".",
"$",
"boundary",
".",
"\"--\"",
")",
"{",
"$",
"part",
"=",
"MimePart",
"::",
"fromLines",
"(",
"$",
"nextPartLines",
")",
";",
"$",
"document",
"->",
"addPart",
"(",
"$",
"part",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"line",
"==",
"\"--\"",
".",
"$",
"boundary",
")",
"{",
"if",
"(",
"!",
"$",
"firstBoundaryFound",
")",
"{",
"$",
"firstBoundaryFound",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"part",
"=",
"MimePart",
"::",
"fromLines",
"(",
"$",
"nextPartLines",
")",
";",
"$",
"document",
"->",
"addPart",
"(",
"$",
"part",
")",
";",
"$",
"nextPartLines",
"=",
"[",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"firstBoundaryFound",
")",
"{",
"$",
"nextPartLines",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"else",
"{",
"$",
"mimeMessage",
".=",
"$",
"line",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"}",
"}",
"$",
"document",
"->",
"setMessage",
"(",
"trim",
"(",
"$",
"mimeMessage",
")",
")",
";",
"return",
"$",
"document",
";",
"}"
] |
Creates a document from a MIME string.
Note this currently only supports a single level of MIME - no nesting.
@param $documentString
@return MimeDocument
|
[
"Creates",
"a",
"document",
"from",
"a",
"MIME",
"string",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimeDocument.php#L125-L176
|
27,830
|
RhubarbPHP/Rhubarb
|
src/Html/ResourceLoader.php
|
ResourceLoader.addScriptCode
|
public static function addScriptCode($scriptCode, $dependantResourceUrls = [])
{
$dependantResourceUrls = array_unique($dependantResourceUrls);
self::$resources[] = [$scriptCode, $dependantResourceUrls];
}
|
php
|
public static function addScriptCode($scriptCode, $dependantResourceUrls = [])
{
$dependantResourceUrls = array_unique($dependantResourceUrls);
self::$resources[] = [$scriptCode, $dependantResourceUrls];
}
|
[
"public",
"static",
"function",
"addScriptCode",
"(",
"$",
"scriptCode",
",",
"$",
"dependantResourceUrls",
"=",
"[",
"]",
")",
"{",
"$",
"dependantResourceUrls",
"=",
"array_unique",
"(",
"$",
"dependantResourceUrls",
")",
";",
"self",
"::",
"$",
"resources",
"[",
"]",
"=",
"[",
"$",
"scriptCode",
",",
"$",
"dependantResourceUrls",
"]",
";",
"}"
] |
Adds javascript script code to the collection
@param $scriptCode
@param array $dependantResourceUrls
|
[
"Adds",
"javascript",
"script",
"code",
"to",
"the",
"collection"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Html/ResourceLoader.php#L34-L39
|
27,831
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.addPropertyChangedNotificationHandler
|
final public function addPropertyChangedNotificationHandler($propertyNames, $callback)
{
if (!is_array($propertyNames)) {
$propertyNames = [$propertyNames];
}
foreach ($propertyNames as $propertyName) {
$this->propertyChangedCallbacks[$propertyName][] = $callback;
}
}
|
php
|
final public function addPropertyChangedNotificationHandler($propertyNames, $callback)
{
if (!is_array($propertyNames)) {
$propertyNames = [$propertyNames];
}
foreach ($propertyNames as $propertyName) {
$this->propertyChangedCallbacks[$propertyName][] = $callback;
}
}
|
[
"final",
"public",
"function",
"addPropertyChangedNotificationHandler",
"(",
"$",
"propertyNames",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"propertyNames",
")",
")",
"{",
"$",
"propertyNames",
"=",
"[",
"$",
"propertyNames",
"]",
";",
"}",
"foreach",
"(",
"$",
"propertyNames",
"as",
"$",
"propertyName",
")",
"{",
"$",
"this",
"->",
"propertyChangedCallbacks",
"[",
"$",
"propertyName",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"}"
] |
When the named properties are changed, the callable method provided will be called and passed details of the change.
@param string|string[] $propertyNames The name of a property, or an array of property names
@param callable $callback A callable which will receive 3 parameters: $newValue, $propertyName, $oldValue
|
[
"When",
"the",
"named",
"properties",
"are",
"changed",
"the",
"callable",
"method",
"provided",
"will",
"be",
"called",
"and",
"passed",
"details",
"of",
"the",
"change",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L84-L93
|
27,832
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.setModelValue
|
final protected function setModelValue($propertyName, $value)
{
try {
$oldValue = (isset($this->modelData[$propertyName])) ? $this->modelData[$propertyName]: null;
} catch (\Exception $ex) {
// Catch any exceptions thrown when trying to retrieve the old value for the sake
// of comparison to trigger the property changed handlers.
$oldValue = null;
}
$this->modelData[$propertyName] = $value;
if ($value instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $value);
}
if ($oldValue != $value) {
if (!$this->propertyChangeEventsDisabled) {
// Don't fire changes if they are disabled.
$this->raisePropertyChangedCallbacks($propertyName, $value, $oldValue);
$this->traitRaiseEvent("AfterChange", $this);
}
}
}
|
php
|
final protected function setModelValue($propertyName, $value)
{
try {
$oldValue = (isset($this->modelData[$propertyName])) ? $this->modelData[$propertyName]: null;
} catch (\Exception $ex) {
// Catch any exceptions thrown when trying to retrieve the old value for the sake
// of comparison to trigger the property changed handlers.
$oldValue = null;
}
$this->modelData[$propertyName] = $value;
if ($value instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $value);
}
if ($oldValue != $value) {
if (!$this->propertyChangeEventsDisabled) {
// Don't fire changes if they are disabled.
$this->raisePropertyChangedCallbacks($propertyName, $value, $oldValue);
$this->traitRaiseEvent("AfterChange", $this);
}
}
}
|
[
"final",
"protected",
"function",
"setModelValue",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"oldValue",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"modelData",
"[",
"$",
"propertyName",
"]",
")",
")",
"?",
"$",
"this",
"->",
"modelData",
"[",
"$",
"propertyName",
"]",
":",
"null",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"// Catch any exceptions thrown when trying to retrieve the old value for the sake",
"// of comparison to trigger the property changed handlers.",
"$",
"oldValue",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"modelData",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"instanceof",
"ModelState",
")",
"{",
"$",
"this",
"->",
"attachChangeListenerToModelProperty",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"oldValue",
"!=",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"propertyChangeEventsDisabled",
")",
"{",
"// Don't fire changes if they are disabled.",
"$",
"this",
"->",
"raisePropertyChangedCallbacks",
"(",
"$",
"propertyName",
",",
"$",
"value",
",",
"$",
"oldValue",
")",
";",
"$",
"this",
"->",
"traitRaiseEvent",
"(",
"\"AfterChange\"",
",",
"$",
"this",
")",
";",
"}",
"}",
"}"
] |
Sets a models property value while also raising property changed notifications if appropriate.
This should be used from setters instead of changing $this->modelData directly.
@param $propertyName
@param $value
|
[
"Sets",
"a",
"models",
"property",
"value",
"while",
"also",
"raising",
"property",
"changed",
"notifications",
"if",
"appropriate",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L123-L146
|
27,833
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.exportPublicData
|
final public function exportPublicData()
{
$publicProperties = $this->getPublicPropertyList();
$data = [];
foreach ($publicProperties as $property) {
if (isset($this[$property])) {
$data[$property] = $this[$property];
}
}
return $data;
}
|
php
|
final public function exportPublicData()
{
$publicProperties = $this->getPublicPropertyList();
$data = [];
foreach ($publicProperties as $property) {
if (isset($this[$property])) {
$data[$property] = $this[$property];
}
}
return $data;
}
|
[
"final",
"public",
"function",
"exportPublicData",
"(",
")",
"{",
"$",
"publicProperties",
"=",
"$",
"this",
"->",
"getPublicPropertyList",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"publicProperties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"property",
"]",
"=",
"$",
"this",
"[",
"$",
"property",
"]",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Exports an array of model values that have been marked safe for public consumption.
@return array
|
[
"Exports",
"an",
"array",
"of",
"model",
"values",
"that",
"have",
"been",
"marked",
"safe",
"for",
"public",
"consumption",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L215-L228
|
27,834
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.importData
|
final public function importData($data)
{
foreach ($data as $property => $value) {
if ($this[$property] instanceof ModelState){
$this[$property]->importData($value);
} else {
$this[$property] = $value;
}
}
}
|
php
|
final public function importData($data)
{
foreach ($data as $property => $value) {
if ($this[$property] instanceof ModelState){
$this[$property]->importData($value);
} else {
$this[$property] = $value;
}
}
}
|
[
"final",
"public",
"function",
"importData",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"[",
"$",
"property",
"]",
"instanceof",
"ModelState",
")",
"{",
"$",
"this",
"[",
"$",
"property",
"]",
"->",
"importData",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"[",
"$",
"property",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] |
Imports an array of model values that have been marked safe for public consumption.
@param array $data
|
[
"Imports",
"an",
"array",
"of",
"model",
"values",
"that",
"have",
"been",
"marked",
"safe",
"for",
"public",
"consumption",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L262-L271
|
27,835
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.hasChanged
|
public function hasChanged()
{
foreach ($this->modelData as $property => $value) {
if ($this->hasPropertyChanged($property)) {
return true;
}
}
// In case model data has been manually unset
$manuallyUnsetProperties = array_diff_key($this->changeSnapshotData, $this->modelData);
foreach ($manuallyUnsetProperties as $property => $value) {
// If it wasn't null before, that's a change
if ($value !== null) {
return true;
}
}
return false;
}
|
php
|
public function hasChanged()
{
foreach ($this->modelData as $property => $value) {
if ($this->hasPropertyChanged($property)) {
return true;
}
}
// In case model data has been manually unset
$manuallyUnsetProperties = array_diff_key($this->changeSnapshotData, $this->modelData);
foreach ($manuallyUnsetProperties as $property => $value) {
// If it wasn't null before, that's a change
if ($value !== null) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasChanged",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modelData",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasPropertyChanged",
"(",
"$",
"property",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// In case model data has been manually unset",
"$",
"manuallyUnsetProperties",
"=",
"array_diff_key",
"(",
"$",
"this",
"->",
"changeSnapshotData",
",",
"$",
"this",
"->",
"modelData",
")",
";",
"foreach",
"(",
"$",
"manuallyUnsetProperties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"// If it wasn't null before, that's a change",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the model has changed
@return bool
|
[
"Returns",
"true",
"if",
"the",
"model",
"has",
"changed"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L278-L296
|
27,836
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.takeChangeSnapshot
|
public function takeChangeSnapshot()
{
$this->changeSnapshotData = $this->modelData;
foreach ($this->changeSnapshotData as $key => $value) {
if (is_object($value)) {
$this->changeSnapshotData[$key] = clone $value;
}
}
return $this->changeSnapshotData;
}
|
php
|
public function takeChangeSnapshot()
{
$this->changeSnapshotData = $this->modelData;
foreach ($this->changeSnapshotData as $key => $value) {
if (is_object($value)) {
$this->changeSnapshotData[$key] = clone $value;
}
}
return $this->changeSnapshotData;
}
|
[
"public",
"function",
"takeChangeSnapshot",
"(",
")",
"{",
"$",
"this",
"->",
"changeSnapshotData",
"=",
"$",
"this",
"->",
"modelData",
";",
"foreach",
"(",
"$",
"this",
"->",
"changeSnapshotData",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"changeSnapshotData",
"[",
"$",
"key",
"]",
"=",
"clone",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"changeSnapshotData",
";",
"}"
] |
Takes a snapshot of the model data into change state data.
Essentially this resets the change status on the model object. HasChanged() should return
false after a call to this.
@return array
|
[
"Takes",
"a",
"snapshot",
"of",
"the",
"model",
"data",
"into",
"change",
"state",
"data",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L306-L317
|
27,837
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.importRawData
|
public function importRawData($data)
{
$this->modelData = $data;
foreach ($data as $propertyName => $item) {
if ($item instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $item);
}
}
// Make sure we can track changes in existing models.
$this->takeChangeSnapshot();
$this->onDataImported();
}
|
php
|
public function importRawData($data)
{
$this->modelData = $data;
foreach ($data as $propertyName => $item) {
if ($item instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $item);
}
}
// Make sure we can track changes in existing models.
$this->takeChangeSnapshot();
$this->onDataImported();
}
|
[
"public",
"function",
"importRawData",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"modelData",
"=",
"$",
"data",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"propertyName",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"ModelState",
")",
"{",
"$",
"this",
"->",
"attachChangeListenerToModelProperty",
"(",
"$",
"propertyName",
",",
"$",
"item",
")",
";",
"}",
"}",
"// Make sure we can track changes in existing models.",
"$",
"this",
"->",
"takeChangeSnapshot",
"(",
")",
";",
"$",
"this",
"->",
"onDataImported",
"(",
")",
";",
"}"
] |
Imports raw model data into the model.
The data does not pass through any applicable Set methods or data transforms. If required to do so
call ImportData() instead, but understand the performance penalty of doing so.
@param array $data
|
[
"Imports",
"raw",
"model",
"data",
"into",
"the",
"model",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L423-L437
|
27,838
|
RhubarbPHP/Rhubarb
|
src/Modelling/ModelState.php
|
ModelState.attachChangeListenerToModelProperty
|
private function attachChangeListenerToModelProperty($propertyName, ModelState $item)
{
$item->clearEventHandlers();
$item->attachEventHandler("AfterChange", function () use ($propertyName, $item) {
$this->raisePropertyChangedCallbacks($propertyName, $item, null);
});
}
|
php
|
private function attachChangeListenerToModelProperty($propertyName, ModelState $item)
{
$item->clearEventHandlers();
$item->attachEventHandler("AfterChange", function () use ($propertyName, $item) {
$this->raisePropertyChangedCallbacks($propertyName, $item, null);
});
}
|
[
"private",
"function",
"attachChangeListenerToModelProperty",
"(",
"$",
"propertyName",
",",
"ModelState",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"clearEventHandlers",
"(",
")",
";",
"$",
"item",
"->",
"attachEventHandler",
"(",
"\"AfterChange\"",
",",
"function",
"(",
")",
"use",
"(",
"$",
"propertyName",
",",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"raisePropertyChangedCallbacks",
"(",
"$",
"propertyName",
",",
"$",
"item",
",",
"null",
")",
";",
"}",
")",
";",
"}"
] |
Attaches a change listener to the model state item and raises a property changed notification when that happens.
@param $propertyName
@param ModelState $item
|
[
"Attaches",
"a",
"change",
"listener",
"to",
"the",
"model",
"state",
"item",
"and",
"raises",
"a",
"property",
"changed",
"notification",
"when",
"that",
"happens",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L445-L451
|
27,839
|
RhubarbPHP/Rhubarb
|
src/DependencyInjection/Container.php
|
Container.getInstance
|
public final function getInstance($requestedClass, ...$arguments)
{
if (isset($this->singletons[$requestedClass])){
return $this->singletons[$requestedClass];
}
$useSingleton = false;
// Check for singletons first as they should trump previous registrations of non
// singleton mappings.
if (isset($this->concreteClassMappings['_'.$requestedClass])) {
$class = $this->concreteClassMappings['_'.$requestedClass];
$useSingleton = true;
} elseif (isset($this->concreteClassMappings[$requestedClass])){
$class = $this->concreteClassMappings[$requestedClass];
} else {
$class = $requestedClass;
}
$reflection = new \ReflectionClass($class);
if ($reflection->isAbstract()){
throw new ClassMappingException($class);
}
$constructor = $reflection->getConstructor();
if ($constructor == null){
// No defined constructor so exit simply with a new instance.
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = $this->generateInstanceFromConstructor($reflection, $constructor, $arguments);
}
if ($useSingleton) {
$this->singletons[$requestedClass] = $instance;
}
return $instance;
}
|
php
|
public final function getInstance($requestedClass, ...$arguments)
{
if (isset($this->singletons[$requestedClass])){
return $this->singletons[$requestedClass];
}
$useSingleton = false;
// Check for singletons first as they should trump previous registrations of non
// singleton mappings.
if (isset($this->concreteClassMappings['_'.$requestedClass])) {
$class = $this->concreteClassMappings['_'.$requestedClass];
$useSingleton = true;
} elseif (isset($this->concreteClassMappings[$requestedClass])){
$class = $this->concreteClassMappings[$requestedClass];
} else {
$class = $requestedClass;
}
$reflection = new \ReflectionClass($class);
if ($reflection->isAbstract()){
throw new ClassMappingException($class);
}
$constructor = $reflection->getConstructor();
if ($constructor == null){
// No defined constructor so exit simply with a new instance.
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = $this->generateInstanceFromConstructor($reflection, $constructor, $arguments);
}
if ($useSingleton) {
$this->singletons[$requestedClass] = $instance;
}
return $instance;
}
|
[
"public",
"final",
"function",
"getInstance",
"(",
"$",
"requestedClass",
",",
"...",
"$",
"arguments",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
";",
"}",
"$",
"useSingleton",
"=",
"false",
";",
"// Check for singletons first as they should trump previous registrations of non",
"// singleton mappings.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"concreteClassMappings",
"[",
"'_'",
".",
"$",
"requestedClass",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"concreteClassMappings",
"[",
"'_'",
".",
"$",
"requestedClass",
"]",
";",
"$",
"useSingleton",
"=",
"true",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"concreteClassMappings",
"[",
"$",
"requestedClass",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"concreteClassMappings",
"[",
"$",
"requestedClass",
"]",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"$",
"requestedClass",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isAbstract",
"(",
")",
")",
"{",
"throw",
"new",
"ClassMappingException",
"(",
"$",
"class",
")",
";",
"}",
"$",
"constructor",
"=",
"$",
"reflection",
"->",
"getConstructor",
"(",
")",
";",
"if",
"(",
"$",
"constructor",
"==",
"null",
")",
"{",
"// No defined constructor so exit simply with a new instance.",
"$",
"instance",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"arguments",
")",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"generateInstanceFromConstructor",
"(",
"$",
"reflection",
",",
"$",
"constructor",
",",
"$",
"arguments",
")",
";",
"}",
"if",
"(",
"$",
"useSingleton",
")",
"{",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Creates an object instance of the requested class, optionally passing additional constructor arguments
@param $requestedClass
@param ...$arguments
@return mixed|object
|
[
"Creates",
"an",
"object",
"instance",
"of",
"the",
"requested",
"class",
"optionally",
"passing",
"additional",
"constructor",
"arguments"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/DependencyInjection/Container.php#L76-L115
|
27,840
|
RhubarbPHP/Rhubarb
|
src/DependencyInjection/Container.php
|
Container.getSingleton
|
public function getSingleton($requestedClass, callable $singletonCreationCallback = null)
{
if (!isset($this->singletons[$requestedClass])){
if ($singletonCreationCallback){
$singleton = $singletonCreationCallback;
} else {
$singleton = $this->instance($requestedClass);
}
$this->singletons[$requestedClass] = $singleton;
$this->concreteClassMappings["_".$requestedClass] = $requestedClass;
}
if (is_callable($this->singletons[$requestedClass])){
$callback = $this->singletons[$requestedClass];
$this->singletons[$requestedClass] = $callback();
}
return $this->singletons[$requestedClass];
}
|
php
|
public function getSingleton($requestedClass, callable $singletonCreationCallback = null)
{
if (!isset($this->singletons[$requestedClass])){
if ($singletonCreationCallback){
$singleton = $singletonCreationCallback;
} else {
$singleton = $this->instance($requestedClass);
}
$this->singletons[$requestedClass] = $singleton;
$this->concreteClassMappings["_".$requestedClass] = $requestedClass;
}
if (is_callable($this->singletons[$requestedClass])){
$callback = $this->singletons[$requestedClass];
$this->singletons[$requestedClass] = $callback();
}
return $this->singletons[$requestedClass];
}
|
[
"public",
"function",
"getSingleton",
"(",
"$",
"requestedClass",
",",
"callable",
"$",
"singletonCreationCallback",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
")",
")",
"{",
"if",
"(",
"$",
"singletonCreationCallback",
")",
"{",
"$",
"singleton",
"=",
"$",
"singletonCreationCallback",
";",
"}",
"else",
"{",
"$",
"singleton",
"=",
"$",
"this",
"->",
"instance",
"(",
"$",
"requestedClass",
")",
";",
"}",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
"=",
"$",
"singleton",
";",
"$",
"this",
"->",
"concreteClassMappings",
"[",
"\"_\"",
".",
"$",
"requestedClass",
"]",
"=",
"$",
"requestedClass",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
";",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
"=",
"$",
"callback",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
";",
"}"
] |
Creates a singleton object instance of the requested class from the current DI container
@see getInstance()
@param $requestedClass
@param ...$arguments
@return mixed
|
[
"Creates",
"a",
"singleton",
"object",
"instance",
"of",
"the",
"requested",
"class",
"from",
"the",
"current",
"DI",
"container"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/DependencyInjection/Container.php#L151-L170
|
27,841
|
glorpen/GlorpenPropelBundle
|
src/Services/OMClassOverrider.php
|
OMClassOverrider.getExtendedClass
|
public function getExtendedClass($class)
{
$ret = null;
if (array_key_exists($class, $this->dynamicClasses)) {
$ret = $this->dynamicClasses[$class];
}
if (!$ret) {
$ret = array_search($class, $this->classes);
}
return $ret?$ret:null;
}
|
php
|
public function getExtendedClass($class)
{
$ret = null;
if (array_key_exists($class, $this->dynamicClasses)) {
$ret = $this->dynamicClasses[$class];
}
if (!$ret) {
$ret = array_search($class, $this->classes);
}
return $ret?$ret:null;
}
|
[
"public",
"function",
"getExtendedClass",
"(",
"$",
"class",
")",
"{",
"$",
"ret",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"dynamicClasses",
")",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"dynamicClasses",
"[",
"$",
"class",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"ret",
")",
"{",
"$",
"ret",
"=",
"array_search",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"classes",
")",
";",
"}",
"return",
"$",
"ret",
"?",
"$",
"ret",
":",
"null",
";",
"}"
] |
Returns base class
@param string $class
@return string
|
[
"Returns",
"base",
"class"
] |
b679c83377c81ab582de179f84bc23eaeb1e86aa
|
https://github.com/glorpen/GlorpenPropelBundle/blob/b679c83377c81ab582de179f84bc23eaeb1e86aa/src/Services/OMClassOverrider.php#L59-L69
|
27,842
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.reset
|
protected function reset()
{
$this->element = null;
$this->arguments = [];
$this->methods = [];
$this->cloneElement = false;
$this->translatableIndicator = false;
return $this;
}
|
php
|
protected function reset()
{
$this->element = null;
$this->arguments = [];
$this->methods = [];
$this->cloneElement = false;
$this->translatableIndicator = false;
return $this;
}
|
[
"protected",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"null",
";",
"$",
"this",
"->",
"arguments",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"methods",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"cloneElement",
"=",
"false",
";",
"$",
"this",
"->",
"translatableIndicator",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] |
Resets the properties.
@return $this
|
[
"Resets",
"the",
"properties",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L171-L180
|
27,843
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.locales
|
public function locales(array $locales = null)
{
return is_null($locales)
? $this->locales
: ($this->locales = $locales);
}
|
php
|
public function locales(array $locales = null)
{
return is_null($locales)
? $this->locales
: ($this->locales = $locales);
}
|
[
"public",
"function",
"locales",
"(",
"array",
"$",
"locales",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"locales",
")",
"?",
"$",
"this",
"->",
"locales",
":",
"(",
"$",
"this",
"->",
"locales",
"=",
"$",
"locales",
")",
";",
"}"
] |
Get or set the available locales.
@param array|null $locales
@return array
|
[
"Get",
"or",
"set",
"the",
"available",
"locales",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L189-L194
|
27,844
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.element
|
protected function element($element = null)
{
return is_null($element)
? $this->element
: ($this->element = $element);
}
|
php
|
protected function element($element = null)
{
return is_null($element)
? $this->element
: ($this->element = $element);
}
|
[
"protected",
"function",
"element",
"(",
"$",
"element",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"element",
")",
"?",
"$",
"this",
"->",
"element",
":",
"(",
"$",
"this",
"->",
"element",
"=",
"$",
"element",
")",
";",
"}"
] |
Get or set the current element.
@param string|null $element
@return string
|
[
"Get",
"or",
"set",
"the",
"current",
"element",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L203-L208
|
27,845
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.arguments
|
protected function arguments(array $arguments = null)
{
return is_null($arguments)
? $this->arguments
: ($this->arguments = $arguments);
}
|
php
|
protected function arguments(array $arguments = null)
{
return is_null($arguments)
? $this->arguments
: ($this->arguments = $arguments);
}
|
[
"protected",
"function",
"arguments",
"(",
"array",
"$",
"arguments",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"arguments",
")",
"?",
"$",
"this",
"->",
"arguments",
":",
"(",
"$",
"this",
"->",
"arguments",
"=",
"$",
"arguments",
")",
";",
"}"
] |
Get or set the arguments.
@param array|null $arguments
@return array
|
[
"Get",
"or",
"set",
"the",
"arguments",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L217-L222
|
27,846
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.methods
|
protected function methods(array $methods = null)
{
return is_null($methods)
? $this->methods
: ($this->methods = $methods);
}
|
php
|
protected function methods(array $methods = null)
{
return is_null($methods)
? $this->methods
: ($this->methods = $methods);
}
|
[
"protected",
"function",
"methods",
"(",
"array",
"$",
"methods",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"methods",
")",
"?",
"$",
"this",
"->",
"methods",
":",
"(",
"$",
"this",
"->",
"methods",
"=",
"$",
"methods",
")",
";",
"}"
] |
Get or set the methods.
@param array|null $methods
@return array
|
[
"Get",
"or",
"set",
"the",
"methods",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L231-L236
|
27,847
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.translatableIndicator
|
protected function translatableIndicator($add = null)
{
return is_null($add)
? $this->translatableIndicator
: ($this->translatableIndicator = (bool) $add);
}
|
php
|
protected function translatableIndicator($add = null)
{
return is_null($add)
? $this->translatableIndicator
: ($this->translatableIndicator = (bool) $add);
}
|
[
"protected",
"function",
"translatableIndicator",
"(",
"$",
"add",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"add",
")",
"?",
"$",
"this",
"->",
"translatableIndicator",
":",
"(",
"$",
"this",
"->",
"translatableIndicator",
"=",
"(",
"bool",
")",
"$",
"add",
")",
";",
"}"
] |
Get or set the translatable indicator boolean.
@param bool|null $add
@return bool
|
[
"Get",
"or",
"set",
"the",
"translatable",
"indicator",
"boolean",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L259-L264
|
27,848
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.overwriteArgument
|
protected function overwriteArgument($argument, $value)
{
$arguments = $this->arguments();
$arguments[$argument] = $value;
$this->arguments($arguments);
}
|
php
|
protected function overwriteArgument($argument, $value)
{
$arguments = $this->arguments();
$arguments[$argument] = $value;
$this->arguments($arguments);
}
|
[
"protected",
"function",
"overwriteArgument",
"(",
"$",
"argument",
",",
"$",
"value",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"arguments",
"(",
")",
";",
"$",
"arguments",
"[",
"$",
"argument",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"arguments",
"(",
"$",
"arguments",
")",
";",
"}"
] |
Overwrites an argument.
@param string $argument
@param string|array $value
|
[
"Overwrites",
"an",
"argument",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L272-L279
|
27,849
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.addMethod
|
protected function addMethod($name, $parameters)
{
$methods = $this->methods();
$parameters = is_array($parameters) ? $parameters : [$parameters];
$methods[] = compact('name', 'parameters');
$this->methods($methods);
}
|
php
|
protected function addMethod($name, $parameters)
{
$methods = $this->methods();
$parameters = is_array($parameters) ? $parameters : [$parameters];
$methods[] = compact('name', 'parameters');
$this->methods($methods);
}
|
[
"protected",
"function",
"addMethod",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"methods",
"(",
")",
";",
"$",
"parameters",
"=",
"is_array",
"(",
"$",
"parameters",
")",
"?",
"$",
"parameters",
":",
"[",
"$",
"parameters",
"]",
";",
"$",
"methods",
"[",
"]",
"=",
"compact",
"(",
"'name'",
",",
"'parameters'",
")",
";",
"$",
"this",
"->",
"methods",
"(",
"$",
"methods",
")",
";",
"}"
] |
Adds a method.
@param string $name
@param string|array $parameters
|
[
"Adds",
"a",
"method",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L287-L296
|
27,850
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.createInput
|
protected function createInput($currentLocale = null)
{
// Create element using arguments.
$element = call_user_func_array([$this->form, $this->element()], array_values($this->arguments()));
// Elements such as 'bind' do not return renderable stuff and do not accept methods.
if ($element) {
// Apply requested methods.
foreach ($this->methods() as $method) {
$methodName = $method['name'];
$methodParameters = $method['parameters'];
// Check if method is locale-specific.
if (ends_with($methodName, 'ForLocale')) {
$methodName = strstr($methodName, 'ForLocale', true);
$locales = array_shift($methodParameters);
$locales = is_array($locales) ? $locales : [$locales];
if (!is_null($currentLocale) && !in_array($currentLocale, $locales)) {
// Method should not be applied for this locale.
continue;
}
}
// Call method.
if (!empty($methodParameters)) {
call_user_func_array([$element, $methodName], $this->replacePlaceholdersRecursively($methodParameters, $currentLocale));
} else {
$element->{$methodName}();
}
}
}
return $element;
}
|
php
|
protected function createInput($currentLocale = null)
{
// Create element using arguments.
$element = call_user_func_array([$this->form, $this->element()], array_values($this->arguments()));
// Elements such as 'bind' do not return renderable stuff and do not accept methods.
if ($element) {
// Apply requested methods.
foreach ($this->methods() as $method) {
$methodName = $method['name'];
$methodParameters = $method['parameters'];
// Check if method is locale-specific.
if (ends_with($methodName, 'ForLocale')) {
$methodName = strstr($methodName, 'ForLocale', true);
$locales = array_shift($methodParameters);
$locales = is_array($locales) ? $locales : [$locales];
if (!is_null($currentLocale) && !in_array($currentLocale, $locales)) {
// Method should not be applied for this locale.
continue;
}
}
// Call method.
if (!empty($methodParameters)) {
call_user_func_array([$element, $methodName], $this->replacePlaceholdersRecursively($methodParameters, $currentLocale));
} else {
$element->{$methodName}();
}
}
}
return $element;
}
|
[
"protected",
"function",
"createInput",
"(",
"$",
"currentLocale",
"=",
"null",
")",
"{",
"// Create element using arguments.",
"$",
"element",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"form",
",",
"$",
"this",
"->",
"element",
"(",
")",
"]",
",",
"array_values",
"(",
"$",
"this",
"->",
"arguments",
"(",
")",
")",
")",
";",
"// Elements such as 'bind' do not return renderable stuff and do not accept methods.",
"if",
"(",
"$",
"element",
")",
"{",
"// Apply requested methods.",
"foreach",
"(",
"$",
"this",
"->",
"methods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"methodName",
"=",
"$",
"method",
"[",
"'name'",
"]",
";",
"$",
"methodParameters",
"=",
"$",
"method",
"[",
"'parameters'",
"]",
";",
"// Check if method is locale-specific.",
"if",
"(",
"ends_with",
"(",
"$",
"methodName",
",",
"'ForLocale'",
")",
")",
"{",
"$",
"methodName",
"=",
"strstr",
"(",
"$",
"methodName",
",",
"'ForLocale'",
",",
"true",
")",
";",
"$",
"locales",
"=",
"array_shift",
"(",
"$",
"methodParameters",
")",
";",
"$",
"locales",
"=",
"is_array",
"(",
"$",
"locales",
")",
"?",
"$",
"locales",
":",
"[",
"$",
"locales",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"currentLocale",
")",
"&&",
"!",
"in_array",
"(",
"$",
"currentLocale",
",",
"$",
"locales",
")",
")",
"{",
"// Method should not be applied for this locale.",
"continue",
";",
"}",
"}",
"// Call method.",
"if",
"(",
"!",
"empty",
"(",
"$",
"methodParameters",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"element",
",",
"$",
"methodName",
"]",
",",
"$",
"this",
"->",
"replacePlaceholdersRecursively",
"(",
"$",
"methodParameters",
",",
"$",
"currentLocale",
")",
")",
";",
"}",
"else",
"{",
"$",
"element",
"->",
"{",
"$",
"methodName",
"}",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"element",
";",
"}"
] |
Creates an input element using the supplied arguments and methods.
@param string|null $currentLocale
@return mixed
|
[
"Creates",
"an",
"input",
"element",
"using",
"the",
"supplied",
"arguments",
"and",
"methods",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L361-L394
|
27,851
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.applyElementBehavior
|
protected function applyElementBehavior()
{
$behaviors = isset($this->elementBehaviors[$this->element()]) ? $this->elementBehaviors[$this->element()] : [];
foreach ($behaviors as $behavior) {
$this->{$behavior}(true);
}
}
|
php
|
protected function applyElementBehavior()
{
$behaviors = isset($this->elementBehaviors[$this->element()]) ? $this->elementBehaviors[$this->element()] : [];
foreach ($behaviors as $behavior) {
$this->{$behavior}(true);
}
}
|
[
"protected",
"function",
"applyElementBehavior",
"(",
")",
"{",
"$",
"behaviors",
"=",
"isset",
"(",
"$",
"this",
"->",
"elementBehaviors",
"[",
"$",
"this",
"->",
"element",
"(",
")",
"]",
")",
"?",
"$",
"this",
"->",
"elementBehaviors",
"[",
"$",
"this",
"->",
"element",
"(",
")",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"behaviors",
"as",
"$",
"behavior",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"behavior",
"}",
"(",
"true",
")",
";",
"}",
"}"
] |
Add specific element behavior to the current translatable form element.
|
[
"Add",
"specific",
"element",
"behavior",
"to",
"the",
"current",
"translatable",
"form",
"element",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L418-L425
|
27,852
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.mapArguments
|
protected function mapArguments(array $arguments)
{
$keys = isset($this->mappableArguments[$this->element()]) ? $this->mappableArguments[$this->element()] : [];
return array_combine(array_slice($keys, 0, count($arguments)), $arguments);
}
|
php
|
protected function mapArguments(array $arguments)
{
$keys = isset($this->mappableArguments[$this->element()]) ? $this->mappableArguments[$this->element()] : [];
return array_combine(array_slice($keys, 0, count($arguments)), $arguments);
}
|
[
"protected",
"function",
"mapArguments",
"(",
"array",
"$",
"arguments",
")",
"{",
"$",
"keys",
"=",
"isset",
"(",
"$",
"this",
"->",
"mappableArguments",
"[",
"$",
"this",
"->",
"element",
"(",
")",
"]",
")",
"?",
"$",
"this",
"->",
"mappableArguments",
"[",
"$",
"this",
"->",
"element",
"(",
")",
"]",
":",
"[",
"]",
";",
"return",
"array_combine",
"(",
"array_slice",
"(",
"$",
"keys",
",",
"0",
",",
"count",
"(",
"$",
"arguments",
")",
")",
",",
"$",
"arguments",
")",
";",
"}"
] |
Maps the form element arguments to their name.
@param array $arguments
@return array
|
[
"Maps",
"the",
"form",
"element",
"arguments",
"to",
"their",
"name",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L434-L439
|
27,853
|
TypiCMS/Laravel-Translatable-Bootforms
|
src/TranslatableBootForm.php
|
TranslatableBootForm.setTranslatableLabelIndicator
|
protected function setTranslatableLabelIndicator($locale)
{
$localizedLabel = str_replace('%label', $this->arguments()['label'], $this->config['label-locale-indicator']);
$this->overwriteArgument('label', str_replace('%locale', $locale, $localizedLabel));
}
|
php
|
protected function setTranslatableLabelIndicator($locale)
{
$localizedLabel = str_replace('%label', $this->arguments()['label'], $this->config['label-locale-indicator']);
$this->overwriteArgument('label', str_replace('%locale', $locale, $localizedLabel));
}
|
[
"protected",
"function",
"setTranslatableLabelIndicator",
"(",
"$",
"locale",
")",
"{",
"$",
"localizedLabel",
"=",
"str_replace",
"(",
"'%label'",
",",
"$",
"this",
"->",
"arguments",
"(",
")",
"[",
"'label'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'label-locale-indicator'",
"]",
")",
";",
"$",
"this",
"->",
"overwriteArgument",
"(",
"'label'",
",",
"str_replace",
"(",
"'%locale'",
",",
"$",
"locale",
",",
"$",
"localizedLabel",
")",
")",
";",
"}"
] |
Add a locale indicator to the label.
@param string $locale
|
[
"Add",
"a",
"locale",
"indicator",
"to",
"the",
"label",
"."
] |
c1c877cff1aed4b8a827fc6b064bfb7832a423ec
|
https://github.com/TypiCMS/Laravel-Translatable-Bootforms/blob/c1c877cff1aed4b8a827fc6b064bfb7832a423ec/src/TranslatableBootForm.php#L446-L450
|
27,854
|
RhubarbPHP/Rhubarb
|
src/Deployment/ResourceDeploymentPackage.php
|
ResourceDeploymentPackage.getDeployedUrls
|
public function getDeployedUrls()
{
$deploymentHandler = ResourceDeploymentProvider::getProvider();
$urls = [];
foreach ($this->resourcesToDeploy as $path) {
$urls[] = $deploymentHandler->getDeployedResourceUrl($path);
}
return $urls;
}
|
php
|
public function getDeployedUrls()
{
$deploymentHandler = ResourceDeploymentProvider::getProvider();
$urls = [];
foreach ($this->resourcesToDeploy as $path) {
$urls[] = $deploymentHandler->getDeployedResourceUrl($path);
}
return $urls;
}
|
[
"public",
"function",
"getDeployedUrls",
"(",
")",
"{",
"$",
"deploymentHandler",
"=",
"ResourceDeploymentProvider",
"::",
"getProvider",
"(",
")",
";",
"$",
"urls",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"resourcesToDeploy",
"as",
"$",
"path",
")",
"{",
"$",
"urls",
"[",
"]",
"=",
"$",
"deploymentHandler",
"->",
"getDeployedResourceUrl",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"urls",
";",
"}"
] |
Returns the urls with which the resources can be accessed after deployment.
|
[
"Returns",
"the",
"urls",
"with",
"which",
"the",
"resources",
"can",
"be",
"accessed",
"after",
"deployment",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Deployment/ResourceDeploymentPackage.php#L33-L44
|
27,855
|
RhubarbPHP/Rhubarb
|
src/Application.php
|
Application.registerModule
|
public final function registerModule(Module $module)
{
$dependencies = $module->getModules();
foreach($dependencies as $dependency){
$this->registerModule($dependency);
}
$this->modules[$module->getModuleName()] = $module;
}
|
php
|
public final function registerModule(Module $module)
{
$dependencies = $module->getModules();
foreach($dependencies as $dependency){
$this->registerModule($dependency);
}
$this->modules[$module->getModuleName()] = $module;
}
|
[
"public",
"final",
"function",
"registerModule",
"(",
"Module",
"$",
"module",
")",
"{",
"$",
"dependencies",
"=",
"$",
"module",
"->",
"getModules",
"(",
")",
";",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"$",
"this",
"->",
"registerModule",
"(",
"$",
"dependency",
")",
";",
"}",
"$",
"this",
"->",
"modules",
"[",
"$",
"module",
"->",
"getModuleName",
"(",
")",
"]",
"=",
"$",
"module",
";",
"}"
] |
Register a module with the application.
Also registers the dependencies of the application also
@param Module $module
|
[
"Register",
"a",
"module",
"with",
"the",
"application",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Application.php#L214-L223
|
27,856
|
RhubarbPHP/Rhubarb
|
src/Application.php
|
Application.filterUrlHandlers
|
public final function filterUrlHandlers($handlerSet)
{
$filteredHandlers = [];
foreach ($handlerSet as $handlers) {
$filteredHandlers = array_merge($filteredHandlers, $handlers);
}
uasort($filteredHandlers, function (UrlHandler $a, UrlHandler $b) {
$aPriority = $a->getPriority();
$bPriority = $b->getPriority();
if ($aPriority == $bPriority) {
return ($a->getCreationOrder() > $b->getCreationOrder());
}
return ($aPriority <= $bPriority);
});
return $filteredHandlers;
}
|
php
|
public final function filterUrlHandlers($handlerSet)
{
$filteredHandlers = [];
foreach ($handlerSet as $handlers) {
$filteredHandlers = array_merge($filteredHandlers, $handlers);
}
uasort($filteredHandlers, function (UrlHandler $a, UrlHandler $b) {
$aPriority = $a->getPriority();
$bPriority = $b->getPriority();
if ($aPriority == $bPriority) {
return ($a->getCreationOrder() > $b->getCreationOrder());
}
return ($aPriority <= $bPriority);
});
return $filteredHandlers;
}
|
[
"public",
"final",
"function",
"filterUrlHandlers",
"(",
"$",
"handlerSet",
")",
"{",
"$",
"filteredHandlers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"handlerSet",
"as",
"$",
"handlers",
")",
"{",
"$",
"filteredHandlers",
"=",
"array_merge",
"(",
"$",
"filteredHandlers",
",",
"$",
"handlers",
")",
";",
"}",
"uasort",
"(",
"$",
"filteredHandlers",
",",
"function",
"(",
"UrlHandler",
"$",
"a",
",",
"UrlHandler",
"$",
"b",
")",
"{",
"$",
"aPriority",
"=",
"$",
"a",
"->",
"getPriority",
"(",
")",
";",
"$",
"bPriority",
"=",
"$",
"b",
"->",
"getPriority",
"(",
")",
";",
"if",
"(",
"$",
"aPriority",
"==",
"$",
"bPriority",
")",
"{",
"return",
"(",
"$",
"a",
"->",
"getCreationOrder",
"(",
")",
">",
"$",
"b",
"->",
"getCreationOrder",
"(",
")",
")",
";",
"}",
"return",
"(",
"$",
"aPriority",
"<=",
"$",
"bPriority",
")",
";",
"}",
")",
";",
"return",
"$",
"filteredHandlers",
";",
"}"
] |
Get's an array of url handlers from all registered modules.
@param UrlHandler[] $handlerSet
@return UrlHandler[]
|
[
"Get",
"s",
"an",
"array",
"of",
"url",
"handlers",
"from",
"all",
"registered",
"modules",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Application.php#L239-L259
|
27,857
|
RhubarbPHP/Rhubarb
|
src/Application.php
|
Application.initialiseModules
|
public final function initialiseModules()
{
foreach ($this->modules as $module) {
$module->initialiseModule();
}
// Initialise the application 'module' itself.
$this->initialiseModule();
$handlers = [];
foreach ($this->modules as $module) {
$handlers[] = $module->getUrlHandlers();
}
$this->rootHandlers = $this->filterUrlHandlers($handlers);
}
|
php
|
public final function initialiseModules()
{
foreach ($this->modules as $module) {
$module->initialiseModule();
}
// Initialise the application 'module' itself.
$this->initialiseModule();
$handlers = [];
foreach ($this->modules as $module) {
$handlers[] = $module->getUrlHandlers();
}
$this->rootHandlers = $this->filterUrlHandlers($handlers);
}
|
[
"public",
"final",
"function",
"initialiseModules",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"initialiseModule",
"(",
")",
";",
"}",
"// Initialise the application 'module' itself.",
"$",
"this",
"->",
"initialiseModule",
"(",
")",
";",
"$",
"handlers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"handlers",
"[",
"]",
"=",
"$",
"module",
"->",
"getUrlHandlers",
"(",
")",
";",
"}",
"$",
"this",
"->",
"rootHandlers",
"=",
"$",
"this",
"->",
"filterUrlHandlers",
"(",
"$",
"handlers",
")",
";",
"}"
] |
Asks all modules to initialise.
Called automatically when processing requests.
|
[
"Asks",
"all",
"modules",
"to",
"initialise",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Application.php#L266-L281
|
27,858
|
RhubarbPHP/Rhubarb
|
src/Application.php
|
Application.getAllResponseFilters
|
private function getAllResponseFilters($preResponse = false)
{
$filters = [];
foreach ($this->modules as $module) {
$moduleFilters = $module->getResponseFilters();
foreach($moduleFilters as $filter){
if ($preResponse && $filter->isPreResponse()){
$filters[] = $filter;
} elseif (!$preResponse && !$filter->isPreResponse()){
$filters[] = $filter;
}
}
}
return $filters;
}
|
php
|
private function getAllResponseFilters($preResponse = false)
{
$filters = [];
foreach ($this->modules as $module) {
$moduleFilters = $module->getResponseFilters();
foreach($moduleFilters as $filter){
if ($preResponse && $filter->isPreResponse()){
$filters[] = $filter;
} elseif (!$preResponse && !$filter->isPreResponse()){
$filters[] = $filter;
}
}
}
return $filters;
}
|
[
"private",
"function",
"getAllResponseFilters",
"(",
"$",
"preResponse",
"=",
"false",
")",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"moduleFilters",
"=",
"$",
"module",
"->",
"getResponseFilters",
"(",
")",
";",
"foreach",
"(",
"$",
"moduleFilters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"preResponse",
"&&",
"$",
"filter",
"->",
"isPreResponse",
"(",
")",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"$",
"filter",
";",
"}",
"elseif",
"(",
"!",
"$",
"preResponse",
"&&",
"!",
"$",
"filter",
"->",
"isPreResponse",
"(",
")",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"$",
"filter",
";",
"}",
"}",
"}",
"return",
"$",
"filters",
";",
"}"
] |
Get's an array of response filters from all registered modules.
@return \Rhubarb\Crown\ResponseFilters\ResponseFilter[]
|
[
"Get",
"s",
"an",
"array",
"of",
"response",
"filters",
"from",
"all",
"registered",
"modules",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Application.php#L288-L306
|
27,859
|
zibios/wrike-php-guzzle
|
src/Client/GuzzleClient.php
|
GuzzleClient.executeRequestForParams
|
public function executeRequestForParams(
string $requestMethod,
string $path,
array $params,
string $accessToken
): ResponseInterface {
RequestMethodEnum::assertIsValidValue($requestMethod);
$options = $this->calculateOptionsForParams($requestMethod, $params, $accessToken);
if (RequestMethodEnum::UPLOAD === $requestMethod) {
$requestMethod = RequestMethodEnum::POST;
}
return $this->request($requestMethod, $path, $options);
}
|
php
|
public function executeRequestForParams(
string $requestMethod,
string $path,
array $params,
string $accessToken
): ResponseInterface {
RequestMethodEnum::assertIsValidValue($requestMethod);
$options = $this->calculateOptionsForParams($requestMethod, $params, $accessToken);
if (RequestMethodEnum::UPLOAD === $requestMethod) {
$requestMethod = RequestMethodEnum::POST;
}
return $this->request($requestMethod, $path, $options);
}
|
[
"public",
"function",
"executeRequestForParams",
"(",
"string",
"$",
"requestMethod",
",",
"string",
"$",
"path",
",",
"array",
"$",
"params",
",",
"string",
"$",
"accessToken",
")",
":",
"ResponseInterface",
"{",
"RequestMethodEnum",
"::",
"assertIsValidValue",
"(",
"$",
"requestMethod",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"calculateOptionsForParams",
"(",
"$",
"requestMethod",
",",
"$",
"params",
",",
"$",
"accessToken",
")",
";",
"if",
"(",
"RequestMethodEnum",
"::",
"UPLOAD",
"===",
"$",
"requestMethod",
")",
"{",
"$",
"requestMethod",
"=",
"RequestMethodEnum",
"::",
"POST",
";",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"requestMethod",
",",
"$",
"path",
",",
"$",
"options",
")",
";",
"}"
] |
Request method.
Generic format for HTTP client request method.
@param string $requestMethod GET/POST/PUT/DELETE
@param string $path full path to REST resource without domain, ex. 'contacts'
@param array $params optional params for GET/POST request
@param string $accessToken Access Token for Wrike access
@see \Zibios\WrikePhpLibrary\Enum\Api\RequestMethodEnum
@see \Zibios\WrikePhpLibrary\Enum\Api\RequestPathFormatEnum
@throws \Throwable
@throws ApiException
@return ResponseInterface
|
[
"Request",
"method",
"."
] |
957319ba26020b207e756699708e865d61b7da2f
|
https://github.com/zibios/wrike-php-guzzle/blob/957319ba26020b207e756699708e865d61b7da2f/src/Client/GuzzleClient.php#L47-L60
|
27,860
|
zibios/wrike-php-guzzle
|
src/Client/GuzzleClient.php
|
GuzzleClient.calculateOptionsForParams
|
protected function calculateOptionsForParams(string $requestMethod, array $params, string $accessToken): array
{
$options = $this->prepareBaseOptions($accessToken);
if (0 === \count($params)) {
return $options;
}
switch ($requestMethod) {
case RequestMethodEnum::GET:
case RequestMethodEnum::DELETE:
$options['query'] = $params;
break;
case RequestMethodEnum::PUT:
case RequestMethodEnum::POST:
$options['form_params'] = $params;
break;
case RequestMethodEnum::UPLOAD:
if (array_key_exists('resource', $params) && array_key_exists('name', $params)) {
$options['headers']['X-File-Name'] = $params['name'];
$options['multipart'] = [
[
'contents' => $params['resource'],
'name' => $params['name'],
],
];
}
break;
default:
throw new \InvalidArgumentException(sprintf('Request method "%s" not allowed!', $requestMethod));
}
return $options;
}
|
php
|
protected function calculateOptionsForParams(string $requestMethod, array $params, string $accessToken): array
{
$options = $this->prepareBaseOptions($accessToken);
if (0 === \count($params)) {
return $options;
}
switch ($requestMethod) {
case RequestMethodEnum::GET:
case RequestMethodEnum::DELETE:
$options['query'] = $params;
break;
case RequestMethodEnum::PUT:
case RequestMethodEnum::POST:
$options['form_params'] = $params;
break;
case RequestMethodEnum::UPLOAD:
if (array_key_exists('resource', $params) && array_key_exists('name', $params)) {
$options['headers']['X-File-Name'] = $params['name'];
$options['multipart'] = [
[
'contents' => $params['resource'],
'name' => $params['name'],
],
];
}
break;
default:
throw new \InvalidArgumentException(sprintf('Request method "%s" not allowed!', $requestMethod));
}
return $options;
}
|
[
"protected",
"function",
"calculateOptionsForParams",
"(",
"string",
"$",
"requestMethod",
",",
"array",
"$",
"params",
",",
"string",
"$",
"accessToken",
")",
":",
"array",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"prepareBaseOptions",
"(",
"$",
"accessToken",
")",
";",
"if",
"(",
"0",
"===",
"\\",
"count",
"(",
"$",
"params",
")",
")",
"{",
"return",
"$",
"options",
";",
"}",
"switch",
"(",
"$",
"requestMethod",
")",
"{",
"case",
"RequestMethodEnum",
"::",
"GET",
":",
"case",
"RequestMethodEnum",
"::",
"DELETE",
":",
"$",
"options",
"[",
"'query'",
"]",
"=",
"$",
"params",
";",
"break",
";",
"case",
"RequestMethodEnum",
"::",
"PUT",
":",
"case",
"RequestMethodEnum",
"::",
"POST",
":",
"$",
"options",
"[",
"'form_params'",
"]",
"=",
"$",
"params",
";",
"break",
";",
"case",
"RequestMethodEnum",
"::",
"UPLOAD",
":",
"if",
"(",
"array_key_exists",
"(",
"'resource'",
",",
"$",
"params",
")",
"&&",
"array_key_exists",
"(",
"'name'",
",",
"$",
"params",
")",
")",
"{",
"$",
"options",
"[",
"'headers'",
"]",
"[",
"'X-File-Name'",
"]",
"=",
"$",
"params",
"[",
"'name'",
"]",
";",
"$",
"options",
"[",
"'multipart'",
"]",
"=",
"[",
"[",
"'contents'",
"=>",
"$",
"params",
"[",
"'resource'",
"]",
",",
"'name'",
"=>",
"$",
"params",
"[",
"'name'",
"]",
",",
"]",
",",
"]",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Request method \"%s\" not allowed!'",
",",
"$",
"requestMethod",
")",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] |
Main method for calculating request params.
@param string $requestMethod
@param array $params
@param string $accessToken
@throws \InvalidArgumentException
@return array
|
[
"Main",
"method",
"for",
"calculating",
"request",
"params",
"."
] |
957319ba26020b207e756699708e865d61b7da2f
|
https://github.com/zibios/wrike-php-guzzle/blob/957319ba26020b207e756699708e865d61b7da2f/src/Client/GuzzleClient.php#L73-L105
|
27,861
|
mediact/testing-suite
|
src/Installer/PackagesInstaller.php
|
PackagesInstaller.isPackageRequired
|
private function isPackageRequired(string $packageName): bool
{
foreach ($this->composer->getPackage()->getRequires() as $require) {
if ($require->getTarget() === $packageName) {
return true;
}
}
return false;
}
|
php
|
private function isPackageRequired(string $packageName): bool
{
foreach ($this->composer->getPackage()->getRequires() as $require) {
if ($require->getTarget() === $packageName) {
return true;
}
}
return false;
}
|
[
"private",
"function",
"isPackageRequired",
"(",
"string",
"$",
"packageName",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
"->",
"getRequires",
"(",
")",
"as",
"$",
"require",
")",
"{",
"if",
"(",
"$",
"require",
"->",
"getTarget",
"(",
")",
"===",
"$",
"packageName",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Whether a package has been required.
@param string $packageName
@return bool
|
[
"Whether",
"a",
"package",
"has",
"been",
"required",
"."
] |
98614fe3b5c174e9bda2ff88d36d30349094dbc2
|
https://github.com/mediact/testing-suite/blob/98614fe3b5c174e9bda2ff88d36d30349094dbc2/src/Installer/PackagesInstaller.php#L101-L110
|
27,862
|
byjg/cache-engine-php
|
src/Psr6/CachePool.php
|
CachePool.addElementToBuffer
|
protected function addElementToBuffer(CacheItem $cacheItem)
{
if ($this->bufferSize < 1) {
return;
}
$key = $cacheItem->getKey();
$this->buffer[$key] = $cacheItem;
if (in_array($key, $this->bufferKeys)) {
return;
}
array_push($this->bufferKeys, $key);
if (count($this->bufferKeys) > $this->bufferSize) {
$element = array_shift($this->bufferKeys);
unset($this->buffer[$element]);
}
}
|
php
|
protected function addElementToBuffer(CacheItem $cacheItem)
{
if ($this->bufferSize < 1) {
return;
}
$key = $cacheItem->getKey();
$this->buffer[$key] = $cacheItem;
if (in_array($key, $this->bufferKeys)) {
return;
}
array_push($this->bufferKeys, $key);
if (count($this->bufferKeys) > $this->bufferSize) {
$element = array_shift($this->bufferKeys);
unset($this->buffer[$element]);
}
}
|
[
"protected",
"function",
"addElementToBuffer",
"(",
"CacheItem",
"$",
"cacheItem",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bufferSize",
"<",
"1",
")",
"{",
"return",
";",
"}",
"$",
"key",
"=",
"$",
"cacheItem",
"->",
"getKey",
"(",
")",
";",
"$",
"this",
"->",
"buffer",
"[",
"$",
"key",
"]",
"=",
"$",
"cacheItem",
";",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"bufferKeys",
")",
")",
"{",
"return",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"bufferKeys",
",",
"$",
"key",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"bufferKeys",
")",
">",
"$",
"this",
"->",
"bufferSize",
")",
"{",
"$",
"element",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"bufferKeys",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"element",
"]",
")",
";",
"}",
"}"
] |
Add an element to buffer. If the buffer is full, the first element added will be removed
@param CacheItem $cacheItem
|
[
"Add",
"an",
"element",
"to",
"buffer",
".",
"If",
"the",
"buffer",
"is",
"full",
"the",
"first",
"element",
"added",
"will",
"be",
"removed"
] |
001281edc3be6d908e7865b836cb6b43bd61a5cc
|
https://github.com/byjg/cache-engine-php/blob/001281edc3be6d908e7865b836cb6b43bd61a5cc/src/Psr6/CachePool.php#L71-L90
|
27,863
|
byjg/cache-engine-php
|
src/Psr6/CachePool.php
|
CachePool.removeElementFromBuffer
|
protected function removeElementFromBuffer($key)
{
$result = array_search($key, $this->bufferKeys);
if ($result === false) {
return;
}
unset($this->buffer[$key]);
unset($this->bufferKeys[$result]);
}
|
php
|
protected function removeElementFromBuffer($key)
{
$result = array_search($key, $this->bufferKeys);
if ($result === false) {
return;
}
unset($this->buffer[$key]);
unset($this->bufferKeys[$result]);
}
|
[
"protected",
"function",
"removeElementFromBuffer",
"(",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"bufferKeys",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"return",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"key",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"bufferKeys",
"[",
"$",
"result",
"]",
")",
";",
"}"
] |
Remove a specific key from buffer
@param $key
|
[
"Remove",
"a",
"specific",
"key",
"from",
"buffer"
] |
001281edc3be6d908e7865b836cb6b43bd61a5cc
|
https://github.com/byjg/cache-engine-php/blob/001281edc3be6d908e7865b836cb6b43bd61a5cc/src/Psr6/CachePool.php#L97-L106
|
27,864
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/NamespaceMappedUrlHandler.php
|
NamespaceMappedUrlHandler.onNoTargetFound
|
protected function onNoTargetFound($request, $currentUrlFragment = "")
{
if (self::$onTargetNotFoundExecuting) {
return false;
}
self::$onTargetNotFoundExecuting = true;
// Try generating a response for the url with /index on the end.
// Note that we don't try /index/. This is very deliberate as we want the default behaviour
// of the handler to kick in and redirect us to /index/ rather than just outputting it's
// contents.
if ($currentUrlFragment[strlen($currentUrlFragment) - 1] != "/") {
$currentUrlFragment .= "/";
}
$currentUrlFragment .= "index";
$response = $this->generateResponseForRequest($request, $currentUrlFragment);
self::$onTargetNotFoundExecuting = false;
return $response;
}
|
php
|
protected function onNoTargetFound($request, $currentUrlFragment = "")
{
if (self::$onTargetNotFoundExecuting) {
return false;
}
self::$onTargetNotFoundExecuting = true;
// Try generating a response for the url with /index on the end.
// Note that we don't try /index/. This is very deliberate as we want the default behaviour
// of the handler to kick in and redirect us to /index/ rather than just outputting it's
// contents.
if ($currentUrlFragment[strlen($currentUrlFragment) - 1] != "/") {
$currentUrlFragment .= "/";
}
$currentUrlFragment .= "index";
$response = $this->generateResponseForRequest($request, $currentUrlFragment);
self::$onTargetNotFoundExecuting = false;
return $response;
}
|
[
"protected",
"function",
"onNoTargetFound",
"(",
"$",
"request",
",",
"$",
"currentUrlFragment",
"=",
"\"\"",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"onTargetNotFoundExecuting",
")",
"{",
"return",
"false",
";",
"}",
"self",
"::",
"$",
"onTargetNotFoundExecuting",
"=",
"true",
";",
"// Try generating a response for the url with /index on the end.",
"// Note that we don't try /index/. This is very deliberate as we want the default behaviour",
"// of the handler to kick in and redirect us to /index/ rather than just outputting it's",
"// contents.",
"if",
"(",
"$",
"currentUrlFragment",
"[",
"strlen",
"(",
"$",
"currentUrlFragment",
")",
"-",
"1",
"]",
"!=",
"\"/\"",
")",
"{",
"$",
"currentUrlFragment",
".=",
"\"/\"",
";",
"}",
"$",
"currentUrlFragment",
".=",
"\"index\"",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"generateResponseForRequest",
"(",
"$",
"request",
",",
"$",
"currentUrlFragment",
")",
";",
"self",
"::",
"$",
"onTargetNotFoundExecuting",
"=",
"false",
";",
"return",
"$",
"response",
";",
"}"
] |
Override this to provide a default response in the event that no action could be found.
@param \Rhubarb\Crown\Request\Request $request The original request we tried to find a target for.
@param $currentUrlFragment
@return bool|string
|
[
"Override",
"this",
"to",
"provide",
"a",
"default",
"response",
"in",
"the",
"event",
"that",
"no",
"action",
"could",
"be",
"found",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/NamespaceMappedUrlHandler.php#L143-L166
|
27,865
|
RhubarbPHP/Rhubarb
|
src/Events/Event.php
|
Event.attachHandler
|
public function attachHandler(callable $handler, $key = null)
{
if ($key !== null) {
$this->eventHandlers[$key] = $handler;
} else {
$this->eventHandlers[] = $handler;
}
}
|
php
|
public function attachHandler(callable $handler, $key = null)
{
if ($key !== null) {
$this->eventHandlers[$key] = $handler;
} else {
$this->eventHandlers[] = $handler;
}
}
|
[
"public",
"function",
"attachHandler",
"(",
"callable",
"$",
"handler",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
"=",
"$",
"handler",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"eventHandlers",
"[",
"]",
"=",
"$",
"handler",
";",
"}",
"}"
] |
Attach an event handler
@param callable $handler
@param string $key An optional unique identifier for the handler in case you wish to specifically remove it later
|
[
"Attach",
"an",
"event",
"handler"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Events/Event.php#L31-L38
|
27,866
|
RhubarbPHP/Rhubarb
|
src/Events/Event.php
|
Event.raise
|
public function raise(...$arguments)
{
$firstResponse = null;
/** @var callable $callBack */
$callBack = false;
$count = count($arguments);
if ($count > 0 && is_object($arguments[$count - 1]) && is_callable($arguments[$count - 1])) {
$callBack = $arguments[$count - 1];
$arguments = array_slice($arguments, 0, -1);
}
foreach ($this->eventHandlers as $handler) {
$response = $handler(...$arguments);
if ($response !== null) {
if ($callBack) {
$callBack($response);
}
if ($firstResponse === null) {
$firstResponse = $response;
}
}
}
return $firstResponse;
}
|
php
|
public function raise(...$arguments)
{
$firstResponse = null;
/** @var callable $callBack */
$callBack = false;
$count = count($arguments);
if ($count > 0 && is_object($arguments[$count - 1]) && is_callable($arguments[$count - 1])) {
$callBack = $arguments[$count - 1];
$arguments = array_slice($arguments, 0, -1);
}
foreach ($this->eventHandlers as $handler) {
$response = $handler(...$arguments);
if ($response !== null) {
if ($callBack) {
$callBack($response);
}
if ($firstResponse === null) {
$firstResponse = $response;
}
}
}
return $firstResponse;
}
|
[
"public",
"function",
"raise",
"(",
"...",
"$",
"arguments",
")",
"{",
"$",
"firstResponse",
"=",
"null",
";",
"/** @var callable $callBack */",
"$",
"callBack",
"=",
"false",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"arguments",
")",
";",
"if",
"(",
"$",
"count",
">",
"0",
"&&",
"is_object",
"(",
"$",
"arguments",
"[",
"$",
"count",
"-",
"1",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"arguments",
"[",
"$",
"count",
"-",
"1",
"]",
")",
")",
"{",
"$",
"callBack",
"=",
"$",
"arguments",
"[",
"$",
"count",
"-",
"1",
"]",
";",
"$",
"arguments",
"=",
"array_slice",
"(",
"$",
"arguments",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"eventHandlers",
"as",
"$",
"handler",
")",
"{",
"$",
"response",
"=",
"$",
"handler",
"(",
"...",
"$",
"arguments",
")",
";",
"if",
"(",
"$",
"response",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"callBack",
")",
"{",
"$",
"callBack",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"$",
"firstResponse",
"===",
"null",
")",
"{",
"$",
"firstResponse",
"=",
"$",
"response",
";",
"}",
"}",
"}",
"return",
"$",
"firstResponse",
";",
"}"
] |
Call all handlers for the event with the passed arguments.
If there are multiple event handlers, this will return the earliest non-null response from the handlers.
If you need to receive response data from multiple handlers, you can pass a callback function as the last argument.
The callback function will only be called for any handler which returns a value.
@param array ...$arguments
@return mixed
|
[
"Call",
"all",
"handlers",
"for",
"the",
"event",
"with",
"the",
"passed",
"arguments",
".",
"If",
"there",
"are",
"multiple",
"event",
"handlers",
"this",
"will",
"return",
"the",
"earliest",
"non",
"-",
"null",
"response",
"from",
"the",
"handlers",
".",
"If",
"you",
"need",
"to",
"receive",
"response",
"data",
"from",
"multiple",
"handlers",
"you",
"can",
"pass",
"a",
"callback",
"function",
"as",
"the",
"last",
"argument",
".",
"The",
"callback",
"function",
"will",
"only",
"be",
"called",
"for",
"any",
"handler",
"which",
"returns",
"a",
"value",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Events/Event.php#L49-L77
|
27,867
|
RhubarbPHP/Rhubarb
|
src/Events/Event.php
|
Event.removeHandler
|
public function removeHandler(callable $handler)
{
$key = array_search($handler, $this->eventHandlers, true);
if ($key !== false) {
unset($this->eventHandlers[$key]);
}
}
|
php
|
public function removeHandler(callable $handler)
{
$key = array_search($handler, $this->eventHandlers, true);
if ($key !== false) {
unset($this->eventHandlers[$key]);
}
}
|
[
"public",
"function",
"removeHandler",
"(",
"callable",
"$",
"handler",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"handler",
",",
"$",
"this",
"->",
"eventHandlers",
",",
"true",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] |
Removes a specific handler. You must pass a reference to the same handler you originally attached.
@param callable $handler
|
[
"Removes",
"a",
"specific",
"handler",
".",
"You",
"must",
"pass",
"a",
"reference",
"to",
"the",
"same",
"handler",
"you",
"originally",
"attached",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Events/Event.php#L102-L109
|
27,868
|
mediact/testing-suite
|
src/MappingResolver.php
|
MappingResolver.resolve
|
public function resolve(): FileMappingReaderInterface
{
$files = [
__DIR__ . '/../templates/mapping/files',
sprintf(
__DIR__ . '/../templates/mapping/project/%s',
$this->typeResolver->resolve()
)
];
return new UnixFileMappingReader(
__DIR__ . '/../templates/files',
getcwd(),
...$files
);
}
|
php
|
public function resolve(): FileMappingReaderInterface
{
$files = [
__DIR__ . '/../templates/mapping/files',
sprintf(
__DIR__ . '/../templates/mapping/project/%s',
$this->typeResolver->resolve()
)
];
return new UnixFileMappingReader(
__DIR__ . '/../templates/files',
getcwd(),
...$files
);
}
|
[
"public",
"function",
"resolve",
"(",
")",
":",
"FileMappingReaderInterface",
"{",
"$",
"files",
"=",
"[",
"__DIR__",
".",
"'/../templates/mapping/files'",
",",
"sprintf",
"(",
"__DIR__",
".",
"'/../templates/mapping/project/%s'",
",",
"$",
"this",
"->",
"typeResolver",
"->",
"resolve",
"(",
")",
")",
"]",
";",
"return",
"new",
"UnixFileMappingReader",
"(",
"__DIR__",
".",
"'/../templates/files'",
",",
"getcwd",
"(",
")",
",",
"...",
"$",
"files",
")",
";",
"}"
] |
Resolve mapping files.
@return FileMappingReaderInterface
|
[
"Resolve",
"mapping",
"files",
"."
] |
98614fe3b5c174e9bda2ff88d36d30349094dbc2
|
https://github.com/mediact/testing-suite/blob/98614fe3b5c174e9bda2ff88d36d30349094dbc2/src/MappingResolver.php#L32-L47
|
27,869
|
RhubarbPHP/Rhubarb
|
src/Xml/NodeStrategyCollation.php
|
NodeStrategyCollation.processNode
|
protected function processNode( Node $node, \XMLReader $xmlReader )
{
$node = parent::processNode( $node, $xmlReader );
$children = [ ];
if( !$xmlReader->isEmptyElement )
{
$scanner = new NodeStrategyTraversal();
$scanner->addNodeHandler( '*', new self( function ( $node ) use ( &$children )
{
$children[] = $node;
} ) );
$scanner->parse( $xmlReader, $this->startDepth );
}
$node->children = $children;
return $node;
}
|
php
|
protected function processNode( Node $node, \XMLReader $xmlReader )
{
$node = parent::processNode( $node, $xmlReader );
$children = [ ];
if( !$xmlReader->isEmptyElement )
{
$scanner = new NodeStrategyTraversal();
$scanner->addNodeHandler( '*', new self( function ( $node ) use ( &$children )
{
$children[] = $node;
} ) );
$scanner->parse( $xmlReader, $this->startDepth );
}
$node->children = $children;
return $node;
}
|
[
"protected",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"\\",
"XMLReader",
"$",
"xmlReader",
")",
"{",
"$",
"node",
"=",
"parent",
"::",
"processNode",
"(",
"$",
"node",
",",
"$",
"xmlReader",
")",
";",
"$",
"children",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"xmlReader",
"->",
"isEmptyElement",
")",
"{",
"$",
"scanner",
"=",
"new",
"NodeStrategyTraversal",
"(",
")",
";",
"$",
"scanner",
"->",
"addNodeHandler",
"(",
"'*'",
",",
"new",
"self",
"(",
"function",
"(",
"$",
"node",
")",
"use",
"(",
"&",
"$",
"children",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"node",
";",
"}",
")",
")",
";",
"$",
"scanner",
"->",
"parse",
"(",
"$",
"xmlReader",
",",
"$",
"this",
"->",
"startDepth",
")",
";",
"}",
"$",
"node",
"->",
"children",
"=",
"$",
"children",
";",
"return",
"$",
"node",
";",
"}"
] |
The collation strategy should to collate all child nodes before callback
@param Node $node
@param \XMLReader $xmlReader
@return Node The node with children collated will be passed to the callback
|
[
"The",
"collation",
"strategy",
"should",
"to",
"collate",
"all",
"child",
"nodes",
"before",
"callback"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Xml/NodeStrategyCollation.php#L50-L68
|
27,870
|
RhubarbPHP/Rhubarb
|
src/Sessions/Session.php
|
Session.getSessionProvider
|
final protected function getSessionProvider()
{
if ($this->sessionProvider == null) {
$this->sessionProvider = $this->getNewSessionProvider();
}
return $this->sessionProvider;
}
|
php
|
final protected function getSessionProvider()
{
if ($this->sessionProvider == null) {
$this->sessionProvider = $this->getNewSessionProvider();
}
return $this->sessionProvider;
}
|
[
"final",
"protected",
"function",
"getSessionProvider",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sessionProvider",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"sessionProvider",
"=",
"$",
"this",
"->",
"getNewSessionProvider",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sessionProvider",
";",
"}"
] |
Get's the SessionProvider for this session.
To change the session provider for a session simply implement the GetNewSessionProvider() method.
@return SessionProviders\SessionProvider
|
[
"Get",
"s",
"the",
"SessionProvider",
"for",
"this",
"session",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sessions/Session.php#L52-L59
|
27,871
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.calculateRawProgresses
|
private function calculateRawProgresses(array $dist): array
{
$m = \count($dist) - 1;
$n = \count($dist[0]) - 1;
$progresses = $trace = [];
for (
$x = $m, $y = $n;
$x !== 0 && $y !== 0;
[$x, $y] = $trace
) {
switch ($dist[$x][$y]) {
case $dist[$x - 1][$y] + $this->costMap[self::OP_DEL]:
$trace = [$x - 1, $y, self::OP_DEL];
break;
case $dist[$x][$y - 1] + $this->costMap[self::OP_INS]:
$trace = [$x, $y - 1, self::OP_INS];
break;
case $dist[$x - 1][$y - 1] + $this->costMap[self::OP_REP]:
$trace = [$x - 1, $y - 1, self::OP_REP];
break;
default:
$trace = [$x - 1, $y - 1, self::OP_CPY];
break;
}
$progresses[] = [$x, $y, $trace[2]];
}
for (; $x > 0; --$x) {
$progresses[] = [$x, 0, self::OP_DEL];
}
for (; $y > 0; --$y) {
$progresses[] = [0, $y, self::OP_INS];
}
return $progresses;
}
|
php
|
private function calculateRawProgresses(array $dist): array
{
$m = \count($dist) - 1;
$n = \count($dist[0]) - 1;
$progresses = $trace = [];
for (
$x = $m, $y = $n;
$x !== 0 && $y !== 0;
[$x, $y] = $trace
) {
switch ($dist[$x][$y]) {
case $dist[$x - 1][$y] + $this->costMap[self::OP_DEL]:
$trace = [$x - 1, $y, self::OP_DEL];
break;
case $dist[$x][$y - 1] + $this->costMap[self::OP_INS]:
$trace = [$x, $y - 1, self::OP_INS];
break;
case $dist[$x - 1][$y - 1] + $this->costMap[self::OP_REP]:
$trace = [$x - 1, $y - 1, self::OP_REP];
break;
default:
$trace = [$x - 1, $y - 1, self::OP_CPY];
break;
}
$progresses[] = [$x, $y, $trace[2]];
}
for (; $x > 0; --$x) {
$progresses[] = [$x, 0, self::OP_DEL];
}
for (; $y > 0; --$y) {
$progresses[] = [0, $y, self::OP_INS];
}
return $progresses;
}
|
[
"private",
"function",
"calculateRawProgresses",
"(",
"array",
"$",
"dist",
")",
":",
"array",
"{",
"$",
"m",
"=",
"\\",
"count",
"(",
"$",
"dist",
")",
"-",
"1",
";",
"$",
"n",
"=",
"\\",
"count",
"(",
"$",
"dist",
"[",
"0",
"]",
")",
"-",
"1",
";",
"$",
"progresses",
"=",
"$",
"trace",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"x",
"=",
"$",
"m",
",",
"$",
"y",
"=",
"$",
"n",
";",
"$",
"x",
"!==",
"0",
"&&",
"$",
"y",
"!==",
"0",
";",
"[",
"$",
"x",
",",
"$",
"y",
"]",
"=",
"$",
"trace",
")",
"{",
"switch",
"(",
"$",
"dist",
"[",
"$",
"x",
"]",
"[",
"$",
"y",
"]",
")",
"{",
"case",
"$",
"dist",
"[",
"$",
"x",
"-",
"1",
"]",
"[",
"$",
"y",
"]",
"+",
"$",
"this",
"->",
"costMap",
"[",
"self",
"::",
"OP_DEL",
"]",
":",
"$",
"trace",
"=",
"[",
"$",
"x",
"-",
"1",
",",
"$",
"y",
",",
"self",
"::",
"OP_DEL",
"]",
";",
"break",
";",
"case",
"$",
"dist",
"[",
"$",
"x",
"]",
"[",
"$",
"y",
"-",
"1",
"]",
"+",
"$",
"this",
"->",
"costMap",
"[",
"self",
"::",
"OP_INS",
"]",
":",
"$",
"trace",
"=",
"[",
"$",
"x",
",",
"$",
"y",
"-",
"1",
",",
"self",
"::",
"OP_INS",
"]",
";",
"break",
";",
"case",
"$",
"dist",
"[",
"$",
"x",
"-",
"1",
"]",
"[",
"$",
"y",
"-",
"1",
"]",
"+",
"$",
"this",
"->",
"costMap",
"[",
"self",
"::",
"OP_REP",
"]",
":",
"$",
"trace",
"=",
"[",
"$",
"x",
"-",
"1",
",",
"$",
"y",
"-",
"1",
",",
"self",
"::",
"OP_REP",
"]",
";",
"break",
";",
"default",
":",
"$",
"trace",
"=",
"[",
"$",
"x",
"-",
"1",
",",
"$",
"y",
"-",
"1",
",",
"self",
"::",
"OP_CPY",
"]",
";",
"break",
";",
"}",
"$",
"progresses",
"[",
"]",
"=",
"[",
"$",
"x",
",",
"$",
"y",
",",
"$",
"trace",
"[",
"2",
"]",
"]",
";",
"}",
"for",
"(",
";",
"$",
"x",
">",
"0",
";",
"--",
"$",
"x",
")",
"{",
"$",
"progresses",
"[",
"]",
"=",
"[",
"$",
"x",
",",
"0",
",",
"self",
"::",
"OP_DEL",
"]",
";",
"}",
"for",
"(",
";",
"$",
"y",
">",
"0",
";",
"--",
"$",
"y",
")",
"{",
"$",
"progresses",
"[",
"]",
"=",
"[",
"0",
",",
"$",
"y",
",",
"self",
"::",
"OP_INS",
"]",
";",
"}",
"return",
"$",
"progresses",
";",
"}"
] |
Calculate the raw progresses.
@param array $dist the distance array
@return array the raw progresses
|
[
"Calculate",
"the",
"raw",
"progresses",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L352-L391
|
27,872
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.resolveRawProgresses
|
private function resolveRawProgresses(array $rawProgresses): array
{
static $callbacks;
$callbacks = $callbacks ?? [
self::OP_CPY => function (int $x, int $y): array {
return [self::OP_CPY, $x - 1, $y - 1, 1];
},
self::OP_DEL => function (int $x, int $y): array {
return [self::OP_DEL, $x - 1, $y, 1];
},
self::OP_INS => function (int $x, int $y): array {
return [self::OP_INS, $x, $y - 1, 1];
},
self::OP_REP => function (int $x, int $y): array {
return [self::OP_REP, $x - 1, $y - 1, 1];
},
];
foreach ($rawProgresses as &$rawProgress) {
$rawProgress = $callbacks[$rawProgress[2]](
$rawProgress[0],
$rawProgress[1]
);
}
unset($rawProgress);
return $rawProgresses;
}
|
php
|
private function resolveRawProgresses(array $rawProgresses): array
{
static $callbacks;
$callbacks = $callbacks ?? [
self::OP_CPY => function (int $x, int $y): array {
return [self::OP_CPY, $x - 1, $y - 1, 1];
},
self::OP_DEL => function (int $x, int $y): array {
return [self::OP_DEL, $x - 1, $y, 1];
},
self::OP_INS => function (int $x, int $y): array {
return [self::OP_INS, $x, $y - 1, 1];
},
self::OP_REP => function (int $x, int $y): array {
return [self::OP_REP, $x - 1, $y - 1, 1];
},
];
foreach ($rawProgresses as &$rawProgress) {
$rawProgress = $callbacks[$rawProgress[2]](
$rawProgress[0],
$rawProgress[1]
);
}
unset($rawProgress);
return $rawProgresses;
}
|
[
"private",
"function",
"resolveRawProgresses",
"(",
"array",
"$",
"rawProgresses",
")",
":",
"array",
"{",
"static",
"$",
"callbacks",
";",
"$",
"callbacks",
"=",
"$",
"callbacks",
"??",
"[",
"self",
"::",
"OP_CPY",
"=>",
"function",
"(",
"int",
"$",
"x",
",",
"int",
"$",
"y",
")",
":",
"array",
"{",
"return",
"[",
"self",
"::",
"OP_CPY",
",",
"$",
"x",
"-",
"1",
",",
"$",
"y",
"-",
"1",
",",
"1",
"]",
";",
"}",
",",
"self",
"::",
"OP_DEL",
"=>",
"function",
"(",
"int",
"$",
"x",
",",
"int",
"$",
"y",
")",
":",
"array",
"{",
"return",
"[",
"self",
"::",
"OP_DEL",
",",
"$",
"x",
"-",
"1",
",",
"$",
"y",
",",
"1",
"]",
";",
"}",
",",
"self",
"::",
"OP_INS",
"=>",
"function",
"(",
"int",
"$",
"x",
",",
"int",
"$",
"y",
")",
":",
"array",
"{",
"return",
"[",
"self",
"::",
"OP_INS",
",",
"$",
"x",
",",
"$",
"y",
"-",
"1",
",",
"1",
"]",
";",
"}",
",",
"self",
"::",
"OP_REP",
"=>",
"function",
"(",
"int",
"$",
"x",
",",
"int",
"$",
"y",
")",
":",
"array",
"{",
"return",
"[",
"self",
"::",
"OP_REP",
",",
"$",
"x",
"-",
"1",
",",
"$",
"y",
"-",
"1",
",",
"1",
"]",
";",
"}",
",",
"]",
";",
"foreach",
"(",
"$",
"rawProgresses",
"as",
"&",
"$",
"rawProgress",
")",
"{",
"$",
"rawProgress",
"=",
"$",
"callbacks",
"[",
"$",
"rawProgress",
"[",
"2",
"]",
"]",
"(",
"$",
"rawProgress",
"[",
"0",
"]",
",",
"$",
"rawProgress",
"[",
"1",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"rawProgress",
")",
";",
"return",
"$",
"rawProgresses",
";",
"}"
] |
Resolve the raw progresses.
@param array $rawProgresses the raw progresses
@return array [operation, old position, new position, length]
|
[
"Resolve",
"the",
"raw",
"progresses",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L400-L428
|
27,873
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.mergeNeighborProgresses
|
private function mergeNeighborProgresses(array $progresses): array
{
$progressesCount = \count($progresses);
if ($progressesCount === 0) {
return [];
}
$merged = [];
$last = $progresses[0];
for ($step = 1; $step < $progressesCount; ++$step) {
$progress = $progresses[$step];
if ($last[0] === $progress[0]) {
$progress[3] += $last[3];
} else {
$merged[] = $last;
}
$last = $progress;
}
$merged[] = $last;
return $merged;
}
|
php
|
private function mergeNeighborProgresses(array $progresses): array
{
$progressesCount = \count($progresses);
if ($progressesCount === 0) {
return [];
}
$merged = [];
$last = $progresses[0];
for ($step = 1; $step < $progressesCount; ++$step) {
$progress = $progresses[$step];
if ($last[0] === $progress[0]) {
$progress[3] += $last[3];
} else {
$merged[] = $last;
}
$last = $progress;
}
$merged[] = $last;
return $merged;
}
|
[
"private",
"function",
"mergeNeighborProgresses",
"(",
"array",
"$",
"progresses",
")",
":",
"array",
"{",
"$",
"progressesCount",
"=",
"\\",
"count",
"(",
"$",
"progresses",
")",
";",
"if",
"(",
"$",
"progressesCount",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"merged",
"=",
"[",
"]",
";",
"$",
"last",
"=",
"$",
"progresses",
"[",
"0",
"]",
";",
"for",
"(",
"$",
"step",
"=",
"1",
";",
"$",
"step",
"<",
"$",
"progressesCount",
";",
"++",
"$",
"step",
")",
"{",
"$",
"progress",
"=",
"$",
"progresses",
"[",
"$",
"step",
"]",
";",
"if",
"(",
"$",
"last",
"[",
"0",
"]",
"===",
"$",
"progress",
"[",
"0",
"]",
")",
"{",
"$",
"progress",
"[",
"3",
"]",
"+=",
"$",
"last",
"[",
"3",
"]",
";",
"}",
"else",
"{",
"$",
"merged",
"[",
"]",
"=",
"$",
"last",
";",
"}",
"$",
"last",
"=",
"$",
"progress",
";",
"}",
"$",
"merged",
"[",
"]",
"=",
"$",
"last",
";",
"return",
"$",
"merged",
";",
"}"
] |
Merge neighbor progresses and return the merged result.
@param array $progresses the progresses
@return array
|
[
"Merge",
"neighbor",
"progresses",
"and",
"return",
"the",
"merged",
"result",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L437-L463
|
27,874
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.makeProgressesPatch
|
private function makeProgressesPatch(array $olds, array $news, array $progresses): array
{
foreach ($progresses as $step => [$operation, $oldPos, $newPos, $length]) {
if ($operation & (self::OP_CPY | self::OP_DEL)) {
$chars = \array_slice($olds, $oldPos, $length);
} elseif ($operation & (self::OP_INS | self::OP_REP)) {
$chars = \array_slice($news, $newPos, $length);
} else {
$chars = [];
}
$progresses[$step][2] = \implode('', $chars);
}
return $progresses;
}
|
php
|
private function makeProgressesPatch(array $olds, array $news, array $progresses): array
{
foreach ($progresses as $step => [$operation, $oldPos, $newPos, $length]) {
if ($operation & (self::OP_CPY | self::OP_DEL)) {
$chars = \array_slice($olds, $oldPos, $length);
} elseif ($operation & (self::OP_INS | self::OP_REP)) {
$chars = \array_slice($news, $newPos, $length);
} else {
$chars = [];
}
$progresses[$step][2] = \implode('', $chars);
}
return $progresses;
}
|
[
"private",
"function",
"makeProgressesPatch",
"(",
"array",
"$",
"olds",
",",
"array",
"$",
"news",
",",
"array",
"$",
"progresses",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"progresses",
"as",
"$",
"step",
"=>",
"[",
"$",
"operation",
",",
"$",
"oldPos",
",",
"$",
"newPos",
",",
"$",
"length",
"]",
")",
"{",
"if",
"(",
"$",
"operation",
"&",
"(",
"self",
"::",
"OP_CPY",
"|",
"self",
"::",
"OP_DEL",
")",
")",
"{",
"$",
"chars",
"=",
"\\",
"array_slice",
"(",
"$",
"olds",
",",
"$",
"oldPos",
",",
"$",
"length",
")",
";",
"}",
"elseif",
"(",
"$",
"operation",
"&",
"(",
"self",
"::",
"OP_INS",
"|",
"self",
"::",
"OP_REP",
")",
")",
"{",
"$",
"chars",
"=",
"\\",
"array_slice",
"(",
"$",
"news",
",",
"$",
"newPos",
",",
"$",
"length",
")",
";",
"}",
"else",
"{",
"$",
"chars",
"=",
"[",
"]",
";",
"}",
"$",
"progresses",
"[",
"$",
"step",
"]",
"[",
"2",
"]",
"=",
"\\",
"implode",
"(",
"''",
",",
"$",
"chars",
")",
";",
"}",
"return",
"$",
"progresses",
";",
"}"
] |
Make progresses just like patch.
@param array $olds the old characters
@param array $news the new characters
@param array $progresses the progresses
@return array
|
[
"Make",
"progresses",
"just",
"like",
"patch",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L474-L489
|
27,875
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.removeCopyProgresses
|
private function removeCopyProgresses(array $progresses): array
{
foreach ($progresses as $step => $progress) {
if ($progress[0] === self::OP_CPY) {
unset($progresses[$step]);
}
}
// resort keys
return \array_values($progresses);
}
|
php
|
private function removeCopyProgresses(array $progresses): array
{
foreach ($progresses as $step => $progress) {
if ($progress[0] === self::OP_CPY) {
unset($progresses[$step]);
}
}
// resort keys
return \array_values($progresses);
}
|
[
"private",
"function",
"removeCopyProgresses",
"(",
"array",
"$",
"progresses",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"progresses",
"as",
"$",
"step",
"=>",
"$",
"progress",
")",
"{",
"if",
"(",
"$",
"progress",
"[",
"0",
"]",
"===",
"self",
"::",
"OP_CPY",
")",
"{",
"unset",
"(",
"$",
"progresses",
"[",
"$",
"step",
"]",
")",
";",
"}",
"}",
"// resort keys",
"return",
"\\",
"array_values",
"(",
"$",
"progresses",
")",
";",
"}"
] |
Remove "COPY" progresses.
@param array $progresses the progresses
@return array
|
[
"Remove",
"COPY",
"progresses",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L498-L508
|
27,876
|
jfcherng/php-levenshtein-distance
|
src/LevenshteinDistance.php
|
LevenshteinDistance.stringifyOperations
|
private function stringifyOperations(array $progresses): array
{
foreach ($progresses as &$progress) {
$progress[0] = static::OP_INT2STR_MAP[$progress[0]];
}
unset($progress);
return $progresses;
}
|
php
|
private function stringifyOperations(array $progresses): array
{
foreach ($progresses as &$progress) {
$progress[0] = static::OP_INT2STR_MAP[$progress[0]];
}
unset($progress);
return $progresses;
}
|
[
"private",
"function",
"stringifyOperations",
"(",
"array",
"$",
"progresses",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"progresses",
"as",
"&",
"$",
"progress",
")",
"{",
"$",
"progress",
"[",
"0",
"]",
"=",
"static",
"::",
"OP_INT2STR_MAP",
"[",
"$",
"progress",
"[",
"0",
"]",
"]",
";",
"}",
"unset",
"(",
"$",
"progress",
")",
";",
"return",
"$",
"progresses",
";",
"}"
] |
Convert the operation in progresses from int to string.
@param array $progresses the progresses
@return array
|
[
"Convert",
"the",
"operation",
"in",
"progresses",
"from",
"int",
"to",
"string",
"."
] |
7184e6220547a80752c08386a2907655f0b20b56
|
https://github.com/jfcherng/php-levenshtein-distance/blob/7184e6220547a80752c08386a2907655f0b20b56/src/LevenshteinDistance.php#L517-L525
|
27,877
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/UrlHandler.php
|
UrlHandler.addChildUrlHandlers
|
private function addChildUrlHandlers($childHandlers)
{
foreach ($childHandlers as $childUrl => $childHandler) {
$childHandler->setUrl($childUrl);
$childHandler->setParentHandler($this);
$this->childUrlHandlers[] = $childHandler;
}
return $this;
}
|
php
|
private function addChildUrlHandlers($childHandlers)
{
foreach ($childHandlers as $childUrl => $childHandler) {
$childHandler->setUrl($childUrl);
$childHandler->setParentHandler($this);
$this->childUrlHandlers[] = $childHandler;
}
return $this;
}
|
[
"private",
"function",
"addChildUrlHandlers",
"(",
"$",
"childHandlers",
")",
"{",
"foreach",
"(",
"$",
"childHandlers",
"as",
"$",
"childUrl",
"=>",
"$",
"childHandler",
")",
"{",
"$",
"childHandler",
"->",
"setUrl",
"(",
"$",
"childUrl",
")",
";",
"$",
"childHandler",
"->",
"setParentHandler",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"childUrlHandlers",
"[",
"]",
"=",
"$",
"childHandler",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds child url handlers to this the parent.
@param UrlHandler[] $childHandlers
@return $this
|
[
"Adds",
"child",
"url",
"handlers",
"to",
"this",
"the",
"parent",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/UrlHandler.php#L204-L214
|
27,878
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/UrlHandler.php
|
UrlHandler.buildCompleteChildUrl
|
protected function buildCompleteChildUrl($childUrlFragment)
{
if ($this->parentHandler !== null) {
return $this->parentHandler->matchingUrl . $childUrlFragment;
} else {
return $childUrlFragment;
}
}
|
php
|
protected function buildCompleteChildUrl($childUrlFragment)
{
if ($this->parentHandler !== null) {
return $this->parentHandler->matchingUrl . $childUrlFragment;
} else {
return $childUrlFragment;
}
}
|
[
"protected",
"function",
"buildCompleteChildUrl",
"(",
"$",
"childUrlFragment",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parentHandler",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"parentHandler",
"->",
"matchingUrl",
".",
"$",
"childUrlFragment",
";",
"}",
"else",
"{",
"return",
"$",
"childUrlFragment",
";",
"}",
"}"
] |
Takes a URL fragment understood by a child handler and adds back the parents URL fragment to form a complete URL.
@param $childUrlFragment
@return string
|
[
"Takes",
"a",
"URL",
"fragment",
"understood",
"by",
"a",
"child",
"handler",
"and",
"adds",
"back",
"the",
"parents",
"URL",
"fragment",
"to",
"form",
"a",
"complete",
"URL",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/UrlHandler.php#L253-L260
|
27,879
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/UrlHandler.php
|
UrlHandler.generateResponse
|
public function generateResponse($request = null, $currentUrlFragment = false)
{
if ($currentUrlFragment === false) {
$currentUrlFragment = $request->urlPath;
}
if (!$this->matchesRequest($request, $currentUrlFragment)) {
return false;
}
UrlHandler::setExecutingUrlHandler($this);
Log::debug(function () {
return "Handler " . get_class($this) . " selected to generate response";
}, "ROUTER");
Log::indent();
$context = new PhpContext();
$context->UrlHandler = $this;
$this->matchingUrl = $this->getMatchingUrlFragment($request, $currentUrlFragment);
if ($this->parentHandler) {
$this->handledUrl = $this->parentHandler->handledUrl . $this->matchingUrl;
} else {
$this->handledUrl = $this->matchingUrl;
}
$childUrlFragment = substr($currentUrlFragment, strlen($this->matchingUrl));
foreach ($this->childUrlHandlers as $childHandler) {
$response = $childHandler->generateResponse($request, $childUrlFragment);
if ($response !== false) {
return $response;
}
}
$response = $this->generateResponseForRequest($request, $currentUrlFragment);
Log::debug(function () use ($response) {
if ($response !== false) {
return "Response generated by handler";
}
return "Handler deferred generation";
}, "ROUTER");
Log::outdent();
return $response;
}
|
php
|
public function generateResponse($request = null, $currentUrlFragment = false)
{
if ($currentUrlFragment === false) {
$currentUrlFragment = $request->urlPath;
}
if (!$this->matchesRequest($request, $currentUrlFragment)) {
return false;
}
UrlHandler::setExecutingUrlHandler($this);
Log::debug(function () {
return "Handler " . get_class($this) . " selected to generate response";
}, "ROUTER");
Log::indent();
$context = new PhpContext();
$context->UrlHandler = $this;
$this->matchingUrl = $this->getMatchingUrlFragment($request, $currentUrlFragment);
if ($this->parentHandler) {
$this->handledUrl = $this->parentHandler->handledUrl . $this->matchingUrl;
} else {
$this->handledUrl = $this->matchingUrl;
}
$childUrlFragment = substr($currentUrlFragment, strlen($this->matchingUrl));
foreach ($this->childUrlHandlers as $childHandler) {
$response = $childHandler->generateResponse($request, $childUrlFragment);
if ($response !== false) {
return $response;
}
}
$response = $this->generateResponseForRequest($request, $currentUrlFragment);
Log::debug(function () use ($response) {
if ($response !== false) {
return "Response generated by handler";
}
return "Handler deferred generation";
}, "ROUTER");
Log::outdent();
return $response;
}
|
[
"public",
"function",
"generateResponse",
"(",
"$",
"request",
"=",
"null",
",",
"$",
"currentUrlFragment",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"currentUrlFragment",
"===",
"false",
")",
"{",
"$",
"currentUrlFragment",
"=",
"$",
"request",
"->",
"urlPath",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"matchesRequest",
"(",
"$",
"request",
",",
"$",
"currentUrlFragment",
")",
")",
"{",
"return",
"false",
";",
"}",
"UrlHandler",
"::",
"setExecutingUrlHandler",
"(",
"$",
"this",
")",
";",
"Log",
"::",
"debug",
"(",
"function",
"(",
")",
"{",
"return",
"\"Handler \"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\" selected to generate response\"",
";",
"}",
",",
"\"ROUTER\"",
")",
";",
"Log",
"::",
"indent",
"(",
")",
";",
"$",
"context",
"=",
"new",
"PhpContext",
"(",
")",
";",
"$",
"context",
"->",
"UrlHandler",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"matchingUrl",
"=",
"$",
"this",
"->",
"getMatchingUrlFragment",
"(",
"$",
"request",
",",
"$",
"currentUrlFragment",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parentHandler",
")",
"{",
"$",
"this",
"->",
"handledUrl",
"=",
"$",
"this",
"->",
"parentHandler",
"->",
"handledUrl",
".",
"$",
"this",
"->",
"matchingUrl",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"handledUrl",
"=",
"$",
"this",
"->",
"matchingUrl",
";",
"}",
"$",
"childUrlFragment",
"=",
"substr",
"(",
"$",
"currentUrlFragment",
",",
"strlen",
"(",
"$",
"this",
"->",
"matchingUrl",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"childUrlHandlers",
"as",
"$",
"childHandler",
")",
"{",
"$",
"response",
"=",
"$",
"childHandler",
"->",
"generateResponse",
"(",
"$",
"request",
",",
"$",
"childUrlFragment",
")",
";",
"if",
"(",
"$",
"response",
"!==",
"false",
")",
"{",
"return",
"$",
"response",
";",
"}",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"generateResponseForRequest",
"(",
"$",
"request",
",",
"$",
"currentUrlFragment",
")",
";",
"Log",
"::",
"debug",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"response",
"!==",
"false",
")",
"{",
"return",
"\"Response generated by handler\"",
";",
"}",
"return",
"\"Handler deferred generation\"",
";",
"}",
",",
"\"ROUTER\"",
")",
";",
"Log",
"::",
"outdent",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Return the response when appropriate or false if no response could be generated.
If child handlers are present they are given priority.
@param mixed $request
@param bool|string $currentUrlFragment
@return bool|Response
|
[
"Return",
"the",
"response",
"when",
"appropriate",
"or",
"false",
"if",
"no",
"response",
"could",
"be",
"generated",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/UrlHandler.php#L278-L330
|
27,880
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/UrlHandler.php
|
UrlHandler.getMatchingUrlFragment
|
protected function getMatchingUrlFragment(Request $request, $currentUrlFragment = "")
{
if ($currentUrlFragment[strlen($currentUrlFragment) - 1] != "/") {
$currentUrlFragment .= "/";
}
if (stripos($currentUrlFragment, $this->url) === 0) {
return $this->url;
}
return false;
}
|
php
|
protected function getMatchingUrlFragment(Request $request, $currentUrlFragment = "")
{
if ($currentUrlFragment[strlen($currentUrlFragment) - 1] != "/") {
$currentUrlFragment .= "/";
}
if (stripos($currentUrlFragment, $this->url) === 0) {
return $this->url;
}
return false;
}
|
[
"protected",
"function",
"getMatchingUrlFragment",
"(",
"Request",
"$",
"request",
",",
"$",
"currentUrlFragment",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"currentUrlFragment",
"[",
"strlen",
"(",
"$",
"currentUrlFragment",
")",
"-",
"1",
"]",
"!=",
"\"/\"",
")",
"{",
"$",
"currentUrlFragment",
".=",
"\"/\"",
";",
"}",
"if",
"(",
"stripos",
"(",
"$",
"currentUrlFragment",
",",
"$",
"this",
"->",
"url",
")",
"===",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"url",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns the portion of the URL that this handler would be able to return a response for.
@param \Rhubarb\Crown\Request\Request $request
@param string $currentUrlFragment
@return bool
|
[
"Returns",
"the",
"portion",
"of",
"the",
"URL",
"that",
"this",
"handler",
"would",
"be",
"able",
"to",
"return",
"a",
"response",
"for",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/UrlHandler.php#L355-L366
|
27,881
|
RhubarbPHP/Rhubarb
|
src/UrlHandlers/UrlHandler.php
|
UrlHandler.matchesRequest
|
private function matchesRequest(Request $request, $currentUrlFragment = "")
{
// Some URL Handlers don't have a url at all in which case we assume they apply
// before even considering the url.
if ($this->url == "") {
return true;
}
return (stripos($currentUrlFragment, $this->url) === 0);
}
|
php
|
private function matchesRequest(Request $request, $currentUrlFragment = "")
{
// Some URL Handlers don't have a url at all in which case we assume they apply
// before even considering the url.
if ($this->url == "") {
return true;
}
return (stripos($currentUrlFragment, $this->url) === 0);
}
|
[
"private",
"function",
"matchesRequest",
"(",
"Request",
"$",
"request",
",",
"$",
"currentUrlFragment",
"=",
"\"\"",
")",
"{",
"// Some URL Handlers don't have a url at all in which case we assume they apply",
"// before even considering the url.",
"if",
"(",
"$",
"this",
"->",
"url",
"==",
"\"\"",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"stripos",
"(",
"$",
"currentUrlFragment",
",",
"$",
"this",
"->",
"url",
")",
"===",
"0",
")",
";",
"}"
] |
Returns true of this handler's URL allows it to consider a response for the request.
In general terms this means that the current URL begins with the URL this handler is registered to handle.
However more advanced handlers might use other aspects of the request instead of the URL to determine this.
@param Request $request
@param string $currentUrlFragment
@return bool
|
[
"Returns",
"true",
"of",
"this",
"handler",
"s",
"URL",
"allows",
"it",
"to",
"consider",
"a",
"response",
"for",
"the",
"request",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/UrlHandlers/UrlHandler.php#L378-L387
|
27,882
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.makeFromDate
|
public static function makeFromDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::makeFromDateTime($year, $month, $day, null, null, null, $timezone);
}
|
php
|
public static function makeFromDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::makeFromDateTime($year, $month, $day, null, null, null, $timezone);
}
|
[
"public",
"static",
"function",
"makeFromDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"makeFromDateTime",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"timezone",
")",
";",
"}"
] |
Make and return a new ExpressiveDate instance with defined year, month, and day.
@param int $year
@param int $month
@param int $day
@param string|DateTimeZone $timezone
@return ExpressiveDate
|
[
"Make",
"and",
"return",
"a",
"new",
"ExpressiveDate",
"instance",
"with",
"defined",
"year",
"month",
"and",
"day",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L80-L83
|
27,883
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.makeFromTime
|
public static function makeFromTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::makeFromDateTime(null, null, null, $hour, $minute, $second, $timezone);
}
|
php
|
public static function makeFromTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::makeFromDateTime(null, null, null, $hour, $minute, $second, $timezone);
}
|
[
"public",
"static",
"function",
"makeFromTime",
"(",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"makeFromDateTime",
"(",
"null",
",",
"null",
",",
"null",
",",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
",",
"$",
"timezone",
")",
";",
"}"
] |
Make and return a new ExpressiveDate instance with defined hour, minute, and second.
@param int $hour
@param int $minute
@param int $second
@param string|DateTimeZone $timezone
@return ExpressiveDate
|
[
"Make",
"and",
"return",
"a",
"new",
"ExpressiveDate",
"instance",
"with",
"defined",
"hour",
"minute",
"and",
"second",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L94-L97
|
27,884
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.makeFromDateTime
|
public static function makeFromDateTime($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$date = new static(null, $timezone);
$date->setDate($year ?: $date->getYear(), $month ?: $date->getMonth(), $day ?: $date->getDay());
// If no hour was given then we'll default the minute and second to the current
// minute and second. If a date was given and minute or second are null then
// we'll set them to 0, mimicking PHPs behaviour.
if (is_null($hour))
{
$minute = $minute ?: $date->getMinute();
$second = $second ?: $date->getSecond();
}
else
{
$minute = $minute ?: 0;
$second = $second ?: 0;
}
$date->setTime($hour ?: $date->getHour(), $minute, $second);
return $date;
}
|
php
|
public static function makeFromDateTime($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$date = new static(null, $timezone);
$date->setDate($year ?: $date->getYear(), $month ?: $date->getMonth(), $day ?: $date->getDay());
// If no hour was given then we'll default the minute and second to the current
// minute and second. If a date was given and minute or second are null then
// we'll set them to 0, mimicking PHPs behaviour.
if (is_null($hour))
{
$minute = $minute ?: $date->getMinute();
$second = $second ?: $date->getSecond();
}
else
{
$minute = $minute ?: 0;
$second = $second ?: 0;
}
$date->setTime($hour ?: $date->getHour(), $minute, $second);
return $date;
}
|
[
"public",
"static",
"function",
"makeFromDateTime",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"new",
"static",
"(",
"null",
",",
"$",
"timezone",
")",
";",
"$",
"date",
"->",
"setDate",
"(",
"$",
"year",
"?",
":",
"$",
"date",
"->",
"getYear",
"(",
")",
",",
"$",
"month",
"?",
":",
"$",
"date",
"->",
"getMonth",
"(",
")",
",",
"$",
"day",
"?",
":",
"$",
"date",
"->",
"getDay",
"(",
")",
")",
";",
"// If no hour was given then we'll default the minute and second to the current",
"// minute and second. If a date was given and minute or second are null then",
"// we'll set them to 0, mimicking PHPs behaviour.",
"if",
"(",
"is_null",
"(",
"$",
"hour",
")",
")",
"{",
"$",
"minute",
"=",
"$",
"minute",
"?",
":",
"$",
"date",
"->",
"getMinute",
"(",
")",
";",
"$",
"second",
"=",
"$",
"second",
"?",
":",
"$",
"date",
"->",
"getSecond",
"(",
")",
";",
"}",
"else",
"{",
"$",
"minute",
"=",
"$",
"minute",
"?",
":",
"0",
";",
"$",
"second",
"=",
"$",
"second",
"?",
":",
"0",
";",
"}",
"$",
"date",
"->",
"setTime",
"(",
"$",
"hour",
"?",
":",
"$",
"date",
"->",
"getHour",
"(",
")",
",",
"$",
"minute",
",",
"$",
"second",
")",
";",
"return",
"$",
"date",
";",
"}"
] |
Make and return a new ExpressiveDate instance with defined year, month, day, hour, minute, and second.
@param int $year
@param int $month
@param int $day
@param int $hour
@param int $minute
@param int $second
@param string|DateTimeZone $timezone
@return ExpressiveDate
|
[
"Make",
"and",
"return",
"a",
"new",
"ExpressiveDate",
"instance",
"with",
"defined",
"year",
"month",
"day",
"hour",
"minute",
"and",
"second",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L111-L135
|
27,885
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.modifySeconds
|
protected function modifySeconds($amount, $invert = false)
{
$interval = new DateInterval("PT{$amount}S");
$this->modifyFromInterval($interval, $invert);
return $this;
}
|
php
|
protected function modifySeconds($amount, $invert = false)
{
$interval = new DateInterval("PT{$amount}S");
$this->modifyFromInterval($interval, $invert);
return $this;
}
|
[
"protected",
"function",
"modifySeconds",
"(",
"$",
"amount",
",",
"$",
"invert",
"=",
"false",
")",
"{",
"$",
"interval",
"=",
"new",
"DateInterval",
"(",
"\"PT{$amount}S\"",
")",
";",
"$",
"this",
"->",
"modifyFromInterval",
"(",
"$",
"interval",
",",
"$",
"invert",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Modify by an amount of seconds.
@param int $amount
@param bool $invert
@return ExpressiveDate
|
[
"Modify",
"by",
"an",
"amount",
"of",
"seconds",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L652-L659
|
27,886
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.modifyFromInterval
|
protected function modifyFromInterval($interval, $invert = false)
{
if ($invert)
{
$this->sub($interval);
}
else
{
$this->add($interval);
}
return $this;
}
|
php
|
protected function modifyFromInterval($interval, $invert = false)
{
if ($invert)
{
$this->sub($interval);
}
else
{
$this->add($interval);
}
return $this;
}
|
[
"protected",
"function",
"modifyFromInterval",
"(",
"$",
"interval",
",",
"$",
"invert",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"invert",
")",
"{",
"$",
"this",
"->",
"sub",
"(",
"$",
"interval",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Modify from a DateInterval object.
@param DateInterval $interval
@param bool $invert
@return ExpressiveDate
|
[
"Modify",
"from",
"a",
"DateInterval",
"object",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L732-L744
|
27,887
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.setTimezone
|
public function setTimezone($timezone)
{
$timezone = $this->parseSuppliedTimezone($timezone);
parent::setTimezone($timezone);
return $this;
}
|
php
|
public function setTimezone($timezone)
{
$timezone = $this->parseSuppliedTimezone($timezone);
parent::setTimezone($timezone);
return $this;
}
|
[
"public",
"function",
"setTimezone",
"(",
"$",
"timezone",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"parseSuppliedTimezone",
"(",
"$",
"timezone",
")",
";",
"parent",
"::",
"setTimezone",
"(",
"$",
"timezone",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the timezone.
@param string|DateTimeZone $timezone
@return ExpressiveDate
|
[
"Set",
"the",
"timezone",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L752-L759
|
27,888
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.setWeekStartDay
|
public function setWeekStartDay($weekStartDay)
{
if (is_numeric($weekStartDay))
{
$this->weekStartDay = $weekStartDay;
}
else
{
$this->weekStartDay = array_search(strtolower($weekStartDay), array('sunday', 'monday'));
}
return $this;
}
|
php
|
public function setWeekStartDay($weekStartDay)
{
if (is_numeric($weekStartDay))
{
$this->weekStartDay = $weekStartDay;
}
else
{
$this->weekStartDay = array_search(strtolower($weekStartDay), array('sunday', 'monday'));
}
return $this;
}
|
[
"public",
"function",
"setWeekStartDay",
"(",
"$",
"weekStartDay",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"weekStartDay",
")",
")",
"{",
"$",
"this",
"->",
"weekStartDay",
"=",
"$",
"weekStartDay",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"weekStartDay",
"=",
"array_search",
"(",
"strtolower",
"(",
"$",
"weekStartDay",
")",
",",
"array",
"(",
"'sunday'",
",",
"'monday'",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the starting day of the week, where 0 is Sunday and 1 is Monday.
@param int|string $weekStartDay
@return void
|
[
"Set",
"the",
"starting",
"day",
"of",
"the",
"week",
"where",
"0",
"is",
"Sunday",
"and",
"1",
"is",
"Monday",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L1027-L1039
|
27,889
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.isDateAttribute
|
protected function isDateAttribute($attribute)
{
switch ($attribute)
{
case 'LeapYear':
return (bool) $this->format('L');
break;
case 'AmOrPm':
return $this->format('A');
break;
case 'DaylightSavings':
return (bool) $this->format('I');
break;
}
throw new InvalidArgumentException('The date attribute ['.$attribute.'] could not be found.');
}
|
php
|
protected function isDateAttribute($attribute)
{
switch ($attribute)
{
case 'LeapYear':
return (bool) $this->format('L');
break;
case 'AmOrPm':
return $this->format('A');
break;
case 'DaylightSavings':
return (bool) $this->format('I');
break;
}
throw new InvalidArgumentException('The date attribute ['.$attribute.'] could not be found.');
}
|
[
"protected",
"function",
"isDateAttribute",
"(",
"$",
"attribute",
")",
"{",
"switch",
"(",
"$",
"attribute",
")",
"{",
"case",
"'LeapYear'",
":",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"format",
"(",
"'L'",
")",
";",
"break",
";",
"case",
"'AmOrPm'",
":",
"return",
"$",
"this",
"->",
"format",
"(",
"'A'",
")",
";",
"break",
";",
"case",
"'DaylightSavings'",
":",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"format",
"(",
"'I'",
")",
";",
"break",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The date attribute ['",
".",
"$",
"attribute",
".",
"'] could not be found.'",
")",
";",
"}"
] |
Syntactical sugar for determining if date object "is" a condition.
@param string $attribute
@return mixed
|
[
"Syntactical",
"sugar",
"for",
"determining",
"if",
"date",
"object",
"is",
"a",
"condition",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L1114-L1130
|
27,890
|
jasonlewis/expressive-date
|
src/ExpressiveDate.php
|
ExpressiveDate.setDateAttribute
|
protected function setDateAttribute($attribute, $value)
{
switch ($attribute)
{
case 'Day':
return $this->setDate($this->getYear(), $this->getMonth(), $value);
break;
case 'Month':
return $this->setDate($this->getYear(), $value, $this->getDay());
break;
case 'Year':
return $this->setDate($value, $this->getMonth(), $this->getDay());
break;
case 'Hour':
return $this->setTime($value, $this->getMinute(), $this->getSecond());
break;
case 'Minute':
return $this->setTime($this->getHour(), $value, $this->getSecond());
break;
case 'Second':
return $this->setTime($this->getHour(), $this->getMinute(), $value);
break;
}
throw new InvalidArgumentException('The date attribute ['.$attribute.'] could not be set.');
}
|
php
|
protected function setDateAttribute($attribute, $value)
{
switch ($attribute)
{
case 'Day':
return $this->setDate($this->getYear(), $this->getMonth(), $value);
break;
case 'Month':
return $this->setDate($this->getYear(), $value, $this->getDay());
break;
case 'Year':
return $this->setDate($value, $this->getMonth(), $this->getDay());
break;
case 'Hour':
return $this->setTime($value, $this->getMinute(), $this->getSecond());
break;
case 'Minute':
return $this->setTime($this->getHour(), $value, $this->getSecond());
break;
case 'Second':
return $this->setTime($this->getHour(), $this->getMinute(), $value);
break;
}
throw new InvalidArgumentException('The date attribute ['.$attribute.'] could not be set.');
}
|
[
"protected",
"function",
"setDateAttribute",
"(",
"$",
"attribute",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"attribute",
")",
"{",
"case",
"'Day'",
":",
"return",
"$",
"this",
"->",
"setDate",
"(",
"$",
"this",
"->",
"getYear",
"(",
")",
",",
"$",
"this",
"->",
"getMonth",
"(",
")",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'Month'",
":",
"return",
"$",
"this",
"->",
"setDate",
"(",
"$",
"this",
"->",
"getYear",
"(",
")",
",",
"$",
"value",
",",
"$",
"this",
"->",
"getDay",
"(",
")",
")",
";",
"break",
";",
"case",
"'Year'",
":",
"return",
"$",
"this",
"->",
"setDate",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getMonth",
"(",
")",
",",
"$",
"this",
"->",
"getDay",
"(",
")",
")",
";",
"break",
";",
"case",
"'Hour'",
":",
"return",
"$",
"this",
"->",
"setTime",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getMinute",
"(",
")",
",",
"$",
"this",
"->",
"getSecond",
"(",
")",
")",
";",
"break",
";",
"case",
"'Minute'",
":",
"return",
"$",
"this",
"->",
"setTime",
"(",
"$",
"this",
"->",
"getHour",
"(",
")",
",",
"$",
"value",
",",
"$",
"this",
"->",
"getSecond",
"(",
")",
")",
";",
"break",
";",
"case",
"'Second'",
":",
"return",
"$",
"this",
"->",
"setTime",
"(",
"$",
"this",
"->",
"getHour",
"(",
")",
",",
"$",
"this",
"->",
"getMinute",
"(",
")",
",",
"$",
"value",
")",
";",
"break",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The date attribute ['",
".",
"$",
"attribute",
".",
"'] could not be set.'",
")",
";",
"}"
] |
Set a date attribute.
@param string $attribute
@return mixed
|
[
"Set",
"a",
"date",
"attribute",
"."
] |
1215d093fd3fe222e26629e0bc3885968ba88a01
|
https://github.com/jasonlewis/expressive-date/blob/1215d093fd3fe222e26629e0bc3885968ba88a01/src/ExpressiveDate.php#L1138-L1163
|
27,891
|
mediact/testing-suite
|
src/Installer/PipelinesInstaller.php
|
PipelinesInstaller.isBitbucket
|
private function isBitbucket(): bool
{
$process = $this->processFactory->create('git remote -v');
$process->run();
return strpos($process->getOutput(), $this->pattern) !== false;
}
|
php
|
private function isBitbucket(): bool
{
$process = $this->processFactory->create('git remote -v');
$process->run();
return strpos($process->getOutput(), $this->pattern) !== false;
}
|
[
"private",
"function",
"isBitbucket",
"(",
")",
":",
"bool",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"processFactory",
"->",
"create",
"(",
"'git remote -v'",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"return",
"strpos",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
",",
"$",
"this",
"->",
"pattern",
")",
"!==",
"false",
";",
"}"
] |
Check whether the project is on Bitbucket.
@return bool
|
[
"Check",
"whether",
"the",
"project",
"is",
"on",
"Bitbucket",
"."
] |
98614fe3b5c174e9bda2ff88d36d30349094dbc2
|
https://github.com/mediact/testing-suite/blob/98614fe3b5c174e9bda2ff88d36d30349094dbc2/src/Installer/PipelinesInstaller.php#L112-L118
|
27,892
|
RhubarbPHP/Rhubarb
|
src/Http/CurlHttpClient.php
|
CurlHttpClient.getResponse
|
public function getResponse(HttpRequest $request)
{
$uri = $request->getUrl();
$headers = $request->getHeaders();
$flatHeaders = [];
foreach ($headers as $key => $value) {
$flatHeaders[] = $key . ": " . $value;
}
$flatHeaders[] = 'Connection: Keep-Alive';
$flatHeaders[] = 'Expect:';
$flatHeaders[] = 'Accept-Language: en-GB';
$flatHeaders[] = 'Cache-Control: no-cache';
$flatHeaders[] = 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';
$curl = curl_init($uri);
curl_setopt($curl, CURLOPT_HEADER, false);
$payload = $request->getPayload();
switch ($request->getMethod()) {
case "head":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "HEAD");
break;
case "delete":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case "post":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "put":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
break;
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $flatHeaders);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$httpResponse = new HttpResponse();
$httpResponse->setResponseBody($response);
$httpResponse->setResponseCode($responseCode);
return $httpResponse;
}
|
php
|
public function getResponse(HttpRequest $request)
{
$uri = $request->getUrl();
$headers = $request->getHeaders();
$flatHeaders = [];
foreach ($headers as $key => $value) {
$flatHeaders[] = $key . ": " . $value;
}
$flatHeaders[] = 'Connection: Keep-Alive';
$flatHeaders[] = 'Expect:';
$flatHeaders[] = 'Accept-Language: en-GB';
$flatHeaders[] = 'Cache-Control: no-cache';
$flatHeaders[] = 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';
$curl = curl_init($uri);
curl_setopt($curl, CURLOPT_HEADER, false);
$payload = $request->getPayload();
switch ($request->getMethod()) {
case "head":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "HEAD");
break;
case "delete":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case "post":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "put":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
break;
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $flatHeaders);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$httpResponse = new HttpResponse();
$httpResponse->setResponseBody($response);
$httpResponse->setResponseCode($responseCode);
return $httpResponse;
}
|
[
"public",
"function",
"getResponse",
"(",
"HttpRequest",
"$",
"request",
")",
"{",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUrl",
"(",
")",
";",
"$",
"headers",
"=",
"$",
"request",
"->",
"getHeaders",
"(",
")",
";",
"$",
"flatHeaders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"flatHeaders",
"[",
"]",
"=",
"$",
"key",
".",
"\": \"",
".",
"$",
"value",
";",
"}",
"$",
"flatHeaders",
"[",
"]",
"=",
"'Connection: Keep-Alive'",
";",
"$",
"flatHeaders",
"[",
"]",
"=",
"'Expect:'",
";",
"$",
"flatHeaders",
"[",
"]",
"=",
"'Accept-Language: en-GB'",
";",
"$",
"flatHeaders",
"[",
"]",
"=",
"'Cache-Control: no-cache'",
";",
"$",
"flatHeaders",
"[",
"]",
"=",
"'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'",
";",
"$",
"curl",
"=",
"curl_init",
"(",
"$",
"uri",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_HEADER",
",",
"false",
")",
";",
"$",
"payload",
"=",
"$",
"request",
"->",
"getPayload",
"(",
")",
";",
"switch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"\"head\"",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"HEAD\"",
")",
";",
"break",
";",
"case",
"\"delete\"",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"DELETE\"",
")",
";",
"break",
";",
"case",
"\"post\"",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"payload",
")",
";",
"break",
";",
"case",
"\"put\"",
":",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"payload",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"PUT\"",
")",
";",
"break",
";",
"}",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"flatHeaders",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"curl",
")",
";",
"$",
"responseCode",
"=",
"curl_getinfo",
"(",
"$",
"curl",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"curl",
")",
";",
"$",
"httpResponse",
"=",
"new",
"HttpResponse",
"(",
")",
";",
"$",
"httpResponse",
"->",
"setResponseBody",
"(",
"$",
"response",
")",
";",
"$",
"httpResponse",
"->",
"setResponseCode",
"(",
"$",
"responseCode",
")",
";",
"return",
"$",
"httpResponse",
";",
"}"
] |
Executes an HTTP transaction and returns the response.
@param HttpRequest $request
@return HttpResponse
|
[
"Executes",
"an",
"HTTP",
"transaction",
"and",
"returns",
"the",
"response",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Http/CurlHttpClient.php#L31-L88
|
27,893
|
RhubarbPHP/Rhubarb
|
src/DateTime/RhubarbDateTime.php
|
RhubarbDateTime.previousMonday
|
public static function previousMonday($referenceDate = null)
{
if ($referenceDate == null) {
$referenceDate = new RhubarbDateTime("today");
}
$dayOfWeek = $referenceDate->format("N") - 1;
$referenceDate->modify(-$dayOfWeek . " days");
return $referenceDate;
}
|
php
|
public static function previousMonday($referenceDate = null)
{
if ($referenceDate == null) {
$referenceDate = new RhubarbDateTime("today");
}
$dayOfWeek = $referenceDate->format("N") - 1;
$referenceDate->modify(-$dayOfWeek . " days");
return $referenceDate;
}
|
[
"public",
"static",
"function",
"previousMonday",
"(",
"$",
"referenceDate",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"referenceDate",
"==",
"null",
")",
"{",
"$",
"referenceDate",
"=",
"new",
"RhubarbDateTime",
"(",
"\"today\"",
")",
";",
"}",
"$",
"dayOfWeek",
"=",
"$",
"referenceDate",
"->",
"format",
"(",
"\"N\"",
")",
"-",
"1",
";",
"$",
"referenceDate",
"->",
"modify",
"(",
"-",
"$",
"dayOfWeek",
".",
"\" days\"",
")",
";",
"return",
"$",
"referenceDate",
";",
"}"
] |
Returns the date of the Monday of this week.
This is often used as a handle on the week commencing date
@param RhubarbDateTime $referenceDate The date to find the previous Monday of. Today if null.
@return RhubarbDateTime
|
[
"Returns",
"the",
"date",
"of",
"the",
"Monday",
"of",
"this",
"week",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/DateTime/RhubarbDateTime.php#L112-L123
|
27,894
|
RhubarbPHP/Rhubarb
|
src/DateTime/RhubarbDateTime.php
|
RhubarbDateTime.createFromFormat
|
public static function createFromFormat($format, $time, $timezone = null)
{
if ($timezone == null) {
$dateTime = DateTime::createFromFormat($format, $time);
} else {
$dateTime = DateTime::createFromFormat($format, $time, $timezone);
}
return new self($dateTime, $timezone);
}
|
php
|
public static function createFromFormat($format, $time, $timezone = null)
{
if ($timezone == null) {
$dateTime = DateTime::createFromFormat($format, $time);
} else {
$dateTime = DateTime::createFromFormat($format, $time, $timezone);
}
return new self($dateTime, $timezone);
}
|
[
"public",
"static",
"function",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"timezone",
"==",
"null",
")",
"{",
"$",
"dateTime",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
")",
";",
"}",
"else",
"{",
"$",
"dateTime",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"timezone",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"dateTime",
",",
"$",
"timezone",
")",
";",
"}"
] |
Parse a string into a new RhubarbDateTime object according to the specified format
@param string $format Format accepted by date().
@param string $time String representing the time.
@param $timezone A DateTimeZone object representing the desired time zone.
@return RhubarbDateTime
|
[
"Parse",
"a",
"string",
"into",
"a",
"new",
"RhubarbDateTime",
"object",
"according",
"to",
"the",
"specified",
"format"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/DateTime/RhubarbDateTime.php#L134-L142
|
27,895
|
RhubarbPHP/Rhubarb
|
src/Events/EventEmitter.php
|
EventEmitter.replaceEventHandler
|
public function replaceEventHandler($event, callable $delegate)
{
if (isset($this->eventHandlers[$event])) {
$this->eventHandlers[$event] = [];
}
$this->attachEventHandler($event, $delegate);
}
|
php
|
public function replaceEventHandler($event, callable $delegate)
{
if (isset($this->eventHandlers[$event])) {
$this->eventHandlers[$event] = [];
}
$this->attachEventHandler($event, $delegate);
}
|
[
"public",
"function",
"replaceEventHandler",
"(",
"$",
"event",
",",
"callable",
"$",
"delegate",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"event",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"attachEventHandler",
"(",
"$",
"event",
",",
"$",
"delegate",
")",
";",
"}"
] |
Attach an event handler as the sole handler for this event.
Removes all previously attached handlers.
@param $event
@param callable $delegate
|
[
"Attach",
"an",
"event",
"handler",
"as",
"the",
"sole",
"handler",
"for",
"this",
"event",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Events/EventEmitter.php#L54-L61
|
27,896
|
RhubarbPHP/Rhubarb
|
src/Events/EventEmitter.php
|
EventEmitter.raiseEvent
|
protected function raiseEvent($event)
{
if (!isset($this->eventHandlers[$event])) {
return null;
}
$args = func_get_args();
$args = array_slice($args, 1);
// Check if the last argument is a callback.
$count = count($args);
$callBack = false;
if (($count > 0) && is_object($args[$count - 1]) && is_callable($args[$count - 1])) {
$callBack = $args[$count - 1];
$args = array_slice($args, 0, -1);
}
$result = null;
foreach ($this->eventHandlers[$event] as $delegate) {
$answer = call_user_func_array($delegate, $args);
if ($callBack !== false && $answer !== null) {
call_user_func($callBack, $answer);
}
// If we don't have a result yet - make this the result. This way the first event handler to
// return a non null result will be the overall result of the event.
if ($result === null) {
$result = $answer;
}
}
return $result;
}
|
php
|
protected function raiseEvent($event)
{
if (!isset($this->eventHandlers[$event])) {
return null;
}
$args = func_get_args();
$args = array_slice($args, 1);
// Check if the last argument is a callback.
$count = count($args);
$callBack = false;
if (($count > 0) && is_object($args[$count - 1]) && is_callable($args[$count - 1])) {
$callBack = $args[$count - 1];
$args = array_slice($args, 0, -1);
}
$result = null;
foreach ($this->eventHandlers[$event] as $delegate) {
$answer = call_user_func_array($delegate, $args);
if ($callBack !== false && $answer !== null) {
call_user_func($callBack, $answer);
}
// If we don't have a result yet - make this the result. This way the first event handler to
// return a non null result will be the overall result of the event.
if ($result === null) {
$result = $answer;
}
}
return $result;
}
|
[
"protected",
"function",
"raiseEvent",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"event",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"args",
"=",
"array_slice",
"(",
"$",
"args",
",",
"1",
")",
";",
"// Check if the last argument is a callback.",
"$",
"count",
"=",
"count",
"(",
"$",
"args",
")",
";",
"$",
"callBack",
"=",
"false",
";",
"if",
"(",
"(",
"$",
"count",
">",
"0",
")",
"&&",
"is_object",
"(",
"$",
"args",
"[",
"$",
"count",
"-",
"1",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"args",
"[",
"$",
"count",
"-",
"1",
"]",
")",
")",
"{",
"$",
"callBack",
"=",
"$",
"args",
"[",
"$",
"count",
"-",
"1",
"]",
";",
"$",
"args",
"=",
"array_slice",
"(",
"$",
"args",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"result",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"event",
"]",
"as",
"$",
"delegate",
")",
"{",
"$",
"answer",
"=",
"call_user_func_array",
"(",
"$",
"delegate",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"callBack",
"!==",
"false",
"&&",
"$",
"answer",
"!==",
"null",
")",
"{",
"call_user_func",
"(",
"$",
"callBack",
",",
"$",
"answer",
")",
";",
"}",
"// If we don't have a result yet - make this the result. This way the first event handler to",
"// return a non null result will be the overall result of the event.",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"answer",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Call this function to raise an event.
In addition to $event you can pass any number of other events which are passed through
to the event handling delegate.
@param string $event The name of the event
@return mixed|null
|
[
"Call",
"this",
"function",
"to",
"raise",
"an",
"event",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Events/EventEmitter.php#L105-L140
|
27,897
|
RhubarbPHP/Rhubarb
|
src/Response/Response.php
|
Response.addHeaders
|
public function addHeaders($headers)
{
foreach ($headers as $name => $value) {
$this->setHeader($name, $value);
}
}
|
php
|
public function addHeaders($headers)
{
foreach ($headers as $name => $value) {
$this->setHeader($name, $value);
}
}
|
[
"public",
"function",
"addHeaders",
"(",
"$",
"headers",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Sets headers from array. Keys should be the header names.
@param string[] $headers
|
[
"Sets",
"headers",
"from",
"array",
".",
"Keys",
"should",
"be",
"the",
"header",
"names",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Response/Response.php#L230-L235
|
27,898
|
RhubarbPHP/Rhubarb
|
src/Request/Request.php
|
Request.fromPhpContext
|
public final static function fromPhpContext(PhpContext $phpContext)
{
if ($phpContext->isCliInvocation()) {
$request = new CliRequest();
} else {
$contentType = (isset($_SERVER["CONTENT_TYPE"])) ? strtolower($_SERVER["CONTENT_TYPE"]) : "";
// Special check for multipart, because the header could be multipart/form-data
// followed by boundary
$multipartType = "multipart/form-data";
if (strpos($contentType, $multipartType) === 0) {
$contentType = $multipartType;
}
// Firefox puts a charset on the end of the content type line
$parts = explode(";", $contentType);
$contentType = $parts[0];
switch ($contentType) {
case "application/octet-stream":
case "image/jpeg":
case "image/jpg":
case "image/gif":
case "image/png":
$request = new BinaryRequest();
break;
case "application/json":
$request = new JsonRequest();
break;
case "text/xml":
case "application/xml":
$request = new XmlRequest();
break;
case "multipart/form-data":
$request = new MultiPartFormDataRequest();
break;
default:
$request = new WebRequest();
break;
}
}
$request->phpContext = $phpContext;
return $request;
}
|
php
|
public final static function fromPhpContext(PhpContext $phpContext)
{
if ($phpContext->isCliInvocation()) {
$request = new CliRequest();
} else {
$contentType = (isset($_SERVER["CONTENT_TYPE"])) ? strtolower($_SERVER["CONTENT_TYPE"]) : "";
// Special check for multipart, because the header could be multipart/form-data
// followed by boundary
$multipartType = "multipart/form-data";
if (strpos($contentType, $multipartType) === 0) {
$contentType = $multipartType;
}
// Firefox puts a charset on the end of the content type line
$parts = explode(";", $contentType);
$contentType = $parts[0];
switch ($contentType) {
case "application/octet-stream":
case "image/jpeg":
case "image/jpg":
case "image/gif":
case "image/png":
$request = new BinaryRequest();
break;
case "application/json":
$request = new JsonRequest();
break;
case "text/xml":
case "application/xml":
$request = new XmlRequest();
break;
case "multipart/form-data":
$request = new MultiPartFormDataRequest();
break;
default:
$request = new WebRequest();
break;
}
}
$request->phpContext = $phpContext;
return $request;
}
|
[
"public",
"final",
"static",
"function",
"fromPhpContext",
"(",
"PhpContext",
"$",
"phpContext",
")",
"{",
"if",
"(",
"$",
"phpContext",
"->",
"isCliInvocation",
"(",
")",
")",
"{",
"$",
"request",
"=",
"new",
"CliRequest",
"(",
")",
";",
"}",
"else",
"{",
"$",
"contentType",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"CONTENT_TYPE\"",
"]",
")",
")",
"?",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"\"CONTENT_TYPE\"",
"]",
")",
":",
"\"\"",
";",
"// Special check for multipart, because the header could be multipart/form-data",
"// followed by boundary",
"$",
"multipartType",
"=",
"\"multipart/form-data\"",
";",
"if",
"(",
"strpos",
"(",
"$",
"contentType",
",",
"$",
"multipartType",
")",
"===",
"0",
")",
"{",
"$",
"contentType",
"=",
"$",
"multipartType",
";",
"}",
"// Firefox puts a charset on the end of the content type line",
"$",
"parts",
"=",
"explode",
"(",
"\";\"",
",",
"$",
"contentType",
")",
";",
"$",
"contentType",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"switch",
"(",
"$",
"contentType",
")",
"{",
"case",
"\"application/octet-stream\"",
":",
"case",
"\"image/jpeg\"",
":",
"case",
"\"image/jpg\"",
":",
"case",
"\"image/gif\"",
":",
"case",
"\"image/png\"",
":",
"$",
"request",
"=",
"new",
"BinaryRequest",
"(",
")",
";",
"break",
";",
"case",
"\"application/json\"",
":",
"$",
"request",
"=",
"new",
"JsonRequest",
"(",
")",
";",
"break",
";",
"case",
"\"text/xml\"",
":",
"case",
"\"application/xml\"",
":",
"$",
"request",
"=",
"new",
"XmlRequest",
"(",
")",
";",
"break",
";",
"case",
"\"multipart/form-data\"",
":",
"$",
"request",
"=",
"new",
"MultiPartFormDataRequest",
"(",
")",
";",
"break",
";",
"default",
":",
"$",
"request",
"=",
"new",
"WebRequest",
"(",
")",
";",
"break",
";",
"}",
"}",
"$",
"request",
"->",
"phpContext",
"=",
"$",
"phpContext",
";",
"return",
"$",
"request",
";",
"}"
] |
Creates a request object from the PHP context
@return Request
|
[
"Creates",
"a",
"request",
"object",
"from",
"the",
"PHP",
"context"
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Request/Request.php#L98-L143
|
27,899
|
RhubarbPHP/Rhubarb
|
src/Request/Request.php
|
Request.getSuperglobalValue
|
protected function getSuperglobalValue($superglobal, $index, $defaultValue = null)
{
$propertyName = $superglobal . 'Data';
if (isset($this->$propertyName)){
$data = $this->$propertyName;
if (isset($data[$index])){
return $data[$index];
}
}
return $defaultValue;
}
|
php
|
protected function getSuperglobalValue($superglobal, $index, $defaultValue = null)
{
$propertyName = $superglobal . 'Data';
if (isset($this->$propertyName)){
$data = $this->$propertyName;
if (isset($data[$index])){
return $data[$index];
}
}
return $defaultValue;
}
|
[
"protected",
"function",
"getSuperglobalValue",
"(",
"$",
"superglobal",
",",
"$",
"index",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"propertyName",
"=",
"$",
"superglobal",
".",
"'Data'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"propertyName",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"$",
"propertyName",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"return",
"$",
"defaultValue",
";",
"}"
] |
Get the value stored against one of the request superglobals.
@param string $superglobal
@param mixed $index
@return mixed
|
[
"Get",
"the",
"value",
"stored",
"against",
"one",
"of",
"the",
"request",
"superglobals",
"."
] |
327ff1f05d6a7e651d41c8e771f3551acfac18ae
|
https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Request/Request.php#L178-L191
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.