id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,000 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Context.php | HTMLPurifier_Context.destroy | public function destroy($name) {
if (!isset($this->_storage[$name])) {
trigger_error("Attempted to destroy non-existent variable $name",
E_USER_ERROR);
return;
}
unset($this->_storage[$name]);
} | php | public function destroy($name) {
if (!isset($this->_storage[$name])) {
trigger_error("Attempted to destroy non-existent variable $name",
E_USER_ERROR);
return;
}
unset($this->_storage[$name]);
} | [
"public",
"function",
"destroy",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_storage",
"[",
"$",
"name",
"]",
")",
")",
"{",
"trigger_error",
"(",
"\"Attempted to destroy non-existent variable $name\"",
",",
"E_USER_ERROR",
")",
";",
"return",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_storage",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Destorys a variable in the context.
@param $name String name | [
"Destorys",
"a",
"variable",
"in",
"the",
"context",
"."
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Context.php#L53-L60 |
13,001 | cauditor/php-analyzer | src/Api.php | Api.get | public function get($uri)
{
$options = array(
CURLOPT_URL => $this->domain.'/'.ltrim($uri, '/'),
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
);
return $this->exec($options);
} | php | public function get($uri)
{
$options = array(
CURLOPT_URL => $this->domain.'/'.ltrim($uri, '/'),
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
);
return $this->exec($options);
} | [
"public",
"function",
"get",
"(",
"$",
"uri",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_URL",
"=>",
"$",
"this",
"->",
"domain",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"uri",
",",
"'/'",
")",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"1",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"1",
",",
")",
";",
"return",
"$",
"this",
"->",
"exec",
"(",
"$",
"options",
")",
";",
"}"
] | Read data from cauditor API.
@param string $uri
@return string|bool API response (on success) or false (on failure) | [
"Read",
"data",
"from",
"cauditor",
"API",
"."
] | 0d86686d64d01e6aaed433898841894fa3ce1101 | https://github.com/cauditor/php-analyzer/blob/0d86686d64d01e6aaed433898841894fa3ce1101/src/Api.php#L40-L49 |
13,002 | cauditor/php-analyzer | src/Api.php | Api.put | public function put($uri, array $data)
{
// PUT requests need an fopen wrapper, so we'll create a temporary one
// for the data to submit...
$json = json_encode($data);
$file = fopen('php://temp', 'w+');
fwrite($file, $json, strlen($json));
fseek($file, 0);
$options = array(
CURLOPT_URL => $this->domain.'/'.ltrim($uri, '/'),
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_PUT => 1,
CURLOPT_INFILE => $file,
CURLOPT_INFILESIZE => strlen($json),
);
$result = $this->exec($options);
fclose($file);
return $result;
} | php | public function put($uri, array $data)
{
// PUT requests need an fopen wrapper, so we'll create a temporary one
// for the data to submit...
$json = json_encode($data);
$file = fopen('php://temp', 'w+');
fwrite($file, $json, strlen($json));
fseek($file, 0);
$options = array(
CURLOPT_URL => $this->domain.'/'.ltrim($uri, '/'),
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_PUT => 1,
CURLOPT_INFILE => $file,
CURLOPT_INFILESIZE => strlen($json),
);
$result = $this->exec($options);
fclose($file);
return $result;
} | [
"public",
"function",
"put",
"(",
"$",
"uri",
",",
"array",
"$",
"data",
")",
"{",
"// PUT requests need an fopen wrapper, so we'll create a temporary one",
"// for the data to submit...",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"$",
"file",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'w+'",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"$",
"json",
",",
"strlen",
"(",
"$",
"json",
")",
")",
";",
"fseek",
"(",
"$",
"file",
",",
"0",
")",
";",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_URL",
"=>",
"$",
"this",
"->",
"domain",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"uri",
",",
"'/'",
")",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"1",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"1",
",",
"CURLOPT_PUT",
"=>",
"1",
",",
"CURLOPT_INFILE",
"=>",
"$",
"file",
",",
"CURLOPT_INFILESIZE",
"=>",
"strlen",
"(",
"$",
"json",
")",
",",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"exec",
"(",
"$",
"options",
")",
";",
"fclose",
"(",
"$",
"file",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Submit the data to cauditor API.
@param string $uri
@param array $data
@return string|bool API response (on success) or false (on failure) | [
"Submit",
"the",
"data",
"to",
"cauditor",
"API",
"."
] | 0d86686d64d01e6aaed433898841894fa3ce1101 | https://github.com/cauditor/php-analyzer/blob/0d86686d64d01e6aaed433898841894fa3ce1101/src/Api.php#L59-L82 |
13,003 | liip/LiipDrupalConnectorModule | src/Liip/Drupal/Modules/DrupalConnector/Form.php | Form.form_set_error | public function form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL)
{
return form_set_error($name, $message, $limit_validation_errors);
} | php | public function form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL)
{
return form_set_error($name, $message, $limit_validation_errors);
} | [
"public",
"function",
"form_set_error",
"(",
"$",
"name",
"=",
"NULL",
",",
"$",
"message",
"=",
"''",
",",
"$",
"limit_validation_errors",
"=",
"NULL",
")",
"{",
"return",
"form_set_error",
"(",
"$",
"name",
",",
"$",
"message",
",",
"$",
"limit_validation_errors",
")",
";",
"}"
] | Files an error against a form element.
When a validation error is detected, the validator calls form_set_error() to
indicate which element needs to be changed and provide an error message. This
causes the Form API to not execute the form submit handlers, and instead to
re-display the form to the user with the corresponding elements rendered with
an 'error' CSS class (shown as red by default).
The standard form_set_error() behavior can be changed if a button provides
the #limit_validation_errors property. Multistep forms not wanting to
validate the whole form can set #limit_validation_errors on buttons to
limit validation errors to only certain elements. For example, pressing the
"Previous" button in a multistep form should not fire validation errors just
because the current step has invalid values. If #limit_validation_errors is
set on a clicked button, the button must also define a #submit property
(may be set to an empty array). Any #submit handlers will be executed even if
there is invalid input, so extreme care should be taken with respect to any
actions taken by them. This is typically not a problem with buttons like
"Previous" or "Add more" that do not invoke persistent storage of the
submitted form values. Do not use the #limit_validation_errors property on
buttons that trigger saving of form values to the database.
The #limit_validation_errors property is a list of "sections" within
$form_state['values'] that must contain valid values. Each "section" is an
array with the ordered set of keys needed to reach that part of
$form_state['values'] (i.e., the #parents property of the element).
Example 1: Allow the "Previous" button to function, regardless of whether any
user input is valid.
@code
$form['actions']['previous'] = array(
'#type' => 'submit',
'#value' => t('Previous'),
'#limit_validation_errors' => array(), // No validation.
'#submit' => array('some_submit_function'), // #submit required.
);
@endcode
Example 2: Require some, but not all, user input to be valid to process the
submission of a "Previous" button.
@code
$form['actions']['previous'] = array(
'#type' => 'submit',
'#value' => t('Previous'),
'#limit_validation_errors' => array(
array('step1'), // Validate $form_state['values']['step1'].
array('foo', 'bar'), // Validate $form_state['values']['foo']['bar'].
),
'#submit' => array('some_submit_function'), // #submit required.
);
@endcode
This will require $form_state['values']['step1'] and everything within it
(for example, $form_state['values']['step1']['choice']) to be valid, so
calls to form_set_error('step1', $message) or
form_set_error('step1][choice', $message) will prevent the submit handlers
from running, and result in the error message being displayed to the user.
However, calls to form_set_error('step2', $message) and
form_set_error('step2][groupX][choiceY', $message) will be suppressed,
resulting in the message not being displayed to the user, and the submit
handlers will run despite $form_state['values']['step2'] and
$form_state['values']['step2']['groupX']['choiceY'] containing invalid
values. Errors for an invalid $form_state['values']['foo'] will be
suppressed, but errors flagging invalid values for
$form_state['values']['foo']['bar'] and everything within it will be
flagged and submission prevented.
Partial form validation is implemented by suppressing errors rather than by
skipping the input processing and validation steps entirely, because some
forms have button-level submit handlers that call Drupal API functions that
assume that certain data exists within $form_state['values'], and while not
doing anything with that data that requires it to be valid, PHP errors
would be triggered if the input processing and validation steps were fully
skipped.
@param $name
The name of the form element. If the #parents property of your form
element is array('foo', 'bar', 'baz') then you may set an error on 'foo'
or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every
element where the #parents array starts with 'foo'.
@param $message
The error message to present to the user.
@param $limit_validation_errors
Internal use only. The #limit_validation_errors property of the clicked
button, if it exists.
@return
Return value is for internal use only. To get a list of errors, use
form_get_errors() or form_get_error().
@see http://drupal.org/node/370537
@see http://drupal.org/node/763376 | [
"Files",
"an",
"error",
"against",
"a",
"form",
"element",
"."
] | 6ba161ef0d3a27c108e533f1adbea22ed73b78ce | https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Form.php#L147-L150 |
13,004 | DevGroup-ru/yii2-data-structure-tools | src/searchOld/base/AbstractWatch.php | AbstractWatch.init | public function init()
{
if (true === $this->beforeInit()) {
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_AFTER_SAVE, [$this, 'onSave']);
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_AFTER_UPDATE, [$this, 'onUpdate']);
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_BEFORE_DELETE, [$this, 'onDelete']);
}
} | php | public function init()
{
if (true === $this->beforeInit()) {
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_AFTER_SAVE, [$this, 'onSave']);
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_AFTER_UPDATE, [$this, 'onUpdate']);
HasPropertiesEvent::on(HasProperties::class, HasProperties::EVENT_BEFORE_DELETE, [$this, 'onDelete']);
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"beforeInit",
"(",
")",
")",
"{",
"HasPropertiesEvent",
"::",
"on",
"(",
"HasProperties",
"::",
"class",
",",
"HasProperties",
"::",
"EVENT_AFTER_SAVE",
",",
"[",
"$",
"this",
",",
"'onSave'",
"]",
")",
";",
"HasPropertiesEvent",
"::",
"on",
"(",
"HasProperties",
"::",
"class",
",",
"HasProperties",
"::",
"EVENT_AFTER_UPDATE",
",",
"[",
"$",
"this",
",",
"'onUpdate'",
"]",
")",
";",
"HasPropertiesEvent",
"::",
"on",
"(",
"HasProperties",
"::",
"class",
",",
"HasProperties",
"::",
"EVENT_BEFORE_DELETE",
",",
"[",
"$",
"this",
",",
"'onDelete'",
"]",
")",
";",
"}",
"}"
] | Adds event listeners to perform search index actualization if pre initialization was successful | [
"Adds",
"event",
"listeners",
"to",
"perform",
"search",
"index",
"actualization",
"if",
"pre",
"initialization",
"was",
"successful"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/searchOld/base/AbstractWatch.php#L20-L27 |
13,005 | PandaPlatform/framework | src/Panda/Support/Helpers/NumberHelper.php | NumberHelper.isEqual | public static function isEqual($value1, $value2, $roundPrecision = 0)
{
$equal = false;
if (static::floor($value1, $roundPrecision) == static::floor($value2, $roundPrecision)) {
$equal = true;
}
return $equal;
} | php | public static function isEqual($value1, $value2, $roundPrecision = 0)
{
$equal = false;
if (static::floor($value1, $roundPrecision) == static::floor($value2, $roundPrecision)) {
$equal = true;
}
return $equal;
} | [
"public",
"static",
"function",
"isEqual",
"(",
"$",
"value1",
",",
"$",
"value2",
",",
"$",
"roundPrecision",
"=",
"0",
")",
"{",
"$",
"equal",
"=",
"false",
";",
"if",
"(",
"static",
"::",
"floor",
"(",
"$",
"value1",
",",
"$",
"roundPrecision",
")",
"==",
"static",
"::",
"floor",
"(",
"$",
"value2",
",",
"$",
"roundPrecision",
")",
")",
"{",
"$",
"equal",
"=",
"true",
";",
"}",
"return",
"$",
"equal",
";",
"}"
] | Checks if of two numbers are equal.
Optional to set a required precision
@param float $value1
@param float $value2
@param int $roundPrecision
@return bool | [
"Checks",
"if",
"of",
"two",
"numbers",
"are",
"equal",
".",
"Optional",
"to",
"set",
"a",
"required",
"precision"
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/NumberHelper.php#L60-L69 |
13,006 | Arcavias/ext-phpexcel | lib/custom/src/MW/Container/Content/PHPExcel.php | MW_Container_Content_PHPExcel.add | public function add( $data )
{
$columnNum = 0;
$rowNum = $this->_iterator->current()->getRowIndex();
foreach( (array) $data as $value ) {
$this->_sheet->setCellValueByColumnAndRow( $columnNum++, $rowNum, $value );
}
$this->_iterator->next();
} | php | public function add( $data )
{
$columnNum = 0;
$rowNum = $this->_iterator->current()->getRowIndex();
foreach( (array) $data as $value ) {
$this->_sheet->setCellValueByColumnAndRow( $columnNum++, $rowNum, $value );
}
$this->_iterator->next();
} | [
"public",
"function",
"add",
"(",
"$",
"data",
")",
"{",
"$",
"columnNum",
"=",
"0",
";",
"$",
"rowNum",
"=",
"$",
"this",
"->",
"_iterator",
"->",
"current",
"(",
")",
"->",
"getRowIndex",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_sheet",
"->",
"setCellValueByColumnAndRow",
"(",
"$",
"columnNum",
"++",
",",
"$",
"rowNum",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"_iterator",
"->",
"next",
"(",
")",
";",
"}"
] | Adds a row to the content object.
@param mixed $data Data to add | [
"Adds",
"a",
"row",
"to",
"the",
"content",
"object",
"."
] | 00e6ce6205e4f44eb0c438093b523b084a019e8d | https://github.com/Arcavias/ext-phpexcel/blob/00e6ce6205e4f44eb0c438093b523b084a019e8d/lib/custom/src/MW/Container/Content/PHPExcel.php#L54-L64 |
13,007 | unimapper/unimapper | src/Association.php | Association.groupResult | public static function groupResult(array $original, array $keys, $level = 0)
{
$converted = [];
$key = $keys[$level];
$isDeepest = sizeof($keys) - 1 == $level;
$level++;
$filtered = [];
foreach ($original as $k => $subArray) {
$subArray = (array) $subArray;
if (!isset($subArray[$key])) {
throw new AssociationException(
"Index '" . $key . "' not found on level '" . $level . "'!"
);
}
$thisLevel = $subArray[$key];
if (is_object($thisLevel)) {
$thisLevel = (string) $thisLevel;
}
if ($isDeepest) {
$converted[$thisLevel] = $subArray;
} else {
$converted[$thisLevel] = [];
}
$filtered[$thisLevel][] = $subArray;
}
if (!$isDeepest) {
foreach (array_keys($converted) as $value) {
$converted[$value] = self::groupResult(
$filtered[$value],
$keys,
$level
);
}
}
return $converted;
} | php | public static function groupResult(array $original, array $keys, $level = 0)
{
$converted = [];
$key = $keys[$level];
$isDeepest = sizeof($keys) - 1 == $level;
$level++;
$filtered = [];
foreach ($original as $k => $subArray) {
$subArray = (array) $subArray;
if (!isset($subArray[$key])) {
throw new AssociationException(
"Index '" . $key . "' not found on level '" . $level . "'!"
);
}
$thisLevel = $subArray[$key];
if (is_object($thisLevel)) {
$thisLevel = (string) $thisLevel;
}
if ($isDeepest) {
$converted[$thisLevel] = $subArray;
} else {
$converted[$thisLevel] = [];
}
$filtered[$thisLevel][] = $subArray;
}
if (!$isDeepest) {
foreach (array_keys($converted) as $value) {
$converted[$value] = self::groupResult(
$filtered[$value],
$keys,
$level
);
}
}
return $converted;
} | [
"public",
"static",
"function",
"groupResult",
"(",
"array",
"$",
"original",
",",
"array",
"$",
"keys",
",",
"$",
"level",
"=",
"0",
")",
"{",
"$",
"converted",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"$",
"keys",
"[",
"$",
"level",
"]",
";",
"$",
"isDeepest",
"=",
"sizeof",
"(",
"$",
"keys",
")",
"-",
"1",
"==",
"$",
"level",
";",
"$",
"level",
"++",
";",
"$",
"filtered",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"original",
"as",
"$",
"k",
"=>",
"$",
"subArray",
")",
"{",
"$",
"subArray",
"=",
"(",
"array",
")",
"$",
"subArray",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"subArray",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"AssociationException",
"(",
"\"Index '\"",
".",
"$",
"key",
".",
"\"' not found on level '\"",
".",
"$",
"level",
".",
"\"'!\"",
")",
";",
"}",
"$",
"thisLevel",
"=",
"$",
"subArray",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"is_object",
"(",
"$",
"thisLevel",
")",
")",
"{",
"$",
"thisLevel",
"=",
"(",
"string",
")",
"$",
"thisLevel",
";",
"}",
"if",
"(",
"$",
"isDeepest",
")",
"{",
"$",
"converted",
"[",
"$",
"thisLevel",
"]",
"=",
"$",
"subArray",
";",
"}",
"else",
"{",
"$",
"converted",
"[",
"$",
"thisLevel",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"filtered",
"[",
"$",
"thisLevel",
"]",
"[",
"]",
"=",
"$",
"subArray",
";",
"}",
"if",
"(",
"!",
"$",
"isDeepest",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"converted",
")",
"as",
"$",
"value",
")",
"{",
"$",
"converted",
"[",
"$",
"value",
"]",
"=",
"self",
"::",
"groupResult",
"(",
"$",
"filtered",
"[",
"$",
"value",
"]",
",",
"$",
"keys",
",",
"$",
"level",
")",
";",
"}",
"}",
"return",
"$",
"converted",
";",
"}"
] | Group associative array
@param array $original
@param array $keys
@param int $level
@return array
@link http://tigrou.nl/2012/11/26/group-a-php-array-to-a-tree-structure/
@throws \Exception | [
"Group",
"associative",
"array"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Association.php#L111-L154 |
13,008 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Select.php | Select.setValue | public function setValue($value)
{
$this->selected = $value;
if ($this->hasChildren()) {
foreach ($this->childNodes as $child) {
if ($child instanceof Select\Option) {
if ($child->getValue() == $this->selected) {
$child->select();
} else {
$child->deselect();
}
} else if ($child instanceof Select\Optgroup) {
$options = $child->getOptions();
foreach ($options as $option) {
if ($option->getValue() == $this->selected) {
$option->select();
} else {
$option->deselect();
}
}
}
}
}
return $this;
} | php | public function setValue($value)
{
$this->selected = $value;
if ($this->hasChildren()) {
foreach ($this->childNodes as $child) {
if ($child instanceof Select\Option) {
if ($child->getValue() == $this->selected) {
$child->select();
} else {
$child->deselect();
}
} else if ($child instanceof Select\Optgroup) {
$options = $child->getOptions();
foreach ($options as $option) {
if ($option->getValue() == $this->selected) {
$option->select();
} else {
$option->deselect();
}
}
}
}
}
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"selected",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"this",
"->",
"hasChildren",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"Select",
"\\",
"Option",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getValue",
"(",
")",
"==",
"$",
"this",
"->",
"selected",
")",
"{",
"$",
"child",
"->",
"select",
"(",
")",
";",
"}",
"else",
"{",
"$",
"child",
"->",
"deselect",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"child",
"instanceof",
"Select",
"\\",
"Optgroup",
")",
"{",
"$",
"options",
"=",
"$",
"child",
"->",
"getOptions",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"option",
"->",
"getValue",
"(",
")",
"==",
"$",
"this",
"->",
"selected",
")",
"{",
"$",
"option",
"->",
"select",
"(",
")",
";",
"}",
"else",
"{",
"$",
"option",
"->",
"deselect",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the selected value of the select form element
@param mixed $value
@return Select | [
"Set",
"the",
"selected",
"value",
"of",
"the",
"select",
"form",
"element"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Select.php#L83-L107 |
13,009 | cauditor/php-analyzer | src/Aggregator.php | Aggregator.average | public function average()
{
$flat = $this->flatten();
$avg = array();
foreach ($flat as $metric => $values) {
$avg[$metric] = (float) number_format(array_sum($values) / count($values), 2, '.', '');
}
return $avg;
} | php | public function average()
{
$flat = $this->flatten();
$avg = array();
foreach ($flat as $metric => $values) {
$avg[$metric] = (float) number_format(array_sum($values) / count($values), 2, '.', '');
}
return $avg;
} | [
"public",
"function",
"average",
"(",
")",
"{",
"$",
"flat",
"=",
"$",
"this",
"->",
"flatten",
"(",
")",
";",
"$",
"avg",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"flat",
"as",
"$",
"metric",
"=>",
"$",
"values",
")",
"{",
"$",
"avg",
"[",
"$",
"metric",
"]",
"=",
"(",
"float",
")",
"number_format",
"(",
"array_sum",
"(",
"$",
"values",
")",
"/",
"count",
"(",
"$",
"values",
")",
",",
"2",
",",
"'.'",
",",
"''",
")",
";",
"}",
"return",
"$",
"avg",
";",
"}"
] | Get metric averages.
@return float[] | [
"Get",
"metric",
"averages",
"."
] | 0d86686d64d01e6aaed433898841894fa3ce1101 | https://github.com/cauditor/php-analyzer/blob/0d86686d64d01e6aaed433898841894fa3ce1101/src/Aggregator.php#L35-L45 |
13,010 | joomla-projects/jorobo | src/Tasks/Build/CBPlugin.php | CBPlugin.createInstaller | private function createInstaller($files)
{
$this->say("Creating plugin installer");
$xmlFile = $this->target . "/" . str_replace('plug_', '', $this->plgName) . ".xml";
// Version & Date Replace
$this->replaceInFile($xmlFile);
} | php | private function createInstaller($files)
{
$this->say("Creating plugin installer");
$xmlFile = $this->target . "/" . str_replace('plug_', '', $this->plgName) . ".xml";
// Version & Date Replace
$this->replaceInFile($xmlFile);
} | [
"private",
"function",
"createInstaller",
"(",
"$",
"files",
")",
"{",
"$",
"this",
"->",
"say",
"(",
"\"Creating plugin installer\"",
")",
";",
"$",
"xmlFile",
"=",
"$",
"this",
"->",
"target",
".",
"\"/\"",
".",
"str_replace",
"(",
"'plug_'",
",",
"''",
",",
"$",
"this",
"->",
"plgName",
")",
".",
"\".xml\"",
";",
"// Version & Date Replace",
"$",
"this",
"->",
"replaceInFile",
"(",
"$",
"xmlFile",
")",
";",
"}"
] | Generate the installer xml file for the plugin
@param array $files The module files
@return void
@since 1.0 | [
"Generate",
"the",
"installer",
"xml",
"file",
"for",
"the",
"plugin"
] | e72dd0ed15f387739f67cacdbc2c0bd1b427f317 | https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Build/CBPlugin.php#L108-L116 |
13,011 | terdia/legato-framework | src/Security/Auth/Auth.php | Auth.remembered | public static function remembered(Request $request)
{
$remember = readCookie($request, 'remember_token');
if ($remember != null) {
try {
$decrypted = decrypt($remember);
$authConfig = getConfigPath('app', 'auth');
return Gate::user($authConfig, $decrypted);
} catch (Exception $ex) {
return false;
}
}
return false;
} | php | public static function remembered(Request $request)
{
$remember = readCookie($request, 'remember_token');
if ($remember != null) {
try {
$decrypted = decrypt($remember);
$authConfig = getConfigPath('app', 'auth');
return Gate::user($authConfig, $decrypted);
} catch (Exception $ex) {
return false;
}
}
return false;
} | [
"public",
"static",
"function",
"remembered",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"remember",
"=",
"readCookie",
"(",
"$",
"request",
",",
"'remember_token'",
")",
";",
"if",
"(",
"$",
"remember",
"!=",
"null",
")",
"{",
"try",
"{",
"$",
"decrypted",
"=",
"decrypt",
"(",
"$",
"remember",
")",
";",
"$",
"authConfig",
"=",
"getConfigPath",
"(",
"'app'",
",",
"'auth'",
")",
";",
"return",
"Gate",
"::",
"user",
"(",
"$",
"authConfig",
",",
"$",
"decrypted",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check remember user.
@param Request $request
@return bool|mixed | [
"Check",
"remember",
"user",
"."
] | 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Security/Auth/Auth.php#L71-L86 |
13,012 | falkmueller/hubert | src/generic/controller.php | controller.responseRedirect | protected function responseRedirect($url, $status = null)
{
$responseWithRedirect = $this->_response->withHeader('Location', (string)$url);
if (is_null($status) && $this->_response->getStatusCode() === 200) {
$status = 302;
}
if (!is_null($status)) {
return $responseWithRedirect->withStatus($status);
}
return $responseWithRedirect;
} | php | protected function responseRedirect($url, $status = null)
{
$responseWithRedirect = $this->_response->withHeader('Location', (string)$url);
if (is_null($status) && $this->_response->getStatusCode() === 200) {
$status = 302;
}
if (!is_null($status)) {
return $responseWithRedirect->withStatus($status);
}
return $responseWithRedirect;
} | [
"protected",
"function",
"responseRedirect",
"(",
"$",
"url",
",",
"$",
"status",
"=",
"null",
")",
"{",
"$",
"responseWithRedirect",
"=",
"$",
"this",
"->",
"_response",
"->",
"withHeader",
"(",
"'Location'",
",",
"(",
"string",
")",
"$",
"url",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"status",
")",
"&&",
"$",
"this",
"->",
"_response",
"->",
"getStatusCode",
"(",
")",
"===",
"200",
")",
"{",
"$",
"status",
"=",
"302",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"status",
")",
")",
"{",
"return",
"$",
"responseWithRedirect",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"}",
"return",
"$",
"responseWithRedirect",
";",
"}"
] | set redirekt url in response
@param string $url
@param int $status
@return \Zend\Diactoros\Response | [
"set",
"redirekt",
"url",
"in",
"response"
] | a4fa52de158262dddd9cf349bf5267f7923874f9 | https://github.com/falkmueller/hubert/blob/a4fa52de158262dddd9cf349bf5267f7923874f9/src/generic/controller.php#L40-L50 |
13,013 | falkmueller/hubert | src/generic/controller.php | controller.responseJson | protected function responseJson($data, $status = null, $encodingOptions = 0)
{
$body = $this->_response->getBody();
$body->rewind();
$body->write($json = json_encode($data, $encodingOptions));
// Ensure that the json encoding passed successfully
if ($json === false) {
throw new \RuntimeException(json_last_error_msg(), json_last_error());
}
$responseWithJson = $this->_response->withHeader('Content-Type', 'application/json;charset=utf-8');
if (isset($status)) {
return $responseWithJson->withStatus($status);
}
return $responseWithJson;
} | php | protected function responseJson($data, $status = null, $encodingOptions = 0)
{
$body = $this->_response->getBody();
$body->rewind();
$body->write($json = json_encode($data, $encodingOptions));
// Ensure that the json encoding passed successfully
if ($json === false) {
throw new \RuntimeException(json_last_error_msg(), json_last_error());
}
$responseWithJson = $this->_response->withHeader('Content-Type', 'application/json;charset=utf-8');
if (isset($status)) {
return $responseWithJson->withStatus($status);
}
return $responseWithJson;
} | [
"protected",
"function",
"responseJson",
"(",
"$",
"data",
",",
"$",
"status",
"=",
"null",
",",
"$",
"encodingOptions",
"=",
"0",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"_response",
"->",
"getBody",
"(",
")",
";",
"$",
"body",
"->",
"rewind",
"(",
")",
";",
"$",
"body",
"->",
"write",
"(",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"data",
",",
"$",
"encodingOptions",
")",
")",
";",
"// Ensure that the json encoding passed successfully",
"if",
"(",
"$",
"json",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"json_last_error_msg",
"(",
")",
",",
"json_last_error",
"(",
")",
")",
";",
"}",
"$",
"responseWithJson",
"=",
"$",
"this",
"->",
"_response",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"'application/json;charset=utf-8'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"status",
")",
")",
"{",
"return",
"$",
"responseWithJson",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"}",
"return",
"$",
"responseWithJson",
";",
"}"
] | transform response for with json-data
@param type $data
@param int $status
@param type $encodingOptions
@return \Zend\Diactoros\Response
@throws \RuntimeException | [
"transform",
"response",
"for",
"with",
"json",
"-",
"data"
] | a4fa52de158262dddd9cf349bf5267f7923874f9 | https://github.com/falkmueller/hubert/blob/a4fa52de158262dddd9cf349bf5267f7923874f9/src/generic/controller.php#L60-L74 |
13,014 | falkmueller/hubert | src/generic/controller.php | controller.responseTemplate | protected function responseTemplate($template, $data = array()){
if(!isset(hubert()->template)){
throw new \Exception("no template engine installed");
}
$html = hubert()->template->render($template, $data);
$this->_response->getBody()->write($html);
return $this->_response;
} | php | protected function responseTemplate($template, $data = array()){
if(!isset(hubert()->template)){
throw new \Exception("no template engine installed");
}
$html = hubert()->template->render($template, $data);
$this->_response->getBody()->write($html);
return $this->_response;
} | [
"protected",
"function",
"responseTemplate",
"(",
"$",
"template",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"hubert",
"(",
")",
"->",
"template",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"no template engine installed\"",
")",
";",
"}",
"$",
"html",
"=",
"hubert",
"(",
")",
"->",
"template",
"->",
"render",
"(",
"$",
"template",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"html",
")",
";",
"return",
"$",
"this",
"->",
"_response",
";",
"}"
] | render template in response
@param string $template
@param array $data
@return \Zend\Diactoros\Response | [
"render",
"template",
"in",
"response"
] | a4fa52de158262dddd9cf349bf5267f7923874f9 | https://github.com/falkmueller/hubert/blob/a4fa52de158262dddd9cf349bf5267f7923874f9/src/generic/controller.php#L82-L92 |
13,015 | sifophp/sifo-common-instance | controllers/error/common.php | ErrorCommonController.getErrorMetadata | public function getErrorMetadata()
{
try
{
$metadata = \Sifo\Config::getInstance()->getConfig( 'lang/metadata_' . $this->getParam( 'lang' ) );
}
catch ( Exception_Configuration $e )
{
$metadata = \Sifo\Config::getInstance()->getConfig( 'lang/metadata_en_US' );
}
$error_code = $this->getParam( 'code' );
return ( isset( $metadata[$error_code] ) ) ? $metadata[$error_code] : false;
} | php | public function getErrorMetadata()
{
try
{
$metadata = \Sifo\Config::getInstance()->getConfig( 'lang/metadata_' . $this->getParam( 'lang' ) );
}
catch ( Exception_Configuration $e )
{
$metadata = \Sifo\Config::getInstance()->getConfig( 'lang/metadata_en_US' );
}
$error_code = $this->getParam( 'code' );
return ( isset( $metadata[$error_code] ) ) ? $metadata[$error_code] : false;
} | [
"public",
"function",
"getErrorMetadata",
"(",
")",
"{",
"try",
"{",
"$",
"metadata",
"=",
"\\",
"Sifo",
"\\",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"getConfig",
"(",
"'lang/metadata_'",
".",
"$",
"this",
"->",
"getParam",
"(",
"'lang'",
")",
")",
";",
"}",
"catch",
"(",
"Exception_Configuration",
"$",
"e",
")",
"{",
"$",
"metadata",
"=",
"\\",
"Sifo",
"\\",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"getConfig",
"(",
"'lang/metadata_en_US'",
")",
";",
"}",
"$",
"error_code",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'code'",
")",
";",
"return",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"$",
"error_code",
"]",
")",
")",
"?",
"$",
"metadata",
"[",
"$",
"error_code",
"]",
":",
"false",
";",
"}"
] | Assign selected error code metadata to page to allow error translations.
@return array | [
"Assign",
"selected",
"error",
"code",
"metadata",
"to",
"page",
"to",
"allow",
"error",
"translations",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/error/common.php#L58-L72 |
13,016 | Guzzle3/guzzle-silex-extension | GuzzleServiceProvider.php | GuzzleServiceProvider.register | public function register(Application $app)
{
$app['guzzle.base_url'] = '/';
if(!isset($app['guzzle.plugins'])){
$app['guzzle.plugins'] = array();
}
// Register a Guzzle ServiceBuilder
$app['guzzle'] = $app->share(function () use ($app) {
if (!isset($app['guzzle.services'])) {
$builder = new ServiceBuilder(array());
} else {
$builder = ServiceBuilder::factory($app['guzzle.services']);
}
return $builder;
});
// Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
$app['guzzle.client'] = $app->share(function() use ($app) {
$client = new Client($app['guzzle.base_url']);
foreach ($app['guzzle.plugins'] as $plugin) {
$client->addSubscriber($plugin);
}
return $client;
});
} | php | public function register(Application $app)
{
$app['guzzle.base_url'] = '/';
if(!isset($app['guzzle.plugins'])){
$app['guzzle.plugins'] = array();
}
// Register a Guzzle ServiceBuilder
$app['guzzle'] = $app->share(function () use ($app) {
if (!isset($app['guzzle.services'])) {
$builder = new ServiceBuilder(array());
} else {
$builder = ServiceBuilder::factory($app['guzzle.services']);
}
return $builder;
});
// Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
$app['guzzle.client'] = $app->share(function() use ($app) {
$client = new Client($app['guzzle.base_url']);
foreach ($app['guzzle.plugins'] as $plugin) {
$client->addSubscriber($plugin);
}
return $client;
});
} | [
"public",
"function",
"register",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'guzzle.base_url'",
"]",
"=",
"'/'",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"app",
"[",
"'guzzle.plugins'",
"]",
")",
")",
"{",
"$",
"app",
"[",
"'guzzle.plugins'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// Register a Guzzle ServiceBuilder",
"$",
"app",
"[",
"'guzzle'",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"app",
"[",
"'guzzle.services'",
"]",
")",
")",
"{",
"$",
"builder",
"=",
"new",
"ServiceBuilder",
"(",
"array",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"builder",
"=",
"ServiceBuilder",
"::",
"factory",
"(",
"$",
"app",
"[",
"'guzzle.services'",
"]",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}",
")",
";",
"// Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)",
"$",
"app",
"[",
"'guzzle.client'",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
"$",
"app",
"[",
"'guzzle.base_url'",
"]",
")",
";",
"foreach",
"(",
"$",
"app",
"[",
"'guzzle.plugins'",
"]",
"as",
"$",
"plugin",
")",
"{",
"$",
"client",
"->",
"addSubscriber",
"(",
"$",
"plugin",
")",
";",
"}",
"return",
"$",
"client",
";",
"}",
")",
";",
"}"
] | Register Guzzle with Silex
@param Application $app Application to register with | [
"Register",
"Guzzle",
"with",
"Silex"
] | 557d0205d8691d0702380102fac5a662854e0691 | https://github.com/Guzzle3/guzzle-silex-extension/blob/557d0205d8691d0702380102fac5a662854e0691/GuzzleServiceProvider.php#L34-L62 |
13,017 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/PercentEncoder.php | HTMLPurifier_PercentEncoder.normalize | public function normalize($string) {
if ($string == '') return '';
$parts = explode('%', $string);
$ret = array_shift($parts);
foreach ($parts as $part) {
$length = strlen($part);
if ($length < 2) {
$ret .= '%25' . $part;
continue;
}
$encoding = substr($part, 0, 2);
$text = substr($part, 2);
if (!ctype_xdigit($encoding)) {
$ret .= '%25' . $part;
continue;
}
$int = hexdec($encoding);
if (isset($this->preserve[$int])) {
$ret .= chr($int) . $text;
continue;
}
$encoding = strtoupper($encoding);
$ret .= '%' . $encoding . $text;
}
return $ret;
} | php | public function normalize($string) {
if ($string == '') return '';
$parts = explode('%', $string);
$ret = array_shift($parts);
foreach ($parts as $part) {
$length = strlen($part);
if ($length < 2) {
$ret .= '%25' . $part;
continue;
}
$encoding = substr($part, 0, 2);
$text = substr($part, 2);
if (!ctype_xdigit($encoding)) {
$ret .= '%25' . $part;
continue;
}
$int = hexdec($encoding);
if (isset($this->preserve[$int])) {
$ret .= chr($int) . $text;
continue;
}
$encoding = strtoupper($encoding);
$ret .= '%' . $encoding . $text;
}
return $ret;
} | [
"public",
"function",
"normalize",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"$",
"string",
"==",
"''",
")",
"return",
"''",
";",
"$",
"parts",
"=",
"explode",
"(",
"'%'",
",",
"$",
"string",
")",
";",
"$",
"ret",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"part",
")",
";",
"if",
"(",
"$",
"length",
"<",
"2",
")",
"{",
"$",
"ret",
".=",
"'%25'",
".",
"$",
"part",
";",
"continue",
";",
"}",
"$",
"encoding",
"=",
"substr",
"(",
"$",
"part",
",",
"0",
",",
"2",
")",
";",
"$",
"text",
"=",
"substr",
"(",
"$",
"part",
",",
"2",
")",
";",
"if",
"(",
"!",
"ctype_xdigit",
"(",
"$",
"encoding",
")",
")",
"{",
"$",
"ret",
".=",
"'%25'",
".",
"$",
"part",
";",
"continue",
";",
"}",
"$",
"int",
"=",
"hexdec",
"(",
"$",
"encoding",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"preserve",
"[",
"$",
"int",
"]",
")",
")",
"{",
"$",
"ret",
".=",
"chr",
"(",
"$",
"int",
")",
".",
"$",
"text",
";",
"continue",
";",
"}",
"$",
"encoding",
"=",
"strtoupper",
"(",
"$",
"encoding",
")",
";",
"$",
"ret",
".=",
"'%'",
".",
"$",
"encoding",
".",
"$",
"text",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Fix up percent-encoding by decoding unreserved characters and normalizing.
@warning This function is affected by $preserve, even though the
usual desired behavior is for this not to preserve those
characters. Be careful when reusing instances of PercentEncoder!
@param $string String to normalize | [
"Fix",
"up",
"percent",
"-",
"encoding",
"by",
"decoding",
"unreserved",
"characters",
"and",
"normalizing",
"."
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/PercentEncoder.php#L69-L94 |
13,018 | ssnepenthe/soter | src/class-options-page.php | Options_Page.admin_init | public function admin_init() {
add_settings_section(
'soter_general',
'General Settings',
[ $this, 'render_section_general' ],
'soter'
);
add_settings_section(
'soter_email',
'Email Settings',
[ $this, 'render_section_email' ],
'soter'
);
add_settings_section(
'soter_slack',
'Slack Settings',
[ $this, 'render_section_slack' ],
'soter'
);
add_settings_field(
'soter_should_nag',
'Notification Frequency',
[ $this, 'render_should_nag' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_ignored_plugins',
'Ignored Plugins',
[ $this, 'render_ignored_plugins' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_ignored_themes',
'Ignored Themes',
[ $this, 'render_ignored_themes' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_email_enabled',
'Send Email Notifications',
[ $this, 'render_email_enabled' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_email_address',
'Email Address',
[ $this, 'render_email_address' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_email_type',
'Email Type',
[ $this, 'render_email_type' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_slack_enabled',
'Send Slack Notifications',
[ $this, 'render_slack_enabled' ],
'soter',
'soter_slack'
);
add_settings_field(
'soter_slack_url',
'WebHook URL',
[ $this, 'render_slack_url' ],
'soter',
'soter_slack'
);
} | php | public function admin_init() {
add_settings_section(
'soter_general',
'General Settings',
[ $this, 'render_section_general' ],
'soter'
);
add_settings_section(
'soter_email',
'Email Settings',
[ $this, 'render_section_email' ],
'soter'
);
add_settings_section(
'soter_slack',
'Slack Settings',
[ $this, 'render_section_slack' ],
'soter'
);
add_settings_field(
'soter_should_nag',
'Notification Frequency',
[ $this, 'render_should_nag' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_ignored_plugins',
'Ignored Plugins',
[ $this, 'render_ignored_plugins' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_ignored_themes',
'Ignored Themes',
[ $this, 'render_ignored_themes' ],
'soter',
'soter_general'
);
add_settings_field(
'soter_email_enabled',
'Send Email Notifications',
[ $this, 'render_email_enabled' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_email_address',
'Email Address',
[ $this, 'render_email_address' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_email_type',
'Email Type',
[ $this, 'render_email_type' ],
'soter',
'soter_email'
);
add_settings_field(
'soter_slack_enabled',
'Send Slack Notifications',
[ $this, 'render_slack_enabled' ],
'soter',
'soter_slack'
);
add_settings_field(
'soter_slack_url',
'WebHook URL',
[ $this, 'render_slack_url' ],
'soter',
'soter_slack'
);
} | [
"public",
"function",
"admin_init",
"(",
")",
"{",
"add_settings_section",
"(",
"'soter_general'",
",",
"'General Settings'",
",",
"[",
"$",
"this",
",",
"'render_section_general'",
"]",
",",
"'soter'",
")",
";",
"add_settings_section",
"(",
"'soter_email'",
",",
"'Email Settings'",
",",
"[",
"$",
"this",
",",
"'render_section_email'",
"]",
",",
"'soter'",
")",
";",
"add_settings_section",
"(",
"'soter_slack'",
",",
"'Slack Settings'",
",",
"[",
"$",
"this",
",",
"'render_section_slack'",
"]",
",",
"'soter'",
")",
";",
"add_settings_field",
"(",
"'soter_should_nag'",
",",
"'Notification Frequency'",
",",
"[",
"$",
"this",
",",
"'render_should_nag'",
"]",
",",
"'soter'",
",",
"'soter_general'",
")",
";",
"add_settings_field",
"(",
"'soter_ignored_plugins'",
",",
"'Ignored Plugins'",
",",
"[",
"$",
"this",
",",
"'render_ignored_plugins'",
"]",
",",
"'soter'",
",",
"'soter_general'",
")",
";",
"add_settings_field",
"(",
"'soter_ignored_themes'",
",",
"'Ignored Themes'",
",",
"[",
"$",
"this",
",",
"'render_ignored_themes'",
"]",
",",
"'soter'",
",",
"'soter_general'",
")",
";",
"add_settings_field",
"(",
"'soter_email_enabled'",
",",
"'Send Email Notifications'",
",",
"[",
"$",
"this",
",",
"'render_email_enabled'",
"]",
",",
"'soter'",
",",
"'soter_email'",
")",
";",
"add_settings_field",
"(",
"'soter_email_address'",
",",
"'Email Address'",
",",
"[",
"$",
"this",
",",
"'render_email_address'",
"]",
",",
"'soter'",
",",
"'soter_email'",
")",
";",
"add_settings_field",
"(",
"'soter_email_type'",
",",
"'Email Type'",
",",
"[",
"$",
"this",
",",
"'render_email_type'",
"]",
",",
"'soter'",
",",
"'soter_email'",
")",
";",
"add_settings_field",
"(",
"'soter_slack_enabled'",
",",
"'Send Slack Notifications'",
",",
"[",
"$",
"this",
",",
"'render_slack_enabled'",
"]",
",",
"'soter'",
",",
"'soter_slack'",
")",
";",
"add_settings_field",
"(",
"'soter_slack_url'",
",",
"'WebHook URL'",
",",
"[",
"$",
"this",
",",
"'render_slack_url'",
"]",
",",
"'soter'",
",",
"'soter_slack'",
")",
";",
"}"
] | Registers settings, sections and fields.
@return void | [
"Registers",
"settings",
"sections",
"and",
"fields",
"."
] | f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7 | https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-options-page.php#L50-L135 |
13,019 | ssnepenthe/soter | src/class-options-page.php | Options_Page.print_notice_when_no_notifiers_active | public function print_notice_when_no_notifiers_active() {
if (
'settings_page_soter' !== get_current_screen()->base
|| $this->options->email_enabled
|| $this->options->slack_enabled
) {
return;
}
echo $this->template->render( 'admin-notice.php', [ // WPCS: XSS OK.
'type' => 'error',
'message' => 'All notification channels are currently disabled. Please enable one or more below.',
] );
} | php | public function print_notice_when_no_notifiers_active() {
if (
'settings_page_soter' !== get_current_screen()->base
|| $this->options->email_enabled
|| $this->options->slack_enabled
) {
return;
}
echo $this->template->render( 'admin-notice.php', [ // WPCS: XSS OK.
'type' => 'error',
'message' => 'All notification channels are currently disabled. Please enable one or more below.',
] );
} | [
"public",
"function",
"print_notice_when_no_notifiers_active",
"(",
")",
"{",
"if",
"(",
"'settings_page_soter'",
"!==",
"get_current_screen",
"(",
")",
"->",
"base",
"||",
"$",
"this",
"->",
"options",
"->",
"email_enabled",
"||",
"$",
"this",
"->",
"options",
"->",
"slack_enabled",
")",
"{",
"return",
";",
"}",
"echo",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"'admin-notice.php'",
",",
"[",
"// WPCS: XSS OK.",
"'type'",
"=>",
"'error'",
",",
"'message'",
"=>",
"'All notification channels are currently disabled. Please enable one or more below.'",
",",
"]",
")",
";",
"}"
] | Print an admin notice indicating to user that no notifiers are currently enabled.
@return void | [
"Print",
"an",
"admin",
"notice",
"indicating",
"to",
"user",
"that",
"no",
"notifiers",
"are",
"currently",
"enabled",
"."
] | f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7 | https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-options-page.php#L157-L170 |
13,020 | ssnepenthe/soter | src/class-options-page.php | Options_Page.render_email_address | public function render_email_address() {
$placeholder = get_bloginfo( 'admin_email' );
$current = $this->options->email_address;
$value = $placeholder === $current ? '' : $current;
echo $this->template->render( // WPCS: XSS OK.
'options/email-address.php',
compact( 'placeholder', 'value' )
);
} | php | public function render_email_address() {
$placeholder = get_bloginfo( 'admin_email' );
$current = $this->options->email_address;
$value = $placeholder === $current ? '' : $current;
echo $this->template->render( // WPCS: XSS OK.
'options/email-address.php',
compact( 'placeholder', 'value' )
);
} | [
"public",
"function",
"render_email_address",
"(",
")",
"{",
"$",
"placeholder",
"=",
"get_bloginfo",
"(",
"'admin_email'",
")",
";",
"$",
"current",
"=",
"$",
"this",
"->",
"options",
"->",
"email_address",
";",
"$",
"value",
"=",
"$",
"placeholder",
"===",
"$",
"current",
"?",
"''",
":",
"$",
"current",
";",
"echo",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"// WPCS: XSS OK.",
"'options/email-address.php'",
",",
"compact",
"(",
"'placeholder'",
",",
"'value'",
")",
")",
";",
"}"
] | Renders the email address field.
@return void | [
"Renders",
"the",
"email",
"address",
"field",
"."
] | f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7 | https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-options-page.php#L177-L186 |
13,021 | ssnepenthe/soter | src/class-options-page.php | Options_Page.render_ignored_plugins | public function render_ignored_plugins() {
$plugins = get_plugins();
$plugins = array_map( function( $key, $value ) {
if ( false === strpos( $key, '/' ) ) {
$slug = basename( $key, '.php' );
} else {
$slug = dirname( $key );
}
return [
'name' => $value['Name'],
'slug' => $slug,
];
}, array_keys( $plugins ), $plugins );
echo $this->template->render( 'options/ignored-packages.php', [ // WPCS: XSS OK.
'ignored_packages' => $this->options->ignored_plugins,
'packages' => $plugins,
'type' => 'plugins',
] );
} | php | public function render_ignored_plugins() {
$plugins = get_plugins();
$plugins = array_map( function( $key, $value ) {
if ( false === strpos( $key, '/' ) ) {
$slug = basename( $key, '.php' );
} else {
$slug = dirname( $key );
}
return [
'name' => $value['Name'],
'slug' => $slug,
];
}, array_keys( $plugins ), $plugins );
echo $this->template->render( 'options/ignored-packages.php', [ // WPCS: XSS OK.
'ignored_packages' => $this->options->ignored_plugins,
'packages' => $plugins,
'type' => 'plugins',
] );
} | [
"public",
"function",
"render_ignored_plugins",
"(",
")",
"{",
"$",
"plugins",
"=",
"get_plugins",
"(",
")",
";",
"$",
"plugins",
"=",
"array_map",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"key",
",",
"'/'",
")",
")",
"{",
"$",
"slug",
"=",
"basename",
"(",
"$",
"key",
",",
"'.php'",
")",
";",
"}",
"else",
"{",
"$",
"slug",
"=",
"dirname",
"(",
"$",
"key",
")",
";",
"}",
"return",
"[",
"'name'",
"=>",
"$",
"value",
"[",
"'Name'",
"]",
",",
"'slug'",
"=>",
"$",
"slug",
",",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"plugins",
")",
",",
"$",
"plugins",
")",
";",
"echo",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"'options/ignored-packages.php'",
",",
"[",
"// WPCS: XSS OK.",
"'ignored_packages'",
"=>",
"$",
"this",
"->",
"options",
"->",
"ignored_plugins",
",",
"'packages'",
"=>",
"$",
"plugins",
",",
"'type'",
"=>",
"'plugins'",
",",
"]",
")",
";",
"}"
] | Renders the ignored plugins field.
@return void | [
"Renders",
"the",
"ignored",
"plugins",
"field",
"."
] | f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7 | https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-options-page.php#L217-L237 |
13,022 | ssnepenthe/soter | src/class-options-page.php | Options_Page.render_ignored_themes | public function render_ignored_themes() {
$themes = array_map( function( $value ) {
return [
'name' => $value->display( 'Name' ),
'slug' => $value->get_stylesheet(),
];
}, wp_get_themes() );
echo $this->template->render( 'options/ignored-packages.php', [ // WPCS: XSS OK.
'ignored_packages' => $this->options->ignored_themes,
'packages' => $themes,
'type' => 'themes',
] );
} | php | public function render_ignored_themes() {
$themes = array_map( function( $value ) {
return [
'name' => $value->display( 'Name' ),
'slug' => $value->get_stylesheet(),
];
}, wp_get_themes() );
echo $this->template->render( 'options/ignored-packages.php', [ // WPCS: XSS OK.
'ignored_packages' => $this->options->ignored_themes,
'packages' => $themes,
'type' => 'themes',
] );
} | [
"public",
"function",
"render_ignored_themes",
"(",
")",
"{",
"$",
"themes",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"value",
"->",
"display",
"(",
"'Name'",
")",
",",
"'slug'",
"=>",
"$",
"value",
"->",
"get_stylesheet",
"(",
")",
",",
"]",
";",
"}",
",",
"wp_get_themes",
"(",
")",
")",
";",
"echo",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"'options/ignored-packages.php'",
",",
"[",
"// WPCS: XSS OK.",
"'ignored_packages'",
"=>",
"$",
"this",
"->",
"options",
"->",
"ignored_themes",
",",
"'packages'",
"=>",
"$",
"themes",
",",
"'type'",
"=>",
"'themes'",
",",
"]",
")",
";",
"}"
] | Renders the ignored themes field.
@return void | [
"Renders",
"the",
"ignored",
"themes",
"field",
"."
] | f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7 | https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-options-page.php#L244-L257 |
13,023 | bariew/yii2-rbac-cms-module | components/TreeBuilder.php | TreeBuilder.nodeAttributes | public function nodeAttributes($model = false, $pid = '', $uniqueKey = false)
{
$uniqueKey = $uniqueKey ? $uniqueKey : self::$uniqueKey++;
$model = ($model) ? $model : $this->owner;
$id = $model[$this->id];
$nodeId = $uniqueKey . '-id-' . $id;
return array(
'id' => $nodeId,
'model' => $model,
'children' => $model[$this->childrenAttribute],
'text' => $model['name'],
'type' => $model['type'] == 1 ? 'user' : 'flag',
'selected' => in_array($model[$this->id], $this->selectedNodes),
'a_attr' => array(
'class' => 'jstree-clicked',
'data-id' => $nodeId,
'href' => [$this->actionPath, $this->id => $id, 'pid'=> $pid]
)
);
} | php | public function nodeAttributes($model = false, $pid = '', $uniqueKey = false)
{
$uniqueKey = $uniqueKey ? $uniqueKey : self::$uniqueKey++;
$model = ($model) ? $model : $this->owner;
$id = $model[$this->id];
$nodeId = $uniqueKey . '-id-' . $id;
return array(
'id' => $nodeId,
'model' => $model,
'children' => $model[$this->childrenAttribute],
'text' => $model['name'],
'type' => $model['type'] == 1 ? 'user' : 'flag',
'selected' => in_array($model[$this->id], $this->selectedNodes),
'a_attr' => array(
'class' => 'jstree-clicked',
'data-id' => $nodeId,
'href' => [$this->actionPath, $this->id => $id, 'pid'=> $pid]
)
);
} | [
"public",
"function",
"nodeAttributes",
"(",
"$",
"model",
"=",
"false",
",",
"$",
"pid",
"=",
"''",
",",
"$",
"uniqueKey",
"=",
"false",
")",
"{",
"$",
"uniqueKey",
"=",
"$",
"uniqueKey",
"?",
"$",
"uniqueKey",
":",
"self",
"::",
"$",
"uniqueKey",
"++",
";",
"$",
"model",
"=",
"(",
"$",
"model",
")",
"?",
"$",
"model",
":",
"$",
"this",
"->",
"owner",
";",
"$",
"id",
"=",
"$",
"model",
"[",
"$",
"this",
"->",
"id",
"]",
";",
"$",
"nodeId",
"=",
"$",
"uniqueKey",
".",
"'-id-'",
".",
"$",
"id",
";",
"return",
"array",
"(",
"'id'",
"=>",
"$",
"nodeId",
",",
"'model'",
"=>",
"$",
"model",
",",
"'children'",
"=>",
"$",
"model",
"[",
"$",
"this",
"->",
"childrenAttribute",
"]",
",",
"'text'",
"=>",
"$",
"model",
"[",
"'name'",
"]",
",",
"'type'",
"=>",
"$",
"model",
"[",
"'type'",
"]",
"==",
"1",
"?",
"'user'",
":",
"'flag'",
",",
"'selected'",
"=>",
"in_array",
"(",
"$",
"model",
"[",
"$",
"this",
"->",
"id",
"]",
",",
"$",
"this",
"->",
"selectedNodes",
")",
",",
"'a_attr'",
"=>",
"array",
"(",
"'class'",
"=>",
"'jstree-clicked'",
",",
"'data-id'",
"=>",
"$",
"nodeId",
",",
"'href'",
"=>",
"[",
"$",
"this",
"->",
"actionPath",
",",
"$",
"this",
"->",
"id",
"=>",
"$",
"id",
",",
"'pid'",
"=>",
"$",
"pid",
"]",
")",
")",
";",
"}"
] | Generates attributes for jstree item from owner model.
@param mixed $model model
@param mixed $pid view item parent id.
@param bool $uniqueKey unique node view id prefix.
@return array attributes | [
"Generates",
"attributes",
"for",
"jstree",
"item",
"from",
"owner",
"model",
"."
] | c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/components/TreeBuilder.php#L64-L84 |
13,024 | bariew/yii2-rbac-cms-module | components/TreeBuilder.php | TreeBuilder.generateTree | public function generateTree($items, $relations)
{
$children = ArrayHelper::map($relations, 'child', 'parent');
foreach ($relations as $relation) {
if (!isset($items[$relation['child']]) || !isset($items[$relation['parent']])) {
continue;
}
$tree = $items[$relation['parent']]['childrenTree'];
$tree[] = &$items[$relation['child']];
$items[$relation['parent']]['childrenTree'] = $tree;
}
return array_diff_key($items, $children);
} | php | public function generateTree($items, $relations)
{
$children = ArrayHelper::map($relations, 'child', 'parent');
foreach ($relations as $relation) {
if (!isset($items[$relation['child']]) || !isset($items[$relation['parent']])) {
continue;
}
$tree = $items[$relation['parent']]['childrenTree'];
$tree[] = &$items[$relation['child']];
$items[$relation['parent']]['childrenTree'] = $tree;
}
return array_diff_key($items, $children);
} | [
"public",
"function",
"generateTree",
"(",
"$",
"items",
",",
"$",
"relations",
")",
"{",
"$",
"children",
"=",
"ArrayHelper",
"::",
"map",
"(",
"$",
"relations",
",",
"'child'",
",",
"'parent'",
")",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"items",
"[",
"$",
"relation",
"[",
"'child'",
"]",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"items",
"[",
"$",
"relation",
"[",
"'parent'",
"]",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"tree",
"=",
"$",
"items",
"[",
"$",
"relation",
"[",
"'parent'",
"]",
"]",
"[",
"'childrenTree'",
"]",
";",
"$",
"tree",
"[",
"]",
"=",
"&",
"$",
"items",
"[",
"$",
"relation",
"[",
"'child'",
"]",
"]",
";",
"$",
"items",
"[",
"$",
"relation",
"[",
"'parent'",
"]",
"]",
"[",
"'childrenTree'",
"]",
"=",
"$",
"tree",
";",
"}",
"return",
"array_diff_key",
"(",
"$",
"items",
",",
"$",
"children",
")",
";",
"}"
] | Generates children tree.
@param $items
@param $relations
@return array $items children tree. | [
"Generates",
"children",
"tree",
"."
] | c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/components/TreeBuilder.php#L92-L105 |
13,025 | AbuseIO/parser-common | src/Parser.php | Parser.startup | protected function startup($parser)
{
$reflect = new ReflectionClass($parser);
$this->configBase = 'parsers.' . $reflect->getShortName();
if (empty(config("{$this->configBase}.parser.name"))) {
$this->failed("Required parser.name is missing in parser configuration");
}
Log::info(
get_class($this) . ': ' .
'Received message from: ' . $this->parsedMail->getHeader('from') . " with subject: '" .
$this->parsedMail->getHeader('subject') . "' arrived at parser: " .
config("{$this->configBase}.parser.name")
);
} | php | protected function startup($parser)
{
$reflect = new ReflectionClass($parser);
$this->configBase = 'parsers.' . $reflect->getShortName();
if (empty(config("{$this->configBase}.parser.name"))) {
$this->failed("Required parser.name is missing in parser configuration");
}
Log::info(
get_class($this) . ': ' .
'Received message from: ' . $this->parsedMail->getHeader('from') . " with subject: '" .
$this->parsedMail->getHeader('subject') . "' arrived at parser: " .
config("{$this->configBase}.parser.name")
);
} | [
"protected",
"function",
"startup",
"(",
"$",
"parser",
")",
"{",
"$",
"reflect",
"=",
"new",
"ReflectionClass",
"(",
"$",
"parser",
")",
";",
"$",
"this",
"->",
"configBase",
"=",
"'parsers.'",
".",
"$",
"reflect",
"->",
"getShortName",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
")",
")",
"{",
"$",
"this",
"->",
"failed",
"(",
"\"Required parser.name is missing in parser configuration\"",
")",
";",
"}",
"Log",
"::",
"info",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"': '",
".",
"'Received message from: '",
".",
"$",
"this",
"->",
"parsedMail",
"->",
"getHeader",
"(",
"'from'",
")",
".",
"\" with subject: '\"",
".",
"$",
"this",
"->",
"parsedMail",
"->",
"getHeader",
"(",
"'subject'",
")",
".",
"\"' arrived at parser: \"",
".",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
")",
";",
"}"
] | Generalize the local config based on the parser class object.
@param object $parser
@return void | [
"Generalize",
"the",
"local",
"config",
"based",
"on",
"the",
"parser",
"class",
"object",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L85-L102 |
13,026 | AbuseIO/parser-common | src/Parser.php | Parser.createWorkingDir | protected function createWorkingDir()
{
$uuid = Uuid::generate(4);
$this->tempPath = "/tmp/abuseio-{$uuid}/";
$this->fs = new Filesystem;
if (!$this->fs->makeDirectory($this->tempPath)) {
return $this->failed("Unable to create directory {$this->tempPath}");
}
return true;
} | php | protected function createWorkingDir()
{
$uuid = Uuid::generate(4);
$this->tempPath = "/tmp/abuseio-{$uuid}/";
$this->fs = new Filesystem;
if (!$this->fs->makeDirectory($this->tempPath)) {
return $this->failed("Unable to create directory {$this->tempPath}");
}
return true;
} | [
"protected",
"function",
"createWorkingDir",
"(",
")",
"{",
"$",
"uuid",
"=",
"Uuid",
"::",
"generate",
"(",
"4",
")",
";",
"$",
"this",
"->",
"tempPath",
"=",
"\"/tmp/abuseio-{$uuid}/\"",
";",
"$",
"this",
"->",
"fs",
"=",
"new",
"Filesystem",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"fs",
"->",
"makeDirectory",
"(",
"$",
"this",
"->",
"tempPath",
")",
")",
"{",
"return",
"$",
"this",
"->",
"failed",
"(",
"\"Unable to create directory {$this->tempPath}\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Setup a working directory for the parser
@return boolean Returns true or call $this->failed() | [
"Setup",
"a",
"working",
"directory",
"for",
"the",
"parser"
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L179-L190 |
13,027 | AbuseIO/parser-common | src/Parser.php | Parser.isKnownFeed | protected function isKnownFeed()
{
if ($this->feedName === false) {
return $this->failed("Parser did not set the required feedName value");
}
if (empty(config("{$this->configBase}.feeds.{$this->feedName}"))) {
$this->warningCount++;
Log::warning(
get_class($this) . ': ' .
"The feed referred as '{$this->feedName}' is not configured in the parser " .
config("{$this->configBase}.parser.name") .
' therefore skipping processing of this e-mail'
);
return false;
}
return true;
} | php | protected function isKnownFeed()
{
if ($this->feedName === false) {
return $this->failed("Parser did not set the required feedName value");
}
if (empty(config("{$this->configBase}.feeds.{$this->feedName}"))) {
$this->warningCount++;
Log::warning(
get_class($this) . ': ' .
"The feed referred as '{$this->feedName}' is not configured in the parser " .
config("{$this->configBase}.parser.name") .
' therefore skipping processing of this e-mail'
);
return false;
}
return true;
} | [
"protected",
"function",
"isKnownFeed",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"feedName",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"failed",
"(",
"\"Parser did not set the required feedName value\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}\"",
")",
")",
")",
"{",
"$",
"this",
"->",
"warningCount",
"++",
";",
"Log",
"::",
"warning",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"': '",
".",
"\"The feed referred as '{$this->feedName}' is not configured in the parser \"",
".",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
".",
"' therefore skipping processing of this e-mail'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if the feed specified is known in the parser config.
@return boolean Returns true or false | [
"Check",
"if",
"the",
"feed",
"specified",
"is",
"known",
"in",
"the",
"parser",
"config",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L196-L214 |
13,028 | AbuseIO/parser-common | src/Parser.php | Parser.hasArfMail | protected function hasArfMail()
{
if ($this->arfMail === false) {
$this->warningCount++;
Log::warning(
get_class($this) . ': ' .
"The feed referred as '{$this->feedName}' has an ARF requirement that was not met"
);
return false;
} else {
return true;
}
} | php | protected function hasArfMail()
{
if ($this->arfMail === false) {
$this->warningCount++;
Log::warning(
get_class($this) . ': ' .
"The feed referred as '{$this->feedName}' has an ARF requirement that was not met"
);
return false;
} else {
return true;
}
} | [
"protected",
"function",
"hasArfMail",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arfMail",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"warningCount",
"++",
";",
"Log",
"::",
"warning",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"': '",
".",
"\"The feed referred as '{$this->feedName}' has an ARF requirement that was not met\"",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] | Check if a valid arfMail was passed along which is required when called.
@return boolean Returns true or false | [
"Check",
"if",
"a",
"valid",
"arfMail",
"was",
"passed",
"along",
"which",
"is",
"required",
"when",
"called",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L220-L232 |
13,029 | AbuseIO/parser-common | src/Parser.php | Parser.isEnabledFeed | protected function isEnabledFeed()
{
if (config("{$this->configBase}.feeds.{$this->feedName}.enabled") !== true) {
Log::warning(
get_class($this) . ': ' .
"The feed '{$this->feedName}' is disabled in the configuration of parser " .
config("{$this->configBase}.parser.name") .
' therefore skipping processing of this e-mail'
);
return false;
}
return true;
} | php | protected function isEnabledFeed()
{
if (config("{$this->configBase}.feeds.{$this->feedName}.enabled") !== true) {
Log::warning(
get_class($this) . ': ' .
"The feed '{$this->feedName}' is disabled in the configuration of parser " .
config("{$this->configBase}.parser.name") .
' therefore skipping processing of this e-mail'
);
return false;
}
return true;
} | [
"protected",
"function",
"isEnabledFeed",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.enabled\"",
")",
"!==",
"true",
")",
"{",
"Log",
"::",
"warning",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"': '",
".",
"\"The feed '{$this->feedName}' is disabled in the configuration of parser \"",
".",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
".",
"' therefore skipping processing of this e-mail'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check and see if a feed is enabled.
@return boolean Returns true or false | [
"Check",
"and",
"see",
"if",
"a",
"feed",
"is",
"enabled",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L238-L250 |
13,030 | AbuseIO/parser-common | src/Parser.php | Parser.hasRequiredFields | protected function hasRequiredFields($report)
{
if (is_array(config("{$this->configBase}.feeds.{$this->feedName}.fields"))) {
$columns = array_filter(config("{$this->configBase}.feeds.{$this->feedName}.fields"));
if (count($columns) > 0) {
foreach ($columns as $column) {
if (!isset($report[$column])) {
Log::warning(
get_class($this) . ': ' .
config("{$this->configBase}.parser.name") . " feed '{$this->feedName}' " .
"says $column is required but is missing, therefore skipping processing of this incident"
);
$this->warningCount++;
return false;
}
}
}
}
return true;
} | php | protected function hasRequiredFields($report)
{
if (is_array(config("{$this->configBase}.feeds.{$this->feedName}.fields"))) {
$columns = array_filter(config("{$this->configBase}.feeds.{$this->feedName}.fields"));
if (count($columns) > 0) {
foreach ($columns as $column) {
if (!isset($report[$column])) {
Log::warning(
get_class($this) . ': ' .
config("{$this->configBase}.parser.name") . " feed '{$this->feedName}' " .
"says $column is required but is missing, therefore skipping processing of this incident"
);
$this->warningCount++;
return false;
}
}
}
}
return true;
} | [
"protected",
"function",
"hasRequiredFields",
"(",
"$",
"report",
")",
"{",
"if",
"(",
"is_array",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.fields\"",
")",
")",
")",
"{",
"$",
"columns",
"=",
"array_filter",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.fields\"",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"columns",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"report",
"[",
"$",
"column",
"]",
")",
")",
"{",
"Log",
"::",
"warning",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"': '",
".",
"config",
"(",
"\"{$this->configBase}.parser.name\"",
")",
".",
"\" feed '{$this->feedName}' \"",
".",
"\"says $column is required but is missing, therefore skipping processing of this incident\"",
")",
";",
"$",
"this",
"->",
"warningCount",
"++",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Check if all required fields are in the report.
@param array $report Report data
@return boolean Returns true or false | [
"Check",
"if",
"all",
"required",
"fields",
"are",
"in",
"the",
"report",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L257-L277 |
13,031 | AbuseIO/parser-common | src/Parser.php | Parser.applyFilters | protected function applyFilters($report, $removeEmpty = true)
{
if ((!empty(config("{$this->configBase}.feeds.{$this->feedName}.filters"))) &&
(is_array(config("{$this->configBase}.feeds.{$this->feedName}.filters")))
) {
$filter_columns = array_filter(config("{$this->configBase}.feeds.{$this->feedName}.filters"));
foreach ($filter_columns as $column) {
if (!empty($report[$column])) {
unset($report[$column]);
}
}
}
// No sense in adding empty fields, so we remove them
if ($removeEmpty) {
foreach ($report as $field => $value) {
if ($value == "" && !is_bool($value)) {
unset($report[$field]);
}
}
}
return $report;
} | php | protected function applyFilters($report, $removeEmpty = true)
{
if ((!empty(config("{$this->configBase}.feeds.{$this->feedName}.filters"))) &&
(is_array(config("{$this->configBase}.feeds.{$this->feedName}.filters")))
) {
$filter_columns = array_filter(config("{$this->configBase}.feeds.{$this->feedName}.filters"));
foreach ($filter_columns as $column) {
if (!empty($report[$column])) {
unset($report[$column]);
}
}
}
// No sense in adding empty fields, so we remove them
if ($removeEmpty) {
foreach ($report as $field => $value) {
if ($value == "" && !is_bool($value)) {
unset($report[$field]);
}
}
}
return $report;
} | [
"protected",
"function",
"applyFilters",
"(",
"$",
"report",
",",
"$",
"removeEmpty",
"=",
"true",
")",
"{",
"if",
"(",
"(",
"!",
"empty",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.filters\"",
")",
")",
")",
"&&",
"(",
"is_array",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.filters\"",
")",
")",
")",
")",
"{",
"$",
"filter_columns",
"=",
"array_filter",
"(",
"config",
"(",
"\"{$this->configBase}.feeds.{$this->feedName}.filters\"",
")",
")",
";",
"foreach",
"(",
"$",
"filter_columns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"report",
"[",
"$",
"column",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"report",
"[",
"$",
"column",
"]",
")",
";",
"}",
"}",
"}",
"// No sense in adding empty fields, so we remove them",
"if",
"(",
"$",
"removeEmpty",
")",
"{",
"foreach",
"(",
"$",
"report",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"\"\"",
"&&",
"!",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"report",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"report",
";",
"}"
] | Filter the unwanted and empty fields from the report.
@param array $report The report that needs filtering base on config elements
@param boolean $removeEmpty Option to remove empty fields from report, default is true
@return array $report The filtered version of the report | [
"Filter",
"the",
"unwanted",
"and",
"empty",
"fields",
"from",
"the",
"report",
"."
] | a77707df73908a3e9770f5bd8504fe444b5576b8 | https://github.com/AbuseIO/parser-common/blob/a77707df73908a3e9770f5bd8504fe444b5576b8/src/Parser.php#L285-L308 |
13,032 | buonzz/laravel-4-freegeoip | src/Buonzz/GeoIP/GeoIP.php | GeoIP.getItem | private function getItem($name){
if($this->geoip_data == NULL)
$this->retrievefromCache();
return $this->geoip_data->$name;
} | php | private function getItem($name){
if($this->geoip_data == NULL)
$this->retrievefromCache();
return $this->geoip_data->$name;
} | [
"private",
"function",
"getItem",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"geoip_data",
"==",
"NULL",
")",
"$",
"this",
"->",
"retrievefromCache",
"(",
")",
";",
"return",
"$",
"this",
"->",
"geoip_data",
"->",
"$",
"name",
";",
"}"
] | generic property retriever.
@return string | [
"generic",
"property",
"retriever",
"."
] | 0944809d7b98f7beea00b1614f33d74b60931272 | https://github.com/buonzz/laravel-4-freegeoip/blob/0944809d7b98f7beea00b1614f33d74b60931272/src/Buonzz/GeoIP/GeoIP.php#L143-L149 |
13,033 | buonzz/laravel-4-freegeoip | src/Buonzz/GeoIP/GeoIP.php | GeoIP.retrievefromCache | private function retrievefromCache(){
if (class_exists('\\Cache'))
{
$cache_key = 'laravel-4-freegeoip-'. $this->ip;
if (\Cache::has($cache_key))
$this->geoip_data = \Cache::get($cache_key);
else
{
$this->geoip_data = $this->resolve($this->ip);
\Cache::put($cache_key, $this->geoip_data , 60*60);
}
}
else
$this->geoip_data = $this->resolve($this->ip);
} | php | private function retrievefromCache(){
if (class_exists('\\Cache'))
{
$cache_key = 'laravel-4-freegeoip-'. $this->ip;
if (\Cache::has($cache_key))
$this->geoip_data = \Cache::get($cache_key);
else
{
$this->geoip_data = $this->resolve($this->ip);
\Cache::put($cache_key, $this->geoip_data , 60*60);
}
}
else
$this->geoip_data = $this->resolve($this->ip);
} | [
"private",
"function",
"retrievefromCache",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'\\\\Cache'",
")",
")",
"{",
"$",
"cache_key",
"=",
"'laravel-4-freegeoip-'",
".",
"$",
"this",
"->",
"ip",
";",
"if",
"(",
"\\",
"Cache",
"::",
"has",
"(",
"$",
"cache_key",
")",
")",
"$",
"this",
"->",
"geoip_data",
"=",
"\\",
"Cache",
"::",
"get",
"(",
"$",
"cache_key",
")",
";",
"else",
"{",
"$",
"this",
"->",
"geoip_data",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"this",
"->",
"ip",
")",
";",
"\\",
"Cache",
"::",
"put",
"(",
"$",
"cache_key",
",",
"$",
"this",
"->",
"geoip_data",
",",
"60",
"*",
"60",
")",
";",
"}",
"}",
"else",
"$",
"this",
"->",
"geoip_data",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"this",
"->",
"ip",
")",
";",
"}"
] | check if the Cache class exists and use caching mechanism if there is, otherwise just call the API directly.
@return void | [
"check",
"if",
"the",
"Cache",
"class",
"exists",
"and",
"use",
"caching",
"mechanism",
"if",
"there",
"is",
"otherwise",
"just",
"call",
"the",
"API",
"directly",
"."
] | 0944809d7b98f7beea00b1614f33d74b60931272 | https://github.com/buonzz/laravel-4-freegeoip/blob/0944809d7b98f7beea00b1614f33d74b60931272/src/Buonzz/GeoIP/GeoIP.php#L156-L173 |
13,034 | buonzz/laravel-4-freegeoip | src/Buonzz/GeoIP/GeoIP.php | GeoIP.resolve | function resolve($ip){
$url = \Config::get('laravel-4-freegeoip::freegeoipURL').$ip;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, \Config::get('laravel-4-freegeoip::timeout'));
$file_contents = curl_exec($ch);
curl_close($ch);
$data = json_decode($file_contents);
if($data == NULL)
throw new \Exception("Problems in retrieving data from http://freegeoip.net");
return $data;
} | php | function resolve($ip){
$url = \Config::get('laravel-4-freegeoip::freegeoipURL').$ip;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, \Config::get('laravel-4-freegeoip::timeout'));
$file_contents = curl_exec($ch);
curl_close($ch);
$data = json_decode($file_contents);
if($data == NULL)
throw new \Exception("Problems in retrieving data from http://freegeoip.net");
return $data;
} | [
"function",
"resolve",
"(",
"$",
"ip",
")",
"{",
"$",
"url",
"=",
"\\",
"Config",
"::",
"get",
"(",
"'laravel-4-freegeoip::freegeoipURL'",
")",
".",
"$",
"ip",
";",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"\\",
"Config",
"::",
"get",
"(",
"'laravel-4-freegeoip::timeout'",
")",
")",
";",
"$",
"file_contents",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"file_contents",
")",
";",
"if",
"(",
"$",
"data",
"==",
"NULL",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Problems in retrieving data from http://freegeoip.net\"",
")",
";",
"return",
"$",
"data",
";",
"}"
] | call the freegeoip.net for data, retrieve it as JSON and convert it to stdclass.
@todo make this thing use Guzzle instead, you novice kid!
@return void | [
"call",
"the",
"freegeoip",
".",
"net",
"for",
"data",
"retrieve",
"it",
"as",
"JSON",
"and",
"convert",
"it",
"to",
"stdclass",
"."
] | 0944809d7b98f7beea00b1614f33d74b60931272 | https://github.com/buonzz/laravel-4-freegeoip/blob/0944809d7b98f7beea00b1614f33d74b60931272/src/Buonzz/GeoIP/GeoIP.php#L183-L201 |
13,035 | kriskbx/mikado | src/Mikado.php | Mikado.get | public function get($identifier)
{
if(!isset($this->managers[$identifier]))
throw new InvalidArgumentException('A manager with that identifier does not exist.');
return $this->managers[$identifier];
} | php | public function get($identifier)
{
if(!isset($this->managers[$identifier]))
throw new InvalidArgumentException('A manager with that identifier does not exist.');
return $this->managers[$identifier];
} | [
"public",
"function",
"get",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"managers",
"[",
"$",
"identifier",
"]",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A manager with that identifier does not exist.'",
")",
";",
"return",
"$",
"this",
"->",
"managers",
"[",
"$",
"identifier",
"]",
";",
"}"
] | Get manager by the given identifier.
@param $identifier
@throws InvalidArgumentException
@return mixed | [
"Get",
"manager",
"by",
"the",
"given",
"identifier",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Mikado.php#L40-L46 |
13,036 | ionutmilica/laravel-settings | src/Drivers/Database.php | Database.load | public function load()
{
$data = [];
$settings = $this->database->select('SELECT * FROM '.$this->table);
foreach ($settings as $setting) {
$id = $setting->id;
$value = $setting->value;
$decoded = json_decode($value, 1, 512);
if (is_array($decoded)) {
$value = $decoded;
}
Arr::set($data, $id, $value);
}
return $data;
} | php | public function load()
{
$data = [];
$settings = $this->database->select('SELECT * FROM '.$this->table);
foreach ($settings as $setting) {
$id = $setting->id;
$value = $setting->value;
$decoded = json_decode($value, 1, 512);
if (is_array($decoded)) {
$value = $decoded;
}
Arr::set($data, $id, $value);
}
return $data;
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"database",
"->",
"select",
"(",
"'SELECT * FROM '",
".",
"$",
"this",
"->",
"table",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"setting",
")",
"{",
"$",
"id",
"=",
"$",
"setting",
"->",
"id",
";",
"$",
"value",
"=",
"$",
"setting",
"->",
"value",
";",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"value",
",",
"1",
",",
"512",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"decoded",
")",
")",
"{",
"$",
"value",
"=",
"$",
"decoded",
";",
"}",
"Arr",
"::",
"set",
"(",
"$",
"data",
",",
"$",
"id",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Fetch the settings from the database
@return array | [
"Fetch",
"the",
"settings",
"from",
"the",
"database"
] | becbd839f8c1c1bcbfde42ea808f1c69e5233dee | https://github.com/ionutmilica/laravel-settings/blob/becbd839f8c1c1bcbfde42ea808f1c69e5233dee/src/Drivers/Database.php#L38-L57 |
13,037 | itrnka/ha-framework | src/ha/Access/HTTP/Router/Builder/HTTPRouterBuilderExample.php | HTTPRouterBuilderExample.buildRouter | public function buildRouter() : HTTPRouter
{
// create router dependencies and router instance
$request = new HTTPInputRequestDefault();
$response = new HTTPOutputResponseDefault($request);
$errHandler = new HTTPErrorHandlerDefault();
$router = new HTTPRouterDefault($request, $response, $errHandler);
// prepare authorizations
$authorizationDisabled = new AuthorizationDisabled();
// add your routes here
$router->addRoute(new HTTPRouteExample($request, $response, $authorizationDisabled));
// return
return $router;
} | php | public function buildRouter() : HTTPRouter
{
// create router dependencies and router instance
$request = new HTTPInputRequestDefault();
$response = new HTTPOutputResponseDefault($request);
$errHandler = new HTTPErrorHandlerDefault();
$router = new HTTPRouterDefault($request, $response, $errHandler);
// prepare authorizations
$authorizationDisabled = new AuthorizationDisabled();
// add your routes here
$router->addRoute(new HTTPRouteExample($request, $response, $authorizationDisabled));
// return
return $router;
} | [
"public",
"function",
"buildRouter",
"(",
")",
":",
"HTTPRouter",
"{",
"// create router dependencies and router instance",
"$",
"request",
"=",
"new",
"HTTPInputRequestDefault",
"(",
")",
";",
"$",
"response",
"=",
"new",
"HTTPOutputResponseDefault",
"(",
"$",
"request",
")",
";",
"$",
"errHandler",
"=",
"new",
"HTTPErrorHandlerDefault",
"(",
")",
";",
"$",
"router",
"=",
"new",
"HTTPRouterDefault",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"errHandler",
")",
";",
"// prepare authorizations",
"$",
"authorizationDisabled",
"=",
"new",
"AuthorizationDisabled",
"(",
")",
";",
"// add your routes here",
"$",
"router",
"->",
"addRoute",
"(",
"new",
"HTTPRouteExample",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"authorizationDisabled",
")",
")",
";",
"// return",
"return",
"$",
"router",
";",
"}"
] | Build and return Router.
@return HTTPRouter | [
"Build",
"and",
"return",
"Router",
"."
] | a72b09c28f8e966c37f98a0004e4fbbce80df42c | https://github.com/itrnka/ha-framework/blob/a72b09c28f8e966c37f98a0004e4fbbce80df42c/src/ha/Access/HTTP/Router/Builder/HTTPRouterBuilderExample.php#L37-L53 |
13,038 | chippyash/Strong-Type | src/Chippyash/Type/RequiredType.php | RequiredType.get | public function get()
{
if ($this->requiredType == self::TYPE_DEFAULT) {
$this->requiredType = (extension_loaded('gmp') ? self::TYPE_GMP : self::TYPE_NATIVE);
}
return $this->requiredType;
} | php | public function get()
{
if ($this->requiredType == self::TYPE_DEFAULT) {
$this->requiredType = (extension_loaded('gmp') ? self::TYPE_GMP : self::TYPE_NATIVE);
}
return $this->requiredType;
} | [
"public",
"function",
"get",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requiredType",
"==",
"self",
"::",
"TYPE_DEFAULT",
")",
"{",
"$",
"this",
"->",
"requiredType",
"=",
"(",
"extension_loaded",
"(",
"'gmp'",
")",
"?",
"self",
"::",
"TYPE_GMP",
":",
"self",
"::",
"TYPE_NATIVE",
")",
";",
"}",
"return",
"$",
"this",
"->",
"requiredType",
";",
"}"
] | Return required number base type
@return string | [
"Return",
"required",
"number",
"base",
"type"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/RequiredType.php#L46-L53 |
13,039 | chippyash/Strong-Type | src/Chippyash/Type/RequiredType.php | RequiredType.set | public function set($requiredType)
{
if (!in_array($requiredType, $this->validTypes)) {
throw new \InvalidArgumentException("{$requiredType} is not a supported number type");
}
if ($requiredType == self::TYPE_GMP && !extension_loaded('gmp')) {
throw new \InvalidArgumentException('GMP not supported');
}
$this->requiredType = $requiredType;
return $this;
} | php | public function set($requiredType)
{
if (!in_array($requiredType, $this->validTypes)) {
throw new \InvalidArgumentException("{$requiredType} is not a supported number type");
}
if ($requiredType == self::TYPE_GMP && !extension_loaded('gmp')) {
throw new \InvalidArgumentException('GMP not supported');
}
$this->requiredType = $requiredType;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"requiredType",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"requiredType",
",",
"$",
"this",
"->",
"validTypes",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"{$requiredType} is not a supported number type\"",
")",
";",
"}",
"if",
"(",
"$",
"requiredType",
"==",
"self",
"::",
"TYPE_GMP",
"&&",
"!",
"extension_loaded",
"(",
"'gmp'",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'GMP not supported'",
")",
";",
"}",
"$",
"this",
"->",
"requiredType",
"=",
"$",
"requiredType",
";",
"return",
"$",
"this",
";",
"}"
] | Set the required number base type
@param $requiredType
@return $this | [
"Set",
"the",
"required",
"number",
"base",
"type"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/RequiredType.php#L62-L74 |
13,040 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php | HTMLPurifier_HTMLModule.parseContents | public function parseContents($contents) {
if (!is_string($contents)) return array(null, null); // defer
switch ($contents) {
// check for shorthand content model forms
case 'Empty':
return array('empty', '');
case 'Inline':
return array('optional', 'Inline | #PCDATA');
case 'Flow':
return array('optional', 'Flow | #PCDATA');
}
list($content_model_type, $content_model) = explode(':', $contents);
$content_model_type = strtolower(trim($content_model_type));
$content_model = trim($content_model);
return array($content_model_type, $content_model);
} | php | public function parseContents($contents) {
if (!is_string($contents)) return array(null, null); // defer
switch ($contents) {
// check for shorthand content model forms
case 'Empty':
return array('empty', '');
case 'Inline':
return array('optional', 'Inline | #PCDATA');
case 'Flow':
return array('optional', 'Flow | #PCDATA');
}
list($content_model_type, $content_model) = explode(':', $contents);
$content_model_type = strtolower(trim($content_model_type));
$content_model = trim($content_model);
return array($content_model_type, $content_model);
} | [
"public",
"function",
"parseContents",
"(",
"$",
"contents",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"contents",
")",
")",
"return",
"array",
"(",
"null",
",",
"null",
")",
";",
"// defer",
"switch",
"(",
"$",
"contents",
")",
"{",
"// check for shorthand content model forms",
"case",
"'Empty'",
":",
"return",
"array",
"(",
"'empty'",
",",
"''",
")",
";",
"case",
"'Inline'",
":",
"return",
"array",
"(",
"'optional'",
",",
"'Inline | #PCDATA'",
")",
";",
"case",
"'Flow'",
":",
"return",
"array",
"(",
"'optional'",
",",
"'Flow | #PCDATA'",
")",
";",
"}",
"list",
"(",
"$",
"content_model_type",
",",
"$",
"content_model",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"contents",
")",
";",
"$",
"content_model_type",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"content_model_type",
")",
")",
";",
"$",
"content_model",
"=",
"trim",
"(",
"$",
"content_model",
")",
";",
"return",
"array",
"(",
"$",
"content_model_type",
",",
"$",
"content_model",
")",
";",
"}"
] | Convenience function that transforms single-string contents
into separate content model and content model type
@param $contents Allowed children in form of:
"$content_model_type: $content_model"
@note If contents is an object, an array of two nulls will be
returned, and the callee needs to take the original $contents
and use it directly. | [
"Convenience",
"function",
"that",
"transforms",
"single",
"-",
"string",
"contents",
"into",
"separate",
"content",
"model",
"and",
"content",
"model",
"type"
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php#L185-L200 |
13,041 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php | HTMLPurifier_HTMLModule.mergeInAttrIncludes | public function mergeInAttrIncludes(&$attr, $attr_includes) {
if (!is_array($attr_includes)) {
if (empty($attr_includes)) $attr_includes = array();
else $attr_includes = array($attr_includes);
}
$attr[0] = $attr_includes;
} | php | public function mergeInAttrIncludes(&$attr, $attr_includes) {
if (!is_array($attr_includes)) {
if (empty($attr_includes)) $attr_includes = array();
else $attr_includes = array($attr_includes);
}
$attr[0] = $attr_includes;
} | [
"public",
"function",
"mergeInAttrIncludes",
"(",
"&",
"$",
"attr",
",",
"$",
"attr_includes",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attr_includes",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"attr_includes",
")",
")",
"$",
"attr_includes",
"=",
"array",
"(",
")",
";",
"else",
"$",
"attr_includes",
"=",
"array",
"(",
"$",
"attr_includes",
")",
";",
"}",
"$",
"attr",
"[",
"0",
"]",
"=",
"$",
"attr_includes",
";",
"}"
] | Convenience function that merges a list of attribute includes into
an attribute array.
@param $attr Reference to attr array to modify
@param $attr_includes Array of includes / string include to merge in | [
"Convenience",
"function",
"that",
"merges",
"a",
"list",
"of",
"attribute",
"includes",
"into",
"an",
"attribute",
"array",
"."
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php#L208-L214 |
13,042 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php | HTMLPurifier_HTMLModule.makeLookup | public function makeLookup($list) {
if (is_string($list)) $list = func_get_args();
$ret = array();
foreach ($list as $value) {
if (is_null($value)) continue;
$ret[$value] = true;
}
return $ret;
} | php | public function makeLookup($list) {
if (is_string($list)) $list = func_get_args();
$ret = array();
foreach ($list as $value) {
if (is_null($value)) continue;
$ret[$value] = true;
}
return $ret;
} | [
"public",
"function",
"makeLookup",
"(",
"$",
"list",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"list",
")",
")",
"$",
"list",
"=",
"func_get_args",
"(",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"continue",
";",
"$",
"ret",
"[",
"$",
"value",
"]",
"=",
"true",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Convenience function that generates a lookup table with boolean
true as value.
@param $list List of values to turn into a lookup
@note You can also pass an arbitrary number of arguments in
place of the regular argument
@return Lookup array equivalent of list | [
"Convenience",
"function",
"that",
"generates",
"a",
"lookup",
"table",
"with",
"boolean",
"true",
"as",
"value",
"."
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/HTMLModule.php#L224-L232 |
13,043 | wshafer/assetmanager-core | src/Resolver/FileResolverAbstract.php | FileResolverAbstract.getFileAsset | protected function getFileAsset($filePath)
{
$file = new \SplFileInfo($filePath);
if (!$file->isReadable() || $file->isDir()) {
return null;
}
$filePath = $file->getRealPath();
return new FileAsset($filePath);
} | php | protected function getFileAsset($filePath)
{
$file = new \SplFileInfo($filePath);
if (!$file->isReadable() || $file->isDir()) {
return null;
}
$filePath = $file->getRealPath();
return new FileAsset($filePath);
} | [
"protected",
"function",
"getFileAsset",
"(",
"$",
"filePath",
")",
"{",
"$",
"file",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"isReadable",
"(",
")",
"||",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"filePath",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"return",
"new",
"FileAsset",
"(",
"$",
"filePath",
")",
";",
"}"
] | Get a File Asset
@param string $filePath
@return FileAsset|null | [
"Get",
"a",
"File",
"Asset"
] | b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d | https://github.com/wshafer/assetmanager-core/blob/b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d/src/Resolver/FileResolverAbstract.php#L49-L60 |
13,044 | joomla-projects/jorobo | src/Tasks/Build/Language.php | Language.copyLanguage | public function copyLanguage($dir, $target)
{
// Equals administrator/language or language
$path = $this->getSourceFolder() . "/" . $dir;
$files = array();
$hdl = opendir($path);
while ($entry = readdir($hdl))
{
$p = $path . "/" . $entry;
// Which languages do we have
// Ignore hidden files
if (substr($entry, 0, 1) != '.')
{
// Language folders
if (!is_file($p))
{
// Make folder at destination
$this->_mkdir($target . "/" . $dir . "/" . $entry);
$fileHdl = opendir($p);
while ($file = readdir($fileHdl))
{
// Only copy language files for this extension (and sys files..)
if (substr($file, 0, 1) != '.' && strpos($file, $this->ext . "."))
{
$files[] = array($entry => $file);
// Copy file
$this->_copy($p . "/" . $file, $target . "/" . $dir . "/" . $entry . "/" . $file);
}
}
closedir($fileHdl);
}
}
}
closedir($hdl);
return $files;
} | php | public function copyLanguage($dir, $target)
{
// Equals administrator/language or language
$path = $this->getSourceFolder() . "/" . $dir;
$files = array();
$hdl = opendir($path);
while ($entry = readdir($hdl))
{
$p = $path . "/" . $entry;
// Which languages do we have
// Ignore hidden files
if (substr($entry, 0, 1) != '.')
{
// Language folders
if (!is_file($p))
{
// Make folder at destination
$this->_mkdir($target . "/" . $dir . "/" . $entry);
$fileHdl = opendir($p);
while ($file = readdir($fileHdl))
{
// Only copy language files for this extension (and sys files..)
if (substr($file, 0, 1) != '.' && strpos($file, $this->ext . "."))
{
$files[] = array($entry => $file);
// Copy file
$this->_copy($p . "/" . $file, $target . "/" . $dir . "/" . $entry . "/" . $file);
}
}
closedir($fileHdl);
}
}
}
closedir($hdl);
return $files;
} | [
"public",
"function",
"copyLanguage",
"(",
"$",
"dir",
",",
"$",
"target",
")",
"{",
"// Equals administrator/language or language",
"$",
"path",
"=",
"$",
"this",
"->",
"getSourceFolder",
"(",
")",
".",
"\"/\"",
".",
"$",
"dir",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"hdl",
"=",
"opendir",
"(",
"$",
"path",
")",
";",
"while",
"(",
"$",
"entry",
"=",
"readdir",
"(",
"$",
"hdl",
")",
")",
"{",
"$",
"p",
"=",
"$",
"path",
".",
"\"/\"",
".",
"$",
"entry",
";",
"// Which languages do we have",
"// Ignore hidden files",
"if",
"(",
"substr",
"(",
"$",
"entry",
",",
"0",
",",
"1",
")",
"!=",
"'.'",
")",
"{",
"// Language folders",
"if",
"(",
"!",
"is_file",
"(",
"$",
"p",
")",
")",
"{",
"// Make folder at destination",
"$",
"this",
"->",
"_mkdir",
"(",
"$",
"target",
".",
"\"/\"",
".",
"$",
"dir",
".",
"\"/\"",
".",
"$",
"entry",
")",
";",
"$",
"fileHdl",
"=",
"opendir",
"(",
"$",
"p",
")",
";",
"while",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"fileHdl",
")",
")",
"{",
"// Only copy language files for this extension (and sys files..)",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"!=",
"'.'",
"&&",
"strpos",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"ext",
".",
"\".\"",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"array",
"(",
"$",
"entry",
"=>",
"$",
"file",
")",
";",
"// Copy file",
"$",
"this",
"->",
"_copy",
"(",
"$",
"p",
".",
"\"/\"",
".",
"$",
"file",
",",
"$",
"target",
".",
"\"/\"",
".",
"$",
"dir",
".",
"\"/\"",
".",
"$",
"entry",
".",
"\"/\"",
".",
"$",
"file",
")",
";",
"}",
"}",
"closedir",
"(",
"$",
"fileHdl",
")",
";",
"}",
"}",
"}",
"closedir",
"(",
"$",
"hdl",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Copy language files
@param string $dir The directory (administrator/language or language or mod_xy/language etc)
@param String $target The target directory
@return array
@since 1.0 | [
"Copy",
"language",
"files"
] | e72dd0ed15f387739f67cacdbc2c0bd1b427f317 | https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Build/Language.php#L216-L260 |
13,045 | markwatkinson/luminous | src/Luminous/Scanners/ScalaScanner.php | ScalaScanner.xmlOverride | public function xmlOverride($matches)
{
// this might just be an inequality, so we first need to disambiguate
// that
// 1.5 - the disambiguation is pretty simple, an XML tag must
// follow either whitespace, (, or {, and the '<' must be followed
// by '[!?_a-zA-Z]
// I'm not sure if a comment is a special case, or if it's treated as
// whitespace...
$xml = false;
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
$tok = $this->tokens[$i];
$name = $tok[0];
// ... but we're going treat it as a no-op and skip over it
if ($name === 'COMMENT') {
continue;
}
$lastChar = $tok[1][strlen($tok[1]) - 1];
if (!(ctype_space($lastChar) || $lastChar === '(' || $lastChar === '{')) {
break;
}
if (!$this->check('/<[!?a-zA-Z0-9_]/')) {
break;
}
$xml = true;
}
if (!$xml) {
$this->record($matches[0], 'OPERATOR');
$this->posShift(strlen($matches[0]));
return;
}
$subscanner = new XmlScanner();
$subscanner->string($this->string());
$subscanner->pos($this->pos());
$subscanner->xmlLiteral = true;
$subscanner->init();
$subscanner->main();
$tagged = $subscanner->tagged();
$this->record($tagged, 'XML', true);
$this->pos($subscanner->pos());
} | php | public function xmlOverride($matches)
{
// this might just be an inequality, so we first need to disambiguate
// that
// 1.5 - the disambiguation is pretty simple, an XML tag must
// follow either whitespace, (, or {, and the '<' must be followed
// by '[!?_a-zA-Z]
// I'm not sure if a comment is a special case, or if it's treated as
// whitespace...
$xml = false;
for ($i = count($this->tokens) - 1; $i >= 0; $i--) {
$tok = $this->tokens[$i];
$name = $tok[0];
// ... but we're going treat it as a no-op and skip over it
if ($name === 'COMMENT') {
continue;
}
$lastChar = $tok[1][strlen($tok[1]) - 1];
if (!(ctype_space($lastChar) || $lastChar === '(' || $lastChar === '{')) {
break;
}
if (!$this->check('/<[!?a-zA-Z0-9_]/')) {
break;
}
$xml = true;
}
if (!$xml) {
$this->record($matches[0], 'OPERATOR');
$this->posShift(strlen($matches[0]));
return;
}
$subscanner = new XmlScanner();
$subscanner->string($this->string());
$subscanner->pos($this->pos());
$subscanner->xmlLiteral = true;
$subscanner->init();
$subscanner->main();
$tagged = $subscanner->tagged();
$this->record($tagged, 'XML', true);
$this->pos($subscanner->pos());
} | [
"public",
"function",
"xmlOverride",
"(",
"$",
"matches",
")",
"{",
"// this might just be an inequality, so we first need to disambiguate",
"// that",
"// 1.5 - the disambiguation is pretty simple, an XML tag must",
"// follow either whitespace, (, or {, and the '<' must be followed",
"// by '[!?_a-zA-Z]",
"// I'm not sure if a comment is a special case, or if it's treated as",
"// whitespace...",
"$",
"xml",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
";",
"$",
"name",
"=",
"$",
"tok",
"[",
"0",
"]",
";",
"// ... but we're going treat it as a no-op and skip over it",
"if",
"(",
"$",
"name",
"===",
"'COMMENT'",
")",
"{",
"continue",
";",
"}",
"$",
"lastChar",
"=",
"$",
"tok",
"[",
"1",
"]",
"[",
"strlen",
"(",
"$",
"tok",
"[",
"1",
"]",
")",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"(",
"ctype_space",
"(",
"$",
"lastChar",
")",
"||",
"$",
"lastChar",
"===",
"'('",
"||",
"$",
"lastChar",
"===",
"'{'",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"check",
"(",
"'/<[!?a-zA-Z0-9_]/'",
")",
")",
"{",
"break",
";",
"}",
"$",
"xml",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"xml",
")",
"{",
"$",
"this",
"->",
"record",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"'OPERATOR'",
")",
";",
"$",
"this",
"->",
"posShift",
"(",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"return",
";",
"}",
"$",
"subscanner",
"=",
"new",
"XmlScanner",
"(",
")",
";",
"$",
"subscanner",
"->",
"string",
"(",
"$",
"this",
"->",
"string",
"(",
")",
")",
";",
"$",
"subscanner",
"->",
"pos",
"(",
"$",
"this",
"->",
"pos",
"(",
")",
")",
";",
"$",
"subscanner",
"->",
"xmlLiteral",
"=",
"true",
";",
"$",
"subscanner",
"->",
"init",
"(",
")",
";",
"$",
"subscanner",
"->",
"main",
"(",
")",
";",
"$",
"tagged",
"=",
"$",
"subscanner",
"->",
"tagged",
"(",
")",
";",
"$",
"this",
"->",
"record",
"(",
"$",
"tagged",
",",
"'XML'",
",",
"true",
")",
";",
"$",
"this",
"->",
"pos",
"(",
"$",
"subscanner",
"->",
"pos",
"(",
")",
")",
";",
"}"
] | Scala has XML literals. | [
"Scala",
"has",
"XML",
"literals",
"."
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners/ScalaScanner.php#L35-L76 |
13,046 | ptlis/conneg | src/Preference/Matched/MatchedPreference.php | MatchedPreference.getVariant | public function getVariant()
{
// Special handling for language partial matches. These require that the returned variant name is the portion of
// the language before the wildcard as this is what the application will be using to encode the response.
if ($this->isLanguageWildcard()) {
return str_replace('-*', '', $this->serverPref->getVariant());
// If the client contained a wildcard or is absent return the concrete variant from teh server.
} elseif ($this->clientWildcardOrAbsent()) {
return $this->serverPref->getVariant();
// In all other cases the client is canonical
} else {
return $this->clientPref->getVariant();
}
} | php | public function getVariant()
{
// Special handling for language partial matches. These require that the returned variant name is the portion of
// the language before the wildcard as this is what the application will be using to encode the response.
if ($this->isLanguageWildcard()) {
return str_replace('-*', '', $this->serverPref->getVariant());
// If the client contained a wildcard or is absent return the concrete variant from teh server.
} elseif ($this->clientWildcardOrAbsent()) {
return $this->serverPref->getVariant();
// In all other cases the client is canonical
} else {
return $this->clientPref->getVariant();
}
} | [
"public",
"function",
"getVariant",
"(",
")",
"{",
"// Special handling for language partial matches. These require that the returned variant name is the portion of",
"// the language before the wildcard as this is what the application will be using to encode the response.",
"if",
"(",
"$",
"this",
"->",
"isLanguageWildcard",
"(",
")",
")",
"{",
"return",
"str_replace",
"(",
"'-*'",
",",
"''",
",",
"$",
"this",
"->",
"serverPref",
"->",
"getVariant",
"(",
")",
")",
";",
"// If the client contained a wildcard or is absent return the concrete variant from teh server.",
"}",
"elseif",
"(",
"$",
"this",
"->",
"clientWildcardOrAbsent",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"serverPref",
"->",
"getVariant",
"(",
")",
";",
"// In all other cases the client is canonical",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"clientPref",
"->",
"getVariant",
"(",
")",
";",
"}",
"}"
] | Get the shared variant for this pair.
@return string | [
"Get",
"the",
"shared",
"variant",
"for",
"this",
"pair",
"."
] | 04afb568f368ecdd81c13277006c4be041ccb58b | https://github.com/ptlis/conneg/blob/04afb568f368ecdd81c13277006c4be041ccb58b/src/Preference/Matched/MatchedPreference.php#L75-L90 |
13,047 | ptlis/conneg | src/Preference/Matched/MatchedPreference.php | MatchedPreference.isLanguageWildcard | private function isLanguageWildcard()
{
return PreferenceInterface::LANGUAGE === $this->fromField
&& PreferenceInterface::PARTIAL_WILDCARD === $this->serverPref->getPrecedence();
} | php | private function isLanguageWildcard()
{
return PreferenceInterface::LANGUAGE === $this->fromField
&& PreferenceInterface::PARTIAL_WILDCARD === $this->serverPref->getPrecedence();
} | [
"private",
"function",
"isLanguageWildcard",
"(",
")",
"{",
"return",
"PreferenceInterface",
"::",
"LANGUAGE",
"===",
"$",
"this",
"->",
"fromField",
"&&",
"PreferenceInterface",
"::",
"PARTIAL_WILDCARD",
"===",
"$",
"this",
"->",
"serverPref",
"->",
"getPrecedence",
"(",
")",
";",
"}"
] | Returns true if the match was by partial language wildcard.
@return bool | [
"Returns",
"true",
"if",
"the",
"match",
"was",
"by",
"partial",
"language",
"wildcard",
"."
] | 04afb568f368ecdd81c13277006c4be041ccb58b | https://github.com/ptlis/conneg/blob/04afb568f368ecdd81c13277006c4be041ccb58b/src/Preference/Matched/MatchedPreference.php#L97-L101 |
13,048 | antarestupin/Accessible | lib/Accessible/AutomatedBehaviorTrait.php | AutomatedBehaviorTrait.assertPropertyValue | protected function assertPropertyValue($property, $value)
{
$this->getPropertiesInfo();
if ($this->_constraintsValidationEnabled) {
$constraintsViolations = ConstraintsReader::validatePropertyValue($this, $property, $value);
if ($constraintsViolations->count()) {
$errorMessage = "Argument given is invalid; its constraints validation failed for property $property with the following messages: \"";
$errorMessageList = array();
foreach ($constraintsViolations as $violation) {
$errorMessageList[] = $violation->getMessage();
}
$errorMessage .= implode("\", \n\"", $errorMessageList) . "\".";
throw new \InvalidArgumentException($errorMessage);
}
}
} | php | protected function assertPropertyValue($property, $value)
{
$this->getPropertiesInfo();
if ($this->_constraintsValidationEnabled) {
$constraintsViolations = ConstraintsReader::validatePropertyValue($this, $property, $value);
if ($constraintsViolations->count()) {
$errorMessage = "Argument given is invalid; its constraints validation failed for property $property with the following messages: \"";
$errorMessageList = array();
foreach ($constraintsViolations as $violation) {
$errorMessageList[] = $violation->getMessage();
}
$errorMessage .= implode("\", \n\"", $errorMessageList) . "\".";
throw new \InvalidArgumentException($errorMessage);
}
}
} | [
"protected",
"function",
"assertPropertyValue",
"(",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"getPropertiesInfo",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_constraintsValidationEnabled",
")",
"{",
"$",
"constraintsViolations",
"=",
"ConstraintsReader",
"::",
"validatePropertyValue",
"(",
"$",
"this",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"constraintsViolations",
"->",
"count",
"(",
")",
")",
"{",
"$",
"errorMessage",
"=",
"\"Argument given is invalid; its constraints validation failed for property $property with the following messages: \\\"\"",
";",
"$",
"errorMessageList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"constraintsViolations",
"as",
"$",
"violation",
")",
"{",
"$",
"errorMessageList",
"[",
"]",
"=",
"$",
"violation",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"errorMessage",
".=",
"implode",
"(",
"\"\\\", \\n\\\"\"",
",",
"$",
"errorMessageList",
")",
".",
"\"\\\".\"",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"errorMessage",
")",
";",
"}",
"}",
"}"
] | Validates the given value compared to given property constraints.
If the value is not valid, an InvalidArgumentException will be thrown.
@param string $property The name of the reference property.
@param mixed $value The value to check.
@throws \InvalidArgumentException If the value is not valid. | [
"Validates",
"the",
"given",
"value",
"compared",
"to",
"given",
"property",
"constraints",
".",
"If",
"the",
"value",
"is",
"not",
"valid",
"an",
"InvalidArgumentException",
"will",
"be",
"thrown",
"."
] | d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/AutomatedBehaviorTrait.php#L110-L127 |
13,049 | antarestupin/Accessible | lib/Accessible/AutomatedBehaviorTrait.php | AutomatedBehaviorTrait.updatePropertyAssociation | protected function updatePropertyAssociation($property, array $values)
{
$this->getPropertiesInfo();
$oldValue = empty($values['oldValue']) ? null : $values['oldValue'];
$newValue = empty($values['newValue']) ? null : $values['newValue'];
$association = $this->_associationsList[$property];
if (!empty($association)) {
$associatedProperty = $association['property'];
switch ($association['association']) {
case 'inverted':
$invertedGetMethod = 'get' . ucfirst($associatedProperty);
$invertedSetMethod = 'set' . ucfirst($associatedProperty);
if ($oldValue !== null && $oldValue->$invertedGetMethod() === $this) {
$oldValue->$invertedSetMethod(null);
}
if ($newValue !== null && $newValue->$invertedGetMethod() !== $this) {
$newValue->$invertedSetMethod($this);
}
break;
case 'mapped':
$itemName = $association['itemName'];
$mappedGetMethod = 'get' . ucfirst($associatedProperty);
$mappedAddMethod = 'add' . ucfirst($itemName);
$mappedRemoveMethod = 'remove' . ucfirst($itemName);
if ($oldValue !== null && CollectionManager::collectionContains($this, $oldValue->$mappedGetMethod())) {
$oldValue->$mappedRemoveMethod($this);
}
if ($newValue !== null && !CollectionManager::collectionContains($this, $newValue->$mappedGetMethod())) {
$newValue->$mappedAddMethod($this);
}
break;
}
}
} | php | protected function updatePropertyAssociation($property, array $values)
{
$this->getPropertiesInfo();
$oldValue = empty($values['oldValue']) ? null : $values['oldValue'];
$newValue = empty($values['newValue']) ? null : $values['newValue'];
$association = $this->_associationsList[$property];
if (!empty($association)) {
$associatedProperty = $association['property'];
switch ($association['association']) {
case 'inverted':
$invertedGetMethod = 'get' . ucfirst($associatedProperty);
$invertedSetMethod = 'set' . ucfirst($associatedProperty);
if ($oldValue !== null && $oldValue->$invertedGetMethod() === $this) {
$oldValue->$invertedSetMethod(null);
}
if ($newValue !== null && $newValue->$invertedGetMethod() !== $this) {
$newValue->$invertedSetMethod($this);
}
break;
case 'mapped':
$itemName = $association['itemName'];
$mappedGetMethod = 'get' . ucfirst($associatedProperty);
$mappedAddMethod = 'add' . ucfirst($itemName);
$mappedRemoveMethod = 'remove' . ucfirst($itemName);
if ($oldValue !== null && CollectionManager::collectionContains($this, $oldValue->$mappedGetMethod())) {
$oldValue->$mappedRemoveMethod($this);
}
if ($newValue !== null && !CollectionManager::collectionContains($this, $newValue->$mappedGetMethod())) {
$newValue->$mappedAddMethod($this);
}
break;
}
}
} | [
"protected",
"function",
"updatePropertyAssociation",
"(",
"$",
"property",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"getPropertiesInfo",
"(",
")",
";",
"$",
"oldValue",
"=",
"empty",
"(",
"$",
"values",
"[",
"'oldValue'",
"]",
")",
"?",
"null",
":",
"$",
"values",
"[",
"'oldValue'",
"]",
";",
"$",
"newValue",
"=",
"empty",
"(",
"$",
"values",
"[",
"'newValue'",
"]",
")",
"?",
"null",
":",
"$",
"values",
"[",
"'newValue'",
"]",
";",
"$",
"association",
"=",
"$",
"this",
"->",
"_associationsList",
"[",
"$",
"property",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"association",
")",
")",
"{",
"$",
"associatedProperty",
"=",
"$",
"association",
"[",
"'property'",
"]",
";",
"switch",
"(",
"$",
"association",
"[",
"'association'",
"]",
")",
"{",
"case",
"'inverted'",
":",
"$",
"invertedGetMethod",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"associatedProperty",
")",
";",
"$",
"invertedSetMethod",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"associatedProperty",
")",
";",
"if",
"(",
"$",
"oldValue",
"!==",
"null",
"&&",
"$",
"oldValue",
"->",
"$",
"invertedGetMethod",
"(",
")",
"===",
"$",
"this",
")",
"{",
"$",
"oldValue",
"->",
"$",
"invertedSetMethod",
"(",
"null",
")",
";",
"}",
"if",
"(",
"$",
"newValue",
"!==",
"null",
"&&",
"$",
"newValue",
"->",
"$",
"invertedGetMethod",
"(",
")",
"!==",
"$",
"this",
")",
"{",
"$",
"newValue",
"->",
"$",
"invertedSetMethod",
"(",
"$",
"this",
")",
";",
"}",
"break",
";",
"case",
"'mapped'",
":",
"$",
"itemName",
"=",
"$",
"association",
"[",
"'itemName'",
"]",
";",
"$",
"mappedGetMethod",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"associatedProperty",
")",
";",
"$",
"mappedAddMethod",
"=",
"'add'",
".",
"ucfirst",
"(",
"$",
"itemName",
")",
";",
"$",
"mappedRemoveMethod",
"=",
"'remove'",
".",
"ucfirst",
"(",
"$",
"itemName",
")",
";",
"if",
"(",
"$",
"oldValue",
"!==",
"null",
"&&",
"CollectionManager",
"::",
"collectionContains",
"(",
"$",
"this",
",",
"$",
"oldValue",
"->",
"$",
"mappedGetMethod",
"(",
")",
")",
")",
"{",
"$",
"oldValue",
"->",
"$",
"mappedRemoveMethod",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"newValue",
"!==",
"null",
"&&",
"!",
"CollectionManager",
"::",
"collectionContains",
"(",
"$",
"this",
",",
"$",
"newValue",
"->",
"$",
"mappedGetMethod",
"(",
")",
")",
")",
"{",
"$",
"newValue",
"->",
"$",
"mappedAddMethod",
"(",
"$",
"this",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
] | Update the property associated to the given property.
You can pass the old or the new value given to the property.
@param string $property The property of the current class to update
@param object $values An array of old a new value under the following form:
['oldValue' => $oldvalue, 'newValue' => $newValue]
If one of theses values is not given, it will simply not be updated. | [
"Update",
"the",
"property",
"associated",
"to",
"the",
"given",
"property",
".",
"You",
"can",
"pass",
"the",
"old",
"or",
"the",
"new",
"value",
"given",
"to",
"the",
"property",
"."
] | d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/AutomatedBehaviorTrait.php#L138-L175 |
13,050 | antarestupin/Accessible | lib/Accessible/AutomatedBehaviorTrait.php | AutomatedBehaviorTrait.getPropertiesInfo | private function getPropertiesInfo()
{
if (!$this->_automatedBehaviorInitialized) {
$classInfo = Reader::getClassInformation($this);
$this->_accessProperties = $classInfo['accessProperties'];
$this->_collectionsItemNames = $classInfo['collectionsItemNames'];
$this->_associationsList = $classInfo['associationsList'];
$this->_initialPropertiesValues = $classInfo['initialPropertiesValues'];
$this->_initializationNeededArguments = $classInfo['initializationNeededArguments'];
if ($this->_constraintsValidationEnabled === null) {
$this->_constraintsValidationEnabled = $classInfo['constraintsValidationEnabled'];
}
$this->_automatedBehaviorInitialized = true;
}
} | php | private function getPropertiesInfo()
{
if (!$this->_automatedBehaviorInitialized) {
$classInfo = Reader::getClassInformation($this);
$this->_accessProperties = $classInfo['accessProperties'];
$this->_collectionsItemNames = $classInfo['collectionsItemNames'];
$this->_associationsList = $classInfo['associationsList'];
$this->_initialPropertiesValues = $classInfo['initialPropertiesValues'];
$this->_initializationNeededArguments = $classInfo['initializationNeededArguments'];
if ($this->_constraintsValidationEnabled === null) {
$this->_constraintsValidationEnabled = $classInfo['constraintsValidationEnabled'];
}
$this->_automatedBehaviorInitialized = true;
}
} | [
"private",
"function",
"getPropertiesInfo",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_automatedBehaviorInitialized",
")",
"{",
"$",
"classInfo",
"=",
"Reader",
"::",
"getClassInformation",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_accessProperties",
"=",
"$",
"classInfo",
"[",
"'accessProperties'",
"]",
";",
"$",
"this",
"->",
"_collectionsItemNames",
"=",
"$",
"classInfo",
"[",
"'collectionsItemNames'",
"]",
";",
"$",
"this",
"->",
"_associationsList",
"=",
"$",
"classInfo",
"[",
"'associationsList'",
"]",
";",
"$",
"this",
"->",
"_initialPropertiesValues",
"=",
"$",
"classInfo",
"[",
"'initialPropertiesValues'",
"]",
";",
"$",
"this",
"->",
"_initializationNeededArguments",
"=",
"$",
"classInfo",
"[",
"'initializationNeededArguments'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_constraintsValidationEnabled",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_constraintsValidationEnabled",
"=",
"$",
"classInfo",
"[",
"'constraintsValidationEnabled'",
"]",
";",
"}",
"$",
"this",
"->",
"_automatedBehaviorInitialized",
"=",
"true",
";",
"}",
"}"
] | Get every information needed from this class. | [
"Get",
"every",
"information",
"needed",
"from",
"this",
"class",
"."
] | d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/AutomatedBehaviorTrait.php#L180-L197 |
13,051 | venta/framework | src/Console/src/Command/SignatureParser.php | SignatureParser.defineType | private function defineType($array = false, $optional = false): int
{
$type = ($optional) ? InputArgument::OPTIONAL : InputArgument::REQUIRED;
if ($array) {
$type = InputArgument::IS_ARRAY | $type;
}
return $type;
} | php | private function defineType($array = false, $optional = false): int
{
$type = ($optional) ? InputArgument::OPTIONAL : InputArgument::REQUIRED;
if ($array) {
$type = InputArgument::IS_ARRAY | $type;
}
return $type;
} | [
"private",
"function",
"defineType",
"(",
"$",
"array",
"=",
"false",
",",
"$",
"optional",
"=",
"false",
")",
":",
"int",
"{",
"$",
"type",
"=",
"(",
"$",
"optional",
")",
"?",
"InputArgument",
"::",
"OPTIONAL",
":",
"InputArgument",
"::",
"REQUIRED",
";",
"if",
"(",
"$",
"array",
")",
"{",
"$",
"type",
"=",
"InputArgument",
"::",
"IS_ARRAY",
"|",
"$",
"type",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Defines type of an argument or option based on options
@param bool $array
@param bool $optional
@return int | [
"Defines",
"type",
"of",
"an",
"argument",
"or",
"option",
"based",
"on",
"options"
] | 514a7854cc69f84f47e62a58cc55efd68b7c9f83 | https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Console/src/Command/SignatureParser.php#L57-L66 |
13,052 | venta/framework | src/Console/src/Command/SignatureParser.php | SignatureParser.parseParameters | private function parseParameters(): array
{
$arguments = [];
$options = [];
$signatureArguments = $this->getParameters();
foreach ($signatureArguments as $value) {
$item = [];
$matches = [];
$exploded = explode(':', $value);
if (count($exploded) > 0 && preg_match($this->argumentsMatcher, $exploded[0], $matches)) {
$item['name'] = $matches[1];
$item['type'] = $this->defineType($matches[2] === '[]', $matches[3] === '=');
$item['default'] = $matches[4] !== '' ? $matches[4] : null;
$item['description'] = count($exploded) === 2 ? $exploded[1] : null;
if ($matches[2] === '[]' && $item['default'] !== null) {
$item['default'] = explode(',', $item['default']);
}
if (substr($exploded[0], 0, 2) === '--') {
$options[] = $item;
} else {
$arguments[] = $item;
}
}
}
return [
'arguments' => $arguments,
'options' => $options,
];
} | php | private function parseParameters(): array
{
$arguments = [];
$options = [];
$signatureArguments = $this->getParameters();
foreach ($signatureArguments as $value) {
$item = [];
$matches = [];
$exploded = explode(':', $value);
if (count($exploded) > 0 && preg_match($this->argumentsMatcher, $exploded[0], $matches)) {
$item['name'] = $matches[1];
$item['type'] = $this->defineType($matches[2] === '[]', $matches[3] === '=');
$item['default'] = $matches[4] !== '' ? $matches[4] : null;
$item['description'] = count($exploded) === 2 ? $exploded[1] : null;
if ($matches[2] === '[]' && $item['default'] !== null) {
$item['default'] = explode(',', $item['default']);
}
if (substr($exploded[0], 0, 2) === '--') {
$options[] = $item;
} else {
$arguments[] = $item;
}
}
}
return [
'arguments' => $arguments,
'options' => $options,
];
} | [
"private",
"function",
"parseParameters",
"(",
")",
":",
"array",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"signatureArguments",
"=",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"foreach",
"(",
"$",
"signatureArguments",
"as",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"exploded",
"=",
"explode",
"(",
"':'",
",",
"$",
"value",
")",
";",
"if",
"(",
"count",
"(",
"$",
"exploded",
")",
">",
"0",
"&&",
"preg_match",
"(",
"$",
"this",
"->",
"argumentsMatcher",
",",
"$",
"exploded",
"[",
"0",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"item",
"[",
"'name'",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"item",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"defineType",
"(",
"$",
"matches",
"[",
"2",
"]",
"===",
"'[]'",
",",
"$",
"matches",
"[",
"3",
"]",
"===",
"'='",
")",
";",
"$",
"item",
"[",
"'default'",
"]",
"=",
"$",
"matches",
"[",
"4",
"]",
"!==",
"''",
"?",
"$",
"matches",
"[",
"4",
"]",
":",
"null",
";",
"$",
"item",
"[",
"'description'",
"]",
"=",
"count",
"(",
"$",
"exploded",
")",
"===",
"2",
"?",
"$",
"exploded",
"[",
"1",
"]",
":",
"null",
";",
"if",
"(",
"$",
"matches",
"[",
"2",
"]",
"===",
"'[]'",
"&&",
"$",
"item",
"[",
"'default'",
"]",
"!==",
"null",
")",
"{",
"$",
"item",
"[",
"'default'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"item",
"[",
"'default'",
"]",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"exploded",
"[",
"0",
"]",
",",
"0",
",",
"2",
")",
"===",
"'--'",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"else",
"{",
"$",
"arguments",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"}",
"return",
"[",
"'arguments'",
"=>",
"$",
"arguments",
",",
"'options'",
"=>",
"$",
"options",
",",
"]",
";",
"}"
] | Parses arguments and options from signature string,
returns an array with definitions
@return array | [
"Parses",
"arguments",
"and",
"options",
"from",
"signature",
"string",
"returns",
"an",
"array",
"with",
"definitions"
] | 514a7854cc69f84f47e62a58cc55efd68b7c9f83 | https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Console/src/Command/SignatureParser.php#L87-L120 |
13,053 | wangsir0624/queue | src/Worker.php | Worker.bootstrap | protected function bootstrap()
{
if($this->_isBooted) {
return;
}
swoole_set_process_name($this->name . ':master');
$this->installSignals();
$this->_isBooted = true;
} | php | protected function bootstrap()
{
if($this->_isBooted) {
return;
}
swoole_set_process_name($this->name . ':master');
$this->installSignals();
$this->_isBooted = true;
} | [
"protected",
"function",
"bootstrap",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isBooted",
")",
"{",
"return",
";",
"}",
"swoole_set_process_name",
"(",
"$",
"this",
"->",
"name",
".",
"':master'",
")",
";",
"$",
"this",
"->",
"installSignals",
"(",
")",
";",
"$",
"this",
"->",
"_isBooted",
"=",
"true",
";",
"}"
] | bootstrap the worker | [
"bootstrap",
"the",
"worker"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Worker.php#L149-L158 |
13,054 | wangsir0624/queue | src/Worker.php | Worker.installSignals | protected function installSignals()
{
$worker = $this;
swoole_process::signal(SIGTERM, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGINT, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGQUIT, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGCHLD, function() use($worker) {
$worker->handleWorkerExit();
});
} | php | protected function installSignals()
{
$worker = $this;
swoole_process::signal(SIGTERM, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGINT, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGQUIT, function() use($worker) {
$worker->stop();
});
swoole_process::signal(SIGCHLD, function() use($worker) {
$worker->handleWorkerExit();
});
} | [
"protected",
"function",
"installSignals",
"(",
")",
"{",
"$",
"worker",
"=",
"$",
"this",
";",
"swoole_process",
"::",
"signal",
"(",
"SIGTERM",
",",
"function",
"(",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"$",
"worker",
"->",
"stop",
"(",
")",
";",
"}",
")",
";",
"swoole_process",
"::",
"signal",
"(",
"SIGINT",
",",
"function",
"(",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"$",
"worker",
"->",
"stop",
"(",
")",
";",
"}",
")",
";",
"swoole_process",
"::",
"signal",
"(",
"SIGQUIT",
",",
"function",
"(",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"$",
"worker",
"->",
"stop",
"(",
")",
";",
"}",
")",
";",
"swoole_process",
"::",
"signal",
"(",
"SIGCHLD",
",",
"function",
"(",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"$",
"worker",
"->",
"handleWorkerExit",
"(",
")",
";",
"}",
")",
";",
"}"
] | register master signal handlers | [
"register",
"master",
"signal",
"handlers"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Worker.php#L163-L178 |
13,055 | wangsir0624/queue | src/Worker.php | Worker.handleWorkerExit | protected function handleWorkerExit()
{
$result = swoole_process::wait();
if(!empty($this->_noRestartProcesses[$result['pid']])) {
unset($this->_noRestartProcesses[$result['pid']]);
return;
}
if($result['signal'] > 0) {
if($this->restartPolicy & self::RESTART_ON_SIGNAL) {
$this->forkOneWorker();
}
} else {
if($result['code'] > 0) {
$this->_errors[] = microtime(true);
if($this->restartPolicy & self::RESTART_ON_ERROR && !$this->_disableRestartOnError) {
if($this->tooManyErrors()) {
//if exceed the maximum error frequency, stop forking new workers on error
$this->_disableRestartOnError = true;
} else {
$this->forkOneWorker();
}
}
} else {
if($this->restartPolicy & self::RESTART_ON_EXIT) {
$this->forkOneWorker();
}
}
}
} | php | protected function handleWorkerExit()
{
$result = swoole_process::wait();
if(!empty($this->_noRestartProcesses[$result['pid']])) {
unset($this->_noRestartProcesses[$result['pid']]);
return;
}
if($result['signal'] > 0) {
if($this->restartPolicy & self::RESTART_ON_SIGNAL) {
$this->forkOneWorker();
}
} else {
if($result['code'] > 0) {
$this->_errors[] = microtime(true);
if($this->restartPolicy & self::RESTART_ON_ERROR && !$this->_disableRestartOnError) {
if($this->tooManyErrors()) {
//if exceed the maximum error frequency, stop forking new workers on error
$this->_disableRestartOnError = true;
} else {
$this->forkOneWorker();
}
}
} else {
if($this->restartPolicy & self::RESTART_ON_EXIT) {
$this->forkOneWorker();
}
}
}
} | [
"protected",
"function",
"handleWorkerExit",
"(",
")",
"{",
"$",
"result",
"=",
"swoole_process",
"::",
"wait",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_noRestartProcesses",
"[",
"$",
"result",
"[",
"'pid'",
"]",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_noRestartProcesses",
"[",
"$",
"result",
"[",
"'pid'",
"]",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"result",
"[",
"'signal'",
"]",
">",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"restartPolicy",
"&",
"self",
"::",
"RESTART_ON_SIGNAL",
")",
"{",
"$",
"this",
"->",
"forkOneWorker",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"result",
"[",
"'code'",
"]",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"restartPolicy",
"&",
"self",
"::",
"RESTART_ON_ERROR",
"&&",
"!",
"$",
"this",
"->",
"_disableRestartOnError",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tooManyErrors",
"(",
")",
")",
"{",
"//if exceed the maximum error frequency, stop forking new workers on error",
"$",
"this",
"->",
"_disableRestartOnError",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"forkOneWorker",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"restartPolicy",
"&",
"self",
"::",
"RESTART_ON_EXIT",
")",
"{",
"$",
"this",
"->",
"forkOneWorker",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | handler worker exit signal | [
"handler",
"worker",
"exit",
"signal"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Worker.php#L213-L244 |
13,056 | wangsir0624/queue | src/Worker.php | Worker.forkOneWorker | protected function forkOneWorker()
{
$worker = $this;
$process = new swoole_process(function (swoole_process $process) use ($worker) {
swoole_set_process_name($worker->name . ':worker');
call_user_func($worker->_work, $process);
}, false, false);
$pid = $process->start();
if($pid === false) {
return false;
}
$this->_workers++;
$this->_workerProcesses[$pid] = $process;
return true;
} | php | protected function forkOneWorker()
{
$worker = $this;
$process = new swoole_process(function (swoole_process $process) use ($worker) {
swoole_set_process_name($worker->name . ':worker');
call_user_func($worker->_work, $process);
}, false, false);
$pid = $process->start();
if($pid === false) {
return false;
}
$this->_workers++;
$this->_workerProcesses[$pid] = $process;
return true;
} | [
"protected",
"function",
"forkOneWorker",
"(",
")",
"{",
"$",
"worker",
"=",
"$",
"this",
";",
"$",
"process",
"=",
"new",
"swoole_process",
"(",
"function",
"(",
"swoole_process",
"$",
"process",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"swoole_set_process_name",
"(",
"$",
"worker",
"->",
"name",
".",
"':worker'",
")",
";",
"call_user_func",
"(",
"$",
"worker",
"->",
"_work",
",",
"$",
"process",
")",
";",
"}",
",",
"false",
",",
"false",
")",
";",
"$",
"pid",
"=",
"$",
"process",
"->",
"start",
"(",
")",
";",
"if",
"(",
"$",
"pid",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"_workers",
"++",
";",
"$",
"this",
"->",
"_workerProcesses",
"[",
"$",
"pid",
"]",
"=",
"$",
"process",
";",
"return",
"true",
";",
"}"
] | create a worker process
@return bool | [
"create",
"a",
"worker",
"process"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Worker.php#L260-L277 |
13,057 | wangsir0624/queue | src/Worker.php | Worker.tooManyErrors | protected function tooManyErrors()
{
$count = count($this->_errors);
if($count < $this->maxErrorTimes) {
return false;
}
return ($this->_errors[$count - 1] - $this->_errors[$count - $this->maxErrorTimes]) <= $this->errorInterval;
} | php | protected function tooManyErrors()
{
$count = count($this->_errors);
if($count < $this->maxErrorTimes) {
return false;
}
return ($this->_errors[$count - 1] - $this->_errors[$count - $this->maxErrorTimes]) <= $this->errorInterval;
} | [
"protected",
"function",
"tooManyErrors",
"(",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"_errors",
")",
";",
"if",
"(",
"$",
"count",
"<",
"$",
"this",
"->",
"maxErrorTimes",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"_errors",
"[",
"$",
"count",
"-",
"1",
"]",
"-",
"$",
"this",
"->",
"_errors",
"[",
"$",
"count",
"-",
"$",
"this",
"->",
"maxErrorTimes",
"]",
")",
"<=",
"$",
"this",
"->",
"errorInterval",
";",
"}"
] | whether exceed the maximum error frequency
@return bool | [
"whether",
"exceed",
"the",
"maximum",
"error",
"frequency"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Worker.php#L283-L291 |
13,058 | crysalead/net | src/Http/Psr7/RequestTrait.php | RequestTrait.withRequestTarget | public function withRequestTarget($requestTarget)
{
$request = clone $this;
if (preg_match('~^(?:[a-z]+:)?//~i', $requestTarget)) {
$result = parse_url($requestTarget);
if (isset($result['user'])) {
$result['username'] = $result['user'];
unset($result['user']);
}
if (isset($result['pass'])) {
$result['password'] = $result['pass'];
unset($result['pass']);
}
foreach ($result as $method => $value) {
$request->$method($value);
}
$request->mode('absolute');
return $request;
}
if (preg_match("~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~", $requestTarget, $matches)) {
$request->username($matches['username'] ?: null);
$request->password($matches['password'] ?: null);
$request->host($matches['host']);
$request->mode('authority');
return $request;
}
if ($requestTarget === '*') {
$request->mode('asterisk');
return $request;
}
$parts = explode('#', $requestTarget);
if (isset($parts[1])) {
$request->fragment($parts[1]);
}
$parts = explode('?', $parts[0]);
if (isset($parts[1])) {
$request->query($parts[1]);
}
$request->path($parts[0]);
return $request;
} | php | public function withRequestTarget($requestTarget)
{
$request = clone $this;
if (preg_match('~^(?:[a-z]+:)?//~i', $requestTarget)) {
$result = parse_url($requestTarget);
if (isset($result['user'])) {
$result['username'] = $result['user'];
unset($result['user']);
}
if (isset($result['pass'])) {
$result['password'] = $result['pass'];
unset($result['pass']);
}
foreach ($result as $method => $value) {
$request->$method($value);
}
$request->mode('absolute');
return $request;
}
if (preg_match("~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~", $requestTarget, $matches)) {
$request->username($matches['username'] ?: null);
$request->password($matches['password'] ?: null);
$request->host($matches['host']);
$request->mode('authority');
return $request;
}
if ($requestTarget === '*') {
$request->mode('asterisk');
return $request;
}
$parts = explode('#', $requestTarget);
if (isset($parts[1])) {
$request->fragment($parts[1]);
}
$parts = explode('?', $parts[0]);
if (isset($parts[1])) {
$request->query($parts[1]);
}
$request->path($parts[0]);
return $request;
} | [
"public",
"function",
"withRequestTarget",
"(",
"$",
"requestTarget",
")",
"{",
"$",
"request",
"=",
"clone",
"$",
"this",
";",
"if",
"(",
"preg_match",
"(",
"'~^(?:[a-z]+:)?//~i'",
",",
"$",
"requestTarget",
")",
")",
"{",
"$",
"result",
"=",
"parse_url",
"(",
"$",
"requestTarget",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'username'",
"]",
"=",
"$",
"result",
"[",
"'user'",
"]",
";",
"unset",
"(",
"$",
"result",
"[",
"'user'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'pass'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'password'",
"]",
"=",
"$",
"result",
"[",
"'pass'",
"]",
";",
"unset",
"(",
"$",
"result",
"[",
"'pass'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"result",
"as",
"$",
"method",
"=>",
"$",
"value",
")",
"{",
"$",
"request",
"->",
"$",
"method",
"(",
"$",
"value",
")",
";",
"}",
"$",
"request",
"->",
"mode",
"(",
"'absolute'",
")",
";",
"return",
"$",
"request",
";",
"}",
"if",
"(",
"preg_match",
"(",
"\"~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~\"",
",",
"$",
"requestTarget",
",",
"$",
"matches",
")",
")",
"{",
"$",
"request",
"->",
"username",
"(",
"$",
"matches",
"[",
"'username'",
"]",
"?",
":",
"null",
")",
";",
"$",
"request",
"->",
"password",
"(",
"$",
"matches",
"[",
"'password'",
"]",
"?",
":",
"null",
")",
";",
"$",
"request",
"->",
"host",
"(",
"$",
"matches",
"[",
"'host'",
"]",
")",
";",
"$",
"request",
"->",
"mode",
"(",
"'authority'",
")",
";",
"return",
"$",
"request",
";",
"}",
"if",
"(",
"$",
"requestTarget",
"===",
"'*'",
")",
"{",
"$",
"request",
"->",
"mode",
"(",
"'asterisk'",
")",
";",
"return",
"$",
"request",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'#'",
",",
"$",
"requestTarget",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
"{",
"$",
"request",
"->",
"fragment",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'?'",
",",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
"{",
"$",
"request",
"->",
"query",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}",
"$",
"request",
"->",
"path",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"return",
"$",
"request",
";",
"}"
] | Returns a new instance with the specific request-target.
If the request needs a non-origin-form request-target — e.g., for
specifying an absolute-form, authority-form, or asterisk-form —
this method may be used to create an instance with the specified
request-target, verbatim.
@link http://tools.ietf.org/html/rfc7230#section-2.7
@param mixed $requestTarget
@return self | [
"Returns",
"a",
"new",
"instance",
"with",
"the",
"specific",
"request",
"-",
"target",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Psr7/RequestTrait.php#L75-L115 |
13,059 | phlib/beanstalk | src/Command/StatsTrait.php | StatsTrait.decode | protected function decode($response)
{
$lines = array_slice(explode("\n", trim($response)), 1);
$result = [];
foreach ($lines as $line) {
if ($line[0] == '-') {
$result[] = trim(ltrim($line, '- '));
} else {
$key = strtok($line, ': ');
if ($key) {
$value = ltrim(trim(strtok('')), ' ');
if (is_numeric($value)) {
$value = $value + 0;
}
$result[$key] = $value;
}
}
}
return $result;
} | php | protected function decode($response)
{
$lines = array_slice(explode("\n", trim($response)), 1);
$result = [];
foreach ($lines as $line) {
if ($line[0] == '-') {
$result[] = trim(ltrim($line, '- '));
} else {
$key = strtok($line, ': ');
if ($key) {
$value = ltrim(trim(strtok('')), ' ');
if (is_numeric($value)) {
$value = $value + 0;
}
$result[$key] = $value;
}
}
}
return $result;
} | [
"protected",
"function",
"decode",
"(",
"$",
"response",
")",
"{",
"$",
"lines",
"=",
"array_slice",
"(",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"response",
")",
")",
",",
"1",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"line",
"[",
"0",
"]",
"==",
"'-'",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"trim",
"(",
"ltrim",
"(",
"$",
"line",
",",
"'- '",
")",
")",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"strtok",
"(",
"$",
"line",
",",
"': '",
")",
";",
"if",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"ltrim",
"(",
"trim",
"(",
"strtok",
"(",
"''",
")",
")",
",",
"' '",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"+",
"0",
";",
"}",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Decodes the YAML string into an array of data.
@param string $response
@return array | [
"Decodes",
"the",
"YAML",
"string",
"into",
"an",
"array",
"of",
"data",
"."
] | cc37083f506b65a5f005ca7a8920072d292a1d83 | https://github.com/phlib/beanstalk/blob/cc37083f506b65a5f005ca7a8920072d292a1d83/src/Command/StatsTrait.php#L45-L68 |
13,060 | ptlis/conneg | src/Negotiator/Matcher/PartialLanguageMatcher.php | PartialLanguageMatcher.partialLangMatches | private function partialLangMatches(
$fromField,
MatchedPreferenceInterface $matchedPreference,
PreferenceInterface $newClientPref
) {
$serverPref = $matchedPreference->getServerPreference();
$oldClientPref = $matchedPreference->getClientPreference();
// Note that this only supports the simplest case of (e.g.) en-* matching en-GB and en-US, additional
// Language tags are explicitly ignored
list($clientMainLang) = explode('-', $newClientPref->getVariant());
list($serverMainLang) = explode('-', $serverPref->getVariant());
return PreferenceInterface::LANGUAGE === $fromField
&& PreferenceInterface::PARTIAL_WILDCARD === $serverPref->getPrecedence()
&& $clientMainLang == $serverMainLang
&& $newClientPref->getPrecedence() > $oldClientPref->getPrecedence();
} | php | private function partialLangMatches(
$fromField,
MatchedPreferenceInterface $matchedPreference,
PreferenceInterface $newClientPref
) {
$serverPref = $matchedPreference->getServerPreference();
$oldClientPref = $matchedPreference->getClientPreference();
// Note that this only supports the simplest case of (e.g.) en-* matching en-GB and en-US, additional
// Language tags are explicitly ignored
list($clientMainLang) = explode('-', $newClientPref->getVariant());
list($serverMainLang) = explode('-', $serverPref->getVariant());
return PreferenceInterface::LANGUAGE === $fromField
&& PreferenceInterface::PARTIAL_WILDCARD === $serverPref->getPrecedence()
&& $clientMainLang == $serverMainLang
&& $newClientPref->getPrecedence() > $oldClientPref->getPrecedence();
} | [
"private",
"function",
"partialLangMatches",
"(",
"$",
"fromField",
",",
"MatchedPreferenceInterface",
"$",
"matchedPreference",
",",
"PreferenceInterface",
"$",
"newClientPref",
")",
"{",
"$",
"serverPref",
"=",
"$",
"matchedPreference",
"->",
"getServerPreference",
"(",
")",
";",
"$",
"oldClientPref",
"=",
"$",
"matchedPreference",
"->",
"getClientPreference",
"(",
")",
";",
"// Note that this only supports the simplest case of (e.g.) en-* matching en-GB and en-US, additional",
"// Language tags are explicitly ignored",
"list",
"(",
"$",
"clientMainLang",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"newClientPref",
"->",
"getVariant",
"(",
")",
")",
";",
"list",
"(",
"$",
"serverMainLang",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"serverPref",
"->",
"getVariant",
"(",
")",
")",
";",
"return",
"PreferenceInterface",
"::",
"LANGUAGE",
"===",
"$",
"fromField",
"&&",
"PreferenceInterface",
"::",
"PARTIAL_WILDCARD",
"===",
"$",
"serverPref",
"->",
"getPrecedence",
"(",
")",
"&&",
"$",
"clientMainLang",
"==",
"$",
"serverMainLang",
"&&",
"$",
"newClientPref",
"->",
"getPrecedence",
"(",
")",
">",
"$",
"oldClientPref",
"->",
"getPrecedence",
"(",
")",
";",
"}"
] | Returns true if the server preference contains a partial language that matches the language in the client
preference.
e.g. An server variant of en-* would match en, en-US but not es-ES
@param string $fromField
@param MatchedPreferenceInterface $matchedPreference
@param PreferenceInterface $newClientPref
@return bool | [
"Returns",
"true",
"if",
"the",
"server",
"preference",
"contains",
"a",
"partial",
"language",
"that",
"matches",
"the",
"language",
"in",
"the",
"client",
"preference",
"."
] | 04afb568f368ecdd81c13277006c4be041ccb58b | https://github.com/ptlis/conneg/blob/04afb568f368ecdd81c13277006c4be041ccb58b/src/Negotiator/Matcher/PartialLanguageMatcher.php#L80-L97 |
13,061 | mimmi20/Wurfl | src/Handlers/Chain/UserAgentHandlerChainFactory.php | UserAgentHandlerChainFactory.createFrom | public static function createFrom(
Storage $persistenceProvider,
Storage $cacheProvider,
LoggerInterface $logger = null
) {
/** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */
$userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain');
if (!($userAgentHandlerChain instanceof UserAgentHandlerChain)) {
$userAgentHandlerChain = self::init();
$cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600);
}
$userAgentHandlerChain->setLogger($logger);
foreach ($userAgentHandlerChain->getHandlers() as $handler) {
/* @var $handler \Wurfl\Handlers\AbstractHandler */
$handler
->setLogger($logger)
->setPersistenceProvider($persistenceProvider);
}
return $userAgentHandlerChain;
} | php | public static function createFrom(
Storage $persistenceProvider,
Storage $cacheProvider,
LoggerInterface $logger = null
) {
/** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */
$userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain');
if (!($userAgentHandlerChain instanceof UserAgentHandlerChain)) {
$userAgentHandlerChain = self::init();
$cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600);
}
$userAgentHandlerChain->setLogger($logger);
foreach ($userAgentHandlerChain->getHandlers() as $handler) {
/* @var $handler \Wurfl\Handlers\AbstractHandler */
$handler
->setLogger($logger)
->setPersistenceProvider($persistenceProvider);
}
return $userAgentHandlerChain;
} | [
"public",
"static",
"function",
"createFrom",
"(",
"Storage",
"$",
"persistenceProvider",
",",
"Storage",
"$",
"cacheProvider",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
"{",
"/** @var $userAgentHandlerChain \\Wurfl\\Handlers\\Chain\\UserAgentHandlerChain */",
"$",
"userAgentHandlerChain",
"=",
"$",
"cacheProvider",
"->",
"load",
"(",
"'UserAgentHandlerChain'",
")",
";",
"if",
"(",
"!",
"(",
"$",
"userAgentHandlerChain",
"instanceof",
"UserAgentHandlerChain",
")",
")",
"{",
"$",
"userAgentHandlerChain",
"=",
"self",
"::",
"init",
"(",
")",
";",
"$",
"cacheProvider",
"->",
"save",
"(",
"'UserAgentHandlerChain'",
",",
"$",
"userAgentHandlerChain",
",",
"3600",
")",
";",
"}",
"$",
"userAgentHandlerChain",
"->",
"setLogger",
"(",
"$",
"logger",
")",
";",
"foreach",
"(",
"$",
"userAgentHandlerChain",
"->",
"getHandlers",
"(",
")",
"as",
"$",
"handler",
")",
"{",
"/* @var $handler \\Wurfl\\Handlers\\AbstractHandler */",
"$",
"handler",
"->",
"setLogger",
"(",
"$",
"logger",
")",
"->",
"setPersistenceProvider",
"(",
"$",
"persistenceProvider",
")",
";",
"}",
"return",
"$",
"userAgentHandlerChain",
";",
"}"
] | Create a \Wurfl\Handlers\Chain\UserAgentHandlerChain
@param \Wurfl\Storage\Storage $persistenceProvider
@param \Wurfl\Storage\Storage $cacheProvider
@param \Psr\Log\LoggerInterface $logger
@return UserAgentHandlerChain | [
"Create",
"a",
"\\",
"Wurfl",
"\\",
"Handlers",
"\\",
"Chain",
"\\",
"UserAgentHandlerChain"
] | 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Handlers/Chain/UserAgentHandlerChainFactory.php#L130-L153 |
13,062 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.getProperty | public function getProperty($name)
{
if (!$this->hasProperty($name)) {
return;
}
if (strstr($name, '.')) {
$value = false;
@eval('$value = '.$this->resolveArrayPath($name).';');
return $value;
}
if ($this->isArray()) {
return $this->object[$name];
} else {
return $this->object->$name;
}
} | php | public function getProperty($name)
{
if (!$this->hasProperty($name)) {
return;
}
if (strstr($name, '.')) {
$value = false;
@eval('$value = '.$this->resolveArrayPath($name).';');
return $value;
}
if ($this->isArray()) {
return $this->object[$name];
} else {
return $this->object->$name;
}
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"strstr",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"$",
"value",
"=",
"false",
";",
"@",
"eval",
"(",
"'$value = '",
".",
"$",
"this",
"->",
"resolveArrayPath",
"(",
"$",
"name",
")",
".",
"';'",
")",
";",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isArray",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"object",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"object",
"->",
"$",
"name",
";",
"}",
"}"
] | Get Property.
@param string $name
@return mixed | [
"Get",
"Property",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L60-L78 |
13,063 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.setProperty | public function setProperty($name, $value)
{
if (strstr($name, '.')) {
$this->setPropertyByPath($name, $value);
return true;
}
if ($this->isArray()) {
$this->object[$name] = $value;
} else {
$this->object->$name = $value;
}
return true;
} | php | public function setProperty($name, $value)
{
if (strstr($name, '.')) {
$this->setPropertyByPath($name, $value);
return true;
}
if ($this->isArray()) {
$this->object[$name] = $value;
} else {
$this->object->$name = $value;
}
return true;
} | [
"public",
"function",
"setProperty",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"strstr",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"$",
"this",
"->",
"setPropertyByPath",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isArray",
"(",
")",
")",
"{",
"$",
"this",
"->",
"object",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"object",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"return",
"true",
";",
"}"
] | Set Property.
@param string $name
@param mixed $value
@return bool | [
"Set",
"Property",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L88-L103 |
13,064 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.setPropertyByPath | protected function setPropertyByPath($path, $value)
{
$path = explode('.', $path);
$root = $path[0];
unset($path[0]);
$array = ($this->hasProperty($root) ? $this->getProperty($root) : []);
$pointer = &$array;
// Loop through the array path and set array parts
foreach ($path as $part) {
if (!isset($pointer[$part])) {
$pointer[$part] = [];
}
if (!is_array($pointer[$part])) {
$pointer[$part] = [];
}
$pointer = &$pointer[$part];
}
$pointer = $value;
unset($pointer);
$this->setProperty($root, $array);
} | php | protected function setPropertyByPath($path, $value)
{
$path = explode('.', $path);
$root = $path[0];
unset($path[0]);
$array = ($this->hasProperty($root) ? $this->getProperty($root) : []);
$pointer = &$array;
// Loop through the array path and set array parts
foreach ($path as $part) {
if (!isset($pointer[$part])) {
$pointer[$part] = [];
}
if (!is_array($pointer[$part])) {
$pointer[$part] = [];
}
$pointer = &$pointer[$part];
}
$pointer = $value;
unset($pointer);
$this->setProperty($root, $array);
} | [
"protected",
"function",
"setPropertyByPath",
"(",
"$",
"path",
",",
"$",
"value",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"$",
"root",
"=",
"$",
"path",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"path",
"[",
"0",
"]",
")",
";",
"$",
"array",
"=",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"root",
")",
"?",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"root",
")",
":",
"[",
"]",
")",
";",
"$",
"pointer",
"=",
"&",
"$",
"array",
";",
"// Loop through the array path and set array parts",
"foreach",
"(",
"$",
"path",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"pointer",
"[",
"$",
"part",
"]",
")",
")",
"{",
"$",
"pointer",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pointer",
"[",
"$",
"part",
"]",
")",
")",
"{",
"$",
"pointer",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"pointer",
"=",
"&",
"$",
"pointer",
"[",
"$",
"part",
"]",
";",
"}",
"$",
"pointer",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"pointer",
")",
";",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"root",
",",
"$",
"array",
")",
";",
"}"
] | Set a property by looping through.
@param string $path | [
"Set",
"a",
"property",
"by",
"looping",
"through",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L110-L136 |
13,065 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.unsetProperty | public function unsetProperty($name)
{
if (!$this->hasProperty($name)) {
return false;
}
if (strstr($name, '.')) {
try {
$path = explode('.', $name);
$root = $path[0];
unset($path[0]);
$array = ($this->hasProperty($root) ? $this->getProperty($root) : []);
$arrayPath = '["'.implode('"]["', $path).'"]';
eval('unset($array'.$arrayPath.');');
$this->setProperty($root, $array);
} catch (Exception $e) {
return false;
}
return true;
}
if ($this->isArray()) {
unset($this->object[$name]);
} else {
unset($this->object->$name);
}
return true;
} | php | public function unsetProperty($name)
{
if (!$this->hasProperty($name)) {
return false;
}
if (strstr($name, '.')) {
try {
$path = explode('.', $name);
$root = $path[0];
unset($path[0]);
$array = ($this->hasProperty($root) ? $this->getProperty($root) : []);
$arrayPath = '["'.implode('"]["', $path).'"]';
eval('unset($array'.$arrayPath.');');
$this->setProperty($root, $array);
} catch (Exception $e) {
return false;
}
return true;
}
if ($this->isArray()) {
unset($this->object[$name]);
} else {
unset($this->object->$name);
}
return true;
} | [
"public",
"function",
"unsetProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strstr",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"try",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"root",
"=",
"$",
"path",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"path",
"[",
"0",
"]",
")",
";",
"$",
"array",
"=",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"root",
")",
"?",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"root",
")",
":",
"[",
"]",
")",
";",
"$",
"arrayPath",
"=",
"'[\"'",
".",
"implode",
"(",
"'\"][\"'",
",",
"$",
"path",
")",
".",
"'\"]'",
";",
"eval",
"(",
"'unset($array'",
".",
"$",
"arrayPath",
".",
"');'",
")",
";",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"root",
",",
"$",
"array",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isArray",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"object",
"[",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"object",
"->",
"$",
"name",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Unset Property.
@param string $name
@return bool | [
"Unset",
"Property",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L145-L177 |
13,066 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.resolveArrayPath | public function resolveArrayPath($path)
{
$path = explode('.', $this->escape($path));
$root = $path[0];
unset($path[0]);
$arrayPath = '["'.implode('"]["', $path).'"]';
$arrayBracket = '->';
$arrayBracketEnd = '';
if ($this->isArray()) {
$arrayBracket = '["';
$arrayBracketEnd = '"]';
}
return '$this->object'.$arrayBracket.$root.$arrayBracketEnd.$arrayPath;
} | php | public function resolveArrayPath($path)
{
$path = explode('.', $this->escape($path));
$root = $path[0];
unset($path[0]);
$arrayPath = '["'.implode('"]["', $path).'"]';
$arrayBracket = '->';
$arrayBracketEnd = '';
if ($this->isArray()) {
$arrayBracket = '["';
$arrayBracketEnd = '"]';
}
return '$this->object'.$arrayBracket.$root.$arrayBracketEnd.$arrayPath;
} | [
"public",
"function",
"resolveArrayPath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"escape",
"(",
"$",
"path",
")",
")",
";",
"$",
"root",
"=",
"$",
"path",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"path",
"[",
"0",
"]",
")",
";",
"$",
"arrayPath",
"=",
"'[\"'",
".",
"implode",
"(",
"'\"][\"'",
",",
"$",
"path",
")",
".",
"'\"]'",
";",
"$",
"arrayBracket",
"=",
"'->'",
";",
"$",
"arrayBracketEnd",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isArray",
"(",
")",
")",
"{",
"$",
"arrayBracket",
"=",
"'[\"'",
";",
"$",
"arrayBracketEnd",
"=",
"'\"]'",
";",
"}",
"return",
"'$this->object'",
".",
"$",
"arrayBracket",
".",
"$",
"root",
".",
"$",
"arrayBracketEnd",
".",
"$",
"arrayPath",
";",
"}"
] | Resolve punctuation format and return path.
@param string $path
@return string | [
"Resolve",
"punctuation",
"format",
"and",
"return",
"path",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L186-L203 |
13,067 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.loopThrough | public function loopThrough(Closure $callable)
{
$reference = $this->getReference();
if (is_null($reference)) {
$reference = $this->object;
}
$this->loop($reference, $callable);
} | php | public function loopThrough(Closure $callable)
{
$reference = $this->getReference();
if (is_null($reference)) {
$reference = $this->object;
}
$this->loop($reference, $callable);
} | [
"public",
"function",
"loopThrough",
"(",
"Closure",
"$",
"callable",
")",
"{",
"$",
"reference",
"=",
"$",
"this",
"->",
"getReference",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"reference",
")",
")",
"{",
"$",
"reference",
"=",
"$",
"this",
"->",
"object",
";",
"}",
"$",
"this",
"->",
"loop",
"(",
"$",
"reference",
",",
"$",
"callable",
")",
";",
"}"
] | Loop through the stored data.
@param Closure $callable | [
"Loop",
"through",
"the",
"stored",
"data",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L218-L227 |
13,068 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.loop | protected function loop($data, Closure $callable)
{
if (!is_array($data) && !is_object($data)) {
return;
}
foreach ($data as $key => $value) {
call_user_func_array($callable, [$key, $value]);
}
} | php | protected function loop($data, Closure $callable)
{
if (!is_array($data) && !is_object($data)) {
return;
}
foreach ($data as $key => $value) {
call_user_func_array($callable, [$key, $value]);
}
} | [
"protected",
"function",
"loop",
"(",
"$",
"data",
",",
"Closure",
"$",
"callable",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"&&",
"!",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"call_user_func_array",
"(",
"$",
"callable",
",",
"[",
"$",
"key",
",",
"$",
"value",
"]",
")",
";",
"}",
"}"
] | Loop through the given data and call the given function.
@param array|object $data
@param Closure $callable | [
"Loop",
"through",
"the",
"given",
"data",
"and",
"call",
"the",
"given",
"function",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L275-L284 |
13,069 | kriskbx/mikado | src/Data/FormatAbleObject.php | FormatAbleObject.unsetNullRecursively | protected function unsetNullRecursively($data, $reference = null)
{
if (is_null($reference)) {
$reference = $data;
}
$this->loop($reference, function ($key, $value) use (&$data) {
if (is_array($data)) {
if (is_null($value)) {
unset($data[$key]);
} else {
$data[$key] = $this->unsetNullRecursively($value);
}
}
if (is_object($data)) {
if (is_null($value)) {
unset($data->$key);
} else {
$data->$key = $this->unsetNullRecursively($value);
}
}
});
return $data;
} | php | protected function unsetNullRecursively($data, $reference = null)
{
if (is_null($reference)) {
$reference = $data;
}
$this->loop($reference, function ($key, $value) use (&$data) {
if (is_array($data)) {
if (is_null($value)) {
unset($data[$key]);
} else {
$data[$key] = $this->unsetNullRecursively($value);
}
}
if (is_object($data)) {
if (is_null($value)) {
unset($data->$key);
} else {
$data->$key = $this->unsetNullRecursively($value);
}
}
});
return $data;
} | [
"protected",
"function",
"unsetNullRecursively",
"(",
"$",
"data",
",",
"$",
"reference",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"reference",
")",
")",
"{",
"$",
"reference",
"=",
"$",
"data",
";",
"}",
"$",
"this",
"->",
"loop",
"(",
"$",
"reference",
",",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"use",
"(",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"unsetNullRecursively",
"(",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"->",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"$",
"key",
"=",
"$",
"this",
"->",
"unsetNullRecursively",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Unset null properties and keys of the given data.
@param array|object $data
@return array|object | [
"Unset",
"null",
"properties",
"and",
"keys",
"of",
"the",
"given",
"data",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Data/FormatAbleObject.php#L293-L318 |
13,070 | DevGroup-ru/yii2-data-structure-tools | src/Properties/Module.php | Module.prepareWizardData | public function prepareWizardData()
{
$cacheKey = 'property-wizard' . md5(implode(':', $this->handlersList));
$data = Yii::$app->cache->get($cacheKey);
if (false === $data) {
$query = (new Query())->from(PropertyHandlers::tableName())->indexBy('id')->select('class_name');
if ((count($this->handlersList) != 0)) {
$query->where(['class_name' => $this->handlersList]);
}
$handlers = $query->column();
$storageToId = (new Query())->from(PropertyStorage::tableName())->indexBy('id')->select('class_name')->column();
/**
* @var AbstractPropertyHandler $className
*/
foreach ($handlers as $id => $className) {
$data[$id] = [
'id' => $id,
'allowedTypes' => $className::$allowedTypes,
'allowedStorage' => array_keys(array_intersect($storageToId, $className::$allowedStorage)),
'allowInSearch' => (bool)$className::$allowInSearch,
'multipleMode' => $className::$multipleMode
];
}
Yii::$app->cache->set(
$cacheKey,
$data,
86400,
new TagDependency(['tags' => [
NamingHelper::getCommonTag(PropertyHandlers::class),
NamingHelper::getCommonTag(PropertyStorage::class)
]])
);
}
return $data;
} | php | public function prepareWizardData()
{
$cacheKey = 'property-wizard' . md5(implode(':', $this->handlersList));
$data = Yii::$app->cache->get($cacheKey);
if (false === $data) {
$query = (new Query())->from(PropertyHandlers::tableName())->indexBy('id')->select('class_name');
if ((count($this->handlersList) != 0)) {
$query->where(['class_name' => $this->handlersList]);
}
$handlers = $query->column();
$storageToId = (new Query())->from(PropertyStorage::tableName())->indexBy('id')->select('class_name')->column();
/**
* @var AbstractPropertyHandler $className
*/
foreach ($handlers as $id => $className) {
$data[$id] = [
'id' => $id,
'allowedTypes' => $className::$allowedTypes,
'allowedStorage' => array_keys(array_intersect($storageToId, $className::$allowedStorage)),
'allowInSearch' => (bool)$className::$allowInSearch,
'multipleMode' => $className::$multipleMode
];
}
Yii::$app->cache->set(
$cacheKey,
$data,
86400,
new TagDependency(['tags' => [
NamingHelper::getCommonTag(PropertyHandlers::class),
NamingHelper::getCommonTag(PropertyStorage::class)
]])
);
}
return $data;
} | [
"public",
"function",
"prepareWizardData",
"(",
")",
"{",
"$",
"cacheKey",
"=",
"'property-wizard'",
".",
"md5",
"(",
"implode",
"(",
"':'",
",",
"$",
"this",
"->",
"handlersList",
")",
")",
";",
"$",
"data",
"=",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"get",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"PropertyHandlers",
"::",
"tableName",
"(",
")",
")",
"->",
"indexBy",
"(",
"'id'",
")",
"->",
"select",
"(",
"'class_name'",
")",
";",
"if",
"(",
"(",
"count",
"(",
"$",
"this",
"->",
"handlersList",
")",
"!=",
"0",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"[",
"'class_name'",
"=>",
"$",
"this",
"->",
"handlersList",
"]",
")",
";",
"}",
"$",
"handlers",
"=",
"$",
"query",
"->",
"column",
"(",
")",
";",
"$",
"storageToId",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"PropertyStorage",
"::",
"tableName",
"(",
")",
")",
"->",
"indexBy",
"(",
"'id'",
")",
"->",
"select",
"(",
"'class_name'",
")",
"->",
"column",
"(",
")",
";",
"/**\n * @var AbstractPropertyHandler $className\n */",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"id",
"=>",
"$",
"className",
")",
"{",
"$",
"data",
"[",
"$",
"id",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'allowedTypes'",
"=>",
"$",
"className",
"::",
"$",
"allowedTypes",
",",
"'allowedStorage'",
"=>",
"array_keys",
"(",
"array_intersect",
"(",
"$",
"storageToId",
",",
"$",
"className",
"::",
"$",
"allowedStorage",
")",
")",
",",
"'allowInSearch'",
"=>",
"(",
"bool",
")",
"$",
"className",
"::",
"$",
"allowInSearch",
",",
"'multipleMode'",
"=>",
"$",
"className",
"::",
"$",
"multipleMode",
"]",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"set",
"(",
"$",
"cacheKey",
",",
"$",
"data",
",",
"86400",
",",
"new",
"TagDependency",
"(",
"[",
"'tags'",
"=>",
"[",
"NamingHelper",
"::",
"getCommonTag",
"(",
"PropertyHandlers",
"::",
"class",
")",
",",
"NamingHelper",
"::",
"getCommonTag",
"(",
"PropertyStorage",
"::",
"class",
")",
"]",
"]",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Prepares json string to use in js property creation wizard
@return array | [
"Prepares",
"json",
"string",
"to",
"use",
"in",
"js",
"property",
"creation",
"wizard"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/Properties/Module.php#L72-L106 |
13,071 | ahuggins/utilities | src/Console/Commands/SetDatabaseCredentials.php | SetDatabaseCredentials.handle | public function handle()
{
if (! $this->confirm('Set up DB creds now? [y|N]')) {
return;
}
$connected = false;
while (! $connected) {
$host = $this->askDatabaseHost();
$name = $this->askDatabaseName();
$user = $this->askDatabaseUsername();
$password = $this->askDatabasePassword();
$this->setLaravelConfiguration($name, $user, $password, $host);
if ($this->databaseConnectionIsValid()) {
$connected = true;
} else {
$this->error("Please ensure your database credentials are valid.");
}
}
$this->env->write($name, $user, $password, $host);
$this->info('Database successfully configured');
} | php | public function handle()
{
if (! $this->confirm('Set up DB creds now? [y|N]')) {
return;
}
$connected = false;
while (! $connected) {
$host = $this->askDatabaseHost();
$name = $this->askDatabaseName();
$user = $this->askDatabaseUsername();
$password = $this->askDatabasePassword();
$this->setLaravelConfiguration($name, $user, $password, $host);
if ($this->databaseConnectionIsValid()) {
$connected = true;
} else {
$this->error("Please ensure your database credentials are valid.");
}
}
$this->env->write($name, $user, $password, $host);
$this->info('Database successfully configured');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"confirm",
"(",
"'Set up DB creds now? [y|N]'",
")",
")",
"{",
"return",
";",
"}",
"$",
"connected",
"=",
"false",
";",
"while",
"(",
"!",
"$",
"connected",
")",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"askDatabaseHost",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"askDatabaseName",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"askDatabaseUsername",
"(",
")",
";",
"$",
"password",
"=",
"$",
"this",
"->",
"askDatabasePassword",
"(",
")",
";",
"$",
"this",
"->",
"setLaravelConfiguration",
"(",
"$",
"name",
",",
"$",
"user",
",",
"$",
"password",
",",
"$",
"host",
")",
";",
"if",
"(",
"$",
"this",
"->",
"databaseConnectionIsValid",
"(",
")",
")",
"{",
"$",
"connected",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Please ensure your database credentials are valid.\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"env",
"->",
"write",
"(",
"$",
"name",
",",
"$",
"user",
",",
"$",
"password",
",",
"$",
"host",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Database successfully configured'",
")",
";",
"}"
] | Handle the Command
@return mixed | [
"Handle",
"the",
"Command"
] | efb79f2dd12335e8115722568239ee22c899e0f1 | https://github.com/ahuggins/utilities/blob/efb79f2dd12335e8115722568239ee22c899e0f1/src/Console/Commands/SetDatabaseCredentials.php#L56-L85 |
13,072 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/Query.php | Query.stats | public function stats()
{
return new Query\Stats($this->mongo, $this->entity, $this->ref, $this->dateRange);
} | php | public function stats()
{
return new Query\Stats($this->mongo, $this->entity, $this->ref, $this->dateRange);
} | [
"public",
"function",
"stats",
"(",
")",
"{",
"return",
"new",
"Query",
"\\",
"Stats",
"(",
"$",
"this",
"->",
"mongo",
",",
"$",
"this",
"->",
"entity",
",",
"$",
"this",
"->",
"ref",
",",
"$",
"this",
"->",
"dateRange",
")",
";",
"}"
] | Query daily or monthly statistics.
@return Query\Stats | [
"Query",
"daily",
"or",
"monthly",
"statistics",
"."
] | e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/Query.php#L62-L65 |
13,073 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/Query.php | Query.dimension | public function dimension($name = null, $value = null)
{
$query = new Query\Dimensions($this->mongo, $this->entity, $this->ref, $this->dateRange);
if (!empty($name)) {
if (!empty($value)) {
$query->setDimension($name, $value);
} else {
$query->setDimension($name);
}
}
return $query;
} | php | public function dimension($name = null, $value = null)
{
$query = new Query\Dimensions($this->mongo, $this->entity, $this->ref, $this->dateRange);
if (!empty($name)) {
if (!empty($value)) {
$query->setDimension($name, $value);
} else {
$query->setDimension($name);
}
}
return $query;
} | [
"public",
"function",
"dimension",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"\\",
"Dimensions",
"(",
"$",
"this",
"->",
"mongo",
",",
"$",
"this",
"->",
"entity",
",",
"$",
"this",
"->",
"ref",
",",
"$",
"this",
"->",
"dateRange",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"query",
"->",
"setDimension",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"setDimension",
"(",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] | Query the dimensions.
@param string $name Dimension name
@param string $value Dimension value
@return Query\Dimensions | [
"Query",
"the",
"dimensions",
"."
] | e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/Query.php#L75-L87 |
13,074 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.discard | public function discard($discard = null)
{
if (func_num_args() === 0) {
return $this->_data['discard'];
}
return $this->_data['discard'] = (boolean) $discard;
} | php | public function discard($discard = null)
{
if (func_num_args() === 0) {
return $this->_data['discard'];
}
return $this->_data['discard'] = (boolean) $discard;
} | [
"public",
"function",
"discard",
"(",
"$",
"discard",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"_data",
"[",
"'discard'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"_data",
"[",
"'discard'",
"]",
"=",
"(",
"boolean",
")",
"$",
"discard",
";",
"}"
] | Set whether or not this is a session cookie.
@param boolean $discard The discard value.
@return boolean Returns discard value. | [
"Set",
"whether",
"or",
"not",
"this",
"is",
"a",
"session",
"cookie",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L202-L208 |
13,075 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.matches | public function matches($url)
{
$infos = parse_url($url);
if ($this->expired()) {
return false;
}
if (!$this->matchesScheme($infos['scheme'])) {
return false;
}
if (!$this->matchesDomain($infos['host'])) {
return false;
}
return $this->matchesPath($infos['path']);
} | php | public function matches($url)
{
$infos = parse_url($url);
if ($this->expired()) {
return false;
}
if (!$this->matchesScheme($infos['scheme'])) {
return false;
}
if (!$this->matchesDomain($infos['host'])) {
return false;
}
return $this->matchesPath($infos['path']);
} | [
"public",
"function",
"matches",
"(",
"$",
"url",
")",
"{",
"$",
"infos",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"expired",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"matchesScheme",
"(",
"$",
"infos",
"[",
"'scheme'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"matchesDomain",
"(",
"$",
"infos",
"[",
"'host'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"matchesPath",
"(",
"$",
"infos",
"[",
"'path'",
"]",
")",
";",
"}"
] | Checks if a scheme, domain and path match the Cookie ones.
@param string $url The URL path.
@return boolean Returns `true` if it matches, `false otherwise`. | [
"Checks",
"if",
"a",
"scheme",
"domain",
"and",
"path",
"match",
"the",
"Cookie",
"ones",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L226-L243 |
13,076 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.matchesPath | public function matchesPath($path)
{
if ($this->_data['path'] === '/' || $this->_data['path'] === $path) {
return true;
}
if (strpos($path, $this->_data['path']) !== 0) {
return false;
}
if (substr($this->_data['path'], -1, 1) === '/') {
return true;
}
return substr($path, strlen($this->_data['path']), 1) === '/';
} | php | public function matchesPath($path)
{
if ($this->_data['path'] === '/' || $this->_data['path'] === $path) {
return true;
}
if (strpos($path, $this->_data['path']) !== 0) {
return false;
}
if (substr($this->_data['path'], -1, 1) === '/') {
return true;
}
return substr($path, strlen($this->_data['path']), 1) === '/';
} | [
"public",
"function",
"matchesPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_data",
"[",
"'path'",
"]",
"===",
"'/'",
"||",
"$",
"this",
"->",
"_data",
"[",
"'path'",
"]",
"===",
"$",
"path",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"_data",
"[",
"'path'",
"]",
")",
"!==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"_data",
"[",
"'path'",
"]",
",",
"-",
"1",
",",
"1",
")",
"===",
"'/'",
")",
"{",
"return",
"true",
";",
"}",
"return",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"this",
"->",
"_data",
"[",
"'path'",
"]",
")",
",",
"1",
")",
"===",
"'/'",
";",
"}"
] | Checks if a path match the Cookie path.
@param string $scheme The scheme name.
@return boolean Returns `true` if schemes match, `false otherwise`. | [
"Checks",
"if",
"a",
"path",
"match",
"the",
"Cookie",
"path",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L251-L266 |
13,077 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.matchesScheme | public function matchesScheme($scheme)
{
$scheme = strtolower($scheme);
$secure = $this->_data['secure'];
return ($secure && $scheme === 'https') || (!$secure && $scheme === 'http');
} | php | public function matchesScheme($scheme)
{
$scheme = strtolower($scheme);
$secure = $this->_data['secure'];
return ($secure && $scheme === 'https') || (!$secure && $scheme === 'http');
} | [
"public",
"function",
"matchesScheme",
"(",
"$",
"scheme",
")",
"{",
"$",
"scheme",
"=",
"strtolower",
"(",
"$",
"scheme",
")",
";",
"$",
"secure",
"=",
"$",
"this",
"->",
"_data",
"[",
"'secure'",
"]",
";",
"return",
"(",
"$",
"secure",
"&&",
"$",
"scheme",
"===",
"'https'",
")",
"||",
"(",
"!",
"$",
"secure",
"&&",
"$",
"scheme",
"===",
"'http'",
")",
";",
"}"
] | Checks if a domain match the Cookie scheme.
@param string $scheme The scheme name.
@return boolean Returns `true` if schemes match, `false otherwise`. | [
"Checks",
"if",
"a",
"domain",
"match",
"the",
"Cookie",
"scheme",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L274-L279 |
13,078 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.expired | public function expired($onSessionExpires = false)
{
if (!$this->_data['expires'] && $onSessionExpires) {
return true;
}
return $this->_data['expires'] < time() && $this->_data['expires'];
} | php | public function expired($onSessionExpires = false)
{
if (!$this->_data['expires'] && $onSessionExpires) {
return true;
}
return $this->_data['expires'] < time() && $this->_data['expires'];
} | [
"public",
"function",
"expired",
"(",
"$",
"onSessionExpires",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_data",
"[",
"'expires'",
"]",
"&&",
"$",
"onSessionExpires",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"_data",
"[",
"'expires'",
"]",
"<",
"time",
"(",
")",
"&&",
"$",
"this",
"->",
"_data",
"[",
"'expires'",
"]",
";",
"}"
] | Checks if the Cookie expired.
@param boolean $onSessionExpires Sets to `true` to check if the Cookie will expires when the session expires.
@return boolean | [
"Checks",
"if",
"the",
"Cookie",
"expired",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L314-L321 |
13,079 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.toString | public function toString()
{
$parts = [];
$data = $this->data();
$parts[] = $data['name'] . '=' . rawurlencode($data['value']);
if ($data['domain']) {
$parts[] = 'Domain=' . $data['domain'];
}
if ($data['path']) {
$parts[] = 'Path=' . $data['path'];
}
if (isset($data['max-age'])) {
$parts[] = 'Max-Age=' . (string) $data['max-age'];
} elseif (isset($data['expires'])) {
$parts[] = 'Expires=' . gmdate('D, d M Y H:i:s \G\M\T', $data['expires']);
}
if ($data['secure']) {
$parts[] = 'Secure';
}
if ($data['httponly']) {
$parts[] = 'HttpOnly';
}
return join('; ', $parts);
} | php | public function toString()
{
$parts = [];
$data = $this->data();
$parts[] = $data['name'] . '=' . rawurlencode($data['value']);
if ($data['domain']) {
$parts[] = 'Domain=' . $data['domain'];
}
if ($data['path']) {
$parts[] = 'Path=' . $data['path'];
}
if (isset($data['max-age'])) {
$parts[] = 'Max-Age=' . (string) $data['max-age'];
} elseif (isset($data['expires'])) {
$parts[] = 'Expires=' . gmdate('D, d M Y H:i:s \G\M\T', $data['expires']);
}
if ($data['secure']) {
$parts[] = 'Secure';
}
if ($data['httponly']) {
$parts[] = 'HttpOnly';
}
return join('; ', $parts);
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"parts",
"=",
"[",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
"(",
")",
";",
"$",
"parts",
"[",
"]",
"=",
"$",
"data",
"[",
"'name'",
"]",
".",
"'='",
".",
"rawurlencode",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'domain'",
"]",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'Domain='",
".",
"$",
"data",
"[",
"'domain'",
"]",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'path'",
"]",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'Path='",
".",
"$",
"data",
"[",
"'path'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'max-age'",
"]",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'Max-Age='",
".",
"(",
"string",
")",
"$",
"data",
"[",
"'max-age'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"data",
"[",
"'expires'",
"]",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'Expires='",
".",
"gmdate",
"(",
"'D, d M Y H:i:s \\G\\M\\T'",
",",
"$",
"data",
"[",
"'expires'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'secure'",
"]",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'Secure'",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'httponly'",
"]",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'HttpOnly'",
";",
"}",
"return",
"join",
"(",
"'; '",
",",
"$",
"parts",
")",
";",
"}"
] | Return a Set-Cookie string representation of a Cookie.
@param string $cookie The Cookie.
@return string | [
"Return",
"a",
"Set",
"-",
"Cookie",
"string",
"representation",
"of",
"a",
"Cookie",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L360-L384 |
13,080 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.fromString | public static function fromString($value)
{
$parts = array_filter(array_map('trim', explode(';', $value)));
if (empty($parts) || !strpos($parts[0], '=')) {
return [];
}
$config = [];
$pieces = explode('=', array_shift($parts), 2);
if (count($pieces) !== 2) {
return [];
}
$config['name'] = trim($pieces[0]);
$config['value'] = urldecode(trim($pieces[1], " \n\r\t\0\x0B"));
foreach ($parts as $item) {
$pieces = explode('=', trim($item), 2);
$pieces[0] = strtolower($pieces[0]);
if (count($pieces) !== 2) {
$config[$pieces[0]] = true;
} else {
$config[$pieces[0]] = $pieces[1];
}
}
return new static($config);
} | php | public static function fromString($value)
{
$parts = array_filter(array_map('trim', explode(';', $value)));
if (empty($parts) || !strpos($parts[0], '=')) {
return [];
}
$config = [];
$pieces = explode('=', array_shift($parts), 2);
if (count($pieces) !== 2) {
return [];
}
$config['name'] = trim($pieces[0]);
$config['value'] = urldecode(trim($pieces[1], " \n\r\t\0\x0B"));
foreach ($parts as $item) {
$pieces = explode('=', trim($item), 2);
$pieces[0] = strtolower($pieces[0]);
if (count($pieces) !== 2) {
$config[$pieces[0]] = true;
} else {
$config[$pieces[0]] = $pieces[1];
}
}
return new static($config);
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"value",
")",
"{",
"$",
"parts",
"=",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"';'",
",",
"$",
"value",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parts",
")",
"||",
"!",
"strpos",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"'='",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"config",
"=",
"[",
"]",
";",
"$",
"pieces",
"=",
"explode",
"(",
"'='",
",",
"array_shift",
"(",
"$",
"parts",
")",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
"!==",
"2",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"config",
"[",
"'name'",
"]",
"=",
"trim",
"(",
"$",
"pieces",
"[",
"0",
"]",
")",
";",
"$",
"config",
"[",
"'value'",
"]",
"=",
"urldecode",
"(",
"trim",
"(",
"$",
"pieces",
"[",
"1",
"]",
",",
"\" \\n\\r\\t\\0\\x0B\"",
")",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"item",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"'='",
",",
"trim",
"(",
"$",
"item",
")",
",",
"2",
")",
";",
"$",
"pieces",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"pieces",
"[",
"0",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
"!==",
"2",
")",
"{",
"$",
"config",
"[",
"$",
"pieces",
"[",
"0",
"]",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"config",
"[",
"$",
"pieces",
"[",
"0",
"]",
"]",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"new",
"static",
"(",
"$",
"config",
")",
";",
"}"
] | Create a new Cookie object from a Set-Cookie header value
@param string $value Set-Cookie header value.
@return self | [
"Create",
"a",
"new",
"Cookie",
"object",
"from",
"a",
"Set",
"-",
"Cookie",
"header",
"value"
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L393-L420 |
13,081 | crysalead/net | src/Http/Cookie/Cookie.php | Cookie.isValidTimeStamp | public static function isValidTimeStamp($timestamp)
{
return ((string) (integer) $timestamp === (string) $timestamp) && $timestamp <= PHP_INT_MAX && $timestamp >= ~PHP_INT_MAX;
} | php | public static function isValidTimeStamp($timestamp)
{
return ((string) (integer) $timestamp === (string) $timestamp) && $timestamp <= PHP_INT_MAX && $timestamp >= ~PHP_INT_MAX;
} | [
"public",
"static",
"function",
"isValidTimeStamp",
"(",
"$",
"timestamp",
")",
"{",
"return",
"(",
"(",
"string",
")",
"(",
"integer",
")",
"$",
"timestamp",
"===",
"(",
"string",
")",
"$",
"timestamp",
")",
"&&",
"$",
"timestamp",
"<=",
"PHP_INT_MAX",
"&&",
"$",
"timestamp",
">=",
"~",
"PHP_INT_MAX",
";",
"}"
] | Checks if a timestamp is valid.
@param integer|string $timestamp The timestamp to check.
@return boolean | [
"Checks",
"if",
"a",
"timestamp",
"is",
"valid",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Cookie/Cookie.php#L445-L448 |
13,082 | abhi1693/yii2-enum | helpers/EnumException.php | EnumException.invalidValue | public static function invalidValue($type, $value)
{
if (is_object($value)) {
$value = get_class($value);
} elseif (is_bool($value) || is_null($value)) {
$value = var_export($value, true);
}
return new self(sprintf('The type "%s" does not have a name for the value "%s".', $type, $value));
} | php | public static function invalidValue($type, $value)
{
if (is_object($value)) {
$value = get_class($value);
} elseif (is_bool($value) || is_null($value)) {
$value = var_export($value, true);
}
return new self(sprintf('The type "%s" does not have a name for the value "%s".', $type, $value));
} | [
"public",
"static",
"function",
"invalidValue",
"(",
"$",
"type",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
"||",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"}",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'The type \"%s\" does not have a name for the value \"%s\".'",
",",
"$",
"type",
",",
"$",
"value",
")",
")",
";",
"}"
] | Creates a new exception for a value that is not
valid for a type
@param string $type The name of the type
@param string $value The invalid value
@return EnumException The new exception | [
"Creates",
"a",
"new",
"exception",
"for",
"a",
"value",
"that",
"is",
"not",
"valid",
"for",
"a",
"type"
] | 1def6522303fa8f0277f09d1123229c32c942cd9 | https://github.com/abhi1693/yii2-enum/blob/1def6522303fa8f0277f09d1123229c32c942cd9/helpers/EnumException.php#L38-L47 |
13,083 | sifophp/sifo-common-instance | controllers/shared/commandLine.php | SharedCommandLineController.showMessage | protected function showMessage( $message, $in_mode = self::ALL, $params = NULL )
{
if ( isset( $params ) && is_array( $params ) )
{
$color_codes = '';
$tabs = '';
foreach ( $params as $key => $value )
{
switch ( $key )
{
case 'foreground':
{
$color_codes .= "\033[" . $this->_foreground_colors[$value] . "m";
}break;
case 'background':
{
$color_codes .= "\033[" . $this->_background_colors[$value] . "m";
}break;
case 'indent':
{
for ( $i = 0; $i < $value; $i++ )
{
$tabs = "\t" . $tabs;
}
}break;
}
}
$message = $color_codes . "[" . $in_mode . "] " . $tabs . $message . "\033[0m";
}
else
{
$message = "[" . $in_mode . "] " . $message;
}
switch ( $in_mode )
{
case self::TEST:
if ( $this->test )
{
$this->addToOutput($message);
echo $message . PHP_EOL;
}
break;
case self::VERBOSE:
$this->addToOutput($message);
if ( $this->_verbose )
{
echo $message . PHP_EOL;
}
break;
case self::ALL:
$this->addToOutput($message);
echo $message . PHP_EOL;
break;
default:
throw new \OutOfBoundsException( 'Undefined in_mode selected.' );
}
} | php | protected function showMessage( $message, $in_mode = self::ALL, $params = NULL )
{
if ( isset( $params ) && is_array( $params ) )
{
$color_codes = '';
$tabs = '';
foreach ( $params as $key => $value )
{
switch ( $key )
{
case 'foreground':
{
$color_codes .= "\033[" . $this->_foreground_colors[$value] . "m";
}break;
case 'background':
{
$color_codes .= "\033[" . $this->_background_colors[$value] . "m";
}break;
case 'indent':
{
for ( $i = 0; $i < $value; $i++ )
{
$tabs = "\t" . $tabs;
}
}break;
}
}
$message = $color_codes . "[" . $in_mode . "] " . $tabs . $message . "\033[0m";
}
else
{
$message = "[" . $in_mode . "] " . $message;
}
switch ( $in_mode )
{
case self::TEST:
if ( $this->test )
{
$this->addToOutput($message);
echo $message . PHP_EOL;
}
break;
case self::VERBOSE:
$this->addToOutput($message);
if ( $this->_verbose )
{
echo $message . PHP_EOL;
}
break;
case self::ALL:
$this->addToOutput($message);
echo $message . PHP_EOL;
break;
default:
throw new \OutOfBoundsException( 'Undefined in_mode selected.' );
}
} | [
"protected",
"function",
"showMessage",
"(",
"$",
"message",
",",
"$",
"in_mode",
"=",
"self",
"::",
"ALL",
",",
"$",
"params",
"=",
"NULL",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
")",
"&&",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"color_codes",
"=",
"''",
";",
"$",
"tabs",
"=",
"''",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'foreground'",
":",
"{",
"$",
"color_codes",
".=",
"\"\\033[\"",
".",
"$",
"this",
"->",
"_foreground_colors",
"[",
"$",
"value",
"]",
".",
"\"m\"",
";",
"}",
"break",
";",
"case",
"'background'",
":",
"{",
"$",
"color_codes",
".=",
"\"\\033[\"",
".",
"$",
"this",
"->",
"_background_colors",
"[",
"$",
"value",
"]",
".",
"\"m\"",
";",
"}",
"break",
";",
"case",
"'indent'",
":",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"value",
";",
"$",
"i",
"++",
")",
"{",
"$",
"tabs",
"=",
"\"\\t\"",
".",
"$",
"tabs",
";",
"}",
"}",
"break",
";",
"}",
"}",
"$",
"message",
"=",
"$",
"color_codes",
".",
"\"[\"",
".",
"$",
"in_mode",
".",
"\"] \"",
".",
"$",
"tabs",
".",
"$",
"message",
".",
"\"\\033[0m\"",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"[\"",
".",
"$",
"in_mode",
".",
"\"] \"",
".",
"$",
"message",
";",
"}",
"switch",
"(",
"$",
"in_mode",
")",
"{",
"case",
"self",
"::",
"TEST",
":",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"addToOutput",
"(",
"$",
"message",
")",
";",
"echo",
"$",
"message",
".",
"PHP_EOL",
";",
"}",
"break",
";",
"case",
"self",
"::",
"VERBOSE",
":",
"$",
"this",
"->",
"addToOutput",
"(",
"$",
"message",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_verbose",
")",
"{",
"echo",
"$",
"message",
".",
"PHP_EOL",
";",
"}",
"break",
";",
"case",
"self",
"::",
"ALL",
":",
"$",
"this",
"->",
"addToOutput",
"(",
"$",
"message",
")",
";",
"echo",
"$",
"message",
".",
"PHP_EOL",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Undefined in_mode selected.'",
")",
";",
"}",
"}"
] | Print a message on the console.
Usage example:
$this->showMessage( 'Example message', self::VERBOSE, array( 'background' => 'red', 'indent' => 4 ) );
@param string $message
@param string $in_mode (by default: self::ALL)
@param array $params (optional array keys: indent, foreground and background)
@throws \OutOfBoundsException | [
"Print",
"a",
"message",
"on",
"the",
"console",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/shared/commandLine.php#L166-L226 |
13,084 | sifophp/sifo-common-instance | controllers/shared/commandLine.php | SharedCommandLineController.setNewParam | protected function setNewParam( $short_param_name, $long_param_name, $help_string, $need_second_param, $is_required )
{
foreach ( $this->_shell_common_params as $param )
{
if ( ( $short_param_name == $param['short_param_name'] ) || ( $long_param_name == $param['long_param_name'] ) )
{
throw new \RuntimeException( 'You are trying to set a previously defined param.' );
}
}
$this->_shell_common_params[] = array(
'short_param_name' => $short_param_name,
'long_param_name' => $long_param_name,
'help_string' => $help_string,
'need_second_param' => $need_second_param,
'is_required' => $is_required,
);
} | php | protected function setNewParam( $short_param_name, $long_param_name, $help_string, $need_second_param, $is_required )
{
foreach ( $this->_shell_common_params as $param )
{
if ( ( $short_param_name == $param['short_param_name'] ) || ( $long_param_name == $param['long_param_name'] ) )
{
throw new \RuntimeException( 'You are trying to set a previously defined param.' );
}
}
$this->_shell_common_params[] = array(
'short_param_name' => $short_param_name,
'long_param_name' => $long_param_name,
'help_string' => $help_string,
'need_second_param' => $need_second_param,
'is_required' => $is_required,
);
} | [
"protected",
"function",
"setNewParam",
"(",
"$",
"short_param_name",
",",
"$",
"long_param_name",
",",
"$",
"help_string",
",",
"$",
"need_second_param",
",",
"$",
"is_required",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_shell_common_params",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"(",
"$",
"short_param_name",
"==",
"$",
"param",
"[",
"'short_param_name'",
"]",
")",
"||",
"(",
"$",
"long_param_name",
"==",
"$",
"param",
"[",
"'long_param_name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'You are trying to set a previously defined param.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_shell_common_params",
"[",
"]",
"=",
"array",
"(",
"'short_param_name'",
"=>",
"$",
"short_param_name",
",",
"'long_param_name'",
"=>",
"$",
"long_param_name",
",",
"'help_string'",
"=>",
"$",
"help_string",
",",
"'need_second_param'",
"=>",
"$",
"need_second_param",
",",
"'is_required'",
"=>",
"$",
"is_required",
",",
")",
";",
"}"
] | Set a new exec param.
@param string $short_param_name The short option id.
@param string $long_param_name The long name option.
@param string $help_string The help string.
@param boolean $need_second_param True if needs a param.
@param boolean $is_required Must be set.
@throws \RuntimeException | [
"Set",
"a",
"new",
"exec",
"param",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/shared/commandLine.php#L243-L261 |
13,085 | sifophp/sifo-common-instance | controllers/shared/commandLine.php | SharedCommandLineController.parseParams | protected function parseParams()
{
$this->params['parsed_params'] = array();
foreach ( $this->_shell_common_params as $common_param )
{
$value = false;
foreach ( $this->command_options as $option )
{
if ( $option[0] === $common_param['short_param_name'] || $option[0] === $common_param['long_param_name'] )
{
if ( !isset( $option[1] ) )
{
$value = true;
}
else
{
$value = $option[1];
}
break;
}
}
$this->params['parsed_params'][$common_param['short_param_name']] = $value;
$this->params['parsed_params'][$common_param['long_param_name']] = $value;
}
} | php | protected function parseParams()
{
$this->params['parsed_params'] = array();
foreach ( $this->_shell_common_params as $common_param )
{
$value = false;
foreach ( $this->command_options as $option )
{
if ( $option[0] === $common_param['short_param_name'] || $option[0] === $common_param['long_param_name'] )
{
if ( !isset( $option[1] ) )
{
$value = true;
}
else
{
$value = $option[1];
}
break;
}
}
$this->params['parsed_params'][$common_param['short_param_name']] = $value;
$this->params['parsed_params'][$common_param['long_param_name']] = $value;
}
} | [
"protected",
"function",
"parseParams",
"(",
")",
"{",
"$",
"this",
"->",
"params",
"[",
"'parsed_params'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_shell_common_params",
"as",
"$",
"common_param",
")",
"{",
"$",
"value",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"command_options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"option",
"[",
"0",
"]",
"===",
"$",
"common_param",
"[",
"'short_param_name'",
"]",
"||",
"$",
"option",
"[",
"0",
"]",
"===",
"$",
"common_param",
"[",
"'long_param_name'",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"option",
"[",
"1",
"]",
")",
")",
"{",
"$",
"value",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"option",
"[",
"1",
"]",
";",
"}",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"params",
"[",
"'parsed_params'",
"]",
"[",
"$",
"common_param",
"[",
"'short_param_name'",
"]",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"params",
"[",
"'parsed_params'",
"]",
"[",
"$",
"common_param",
"[",
"'long_param_name'",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Parse the input arguments and store them in a class property for later usage.
@internal param array $params Get params.
@return array | [
"Parse",
"the",
"input",
"arguments",
"and",
"store",
"them",
"in",
"a",
"class",
"property",
"for",
"later",
"usage",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/shared/commandLine.php#L568-L593 |
13,086 | crysalead/net | src/MixedPart.php | MixedPart._updateContentType | public function _updateContentType()
{
unset($this->_headers['Content-Type']);
$suffix = '';
if ($this->isMultipart()) {
$suffix = '; boundary=' . $this->boundary();
} elseif ($this->_charset) {
$suffix = '; charset=' . $this->_charset . $suffix;
}
if ($this->_mime) {
$this->_headers['Content-Type'] = $this->_mime . $suffix;
}
} | php | public function _updateContentType()
{
unset($this->_headers['Content-Type']);
$suffix = '';
if ($this->isMultipart()) {
$suffix = '; boundary=' . $this->boundary();
} elseif ($this->_charset) {
$suffix = '; charset=' . $this->_charset . $suffix;
}
if ($this->_mime) {
$this->_headers['Content-Type'] = $this->_mime . $suffix;
}
} | [
"public",
"function",
"_updateContentType",
"(",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'Content-Type'",
"]",
")",
";",
"$",
"suffix",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"isMultipart",
"(",
")",
")",
"{",
"$",
"suffix",
"=",
"'; boundary='",
".",
"$",
"this",
"->",
"boundary",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_charset",
")",
"{",
"$",
"suffix",
"=",
"'; charset='",
".",
"$",
"this",
"->",
"_charset",
".",
"$",
"suffix",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_mime",
")",
"{",
"$",
"this",
"->",
"_headers",
"[",
"'Content-Type'",
"]",
"=",
"$",
"this",
"->",
"_mime",
".",
"$",
"suffix",
";",
"}",
"}"
] | Update Content-Type helper | [
"Update",
"Content",
"-",
"Type",
"helper"
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/MixedPart.php#L152-L164 |
13,087 | crysalead/net | src/MixedPart.php | MixedPart.syncContentType | public function syncContentType()
{
$stream = reset($this->_streams);
if (!$this->isMultipart() && $stream) {
unset($this->_headers['Content-Type']);
$this->mime($stream->mime());
$this->charset($stream->charset());
unset($this->_headers['Content-Transfer-Encoding']);
if ($encoding = $stream->encoding()) {
$this->_headers['Content-Transfer-Encoding'] = $encoding;
}
}
} | php | public function syncContentType()
{
$stream = reset($this->_streams);
if (!$this->isMultipart() && $stream) {
unset($this->_headers['Content-Type']);
$this->mime($stream->mime());
$this->charset($stream->charset());
unset($this->_headers['Content-Transfer-Encoding']);
if ($encoding = $stream->encoding()) {
$this->_headers['Content-Transfer-Encoding'] = $encoding;
}
}
} | [
"public",
"function",
"syncContentType",
"(",
")",
"{",
"$",
"stream",
"=",
"reset",
"(",
"$",
"this",
"->",
"_streams",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isMultipart",
"(",
")",
"&&",
"$",
"stream",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'Content-Type'",
"]",
")",
";",
"$",
"this",
"->",
"mime",
"(",
"$",
"stream",
"->",
"mime",
"(",
")",
")",
";",
"$",
"this",
"->",
"charset",
"(",
"$",
"stream",
"->",
"charset",
"(",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'Content-Transfer-Encoding'",
"]",
")",
";",
"if",
"(",
"$",
"encoding",
"=",
"$",
"stream",
"->",
"encoding",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_headers",
"[",
"'Content-Transfer-Encoding'",
"]",
"=",
"$",
"encoding",
";",
"}",
"}",
"}"
] | Sync Content-Type helper. | [
"Sync",
"Content",
"-",
"Type",
"helper",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/MixedPart.php#L299-L311 |
13,088 | crysalead/net | src/MixedPart.php | MixedPart._headers | protected function _headers($options, $mime, $charset, $encoding, $length)
{
$headers = !empty($options['headers']) ? $options['headers'] : [];
if (!empty($options['disposition'])) {
$parts = [$options['disposition']];
foreach (['name', 'filename'] as $name) {
if (!empty($options[$name])) {
$value = htmlspecialchars_decode(htmlspecialchars($options[$name], ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
$value = preg_replace('~[\s/\\\]~', '', $value);
$value = addcslashes($value, '"');
$parts[] = "{$name}=\"{$value}\"";
}
}
$headers[] = "Content-Disposition: " . join('; ', $parts);
}
if (!empty($options['id'])) {
$headers[] = 'Content-ID: ' . $options['id'];
}
if (!empty($mime)) {
$charset = $charset ? '; charset=' . $charset : '';
$headers[] = 'Content-Type: ' . $mime . $charset;
}
if (!empty($encoding)) {
$headers[] = 'Content-Transfer-Encoding: ' . $encoding;
}
if (!empty($options['length'])) {
$headers[] = 'Content-Length: ' . $length;
}
if (!empty($options['description'])) {
$headers[] = 'Content-Description: ' . $options['description'];
}
if (!empty($options['location'])) {
$headers[] = 'Content-Location: ' . $options['location'];
}
if (!empty($options['language'])) {
$headers[] = 'Content-Language: ' . $options['language'];
}
return $headers;
} | php | protected function _headers($options, $mime, $charset, $encoding, $length)
{
$headers = !empty($options['headers']) ? $options['headers'] : [];
if (!empty($options['disposition'])) {
$parts = [$options['disposition']];
foreach (['name', 'filename'] as $name) {
if (!empty($options[$name])) {
$value = htmlspecialchars_decode(htmlspecialchars($options[$name], ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
$value = preg_replace('~[\s/\\\]~', '', $value);
$value = addcslashes($value, '"');
$parts[] = "{$name}=\"{$value}\"";
}
}
$headers[] = "Content-Disposition: " . join('; ', $parts);
}
if (!empty($options['id'])) {
$headers[] = 'Content-ID: ' . $options['id'];
}
if (!empty($mime)) {
$charset = $charset ? '; charset=' . $charset : '';
$headers[] = 'Content-Type: ' . $mime . $charset;
}
if (!empty($encoding)) {
$headers[] = 'Content-Transfer-Encoding: ' . $encoding;
}
if (!empty($options['length'])) {
$headers[] = 'Content-Length: ' . $length;
}
if (!empty($options['description'])) {
$headers[] = 'Content-Description: ' . $options['description'];
}
if (!empty($options['location'])) {
$headers[] = 'Content-Location: ' . $options['location'];
}
if (!empty($options['language'])) {
$headers[] = 'Content-Language: ' . $options['language'];
}
return $headers;
} | [
"protected",
"function",
"_headers",
"(",
"$",
"options",
",",
"$",
"mime",
",",
"$",
"charset",
",",
"$",
"encoding",
",",
"$",
"length",
")",
"{",
"$",
"headers",
"=",
"!",
"empty",
"(",
"$",
"options",
"[",
"'headers'",
"]",
")",
"?",
"$",
"options",
"[",
"'headers'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'disposition'",
"]",
")",
")",
"{",
"$",
"parts",
"=",
"[",
"$",
"options",
"[",
"'disposition'",
"]",
"]",
";",
"foreach",
"(",
"[",
"'name'",
",",
"'filename'",
"]",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"value",
"=",
"htmlspecialchars_decode",
"(",
"htmlspecialchars",
"(",
"$",
"options",
"[",
"$",
"name",
"]",
",",
"ENT_NOQUOTES",
"|",
"ENT_IGNORE",
",",
"'UTF-8'",
")",
",",
"ENT_NOQUOTES",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"'~[\\s/\\\\\\]~'",
",",
"''",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"addcslashes",
"(",
"$",
"value",
",",
"'\"'",
")",
";",
"$",
"parts",
"[",
"]",
"=",
"\"{$name}=\\\"{$value}\\\"\"",
";",
"}",
"}",
"$",
"headers",
"[",
"]",
"=",
"\"Content-Disposition: \"",
".",
"join",
"(",
"'; '",
",",
"$",
"parts",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-ID: '",
".",
"$",
"options",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"mime",
")",
")",
"{",
"$",
"charset",
"=",
"$",
"charset",
"?",
"'; charset='",
".",
"$",
"charset",
":",
"''",
";",
"$",
"headers",
"[",
"]",
"=",
"'Content-Type: '",
".",
"$",
"mime",
".",
"$",
"charset",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"encoding",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-Transfer-Encoding: '",
".",
"$",
"encoding",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'length'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-Length: '",
".",
"$",
"length",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-Description: '",
".",
"$",
"options",
"[",
"'description'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'location'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-Location: '",
".",
"$",
"options",
"[",
"'location'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'language'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Content-Language: '",
".",
"$",
"options",
"[",
"'language'",
"]",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Extract headers form streams options.
@param array $options The stream end user options.
@param string $length The length of the encoded stream.
@return array | [
"Extract",
"headers",
"form",
"streams",
"options",
"."
] | 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/MixedPart.php#L364-L410 |
13,089 | transfer-framework/transfer | src/Transfer/Adapter/LocalDirectoryAdapter.php | LocalDirectoryAdapter.currentCallback | public function currentCallback(CallbackIterator $iterator)
{
$clientFilename = $this->fileNames[$iterator->key()];
$filename = $this->directory.DIRECTORY_SEPARATOR.$clientFilename;
$fileObject = new ValueObject(file_get_contents($filename));
$fileObject->setProperty('filename', $filename);
$fileObject->setProperty('client_filename', $clientFilename);
return $fileObject;
} | php | public function currentCallback(CallbackIterator $iterator)
{
$clientFilename = $this->fileNames[$iterator->key()];
$filename = $this->directory.DIRECTORY_SEPARATOR.$clientFilename;
$fileObject = new ValueObject(file_get_contents($filename));
$fileObject->setProperty('filename', $filename);
$fileObject->setProperty('client_filename', $clientFilename);
return $fileObject;
} | [
"public",
"function",
"currentCallback",
"(",
"CallbackIterator",
"$",
"iterator",
")",
"{",
"$",
"clientFilename",
"=",
"$",
"this",
"->",
"fileNames",
"[",
"$",
"iterator",
"->",
"key",
"(",
")",
"]",
";",
"$",
"filename",
"=",
"$",
"this",
"->",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"clientFilename",
";",
"$",
"fileObject",
"=",
"new",
"ValueObject",
"(",
"file_get_contents",
"(",
"$",
"filename",
")",
")",
";",
"$",
"fileObject",
"->",
"setProperty",
"(",
"'filename'",
",",
"$",
"filename",
")",
";",
"$",
"fileObject",
"->",
"setProperty",
"(",
"'client_filename'",
",",
"$",
"clientFilename",
")",
";",
"return",
"$",
"fileObject",
";",
"}"
] | Returns a file object.
@param CallbackIterator $iterator
@return ValueObject | [
"Returns",
"a",
"file",
"object",
"."
] | 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Adapter/LocalDirectoryAdapter.php#L94-L104 |
13,090 | dekuan/delib | src/CMIdLib.php | CMIdLib.isValidMId | static function isValidMId( $vMId )
{
$bRet = false;
if ( is_array( $vMId ) && count( $vMId ) > 0 )
{
$bRet = true;
foreach ( $vMId as $vItem )
{
if ( ! CDId::getInstance()->isValidId( $vItem ) )
{
$bRet = false;
break;
}
}
}
else
{
$bRet = CDId::getInstance()->isValidId( intval( $vMId ) );
}
return $bRet;
} | php | static function isValidMId( $vMId )
{
$bRet = false;
if ( is_array( $vMId ) && count( $vMId ) > 0 )
{
$bRet = true;
foreach ( $vMId as $vItem )
{
if ( ! CDId::getInstance()->isValidId( $vItem ) )
{
$bRet = false;
break;
}
}
}
else
{
$bRet = CDId::getInstance()->isValidId( intval( $vMId ) );
}
return $bRet;
} | [
"static",
"function",
"isValidMId",
"(",
"$",
"vMId",
")",
"{",
"$",
"bRet",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"vMId",
")",
"&&",
"count",
"(",
"$",
"vMId",
")",
">",
"0",
")",
"{",
"$",
"bRet",
"=",
"true",
";",
"foreach",
"(",
"$",
"vMId",
"as",
"$",
"vItem",
")",
"{",
"if",
"(",
"!",
"CDId",
"::",
"getInstance",
"(",
")",
"->",
"isValidId",
"(",
"$",
"vItem",
")",
")",
"{",
"$",
"bRet",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"bRet",
"=",
"CDId",
"::",
"getInstance",
"(",
")",
"->",
"isValidId",
"(",
"intval",
"(",
"$",
"vMId",
")",
")",
";",
"}",
"return",
"$",
"bRet",
";",
"}"
] | check if a mid is valid
@param $vMId mixed
@return boolean | [
"check",
"if",
"a",
"mid",
"is",
"valid"
] | a0b82c5f1eb0cf7379eac3670ebf362787a7c6f8 | https://github.com/dekuan/delib/blob/a0b82c5f1eb0cf7379eac3670ebf362787a7c6f8/src/CMIdLib.php#L19-L41 |
13,091 | dekuan/delib | src/CMIdLib.php | CMIdLib.createMId | static function createMId( $nCenter = 0, $nNode = 0, $sSource = null, & $arrData = null )
{
return CDId::getInstance()->createId( $nCenter, $nNode, $sSource, $arrData );
} | php | static function createMId( $nCenter = 0, $nNode = 0, $sSource = null, & $arrData = null )
{
return CDId::getInstance()->createId( $nCenter, $nNode, $sSource, $arrData );
} | [
"static",
"function",
"createMId",
"(",
"$",
"nCenter",
"=",
"0",
",",
"$",
"nNode",
"=",
"0",
",",
"$",
"sSource",
"=",
"null",
",",
"&",
"$",
"arrData",
"=",
"null",
")",
"{",
"return",
"CDId",
"::",
"getInstance",
"(",
")",
"->",
"createId",
"(",
"$",
"nCenter",
",",
"$",
"nNode",
",",
"$",
"sSource",
",",
"$",
"arrData",
")",
";",
"}"
] | create a new mid
@param $nCenter int
@param $nNode int
@param $sSource string
@param $arrData array
@return int | [
"create",
"a",
"new",
"mid"
] | a0b82c5f1eb0cf7379eac3670ebf362787a7c6f8 | https://github.com/dekuan/delib/blob/a0b82c5f1eb0cf7379eac3670ebf362787a7c6f8/src/CMIdLib.php#L52-L55 |
13,092 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Captcha.php | Captcha.createNewToken | public function createNewToken($captcha = null, $answer = null, $expire = 300)
{
if ((null === $captcha) || (null === $answer)) {
$captcha = $this->generateEquation();
$answer = $this->evaluateEquation($captcha);
}
$this->token = [
'captcha' => $captcha,
'answer' => $answer,
'expire' => (int)$expire,
'start' => time()
];
$_SESSION['pop_captcha'] = serialize($this->token);
return $this;
} | php | public function createNewToken($captcha = null, $answer = null, $expire = 300)
{
if ((null === $captcha) || (null === $answer)) {
$captcha = $this->generateEquation();
$answer = $this->evaluateEquation($captcha);
}
$this->token = [
'captcha' => $captcha,
'answer' => $answer,
'expire' => (int)$expire,
'start' => time()
];
$_SESSION['pop_captcha'] = serialize($this->token);
return $this;
} | [
"public",
"function",
"createNewToken",
"(",
"$",
"captcha",
"=",
"null",
",",
"$",
"answer",
"=",
"null",
",",
"$",
"expire",
"=",
"300",
")",
"{",
"if",
"(",
"(",
"null",
"===",
"$",
"captcha",
")",
"||",
"(",
"null",
"===",
"$",
"answer",
")",
")",
"{",
"$",
"captcha",
"=",
"$",
"this",
"->",
"generateEquation",
"(",
")",
";",
"$",
"answer",
"=",
"$",
"this",
"->",
"evaluateEquation",
"(",
"$",
"captcha",
")",
";",
"}",
"$",
"this",
"->",
"token",
"=",
"[",
"'captcha'",
"=>",
"$",
"captcha",
",",
"'answer'",
"=>",
"$",
"answer",
",",
"'expire'",
"=>",
"(",
"int",
")",
"$",
"expire",
",",
"'start'",
"=>",
"time",
"(",
")",
"]",
";",
"$",
"_SESSION",
"[",
"'pop_captcha'",
"]",
"=",
"serialize",
"(",
"$",
"this",
"->",
"token",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the token of the CAPTCHA form element
@param string $captcha
@param string $answer
@param int $expire
@return Captcha | [
"Set",
"the",
"token",
"of",
"the",
"CAPTCHA",
"form",
"element"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Captcha.php#L66-L80 |
13,093 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Captcha.php | Captcha.setLabel | public function setLabel($label)
{
parent::setLabel($label);
if (isset($this->token['captcha'])) {
if ((strpos($this->token['captcha'], '<img') === false) &&
((strpos($this->token['captcha'], ' + ') !== false) ||
(strpos($this->token['captcha'], ' - ') !== false) ||
(strpos($this->token['captcha'], ' * ') !== false) ||
(strpos($this->token['captcha'], ' / ') !== false))) {
$this->label = $this->label . '(' .
str_replace([' * ', ' / '], [' × ', ' ÷ '], $this->token['captcha'] .')');
} else {
$this->label = $this->label . $this->token['captcha'];
}
}
return $this;
} | php | public function setLabel($label)
{
parent::setLabel($label);
if (isset($this->token['captcha'])) {
if ((strpos($this->token['captcha'], '<img') === false) &&
((strpos($this->token['captcha'], ' + ') !== false) ||
(strpos($this->token['captcha'], ' - ') !== false) ||
(strpos($this->token['captcha'], ' * ') !== false) ||
(strpos($this->token['captcha'], ' / ') !== false))) {
$this->label = $this->label . '(' .
str_replace([' * ', ' / '], [' × ', ' ÷ '], $this->token['captcha'] .')');
} else {
$this->label = $this->label . $this->token['captcha'];
}
}
return $this;
} | [
"public",
"function",
"setLabel",
"(",
"$",
"label",
")",
"{",
"parent",
"::",
"setLabel",
"(",
"$",
"label",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
")",
")",
"{",
"if",
"(",
"(",
"strpos",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
",",
"'<img'",
")",
"===",
"false",
")",
"&&",
"(",
"(",
"strpos",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
",",
"' + '",
")",
"!==",
"false",
")",
"||",
"(",
"strpos",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
",",
"' - '",
")",
"!==",
"false",
")",
"||",
"(",
"strpos",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
",",
"' * '",
")",
"!==",
"false",
")",
"||",
"(",
"strpos",
"(",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
",",
"' / '",
")",
"!==",
"false",
")",
")",
")",
"{",
"$",
"this",
"->",
"label",
"=",
"$",
"this",
"->",
"label",
".",
"'('",
".",
"str_replace",
"(",
"[",
"' * '",
",",
"' / '",
"]",
",",
"[",
"' × '",
",",
"' ÷ '",
"]",
",",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
".",
"')'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"label",
"=",
"$",
"this",
"->",
"label",
".",
"$",
"this",
"->",
"token",
"[",
"'captcha'",
"]",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the label of the captcha form element
@param string $label
@return Captcha | [
"Set",
"the",
"label",
"of",
"the",
"captcha",
"form",
"element"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Captcha.php#L96-L112 |
13,094 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Captcha.php | Captcha.generateEquation | protected function generateEquation()
{
$ops = [' + ', ' - ', ' * ', ' / '];
$equation = null;
$rand1 = rand(1, 10);
$rand2 = rand(1, 10);
$op = $ops[rand(0, 3)];
// If the operator is division, keep the equation very simple, with no remainder
if ($op == ' / ') {
$mod = ($rand2 > $rand1) ? $rand2 % $rand1 : $rand1 % $rand2;
while ($mod != 0) {
$rand1 = rand(1, 10);
$rand2 = rand(1, 10);
$mod = ($rand2 > $rand1) ? $rand2 % $rand1 : $rand1 % $rand2;
}
}
$equation = ($rand2 > $rand1) ? $rand2 . $op . $rand1 : $rand1 . $op . $rand2;
return $equation;
} | php | protected function generateEquation()
{
$ops = [' + ', ' - ', ' * ', ' / '];
$equation = null;
$rand1 = rand(1, 10);
$rand2 = rand(1, 10);
$op = $ops[rand(0, 3)];
// If the operator is division, keep the equation very simple, with no remainder
if ($op == ' / ') {
$mod = ($rand2 > $rand1) ? $rand2 % $rand1 : $rand1 % $rand2;
while ($mod != 0) {
$rand1 = rand(1, 10);
$rand2 = rand(1, 10);
$mod = ($rand2 > $rand1) ? $rand2 % $rand1 : $rand1 % $rand2;
}
}
$equation = ($rand2 > $rand1) ? $rand2 . $op . $rand1 : $rand1 . $op . $rand2;
return $equation;
} | [
"protected",
"function",
"generateEquation",
"(",
")",
"{",
"$",
"ops",
"=",
"[",
"' + '",
",",
"' - '",
",",
"' * '",
",",
"' / '",
"]",
";",
"$",
"equation",
"=",
"null",
";",
"$",
"rand1",
"=",
"rand",
"(",
"1",
",",
"10",
")",
";",
"$",
"rand2",
"=",
"rand",
"(",
"1",
",",
"10",
")",
";",
"$",
"op",
"=",
"$",
"ops",
"[",
"rand",
"(",
"0",
",",
"3",
")",
"]",
";",
"// If the operator is division, keep the equation very simple, with no remainder",
"if",
"(",
"$",
"op",
"==",
"' / '",
")",
"{",
"$",
"mod",
"=",
"(",
"$",
"rand2",
">",
"$",
"rand1",
")",
"?",
"$",
"rand2",
"%",
"$",
"rand1",
":",
"$",
"rand1",
"%",
"$",
"rand2",
";",
"while",
"(",
"$",
"mod",
"!=",
"0",
")",
"{",
"$",
"rand1",
"=",
"rand",
"(",
"1",
",",
"10",
")",
";",
"$",
"rand2",
"=",
"rand",
"(",
"1",
",",
"10",
")",
";",
"$",
"mod",
"=",
"(",
"$",
"rand2",
">",
"$",
"rand1",
")",
"?",
"$",
"rand2",
"%",
"$",
"rand1",
":",
"$",
"rand1",
"%",
"$",
"rand2",
";",
"}",
"}",
"$",
"equation",
"=",
"(",
"$",
"rand2",
">",
"$",
"rand1",
")",
"?",
"$",
"rand2",
".",
"$",
"op",
".",
"$",
"rand1",
":",
"$",
"rand1",
".",
"$",
"op",
".",
"$",
"rand2",
";",
"return",
"$",
"equation",
";",
"}"
] | Randomly generate a simple, basic equation
@return string | [
"Randomly",
"generate",
"a",
"simple",
"basic",
"equation"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Captcha.php#L161-L179 |
13,095 | breadlesscode/neos-listable | Classes/Fusion/PaginationArrayImplementation.php | PaginationArrayImplementation.calculateFirstAndLastPage | protected function calculateFirstAndLastPage()
{
$delta = \floor($this->maximumNumberOfLinks / 2);
$firstPage = $this->currentPage - $delta;
$lastPage = $this->currentPage + $delta + ($this->maximumNumberOfLinks % 2 === 0 ? 1 : 0);
if ($firstPage < 1) {
$lastPage -= $firstPage - 1;
}
if ($lastPage > $this->numberOfPages) {
$firstPage -= ($lastPage - $this->numberOfPages);
}
$this->firstPage = \max($firstPage, 1);
$this->lastPage = \min($lastPage, $this->numberOfPages);
} | php | protected function calculateFirstAndLastPage()
{
$delta = \floor($this->maximumNumberOfLinks / 2);
$firstPage = $this->currentPage - $delta;
$lastPage = $this->currentPage + $delta + ($this->maximumNumberOfLinks % 2 === 0 ? 1 : 0);
if ($firstPage < 1) {
$lastPage -= $firstPage - 1;
}
if ($lastPage > $this->numberOfPages) {
$firstPage -= ($lastPage - $this->numberOfPages);
}
$this->firstPage = \max($firstPage, 1);
$this->lastPage = \min($lastPage, $this->numberOfPages);
} | [
"protected",
"function",
"calculateFirstAndLastPage",
"(",
")",
"{",
"$",
"delta",
"=",
"\\",
"floor",
"(",
"$",
"this",
"->",
"maximumNumberOfLinks",
"/",
"2",
")",
";",
"$",
"firstPage",
"=",
"$",
"this",
"->",
"currentPage",
"-",
"$",
"delta",
";",
"$",
"lastPage",
"=",
"$",
"this",
"->",
"currentPage",
"+",
"$",
"delta",
"+",
"(",
"$",
"this",
"->",
"maximumNumberOfLinks",
"%",
"2",
"===",
"0",
"?",
"1",
":",
"0",
")",
";",
"if",
"(",
"$",
"firstPage",
"<",
"1",
")",
"{",
"$",
"lastPage",
"-=",
"$",
"firstPage",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"lastPage",
">",
"$",
"this",
"->",
"numberOfPages",
")",
"{",
"$",
"firstPage",
"-=",
"(",
"$",
"lastPage",
"-",
"$",
"this",
"->",
"numberOfPages",
")",
";",
"}",
"$",
"this",
"->",
"firstPage",
"=",
"\\",
"max",
"(",
"$",
"firstPage",
",",
"1",
")",
";",
"$",
"this",
"->",
"lastPage",
"=",
"\\",
"min",
"(",
"$",
"lastPage",
",",
"$",
"this",
"->",
"numberOfPages",
")",
";",
"}"
] | calculates the first and last page to show
@return void | [
"calculates",
"the",
"first",
"and",
"last",
"page",
"to",
"show"
] | a1d77ab86f4f9b12a81bbe86959be0874d4a1b92 | https://github.com/breadlesscode/neos-listable/blob/a1d77ab86f4f9b12a81bbe86959be0874d4a1b92/Classes/Fusion/PaginationArrayImplementation.php#L39-L54 |
13,096 | breadlesscode/neos-listable | Classes/Fusion/PaginationArrayImplementation.php | PaginationArrayImplementation.getNumberOfPages | protected function getNumberOfPages()
{
$numberOfPages = \ceil($this->totalCount / $this->itemsPerPage);
if ($this->maximumNumberOfLinks > $numberOfPages) {
return $numberOfPages;
}
return $numberOfPages;
} | php | protected function getNumberOfPages()
{
$numberOfPages = \ceil($this->totalCount / $this->itemsPerPage);
if ($this->maximumNumberOfLinks > $numberOfPages) {
return $numberOfPages;
}
return $numberOfPages;
} | [
"protected",
"function",
"getNumberOfPages",
"(",
")",
"{",
"$",
"numberOfPages",
"=",
"\\",
"ceil",
"(",
"$",
"this",
"->",
"totalCount",
"/",
"$",
"this",
"->",
"itemsPerPage",
")",
";",
"if",
"(",
"$",
"this",
"->",
"maximumNumberOfLinks",
">",
"$",
"numberOfPages",
")",
"{",
"return",
"$",
"numberOfPages",
";",
"}",
"return",
"$",
"numberOfPages",
";",
"}"
] | calculates the number of pages
@return integer | [
"calculates",
"the",
"number",
"of",
"pages"
] | a1d77ab86f4f9b12a81bbe86959be0874d4a1b92 | https://github.com/breadlesscode/neos-listable/blob/a1d77ab86f4f9b12a81bbe86959be0874d4a1b92/Classes/Fusion/PaginationArrayImplementation.php#L60-L68 |
13,097 | breadlesscode/neos-listable | Classes/Fusion/PaginationArrayImplementation.php | PaginationArrayImplementation.getPageArray | protected function getPageArray()
{
$range = \range($this->firstPage, $this->lastPage);
$pageArray = [];
foreach ($range as $page) {
$pageArray[] = [
'page' => $page,
'label' => $page,
'type' => 'page'
];
}
return $pageArray;
} | php | protected function getPageArray()
{
$range = \range($this->firstPage, $this->lastPage);
$pageArray = [];
foreach ($range as $page) {
$pageArray[] = [
'page' => $page,
'label' => $page,
'type' => 'page'
];
}
return $pageArray;
} | [
"protected",
"function",
"getPageArray",
"(",
")",
"{",
"$",
"range",
"=",
"\\",
"range",
"(",
"$",
"this",
"->",
"firstPage",
",",
"$",
"this",
"->",
"lastPage",
")",
";",
"$",
"pageArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"range",
"as",
"$",
"page",
")",
"{",
"$",
"pageArray",
"[",
"]",
"=",
"[",
"'page'",
"=>",
"$",
"page",
",",
"'label'",
"=>",
"$",
"page",
",",
"'type'",
"=>",
"'page'",
"]",
";",
"}",
"return",
"$",
"pageArray",
";",
"}"
] | get an array of pages to display
@return array | [
"get",
"an",
"array",
"of",
"pages",
"to",
"display"
] | a1d77ab86f4f9b12a81bbe86959be0874d4a1b92 | https://github.com/breadlesscode/neos-listable/blob/a1d77ab86f4f9b12a81bbe86959be0874d4a1b92/Classes/Fusion/PaginationArrayImplementation.php#L74-L88 |
13,098 | breadlesscode/neos-listable | Classes/Fusion/PaginationArrayImplementation.php | PaginationArrayImplementation.addItemToTheStartOfPageArray | protected function addItemToTheStartOfPageArray($pageArray, $page, $type)
{
array_unshift($pageArray, [
'page' => $page,
'label' => $this->paginationConfig['labels'][$type],
'type' => $type
]);
return $pageArray;
} | php | protected function addItemToTheStartOfPageArray($pageArray, $page, $type)
{
array_unshift($pageArray, [
'page' => $page,
'label' => $this->paginationConfig['labels'][$type],
'type' => $type
]);
return $pageArray;
} | [
"protected",
"function",
"addItemToTheStartOfPageArray",
"(",
"$",
"pageArray",
",",
"$",
"page",
",",
"$",
"type",
")",
"{",
"array_unshift",
"(",
"$",
"pageArray",
",",
"[",
"'page'",
"=>",
"$",
"page",
",",
"'label'",
"=>",
"$",
"this",
"->",
"paginationConfig",
"[",
"'labels'",
"]",
"[",
"$",
"type",
"]",
",",
"'type'",
"=>",
"$",
"type",
"]",
")",
";",
"return",
"$",
"pageArray",
";",
"}"
] | add a item to the start of the page array
@param array $pageArray
@param integer $page
@param string $type
@return array | [
"add",
"a",
"item",
"to",
"the",
"start",
"of",
"the",
"page",
"array"
] | a1d77ab86f4f9b12a81bbe86959be0874d4a1b92 | https://github.com/breadlesscode/neos-listable/blob/a1d77ab86f4f9b12a81bbe86959be0874d4a1b92/Classes/Fusion/PaginationArrayImplementation.php#L97-L106 |
13,099 | breadlesscode/neos-listable | Classes/Fusion/PaginationArrayImplementation.php | PaginationArrayImplementation.addItemToTheEndOfPageArray | protected function addItemToTheEndOfPageArray($pageArray, $page, $type)
{
$pageArray[] = [
'page' => $page,
'label' => $this->paginationConfig['labels'][$type],
'type' => $type
];
return $pageArray;
} | php | protected function addItemToTheEndOfPageArray($pageArray, $page, $type)
{
$pageArray[] = [
'page' => $page,
'label' => $this->paginationConfig['labels'][$type],
'type' => $type
];
return $pageArray;
} | [
"protected",
"function",
"addItemToTheEndOfPageArray",
"(",
"$",
"pageArray",
",",
"$",
"page",
",",
"$",
"type",
")",
"{",
"$",
"pageArray",
"[",
"]",
"=",
"[",
"'page'",
"=>",
"$",
"page",
",",
"'label'",
"=>",
"$",
"this",
"->",
"paginationConfig",
"[",
"'labels'",
"]",
"[",
"$",
"type",
"]",
",",
"'type'",
"=>",
"$",
"type",
"]",
";",
"return",
"$",
"pageArray",
";",
"}"
] | add a item to the end of the page array
@param array $pageArray
@param integer $page
@param string $type
@return array | [
"add",
"a",
"item",
"to",
"the",
"end",
"of",
"the",
"page",
"array"
] | a1d77ab86f4f9b12a81bbe86959be0874d4a1b92 | https://github.com/breadlesscode/neos-listable/blob/a1d77ab86f4f9b12a81bbe86959be0874d4a1b92/Classes/Fusion/PaginationArrayImplementation.php#L115-L124 |
Subsets and Splits