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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
jails/li3_tree | extensions/data/behavior/Tree.php | Tree.moveDown | public function moveDown($entity) {
extract($this->_config);
$next = $model::find('first', [
'conditions' => [
$parent => $entity->$parent,
$left => $entity->$right + 1
]]);
if ($next !== null) {
$spanToZero = $entity->$right;
$rangeX = ['floor' => $entity->$left, 'ceiling' => $entity->$right];
$shiftX = ($next->$right - $next->$left) + 1;
$rangeY = ['floor' => $next->$left, 'ceiling' => $next->$right];
$shiftY = ($entity->$right - $entity->$left) + 1;
$this->_updateBetween($rangeX, '-', $spanToZero, $this->_scope($entity));
$this->_updateBetween($rangeY, '-', $shiftY, $this->_scope($entity));
$this->_updateBetween([
'floor' => (0 - $shiftY), 'ceiling' => 0
], '+', $spanToZero + $shiftX, $this->_scope($entity));
$entity->set([
$left => $entity->$left + $shiftX, $right => $entity->$right + $shiftX
]);
}
return true;
} | php | public function moveDown($entity) {
extract($this->_config);
$next = $model::find('first', [
'conditions' => [
$parent => $entity->$parent,
$left => $entity->$right + 1
]]);
if ($next !== null) {
$spanToZero = $entity->$right;
$rangeX = ['floor' => $entity->$left, 'ceiling' => $entity->$right];
$shiftX = ($next->$right - $next->$left) + 1;
$rangeY = ['floor' => $next->$left, 'ceiling' => $next->$right];
$shiftY = ($entity->$right - $entity->$left) + 1;
$this->_updateBetween($rangeX, '-', $spanToZero, $this->_scope($entity));
$this->_updateBetween($rangeY, '-', $shiftY, $this->_scope($entity));
$this->_updateBetween([
'floor' => (0 - $shiftY), 'ceiling' => 0
], '+', $spanToZero + $shiftX, $this->_scope($entity));
$entity->set([
$left => $entity->$left + $shiftX, $right => $entity->$right + $shiftX
]);
}
return true;
} | [
"public",
"function",
"moveDown",
"(",
"$",
"entity",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"_config",
")",
";",
"$",
"next",
"=",
"$",
"model",
"::",
"find",
"(",
"'first'",
",",
"[",
"'conditions'",
"=>",
"[",
"$",
"parent",
"=>",
"$",
"entity",
"->",
"$",
"parent",
",",
"$",
"left",
"=>",
"$",
"entity",
"->",
"$",
"right",
"+",
"1",
"]",
"]",
")",
";",
"if",
"(",
"$",
"next",
"!==",
"null",
")",
"{",
"$",
"spanToZero",
"=",
"$",
"entity",
"->",
"$",
"right",
";",
"$",
"rangeX",
"=",
"[",
"'floor'",
"=>",
"$",
"entity",
"->",
"$",
"left",
",",
"'ceiling'",
"=>",
"$",
"entity",
"->",
"$",
"right",
"]",
";",
"$",
"shiftX",
"=",
"(",
"$",
"next",
"->",
"$",
"right",
"-",
"$",
"next",
"->",
"$",
"left",
")",
"+",
"1",
";",
"$",
"rangeY",
"=",
"[",
"'floor'",
"=>",
"$",
"next",
"->",
"$",
"left",
",",
"'ceiling'",
"=>",
"$",
"next",
"->",
"$",
"right",
"]",
";",
"$",
"shiftY",
"=",
"(",
"$",
"entity",
"->",
"$",
"right",
"-",
"$",
"entity",
"->",
"$",
"left",
")",
"+",
"1",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"$",
"rangeX",
",",
"'-'",
",",
"$",
"spanToZero",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"$",
"rangeY",
",",
"'-'",
",",
"$",
"shiftY",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"[",
"'floor'",
"=>",
"(",
"0",
"-",
"$",
"shiftY",
")",
",",
"'ceiling'",
"=>",
"0",
"]",
",",
"'+'",
",",
"$",
"spanToZero",
"+",
"$",
"shiftX",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"[",
"$",
"left",
"=>",
"$",
"entity",
"->",
"$",
"left",
"+",
"$",
"shiftX",
",",
"$",
"right",
"=>",
"$",
"entity",
"->",
"$",
"right",
"+",
"$",
"shiftX",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Moves an element down in order
@param object $entity The Entity to move down | [
"Moves",
"an",
"element",
"down",
"in",
"order"
] | 43fdbe9c621f1f712131c6a338bb5421da67fc17 | https://github.com/jails/li3_tree/blob/43fdbe9c621f1f712131c6a338bb5421da67fc17/extensions/data/behavior/Tree.php#L420-L446 | train |
jails/li3_tree | extensions/data/behavior/Tree.php | Tree.moveUp | public function moveUp($entity) {
extract($this->_config);
$prev = $model::find('first', [
'conditions' => [
$parent => $entity->$parent,
$right => $entity->$left - 1
]
]);
if (!$prev) {
return true;
}
$spanToZero = $entity->$right;
$rangeX = ['floor' => $entity->$left, 'ceiling' => $entity->$right];
$shiftX = ($prev->$right - $prev->$left) + 1;
$rangeY = ['floor' => $prev->$left, 'ceiling' => $prev->$right];
$shiftY = ($entity->$right - $entity->$left) + 1;
$this->_updateBetween($rangeX, '-', $spanToZero, $this->_scope($entity));
$this->_updateBetween($rangeY, '+', $shiftY, $this->_scope($entity));
$this->_updateBetween([
'floor' => (0 - $shiftY), 'ceiling' => 0
], '+', $spanToZero - $shiftX, $this->_scope($entity));
$entity->set([
$left => $entity->$left - $shiftX, $right => $entity->$right - $shiftX
]);
return true;
} | php | public function moveUp($entity) {
extract($this->_config);
$prev = $model::find('first', [
'conditions' => [
$parent => $entity->$parent,
$right => $entity->$left - 1
]
]);
if (!$prev) {
return true;
}
$spanToZero = $entity->$right;
$rangeX = ['floor' => $entity->$left, 'ceiling' => $entity->$right];
$shiftX = ($prev->$right - $prev->$left) + 1;
$rangeY = ['floor' => $prev->$left, 'ceiling' => $prev->$right];
$shiftY = ($entity->$right - $entity->$left) + 1;
$this->_updateBetween($rangeX, '-', $spanToZero, $this->_scope($entity));
$this->_updateBetween($rangeY, '+', $shiftY, $this->_scope($entity));
$this->_updateBetween([
'floor' => (0 - $shiftY), 'ceiling' => 0
], '+', $spanToZero - $shiftX, $this->_scope($entity));
$entity->set([
$left => $entity->$left - $shiftX, $right => $entity->$right - $shiftX
]);
return true;
} | [
"public",
"function",
"moveUp",
"(",
"$",
"entity",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"_config",
")",
";",
"$",
"prev",
"=",
"$",
"model",
"::",
"find",
"(",
"'first'",
",",
"[",
"'conditions'",
"=>",
"[",
"$",
"parent",
"=>",
"$",
"entity",
"->",
"$",
"parent",
",",
"$",
"right",
"=>",
"$",
"entity",
"->",
"$",
"left",
"-",
"1",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"prev",
")",
"{",
"return",
"true",
";",
"}",
"$",
"spanToZero",
"=",
"$",
"entity",
"->",
"$",
"right",
";",
"$",
"rangeX",
"=",
"[",
"'floor'",
"=>",
"$",
"entity",
"->",
"$",
"left",
",",
"'ceiling'",
"=>",
"$",
"entity",
"->",
"$",
"right",
"]",
";",
"$",
"shiftX",
"=",
"(",
"$",
"prev",
"->",
"$",
"right",
"-",
"$",
"prev",
"->",
"$",
"left",
")",
"+",
"1",
";",
"$",
"rangeY",
"=",
"[",
"'floor'",
"=>",
"$",
"prev",
"->",
"$",
"left",
",",
"'ceiling'",
"=>",
"$",
"prev",
"->",
"$",
"right",
"]",
";",
"$",
"shiftY",
"=",
"(",
"$",
"entity",
"->",
"$",
"right",
"-",
"$",
"entity",
"->",
"$",
"left",
")",
"+",
"1",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"$",
"rangeX",
",",
"'-'",
",",
"$",
"spanToZero",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"$",
"rangeY",
",",
"'+'",
",",
"$",
"shiftY",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"this",
"->",
"_updateBetween",
"(",
"[",
"'floor'",
"=>",
"(",
"0",
"-",
"$",
"shiftY",
")",
",",
"'ceiling'",
"=>",
"0",
"]",
",",
"'+'",
",",
"$",
"spanToZero",
"-",
"$",
"shiftX",
",",
"$",
"this",
"->",
"_scope",
"(",
"$",
"entity",
")",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"[",
"$",
"left",
"=>",
"$",
"entity",
"->",
"$",
"left",
"-",
"$",
"shiftX",
",",
"$",
"right",
"=>",
"$",
"entity",
"->",
"$",
"right",
"-",
"$",
"shiftX",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Moves an element up in order
@param object $entity The Entity to move up | [
"Moves",
"an",
"element",
"up",
"in",
"order"
] | 43fdbe9c621f1f712131c6a338bb5421da67fc17 | https://github.com/jails/li3_tree/blob/43fdbe9c621f1f712131c6a338bb5421da67fc17/extensions/data/behavior/Tree.php#L453-L480 | train |
jails/li3_tree | extensions/data/behavior/Tree.php | Tree._getPosition | protected function _getPosition($entity, $childrenCount = false) {
extract($this->_config);
$parent = $this->_getById($entity->$parent);
if ($entity->$left === ($parent->$left + 1)) {
return 0;
}
if (($entity->$right + 1) === $parent->$right) {
if ($childrenCount === false) {
$childrenCount = $parent->childrens(false, 'count');
}
return $childrenCount - 1;
}
$count = 0;
$children = $parent->childrens(false);
$id = $entity->data($model::key());
foreach ($children as $child) {
if ($child->data($model::key()) === $id) {
return $count;
}
$count++;
}
return false;
} | php | protected function _getPosition($entity, $childrenCount = false) {
extract($this->_config);
$parent = $this->_getById($entity->$parent);
if ($entity->$left === ($parent->$left + 1)) {
return 0;
}
if (($entity->$right + 1) === $parent->$right) {
if ($childrenCount === false) {
$childrenCount = $parent->childrens(false, 'count');
}
return $childrenCount - 1;
}
$count = 0;
$children = $parent->childrens(false);
$id = $entity->data($model::key());
foreach ($children as $child) {
if ($child->data($model::key()) === $id) {
return $count;
}
$count++;
}
return false;
} | [
"protected",
"function",
"_getPosition",
"(",
"$",
"entity",
",",
"$",
"childrenCount",
"=",
"false",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"_config",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"_getById",
"(",
"$",
"entity",
"->",
"$",
"parent",
")",
";",
"if",
"(",
"$",
"entity",
"->",
"$",
"left",
"===",
"(",
"$",
"parent",
"->",
"$",
"left",
"+",
"1",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"(",
"$",
"entity",
"->",
"$",
"right",
"+",
"1",
")",
"===",
"$",
"parent",
"->",
"$",
"right",
")",
"{",
"if",
"(",
"$",
"childrenCount",
"===",
"false",
")",
"{",
"$",
"childrenCount",
"=",
"$",
"parent",
"->",
"childrens",
"(",
"false",
",",
"'count'",
")",
";",
"}",
"return",
"$",
"childrenCount",
"-",
"1",
";",
"}",
"$",
"count",
"=",
"0",
";",
"$",
"children",
"=",
"$",
"parent",
"->",
"childrens",
"(",
"false",
")",
";",
"$",
"id",
"=",
"$",
"entity",
"->",
"data",
"(",
"$",
"model",
"::",
"key",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"data",
"(",
"$",
"model",
"::",
"key",
"(",
")",
")",
"===",
"$",
"id",
")",
"{",
"return",
"$",
"count",
";",
"}",
"$",
"count",
"++",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the current position number of an element at the same level,
where 0 is first position
@param object $entity the entity node to get the position from.
@param integer $childrenCount number of children of entity's parent,
performance parameter to avoid double select. | [
"Returns",
"the",
"current",
"position",
"number",
"of",
"an",
"element",
"at",
"the",
"same",
"level",
"where",
"0",
"is",
"first",
"position"
] | 43fdbe9c621f1f712131c6a338bb5421da67fc17 | https://github.com/jails/li3_tree/blob/43fdbe9c621f1f712131c6a338bb5421da67fc17/extensions/data/behavior/Tree.php#L509-L537 | train |
alphacomm/alpharpc | src/AlphaRPC/Client/AlphaRPCStatus.php | AlphaRPCStatus.queueStatus | public function queueStatus($manager)
{
$socket = $this->getSocket($manager);
$stream = $socket->getStream();
$stream->send(new QueueStatusRequest());
$msg = $stream->read(new TimeoutTimer(1500));
if (!$msg instanceof QueueStatusResponse) {
throw new RuntimeException('Invalid response: '.get_class($msg).'.');
}
return $msg->getQueueStatus();
} | php | public function queueStatus($manager)
{
$socket = $this->getSocket($manager);
$stream = $socket->getStream();
$stream->send(new QueueStatusRequest());
$msg = $stream->read(new TimeoutTimer(1500));
if (!$msg instanceof QueueStatusResponse) {
throw new RuntimeException('Invalid response: '.get_class($msg).'.');
}
return $msg->getQueueStatus();
} | [
"public",
"function",
"queueStatus",
"(",
"$",
"manager",
")",
"{",
"$",
"socket",
"=",
"$",
"this",
"->",
"getSocket",
"(",
"$",
"manager",
")",
";",
"$",
"stream",
"=",
"$",
"socket",
"->",
"getStream",
"(",
")",
";",
"$",
"stream",
"->",
"send",
"(",
"new",
"QueueStatusRequest",
"(",
")",
")",
";",
"$",
"msg",
"=",
"$",
"stream",
"->",
"read",
"(",
"new",
"TimeoutTimer",
"(",
"1500",
")",
")",
";",
"if",
"(",
"!",
"$",
"msg",
"instanceof",
"QueueStatusResponse",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Invalid response: '",
".",
"get_class",
"(",
"$",
"msg",
")",
".",
"'.'",
")",
";",
"}",
"return",
"$",
"msg",
"->",
"getQueueStatus",
"(",
")",
";",
"}"
] | Requests the queue status.
@param string $manager
@return array
@throws \RuntimeException | [
"Requests",
"the",
"queue",
"status",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/AlphaRPCStatus.php#L70-L83 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/service/HCServiceFormValidators.php | HCServiceFormValidators.optimize | public function optimize (stdClass $data)
{
$data->formValidationName = $data->serviceName . 'Validator';
$data->formValidationNameSpace = str_replace ('\\http\\controllers', '\\validators', $data->controllerNamespace);
$data->formValidationDestination = str_replace ('/http/controllers', '/validators', $data->controllerDestination) . '/' . $data->formValidationName . '.php';
if (isset($data->mainModel->multiLanguage)) {
$data->formTranslationsValidationName = $data->serviceName . 'TranslationsValidator';
$data->formTranslationsValidationDestination = str_replace ('/http/controllers', '/validators', $data->controllerDestination) . '/' . $data->formTranslationsValidationName . '.php';
}
return $data;
} | php | public function optimize (stdClass $data)
{
$data->formValidationName = $data->serviceName . 'Validator';
$data->formValidationNameSpace = str_replace ('\\http\\controllers', '\\validators', $data->controllerNamespace);
$data->formValidationDestination = str_replace ('/http/controllers', '/validators', $data->controllerDestination) . '/' . $data->formValidationName . '.php';
if (isset($data->mainModel->multiLanguage)) {
$data->formTranslationsValidationName = $data->serviceName . 'TranslationsValidator';
$data->formTranslationsValidationDestination = str_replace ('/http/controllers', '/validators', $data->controllerDestination) . '/' . $data->formTranslationsValidationName . '.php';
}
return $data;
} | [
"public",
"function",
"optimize",
"(",
"stdClass",
"$",
"data",
")",
"{",
"$",
"data",
"->",
"formValidationName",
"=",
"$",
"data",
"->",
"serviceName",
".",
"'Validator'",
";",
"$",
"data",
"->",
"formValidationNameSpace",
"=",
"str_replace",
"(",
"'\\\\http\\\\controllers'",
",",
"'\\\\validators'",
",",
"$",
"data",
"->",
"controllerNamespace",
")",
";",
"$",
"data",
"->",
"formValidationDestination",
"=",
"str_replace",
"(",
"'/http/controllers'",
",",
"'/validators'",
",",
"$",
"data",
"->",
"controllerDestination",
")",
".",
"'/'",
".",
"$",
"data",
"->",
"formValidationName",
".",
"'.php'",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"->",
"mainModel",
"->",
"multiLanguage",
")",
")",
"{",
"$",
"data",
"->",
"formTranslationsValidationName",
"=",
"$",
"data",
"->",
"serviceName",
".",
"'TranslationsValidator'",
";",
"$",
"data",
"->",
"formTranslationsValidationDestination",
"=",
"str_replace",
"(",
"'/http/controllers'",
",",
"'/validators'",
",",
"$",
"data",
"->",
"controllerDestination",
")",
".",
"'/'",
".",
"$",
"data",
"->",
"formTranslationsValidationName",
".",
"'.php'",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Optimizing configuration for form creation
@param stdClass $data
@return stdClass | [
"Optimizing",
"configuration",
"for",
"form",
"creation"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceFormValidators.php#L21-L33 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/service/HCServiceFormValidators.php | HCServiceFormValidators.generate | public function generate (stdClass $data)
{
$files = [];
$this->createFileFromTemplate ([
"destination" => $data->formValidationDestination,
"templateDestination" => __DIR__ . '/../templates/service/validator.hctpl',
"content" => [
"formValidationNameSpace" => $data->formValidationNameSpace,
"formValidationName" => $data->formValidationName,
"formRules" => $this->getRules ($data->mainModel, array_merge ($this->getAutoFill (), ['id']), false),
],
]);
$files[] = $data->formValidationDestination;
if (isset($data->mainModel->multiLanguage)) {
$this->createFileFromTemplate ([
"destination" => $data->formTranslationsValidationDestination,
"templateDestination" => __DIR__ . '/../templates/service/validator.hctpl',
"content" => [
"formValidationNameSpace" => $data->formValidationNameSpace,
"formValidationName" => $data->formTranslationsValidationName,
"formRules" => $this->getRules ($data->mainModel->multiLanguage, array_merge ($this->getAutoFill (), ['id', 'record_id', 'language_id']), true),
],
]);
$files[] = $data->formTranslationsValidationDestination;
}
return $files;
} | php | public function generate (stdClass $data)
{
$files = [];
$this->createFileFromTemplate ([
"destination" => $data->formValidationDestination,
"templateDestination" => __DIR__ . '/../templates/service/validator.hctpl',
"content" => [
"formValidationNameSpace" => $data->formValidationNameSpace,
"formValidationName" => $data->formValidationName,
"formRules" => $this->getRules ($data->mainModel, array_merge ($this->getAutoFill (), ['id']), false),
],
]);
$files[] = $data->formValidationDestination;
if (isset($data->mainModel->multiLanguage)) {
$this->createFileFromTemplate ([
"destination" => $data->formTranslationsValidationDestination,
"templateDestination" => __DIR__ . '/../templates/service/validator.hctpl',
"content" => [
"formValidationNameSpace" => $data->formValidationNameSpace,
"formValidationName" => $data->formTranslationsValidationName,
"formRules" => $this->getRules ($data->mainModel->multiLanguage, array_merge ($this->getAutoFill (), ['id', 'record_id', 'language_id']), true),
],
]);
$files[] = $data->formTranslationsValidationDestination;
}
return $files;
} | [
"public",
"function",
"generate",
"(",
"stdClass",
"$",
"data",
")",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"createFileFromTemplate",
"(",
"[",
"\"destination\"",
"=>",
"$",
"data",
"->",
"formValidationDestination",
",",
"\"templateDestination\"",
"=>",
"__DIR__",
".",
"'/../templates/service/validator.hctpl'",
",",
"\"content\"",
"=>",
"[",
"\"formValidationNameSpace\"",
"=>",
"$",
"data",
"->",
"formValidationNameSpace",
",",
"\"formValidationName\"",
"=>",
"$",
"data",
"->",
"formValidationName",
",",
"\"formRules\"",
"=>",
"$",
"this",
"->",
"getRules",
"(",
"$",
"data",
"->",
"mainModel",
",",
"array_merge",
"(",
"$",
"this",
"->",
"getAutoFill",
"(",
")",
",",
"[",
"'id'",
"]",
")",
",",
"false",
")",
",",
"]",
",",
"]",
")",
";",
"$",
"files",
"[",
"]",
"=",
"$",
"data",
"->",
"formValidationDestination",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"->",
"mainModel",
"->",
"multiLanguage",
")",
")",
"{",
"$",
"this",
"->",
"createFileFromTemplate",
"(",
"[",
"\"destination\"",
"=>",
"$",
"data",
"->",
"formTranslationsValidationDestination",
",",
"\"templateDestination\"",
"=>",
"__DIR__",
".",
"'/../templates/service/validator.hctpl'",
",",
"\"content\"",
"=>",
"[",
"\"formValidationNameSpace\"",
"=>",
"$",
"data",
"->",
"formValidationNameSpace",
",",
"\"formValidationName\"",
"=>",
"$",
"data",
"->",
"formTranslationsValidationName",
",",
"\"formRules\"",
"=>",
"$",
"this",
"->",
"getRules",
"(",
"$",
"data",
"->",
"mainModel",
"->",
"multiLanguage",
",",
"array_merge",
"(",
"$",
"this",
"->",
"getAutoFill",
"(",
")",
",",
"[",
"'id'",
",",
"'record_id'",
",",
"'language_id'",
"]",
")",
",",
"true",
")",
",",
"]",
",",
"]",
")",
";",
"$",
"files",
"[",
"]",
"=",
"$",
"data",
"->",
"formTranslationsValidationDestination",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Generating validator files
@param stdClass $data
@return array | [
"Generating",
"validator",
"files"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceFormValidators.php#L41-L73 | train |
pmdevelopment/tool-bundle | Components/Helper/ComposerHelper.php | ComposerHelper.getConsoleDir | public static function getConsoleDir()
{
$rootDir = sprintf('%s/../../../../../../../..', __DIR__);
$paths = [
'bin',
'app',
];
foreach ($paths as $path) {
$fullPath = sprintf('%s/%s', $rootDir, $path);
if (true === is_dir($fullPath) && true === file_exists(sprintf('%s/console', $fullPath))) {
return $fullPath;
}
}
return null;
} | php | public static function getConsoleDir()
{
$rootDir = sprintf('%s/../../../../../../../..', __DIR__);
$paths = [
'bin',
'app',
];
foreach ($paths as $path) {
$fullPath = sprintf('%s/%s', $rootDir, $path);
if (true === is_dir($fullPath) && true === file_exists(sprintf('%s/console', $fullPath))) {
return $fullPath;
}
}
return null;
} | [
"public",
"static",
"function",
"getConsoleDir",
"(",
")",
"{",
"$",
"rootDir",
"=",
"sprintf",
"(",
"'%s/../../../../../../../..'",
",",
"__DIR__",
")",
";",
"$",
"paths",
"=",
"[",
"'bin'",
",",
"'app'",
",",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"fullPath",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"$",
"rootDir",
",",
"$",
"path",
")",
";",
"if",
"(",
"true",
"===",
"is_dir",
"(",
"$",
"fullPath",
")",
"&&",
"true",
"===",
"file_exists",
"(",
"sprintf",
"(",
"'%s/console'",
",",
"$",
"fullPath",
")",
")",
")",
"{",
"return",
"$",
"fullPath",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get Console Dir
@return null|string | [
"Get",
"Console",
"Dir"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Components/Helper/ComposerHelper.php#L100-L118 | train |
mglaman/docker-helper | src/Machine.php | Machine.start | public static function start($name)
{
// Check if machine is running.
$status = self::status($name);
if ($status == self::STOPPED) {
// If not, try to start it.
return self::runCommand('start', [$name])->isSuccessful();
}
return $status == Machine::RUNNING;
} | php | public static function start($name)
{
// Check if machine is running.
$status = self::status($name);
if ($status == self::STOPPED) {
// If not, try to start it.
return self::runCommand('start', [$name])->isSuccessful();
}
return $status == Machine::RUNNING;
} | [
"public",
"static",
"function",
"start",
"(",
"$",
"name",
")",
"{",
"// Check if machine is running.",
"$",
"status",
"=",
"self",
"::",
"status",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"status",
"==",
"self",
"::",
"STOPPED",
")",
"{",
"// If not, try to start it.",
"return",
"self",
"::",
"runCommand",
"(",
"'start'",
",",
"[",
"$",
"name",
"]",
")",
"->",
"isSuccessful",
"(",
")",
";",
"}",
"return",
"$",
"status",
"==",
"Machine",
"::",
"RUNNING",
";",
"}"
] | Start a machine.
@param $name
@return bool
@throws \Exception | [
"Start",
"a",
"machine",
"."
] | b262a50dcdbc495487568f775a8f41da82ae2c03 | https://github.com/mglaman/docker-helper/blob/b262a50dcdbc495487568f775a8f41da82ae2c03/src/Machine.php#L45-L56 | train |
mglaman/docker-helper | src/Machine.php | Machine.getEnv | public static function getEnv($name)
{
$envs = [];
$output = self::runCommand('env', [$name]);
if (trim($output->getOutput()) == "$name is not running. Please start this with docker-machine start $name") {
throw new \Exception('Docker machine has not been started yet.');
}
$envOutput = explode(PHP_EOL, $output->getOutput());
foreach ($envOutput as $line) {
if (strpos($line, 'export') !== false) {
list(, $export) = explode(' ', $line, 2);
list($key, $value) = explode('=', $export, 2);
$envs[$key] = str_replace('"', '', $value);
}
}
return $envs;
} | php | public static function getEnv($name)
{
$envs = [];
$output = self::runCommand('env', [$name]);
if (trim($output->getOutput()) == "$name is not running. Please start this with docker-machine start $name") {
throw new \Exception('Docker machine has not been started yet.');
}
$envOutput = explode(PHP_EOL, $output->getOutput());
foreach ($envOutput as $line) {
if (strpos($line, 'export') !== false) {
list(, $export) = explode(' ', $line, 2);
list($key, $value) = explode('=', $export, 2);
$envs[$key] = str_replace('"', '', $value);
}
}
return $envs;
} | [
"public",
"static",
"function",
"getEnv",
"(",
"$",
"name",
")",
"{",
"$",
"envs",
"=",
"[",
"]",
";",
"$",
"output",
"=",
"self",
"::",
"runCommand",
"(",
"'env'",
",",
"[",
"$",
"name",
"]",
")",
";",
"if",
"(",
"trim",
"(",
"$",
"output",
"->",
"getOutput",
"(",
")",
")",
"==",
"\"$name is not running. Please start this with docker-machine start $name\"",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Docker machine has not been started yet.'",
")",
";",
"}",
"$",
"envOutput",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"output",
"->",
"getOutput",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"envOutput",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"'export'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
",",
"$",
"export",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"line",
",",
"2",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"export",
",",
"2",
")",
";",
"$",
"envs",
"[",
"$",
"key",
"]",
"=",
"str_replace",
"(",
"'\"'",
",",
"''",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"envs",
";",
"}"
] | Returns an array of the environment for the Docker client.
@param $name
@return array
@throws \Exception | [
"Returns",
"an",
"array",
"of",
"the",
"environment",
"for",
"the",
"Docker",
"client",
"."
] | b262a50dcdbc495487568f775a8f41da82ae2c03 | https://github.com/mglaman/docker-helper/blob/b262a50dcdbc495487568f775a8f41da82ae2c03/src/Machine.php#L89-L105 | train |
K-Phoen/gaufrette-extras-bundle | Form/Type/ImageType.php | ImageType.buildView | public function buildView(FormView $view, FormInterface $form, array $options)
{
$parentData = $form->getParent()->getData();
if ($parentData !== null) {
$accessor = PropertyAccess::getPropertyAccessor();
// set an "image_url" variable that will be available when rendering this field
$url = $accessor->getValue($parentData, $options['image_path']);
if ($url !== null) {
$view->vars['image_url'] = $url;
}
}
if (empty($view->vars['image_url']) && $options['no_image_placeholder'] !== null) {
$view->vars['image_url'] = $options['no_image_placeholder'];
}
$view->vars['gaufrette'] = $options['gaufrette'];
$view->vars['image_alt'] = $options['image_alt'];
$view->vars['image_width'] = $options['image_width'];
$view->vars['image_height'] = $options['image_height'];
} | php | public function buildView(FormView $view, FormInterface $form, array $options)
{
$parentData = $form->getParent()->getData();
if ($parentData !== null) {
$accessor = PropertyAccess::getPropertyAccessor();
// set an "image_url" variable that will be available when rendering this field
$url = $accessor->getValue($parentData, $options['image_path']);
if ($url !== null) {
$view->vars['image_url'] = $url;
}
}
if (empty($view->vars['image_url']) && $options['no_image_placeholder'] !== null) {
$view->vars['image_url'] = $options['no_image_placeholder'];
}
$view->vars['gaufrette'] = $options['gaufrette'];
$view->vars['image_alt'] = $options['image_alt'];
$view->vars['image_width'] = $options['image_width'];
$view->vars['image_height'] = $options['image_height'];
} | [
"public",
"function",
"buildView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"$",
"parentData",
"=",
"$",
"form",
"->",
"getParent",
"(",
")",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"parentData",
"!==",
"null",
")",
"{",
"$",
"accessor",
"=",
"PropertyAccess",
"::",
"getPropertyAccessor",
"(",
")",
";",
"// set an \"image_url\" variable that will be available when rendering this field",
"$",
"url",
"=",
"$",
"accessor",
"->",
"getValue",
"(",
"$",
"parentData",
",",
"$",
"options",
"[",
"'image_path'",
"]",
")",
";",
"if",
"(",
"$",
"url",
"!==",
"null",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'image_url'",
"]",
"=",
"$",
"url",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"view",
"->",
"vars",
"[",
"'image_url'",
"]",
")",
"&&",
"$",
"options",
"[",
"'no_image_placeholder'",
"]",
"!==",
"null",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'image_url'",
"]",
"=",
"$",
"options",
"[",
"'no_image_placeholder'",
"]",
";",
"}",
"$",
"view",
"->",
"vars",
"[",
"'gaufrette'",
"]",
"=",
"$",
"options",
"[",
"'gaufrette'",
"]",
";",
"$",
"view",
"->",
"vars",
"[",
"'image_alt'",
"]",
"=",
"$",
"options",
"[",
"'image_alt'",
"]",
";",
"$",
"view",
"->",
"vars",
"[",
"'image_width'",
"]",
"=",
"$",
"options",
"[",
"'image_width'",
"]",
";",
"$",
"view",
"->",
"vars",
"[",
"'image_height'",
"]",
"=",
"$",
"options",
"[",
"'image_height'",
"]",
";",
"}"
] | Pass the image url to the view
@param FormView $view
@param FormInterface $form
@param array $options | [
"Pass",
"the",
"image",
"url",
"to",
"the",
"view"
] | 3f05779179117d5649184164544e1f22de28d706 | https://github.com/K-Phoen/gaufrette-extras-bundle/blob/3f05779179117d5649184164544e1f22de28d706/Form/Type/ImageType.php#L46-L67 | train |
antaresproject/translations | src/Http/Controllers/Admin/SyncController.php | SyncController.index | public function index($area = null, $locale = null)
{
return $this->processor->index($this, !is_null($area) ? $area : area(), $locale);
} | php | public function index($area = null, $locale = null)
{
return $this->processor->index($this, !is_null($area) ? $area : area(), $locale);
} | [
"public",
"function",
"index",
"(",
"$",
"area",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"processor",
"->",
"index",
"(",
"$",
"this",
",",
"!",
"is_null",
"(",
"$",
"area",
")",
"?",
"$",
"area",
":",
"area",
"(",
")",
",",
"$",
"locale",
")",
";",
"}"
] | index default action
@return \Illuminate\View\View | [
"index",
"default",
"action"
] | 63097aeb97f18c5aeeef7dcf15f0c67959951685 | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Http/Controllers/Admin/SyncController.php#L57-L60 | train |
newup/core | src/Console/Commandable.php | Commandable.setApplication | public function setApplication(ApplicationContract $application = null)
{
$this->application = $application;
if ($application) {
$this->setHelperSet($application->getHelperSet());
} else {
$this->helperSet = null;
}
} | php | public function setApplication(ApplicationContract $application = null)
{
$this->application = $application;
if ($application) {
$this->setHelperSet($application->getHelperSet());
} else {
$this->helperSet = null;
}
} | [
"public",
"function",
"setApplication",
"(",
"ApplicationContract",
"$",
"application",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"application",
"=",
"$",
"application",
";",
"if",
"(",
"$",
"application",
")",
"{",
"$",
"this",
"->",
"setHelperSet",
"(",
"$",
"application",
"->",
"getHelperSet",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"helperSet",
"=",
"null",
";",
"}",
"}"
] | Sets the ApplicationContract instance.
@param ApplicationContract|null $application | [
"Sets",
"the",
"ApplicationContract",
"instance",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Console/Commandable.php#L50-L58 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Subscriber_Update | public function Subscriber_Update($user_id, $subscription_state, $division, $attributes, $allow_resubscribe = true,
$append = false) {
$data = $this->_package_subscriber_elements($subscription_state, $division, $attributes);
if (is_null($allow_resubscribe) === false) {
$data->allowResubscribe = $allow_resubscribe;
}
if (is_null($append) === false) {
$data->append = $append;
}
$ret = $this->_call_api('put', "{$this->_url}/subscribers/$user_id", $data);
return $ret;
} | php | public function Subscriber_Update($user_id, $subscription_state, $division, $attributes, $allow_resubscribe = true,
$append = false) {
$data = $this->_package_subscriber_elements($subscription_state, $division, $attributes);
if (is_null($allow_resubscribe) === false) {
$data->allowResubscribe = $allow_resubscribe;
}
if (is_null($append) === false) {
$data->append = $append;
}
$ret = $this->_call_api('put', "{$this->_url}/subscribers/$user_id", $data);
return $ret;
} | [
"public",
"function",
"Subscriber_Update",
"(",
"$",
"user_id",
",",
"$",
"subscription_state",
",",
"$",
"division",
",",
"$",
"attributes",
",",
"$",
"allow_resubscribe",
"=",
"true",
",",
"$",
"append",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_package_subscriber_elements",
"(",
"$",
"subscription_state",
",",
"$",
"division",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"allow_resubscribe",
")",
"===",
"false",
")",
"{",
"$",
"data",
"->",
"allowResubscribe",
"=",
"$",
"allow_resubscribe",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"append",
")",
"===",
"false",
")",
"{",
"$",
"data",
"->",
"append",
"=",
"$",
"append",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'put'",
",",
"\"{$this->_url}/subscribers/$user_id\"",
",",
"$",
"data",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Update an existing subscriber.
@param int $user_id The id of the subscriber to update
@param mixed $subscription_state [optional] Any of {"UNSUBSCRIBED", "SUBSCRIBED", "REFERRED", "DEAD", "REVIVED"}
@param mixed $division [optional] The division display name. If this is specified the subscriber will be
subscribed to this division.
@param array $attributes Valid attributes in the payload include any subscriber attributes defined for this
company. In order to create a subscriber, all of the attributes which comprise the
unique subscriber key for the company are required, and a valid value must be provided
for each required attribute. Attributes which are not in the unique key are optional.
NOTE: emailFormat, aka emailProgram, is an optional setting, but if it is not set, then
when editing the user in the UI it will default to TEXT.
@param bool $allow_resubscribe [optional] Flag to explicitly indicate you wish to resubscribe a subscriber. allowResubscribe
must be set to true when transitioning from an UNSUBSCRIBED to SUBSCRIBED state.
@param bool $append [optional] If true all multi-value attributes get updated like an append or merge, if false
(the default) all are replaced
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Update",
"an",
"existing",
"subscriber",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L99-L114 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Subscriber_Get_Id | public function Subscriber_Get_Id($attributes) {
try {
$ret = $this->Subscriber_Lookup($attributes);
$uri = $ret->uri;
$id = (int) substr(strrchr($uri, '/'), 1);
} catch (\Exception $e) {
if( $e->getCode() === 404){
$id = false;
} else {
throw $e;
}
}
return $id;
} | php | public function Subscriber_Get_Id($attributes) {
try {
$ret = $this->Subscriber_Lookup($attributes);
$uri = $ret->uri;
$id = (int) substr(strrchr($uri, '/'), 1);
} catch (\Exception $e) {
if( $e->getCode() === 404){
$id = false;
} else {
throw $e;
}
}
return $id;
} | [
"public",
"function",
"Subscriber_Get_Id",
"(",
"$",
"attributes",
")",
"{",
"try",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"Subscriber_Lookup",
"(",
"$",
"attributes",
")",
";",
"$",
"uri",
"=",
"$",
"ret",
"->",
"uri",
";",
"$",
"id",
"=",
"(",
"int",
")",
"substr",
"(",
"strrchr",
"(",
"$",
"uri",
",",
"'/'",
")",
",",
"1",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"===",
"404",
")",
"{",
"$",
"id",
"=",
"false",
";",
"}",
"else",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"return",
"$",
"id",
";",
"}"
] | Look up the id of an existing subscriber.
@param array $attributes An array of attribute to look up the subscriber with
@return mixed Either the subscriber id, or false if the subscriber is not found
@access public | [
"Look",
"up",
"the",
"id",
"of",
"an",
"existing",
"subscriber",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L136-L150 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Subscriber_Retrieve | public function Subscriber_Retrieve($attributes, $division) {
$ret = false;
$subscriberId = $this->Subscriber_Get_Id($attributes);
if ($subscriberId !== false) {
$ret = $this->_call_api('get', "{$this->_url}/subscribers/$subscriberId", array('division' => $division));
}
return $ret;
} | php | public function Subscriber_Retrieve($attributes, $division) {
$ret = false;
$subscriberId = $this->Subscriber_Get_Id($attributes);
if ($subscriberId !== false) {
$ret = $this->_call_api('get', "{$this->_url}/subscribers/$subscriberId", array('division' => $division));
}
return $ret;
} | [
"public",
"function",
"Subscriber_Retrieve",
"(",
"$",
"attributes",
",",
"$",
"division",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"subscriberId",
"=",
"$",
"this",
"->",
"Subscriber_Get_Id",
"(",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"subscriberId",
"!==",
"false",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/subscribers/$subscriberId\"",
",",
"array",
"(",
"'division'",
"=>",
"$",
"division",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Retrieve all information about a subscriber, including attributes, division subscription status, etc.
@param array $attributes An array of attribute to look up the subscriber with
@param mixed $division The division display name. The division from which to get the subscribers information
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Retrieve",
"all",
"information",
"about",
"a",
"subscriber",
"including",
"attributes",
"division",
"subscription",
"status",
"etc",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L174-L182 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Subscribe_And_Send | public function Subscribe_And_Send($subscription_state, $division, $attributes, $allow_resubscribe, $masterId) {
$data = new \stdClass();
$subscriber = $this->_package_subscriber_elements($subscription_state, $division, $attributes);
if (is_bool($allow_resubscribe) === true) {
$subscriber->allowResubscribe = $allow_resubscribe;
}
$data->subscriber = $subscriber;
$subscriberMessage = new \stdClass();
$subscriberMessage->masterId = $masterId;
$data->subscriberMessage = $subscriberMessage;
$ret = $this->_call_api('post', "{$this->_url}/composite/subscribeAndSend", $data);
return $ret;
} | php | public function Subscribe_And_Send($subscription_state, $division, $attributes, $allow_resubscribe, $masterId) {
$data = new \stdClass();
$subscriber = $this->_package_subscriber_elements($subscription_state, $division, $attributes);
if (is_bool($allow_resubscribe) === true) {
$subscriber->allowResubscribe = $allow_resubscribe;
}
$data->subscriber = $subscriber;
$subscriberMessage = new \stdClass();
$subscriberMessage->masterId = $masterId;
$data->subscriberMessage = $subscriberMessage;
$ret = $this->_call_api('post', "{$this->_url}/composite/subscribeAndSend", $data);
return $ret;
} | [
"public",
"function",
"Subscribe_And_Send",
"(",
"$",
"subscription_state",
",",
"$",
"division",
",",
"$",
"attributes",
",",
"$",
"allow_resubscribe",
",",
"$",
"masterId",
")",
"{",
"$",
"data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"subscriber",
"=",
"$",
"this",
"->",
"_package_subscriber_elements",
"(",
"$",
"subscription_state",
",",
"$",
"division",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"is_bool",
"(",
"$",
"allow_resubscribe",
")",
"===",
"true",
")",
"{",
"$",
"subscriber",
"->",
"allowResubscribe",
"=",
"$",
"allow_resubscribe",
";",
"}",
"$",
"data",
"->",
"subscriber",
"=",
"$",
"subscriber",
";",
"$",
"subscriberMessage",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"subscriberMessage",
"->",
"masterId",
"=",
"$",
"masterId",
";",
"$",
"data",
"->",
"subscriberMessage",
"=",
"$",
"subscriberMessage",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'post'",
",",
"\"{$this->_url}/composite/subscribeAndSend\"",
",",
"$",
"data",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Subscribe and send
@param mixed $subscription_state Any of {"UNSUBSCRIBED", "SUBSCRIBED", "REFERRED", "DEAD", "REVIVED"} or null
@param mixed $division The division display name. If specified, the subscriber will be subscribed
to this division. If null, subscriber will not be subscribed to a division.
@param array $attributes Valid values are any attributes defined in the system.
@param bool $allow_resubscribe Flag to explicitly indicate you wish to resubscribe a subscriber. allowResubscribe
must be set to true when transitioning from an UNSUBSCRIBED to SUBSCRIBED state.
@param int $masterId Must be a valid master defined for the company. The master is typically set up to be in a
disabled state.
@return
@access public | [
"Subscribe",
"and",
"send"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L198-L214 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Status_Get | public function Status_Get($guid, $nowait = true) {
if ($nowait === true) {
$ret = $this->_call_api('get', "{$this->_url}/statusNoWait/$guid", array());
} else {
do {
$ret = $this->_call_api('get', "{$this->_url}/status/$guid", array());
switch($ret->statusCode) {
case 'COMPLETED':
case 'CANCELLED':
case 'ERROR':
$wait = false;
break;
case 'INPROGRESS':
case 'SUBMITTED':
case 'PAUSED':
$wait = true;
break;
default:
$wait = false; // Unknown status, don't wait forever
}
} while ( $wait === true);
}
return $ret;
} | php | public function Status_Get($guid, $nowait = true) {
if ($nowait === true) {
$ret = $this->_call_api('get', "{$this->_url}/statusNoWait/$guid", array());
} else {
do {
$ret = $this->_call_api('get', "{$this->_url}/status/$guid", array());
switch($ret->statusCode) {
case 'COMPLETED':
case 'CANCELLED':
case 'ERROR':
$wait = false;
break;
case 'INPROGRESS':
case 'SUBMITTED':
case 'PAUSED':
$wait = true;
break;
default:
$wait = false; // Unknown status, don't wait forever
}
} while ( $wait === true);
}
return $ret;
} | [
"public",
"function",
"Status_Get",
"(",
"$",
"guid",
",",
"$",
"nowait",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"nowait",
"===",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/statusNoWait/$guid\"",
",",
"array",
"(",
")",
")",
";",
"}",
"else",
"{",
"do",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/status/$guid\"",
",",
"array",
"(",
")",
")",
";",
"switch",
"(",
"$",
"ret",
"->",
"statusCode",
")",
"{",
"case",
"'COMPLETED'",
":",
"case",
"'CANCELLED'",
":",
"case",
"'ERROR'",
":",
"$",
"wait",
"=",
"false",
";",
"break",
";",
"case",
"'INPROGRESS'",
":",
"case",
"'SUBMITTED'",
":",
"case",
"'PAUSED'",
":",
"$",
"wait",
"=",
"true",
";",
"break",
";",
"default",
":",
"$",
"wait",
"=",
"false",
";",
"// Unknown status, don't wait forever",
"}",
"}",
"while",
"(",
"$",
"wait",
"===",
"true",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get the status of an outstanding request.
@param int $guid The trackingId of the request to get status for
@param bool $nowait True if we should return without blocking. False if we should block until the request
reaches a completed state.
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Get",
"the",
"status",
"of",
"an",
"outstanding",
"request",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L225-L251 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Create | public function Master_Create($envelope, $targeting, $scheduling) {
$ret = false;
$data = $this->_package_master_elements($envelope, $targeting, $scheduling);
if ($data !== false) {
$ret = $this->_call_api('post', "{$this->_url}/masters", $data);
}
return $ret;
} | php | public function Master_Create($envelope, $targeting, $scheduling) {
$ret = false;
$data = $this->_package_master_elements($envelope, $targeting, $scheduling);
if ($data !== false) {
$ret = $this->_call_api('post', "{$this->_url}/masters", $data);
}
return $ret;
} | [
"public",
"function",
"Master_Create",
"(",
"$",
"envelope",
",",
"$",
"targeting",
",",
"$",
"scheduling",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_package_master_elements",
"(",
"$",
"envelope",
",",
"$",
"targeting",
",",
"$",
"scheduling",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"false",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'post'",
",",
"\"{$this->_url}/masters\"",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Create a new Master
@param object $envelope The envelope to use for the new master
@param mixed $targeting [optional] Optional targeting parameters to use for the new master
@param mixed $scheduling [optional] Optional scheduling parameters to use for the new master
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Create",
"a",
"new",
"Master"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L271-L280 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Update | public function Master_Update($masterId, $envelope, $targeting, $scheduling) {
$ret = false;
$data = $this->_package_master_elements($envelope, $targeting, $scheduling);
if ($data !== false) {
$ret = $this->_call_api('put', "{$this->_url}/masters/$masterId", $data);
}
return $ret;
} | php | public function Master_Update($masterId, $envelope, $targeting, $scheduling) {
$ret = false;
$data = $this->_package_master_elements($envelope, $targeting, $scheduling);
if ($data !== false) {
$ret = $this->_call_api('put', "{$this->_url}/masters/$masterId", $data);
}
return $ret;
} | [
"public",
"function",
"Master_Update",
"(",
"$",
"masterId",
",",
"$",
"envelope",
",",
"$",
"targeting",
",",
"$",
"scheduling",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_package_master_elements",
"(",
"$",
"envelope",
",",
"$",
"targeting",
",",
"$",
"scheduling",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"false",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'put'",
",",
"\"{$this->_url}/masters/$masterId\"",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Update an existing Master
@param int $masterId The id of the master to update
@param object $envelope The envelope to use for the new master
@param mixed $targeting [optional] Optional targeting parameters to use for the new master
@param mixed $scheduling [optional] Optional scheduling parameters to use for the new master
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Update",
"an",
"existing",
"Master"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L292-L301 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Get | public function Master_Get($masterId) {
$ret = false;
if (is_int($masterId) === true) {
try {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId", array());
$ret = $this->_Type_Safe_Yesmail_Master($ret);
$ret->id = (int) $masterId; // Add id to object for easy reference
} catch (\Exception $e) {
if( $e->getCode() === 404){
$ret = false;
} else {
throw $e;
}
}
}
return $ret;
} | php | public function Master_Get($masterId) {
$ret = false;
if (is_int($masterId) === true) {
try {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId", array());
$ret = $this->_Type_Safe_Yesmail_Master($ret);
$ret->id = (int) $masterId; // Add id to object for easy reference
} catch (\Exception $e) {
if( $e->getCode() === 404){
$ret = false;
} else {
throw $e;
}
}
}
return $ret;
} | [
"public",
"function",
"Master_Get",
"(",
"$",
"masterId",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_int",
"(",
"$",
"masterId",
")",
"===",
"true",
")",
"{",
"try",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/masters/$masterId\"",
",",
"array",
"(",
")",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"_Type_Safe_Yesmail_Master",
"(",
"$",
"ret",
")",
";",
"$",
"ret",
"->",
"id",
"=",
"(",
"int",
")",
"$",
"masterId",
";",
"// Add id to object for easy reference",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"===",
"404",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"}",
"else",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get an existing Master
@param int $masterId The id of the master to retrieve
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Get",
"an",
"existing",
"Master"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L337-L355 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Get_By_Name | public function Master_Get_By_Name($masterName) {
$ret = false;
if (is_string($masterName) === true) {
$pageSize = 50;
$begin = 1;
$end = $pageSize;
$filter = 'active';
$more = true;
while($more) {
$res = $this->_call_api('get', "{$this->_url}/masters", array('begin' => $begin, 'end' => $end,
'filter' => $filter));
foreach($res->masters as $result) {
if ($result->masterName === $masterName) {
$ret = $result;
break;
}
}
// NOTE: Do not change >= to === below. Yesmail API does not always return the correct number of records.
// Using >= makes us safe from their bad math.
$more = ($ret === false && count($res->masters) >= $pageSize ? true : false);
$begin += $pageSize;
$end += $pageSize;
}
}
if ($ret !== false) {
$ret = $this->Master_Get((int)$ret->masterId);
}
return $ret;
} | php | public function Master_Get_By_Name($masterName) {
$ret = false;
if (is_string($masterName) === true) {
$pageSize = 50;
$begin = 1;
$end = $pageSize;
$filter = 'active';
$more = true;
while($more) {
$res = $this->_call_api('get', "{$this->_url}/masters", array('begin' => $begin, 'end' => $end,
'filter' => $filter));
foreach($res->masters as $result) {
if ($result->masterName === $masterName) {
$ret = $result;
break;
}
}
// NOTE: Do not change >= to === below. Yesmail API does not always return the correct number of records.
// Using >= makes us safe from their bad math.
$more = ($ret === false && count($res->masters) >= $pageSize ? true : false);
$begin += $pageSize;
$end += $pageSize;
}
}
if ($ret !== false) {
$ret = $this->Master_Get((int)$ret->masterId);
}
return $ret;
} | [
"public",
"function",
"Master_Get_By_Name",
"(",
"$",
"masterName",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"masterName",
")",
"===",
"true",
")",
"{",
"$",
"pageSize",
"=",
"50",
";",
"$",
"begin",
"=",
"1",
";",
"$",
"end",
"=",
"$",
"pageSize",
";",
"$",
"filter",
"=",
"'active'",
";",
"$",
"more",
"=",
"true",
";",
"while",
"(",
"$",
"more",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/masters\"",
",",
"array",
"(",
"'begin'",
"=>",
"$",
"begin",
",",
"'end'",
"=>",
"$",
"end",
",",
"'filter'",
"=>",
"$",
"filter",
")",
")",
";",
"foreach",
"(",
"$",
"res",
"->",
"masters",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"masterName",
"===",
"$",
"masterName",
")",
"{",
"$",
"ret",
"=",
"$",
"result",
";",
"break",
";",
"}",
"}",
"// NOTE: Do not change >= to === below. Yesmail API does not always return the correct number of records. ",
"// Using >= makes us safe from their bad math. ",
"$",
"more",
"=",
"(",
"$",
"ret",
"===",
"false",
"&&",
"count",
"(",
"$",
"res",
"->",
"masters",
")",
">=",
"$",
"pageSize",
"?",
"true",
":",
"false",
")",
";",
"$",
"begin",
"+=",
"$",
"pageSize",
";",
"$",
"end",
"+=",
"$",
"pageSize",
";",
"}",
"}",
"if",
"(",
"$",
"ret",
"!==",
"false",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"Master_Get",
"(",
"(",
"int",
")",
"$",
"ret",
"->",
"masterId",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get an existing Master by name
@param int $masterName The name of the master to retrieve
@return mixed A JSON decoded PHP variable representing the HTTP response, or false if the master is not found
@access public | [
"Get",
"an",
"existing",
"Master",
"by",
"name"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L364-L397 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Post_Run_Count | public function Master_Post_Run_Count($masterId) {
$ret = false;
if (is_int($masterId) === true) {
$ret = $this->_call_api('post', "{$this->_url}/masters/$masterId/RUN/countData", array());
}
return $ret;
} | php | public function Master_Post_Run_Count($masterId) {
$ret = false;
if (is_int($masterId) === true) {
$ret = $this->_call_api('post', "{$this->_url}/masters/$masterId/RUN/countData", array());
}
return $ret;
} | [
"public",
"function",
"Master_Post_Run_Count",
"(",
"$",
"masterId",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_int",
"(",
"$",
"masterId",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'post'",
",",
"\"{$this->_url}/masters/$masterId/RUN/countData\"",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Submit the master's ID and RUN the eAPI service URL to request the the count job for a specific master
Run this before doing Master_Post_Run_Count
@param int $master_id master's id to check the count for
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Submit",
"the",
"master",
"s",
"ID",
"and",
"RUN",
"the",
"eAPI",
"service",
"URL",
"to",
"request",
"the",
"the",
"count",
"job",
"for",
"a",
"specific",
"master",
"Run",
"this",
"before",
"doing",
"Master_Post_Run_Count"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L407-L415 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Get_Count | public function Master_Get_Count($masterId) {
$ret = false;
if (is_int($masterId) === true) {
do {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId/countData", array());
// Sleep for 15 seconds so we don't keep hammering the api
sleep(15);
}
while (!$this->Status_Is_Completed($ret->status));
}
return $ret;
} | php | public function Master_Get_Count($masterId) {
$ret = false;
if (is_int($masterId) === true) {
do {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId/countData", array());
// Sleep for 15 seconds so we don't keep hammering the api
sleep(15);
}
while (!$this->Status_Is_Completed($ret->status));
}
return $ret;
} | [
"public",
"function",
"Master_Get_Count",
"(",
"$",
"masterId",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_int",
"(",
"$",
"masterId",
")",
"===",
"true",
")",
"{",
"do",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/masters/$masterId/countData\"",
",",
"array",
"(",
")",
")",
";",
"// Sleep for 15 seconds so we don't keep hammering the api",
"sleep",
"(",
"15",
")",
";",
"}",
"while",
"(",
"!",
"$",
"this",
"->",
"Status_Is_Completed",
"(",
"$",
"ret",
"->",
"status",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get the number of active subscribers based on master's id.
Run this after doing Master_Post_Run_Count
@param int $master_id master's id to check the count for
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Get",
"the",
"number",
"of",
"active",
"subscribers",
"based",
"on",
"master",
"s",
"id",
".",
"Run",
"this",
"after",
"doing",
"Master_Post_Run_Count"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L425-L438 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Assets_Get | public function Master_Assets_Get($masterId) {
$ret = false;
if (is_int($masterId) === true) {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId/assets", array());
}
return $ret;
} | php | public function Master_Assets_Get($masterId) {
$ret = false;
if (is_int($masterId) === true) {
$ret = $this->_call_api('get', "{$this->_url}/masters/$masterId/assets", array());
}
return $ret;
} | [
"public",
"function",
"Master_Assets_Get",
"(",
"$",
"masterId",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_int",
"(",
"$",
"masterId",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/masters/$masterId/assets\"",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get the assets that belong to a Master
@param int $masterId The id of the master who's assets are being requested
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Get",
"the",
"assets",
"that",
"belong",
"to",
"a",
"Master"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L484-L492 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.Master_Preview | public function Master_Preview($masterId, $contentType, $distributionList, $userId, $emails) {
$ret = false;
$contentTypes = array('HTML', 'PLAIN', 'BOTH', 'USERPREFERENCE');
if (in_array($contentType, $contentTypes) === true) {
if (is_string($distributionList) === true xor (is_int($userId) === true && is_array($emails) === true)) {
$data = new \stdClass();
$data->contentType = $contentType;
if (is_string($distributionList) === true) {
$data->distributionList = $distributionList;
} else {
$data->manualList = new \stdClass();
$data->manualList->userId = $userId;
$data->manualList->emails = $emails;
}
$ret = $this->_call_api('post', "{$this->_url}/masters/$masterId/sendPreviews?validate", $data);
}
}
return $ret;
} | php | public function Master_Preview($masterId, $contentType, $distributionList, $userId, $emails) {
$ret = false;
$contentTypes = array('HTML', 'PLAIN', 'BOTH', 'USERPREFERENCE');
if (in_array($contentType, $contentTypes) === true) {
if (is_string($distributionList) === true xor (is_int($userId) === true && is_array($emails) === true)) {
$data = new \stdClass();
$data->contentType = $contentType;
if (is_string($distributionList) === true) {
$data->distributionList = $distributionList;
} else {
$data->manualList = new \stdClass();
$data->manualList->userId = $userId;
$data->manualList->emails = $emails;
}
$ret = $this->_call_api('post', "{$this->_url}/masters/$masterId/sendPreviews?validate", $data);
}
}
return $ret;
} | [
"public",
"function",
"Master_Preview",
"(",
"$",
"masterId",
",",
"$",
"contentType",
",",
"$",
"distributionList",
",",
"$",
"userId",
",",
"$",
"emails",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"contentTypes",
"=",
"array",
"(",
"'HTML'",
",",
"'PLAIN'",
",",
"'BOTH'",
",",
"'USERPREFERENCE'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"contentType",
",",
"$",
"contentTypes",
")",
"===",
"true",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"distributionList",
")",
"===",
"true",
"xor",
"(",
"is_int",
"(",
"$",
"userId",
")",
"===",
"true",
"&&",
"is_array",
"(",
"$",
"emails",
")",
"===",
"true",
")",
")",
"{",
"$",
"data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"contentType",
"=",
"$",
"contentType",
";",
"if",
"(",
"is_string",
"(",
"$",
"distributionList",
")",
"===",
"true",
")",
"{",
"$",
"data",
"->",
"distributionList",
"=",
"$",
"distributionList",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"manualList",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"manualList",
"->",
"userId",
"=",
"$",
"userId",
";",
"$",
"data",
"->",
"manualList",
"->",
"emails",
"=",
"$",
"emails",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'post'",
",",
"\"{$this->_url}/masters/$masterId/sendPreviews?validate\"",
",",
"$",
"data",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Provides a way to preview a message by sending it to a group of email addresses, following the same semantics as
the preview functionality within the Enterprise Application.
@param int $masterId The id of the master to preview
@param string $contentType HTML - Use HTML content in the email
PLAIN - Use plain text content in the email.
BOTH - Send two emails, one using HTML content and another using the plain text version.
If the user is configured to only accept one type of email, only one will be sent.
USERPREFERENCE - Send either HTML or plain text email based on the preference
indicated by the user being targeted.
@param string $distributionList The name of a distribution list to email to. Mutually exclusive with manualList
@param int $userId A child element of manualList, templating of the email uses this user's attributes.
@param array $emails A child element of manualList, this is a space-delimited list of email addresses.
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access public | [
"Provides",
"a",
"way",
"to",
"preview",
"a",
"message",
"by",
"sending",
"it",
"to",
"a",
"group",
"of",
"email",
"addresses",
"following",
"the",
"same",
"semantics",
"as",
"the",
"preview",
"functionality",
"within",
"the",
"Enterprise",
"Application",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L545-L567 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.ListManagement_Get_Lists | public function ListManagement_Get_Lists($type) {
$ret = false;
if (is_string($type) === true) {
$type = rawurlencode($type);
$ret = $this->_call_api('get', "{$this->_url}/lists/$type", array());
}
return $ret;
} | php | public function ListManagement_Get_Lists($type) {
$ret = false;
if (is_string($type) === true) {
$type = rawurlencode($type);
$ret = $this->_call_api('get', "{$this->_url}/lists/$type", array());
}
return $ret;
} | [
"public",
"function",
"ListManagement_Get_Lists",
"(",
"$",
"type",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"type",
")",
"===",
"true",
")",
"{",
"$",
"type",
"=",
"rawurlencode",
"(",
"$",
"type",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'get'",
",",
"\"{$this->_url}/lists/$type\"",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get a list of lists given a list type
@param string $type The type of lists to get. Should be either LISTLOADLIST or DISTRIBUTIONLIST
@return mixed A JSON decoded PHP variable representing the HTTP response | [
"Get",
"a",
"list",
"of",
"lists",
"given",
"a",
"list",
"type"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L575-L584 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.ListManagement_Update_List | public function ListManagement_Update_List($modifyList) {
$ret = false;
if ($modifyList instanceof \Yesmail\YesmailListManagementModifyList && $modifyList->is_valid() === true) {
$name = rawurlencode($modifyList->name);
$type = rawurlencode($modifyList->type);
$ret = $this->_call_api('put', "{$this->_url}/lists/$type/$name", $modifyList->subscriberList);
}
return $ret;
} | php | public function ListManagement_Update_List($modifyList) {
$ret = false;
if ($modifyList instanceof \Yesmail\YesmailListManagementModifyList && $modifyList->is_valid() === true) {
$name = rawurlencode($modifyList->name);
$type = rawurlencode($modifyList->type);
$ret = $this->_call_api('put', "{$this->_url}/lists/$type/$name", $modifyList->subscriberList);
}
return $ret;
} | [
"public",
"function",
"ListManagement_Update_List",
"(",
"$",
"modifyList",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"$",
"modifyList",
"instanceof",
"\\",
"Yesmail",
"\\",
"YesmailListManagementModifyList",
"&&",
"$",
"modifyList",
"->",
"is_valid",
"(",
")",
"===",
"true",
")",
"{",
"$",
"name",
"=",
"rawurlencode",
"(",
"$",
"modifyList",
"->",
"name",
")",
";",
"$",
"type",
"=",
"rawurlencode",
"(",
"$",
"modifyList",
"->",
"type",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'put'",
",",
"\"{$this->_url}/lists/$type/$name\"",
",",
"$",
"modifyList",
"->",
"subscriberList",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Either remove or append the subscribers identified in the payload. For subscriberIds and emails that are
submitted as part of a request that cannot be mapped back to existing subscriber data are ignored and a total
count of the number added users is returned as part of the status message.
@param object $modifyList
@return mixed A JSON decoded PHP variable representing the HTTP response | [
"Either",
"remove",
"or",
"append",
"the",
"subscribers",
"identified",
"in",
"the",
"payload",
".",
"For",
"subscriberIds",
"and",
"emails",
"that",
"are",
"submitted",
"as",
"part",
"of",
"a",
"request",
"that",
"cannot",
"be",
"mapped",
"back",
"to",
"existing",
"subscriber",
"data",
"are",
"ignored",
"and",
"a",
"total",
"count",
"of",
"the",
"number",
"added",
"users",
"is",
"returned",
"as",
"part",
"of",
"the",
"status",
"message",
"."
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L614-L624 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail.ListManagement_Create_List | public function ListManagement_Create_List($modifyList) {
$ret = false;
if ($modifyList instanceof \Yesmail\YesmailListManagementModifyList && $modifyList->is_valid() === true) {
$ret = $this->_call_api('post', "{$this->_url}/lists/{$modifyList->type}", $modifyList);
}
return $ret;
} | php | public function ListManagement_Create_List($modifyList) {
$ret = false;
if ($modifyList instanceof \Yesmail\YesmailListManagementModifyList && $modifyList->is_valid() === true) {
$ret = $this->_call_api('post', "{$this->_url}/lists/{$modifyList->type}", $modifyList);
}
return $ret;
} | [
"public",
"function",
"ListManagement_Create_List",
"(",
"$",
"modifyList",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"$",
"modifyList",
"instanceof",
"\\",
"Yesmail",
"\\",
"YesmailListManagementModifyList",
"&&",
"$",
"modifyList",
"->",
"is_valid",
"(",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_call_api",
"(",
"'post'",
",",
"\"{$this->_url}/lists/{$modifyList->type}\"",
",",
"$",
"modifyList",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Create a new list of the given type
@param object $modifyList
@return mixed A JSON decoded PHP variable representing the HTTP response | [
"Create",
"a",
"new",
"list",
"of",
"the",
"given",
"type"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L632-L640 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail._package_master_elements | protected function _package_master_elements($envelope, $targeting, $scheduling) {
$ret = false;
if ($envelope instanceof \Yesmail\YesmailMasterEnvelope && $envelope->is_valid() === true) {
$ret = new \stdClass();
$ret->envelope = $envelope;
if ($targeting instanceof \Yesmail\YesmailMasterTargeting && $targeting->is_valid() === true) {
$ret->targeting = $targeting;
}
if ($scheduling instanceof \Yesmail\YesmailMasterScheduling && $scheduling->is_valid() === true) {
$ret->scheduling = $scheduling;
}
}
return $ret;
} | php | protected function _package_master_elements($envelope, $targeting, $scheduling) {
$ret = false;
if ($envelope instanceof \Yesmail\YesmailMasterEnvelope && $envelope->is_valid() === true) {
$ret = new \stdClass();
$ret->envelope = $envelope;
if ($targeting instanceof \Yesmail\YesmailMasterTargeting && $targeting->is_valid() === true) {
$ret->targeting = $targeting;
}
if ($scheduling instanceof \Yesmail\YesmailMasterScheduling && $scheduling->is_valid() === true) {
$ret->scheduling = $scheduling;
}
}
return $ret;
} | [
"protected",
"function",
"_package_master_elements",
"(",
"$",
"envelope",
",",
"$",
"targeting",
",",
"$",
"scheduling",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"$",
"envelope",
"instanceof",
"\\",
"Yesmail",
"\\",
"YesmailMasterEnvelope",
"&&",
"$",
"envelope",
"->",
"is_valid",
"(",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"ret",
"->",
"envelope",
"=",
"$",
"envelope",
";",
"if",
"(",
"$",
"targeting",
"instanceof",
"\\",
"Yesmail",
"\\",
"YesmailMasterTargeting",
"&&",
"$",
"targeting",
"->",
"is_valid",
"(",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"->",
"targeting",
"=",
"$",
"targeting",
";",
"}",
"if",
"(",
"$",
"scheduling",
"instanceof",
"\\",
"Yesmail",
"\\",
"YesmailMasterScheduling",
"&&",
"$",
"scheduling",
"->",
"is_valid",
"(",
")",
"===",
"true",
")",
"{",
"$",
"ret",
"->",
"scheduling",
"=",
"$",
"scheduling",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Package a Master's envelope, targeting, and scheduling for sending in a request
@param object $envelope The Master's envelope
@param mixed $targeting [optional] Optional targeting parameters for the new master
@param mixed $scheduling [optional] Optional scheduling parameters for the new master
@return mixed Either a stdClass object containing the Master's elements, or false upon failure | [
"Package",
"a",
"Master",
"s",
"envelope",
"targeting",
"and",
"scheduling",
"for",
"sending",
"in",
"a",
"request"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L681-L698 | train |
PopSugar/php-yesmail-api | src/Yesmail/Yesmail.php | Yesmail._call_api | protected function _call_api( $method, $url, $params ) {
$raw_response = $this->_client->$method($url, $params);
$info = $this->_client->get_info();
if ($info['http_code'] != null) {
switch ($info["http_code"]) {
case 200:
case 202:
$response = json_decode($raw_response);
break;
/*
case 400:
throw new MalformedRequestException();
case 401:
throw new AuthenticationFailedException();
case 404:
throw new ResourceNotFoundException();
case 500:
throw new InternalServerErrorException();
case 503:
throw new ServiceTemporarilyUnavailableException();
*/
default:
throw new \Exception("Error: {$info['http_code']}", $info['http_code']);
}
}
return $response;
} | php | protected function _call_api( $method, $url, $params ) {
$raw_response = $this->_client->$method($url, $params);
$info = $this->_client->get_info();
if ($info['http_code'] != null) {
switch ($info["http_code"]) {
case 200:
case 202:
$response = json_decode($raw_response);
break;
/*
case 400:
throw new MalformedRequestException();
case 401:
throw new AuthenticationFailedException();
case 404:
throw new ResourceNotFoundException();
case 500:
throw new InternalServerErrorException();
case 503:
throw new ServiceTemporarilyUnavailableException();
*/
default:
throw new \Exception("Error: {$info['http_code']}", $info['http_code']);
}
}
return $response;
} | [
"protected",
"function",
"_call_api",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
"{",
"$",
"raw_response",
"=",
"$",
"this",
"->",
"_client",
"->",
"$",
"method",
"(",
"$",
"url",
",",
"$",
"params",
")",
";",
"$",
"info",
"=",
"$",
"this",
"->",
"_client",
"->",
"get_info",
"(",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
"!=",
"null",
")",
"{",
"switch",
"(",
"$",
"info",
"[",
"\"http_code\"",
"]",
")",
"{",
"case",
"200",
":",
"case",
"202",
":",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"raw_response",
")",
";",
"break",
";",
"/*\n case 400:\n throw new MalformedRequestException();\n case 401:\n throw new AuthenticationFailedException();\n case 404:\n throw new ResourceNotFoundException();\n case 500:\n throw new InternalServerErrorException();\n case 503:\n throw new ServiceTemporarilyUnavailableException();\n */",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error: {$info['http_code']}\"",
",",
"$",
"info",
"[",
"'http_code'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Make a call to the Yesmail API
@param string $method Any of {'get', 'put', 'post', 'delete'}
@param string $url The url of the API call
@param mixed $params An object or array of parameters to submit in the request
@return mixed A JSON decoded PHP variable representing the HTTP response.
@access protected
@throws Exception | [
"Make",
"a",
"call",
"to",
"the",
"Yesmail",
"API"
] | 42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c | https://github.com/PopSugar/php-yesmail-api/blob/42c20a3ded1d8f2177c792cd3aa44bcdfdcb239c/src/Yesmail/Yesmail.php#L735-L762 | train |
pmdevelopment/tool-bundle | Twig/TimeExtension.php | TimeExtension.getSecondsAsText | public function getSecondsAsText($seconds, $decimals = 2, $decPoint = ',', $thousandsSep = '.')
{
$seconds = floatval($seconds);
if (60 > $seconds) {
return sprintf('%ss', number_format($seconds, $decimals, $decPoint, $thousandsSep));
}
$minutes = floor($seconds / 60);
if (3600 > $seconds) {
return sprintf('%sm %ss', $minutes, number_format($seconds - ($minutes * 60), 0, $decPoint, $thousandsSep));
}
$hours = floor($minutes / 60);
$minutes = $minutes - ($hours * 60);
return sprintf('%sh %sm %ss', $hours, $minutes, number_format($seconds - ($minutes * 60) - ($hours * 3600), 0, $decPoint, $thousandsSep));
} | php | public function getSecondsAsText($seconds, $decimals = 2, $decPoint = ',', $thousandsSep = '.')
{
$seconds = floatval($seconds);
if (60 > $seconds) {
return sprintf('%ss', number_format($seconds, $decimals, $decPoint, $thousandsSep));
}
$minutes = floor($seconds / 60);
if (3600 > $seconds) {
return sprintf('%sm %ss', $minutes, number_format($seconds - ($minutes * 60), 0, $decPoint, $thousandsSep));
}
$hours = floor($minutes / 60);
$minutes = $minutes - ($hours * 60);
return sprintf('%sh %sm %ss', $hours, $minutes, number_format($seconds - ($minutes * 60) - ($hours * 3600), 0, $decPoint, $thousandsSep));
} | [
"public",
"function",
"getSecondsAsText",
"(",
"$",
"seconds",
",",
"$",
"decimals",
"=",
"2",
",",
"$",
"decPoint",
"=",
"','",
",",
"$",
"thousandsSep",
"=",
"'.'",
")",
"{",
"$",
"seconds",
"=",
"floatval",
"(",
"$",
"seconds",
")",
";",
"if",
"(",
"60",
">",
"$",
"seconds",
")",
"{",
"return",
"sprintf",
"(",
"'%ss'",
",",
"number_format",
"(",
"$",
"seconds",
",",
"$",
"decimals",
",",
"$",
"decPoint",
",",
"$",
"thousandsSep",
")",
")",
";",
"}",
"$",
"minutes",
"=",
"floor",
"(",
"$",
"seconds",
"/",
"60",
")",
";",
"if",
"(",
"3600",
">",
"$",
"seconds",
")",
"{",
"return",
"sprintf",
"(",
"'%sm %ss'",
",",
"$",
"minutes",
",",
"number_format",
"(",
"$",
"seconds",
"-",
"(",
"$",
"minutes",
"*",
"60",
")",
",",
"0",
",",
"$",
"decPoint",
",",
"$",
"thousandsSep",
")",
")",
";",
"}",
"$",
"hours",
"=",
"floor",
"(",
"$",
"minutes",
"/",
"60",
")",
";",
"$",
"minutes",
"=",
"$",
"minutes",
"-",
"(",
"$",
"hours",
"*",
"60",
")",
";",
"return",
"sprintf",
"(",
"'%sh %sm %ss'",
",",
"$",
"hours",
",",
"$",
"minutes",
",",
"number_format",
"(",
"$",
"seconds",
"-",
"(",
"$",
"minutes",
"*",
"60",
")",
"-",
"(",
"$",
"hours",
"*",
"3600",
")",
",",
"0",
",",
"$",
"decPoint",
",",
"$",
"thousandsSep",
")",
")",
";",
"}"
] | Get Seconds As Text
@param float $seconds
@param int $decimals
@param string $decPoint
@param string $thousandsSep
@return string | [
"Get",
"Seconds",
"As",
"Text"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Twig/TimeExtension.php#L82-L100 | train |
pmdevelopment/tool-bundle | Twig/TimeExtension.php | TimeExtension.getSecondsAsTextExtended | public function getSecondsAsTextExtended($seconds)
{
$seconds = floatval($seconds);
$result = [];
$steps = [
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1,
];
foreach ($steps as $stepName => $stepDivider) {
$stepCount = floor($seconds / $stepDivider);
if (0 < $stepCount) {
$result[] = sprintf('%d %s', $stepCount, $this->getTranslator()->transChoice($stepName, $stepCount));
$seconds = $seconds - ($stepCount * $stepDivider);
}
}
return implode(' ', $result);
} | php | public function getSecondsAsTextExtended($seconds)
{
$seconds = floatval($seconds);
$result = [];
$steps = [
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1,
];
foreach ($steps as $stepName => $stepDivider) {
$stepCount = floor($seconds / $stepDivider);
if (0 < $stepCount) {
$result[] = sprintf('%d %s', $stepCount, $this->getTranslator()->transChoice($stepName, $stepCount));
$seconds = $seconds - ($stepCount * $stepDivider);
}
}
return implode(' ', $result);
} | [
"public",
"function",
"getSecondsAsTextExtended",
"(",
"$",
"seconds",
")",
"{",
"$",
"seconds",
"=",
"floatval",
"(",
"$",
"seconds",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"steps",
"=",
"[",
"'days'",
"=>",
"86400",
",",
"'hours'",
"=>",
"3600",
",",
"'minutes'",
"=>",
"60",
",",
"'seconds'",
"=>",
"1",
",",
"]",
";",
"foreach",
"(",
"$",
"steps",
"as",
"$",
"stepName",
"=>",
"$",
"stepDivider",
")",
"{",
"$",
"stepCount",
"=",
"floor",
"(",
"$",
"seconds",
"/",
"$",
"stepDivider",
")",
";",
"if",
"(",
"0",
"<",
"$",
"stepCount",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"sprintf",
"(",
"'%d %s'",
",",
"$",
"stepCount",
",",
"$",
"this",
"->",
"getTranslator",
"(",
")",
"->",
"transChoice",
"(",
"$",
"stepName",
",",
"$",
"stepCount",
")",
")",
";",
"$",
"seconds",
"=",
"$",
"seconds",
"-",
"(",
"$",
"stepCount",
"*",
"$",
"stepDivider",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"result",
")",
";",
"}"
] | Get Seconds As Text Extended
@param float $seconds
@return string | [
"Get",
"Seconds",
"As",
"Text",
"Extended"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Twig/TimeExtension.php#L109-L130 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.validate | protected function validate()
{
if ($this->method === HttpMethods::POST && empty($this->data)) {
throw new Exceptions\WebException(
"Using method POST without data."
);
}
} | php | protected function validate()
{
if ($this->method === HttpMethods::POST && empty($this->data)) {
throw new Exceptions\WebException(
"Using method POST without data."
);
}
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"HttpMethods",
"::",
"POST",
"&&",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"WebException",
"(",
"\"Using method POST without data.\"",
")",
";",
"}",
"}"
] | Validates the request values for correctness
@throws Exceptions\WebException When an incorrect value is found | [
"Validates",
"the",
"request",
"values",
"for",
"correctness"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L297-L304 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.prepareCurl | protected function prepareCurl()
{
$this->curl = curl_init();
$this->complete = Complete::factory(function() {
if ($this->curl) {
curl_close($this->curl);
}
$this->curl = null;
$this->complete = null;
});
foreach(self::$curlOptions as $option => $value) {
curl_setopt($this->curl, $option, $value);
}
if ($this->method === HttpMethods::POST) {
curl_setopt($this->curl, CURLOPT_POST, true);
}
if (!empty($this->auth)) {
curl_setopt($this->curl, CURLOPT_USERPWD, sprintf(
"%s:%s",
$this->auth["user"],
$this->auth["pass"]
));
}
} | php | protected function prepareCurl()
{
$this->curl = curl_init();
$this->complete = Complete::factory(function() {
if ($this->curl) {
curl_close($this->curl);
}
$this->curl = null;
$this->complete = null;
});
foreach(self::$curlOptions as $option => $value) {
curl_setopt($this->curl, $option, $value);
}
if ($this->method === HttpMethods::POST) {
curl_setopt($this->curl, CURLOPT_POST, true);
}
if (!empty($this->auth)) {
curl_setopt($this->curl, CURLOPT_USERPWD, sprintf(
"%s:%s",
$this->auth["user"],
$this->auth["pass"]
));
}
} | [
"protected",
"function",
"prepareCurl",
"(",
")",
"{",
"$",
"this",
"->",
"curl",
"=",
"curl_init",
"(",
")",
";",
"$",
"this",
"->",
"complete",
"=",
"Complete",
"::",
"factory",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"curl",
")",
"{",
"curl_close",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"}",
"$",
"this",
"->",
"curl",
"=",
"null",
";",
"$",
"this",
"->",
"complete",
"=",
"null",
";",
"}",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"curlOptions",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"$",
"option",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"HttpMethods",
"::",
"POST",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"auth",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_USERPWD",
",",
"sprintf",
"(",
"\"%s:%s\"",
",",
"$",
"this",
"->",
"auth",
"[",
"\"user\"",
"]",
",",
"$",
"this",
"->",
"auth",
"[",
"\"pass\"",
"]",
")",
")",
";",
"}",
"}"
] | Initializes the curl resource | [
"Initializes",
"the",
"curl",
"resource"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L309-L333 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.prepareData | protected function prepareData()
{
if (!empty($this->data)) {
if ($this->method === HttpMethods::GET) {
$this->url = Utils::appendUrlQuery($this->url, $this->data);
} else if ($this->method === HttpMethods::POST) {
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->data);
}
}
} | php | protected function prepareData()
{
if (!empty($this->data)) {
if ($this->method === HttpMethods::GET) {
$this->url = Utils::appendUrlQuery($this->url, $this->data);
} else if ($this->method === HttpMethods::POST) {
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->data);
}
}
} | [
"protected",
"function",
"prepareData",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"HttpMethods",
"::",
"GET",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"Utils",
"::",
"appendUrlQuery",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"data",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"HttpMethods",
"::",
"POST",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"data",
")",
";",
"}",
"}",
"}"
] | Adds the data value to the curl request | [
"Adds",
"the",
"data",
"value",
"to",
"the",
"curl",
"request"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L338-L347 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.prepareHeaders | protected function prepareHeaders()
{
// Need to let curl set the content type when posting. Our own content type
// value would overwrite that.
if ($this->method === HttpMethods::POST && !empty($this->headers["Content-Type"])) {
unset($this->headers["Content-Type"]);
}
curl_setopt($this->curl, CURLOPT_USERAGENT, $this->userAgent);
if (!empty($this->headers)) {
$headers = $this->getHeadersBuilder()->normalize($this->headers);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
}
} | php | protected function prepareHeaders()
{
// Need to let curl set the content type when posting. Our own content type
// value would overwrite that.
if ($this->method === HttpMethods::POST && !empty($this->headers["Content-Type"])) {
unset($this->headers["Content-Type"]);
}
curl_setopt($this->curl, CURLOPT_USERAGENT, $this->userAgent);
if (!empty($this->headers)) {
$headers = $this->getHeadersBuilder()->normalize($this->headers);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
}
} | [
"protected",
"function",
"prepareHeaders",
"(",
")",
"{",
"// Need to let curl set the content type when posting. Our own content type",
"// value would overwrite that.",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"HttpMethods",
"::",
"POST",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Type\"",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Type\"",
"]",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_USERAGENT",
",",
"$",
"this",
"->",
"userAgent",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"headers",
")",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"getHeadersBuilder",
"(",
")",
"->",
"normalize",
"(",
"$",
"this",
"->",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}",
"}"
] | Adds the set headers to the curl request | [
"Adds",
"the",
"set",
"headers",
"to",
"the",
"curl",
"request"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L352-L365 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.exec | protected function exec()
{
curl_setopt($this->curl, CURLOPT_URL, $this->url);
$response_text = curl_exec($this->curl);
$this->info = curl_getinfo($this->curl);
$this->logInformation();
if (false === $response_text) {
throw new Exceptions\WebException(
curl_error($this->curl),
curl_errno($this->curl)
);
}
/** @var $options string */
$this->response["info"] = $this->info;
$this->response["code"] = $this->response["info"]["http_code"];
$this->response["body"] = substr(
$response_text,
$this->response["info"]["header_size"]
);
$this->response["headers"] = substr(
$response_text,
0,
$this->response["info"]["header_size"]
);
$this->response["headers"] = $this->getHeadersParser()->parse(
$this->response["headers"],
$options
);
$this->response["version"] = explode(" ", $options, 3)[0];
} | php | protected function exec()
{
curl_setopt($this->curl, CURLOPT_URL, $this->url);
$response_text = curl_exec($this->curl);
$this->info = curl_getinfo($this->curl);
$this->logInformation();
if (false === $response_text) {
throw new Exceptions\WebException(
curl_error($this->curl),
curl_errno($this->curl)
);
}
/** @var $options string */
$this->response["info"] = $this->info;
$this->response["code"] = $this->response["info"]["http_code"];
$this->response["body"] = substr(
$response_text,
$this->response["info"]["header_size"]
);
$this->response["headers"] = substr(
$response_text,
0,
$this->response["info"]["header_size"]
);
$this->response["headers"] = $this->getHeadersParser()->parse(
$this->response["headers"],
$options
);
$this->response["version"] = explode(" ", $options, 3)[0];
} | [
"protected",
"function",
"exec",
"(",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_URL",
",",
"$",
"this",
"->",
"url",
")",
";",
"$",
"response_text",
"=",
"curl_exec",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"$",
"this",
"->",
"info",
"=",
"curl_getinfo",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"$",
"this",
"->",
"logInformation",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"response_text",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"WebException",
"(",
"curl_error",
"(",
"$",
"this",
"->",
"curl",
")",
",",
"curl_errno",
"(",
"$",
"this",
"->",
"curl",
")",
")",
";",
"}",
"/** @var $options string */",
"$",
"this",
"->",
"response",
"[",
"\"info\"",
"]",
"=",
"$",
"this",
"->",
"info",
";",
"$",
"this",
"->",
"response",
"[",
"\"code\"",
"]",
"=",
"$",
"this",
"->",
"response",
"[",
"\"info\"",
"]",
"[",
"\"http_code\"",
"]",
";",
"$",
"this",
"->",
"response",
"[",
"\"body\"",
"]",
"=",
"substr",
"(",
"$",
"response_text",
",",
"$",
"this",
"->",
"response",
"[",
"\"info\"",
"]",
"[",
"\"header_size\"",
"]",
")",
";",
"$",
"this",
"->",
"response",
"[",
"\"headers\"",
"]",
"=",
"substr",
"(",
"$",
"response_text",
",",
"0",
",",
"$",
"this",
"->",
"response",
"[",
"\"info\"",
"]",
"[",
"\"header_size\"",
"]",
")",
";",
"$",
"this",
"->",
"response",
"[",
"\"headers\"",
"]",
"=",
"$",
"this",
"->",
"getHeadersParser",
"(",
")",
"->",
"parse",
"(",
"$",
"this",
"->",
"response",
"[",
"\"headers\"",
"]",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"response",
"[",
"\"version\"",
"]",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"options",
",",
"3",
")",
"[",
"0",
"]",
";",
"}"
] | Executes the configured request | [
"Executes",
"the",
"configured",
"request"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L370-L401 | train |
headzoo/web-tools | src/Headzoo/Web/Tools/WebClient.php | WebClient.logInformation | protected function logInformation()
{
if ($this->logger) {
$level = $this->info["http_code"] > 0 && $this->info["http_code"] < 400
? LogLevel::INFO
: LogLevel::ERROR;
$this->info["method"] = $this->method;
$this->logger->log($level, $this->logFormat, $this->info);
}
} | php | protected function logInformation()
{
if ($this->logger) {
$level = $this->info["http_code"] > 0 && $this->info["http_code"] < 400
? LogLevel::INFO
: LogLevel::ERROR;
$this->info["method"] = $this->method;
$this->logger->log($level, $this->logFormat, $this->info);
}
} | [
"protected",
"function",
"logInformation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"info",
"[",
"\"http_code\"",
"]",
">",
"0",
"&&",
"$",
"this",
"->",
"info",
"[",
"\"http_code\"",
"]",
"<",
"400",
"?",
"LogLevel",
"::",
"INFO",
":",
"LogLevel",
"::",
"ERROR",
";",
"$",
"this",
"->",
"info",
"[",
"\"method\"",
"]",
"=",
"$",
"this",
"->",
"method",
";",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"this",
"->",
"logFormat",
",",
"$",
"this",
"->",
"info",
")",
";",
"}",
"}"
] | Logs request information when logging is enabled | [
"Logs",
"request",
"information",
"when",
"logging",
"is",
"enabled"
] | 305ce78029b86fa1fadaf8341d8fc737c84eab87 | https://github.com/headzoo/web-tools/blob/305ce78029b86fa1fadaf8341d8fc737c84eab87/src/Headzoo/Web/Tools/WebClient.php#L406-L415 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.Allow | public function Allow ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
$this->allowIPs[$formatted[0]] = $formatted[1];
return TRUE;
} | php | public function Allow ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
$this->allowIPs[$formatted[0]] = $formatted[1];
return TRUE;
} | [
"public",
"function",
"Allow",
"(",
"$",
"range",
")",
"{",
"$",
"formatted",
"=",
"$",
"this",
"->",
"formatRange",
"(",
"$",
"range",
")",
";",
"if",
"(",
"!",
"$",
"formatted",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"allowIPs",
"[",
"$",
"formatted",
"[",
"0",
"]",
"]",
"=",
"$",
"formatted",
"[",
"1",
"]",
";",
"return",
"TRUE",
";",
"}"
] | Add an IP address range to allow
Return FALSE is the IP range is invalid
@see formatRange ()
@param string $range IP range to allow
@return boolean | [
"Add",
"an",
"IP",
"address",
"range",
"to",
"allow",
"Return",
"FALSE",
"is",
"the",
"IP",
"range",
"is",
"invalid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L37-L50 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.Deny | public function Deny ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
$this->denyIPs[$formatted[0]] = $formatted[1];
return TRUE;
} | php | public function Deny ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
$this->denyIPs[$formatted[0]] = $formatted[1];
return TRUE;
} | [
"public",
"function",
"Deny",
"(",
"$",
"range",
")",
"{",
"$",
"formatted",
"=",
"$",
"this",
"->",
"formatRange",
"(",
"$",
"range",
")",
";",
"if",
"(",
"!",
"$",
"formatted",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"denyIPs",
"[",
"$",
"formatted",
"[",
"0",
"]",
"]",
"=",
"$",
"formatted",
"[",
"1",
"]",
";",
"return",
"TRUE",
";",
"}"
] | Add an IP address range to deny
Return FALSE is the IP range is invalid
@see formatRange ()
@param string $range IP range to deny
@return boolean | [
"Add",
"an",
"IP",
"address",
"range",
"to",
"deny",
"Return",
"FALSE",
"is",
"the",
"IP",
"range",
"is",
"invalid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L61-L74 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.removeAllowed | public function removeAllowed ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
unset ($this->allowIPs[$formatted[0]]);
return TRUE;
} | php | public function removeAllowed ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
unset ($this->allowIPs[$formatted[0]]);
return TRUE;
} | [
"public",
"function",
"removeAllowed",
"(",
"$",
"range",
")",
"{",
"$",
"formatted",
"=",
"$",
"this",
"->",
"formatRange",
"(",
"$",
"range",
")",
";",
"if",
"(",
"!",
"$",
"formatted",
")",
"{",
"return",
"FALSE",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"allowIPs",
"[",
"$",
"formatted",
"[",
"0",
"]",
"]",
")",
";",
"return",
"TRUE",
";",
"}"
] | Remove an allowed IP address range
Return FALSE is the IP range is invalid
@param string $range IP range to remove
@return boolean | [
"Remove",
"an",
"allowed",
"IP",
"address",
"range",
"Return",
"FALSE",
"is",
"the",
"IP",
"range",
"is",
"invalid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L84-L97 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.removeDenied | public function removeDenied ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
unset ($this->denyIPs[$formatted[0]]);
return TRUE;
} | php | public function removeDenied ($range)
{
$formatted = $this->formatRange ($range);
if (!$formatted)
{
return FALSE;
}
unset ($this->denyIPs[$formatted[0]]);
return TRUE;
} | [
"public",
"function",
"removeDenied",
"(",
"$",
"range",
")",
"{",
"$",
"formatted",
"=",
"$",
"this",
"->",
"formatRange",
"(",
"$",
"range",
")",
";",
"if",
"(",
"!",
"$",
"formatted",
")",
"{",
"return",
"FALSE",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"denyIPs",
"[",
"$",
"formatted",
"[",
"0",
"]",
"]",
")",
";",
"return",
"TRUE",
";",
"}"
] | Remove a denied IP address range
Return FALSE is the IP range is invalid
@param string $range IP range to remove
@return boolean | [
"Remove",
"a",
"denied",
"IP",
"address",
"range",
"Return",
"FALSE",
"is",
"the",
"IP",
"range",
"is",
"invalid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L107-L120 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.formatRange | public function formatRange ($range)
{
// CIDR
if (strpos ($range, '/') !== FALSE)
{
// Get the IP and netmask
list ($ip, $netmask) = explode ('/', $range, 2);
// Split decimal and pad to ensure we have 4 octets
$ip = implode ('.', array_pad (explode ('.', $ip), 4, 0));
// If the netmask is a dotted decimal format
if (strpos ($netmask, '.') !== FALSE)
{
// Convert wildcards
$netmask = str_replace ('*', '0', $netmask);
// Convert to long
$ipLong = ip2long ($ip);
$netmaskLong = ip2long ($netmask);
// Check IPs are valid
if ($ipLong === FALSE || $netmaskLong === FALSE)
{
return FALSE;
}
// Return range
return array (
$ip . '/' . $netmask,
array (
(float)sprintf ("%u", $ipLong),
(float)sprintf ("%u", $netmaskLong)
)
);
}
// Else netmask is a CIDR block
else
{
// Convert netmask block to bit-mask
// Bitwise NOT on wildcard
$wildcard = pow (2, (32 - (int)$netmask)) - 1;
$netmaskDec = ~$wildcard;
// Return range
return array (
$ip . '/' . $netmask,
array (
(float)sprintf ("%u", ip2long ($ip)),
$netmaskDec
)
);
}
// Return TRUE
return TRUE;
}
// Wildcard or Start-End
elseif (strpos ($range, '*') !== FALSE || strpos ($range, '-') !== FALSE)
{
// Wildcard
if (strpos ($range, '*') !== FALSE)
{
$lower = str_replace ('*', '0', $range);
$upper = str_replace ('*', '255', $range);
$name = $lower . '-' . $upper;
}
// Start-End
else
{
list ($lower, $upper) = explode ('-', $range, 2);
$name = $range;
}
// Convert to long
$lowerLong = ip2long ($lower);
$upperLong = ip2long ($upper);
// Check IPs are valid
if ($lowerLong === FALSE || $upperLong === FALSE)
{
return FALSE;
}
// Return range
return array (
$name,
array (
(float)sprintf ("%u", $lowerLong),
(float)sprintf ("%u", $upperLong)
)
);
}
// Else a single IP
if (strpos ($range, '.') !== FALSE)
{
// Return range
return array (
$range,
(float)sprintf ("%u", ip2long ($range))
);
}
// No range to return
return FALSE;
} | php | public function formatRange ($range)
{
// CIDR
if (strpos ($range, '/') !== FALSE)
{
// Get the IP and netmask
list ($ip, $netmask) = explode ('/', $range, 2);
// Split decimal and pad to ensure we have 4 octets
$ip = implode ('.', array_pad (explode ('.', $ip), 4, 0));
// If the netmask is a dotted decimal format
if (strpos ($netmask, '.') !== FALSE)
{
// Convert wildcards
$netmask = str_replace ('*', '0', $netmask);
// Convert to long
$ipLong = ip2long ($ip);
$netmaskLong = ip2long ($netmask);
// Check IPs are valid
if ($ipLong === FALSE || $netmaskLong === FALSE)
{
return FALSE;
}
// Return range
return array (
$ip . '/' . $netmask,
array (
(float)sprintf ("%u", $ipLong),
(float)sprintf ("%u", $netmaskLong)
)
);
}
// Else netmask is a CIDR block
else
{
// Convert netmask block to bit-mask
// Bitwise NOT on wildcard
$wildcard = pow (2, (32 - (int)$netmask)) - 1;
$netmaskDec = ~$wildcard;
// Return range
return array (
$ip . '/' . $netmask,
array (
(float)sprintf ("%u", ip2long ($ip)),
$netmaskDec
)
);
}
// Return TRUE
return TRUE;
}
// Wildcard or Start-End
elseif (strpos ($range, '*') !== FALSE || strpos ($range, '-') !== FALSE)
{
// Wildcard
if (strpos ($range, '*') !== FALSE)
{
$lower = str_replace ('*', '0', $range);
$upper = str_replace ('*', '255', $range);
$name = $lower . '-' . $upper;
}
// Start-End
else
{
list ($lower, $upper) = explode ('-', $range, 2);
$name = $range;
}
// Convert to long
$lowerLong = ip2long ($lower);
$upperLong = ip2long ($upper);
// Check IPs are valid
if ($lowerLong === FALSE || $upperLong === FALSE)
{
return FALSE;
}
// Return range
return array (
$name,
array (
(float)sprintf ("%u", $lowerLong),
(float)sprintf ("%u", $upperLong)
)
);
}
// Else a single IP
if (strpos ($range, '.') !== FALSE)
{
// Return range
return array (
$range,
(float)sprintf ("%u", ip2long ($range))
);
}
// No range to return
return FALSE;
} | [
"public",
"function",
"formatRange",
"(",
"$",
"range",
")",
"{",
"// CIDR",
"if",
"(",
"strpos",
"(",
"$",
"range",
",",
"'/'",
")",
"!==",
"FALSE",
")",
"{",
"// Get the IP and netmask",
"list",
"(",
"$",
"ip",
",",
"$",
"netmask",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"range",
",",
"2",
")",
";",
"// Split decimal and pad to ensure we have 4 octets",
"$",
"ip",
"=",
"implode",
"(",
"'.'",
",",
"array_pad",
"(",
"explode",
"(",
"'.'",
",",
"$",
"ip",
")",
",",
"4",
",",
"0",
")",
")",
";",
"// If the netmask is a dotted decimal format",
"if",
"(",
"strpos",
"(",
"$",
"netmask",
",",
"'.'",
")",
"!==",
"FALSE",
")",
"{",
"// Convert wildcards",
"$",
"netmask",
"=",
"str_replace",
"(",
"'*'",
",",
"'0'",
",",
"$",
"netmask",
")",
";",
"// Convert to long",
"$",
"ipLong",
"=",
"ip2long",
"(",
"$",
"ip",
")",
";",
"$",
"netmaskLong",
"=",
"ip2long",
"(",
"$",
"netmask",
")",
";",
"// Check IPs are valid",
"if",
"(",
"$",
"ipLong",
"===",
"FALSE",
"||",
"$",
"netmaskLong",
"===",
"FALSE",
")",
"{",
"return",
"FALSE",
";",
"}",
"// Return range",
"return",
"array",
"(",
"$",
"ip",
".",
"'/'",
".",
"$",
"netmask",
",",
"array",
"(",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"$",
"ipLong",
")",
",",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"$",
"netmaskLong",
")",
")",
")",
";",
"}",
"// Else netmask is a CIDR block",
"else",
"{",
"// Convert netmask block to bit-mask",
"// Bitwise NOT on wildcard",
"$",
"wildcard",
"=",
"pow",
"(",
"2",
",",
"(",
"32",
"-",
"(",
"int",
")",
"$",
"netmask",
")",
")",
"-",
"1",
";",
"$",
"netmaskDec",
"=",
"~",
"$",
"wildcard",
";",
"// Return range",
"return",
"array",
"(",
"$",
"ip",
".",
"'/'",
".",
"$",
"netmask",
",",
"array",
"(",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"ip2long",
"(",
"$",
"ip",
")",
")",
",",
"$",
"netmaskDec",
")",
")",
";",
"}",
"// Return TRUE",
"return",
"TRUE",
";",
"}",
"// Wildcard or Start-End",
"elseif",
"(",
"strpos",
"(",
"$",
"range",
",",
"'*'",
")",
"!==",
"FALSE",
"||",
"strpos",
"(",
"$",
"range",
",",
"'-'",
")",
"!==",
"FALSE",
")",
"{",
"// Wildcard",
"if",
"(",
"strpos",
"(",
"$",
"range",
",",
"'*'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"lower",
"=",
"str_replace",
"(",
"'*'",
",",
"'0'",
",",
"$",
"range",
")",
";",
"$",
"upper",
"=",
"str_replace",
"(",
"'*'",
",",
"'255'",
",",
"$",
"range",
")",
";",
"$",
"name",
"=",
"$",
"lower",
".",
"'-'",
".",
"$",
"upper",
";",
"}",
"// Start-End",
"else",
"{",
"list",
"(",
"$",
"lower",
",",
"$",
"upper",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"range",
",",
"2",
")",
";",
"$",
"name",
"=",
"$",
"range",
";",
"}",
"// Convert to long",
"$",
"lowerLong",
"=",
"ip2long",
"(",
"$",
"lower",
")",
";",
"$",
"upperLong",
"=",
"ip2long",
"(",
"$",
"upper",
")",
";",
"// Check IPs are valid",
"if",
"(",
"$",
"lowerLong",
"===",
"FALSE",
"||",
"$",
"upperLong",
"===",
"FALSE",
")",
"{",
"return",
"FALSE",
";",
"}",
"// Return range",
"return",
"array",
"(",
"$",
"name",
",",
"array",
"(",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"$",
"lowerLong",
")",
",",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"$",
"upperLong",
")",
")",
")",
";",
"}",
"// Else a single IP",
"if",
"(",
"strpos",
"(",
"$",
"range",
",",
"'.'",
")",
"!==",
"FALSE",
")",
"{",
"// Return range",
"return",
"array",
"(",
"$",
"range",
",",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"ip2long",
"(",
"$",
"range",
")",
")",
")",
";",
"}",
"// No range to return",
"return",
"FALSE",
";",
"}"
] | Format an IP address range
Valid IP ranges can be:
Single: 192.168.1.1
CIDR: 192.168.1/24, 192.168.1.0/24 or 192.168.1.0/255.255.255.0
Wildcard: 192.168.1.*
Start-End: 192.168.1.0-192.168.1.255
@param string $range Valid IP range
@return FALSE|array (name, range) | [
"Format",
"an",
"IP",
"address",
"range"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L182-L325 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.isInside | protected function isInside ($ip, $name, $range)
{
// Single IP
if (!is_array ($range))
{
if ($ip == $range)
{
return TRUE;
}
}
// CIDR
elseif (strpos ($name, '/') !== FALSE)
{
if (($ip & $range[1]) == ($range[0] & $range[1]))
{
return TRUE;
}
}
// Start-End
elseif (strpos ($name, '-') !== FALSE)
{
if (($ip >= $range[0]) && ($ip <= $range[1]))
{
return TRUE;
}
}
// Not inside any range
return FALSE;
} | php | protected function isInside ($ip, $name, $range)
{
// Single IP
if (!is_array ($range))
{
if ($ip == $range)
{
return TRUE;
}
}
// CIDR
elseif (strpos ($name, '/') !== FALSE)
{
if (($ip & $range[1]) == ($range[0] & $range[1]))
{
return TRUE;
}
}
// Start-End
elseif (strpos ($name, '-') !== FALSE)
{
if (($ip >= $range[0]) && ($ip <= $range[1]))
{
return TRUE;
}
}
// Not inside any range
return FALSE;
} | [
"protected",
"function",
"isInside",
"(",
"$",
"ip",
",",
"$",
"name",
",",
"$",
"range",
")",
"{",
"// Single IP",
"if",
"(",
"!",
"is_array",
"(",
"$",
"range",
")",
")",
"{",
"if",
"(",
"$",
"ip",
"==",
"$",
"range",
")",
"{",
"return",
"TRUE",
";",
"}",
"}",
"// CIDR",
"elseif",
"(",
"strpos",
"(",
"$",
"name",
",",
"'/'",
")",
"!==",
"FALSE",
")",
"{",
"if",
"(",
"(",
"$",
"ip",
"&",
"$",
"range",
"[",
"1",
"]",
")",
"==",
"(",
"$",
"range",
"[",
"0",
"]",
"&",
"$",
"range",
"[",
"1",
"]",
")",
")",
"{",
"return",
"TRUE",
";",
"}",
"}",
"// Start-End",
"elseif",
"(",
"strpos",
"(",
"$",
"name",
",",
"'-'",
")",
"!==",
"FALSE",
")",
"{",
"if",
"(",
"(",
"$",
"ip",
">=",
"$",
"range",
"[",
"0",
"]",
")",
"&&",
"(",
"$",
"ip",
"<=",
"$",
"range",
"[",
"1",
"]",
")",
")",
"{",
"return",
"TRUE",
";",
"}",
"}",
"// Not inside any range",
"return",
"FALSE",
";",
"}"
] | Return whether an IP is inside a range
@param intger $ip IP decimal to check
@param string $name IP Range name
@param string|array $range Valid IP range
@return boolean | [
"Return",
"whether",
"an",
"IP",
"is",
"inside",
"a",
"range"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L336-L373 | train |
andyburton/Sonic-Framework | src/Resource/IP.php | IP.isAllowed | public function isAllowed ($ip, $priority = 'deny,allow')
{
// Convert IP to decimal
$ipDec = (float)sprintf ("%u", ip2long ($ip));
// Check
foreach (explode (',', $priority) as $type)
{
switch ($type)
{
// Check if the IP is allowed
case 'allow':
foreach ($this->allowIPs as $name => $range)
{
if ($this->isInside ($ipDec, $name, $range))
{
return TRUE;
}
}
break;
// Check if IP is denied
case 'deny':
foreach ($this->denyIPs as $name => $range)
{
if ($this->isInside ($ipDec, $name, $range))
{
return FALSE;
}
}
break;
}
}
// Not allowed by default
return FALSE;
} | php | public function isAllowed ($ip, $priority = 'deny,allow')
{
// Convert IP to decimal
$ipDec = (float)sprintf ("%u", ip2long ($ip));
// Check
foreach (explode (',', $priority) as $type)
{
switch ($type)
{
// Check if the IP is allowed
case 'allow':
foreach ($this->allowIPs as $name => $range)
{
if ($this->isInside ($ipDec, $name, $range))
{
return TRUE;
}
}
break;
// Check if IP is denied
case 'deny':
foreach ($this->denyIPs as $name => $range)
{
if ($this->isInside ($ipDec, $name, $range))
{
return FALSE;
}
}
break;
}
}
// Not allowed by default
return FALSE;
} | [
"public",
"function",
"isAllowed",
"(",
"$",
"ip",
",",
"$",
"priority",
"=",
"'deny,allow'",
")",
"{",
"// Convert IP to decimal",
"$",
"ipDec",
"=",
"(",
"float",
")",
"sprintf",
"(",
"\"%u\"",
",",
"ip2long",
"(",
"$",
"ip",
")",
")",
";",
"// Check",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"priority",
")",
"as",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"// Check if the IP is allowed",
"case",
"'allow'",
":",
"foreach",
"(",
"$",
"this",
"->",
"allowIPs",
"as",
"$",
"name",
"=>",
"$",
"range",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isInside",
"(",
"$",
"ipDec",
",",
"$",
"name",
",",
"$",
"range",
")",
")",
"{",
"return",
"TRUE",
";",
"}",
"}",
"break",
";",
"// Check if IP is denied",
"case",
"'deny'",
":",
"foreach",
"(",
"$",
"this",
"->",
"denyIPs",
"as",
"$",
"name",
"=>",
"$",
"range",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isInside",
"(",
"$",
"ipDec",
",",
"$",
"name",
",",
"$",
"range",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"}",
"break",
";",
"}",
"}",
"// Not allowed by default",
"return",
"FALSE",
";",
"}"
] | Return whether an IP is allowed
@param string $ip IPv4 address
@param string $priority Order priority, default deny,allow
@return boolean | [
"Return",
"whether",
"an",
"IP",
"is",
"allowed"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/IP.php#L383-L434 | train |
alphacomm/alpharpc | src/AlphaRPC/Console/Command/WorkerStatus.php | WorkerStatus.row | protected function row($worker, $service, $current, $ready, $valid)
{
$mask = "| %-10.10s | %-40.40s | %-40.40s | %-5s | %-5s |";
$text = sprintf($mask, $worker, $service, $current, $ready, $valid);
$this->output->writeln($text);
} | php | protected function row($worker, $service, $current, $ready, $valid)
{
$mask = "| %-10.10s | %-40.40s | %-40.40s | %-5s | %-5s |";
$text = sprintf($mask, $worker, $service, $current, $ready, $valid);
$this->output->writeln($text);
} | [
"protected",
"function",
"row",
"(",
"$",
"worker",
",",
"$",
"service",
",",
"$",
"current",
",",
"$",
"ready",
",",
"$",
"valid",
")",
"{",
"$",
"mask",
"=",
"\"| %-10.10s | %-40.40s | %-40.40s | %-5s | %-5s |\"",
";",
"$",
"text",
"=",
"sprintf",
"(",
"$",
"mask",
",",
"$",
"worker",
",",
"$",
"service",
",",
"$",
"current",
",",
"$",
"ready",
",",
"$",
"valid",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"text",
")",
";",
"}"
] | Print a single line with information.
@param $worker
@param $service
@param $current
@param $ready
@param $valid | [
"Print",
"a",
"single",
"line",
"with",
"information",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Console/Command/WorkerStatus.php#L120-L125 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.parseValidKeys | protected static function parseValidKeys()
{
if (self::$validOptions !== null) {
return;
}
$refl = new ReflectionClass('\ZMQ');
$const = $refl->getConstants();
self::$validOptions = array();
foreach ($const as $key => $value) {
if (substr($key, 0, 8) == 'SOCKOPT_') {
self::$validOptions[$value] = '\ZMQ::'.$key;
}
}
} | php | protected static function parseValidKeys()
{
if (self::$validOptions !== null) {
return;
}
$refl = new ReflectionClass('\ZMQ');
$const = $refl->getConstants();
self::$validOptions = array();
foreach ($const as $key => $value) {
if (substr($key, 0, 8) == 'SOCKOPT_') {
self::$validOptions[$value] = '\ZMQ::'.$key;
}
}
} | [
"protected",
"static",
"function",
"parseValidKeys",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"validOptions",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"$",
"refl",
"=",
"new",
"ReflectionClass",
"(",
"'\\ZMQ'",
")",
";",
"$",
"const",
"=",
"$",
"refl",
"->",
"getConstants",
"(",
")",
";",
"self",
"::",
"$",
"validOptions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"const",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"8",
")",
"==",
"'SOCKOPT_'",
")",
"{",
"self",
"::",
"$",
"validOptions",
"[",
"$",
"value",
"]",
"=",
"'\\ZMQ::'",
".",
"$",
"key",
";",
"}",
"}",
"}"
] | Fills the attribute validOptions containing a list of options that
can be set.
@return null | [
"Fills",
"the",
"attribute",
"validOptions",
"containing",
"a",
"list",
"of",
"options",
"that",
"can",
"be",
"set",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L73-L87 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.isOptionKeyValid | public function isOptionKeyValid($key)
{
self::parseValidKeys();
if (isset(self::$validOptions[$key])) {
return true;
}
return false;
} | php | public function isOptionKeyValid($key)
{
self::parseValidKeys();
if (isset(self::$validOptions[$key])) {
return true;
}
return false;
} | [
"public",
"function",
"isOptionKeyValid",
"(",
"$",
"key",
")",
"{",
"self",
"::",
"parseValidKeys",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"validOptions",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the given option key is valid for ZMQ.
@param mixed $key
@return boolean | [
"Checks",
"if",
"the",
"given",
"option",
"key",
"is",
"valid",
"for",
"ZMQ",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L96-L105 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.addOption | public function addOption($key, $value)
{
if (!$this->isOptionKeyValid($key)) {
throw new \RuntimeException('Invalid socket option '.$key.'.');
}
$this->options[$key] = $value;
return $this;
} | php | public function addOption($key, $value)
{
if (!$this->isOptionKeyValid($key)) {
throw new \RuntimeException('Invalid socket option '.$key.'.');
}
$this->options[$key] = $value;
return $this;
} | [
"public",
"function",
"addOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isOptionKeyValid",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Invalid socket option '",
".",
"$",
"key",
".",
"'.'",
")",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Overrides a default ZMQ option.
@param int $key
@param mixed $value
@return \AlphaRPC\Common\Socket\Factory
@throws \RuntimeException | [
"Overrides",
"a",
"default",
"ZMQ",
"option",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L116-L125 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.addOptions | public function addOptions($options)
{
foreach ($options as $key => $value) {
$this->addOption($key, $value);
}
return $this;
} | php | public function addOptions($options)
{
foreach ($options as $key => $value) {
$this->addOption($key, $value);
}
return $this;
} | [
"public",
"function",
"addOptions",
"(",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"addOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds ZMQ socket options.
@param array $options
@return \AlphaRPC\Common\Socket\Factory
@throws \RuntimeException | [
"Adds",
"ZMQ",
"socket",
"options",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L135-L142 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createPublisher | public function createPublisher($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_PUB, $mode, $dsn, $options);
} | php | public function createPublisher($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_PUB, $mode, $dsn, $options);
} | [
"public",
"function",
"createPublisher",
"(",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createSocket",
"(",
"ZMQ",
"::",
"SOCKET_PUB",
",",
"$",
"mode",
",",
"$",
"dsn",
",",
"$",
"options",
")",
";",
"}"
] | Creates a publiser socket.
@param string $mode
@param string|array $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"publiser",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L167-L170 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createSubscriber | public function createSubscriber($mode, $dsn = null, $subscribe = '', $options = array())
{
$options[ZMQ::SOCKOPT_SUBSCRIBE] = $subscribe;
return $this->createSocket(ZMQ::SOCKET_SUB, $mode, $dsn, $options);
} | php | public function createSubscriber($mode, $dsn = null, $subscribe = '', $options = array())
{
$options[ZMQ::SOCKOPT_SUBSCRIBE] = $subscribe;
return $this->createSocket(ZMQ::SOCKET_SUB, $mode, $dsn, $options);
} | [
"public",
"function",
"createSubscriber",
"(",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"subscribe",
"=",
"''",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"[",
"ZMQ",
"::",
"SOCKOPT_SUBSCRIBE",
"]",
"=",
"$",
"subscribe",
";",
"return",
"$",
"this",
"->",
"createSocket",
"(",
"ZMQ",
"::",
"SOCKET_SUB",
",",
"$",
"mode",
",",
"$",
"dsn",
",",
"$",
"options",
")",
";",
"}"
] | Creates a subscriber socket.
@param string $mode
@param string $subscribe
@param string|array $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"subscriber",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L182-L187 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createRequest | public function createRequest($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_REQ, $mode, $dsn, $options);
} | php | public function createRequest($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_REQ, $mode, $dsn, $options);
} | [
"public",
"function",
"createRequest",
"(",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createSocket",
"(",
"ZMQ",
"::",
"SOCKET_REQ",
",",
"$",
"mode",
",",
"$",
"dsn",
",",
"$",
"options",
")",
";",
"}"
] | Creates a request socket.
@param string $mode
@param string|array $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"request",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L198-L201 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createReply | public function createReply($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_REP, $mode, $dsn, $options);
} | php | public function createReply($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_REP, $mode, $dsn, $options);
} | [
"public",
"function",
"createReply",
"(",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createSocket",
"(",
"ZMQ",
"::",
"SOCKET_REP",
",",
"$",
"mode",
",",
"$",
"dsn",
",",
"$",
"options",
")",
";",
"}"
] | Creates a reply socket.
@param string $mode
@param string|array $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"reply",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L212-L215 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createRouter | public function createRouter($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_ROUTER, $mode, $dsn, $options);
} | php | public function createRouter($mode, $dsn = null, $options = array())
{
return $this->createSocket(ZMQ::SOCKET_ROUTER, $mode, $dsn, $options);
} | [
"public",
"function",
"createRouter",
"(",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createSocket",
"(",
"ZMQ",
"::",
"SOCKET_ROUTER",
",",
"$",
"mode",
",",
"$",
"dsn",
",",
"$",
"options",
")",
";",
"}"
] | Creates a router socket.
@param string $mode
@param string|array $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"router",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L226-L229 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.createSocket | protected function createSocket($type, $mode, $dsn = null, $options = array())
{
$context = $this->getContext();
$socket = new Socket($context, $type);
$options = $this->options + $options;
foreach ($options as $key => $value) {
$socket->setSockOpt($key, $value);
}
$this->connect($socket, $mode, $dsn);
return $socket;
} | php | protected function createSocket($type, $mode, $dsn = null, $options = array())
{
$context = $this->getContext();
$socket = new Socket($context, $type);
$options = $this->options + $options;
foreach ($options as $key => $value) {
$socket->setSockOpt($key, $value);
}
$this->connect($socket, $mode, $dsn);
return $socket;
} | [
"protected",
"function",
"createSocket",
"(",
"$",
"type",
",",
"$",
"mode",
",",
"$",
"dsn",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"socket",
"=",
"new",
"Socket",
"(",
"$",
"context",
",",
"$",
"type",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
"+",
"$",
"options",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"socket",
"->",
"setSockOpt",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"connect",
"(",
"$",
"socket",
",",
"$",
"mode",
",",
"$",
"dsn",
")",
";",
"return",
"$",
"socket",
";",
"}"
] | Creates a socket.
@param int $type
@param string $mode
@param string $dsn
@param array $options
@return Socket | [
"Creates",
"a",
"socket",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L241-L254 | train |
alphacomm/alpharpc | src/AlphaRPC/Common/Socket/Factory.php | Factory.connect | public function connect(ZMQSocket $socket, $mode, $dsn)
{
if ($mode == self::MODE_CONSTRUCT) {
return $this;
}
$func = null;
if ($mode == self::MODE_BIND) {
$func = 'bind';
} elseif ($mode == self::MODE_CONNECT) {
$func = 'connect';
}
if (is_string($dsn)) {
$dsn = array($dsn);
}
if (!is_array($dsn)) {
throw new \RuntimeException('DSN should be a string or an array.');
}
foreach ($dsn as $d) {
if (!is_string($d)) {
throw new \RuntimeException('Non-string in DSN array detected.');
}
$socket->$func($d);
}
} | php | public function connect(ZMQSocket $socket, $mode, $dsn)
{
if ($mode == self::MODE_CONSTRUCT) {
return $this;
}
$func = null;
if ($mode == self::MODE_BIND) {
$func = 'bind';
} elseif ($mode == self::MODE_CONNECT) {
$func = 'connect';
}
if (is_string($dsn)) {
$dsn = array($dsn);
}
if (!is_array($dsn)) {
throw new \RuntimeException('DSN should be a string or an array.');
}
foreach ($dsn as $d) {
if (!is_string($d)) {
throw new \RuntimeException('Non-string in DSN array detected.');
}
$socket->$func($d);
}
} | [
"public",
"function",
"connect",
"(",
"ZMQSocket",
"$",
"socket",
",",
"$",
"mode",
",",
"$",
"dsn",
")",
"{",
"if",
"(",
"$",
"mode",
"==",
"self",
"::",
"MODE_CONSTRUCT",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"func",
"=",
"null",
";",
"if",
"(",
"$",
"mode",
"==",
"self",
"::",
"MODE_BIND",
")",
"{",
"$",
"func",
"=",
"'bind'",
";",
"}",
"elseif",
"(",
"$",
"mode",
"==",
"self",
"::",
"MODE_CONNECT",
")",
"{",
"$",
"func",
"=",
"'connect'",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"dsn",
")",
")",
"{",
"$",
"dsn",
"=",
"array",
"(",
"$",
"dsn",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dsn",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'DSN should be a string or an array.'",
")",
";",
"}",
"foreach",
"(",
"$",
"dsn",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"d",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Non-string in DSN array detected.'",
")",
";",
"}",
"$",
"socket",
"->",
"$",
"func",
"(",
"$",
"d",
")",
";",
"}",
"}"
] | Connects or binds a socket based on mode.
@param ZMQSocket $socket
@param string $mode
@param string|array $dsn
@return \AlphaRPC\Common\Socket\Factory
@throws \RuntimeException | [
"Connects",
"or",
"binds",
"a",
"socket",
"based",
"on",
"mode",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Common/Socket/Factory.php#L266-L293 | train |
Synapse-Cmf/synapse-cmf | src/Synapse/Cmf/Framework/Media/Media/Domain/ProxyDomain.php | ProxyDomain.registerMediaDomain | public function registerMediaDomain($extensions, DomainInterface $mediaDomain)
{
foreach ((array) $extensions as $extensions) {
$this->mediaDomainsMap[strtolower($extensions)] = $mediaDomain;
}
} | php | public function registerMediaDomain($extensions, DomainInterface $mediaDomain)
{
foreach ((array) $extensions as $extensions) {
$this->mediaDomainsMap[strtolower($extensions)] = $mediaDomain;
}
} | [
"public",
"function",
"registerMediaDomain",
"(",
"$",
"extensions",
",",
"DomainInterface",
"$",
"mediaDomain",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"extensions",
"as",
"$",
"extensions",
")",
"{",
"$",
"this",
"->",
"mediaDomainsMap",
"[",
"strtolower",
"(",
"$",
"extensions",
")",
"]",
"=",
"$",
"mediaDomain",
";",
"}",
"}"
] | Register a media domain for given file extension set.
@param string|array $extensions
@param DomainInterface $mediaDomain | [
"Register",
"a",
"media",
"domain",
"for",
"given",
"file",
"extension",
"set",
"."
] | d8122a4150a83d5607289724425cf35c56a5e880 | https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Media/Media/Domain/ProxyDomain.php#L37-L42 | train |
Synapse-Cmf/synapse-cmf | src/Synapse/Cmf/Framework/Media/Media/Domain/ProxyDomain.php | ProxyDomain.fetchDomain | private function fetchDomain($extension)
{
if (!array_key_exists($extension = strtolower($extension), $this->mediaDomainsMap)) {
throw new UnsupportedFileException(sprintf(
'Extension ".%s" isnt supported by Media component, only ["%s"] are.',
$extension,
implode('", "', array_keys($this->mediaDomainsMap))
));
}
return $this->mediaDomainsMap[$extension];
} | php | private function fetchDomain($extension)
{
if (!array_key_exists($extension = strtolower($extension), $this->mediaDomainsMap)) {
throw new UnsupportedFileException(sprintf(
'Extension ".%s" isnt supported by Media component, only ["%s"] are.',
$extension,
implode('", "', array_keys($this->mediaDomainsMap))
));
}
return $this->mediaDomainsMap[$extension];
} | [
"private",
"function",
"fetchDomain",
"(",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"extension",
"=",
"strtolower",
"(",
"$",
"extension",
")",
",",
"$",
"this",
"->",
"mediaDomainsMap",
")",
")",
"{",
"throw",
"new",
"UnsupportedFileException",
"(",
"sprintf",
"(",
"'Extension \".%s\" isnt supported by Media component, only [\"%s\"] are.'",
",",
"$",
"extension",
",",
"implode",
"(",
"'\", \"'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"mediaDomainsMap",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mediaDomainsMap",
"[",
"$",
"extension",
"]",
";",
"}"
] | Fetch and return domain matching given file extension.
@param string $extension
@return DomainInterface
@throws UnsupportedFileException If given extension isnt supported | [
"Fetch",
"and",
"return",
"domain",
"matching",
"given",
"file",
"extension",
"."
] | d8122a4150a83d5607289724425cf35c56a5e880 | https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Media/Media/Domain/ProxyDomain.php#L53-L64 | train |
inhere/php-library-plus | libs/Auth/User.php | User.can | public function can($permission, array $params = [], $caching = true)
{
return $this->canAccess($permission, $params, $caching);
} | php | public function can($permission, array $params = [], $caching = true)
{
return $this->canAccess($permission, $params, $caching);
} | [
"public",
"function",
"can",
"(",
"$",
"permission",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"caching",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"canAccess",
"(",
"$",
"permission",
",",
"$",
"params",
",",
"$",
"caching",
")",
";",
"}"
] | check user permission
@param string $permission a permission name or a url
@param array $params
@param bool|true $caching
@return bool | [
"check",
"user",
"permission"
] | 8604e037937d31fa2338d79aaf9d0910cb48f559 | https://github.com/inhere/php-library-plus/blob/8604e037937d31fa2338d79aaf9d0910cb48f559/libs/Auth/User.php#L162-L165 | train |
PHPColibri/framework | Session/Session.php | Session.get | public static function get($dottedKey, $default = null)
{
if (self::$flashedVars) {
$flashedValue = Arr::get(self::$flashedVars, $dottedKey, '~no~flashed~value~');
if ($flashedValue !== '~no~flashed~value~') {
return $flashedValue;
}
}
return self::$storage->get($dottedKey, $default);
} | php | public static function get($dottedKey, $default = null)
{
if (self::$flashedVars) {
$flashedValue = Arr::get(self::$flashedVars, $dottedKey, '~no~flashed~value~');
if ($flashedValue !== '~no~flashed~value~') {
return $flashedValue;
}
}
return self::$storage->get($dottedKey, $default);
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"dottedKey",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"flashedVars",
")",
"{",
"$",
"flashedValue",
"=",
"Arr",
"::",
"get",
"(",
"self",
"::",
"$",
"flashedVars",
",",
"$",
"dottedKey",
",",
"'~no~flashed~value~'",
")",
";",
"if",
"(",
"$",
"flashedValue",
"!==",
"'~no~flashed~value~'",
")",
"{",
"return",
"$",
"flashedValue",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"storage",
"->",
"get",
"(",
"$",
"dottedKey",
",",
"$",
"default",
")",
";",
"}"
] | Retrieve the value from session.
@param string $dottedKey
@param mixed $default
@return mixed | [
"Retrieve",
"the",
"value",
"from",
"session",
"."
] | 7e5b77141da5e5e7c63afc83592671321ac52f36 | https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Session/Session.php#L53-L63 | train |
cymapgt/logger | src/Logger.php | Logger.addLogHandler | public function addLogHandler(array $logHandlers, $createLogger = false) {
try {
$this->configuredLogHandlers = array_merge($this->configuredLogHandlers, $logHandlers);
if ($createLogger === true) {
$this->createLogger($this->channelName);
$this->createLogHandlers();
}
} catch (Exception $ex) {
throw new LoggerException (
"An exception occurred when adding the Log Handler to "
. $this->channelName
. ":"
. $ex->getMessage()
);
}
} | php | public function addLogHandler(array $logHandlers, $createLogger = false) {
try {
$this->configuredLogHandlers = array_merge($this->configuredLogHandlers, $logHandlers);
if ($createLogger === true) {
$this->createLogger($this->channelName);
$this->createLogHandlers();
}
} catch (Exception $ex) {
throw new LoggerException (
"An exception occurred when adding the Log Handler to "
. $this->channelName
. ":"
. $ex->getMessage()
);
}
} | [
"public",
"function",
"addLogHandler",
"(",
"array",
"$",
"logHandlers",
",",
"$",
"createLogger",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"configuredLogHandlers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"configuredLogHandlers",
",",
"$",
"logHandlers",
")",
";",
"if",
"(",
"$",
"createLogger",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"createLogger",
"(",
"$",
"this",
"->",
"channelName",
")",
";",
"$",
"this",
"->",
"createLogHandlers",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"LoggerException",
"(",
"\"An exception occurred when adding the Log Handler to \"",
".",
"$",
"this",
"->",
"channelName",
".",
"\":\"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Add log handlers to the configuration
@param array $logHandlers - Array of log handler configuration. The alphanumeric keys are the namespace
@param bool $createLogger - Boolean flag. If true, create concrete Logger and instantiate the log handlers | [
"Add",
"log",
"handlers",
"to",
"the",
"configuration"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L72-L88 | train |
cymapgt/logger | src/Logger.php | Logger.createLogHandlers | protected function createLogHandlers() {
$logHandlers = $this->configuredLogHandlers;
foreach ($logHandlers as $handlerNamespace => $handlerDetails) {
if (
is_array($handlerDetails)
&& array_key_exists('handler_parameters', $handlerDetails)
) {
$handlerParameters = $handlerDetails['handler_parameters'];
$handlerObj = new $handlerNamespace(...$handlerParameters);
$this->concreteLogger->pushHandler($handlerObj);
}
}
} | php | protected function createLogHandlers() {
$logHandlers = $this->configuredLogHandlers;
foreach ($logHandlers as $handlerNamespace => $handlerDetails) {
if (
is_array($handlerDetails)
&& array_key_exists('handler_parameters', $handlerDetails)
) {
$handlerParameters = $handlerDetails['handler_parameters'];
$handlerObj = new $handlerNamespace(...$handlerParameters);
$this->concreteLogger->pushHandler($handlerObj);
}
}
} | [
"protected",
"function",
"createLogHandlers",
"(",
")",
"{",
"$",
"logHandlers",
"=",
"$",
"this",
"->",
"configuredLogHandlers",
";",
"foreach",
"(",
"$",
"logHandlers",
"as",
"$",
"handlerNamespace",
"=>",
"$",
"handlerDetails",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"handlerDetails",
")",
"&&",
"array_key_exists",
"(",
"'handler_parameters'",
",",
"$",
"handlerDetails",
")",
")",
"{",
"$",
"handlerParameters",
"=",
"$",
"handlerDetails",
"[",
"'handler_parameters'",
"]",
";",
"$",
"handlerObj",
"=",
"new",
"$",
"handlerNamespace",
"(",
"...",
"$",
"handlerParameters",
")",
";",
"$",
"this",
"->",
"concreteLogger",
"->",
"pushHandler",
"(",
"$",
"handlerObj",
")",
";",
"}",
"}",
"}"
] | Iterate the configured log handlers and create concrete handlers | [
"Iterate",
"the",
"configured",
"log",
"handlers",
"and",
"create",
"concrete",
"handlers"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L102-L115 | train |
cymapgt/logger | src/Logger.php | Logger._getLoggerStderr | private static function _getLoggerStderr() {
if (!isset(self::$loggerStderr)) {
$CymapgtStderrLogger = new MonologLogger('cymapgt_stderr');
$CymapgtStderrLogger->pushHandler(new ErrorLogHandler());
self::$loggerStderr = $CymapgtStderrLogger;
}
return self::$loggerStderr;
} | php | private static function _getLoggerStderr() {
if (!isset(self::$loggerStderr)) {
$CymapgtStderrLogger = new MonologLogger('cymapgt_stderr');
$CymapgtStderrLogger->pushHandler(new ErrorLogHandler());
self::$loggerStderr = $CymapgtStderrLogger;
}
return self::$loggerStderr;
} | [
"private",
"static",
"function",
"_getLoggerStderr",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"loggerStderr",
")",
")",
"{",
"$",
"CymapgtStderrLogger",
"=",
"new",
"MonologLogger",
"(",
"'cymapgt_stderr'",
")",
";",
"$",
"CymapgtStderrLogger",
"->",
"pushHandler",
"(",
"new",
"ErrorLogHandler",
"(",
")",
")",
";",
"self",
"::",
"$",
"loggerStderr",
"=",
"$",
"CymapgtStderrLogger",
";",
"}",
"return",
"self",
"::",
"$",
"loggerStderr",
";",
"}"
] | return the stderr logger
@return object
@private
@static | [
"return",
"the",
"stderr",
"logger"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L179-L186 | train |
cymapgt/logger | src/Logger.php | Logger._getLoggerLevel1 | private static function _getLoggerLevel1($loggerParams) {
if (!isset(self::$loggerLevel1)) {
$CymapgtLevel1LogDir = $loggerParams['log_dir'];
$CymapgtLevel1Stream = new StreamHandler($CymapgtLevel1LogDir, MonologLogger::DEBUG);
$CymapgtLevel1Logger = new MonologLogger('cymapgt_level1');
$CymapgtLevel1Logger->pushHandler($CymapgtLevel1Stream);
self::$loggerLevel1 = $CymapgtLevel1Logger;
}
return self::$loggerLevel1;
} | php | private static function _getLoggerLevel1($loggerParams) {
if (!isset(self::$loggerLevel1)) {
$CymapgtLevel1LogDir = $loggerParams['log_dir'];
$CymapgtLevel1Stream = new StreamHandler($CymapgtLevel1LogDir, MonologLogger::DEBUG);
$CymapgtLevel1Logger = new MonologLogger('cymapgt_level1');
$CymapgtLevel1Logger->pushHandler($CymapgtLevel1Stream);
self::$loggerLevel1 = $CymapgtLevel1Logger;
}
return self::$loggerLevel1;
} | [
"private",
"static",
"function",
"_getLoggerLevel1",
"(",
"$",
"loggerParams",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"loggerLevel1",
")",
")",
"{",
"$",
"CymapgtLevel1LogDir",
"=",
"$",
"loggerParams",
"[",
"'log_dir'",
"]",
";",
"$",
"CymapgtLevel1Stream",
"=",
"new",
"StreamHandler",
"(",
"$",
"CymapgtLevel1LogDir",
",",
"MonologLogger",
"::",
"DEBUG",
")",
";",
"$",
"CymapgtLevel1Logger",
"=",
"new",
"MonologLogger",
"(",
"'cymapgt_level1'",
")",
";",
"$",
"CymapgtLevel1Logger",
"->",
"pushHandler",
"(",
"$",
"CymapgtLevel1Stream",
")",
";",
"self",
"::",
"$",
"loggerLevel1",
"=",
"$",
"CymapgtLevel1Logger",
";",
"}",
"return",
"self",
"::",
"$",
"loggerLevel1",
";",
"}"
] | return the level1 logger
@param array $loggerParams - Array of parameters to configure the level 1 logger
@return object
@private
@static | [
"return",
"the",
"level1",
"logger"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L197-L206 | train |
cymapgt/logger | src/Logger.php | Logger._getLoggerLevel2 | private static function _getLoggerLevel2($loggerParams) {
if (!isset(self::$loggerLevel2)) {
$CymapgtLevel2LogDir = $loggerParams['log_dir'];
$CymapgtLevel2Stream = new StreamHandler($CymapgtLevel2LogDir, MonologLogger::ERROR);
$CymapgtLevel2Logger = new MonologLogger('cymapgt_level2');
$CymapgtLevel2Mailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtLevel2Message = $loggerParams['swiftmailer_message'];
$CymapgtLevel2Logger->pushHandler($CymapgtLevel2Stream);
$CymapgtLevel2Logger->pushHandler(new SwiftMailerHandler($CymapgtLevel2Mailer, $CymapgtLevel2Message));
self::$loggerLevel2 = $CymapgtLevel2Logger;
}
return self::$loggerLevel2;
} | php | private static function _getLoggerLevel2($loggerParams) {
if (!isset(self::$loggerLevel2)) {
$CymapgtLevel2LogDir = $loggerParams['log_dir'];
$CymapgtLevel2Stream = new StreamHandler($CymapgtLevel2LogDir, MonologLogger::ERROR);
$CymapgtLevel2Logger = new MonologLogger('cymapgt_level2');
$CymapgtLevel2Mailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtLevel2Message = $loggerParams['swiftmailer_message'];
$CymapgtLevel2Logger->pushHandler($CymapgtLevel2Stream);
$CymapgtLevel2Logger->pushHandler(new SwiftMailerHandler($CymapgtLevel2Mailer, $CymapgtLevel2Message));
self::$loggerLevel2 = $CymapgtLevel2Logger;
}
return self::$loggerLevel2;
} | [
"private",
"static",
"function",
"_getLoggerLevel2",
"(",
"$",
"loggerParams",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"loggerLevel2",
")",
")",
"{",
"$",
"CymapgtLevel2LogDir",
"=",
"$",
"loggerParams",
"[",
"'log_dir'",
"]",
";",
"$",
"CymapgtLevel2Stream",
"=",
"new",
"StreamHandler",
"(",
"$",
"CymapgtLevel2LogDir",
",",
"MonologLogger",
"::",
"ERROR",
")",
";",
"$",
"CymapgtLevel2Logger",
"=",
"new",
"MonologLogger",
"(",
"'cymapgt_level2'",
")",
";",
"$",
"CymapgtLevel2Mailer",
"=",
"new",
"\\",
"Swift_Mailer",
"(",
"$",
"loggerParams",
"[",
"'swiftmailer_transport'",
"]",
")",
";",
"$",
"CymapgtLevel2Message",
"=",
"$",
"loggerParams",
"[",
"'swiftmailer_message'",
"]",
";",
"$",
"CymapgtLevel2Logger",
"->",
"pushHandler",
"(",
"$",
"CymapgtLevel2Stream",
")",
";",
"$",
"CymapgtLevel2Logger",
"->",
"pushHandler",
"(",
"new",
"SwiftMailerHandler",
"(",
"$",
"CymapgtLevel2Mailer",
",",
"$",
"CymapgtLevel2Message",
")",
")",
";",
"self",
"::",
"$",
"loggerLevel2",
"=",
"$",
"CymapgtLevel2Logger",
";",
"}",
"return",
"self",
"::",
"$",
"loggerLevel2",
";",
"}"
] | return the level2 logger
@param array $loggerParams - Array of parameters to configure the level 2 logger
@return object
@private
@static | [
"return",
"the",
"level2",
"logger"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L217-L229 | train |
cymapgt/logger | src/Logger.php | Logger._getLoggerLevel3 | private static function _getLoggerLevel3($loggerParams) {
if (!isset(self::$loggerLevel3)) {
/*create notifier object for africas talking. If you are behind a proxy, the
*second parameter should be true, and your configuration array should contain
*the proxy server settings
*/
$notifierObj = new NotifierSmsAfricasTalkingService($loggerParams['notifier_params'], true);
$recipientList = $loggerParams['notifier_recipients'];
$CymapgtLevel3LogDir = $loggerParams['log_dir'];
$CymapgtLevel3Stream = new StreamHandler($CymapgtLevel3LogDir, MonologLogger::ERROR);
$CymapgtLevel3Logger = new MonologLogger('cymapgt_level3');
$CymapgtLevel3Mailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtLevel3Message = $loggerParams['swiftmailer_message'];
$CymapgtLevel3Logger->pushHandler($CymapgtLevel3Stream);
$CymapgtLevel3Logger->pushHandler(new SwiftMailerHandler($CymapgtLevel3Mailer, $CymapgtLevel3Message));
$smsHandler = new NotifierSmsAfricasTalkingServiceHandler($notifierObj);
$smsHandler->setRecipients($recipientList);
$CymapgtLevel3Logger->pushHandler($smsHandler);
self::$loggerLevel3 = $CymapgtLevel3Logger;
}
return self::$loggerLevel3;
} | php | private static function _getLoggerLevel3($loggerParams) {
if (!isset(self::$loggerLevel3)) {
/*create notifier object for africas talking. If you are behind a proxy, the
*second parameter should be true, and your configuration array should contain
*the proxy server settings
*/
$notifierObj = new NotifierSmsAfricasTalkingService($loggerParams['notifier_params'], true);
$recipientList = $loggerParams['notifier_recipients'];
$CymapgtLevel3LogDir = $loggerParams['log_dir'];
$CymapgtLevel3Stream = new StreamHandler($CymapgtLevel3LogDir, MonologLogger::ERROR);
$CymapgtLevel3Logger = new MonologLogger('cymapgt_level3');
$CymapgtLevel3Mailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtLevel3Message = $loggerParams['swiftmailer_message'];
$CymapgtLevel3Logger->pushHandler($CymapgtLevel3Stream);
$CymapgtLevel3Logger->pushHandler(new SwiftMailerHandler($CymapgtLevel3Mailer, $CymapgtLevel3Message));
$smsHandler = new NotifierSmsAfricasTalkingServiceHandler($notifierObj);
$smsHandler->setRecipients($recipientList);
$CymapgtLevel3Logger->pushHandler($smsHandler);
self::$loggerLevel3 = $CymapgtLevel3Logger;
}
return self::$loggerLevel3;
} | [
"private",
"static",
"function",
"_getLoggerLevel3",
"(",
"$",
"loggerParams",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"loggerLevel3",
")",
")",
"{",
"/*create notifier object for africas talking. If you are behind a proxy, the\n *second parameter should be true, and your configuration array should contain\n *the proxy server settings\n */",
"$",
"notifierObj",
"=",
"new",
"NotifierSmsAfricasTalkingService",
"(",
"$",
"loggerParams",
"[",
"'notifier_params'",
"]",
",",
"true",
")",
";",
"$",
"recipientList",
"=",
"$",
"loggerParams",
"[",
"'notifier_recipients'",
"]",
";",
"$",
"CymapgtLevel3LogDir",
"=",
"$",
"loggerParams",
"[",
"'log_dir'",
"]",
";",
"$",
"CymapgtLevel3Stream",
"=",
"new",
"StreamHandler",
"(",
"$",
"CymapgtLevel3LogDir",
",",
"MonologLogger",
"::",
"ERROR",
")",
";",
"$",
"CymapgtLevel3Logger",
"=",
"new",
"MonologLogger",
"(",
"'cymapgt_level3'",
")",
";",
"$",
"CymapgtLevel3Mailer",
"=",
"new",
"\\",
"Swift_Mailer",
"(",
"$",
"loggerParams",
"[",
"'swiftmailer_transport'",
"]",
")",
";",
"$",
"CymapgtLevel3Message",
"=",
"$",
"loggerParams",
"[",
"'swiftmailer_message'",
"]",
";",
"$",
"CymapgtLevel3Logger",
"->",
"pushHandler",
"(",
"$",
"CymapgtLevel3Stream",
")",
";",
"$",
"CymapgtLevel3Logger",
"->",
"pushHandler",
"(",
"new",
"SwiftMailerHandler",
"(",
"$",
"CymapgtLevel3Mailer",
",",
"$",
"CymapgtLevel3Message",
")",
")",
";",
"$",
"smsHandler",
"=",
"new",
"NotifierSmsAfricasTalkingServiceHandler",
"(",
"$",
"notifierObj",
")",
";",
"$",
"smsHandler",
"->",
"setRecipients",
"(",
"$",
"recipientList",
")",
";",
"$",
"CymapgtLevel3Logger",
"->",
"pushHandler",
"(",
"$",
"smsHandler",
")",
";",
"self",
"::",
"$",
"loggerLevel3",
"=",
"$",
"CymapgtLevel3Logger",
";",
"}",
"return",
"self",
"::",
"$",
"loggerLevel3",
";",
"}"
] | return the level3 logger
@param array $loggerParams - Array of parameters to configure the level 3 logger
@return object
@private
@static | [
"return",
"the",
"level3",
"logger"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L240-L262 | train |
cymapgt/logger | src/Logger.php | Logger._getLoggerSecurity | private static function _getLoggerSecurity($loggerParams) {
if (!isset(self::$loggerSecurity)) {
/*create notifier object for africas talking. If you are behind a proxy, the
*second parameter should be true, and your configuration array should contain
*the proxy server settings
*/
$notifierObj = new NotifierSmsAfricasTalkingService(($loggerParams['notifier_params']), ($loggerParams['notifier_params']['IS_BEHIND_PROXY']));
$recipientList = $loggerParams['notifier_recipients'];
$CymapgtSecurityLogDir = $loggerParams['log_dir'];
$CymapgtSecurityStream = new StreamHandler($CymapgtSecurityLogDir, MonologLogger::ERROR);
$CymapgtSecurityLogger = new MonologLogger('cymapgt_security');
$CymapgtSecurityMailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtSecurityMessage = $loggerParams['swiftmailer_message'];
$CymapgtSecurityLogger->pushHandler($CymapgtSecurityStream);
$CymapgtSecurityLogger->pushHandler(new SwiftMailerHandler($CymapgtSecurityMailer, $CymapgtSecurityMessage));
$smsHandler = new NotifierSmsAfricasTalkingServiceHandler($notifierObj);
$smsHandler->setRecipients($recipientList);
$CymapgtSecurityLogger->pushHandler($smsHandler);
self::$loggerSecurity = $CymapgtSecurityLogger;
}
return self::$loggerSecurity;
} | php | private static function _getLoggerSecurity($loggerParams) {
if (!isset(self::$loggerSecurity)) {
/*create notifier object for africas talking. If you are behind a proxy, the
*second parameter should be true, and your configuration array should contain
*the proxy server settings
*/
$notifierObj = new NotifierSmsAfricasTalkingService(($loggerParams['notifier_params']), ($loggerParams['notifier_params']['IS_BEHIND_PROXY']));
$recipientList = $loggerParams['notifier_recipients'];
$CymapgtSecurityLogDir = $loggerParams['log_dir'];
$CymapgtSecurityStream = new StreamHandler($CymapgtSecurityLogDir, MonologLogger::ERROR);
$CymapgtSecurityLogger = new MonologLogger('cymapgt_security');
$CymapgtSecurityMailer = new \Swift_Mailer($loggerParams['swiftmailer_transport']);
$CymapgtSecurityMessage = $loggerParams['swiftmailer_message'];
$CymapgtSecurityLogger->pushHandler($CymapgtSecurityStream);
$CymapgtSecurityLogger->pushHandler(new SwiftMailerHandler($CymapgtSecurityMailer, $CymapgtSecurityMessage));
$smsHandler = new NotifierSmsAfricasTalkingServiceHandler($notifierObj);
$smsHandler->setRecipients($recipientList);
$CymapgtSecurityLogger->pushHandler($smsHandler);
self::$loggerSecurity = $CymapgtSecurityLogger;
}
return self::$loggerSecurity;
} | [
"private",
"static",
"function",
"_getLoggerSecurity",
"(",
"$",
"loggerParams",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"loggerSecurity",
")",
")",
"{",
"/*create notifier object for africas talking. If you are behind a proxy, the\n *second parameter should be true, and your configuration array should contain\n *the proxy server settings\n */",
"$",
"notifierObj",
"=",
"new",
"NotifierSmsAfricasTalkingService",
"(",
"(",
"$",
"loggerParams",
"[",
"'notifier_params'",
"]",
")",
",",
"(",
"$",
"loggerParams",
"[",
"'notifier_params'",
"]",
"[",
"'IS_BEHIND_PROXY'",
"]",
")",
")",
";",
"$",
"recipientList",
"=",
"$",
"loggerParams",
"[",
"'notifier_recipients'",
"]",
";",
"$",
"CymapgtSecurityLogDir",
"=",
"$",
"loggerParams",
"[",
"'log_dir'",
"]",
";",
"$",
"CymapgtSecurityStream",
"=",
"new",
"StreamHandler",
"(",
"$",
"CymapgtSecurityLogDir",
",",
"MonologLogger",
"::",
"ERROR",
")",
";",
"$",
"CymapgtSecurityLogger",
"=",
"new",
"MonologLogger",
"(",
"'cymapgt_security'",
")",
";",
"$",
"CymapgtSecurityMailer",
"=",
"new",
"\\",
"Swift_Mailer",
"(",
"$",
"loggerParams",
"[",
"'swiftmailer_transport'",
"]",
")",
";",
"$",
"CymapgtSecurityMessage",
"=",
"$",
"loggerParams",
"[",
"'swiftmailer_message'",
"]",
";",
"$",
"CymapgtSecurityLogger",
"->",
"pushHandler",
"(",
"$",
"CymapgtSecurityStream",
")",
";",
"$",
"CymapgtSecurityLogger",
"->",
"pushHandler",
"(",
"new",
"SwiftMailerHandler",
"(",
"$",
"CymapgtSecurityMailer",
",",
"$",
"CymapgtSecurityMessage",
")",
")",
";",
"$",
"smsHandler",
"=",
"new",
"NotifierSmsAfricasTalkingServiceHandler",
"(",
"$",
"notifierObj",
")",
";",
"$",
"smsHandler",
"->",
"setRecipients",
"(",
"$",
"recipientList",
")",
";",
"$",
"CymapgtSecurityLogger",
"->",
"pushHandler",
"(",
"$",
"smsHandler",
")",
";",
"self",
"::",
"$",
"loggerSecurity",
"=",
"$",
"CymapgtSecurityLogger",
";",
"}",
"return",
"self",
"::",
"$",
"loggerSecurity",
";",
"}"
] | return the security logger
@param array $loggerParams - Array of parameters to configure the security logger
@return object
@private
@static | [
"return",
"the",
"security",
"logger"
] | 8d042b21a9e13a3597c99084229781ab6151d78f | https://github.com/cymapgt/logger/blob/8d042b21a9e13a3597c99084229781ab6151d78f/src/Logger.php#L273-L295 | train |
IStranger/yii2-resource-smart-load | base/BaseObject.php | BaseObject.setProperties | public function setProperties($propValues)
{
foreach ($propValues as $propName => $propValue) {
if (property_exists($this, $propName)) {
$this->{$propName} = $propValue;
} else {
$this->throwException('Property "%propName%" does not exist in class "%className%"', array(
'%propName%' => $propName,
'%className%' => static::className(),
));
}
}
} | php | public function setProperties($propValues)
{
foreach ($propValues as $propName => $propValue) {
if (property_exists($this, $propName)) {
$this->{$propName} = $propValue;
} else {
$this->throwException('Property "%propName%" does not exist in class "%className%"', array(
'%propName%' => $propName,
'%className%' => static::className(),
));
}
}
} | [
"public",
"function",
"setProperties",
"(",
"$",
"propValues",
")",
"{",
"foreach",
"(",
"$",
"propValues",
"as",
"$",
"propName",
"=>",
"$",
"propValue",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"propName",
")",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"propName",
"}",
"=",
"$",
"propValue",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"throwException",
"(",
"'Property \"%propName%\" does not exist in class \"%className%\"'",
",",
"array",
"(",
"'%propName%'",
"=>",
"$",
"propName",
",",
"'%className%'",
"=>",
"static",
"::",
"className",
"(",
")",
",",
")",
")",
";",
"}",
"}",
"}"
] | Sets properties values
@param array $propValues Array of properties values in format: ['propName' => 'propValue'] | [
"Sets",
"properties",
"values"
] | a4f203745d9a02fd97853b49c55b287aea6d7e6d | https://github.com/IStranger/yii2-resource-smart-load/blob/a4f203745d9a02fd97853b49c55b287aea6d7e6d/base/BaseObject.php#L28-L40 | train |
akumar2-velsof/guzzlehttp | src/Pool.php | Pool.batch | public static function batch(
ClientInterface $client,
$requests,
array $options = []
) {
$hash = new \SplObjectStorage();
foreach ($requests as $request) {
$hash->attach($request);
}
// In addition to the normally run events when requests complete, add
// and event to continuously track the results of transfers in the hash.
(new self($client, $requests, RequestEvents::convertEventArray(
$options,
['end'],
[
'priority' => RequestEvents::LATE,
'fn' => function (EndEvent $e) use ($hash) {
$hash[$e->getRequest()] = $e->getException()
? $e->getException()
: $e->getResponse();
}
]
)))->wait();
return new BatchResults($hash);
} | php | public static function batch(
ClientInterface $client,
$requests,
array $options = []
) {
$hash = new \SplObjectStorage();
foreach ($requests as $request) {
$hash->attach($request);
}
// In addition to the normally run events when requests complete, add
// and event to continuously track the results of transfers in the hash.
(new self($client, $requests, RequestEvents::convertEventArray(
$options,
['end'],
[
'priority' => RequestEvents::LATE,
'fn' => function (EndEvent $e) use ($hash) {
$hash[$e->getRequest()] = $e->getException()
? $e->getException()
: $e->getResponse();
}
]
)))->wait();
return new BatchResults($hash);
} | [
"public",
"static",
"function",
"batch",
"(",
"ClientInterface",
"$",
"client",
",",
"$",
"requests",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"hash",
"=",
"new",
"\\",
"SplObjectStorage",
"(",
")",
";",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"request",
")",
"{",
"$",
"hash",
"->",
"attach",
"(",
"$",
"request",
")",
";",
"}",
"// In addition to the normally run events when requests complete, add",
"// and event to continuously track the results of transfers in the hash.",
"(",
"new",
"self",
"(",
"$",
"client",
",",
"$",
"requests",
",",
"RequestEvents",
"::",
"convertEventArray",
"(",
"$",
"options",
",",
"[",
"'end'",
"]",
",",
"[",
"'priority'",
"=>",
"RequestEvents",
"::",
"LATE",
",",
"'fn'",
"=>",
"function",
"(",
"EndEvent",
"$",
"e",
")",
"use",
"(",
"$",
"hash",
")",
"{",
"$",
"hash",
"[",
"$",
"e",
"->",
"getRequest",
"(",
")",
"]",
"=",
"$",
"e",
"->",
"getException",
"(",
")",
"?",
"$",
"e",
"->",
"getException",
"(",
")",
":",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"}",
"]",
")",
")",
")",
"->",
"wait",
"(",
")",
";",
"return",
"new",
"BatchResults",
"(",
"$",
"hash",
")",
";",
"}"
] | Sends multiple requests in parallel and returns an array of responses
and exceptions that uses the same ordering as the provided requests.
IMPORTANT: This method keeps every request and response in memory, and
as such, is NOT recommended when sending a large number or an
indeterminate number of requests concurrently.
@param ClientInterface $client Client used to send the requests
@param array|\Iterator $requests Requests to send in parallel
@param array $options Passes through the options available in
{@see GuzzleHttp1\Pool::__construct}
@return BatchResults Returns a container for the results.
@throws \InvalidArgumentException if the event format is incorrect. | [
"Sends",
"multiple",
"requests",
"in",
"parallel",
"and",
"returns",
"an",
"array",
"of",
"responses",
"and",
"exceptions",
"that",
"uses",
"the",
"same",
"ordering",
"as",
"the",
"provided",
"requests",
"."
] | 9588a489c52b27e2d4047f146ddacffc3e111b7e | https://github.com/akumar2-velsof/guzzlehttp/blob/9588a489c52b27e2d4047f146ddacffc3e111b7e/src/Pool.php#L109-L135 | train |
akumar2-velsof/guzzlehttp | src/Pool.php | Pool.send | public static function send(
ClientInterface $client,
$requests,
array $options = []
) {
$pool = new self($client, $requests, $options);
$pool->wait();
} | php | public static function send(
ClientInterface $client,
$requests,
array $options = []
) {
$pool = new self($client, $requests, $options);
$pool->wait();
} | [
"public",
"static",
"function",
"send",
"(",
"ClientInterface",
"$",
"client",
",",
"$",
"requests",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"pool",
"=",
"new",
"self",
"(",
"$",
"client",
",",
"$",
"requests",
",",
"$",
"options",
")",
";",
"$",
"pool",
"->",
"wait",
"(",
")",
";",
"}"
] | Creates a Pool and immediately sends the requests.
@param ClientInterface $client Client used to send the requests
@param array|\Iterator $requests Requests to send in parallel
@param array $options Passes through the options available in
{@see GuzzleHttp1\Pool::__construct} | [
"Creates",
"a",
"Pool",
"and",
"immediately",
"sends",
"the",
"requests",
"."
] | 9588a489c52b27e2d4047f146ddacffc3e111b7e | https://github.com/akumar2-velsof/guzzlehttp/blob/9588a489c52b27e2d4047f146ddacffc3e111b7e/src/Pool.php#L145-L152 | train |
akumar2-velsof/guzzlehttp | src/Pool.php | Pool.addNextRequests | private function addNextRequests()
{
$limit = max($this->getPoolSize() - count($this->waitQueue), 0);
while ($limit--) {
if (!$this->addNextRequest()) {
break;
}
}
} | php | private function addNextRequests()
{
$limit = max($this->getPoolSize() - count($this->waitQueue), 0);
while ($limit--) {
if (!$this->addNextRequest()) {
break;
}
}
} | [
"private",
"function",
"addNextRequests",
"(",
")",
"{",
"$",
"limit",
"=",
"max",
"(",
"$",
"this",
"->",
"getPoolSize",
"(",
")",
"-",
"count",
"(",
"$",
"this",
"->",
"waitQueue",
")",
",",
"0",
")",
";",
"while",
"(",
"$",
"limit",
"--",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"addNextRequest",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"}"
] | Add as many requests as possible up to the current pool limit. | [
"Add",
"as",
"many",
"requests",
"as",
"possible",
"up",
"to",
"the",
"current",
"pool",
"limit",
"."
] | 9588a489c52b27e2d4047f146ddacffc3e111b7e | https://github.com/akumar2-velsof/guzzlehttp/blob/9588a489c52b27e2d4047f146ddacffc3e111b7e/src/Pool.php#L164-L172 | train |
akumar2-velsof/guzzlehttp | src/Pool.php | Pool.addNextRequest | private function addNextRequest()
{
add_next:
if ($this->isRealized || !$this->iter || !$this->iter->valid()) {
return false;
}
$request = $this->iter->current();
$this->iter->next();
if (!($request instanceof RequestInterface)) {
throw new \InvalidArgumentException(sprintf(
'All requests in the provided iterator must implement '
. 'RequestInterface. Found %s',
Core::describeType($request)
));
}
// Be sure to use "lazy" futures, meaning they do not send right away.
$request->getConfig()->set('future', 'lazy');
$hash = spl_object_hash($request);
$this->attachListeners($request, $this->eventListeners);
$request->getEmitter()->on('before', [$this, '_trackRetries'], RequestEvents::EARLY);
$response = $this->client->send($request);
$this->waitQueue[$hash] = $response;
$promise = $response->promise();
// Don't recursively call itself for completed or rejected responses.
if ($promise instanceof FulfilledPromise
|| $promise instanceof RejectedPromise
) {
try {
$this->finishResponse($request, $response->wait(), $hash);
} catch (\Exception $e) {
$this->finishResponse($request, $e, $hash);
}
goto add_next;
}
// Use this function for both resolution and rejection.
$thenFn = function ($value) use ($request, $hash) {
$this->finishResponse($request, $value, $hash);
if (!$request->getConfig()->get('_pool_retries')) {
$this->addNextRequests();
}
};
$promise->then($thenFn, $thenFn);
return true;
} | php | private function addNextRequest()
{
add_next:
if ($this->isRealized || !$this->iter || !$this->iter->valid()) {
return false;
}
$request = $this->iter->current();
$this->iter->next();
if (!($request instanceof RequestInterface)) {
throw new \InvalidArgumentException(sprintf(
'All requests in the provided iterator must implement '
. 'RequestInterface. Found %s',
Core::describeType($request)
));
}
// Be sure to use "lazy" futures, meaning they do not send right away.
$request->getConfig()->set('future', 'lazy');
$hash = spl_object_hash($request);
$this->attachListeners($request, $this->eventListeners);
$request->getEmitter()->on('before', [$this, '_trackRetries'], RequestEvents::EARLY);
$response = $this->client->send($request);
$this->waitQueue[$hash] = $response;
$promise = $response->promise();
// Don't recursively call itself for completed or rejected responses.
if ($promise instanceof FulfilledPromise
|| $promise instanceof RejectedPromise
) {
try {
$this->finishResponse($request, $response->wait(), $hash);
} catch (\Exception $e) {
$this->finishResponse($request, $e, $hash);
}
goto add_next;
}
// Use this function for both resolution and rejection.
$thenFn = function ($value) use ($request, $hash) {
$this->finishResponse($request, $value, $hash);
if (!$request->getConfig()->get('_pool_retries')) {
$this->addNextRequests();
}
};
$promise->then($thenFn, $thenFn);
return true;
} | [
"private",
"function",
"addNextRequest",
"(",
")",
"{",
"add_next",
":",
"if",
"(",
"$",
"this",
"->",
"isRealized",
"||",
"!",
"$",
"this",
"->",
"iter",
"||",
"!",
"$",
"this",
"->",
"iter",
"->",
"valid",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"iter",
"->",
"current",
"(",
")",
";",
"$",
"this",
"->",
"iter",
"->",
"next",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"request",
"instanceof",
"RequestInterface",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'All requests in the provided iterator must implement '",
".",
"'RequestInterface. Found %s'",
",",
"Core",
"::",
"describeType",
"(",
"$",
"request",
")",
")",
")",
";",
"}",
"// Be sure to use \"lazy\" futures, meaning they do not send right away.",
"$",
"request",
"->",
"getConfig",
"(",
")",
"->",
"set",
"(",
"'future'",
",",
"'lazy'",
")",
";",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"attachListeners",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"eventListeners",
")",
";",
"$",
"request",
"->",
"getEmitter",
"(",
")",
"->",
"on",
"(",
"'before'",
",",
"[",
"$",
"this",
",",
"'_trackRetries'",
"]",
",",
"RequestEvents",
"::",
"EARLY",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"waitQueue",
"[",
"$",
"hash",
"]",
"=",
"$",
"response",
";",
"$",
"promise",
"=",
"$",
"response",
"->",
"promise",
"(",
")",
";",
"// Don't recursively call itself for completed or rejected responses.",
"if",
"(",
"$",
"promise",
"instanceof",
"FulfilledPromise",
"||",
"$",
"promise",
"instanceof",
"RejectedPromise",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"finishResponse",
"(",
"$",
"request",
",",
"$",
"response",
"->",
"wait",
"(",
")",
",",
"$",
"hash",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"finishResponse",
"(",
"$",
"request",
",",
"$",
"e",
",",
"$",
"hash",
")",
";",
"}",
"goto",
"add_next",
";",
"}",
"// Use this function for both resolution and rejection.",
"$",
"thenFn",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"request",
",",
"$",
"hash",
")",
"{",
"$",
"this",
"->",
"finishResponse",
"(",
"$",
"request",
",",
"$",
"value",
",",
"$",
"hash",
")",
";",
"if",
"(",
"!",
"$",
"request",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'_pool_retries'",
")",
")",
"{",
"$",
"this",
"->",
"addNextRequests",
"(",
")",
";",
"}",
"}",
";",
"$",
"promise",
"->",
"then",
"(",
"$",
"thenFn",
",",
"$",
"thenFn",
")",
";",
"return",
"true",
";",
"}"
] | Adds the next request to pool and tracks what requests need to be
dereferenced when completing the pool. | [
"Adds",
"the",
"next",
"request",
"to",
"pool",
"and",
"tracks",
"what",
"requests",
"need",
"to",
"be",
"dereferenced",
"when",
"completing",
"the",
"pool",
"."
] | 9588a489c52b27e2d4047f146ddacffc3e111b7e | https://github.com/akumar2-velsof/guzzlehttp/blob/9588a489c52b27e2d4047f146ddacffc3e111b7e/src/Pool.php#L267-L318 | train |
ellipsephp/handlers-adr | src/ActionRequestHandler.php | ActionRequestHandler.handle | public function handle(ServerRequestInterface $request): ResponseInterface
{
$input = $this->input($request);
$payload = $this->domain->payload($input);
return $this->responder->response($request, $payload);
} | php | public function handle(ServerRequestInterface $request): ResponseInterface
{
$input = $this->input($request);
$payload = $this->domain->payload($input);
return $this->responder->response($request, $payload);
} | [
"public",
"function",
"handle",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"input",
"(",
"$",
"request",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"domain",
"->",
"payload",
"(",
"$",
"input",
")",
";",
"return",
"$",
"this",
"->",
"responder",
"->",
"response",
"(",
"$",
"request",
",",
"$",
"payload",
")",
";",
"}"
] | Return a response by following the action domain responder pattern.
@param \Psr\Http\Message\ServerRequestInterface $request
@return \Psr\Http\Message\ResponseInterface | [
"Return",
"a",
"response",
"by",
"following",
"the",
"action",
"domain",
"responder",
"pattern",
"."
] | 1c0879494a8b7718f7e157d0cd41b4c5ec19b5c5 | https://github.com/ellipsephp/handlers-adr/blob/1c0879494a8b7718f7e157d0cd41b4c5ec19b5c5/src/ActionRequestHandler.php#L57-L64 | train |
ellipsephp/handlers-adr | src/ActionRequestHandler.php | ActionRequestHandler.input | private function input(ServerRequestInterface $request): array
{
if (! is_null($this->parser)) {
$input = ($this->parser)($request);
if (is_array($input)) {
return $input;
}
throw new InputTypeException($input);
}
return array_merge(
$request->getAttributes(),
$request->getQueryParams(),
$request->getParsedBody(),
$request->getUploadedFiles()
);
} | php | private function input(ServerRequestInterface $request): array
{
if (! is_null($this->parser)) {
$input = ($this->parser)($request);
if (is_array($input)) {
return $input;
}
throw new InputTypeException($input);
}
return array_merge(
$request->getAttributes(),
$request->getQueryParams(),
$request->getParsedBody(),
$request->getUploadedFiles()
);
} | [
"private",
"function",
"input",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"parser",
")",
")",
"{",
"$",
"input",
"=",
"(",
"$",
"this",
"->",
"parser",
")",
"(",
"$",
"request",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"input",
")",
")",
"{",
"return",
"$",
"input",
";",
"}",
"throw",
"new",
"InputTypeException",
"(",
"$",
"input",
")",
";",
"}",
"return",
"array_merge",
"(",
"$",
"request",
"->",
"getAttributes",
"(",
")",
",",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
",",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
",",
"$",
"request",
"->",
"getUploadedFiles",
"(",
")",
")",
";",
"}"
] | Return an input array from the given request using the request parser.
@param \Psr\Http\Message\ServerRequestInterface $request
@return array
@throws \Ellipse\Handlers\Exceptions\InputTypeException | [
"Return",
"an",
"input",
"array",
"from",
"the",
"given",
"request",
"using",
"the",
"request",
"parser",
"."
] | 1c0879494a8b7718f7e157d0cd41b4c5ec19b5c5 | https://github.com/ellipsephp/handlers-adr/blob/1c0879494a8b7718f7e157d0cd41b4c5ec19b5c5/src/ActionRequestHandler.php#L73-L95 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Languages.php | Radial_Core_Helper_Languages.getStores | public function getStores($langCode = null)
{
$stores = array();
foreach (Mage::app()->getWebsites() as $website) {
$stores = array_replace($stores, $this->getWebsiteStores($website, $langCode));
}
return $stores;
} | php | public function getStores($langCode = null)
{
$stores = array();
foreach (Mage::app()->getWebsites() as $website) {
$stores = array_replace($stores, $this->getWebsiteStores($website, $langCode));
}
return $stores;
} | [
"public",
"function",
"getStores",
"(",
"$",
"langCode",
"=",
"null",
")",
"{",
"$",
"stores",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"Mage",
"::",
"app",
"(",
")",
"->",
"getWebsites",
"(",
")",
"as",
"$",
"website",
")",
"{",
"$",
"stores",
"=",
"array_replace",
"(",
"$",
"stores",
",",
"$",
"this",
"->",
"getWebsiteStores",
"(",
"$",
"website",
",",
"$",
"langCode",
")",
")",
";",
"}",
"return",
"$",
"stores",
";",
"}"
] | Return an array of stores and attach a language code to them, Varien_Object style
@param string $langCode (optional) if passed, only stores using that langCode are returned.
@return array of Mage_Core_Model_Store, keyed by StoreId. Each store has a new magic getter 'getLanguageCode()' | [
"Return",
"an",
"array",
"of",
"stores",
"and",
"attach",
"a",
"language",
"code",
"to",
"them",
"Varien_Object",
"style"
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Languages.php#L61-L68 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Languages.php | Radial_Core_Helper_Languages.getWebsiteStores | public function getWebsiteStores($website, $langCode = null)
{
$stores = array();
$config = Mage::helper('radial_core')->getConfigModel();
$website = Mage::app()->getWebsite($website);
foreach ($website->getGroups() as $group) {
foreach ($group->getStores() as $store) {
$storeId = $store->getStoreId();
$config->setStore($storeId);
if (!$langCode || ($langCode === $config->languageCode)) {
$store->setLanguageCode($config->languageCode);
$stores[$storeId] = $store;
}
}
}
return $stores;
} | php | public function getWebsiteStores($website, $langCode = null)
{
$stores = array();
$config = Mage::helper('radial_core')->getConfigModel();
$website = Mage::app()->getWebsite($website);
foreach ($website->getGroups() as $group) {
foreach ($group->getStores() as $store) {
$storeId = $store->getStoreId();
$config->setStore($storeId);
if (!$langCode || ($langCode === $config->languageCode)) {
$store->setLanguageCode($config->languageCode);
$stores[$storeId] = $store;
}
}
}
return $stores;
} | [
"public",
"function",
"getWebsiteStores",
"(",
"$",
"website",
",",
"$",
"langCode",
"=",
"null",
")",
"{",
"$",
"stores",
"=",
"array",
"(",
")",
";",
"$",
"config",
"=",
"Mage",
"::",
"helper",
"(",
"'radial_core'",
")",
"->",
"getConfigModel",
"(",
")",
";",
"$",
"website",
"=",
"Mage",
"::",
"app",
"(",
")",
"->",
"getWebsite",
"(",
"$",
"website",
")",
";",
"foreach",
"(",
"$",
"website",
"->",
"getGroups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"foreach",
"(",
"$",
"group",
"->",
"getStores",
"(",
")",
"as",
"$",
"store",
")",
"{",
"$",
"storeId",
"=",
"$",
"store",
"->",
"getStoreId",
"(",
")",
";",
"$",
"config",
"->",
"setStore",
"(",
"$",
"storeId",
")",
";",
"if",
"(",
"!",
"$",
"langCode",
"||",
"(",
"$",
"langCode",
"===",
"$",
"config",
"->",
"languageCode",
")",
")",
"{",
"$",
"store",
"->",
"setLanguageCode",
"(",
"$",
"config",
"->",
"languageCode",
")",
";",
"$",
"stores",
"[",
"$",
"storeId",
"]",
"=",
"$",
"store",
";",
"}",
"}",
"}",
"return",
"$",
"stores",
";",
"}"
] | Return an array of stores for the given website and attach a language code to them, Varien_Object style
@param mixed $website the website to get stores from.
@param string $langCode (optional) if passed, only stores using that langCode are returned.
@return array of Mage_Core_Model_Store, keyed by StoreId. Each store has a new magic getter 'getLanguageCode()' | [
"Return",
"an",
"array",
"of",
"stores",
"for",
"the",
"given",
"website",
"and",
"attach",
"a",
"language",
"code",
"to",
"them",
"Varien_Object",
"style"
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Languages.php#L75-L91 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Languages.php | Radial_Core_Helper_Languages.getLanguageCodesList | public function getLanguageCodesList()
{
$languages = array();
foreach ($this->getStores() as $store) {
$languages[] = $store->getLanguageCode();
}
return array_unique($languages);
} | php | public function getLanguageCodesList()
{
$languages = array();
foreach ($this->getStores() as $store) {
$languages[] = $store->getLanguageCode();
}
return array_unique($languages);
} | [
"public",
"function",
"getLanguageCodesList",
"(",
")",
"{",
"$",
"languages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getStores",
"(",
")",
"as",
"$",
"store",
")",
"{",
"$",
"languages",
"[",
"]",
"=",
"$",
"store",
"->",
"getLanguageCode",
"(",
")",
";",
"}",
"return",
"array_unique",
"(",
"$",
"languages",
")",
";",
"}"
] | Get a simple array of all language codes used in this installation
@return array | [
"Get",
"a",
"simple",
"array",
"of",
"all",
"language",
"codes",
"used",
"in",
"this",
"installation"
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Languages.php#L96-L103 | train |
rkeet/zf-doctrine-mvc | src/Controller/AbstractActionController.php | AbstractActionController.redirectToRoute | public function redirectToRoute()
{
if ($this->getRequest()
->isXmlHttpRequest()) {
return [
'redirect' => call_user_func_array(
[
$this->url(),
'fromRoute',
],
func_get_args()
),
];
}
return call_user_func_array(
[
$this->redirect(),
'toRoute',
],
func_get_args()
);
} | php | public function redirectToRoute()
{
if ($this->getRequest()
->isXmlHttpRequest()) {
return [
'redirect' => call_user_func_array(
[
$this->url(),
'fromRoute',
],
func_get_args()
),
];
}
return call_user_func_array(
[
$this->redirect(),
'toRoute',
],
func_get_args()
);
} | [
"public",
"function",
"redirectToRoute",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"return",
"[",
"'redirect'",
"=>",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"url",
"(",
")",
",",
"'fromRoute'",
",",
"]",
",",
"func_get_args",
"(",
")",
")",
",",
"]",
";",
"}",
"return",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"redirect",
"(",
")",
",",
"'toRoute'",
",",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] | Redirect to a route, or pass the url to the view for a javascript redirect
@return mixed|\Zend\Http\Response | [
"Redirect",
"to",
"a",
"route",
"or",
"pass",
"the",
"url",
"to",
"the",
"view",
"for",
"a",
"javascript",
"redirect"
] | ec5fb19e453824383b39570d15bd77b85cec3ca1 | https://github.com/rkeet/zf-doctrine-mvc/blob/ec5fb19e453824383b39570d15bd77b85cec3ca1/src/Controller/AbstractActionController.php#L14-L36 | train |
dark-prospect-games/obsidian-moon-engine | src/Modules/Input.php | Input.fetchFromArray | protected function fetchFromArray(
array $array,
string $index = '',
$xss_clean = false
) {
if (!array_key_exists($index, $array)) {
return false;
}
// Checks to see if the variable is set, since 0 returns as false.
if ($xss_clean === 'isset') {
return array_key_exists($index, $array);
}
return $array[$index];
} | php | protected function fetchFromArray(
array $array,
string $index = '',
$xss_clean = false
) {
if (!array_key_exists($index, $array)) {
return false;
}
// Checks to see if the variable is set, since 0 returns as false.
if ($xss_clean === 'isset') {
return array_key_exists($index, $array);
}
return $array[$index];
} | [
"protected",
"function",
"fetchFromArray",
"(",
"array",
"$",
"array",
",",
"string",
"$",
"index",
"=",
"''",
",",
"$",
"xss_clean",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Checks to see if the variable is set, since 0 returns as false.",
"if",
"(",
"$",
"xss_clean",
"===",
"'isset'",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"array",
")",
";",
"}",
"return",
"$",
"array",
"[",
"$",
"index",
"]",
";",
"}"
] | The function that will handle getting the data from the arrays.
@param mixed $array The array that will pulled from.
@param string $index What we are looking for.
@param boolean $xss_clean Whether to clean it or not or not. Incomplete.
@since 1.0.0
@return mixed | [
"The",
"function",
"that",
"will",
"handle",
"getting",
"the",
"data",
"from",
"the",
"arrays",
"."
] | 83b82990bdea79960a93b52f963cc81b6fa009ba | https://github.com/dark-prospect-games/obsidian-moon-engine/blob/83b82990bdea79960a93b52f963cc81b6fa009ba/src/Modules/Input.php#L60-L75 | train |
acacha/forge-publish | src/Console/Commands/PublishKeyGenerate.php | PublishKeyGenerate.keyIsAlreadyInstalled | protected function keyIsAlreadyInstalled()
{
$key = 'APP_KEY=base64:';
$output = $this->execSSH("cd $this->domain;cat .env");
if (str_contains($output, $key)) {
return true;
}
return false;
} | php | protected function keyIsAlreadyInstalled()
{
$key = 'APP_KEY=base64:';
$output = $this->execSSH("cd $this->domain;cat .env");
if (str_contains($output, $key)) {
return true;
}
return false;
} | [
"protected",
"function",
"keyIsAlreadyInstalled",
"(",
")",
"{",
"$",
"key",
"=",
"'APP_KEY=base64:'",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"execSSH",
"(",
"\"cd $this->domain;cat .env\"",
")",
";",
"if",
"(",
"str_contains",
"(",
"$",
"output",
",",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Key is already installed on production?
@return bool | [
"Key",
"is",
"already",
"installed",
"on",
"production?"
] | 010779e3d2297c763b82dc3fbde992edffb3a6c6 | https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/PublishKeyGenerate.php#L88-L96 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.getRouteInfo | public function getRouteInfo()
{
if ($this->isSingle()) {
if (isset($this->containers['route_info']) && ($controller = $this->containers['route_info']->get('controller'))
&& ($action = $this->containers['route_info']->get('action'))
) {
return ['controller' => $controller, 'action' => $action];
}
}
return ['controller' => 'index', 'action' => 'index'];
} | php | public function getRouteInfo()
{
if ($this->isSingle()) {
if (isset($this->containers['route_info']) && ($controller = $this->containers['route_info']->get('controller'))
&& ($action = $this->containers['route_info']->get('action'))
) {
return ['controller' => $controller, 'action' => $action];
}
}
return ['controller' => 'index', 'action' => 'index'];
} | [
"public",
"function",
"getRouteInfo",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
")",
"&&",
"(",
"$",
"controller",
"=",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
"->",
"get",
"(",
"'controller'",
")",
")",
"&&",
"(",
"$",
"action",
"=",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
"->",
"get",
"(",
"'action'",
")",
")",
")",
"{",
"return",
"[",
"'controller'",
"=>",
"$",
"controller",
",",
"'action'",
"=>",
"$",
"action",
"]",
";",
"}",
"}",
"return",
"[",
"'controller'",
"=>",
"'index'",
",",
"'action'",
"=>",
"'index'",
"]",
";",
"}"
] | Get Route Info
@return array | [
"Get",
"Route",
"Info"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L197-L207 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.isHome | public function isHome()
{
if ($this->isSingle()) {
if (isset($this->containers['route_info'])) {
$home_controller = 'index';
$home_action = 'index';
$home = $this->getHome();
if ($home && isset($home['controller']) && isset($home['action']) && $home['controller'] && $home['action']) {
$home_controller = $home['controller'];
$home_action = $home['action'];
}
if ($this->containers['route_info']->get('controller') == $home_controller && $this->containers['route_info']->get('action') == $home_action) {
return true;
}
}
}
return false;
} | php | public function isHome()
{
if ($this->isSingle()) {
if (isset($this->containers['route_info'])) {
$home_controller = 'index';
$home_action = 'index';
$home = $this->getHome();
if ($home && isset($home['controller']) && isset($home['action']) && $home['controller'] && $home['action']) {
$home_controller = $home['controller'];
$home_action = $home['action'];
}
if ($this->containers['route_info']->get('controller') == $home_controller && $this->containers['route_info']->get('action') == $home_action) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"isHome",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
")",
")",
"{",
"$",
"home_controller",
"=",
"'index'",
";",
"$",
"home_action",
"=",
"'index'",
";",
"$",
"home",
"=",
"$",
"this",
"->",
"getHome",
"(",
")",
";",
"if",
"(",
"$",
"home",
"&&",
"isset",
"(",
"$",
"home",
"[",
"'controller'",
"]",
")",
"&&",
"isset",
"(",
"$",
"home",
"[",
"'action'",
"]",
")",
"&&",
"$",
"home",
"[",
"'controller'",
"]",
"&&",
"$",
"home",
"[",
"'action'",
"]",
")",
"{",
"$",
"home_controller",
"=",
"$",
"home",
"[",
"'controller'",
"]",
";",
"$",
"home_action",
"=",
"$",
"home",
"[",
"'action'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
"->",
"get",
"(",
"'controller'",
")",
"==",
"$",
"home_controller",
"&&",
"$",
"this",
"->",
"containers",
"[",
"'route_info'",
"]",
"->",
"get",
"(",
"'action'",
")",
"==",
"$",
"home_action",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | If is home | [
"If",
"is",
"home"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L210-L227 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.getHomeUri | public function getHomeUri()
{
$homeUri = '';
if ($this->isSingle()) {
$controller = 'index';
$action = 'index';
$home = $this->getHome();
if (isset($home['controller']) && isset($home['action']) && $home['controller'] && $home['action']) {
$controller = $home['controller'];
$action = $home['action'];
}
if ($this->isPrettyUrl()) {
$homeUri = $this->createRelativeUrl("/{$controller}/action/{$action}");
} else {
$homeUri = $this->createRelativeUrl('/index.php', [$controller, 'action' => $action]);
}
}
return $homeUri;
} | php | public function getHomeUri()
{
$homeUri = '';
if ($this->isSingle()) {
$controller = 'index';
$action = 'index';
$home = $this->getHome();
if (isset($home['controller']) && isset($home['action']) && $home['controller'] && $home['action']) {
$controller = $home['controller'];
$action = $home['action'];
}
if ($this->isPrettyUrl()) {
$homeUri = $this->createRelativeUrl("/{$controller}/action/{$action}");
} else {
$homeUri = $this->createRelativeUrl('/index.php', [$controller, 'action' => $action]);
}
}
return $homeUri;
} | [
"public",
"function",
"getHomeUri",
"(",
")",
"{",
"$",
"homeUri",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"$",
"controller",
"=",
"'index'",
";",
"$",
"action",
"=",
"'index'",
";",
"$",
"home",
"=",
"$",
"this",
"->",
"getHome",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"home",
"[",
"'controller'",
"]",
")",
"&&",
"isset",
"(",
"$",
"home",
"[",
"'action'",
"]",
")",
"&&",
"$",
"home",
"[",
"'controller'",
"]",
"&&",
"$",
"home",
"[",
"'action'",
"]",
")",
"{",
"$",
"controller",
"=",
"$",
"home",
"[",
"'controller'",
"]",
";",
"$",
"action",
"=",
"$",
"home",
"[",
"'action'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isPrettyUrl",
"(",
")",
")",
"{",
"$",
"homeUri",
"=",
"$",
"this",
"->",
"createRelativeUrl",
"(",
"\"/{$controller}/action/{$action}\"",
")",
";",
"}",
"else",
"{",
"$",
"homeUri",
"=",
"$",
"this",
"->",
"createRelativeUrl",
"(",
"'/index.php'",
",",
"[",
"$",
"controller",
",",
"'action'",
"=>",
"$",
"action",
"]",
")",
";",
"}",
"}",
"return",
"$",
"homeUri",
";",
"}"
] | Get Home Uri | [
"Get",
"Home",
"Uri"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L230-L248 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.getDb | public function getDb($db_type, $node_type)
{
if ($this->isSingle()) {
switch ($db_type) {
case Connection::DB_TYPE:
switch ($node_type) {
case 'master':
return Connection::component()->write_conn;
case 'slave':
return Connection::component()->read_conn;
default:
return Connection::component()->write_conn;
}
case \lb\components\db\mongodb\Connection::DB_TYPE :
return \lb\components\db\mongodb\Connection::component()->_conn;
default:
return false;
}
}
return false;
} | php | public function getDb($db_type, $node_type)
{
if ($this->isSingle()) {
switch ($db_type) {
case Connection::DB_TYPE:
switch ($node_type) {
case 'master':
return Connection::component()->write_conn;
case 'slave':
return Connection::component()->read_conn;
default:
return Connection::component()->write_conn;
}
case \lb\components\db\mongodb\Connection::DB_TYPE :
return \lb\components\db\mongodb\Connection::component()->_conn;
default:
return false;
}
}
return false;
} | [
"public",
"function",
"getDb",
"(",
"$",
"db_type",
",",
"$",
"node_type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"switch",
"(",
"$",
"db_type",
")",
"{",
"case",
"Connection",
"::",
"DB_TYPE",
":",
"switch",
"(",
"$",
"node_type",
")",
"{",
"case",
"'master'",
":",
"return",
"Connection",
"::",
"component",
"(",
")",
"->",
"write_conn",
";",
"case",
"'slave'",
":",
"return",
"Connection",
"::",
"component",
"(",
")",
"->",
"read_conn",
";",
"default",
":",
"return",
"Connection",
"::",
"component",
"(",
")",
"->",
"write_conn",
";",
"}",
"case",
"\\",
"lb",
"\\",
"components",
"\\",
"db",
"\\",
"mongodb",
"\\",
"Connection",
"::",
"DB_TYPE",
":",
"return",
"\\",
"lb",
"\\",
"components",
"\\",
"db",
"\\",
"mongodb",
"\\",
"Connection",
"::",
"component",
"(",
")",
"->",
"_conn",
";",
"default",
":",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get Db Connection | [
"Get",
"Db",
"Connection"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L282-L302 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.createAbsoluteUrl | public function createAbsoluteUrl($uri, $query_params = [], $ssl = false, $port = 80, $request = null)
{
if ($this->isSingle()) {
return UrlManager::createAbsoluteUrl($uri, $query_params, $ssl, $port, $request);
}
return '';
} | php | public function createAbsoluteUrl($uri, $query_params = [], $ssl = false, $port = 80, $request = null)
{
if ($this->isSingle()) {
return UrlManager::createAbsoluteUrl($uri, $query_params, $ssl, $port, $request);
}
return '';
} | [
"public",
"function",
"createAbsoluteUrl",
"(",
"$",
"uri",
",",
"$",
"query_params",
"=",
"[",
"]",
",",
"$",
"ssl",
"=",
"false",
",",
"$",
"port",
"=",
"80",
",",
"$",
"request",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"return",
"UrlManager",
"::",
"createAbsoluteUrl",
"(",
"$",
"uri",
",",
"$",
"query_params",
",",
"$",
"ssl",
",",
"$",
"port",
",",
"$",
"request",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Create Absolute Url | [
"Create",
"Absolute",
"Url"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L313-L319 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.getParam | public function getParam($param_name, $default_value = null)
{
if ($this->isSingle()) {
return RequestKit::getParam($param_name, $default_value);
}
return false;
} | php | public function getParam($param_name, $default_value = null)
{
if ($this->isSingle()) {
return RequestKit::getParam($param_name, $default_value);
}
return false;
} | [
"public",
"function",
"getParam",
"(",
"$",
"param_name",
",",
"$",
"default_value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"return",
"RequestKit",
"::",
"getParam",
"(",
"$",
"param_name",
",",
"$",
"default_value",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get Http Request Param Value | [
"Get",
"Http",
"Request",
"Param",
"Value"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L331-L337 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.import | public function import($path)
{
if ($this->isSingle()) {
if (file_exists($path) && strtolower(FileHelper::getExtensionName($path)) == 'php') {
include_once str_replace(Security::INSECURE_CODES, '', $path);
}
}
} | php | public function import($path)
{
if ($this->isSingle()) {
if (file_exists($path) && strtolower(FileHelper::getExtensionName($path)) == 'php') {
include_once str_replace(Security::INSECURE_CODES, '', $path);
}
}
} | [
"public",
"function",
"import",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
"&&",
"strtolower",
"(",
"FileHelper",
"::",
"getExtensionName",
"(",
"$",
"path",
")",
")",
"==",
"'php'",
")",
"{",
"include_once",
"str_replace",
"(",
"Security",
"::",
"INSECURE_CODES",
",",
"''",
",",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Import PHP File | [
"Import",
"PHP",
"File"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L367-L374 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.swiftSend | public function swiftSend(
$from_name,
$receivers,
&$successfulRecipients,
&$failedRecipients,
$subject = '',
$body = '',
$content_type = 'text/html',
$charset = 'UTF-8'
) {
if ($this->isSingle()) {
Swift::component()->send(
$from_name,
$receivers,
$successfulRecipients,
$failedRecipients,
$subject,
$body,
$content_type,
$charset
);
}
} | php | public function swiftSend(
$from_name,
$receivers,
&$successfulRecipients,
&$failedRecipients,
$subject = '',
$body = '',
$content_type = 'text/html',
$charset = 'UTF-8'
) {
if ($this->isSingle()) {
Swift::component()->send(
$from_name,
$receivers,
$successfulRecipients,
$failedRecipients,
$subject,
$body,
$content_type,
$charset
);
}
} | [
"public",
"function",
"swiftSend",
"(",
"$",
"from_name",
",",
"$",
"receivers",
",",
"&",
"$",
"successfulRecipients",
",",
"&",
"$",
"failedRecipients",
",",
"$",
"subject",
"=",
"''",
",",
"$",
"body",
"=",
"''",
",",
"$",
"content_type",
"=",
"'text/html'",
",",
"$",
"charset",
"=",
"'UTF-8'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"Swift",
"::",
"component",
"(",
")",
"->",
"send",
"(",
"$",
"from_name",
",",
"$",
"receivers",
",",
"$",
"successfulRecipients",
",",
"$",
"failedRecipients",
",",
"$",
"subject",
",",
"$",
"body",
",",
"$",
"content_type",
",",
"$",
"charset",
")",
";",
"}",
"}"
] | Send Swift Mail | [
"Send",
"Swift",
"Mail"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L386-L409 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.loginRequired | public function loginRequired($redirect_url, $request = null, $response = null)
{
if ($this->isSingle()) {
User::loginRequired($redirect_url, $request, $response);
}
} | php | public function loginRequired($redirect_url, $request = null, $response = null)
{
if ($this->isSingle()) {
User::loginRequired($redirect_url, $request, $response);
}
} | [
"public",
"function",
"loginRequired",
"(",
"$",
"redirect_url",
",",
"$",
"request",
"=",
"null",
",",
"$",
"response",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"User",
"::",
"loginRequired",
"(",
"$",
"redirect_url",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"}"
] | Check If Logged In
@param $redirect_url
@param RequestContract $request
@param ResponseContract $response | [
"Check",
"If",
"Logged",
"In"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L418-L423 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.isAction | public function isAction($request = null)
{
$is_action = false;
if ($this->isSingle()) {
$queryString = $request ? $request->getQueryString() : Lb::app()->getQueryString();
$requestUri = $request ? $request->getUri() : Lb::app()->getUri();
if (Lb::app()->isPrettyUrl()) {
$requestUri = str_replace('?' . $queryString, '', $requestUri);
if (!trim($requestUri, '/') || stripos($requestUri, '/action/') !== false) {
$is_action = true;
}
} else {
if (!trim($requestUri, '/') || stripos($queryString, 'action=') !== false) {
$is_action = true;
}
}
}
return $is_action;
} | php | public function isAction($request = null)
{
$is_action = false;
if ($this->isSingle()) {
$queryString = $request ? $request->getQueryString() : Lb::app()->getQueryString();
$requestUri = $request ? $request->getUri() : Lb::app()->getUri();
if (Lb::app()->isPrettyUrl()) {
$requestUri = str_replace('?' . $queryString, '', $requestUri);
if (!trim($requestUri, '/') || stripos($requestUri, '/action/') !== false) {
$is_action = true;
}
} else {
if (!trim($requestUri, '/') || stripos($queryString, 'action=') !== false) {
$is_action = true;
}
}
}
return $is_action;
} | [
"public",
"function",
"isAction",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"is_action",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"$",
"queryString",
"=",
"$",
"request",
"?",
"$",
"request",
"->",
"getQueryString",
"(",
")",
":",
"Lb",
"::",
"app",
"(",
")",
"->",
"getQueryString",
"(",
")",
";",
"$",
"requestUri",
"=",
"$",
"request",
"?",
"$",
"request",
"->",
"getUri",
"(",
")",
":",
"Lb",
"::",
"app",
"(",
")",
"->",
"getUri",
"(",
")",
";",
"if",
"(",
"Lb",
"::",
"app",
"(",
")",
"->",
"isPrettyUrl",
"(",
")",
")",
"{",
"$",
"requestUri",
"=",
"str_replace",
"(",
"'?'",
".",
"$",
"queryString",
",",
"''",
",",
"$",
"requestUri",
")",
";",
"if",
"(",
"!",
"trim",
"(",
"$",
"requestUri",
",",
"'/'",
")",
"||",
"stripos",
"(",
"$",
"requestUri",
",",
"'/action/'",
")",
"!==",
"false",
")",
"{",
"$",
"is_action",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"trim",
"(",
"$",
"requestUri",
",",
"'/'",
")",
"||",
"stripos",
"(",
"$",
"queryString",
",",
"'action='",
")",
"!==",
"false",
")",
"{",
"$",
"is_action",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"$",
"is_action",
";",
"}"
] | Detect Action Exists
@param RequestContract $request
@return bool | [
"Detect",
"Action",
"Exists"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L478-L496 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.get_rpc_client | public function get_rpc_client($url)
{
if ($this->isSingle()) {
include_once Lb::app()->getRootDir() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'hprose' .
DIRECTORY_SEPARATOR . 'hprose' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Hprose.php';
return new \Hprose\Http\Client($url);
}
return false;
} | php | public function get_rpc_client($url)
{
if ($this->isSingle()) {
include_once Lb::app()->getRootDir() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'hprose' .
DIRECTORY_SEPARATOR . 'hprose' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Hprose.php';
return new \Hprose\Http\Client($url);
}
return false;
} | [
"public",
"function",
"get_rpc_client",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"include_once",
"Lb",
"::",
"app",
"(",
")",
"->",
"getRootDir",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'vendor'",
".",
"DIRECTORY_SEPARATOR",
".",
"'hprose'",
".",
"DIRECTORY_SEPARATOR",
".",
"'hprose'",
".",
"DIRECTORY_SEPARATOR",
".",
"'src'",
".",
"DIRECTORY_SEPARATOR",
".",
"'Hprose.php'",
";",
"return",
"new",
"\\",
"Hprose",
"\\",
"Http",
"\\",
"Client",
"(",
"$",
"url",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get RPC Client | [
"Get",
"RPC",
"Client"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L551-L559 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.on | public function on($event_name, $listener, $data = null)
{
if ($this->isSingle()) {
BaseObserver::on($event_name, $listener, $data);
}
} | php | public function on($event_name, $listener, $data = null)
{
if ($this->isSingle()) {
BaseObserver::on($event_name, $listener, $data);
}
} | [
"public",
"function",
"on",
"(",
"$",
"event_name",
",",
"$",
"listener",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"BaseObserver",
"::",
"on",
"(",
"$",
"event_name",
",",
"$",
"listener",
",",
"$",
"data",
")",
";",
"}",
"}"
] | Register Event Listener | [
"Register",
"Event",
"Listener"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L571-L576 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.dispatchJob | public function dispatchJob($job, $data = [], $handler = 'handler')
{
if ($this->isSingle()) {
if (!is_object($job)) {
$job = new $job;
}
return call_user_func_array([$job, $handler], ['data' => $data]);
}
return null;
} | php | public function dispatchJob($job, $data = [], $handler = 'handler')
{
if ($this->isSingle()) {
if (!is_object($job)) {
$job = new $job;
}
return call_user_func_array([$job, $handler], ['data' => $data]);
}
return null;
} | [
"public",
"function",
"dispatchJob",
"(",
"$",
"job",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"handler",
"=",
"'handler'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingle",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"job",
")",
")",
"{",
"$",
"job",
"=",
"new",
"$",
"job",
";",
"}",
"return",
"call_user_func_array",
"(",
"[",
"$",
"job",
",",
"$",
"handler",
"]",
",",
"[",
"'data'",
"=>",
"$",
"data",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Dispatch a job
@param $job
@param array $data
@param string $handler
@return mixed | [
"Dispatch",
"a",
"job"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L609-L619 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.loadEnv | protected function loadEnv()
{
if (defined('ENV_DIR') && file_exists(ENV_DIR)) {
if (defined('ENV_FILE') && file_exists(ENV_FILE)) {
$dotenv = new \Dotenv\Dotenv(ENV_DIR, ENV_FILE);
} else {
$dotenv = new \Dotenv\Dotenv(ENV_DIR);
}
$dotenv->load();
}
} | php | protected function loadEnv()
{
if (defined('ENV_DIR') && file_exists(ENV_DIR)) {
if (defined('ENV_FILE') && file_exists(ENV_FILE)) {
$dotenv = new \Dotenv\Dotenv(ENV_DIR, ENV_FILE);
} else {
$dotenv = new \Dotenv\Dotenv(ENV_DIR);
}
$dotenv->load();
}
} | [
"protected",
"function",
"loadEnv",
"(",
")",
"{",
"if",
"(",
"defined",
"(",
"'ENV_DIR'",
")",
"&&",
"file_exists",
"(",
"ENV_DIR",
")",
")",
"{",
"if",
"(",
"defined",
"(",
"'ENV_FILE'",
")",
"&&",
"file_exists",
"(",
"ENV_FILE",
")",
")",
"{",
"$",
"dotenv",
"=",
"new",
"\\",
"Dotenv",
"\\",
"Dotenv",
"(",
"ENV_DIR",
",",
"ENV_FILE",
")",
";",
"}",
"else",
"{",
"$",
"dotenv",
"=",
"new",
"\\",
"Dotenv",
"\\",
"Dotenv",
"(",
"ENV_DIR",
")",
";",
"}",
"$",
"dotenv",
"->",
"load",
"(",
")",
";",
"}",
"}"
] | Load Environment Variables | [
"Load",
"Environment",
"Variables"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L667-L677 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.getPageCache | protected function getPageCache($cache_type)
{
$route_info = Lb::app()->getRouteInfo();
$page_cache_key = implode('_', ['page_cache', $route_info['controller'], $route_info['action']]);
return Lb::app()->getCache($page_cache_key, $cache_type);
} | php | protected function getPageCache($cache_type)
{
$route_info = Lb::app()->getRouteInfo();
$page_cache_key = implode('_', ['page_cache', $route_info['controller'], $route_info['action']]);
return Lb::app()->getCache($page_cache_key, $cache_type);
} | [
"protected",
"function",
"getPageCache",
"(",
"$",
"cache_type",
")",
"{",
"$",
"route_info",
"=",
"Lb",
"::",
"app",
"(",
")",
"->",
"getRouteInfo",
"(",
")",
";",
"$",
"page_cache_key",
"=",
"implode",
"(",
"'_'",
",",
"[",
"'page_cache'",
",",
"$",
"route_info",
"[",
"'controller'",
"]",
",",
"$",
"route_info",
"[",
"'action'",
"]",
"]",
")",
";",
"return",
"Lb",
"::",
"app",
"(",
")",
"->",
"getCache",
"(",
"$",
"page_cache_key",
",",
"$",
"cache_type",
")",
";",
"}"
] | Get Page Cache
@param $cache_type
@return string | [
"Get",
"Page",
"Cache"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L928-L933 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.setPageCache | protected function setPageCache($cache_type, $page_cache, $expire = 60)
{
$route_info = Lb::app()->getRouteInfo();
$page_cache_key = implode('_', ['page_cache', $route_info['controller'], $route_info['action']]);
Lb::app()->setCache($page_cache_key, $page_cache, $cache_type, $expire);
} | php | protected function setPageCache($cache_type, $page_cache, $expire = 60)
{
$route_info = Lb::app()->getRouteInfo();
$page_cache_key = implode('_', ['page_cache', $route_info['controller'], $route_info['action']]);
Lb::app()->setCache($page_cache_key, $page_cache, $cache_type, $expire);
} | [
"protected",
"function",
"setPageCache",
"(",
"$",
"cache_type",
",",
"$",
"page_cache",
",",
"$",
"expire",
"=",
"60",
")",
"{",
"$",
"route_info",
"=",
"Lb",
"::",
"app",
"(",
")",
"->",
"getRouteInfo",
"(",
")",
";",
"$",
"page_cache_key",
"=",
"implode",
"(",
"'_'",
",",
"[",
"'page_cache'",
",",
"$",
"route_info",
"[",
"'controller'",
"]",
",",
"$",
"route_info",
"[",
"'action'",
"]",
"]",
")",
";",
"Lb",
"::",
"app",
"(",
")",
"->",
"setCache",
"(",
"$",
"page_cache_key",
",",
"$",
"page_cache",
",",
"$",
"cache_type",
",",
"$",
"expire",
")",
";",
"}"
] | Set Page Cache
@param $cache_type
@param $page_cache
@param int $expire | [
"Set",
"Page",
"Cache"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L942-L947 | train |
luoxiaojun1992/lb_framework | Lb.php | Lb.setHttpCache | protected function setHttpCache($response = null)
{
$http_cache_config = Lb::app()->getHttpCacheConfig();
if (isset($http_cache_config['cache_control']) && isset($http_cache_config['offset'])) {
HttpHelper::setCache($http_cache_config['cache_control'], $http_cache_config['offset'], $response);
}
} | php | protected function setHttpCache($response = null)
{
$http_cache_config = Lb::app()->getHttpCacheConfig();
if (isset($http_cache_config['cache_control']) && isset($http_cache_config['offset'])) {
HttpHelper::setCache($http_cache_config['cache_control'], $http_cache_config['offset'], $response);
}
} | [
"protected",
"function",
"setHttpCache",
"(",
"$",
"response",
"=",
"null",
")",
"{",
"$",
"http_cache_config",
"=",
"Lb",
"::",
"app",
"(",
")",
"->",
"getHttpCacheConfig",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"http_cache_config",
"[",
"'cache_control'",
"]",
")",
"&&",
"isset",
"(",
"$",
"http_cache_config",
"[",
"'offset'",
"]",
")",
")",
"{",
"HttpHelper",
"::",
"setCache",
"(",
"$",
"http_cache_config",
"[",
"'cache_control'",
"]",
",",
"$",
"http_cache_config",
"[",
"'offset'",
"]",
",",
"$",
"response",
")",
";",
"}",
"}"
] | Set Http Cache
@param $response ResponseContract | [
"Set",
"Http",
"Cache"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/Lb.php#L954-L960 | train |
infusephp/auth | src/Libs/Storage/SymfonySessionStorage.php | SymfonySessionStorage.createSession | private function createSession($sid, $userId, Request $req)
{
$sessionCookie = session_get_cookie_params();
$expires = time() + $sessionCookie['lifetime'];
$session = new ActiveSession();
$session->id = $sid;
$session->user_id = $userId;
$session->ip = $req->ip();
$session->user_agent = $req->agent();
$session->expires = $expires;
$session->save();
return $session;
} | php | private function createSession($sid, $userId, Request $req)
{
$sessionCookie = session_get_cookie_params();
$expires = time() + $sessionCookie['lifetime'];
$session = new ActiveSession();
$session->id = $sid;
$session->user_id = $userId;
$session->ip = $req->ip();
$session->user_agent = $req->agent();
$session->expires = $expires;
$session->save();
return $session;
} | [
"private",
"function",
"createSession",
"(",
"$",
"sid",
",",
"$",
"userId",
",",
"Request",
"$",
"req",
")",
"{",
"$",
"sessionCookie",
"=",
"session_get_cookie_params",
"(",
")",
";",
"$",
"expires",
"=",
"time",
"(",
")",
"+",
"$",
"sessionCookie",
"[",
"'lifetime'",
"]",
";",
"$",
"session",
"=",
"new",
"ActiveSession",
"(",
")",
";",
"$",
"session",
"->",
"id",
"=",
"$",
"sid",
";",
"$",
"session",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"session",
"->",
"ip",
"=",
"$",
"req",
"->",
"ip",
"(",
")",
";",
"$",
"session",
"->",
"user_agent",
"=",
"$",
"req",
"->",
"agent",
"(",
")",
";",
"$",
"session",
"->",
"expires",
"=",
"$",
"expires",
";",
"$",
"session",
"->",
"save",
"(",
")",
";",
"return",
"$",
"session",
";",
"}"
] | Creates an active session for a user.
@param string $sid session ID
@param int $userId
@param Request $req
@return ActiveSession | [
"Creates",
"an",
"active",
"session",
"for",
"a",
"user",
"."
] | 720280b4b2635572f331afe8d082e3e88cf54eb7 | https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Libs/Storage/SymfonySessionStorage.php#L218-L232 | train |
infusephp/auth | src/Libs/Storage/SymfonySessionStorage.php | SymfonySessionStorage.refreshSession | private function refreshSession($sid)
{
$sessionCookie = session_get_cookie_params();
$expires = time() + $sessionCookie['lifetime'];
$this->getDatabase()
->update('ActiveSessions')
->where('id', $sid)
->values([
'expires' => $expires,
'updated_at' => Utility::unixToDb(time())
])
->execute();
return true;
} | php | private function refreshSession($sid)
{
$sessionCookie = session_get_cookie_params();
$expires = time() + $sessionCookie['lifetime'];
$this->getDatabase()
->update('ActiveSessions')
->where('id', $sid)
->values([
'expires' => $expires,
'updated_at' => Utility::unixToDb(time())
])
->execute();
return true;
} | [
"private",
"function",
"refreshSession",
"(",
"$",
"sid",
")",
"{",
"$",
"sessionCookie",
"=",
"session_get_cookie_params",
"(",
")",
";",
"$",
"expires",
"=",
"time",
"(",
")",
"+",
"$",
"sessionCookie",
"[",
"'lifetime'",
"]",
";",
"$",
"this",
"->",
"getDatabase",
"(",
")",
"->",
"update",
"(",
"'ActiveSessions'",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"sid",
")",
"->",
"values",
"(",
"[",
"'expires'",
"=>",
"$",
"expires",
",",
"'updated_at'",
"=>",
"Utility",
"::",
"unixToDb",
"(",
"time",
"(",
")",
")",
"]",
")",
"->",
"execute",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Refreshes the expiration on an active session.
@param string $sid session ID
@return bool | [
"Refreshes",
"the",
"expiration",
"on",
"an",
"active",
"session",
"."
] | 720280b4b2635572f331afe8d082e3e88cf54eb7 | https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Libs/Storage/SymfonySessionStorage.php#L255-L270 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.