repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Wedeto/Util | src/Cache/Pool.php | Pool.deleteItem | public function deleteItem($key)
{
if (!is_string($key))
throw new InvalidArgumentException("Invalid key: " . WF::str($key));
unset($this->cache[$key]);
return true;
} | php | public function deleteItem($key)
{
if (!is_string($key))
throw new InvalidArgumentException("Invalid key: " . WF::str($key));
unset($this->cache[$key]);
return true;
} | [
"public",
"function",
"deleteItem",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Invalid key: \"",
".",
"WF",
"::",
"str",
"(",
"$",
"key",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}"
]
| Remove an item from the pool
@param string $key The item to remove
@return bool True | [
"Remove",
"an",
"item",
"from",
"the",
"pool"
]
| 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Pool.php#L165-L172 | train |
Wedeto/Util | src/Cache/Pool.php | Pool.save | public function save(CacheItemInterface $item)
{
$this->cache->set($item->getKey(), $item);
return $this->commit();
} | php | public function save(CacheItemInterface $item)
{
$this->cache->set($item->getKey(), $item);
return $this->commit();
} | [
"public",
"function",
"save",
"(",
"CacheItemInterface",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"item",
"->",
"getKey",
"(",
")",
",",
"$",
"item",
")",
";",
"return",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"}"
]
| Save item to the pool
@param CacheItemInterface $item The item to save
@return bool True | [
"Save",
"item",
"to",
"the",
"pool"
]
| 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Pool.php#L191-L195 | train |
Wedeto/Util | src/Cache/Pool.php | Pool.saveDeferred | public function saveDeferred(CacheItemInterface $item)
{
$this->cache->set($item->getKey(), $item);
return true;
} | php | public function saveDeferred(CacheItemInterface $item)
{
$this->cache->set($item->getKey(), $item);
return true;
} | [
"public",
"function",
"saveDeferred",
"(",
"CacheItemInterface",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"item",
"->",
"getKey",
"(",
")",
",",
"$",
"item",
")",
";",
"return",
"true",
";",
"}"
]
| Store but do not save yet
@param CacheItemInterface $item The item to store
@return bool True | [
"Store",
"but",
"do",
"not",
"save",
"yet"
]
| 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Pool.php#L202-L206 | train |
holyshared/peridot-temporary-plugin | src/TemporaryFile.php | TemporaryFile.write | public function write($content)
{
$this->openForWrite();
$writtenBytes = $this->file->fwrite($content);
return $writtenBytes;
} | php | public function write($content)
{
$this->openForWrite();
$writtenBytes = $this->file->fwrite($content);
return $writtenBytes;
} | [
"public",
"function",
"write",
"(",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"openForWrite",
"(",
")",
";",
"$",
"writtenBytes",
"=",
"$",
"this",
"->",
"file",
"->",
"fwrite",
"(",
"$",
"content",
")",
";",
"return",
"$",
"writtenBytes",
";",
"}"
]
| Write a text
@param string $content
@return int|null | [
"Write",
"a",
"text"
]
| 0d61e7ef8dd0056b9fb4cd118e10295ac0a5456b | https://github.com/holyshared/peridot-temporary-plugin/blob/0d61e7ef8dd0056b9fb4cd118e10295ac0a5456b/src/TemporaryFile.php#L46-L52 | train |
agentmedia/phine-core | src/Core/Logic/Module/JsonModule.php | JsonModule.AttachError | protected final function AttachError($message)
{
$this->result->message = $message;
$this->result->success = false;
} | php | protected final function AttachError($message)
{
$this->result->message = $message;
$this->result->success = false;
} | [
"protected",
"final",
"function",
"AttachError",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"result",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"this",
"->",
"result",
"->",
"success",
"=",
"false",
";",
"}"
]
| Attaches the exception by setting message to the result and the success flag to false
@param string $message | [
"Attaches",
"the",
"exception",
"by",
"setting",
"message",
"to",
"the",
"result",
"and",
"the",
"success",
"flag",
"to",
"false"
]
| 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/JsonModule.php#L34-L38 | train |
agentmedia/phine-core | src/Core/Logic/Module/JsonModule.php | JsonModule.GatherOutput | protected final function GatherOutput()
{
\header('Content-Type: application/json');
try
{
$this->output = json_encode($this->result);
}
catch (\Exception $ex)
{
$this->AttachException($ex);
}
} | php | protected final function GatherOutput()
{
\header('Content-Type: application/json');
try
{
$this->output = json_encode($this->result);
}
catch (\Exception $ex)
{
$this->AttachException($ex);
}
} | [
"protected",
"final",
"function",
"GatherOutput",
"(",
")",
"{",
"\\",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"output",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"AttachException",
"(",
"$",
"ex",
")",
";",
"}",
"}"
]
| Gathers the output by encoding the result to json | [
"Gathers",
"the",
"output",
"by",
"encoding",
"the",
"result",
"to",
"json"
]
| 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/JsonModule.php#L52-L63 | train |
rafrsr/generic-api | sample/Services/PostsServices.php | PostsServices.delete | public function delete(Post $post)
{
$response = $this->api->process(new DeletePost($post));
if ($response->getStatusCode() == 200) {
return true;
} else {
return false;
}
} | php | public function delete(Post $post)
{
$response = $this->api->process(new DeletePost($post));
if ($response->getStatusCode() == 200) {
return true;
} else {
return false;
}
} | [
"public",
"function",
"delete",
"(",
"Post",
"$",
"post",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"api",
"->",
"process",
"(",
"new",
"DeletePost",
"(",
"$",
"post",
")",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"200",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Delete a Post
@param Post $post
@return bool | [
"Delete",
"a",
"Post"
]
| 2572d3dcc32e03914cf710f0229d72e1c09ea65b | https://github.com/rafrsr/generic-api/blob/2572d3dcc32e03914cf710f0229d72e1c09ea65b/sample/Services/PostsServices.php#L98-L106 | train |
Topolis/FunctionLibrary | src/Bitmask.php | Bitmask.set_xor | public function set_xor(Bitmask $Binary)
{
if(!($Binary instanceof Bitmask)) return;
$data = $Binary->get_raw();
foreach($data as $Pos => $Byte)
$this->data[$Pos] = @$this->data[$Pos] ^ $Byte;
} | php | public function set_xor(Bitmask $Binary)
{
if(!($Binary instanceof Bitmask)) return;
$data = $Binary->get_raw();
foreach($data as $Pos => $Byte)
$this->data[$Pos] = @$this->data[$Pos] ^ $Byte;
} | [
"public",
"function",
"set_xor",
"(",
"Bitmask",
"$",
"Binary",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"Binary",
"instanceof",
"Bitmask",
")",
")",
"return",
";",
"$",
"data",
"=",
"$",
"Binary",
"->",
"get_raw",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"Pos",
"=>",
"$",
"Byte",
")",
"$",
"this",
"->",
"data",
"[",
"$",
"Pos",
"]",
"=",
"@",
"$",
"this",
"->",
"data",
"[",
"$",
"Pos",
"]",
"^",
"$",
"Byte",
";",
"}"
]
| Perform xor operation with another Binary object
@param $Binary | [
"Perform",
"xor",
"operation",
"with",
"another",
"Binary",
"object"
]
| bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Bitmask.php#L116-L123 | train |
Topolis/FunctionLibrary | src/Bitmask.php | Bitmask.to_bin | public function to_bin()
{
$out = "";
for ($i=0; $i<$this->dataLength($this->data); $i++)
$out = sprintf("%08b",$this->data[$i]).$out;
return $out;
} | php | public function to_bin()
{
$out = "";
for ($i=0; $i<$this->dataLength($this->data); $i++)
$out = sprintf("%08b",$this->data[$i]).$out;
return $out;
} | [
"public",
"function",
"to_bin",
"(",
")",
"{",
"$",
"out",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"dataLength",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"i",
"++",
")",
"$",
"out",
"=",
"sprintf",
"(",
"\"%08b\"",
",",
"$",
"this",
"->",
"data",
"[",
"$",
"i",
"]",
")",
".",
"$",
"out",
";",
"return",
"$",
"out",
";",
"}"
]
| return value as binary string
@return string | [
"return",
"value",
"as",
"binary",
"string"
]
| bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Bitmask.php#L170-L176 | train |
Topolis/FunctionLibrary | src/Bitmask.php | Bitmask.data2hex | protected function data2hex ($temp)
{
$data = "";
for ($i=0; $i<$this->dataLength($temp); $i++)
$data.=sprintf("%02X",$temp[$i]);
return $data;
} | php | protected function data2hex ($temp)
{
$data = "";
for ($i=0; $i<$this->dataLength($temp); $i++)
$data.=sprintf("%02X",$temp[$i]);
return $data;
} | [
"protected",
"function",
"data2hex",
"(",
"$",
"temp",
")",
"{",
"$",
"data",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"dataLength",
"(",
"$",
"temp",
")",
";",
"$",
"i",
"++",
")",
"$",
"data",
".=",
"sprintf",
"(",
"\"%02X\"",
",",
"$",
"temp",
"[",
"$",
"i",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
]
| convert array of two byte integers to high endian hexadecimal string
@param array $temp
@return string | [
"convert",
"array",
"of",
"two",
"byte",
"integers",
"to",
"high",
"endian",
"hexadecimal",
"string"
]
| bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Bitmask.php#L204-L210 | train |
Topolis/FunctionLibrary | src/Bitmask.php | Bitmask.hex2data | protected function hex2data($temp)
{
$data = array();
$len = strlen($temp);
for ($i=0;$i<$len;$i+=2)
$data[(int)($i/2)]= hexdec(substr($temp,$i,2));
return $data;
} | php | protected function hex2data($temp)
{
$data = array();
$len = strlen($temp);
for ($i=0;$i<$len;$i+=2)
$data[(int)($i/2)]= hexdec(substr($temp,$i,2));
return $data;
} | [
"protected",
"function",
"hex2data",
"(",
"$",
"temp",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"temp",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"+=",
"2",
")",
"$",
"data",
"[",
"(",
"int",
")",
"(",
"$",
"i",
"/",
"2",
")",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"temp",
",",
"$",
"i",
",",
"2",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
]
| convert high endian hexadecimal string to array of two byte integers
@param string $temp
@return array | [
"convert",
"high",
"endian",
"hexadecimal",
"string",
"to",
"array",
"of",
"two",
"byte",
"integers"
]
| bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Bitmask.php#L217-L224 | train |
mmethner/engine | src/Tools/Path.php | Path.language | public static function language(string $template): string
{
list ($component, $file) = static::separate($template);
$elements = [
ENGINE_APP_ROOT,
'src',
$component,
'Resources',
'Language',
$file
];
return implode(DIRECTORY_SEPARATOR, $elements);
} | php | public static function language(string $template): string
{
list ($component, $file) = static::separate($template);
$elements = [
ENGINE_APP_ROOT,
'src',
$component,
'Resources',
'Language',
$file
];
return implode(DIRECTORY_SEPARATOR, $elements);
} | [
"public",
"static",
"function",
"language",
"(",
"string",
"$",
"template",
")",
":",
"string",
"{",
"list",
"(",
"$",
"component",
",",
"$",
"file",
")",
"=",
"static",
"::",
"separate",
"(",
"$",
"template",
")",
";",
"$",
"elements",
"=",
"[",
"ENGINE_APP_ROOT",
",",
"'src'",
",",
"$",
"component",
",",
"'Resources'",
",",
"'Language'",
",",
"$",
"file",
"]",
";",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"elements",
")",
";",
"}"
]
| creates the fully qualified include string for a language resource file
@param string $template
@return string | [
"creates",
"the",
"fully",
"qualified",
"include",
"string",
"for",
"a",
"language",
"resource",
"file"
]
| 89e1bcc644cf8cc3712a67ef1697da2ca4008f74 | https://github.com/mmethner/engine/blob/89e1bcc644cf8cc3712a67ef1697da2ca4008f74/src/Tools/Path.php#L42-L54 | train |
sokil/CommandBusBundle | src/DependencyInjection/RegisterCommandHandlerCompilerPass.php | RegisterCommandHandlerCompilerPass.getBuses | private function getBuses(ContainerBuilder $container)
{
$buses = [];
$busDefinitions = $container->findTaggedServiceIds('sokil.command_bus');
foreach ($busDefinitions as $busServiceId => $busTags) {
foreach ($busTags as $busTagParams) {
$buses[$busServiceId] = $container->findDefinition($busServiceId);
}
}
return $buses;
} | php | private function getBuses(ContainerBuilder $container)
{
$buses = [];
$busDefinitions = $container->findTaggedServiceIds('sokil.command_bus');
foreach ($busDefinitions as $busServiceId => $busTags) {
foreach ($busTags as $busTagParams) {
$buses[$busServiceId] = $container->findDefinition($busServiceId);
}
}
return $buses;
} | [
"private",
"function",
"getBuses",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"buses",
"=",
"[",
"]",
";",
"$",
"busDefinitions",
"=",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'sokil.command_bus'",
")",
";",
"foreach",
"(",
"$",
"busDefinitions",
"as",
"$",
"busServiceId",
"=>",
"$",
"busTags",
")",
"{",
"foreach",
"(",
"$",
"busTags",
"as",
"$",
"busTagParams",
")",
"{",
"$",
"buses",
"[",
"$",
"busServiceId",
"]",
"=",
"$",
"container",
"->",
"findDefinition",
"(",
"$",
"busServiceId",
")",
";",
"}",
"}",
"return",
"$",
"buses",
";",
"}"
]
| Get command buses
@param ContainerBuilder $container
@return array | [
"Get",
"command",
"buses"
]
| 7cfdd5f1e8a77f0620b94dd5214091a2159a143d | https://github.com/sokil/CommandBusBundle/blob/7cfdd5f1e8a77f0620b94dd5214091a2159a143d/src/DependencyInjection/RegisterCommandHandlerCompilerPass.php#L25-L36 | train |
sokil/CommandBusBundle | src/DependencyInjection/RegisterCommandHandlerCompilerPass.php | RegisterCommandHandlerCompilerPass.registerHandlersInBuses | private function registerHandlersInBuses(ContainerBuilder $container)
{
// Get command buses
$buses = $this->getBuses($container);
// Add handlers to command buses
$commandHandlerDefinitions = $container->findTaggedServiceIds('sokil.command_bus_handler');
foreach ($commandHandlerDefinitions as $commandHandlerServiceId => $commandBusHandlerTags) {
foreach ($commandBusHandlerTags as $commandHandlerTagParams) {
// Get command class
if (empty($commandHandlerTagParams['command_class'])) {
throw new InvalidArgumentException(sprintf(
"Parameter '%s' of command handler '%s' not specified",
'command_class',
$commandHandlerServiceId
));
}
$commandClassName = $commandHandlerTagParams['command_class'];
// Get handler's bus service id
if (empty($commandHandlerTagParams['command_bus'])) {
$commandHandlersBusServiceId = 'sokil.command_bus.default';
} else {
$commandHandlersBusServiceId = $commandHandlerTagParams['command_bus'];
if (empty($buses[$commandHandlersBusServiceId])) {
throw new InvalidArgumentException(sprintf(
"CommandBus with service id '%s' of command handler '%s' not found",
$commandHandlersBusServiceId,
$commandHandlerServiceId
));
}
}
// Add handler definition to bus
$buses[$commandHandlersBusServiceId]->addMethodCall(
'addHandlerDefinition',
[
$commandClassName,
$commandHandlerServiceId
]
);
}
}
} | php | private function registerHandlersInBuses(ContainerBuilder $container)
{
// Get command buses
$buses = $this->getBuses($container);
// Add handlers to command buses
$commandHandlerDefinitions = $container->findTaggedServiceIds('sokil.command_bus_handler');
foreach ($commandHandlerDefinitions as $commandHandlerServiceId => $commandBusHandlerTags) {
foreach ($commandBusHandlerTags as $commandHandlerTagParams) {
// Get command class
if (empty($commandHandlerTagParams['command_class'])) {
throw new InvalidArgumentException(sprintf(
"Parameter '%s' of command handler '%s' not specified",
'command_class',
$commandHandlerServiceId
));
}
$commandClassName = $commandHandlerTagParams['command_class'];
// Get handler's bus service id
if (empty($commandHandlerTagParams['command_bus'])) {
$commandHandlersBusServiceId = 'sokil.command_bus.default';
} else {
$commandHandlersBusServiceId = $commandHandlerTagParams['command_bus'];
if (empty($buses[$commandHandlersBusServiceId])) {
throw new InvalidArgumentException(sprintf(
"CommandBus with service id '%s' of command handler '%s' not found",
$commandHandlersBusServiceId,
$commandHandlerServiceId
));
}
}
// Add handler definition to bus
$buses[$commandHandlersBusServiceId]->addMethodCall(
'addHandlerDefinition',
[
$commandClassName,
$commandHandlerServiceId
]
);
}
}
} | [
"private",
"function",
"registerHandlersInBuses",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"// Get command buses",
"$",
"buses",
"=",
"$",
"this",
"->",
"getBuses",
"(",
"$",
"container",
")",
";",
"// Add handlers to command buses",
"$",
"commandHandlerDefinitions",
"=",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'sokil.command_bus_handler'",
")",
";",
"foreach",
"(",
"$",
"commandHandlerDefinitions",
"as",
"$",
"commandHandlerServiceId",
"=>",
"$",
"commandBusHandlerTags",
")",
"{",
"foreach",
"(",
"$",
"commandBusHandlerTags",
"as",
"$",
"commandHandlerTagParams",
")",
"{",
"// Get command class",
"if",
"(",
"empty",
"(",
"$",
"commandHandlerTagParams",
"[",
"'command_class'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Parameter '%s' of command handler '%s' not specified\"",
",",
"'command_class'",
",",
"$",
"commandHandlerServiceId",
")",
")",
";",
"}",
"$",
"commandClassName",
"=",
"$",
"commandHandlerTagParams",
"[",
"'command_class'",
"]",
";",
"// Get handler's bus service id",
"if",
"(",
"empty",
"(",
"$",
"commandHandlerTagParams",
"[",
"'command_bus'",
"]",
")",
")",
"{",
"$",
"commandHandlersBusServiceId",
"=",
"'sokil.command_bus.default'",
";",
"}",
"else",
"{",
"$",
"commandHandlersBusServiceId",
"=",
"$",
"commandHandlerTagParams",
"[",
"'command_bus'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"buses",
"[",
"$",
"commandHandlersBusServiceId",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"CommandBus with service id '%s' of command handler '%s' not found\"",
",",
"$",
"commandHandlersBusServiceId",
",",
"$",
"commandHandlerServiceId",
")",
")",
";",
"}",
"}",
"// Add handler definition to bus",
"$",
"buses",
"[",
"$",
"commandHandlersBusServiceId",
"]",
"->",
"addMethodCall",
"(",
"'addHandlerDefinition'",
",",
"[",
"$",
"commandClassName",
",",
"$",
"commandHandlerServiceId",
"]",
")",
";",
"}",
"}",
"}"
]
| Add handlers to command buses
@param ContainerBuilder $container | [
"Add",
"handlers",
"to",
"command",
"buses"
]
| 7cfdd5f1e8a77f0620b94dd5214091a2159a143d | https://github.com/sokil/CommandBusBundle/blob/7cfdd5f1e8a77f0620b94dd5214091a2159a143d/src/DependencyInjection/RegisterCommandHandlerCompilerPass.php#L43-L86 | train |
pdyn/httpclient | HttpClient.php | HttpClient.post_async | public function post_async($url, $data = array()) {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \Exception('Invalid URL received by http\HttpClient', 400);
}
$paramstr = '';
if (!empty($data)) {
if (is_array($data)) {
$paramstr = $this->urlencode_array($data);
} elseif (is_scalar($data)) {
$paramstr = $data;
}
}
$parts = parse_url($url);
$errno = $errstr = '';
$port = (isset($parts['port'])) ? $parts['port'] : 80;
$timeout = 30;
error_log('post asyncing');
try {
$fp = @fsockopen($parts['host'], $port, $errno, $errstr, $timeout);
} catch (\Exception $e) {
return false;
}
if (empty($fp)) {
return false;
}
$out = 'POST '.$parts['path'].' HTTP/1.1'."\r\n"
.'Host: '.$parts['host']."\r\n"
.'Content-Type: application/x-www-form-urlencoded'."\r\n"
.'Content-Length: '.strlen($paramstr)."\r\n"
.'Connection: Close'."\r\n\r\n";
if (!empty($paramstr)) {
$out .= $paramstr;
}
fwrite($fp, $out);
fclose($fp);
return true;
} | php | public function post_async($url, $data = array()) {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \Exception('Invalid URL received by http\HttpClient', 400);
}
$paramstr = '';
if (!empty($data)) {
if (is_array($data)) {
$paramstr = $this->urlencode_array($data);
} elseif (is_scalar($data)) {
$paramstr = $data;
}
}
$parts = parse_url($url);
$errno = $errstr = '';
$port = (isset($parts['port'])) ? $parts['port'] : 80;
$timeout = 30;
error_log('post asyncing');
try {
$fp = @fsockopen($parts['host'], $port, $errno, $errstr, $timeout);
} catch (\Exception $e) {
return false;
}
if (empty($fp)) {
return false;
}
$out = 'POST '.$parts['path'].' HTTP/1.1'."\r\n"
.'Host: '.$parts['host']."\r\n"
.'Content-Type: application/x-www-form-urlencoded'."\r\n"
.'Content-Length: '.strlen($paramstr)."\r\n"
.'Connection: Close'."\r\n\r\n";
if (!empty($paramstr)) {
$out .= $paramstr;
}
fwrite($fp, $out);
fclose($fp);
return true;
} | [
"public",
"function",
"post_async",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"url",
",",
"FILTER_VALIDATE_URL",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid URL received by http\\HttpClient'",
",",
"400",
")",
";",
"}",
"$",
"paramstr",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"paramstr",
"=",
"$",
"this",
"->",
"urlencode_array",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"data",
")",
")",
"{",
"$",
"paramstr",
"=",
"$",
"data",
";",
"}",
"}",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"errno",
"=",
"$",
"errstr",
"=",
"''",
";",
"$",
"port",
"=",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
")",
"?",
"$",
"parts",
"[",
"'port'",
"]",
":",
"80",
";",
"$",
"timeout",
"=",
"30",
";",
"error_log",
"(",
"'post asyncing'",
")",
";",
"try",
"{",
"$",
"fp",
"=",
"@",
"fsockopen",
"(",
"$",
"parts",
"[",
"'host'",
"]",
",",
"$",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"timeout",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"fp",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"out",
"=",
"'POST '",
".",
"$",
"parts",
"[",
"'path'",
"]",
".",
"' HTTP/1.1'",
".",
"\"\\r\\n\"",
".",
"'Host: '",
".",
"$",
"parts",
"[",
"'host'",
"]",
".",
"\"\\r\\n\"",
".",
"'Content-Type: application/x-www-form-urlencoded'",
".",
"\"\\r\\n\"",
".",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"paramstr",
")",
".",
"\"\\r\\n\"",
".",
"'Connection: Close'",
".",
"\"\\r\\n\\r\\n\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"paramstr",
")",
")",
"{",
"$",
"out",
".=",
"$",
"paramstr",
";",
"}",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"out",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"true",
";",
"}"
]
| Make an asynchronous POST request.
A fire-and-forget post function to distribute information without waiting for the recipient to respond.
@param string $url The URL to POST to.
@param array|string $data An array or string containing data to send.
@return bool Success/Failure | [
"Make",
"an",
"asynchronous",
"POST",
"request",
"."
]
| 9714796945db4908605be6f19c31ded1ee813c70 | https://github.com/pdyn/httpclient/blob/9714796945db4908605be6f19c31ded1ee813c70/HttpClient.php#L128-L168 | train |
pdyn/httpclient | HttpClient.php | HttpClient.get_remote_filesize | public static function get_remote_filesize($url, $maxredirs = 2) {
$parts = parse_url($url);
if (empty($parts['host'])) {
return false;
}
if ($parts['scheme'] === 'https') {
$host = 'ssl://'.$parts['host'];
$port = (isset($parts['port'])) ? $parts['port'] : 443;
} else {
$host = $parts['host'];
$port = (isset($parts['port'])) ? $parts['port'] : 80;
}
$errno = $errstr = '';
$timeout = 30;
try {
$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
} catch (\Exception $e) {
return false;
}
if (empty($fp)) {
return false;
}
$path = $parts['path'];
if (!empty($parts['query'])) {
$path .= '?'.$parts['query'];
}
$out = 'HEAD '.$path.' HTTP/1.1'."\r\n"
.'Host: '.$parts['host']."\r\n"
.'Connection: Close'."\r\n\r\n";
fwrite($fp, $out);
$headers = '';
while (!@feof($fp)) {
$headers .= @fgets($fp, 128);
}
fclose($fp);
$return = false;
$headers = explode("\n", $headers);
foreach ($headers as $header) {
$hparts = explode(':', mb_strtolower($header), 2);
if (!isset($hparts[1])) {
continue;
}
list($hkey, $hval) = $hparts;
switch ($hkey) {
case 'location':
if ($maxredirs > 0) {
return static::get_remote_filesize(trim($hval), ($maxredirs - 1));
} else {
return false;
}
case 'content-length':
return (int)trim($hval);
}
}
} | php | public static function get_remote_filesize($url, $maxredirs = 2) {
$parts = parse_url($url);
if (empty($parts['host'])) {
return false;
}
if ($parts['scheme'] === 'https') {
$host = 'ssl://'.$parts['host'];
$port = (isset($parts['port'])) ? $parts['port'] : 443;
} else {
$host = $parts['host'];
$port = (isset($parts['port'])) ? $parts['port'] : 80;
}
$errno = $errstr = '';
$timeout = 30;
try {
$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
} catch (\Exception $e) {
return false;
}
if (empty($fp)) {
return false;
}
$path = $parts['path'];
if (!empty($parts['query'])) {
$path .= '?'.$parts['query'];
}
$out = 'HEAD '.$path.' HTTP/1.1'."\r\n"
.'Host: '.$parts['host']."\r\n"
.'Connection: Close'."\r\n\r\n";
fwrite($fp, $out);
$headers = '';
while (!@feof($fp)) {
$headers .= @fgets($fp, 128);
}
fclose($fp);
$return = false;
$headers = explode("\n", $headers);
foreach ($headers as $header) {
$hparts = explode(':', mb_strtolower($header), 2);
if (!isset($hparts[1])) {
continue;
}
list($hkey, $hval) = $hparts;
switch ($hkey) {
case 'location':
if ($maxredirs > 0) {
return static::get_remote_filesize(trim($hval), ($maxredirs - 1));
} else {
return false;
}
case 'content-length':
return (int)trim($hval);
}
}
} | [
"public",
"static",
"function",
"get_remote_filesize",
"(",
"$",
"url",
",",
"$",
"maxredirs",
"=",
"2",
")",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parts",
"[",
"'host'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
"===",
"'https'",
")",
"{",
"$",
"host",
"=",
"'ssl://'",
".",
"$",
"parts",
"[",
"'host'",
"]",
";",
"$",
"port",
"=",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
")",
"?",
"$",
"parts",
"[",
"'port'",
"]",
":",
"443",
";",
"}",
"else",
"{",
"$",
"host",
"=",
"$",
"parts",
"[",
"'host'",
"]",
";",
"$",
"port",
"=",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'port'",
"]",
")",
")",
"?",
"$",
"parts",
"[",
"'port'",
"]",
":",
"80",
";",
"}",
"$",
"errno",
"=",
"$",
"errstr",
"=",
"''",
";",
"$",
"timeout",
"=",
"30",
";",
"try",
"{",
"$",
"fp",
"=",
"@",
"fsockopen",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"timeout",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"fp",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"path",
"=",
"$",
"parts",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"path",
".=",
"'?'",
".",
"$",
"parts",
"[",
"'query'",
"]",
";",
"}",
"$",
"out",
"=",
"'HEAD '",
".",
"$",
"path",
".",
"' HTTP/1.1'",
".",
"\"\\r\\n\"",
".",
"'Host: '",
".",
"$",
"parts",
"[",
"'host'",
"]",
".",
"\"\\r\\n\"",
".",
"'Connection: Close'",
".",
"\"\\r\\n\\r\\n\"",
";",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"out",
")",
";",
"$",
"headers",
"=",
"''",
";",
"while",
"(",
"!",
"@",
"feof",
"(",
"$",
"fp",
")",
")",
"{",
"$",
"headers",
".=",
"@",
"fgets",
"(",
"$",
"fp",
",",
"128",
")",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"$",
"return",
"=",
"false",
";",
"$",
"headers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"headers",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"$",
"hparts",
"=",
"explode",
"(",
"':'",
",",
"mb_strtolower",
"(",
"$",
"header",
")",
",",
"2",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"hparts",
"[",
"1",
"]",
")",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"hkey",
",",
"$",
"hval",
")",
"=",
"$",
"hparts",
";",
"switch",
"(",
"$",
"hkey",
")",
"{",
"case",
"'location'",
":",
"if",
"(",
"$",
"maxredirs",
">",
"0",
")",
"{",
"return",
"static",
"::",
"get_remote_filesize",
"(",
"trim",
"(",
"$",
"hval",
")",
",",
"(",
"$",
"maxredirs",
"-",
"1",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"case",
"'content-length'",
":",
"return",
"(",
"int",
")",
"trim",
"(",
"$",
"hval",
")",
";",
"}",
"}",
"}"
]
| Gets the reported filesize of a remote object.
@param string $url The URL to get the filesize of.
@param bool $maxredirs Maximum number of redirects to follow.
@return bool|int The filesize in bytes, or false if fail. | [
"Gets",
"the",
"reported",
"filesize",
"of",
"a",
"remote",
"object",
"."
]
| 9714796945db4908605be6f19c31ded1ee813c70 | https://github.com/pdyn/httpclient/blob/9714796945db4908605be6f19c31ded1ee813c70/HttpClient.php#L177-L238 | train |
pdyn/httpclient | HttpClient.php | HttpClient.urlencode_array | public function urlencode_array(array $ar) {
$datastring = '';
foreach ($ar as $key => $val) {
if (!empty($datastring)) {
$datastring .= '&';
}
$datastring .= urlencode($key).'='.urlencode($val);
}
return $datastring;
} | php | public function urlencode_array(array $ar) {
$datastring = '';
foreach ($ar as $key => $val) {
if (!empty($datastring)) {
$datastring .= '&';
}
$datastring .= urlencode($key).'='.urlencode($val);
}
return $datastring;
} | [
"public",
"function",
"urlencode_array",
"(",
"array",
"$",
"ar",
")",
"{",
"$",
"datastring",
"=",
"''",
";",
"foreach",
"(",
"$",
"ar",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"datastring",
")",
")",
"{",
"$",
"datastring",
".=",
"'&'",
";",
"}",
"$",
"datastring",
".=",
"urlencode",
"(",
"$",
"key",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"val",
")",
";",
"}",
"return",
"$",
"datastring",
";",
"}"
]
| Transforms an array of parameters into a urlencoded request string.
@param array $ar An array of key=>val to encode and transform
@return string The urlencoded request string | [
"Transforms",
"an",
"array",
"of",
"parameters",
"into",
"a",
"urlencoded",
"request",
"string",
"."
]
| 9714796945db4908605be6f19c31ded1ee813c70 | https://github.com/pdyn/httpclient/blob/9714796945db4908605be6f19c31ded1ee813c70/HttpClient.php#L246-L255 | train |
pdyn/httpclient | HttpClient.php | HttpClient.set_basic_auth | public function set_basic_auth($username, $password) {
$value = 'Basic '.base64_encode($username.':'.$password);
$this->set_header('Authorization', $value);
return true;
} | php | public function set_basic_auth($username, $password) {
$value = 'Basic '.base64_encode($username.':'.$password);
$this->set_header('Authorization', $value);
return true;
} | [
"public",
"function",
"set_basic_auth",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"value",
"=",
"'Basic '",
".",
"base64_encode",
"(",
"$",
"username",
".",
"':'",
".",
"$",
"password",
")",
";",
"$",
"this",
"->",
"set_header",
"(",
"'Authorization'",
",",
"$",
"value",
")",
";",
"return",
"true",
";",
"}"
]
| Set a basic auth header.
@param string $username The username to use.
@param string $password The password to use. | [
"Set",
"a",
"basic",
"auth",
"header",
"."
]
| 9714796945db4908605be6f19c31ded1ee813c70 | https://github.com/pdyn/httpclient/blob/9714796945db4908605be6f19c31ded1ee813c70/HttpClient.php#L331-L335 | train |
pdyn/httpclient | HttpClient.php | HttpClient.execute_curl | protected function execute_curl($options) {
$ch = curl_init();
curl_setopt_array($ch, $options);
$returned = curl_exec($ch);
$response = HttpClientResponse::instance_from_curl($ch, $returned);
curl_close($ch);
return $response;
} | php | protected function execute_curl($options) {
$ch = curl_init();
curl_setopt_array($ch, $options);
$returned = curl_exec($ch);
$response = HttpClientResponse::instance_from_curl($ch, $returned);
curl_close($ch);
return $response;
} | [
"protected",
"function",
"execute_curl",
"(",
"$",
"options",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"ch",
",",
"$",
"options",
")",
";",
"$",
"returned",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"response",
"=",
"HttpClientResponse",
"::",
"instance_from_curl",
"(",
"$",
"ch",
",",
"$",
"returned",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Execute a curl call with the given options.
@param array $options Array of curl options.
@return string Returned strings. | [
"Execute",
"a",
"curl",
"call",
"with",
"the",
"given",
"options",
"."
]
| 9714796945db4908605be6f19c31ded1ee813c70 | https://github.com/pdyn/httpclient/blob/9714796945db4908605be6f19c31ded1ee813c70/HttpClient.php#L438-L445 | train |
cubicmushroom/valueobjects | src/Web/Url.php | Url.fromNative | public static function fromNative()
{
$urlString = \func_get_arg(0);
$user = \parse_url($urlString, PHP_URL_USER);
$pass = \parse_url($urlString, PHP_URL_PASS);
$host = \parse_url($urlString, PHP_URL_HOST);
$queryString = \parse_url($urlString, PHP_URL_QUERY);
$fragmentId = \parse_url($urlString, PHP_URL_FRAGMENT);
$port = \parse_url($urlString, PHP_URL_PORT);
$scheme = new SchemeName(\parse_url($urlString, PHP_URL_SCHEME));
$user = $user ? new StringLiteral($user) : new StringLiteral('');
$pass = $pass ? new StringLiteral($pass) : new StringLiteral('');
$domain = Domain::specifyType($host);
$path = new Path(\parse_url($urlString, PHP_URL_PATH));
$portNumber = $port ? new PortNumber($port) : new NullPortNumber();
$query = $queryString ? new QueryString(\sprintf('?%s', $queryString)) : new NullQueryString();
$fragment = $fragmentId ? new FragmentIdentifier(\sprintf('#%s', $fragmentId)) : new NullFragmentIdentifier();
return new self($scheme, $user, $pass, $domain, $portNumber, $path, $query, $fragment);
} | php | public static function fromNative()
{
$urlString = \func_get_arg(0);
$user = \parse_url($urlString, PHP_URL_USER);
$pass = \parse_url($urlString, PHP_URL_PASS);
$host = \parse_url($urlString, PHP_URL_HOST);
$queryString = \parse_url($urlString, PHP_URL_QUERY);
$fragmentId = \parse_url($urlString, PHP_URL_FRAGMENT);
$port = \parse_url($urlString, PHP_URL_PORT);
$scheme = new SchemeName(\parse_url($urlString, PHP_URL_SCHEME));
$user = $user ? new StringLiteral($user) : new StringLiteral('');
$pass = $pass ? new StringLiteral($pass) : new StringLiteral('');
$domain = Domain::specifyType($host);
$path = new Path(\parse_url($urlString, PHP_URL_PATH));
$portNumber = $port ? new PortNumber($port) : new NullPortNumber();
$query = $queryString ? new QueryString(\sprintf('?%s', $queryString)) : new NullQueryString();
$fragment = $fragmentId ? new FragmentIdentifier(\sprintf('#%s', $fragmentId)) : new NullFragmentIdentifier();
return new self($scheme, $user, $pass, $domain, $portNumber, $path, $query, $fragment);
} | [
"public",
"static",
"function",
"fromNative",
"(",
")",
"{",
"$",
"urlString",
"=",
"\\",
"func_get_arg",
"(",
"0",
")",
";",
"$",
"user",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_USER",
")",
";",
"$",
"pass",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_PASS",
")",
";",
"$",
"host",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_HOST",
")",
";",
"$",
"queryString",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_QUERY",
")",
";",
"$",
"fragmentId",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_FRAGMENT",
")",
";",
"$",
"port",
"=",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_PORT",
")",
";",
"$",
"scheme",
"=",
"new",
"SchemeName",
"(",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_SCHEME",
")",
")",
";",
"$",
"user",
"=",
"$",
"user",
"?",
"new",
"StringLiteral",
"(",
"$",
"user",
")",
":",
"new",
"StringLiteral",
"(",
"''",
")",
";",
"$",
"pass",
"=",
"$",
"pass",
"?",
"new",
"StringLiteral",
"(",
"$",
"pass",
")",
":",
"new",
"StringLiteral",
"(",
"''",
")",
";",
"$",
"domain",
"=",
"Domain",
"::",
"specifyType",
"(",
"$",
"host",
")",
";",
"$",
"path",
"=",
"new",
"Path",
"(",
"\\",
"parse_url",
"(",
"$",
"urlString",
",",
"PHP_URL_PATH",
")",
")",
";",
"$",
"portNumber",
"=",
"$",
"port",
"?",
"new",
"PortNumber",
"(",
"$",
"port",
")",
":",
"new",
"NullPortNumber",
"(",
")",
";",
"$",
"query",
"=",
"$",
"queryString",
"?",
"new",
"QueryString",
"(",
"\\",
"sprintf",
"(",
"'?%s'",
",",
"$",
"queryString",
")",
")",
":",
"new",
"NullQueryString",
"(",
")",
";",
"$",
"fragment",
"=",
"$",
"fragmentId",
"?",
"new",
"FragmentIdentifier",
"(",
"\\",
"sprintf",
"(",
"'#%s'",
",",
"$",
"fragmentId",
")",
")",
":",
"new",
"NullFragmentIdentifier",
"(",
")",
";",
"return",
"new",
"self",
"(",
"$",
"scheme",
",",
"$",
"user",
",",
"$",
"pass",
",",
"$",
"domain",
",",
"$",
"portNumber",
",",
"$",
"path",
",",
"$",
"query",
",",
"$",
"fragment",
")",
";",
"}"
]
| Returns a new Url object from a native url string
@param $url_string
@return Url | [
"Returns",
"a",
"new",
"Url",
"object",
"from",
"a",
"native",
"url",
"string"
]
| 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Web/Url.php#L41-L62 | train |
cubicmushroom/valueobjects | src/Web/Url.php | Url.sameValueAs | public function sameValueAs(ValueObjectInterface $url)
{
if (false === Util::classEquals($this, $url)) {
return false;
}
return $this->getScheme()->sameValueAs($url->getScheme()) &&
$this->getUser()->sameValueAs($url->getUser()) &&
$this->getPassword()->sameValueAs($url->getPassword()) &&
$this->getDomain()->sameValueAs($url->getDomain()) &&
$this->getPath()->sameValueAs($url->getPath()) &&
$this->getPort()->sameValueAs($url->getPort()) &&
$this->getQueryString()->sameValueAs($url->getQueryString()) &&
$this->getFragmentIdentifier()->sameValueAs($url->getFragmentIdentifier())
;
} | php | public function sameValueAs(ValueObjectInterface $url)
{
if (false === Util::classEquals($this, $url)) {
return false;
}
return $this->getScheme()->sameValueAs($url->getScheme()) &&
$this->getUser()->sameValueAs($url->getUser()) &&
$this->getPassword()->sameValueAs($url->getPassword()) &&
$this->getDomain()->sameValueAs($url->getDomain()) &&
$this->getPath()->sameValueAs($url->getPath()) &&
$this->getPort()->sameValueAs($url->getPort()) &&
$this->getQueryString()->sameValueAs($url->getQueryString()) &&
$this->getFragmentIdentifier()->sameValueAs($url->getFragmentIdentifier())
;
} | [
"public",
"function",
"sameValueAs",
"(",
"ValueObjectInterface",
"$",
"url",
")",
"{",
"if",
"(",
"false",
"===",
"Util",
"::",
"classEquals",
"(",
"$",
"this",
",",
"$",
"url",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getScheme",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getScheme",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getUser",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getPassword",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getPassword",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getDomain",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getDomain",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getPath",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getPath",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getPort",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getPort",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getQueryString",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getQueryString",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getFragmentIdentifier",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"url",
"->",
"getFragmentIdentifier",
"(",
")",
")",
";",
"}"
]
| Tells whether two Url are sameValueAs by comparing their components
@param ValueObjectInterface $url
@return bool | [
"Tells",
"whether",
"two",
"Url",
"are",
"sameValueAs",
"by",
"comparing",
"their",
"components"
]
| 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Web/Url.php#L94-L109 | train |
libreworks/caridea-session | src/FlashPlugin.php | FlashPlugin.clear | public function clear(bool $current = false): void
{
if ($current) {
$this->curr->clear();
}
$this->next->clear();
} | php | public function clear(bool $current = false): void
{
if ($current) {
$this->curr->clear();
}
$this->next->clear();
} | [
"public",
"function",
"clear",
"(",
"bool",
"$",
"current",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"$",
"current",
")",
"{",
"$",
"this",
"->",
"curr",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"next",
"->",
"clear",
"(",
")",
";",
"}"
]
| Removes any flash values for the _next_ request, optionally also in the _current_.
@param bool $current If true, also clears flash values from the _current_ request. | [
"Removes",
"any",
"flash",
"values",
"for",
"the",
"_next_",
"request",
"optionally",
"also",
"in",
"the",
"_current_",
"."
]
| cb2a7c0cdcd172edbf267e5c69b396708b425f47 | https://github.com/libreworks/caridea-session/blob/cb2a7c0cdcd172edbf267e5c69b396708b425f47/src/FlashPlugin.php#L58-L64 | train |
libreworks/caridea-session | src/FlashPlugin.php | FlashPlugin.getCurrent | public function getCurrent(string $name, $alt = null)
{
return $this->curr->get($name, $alt);
} | php | public function getCurrent(string $name, $alt = null)
{
return $this->curr->get($name, $alt);
} | [
"public",
"function",
"getCurrent",
"(",
"string",
"$",
"name",
",",
"$",
"alt",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"curr",
"->",
"get",
"(",
"$",
"name",
",",
"$",
"alt",
")",
";",
"}"
]
| Gets the flash value for a key in the _current_ request.
@param string $name The name
@param mixed $alt Optional default value to return
@return mixed The value, or the `$alt` if not found | [
"Gets",
"the",
"flash",
"value",
"for",
"a",
"key",
"in",
"the",
"_current_",
"request",
"."
]
| cb2a7c0cdcd172edbf267e5c69b396708b425f47 | https://github.com/libreworks/caridea-session/blob/cb2a7c0cdcd172edbf267e5c69b396708b425f47/src/FlashPlugin.php#L93-L96 | train |
libreworks/caridea-session | src/FlashPlugin.php | FlashPlugin.set | public function set(string $name, $value, bool $current = false): void
{
if ($current) {
$this->curr->offsetSet($name, $value);
}
$this->next->offsetSet($name, $value);
} | php | public function set(string $name, $value, bool $current = false): void
{
if ($current) {
$this->curr->offsetSet($name, $value);
}
$this->next->offsetSet($name, $value);
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"bool",
"$",
"current",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"$",
"current",
")",
"{",
"$",
"this",
"->",
"curr",
"->",
"offsetSet",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"next",
"->",
"offsetSet",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}"
]
| Sets a flash value for the _next_ request, optionally also in the _current_ request.
@param string $name The name
@param mixed $value The value
@param bool $current If true, also sets flash value for the _current_ request. | [
"Sets",
"a",
"flash",
"value",
"for",
"the",
"_next_",
"request",
"optionally",
"also",
"in",
"the",
"_current_",
"request",
"."
]
| cb2a7c0cdcd172edbf267e5c69b396708b425f47 | https://github.com/libreworks/caridea-session/blob/cb2a7c0cdcd172edbf267e5c69b396708b425f47/src/FlashPlugin.php#L125-L131 | train |
libreworks/caridea-session | src/FlashPlugin.php | FlashPlugin.cycle | protected function cycle()
{
if (!$this->moved) {
$this->curr->clear();
$this->curr->merge($this->next);
$this->next->clear();
$this->moved = true;
}
} | php | protected function cycle()
{
if (!$this->moved) {
$this->curr->clear();
$this->curr->merge($this->next);
$this->next->clear();
$this->moved = true;
}
} | [
"protected",
"function",
"cycle",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"moved",
")",
"{",
"$",
"this",
"->",
"curr",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"curr",
"->",
"merge",
"(",
"$",
"this",
"->",
"next",
")",
";",
"$",
"this",
"->",
"next",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"moved",
"=",
"true",
";",
"}",
"}"
]
| Transitions the values from next to current. | [
"Transitions",
"the",
"values",
"from",
"next",
"to",
"current",
"."
]
| cb2a7c0cdcd172edbf267e5c69b396708b425f47 | https://github.com/libreworks/caridea-session/blob/cb2a7c0cdcd172edbf267e5c69b396708b425f47/src/FlashPlugin.php#L146-L154 | train |
teonsystems/php-base | src/Mvc/Controller/Plugin/FlashMessengerNow.php | FlashMessengerNow.getMessagesFromContainer | protected function getMessagesFromContainer()
{
$container = $this->getContainer();
$namespaces = array();
foreach ($container as $namespace => $messages) {
if (isset($this->messages[$namespace])) {
$this->messages[$namespace] = array_merge($this->messages[$namespace], $messages);
} else {
$this->messages[$namespace] = $messages;
}
$namespaces[] = $namespace;
}
foreach ($namespaces as $namespace) {
unset($container->{$namespace});
}
} | php | protected function getMessagesFromContainer()
{
$container = $this->getContainer();
$namespaces = array();
foreach ($container as $namespace => $messages) {
if (isset($this->messages[$namespace])) {
$this->messages[$namespace] = array_merge($this->messages[$namespace], $messages);
} else {
$this->messages[$namespace] = $messages;
}
$namespaces[] = $namespace;
}
foreach ($namespaces as $namespace) {
unset($container->{$namespace});
}
} | [
"protected",
"function",
"getMessagesFromContainer",
"(",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"$",
"namespaces",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"container",
"as",
"$",
"namespace",
"=>",
"$",
"messages",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"messages",
"[",
"$",
"namespace",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"namespace",
"]",
",",
"$",
"messages",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"messages",
"[",
"$",
"namespace",
"]",
"=",
"$",
"messages",
";",
"}",
"$",
"namespaces",
"[",
"]",
"=",
"$",
"namespace",
";",
"}",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"unset",
"(",
"$",
"container",
"->",
"{",
"$",
"namespace",
"}",
")",
";",
"}",
"}"
]
| Pull messages from the session container, and merge them with current messages
Iterates through the session container, removing messages into the local
scope.
@return void | [
"Pull",
"messages",
"from",
"the",
"session",
"container",
"and",
"merge",
"them",
"with",
"current",
"messages"
]
| 010418fd9df3c447a74b36cf0d31e2d38a6527ac | https://github.com/teonsystems/php-base/blob/010418fd9df3c447a74b36cf0d31e2d38a6527ac/src/Mvc/Controller/Plugin/FlashMessengerNow.php#L49-L66 | train |
gplcart/cli | controllers/commands/Field.php | Field.cmdGetField | public function cmdGetField()
{
$result = $this->getListField();
$this->outputFormat($result);
$this->outputFormatTableField($result);
$this->output();
} | php | public function cmdGetField()
{
$result = $this->getListField();
$this->outputFormat($result);
$this->outputFormatTableField($result);
$this->output();
} | [
"public",
"function",
"cmdGetField",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListField",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableField",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
]
| Callback for "field-get" command | [
"Callback",
"for",
"field",
"-",
"get",
"command"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Field.php#L40-L46 | train |
gplcart/cli | controllers/commands/Field.php | Field.cmdUpdateField | public function cmdUpdateField()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('field');
$this->updateField($params[0]);
$this->output();
} | php | public function cmdUpdateField()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('field');
$this->updateField($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateField",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"updateField",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
]
| Callback for "field-update" command | [
"Callback",
"for",
"field",
"-",
"update",
"command"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Field.php#L117-L135 | train |
gplcart/cli | controllers/commands/Field.php | Field.submitAddField | protected function submitAddField()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('field');
$this->addField();
} | php | protected function submitAddField()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('field');
$this->addField();
} | [
"protected",
"function",
"submitAddField",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"addField",
"(",
")",
";",
"}"
]
| Add a new field at once | [
"Add",
"a",
"new",
"field",
"at",
"once"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Field.php#L227-L232 | train |
gplcart/cli | controllers/commands/Field.php | Field.wizardAddField | protected function wizardAddField()
{
// Required
$this->validatePrompt('title', $this->text('Name'), 'field');
$this->validateMenu('type', $this->text('Type'), 'field', $this->field->getTypes());
$this->validateMenu('widget', $this->text('Widget'), 'field', $this->field->getWidgetTypes());
// Optional
$this->validatePrompt('status', $this->text('Status'), 'field', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'field', 0);
$this->validateComponent('field');
$this->addField();
} | php | protected function wizardAddField()
{
// Required
$this->validatePrompt('title', $this->text('Name'), 'field');
$this->validateMenu('type', $this->text('Type'), 'field', $this->field->getTypes());
$this->validateMenu('widget', $this->text('Widget'), 'field', $this->field->getWidgetTypes());
// Optional
$this->validatePrompt('status', $this->text('Status'), 'field', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'field', 0);
$this->validateComponent('field');
$this->addField();
} | [
"protected",
"function",
"wizardAddField",
"(",
")",
"{",
"// Required",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"'field'",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'type'",
",",
"$",
"this",
"->",
"text",
"(",
"'Type'",
")",
",",
"'field'",
",",
"$",
"this",
"->",
"field",
"->",
"getTypes",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'widget'",
",",
"$",
"this",
"->",
"text",
"(",
"'Widget'",
")",
",",
"'field'",
",",
"$",
"this",
"->",
"field",
"->",
"getWidgetTypes",
"(",
")",
")",
";",
"// Optional",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'field'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'weight'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight'",
")",
",",
"'field'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'field'",
")",
";",
"$",
"this",
"->",
"addField",
"(",
")",
";",
"}"
]
| Add a new field step by step | [
"Add",
"a",
"new",
"field",
"step",
"by",
"step"
]
| e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Field.php#L237-L250 | train |
aVigorousDev/numbers | src/drmyersii/Words.php | Words.GetXX | public function GetXX($number_str, $modifer)
{
$number_int = intval($number_str);
if ($number_int >= 0 && $number_int < 100)
{
if (array_key_exists($number_int, $this->words->xx))
{
return $this->words->xx[$number_int];
}
else
{
throw new Exception('xx: Array index (' . $number_int . ') does not exist in JSON file.');
}
}
else
{
throw new Exception('xx: Number is not inclusively between 0 and 99!');
}
} | php | public function GetXX($number_str, $modifer)
{
$number_int = intval($number_str);
if ($number_int >= 0 && $number_int < 100)
{
if (array_key_exists($number_int, $this->words->xx))
{
return $this->words->xx[$number_int];
}
else
{
throw new Exception('xx: Array index (' . $number_int . ') does not exist in JSON file.');
}
}
else
{
throw new Exception('xx: Number is not inclusively between 0 and 99!');
}
} | [
"public",
"function",
"GetXX",
"(",
"$",
"number_str",
",",
"$",
"modifer",
")",
"{",
"$",
"number_int",
"=",
"intval",
"(",
"$",
"number_str",
")",
";",
"if",
"(",
"$",
"number_int",
">=",
"0",
"&&",
"$",
"number_int",
"<",
"100",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"number_int",
",",
"$",
"this",
"->",
"words",
"->",
"xx",
")",
")",
"{",
"return",
"$",
"this",
"->",
"words",
"->",
"xx",
"[",
"$",
"number_int",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'xx: Array index ('",
".",
"$",
"number_int",
".",
"') does not exist in JSON file.'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'xx: Number is not inclusively between 0 and 99!'",
")",
";",
"}",
"}"
]
| Pass in a number that is inclusively between 0 and 99, and it will return the corresponding
words.
@param $number string
@param $modifier string
@return string | [
"Pass",
"in",
"a",
"number",
"that",
"is",
"inclusively",
"between",
"0",
"and",
"99",
"and",
"it",
"will",
"return",
"the",
"corresponding",
"words",
"."
]
| 02124e75286758d216a22d1d963946dab9e8582b | https://github.com/aVigorousDev/numbers/blob/02124e75286758d216a22d1d963946dab9e8582b/src/drmyersii/Words.php#L31-L50 | train |
codeblanche/Web | src/Web/Response/Response.php | Response.send | public function send($output, OutputStrategyInterface $outputStrategy = null)
{
if (!($outputStrategy instanceof OutputStrategyInterface)) {
$outputStrategy = $this->defaultOutputStrategy;
}
$contentType = new Header(
Header::CONTENT_TYPE,
$outputStrategy->getMime()
);
$this->header($contentType);
return $outputStrategy->send($output);
} | php | public function send($output, OutputStrategyInterface $outputStrategy = null)
{
if (!($outputStrategy instanceof OutputStrategyInterface)) {
$outputStrategy = $this->defaultOutputStrategy;
}
$contentType = new Header(
Header::CONTENT_TYPE,
$outputStrategy->getMime()
);
$this->header($contentType);
return $outputStrategy->send($output);
} | [
"public",
"function",
"send",
"(",
"$",
"output",
",",
"OutputStrategyInterface",
"$",
"outputStrategy",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"outputStrategy",
"instanceof",
"OutputStrategyInterface",
")",
")",
"{",
"$",
"outputStrategy",
"=",
"$",
"this",
"->",
"defaultOutputStrategy",
";",
"}",
"$",
"contentType",
"=",
"new",
"Header",
"(",
"Header",
"::",
"CONTENT_TYPE",
",",
"$",
"outputStrategy",
"->",
"getMime",
"(",
")",
")",
";",
"$",
"this",
"->",
"header",
"(",
"$",
"contentType",
")",
";",
"return",
"$",
"outputStrategy",
"->",
"send",
"(",
"$",
"output",
")",
";",
"}"
]
| Send the given output using the given or default output strategy.
@param string $output
@param OutputStrategyInterface $outputStrategy
@return int | [
"Send",
"the",
"given",
"output",
"using",
"the",
"given",
"or",
"default",
"output",
"strategy",
"."
]
| 3e9ebf1943d3ea468f619ba99f7cc10714cb16e9 | https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Response/Response.php#L125-L139 | train |
codeblanche/Web | src/Web/Response/Response.php | Response.sendFile | public function sendFile($src)
{
$pointer = fopen($src, 'r');
if (!is_resource($pointer)) {
throw new RuntimeException("Unable to load '$src' for sending.");
}
$result = fpassthru($pointer);
fclose($pointer);
return $result;
} | php | public function sendFile($src)
{
$pointer = fopen($src, 'r');
if (!is_resource($pointer)) {
throw new RuntimeException("Unable to load '$src' for sending.");
}
$result = fpassthru($pointer);
fclose($pointer);
return $result;
} | [
"public",
"function",
"sendFile",
"(",
"$",
"src",
")",
"{",
"$",
"pointer",
"=",
"fopen",
"(",
"$",
"src",
",",
"'r'",
")",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"pointer",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unable to load '$src' for sending.\"",
")",
";",
"}",
"$",
"result",
"=",
"fpassthru",
"(",
"$",
"pointer",
")",
";",
"fclose",
"(",
"$",
"pointer",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Directly output results from a file. This bypasses the output strategy altogether.
@param $src
@throws RuntimeException
@return int|bool | [
"Directly",
"output",
"results",
"from",
"a",
"file",
".",
"This",
"bypasses",
"the",
"output",
"strategy",
"altogether",
"."
]
| 3e9ebf1943d3ea468f619ba99f7cc10714cb16e9 | https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Response/Response.php#L149-L162 | train |
OliverMonneke/pennePHP | src/Mathematic/Calculate.php | Calculate.divide | public function divide($number)
{
if (Number::isZero($number)) {
throw new DivisionByZeroException;
}
$this->number = $this->number / $number;
return $this;
} | php | public function divide($number)
{
if (Number::isZero($number)) {
throw new DivisionByZeroException;
}
$this->number = $this->number / $number;
return $this;
} | [
"public",
"function",
"divide",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"Number",
"::",
"isZero",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"DivisionByZeroException",
";",
"}",
"$",
"this",
"->",
"number",
"=",
"$",
"this",
"->",
"number",
"/",
"$",
"number",
";",
"return",
"$",
"this",
";",
"}"
]
| Divide a value
@param int|float $number The number
@throws DivisionByZeroException
@return Calculate | [
"Divide",
"a",
"value"
]
| dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Mathematic/Calculate.php#L89-L98 | train |
OliverMonneke/pennePHP | src/Mathematic/Calculate.php | Calculate.round | public function round($precision = 0, $mode = PHP_ROUND_HALF_UP)
{
$this->number = round($this->number, $precision, $mode);
return $this;
} | php | public function round($precision = 0, $mode = PHP_ROUND_HALF_UP)
{
$this->number = round($this->number, $precision, $mode);
return $this;
} | [
"public",
"function",
"round",
"(",
"$",
"precision",
"=",
"0",
",",
"$",
"mode",
"=",
"PHP_ROUND_HALF_UP",
")",
"{",
"$",
"this",
"->",
"number",
"=",
"round",
"(",
"$",
"this",
"->",
"number",
",",
"$",
"precision",
",",
"$",
"mode",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Round the value
@param int $precision The precision
@param int $mode Mode to round
@return Calculate | [
"Round",
"the",
"value"
]
| dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Mathematic/Calculate.php#L108-L113 | train |
OliverMonneke/pennePHP | src/Mathematic/Calculate.php | Calculate.toTheN | public function toTheN($number)
{
for ($i = 1; $i <= $number; $i++) {
$this->multiply($this->number);
}
return $this;
} | php | public function toTheN($number)
{
for ($i = 1; $i <= $number; $i++) {
$this->multiply($this->number);
}
return $this;
} | [
"public",
"function",
"toTheN",
"(",
"$",
"number",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"number",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"multiply",
"(",
"$",
"this",
"->",
"number",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| To the n expression
@param number $number The number
@return Calculate | [
"To",
"the",
"n",
"expression"
]
| dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Mathematic/Calculate.php#L122-L129 | train |
rollerworks/search-core | Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php | DateTimeToTimestampTransformer.transform | public function transform($dateTime): ?int
{
if (null === $dateTime) {
return null;
}
if (!$dateTime instanceof \DateTimeInterface) {
throw new TransformationFailedException('Expected a \DateTimeInterface.');
}
return $dateTime->getTimestamp();
} | php | public function transform($dateTime): ?int
{
if (null === $dateTime) {
return null;
}
if (!$dateTime instanceof \DateTimeInterface) {
throw new TransformationFailedException('Expected a \DateTimeInterface.');
}
return $dateTime->getTimestamp();
} | [
"public",
"function",
"transform",
"(",
"$",
"dateTime",
")",
":",
"?",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"dateTime",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"dateTime",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"'Expected a \\DateTimeInterface.'",
")",
";",
"}",
"return",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
";",
"}"
]
| Transforms a DateTime object into a timestamp in the configured timezone.
@param \DateTimeInterface|null $dateTime
@throws TransformationFailedException If the given value is not a \DateTimeInterface
@return int|null A timestamp | [
"Transforms",
"a",
"DateTime",
"object",
"into",
"a",
"timestamp",
"in",
"the",
"configured",
"timezone",
"."
]
| 6b5671b8c4d6298906ded768261b0a59845140fb | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php#L35-L46 | train |
DaGhostman/codewave | src/Router/ExtendedRouteCollector.php | ExtendedRouteCollector.getData | public function getData()
{
if ($this->cacheProvider !== null &&
$this->cacheProvider->contains('routerCache')) {
return $this->cacheProvider->fetch('routerCache');
}
return parent::getData();
} | php | public function getData()
{
if ($this->cacheProvider !== null &&
$this->cacheProvider->contains('routerCache')) {
return $this->cacheProvider->fetch('routerCache');
}
return parent::getData();
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheProvider",
"!==",
"null",
"&&",
"$",
"this",
"->",
"cacheProvider",
"->",
"contains",
"(",
"'routerCache'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cacheProvider",
"->",
"fetch",
"(",
"'routerCache'",
")",
";",
"}",
"return",
"parent",
"::",
"getData",
"(",
")",
";",
"}"
]
| Returns the collected route data, as provided by the data generator.
@return array | [
"Returns",
"the",
"collected",
"route",
"data",
"as",
"provided",
"by",
"the",
"data",
"generator",
"."
]
| f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Router/ExtendedRouteCollector.php#L63-L71 | train |
pluf/tenant | src/Tenant/SPA/Manager/Simple.php | Tenant_SPA_Manager_Simple.checkUpdate | public static function checkUpdate($request, $object)
{
$repo = new Tenant_Views_SpaRepository();
$spa = $repo->get(new Pluf_HTTP_Request('/'), array(
'modelId' => $object->name
));
$object->last_version = $spa->version;
$object->update();
return $object;
} | php | public static function checkUpdate($request, $object)
{
$repo = new Tenant_Views_SpaRepository();
$spa = $repo->get(new Pluf_HTTP_Request('/'), array(
'modelId' => $object->name
));
$object->last_version = $spa->version;
$object->update();
return $object;
} | [
"public",
"static",
"function",
"checkUpdate",
"(",
"$",
"request",
",",
"$",
"object",
")",
"{",
"$",
"repo",
"=",
"new",
"Tenant_Views_SpaRepository",
"(",
")",
";",
"$",
"spa",
"=",
"$",
"repo",
"->",
"get",
"(",
"new",
"Pluf_HTTP_Request",
"(",
"'/'",
")",
",",
"array",
"(",
"'modelId'",
"=>",
"$",
"object",
"->",
"name",
")",
")",
";",
"$",
"object",
"->",
"last_version",
"=",
"$",
"spa",
"->",
"version",
";",
"$",
"object",
"->",
"update",
"(",
")",
";",
"return",
"$",
"object",
";",
"}"
]
| Check update of an spa
@param Pluf_HTTP_Request $request
@param Tenant_SPA $object | [
"Check",
"update",
"of",
"an",
"spa"
]
| a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/SPA/Manager/Simple.php#L152-L161 | train |
pluf/tenant | src/Tenant/SPA/Manager/Simple.php | Tenant_SPA_Manager_Simple.update | public static function update($request, $object)
{
// request param
$backend = Pluf::f('marketplace.backend', 'http://marketplace.webpich.com');
$path = '/api/v2/marketplace/spas/' . $object->name . '/file';
$file = Pluf::f('temp_folder', '/tmp') . '/spa-' . rand();
// Do request
$client = new GuzzleHttp\Client();
$response = $client->request('GET', $backend . $path, [
'sink' => $file
]);
return Tenant_SpaService::updateFromFile($object, $file, true);
} | php | public static function update($request, $object)
{
// request param
$backend = Pluf::f('marketplace.backend', 'http://marketplace.webpich.com');
$path = '/api/v2/marketplace/spas/' . $object->name . '/file';
$file = Pluf::f('temp_folder', '/tmp') . '/spa-' . rand();
// Do request
$client = new GuzzleHttp\Client();
$response = $client->request('GET', $backend . $path, [
'sink' => $file
]);
return Tenant_SpaService::updateFromFile($object, $file, true);
} | [
"public",
"static",
"function",
"update",
"(",
"$",
"request",
",",
"$",
"object",
")",
"{",
"// request param",
"$",
"backend",
"=",
"Pluf",
"::",
"f",
"(",
"'marketplace.backend'",
",",
"'http://marketplace.webpich.com'",
")",
";",
"$",
"path",
"=",
"'/api/v2/marketplace/spas/'",
".",
"$",
"object",
"->",
"name",
".",
"'/file'",
";",
"$",
"file",
"=",
"Pluf",
"::",
"f",
"(",
"'temp_folder'",
",",
"'/tmp'",
")",
".",
"'/spa-'",
".",
"rand",
"(",
")",
";",
"// Do request",
"$",
"client",
"=",
"new",
"GuzzleHttp",
"\\",
"Client",
"(",
")",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"request",
"(",
"'GET'",
",",
"$",
"backend",
".",
"$",
"path",
",",
"[",
"'sink'",
"=>",
"$",
"file",
"]",
")",
";",
"return",
"Tenant_SpaService",
"::",
"updateFromFile",
"(",
"$",
"object",
",",
"$",
"file",
",",
"true",
")",
";",
"}"
]
| Update an spa
@param Pluf_HTTP_Request $request
@param Tenant_SPA $object | [
"Update",
"an",
"spa"
]
| a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/SPA/Manager/Simple.php#L169-L181 | train |
GeckoPackages/GeckoMemcacheMock | src/MemcacheMock/MemcachedMock.php | MemcachedMock.storeValueInCache | private function storeValueInCache($key, $value, $expiration = null)
{
$this->cache[$key] = new MemcacheObject($key, serialize($value), $this->normalizeExpirationTime($expiration));
} | php | private function storeValueInCache($key, $value, $expiration = null)
{
$this->cache[$key] = new MemcacheObject($key, serialize($value), $this->normalizeExpirationTime($expiration));
} | [
"private",
"function",
"storeValueInCache",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expiration",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"key",
"]",
"=",
"new",
"MemcacheObject",
"(",
"$",
"key",
",",
"serialize",
"(",
"$",
"value",
")",
",",
"$",
"this",
"->",
"normalizeExpirationTime",
"(",
"$",
"expiration",
")",
")",
";",
"}"
]
| Dumb setter, no checks by design.
@param string $key
@param mixed $value
@param int $expiration | [
"Dumb",
"setter",
"no",
"checks",
"by",
"design",
"."
]
| 33be1e858de764cf274f9d7c44627fa63cf50856 | https://github.com/GeckoPackages/GeckoMemcacheMock/blob/33be1e858de764cf274f9d7c44627fa63cf50856/src/MemcacheMock/MemcachedMock.php#L1336-L1339 | train |
Innmind/Math | src/Matrix.php | Matrix.initialize | public static function initialize(Dimension $dimension, Number $value): self
{
$rows = [];
$count = $dimension->rows()->value();
for ($i = 0; $i < $count; ++$i) {
$rows[] = new RowVector(
...array_fill(
0,
$dimension->columns()->value(),
$value
)
);
}
return new self(...$rows);
} | php | public static function initialize(Dimension $dimension, Number $value): self
{
$rows = [];
$count = $dimension->rows()->value();
for ($i = 0; $i < $count; ++$i) {
$rows[] = new RowVector(
...array_fill(
0,
$dimension->columns()->value(),
$value
)
);
}
return new self(...$rows);
} | [
"public",
"static",
"function",
"initialize",
"(",
"Dimension",
"$",
"dimension",
",",
"Number",
"$",
"value",
")",
":",
"self",
"{",
"$",
"rows",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"$",
"dimension",
"->",
"rows",
"(",
")",
"->",
"value",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"new",
"RowVector",
"(",
"...",
"array_fill",
"(",
"0",
",",
"$",
"dimension",
"->",
"columns",
"(",
")",
"->",
"value",
"(",
")",
",",
"$",
"value",
")",
")",
";",
"}",
"return",
"new",
"self",
"(",
"...",
"$",
"rows",
")",
";",
"}"
]
| Initialize a matrix to the wished dimension filled with the specified value | [
"Initialize",
"a",
"matrix",
"to",
"the",
"wished",
"dimension",
"filled",
"with",
"the",
"specified",
"value"
]
| ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Matrix.php#L87-L103 | train |
t3v/t3v_core | Classes/Utility/GeneralUtility.php | GeneralUtility.identifier | public static function identifier(string $name, string $separator = '_'): string {
$slugify = new Slugify(['separator' => $separator]);
$identifier = $slugify->slugify($name);
return $identifier;
} | php | public static function identifier(string $name, string $separator = '_'): string {
$slugify = new Slugify(['separator' => $separator]);
$identifier = $slugify->slugify($name);
return $identifier;
} | [
"public",
"static",
"function",
"identifier",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"separator",
"=",
"'_'",
")",
":",
"string",
"{",
"$",
"slugify",
"=",
"new",
"Slugify",
"(",
"[",
"'separator'",
"=>",
"$",
"separator",
"]",
")",
";",
"$",
"identifier",
"=",
"$",
"slugify",
"->",
"slugify",
"(",
"$",
"name",
")",
";",
"return",
"$",
"identifier",
";",
"}"
]
| Gets an identifier from a name.
@param string $name The name
@param string $separator The optional separator, defaults to `_`
@return string The identifier | [
"Gets",
"an",
"identifier",
"from",
"a",
"name",
"."
]
| 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Utility/GeneralUtility.php#L19-L24 | train |
t3v/t3v_core | Classes/Utility/GeneralUtility.php | GeneralUtility.getIdentifier | public static function getIdentifier(string $name, string $separator = '_'): string {
return self::identifier($name, $separator);
} | php | public static function getIdentifier(string $name, string $separator = '_'): string {
return self::identifier($name, $separator);
} | [
"public",
"static",
"function",
"getIdentifier",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"separator",
"=",
"'_'",
")",
":",
"string",
"{",
"return",
"self",
"::",
"identifier",
"(",
"$",
"name",
",",
"$",
"separator",
")",
";",
"}"
]
| Alias for the `identifier` function.
@param string $name The name
@param string $separator The optional separator, defaults to `_`
@return string The identifier | [
"Alias",
"for",
"the",
"identifier",
"function",
"."
]
| 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Utility/GeneralUtility.php#L33-L35 | train |
TuumPHP/Web | src/Stack/DocView.php | DocView.handle | private function handle($request)
{
$found = $this->fileMap->render($request->getPathToMatch());
if (empty($found)) {
return null;
}
if (is_resource($found[0])) {
return $request->respond()->asFileContents($found[0], $found[1]);
}
if (is_string($found[0])) {
return $request->respond()->asContents($found[0]);
}
return null;
} | php | private function handle($request)
{
$found = $this->fileMap->render($request->getPathToMatch());
if (empty($found)) {
return null;
}
if (is_resource($found[0])) {
return $request->respond()->asFileContents($found[0], $found[1]);
}
if (is_string($found[0])) {
return $request->respond()->asContents($found[0]);
}
return null;
} | [
"private",
"function",
"handle",
"(",
"$",
"request",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"fileMap",
"->",
"render",
"(",
"$",
"request",
"->",
"getPathToMatch",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"found",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"found",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"request",
"->",
"respond",
"(",
")",
"->",
"asFileContents",
"(",
"$",
"found",
"[",
"0",
"]",
",",
"$",
"found",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"found",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"request",
"->",
"respond",
"(",
")",
"->",
"asContents",
"(",
"$",
"found",
"[",
"0",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| do the quick extension check.
@param Request $request
@return null|Response | [
"do",
"the",
"quick",
"extension",
"check",
"."
]
| 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/DocView.php#L79-L92 | train |
TuumPHP/Web | src/Stack/DocView.php | DocView.options | public function options(array $options)
{
if (array_key_exists('enable_raw', $options)) {
$this->fileMap->enable_raw = (bool) $options['enable_raw'];
}
if (array_key_exists('before', $options)) {
$this->setBeforeFilter($options['before']);
}
if (array_key_exists('after', $options)) {
$this->setAfterRelease($options['after']);
}
if (array_key_exists('roots', $options)) {
foreach($options['roots'] as $root) {
$this->setRoot($root);
}
}
} | php | public function options(array $options)
{
if (array_key_exists('enable_raw', $options)) {
$this->fileMap->enable_raw = (bool) $options['enable_raw'];
}
if (array_key_exists('before', $options)) {
$this->setBeforeFilter($options['before']);
}
if (array_key_exists('after', $options)) {
$this->setAfterRelease($options['after']);
}
if (array_key_exists('roots', $options)) {
foreach($options['roots'] as $root) {
$this->setRoot($root);
}
}
} | [
"public",
"function",
"options",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'enable_raw'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"fileMap",
"->",
"enable_raw",
"=",
"(",
"bool",
")",
"$",
"options",
"[",
"'enable_raw'",
"]",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'before'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setBeforeFilter",
"(",
"$",
"options",
"[",
"'before'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'after'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setAfterRelease",
"(",
"$",
"options",
"[",
"'after'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'roots'",
",",
"$",
"options",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'roots'",
"]",
"as",
"$",
"root",
")",
"{",
"$",
"this",
"->",
"setRoot",
"(",
"$",
"root",
")",
";",
"}",
"}",
"}"
]
| set up optional behavior.
- 'enable_raw' : enables raw view for markdown files.
- 'before' : sets before filters.
- 'after' : sets after release filters.
@param array $options | [
"set",
"up",
"optional",
"behavior",
"."
]
| 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Stack/DocView.php#L103-L119 | train |
shgysk8zer0/core_api | traits/socket_server.php | Socket_Server.socketRecv | final public function socketRecv(&$buff, $len, $flags)
{
return socket_recv($this->socket, $buff, $len, $flags);
} | php | final public function socketRecv(&$buff, $len, $flags)
{
return socket_recv($this->socket, $buff, $len, $flags);
} | [
"final",
"public",
"function",
"socketRecv",
"(",
"&",
"$",
"buff",
",",
"$",
"len",
",",
"$",
"flags",
")",
"{",
"return",
"socket_recv",
"(",
"$",
"this",
"->",
"socket",
",",
"$",
"buff",
",",
"$",
"len",
",",
"$",
"flags",
")",
";",
"}"
]
| Receives data from a connected socket
@param string $buff Data received will be fetched to the variable
@param int $len Up to len bytes will be fetched from remote host
@param int $flags MSG_(OOB|PEEK|WAITALL|DONTWAIT) joined with the binary OR (|) operator | [
"Receives",
"data",
"from",
"a",
"connected",
"socket"
]
| 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/socket_server.php#L120-L123 | train |
shgysk8zer0/core_api | traits/socket_server.php | Socket_Server.socketRecvfrom | final public function socketRecvfrom(&$buff, $len, $flags, &$name, &$port = null)
{
return socket_recvfrom($this->socket, $buff, $len, $flags, $name, $port);
} | php | final public function socketRecvfrom(&$buff, $len, $flags, &$name, &$port = null)
{
return socket_recvfrom($this->socket, $buff, $len, $flags, $name, $port);
} | [
"final",
"public",
"function",
"socketRecvfrom",
"(",
"&",
"$",
"buff",
",",
"$",
"len",
",",
"$",
"flags",
",",
"&",
"$",
"name",
",",
"&",
"$",
"port",
"=",
"null",
")",
"{",
"return",
"socket_recvfrom",
"(",
"$",
"this",
"->",
"socket",
",",
"$",
"buff",
",",
"$",
"len",
",",
"$",
"flags",
",",
"$",
"name",
",",
"$",
"port",
")",
";",
"}"
]
| Receives data from a socket whether or not it is connection-oriented
@param string $buff The data received
@param int $len Up to len bytes will be fetched from remote host
@param int $flags MSG_(OOB|PEEK|WAITALL|DONTWAIT) joined with the binary OR (|) operator
@param string $name Path for AF_UNIX, IP address, or null for connection-oriented
@param int $port [description] | [
"Receives",
"data",
"from",
"a",
"socket",
"whether",
"or",
"not",
"it",
"is",
"connection",
"-",
"oriented"
]
| 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/socket_server.php#L134-L137 | train |
shgysk8zer0/core_api | traits/socket_server.php | Socket_Server.socketStrerror | final public function socketStrerror($errno = null)
{
if (! is_int($errno)) {
$errno = $this->socketLastError();
}
return socket_strerror($errno);
} | php | final public function socketStrerror($errno = null)
{
if (! is_int($errno)) {
$errno = $this->socketLastError();
}
return socket_strerror($errno);
} | [
"final",
"public",
"function",
"socketStrerror",
"(",
"$",
"errno",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"errno",
")",
")",
"{",
"$",
"errno",
"=",
"$",
"this",
"->",
"socketLastError",
"(",
")",
";",
"}",
"return",
"socket_strerror",
"(",
"$",
"errno",
")",
";",
"}"
]
| Return a string describing a socket error
@param int $errno A valid socket error number, likely produced by socket_last_error()
@return string The error message associated with the errno parameter | [
"Return",
"a",
"string",
"describing",
"a",
"socket",
"error"
]
| 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/socket_server.php#L156-L163 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.setSource | public function setSource(ChildSource $v = null)
{
if ($v === null) {
$this->setSourceId(NULL);
} else {
$this->setSourceId($v->getId());
}
$this->aSource = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the ChildSource object, it will not be re-added.
if ($v !== null) {
$v->addPage($this);
}
return $this;
} | php | public function setSource(ChildSource $v = null)
{
if ($v === null) {
$this->setSourceId(NULL);
} else {
$this->setSourceId($v->getId());
}
$this->aSource = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the ChildSource object, it will not be re-added.
if ($v !== null) {
$v->addPage($this);
}
return $this;
} | [
"public",
"function",
"setSource",
"(",
"ChildSource",
"$",
"v",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"v",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setSourceId",
"(",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setSourceId",
"(",
"$",
"v",
"->",
"getId",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"aSource",
"=",
"$",
"v",
";",
"// Add binding for other direction of this n:n relationship.",
"// If this object has already been added to the ChildSource object, it will not be re-added.",
"if",
"(",
"$",
"v",
"!==",
"null",
")",
"{",
"$",
"v",
"->",
"addPage",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Declares an association between this object and a ChildSource object.
@param ChildSource $v
@return $this|\Attogram\SharedMedia\Orm\Page The current object (for fluent API support)
@throws PropelException | [
"Declares",
"an",
"association",
"between",
"this",
"object",
"and",
"a",
"ChildSource",
"object",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L1734-L1752 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.getSource | public function getSource(ConnectionInterface $con = null)
{
if ($this->aSource === null && ($this->source_id != 0)) {
$this->aSource = ChildSourceQuery::create()->findPk($this->source_id, $con);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aSource->addPages($this);
*/
}
return $this->aSource;
} | php | public function getSource(ConnectionInterface $con = null)
{
if ($this->aSource === null && ($this->source_id != 0)) {
$this->aSource = ChildSourceQuery::create()->findPk($this->source_id, $con);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aSource->addPages($this);
*/
}
return $this->aSource;
} | [
"public",
"function",
"getSource",
"(",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aSource",
"===",
"null",
"&&",
"(",
"$",
"this",
"->",
"source_id",
"!=",
"0",
")",
")",
"{",
"$",
"this",
"->",
"aSource",
"=",
"ChildSourceQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
"(",
"$",
"this",
"->",
"source_id",
",",
"$",
"con",
")",
";",
"/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aSource->addPages($this);\n */",
"}",
"return",
"$",
"this",
"->",
"aSource",
";",
"}"
]
| Get the associated ChildSource object
@param ConnectionInterface $con Optional Connection object.
@return ChildSource The associated ChildSource object.
@throws PropelException | [
"Get",
"the",
"associated",
"ChildSource",
"object"
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L1762-L1776 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.initC2Ps | public function initC2Ps($overrideExisting = true)
{
if (null !== $this->collC2Ps && !$overrideExisting) {
return;
}
$collectionClassName = C2PTableMap::getTableMap()->getCollectionClassName();
$this->collC2Ps = new $collectionClassName;
$this->collC2Ps->setModel('\Attogram\SharedMedia\Orm\C2P');
} | php | public function initC2Ps($overrideExisting = true)
{
if (null !== $this->collC2Ps && !$overrideExisting) {
return;
}
$collectionClassName = C2PTableMap::getTableMap()->getCollectionClassName();
$this->collC2Ps = new $collectionClassName;
$this->collC2Ps->setModel('\Attogram\SharedMedia\Orm\C2P');
} | [
"public",
"function",
"initC2Ps",
"(",
"$",
"overrideExisting",
"=",
"true",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"collC2Ps",
"&&",
"!",
"$",
"overrideExisting",
")",
"{",
"return",
";",
"}",
"$",
"collectionClassName",
"=",
"C2PTableMap",
"::",
"getTableMap",
"(",
")",
"->",
"getCollectionClassName",
"(",
")",
";",
"$",
"this",
"->",
"collC2Ps",
"=",
"new",
"$",
"collectionClassName",
";",
"$",
"this",
"->",
"collC2Ps",
"->",
"setModel",
"(",
"'\\Attogram\\SharedMedia\\Orm\\C2P'",
")",
";",
"}"
]
| Initializes the collC2Ps collection.
By default this just sets the collC2Ps collection to an empty array (like clearcollC2Ps());
however, you may wish to override this method in your stub class to provide setting appropriate
to your application -- for example, setting the initial array to the values stored in database.
@param boolean $overrideExisting If set to true, the method call initializes
the collection even if it is not empty
@return void | [
"Initializes",
"the",
"collC2Ps",
"collection",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L1833-L1843 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.getC2Ps | public function getC2Ps(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collC2PsPartial && !$this->isNew();
if (null === $this->collC2Ps || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collC2Ps) {
// return empty collection
$this->initC2Ps();
} else {
$collC2Ps = ChildC2PQuery::create(null, $criteria)
->filterByPage($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collC2PsPartial && count($collC2Ps)) {
$this->initC2Ps(false);
foreach ($collC2Ps as $obj) {
if (false == $this->collC2Ps->contains($obj)) {
$this->collC2Ps->append($obj);
}
}
$this->collC2PsPartial = true;
}
return $collC2Ps;
}
if ($partial && $this->collC2Ps) {
foreach ($this->collC2Ps as $obj) {
if ($obj->isNew()) {
$collC2Ps[] = $obj;
}
}
}
$this->collC2Ps = $collC2Ps;
$this->collC2PsPartial = false;
}
}
return $this->collC2Ps;
} | php | public function getC2Ps(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collC2PsPartial && !$this->isNew();
if (null === $this->collC2Ps || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collC2Ps) {
// return empty collection
$this->initC2Ps();
} else {
$collC2Ps = ChildC2PQuery::create(null, $criteria)
->filterByPage($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collC2PsPartial && count($collC2Ps)) {
$this->initC2Ps(false);
foreach ($collC2Ps as $obj) {
if (false == $this->collC2Ps->contains($obj)) {
$this->collC2Ps->append($obj);
}
}
$this->collC2PsPartial = true;
}
return $collC2Ps;
}
if ($partial && $this->collC2Ps) {
foreach ($this->collC2Ps as $obj) {
if ($obj->isNew()) {
$collC2Ps[] = $obj;
}
}
}
$this->collC2Ps = $collC2Ps;
$this->collC2PsPartial = false;
}
}
return $this->collC2Ps;
} | [
"public",
"function",
"getC2Ps",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collC2PsPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collC2Ps",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collC2Ps",
")",
"{",
"// return empty collection",
"$",
"this",
"->",
"initC2Ps",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collC2Ps",
"=",
"ChildC2PQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
"->",
"filterByPage",
"(",
"$",
"this",
")",
"->",
"find",
"(",
"$",
"con",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"criteria",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"collC2PsPartial",
"&&",
"count",
"(",
"$",
"collC2Ps",
")",
")",
"{",
"$",
"this",
"->",
"initC2Ps",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"collC2Ps",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"collC2Ps",
"->",
"contains",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"this",
"->",
"collC2Ps",
"->",
"append",
"(",
"$",
"obj",
")",
";",
"}",
"}",
"$",
"this",
"->",
"collC2PsPartial",
"=",
"true",
";",
"}",
"return",
"$",
"collC2Ps",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"$",
"this",
"->",
"collC2Ps",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collC2Ps",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isNew",
"(",
")",
")",
"{",
"$",
"collC2Ps",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"collC2Ps",
"=",
"$",
"collC2Ps",
";",
"$",
"this",
"->",
"collC2PsPartial",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"collC2Ps",
";",
"}"
]
| Gets an array of ChildC2P objects which contain a foreign key that references this object.
If the $criteria is not null, it is used to always fetch the results from the database.
Otherwise the results are fetched from the database the first time, then cached.
Next time the same method is called without $criteria, the cached collection is returned.
If this ChildPage is new, it will return
an empty collection or the current collection; the criteria is ignored on a new object.
@param Criteria $criteria optional Criteria object to narrow the query
@param ConnectionInterface $con optional connection object
@return ObjectCollection|ChildC2P[] List of ChildC2P objects
@throws PropelException | [
"Gets",
"an",
"array",
"of",
"ChildC2P",
"objects",
"which",
"contain",
"a",
"foreign",
"key",
"that",
"references",
"this",
"object",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L1859-L1901 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.addC2P | public function addC2P(ChildC2P $l)
{
if ($this->collC2Ps === null) {
$this->initC2Ps();
$this->collC2PsPartial = true;
}
if (!$this->collC2Ps->contains($l)) {
$this->doAddC2P($l);
if ($this->c2PsScheduledForDeletion and $this->c2PsScheduledForDeletion->contains($l)) {
$this->c2PsScheduledForDeletion->remove($this->c2PsScheduledForDeletion->search($l));
}
}
return $this;
} | php | public function addC2P(ChildC2P $l)
{
if ($this->collC2Ps === null) {
$this->initC2Ps();
$this->collC2PsPartial = true;
}
if (!$this->collC2Ps->contains($l)) {
$this->doAddC2P($l);
if ($this->c2PsScheduledForDeletion and $this->c2PsScheduledForDeletion->contains($l)) {
$this->c2PsScheduledForDeletion->remove($this->c2PsScheduledForDeletion->search($l));
}
}
return $this;
} | [
"public",
"function",
"addC2P",
"(",
"ChildC2P",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collC2Ps",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initC2Ps",
"(",
")",
";",
"$",
"this",
"->",
"collC2PsPartial",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"collC2Ps",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"doAddC2P",
"(",
"$",
"l",
")",
";",
"if",
"(",
"$",
"this",
"->",
"c2PsScheduledForDeletion",
"and",
"$",
"this",
"->",
"c2PsScheduledForDeletion",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"c2PsScheduledForDeletion",
"->",
"remove",
"(",
"$",
"this",
"->",
"c2PsScheduledForDeletion",
"->",
"search",
"(",
"$",
"l",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method called to associate a ChildC2P object to this object
through the ChildC2P foreign key attribute.
@param ChildC2P $l ChildC2P
@return $this|\Attogram\SharedMedia\Orm\Page The current object (for fluent API support) | [
"Method",
"called",
"to",
"associate",
"a",
"ChildC2P",
"object",
"to",
"this",
"object",
"through",
"the",
"ChildC2P",
"foreign",
"key",
"attribute",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L1980-L1996 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.initM2Ps | public function initM2Ps($overrideExisting = true)
{
if (null !== $this->collM2Ps && !$overrideExisting) {
return;
}
$collectionClassName = M2PTableMap::getTableMap()->getCollectionClassName();
$this->collM2Ps = new $collectionClassName;
$this->collM2Ps->setModel('\Attogram\SharedMedia\Orm\M2P');
} | php | public function initM2Ps($overrideExisting = true)
{
if (null !== $this->collM2Ps && !$overrideExisting) {
return;
}
$collectionClassName = M2PTableMap::getTableMap()->getCollectionClassName();
$this->collM2Ps = new $collectionClassName;
$this->collM2Ps->setModel('\Attogram\SharedMedia\Orm\M2P');
} | [
"public",
"function",
"initM2Ps",
"(",
"$",
"overrideExisting",
"=",
"true",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"collM2Ps",
"&&",
"!",
"$",
"overrideExisting",
")",
"{",
"return",
";",
"}",
"$",
"collectionClassName",
"=",
"M2PTableMap",
"::",
"getTableMap",
"(",
")",
"->",
"getCollectionClassName",
"(",
")",
";",
"$",
"this",
"->",
"collM2Ps",
"=",
"new",
"$",
"collectionClassName",
";",
"$",
"this",
"->",
"collM2Ps",
"->",
"setModel",
"(",
"'\\Attogram\\SharedMedia\\Orm\\M2P'",
")",
";",
"}"
]
| Initializes the collM2Ps collection.
By default this just sets the collM2Ps collection to an empty array (like clearcollM2Ps());
however, you may wish to override this method in your stub class to provide setting appropriate
to your application -- for example, setting the initial array to the values stored in database.
@param boolean $overrideExisting If set to true, the method call initializes
the collection even if it is not empty
@return void | [
"Initializes",
"the",
"collM2Ps",
"collection",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L2086-L2096 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.getM2Ps | public function getM2Ps(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collM2PsPartial && !$this->isNew();
if (null === $this->collM2Ps || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collM2Ps) {
// return empty collection
$this->initM2Ps();
} else {
$collM2Ps = ChildM2PQuery::create(null, $criteria)
->filterByPage($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collM2PsPartial && count($collM2Ps)) {
$this->initM2Ps(false);
foreach ($collM2Ps as $obj) {
if (false == $this->collM2Ps->contains($obj)) {
$this->collM2Ps->append($obj);
}
}
$this->collM2PsPartial = true;
}
return $collM2Ps;
}
if ($partial && $this->collM2Ps) {
foreach ($this->collM2Ps as $obj) {
if ($obj->isNew()) {
$collM2Ps[] = $obj;
}
}
}
$this->collM2Ps = $collM2Ps;
$this->collM2PsPartial = false;
}
}
return $this->collM2Ps;
} | php | public function getM2Ps(Criteria $criteria = null, ConnectionInterface $con = null)
{
$partial = $this->collM2PsPartial && !$this->isNew();
if (null === $this->collM2Ps || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collM2Ps) {
// return empty collection
$this->initM2Ps();
} else {
$collM2Ps = ChildM2PQuery::create(null, $criteria)
->filterByPage($this)
->find($con);
if (null !== $criteria) {
if (false !== $this->collM2PsPartial && count($collM2Ps)) {
$this->initM2Ps(false);
foreach ($collM2Ps as $obj) {
if (false == $this->collM2Ps->contains($obj)) {
$this->collM2Ps->append($obj);
}
}
$this->collM2PsPartial = true;
}
return $collM2Ps;
}
if ($partial && $this->collM2Ps) {
foreach ($this->collM2Ps as $obj) {
if ($obj->isNew()) {
$collM2Ps[] = $obj;
}
}
}
$this->collM2Ps = $collM2Ps;
$this->collM2PsPartial = false;
}
}
return $this->collM2Ps;
} | [
"public",
"function",
"getM2Ps",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collM2PsPartial",
"&&",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"collM2Ps",
"||",
"null",
"!==",
"$",
"criteria",
"||",
"$",
"partial",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"&&",
"null",
"===",
"$",
"this",
"->",
"collM2Ps",
")",
"{",
"// return empty collection",
"$",
"this",
"->",
"initM2Ps",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collM2Ps",
"=",
"ChildM2PQuery",
"::",
"create",
"(",
"null",
",",
"$",
"criteria",
")",
"->",
"filterByPage",
"(",
"$",
"this",
")",
"->",
"find",
"(",
"$",
"con",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"criteria",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"collM2PsPartial",
"&&",
"count",
"(",
"$",
"collM2Ps",
")",
")",
"{",
"$",
"this",
"->",
"initM2Ps",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"collM2Ps",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"collM2Ps",
"->",
"contains",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"this",
"->",
"collM2Ps",
"->",
"append",
"(",
"$",
"obj",
")",
";",
"}",
"}",
"$",
"this",
"->",
"collM2PsPartial",
"=",
"true",
";",
"}",
"return",
"$",
"collM2Ps",
";",
"}",
"if",
"(",
"$",
"partial",
"&&",
"$",
"this",
"->",
"collM2Ps",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collM2Ps",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"isNew",
"(",
")",
")",
"{",
"$",
"collM2Ps",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"collM2Ps",
"=",
"$",
"collM2Ps",
";",
"$",
"this",
"->",
"collM2PsPartial",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"collM2Ps",
";",
"}"
]
| Gets an array of ChildM2P objects which contain a foreign key that references this object.
If the $criteria is not null, it is used to always fetch the results from the database.
Otherwise the results are fetched from the database the first time, then cached.
Next time the same method is called without $criteria, the cached collection is returned.
If this ChildPage is new, it will return
an empty collection or the current collection; the criteria is ignored on a new object.
@param Criteria $criteria optional Criteria object to narrow the query
@param ConnectionInterface $con optional connection object
@return ObjectCollection|ChildM2P[] List of ChildM2P objects
@throws PropelException | [
"Gets",
"an",
"array",
"of",
"ChildM2P",
"objects",
"which",
"contain",
"a",
"foreign",
"key",
"that",
"references",
"this",
"object",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L2112-L2154 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/Page.php | Page.addM2P | public function addM2P(ChildM2P $l)
{
if ($this->collM2Ps === null) {
$this->initM2Ps();
$this->collM2PsPartial = true;
}
if (!$this->collM2Ps->contains($l)) {
$this->doAddM2P($l);
if ($this->m2PsScheduledForDeletion and $this->m2PsScheduledForDeletion->contains($l)) {
$this->m2PsScheduledForDeletion->remove($this->m2PsScheduledForDeletion->search($l));
}
}
return $this;
} | php | public function addM2P(ChildM2P $l)
{
if ($this->collM2Ps === null) {
$this->initM2Ps();
$this->collM2PsPartial = true;
}
if (!$this->collM2Ps->contains($l)) {
$this->doAddM2P($l);
if ($this->m2PsScheduledForDeletion and $this->m2PsScheduledForDeletion->contains($l)) {
$this->m2PsScheduledForDeletion->remove($this->m2PsScheduledForDeletion->search($l));
}
}
return $this;
} | [
"public",
"function",
"addM2P",
"(",
"ChildM2P",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collM2Ps",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initM2Ps",
"(",
")",
";",
"$",
"this",
"->",
"collM2PsPartial",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"collM2Ps",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"doAddM2P",
"(",
"$",
"l",
")",
";",
"if",
"(",
"$",
"this",
"->",
"m2PsScheduledForDeletion",
"and",
"$",
"this",
"->",
"m2PsScheduledForDeletion",
"->",
"contains",
"(",
"$",
"l",
")",
")",
"{",
"$",
"this",
"->",
"m2PsScheduledForDeletion",
"->",
"remove",
"(",
"$",
"this",
"->",
"m2PsScheduledForDeletion",
"->",
"search",
"(",
"$",
"l",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Method called to associate a ChildM2P object to this object
through the ChildM2P foreign key attribute.
@param ChildM2P $l ChildM2P
@return $this|\Attogram\SharedMedia\Orm\Page The current object (for fluent API support) | [
"Method",
"called",
"to",
"associate",
"a",
"ChildM2P",
"object",
"to",
"this",
"object",
"through",
"the",
"ChildM2P",
"foreign",
"key",
"attribute",
"."
]
| 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Page.php#L2233-L2249 | train |
Vectrex/vxPHP | src/User/User.php | User.setHashedPassword | public function setHashedPassword($hashedPassword) {
if($hashedPassword !== $this->hashedPassword) {
$this->authenticated = FALSE;
$this->hashedPassword = $hashedPassword;
}
return $this;
} | php | public function setHashedPassword($hashedPassword) {
if($hashedPassword !== $this->hashedPassword) {
$this->authenticated = FALSE;
$this->hashedPassword = $hashedPassword;
}
return $this;
} | [
"public",
"function",
"setHashedPassword",
"(",
"$",
"hashedPassword",
")",
"{",
"if",
"(",
"$",
"hashedPassword",
"!==",
"$",
"this",
"->",
"hashedPassword",
")",
"{",
"$",
"this",
"->",
"authenticated",
"=",
"FALSE",
";",
"$",
"this",
"->",
"hashedPassword",
"=",
"$",
"hashedPassword",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| set password hash; if password hash
differs from previously set hash any previous
authentication result is reset
@param string $hashedPassword
@return \vxPHP\User\User | [
"set",
"password",
"hash",
";",
"if",
"password",
"hash",
"differs",
"from",
"previously",
"set",
"hash",
"any",
"previous",
"authentication",
"result",
"is",
"reset"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/User.php#L125-L134 | train |
Vectrex/vxPHP | src/User/User.php | User.authenticate | public function authenticate($plaintextPassword) {
$encrypter = new PasswordEncrypter();
$this->authenticated = $encrypter->isPasswordValid($plaintextPassword, $this->hashedPassword);
return $this;
} | php | public function authenticate($plaintextPassword) {
$encrypter = new PasswordEncrypter();
$this->authenticated = $encrypter->isPasswordValid($plaintextPassword, $this->hashedPassword);
return $this;
} | [
"public",
"function",
"authenticate",
"(",
"$",
"plaintextPassword",
")",
"{",
"$",
"encrypter",
"=",
"new",
"PasswordEncrypter",
"(",
")",
";",
"$",
"this",
"->",
"authenticated",
"=",
"$",
"encrypter",
"->",
"isPasswordValid",
"(",
"$",
"plaintextPassword",
",",
"$",
"this",
"->",
"hashedPassword",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| compare passed plain text password with
stored hashed password and store result
@param unknown $plaintextPassword
@return \vxPHP\User\User | [
"compare",
"passed",
"plain",
"text",
"password",
"with",
"stored",
"hashed",
"password",
"and",
"store",
"result"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/User.php#L180-L186 | train |
Vectrex/vxPHP | src/User/User.php | User.setRoles | public function setRoles(array $roles) {
$this->roles = [];
foreach($roles as $role) {
if(!$role instanceof Role) {
throw new \InvalidArgumentException('Role is not a role instance.');
}
if(array_key_exists($role->getRoleName(), $this->roles)) {
throw new \InvalidArgumentException(sprintf("Role '%s' defined twice.", $role->getRoleName()));
}
$this->roles[$role->getRoleName()] = $role;
}
return $this;
} | php | public function setRoles(array $roles) {
$this->roles = [];
foreach($roles as $role) {
if(!$role instanceof Role) {
throw new \InvalidArgumentException('Role is not a role instance.');
}
if(array_key_exists($role->getRoleName(), $this->roles)) {
throw new \InvalidArgumentException(sprintf("Role '%s' defined twice.", $role->getRoleName()));
}
$this->roles[$role->getRoleName()] = $role;
}
return $this;
} | [
"public",
"function",
"setRoles",
"(",
"array",
"$",
"roles",
")",
"{",
"$",
"this",
"->",
"roles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"role",
"instanceof",
"Role",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Role is not a role instance.'",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"role",
"->",
"getRoleName",
"(",
")",
",",
"$",
"this",
"->",
"roles",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Role '%s' defined twice.\"",
",",
"$",
"role",
"->",
"getRoleName",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"roles",
"[",
"$",
"role",
"->",
"getRoleName",
"(",
")",
"]",
"=",
"$",
"role",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| set all roles of user
@param Role[]
@throws \InvalidArgumentException
@return \vxPHP\User\User | [
"set",
"all",
"roles",
"of",
"user"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/User.php#L218-L236 | train |
Vectrex/vxPHP | src/User/User.php | User.getRolesAndSubRoles | public function getRolesAndSubRoles(RoleHierarchy $roleHierarchy) {
$possibleRoles = [];
foreach($this->roles as $role) {
$possibleRoles[] = $role;
$possibleRoles = array_merge($possibleRoles, $roleHierarchy->getSubRoles($role));
return $possibleRoles;
}
} | php | public function getRolesAndSubRoles(RoleHierarchy $roleHierarchy) {
$possibleRoles = [];
foreach($this->roles as $role) {
$possibleRoles[] = $role;
$possibleRoles = array_merge($possibleRoles, $roleHierarchy->getSubRoles($role));
return $possibleRoles;
}
} | [
"public",
"function",
"getRolesAndSubRoles",
"(",
"RoleHierarchy",
"$",
"roleHierarchy",
")",
"{",
"$",
"possibleRoles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"possibleRoles",
"[",
"]",
"=",
"$",
"role",
";",
"$",
"possibleRoles",
"=",
"array_merge",
"(",
"$",
"possibleRoles",
",",
"$",
"roleHierarchy",
"->",
"getSubRoles",
"(",
"$",
"role",
")",
")",
";",
"return",
"$",
"possibleRoles",
";",
"}",
"}"
]
| return all possible roles and subroles - defined by a role
hierarchy - the user can take
@param RoleHierarchy $roleHierarchy
@return Role[] | [
"return",
"all",
"possible",
"roles",
"and",
"subroles",
"-",
"defined",
"by",
"a",
"role",
"hierarchy",
"-",
"the",
"user",
"can",
"take"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/User.php#L257-L269 | train |
p2made/yii2-p2y2-base | helpers/P2Settings.php | P2Settings.p2mSettings | protected static function p2mSettings()
{
if(isset(self::$_p2mSettings)) {
return self::$_p2mSettings;
}
return self::getSettingsItem(self::$_p2mSettings, Yii::$app->params, 'p2m');
} | php | protected static function p2mSettings()
{
if(isset(self::$_p2mSettings)) {
return self::$_p2mSettings;
}
return self::getSettingsItem(self::$_p2mSettings, Yii::$app->params, 'p2m');
} | [
"protected",
"static",
"function",
"p2mSettings",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_p2mSettings",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_p2mSettings",
";",
"}",
"return",
"self",
"::",
"getSettingsItem",
"(",
"self",
"::",
"$",
"_p2mSettings",
",",
"Yii",
"::",
"$",
"app",
"->",
"params",
",",
"'p2m'",
")",
";",
"}"
]
| Get p2m settings
@return array | false
@default false | [
"Get",
"p2m",
"settings"
]
| face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/P2Settings.php#L35-L42 | train |
p2made/yii2-p2y2-base | helpers/P2Settings.php | P2Settings.getSettingsBlock | protected static function getSettingsBlock($name)
{
return self::getSettingsItem(
self::$_settingsBlock,
self::p2mSettings(),
$name, false
);
} | php | protected static function getSettingsBlock($name)
{
return self::getSettingsItem(
self::$_settingsBlock,
self::p2mSettings(),
$name, false
);
} | [
"protected",
"static",
"function",
"getSettingsBlock",
"(",
"$",
"name",
")",
"{",
"return",
"self",
"::",
"getSettingsItem",
"(",
"self",
"::",
"$",
"_settingsBlock",
",",
"self",
"::",
"p2mSettings",
"(",
")",
",",
"$",
"name",
",",
"false",
")",
";",
"}"
]
| Get settings block
@param string $name
@return array | false
@default false | [
"Get",
"settings",
"block"
]
| face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/P2Settings.php#L50-L57 | train |
p2made/yii2-p2y2-base | helpers/P2Settings.php | P2Settings.getSettingsItem | protected static function getSettingsItem(&$target, $source, $name = '', $default = false)
{
/**
* if $target is already set,
* return it unchanged
*/
if(isset($target)) {
return $target;
}
$useSource = true;
/**
* if $source is false,
* or $source[$name] is not set,
* set $useSource false
*/
if($source === false || !isset($source[$name])) {
$useSource = false;
}
$target = ($useSource ? $source[$name] : $default);
return $target;
} | php | protected static function getSettingsItem(&$target, $source, $name = '', $default = false)
{
/**
* if $target is already set,
* return it unchanged
*/
if(isset($target)) {
return $target;
}
$useSource = true;
/**
* if $source is false,
* or $source[$name] is not set,
* set $useSource false
*/
if($source === false || !isset($source[$name])) {
$useSource = false;
}
$target = ($useSource ? $source[$name] : $default);
return $target;
} | [
"protected",
"static",
"function",
"getSettingsItem",
"(",
"&",
"$",
"target",
",",
"$",
"source",
",",
"$",
"name",
"=",
"''",
",",
"$",
"default",
"=",
"false",
")",
"{",
"/**\n\t\t * if $target is already set,\n\t\t * return it unchanged\n\t\t */",
"if",
"(",
"isset",
"(",
"$",
"target",
")",
")",
"{",
"return",
"$",
"target",
";",
"}",
"$",
"useSource",
"=",
"true",
";",
"/**\n\t\t * if $source is false,\n\t\t * or $source[$name] is not set,\n\t\t * set $useSource false\n\t\t */",
"if",
"(",
"$",
"source",
"===",
"false",
"||",
"!",
"isset",
"(",
"$",
"source",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"useSource",
"=",
"false",
";",
"}",
"$",
"target",
"=",
"(",
"$",
"useSource",
"?",
"$",
"source",
"[",
"$",
"name",
"]",
":",
"$",
"default",
")",
";",
"return",
"$",
"target",
";",
"}"
]
| Get settings item
@param array | false $source
@param object &$target
@param string $name
@param object $default
@return object | false
@default false | [
"Get",
"settings",
"item"
]
| face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/P2Settings.php#L68-L91 | train |
Rockbeat-Sky/yii | src/helpers/FileExplorer.php | FileExplorer.getTotalFiles | public function getTotalFiles()
{
if (!$this->_files) {
$this->scan;
}
$i = 0;
foreach ($this->_files as $file) {
if ($file->isFile) {
$i++;
}
}
return $i;
} | php | public function getTotalFiles()
{
if (!$this->_files) {
$this->scan;
}
$i = 0;
foreach ($this->_files as $file) {
if ($file->isFile) {
$i++;
}
}
return $i;
} | [
"public",
"function",
"getTotalFiles",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_files",
")",
"{",
"$",
"this",
"->",
"scan",
";",
"}",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"_files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isFile",
")",
"{",
"$",
"i",
"++",
";",
"}",
"}",
"return",
"$",
"i",
";",
"}"
]
| count total files
@return int | [
"count",
"total",
"files"
]
| 80758d1519162d650ca2d41e00f46e760ee35b92 | https://github.com/Rockbeat-Sky/yii/blob/80758d1519162d650ca2d41e00f46e760ee35b92/src/helpers/FileExplorer.php#L178-L190 | train |
spress/spress-core | ContentManager/Renderizer/TwigRenderizer.php | TwigRenderizer.addLayout | public function addLayout($id, $content, array $attributes = [])
{
$key = $this->getLayoutNameWithNamespace($id);
$this->layouts[$key] = [$id, $content, $attributes];
} | php | public function addLayout($id, $content, array $attributes = [])
{
$key = $this->getLayoutNameWithNamespace($id);
$this->layouts[$key] = [$id, $content, $attributes];
} | [
"public",
"function",
"addLayout",
"(",
"$",
"id",
",",
"$",
"content",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getLayoutNameWithNamespace",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"layouts",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"id",
",",
"$",
"content",
",",
"$",
"attributes",
"]",
";",
"}"
]
| Add a new layout.
@param string $id The identifier of the layout. e.g: path
@param string $content The content of the layout
@param array $attributes The attributes of the layout.
"layout" attribute has a special meaning | [
"Add",
"a",
"new",
"layout",
"."
]
| a61008c4cde3ba990e7faa164462171b019a60bf | https://github.com/spress/spress-core/blob/a61008c4cde3ba990e7faa164462171b019a60bf/ContentManager/Renderizer/TwigRenderizer.php#L55-L59 | train |
alphalemon/BootstrapBundle | Core/Script/Base/BasePostScript.php | BasePostScript.executeActionsFromFile | public function executeActionsFromFile($fileName)
{
$actions = array();
if (file_exists($fileName)) {
$actionsClasses = $this->decode($fileName);
foreach ($actionsClasses as $bundleName => $actionsClass){
$this->actionManagerGenerator->generate($actionsClass);
$actions[$bundleName] = $this->actionManagerGenerator->getActionManager();
}
$this->filesystem->remove($fileName);
}
$this->executeActions($actions);
} | php | public function executeActionsFromFile($fileName)
{
$actions = array();
if (file_exists($fileName)) {
$actionsClasses = $this->decode($fileName);
foreach ($actionsClasses as $bundleName => $actionsClass){
$this->actionManagerGenerator->generate($actionsClass);
$actions[$bundleName] = $this->actionManagerGenerator->getActionManager();
}
$this->filesystem->remove($fileName);
}
$this->executeActions($actions);
} | [
"public",
"function",
"executeActionsFromFile",
"(",
"$",
"fileName",
")",
"{",
"$",
"actions",
"=",
"array",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"actionsClasses",
"=",
"$",
"this",
"->",
"decode",
"(",
"$",
"fileName",
")",
";",
"foreach",
"(",
"$",
"actionsClasses",
"as",
"$",
"bundleName",
"=>",
"$",
"actionsClass",
")",
"{",
"$",
"this",
"->",
"actionManagerGenerator",
"->",
"generate",
"(",
"$",
"actionsClass",
")",
";",
"$",
"actions",
"[",
"$",
"bundleName",
"]",
"=",
"$",
"this",
"->",
"actionManagerGenerator",
"->",
"getActionManager",
"(",
")",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"fileName",
")",
";",
"}",
"$",
"this",
"->",
"executeActions",
"(",
"$",
"actions",
")",
";",
"}"
]
| Execute the actions from a json file
@param string $fileName | [
"Execute",
"the",
"actions",
"from",
"a",
"json",
"file"
]
| 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Script/Base/BasePostScript.php#L65-L79 | train |
LartTyler/PHP-DaybreakCommons | src/DaybreakStudios/Common/IO/CsvFileReader.php | CsvFileReader.addField | public function addField($name, $transformer = null, $pos = null) {
if ($pos === null)
$pos = sizeof($this->fields);
$this->fields[$pos] = $name;
if (is_callable($transformer))
$this->transformers[$pos] = $transformer;
else if ($transformer !== null)
throw new InvalidArgumentException('The transformer provided for ' . $name . ' is not callable');
return $this;
} | php | public function addField($name, $transformer = null, $pos = null) {
if ($pos === null)
$pos = sizeof($this->fields);
$this->fields[$pos] = $name;
if (is_callable($transformer))
$this->transformers[$pos] = $transformer;
else if ($transformer !== null)
throw new InvalidArgumentException('The transformer provided for ' . $name . ' is not callable');
return $this;
} | [
"public",
"function",
"addField",
"(",
"$",
"name",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"pos",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"pos",
"===",
"null",
")",
"$",
"pos",
"=",
"sizeof",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"$",
"this",
"->",
"fields",
"[",
"$",
"pos",
"]",
"=",
"$",
"name",
";",
"if",
"(",
"is_callable",
"(",
"$",
"transformer",
")",
")",
"$",
"this",
"->",
"transformers",
"[",
"$",
"pos",
"]",
"=",
"$",
"transformer",
";",
"else",
"if",
"(",
"$",
"transformer",
"!==",
"null",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The transformer provided for '",
".",
"$",
"name",
".",
"' is not callable'",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds a named field to a CSV row.
@param string $name the name of the field
@param callable $transformer optional; a callback that can be used to transform the field value
@param int $pos optional; the column number of the field, if not specified it will append the
colum name to the list
@return CsvFileReader an object reference for method chaining | [
"Adds",
"a",
"named",
"field",
"to",
"a",
"CSV",
"row",
"."
]
| db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d | https://github.com/LartTyler/PHP-DaybreakCommons/blob/db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d/src/DaybreakStudios/Common/IO/CsvFileReader.php#L19-L31 | train |
LartTyler/PHP-DaybreakCommons | src/DaybreakStudios/Common/IO/CsvFileReader.php | CsvFileReader.addFields | public function addFields(array $fields) {
foreach ($fields as $k => $v)
if (is_string($k))
$this->addField($k, $v);
else
$this->addField($v);
return $this;
} | php | public function addFields(array $fields) {
foreach ($fields as $k => $v)
if (is_string($k))
$this->addField($k, $v);
else
$this->addField($v);
return $this;
} | [
"public",
"function",
"addFields",
"(",
"array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"if",
"(",
"is_string",
"(",
"$",
"k",
")",
")",
"$",
"this",
"->",
"addField",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"else",
"$",
"this",
"->",
"addField",
"(",
"$",
"v",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds multiple fields with an optional transformer to a CSV row.
@param array $fields the fields to add; can either be an array of string names, or an associative array where
the array key is the field name, and the value is the transformer to use for that column
@return CsvFileReader an object reference for method chaining | [
"Adds",
"multiple",
"fields",
"with",
"an",
"optional",
"transformer",
"to",
"a",
"CSV",
"row",
"."
]
| db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d | https://github.com/LartTyler/PHP-DaybreakCommons/blob/db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d/src/DaybreakStudios/Common/IO/CsvFileReader.php#L40-L48 | train |
CraryPrimitiveMan/php-resque | src/InitTrait.php | InitTrait.run | public function run()
{
if (empty($this->queues)) {
die('Set queues var containing the list of queues to work.' . PHP_EOL);
}
Resque::setBackend($this->redisBackend, $this->database, $this->password);
if ($this->count > 1) {
for ($i = 0; $i < $this->count; ++$i) {
$pid = pcntl_fork();
if ($pid == -1) {
die('Could not fork worker ' . $i . PHP_EOL);
} elseif (!$pid) {
// Child, start the worker
$this->_startWorker();
break;
}
}
} else {
if (!empty($this->pidFile)) {
file_put_contents($this->pidFile, getmypid()) or
die('Could not write PID information to ' . $PIDFILE . PHP_EOL);
}
// Start a single worker
$this->_startWorker();
}
} | php | public function run()
{
if (empty($this->queues)) {
die('Set queues var containing the list of queues to work.' . PHP_EOL);
}
Resque::setBackend($this->redisBackend, $this->database, $this->password);
if ($this->count > 1) {
for ($i = 0; $i < $this->count; ++$i) {
$pid = pcntl_fork();
if ($pid == -1) {
die('Could not fork worker ' . $i . PHP_EOL);
} elseif (!$pid) {
// Child, start the worker
$this->_startWorker();
break;
}
}
} else {
if (!empty($this->pidFile)) {
file_put_contents($this->pidFile, getmypid()) or
die('Could not write PID information to ' . $PIDFILE . PHP_EOL);
}
// Start a single worker
$this->_startWorker();
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"queues",
")",
")",
"{",
"die",
"(",
"'Set queues var containing the list of queues to work.'",
".",
"PHP_EOL",
")",
";",
"}",
"Resque",
"::",
"setBackend",
"(",
"$",
"this",
"->",
"redisBackend",
",",
"$",
"this",
"->",
"database",
",",
"$",
"this",
"->",
"password",
")",
";",
"if",
"(",
"$",
"this",
"->",
"count",
">",
"1",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"pid",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"pid",
"==",
"-",
"1",
")",
"{",
"die",
"(",
"'Could not fork worker '",
".",
"$",
"i",
".",
"PHP_EOL",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"pid",
")",
"{",
"// Child, start the worker",
"$",
"this",
"->",
"_startWorker",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"pidFile",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"pidFile",
",",
"getmypid",
"(",
")",
")",
"or",
"die",
"(",
"'Could not write PID information to '",
".",
"$",
"PIDFILE",
".",
"PHP_EOL",
")",
";",
"}",
"// Start a single worker",
"$",
"this",
"->",
"_startWorker",
"(",
")",
";",
"}",
"}"
]
| Run to start workers | [
"Run",
"to",
"start",
"workers"
]
| eff3beba81b7f5e8d6fddb8d24c8dcde6553e209 | https://github.com/CraryPrimitiveMan/php-resque/blob/eff3beba81b7f5e8d6fddb8d24c8dcde6553e209/src/InitTrait.php#L62-L89 | train |
CraryPrimitiveMan/php-resque | src/InitTrait.php | InitTrait._startWorker | protected function _startWorker()
{
$worker = new Worker($this->queues);
$worker->logLevel = $this->logLevel;
fwrite(STDOUT, '*** Starting worker ' . $worker . PHP_EOL);
$worker->work($this->interval);
} | php | protected function _startWorker()
{
$worker = new Worker($this->queues);
$worker->logLevel = $this->logLevel;
fwrite(STDOUT, '*** Starting worker ' . $worker . PHP_EOL);
$worker->work($this->interval);
} | [
"protected",
"function",
"_startWorker",
"(",
")",
"{",
"$",
"worker",
"=",
"new",
"Worker",
"(",
"$",
"this",
"->",
"queues",
")",
";",
"$",
"worker",
"->",
"logLevel",
"=",
"$",
"this",
"->",
"logLevel",
";",
"fwrite",
"(",
"STDOUT",
",",
"'*** Starting worker '",
".",
"$",
"worker",
".",
"PHP_EOL",
")",
";",
"$",
"worker",
"->",
"work",
"(",
"$",
"this",
"->",
"interval",
")",
";",
"}"
]
| Start a worker | [
"Start",
"a",
"worker"
]
| eff3beba81b7f5e8d6fddb8d24c8dcde6553e209 | https://github.com/CraryPrimitiveMan/php-resque/blob/eff3beba81b7f5e8d6fddb8d24c8dcde6553e209/src/InitTrait.php#L94-L100 | train |
hamlet-framework/http | src/Entities/JsonEntity.php | JsonEntity.getKey | public function getKey(): string
{
if ($this->key === null) {
$this->key = md5($this->getContent());
}
return $this->key;
} | php | public function getKey(): string
{
if ($this->key === null) {
$this->key = md5($this->getContent());
}
return $this->key;
} | [
"public",
"function",
"getKey",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"key",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"key",
"=",
"md5",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"key",
";",
"}"
]
| Get the entity key, 304 response needs a proper key value
@return string | [
"Get",
"the",
"entity",
"key",
"304",
"response",
"needs",
"a",
"proper",
"key",
"value"
]
| 1d3f2a05d2914b678bf05bb53effccace82787c1 | https://github.com/hamlet-framework/http/blob/1d3f2a05d2914b678bf05bb53effccace82787c1/src/Entities/JsonEntity.php#L34-L40 | train |
stubbles/stubbles-dbal | src/main/php/QueryResultIterator.php | QueryResultIterator.next | public function next()
{
$this->key++;
if (\PDO::FETCH_COLUMN !== $this->fetchMode) {
$this->current = $this->queryResult->fetch(
$this->fetchMode,
$this->driverOptions
);
} else {
$this->current = $this->queryResult->fetchOne(
$this->driverOptions['columnIndex'] ?? 0
);
}
} | php | public function next()
{
$this->key++;
if (\PDO::FETCH_COLUMN !== $this->fetchMode) {
$this->current = $this->queryResult->fetch(
$this->fetchMode,
$this->driverOptions
);
} else {
$this->current = $this->queryResult->fetchOne(
$this->driverOptions['columnIndex'] ?? 0
);
}
} | [
"public",
"function",
"next",
"(",
")",
"{",
"$",
"this",
"->",
"key",
"++",
";",
"if",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
"!==",
"$",
"this",
"->",
"fetchMode",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"this",
"->",
"queryResult",
"->",
"fetch",
"(",
"$",
"this",
"->",
"fetchMode",
",",
"$",
"this",
"->",
"driverOptions",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"this",
"->",
"queryResult",
"->",
"fetchOne",
"(",
"$",
"this",
"->",
"driverOptions",
"[",
"'columnIndex'",
"]",
"??",
"0",
")",
";",
"}",
"}"
]
| iterates to next result element | [
"iterates",
"to",
"next",
"result",
"element"
]
| b42a589025a9e511b40a2798ac84df94d6451c36 | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/QueryResultIterator.php#L92-L105 | train |
aVigorousDev/numbers | src/drmyersii/NumberSegmentFactory.php | NumberSegmentFactory.SplitIntoSegments | public static function SplitIntoSegments($number)
{
$number_str = $number->GetStringValue();
$segments = [];
$NumberSegments = [];
while (strlen($number_str) > 0)
{
if (strlen($number_str) < 3)
{
$segments[] = $number_str;
break;
}
$segment = substr($number_str, -3);
$number_str = substr($number_str, 0, strlen($number_str) - 3);
$segments[] = $segment;
}
return array_reverse($segments);
} | php | public static function SplitIntoSegments($number)
{
$number_str = $number->GetStringValue();
$segments = [];
$NumberSegments = [];
while (strlen($number_str) > 0)
{
if (strlen($number_str) < 3)
{
$segments[] = $number_str;
break;
}
$segment = substr($number_str, -3);
$number_str = substr($number_str, 0, strlen($number_str) - 3);
$segments[] = $segment;
}
return array_reverse($segments);
} | [
"public",
"static",
"function",
"SplitIntoSegments",
"(",
"$",
"number",
")",
"{",
"$",
"number_str",
"=",
"$",
"number",
"->",
"GetStringValue",
"(",
")",
";",
"$",
"segments",
"=",
"[",
"]",
";",
"$",
"NumberSegments",
"=",
"[",
"]",
";",
"while",
"(",
"strlen",
"(",
"$",
"number_str",
")",
">",
"0",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"number_str",
")",
"<",
"3",
")",
"{",
"$",
"segments",
"[",
"]",
"=",
"$",
"number_str",
";",
"break",
";",
"}",
"$",
"segment",
"=",
"substr",
"(",
"$",
"number_str",
",",
"-",
"3",
")",
";",
"$",
"number_str",
"=",
"substr",
"(",
"$",
"number_str",
",",
"0",
",",
"strlen",
"(",
"$",
"number_str",
")",
"-",
"3",
")",
";",
"$",
"segments",
"[",
"]",
"=",
"$",
"segment",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"segments",
")",
";",
"}"
]
| This will split the number into chunks and then turn them each into NumberSegments.
@param $number NumberW
@return string[] | [
"This",
"will",
"split",
"the",
"number",
"into",
"chunks",
"and",
"then",
"turn",
"them",
"each",
"into",
"NumberSegments",
"."
]
| 02124e75286758d216a22d1d963946dab9e8582b | https://github.com/aVigorousDev/numbers/blob/02124e75286758d216a22d1d963946dab9e8582b/src/drmyersii/NumberSegmentFactory.php#L29-L51 | train |
aVigorousDev/numbers | src/drmyersii/NumberSegmentFactory.php | NumberSegmentFactory.MakeNumberSegments | public static function MakeNumberSegments($segments)
{
$NumberSegments = [];
foreach ($segments as $segment)
{
$NumberSegments[] = new NumberSegment($segment);
}
return $NumberSegments;
} | php | public static function MakeNumberSegments($segments)
{
$NumberSegments = [];
foreach ($segments as $segment)
{
$NumberSegments[] = new NumberSegment($segment);
}
return $NumberSegments;
} | [
"public",
"static",
"function",
"MakeNumberSegments",
"(",
"$",
"segments",
")",
"{",
"$",
"NumberSegments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"segment",
")",
"{",
"$",
"NumberSegments",
"[",
"]",
"=",
"new",
"NumberSegment",
"(",
"$",
"segment",
")",
";",
"}",
"return",
"$",
"NumberSegments",
";",
"}"
]
| This is the actual factory method that converts regular string segments into
the number segment types we need to work with.
@param $segments string[]
@return NumberSegment[] | [
"This",
"is",
"the",
"actual",
"factory",
"method",
"that",
"converts",
"regular",
"string",
"segments",
"into",
"the",
"number",
"segment",
"types",
"we",
"need",
"to",
"work",
"with",
"."
]
| 02124e75286758d216a22d1d963946dab9e8582b | https://github.com/aVigorousDev/numbers/blob/02124e75286758d216a22d1d963946dab9e8582b/src/drmyersii/NumberSegmentFactory.php#L60-L70 | train |
Kris-Kuiper/sFire-Framework | src/Escaper/Escape.php | Escape.setEncoding | public static function setEncoding($encoding) {
if(false === is_string($encoding) || 0 === strlen($encoding)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($encoding)), E_USER_ERROR);
}
$encoding = strtolower($encoding);
if(false === in_array($encoding, static :: $encodings)) {
return trigger_error(sprintf('Argument 1 passed to %s() is not a supported encoding. Provide an encoding supported by htmlspecialchars()', __METHOD__), E_USER_ERROR);
}
static :: $encoding = $encoding;
} | php | public static function setEncoding($encoding) {
if(false === is_string($encoding) || 0 === strlen($encoding)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($encoding)), E_USER_ERROR);
}
$encoding = strtolower($encoding);
if(false === in_array($encoding, static :: $encodings)) {
return trigger_error(sprintf('Argument 1 passed to %s() is not a supported encoding. Provide an encoding supported by htmlspecialchars()', __METHOD__), E_USER_ERROR);
}
static :: $encoding = $encoding;
} | [
"public",
"static",
"function",
"setEncoding",
"(",
"$",
"encoding",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"encoding",
")",
"||",
"0",
"===",
"strlen",
"(",
"$",
"encoding",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"encoding",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"encoding",
"=",
"strtolower",
"(",
"$",
"encoding",
")",
";",
"if",
"(",
"false",
"===",
"in_array",
"(",
"$",
"encoding",
",",
"static",
"::",
"$",
"encodings",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() is not a supported encoding. Provide an encoding supported by htmlspecialchars()'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"static",
"::",
"$",
"encoding",
"=",
"$",
"encoding",
";",
"}"
]
| Set a new encoding
@param string $encoding | [
"Set",
"a",
"new",
"encoding"
]
| deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Escaper/Escape.php#L51-L64 | train |
Kris-Kuiper/sFire-Framework | src/Escaper/Escape.php | Escape.cssMatcher | private static function cssMatcher($matches) {
$chr = $matches[0];
if(1 === strlen($chr)) {
$ord = ord($chr);
}
else {
$chr = static :: convert($chr, 'UTF-8', 'UTF-32BE');
$ord = hexdec(bin2hex($chr));
}
return sprintf('\\%X ', $ord);
} | php | private static function cssMatcher($matches) {
$chr = $matches[0];
if(1 === strlen($chr)) {
$ord = ord($chr);
}
else {
$chr = static :: convert($chr, 'UTF-8', 'UTF-32BE');
$ord = hexdec(bin2hex($chr));
}
return sprintf('\\%X ', $ord);
} | [
"private",
"static",
"function",
"cssMatcher",
"(",
"$",
"matches",
")",
"{",
"$",
"chr",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"if",
"(",
"1",
"===",
"strlen",
"(",
"$",
"chr",
")",
")",
"{",
"$",
"ord",
"=",
"ord",
"(",
"$",
"chr",
")",
";",
"}",
"else",
"{",
"$",
"chr",
"=",
"static",
"::",
"convert",
"(",
"$",
"chr",
",",
"'UTF-8'",
",",
"'UTF-32BE'",
")",
";",
"$",
"ord",
"=",
"hexdec",
"(",
"bin2hex",
"(",
"$",
"chr",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"'\\\\%X '",
",",
"$",
"ord",
")",
";",
"}"
]
| Callback function for preg_replace_callback that applies CSS escaping to all matches.
@param array $matches
@return string | [
"Callback",
"function",
"for",
"preg_replace_callback",
"that",
"applies",
"CSS",
"escaping",
"to",
"all",
"matches",
"."
]
| deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Escaper/Escape.php#L291-L305 | train |
Kris-Kuiper/sFire-Framework | src/Escaper/Escape.php | Escape.convert | private static function convert($string, $from, $to) {
if(true === function_exists('iconv')) {
$result = iconv($from, $to, $string);
}
elseif(true === function_exists('mb_convert_encoding')) {
$result = mb_convert_encoding($string, $to, $from);
}
else {
return trigger_error(sprintf('%s requires either the iconv or mbstring extension to be installed', __METHOD__), E_USER_ERROR);
}
if($result === false) {
return '';
}
return $result;
} | php | private static function convert($string, $from, $to) {
if(true === function_exists('iconv')) {
$result = iconv($from, $to, $string);
}
elseif(true === function_exists('mb_convert_encoding')) {
$result = mb_convert_encoding($string, $to, $from);
}
else {
return trigger_error(sprintf('%s requires either the iconv or mbstring extension to be installed', __METHOD__), E_USER_ERROR);
}
if($result === false) {
return '';
}
return $result;
} | [
"private",
"static",
"function",
"convert",
"(",
"$",
"string",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"true",
"===",
"function_exists",
"(",
"'iconv'",
")",
")",
"{",
"$",
"result",
"=",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"string",
")",
";",
"}",
"elseif",
"(",
"true",
"===",
"function_exists",
"(",
"'mb_convert_encoding'",
")",
")",
"{",
"$",
"result",
"=",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"$",
"to",
",",
"$",
"from",
")",
";",
"}",
"else",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'%s requires either the iconv or mbstring extension to be installed'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Converts string from encoding to another encoding
@param string $string
@param array|string $from
@param string $to
@return string | [
"Converts",
"string",
"from",
"encoding",
"to",
"another",
"encoding"
]
| deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Escaper/Escape.php#L315-L332 | train |
Kris-Kuiper/sFire-Framework | src/Escaper/Escape.php | Escape.toUtf8 | private static function toUtf8($string) {
if(static :: getEncoding() === 'utf-8') {
$result = $string;
}
else {
$result = static :: convert($string, static :: getEncoding(), 'UTF-8');
}
if(false === static :: isUtf8($result)) {
return trigger_error(sprintf('String to be escaped was not valid UTF-8 or could not be converted'), E_USER_ERROR);
}
return $result;
} | php | private static function toUtf8($string) {
if(static :: getEncoding() === 'utf-8') {
$result = $string;
}
else {
$result = static :: convert($string, static :: getEncoding(), 'UTF-8');
}
if(false === static :: isUtf8($result)) {
return trigger_error(sprintf('String to be escaped was not valid UTF-8 or could not be converted'), E_USER_ERROR);
}
return $result;
} | [
"private",
"static",
"function",
"toUtf8",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"static",
"::",
"getEncoding",
"(",
")",
"===",
"'utf-8'",
")",
"{",
"$",
"result",
"=",
"$",
"string",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"static",
"::",
"convert",
"(",
"$",
"string",
",",
"static",
"::",
"getEncoding",
"(",
")",
",",
"'UTF-8'",
")",
";",
"}",
"if",
"(",
"false",
"===",
"static",
"::",
"isUtf8",
"(",
"$",
"result",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'String to be escaped was not valid UTF-8 or could not be converted'",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Converts a string from UTF-8 to the base encoding
@param string $string
@return string | [
"Converts",
"a",
"string",
"from",
"UTF",
"-",
"8",
"to",
"the",
"base",
"encoding"
]
| deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Escaper/Escape.php#L340-L354 | train |
1HappyPlace/ansi-terminal | src/ANSI/TerminalState.php | TerminalState.clear | public function clear() {
// set bold and underscore to false
$this->bold = false;
$this->underscore = false;
// set the text and fill color to empty colors
$this->textColor = new Color();
$this->fillColor = new Color();
} | php | public function clear() {
// set bold and underscore to false
$this->bold = false;
$this->underscore = false;
// set the text and fill color to empty colors
$this->textColor = new Color();
$this->fillColor = new Color();
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"// set bold and underscore to false",
"$",
"this",
"->",
"bold",
"=",
"false",
";",
"$",
"this",
"->",
"underscore",
"=",
"false",
";",
"// set the text and fill color to empty colors",
"$",
"this",
"->",
"textColor",
"=",
"new",
"Color",
"(",
")",
";",
"$",
"this",
"->",
"fillColor",
"=",
"new",
"Color",
"(",
")",
";",
"}"
]
| Set the state to clear, no styling | [
"Set",
"the",
"state",
"to",
"clear",
"no",
"styling"
]
| 3a550eadb21bb87a6909436c3b961919d2731923 | https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/TerminalState.php#L58-L67 | train |
1HappyPlace/ansi-terminal | src/ANSI/TerminalState.php | TerminalState.findChanges | public function findChanges(TerminalStateInterface $desired) {
// create a Terminal State object that will hold the changes needed to achieve the desired state
$ret = new self();
// bold is currently off, and the desired is to turn it on
if (!$this->isBold() && $desired->isBold()) {
// turn bold on the changes
$ret->setBold(true);
// bold is going from on to off, the only way to do that is through an overall clear
} else if ($this->isBold() && !$desired->isBold()) {
// a clear is needed, so no new changed object is needed, all of desired will be used
return null;
}
// underscore is currently off, and the desired is to turn it on
if (!$this->isUnderscore() && $desired->isUnderscore()) {
// turn bold on the changes
$ret->setUnderscore(true);
// the underscore is going from on to off
} else if ($this->isUnderscore() && !$desired->isUnderscore()) {
// a clear is needed
return null;
}
// shortcuts to the current and desired text color
$currentTextColor = $this->getTextColor();
$desiredTextColor = $desired->getTextColor();
// if there is no text color and one is desired
if (!$currentTextColor->isValid() && $desiredTextColor->isValid()) {
// set the text color
$ret->setTextColor($desiredTextColor);
// The text color is getting turned off
} else if ($currentTextColor->isValid() && !$desiredTextColor->isValid()) {
// a clear is needed
return null;
// both are valid colors
} else if ($currentTextColor->isValid() && $desiredTextColor->isValid()) {
// if the two colors are different
if ($currentTextColor != $desiredTextColor) {
// set the text color
$ret->setTextColor($desiredTextColor);
}
}
// shortcuts to the current and desired fill colors
$currentFillColor = $this->getFillColor();
$desiredFillColor = $desired->getFillColor();
// if there is no text color and one is desired
if (!$currentFillColor->isValid() && $desiredFillColor->isValid()) {
// set the text color
$ret->setFillColor($desiredFillColor);
// both are valid
} else if ($currentFillColor->isValid() && !$desiredFillColor->isValid()) {
// a clear is needed
return null;
} else if ($currentFillColor->isValid() && $desiredFillColor->isValid()) {
// if the two colors are different
if ($currentFillColor != $desiredFillColor) {
// set the text color
$ret->setFillColor($desiredFillColor);
}
}
// we got here, so no clear was needed, return the object with the changed properties
return $ret;
} | php | public function findChanges(TerminalStateInterface $desired) {
// create a Terminal State object that will hold the changes needed to achieve the desired state
$ret = new self();
// bold is currently off, and the desired is to turn it on
if (!$this->isBold() && $desired->isBold()) {
// turn bold on the changes
$ret->setBold(true);
// bold is going from on to off, the only way to do that is through an overall clear
} else if ($this->isBold() && !$desired->isBold()) {
// a clear is needed, so no new changed object is needed, all of desired will be used
return null;
}
// underscore is currently off, and the desired is to turn it on
if (!$this->isUnderscore() && $desired->isUnderscore()) {
// turn bold on the changes
$ret->setUnderscore(true);
// the underscore is going from on to off
} else if ($this->isUnderscore() && !$desired->isUnderscore()) {
// a clear is needed
return null;
}
// shortcuts to the current and desired text color
$currentTextColor = $this->getTextColor();
$desiredTextColor = $desired->getTextColor();
// if there is no text color and one is desired
if (!$currentTextColor->isValid() && $desiredTextColor->isValid()) {
// set the text color
$ret->setTextColor($desiredTextColor);
// The text color is getting turned off
} else if ($currentTextColor->isValid() && !$desiredTextColor->isValid()) {
// a clear is needed
return null;
// both are valid colors
} else if ($currentTextColor->isValid() && $desiredTextColor->isValid()) {
// if the two colors are different
if ($currentTextColor != $desiredTextColor) {
// set the text color
$ret->setTextColor($desiredTextColor);
}
}
// shortcuts to the current and desired fill colors
$currentFillColor = $this->getFillColor();
$desiredFillColor = $desired->getFillColor();
// if there is no text color and one is desired
if (!$currentFillColor->isValid() && $desiredFillColor->isValid()) {
// set the text color
$ret->setFillColor($desiredFillColor);
// both are valid
} else if ($currentFillColor->isValid() && !$desiredFillColor->isValid()) {
// a clear is needed
return null;
} else if ($currentFillColor->isValid() && $desiredFillColor->isValid()) {
// if the two colors are different
if ($currentFillColor != $desiredFillColor) {
// set the text color
$ret->setFillColor($desiredFillColor);
}
}
// we got here, so no clear was needed, return the object with the changed properties
return $ret;
} | [
"public",
"function",
"findChanges",
"(",
"TerminalStateInterface",
"$",
"desired",
")",
"{",
"// create a Terminal State object that will hold the changes needed to achieve the desired state",
"$",
"ret",
"=",
"new",
"self",
"(",
")",
";",
"// bold is currently off, and the desired is to turn it on",
"if",
"(",
"!",
"$",
"this",
"->",
"isBold",
"(",
")",
"&&",
"$",
"desired",
"->",
"isBold",
"(",
")",
")",
"{",
"// turn bold on the changes",
"$",
"ret",
"->",
"setBold",
"(",
"true",
")",
";",
"// bold is going from on to off, the only way to do that is through an overall clear",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"isBold",
"(",
")",
"&&",
"!",
"$",
"desired",
"->",
"isBold",
"(",
")",
")",
"{",
"// a clear is needed, so no new changed object is needed, all of desired will be used",
"return",
"null",
";",
"}",
"// underscore is currently off, and the desired is to turn it on",
"if",
"(",
"!",
"$",
"this",
"->",
"isUnderscore",
"(",
")",
"&&",
"$",
"desired",
"->",
"isUnderscore",
"(",
")",
")",
"{",
"// turn bold on the changes",
"$",
"ret",
"->",
"setUnderscore",
"(",
"true",
")",
";",
"// the underscore is going from on to off",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"isUnderscore",
"(",
")",
"&&",
"!",
"$",
"desired",
"->",
"isUnderscore",
"(",
")",
")",
"{",
"// a clear is needed",
"return",
"null",
";",
"}",
"// shortcuts to the current and desired text color",
"$",
"currentTextColor",
"=",
"$",
"this",
"->",
"getTextColor",
"(",
")",
";",
"$",
"desiredTextColor",
"=",
"$",
"desired",
"->",
"getTextColor",
"(",
")",
";",
"// if there is no text color and one is desired",
"if",
"(",
"!",
"$",
"currentTextColor",
"->",
"isValid",
"(",
")",
"&&",
"$",
"desiredTextColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// set the text color",
"$",
"ret",
"->",
"setTextColor",
"(",
"$",
"desiredTextColor",
")",
";",
"// The text color is getting turned off",
"}",
"else",
"if",
"(",
"$",
"currentTextColor",
"->",
"isValid",
"(",
")",
"&&",
"!",
"$",
"desiredTextColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// a clear is needed",
"return",
"null",
";",
"// both are valid colors",
"}",
"else",
"if",
"(",
"$",
"currentTextColor",
"->",
"isValid",
"(",
")",
"&&",
"$",
"desiredTextColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// if the two colors are different",
"if",
"(",
"$",
"currentTextColor",
"!=",
"$",
"desiredTextColor",
")",
"{",
"// set the text color",
"$",
"ret",
"->",
"setTextColor",
"(",
"$",
"desiredTextColor",
")",
";",
"}",
"}",
"// shortcuts to the current and desired fill colors",
"$",
"currentFillColor",
"=",
"$",
"this",
"->",
"getFillColor",
"(",
")",
";",
"$",
"desiredFillColor",
"=",
"$",
"desired",
"->",
"getFillColor",
"(",
")",
";",
"// if there is no text color and one is desired",
"if",
"(",
"!",
"$",
"currentFillColor",
"->",
"isValid",
"(",
")",
"&&",
"$",
"desiredFillColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// set the text color",
"$",
"ret",
"->",
"setFillColor",
"(",
"$",
"desiredFillColor",
")",
";",
"// both are valid ",
"}",
"else",
"if",
"(",
"$",
"currentFillColor",
"->",
"isValid",
"(",
")",
"&&",
"!",
"$",
"desiredFillColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// a clear is needed",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"$",
"currentFillColor",
"->",
"isValid",
"(",
")",
"&&",
"$",
"desiredFillColor",
"->",
"isValid",
"(",
")",
")",
"{",
"// if the two colors are different",
"if",
"(",
"$",
"currentFillColor",
"!=",
"$",
"desiredFillColor",
")",
"{",
"// set the text color",
"$",
"ret",
"->",
"setFillColor",
"(",
"$",
"desiredFillColor",
")",
";",
"}",
"}",
"// we got here, so no clear was needed, return the object with the changed properties",
"return",
"$",
"ret",
";",
"}"
]
| Compare the desired state and capture any things that are going from off to on, if something is going
from on to off, then a clear needs to be sent along with all the desired state, in this case
this function returns null
@param TerminalStateInterface $desired
@return null | TerminalState - returns null if a clear is needed and the entire desired sequence needs to be created
otherwise it returns a TerminalState object that contains only the properties that are changing
between the actual and desired | [
"Compare",
"the",
"desired",
"state",
"and",
"capture",
"any",
"things",
"that",
"are",
"going",
"from",
"off",
"to",
"on",
"if",
"something",
"is",
"going",
"from",
"on",
"to",
"off",
"then",
"a",
"clear",
"needs",
"to",
"be",
"sent",
"along",
"with",
"all",
"the",
"desired",
"state",
"in",
"this",
"case",
"this",
"function",
"returns",
"null"
]
| 3a550eadb21bb87a6909436c3b961919d2731923 | https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/TerminalState.php#L203-L294 | train |
TeaLabs/collections | src/Arr.php | Arr.toArray | public static function toArray($object)
{
if(is_array($object))
return $object;
elseif(!is_object($object))
return (array) $object;
elseif ($object instanceof IlluminateCollection)
return $object->all();
elseif ($object instanceof IlluminateArrayable)
return $object->toArray();
elseif(method_exists($object, '__toString'))
return [$object];
elseif ($object instanceof IlluminateJsonable)
return (array) json_decode($object->toJson(), true);
elseif ($object instanceof JsonSerializable)
return (array) $object->jsonSerialize();
elseif ($object instanceof Traversable)
return iterator_to_array($object);
else
return (array) $object;
} | php | public static function toArray($object)
{
if(is_array($object))
return $object;
elseif(!is_object($object))
return (array) $object;
elseif ($object instanceof IlluminateCollection)
return $object->all();
elseif ($object instanceof IlluminateArrayable)
return $object->toArray();
elseif(method_exists($object, '__toString'))
return [$object];
elseif ($object instanceof IlluminateJsonable)
return (array) json_decode($object->toJson(), true);
elseif ($object instanceof JsonSerializable)
return (array) $object->jsonSerialize();
elseif ($object instanceof Traversable)
return iterator_to_array($object);
else
return (array) $object;
} | [
"public",
"static",
"function",
"toArray",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"return",
"$",
"object",
";",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"return",
"(",
"array",
")",
"$",
"object",
";",
"elseif",
"(",
"$",
"object",
"instanceof",
"IlluminateCollection",
")",
"return",
"$",
"object",
"->",
"all",
"(",
")",
";",
"elseif",
"(",
"$",
"object",
"instanceof",
"IlluminateArrayable",
")",
"return",
"$",
"object",
"->",
"toArray",
"(",
")",
";",
"elseif",
"(",
"method_exists",
"(",
"$",
"object",
",",
"'__toString'",
")",
")",
"return",
"[",
"$",
"object",
"]",
";",
"elseif",
"(",
"$",
"object",
"instanceof",
"IlluminateJsonable",
")",
"return",
"(",
"array",
")",
"json_decode",
"(",
"$",
"object",
"->",
"toJson",
"(",
")",
",",
"true",
")",
";",
"elseif",
"(",
"$",
"object",
"instanceof",
"JsonSerializable",
")",
"return",
"(",
"array",
")",
"$",
"object",
"->",
"jsonSerialize",
"(",
")",
";",
"elseif",
"(",
"$",
"object",
"instanceof",
"Traversable",
")",
"return",
"iterator_to_array",
"(",
"$",
"object",
")",
";",
"else",
"return",
"(",
"array",
")",
"$",
"object",
";",
"}"
]
| Cast the given object to an array
@param mixed $object
@return array | [
"Cast",
"the",
"given",
"object",
"to",
"an",
"array"
]
| 5d8885b2799791c0bcbff4e6cbacddb270b4288e | https://github.com/TeaLabs/collections/blob/5d8885b2799791c0bcbff4e6cbacddb270b4288e/src/Arr.php#L294-L314 | train |
phpffcms/ffcms-core | src/Arch/ActiveModel.php | ActiveModel.getLocaled | public function getLocaled(string $attribute)
{
// if always decoded
if (Any::isArray($this->{$attribute})) {
return $this->{$attribute}[App::$Request->getLanguage()];
}
if (!Any::isStr($attribute) || Str::likeEmpty($this->{$attribute})) {
return null;
}
return Serialize::getDecodeLocale($this->{$attribute});
} | php | public function getLocaled(string $attribute)
{
// if always decoded
if (Any::isArray($this->{$attribute})) {
return $this->{$attribute}[App::$Request->getLanguage()];
}
if (!Any::isStr($attribute) || Str::likeEmpty($this->{$attribute})) {
return null;
}
return Serialize::getDecodeLocale($this->{$attribute});
} | [
"public",
"function",
"getLocaled",
"(",
"string",
"$",
"attribute",
")",
"{",
"// if always decoded",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
"[",
"App",
"::",
"$",
"Request",
"->",
"getLanguage",
"(",
")",
"]",
";",
"}",
"if",
"(",
"!",
"Any",
"::",
"isStr",
"(",
"$",
"attribute",
")",
"||",
"Str",
"::",
"likeEmpty",
"(",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"Serialize",
"::",
"getDecodeLocale",
"(",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
")",
";",
"}"
]
| Special function for locale stored attributes under serialization.
@param string $attribute
@return array|null|string | [
"Special",
"function",
"for",
"locale",
"stored",
"attributes",
"under",
"serialization",
"."
]
| 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/ActiveModel.php#L55-L67 | train |
phpffcms/ffcms-core | src/Arch/ActiveModel.php | ActiveModel.setAttribute | public function setAttribute($key, $value)
{
if ($value !== null && $this->isSerializeCastable($key)) {
$value = $this->asSerialize($value);
}
return parent::setAttribute($key, $value);
} | php | public function setAttribute($key, $value)
{
if ($value !== null && $this->isSerializeCastable($key)) {
$value = $this->asSerialize($value);
}
return parent::setAttribute($key, $value);
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"$",
"this",
"->",
"isSerializeCastable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"asSerialize",
"(",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
]
| Set model attribute. Extend laravel attribute casting mutators by serialized array
@param string $key
@param mixed $value
@return LaravelModel | [
"Set",
"model",
"attribute",
".",
"Extend",
"laravel",
"attribute",
"casting",
"mutators",
"by",
"serialized",
"array"
]
| 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/ActiveModel.php#L75-L82 | train |
phpffcms/ffcms-core | src/Arch/ActiveModel.php | ActiveModel.castAttribute | protected function castAttribute($key, $value)
{
if ($value === null) {
return $value;
}
if ($this->getCastType($key) === 'serialize') {
return $this->fromSerialize($value);
}
return parent::castAttribute($key, $value);
} | php | protected function castAttribute($key, $value)
{
if ($value === null) {
return $value;
}
if ($this->getCastType($key) === 'serialize') {
return $this->fromSerialize($value);
}
return parent::castAttribute($key, $value);
} | [
"protected",
"function",
"castAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getCastType",
"(",
"$",
"key",
")",
"===",
"'serialize'",
")",
"{",
"return",
"$",
"this",
"->",
"fromSerialize",
"(",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"castAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
]
| Cast model attribute. Extend laravel attribute casting mutators by serialized array
@param string $key
@param mixed $value
@return mixed | [
"Cast",
"model",
"attribute",
".",
"Extend",
"laravel",
"attribute",
"casting",
"mutators",
"by",
"serialized",
"array"
]
| 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Arch/ActiveModel.php#L90-L101 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.fromSimpleXml | public static function fromSimpleXml($xml, $userId = null)
{
$torrent = new NyaaTorrent();
$torrent->title = (string)$xml->title;
$torrent->setInfoFromDescription((string)$xml->description);
$torrent->meta = NyaaMeta::createFromTitle($torrent->title);
$torrent->torrentUrl = (string)$xml->link;
$torrent->siteUrl = (string)$xml->guid;
$torrent->category = (string)$xml->category;
$torrent->publishDate = \DateTime::createFromFormat('D, d M Y H:i:s T', $xml->pubDate, new \DateTimeZone('UTC'));
$torrent->userId = $userId;
return $torrent;
} | php | public static function fromSimpleXml($xml, $userId = null)
{
$torrent = new NyaaTorrent();
$torrent->title = (string)$xml->title;
$torrent->setInfoFromDescription((string)$xml->description);
$torrent->meta = NyaaMeta::createFromTitle($torrent->title);
$torrent->torrentUrl = (string)$xml->link;
$torrent->siteUrl = (string)$xml->guid;
$torrent->category = (string)$xml->category;
$torrent->publishDate = \DateTime::createFromFormat('D, d M Y H:i:s T', $xml->pubDate, new \DateTimeZone('UTC'));
$torrent->userId = $userId;
return $torrent;
} | [
"public",
"static",
"function",
"fromSimpleXml",
"(",
"$",
"xml",
",",
"$",
"userId",
"=",
"null",
")",
"{",
"$",
"torrent",
"=",
"new",
"NyaaTorrent",
"(",
")",
";",
"$",
"torrent",
"->",
"title",
"=",
"(",
"string",
")",
"$",
"xml",
"->",
"title",
";",
"$",
"torrent",
"->",
"setInfoFromDescription",
"(",
"(",
"string",
")",
"$",
"xml",
"->",
"description",
")",
";",
"$",
"torrent",
"->",
"meta",
"=",
"NyaaMeta",
"::",
"createFromTitle",
"(",
"$",
"torrent",
"->",
"title",
")",
";",
"$",
"torrent",
"->",
"torrentUrl",
"=",
"(",
"string",
")",
"$",
"xml",
"->",
"link",
";",
"$",
"torrent",
"->",
"siteUrl",
"=",
"(",
"string",
")",
"$",
"xml",
"->",
"guid",
";",
"$",
"torrent",
"->",
"category",
"=",
"(",
"string",
")",
"$",
"xml",
"->",
"category",
";",
"$",
"torrent",
"->",
"publishDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'D, d M Y H:i:s T'",
",",
"$",
"xml",
"->",
"pubDate",
",",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"$",
"torrent",
"->",
"userId",
"=",
"$",
"userId",
";",
"return",
"$",
"torrent",
";",
"}"
]
| Creates a new NyaaTorrent instance from a simple xml element
@param \SimpleXmlElement $xml The SimpleXmlElement from the Nyaa feed containing the torrent info
@param int $userId The userid of this torrent
@return NyaaTorrent | [
"Creates",
"a",
"new",
"NyaaTorrent",
"instance",
"from",
"a",
"simple",
"xml",
"element"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L31-L45 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.setInfoFromDescription | public function setInfoFromDescription($description)
{
// 1 seeder(s), 20 leecher(s), 63 download(s) - 793.9 MiB
if (!preg_match('~([0-9]+) seeder\(s\), ([0-9]+) leecher\(s\), ([0-9]+) download\(s\)(?: - ([0-9]+(\.[0-9]+)))?~i', $description, $match)) {
return;
}
$this->seeds = intval($match[1]);
$this->leechers = intval($match[2]);
$this->downloads = intval($match[3]);
if (isset($match[4])) {
// MB -> B
$this->size = floatval($match[4]) * 1000000;
}
} | php | public function setInfoFromDescription($description)
{
// 1 seeder(s), 20 leecher(s), 63 download(s) - 793.9 MiB
if (!preg_match('~([0-9]+) seeder\(s\), ([0-9]+) leecher\(s\), ([0-9]+) download\(s\)(?: - ([0-9]+(\.[0-9]+)))?~i', $description, $match)) {
return;
}
$this->seeds = intval($match[1]);
$this->leechers = intval($match[2]);
$this->downloads = intval($match[3]);
if (isset($match[4])) {
// MB -> B
$this->size = floatval($match[4]) * 1000000;
}
} | [
"public",
"function",
"setInfoFromDescription",
"(",
"$",
"description",
")",
"{",
"// 1 seeder(s), 20 leecher(s), 63 download(s) - 793.9 MiB",
"if",
"(",
"!",
"preg_match",
"(",
"'~([0-9]+) seeder\\(s\\), ([0-9]+) leecher\\(s\\), ([0-9]+) download\\(s\\)(?: - ([0-9]+(\\.[0-9]+)))?~i'",
",",
"$",
"description",
",",
"$",
"match",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"seeds",
"=",
"intval",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"leechers",
"=",
"intval",
"(",
"$",
"match",
"[",
"2",
"]",
")",
";",
"$",
"this",
"->",
"downloads",
"=",
"intval",
"(",
"$",
"match",
"[",
"3",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"4",
"]",
")",
")",
"{",
"// MB -> B",
"$",
"this",
"->",
"size",
"=",
"floatval",
"(",
"$",
"match",
"[",
"4",
"]",
")",
"*",
"1000000",
";",
"}",
"}"
]
| Sets the torrent info from the description string
@param string $description The description to parse info from | [
"Sets",
"the",
"torrent",
"info",
"from",
"the",
"description",
"string"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L72-L86 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.getUserId | public function getUserId()
{
if ($this->userId === null) {
$this->userId = $this->fetchUserId();
}
return $this->userId;
} | php | public function getUserId()
{
if ($this->userId === null) {
$this->userId = $this->fetchUserId();
}
return $this->userId;
} | [
"public",
"function",
"getUserId",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"userId",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"userId",
"=",
"$",
"this",
"->",
"fetchUserId",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"userId",
";",
"}"
]
| Gets the user id for this torrent
@return int | [
"Gets",
"the",
"user",
"id",
"for",
"this",
"torrent"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L159-L166 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.getTorrentId | public function getTorrentId()
{
if ($this->torrentId === null) {
$this->torrentId = false;
if (preg_match('~tid=([0-9]+)~', $this->torrentUrl, $match)) {
$this->torrentId = intval($match[1]);
}
}
return $this->torrentId;
} | php | public function getTorrentId()
{
if ($this->torrentId === null) {
$this->torrentId = false;
if (preg_match('~tid=([0-9]+)~', $this->torrentUrl, $match)) {
$this->torrentId = intval($match[1]);
}
}
return $this->torrentId;
} | [
"public",
"function",
"getTorrentId",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"torrentId",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"torrentId",
"=",
"false",
";",
"if",
"(",
"preg_match",
"(",
"'~tid=([0-9]+)~'",
",",
"$",
"this",
"->",
"torrentUrl",
",",
"$",
"match",
")",
")",
"{",
"$",
"this",
"->",
"torrentId",
"=",
"intval",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"torrentId",
";",
"}"
]
| Get the id of this torrent
@return int | [
"Get",
"the",
"id",
"of",
"this",
"torrent"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L172-L183 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.fetchUserId | private function fetchUserId()
{
$pool = Registry::getStash();
$cache = $pool->getItem('nyaa/user/'.$this->getTorrentId());
if ($cache->isMiss()) {
// sadly we have to use the site since nothing provides the user id
$userId = false;
$html = file_get_contents($this->siteUrl);
// lets not depend on the actual domain
if(preg_match('~\/\?user\=([0-9]+)~i', $html, $match)) {
$userId = intval($match[1]);
}
$cache->set($userId);
}
return $cache->get();
} | php | private function fetchUserId()
{
$pool = Registry::getStash();
$cache = $pool->getItem('nyaa/user/'.$this->getTorrentId());
if ($cache->isMiss()) {
// sadly we have to use the site since nothing provides the user id
$userId = false;
$html = file_get_contents($this->siteUrl);
// lets not depend on the actual domain
if(preg_match('~\/\?user\=([0-9]+)~i', $html, $match)) {
$userId = intval($match[1]);
}
$cache->set($userId);
}
return $cache->get();
} | [
"private",
"function",
"fetchUserId",
"(",
")",
"{",
"$",
"pool",
"=",
"Registry",
"::",
"getStash",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"pool",
"->",
"getItem",
"(",
"'nyaa/user/'",
".",
"$",
"this",
"->",
"getTorrentId",
"(",
")",
")",
";",
"if",
"(",
"$",
"cache",
"->",
"isMiss",
"(",
")",
")",
"{",
"// sadly we have to use the site since nothing provides the user id",
"$",
"userId",
"=",
"false",
";",
"$",
"html",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"siteUrl",
")",
";",
"// lets not depend on the actual domain",
"if",
"(",
"preg_match",
"(",
"'~\\/\\?user\\=([0-9]+)~i'",
",",
"$",
"html",
",",
"$",
"match",
")",
")",
"{",
"$",
"userId",
"=",
"intval",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"$",
"userId",
")",
";",
"}",
"return",
"$",
"cache",
"->",
"get",
"(",
")",
";",
"}"
]
| Gets the user id by getting the overview of the torrent page and looking for the user id there
@return int | [
"Gets",
"the",
"user",
"id",
"by",
"getting",
"the",
"overview",
"of",
"the",
"torrent",
"page",
"and",
"looking",
"for",
"the",
"user",
"id",
"there"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L189-L209 | train |
the-eater/odango.php | src/NyaaTorrent.php | NyaaTorrent.getMeta | public function getMeta($meta = null)
{
if ($meta === null) {
return $this->meta;
}
return $this->meta->get($meta);
} | php | public function getMeta($meta = null)
{
if ($meta === null) {
return $this->meta;
}
return $this->meta->get($meta);
} | [
"public",
"function",
"getMeta",
"(",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"meta",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"meta",
";",
"}",
"return",
"$",
"this",
"->",
"meta",
"->",
"get",
"(",
"$",
"meta",
")",
";",
"}"
]
| Gets the NyaaMeta object or a meta value from the meta object if an argument is given
@param string $meta Meta name to get
@return mixed | [
"Gets",
"the",
"NyaaMeta",
"object",
"or",
"a",
"meta",
"value",
"from",
"the",
"meta",
"object",
"if",
"an",
"argument",
"is",
"given"
]
| 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaTorrent.php#L216-L223 | train |
irfantoor/collection | src/Collection.php | Collection.has | public function has($id)
{
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
return $has;
} else {
return (is_string($id)) ? array_key_exists($id, $this->data) : false;
}
} | php | public function has($id)
{
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
return $has;
} else {
return (is_string($id)) ? array_key_exists($id, $this->data) : false;
}
} | [
"public",
"function",
"has",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"id",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"k",
"=",
"'$this->data'",
".",
"\"['\"",
".",
"str_replace",
"(",
"'.'",
",",
"\"']['\"",
",",
"$",
"id",
")",
".",
"\"']\"",
";",
"eval",
"(",
"'$has = isset('",
".",
"$",
"k",
".",
"');'",
")",
";",
"return",
"$",
"has",
";",
"}",
"else",
"{",
"return",
"(",
"is_string",
"(",
"$",
"id",
")",
")",
"?",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"data",
")",
":",
"false",
";",
"}",
"}"
]
| Returns true if the collection can return an entry for the given
identifier, returns false otherwise.
`has($id)` returning true does not mean that `get($id)` will not throw
an exception.
It does however mean that `get($id)` will not throw a
`NotFoundExceptionInterface`.
@param String $id Identifier of the entry to look for.
@return boolval true if found, false otherwise | [
"Returns",
"true",
"if",
"the",
"collection",
"can",
"return",
"an",
"entry",
"for",
"the",
"given",
"identifier",
"returns",
"false",
"otherwise",
"."
]
| 1a69d9f09e9960bce33e00bf985ca47aa0566cf9 | https://github.com/irfantoor/collection/blob/1a69d9f09e9960bce33e00bf985ca47aa0566cf9/src/Collection.php#L154-L163 | train |
irfantoor/collection | src/Collection.php | Collection.get | public function get($id, $default = null)
{
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
if ($has) {
eval('$value = ' . $k . ';');
return $value;
} else {
return $default;
}
} else {
return $this->has($id) ? $this->data[$id] : $default;
}
} | php | public function get($id, $default = null)
{
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
if ($has) {
eval('$value = ' . $k . ';');
return $value;
} else {
return $default;
}
} else {
return $this->has($id) ? $this->data[$id] : $default;
}
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"id",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"k",
"=",
"'$this->data'",
".",
"\"['\"",
".",
"str_replace",
"(",
"'.'",
",",
"\"']['\"",
",",
"$",
"id",
")",
".",
"\"']\"",
";",
"eval",
"(",
"'$has = isset('",
".",
"$",
"k",
".",
"');'",
")",
";",
"if",
"(",
"$",
"has",
")",
"{",
"eval",
"(",
"'$value = '",
".",
"$",
"k",
".",
"';'",
")",
";",
"return",
"$",
"value",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"id",
"]",
":",
"$",
"default",
";",
"}",
"}"
]
| Finds an entry of the collection by its identifier and returns it.
@param String $id Identifier of the entry to look for.
@param Mixed $default A default value.
@return Mixed Entry. | [
"Finds",
"an",
"entry",
"of",
"the",
"collection",
"by",
"its",
"identifier",
"and",
"returns",
"it",
"."
]
| 1a69d9f09e9960bce33e00bf985ca47aa0566cf9 | https://github.com/irfantoor/collection/blob/1a69d9f09e9960bce33e00bf985ca47aa0566cf9/src/Collection.php#L173-L187 | train |
irfantoor/collection | src/Collection.php | Collection.remove | public function remove($id)
{
if ($this->locked) {
return false;
}
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
if ($has) {
eval('unset(' . $k . ');');
return true;
} else {
return false;
}
} elseif ($this->has($id)) {
unset($this->data[$id]);
return true;
} else {
return false;
}
} | php | public function remove($id)
{
if ($this->locked) {
return false;
}
if (strpos($id, '.') !== false) {
$k = '$this->data' . "['" . str_replace('.', "']['", $id) . "']";
eval('$has = isset(' . $k . ');');
if ($has) {
eval('unset(' . $k . ');');
return true;
} else {
return false;
}
} elseif ($this->has($id)) {
unset($this->data[$id]);
return true;
} else {
return false;
}
} | [
"public",
"function",
"remove",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"locked",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"id",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"k",
"=",
"'$this->data'",
".",
"\"['\"",
".",
"str_replace",
"(",
"'.'",
",",
"\"']['\"",
",",
"$",
"id",
")",
".",
"\"']\"",
";",
"eval",
"(",
"'$has = isset('",
".",
"$",
"k",
".",
"');'",
")",
";",
"if",
"(",
"$",
"has",
")",
"{",
"eval",
"(",
"'unset('",
".",
"$",
"k",
".",
"');'",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"id",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Removes the value from identified by an identifier from the colection
@param String $id identifier
@return boolval true if successful in removing, false otherwise | [
"Removes",
"the",
"value",
"from",
"identified",
"by",
"an",
"identifier",
"from",
"the",
"colection"
]
| 1a69d9f09e9960bce33e00bf985ca47aa0566cf9 | https://github.com/irfantoor/collection/blob/1a69d9f09e9960bce33e00bf985ca47aa0566cf9/src/Collection.php#L196-L217 | train |
kapitchi/KapitchiIdentity | src/KapitchiIdentity/Service/Auth.php | Auth.clearIdentity | public function clearIdentity()
{
$this->getStorage()->clear();
//all identies go - it's done that way now at least
$ids = $this->getContainer()->getIdentities();
$sessionIds = array();
foreach($ids as $id) {
$sessionIds[] = $id->getSessionId();
}
$this->getSessionProvider()->clear($sessionIds);
$this->getEventManager()->trigger('clearIdentity.post', $this, array(
'identities' => $ids
));
return $ids;
} | php | public function clearIdentity()
{
$this->getStorage()->clear();
//all identies go - it's done that way now at least
$ids = $this->getContainer()->getIdentities();
$sessionIds = array();
foreach($ids as $id) {
$sessionIds[] = $id->getSessionId();
}
$this->getSessionProvider()->clear($sessionIds);
$this->getEventManager()->trigger('clearIdentity.post', $this, array(
'identities' => $ids
));
return $ids;
} | [
"public",
"function",
"clearIdentity",
"(",
")",
"{",
"$",
"this",
"->",
"getStorage",
"(",
")",
"->",
"clear",
"(",
")",
";",
"//all identies go - it's done that way now at least",
"$",
"ids",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getIdentities",
"(",
")",
";",
"$",
"sessionIds",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"sessionIds",
"[",
"]",
"=",
"$",
"id",
"->",
"getSessionId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"getSessionProvider",
"(",
")",
"->",
"clear",
"(",
"$",
"sessionIds",
")",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"'clearIdentity.post'",
",",
"$",
"this",
",",
"array",
"(",
"'identities'",
"=>",
"$",
"ids",
")",
")",
";",
"return",
"$",
"ids",
";",
"}"
]
| Clears the identity from persistent storage
@return array AuthIdentity | [
"Clears",
"the",
"identity",
"from",
"persistent",
"storage"
]
| 744bd4341079045d067993eab0c63486d2693caa | https://github.com/kapitchi/KapitchiIdentity/blob/744bd4341079045d067993eab0c63486d2693caa/src/KapitchiIdentity/Service/Auth.php#L149-L166 | train |
DaGhostman/codewave | src/Application/AspectsKernel.php | AspectsKernel.addAspect | public function addAspect(Aspect $aspect)
{
if ($this->container !== null) {
$this->container->registerAspect($aspect);
}
return $this;
} | php | public function addAspect(Aspect $aspect)
{
if ($this->container !== null) {
$this->container->registerAspect($aspect);
}
return $this;
} | [
"public",
"function",
"addAspect",
"(",
"Aspect",
"$",
"aspect",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"registerAspect",
"(",
"$",
"aspect",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Registers an aspect to the aspects kernel
@param Aspect $aspect
@return $this | [
"Registers",
"an",
"aspect",
"to",
"the",
"aspects",
"kernel"
]
| f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/AspectsKernel.php#L47-L54 | train |
Emagedev/Utils | app/code/community/Emagedev/Utils/Helper/Curl.php | Emagedev_Utils_Helper_Curl.dispatchResponse | public function dispatchResponse($response)
{
$parts = explode("\r\n\r\n", $response, 2);
if (count($parts) < 2) {
$this->throwException();
}
list($headersAsString, $body) = $parts;
$headers = explode("\r\n", $headersAsString);
list($code, $status) = $this->dispatchHttpStatus(array_shift($headers));
$headers = $this->dispatchHeaders($headers);
/** @var Emagedev_Utils_Model_Curl_Response $responseObject */
$responseObject = Mage::getModel('emagedev_utils/curl_response');
return $responseObject->setData(
array(
'code' => $code,
'status' => $status,
'headers_as_string' => $headersAsString,
'headers' => $headers,
'body' => $body
)
);
} | php | public function dispatchResponse($response)
{
$parts = explode("\r\n\r\n", $response, 2);
if (count($parts) < 2) {
$this->throwException();
}
list($headersAsString, $body) = $parts;
$headers = explode("\r\n", $headersAsString);
list($code, $status) = $this->dispatchHttpStatus(array_shift($headers));
$headers = $this->dispatchHeaders($headers);
/** @var Emagedev_Utils_Model_Curl_Response $responseObject */
$responseObject = Mage::getModel('emagedev_utils/curl_response');
return $responseObject->setData(
array(
'code' => $code,
'status' => $status,
'headers_as_string' => $headersAsString,
'headers' => $headers,
'body' => $body
)
);
} | [
"public",
"function",
"dispatchResponse",
"(",
"$",
"response",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"response",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"throwException",
"(",
")",
";",
"}",
"list",
"(",
"$",
"headersAsString",
",",
"$",
"body",
")",
"=",
"$",
"parts",
";",
"$",
"headers",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headersAsString",
")",
";",
"list",
"(",
"$",
"code",
",",
"$",
"status",
")",
"=",
"$",
"this",
"->",
"dispatchHttpStatus",
"(",
"array_shift",
"(",
"$",
"headers",
")",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"dispatchHeaders",
"(",
"$",
"headers",
")",
";",
"/** @var Emagedev_Utils_Model_Curl_Response $responseObject */",
"$",
"responseObject",
"=",
"Mage",
"::",
"getModel",
"(",
"'emagedev_utils/curl_response'",
")",
";",
"return",
"$",
"responseObject",
"->",
"setData",
"(",
"array",
"(",
"'code'",
"=>",
"$",
"code",
",",
"'status'",
"=>",
"$",
"status",
",",
"'headers_as_string'",
"=>",
"$",
"headersAsString",
",",
"'headers'",
"=>",
"$",
"headers",
",",
"'body'",
"=>",
"$",
"body",
")",
")",
";",
"}"
]
| Get response code, headers, status, body
@param string $response
@return Omedrec_Welcome_Model_Curl_Response | [
"Get",
"response",
"code",
"headers",
"status",
"body"
]
| 1a9b40fef401e19c94cc6d7bfb14a42bda720273 | https://github.com/Emagedev/Utils/blob/1a9b40fef401e19c94cc6d7bfb14a42bda720273/app/code/community/Emagedev/Utils/Helper/Curl.php#L54-L80 | train |
Emagedev/Utils | app/code/community/Emagedev/Utils/Helper/Curl.php | Emagedev_Utils_Helper_Curl.dispatchHttpStatus | protected function dispatchHttpStatus($header)
{
$statuses = array();
$result = preg_match('/^http\/[1|2]\.\d (\d{3}) (.*)$/i', $header, $statuses);
if ($result < 1) {
$this->throwException();
}
// Code, status text
return array((int)$statuses[1], $statuses[2]);
} | php | protected function dispatchHttpStatus($header)
{
$statuses = array();
$result = preg_match('/^http\/[1|2]\.\d (\d{3}) (.*)$/i', $header, $statuses);
if ($result < 1) {
$this->throwException();
}
// Code, status text
return array((int)$statuses[1], $statuses[2]);
} | [
"protected",
"function",
"dispatchHttpStatus",
"(",
"$",
"header",
")",
"{",
"$",
"statuses",
"=",
"array",
"(",
")",
";",
"$",
"result",
"=",
"preg_match",
"(",
"'/^http\\/[1|2]\\.\\d (\\d{3}) (.*)$/i'",
",",
"$",
"header",
",",
"$",
"statuses",
")",
";",
"if",
"(",
"$",
"result",
"<",
"1",
")",
"{",
"$",
"this",
"->",
"throwException",
"(",
")",
";",
"}",
"// Code, status text",
"return",
"array",
"(",
"(",
"int",
")",
"$",
"statuses",
"[",
"1",
"]",
",",
"$",
"statuses",
"[",
"2",
"]",
")",
";",
"}"
]
| Get HTTP status and code from first header
@param string $header
@return array | [
"Get",
"HTTP",
"status",
"and",
"code",
"from",
"first",
"header"
]
| 1a9b40fef401e19c94cc6d7bfb14a42bda720273 | https://github.com/Emagedev/Utils/blob/1a9b40fef401e19c94cc6d7bfb14a42bda720273/app/code/community/Emagedev/Utils/Helper/Curl.php#L89-L100 | train |
Emagedev/Utils | app/code/community/Emagedev/Utils/Helper/Curl.php | Emagedev_Utils_Helper_Curl.dispatchHeaders | protected function dispatchHeaders($headersAsString)
{
$headers = array();
foreach ($headersAsString as $header) {
$headerData = $this->dispatchHeaderValue($header);
if (is_null($headerData)) {
continue;
}
$headers[$headerData['name']] = $headerData['value'];
}
return $headers;
} | php | protected function dispatchHeaders($headersAsString)
{
$headers = array();
foreach ($headersAsString as $header) {
$headerData = $this->dispatchHeaderValue($header);
if (is_null($headerData)) {
continue;
}
$headers[$headerData['name']] = $headerData['value'];
}
return $headers;
} | [
"protected",
"function",
"dispatchHeaders",
"(",
"$",
"headersAsString",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"headersAsString",
"as",
"$",
"header",
")",
"{",
"$",
"headerData",
"=",
"$",
"this",
"->",
"dispatchHeaderValue",
"(",
"$",
"header",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"headerData",
")",
")",
"{",
"continue",
";",
"}",
"$",
"headers",
"[",
"$",
"headerData",
"[",
"'name'",
"]",
"]",
"=",
"$",
"headerData",
"[",
"'value'",
"]",
";",
"}",
"return",
"$",
"headers",
";",
"}"
]
| Get headers an values
@param $headersAsString
@return array | [
"Get",
"headers",
"an",
"values"
]
| 1a9b40fef401e19c94cc6d7bfb14a42bda720273 | https://github.com/Emagedev/Utils/blob/1a9b40fef401e19c94cc6d7bfb14a42bda720273/app/code/community/Emagedev/Utils/Helper/Curl.php#L109-L124 | train |
Emagedev/Utils | app/code/community/Emagedev/Utils/Helper/Curl.php | Emagedev_Utils_Helper_Curl.dispatchHeaderValue | protected function dispatchHeaderValue($header)
{
$header = explode(':', $header, 2);
if (count($header) < 2) {
return null;
}
return array(
'name' => trim($header[0]),
'value' => trim($header[1]),
);
} | php | protected function dispatchHeaderValue($header)
{
$header = explode(':', $header, 2);
if (count($header) < 2) {
return null;
}
return array(
'name' => trim($header[0]),
'value' => trim($header[1]),
);
} | [
"protected",
"function",
"dispatchHeaderValue",
"(",
"$",
"header",
")",
"{",
"$",
"header",
"=",
"explode",
"(",
"':'",
",",
"$",
"header",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"header",
")",
"<",
"2",
")",
"{",
"return",
"null",
";",
"}",
"return",
"array",
"(",
"'name'",
"=>",
"trim",
"(",
"$",
"header",
"[",
"0",
"]",
")",
",",
"'value'",
"=>",
"trim",
"(",
"$",
"header",
"[",
"1",
"]",
")",
",",
")",
";",
"}"
]
| Get key-value array
@see https://stackoverflow.com/questions/9183178/can-php-curl-retrieve-response-headers-and-body-in-a-single-request
@param $header
@return array|null | [
"Get",
"key",
"-",
"value",
"array"
]
| 1a9b40fef401e19c94cc6d7bfb14a42bda720273 | https://github.com/Emagedev/Utils/blob/1a9b40fef401e19c94cc6d7bfb14a42bda720273/app/code/community/Emagedev/Utils/Helper/Curl.php#L135-L147 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.