repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
SpoonX/SxBootstrap | src/SxBootstrap/Service/BootstrapFilter.php | BootstrapFilter.removeImportFiles | protected function removeImportFiles(array $importFiles, array $config)
{
foreach ($config as $item) {
if (in_array($item, $importFiles)) {
unset($importFiles[array_search($item, $importFiles)]);
}
}
return $importFiles;
} | php | protected function removeImportFiles(array $importFiles, array $config)
{
foreach ($config as $item) {
if (in_array($item, $importFiles)) {
unset($importFiles[array_search($item, $importFiles)]);
}
}
return $importFiles;
} | [
"protected",
"function",
"removeImportFiles",
"(",
"array",
"$",
"importFiles",
",",
"array",
"$",
"config",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"item",
",",
"$",
"importFiles",
")",
")",
"{",
"unset",
"(",
"$",
"importFiles",
"[",
"array_search",
"(",
"$",
"item",
",",
"$",
"importFiles",
")",
"]",
")",
";",
"}",
"}",
"return",
"$",
"importFiles",
";",
"}"
] | Remove import files from the import config.
@param array $importFiles
@param array $config
@return array | [
"Remove",
"import",
"files",
"from",
"the",
"import",
"config",
"."
] | 768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6 | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/Service/BootstrapFilter.php#L212-L221 | train |
phramework/phramework | src/Models/Request.php | Request.checkPermission | public static function checkPermission($userId = false)
{
$user = \Phramework\Phramework::getUser();
//If user is not authenticated throw an \Exception
if (!$user) {
throw new \Phramework\Exceptions\UnauthorizedException();
}
//Check if speficied user is same as current user
if ($userId !== false && $user->id != $userId) {
throw new PermissionException(
'Insufficient permissions'
);
}
return $user;
} | php | public static function checkPermission($userId = false)
{
$user = \Phramework\Phramework::getUser();
//If user is not authenticated throw an \Exception
if (!$user) {
throw new \Phramework\Exceptions\UnauthorizedException();
}
//Check if speficied user is same as current user
if ($userId !== false && $user->id != $userId) {
throw new PermissionException(
'Insufficient permissions'
);
}
return $user;
} | [
"public",
"static",
"function",
"checkPermission",
"(",
"$",
"userId",
"=",
"false",
")",
"{",
"$",
"user",
"=",
"\\",
"Phramework",
"\\",
"Phramework",
"::",
"getUser",
"(",
")",
";",
"//If user is not authenticated throw an \\Exception",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"\\",
"Phramework",
"\\",
"Exceptions",
"\\",
"UnauthorizedException",
"(",
")",
";",
"}",
"//Check if speficied user is same as current user",
"if",
"(",
"$",
"userId",
"!==",
"false",
"&&",
"$",
"user",
"->",
"id",
"!=",
"$",
"userId",
")",
"{",
"throw",
"new",
"PermissionException",
"(",
"'Insufficient permissions'",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Check if current request is authenticated
Optionaly it checks the authenticated user has a specific user_id
@param integer $userId *[Optional]* Check if current user has the same id with $userId
@return object Returns the user object
@throws \Phramework\Exceptions\PermissionException
@throws \Phramework\Exceptions\UnauthorizedException | [
"Check",
"if",
"current",
"request",
"is",
"authenticated"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Request.php#L46-L63 | train |
phramework/phramework | src/Models/Request.php | Request.requireParameters | public static function requireParameters($parameters, $required)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
$missing = [];
if (!is_array($required)) {
$required = [$required];
}
foreach ($required as $key) {
if (!isset($parameters[$key])) {
array_push($missing, $key);
}
}
if (count($missing)) {
throw new MissingParametersException($missing);
}
} | php | public static function requireParameters($parameters, $required)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
$missing = [];
if (!is_array($required)) {
$required = [$required];
}
foreach ($required as $key) {
if (!isset($parameters[$key])) {
array_push($missing, $key);
}
}
if (count($missing)) {
throw new MissingParametersException($missing);
}
} | [
"public",
"static",
"function",
"requireParameters",
"(",
"$",
"parameters",
",",
"$",
"required",
")",
"{",
"//Work with arrays",
"if",
"(",
"is_object",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parameters",
"=",
"(",
"array",
")",
"$",
"parameters",
";",
"}",
"$",
"missing",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"required",
")",
")",
"{",
"$",
"required",
"=",
"[",
"$",
"required",
"]",
";",
"}",
"foreach",
"(",
"$",
"required",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
")",
"{",
"array_push",
"(",
"$",
"missing",
",",
"$",
"key",
")",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"missing",
")",
")",
"{",
"throw",
"new",
"MissingParametersException",
"(",
"$",
"missing",
")",
";",
"}",
"}"
] | Check if required parameters are set
@param array|object $parameters Request's parameters
@param string|array $required The required parameters
@throws \Phramework\Exceptions\MissingParametersException | [
"Check",
"if",
"required",
"parameters",
"are",
"set"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Request.php#L71-L93 | train |
phramework/phramework | src/Models/Request.php | Request.resourceId | public static function resourceId($parameters, $UINTEGER = true)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
//Check if is set AND validate
if (isset($parameters['resource_id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['resource_id']) !== false
) {
if ($UINTEGER) {
return UnsignedIntegerValidator::parseStatic($parameters['resource_id']);
}
return $parameters['resource_id'];
}
if (isset($parameters['id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['id']) !== false
) {
if ($UINTEGER) {
return UnsignedIntegerValidator::parseStatic($parameters['id']);
}
return $parameters['id'];
}
return false;
} | php | public static function resourceId($parameters, $UINTEGER = true)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
//Check if is set AND validate
if (isset($parameters['resource_id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['resource_id']) !== false
) {
if ($UINTEGER) {
return UnsignedIntegerValidator::parseStatic($parameters['resource_id']);
}
return $parameters['resource_id'];
}
if (isset($parameters['id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['id']) !== false
) {
if ($UINTEGER) {
return UnsignedIntegerValidator::parseStatic($parameters['id']);
}
return $parameters['id'];
}
return false;
} | [
"public",
"static",
"function",
"resourceId",
"(",
"$",
"parameters",
",",
"$",
"UINTEGER",
"=",
"true",
")",
"{",
"//Work with arrays",
"if",
"(",
"is_object",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parameters",
"=",
"(",
"array",
")",
"$",
"parameters",
";",
"}",
"//Check if is set AND validate",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'resource_id'",
"]",
")",
"&&",
"preg_match",
"(",
"Validate",
"::",
"REGEXP_RESOURCE_ID",
",",
"$",
"parameters",
"[",
"'resource_id'",
"]",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"UINTEGER",
")",
"{",
"return",
"UnsignedIntegerValidator",
"::",
"parseStatic",
"(",
"$",
"parameters",
"[",
"'resource_id'",
"]",
")",
";",
"}",
"return",
"$",
"parameters",
"[",
"'resource_id'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
"&&",
"preg_match",
"(",
"Validate",
"::",
"REGEXP_RESOURCE_ID",
",",
"$",
"parameters",
"[",
"'id'",
"]",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"UINTEGER",
")",
"{",
"return",
"UnsignedIntegerValidator",
"::",
"parseStatic",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
";",
"}",
"return",
"$",
"parameters",
"[",
"'id'",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Require id parameter if it's set else return NULL, it uses `resource_id` or `id` parameter if available
@param array|object $parameters The request parameters
@param boolean $UINTEGER *[Optional]*, Check id's type to be unsigned integer
@throws \Phramework\Exceptions\IncorrectParameters When value is not correct
@return string|integer Returns the id or NULL if not set,
if $UINTEGER the returned value will be converted to unsigned integer | [
"Require",
"id",
"parameter",
"if",
"it",
"s",
"set",
"else",
"return",
"NULL",
"it",
"uses",
"resource_id",
"or",
"id",
"parameter",
"if",
"available"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Request.php#L103-L129 | train |
phramework/phramework | src/Models/Request.php | Request.requireId | public static function requireId($parameters, $UINTEGER = true)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
if (isset($parameters['resource_id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['resource_id']) !== false
) {
$parameters['id'] = $parameters['resource_id'];
}
if (!isset($parameters['id'])) {
throw new MissingParametersException(['id']);
}
//Validate as unsigned integer
if ($UINTEGER
&& filter_var($parameters['id'], FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]) === false
) {
throw new IncorrectParametersException(['id']);
} elseif (!$UINTEGER
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['id']) === false
) {
//Validate as alphanumeric
throw new IncorrectParametersException(['id']);
}
return ($UINTEGER ? intval($parameters['id']) : $parameters['id']);
} | php | public static function requireId($parameters, $UINTEGER = true)
{
//Work with arrays
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
if (isset($parameters['resource_id'])
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['resource_id']) !== false
) {
$parameters['id'] = $parameters['resource_id'];
}
if (!isset($parameters['id'])) {
throw new MissingParametersException(['id']);
}
//Validate as unsigned integer
if ($UINTEGER
&& filter_var($parameters['id'], FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]) === false
) {
throw new IncorrectParametersException(['id']);
} elseif (!$UINTEGER
&& preg_match(Validate::REGEXP_RESOURCE_ID, $parameters['id']) === false
) {
//Validate as alphanumeric
throw new IncorrectParametersException(['id']);
}
return ($UINTEGER ? intval($parameters['id']) : $parameters['id']);
} | [
"public",
"static",
"function",
"requireId",
"(",
"$",
"parameters",
",",
"$",
"UINTEGER",
"=",
"true",
")",
"{",
"//Work with arrays",
"if",
"(",
"is_object",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parameters",
"=",
"(",
"array",
")",
"$",
"parameters",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"'resource_id'",
"]",
")",
"&&",
"preg_match",
"(",
"Validate",
"::",
"REGEXP_RESOURCE_ID",
",",
"$",
"parameters",
"[",
"'resource_id'",
"]",
")",
"!==",
"false",
")",
"{",
"$",
"parameters",
"[",
"'id'",
"]",
"=",
"$",
"parameters",
"[",
"'resource_id'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"MissingParametersException",
"(",
"[",
"'id'",
"]",
")",
";",
"}",
"//Validate as unsigned integer",
"if",
"(",
"$",
"UINTEGER",
"&&",
"filter_var",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
",",
"FILTER_VALIDATE_INT",
",",
"[",
"'options'",
"=>",
"[",
"'min_range'",
"=>",
"0",
"]",
"]",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"IncorrectParametersException",
"(",
"[",
"'id'",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"UINTEGER",
"&&",
"preg_match",
"(",
"Validate",
"::",
"REGEXP_RESOURCE_ID",
",",
"$",
"parameters",
"[",
"'id'",
"]",
")",
"===",
"false",
")",
"{",
"//Validate as alphanumeric",
"throw",
"new",
"IncorrectParametersException",
"(",
"[",
"'id'",
"]",
")",
";",
"}",
"return",
"(",
"$",
"UINTEGER",
"?",
"intval",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
":",
"$",
"parameters",
"[",
"'id'",
"]",
")",
";",
"}"
] | Require id parameter, it uses `resource_id` or `id` parameter if available
@param array|object $parameters The request paramters
@param boolean $UINTEGER *[Optional]*, Check id's type to be unsigned integer, default is true
@throws \Phramework\Exceptions\IncorrectParameters When value is not correct
@throws \Phramework\Exceptions\MissingParametersException When id is missing
if $UINTEGER the returned value will be converted to unsigned integer | [
"Require",
"id",
"parameter",
"it",
"uses",
"resource_id",
"or",
"id",
"parameter",
"if",
"available"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Request.php#L139-L167 | train |
phramework/phramework | src/Models/Request.php | Request.parseModel | public static function parseModel($parameters, $model)
{
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
$required_fields = [];
foreach ($model as $key => $value) {
if (in_array('required', $value, true) === true
|| in_array('required', $value, true) == true) {
$required_fields[] = $key;
}
}
Request::requireParameters($parameters, $required_fields);
\Phramework\Validate\Validate::model($parameters, $model);
$keys_values = [];
foreach ($model as $key => $value) {
if (isset($parameters[$key])) {
if (in_array('nullable', $value) && $parameters[$key] == '0') {
$keys_values[$key] = null;
continue;
}
//Set value as null
if (in_array('nullable', $value) && !$parameters[$key]) {
$keys_values[$key] = null;
continue;
}
/*
if ($value['type'] == 'select' && !$parameters[$key]) {
$keys_values[$key] = NULL;
} else {*/
$keys_values[$key] = $parameters[$key];
/*}*/
} elseif (($value['type'] == 'boolean' || in_array('boolean', $value))
&& (!isset($parameters[$key]) || !$parameters[$key])) {
$keys_values[$key] = false;
}
}
return $keys_values;
} | php | public static function parseModel($parameters, $model)
{
if (is_object($parameters)) {
$parameters = (array)$parameters;
}
$required_fields = [];
foreach ($model as $key => $value) {
if (in_array('required', $value, true) === true
|| in_array('required', $value, true) == true) {
$required_fields[] = $key;
}
}
Request::requireParameters($parameters, $required_fields);
\Phramework\Validate\Validate::model($parameters, $model);
$keys_values = [];
foreach ($model as $key => $value) {
if (isset($parameters[$key])) {
if (in_array('nullable', $value) && $parameters[$key] == '0') {
$keys_values[$key] = null;
continue;
}
//Set value as null
if (in_array('nullable', $value) && !$parameters[$key]) {
$keys_values[$key] = null;
continue;
}
/*
if ($value['type'] == 'select' && !$parameters[$key]) {
$keys_values[$key] = NULL;
} else {*/
$keys_values[$key] = $parameters[$key];
/*}*/
} elseif (($value['type'] == 'boolean' || in_array('boolean', $value))
&& (!isset($parameters[$key]) || !$parameters[$key])) {
$keys_values[$key] = false;
}
}
return $keys_values;
} | [
"public",
"static",
"function",
"parseModel",
"(",
"$",
"parameters",
",",
"$",
"model",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parameters",
"=",
"(",
"array",
")",
"$",
"parameters",
";",
"}",
"$",
"required_fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"model",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"'required'",
",",
"$",
"value",
",",
"true",
")",
"===",
"true",
"||",
"in_array",
"(",
"'required'",
",",
"$",
"value",
",",
"true",
")",
"==",
"true",
")",
"{",
"$",
"required_fields",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"Request",
"::",
"requireParameters",
"(",
"$",
"parameters",
",",
"$",
"required_fields",
")",
";",
"\\",
"Phramework",
"\\",
"Validate",
"\\",
"Validate",
"::",
"model",
"(",
"$",
"parameters",
",",
"$",
"model",
")",
";",
"$",
"keys_values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"model",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"'nullable'",
",",
"$",
"value",
")",
"&&",
"$",
"parameters",
"[",
"$",
"key",
"]",
"==",
"'0'",
")",
"{",
"$",
"keys_values",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"continue",
";",
"}",
"//Set value as null",
"if",
"(",
"in_array",
"(",
"'nullable'",
",",
"$",
"value",
")",
"&&",
"!",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"keys_values",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"continue",
";",
"}",
"/*\n if ($value['type'] == 'select' && !$parameters[$key]) {\n $keys_values[$key] = NULL;\n } else {*/",
"$",
"keys_values",
"[",
"$",
"key",
"]",
"=",
"$",
"parameters",
"[",
"$",
"key",
"]",
";",
"/*}*/",
"}",
"elseif",
"(",
"(",
"$",
"value",
"[",
"'type'",
"]",
"==",
"'boolean'",
"||",
"in_array",
"(",
"'boolean'",
",",
"$",
"value",
")",
")",
"&&",
"(",
"!",
"isset",
"(",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"keys_values",
"[",
"$",
"key",
"]",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"keys_values",
";",
"}"
] | Required required values and parse provided parameters into an array
Validate the provided request model and return the
@uses \Phramework\Models\Request::requireParameters
@param array|object $parameters
@param array $model
@return array Return the keys => values collection
@deprecated since 1.0.0 | [
"Required",
"required",
"values",
"and",
"parse",
"provided",
"parameters",
"into",
"an",
"array",
"Validate",
"the",
"provided",
"request",
"model",
"and",
"return",
"the"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Request.php#L178-L220 | train |
keeko/framework | src/utils/NameUtils.php | NameUtils.toStudlyCase | public static function toStudlyCase($input) {
$input = trim($input, '-_');
return ucfirst(preg_replace_callback('/([A-Z-_][a-z]+)/', function($matches) {
return ucfirst(str_replace(['-','_'], '',$matches[0]));
}, $input));
} | php | public static function toStudlyCase($input) {
$input = trim($input, '-_');
return ucfirst(preg_replace_callback('/([A-Z-_][a-z]+)/', function($matches) {
return ucfirst(str_replace(['-','_'], '',$matches[0]));
}, $input));
} | [
"public",
"static",
"function",
"toStudlyCase",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"trim",
"(",
"$",
"input",
",",
"'-_'",
")",
";",
"return",
"ucfirst",
"(",
"preg_replace_callback",
"(",
"'/([A-Z-_][a-z]+)/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"ucfirst",
"(",
"str_replace",
"(",
"[",
"'-'",
",",
"'_'",
"]",
",",
"''",
",",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"}",
",",
"$",
"input",
")",
")",
";",
"}"
] | Transforms a given input into StudlyCase
@param string $input
@return string | [
"Transforms",
"a",
"given",
"input",
"into",
"StudlyCase"
] | a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac | https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/utils/NameUtils.php#L14-L19 | train |
keeko/framework | src/utils/NameUtils.php | NameUtils.pluralize | public static function pluralize($input) {
if (self::$pluralizer === null) {
self::$pluralizer = new StandardEnglishSingularizer();
}
return self::$pluralizer->getPluralForm($input);
} | php | public static function pluralize($input) {
if (self::$pluralizer === null) {
self::$pluralizer = new StandardEnglishSingularizer();
}
return self::$pluralizer->getPluralForm($input);
} | [
"public",
"static",
"function",
"pluralize",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"pluralizer",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"pluralizer",
"=",
"new",
"StandardEnglishSingularizer",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"pluralizer",
"->",
"getPluralForm",
"(",
"$",
"input",
")",
";",
"}"
] | Returns the plural form of the input
@param string $input
@return string | [
"Returns",
"the",
"plural",
"form",
"of",
"the",
"input"
] | a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac | https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/utils/NameUtils.php#L67-L73 | train |
keeko/framework | src/utils/NameUtils.php | NameUtils.singularize | public static function singularize($input) {
if (self::$pluralizer === null) {
self::$pluralizer = new StandardEnglishSingularizer();
}
return self::$pluralizer->getSingularForm($input);
} | php | public static function singularize($input) {
if (self::$pluralizer === null) {
self::$pluralizer = new StandardEnglishSingularizer();
}
return self::$pluralizer->getSingularForm($input);
} | [
"public",
"static",
"function",
"singularize",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"pluralizer",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"pluralizer",
"=",
"new",
"StandardEnglishSingularizer",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"pluralizer",
"->",
"getSingularForm",
"(",
"$",
"input",
")",
";",
"}"
] | Returns the singular form of the input
@param string $input
@return string | [
"Returns",
"the",
"singular",
"form",
"of",
"the",
"input"
] | a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac | https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/utils/NameUtils.php#L81-L87 | train |
znframework/package-pagination | Paginator.php | Paginator.linkNames | public function linkNames(String $prev, String $next, String $first, String $last) : Paginator
{
$this->settings['prevName'] = $prev;
$this->settings['nextName'] = $next;
$this->settings['firstName'] = $first;
$this->settings['lastName'] = $last;
return $this;
} | php | public function linkNames(String $prev, String $next, String $first, String $last) : Paginator
{
$this->settings['prevName'] = $prev;
$this->settings['nextName'] = $next;
$this->settings['firstName'] = $first;
$this->settings['lastName'] = $last;
return $this;
} | [
"public",
"function",
"linkNames",
"(",
"String",
"$",
"prev",
",",
"String",
"$",
"next",
",",
"String",
"$",
"first",
",",
"String",
"$",
"last",
")",
":",
"Paginator",
"{",
"$",
"this",
"->",
"settings",
"[",
"'prevName'",
"]",
"=",
"$",
"prev",
";",
"$",
"this",
"->",
"settings",
"[",
"'nextName'",
"]",
"=",
"$",
"next",
";",
"$",
"this",
"->",
"settings",
"[",
"'firstName'",
"]",
"=",
"$",
"first",
";",
"$",
"this",
"->",
"settings",
"[",
"'lastName'",
"]",
"=",
"$",
"last",
";",
"return",
"$",
"this",
";",
"}"
] | Change the names of links.
@param string $prev
@param string $next
@param string $first
@param string $last
@return Paginator | [
"Change",
"the",
"names",
"of",
"links",
"."
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L237-L245 | train |
znframework/package-pagination | Paginator.php | Paginator.settings | public function settings(Array $config = []) : Paginator
{
foreach( $config as $key => $value )
{
$this->$key = $value;
}
$this->class = array_merge($this->config['class'], $this->class ?? []);
$this->style = array_merge($this->config['style'], $this->style ?? []);
if( isset($config['url']) && $this->type !== 'ajax' )
{
$this->url = Base::suffix(URL::site($config['url']));
}
elseif( $this->type === 'ajax' )
{
$this->url = 'javascript:;';
}
else
{
$this->url = CURRENT_CFURL;
}
return $this;
} | php | public function settings(Array $config = []) : Paginator
{
foreach( $config as $key => $value )
{
$this->$key = $value;
}
$this->class = array_merge($this->config['class'], $this->class ?? []);
$this->style = array_merge($this->config['style'], $this->style ?? []);
if( isset($config['url']) && $this->type !== 'ajax' )
{
$this->url = Base::suffix(URL::site($config['url']));
}
elseif( $this->type === 'ajax' )
{
$this->url = 'javascript:;';
}
else
{
$this->url = CURRENT_CFURL;
}
return $this;
} | [
"public",
"function",
"settings",
"(",
"Array",
"$",
"config",
"=",
"[",
"]",
")",
":",
"Paginator",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"class",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
"[",
"'class'",
"]",
",",
"$",
"this",
"->",
"class",
"??",
"[",
"]",
")",
";",
"$",
"this",
"->",
"style",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
"[",
"'style'",
"]",
",",
"$",
"this",
"->",
"style",
"??",
"[",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'url'",
"]",
")",
"&&",
"$",
"this",
"->",
"type",
"!==",
"'ajax'",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"Base",
"::",
"suffix",
"(",
"URL",
"::",
"site",
"(",
"$",
"config",
"[",
"'url'",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"type",
"===",
"'ajax'",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"'javascript:;'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"url",
"=",
"CURRENT_CFURL",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Configures all settings of the page.
@param array $cofig = []
@return Paginator | [
"Configures",
"all",
"settings",
"of",
"the",
"page",
"."
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L308-L332 | train |
znframework/package-pagination | Paginator.php | Paginator.create | public function create($start = NULL, Array $settings = []) : String
{
# The configuration arrays are merge.
$settings = array_merge($this->config, $this->settings, $settings);
# If the configuration is present, it is rearranged.
if( ! empty($settings) )
{
$this->settings($settings);
}
# Gets information about which recording to start the paging process.
$startRowNumber = $this->getStartRowNumber($start);
# If the limit is set to 0, 1 is accepted.
$this->limit = $this->limit === 0 ? 1 : $this->limit;
# Generate pagination bar.
if( $this->isPaginationBar() )
{
return $this->isBasicPaginationBar() ? $this->createBasicPaginationBar($startRowNumber) : $this->createAdvancedPaginationBar($startRowNumber);
}
return false;
} | php | public function create($start = NULL, Array $settings = []) : String
{
# The configuration arrays are merge.
$settings = array_merge($this->config, $this->settings, $settings);
# If the configuration is present, it is rearranged.
if( ! empty($settings) )
{
$this->settings($settings);
}
# Gets information about which recording to start the paging process.
$startRowNumber = $this->getStartRowNumber($start);
# If the limit is set to 0, 1 is accepted.
$this->limit = $this->limit === 0 ? 1 : $this->limit;
# Generate pagination bar.
if( $this->isPaginationBar() )
{
return $this->isBasicPaginationBar() ? $this->createBasicPaginationBar($startRowNumber) : $this->createAdvancedPaginationBar($startRowNumber);
}
return false;
} | [
"public",
"function",
"create",
"(",
"$",
"start",
"=",
"NULL",
",",
"Array",
"$",
"settings",
"=",
"[",
"]",
")",
":",
"String",
"{",
"# The configuration arrays are merge.",
"$",
"settings",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"settings",
",",
"$",
"settings",
")",
";",
"# If the configuration is present, it is rearranged.",
"if",
"(",
"!",
"empty",
"(",
"$",
"settings",
")",
")",
"{",
"$",
"this",
"->",
"settings",
"(",
"$",
"settings",
")",
";",
"}",
"# Gets information about which recording to start the paging process.",
"$",
"startRowNumber",
"=",
"$",
"this",
"->",
"getStartRowNumber",
"(",
"$",
"start",
")",
";",
"# If the limit is set to 0, 1 is accepted.",
"$",
"this",
"->",
"limit",
"=",
"$",
"this",
"->",
"limit",
"===",
"0",
"?",
"1",
":",
"$",
"this",
"->",
"limit",
";",
"# Generate pagination bar.",
"if",
"(",
"$",
"this",
"->",
"isPaginationBar",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"isBasicPaginationBar",
"(",
")",
"?",
"$",
"this",
"->",
"createBasicPaginationBar",
"(",
"$",
"startRowNumber",
")",
":",
"$",
"this",
"->",
"createAdvancedPaginationBar",
"(",
"$",
"startRowNumber",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Creates the pagination.
@param mixed $start
@param array $settings = []
@return string | [
"Creates",
"the",
"pagination",
"."
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L342-L366 | train |
znframework/package-pagination | Paginator.php | Paginator.createBasicPaginationBar | protected function createBasicPaginationBar($startRowNumber)
{
# Add prev link.
if( $this->isPrevLink($startRowNumber) )
{
$this->addPrevLink($startRowNumber, $prevLink);
}
# Remove prev link.
else
{
$this->removeLinkFromPagingationBar($prevLink);
}
# Add next link.
if( $this->isNextLink($this->getPerPage(), $startRowNumber) )
{
$this->addNextLink($startRowNumber, $nextLink);
}
# Remove next link.
else
{
$this->removeLinkFromPagingationBar($nextLink);
}
# Generate pagination bar.
return $this->generatePaginationBar($prevLink, $this->getNumberLinks($this->getPerPage(), $startRowNumber), $nextLink);
} | php | protected function createBasicPaginationBar($startRowNumber)
{
# Add prev link.
if( $this->isPrevLink($startRowNumber) )
{
$this->addPrevLink($startRowNumber, $prevLink);
}
# Remove prev link.
else
{
$this->removeLinkFromPagingationBar($prevLink);
}
# Add next link.
if( $this->isNextLink($this->getPerPage(), $startRowNumber) )
{
$this->addNextLink($startRowNumber, $nextLink);
}
# Remove next link.
else
{
$this->removeLinkFromPagingationBar($nextLink);
}
# Generate pagination bar.
return $this->generatePaginationBar($prevLink, $this->getNumberLinks($this->getPerPage(), $startRowNumber), $nextLink);
} | [
"protected",
"function",
"createBasicPaginationBar",
"(",
"$",
"startRowNumber",
")",
"{",
"# Add prev link.",
"if",
"(",
"$",
"this",
"->",
"isPrevLink",
"(",
"$",
"startRowNumber",
")",
")",
"{",
"$",
"this",
"->",
"addPrevLink",
"(",
"$",
"startRowNumber",
",",
"$",
"prevLink",
")",
";",
"}",
"# Remove prev link.",
"else",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"prevLink",
")",
";",
"}",
"# Add next link.",
"if",
"(",
"$",
"this",
"->",
"isNextLink",
"(",
"$",
"this",
"->",
"getPerPage",
"(",
")",
",",
"$",
"startRowNumber",
")",
")",
"{",
"$",
"this",
"->",
"addNextLink",
"(",
"$",
"startRowNumber",
",",
"$",
"nextLink",
")",
";",
"}",
"# Remove next link.",
"else",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"nextLink",
")",
";",
"}",
"# Generate pagination bar.",
"return",
"$",
"this",
"->",
"generatePaginationBar",
"(",
"$",
"prevLink",
",",
"$",
"this",
"->",
"getNumberLinks",
"(",
"$",
"this",
"->",
"getPerPage",
"(",
")",
",",
"$",
"startRowNumber",
")",
",",
"$",
"nextLink",
")",
";",
"}"
] | Protected create basic pagination bar | [
"Protected",
"create",
"basic",
"pagination",
"bar"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L371-L397 | train |
znframework/package-pagination | Paginator.php | Paginator.createAdvancedPaginationBar | protected function createAdvancedPaginationBar($startRowNumber)
{
# Add prev link.
if( $this->isAdvancedPrevLink($startRowNumber) )
{
$this->addPrevLink($startRowNumber, $prevLink);
}
# Remove prev link.
else
{
$this->removeLinkFromPagingationBar($prevLink);
}
# Add first, next, last links.
if( $this->isAdvancedNextLink($startRowNumber) )
{
$this->addNextLink($startRowNumber, $nextLink);
$this->addLastLink($lastLink);
$pageIndex = $this->getPageIndex($startRowNumber);
}
# Remove next, last links.
else
{
$this->removeLinkFromPagingationBar($nextLink);
$this->removeLinkFromPagingationBar($lastLink);
$pageIndex = $this->getPageIndexWithoutNextLinks();
}
# On the first page, remove the first link.
if( $this->isFirstLink($startRowNumber, $pageIndex) )
{
$this->removeLinkFromPagingationBar($firstLink);
}
else
{
$this->addFirstLink($firstLink);
}
$advancedPerPage = $this->getAdvancedPerPage($pageIndex, $nextLink, $lastLink);
return $this->generatePaginationBar($firstLink, $prevLink, $this->getNumberLinks($advancedPerPage, $startRowNumber, $pageIndex), $nextLink, $lastLink);
} | php | protected function createAdvancedPaginationBar($startRowNumber)
{
# Add prev link.
if( $this->isAdvancedPrevLink($startRowNumber) )
{
$this->addPrevLink($startRowNumber, $prevLink);
}
# Remove prev link.
else
{
$this->removeLinkFromPagingationBar($prevLink);
}
# Add first, next, last links.
if( $this->isAdvancedNextLink($startRowNumber) )
{
$this->addNextLink($startRowNumber, $nextLink);
$this->addLastLink($lastLink);
$pageIndex = $this->getPageIndex($startRowNumber);
}
# Remove next, last links.
else
{
$this->removeLinkFromPagingationBar($nextLink);
$this->removeLinkFromPagingationBar($lastLink);
$pageIndex = $this->getPageIndexWithoutNextLinks();
}
# On the first page, remove the first link.
if( $this->isFirstLink($startRowNumber, $pageIndex) )
{
$this->removeLinkFromPagingationBar($firstLink);
}
else
{
$this->addFirstLink($firstLink);
}
$advancedPerPage = $this->getAdvancedPerPage($pageIndex, $nextLink, $lastLink);
return $this->generatePaginationBar($firstLink, $prevLink, $this->getNumberLinks($advancedPerPage, $startRowNumber, $pageIndex), $nextLink, $lastLink);
} | [
"protected",
"function",
"createAdvancedPaginationBar",
"(",
"$",
"startRowNumber",
")",
"{",
"# Add prev link.",
"if",
"(",
"$",
"this",
"->",
"isAdvancedPrevLink",
"(",
"$",
"startRowNumber",
")",
")",
"{",
"$",
"this",
"->",
"addPrevLink",
"(",
"$",
"startRowNumber",
",",
"$",
"prevLink",
")",
";",
"}",
"# Remove prev link.",
"else",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"prevLink",
")",
";",
"}",
"# Add first, next, last links.",
"if",
"(",
"$",
"this",
"->",
"isAdvancedNextLink",
"(",
"$",
"startRowNumber",
")",
")",
"{",
"$",
"this",
"->",
"addNextLink",
"(",
"$",
"startRowNumber",
",",
"$",
"nextLink",
")",
";",
"$",
"this",
"->",
"addLastLink",
"(",
"$",
"lastLink",
")",
";",
"$",
"pageIndex",
"=",
"$",
"this",
"->",
"getPageIndex",
"(",
"$",
"startRowNumber",
")",
";",
"}",
"# Remove next, last links.",
"else",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"nextLink",
")",
";",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"lastLink",
")",
";",
"$",
"pageIndex",
"=",
"$",
"this",
"->",
"getPageIndexWithoutNextLinks",
"(",
")",
";",
"}",
"# On the first page, remove the first link.",
"if",
"(",
"$",
"this",
"->",
"isFirstLink",
"(",
"$",
"startRowNumber",
",",
"$",
"pageIndex",
")",
")",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"firstLink",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addFirstLink",
"(",
"$",
"firstLink",
")",
";",
"}",
"$",
"advancedPerPage",
"=",
"$",
"this",
"->",
"getAdvancedPerPage",
"(",
"$",
"pageIndex",
",",
"$",
"nextLink",
",",
"$",
"lastLink",
")",
";",
"return",
"$",
"this",
"->",
"generatePaginationBar",
"(",
"$",
"firstLink",
",",
"$",
"prevLink",
",",
"$",
"this",
"->",
"getNumberLinks",
"(",
"$",
"advancedPerPage",
",",
"$",
"startRowNumber",
",",
"$",
"pageIndex",
")",
",",
"$",
"nextLink",
",",
"$",
"lastLink",
")",
";",
"}"
] | Protected create advanced pagination bar | [
"Protected",
"create",
"advanced",
"pagination",
"bar"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L402-L445 | train |
znframework/package-pagination | Paginator.php | Paginator.addLastLink | protected function addLastLink(&$lastLink)
{
$lastLink = $this->getLink($this->calculatePageRowNumberForLastLink(), $this->getStyleClassAttributes('last'), $this->lastName);
} | php | protected function addLastLink(&$lastLink)
{
$lastLink = $this->getLink($this->calculatePageRowNumberForLastLink(), $this->getStyleClassAttributes('last'), $this->lastName);
} | [
"protected",
"function",
"addLastLink",
"(",
"&",
"$",
"lastLink",
")",
"{",
"$",
"lastLink",
"=",
"$",
"this",
"->",
"getLink",
"(",
"$",
"this",
"->",
"calculatePageRowNumberForLastLink",
"(",
")",
",",
"$",
"this",
"->",
"getStyleClassAttributes",
"(",
"'last'",
")",
",",
"$",
"this",
"->",
"lastName",
")",
";",
"}"
] | Protected get last link | [
"Protected",
"get",
"last",
"link"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L487-L490 | train |
znframework/package-pagination | Paginator.php | Paginator.addPrevLink | protected function addPrevLink($startRowNumber, &$prevLink)
{
$prevLink = $this->getLink($this->decrementPageRowNumber($startRowNumber), $this->getStyleClassAttributes('prev'), $this->prevName);
} | php | protected function addPrevLink($startRowNumber, &$prevLink)
{
$prevLink = $this->getLink($this->decrementPageRowNumber($startRowNumber), $this->getStyleClassAttributes('prev'), $this->prevName);
} | [
"protected",
"function",
"addPrevLink",
"(",
"$",
"startRowNumber",
",",
"&",
"$",
"prevLink",
")",
"{",
"$",
"prevLink",
"=",
"$",
"this",
"->",
"getLink",
"(",
"$",
"this",
"->",
"decrementPageRowNumber",
"(",
"$",
"startRowNumber",
")",
",",
"$",
"this",
"->",
"getStyleClassAttributes",
"(",
"'prev'",
")",
",",
"$",
"this",
"->",
"prevName",
")",
";",
"}"
] | Protected get prev link | [
"Protected",
"get",
"prev",
"link"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L495-L498 | train |
znframework/package-pagination | Paginator.php | Paginator.addNextLink | protected function addNextLink($startRowNumber, &$nextLink)
{
$nextLink = $this->getLink($this->incrementPageRowNumber($startRowNumber), $this->getStyleClassAttributes('next'), $this->nextName);
} | php | protected function addNextLink($startRowNumber, &$nextLink)
{
$nextLink = $this->getLink($this->incrementPageRowNumber($startRowNumber), $this->getStyleClassAttributes('next'), $this->nextName);
} | [
"protected",
"function",
"addNextLink",
"(",
"$",
"startRowNumber",
",",
"&",
"$",
"nextLink",
")",
"{",
"$",
"nextLink",
"=",
"$",
"this",
"->",
"getLink",
"(",
"$",
"this",
"->",
"incrementPageRowNumber",
"(",
"$",
"startRowNumber",
")",
",",
"$",
"this",
"->",
"getStyleClassAttributes",
"(",
"'next'",
")",
",",
"$",
"this",
"->",
"nextName",
")",
";",
"}"
] | Protected get advanced next link | [
"Protected",
"get",
"advanced",
"next",
"link"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L503-L506 | train |
znframework/package-pagination | Paginator.php | Paginator.getStartRowNumber | protected function getStartRowNumber($start)
{
if( $this->start !== NULL )
{
$start = (int) $this->start;
}
if( empty($start) && ! is_numeric($start) )
{
return ! is_numeric($segment = URI::segment(-1)) ? 0 : $segment;
}
return ! is_numeric($start) ? 0 : $start;
} | php | protected function getStartRowNumber($start)
{
if( $this->start !== NULL )
{
$start = (int) $this->start;
}
if( empty($start) && ! is_numeric($start) )
{
return ! is_numeric($segment = URI::segment(-1)) ? 0 : $segment;
}
return ! is_numeric($start) ? 0 : $start;
} | [
"protected",
"function",
"getStartRowNumber",
"(",
"$",
"start",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"start",
"!==",
"NULL",
")",
"{",
"$",
"start",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"start",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"start",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"start",
")",
")",
"{",
"return",
"!",
"is_numeric",
"(",
"$",
"segment",
"=",
"URI",
"::",
"segment",
"(",
"-",
"1",
")",
")",
"?",
"0",
":",
"$",
"segment",
";",
"}",
"return",
"!",
"is_numeric",
"(",
"$",
"start",
")",
"?",
"0",
":",
"$",
"start",
";",
"}"
] | Protected get start row number | [
"Protected",
"get",
"start",
"row",
"number"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L511-L524 | train |
znframework/package-pagination | Paginator.php | Paginator.getAdvancedPerPage | protected function getAdvancedPerPage($pageIndex, &$nextLink, &$lastLink)
{
$perPage = $this->countLinks + $pageIndex - 1;
if( $perPage >= ($getPerPage = $this->getPerPage()) )
{
$this->removeLinkFromPagingationBar($nextLink);
$this->removeLinkFromPagingationBar($lastLink);
$perPage = $getPerPage;
}
return $perPage;
} | php | protected function getAdvancedPerPage($pageIndex, &$nextLink, &$lastLink)
{
$perPage = $this->countLinks + $pageIndex - 1;
if( $perPage >= ($getPerPage = $this->getPerPage()) )
{
$this->removeLinkFromPagingationBar($nextLink);
$this->removeLinkFromPagingationBar($lastLink);
$perPage = $getPerPage;
}
return $perPage;
} | [
"protected",
"function",
"getAdvancedPerPage",
"(",
"$",
"pageIndex",
",",
"&",
"$",
"nextLink",
",",
"&",
"$",
"lastLink",
")",
"{",
"$",
"perPage",
"=",
"$",
"this",
"->",
"countLinks",
"+",
"$",
"pageIndex",
"-",
"1",
";",
"if",
"(",
"$",
"perPage",
">=",
"(",
"$",
"getPerPage",
"=",
"$",
"this",
"->",
"getPerPage",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"nextLink",
")",
";",
"$",
"this",
"->",
"removeLinkFromPagingationBar",
"(",
"$",
"lastLink",
")",
";",
"$",
"perPage",
"=",
"$",
"getPerPage",
";",
"}",
"return",
"$",
"perPage",
";",
"}"
] | Protected advanced per page. | [
"Protected",
"advanced",
"per",
"page",
"."
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L545-L558 | train |
znframework/package-pagination | Paginator.php | Paginator.getNumberLinks | protected function getNumberLinks($perPage, $startRowNumber, $startIndexNumber = 1)
{
$numberLinks = NULL;
for( $i = $startIndexNumber; $i <= $perPage; $i++ )
{
$page = ($i - 1) * $this->limit;
if( $i - 1 == floor((int) $startRowNumber / $this->limit) )
{
$currentLink = $this->getStyleClassAttributes('current');
}
else
{
$currentLink = $this->getStyleClassLinkAttributes('links');;
}
$numberLinks .= $this->getLink($page, $currentLink, $i);
}
return $numberLinks;
} | php | protected function getNumberLinks($perPage, $startRowNumber, $startIndexNumber = 1)
{
$numberLinks = NULL;
for( $i = $startIndexNumber; $i <= $perPage; $i++ )
{
$page = ($i - 1) * $this->limit;
if( $i - 1 == floor((int) $startRowNumber / $this->limit) )
{
$currentLink = $this->getStyleClassAttributes('current');
}
else
{
$currentLink = $this->getStyleClassLinkAttributes('links');;
}
$numberLinks .= $this->getLink($page, $currentLink, $i);
}
return $numberLinks;
} | [
"protected",
"function",
"getNumberLinks",
"(",
"$",
"perPage",
",",
"$",
"startRowNumber",
",",
"$",
"startIndexNumber",
"=",
"1",
")",
"{",
"$",
"numberLinks",
"=",
"NULL",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"startIndexNumber",
";",
"$",
"i",
"<=",
"$",
"perPage",
";",
"$",
"i",
"++",
")",
"{",
"$",
"page",
"=",
"(",
"$",
"i",
"-",
"1",
")",
"*",
"$",
"this",
"->",
"limit",
";",
"if",
"(",
"$",
"i",
"-",
"1",
"==",
"floor",
"(",
"(",
"int",
")",
"$",
"startRowNumber",
"/",
"$",
"this",
"->",
"limit",
")",
")",
"{",
"$",
"currentLink",
"=",
"$",
"this",
"->",
"getStyleClassAttributes",
"(",
"'current'",
")",
";",
"}",
"else",
"{",
"$",
"currentLink",
"=",
"$",
"this",
"->",
"getStyleClassLinkAttributes",
"(",
"'links'",
")",
";",
";",
"}",
"$",
"numberLinks",
".=",
"$",
"this",
"->",
"getLink",
"(",
"$",
"page",
",",
"$",
"currentLink",
",",
"$",
"i",
")",
";",
"}",
"return",
"$",
"numberLinks",
";",
"}"
] | Protected get number links | [
"Protected",
"get",
"number",
"links"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L611-L632 | train |
znframework/package-pagination | Paginator.php | Paginator.calculatePageRowNumberForLastLink | protected function calculatePageRowNumberForLastLink()
{
$mod = $this->totalRows % $this->limit;
return ($this->totalRows - $mod ) - ($mod == 0 ? $this->limit : 0);
} | php | protected function calculatePageRowNumberForLastLink()
{
$mod = $this->totalRows % $this->limit;
return ($this->totalRows - $mod ) - ($mod == 0 ? $this->limit : 0);
} | [
"protected",
"function",
"calculatePageRowNumberForLastLink",
"(",
")",
"{",
"$",
"mod",
"=",
"$",
"this",
"->",
"totalRows",
"%",
"$",
"this",
"->",
"limit",
";",
"return",
"(",
"$",
"this",
"->",
"totalRows",
"-",
"$",
"mod",
")",
"-",
"(",
"$",
"mod",
"==",
"0",
"?",
"$",
"this",
"->",
"limit",
":",
"0",
")",
";",
"}"
] | Protected page row number for last link | [
"Protected",
"page",
"row",
"number",
"for",
"last",
"link"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L653-L658 | train |
znframework/package-pagination | Paginator.php | Paginator.checkGetRequest | protected function checkGetRequest($page)
{
$this->url .= $this->explodeRequestGetValue();
if( strstr($this->url, '?') )
{
$urlEx = explode('?', $this->url);
return Base::suffix($urlEx[0]) . $page . '?' . rtrim($urlEx[1], '/');
}
return $this->type === 'ajax' ? $this->url : Base::suffix($this->url) . $page;
} | php | protected function checkGetRequest($page)
{
$this->url .= $this->explodeRequestGetValue();
if( strstr($this->url, '?') )
{
$urlEx = explode('?', $this->url);
return Base::suffix($urlEx[0]) . $page . '?' . rtrim($urlEx[1], '/');
}
return $this->type === 'ajax' ? $this->url : Base::suffix($this->url) . $page;
} | [
"protected",
"function",
"checkGetRequest",
"(",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"url",
".=",
"$",
"this",
"->",
"explodeRequestGetValue",
"(",
")",
";",
"if",
"(",
"strstr",
"(",
"$",
"this",
"->",
"url",
",",
"'?'",
")",
")",
"{",
"$",
"urlEx",
"=",
"explode",
"(",
"'?'",
",",
"$",
"this",
"->",
"url",
")",
";",
"return",
"Base",
"::",
"suffix",
"(",
"$",
"urlEx",
"[",
"0",
"]",
")",
".",
"$",
"page",
".",
"'?'",
".",
"rtrim",
"(",
"$",
"urlEx",
"[",
"1",
"]",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"type",
"===",
"'ajax'",
"?",
"$",
"this",
"->",
"url",
":",
"Base",
"::",
"suffix",
"(",
"$",
"this",
"->",
"url",
")",
".",
"$",
"page",
";",
"}"
] | Protected check get request | [
"Protected",
"check",
"get",
"request"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L697-L709 | train |
znframework/package-pagination | Paginator.php | Paginator.getLink | protected function getLink($var, $fix, $val)
{
return $this->getHtmlLiElement($this->getHtmlAnchorElement($var, $fix, $val), $fix);
} | php | protected function getLink($var, $fix, $val)
{
return $this->getHtmlLiElement($this->getHtmlAnchorElement($var, $fix, $val), $fix);
} | [
"protected",
"function",
"getLink",
"(",
"$",
"var",
",",
"$",
"fix",
",",
"$",
"val",
")",
"{",
"return",
"$",
"this",
"->",
"getHtmlLiElement",
"(",
"$",
"this",
"->",
"getHtmlAnchorElement",
"(",
"$",
"var",
",",
"$",
"fix",
",",
"$",
"val",
")",
",",
"$",
"fix",
")",
";",
"}"
] | Protected get link | [
"Protected",
"get",
"link"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L714-L717 | train |
znframework/package-pagination | Paginator.php | Paginator.getHtmlAnchorElement | protected function getHtmlAnchorElement($var, $attr, $val)
{
if( $this->output === 'bootstrap' )
{
$attr = NULL;
}
return '<a href="'.$this->checkGetRequest($var).'"'.$this->getAttributesForAjaxProcess($var).$attr.'>'.$val.'</a>';
} | php | protected function getHtmlAnchorElement($var, $attr, $val)
{
if( $this->output === 'bootstrap' )
{
$attr = NULL;
}
return '<a href="'.$this->checkGetRequest($var).'"'.$this->getAttributesForAjaxProcess($var).$attr.'>'.$val.'</a>';
} | [
"protected",
"function",
"getHtmlAnchorElement",
"(",
"$",
"var",
",",
"$",
"attr",
",",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"output",
"===",
"'bootstrap'",
")",
"{",
"$",
"attr",
"=",
"NULL",
";",
"}",
"return",
"'<a href=\"'",
".",
"$",
"this",
"->",
"checkGetRequest",
"(",
"$",
"var",
")",
".",
"'\"'",
".",
"$",
"this",
"->",
"getAttributesForAjaxProcess",
"(",
"$",
"var",
")",
".",
"$",
"attr",
".",
"'>'",
".",
"$",
"val",
".",
"'</a>'",
";",
"}"
] | Protected get html anchor element | [
"Protected",
"get",
"html",
"anchor",
"element"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L722-L730 | train |
znframework/package-pagination | Paginator.php | Paginator.generatePaginationBar | protected function generatePaginationBar(...$numberLinks)
{
$links = $this->implodeLinks(...$numberLinks);
if( $this->output === 'bootstrap' )
{
return '<ul class="pagination">' . $links . '</ul>';
}
return $links;
} | php | protected function generatePaginationBar(...$numberLinks)
{
$links = $this->implodeLinks(...$numberLinks);
if( $this->output === 'bootstrap' )
{
return '<ul class="pagination">' . $links . '</ul>';
}
return $links;
} | [
"protected",
"function",
"generatePaginationBar",
"(",
"...",
"$",
"numberLinks",
")",
"{",
"$",
"links",
"=",
"$",
"this",
"->",
"implodeLinks",
"(",
"...",
"$",
"numberLinks",
")",
";",
"if",
"(",
"$",
"this",
"->",
"output",
"===",
"'bootstrap'",
")",
"{",
"return",
"'<ul class=\"pagination\">'",
".",
"$",
"links",
".",
"'</ul>'",
";",
"}",
"return",
"$",
"links",
";",
"}"
] | Protected get html ul element | [
"Protected",
"get",
"html",
"ul",
"element"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L748-L758 | train |
znframework/package-pagination | Paginator.php | Paginator.getStyleLinkAttribute | protected function getStyleLinkAttribute($var, $type = 'style')
{
$getAttribute = ( ! empty($this->{$type}[$var]) ) ? $this->{$type}[$var] . ' ' : '';
if( $type === 'class' )
{
$this->classAttribute = $getAttribute;
}
else
{
$this->styleAttribute = $getAttribute;
}
return $this->createAttribute($getAttribute, $type);
} | php | protected function getStyleLinkAttribute($var, $type = 'style')
{
$getAttribute = ( ! empty($this->{$type}[$var]) ) ? $this->{$type}[$var] . ' ' : '';
if( $type === 'class' )
{
$this->classAttribute = $getAttribute;
}
else
{
$this->styleAttribute = $getAttribute;
}
return $this->createAttribute($getAttribute, $type);
} | [
"protected",
"function",
"getStyleLinkAttribute",
"(",
"$",
"var",
",",
"$",
"type",
"=",
"'style'",
")",
"{",
"$",
"getAttribute",
"=",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"{",
"$",
"type",
"}",
"[",
"$",
"var",
"]",
")",
")",
"?",
"$",
"this",
"->",
"{",
"$",
"type",
"}",
"[",
"$",
"var",
"]",
".",
"' '",
":",
"''",
";",
"if",
"(",
"$",
"type",
"===",
"'class'",
")",
"{",
"$",
"this",
"->",
"classAttribute",
"=",
"$",
"getAttribute",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"styleAttribute",
"=",
"$",
"getAttribute",
";",
"}",
"return",
"$",
"this",
"->",
"createAttribute",
"(",
"$",
"getAttribute",
",",
"$",
"type",
")",
";",
"}"
] | Protected get style link attribute | [
"Protected",
"get",
"style",
"link",
"attribute"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L763-L777 | train |
znframework/package-pagination | Paginator.php | Paginator.getClassAttribute | protected function getClassAttribute($var, $type = 'class')
{
$status = trim(( $type === 'class' ? $this->classAttribute : $this->styleAttribute) . $this->{$type}[$var]);
return $this->createAttribute($status, $type);
} | php | protected function getClassAttribute($var, $type = 'class')
{
$status = trim(( $type === 'class' ? $this->classAttribute : $this->styleAttribute) . $this->{$type}[$var]);
return $this->createAttribute($status, $type);
} | [
"protected",
"function",
"getClassAttribute",
"(",
"$",
"var",
",",
"$",
"type",
"=",
"'class'",
")",
"{",
"$",
"status",
"=",
"trim",
"(",
"(",
"$",
"type",
"===",
"'class'",
"?",
"$",
"this",
"->",
"classAttribute",
":",
"$",
"this",
"->",
"styleAttribute",
")",
".",
"$",
"this",
"->",
"{",
"$",
"type",
"}",
"[",
"$",
"var",
"]",
")",
";",
"return",
"$",
"this",
"->",
"createAttribute",
"(",
"$",
"status",
",",
"$",
"type",
")",
";",
"}"
] | Protected get class attribute | [
"Protected",
"get",
"class",
"attribute"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L790-L795 | train |
znframework/package-pagination | Paginator.php | Paginator.createAttribute | protected function createAttribute($condition, $key, $value = NULL)
{
return ! empty($condition) ? ' ' . $key . '="' . trim($value ?? $condition) . '"' : '';
} | php | protected function createAttribute($condition, $key, $value = NULL)
{
return ! empty($condition) ? ' ' . $key . '="' . trim($value ?? $condition) . '"' : '';
} | [
"protected",
"function",
"createAttribute",
"(",
"$",
"condition",
",",
"$",
"key",
",",
"$",
"value",
"=",
"NULL",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"condition",
")",
"?",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"trim",
"(",
"$",
"value",
"??",
"$",
"condition",
")",
".",
"'\"'",
":",
"''",
";",
"}"
] | Protcted create attribute | [
"Protcted",
"create",
"attribute"
] | 43549d3c7d1783d0d92195384f0cc2b0f73c1693 | https://github.com/znframework/package-pagination/blob/43549d3c7d1783d0d92195384f0cc2b0f73c1693/Paginator.php#L800-L803 | train |
phavour/phavour | Phavour/Runnable.php | Runnable.finalise | final public function finalise()
{
if ($this->view->isEnabled()) {
$this->view->setResponse($this->response);
$this->view->render();
}
return true;
} | php | final public function finalise()
{
if ($this->view->isEnabled()) {
$this->view->setResponse($this->response);
$this->view->render();
}
return true;
} | [
"final",
"public",
"function",
"finalise",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"view",
"->",
"isEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"view",
"->",
"setResponse",
"(",
"$",
"this",
"->",
"response",
")",
";",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Called at the end of the process.
@return boolean | [
"Called",
"at",
"the",
"end",
"of",
"the",
"process",
"."
] | 2246f78203312eb2e23fdb0f776f790e81b4d20f | https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Runnable.php#L199-L206 | train |
phavour/phavour | Phavour/Runnable.php | Runnable.urlFor | final public function urlFor($routeName, array $params = array())
{
if (null === $this->router) {
return '';
}
return $this->router->urlFor($routeName, $params);
} | php | final public function urlFor($routeName, array $params = array())
{
if (null === $this->router) {
return '';
}
return $this->router->urlFor($routeName, $params);
} | [
"final",
"public",
"function",
"urlFor",
"(",
"$",
"routeName",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"router",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"router",
"->",
"urlFor",
"(",
"$",
"routeName",
",",
"$",
"params",
")",
";",
"}"
] | Get a route path by a given name
@param string $routeName
@param array $params (optional)
@return string | [
"Get",
"a",
"route",
"path",
"by",
"a",
"given",
"name"
] | 2246f78203312eb2e23fdb0f776f790e81b4d20f | https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Runnable.php#L214-L221 | train |
phavour/phavour | Phavour/Runnable.php | Runnable.notFound | public function notFound($package = 'DefaultPackage', $class = 'Error', $method = 'notFound')
{
$this->response->setStatus(404);
$this->view->setPackage($package);
$this->view->setClass($class);
$this->view->setScriptName($method);
return;
} | php | public function notFound($package = 'DefaultPackage', $class = 'Error', $method = 'notFound')
{
$this->response->setStatus(404);
$this->view->setPackage($package);
$this->view->setClass($class);
$this->view->setScriptName($method);
return;
} | [
"public",
"function",
"notFound",
"(",
"$",
"package",
"=",
"'DefaultPackage'",
",",
"$",
"class",
"=",
"'Error'",
",",
"$",
"method",
"=",
"'notFound'",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"404",
")",
";",
"$",
"this",
"->",
"view",
"->",
"setPackage",
"(",
"$",
"package",
")",
";",
"$",
"this",
"->",
"view",
"->",
"setClass",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"view",
"->",
"setScriptName",
"(",
"$",
"method",
")",
";",
"return",
";",
"}"
] | When you need to send a not found in your runnable, you
can call this directly.
Optionally, you can specify the package name, class name,
and method name to render accordingly.
@param sring $package (optional) default 'DefaultPackage'
@param sring $class (optional) default 'Error'
@param sring $method (optional) default 'notFound'
@return void | [
"When",
"you",
"need",
"to",
"send",
"a",
"not",
"found",
"in",
"your",
"runnable",
"you",
"can",
"call",
"this",
"directly",
".",
"Optionally",
"you",
"can",
"specify",
"the",
"package",
"name",
"class",
"name",
"and",
"method",
"name",
"to",
"render",
"accordingly",
"."
] | 2246f78203312eb2e23fdb0f776f790e81b4d20f | https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Runnable.php#L233-L240 | train |
Boolive/Core | data/Entity.php | Entity.parent | function parent($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_parent = $new;
$new = $new->uri();
}else{
$this->_parent = null; // for reloading
}
if ($new != $this->_attributes['parent']){
$this->change('parent', $new);
$this->change('order', Entity::MAX_ORDER);
$this->change('uri', $new.'/'.$this->_attributes['name']);
}
}
if ($return_entity){
if (!isset($this->_parent)){
if (isset($this->_attributes['parent'])){
$this->_parent = Data::read($this->_attributes['parent']);
}else{
$this->_parent = false;
}
}
return $this->_parent;
}
return $this->_attributes['parent'];
} | php | function parent($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_parent = $new;
$new = $new->uri();
}else{
$this->_parent = null; // for reloading
}
if ($new != $this->_attributes['parent']){
$this->change('parent', $new);
$this->change('order', Entity::MAX_ORDER);
$this->change('uri', $new.'/'.$this->_attributes['name']);
}
}
if ($return_entity){
if (!isset($this->_parent)){
if (isset($this->_attributes['parent'])){
$this->_parent = Data::read($this->_attributes['parent']);
}else{
$this->_parent = false;
}
}
return $this->_parent;
}
return $this->_attributes['parent'];
} | [
"function",
"parent",
"(",
"$",
"new",
"=",
"null",
",",
"$",
"return_entity",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
")",
"{",
"if",
"(",
"$",
"new",
"instanceof",
"Entity",
")",
"{",
"$",
"this",
"->",
"_parent",
"=",
"$",
"new",
";",
"$",
"new",
"=",
"$",
"new",
"->",
"uri",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_parent",
"=",
"null",
";",
"// for reloading",
"}",
"if",
"(",
"$",
"new",
"!=",
"$",
"this",
"->",
"_attributes",
"[",
"'parent'",
"]",
")",
"{",
"$",
"this",
"->",
"change",
"(",
"'parent'",
",",
"$",
"new",
")",
";",
"$",
"this",
"->",
"change",
"(",
"'order'",
",",
"Entity",
"::",
"MAX_ORDER",
")",
";",
"$",
"this",
"->",
"change",
"(",
"'uri'",
",",
"$",
"new",
".",
"'/'",
".",
"$",
"this",
"->",
"_attributes",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"return_entity",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_parent",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'parent'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_parent",
"=",
"Data",
"::",
"read",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'parent'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_parent",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_parent",
";",
"}",
"return",
"$",
"this",
"->",
"_attributes",
"[",
"'parent'",
"]",
";",
"}"
] | Parent of this object
@param null|string|Entity $new New parent. URI or object
@param bool $return_entity Признак, возвращать объект вместо uri
@return string|Entity|false | [
"Parent",
"of",
"this",
"object"
] | ead9668f1a6adf41656131eb608a99db6855138d | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/data/Entity.php#L248-L274 | train |
Boolive/Core | data/Entity.php | Entity.proto | function proto($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_proto = $new;
$new = $new->uri();
}else{
$this->_proto = null; // for reloading
}
if ($new != $this->_attributes['proto']){
$this->change('proto', $new);
}
}
if ($return_entity){
if (!isset($this->_proto)){
if (isset($this->_attributes['proto'])){
$this->_proto = Data::read($this->_attributes['proto']);
}else{
$this->_proto = false;
}
}
return $this->_proto;
}
return $this->_attributes['proto'];
} | php | function proto($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_proto = $new;
$new = $new->uri();
}else{
$this->_proto = null; // for reloading
}
if ($new != $this->_attributes['proto']){
$this->change('proto', $new);
}
}
if ($return_entity){
if (!isset($this->_proto)){
if (isset($this->_attributes['proto'])){
$this->_proto = Data::read($this->_attributes['proto']);
}else{
$this->_proto = false;
}
}
return $this->_proto;
}
return $this->_attributes['proto'];
} | [
"function",
"proto",
"(",
"$",
"new",
"=",
"null",
",",
"$",
"return_entity",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
")",
"{",
"if",
"(",
"$",
"new",
"instanceof",
"Entity",
")",
"{",
"$",
"this",
"->",
"_proto",
"=",
"$",
"new",
";",
"$",
"new",
"=",
"$",
"new",
"->",
"uri",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_proto",
"=",
"null",
";",
"// for reloading",
"}",
"if",
"(",
"$",
"new",
"!=",
"$",
"this",
"->",
"_attributes",
"[",
"'proto'",
"]",
")",
"{",
"$",
"this",
"->",
"change",
"(",
"'proto'",
",",
"$",
"new",
")",
";",
"}",
"}",
"if",
"(",
"$",
"return_entity",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_proto",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'proto'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_proto",
"=",
"Data",
"::",
"read",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'proto'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_proto",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_proto",
";",
"}",
"return",
"$",
"this",
"->",
"_attributes",
"[",
"'proto'",
"]",
";",
"}"
] | Prototype of this object
@param null|string|Entity $new Новый прототип. URI или объект
@param bool $return_entity Признак, возвращать объект вместо uri
@return string|Entity|false | [
"Prototype",
"of",
"this",
"object"
] | ead9668f1a6adf41656131eb608a99db6855138d | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/data/Entity.php#L282-L306 | train |
Boolive/Core | data/Entity.php | Entity.author | function author($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_author = $new;
$new = $new->uri();
}else{
$this->_author = null; // for reloading
}
if ($new != $this->_attributes['author']){
$this->change('author', $new);
}
}
if ($return_entity){
if (!isset($this->_author)){
if (isset($this->_attributes['author'])){
$this->_author = Data::read($this->_attributes['author']);
}else{
$this->_author = false;
}
}
return $this->_author;
}
return $this->_attributes['author'];
} | php | function author($new = null, $return_entity = false)
{
if (isset($new)){
if ($new instanceof Entity){
$this->_author = $new;
$new = $new->uri();
}else{
$this->_author = null; // for reloading
}
if ($new != $this->_attributes['author']){
$this->change('author', $new);
}
}
if ($return_entity){
if (!isset($this->_author)){
if (isset($this->_attributes['author'])){
$this->_author = Data::read($this->_attributes['author']);
}else{
$this->_author = false;
}
}
return $this->_author;
}
return $this->_attributes['author'];
} | [
"function",
"author",
"(",
"$",
"new",
"=",
"null",
",",
"$",
"return_entity",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
")",
"{",
"if",
"(",
"$",
"new",
"instanceof",
"Entity",
")",
"{",
"$",
"this",
"->",
"_author",
"=",
"$",
"new",
";",
"$",
"new",
"=",
"$",
"new",
"->",
"uri",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_author",
"=",
"null",
";",
"// for reloading",
"}",
"if",
"(",
"$",
"new",
"!=",
"$",
"this",
"->",
"_attributes",
"[",
"'author'",
"]",
")",
"{",
"$",
"this",
"->",
"change",
"(",
"'author'",
",",
"$",
"new",
")",
";",
"}",
"}",
"if",
"(",
"$",
"return_entity",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_author",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_author",
"=",
"Data",
"::",
"read",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'author'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_author",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_author",
";",
"}",
"return",
"$",
"this",
"->",
"_attributes",
"[",
"'author'",
"]",
";",
"}"
] | Author of this object
@param null|string|Entity $new Новый автор. URI или объект
@param bool $return_entity Признак, возвращать объект вместо uri
@return mixed | [
"Author",
"of",
"this",
"object"
] | ead9668f1a6adf41656131eb608a99db6855138d | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/data/Entity.php#L314-L338 | train |
Boolive/Core | data/Entity.php | Entity.is_link | function is_link($new = null, $return_entity = false)
{
if (isset($new) && ($this->_attributes['is_link'] != $new)){
$this->change('is_link', (bool)$new);
}
if ($return_entity){
if (!isset($this->_link)){
if (empty($this->_attributes['is_link'])){
$this->_link = false;
}else
if (($this->_link = $this->proto(null, true))){
if ($p = $this->_link->is_link(null, true)) $this->_link = $p;
}
}
return $this->_link;
}
return $this->_attributes['is_link'];
} | php | function is_link($new = null, $return_entity = false)
{
if (isset($new) && ($this->_attributes['is_link'] != $new)){
$this->change('is_link', (bool)$new);
}
if ($return_entity){
if (!isset($this->_link)){
if (empty($this->_attributes['is_link'])){
$this->_link = false;
}else
if (($this->_link = $this->proto(null, true))){
if ($p = $this->_link->is_link(null, true)) $this->_link = $p;
}
}
return $this->_link;
}
return $this->_attributes['is_link'];
} | [
"function",
"is_link",
"(",
"$",
"new",
"=",
"null",
",",
"$",
"return_entity",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
"&&",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'is_link'",
"]",
"!=",
"$",
"new",
")",
")",
"{",
"$",
"this",
"->",
"change",
"(",
"'is_link'",
",",
"(",
"bool",
")",
"$",
"new",
")",
";",
"}",
"if",
"(",
"$",
"return_entity",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_link",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_attributes",
"[",
"'is_link'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_link",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"this",
"->",
"_link",
"=",
"$",
"this",
"->",
"proto",
"(",
"null",
",",
"true",
")",
")",
")",
"{",
"if",
"(",
"$",
"p",
"=",
"$",
"this",
"->",
"_link",
"->",
"is_link",
"(",
"null",
",",
"true",
")",
")",
"$",
"this",
"->",
"_link",
"=",
"$",
"p",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_link",
";",
"}",
"return",
"$",
"this",
"->",
"_attributes",
"[",
"'is_link'",
"]",
";",
"}"
] | Object referenced by this object
@param null|bool $new Новое значение признака
@param bool $return_entity Признак, возвращать объект вместо uri
@return bool|Entity | [
"Object",
"referenced",
"by",
"this",
"object"
] | ead9668f1a6adf41656131eb608a99db6855138d | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/data/Entity.php#L574-L591 | train |
comodojo/extender.framework | src/Comodojo/Extender/Task/Table.php | Table.add | public function add($name, $class, $description = null) {
if ( array_key_exists($name, $this->data) ) {
$this->logger->warning("Skipping duplicate task $name ($class)");
return false;
}
if ( empty($name) || empty($class) || !class_exists($class) ) {
$this->logger->warning("Skipping invalid task definition", array(
"NAME" => $name,
"CLASS" => $class,
"DESCRIPTION"=> $description
));
return false;
}
$this->data[$name] = new TaskItem(
$this->getConfiguration(),
$this->getEvents(),
$this->getLogger(),
$name,
$class,
$description
);
$this->logger->debug("Task $name ($class) in table");
return true;
} | php | public function add($name, $class, $description = null) {
if ( array_key_exists($name, $this->data) ) {
$this->logger->warning("Skipping duplicate task $name ($class)");
return false;
}
if ( empty($name) || empty($class) || !class_exists($class) ) {
$this->logger->warning("Skipping invalid task definition", array(
"NAME" => $name,
"CLASS" => $class,
"DESCRIPTION"=> $description
));
return false;
}
$this->data[$name] = new TaskItem(
$this->getConfiguration(),
$this->getEvents(),
$this->getLogger(),
$name,
$class,
$description
);
$this->logger->debug("Task $name ($class) in table");
return true;
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"$",
"class",
",",
"$",
"description",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Skipping duplicate task $name ($class)\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
"||",
"empty",
"(",
"$",
"class",
")",
"||",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Skipping invalid task definition\"",
",",
"array",
"(",
"\"NAME\"",
"=>",
"$",
"name",
",",
"\"CLASS\"",
"=>",
"$",
"class",
",",
"\"DESCRIPTION\"",
"=>",
"$",
"description",
")",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"new",
"TaskItem",
"(",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
",",
"$",
"this",
"->",
"getEvents",
"(",
")",
",",
"$",
"this",
"->",
"getLogger",
"(",
")",
",",
"$",
"name",
",",
"$",
"class",
",",
"$",
"description",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Task $name ($class) in table\"",
")",
";",
"return",
"true",
";",
"}"
] | Add a new task to table
@param string $name
@param string $class
@param string $description
@return bool | [
"Add",
"a",
"new",
"task",
"to",
"table"
] | cc9a4fbd29fe0e80965ce4535091c956aad70b27 | https://github.com/comodojo/extender.framework/blob/cc9a4fbd29fe0e80965ce4535091c956aad70b27/src/Comodojo/Extender/Task/Table.php#L84-L113 | train |
comodojo/extender.framework | src/Comodojo/Extender/Task/Table.php | Table.delete | public function delete($name) {
if ( array_key_exists($name, $this->data) ) {
unset($this->data[$name]);
return true;
}
return false;
} | php | public function delete($name) {
if ( array_key_exists($name, $this->data) ) {
unset($this->data[$name]);
return true;
}
return false;
} | [
"public",
"function",
"delete",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Delete a task from table
@param string $name
@return bool | [
"Delete",
"a",
"task",
"from",
"table"
] | cc9a4fbd29fe0e80965ce4535091c956aad70b27 | https://github.com/comodojo/extender.framework/blob/cc9a4fbd29fe0e80965ce4535091c956aad70b27/src/Comodojo/Extender/Task/Table.php#L121-L130 | train |
comodojo/extender.framework | src/Comodojo/Extender/Task/Table.php | Table.addBulk | public function addBulk(array $tasks) {
$result = [];
foreach($tasks as $name => $task) {
if ( empty($task['class']) ) {
$this->logger->warning("Missing class for task $name");
$result[] = false;
} else {
$result[] = $this->add($name, $task['class'], empty($task['description']) ? null : $task['description']);
}
}
return $result;
} | php | public function addBulk(array $tasks) {
$result = [];
foreach($tasks as $name => $task) {
if ( empty($task['class']) ) {
$this->logger->warning("Missing class for task $name");
$result[] = false;
} else {
$result[] = $this->add($name, $task['class'], empty($task['description']) ? null : $task['description']);
}
}
return $result;
} | [
"public",
"function",
"addBulk",
"(",
"array",
"$",
"tasks",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tasks",
"as",
"$",
"name",
"=>",
"$",
"task",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"task",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Missing class for task $name\"",
")",
";",
"$",
"result",
"[",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"task",
"[",
"'class'",
"]",
",",
"empty",
"(",
"$",
"task",
"[",
"'description'",
"]",
")",
"?",
"null",
":",
"$",
"task",
"[",
"'description'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Load a bulk task list into the table
@param array $tasks
@return bool | [
"Load",
"a",
"bulk",
"task",
"list",
"into",
"the",
"table"
] | cc9a4fbd29fe0e80965ce4535091c956aad70b27 | https://github.com/comodojo/extender.framework/blob/cc9a4fbd29fe0e80965ce4535091c956aad70b27/src/Comodojo/Extender/Task/Table.php#L138-L159 | train |
andyburton/Sonic-Framework | src/Resource/Model/Collection.php | Collection.random | public function random ()
{
$arr = $this->getArrayCopy ();
$rand = array_rand ($arr);
return isset ($arr[$rand])? $arr[$rand] : FALSE;
} | php | public function random ()
{
$arr = $this->getArrayCopy ();
$rand = array_rand ($arr);
return isset ($arr[$rand])? $arr[$rand] : FALSE;
} | [
"public",
"function",
"random",
"(",
")",
"{",
"$",
"arr",
"=",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"rand",
"=",
"array_rand",
"(",
"$",
"arr",
")",
";",
"return",
"isset",
"(",
"$",
"arr",
"[",
"$",
"rand",
"]",
")",
"?",
"$",
"arr",
"[",
"$",
"rand",
"]",
":",
"FALSE",
";",
"}"
] | Return random collection item
@return \Sonic\Model|FALSE | [
"Return",
"random",
"collection",
"item"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/Model/Collection.php#L81-L86 | train |
andyburton/Sonic-Framework | src/Resource/Model/Collection.php | Collection.toArray | public function toArray ($attributes = FALSE, $relations = array (), $recursive = FALSE)
{
$arr = array ();
$it = $this->getIterator ();
while ($it->valid ())
{
$arr[$it->key ()] = $it->current ()->toArray ($attributes, $relations, $recursive);
$it->next ();
}
return $arr;
} | php | public function toArray ($attributes = FALSE, $relations = array (), $recursive = FALSE)
{
$arr = array ();
$it = $this->getIterator ();
while ($it->valid ())
{
$arr[$it->key ()] = $it->current ()->toArray ($attributes, $relations, $recursive);
$it->next ();
}
return $arr;
} | [
"public",
"function",
"toArray",
"(",
"$",
"attributes",
"=",
"FALSE",
",",
"$",
"relations",
"=",
"array",
"(",
")",
",",
"$",
"recursive",
"=",
"FALSE",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"$",
"it",
"=",
"$",
"this",
"->",
"getIterator",
"(",
")",
";",
"while",
"(",
"$",
"it",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"arr",
"[",
"$",
"it",
"->",
"key",
"(",
")",
"]",
"=",
"$",
"it",
"->",
"current",
"(",
")",
"->",
"toArray",
"(",
"$",
"attributes",
",",
"$",
"relations",
",",
"$",
"recursive",
")",
";",
"$",
"it",
"->",
"next",
"(",
")",
";",
"}",
"return",
"$",
"arr",
";",
"}"
] | Return a multidimensional array with objects and their attributes
@param array|boolean $attributes Attributes to include, default to false i.e all attributes
@param array $relations Array of related object attributes or tranformed method attributes to return
e.g. related value - 'query_name' => array ('\Sonic\Model\User\Group', 'name')
e.g. object tranformed value - 'permission_value' => array ('$this', 'getStringValue')
e.g. static tranformed value - 'permission_value' => array ('self', '_getStringValue')
@param integer $recursive Output array recursively, so any $this->children also get output
@return object|boolean | [
"Return",
"a",
"multidimensional",
"array",
"with",
"objects",
"and",
"their",
"attributes"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/Model/Collection.php#L100-L114 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.prepareOptions | private function prepareOptions($options, $forceOptions = [])
{
$optionString = '';
foreach ($forceOptions as $option => $value) {
if (is_numeric($option)) {
$options[$value] = null;
} else {
$options[$option] = $value;
}
}
foreach ($options as $option => $value) {
if (is_null($value)) {
$optionString .= ' ' . $option;
} else {
$optionString .= ' ' . $option . '=' . $value;
}
}
return $optionString;
} | php | private function prepareOptions($options, $forceOptions = [])
{
$optionString = '';
foreach ($forceOptions as $option => $value) {
if (is_numeric($option)) {
$options[$value] = null;
} else {
$options[$option] = $value;
}
}
foreach ($options as $option => $value) {
if (is_null($value)) {
$optionString .= ' ' . $option;
} else {
$optionString .= ' ' . $option . '=' . $value;
}
}
return $optionString;
} | [
"private",
"function",
"prepareOptions",
"(",
"$",
"options",
",",
"$",
"forceOptions",
"=",
"[",
"]",
")",
"{",
"$",
"optionString",
"=",
"''",
";",
"foreach",
"(",
"$",
"forceOptions",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"option",
")",
")",
"{",
"$",
"options",
"[",
"$",
"value",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"optionString",
".=",
"' '",
".",
"$",
"option",
";",
"}",
"else",
"{",
"$",
"optionString",
".=",
"' '",
".",
"$",
"option",
".",
"'='",
".",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"optionString",
";",
"}"
] | Prepares the options string.
@param $options
@param $forceOptions
@return string | [
"Prepares",
"the",
"options",
"string",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L118-L140 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.prepareInstallationDirectory | private function prepareInstallationDirectory($directory)
{
if (!$this->files->exists($directory)) {
$this->files->makeDirectory($directory . DIRECTORY_SEPARATOR, 0755, true);
return;
}
$this->files->deleteDirectory($directory, true);
$this->checkInstallationDirectory($directory);
} | php | private function prepareInstallationDirectory($directory)
{
if (!$this->files->exists($directory)) {
$this->files->makeDirectory($directory . DIRECTORY_SEPARATOR, 0755, true);
return;
}
$this->files->deleteDirectory($directory, true);
$this->checkInstallationDirectory($directory);
} | [
"private",
"function",
"prepareInstallationDirectory",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"this",
"->",
"files",
"->",
"makeDirectory",
"(",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
",",
"0755",
",",
"true",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"files",
"->",
"deleteDirectory",
"(",
"$",
"directory",
",",
"true",
")",
";",
"$",
"this",
"->",
"checkInstallationDirectory",
"(",
"$",
"directory",
")",
";",
"}"
] | Prepares the installation directory.
This method will create the directory if it does
not exist and will ensure that the directory is
empty if it does.
@param $directory | [
"Prepares",
"the",
"installation",
"directory",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L151-L161 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.checkInstallationDirectory | private function checkInstallationDirectory($directory)
{
if ($this->installationAttempts >= $this->breakAtInstallationAttempt) {
$this->log->error('Installation directory checks failed at max attempts', ['attempts' => $this->installationAttempts]);
throw new PackageInstallationException(null, "The package template could not be installed.");
}
$files = $this->files->allFiles($directory);
$directories = $this->files->directories($directory);
if (count($files) == 0 && count($directories) == 0) {
return;
}
$directoriesReadable = true;
$filesReadable = true;
foreach ($directories as $directory) {
if (!$this->files->isReadable($directory)) {
$this->log->error('Unreadable directory preventing Composer install', ['directory' => $directory]);
$directoriesReadable = false;
}
}
foreach ($files as $file) {
if (!$this->files->isReadable($file->getPathname())) {
$this->log->error('Unreadable file preventing Composer install', ['file' => $file]);
$filesReadable = false;
}
}
if (!$directoriesReadable || !$filesReadable) {
$this->log->critical('Unreadable files/directories, cannot proceed with install.');
throw new InvalidInstallationDirectoryException(null,
"The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again.");
}
if (!$this->files->isWritable($directory)) {
$this->log->critical('Installation directory is not writeable by NewUp. Cannot proceed with install.', ['directory' => $directory, 'permissions' => fileperms($directory)]);
throw new InvalidInstallationDirectoryException(null,
"The installation directory ({$directory}) is not writeable by the NewUp process.");
}
// At this point, there is no clear reason why the preparation
// did not succeed. Because of this, we will try again.
$this->installationAttempts++;
$this->log->debug('Installation attempt incremented', ['directory' => $directory, 'attempt' => $this->installationAttempts]);
$this->prepareInstallationDirectory($directory);
} | php | private function checkInstallationDirectory($directory)
{
if ($this->installationAttempts >= $this->breakAtInstallationAttempt) {
$this->log->error('Installation directory checks failed at max attempts', ['attempts' => $this->installationAttempts]);
throw new PackageInstallationException(null, "The package template could not be installed.");
}
$files = $this->files->allFiles($directory);
$directories = $this->files->directories($directory);
if (count($files) == 0 && count($directories) == 0) {
return;
}
$directoriesReadable = true;
$filesReadable = true;
foreach ($directories as $directory) {
if (!$this->files->isReadable($directory)) {
$this->log->error('Unreadable directory preventing Composer install', ['directory' => $directory]);
$directoriesReadable = false;
}
}
foreach ($files as $file) {
if (!$this->files->isReadable($file->getPathname())) {
$this->log->error('Unreadable file preventing Composer install', ['file' => $file]);
$filesReadable = false;
}
}
if (!$directoriesReadable || !$filesReadable) {
$this->log->critical('Unreadable files/directories, cannot proceed with install.');
throw new InvalidInstallationDirectoryException(null,
"The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again.");
}
if (!$this->files->isWritable($directory)) {
$this->log->critical('Installation directory is not writeable by NewUp. Cannot proceed with install.', ['directory' => $directory, 'permissions' => fileperms($directory)]);
throw new InvalidInstallationDirectoryException(null,
"The installation directory ({$directory}) is not writeable by the NewUp process.");
}
// At this point, there is no clear reason why the preparation
// did not succeed. Because of this, we will try again.
$this->installationAttempts++;
$this->log->debug('Installation attempt incremented', ['directory' => $directory, 'attempt' => $this->installationAttempts]);
$this->prepareInstallationDirectory($directory);
} | [
"private",
"function",
"checkInstallationDirectory",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"installationAttempts",
">=",
"$",
"this",
"->",
"breakAtInstallationAttempt",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Installation directory checks failed at max attempts'",
",",
"[",
"'attempts'",
"=>",
"$",
"this",
"->",
"installationAttempts",
"]",
")",
";",
"throw",
"new",
"PackageInstallationException",
"(",
"null",
",",
"\"The package template could not be installed.\"",
")",
";",
"}",
"$",
"files",
"=",
"$",
"this",
"->",
"files",
"->",
"allFiles",
"(",
"$",
"directory",
")",
";",
"$",
"directories",
"=",
"$",
"this",
"->",
"files",
"->",
"directories",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"count",
"(",
"$",
"files",
")",
"==",
"0",
"&&",
"count",
"(",
"$",
"directories",
")",
"==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"directoriesReadable",
"=",
"true",
";",
"$",
"filesReadable",
"=",
"true",
";",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"directory",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isReadable",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Unreadable directory preventing Composer install'",
",",
"[",
"'directory'",
"=>",
"$",
"directory",
"]",
")",
";",
"$",
"directoriesReadable",
"=",
"false",
";",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isReadable",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Unreadable file preventing Composer install'",
",",
"[",
"'file'",
"=>",
"$",
"file",
"]",
")",
";",
"$",
"filesReadable",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"directoriesReadable",
"||",
"!",
"$",
"filesReadable",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"critical",
"(",
"'Unreadable files/directories, cannot proceed with install.'",
")",
";",
"throw",
"new",
"InvalidInstallationDirectoryException",
"(",
"null",
",",
"\"The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isWritable",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"critical",
"(",
"'Installation directory is not writeable by NewUp. Cannot proceed with install.'",
",",
"[",
"'directory'",
"=>",
"$",
"directory",
",",
"'permissions'",
"=>",
"fileperms",
"(",
"$",
"directory",
")",
"]",
")",
";",
"throw",
"new",
"InvalidInstallationDirectoryException",
"(",
"null",
",",
"\"The installation directory ({$directory}) is not writeable by the NewUp process.\"",
")",
";",
"}",
"// At this point, there is no clear reason why the preparation",
"// did not succeed. Because of this, we will try again.",
"$",
"this",
"->",
"installationAttempts",
"++",
";",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Installation attempt incremented'",
",",
"[",
"'directory'",
"=>",
"$",
"directory",
",",
"'attempt'",
"=>",
"$",
"this",
"->",
"installationAttempts",
"]",
")",
";",
"$",
"this",
"->",
"prepareInstallationDirectory",
"(",
"$",
"directory",
")",
";",
"}"
] | Checks the installation directory to make sure it is ready.
@throws InvalidInstallationDirectoryException
@throws PackageInstallationException
@param $directory | [
"Checks",
"the",
"installation",
"directory",
"to",
"make",
"sure",
"it",
"is",
"ready",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L170-L218 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.installPackage | public function installPackage($packageName, $options = [])
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' create-project ' . $packageName . ' "' .
$this->workingPath . '" ' .
$this->prepareOptions($options, ['--no-ansi', '--no-install']));
$process->setCommandLine($processCommand);
$this->prepareInstallationDirectory($this->workingPath);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = $this->parseComposerErrorMessage($process->getErrorOutput());
$this->log->error('Composer create-project process failure', ['composer' => $composerError]);
$additionalInformation = '';
if (Str::contains($process->getErrorOutput(), 'The system cannot find the path specified. (code: 3)')) {
$additionalInformation = PHP_EOL.PHP_EOL.'Based on the provided error message, the following article may be helpful:'.PHP_EOL.'https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows-';
}
throw new PackageInstallationException($process->getErrorOutput(),
"There was an error installing the package: {$packageName}" . PHP_EOL .
'Composer is reporting the following error:' . PHP_EOL . '--> ' . $composerError.$additionalInformation);
}
return true;
} | php | public function installPackage($packageName, $options = [])
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' create-project ' . $packageName . ' "' .
$this->workingPath . '" ' .
$this->prepareOptions($options, ['--no-ansi', '--no-install']));
$process->setCommandLine($processCommand);
$this->prepareInstallationDirectory($this->workingPath);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = $this->parseComposerErrorMessage($process->getErrorOutput());
$this->log->error('Composer create-project process failure', ['composer' => $composerError]);
$additionalInformation = '';
if (Str::contains($process->getErrorOutput(), 'The system cannot find the path specified. (code: 3)')) {
$additionalInformation = PHP_EOL.PHP_EOL.'Based on the provided error message, the following article may be helpful:'.PHP_EOL.'https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows-';
}
throw new PackageInstallationException($process->getErrorOutput(),
"There was an error installing the package: {$packageName}" . PHP_EOL .
'Composer is reporting the following error:' . PHP_EOL . '--> ' . $composerError.$additionalInformation);
}
return true;
} | [
"public",
"function",
"installPackage",
"(",
"$",
"packageName",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"getProcess",
"(",
")",
";",
"$",
"processCommand",
"=",
"trim",
"(",
"$",
"this",
"->",
"findComposer",
"(",
")",
".",
"' create-project '",
".",
"$",
"packageName",
".",
"' \"'",
".",
"$",
"this",
"->",
"workingPath",
".",
"'\" '",
".",
"$",
"this",
"->",
"prepareOptions",
"(",
"$",
"options",
",",
"[",
"'--no-ansi'",
",",
"'--no-install'",
"]",
")",
")",
";",
"$",
"process",
"->",
"setCommandLine",
"(",
"$",
"processCommand",
")",
";",
"$",
"this",
"->",
"prepareInstallationDirectory",
"(",
"$",
"this",
"->",
"workingPath",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Running Composer command'",
",",
"[",
"'command'",
"=>",
"$",
"processCommand",
"]",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
"==",
"false",
")",
"{",
"$",
"composerError",
"=",
"$",
"this",
"->",
"parseComposerErrorMessage",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Composer create-project process failure'",
",",
"[",
"'composer'",
"=>",
"$",
"composerError",
"]",
")",
";",
"$",
"additionalInformation",
"=",
"''",
";",
"if",
"(",
"Str",
"::",
"contains",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
",",
"'The system cannot find the path specified. (code: 3)'",
")",
")",
"{",
"$",
"additionalInformation",
"=",
"PHP_EOL",
".",
"PHP_EOL",
".",
"'Based on the provided error message, the following article may be helpful:'",
".",
"PHP_EOL",
".",
"'https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows-'",
";",
"}",
"throw",
"new",
"PackageInstallationException",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
",",
"\"There was an error installing the package: {$packageName}\"",
".",
"PHP_EOL",
".",
"'Composer is reporting the following error:'",
".",
"PHP_EOL",
".",
"'--> '",
".",
"$",
"composerError",
".",
"$",
"additionalInformation",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Installs a Composer package, placing it in NewUp's template storage.
@param $packageName
@param array $options
@throws PackageInstallationException
@return bool | [
"Installs",
"a",
"Composer",
"package",
"placing",
"it",
"in",
"NewUp",
"s",
"template",
"storage",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L245-L276 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.updatePackageDependencies | public function updatePackageDependencies($options = [])
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' update ' .
$this->prepareOptions($options, ['--no-progress', '--no-ansi']));
$process->setCommandLine($processCommand);
chdir($this->workingPath);
$this->log->info('Changing working directory for Composer update', ['directory' => $this->workingPath]);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$this->restoreWorkingDirectory();
$composerError = $process->getErrorOutput();
$this->log->error('Composer update process failure', ['composer' => $composerError]);
throw new PackageInstallationException($process->getErrorOutput(),
"There was an error updating the dependencies." . PHP_EOL .
'Composer is reporting the following error(s):' . PHP_EOL . '--> ' . $composerError);
}
$this->restoreWorkingDirectory();
$this->log->info('Package template dependencies updated', ['directory' => $this->workingPath]);
return true;
} | php | public function updatePackageDependencies($options = [])
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' update ' .
$this->prepareOptions($options, ['--no-progress', '--no-ansi']));
$process->setCommandLine($processCommand);
chdir($this->workingPath);
$this->log->info('Changing working directory for Composer update', ['directory' => $this->workingPath]);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$this->restoreWorkingDirectory();
$composerError = $process->getErrorOutput();
$this->log->error('Composer update process failure', ['composer' => $composerError]);
throw new PackageInstallationException($process->getErrorOutput(),
"There was an error updating the dependencies." . PHP_EOL .
'Composer is reporting the following error(s):' . PHP_EOL . '--> ' . $composerError);
}
$this->restoreWorkingDirectory();
$this->log->info('Package template dependencies updated', ['directory' => $this->workingPath]);
return true;
} | [
"public",
"function",
"updatePackageDependencies",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"getProcess",
"(",
")",
";",
"$",
"processCommand",
"=",
"trim",
"(",
"$",
"this",
"->",
"findComposer",
"(",
")",
".",
"' update '",
".",
"$",
"this",
"->",
"prepareOptions",
"(",
"$",
"options",
",",
"[",
"'--no-progress'",
",",
"'--no-ansi'",
"]",
")",
")",
";",
"$",
"process",
"->",
"setCommandLine",
"(",
"$",
"processCommand",
")",
";",
"chdir",
"(",
"$",
"this",
"->",
"workingPath",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Changing working directory for Composer update'",
",",
"[",
"'directory'",
"=>",
"$",
"this",
"->",
"workingPath",
"]",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Running Composer command'",
",",
"[",
"'command'",
"=>",
"$",
"processCommand",
"]",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"restoreWorkingDirectory",
"(",
")",
";",
"$",
"composerError",
"=",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
";",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Composer update process failure'",
",",
"[",
"'composer'",
"=>",
"$",
"composerError",
"]",
")",
";",
"throw",
"new",
"PackageInstallationException",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
",",
"\"There was an error updating the dependencies.\"",
".",
"PHP_EOL",
".",
"'Composer is reporting the following error(s):'",
".",
"PHP_EOL",
".",
"'--> '",
".",
"$",
"composerError",
")",
";",
"}",
"$",
"this",
"->",
"restoreWorkingDirectory",
"(",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Package template dependencies updated'",
",",
"[",
"'directory'",
"=>",
"$",
"this",
"->",
"workingPath",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Updates the packages dependencies by running "composer update".
@throws PackageInstallationException
@param array $options
@return bool | [
"Updates",
"the",
"packages",
"dependencies",
"by",
"running",
"composer",
"update",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L285-L313 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.getVersion | public function getVersion()
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' --version');
$process->setCommandLine($processCommand);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = remove_ansi($process->getErrorOutput());
$this->log->error('Composer version process failure', ['composer' => $composerError]);
throw new ComposerException('There was an error retrieving the Composer version');
}
return $process->getOutput();
} | php | public function getVersion()
{
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' --version');
$process->setCommandLine($processCommand);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = remove_ansi($process->getErrorOutput());
$this->log->error('Composer version process failure', ['composer' => $composerError]);
throw new ComposerException('There was an error retrieving the Composer version');
}
return $process->getOutput();
} | [
"public",
"function",
"getVersion",
"(",
")",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"getProcess",
"(",
")",
";",
"$",
"processCommand",
"=",
"trim",
"(",
"$",
"this",
"->",
"findComposer",
"(",
")",
".",
"' --version'",
")",
";",
"$",
"process",
"->",
"setCommandLine",
"(",
"$",
"processCommand",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Running Composer command'",
",",
"[",
"'command'",
"=>",
"$",
"processCommand",
"]",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
"==",
"false",
")",
"{",
"$",
"composerError",
"=",
"remove_ansi",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Composer version process failure'",
",",
"[",
"'composer'",
"=>",
"$",
"composerError",
"]",
")",
";",
"throw",
"new",
"ComposerException",
"(",
"'There was an error retrieving the Composer version'",
")",
";",
"}",
"return",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}"
] | Gets the Composer version.
@return string
@throws ComposerException | [
"Gets",
"the",
"Composer",
"version",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L332-L347 | train |
newup/core | src/Foundation/Composer/Composer.php | Composer.selfUpdate | public function selfUpdate()
{
$beforeVersion = $this->getVersion();
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' self-update');
$process->setCommandLine($processCommand);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = remove_ansi($process->getErrorOutput());
$this->log->error('Composer self update process failure', ['composer' => $composerError]);
throw new ComposerException('There was an error updating Composer');
}
$afterVersion = $this->getVersion();
if ($beforeVersion == $afterVersion) {
return false;
}
return true;
} | php | public function selfUpdate()
{
$beforeVersion = $this->getVersion();
$process = $this->getProcess();
$processCommand = trim($this->findComposer() . ' self-update');
$process->setCommandLine($processCommand);
$this->log->info('Running Composer command', ['command' => $processCommand]);
$process->run();
if ($process->isSuccessful() == false) {
$composerError = remove_ansi($process->getErrorOutput());
$this->log->error('Composer self update process failure', ['composer' => $composerError]);
throw new ComposerException('There was an error updating Composer');
}
$afterVersion = $this->getVersion();
if ($beforeVersion == $afterVersion) {
return false;
}
return true;
} | [
"public",
"function",
"selfUpdate",
"(",
")",
"{",
"$",
"beforeVersion",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"$",
"process",
"=",
"$",
"this",
"->",
"getProcess",
"(",
")",
";",
"$",
"processCommand",
"=",
"trim",
"(",
"$",
"this",
"->",
"findComposer",
"(",
")",
".",
"' self-update'",
")",
";",
"$",
"process",
"->",
"setCommandLine",
"(",
"$",
"processCommand",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'Running Composer command'",
",",
"[",
"'command'",
"=>",
"$",
"processCommand",
"]",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
"==",
"false",
")",
"{",
"$",
"composerError",
"=",
"remove_ansi",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"$",
"this",
"->",
"log",
"->",
"error",
"(",
"'Composer self update process failure'",
",",
"[",
"'composer'",
"=>",
"$",
"composerError",
"]",
")",
";",
"throw",
"new",
"ComposerException",
"(",
"'There was an error updating Composer'",
")",
";",
"}",
"$",
"afterVersion",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"if",
"(",
"$",
"beforeVersion",
"==",
"$",
"afterVersion",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Attempts to update Composer.
Returns true if Composer was updated, false if not.
@return bool
@throws ComposerException | [
"Attempts",
"to",
"update",
"Composer",
"."
] | 54128903e7775e67d63284d958b46862c8df71f9 | https://github.com/newup/core/blob/54128903e7775e67d63284d958b46862c8df71f9/src/Foundation/Composer/Composer.php#L357-L380 | train |
schpill/thin | src/Database/Collection.php | Collection.get | public function get($index = 0)
{
if (is_integer($index)) {
if ($index + 1 > $this->count()) {
return null;
} else {
return Arrays::first(array_slice($this->_items, $index, 1));
}
} else {
if ($this->has($index)) {
return $this->_items[$index];
}
}
return null;
} | php | public function get($index = 0)
{
if (is_integer($index)) {
if ($index + 1 > $this->count()) {
return null;
} else {
return Arrays::first(array_slice($this->_items, $index, 1));
}
} else {
if ($this->has($index)) {
return $this->_items[$index];
}
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"index",
")",
")",
"{",
"if",
"(",
"$",
"index",
"+",
"1",
">",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"Arrays",
"::",
"first",
"(",
"array_slice",
"(",
"$",
"this",
"->",
"_items",
",",
"$",
"index",
",",
"1",
")",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"index",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_items",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get item by numeric index
@param int $index model to get
@return Model | [
"Get",
"item",
"by",
"numeric",
"index"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Database/Collection.php#L86-L101 | train |
schpill/thin | src/Database/Collection.php | Collection.keyBy | public function keyBy($keyBy)
{
$results = array();
foreach ($this->_items as $item) {
$key = dataGet($item, $keyBy);
$results[$key] = $item;
}
return new self($results);
} | php | public function keyBy($keyBy)
{
$results = array();
foreach ($this->_items as $item) {
$key = dataGet($item, $keyBy);
$results[$key] = $item;
}
return new self($results);
} | [
"public",
"function",
"keyBy",
"(",
"$",
"keyBy",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_items",
"as",
"$",
"item",
")",
"{",
"$",
"key",
"=",
"dataGet",
"(",
"$",
"item",
",",
"$",
"keyBy",
")",
";",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"results",
")",
";",
"}"
] | Key an associative array by a field.
@param string $keyBy
@return Collection | [
"Key",
"an",
"associative",
"array",
"by",
"a",
"field",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Database/Collection.php#L572-L582 | train |
schpill/thin | src/Database/Collection.php | Collection.extend | public function extend($name, Closure $callback)
{
if (count($this->_items)) {
$collection = array();
foreach ($this->_items as $item) {
if ($item instanceof Container) {
$item->fn($name, $callback);
}
array_push($collection, $item);
}
return new self($collection);
}
return $this;
} | php | public function extend($name, Closure $callback)
{
if (count($this->_items)) {
$collection = array();
foreach ($this->_items as $item) {
if ($item instanceof Container) {
$item->fn($name, $callback);
}
array_push($collection, $item);
}
return new self($collection);
}
return $this;
} | [
"public",
"function",
"extend",
"(",
"$",
"name",
",",
"Closure",
"$",
"callback",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_items",
")",
")",
"{",
"$",
"collection",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"Container",
")",
"{",
"$",
"item",
"->",
"fn",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"}",
"array_push",
"(",
"$",
"collection",
",",
"$",
"item",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"collection",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | extends each Container item of this collection with a Closure.
@param string $name
@param Closure $callback callback
@return Collection | [
"extends",
"each",
"Container",
"item",
"of",
"this",
"collection",
"with",
"a",
"Closure",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Database/Collection.php#L727-L743 | train |
schpill/thin | src/Database/Collection.php | Collection.toJson | public function toJson($render = false)
{
$json = json_encode($this->toArray(true, true));
if (false === $render) {
return $json;
} else {
header('content-type: application/json; charset=utf-8');
die($json);
}
} | php | public function toJson($render = false)
{
$json = json_encode($this->toArray(true, true));
if (false === $render) {
return $json;
} else {
header('content-type: application/json; charset=utf-8');
die($json);
}
} | [
"public",
"function",
"toJson",
"(",
"$",
"render",
"=",
"false",
")",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"toArray",
"(",
"true",
",",
"true",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"render",
")",
"{",
"return",
"$",
"json",
";",
"}",
"else",
"{",
"header",
"(",
"'content-type: application/json; charset=utf-8'",
")",
";",
"die",
"(",
"$",
"json",
")",
";",
"}",
"}"
] | Export all items to a json string
@param boolean $is_numeric_index is numeric index
@param boolean $itemToArray item to array
@return string | [
"Export",
"all",
"items",
"to",
"a",
"json",
"string"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Database/Collection.php#L807-L817 | train |
phramework/phramework | src/Models/Response.php | Response.cacheHeaders | public static function cacheHeaders($expires = '+1 hour')
{
if (!headers_sent()) {
header('Cache-Control: private, max-age=3600');
header('Pragma: public');
header('Last-Modified: ' . date(DATE_RFC822, strtotime('-1 second')));
header('Expires: ' . date(DATE_RFC822, strtotime($expires)));
}
} | php | public static function cacheHeaders($expires = '+1 hour')
{
if (!headers_sent()) {
header('Cache-Control: private, max-age=3600');
header('Pragma: public');
header('Last-Modified: ' . date(DATE_RFC822, strtotime('-1 second')));
header('Expires: ' . date(DATE_RFC822, strtotime($expires)));
}
} | [
"public",
"static",
"function",
"cacheHeaders",
"(",
"$",
"expires",
"=",
"'+1 hour'",
")",
"{",
"if",
"(",
"!",
"headers_sent",
"(",
")",
")",
"{",
"header",
"(",
"'Cache-Control: private, max-age=3600'",
")",
";",
"header",
"(",
"'Pragma: public'",
")",
";",
"header",
"(",
"'Last-Modified: '",
".",
"date",
"(",
"DATE_RFC822",
",",
"strtotime",
"(",
"'-1 second'",
")",
")",
")",
";",
"header",
"(",
"'Expires: '",
".",
"date",
"(",
"DATE_RFC822",
",",
"strtotime",
"(",
"$",
"expires",
")",
")",
")",
";",
"}",
"}"
] | Write cache headers | [
"Write",
"cache",
"headers"
] | 40041d1ef23b1f8cdbd26fb112448d6a3dbef012 | https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Response.php#L96-L104 | train |
plinker-rpc/system | src/System.php | System.enumerate | public function enumerate($methods = [], $params = [])
{
if (is_array($methods)) {
$return = [];
foreach ($methods as $key => $value) {
if (is_array($value)) {
$return[$key] = $this->$key(...$value);
} else {
$return[$value] = $this->$value();
}
}
return $return;
} elseif (is_string($methods)) {
return $this->$methods(...$params);
}
} | php | public function enumerate($methods = [], $params = [])
{
if (is_array($methods)) {
$return = [];
foreach ($methods as $key => $value) {
if (is_array($value)) {
$return[$key] = $this->$key(...$value);
} else {
$return[$value] = $this->$value();
}
}
return $return;
} elseif (is_string($methods)) {
return $this->$methods(...$params);
}
} | [
"public",
"function",
"enumerate",
"(",
"$",
"methods",
"=",
"[",
"]",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"methods",
")",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"$",
"key",
"(",
"...",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"$",
"value",
"]",
"=",
"$",
"this",
"->",
"$",
"value",
"(",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"methods",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"methods",
"(",
"...",
"$",
"params",
")",
";",
"}",
"}"
] | Enumerate multiple methods, saves on HTTP calls
@param array $methods | [
"Enumerate",
"multiple",
"methods",
"saves",
"on",
"HTTP",
"calls"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L47-L62 | train |
plinker-rpc/system | src/System.php | System.system_updates | public function system_updates()
{
if (file_exists($this->tmp_path.'/check-updates')) {
unlink($this->tmp_path.'/check-updates');
}
if ($this->host_os === 'WINDOWS') {
$updSess = new \COM("Microsoft.Update.Session");
$updSrc = $updSess->CreateUpdateSearcher();
$result = $updSrc->Search('IsInstalled=0 and Type=\'Software\' and IsHidden=0');
return !empty($result->Updates->Count) ? '1' : '0';
}
if ($this->distro() === 'UBUNTU') {
$get_updates = shell_exec('apt-get -s dist-upgrade');
if (preg_match('/^(\d+).+upgrade.+(\d+).+newly\sinstall/m', $get_updates, $matches)) {
$result = (int) $matches[1] + (int) $matches[2];
} else {
$result = 0;
}
return !empty($result) ? '1' : '0';
}
if ($this->distro() === 'CENTOS') {
exec('yum check-update', $output, $exitCode);
return ($exitCode == 100) ? '1' : '0';
}
return '-1';
} | php | public function system_updates()
{
if (file_exists($this->tmp_path.'/check-updates')) {
unlink($this->tmp_path.'/check-updates');
}
if ($this->host_os === 'WINDOWS') {
$updSess = new \COM("Microsoft.Update.Session");
$updSrc = $updSess->CreateUpdateSearcher();
$result = $updSrc->Search('IsInstalled=0 and Type=\'Software\' and IsHidden=0');
return !empty($result->Updates->Count) ? '1' : '0';
}
if ($this->distro() === 'UBUNTU') {
$get_updates = shell_exec('apt-get -s dist-upgrade');
if (preg_match('/^(\d+).+upgrade.+(\d+).+newly\sinstall/m', $get_updates, $matches)) {
$result = (int) $matches[1] + (int) $matches[2];
} else {
$result = 0;
}
return !empty($result) ? '1' : '0';
}
if ($this->distro() === 'CENTOS') {
exec('yum check-update', $output, $exitCode);
return ($exitCode == 100) ? '1' : '0';
}
return '-1';
} | [
"public",
"function",
"system_updates",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/check-updates'",
")",
")",
"{",
"unlink",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/check-updates'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"updSess",
"=",
"new",
"\\",
"COM",
"(",
"\"Microsoft.Update.Session\"",
")",
";",
"$",
"updSrc",
"=",
"$",
"updSess",
"->",
"CreateUpdateSearcher",
"(",
")",
";",
"$",
"result",
"=",
"$",
"updSrc",
"->",
"Search",
"(",
"'IsInstalled=0 and Type=\\'Software\\' and IsHidden=0'",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"result",
"->",
"Updates",
"->",
"Count",
")",
"?",
"'1'",
":",
"'0'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"distro",
"(",
")",
"===",
"'UBUNTU'",
")",
"{",
"$",
"get_updates",
"=",
"shell_exec",
"(",
"'apt-get -s dist-upgrade'",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^(\\d+).+upgrade.+(\\d+).+newly\\sinstall/m'",
",",
"$",
"get_updates",
",",
"$",
"matches",
")",
")",
"{",
"$",
"result",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
"+",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"0",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"result",
")",
"?",
"'1'",
":",
"'0'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"distro",
"(",
")",
"===",
"'CENTOS'",
")",
"{",
"exec",
"(",
"'yum check-update'",
",",
"$",
"output",
",",
"$",
"exitCode",
")",
";",
"return",
"(",
"$",
"exitCode",
"==",
"100",
")",
"?",
"'1'",
":",
"'0'",
";",
"}",
"return",
"'-1'",
";",
"}"
] | Check system for updates
@return int 1=has updates, 0=no updates, -1=unknown | [
"Check",
"system",
"for",
"updates"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L69-L97 | train |
plinker-rpc/system | src/System.php | System.total_disk_space | public function total_disk_space($path = '/')
{
$ds = 0;
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$disks = $wmi->ExecQuery("Select * from Win32_LogicalDisk");
foreach ($disks as $d) {
if ($d->Name == $path) {
$ds = $d->Size;
}
}
} else {
$ds = disk_total_space($path);
}
return $ds;
} | php | public function total_disk_space($path = '/')
{
$ds = 0;
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$disks = $wmi->ExecQuery("Select * from Win32_LogicalDisk");
foreach ($disks as $d) {
if ($d->Name == $path) {
$ds = $d->Size;
}
}
} else {
$ds = disk_total_space($path);
}
return $ds;
} | [
"public",
"function",
"total_disk_space",
"(",
"$",
"path",
"=",
"'/'",
")",
"{",
"$",
"ds",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"disks",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"Select * from Win32_LogicalDisk\"",
")",
";",
"foreach",
"(",
"$",
"disks",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"$",
"d",
"->",
"Name",
"==",
"$",
"path",
")",
"{",
"$",
"ds",
"=",
"$",
"d",
"->",
"Size",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"ds",
"=",
"disk_total_space",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"ds",
";",
"}"
] | Get total diskspace
@param string $path
@return int | [
"Get",
"total",
"diskspace"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L130-L146 | train |
plinker-rpc/system | src/System.php | System.memory_stats | public function memory_stats()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $m) {
$mem_total = $m->TotalVisibleMemorySize;
$mem_free = $m->FreePhysicalMemory;
}
$prefMemory = $wmi->ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");
foreach ($prefMemory as $pm) {
$mem_cache = $pm->CacheBytes/1024;
}
$mem_buff = 0;
} else {
$fh = fopen('/proc/meminfo', 'r');
$mem_free = $mem_buff = $mem_cache = $mem_total = 0;
while ($line = fgets($fh)) {
$pieces = array();
if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_total = $pieces[1];
}
if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_free = $pieces[1];
}
if (preg_match('/^Buffers:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_buff = $pieces[1];
}
if (preg_match('/^Cached:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_cache = $pieces[1];
break;
}
}
fclose($fh);
}
$result['used'] = round(($mem_total - ($mem_buff + $mem_cache + $mem_free)) * 100 / $mem_total);
$result['cache'] = round(($mem_cache + $mem_buff) * 100 / $mem_total);
$result['free'] = round($mem_free * 100 / $mem_total);
return $result;
} | php | public function memory_stats()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $m) {
$mem_total = $m->TotalVisibleMemorySize;
$mem_free = $m->FreePhysicalMemory;
}
$prefMemory = $wmi->ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");
foreach ($prefMemory as $pm) {
$mem_cache = $pm->CacheBytes/1024;
}
$mem_buff = 0;
} else {
$fh = fopen('/proc/meminfo', 'r');
$mem_free = $mem_buff = $mem_cache = $mem_total = 0;
while ($line = fgets($fh)) {
$pieces = array();
if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_total = $pieces[1];
}
if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_free = $pieces[1];
}
if (preg_match('/^Buffers:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_buff = $pieces[1];
}
if (preg_match('/^Cached:\s+(\d+)\skB$/', $line, $pieces)) {
$mem_cache = $pieces[1];
break;
}
}
fclose($fh);
}
$result['used'] = round(($mem_total - ($mem_buff + $mem_cache + $mem_free)) * 100 / $mem_total);
$result['cache'] = round(($mem_cache + $mem_buff) * 100 / $mem_total);
$result['free'] = round($mem_free * 100 / $mem_total);
return $result;
} | [
"public",
"function",
"memory_stats",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"os",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT * FROM Win32_OperatingSystem\"",
")",
";",
"foreach",
"(",
"$",
"os",
"as",
"$",
"m",
")",
"{",
"$",
"mem_total",
"=",
"$",
"m",
"->",
"TotalVisibleMemorySize",
";",
"$",
"mem_free",
"=",
"$",
"m",
"->",
"FreePhysicalMemory",
";",
"}",
"$",
"prefMemory",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory\"",
")",
";",
"foreach",
"(",
"$",
"prefMemory",
"as",
"$",
"pm",
")",
"{",
"$",
"mem_cache",
"=",
"$",
"pm",
"->",
"CacheBytes",
"/",
"1024",
";",
"}",
"$",
"mem_buff",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"fh",
"=",
"fopen",
"(",
"'/proc/meminfo'",
",",
"'r'",
")",
";",
"$",
"mem_free",
"=",
"$",
"mem_buff",
"=",
"$",
"mem_cache",
"=",
"$",
"mem_total",
"=",
"0",
";",
"while",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"fh",
")",
")",
"{",
"$",
"pieces",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^MemTotal:\\s+(\\d+)\\skB$/'",
",",
"$",
"line",
",",
"$",
"pieces",
")",
")",
"{",
"$",
"mem_total",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^MemFree:\\s+(\\d+)\\skB$/'",
",",
"$",
"line",
",",
"$",
"pieces",
")",
")",
"{",
"$",
"mem_free",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^Buffers:\\s+(\\d+)\\skB$/'",
",",
"$",
"line",
",",
"$",
"pieces",
")",
")",
"{",
"$",
"mem_buff",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^Cached:\\s+(\\d+)\\skB$/'",
",",
"$",
"line",
",",
"$",
"pieces",
")",
")",
"{",
"$",
"mem_cache",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"break",
";",
"}",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"$",
"result",
"[",
"'used'",
"]",
"=",
"round",
"(",
"(",
"$",
"mem_total",
"-",
"(",
"$",
"mem_buff",
"+",
"$",
"mem_cache",
"+",
"$",
"mem_free",
")",
")",
"*",
"100",
"/",
"$",
"mem_total",
")",
";",
"$",
"result",
"[",
"'cache'",
"]",
"=",
"round",
"(",
"(",
"$",
"mem_cache",
"+",
"$",
"mem_buff",
")",
"*",
"100",
"/",
"$",
"mem_total",
")",
";",
"$",
"result",
"[",
"'free'",
"]",
"=",
"round",
"(",
"$",
"mem_free",
"*",
"100",
"/",
"$",
"mem_total",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Get memory usage
@return array | [
"Get",
"memory",
"usage"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L153-L198 | train |
plinker-rpc/system | src/System.php | System.memory_total | public function memory_total()
{
$mem_total = 0;
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $m) {
$mem_total = $m->TotalVisibleMemorySize;
}
} else {
$fh = fopen('/proc/meminfo', 'r');
while ($line = fgets($fh)) {
$pieces = array();
if (preg_match('/^MemTotal:\s+(\d+)\skB$/', trim($line), $pieces)) {
$mem_total = $pieces[1];
break;
}
}
fclose($fh);
}
return $mem_total;
} | php | public function memory_total()
{
$mem_total = 0;
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $m) {
$mem_total = $m->TotalVisibleMemorySize;
}
} else {
$fh = fopen('/proc/meminfo', 'r');
while ($line = fgets($fh)) {
$pieces = array();
if (preg_match('/^MemTotal:\s+(\d+)\skB$/', trim($line), $pieces)) {
$mem_total = $pieces[1];
break;
}
}
fclose($fh);
}
return $mem_total;
} | [
"public",
"function",
"memory_total",
"(",
")",
"{",
"$",
"mem_total",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"os",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT * FROM Win32_OperatingSystem\"",
")",
";",
"foreach",
"(",
"$",
"os",
"as",
"$",
"m",
")",
"{",
"$",
"mem_total",
"=",
"$",
"m",
"->",
"TotalVisibleMemorySize",
";",
"}",
"}",
"else",
"{",
"$",
"fh",
"=",
"fopen",
"(",
"'/proc/meminfo'",
",",
"'r'",
")",
";",
"while",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"fh",
")",
")",
"{",
"$",
"pieces",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^MemTotal:\\s+(\\d+)\\skB$/'",
",",
"trim",
"(",
"$",
"line",
")",
",",
"$",
"pieces",
")",
")",
"{",
"$",
"mem_total",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"break",
";",
"}",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"return",
"$",
"mem_total",
";",
"}"
] | Get memory total kB
@return int | [
"Get",
"memory",
"total",
"kB"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L205-L228 | train |
plinker-rpc/system | src/System.php | System.cpu_usage | public function cpu_usage()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$cpus = $wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor");
foreach ($cpus as $cpu) {
$return = $cpu->LoadPercentage;
}
} else {
$return = shell_exec('top -d 0.5 -b -n2 | grep "Cpu(s)"|tail -n 1 | awk \'{print $2 + $4}\'');
}
return trim($return);
} | php | public function cpu_usage()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$cpus = $wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor");
foreach ($cpus as $cpu) {
$return = $cpu->LoadPercentage;
}
} else {
$return = shell_exec('top -d 0.5 -b -n2 | grep "Cpu(s)"|tail -n 1 | awk \'{print $2 + $4}\'');
}
return trim($return);
} | [
"public",
"function",
"cpu_usage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"cpus",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT LoadPercentage FROM Win32_Processor\"",
")",
";",
"foreach",
"(",
"$",
"cpus",
"as",
"$",
"cpu",
")",
"{",
"$",
"return",
"=",
"$",
"cpu",
"->",
"LoadPercentage",
";",
"}",
"}",
"else",
"{",
"$",
"return",
"=",
"shell_exec",
"(",
"'top -d 0.5 -b -n2 | grep \"Cpu(s)\"|tail -n 1 | awk \\'{print $2 + $4}\\''",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"return",
")",
";",
"}"
] | Get CPU usage in percentage
@return int | [
"Get",
"CPU",
"usage",
"in",
"percentage"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L235-L248 | train |
plinker-rpc/system | src/System.php | System.netstat | public function netstat($parse = true)
{
$result = trim(shell_exec('netstat -pant'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
unset($lines[0]);
unset($lines[1]);
$columns = [
'Proto',
'Recv-Q',
'Send-Q',
'Local Address',
'Foreign Address',
'State',
'PID/Program',
'Process Name',
];
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | php | public function netstat($parse = true)
{
$result = trim(shell_exec('netstat -pant'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
unset($lines[0]);
unset($lines[1]);
$columns = [
'Proto',
'Recv-Q',
'Send-Q',
'Local Address',
'Foreign Address',
'State',
'PID/Program',
'Process Name',
];
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | [
"public",
"function",
"netstat",
"(",
"$",
"parse",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"trim",
"(",
"shell_exec",
"(",
"'netstat -pant'",
")",
")",
";",
"if",
"(",
"$",
"parse",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"result",
")",
";",
"unset",
"(",
"$",
"lines",
"[",
"0",
"]",
")",
";",
"unset",
"(",
"$",
"lines",
"[",
"1",
"]",
")",
";",
"$",
"columns",
"=",
"[",
"'Proto'",
",",
"'Recv-Q'",
",",
"'Send-Q'",
",",
"'Local Address'",
",",
"'Foreign Address'",
",",
"'State'",
",",
"'PID/Program'",
",",
"'Process Name'",
",",
"]",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"row",
"=>",
"$",
"line",
")",
"{",
"$",
"column",
"=",
"array_values",
"(",
"array_filter",
"(",
"explode",
"(",
"' '",
",",
"$",
"line",
")",
",",
"'strlen'",
")",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"col",
"=>",
"$",
"key",
")",
"{",
"$",
"result",
"[",
"$",
"row",
"]",
"[",
"$",
"key",
"]",
"=",
"@",
"$",
"column",
"[",
"$",
"col",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"array_values",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get netstat output
@return string | [
"Get",
"netstat",
"output"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L290-L321 | train |
plinker-rpc/system | src/System.php | System.arch | public function arch()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$cpu= $wmi->ExecQuery("Select * from Win32_Processor");
foreach ($cpu as $c) {
$arch = '32-bit';
$cpu_arch = $c->AddressWidth;
if ($cpu_arch != 32) {
$os = $wmi->ExecQuery("Select * from Win32_OperatingSystem");
foreach ($os as $o) {
if ($o->Version >= 6.0) {
$arch = objItem.OSArchitecture;
}
}
}
}
} else {
$arch = shell_exec('arch');
}
return trim($arch);
} | php | public function arch()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$cpu= $wmi->ExecQuery("Select * from Win32_Processor");
foreach ($cpu as $c) {
$arch = '32-bit';
$cpu_arch = $c->AddressWidth;
if ($cpu_arch != 32) {
$os = $wmi->ExecQuery("Select * from Win32_OperatingSystem");
foreach ($os as $o) {
if ($o->Version >= 6.0) {
$arch = objItem.OSArchitecture;
}
}
}
}
} else {
$arch = shell_exec('arch');
}
return trim($arch);
} | [
"public",
"function",
"arch",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"cpu",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"Select * from Win32_Processor\"",
")",
";",
"foreach",
"(",
"$",
"cpu",
"as",
"$",
"c",
")",
"{",
"$",
"arch",
"=",
"'32-bit'",
";",
"$",
"cpu_arch",
"=",
"$",
"c",
"->",
"AddressWidth",
";",
"if",
"(",
"$",
"cpu_arch",
"!=",
"32",
")",
"{",
"$",
"os",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"Select * from Win32_OperatingSystem\"",
")",
";",
"foreach",
"(",
"$",
"os",
"as",
"$",
"o",
")",
"{",
"if",
"(",
"$",
"o",
"->",
"Version",
">=",
"6.0",
")",
"{",
"$",
"arch",
"=",
"objItem",
".",
"OSArchitecture",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"arch",
"=",
"shell_exec",
"(",
"'arch'",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"arch",
")",
";",
"}"
] | Get system architecture
@return string | [
"Get",
"system",
"architecture"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L328-L352 | train |
plinker-rpc/system | src/System.php | System.hostname | public function hostname()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$computer = $wmi->ExecQuery("SELECT * FROM Win32_ComputerSystem");
foreach ($computer as $c) {
$hostname = $c->Name;
}
} else {
$hostname = shell_exec('hostname');
}
return trim($hostname);
} | php | public function hostname()
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$computer = $wmi->ExecQuery("SELECT * FROM Win32_ComputerSystem");
foreach ($computer as $c) {
$hostname = $c->Name;
}
} else {
$hostname = shell_exec('hostname');
}
return trim($hostname);
} | [
"public",
"function",
"hostname",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"computer",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT * FROM Win32_ComputerSystem\"",
")",
";",
"foreach",
"(",
"$",
"computer",
"as",
"$",
"c",
")",
"{",
"$",
"hostname",
"=",
"$",
"c",
"->",
"Name",
";",
"}",
"}",
"else",
"{",
"$",
"hostname",
"=",
"shell_exec",
"(",
"'hostname'",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"hostname",
")",
";",
"}"
] | Get system hostname
@return string | [
"Get",
"system",
"hostname"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L359-L372 | train |
plinker-rpc/system | src/System.php | System.logins | public function logins($parse = true)
{
$result = trim(shell_exec('last'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
// detect end by empty line space
$end = 0;
foreach ($lines as $no => $line) {
if (trim($line) == '') {
$end = $no;
break;
}
}
// filter out end lines
foreach (range($end, count($lines)) as $key) {
unset($lines[$key]);
}
// define columns
$columns = [
'User',
'Terminal',
'Display',
'Day',
'Month',
'Day Date',
'Day Time',
'-',
'Disconnected',
'Duration',
];
// generic match rows for columns and set into return
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
// fix
$fix = [];
foreach ($result as $key => $row) {
if ($row['User'] == 'reboot') {
$fix[] = [
'User' => 'Reboot',
'Terminal' => '',
'Date' => '',
'Disconnected' => '',
'Duration' => '',
];
} else {
if ($row['Duration'] == 'no') {
$row['Duration'] = '';
}
if ($row['Disconnected'] == '-') {
$row['Disconnected'] = '';
}
$fix[] = [
'User' => $row['User'],
'Terminal' => $row['Terminal'],
'Display' => $row['Display'],
'Date' => $row['Day'].' '.$row['Month'].' '.$row['Day Date'].' '.$row['Day Time'],
'Disconnected' => $row['Disconnected'],
'Duration' => trim($row['Duration'], '()'),
];
}
}
$result = $fix;
}
return $result;
} | php | public function logins($parse = true)
{
$result = trim(shell_exec('last'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
// detect end by empty line space
$end = 0;
foreach ($lines as $no => $line) {
if (trim($line) == '') {
$end = $no;
break;
}
}
// filter out end lines
foreach (range($end, count($lines)) as $key) {
unset($lines[$key]);
}
// define columns
$columns = [
'User',
'Terminal',
'Display',
'Day',
'Month',
'Day Date',
'Day Time',
'-',
'Disconnected',
'Duration',
];
// generic match rows for columns and set into return
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
// fix
$fix = [];
foreach ($result as $key => $row) {
if ($row['User'] == 'reboot') {
$fix[] = [
'User' => 'Reboot',
'Terminal' => '',
'Date' => '',
'Disconnected' => '',
'Duration' => '',
];
} else {
if ($row['Duration'] == 'no') {
$row['Duration'] = '';
}
if ($row['Disconnected'] == '-') {
$row['Disconnected'] = '';
}
$fix[] = [
'User' => $row['User'],
'Terminal' => $row['Terminal'],
'Display' => $row['Display'],
'Date' => $row['Day'].' '.$row['Month'].' '.$row['Day Date'].' '.$row['Day Time'],
'Disconnected' => $row['Disconnected'],
'Duration' => trim($row['Duration'], '()'),
];
}
}
$result = $fix;
}
return $result;
} | [
"public",
"function",
"logins",
"(",
"$",
"parse",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"trim",
"(",
"shell_exec",
"(",
"'last'",
")",
")",
";",
"if",
"(",
"$",
"parse",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"result",
")",
";",
"// detect end by empty line space",
"$",
"end",
"=",
"0",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"no",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"line",
")",
"==",
"''",
")",
"{",
"$",
"end",
"=",
"$",
"no",
";",
"break",
";",
"}",
"}",
"// filter out end lines",
"foreach",
"(",
"range",
"(",
"$",
"end",
",",
"count",
"(",
"$",
"lines",
")",
")",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"lines",
"[",
"$",
"key",
"]",
")",
";",
"}",
"// define columns",
"$",
"columns",
"=",
"[",
"'User'",
",",
"'Terminal'",
",",
"'Display'",
",",
"'Day'",
",",
"'Month'",
",",
"'Day Date'",
",",
"'Day Time'",
",",
"'-'",
",",
"'Disconnected'",
",",
"'Duration'",
",",
"]",
";",
"// generic match rows for columns and set into return",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"row",
"=>",
"$",
"line",
")",
"{",
"$",
"column",
"=",
"array_values",
"(",
"array_filter",
"(",
"explode",
"(",
"' '",
",",
"$",
"line",
")",
",",
"'strlen'",
")",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"col",
"=>",
"$",
"key",
")",
"{",
"$",
"result",
"[",
"$",
"row",
"]",
"[",
"$",
"key",
"]",
"=",
"@",
"$",
"column",
"[",
"$",
"col",
"]",
";",
"}",
"}",
"// fix",
"$",
"fix",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'User'",
"]",
"==",
"'reboot'",
")",
"{",
"$",
"fix",
"[",
"]",
"=",
"[",
"'User'",
"=>",
"'Reboot'",
",",
"'Terminal'",
"=>",
"''",
",",
"'Date'",
"=>",
"''",
",",
"'Disconnected'",
"=>",
"''",
",",
"'Duration'",
"=>",
"''",
",",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"row",
"[",
"'Duration'",
"]",
"==",
"'no'",
")",
"{",
"$",
"row",
"[",
"'Duration'",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"row",
"[",
"'Disconnected'",
"]",
"==",
"'-'",
")",
"{",
"$",
"row",
"[",
"'Disconnected'",
"]",
"=",
"''",
";",
"}",
"$",
"fix",
"[",
"]",
"=",
"[",
"'User'",
"=>",
"$",
"row",
"[",
"'User'",
"]",
",",
"'Terminal'",
"=>",
"$",
"row",
"[",
"'Terminal'",
"]",
",",
"'Display'",
"=>",
"$",
"row",
"[",
"'Display'",
"]",
",",
"'Date'",
"=>",
"$",
"row",
"[",
"'Day'",
"]",
".",
"' '",
".",
"$",
"row",
"[",
"'Month'",
"]",
".",
"' '",
".",
"$",
"row",
"[",
"'Day Date'",
"]",
".",
"' '",
".",
"$",
"row",
"[",
"'Day Time'",
"]",
",",
"'Disconnected'",
"=>",
"$",
"row",
"[",
"'Disconnected'",
"]",
",",
"'Duration'",
"=>",
"trim",
"(",
"$",
"row",
"[",
"'Duration'",
"]",
",",
"'()'",
")",
",",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"fix",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get system last logins
@return string | [
"Get",
"system",
"last",
"logins"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L379-L455 | train |
plinker-rpc/system | src/System.php | System.top | public function top($parse = true)
{
if (!file_exists($this->tmp_path.'/system')) {
mkdir($this->tmp_path.'/system', 0755, true);
}
shell_exec('top -n 1 -b > '.$this->tmp_path.'/system/top-output');
usleep(25000);
$result = trim(file_get_contents($this->tmp_path.'/system/top-output'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
// detect start by empty line space
$start = 0;
foreach ($lines as $no => $line) {
if (trim($line) == '') {
$start = $no;
break;
}
}
// filter out header lines
foreach (range(0, $start) as $key) {
unset($lines[$key]);
}
//remove column line
unset($lines[$start+1]);
// define columns
$columns = [
'PID',
'USER',
'PR',
'NI',
'VIRT',
'RES',
'SHR',
'S',
'%CPU',
'%MEM',
'TIME+',
'COMMAND'
];
// match rows for columns and set into return
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | php | public function top($parse = true)
{
if (!file_exists($this->tmp_path.'/system')) {
mkdir($this->tmp_path.'/system', 0755, true);
}
shell_exec('top -n 1 -b > '.$this->tmp_path.'/system/top-output');
usleep(25000);
$result = trim(file_get_contents($this->tmp_path.'/system/top-output'));
if ($parse) {
$lines = explode(PHP_EOL, $result);
// detect start by empty line space
$start = 0;
foreach ($lines as $no => $line) {
if (trim($line) == '') {
$start = $no;
break;
}
}
// filter out header lines
foreach (range(0, $start) as $key) {
unset($lines[$key]);
}
//remove column line
unset($lines[$start+1]);
// define columns
$columns = [
'PID',
'USER',
'PR',
'NI',
'VIRT',
'RES',
'SHR',
'S',
'%CPU',
'%MEM',
'TIME+',
'COMMAND'
];
// match rows for columns and set into return
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | [
"public",
"function",
"top",
"(",
"$",
"parse",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/system'",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/system'",
",",
"0755",
",",
"true",
")",
";",
"}",
"shell_exec",
"(",
"'top -n 1 -b > '",
".",
"$",
"this",
"->",
"tmp_path",
".",
"'/system/top-output'",
")",
";",
"usleep",
"(",
"25000",
")",
";",
"$",
"result",
"=",
"trim",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/system/top-output'",
")",
")",
";",
"if",
"(",
"$",
"parse",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"result",
")",
";",
"// detect start by empty line space",
"$",
"start",
"=",
"0",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"no",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"line",
")",
"==",
"''",
")",
"{",
"$",
"start",
"=",
"$",
"no",
";",
"break",
";",
"}",
"}",
"// filter out header lines",
"foreach",
"(",
"range",
"(",
"0",
",",
"$",
"start",
")",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"lines",
"[",
"$",
"key",
"]",
")",
";",
"}",
"//remove column line",
"unset",
"(",
"$",
"lines",
"[",
"$",
"start",
"+",
"1",
"]",
")",
";",
"// define columns",
"$",
"columns",
"=",
"[",
"'PID'",
",",
"'USER'",
",",
"'PR'",
",",
"'NI'",
",",
"'VIRT'",
",",
"'RES'",
",",
"'SHR'",
",",
"'S'",
",",
"'%CPU'",
",",
"'%MEM'",
",",
"'TIME+'",
",",
"'COMMAND'",
"]",
";",
"// match rows for columns and set into return",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"row",
"=>",
"$",
"line",
")",
"{",
"$",
"column",
"=",
"array_values",
"(",
"array_filter",
"(",
"explode",
"(",
"' '",
",",
"$",
"line",
")",
",",
"'strlen'",
")",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"col",
"=>",
"$",
"key",
")",
"{",
"$",
"result",
"[",
"$",
"row",
"]",
"[",
"$",
"key",
"]",
"=",
"@",
"$",
"column",
"[",
"$",
"col",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"array_values",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get system top output
@param string | [
"Get",
"system",
"top",
"output"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L472-L527 | train |
plinker-rpc/system | src/System.php | System.cpu_info | public function cpu_info($parse = true)
{
$lines = trim(shell_exec('lscpu'));
if (!$parse) {
return $lines;
}
if (empty($lines)) {
return [];
}
$lines = explode(PHP_EOL, $lines);
$return = [];
foreach ($lines as $line) {
$parts = explode(':', $line);
$return[trim($parts[0])] = trim($parts[1]);
}
return $return;
} | php | public function cpu_info($parse = true)
{
$lines = trim(shell_exec('lscpu'));
if (!$parse) {
return $lines;
}
if (empty($lines)) {
return [];
}
$lines = explode(PHP_EOL, $lines);
$return = [];
foreach ($lines as $line) {
$parts = explode(':', $line);
$return[trim($parts[0])] = trim($parts[1]);
}
return $return;
} | [
"public",
"function",
"cpu_info",
"(",
"$",
"parse",
"=",
"true",
")",
"{",
"$",
"lines",
"=",
"trim",
"(",
"shell_exec",
"(",
"'lscpu'",
")",
")",
";",
"if",
"(",
"!",
"$",
"parse",
")",
"{",
"return",
"$",
"lines",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"lines",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"lines",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"line",
")",
";",
"$",
"return",
"[",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"]",
"=",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Get system CPU info | [
"Get",
"system",
"CPU",
"info"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L553-L574 | train |
plinker-rpc/system | src/System.php | System.disks | public function disks($parse = true)
{
if ($this->host_os !== 'WINDOWS') {
$result = shell_exec('df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs');
} else {
$result = '';
}
if ($parse) {
if (empty($result)) {
return [];
}
$lines = explode(PHP_EOL, trim($result));
unset($lines[0]);
$columns = [
'Filesystem',
'Type',
'Size',
'Used',
'Avail',
'Used (%)',
'Mounted'
];
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | php | public function disks($parse = true)
{
if ($this->host_os !== 'WINDOWS') {
$result = shell_exec('df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs');
} else {
$result = '';
}
if ($parse) {
if (empty($result)) {
return [];
}
$lines = explode(PHP_EOL, trim($result));
unset($lines[0]);
$columns = [
'Filesystem',
'Type',
'Size',
'Used',
'Avail',
'Used (%)',
'Mounted'
];
$result = [];
foreach ($lines as $row => $line) {
$column = array_values(array_filter(explode(' ', $line), 'strlen'));
foreach ($columns as $col => $key) {
$result[$row][$key] = @$column[$col];
}
}
$result = array_values($result);
}
return $result;
} | [
"public",
"function",
"disks",
"(",
"$",
"parse",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"!==",
"'WINDOWS'",
")",
"{",
"$",
"result",
"=",
"shell_exec",
"(",
"'df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs'",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"parse",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"trim",
"(",
"$",
"result",
")",
")",
";",
"unset",
"(",
"$",
"lines",
"[",
"0",
"]",
")",
";",
"$",
"columns",
"=",
"[",
"'Filesystem'",
",",
"'Type'",
",",
"'Size'",
",",
"'Used'",
",",
"'Avail'",
",",
"'Used (%)'",
",",
"'Mounted'",
"]",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"row",
"=>",
"$",
"line",
")",
"{",
"$",
"column",
"=",
"array_values",
"(",
"array_filter",
"(",
"explode",
"(",
"' '",
",",
"$",
"line",
")",
",",
"'strlen'",
")",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"col",
"=>",
"$",
"key",
")",
"{",
"$",
"result",
"[",
"$",
"row",
"]",
"[",
"$",
"key",
"]",
"=",
"@",
"$",
"column",
"[",
"$",
"col",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"array_values",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get disk file system table
@return string | [
"Get",
"disk",
"file",
"system",
"table"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L623-L659 | train |
plinker-rpc/system | src/System.php | System.uptime | public function uptime($option = '-p')
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $o) {
$date = explode('.', $o->LastBootUpTime);
$uptime_date = DateTime::createFromFormat('YmdHis', $date[0]);
$now = DateTime::createFromFormat('U', time());
$interval = $uptime_date->diff($now);
$uptime = $interval->format('up %a days, %h hours, %i minutes');
}
} else {
$uptime = shell_exec('uptime '.$option);
}
return trim($uptime);
} | php | public function uptime($option = '-p')
{
if ($this->host_os === 'WINDOWS') {
$wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
$os = $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");
foreach ($os as $o) {
$date = explode('.', $o->LastBootUpTime);
$uptime_date = DateTime::createFromFormat('YmdHis', $date[0]);
$now = DateTime::createFromFormat('U', time());
$interval = $uptime_date->diff($now);
$uptime = $interval->format('up %a days, %h hours, %i minutes');
}
} else {
$uptime = shell_exec('uptime '.$option);
}
return trim($uptime);
} | [
"public",
"function",
"uptime",
"(",
"$",
"option",
"=",
"'-p'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"host_os",
"===",
"'WINDOWS'",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\"",
")",
";",
"$",
"os",
"=",
"$",
"wmi",
"->",
"ExecQuery",
"(",
"\"SELECT * FROM Win32_OperatingSystem\"",
")",
";",
"foreach",
"(",
"$",
"os",
"as",
"$",
"o",
")",
"{",
"$",
"date",
"=",
"explode",
"(",
"'.'",
",",
"$",
"o",
"->",
"LastBootUpTime",
")",
";",
"$",
"uptime_date",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"'YmdHis'",
",",
"$",
"date",
"[",
"0",
"]",
")",
";",
"$",
"now",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"'U'",
",",
"time",
"(",
")",
")",
";",
"$",
"interval",
"=",
"$",
"uptime_date",
"->",
"diff",
"(",
"$",
"now",
")",
";",
"$",
"uptime",
"=",
"$",
"interval",
"->",
"format",
"(",
"'up %a days, %h hours, %i minutes'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"uptime",
"=",
"shell_exec",
"(",
"'uptime '",
".",
"$",
"option",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"uptime",
")",
";",
"}"
] | Get system uptime | [
"Get",
"system",
"uptime"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L664-L682 | train |
plinker-rpc/system | src/System.php | System.ping | public function ping($host = '', $port = 80)
{
$start = microtime(true);
$file = @fsockopen($host, $port, $errno, $errstr, 5);
$stop = microtime(true);
$status = 0;
if (!$file) {
$status = -1;
} else {
fclose($file);
$status = round((($stop - $start) * 1000), 2);
}
return $status;
} | php | public function ping($host = '', $port = 80)
{
$start = microtime(true);
$file = @fsockopen($host, $port, $errno, $errstr, 5);
$stop = microtime(true);
$status = 0;
if (!$file) {
$status = -1;
} else {
fclose($file);
$status = round((($stop - $start) * 1000), 2);
}
return $status;
} | [
"public",
"function",
"ping",
"(",
"$",
"host",
"=",
"''",
",",
"$",
"port",
"=",
"80",
")",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"file",
"=",
"@",
"fsockopen",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"5",
")",
";",
"$",
"stop",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"status",
"=",
"0",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"$",
"status",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"fclose",
"(",
"$",
"file",
")",
";",
"$",
"status",
"=",
"round",
"(",
"(",
"(",
"$",
"stop",
"-",
"$",
"start",
")",
"*",
"1000",
")",
",",
"2",
")",
";",
"}",
"return",
"$",
"status",
";",
"}"
] | Ping a server and return timing
@return float | [
"Ping",
"a",
"server",
"and",
"return",
"timing"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L689-L703 | train |
plinker-rpc/system | src/System.php | System.distro | public function distro()
{
if (file_exists('/etc/redhat-release')) {
$centos_array = explode(' ', file_get_contents('/etc/redhat-release'));
return strtoupper($centos_array[0]);
}
if (file_exists('/etc/os-release')) {
preg_match('/ID=([a-zA-Z]+)/', file_get_contents('/etc/os-release'), $matches);
return strtoupper($matches[1]);
}
return false;
} | php | public function distro()
{
if (file_exists('/etc/redhat-release')) {
$centos_array = explode(' ', file_get_contents('/etc/redhat-release'));
return strtoupper($centos_array[0]);
}
if (file_exists('/etc/os-release')) {
preg_match('/ID=([a-zA-Z]+)/', file_get_contents('/etc/os-release'), $matches);
return strtoupper($matches[1]);
}
return false;
} | [
"public",
"function",
"distro",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"'/etc/redhat-release'",
")",
")",
"{",
"$",
"centos_array",
"=",
"explode",
"(",
"' '",
",",
"file_get_contents",
"(",
"'/etc/redhat-release'",
")",
")",
";",
"return",
"strtoupper",
"(",
"$",
"centos_array",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"'/etc/os-release'",
")",
")",
"{",
"preg_match",
"(",
"'/ID=([a-zA-Z]+)/'",
",",
"file_get_contents",
"(",
"'/etc/os-release'",
")",
",",
"$",
"matches",
")",
";",
"return",
"strtoupper",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get system distro
@return string | [
"Get",
"system",
"distro"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L710-L722 | train |
plinker-rpc/system | src/System.php | System.reboot | public function reboot()
{
if (!file_exists($this->tmp_path.'/reboot.sh')) {
file_put_contents($this->tmp_path.'/reboot.sh', '#!/bin/bash'.PHP_EOL.'/sbin/shutdown -r now');
chmod($this->tmp_path.'/reboot.sh', 0750);
}
shell_exec($this->tmp_path.'/reboot.sh');
return true;
} | php | public function reboot()
{
if (!file_exists($this->tmp_path.'/reboot.sh')) {
file_put_contents($this->tmp_path.'/reboot.sh', '#!/bin/bash'.PHP_EOL.'/sbin/shutdown -r now');
chmod($this->tmp_path.'/reboot.sh', 0750);
}
shell_exec($this->tmp_path.'/reboot.sh');
return true;
} | [
"public",
"function",
"reboot",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/reboot.sh'",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/reboot.sh'",
",",
"'#!/bin/bash'",
".",
"PHP_EOL",
".",
"'/sbin/shutdown -r now'",
")",
";",
"chmod",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/reboot.sh'",
",",
"0750",
")",
";",
"}",
"shell_exec",
"(",
"$",
"this",
"->",
"tmp_path",
".",
"'/reboot.sh'",
")",
";",
"return",
"true",
";",
"}"
] | Reboot the system
@requires root
@return void | [
"Reboot",
"the",
"system"
] | b0b83aad136a91c094eaac8c463df7c916d1c76e | https://github.com/plinker-rpc/system/blob/b0b83aad136a91c094eaac8c463df7c916d1c76e/src/System.php#L763-L771 | train |
QoboLtd/cakephp-translations | src/Model/Table/LanguagesTable.php | LanguagesTable.localeToLanguage | public function localeToLanguage(string $locale): string
{
if (empty($locale)) {
throw new InvalidArgumentException("Locale must be a non-emptystring.");
}
// Truncate all, starting with underscore, at, or dot
$result = (string)preg_replace('/(_|@|\.).*$/', '', strtolower($locale));
// Convert to lowercase for consistency
$result = strtolower($result);
return $result;
} | php | public function localeToLanguage(string $locale): string
{
if (empty($locale)) {
throw new InvalidArgumentException("Locale must be a non-emptystring.");
}
// Truncate all, starting with underscore, at, or dot
$result = (string)preg_replace('/(_|@|\.).*$/', '', strtolower($locale));
// Convert to lowercase for consistency
$result = strtolower($result);
return $result;
} | [
"public",
"function",
"localeToLanguage",
"(",
"string",
"$",
"locale",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"locale",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Locale must be a non-emptystring.\"",
")",
";",
"}",
"// Truncate all, starting with underscore, at, or dot",
"$",
"result",
"=",
"(",
"string",
")",
"preg_replace",
"(",
"'/(_|@|\\.).*$/'",
",",
"''",
",",
"strtolower",
"(",
"$",
"locale",
")",
")",
";",
"// Convert to lowercase for consistency",
"$",
"result",
"=",
"strtolower",
"(",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Convert locale to language
On Linux, have a look at /usr/share/locale for the
list of possible locales and locale formats.
@throws \InvalidArgumentException when locale is not a string
@param string $locale Locale string (example: ru_RU.KOI8-R)
@return string Language (example: ru) | [
"Convert",
"locale",
"to",
"language"
] | b488eafce71a55d517b975342487812f0d2d375a | https://github.com/QoboLtd/cakephp-translations/blob/b488eafce71a55d517b975342487812f0d2d375a/src/Model/Table/LanguagesTable.php#L97-L109 | train |
QoboLtd/cakephp-translations | src/Model/Table/LanguagesTable.php | LanguagesTable.isRtl | public function isRtl(string $language): bool
{
$result = false;
// Simplify and verify, just in case
$language = $this->localeToLanguage($language);
if (in_array($language, $this->getRtl())) {
$result = true;
}
return $result;
} | php | public function isRtl(string $language): bool
{
$result = false;
// Simplify and verify, just in case
$language = $this->localeToLanguage($language);
if (in_array($language, $this->getRtl())) {
$result = true;
}
return $result;
} | [
"public",
"function",
"isRtl",
"(",
"string",
"$",
"language",
")",
":",
"bool",
"{",
"$",
"result",
"=",
"false",
";",
"// Simplify and verify, just in case",
"$",
"language",
"=",
"$",
"this",
"->",
"localeToLanguage",
"(",
"$",
"language",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"language",
",",
"$",
"this",
"->",
"getRtl",
"(",
")",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Check if given language is right-to-left
@param string $language Language code or locale string (example: ru_RU.KOI8-R)
@return bool | [
"Check",
"if",
"given",
"language",
"is",
"right",
"-",
"to",
"-",
"left"
] | b488eafce71a55d517b975342487812f0d2d375a | https://github.com/QoboLtd/cakephp-translations/blob/b488eafce71a55d517b975342487812f0d2d375a/src/Model/Table/LanguagesTable.php#L129-L140 | train |
QoboLtd/cakephp-translations | src/Model/Table/LanguagesTable.php | LanguagesTable.getAvailable | public function getAvailable(): array
{
$result = [];
$dbLanguages = $this->find('list', ['keyField' => 'code', 'valueField' => 'name'])
->where(['trashed IS' => null])
->toArray();
$supportedLanguages = $this->getSupported();
$result = array_diff_assoc($supportedLanguages, $dbLanguages);
return $result;
} | php | public function getAvailable(): array
{
$result = [];
$dbLanguages = $this->find('list', ['keyField' => 'code', 'valueField' => 'name'])
->where(['trashed IS' => null])
->toArray();
$supportedLanguages = $this->getSupported();
$result = array_diff_assoc($supportedLanguages, $dbLanguages);
return $result;
} | [
"public",
"function",
"getAvailable",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"dbLanguages",
"=",
"$",
"this",
"->",
"find",
"(",
"'list'",
",",
"[",
"'keyField'",
"=>",
"'code'",
",",
"'valueField'",
"=>",
"'name'",
"]",
")",
"->",
"where",
"(",
"[",
"'trashed IS'",
"=>",
"null",
"]",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"supportedLanguages",
"=",
"$",
"this",
"->",
"getSupported",
"(",
")",
";",
"$",
"result",
"=",
"array_diff_assoc",
"(",
"$",
"supportedLanguages",
",",
"$",
"dbLanguages",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Get a list of all available languages
Available languages are those that are in
configuration, but haven't yet been used for
an active language.
@return mixed[] | [
"Get",
"a",
"list",
"of",
"all",
"available",
"languages"
] | b488eafce71a55d517b975342487812f0d2d375a | https://github.com/QoboLtd/cakephp-translations/blob/b488eafce71a55d517b975342487812f0d2d375a/src/Model/Table/LanguagesTable.php#L163-L174 | train |
QoboLtd/cakephp-translations | src/Model/Table/LanguagesTable.php | LanguagesTable.getName | public function getName(string $code): string
{
$result = $code;
if (empty($code)) {
throw new InvalidArgumentException("Code must be a non-empty string.");
}
$languages = $this->getSupported();
if (!empty($languages[$code])) {
$result = $languages[$code];
}
return $result;
} | php | public function getName(string $code): string
{
$result = $code;
if (empty($code)) {
throw new InvalidArgumentException("Code must be a non-empty string.");
}
$languages = $this->getSupported();
if (!empty($languages[$code])) {
$result = $languages[$code];
}
return $result;
} | [
"public",
"function",
"getName",
"(",
"string",
"$",
"code",
")",
":",
"string",
"{",
"$",
"result",
"=",
"$",
"code",
";",
"if",
"(",
"empty",
"(",
"$",
"code",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Code must be a non-empty string.\"",
")",
";",
"}",
"$",
"languages",
"=",
"$",
"this",
"->",
"getSupported",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"languages",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"languages",
"[",
"$",
"code",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get language name by code
@throws \InvalidArgumentException when code is not a string
@param string $code Language code to lookup
@return string | [
"Get",
"language",
"name",
"by",
"code"
] | b488eafce71a55d517b975342487812f0d2d375a | https://github.com/QoboLtd/cakephp-translations/blob/b488eafce71a55d517b975342487812f0d2d375a/src/Model/Table/LanguagesTable.php#L183-L197 | train |
QoboLtd/cakephp-translations | src/Model/Table/LanguagesTable.php | LanguagesTable.addOrRestore | public function addOrRestore(array $data): \Translations\Model\Entity\Language
{
if (empty($data['code'])) {
throw new InvalidArgumentException("Language data is missing 'code' key");
}
if (empty($data['is_rtl'])) {
$data['is_rtl'] = $this->isRtl($data['code']);
}
if (empty($data['name'])) {
$data['name'] = $this->getName($data['code']);
}
/**
* @var \Cake\Datasource\EntityInterface $deletedEntity
*/
$deletedEntity = $this->find('onlyTrashed')
->where(['code' => $data['code']])
->first();
if (!empty($deletedEntity)) {
return $this->restoreTrash($deletedEntity);
}
$newEntity = $this->newEntity();
$newEntity = $this->patchEntity($newEntity, $data);
/**
* @var \Translations\Model\Entity\Language $result
*/
$result = $this->save($newEntity);
return $result;
} | php | public function addOrRestore(array $data): \Translations\Model\Entity\Language
{
if (empty($data['code'])) {
throw new InvalidArgumentException("Language data is missing 'code' key");
}
if (empty($data['is_rtl'])) {
$data['is_rtl'] = $this->isRtl($data['code']);
}
if (empty($data['name'])) {
$data['name'] = $this->getName($data['code']);
}
/**
* @var \Cake\Datasource\EntityInterface $deletedEntity
*/
$deletedEntity = $this->find('onlyTrashed')
->where(['code' => $data['code']])
->first();
if (!empty($deletedEntity)) {
return $this->restoreTrash($deletedEntity);
}
$newEntity = $this->newEntity();
$newEntity = $this->patchEntity($newEntity, $data);
/**
* @var \Translations\Model\Entity\Language $result
*/
$result = $this->save($newEntity);
return $result;
} | [
"public",
"function",
"addOrRestore",
"(",
"array",
"$",
"data",
")",
":",
"\\",
"Translations",
"\\",
"Model",
"\\",
"Entity",
"\\",
"Language",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'code'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Language data is missing 'code' key\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'is_rtl'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'is_rtl'",
"]",
"=",
"$",
"this",
"->",
"isRtl",
"(",
"$",
"data",
"[",
"'code'",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"getName",
"(",
"$",
"data",
"[",
"'code'",
"]",
")",
";",
"}",
"/**\n * @var \\Cake\\Datasource\\EntityInterface $deletedEntity\n */",
"$",
"deletedEntity",
"=",
"$",
"this",
"->",
"find",
"(",
"'onlyTrashed'",
")",
"->",
"where",
"(",
"[",
"'code'",
"=>",
"$",
"data",
"[",
"'code'",
"]",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"deletedEntity",
")",
")",
"{",
"return",
"$",
"this",
"->",
"restoreTrash",
"(",
"$",
"deletedEntity",
")",
";",
"}",
"$",
"newEntity",
"=",
"$",
"this",
"->",
"newEntity",
"(",
")",
";",
"$",
"newEntity",
"=",
"$",
"this",
"->",
"patchEntity",
"(",
"$",
"newEntity",
",",
"$",
"data",
")",
";",
"/**\n * @var \\Translations\\Model\\Entity\\Language $result\n */",
"$",
"result",
"=",
"$",
"this",
"->",
"save",
"(",
"$",
"newEntity",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Add a new language or restore a deleted one
@throws \InvalidArgumentException when data is wrong or incomplete
@param mixed[] $data Language data to populate Entity with
@return \Translations\Model\Entity\Language | [
"Add",
"a",
"new",
"language",
"or",
"restore",
"a",
"deleted",
"one"
] | b488eafce71a55d517b975342487812f0d2d375a | https://github.com/QoboLtd/cakephp-translations/blob/b488eafce71a55d517b975342487812f0d2d375a/src/Model/Table/LanguagesTable.php#L206-L239 | train |
chilimatic/chilimatic-framework | lib/cgenerator/Mysql.php | Mysql.scan_table | public function scan_table($table_name = '')
{
if (empty($table_name)) return false;
$this->_l_table_name = strtolower($table_name);
$this->table_name = $table_name;
$this->tpl_replacements['table_name'] = $table_name;
// get a more detailed description of the table
$sql = "SHOW FULL COLUMNS FROM `$table_name`";
$res = $this->db->query($sql);
$this->table_model = $this->db->fetch_object_list($res);
return true;
} | php | public function scan_table($table_name = '')
{
if (empty($table_name)) return false;
$this->_l_table_name = strtolower($table_name);
$this->table_name = $table_name;
$this->tpl_replacements['table_name'] = $table_name;
// get a more detailed description of the table
$sql = "SHOW FULL COLUMNS FROM `$table_name`";
$res = $this->db->query($sql);
$this->table_model = $this->db->fetch_object_list($res);
return true;
} | [
"public",
"function",
"scan_table",
"(",
"$",
"table_name",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"table_name",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"_l_table_name",
"=",
"strtolower",
"(",
"$",
"table_name",
")",
";",
"$",
"this",
"->",
"table_name",
"=",
"$",
"table_name",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'table_name'",
"]",
"=",
"$",
"table_name",
";",
"// get a more detailed description of the table",
"$",
"sql",
"=",
"\"SHOW FULL COLUMNS FROM `$table_name`\"",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"table_model",
"=",
"$",
"this",
"->",
"db",
"->",
"fetch_object_list",
"(",
"$",
"res",
")",
";",
"return",
"true",
";",
"}"
] | fetches a numeric table list
@param $table_name string
@return boolean | [
"fetches",
"a",
"numeric",
"table",
"list"
] | 8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12 | https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/cgenerator/Mysql.php#L92-L107 | train |
chilimatic/chilimatic-framework | lib/cgenerator/Mysql.php | Mysql.get_type_value | public function get_type_value($type = null, $type_cast = false)
{
if (empty($type)) return "null";
if (strpos(strtolower($type), 'int') !== false) {
return ($type_cast) ? '(int)' : 0;
}
if (strpos(strtolower($type), 'float') !== false) {
return ($type_cast) ? '(float)' : 0;
}
if (strpos(strtolower($type), 'char') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'enum') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'dec') !== false) {
return ($type_cast) ? '(float)' : 0;
}
if (strpos(strtolower($type), 'text') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'bit') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'bool') !== false) {
return ($type_cast) ? '(boolean)' : "false";
}
if (strpos(strtolower($type), 'datetime') !== false) {
return ($type_cast) ? '(string)' : "'0000-00-00 00:00:00'";
}
if (strpos(strtolower($type), 'date') !== false) {
return ($type_cast) ? '(string)' : "'0000-00-00'";
}
if (strpos(strtolower($type), 'year') !== false) {
return ($type_cast) ? '(string)' : "'0000'";
}
if (strpos(strtolower($type), 'time') !== false) {
return ($type_cast) ? '(int)' : 0;
}
if (strpos(strtolower($type), 'double')) {
return ($type_cast) ? '(double)' : 0;
}
return "null";
} | php | public function get_type_value($type = null, $type_cast = false)
{
if (empty($type)) return "null";
if (strpos(strtolower($type), 'int') !== false) {
return ($type_cast) ? '(int)' : 0;
}
if (strpos(strtolower($type), 'float') !== false) {
return ($type_cast) ? '(float)' : 0;
}
if (strpos(strtolower($type), 'char') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'enum') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'dec') !== false) {
return ($type_cast) ? '(float)' : 0;
}
if (strpos(strtolower($type), 'text') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'bit') !== false) {
return ($type_cast) ? '(string)' : "''";
}
if (strpos(strtolower($type), 'bool') !== false) {
return ($type_cast) ? '(boolean)' : "false";
}
if (strpos(strtolower($type), 'datetime') !== false) {
return ($type_cast) ? '(string)' : "'0000-00-00 00:00:00'";
}
if (strpos(strtolower($type), 'date') !== false) {
return ($type_cast) ? '(string)' : "'0000-00-00'";
}
if (strpos(strtolower($type), 'year') !== false) {
return ($type_cast) ? '(string)' : "'0000'";
}
if (strpos(strtolower($type), 'time') !== false) {
return ($type_cast) ? '(int)' : 0;
}
if (strpos(strtolower($type), 'double')) {
return ($type_cast) ? '(double)' : 0;
}
return "null";
} | [
"public",
"function",
"get_type_value",
"(",
"$",
"type",
"=",
"null",
",",
"$",
"type_cast",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"return",
"\"null\"",
";",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'int'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(int)'",
":",
"0",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'float'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(float)'",
":",
"0",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'char'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"''\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'enum'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"''\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'dec'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(float)'",
":",
"0",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'text'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"''\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'bit'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"''\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'bool'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(boolean)'",
":",
"\"false\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'datetime'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"'0000-00-00 00:00:00'\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'date'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"'0000-00-00'\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'year'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(string)'",
":",
"\"'0000'\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'time'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(int)'",
":",
"0",
";",
"}",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"'double'",
")",
")",
"{",
"return",
"(",
"$",
"type_cast",
")",
"?",
"'(double)'",
":",
"0",
";",
"}",
"return",
"\"null\"",
";",
"}"
] | get type value parses the mysql type and returns
@param $type string
@param bool|string $type_cast string
@return string | [
"get",
"type",
"value",
"parses",
"the",
"mysql",
"type",
"and",
"returns"
] | 8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12 | https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/cgenerator/Mysql.php#L118-L176 | train |
chilimatic/chilimatic-framework | lib/cgenerator/Mysql.php | Mysql.generate_primary_key_statement | public function generate_primary_key_statement()
{
if (empty($this->primary_key)) return false;
if (count($this->primary_key) == 1) {
$this->tpl_replacements['primary_key_assign_statement'] = "'{$this->primary_key[0]}'";
$this->tpl_replacements['primary_key_if_statement'] = 'empty($this->' . (string)strtolower((string)$this->primary_key[0]) . ')';
$this->tpl_replacements['primary_key_where_statement'] = ' `' . (string)$this->primary_key[0] . '` = \'{$this->' . (string)strtolower((string)$this->primary_key[0]) . '}\'';
$this->tpl_replacements['primary_key_method_statement'] = '$' . strtolower((string)$this->primary_key[0]) . " = null";
return true;
}
$this->tpl_replacements['primary_key_assign_statement'] = 'array(';
foreach ($this->primary_key as $p_key) {
$this->tpl_replacements['primary_key_assign_statement'] .= "'$p_key',";
$this->tpl_replacements['primary_key_if_statement'] .= ' || empty($this->' . (string)strtolower((string)$p_key) . ')';
$this->tpl_replacements['primary_key_where_statement'] .= ' AND `' . (string)$p_key . '` = \'{$this->' . (string)strtolower((string)$p_key) . '}\'';
$this->tpl_replacements['primary_key_method_statement'] .= '$' . (string)strtolower((string)$p_key) . " = null,";
}
$this->tpl_replacements['primary_key_if_statement'] = substr($this->primary_key_if_statement, 4);
$this->tpl_replacements['primary_key_assign_statement'] = substr($this->primary_key_assign_statement, 0, -1) . ')';
$this->tpl_replacements['primary_key_method_statement'] = substr($this->primary_key_method_statement, 0, -1);
$this->tpl_replacements['primary_key_where_statement'] = substr($this->primary_key_where_statement, 5);
return true;
} | php | public function generate_primary_key_statement()
{
if (empty($this->primary_key)) return false;
if (count($this->primary_key) == 1) {
$this->tpl_replacements['primary_key_assign_statement'] = "'{$this->primary_key[0]}'";
$this->tpl_replacements['primary_key_if_statement'] = 'empty($this->' . (string)strtolower((string)$this->primary_key[0]) . ')';
$this->tpl_replacements['primary_key_where_statement'] = ' `' . (string)$this->primary_key[0] . '` = \'{$this->' . (string)strtolower((string)$this->primary_key[0]) . '}\'';
$this->tpl_replacements['primary_key_method_statement'] = '$' . strtolower((string)$this->primary_key[0]) . " = null";
return true;
}
$this->tpl_replacements['primary_key_assign_statement'] = 'array(';
foreach ($this->primary_key as $p_key) {
$this->tpl_replacements['primary_key_assign_statement'] .= "'$p_key',";
$this->tpl_replacements['primary_key_if_statement'] .= ' || empty($this->' . (string)strtolower((string)$p_key) . ')';
$this->tpl_replacements['primary_key_where_statement'] .= ' AND `' . (string)$p_key . '` = \'{$this->' . (string)strtolower((string)$p_key) . '}\'';
$this->tpl_replacements['primary_key_method_statement'] .= '$' . (string)strtolower((string)$p_key) . " = null,";
}
$this->tpl_replacements['primary_key_if_statement'] = substr($this->primary_key_if_statement, 4);
$this->tpl_replacements['primary_key_assign_statement'] = substr($this->primary_key_assign_statement, 0, -1) . ')';
$this->tpl_replacements['primary_key_method_statement'] = substr($this->primary_key_method_statement, 0, -1);
$this->tpl_replacements['primary_key_where_statement'] = substr($this->primary_key_where_statement, 5);
return true;
} | [
"public",
"function",
"generate_primary_key_statement",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"primary_key",
")",
")",
"return",
"false",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"primary_key",
")",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_assign_statement'",
"]",
"=",
"\"'{$this->primary_key[0]}'\"",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_if_statement'",
"]",
"=",
"'empty($this->'",
".",
"(",
"string",
")",
"strtolower",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"primary_key",
"[",
"0",
"]",
")",
".",
"')'",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_where_statement'",
"]",
"=",
"' `'",
".",
"(",
"string",
")",
"$",
"this",
"->",
"primary_key",
"[",
"0",
"]",
".",
"'` = \\'{$this->'",
".",
"(",
"string",
")",
"strtolower",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"primary_key",
"[",
"0",
"]",
")",
".",
"'}\\''",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_method_statement'",
"]",
"=",
"'$'",
".",
"strtolower",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"primary_key",
"[",
"0",
"]",
")",
".",
"\" = null\"",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_assign_statement'",
"]",
"=",
"'array('",
";",
"foreach",
"(",
"$",
"this",
"->",
"primary_key",
"as",
"$",
"p_key",
")",
"{",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_assign_statement'",
"]",
".=",
"\"'$p_key',\"",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_if_statement'",
"]",
".=",
"' || empty($this->'",
".",
"(",
"string",
")",
"strtolower",
"(",
"(",
"string",
")",
"$",
"p_key",
")",
".",
"')'",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_where_statement'",
"]",
".=",
"' AND `'",
".",
"(",
"string",
")",
"$",
"p_key",
".",
"'` = \\'{$this->'",
".",
"(",
"string",
")",
"strtolower",
"(",
"(",
"string",
")",
"$",
"p_key",
")",
".",
"'}\\''",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_method_statement'",
"]",
".=",
"'$'",
".",
"(",
"string",
")",
"strtolower",
"(",
"(",
"string",
")",
"$",
"p_key",
")",
".",
"\" = null,\"",
";",
"}",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_if_statement'",
"]",
"=",
"substr",
"(",
"$",
"this",
"->",
"primary_key_if_statement",
",",
"4",
")",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_assign_statement'",
"]",
"=",
"substr",
"(",
"$",
"this",
"->",
"primary_key_assign_statement",
",",
"0",
",",
"-",
"1",
")",
".",
"')'",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_method_statement'",
"]",
"=",
"substr",
"(",
"$",
"this",
"->",
"primary_key_method_statement",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"this",
"->",
"tpl_replacements",
"[",
"'primary_key_where_statement'",
"]",
"=",
"substr",
"(",
"$",
"this",
"->",
"primary_key_where_statement",
",",
"5",
")",
";",
"return",
"true",
";",
"}"
] | generates the primary key statement
@return bool | [
"generates",
"the",
"primary",
"key",
"statement"
] | 8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12 | https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/cgenerator/Mysql.php#L183-L210 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Amqp/Helper/Config.php | Radial_Amqp_Helper_Config.getQueueConfigurationScopes | public function getQueueConfigurationScopes()
{
// cache of seen, unique AMQP configurations
$configurations = array();
// list of stores to produce unique AMQP configuration
$uniqueStores = array();
foreach (Mage::app()->getStores(true) as $store) {
$amqpConfig = $this->getStoreLevelAmqpConfigurations($store);
if (!in_array($amqpConfig, $configurations, true)) {
$configurations[] = $amqpConfig;
$uniqueStores[] = $store;
}
}
return $uniqueStores;
} | php | public function getQueueConfigurationScopes()
{
// cache of seen, unique AMQP configurations
$configurations = array();
// list of stores to produce unique AMQP configuration
$uniqueStores = array();
foreach (Mage::app()->getStores(true) as $store) {
$amqpConfig = $this->getStoreLevelAmqpConfigurations($store);
if (!in_array($amqpConfig, $configurations, true)) {
$configurations[] = $amqpConfig;
$uniqueStores[] = $store;
}
}
return $uniqueStores;
} | [
"public",
"function",
"getQueueConfigurationScopes",
"(",
")",
"{",
"// cache of seen, unique AMQP configurations",
"$",
"configurations",
"=",
"array",
"(",
")",
";",
"// list of stores to produce unique AMQP configuration",
"$",
"uniqueStores",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"Mage",
"::",
"app",
"(",
")",
"->",
"getStores",
"(",
"true",
")",
"as",
"$",
"store",
")",
"{",
"$",
"amqpConfig",
"=",
"$",
"this",
"->",
"getStoreLevelAmqpConfigurations",
"(",
"$",
"store",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"amqpConfig",
",",
"$",
"configurations",
",",
"true",
")",
")",
"{",
"$",
"configurations",
"[",
"]",
"=",
"$",
"amqpConfig",
";",
"$",
"uniqueStores",
"[",
"]",
"=",
"$",
"store",
";",
"}",
"}",
"return",
"$",
"uniqueStores",
";",
"}"
] | Get an array of stores with unique AMQP configuration.
@return Mage_Core_Model_Store[] | [
"Get",
"an",
"array",
"of",
"stores",
"with",
"unique",
"AMQP",
"configuration",
"."
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Amqp/Helper/Config.php#L58-L72 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Amqp/Helper/Config.php | Radial_Amqp_Helper_Config.updateLastTimestamp | public function updateLastTimestamp(ITestMessage $payload, Mage_Core_Model_Store $store)
{
list($scope, $scopeId) = $this->getScopeForStoreSettings($store);
return Mage::getModel('core/config_data')
->addData(array(
'path' => $this->_amqpConfigMap->getPathForKey('last_test_message_timestamp'),
'value' => $payload->getTimestamp()->format(self::TIMESTAMP_FORMAT),
'scope' => $scope,
'scope_id' => $scopeId,
))
->save();
} | php | public function updateLastTimestamp(ITestMessage $payload, Mage_Core_Model_Store $store)
{
list($scope, $scopeId) = $this->getScopeForStoreSettings($store);
return Mage::getModel('core/config_data')
->addData(array(
'path' => $this->_amqpConfigMap->getPathForKey('last_test_message_timestamp'),
'value' => $payload->getTimestamp()->format(self::TIMESTAMP_FORMAT),
'scope' => $scope,
'scope_id' => $scopeId,
))
->save();
} | [
"public",
"function",
"updateLastTimestamp",
"(",
"ITestMessage",
"$",
"payload",
",",
"Mage_Core_Model_Store",
"$",
"store",
")",
"{",
"list",
"(",
"$",
"scope",
",",
"$",
"scopeId",
")",
"=",
"$",
"this",
"->",
"getScopeForStoreSettings",
"(",
"$",
"store",
")",
";",
"return",
"Mage",
"::",
"getModel",
"(",
"'core/config_data'",
")",
"->",
"addData",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"this",
"->",
"_amqpConfigMap",
"->",
"getPathForKey",
"(",
"'last_test_message_timestamp'",
")",
",",
"'value'",
"=>",
"$",
"payload",
"->",
"getTimestamp",
"(",
")",
"->",
"format",
"(",
"self",
"::",
"TIMESTAMP_FORMAT",
")",
",",
"'scope'",
"=>",
"$",
"scope",
",",
"'scope_id'",
"=>",
"$",
"scopeId",
",",
")",
")",
"->",
"save",
"(",
")",
";",
"}"
] | Update the core_config_data setting for timestamp from the last test
message received. Value should be saved in the most appropriate scope for
the store being processed. E.g. if the store is the default store, or has
the same AMQP configuration as the default store, the timestamp should be
updated in the default scope. If the stores AMQP configuration matches a
website level configuration, should be saved within that website's scope.
@param ITestMessage $payload
@param Mage_Core_Model_Store $store
@return Mage_Core_Model_Config_Data | [
"Update",
"the",
"core_config_data",
"setting",
"for",
"timestamp",
"from",
"the",
"last",
"test",
"message",
"received",
".",
"Value",
"should",
"be",
"saved",
"in",
"the",
"most",
"appropriate",
"scope",
"for",
"the",
"store",
"being",
"processed",
".",
"E",
".",
"g",
".",
"if",
"the",
"store",
"is",
"the",
"default",
"store",
"or",
"has",
"the",
"same",
"AMQP",
"configuration",
"as",
"the",
"default",
"store",
"the",
"timestamp",
"should",
"be",
"updated",
"in",
"the",
"default",
"scope",
".",
"If",
"the",
"stores",
"AMQP",
"configuration",
"matches",
"a",
"website",
"level",
"configuration",
"should",
"be",
"saved",
"within",
"that",
"website",
"s",
"scope",
"."
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Amqp/Helper/Config.php#L123-L134 | train |
romaricdrigon/OrchestraBundle | Controller/GenericController.php | GenericController.listAction | public function listAction(RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, EntityReflectionInterface $entity)
{
$name = $this->get('orchestra.resolver.repository_name')->getName($repository_definition);
if (false === $entity->isListable()) {
throw new DomainErrorException('Entity '.$entity->getName().' is not listable. Maybe you forgot to implement ListableEntityInterface?');
}
// Get objects to show
$objects = $repository->listing();
// Do not use empty, Doctrine Collection does not support it, only count
$noData = (0 === count($objects));
// We will also need titles for our table header
$headers = [];
if (false === $noData) {
$headers = $this->get('orchestra.resolver.listing_header')->getHeaders($objects[0], 'viewListing');
}
// Finally, we need the routes for each entity
$actions = $this->get('orchestra.core_entity.action_collection_builder')->build($entity);
return $this->render('RomaricDrigonOrchestraBundle:Generic:list.html.twig', [
'actions' => $actions,
'headers' => $headers,
'no_data' => $noData,
'objects' => $objects,
'title' => $name
]);
} | php | public function listAction(RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, EntityReflectionInterface $entity)
{
$name = $this->get('orchestra.resolver.repository_name')->getName($repository_definition);
if (false === $entity->isListable()) {
throw new DomainErrorException('Entity '.$entity->getName().' is not listable. Maybe you forgot to implement ListableEntityInterface?');
}
// Get objects to show
$objects = $repository->listing();
// Do not use empty, Doctrine Collection does not support it, only count
$noData = (0 === count($objects));
// We will also need titles for our table header
$headers = [];
if (false === $noData) {
$headers = $this->get('orchestra.resolver.listing_header')->getHeaders($objects[0], 'viewListing');
}
// Finally, we need the routes for each entity
$actions = $this->get('orchestra.core_entity.action_collection_builder')->build($entity);
return $this->render('RomaricDrigonOrchestraBundle:Generic:list.html.twig', [
'actions' => $actions,
'headers' => $headers,
'no_data' => $noData,
'objects' => $objects,
'title' => $name
]);
} | [
"public",
"function",
"listAction",
"(",
"RepositoryDefinitionInterface",
"$",
"repository_definition",
",",
"RepositoryInterface",
"$",
"repository",
",",
"EntityReflectionInterface",
"$",
"entity",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.resolver.repository_name'",
")",
"->",
"getName",
"(",
"$",
"repository_definition",
")",
";",
"if",
"(",
"false",
"===",
"$",
"entity",
"->",
"isListable",
"(",
")",
")",
"{",
"throw",
"new",
"DomainErrorException",
"(",
"'Entity '",
".",
"$",
"entity",
"->",
"getName",
"(",
")",
".",
"' is not listable. Maybe you forgot to implement ListableEntityInterface?'",
")",
";",
"}",
"// Get objects to show",
"$",
"objects",
"=",
"$",
"repository",
"->",
"listing",
"(",
")",
";",
"// Do not use empty, Doctrine Collection does not support it, only count",
"$",
"noData",
"=",
"(",
"0",
"===",
"count",
"(",
"$",
"objects",
")",
")",
";",
"// We will also need titles for our table header",
"$",
"headers",
"=",
"[",
"]",
";",
"if",
"(",
"false",
"===",
"$",
"noData",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.resolver.listing_header'",
")",
"->",
"getHeaders",
"(",
"$",
"objects",
"[",
"0",
"]",
",",
"'viewListing'",
")",
";",
"}",
"// Finally, we need the routes for each entity",
"$",
"actions",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.core_entity.action_collection_builder'",
")",
"->",
"build",
"(",
"$",
"entity",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'RomaricDrigonOrchestraBundle:Generic:list.html.twig'",
",",
"[",
"'actions'",
"=>",
"$",
"actions",
",",
"'headers'",
"=>",
"$",
"headers",
",",
"'no_data'",
"=>",
"$",
"noData",
",",
"'objects'",
"=>",
"$",
"objects",
",",
"'title'",
"=>",
"$",
"name",
"]",
")",
";",
"}"
] | Action used when a repository "listing" is called
@param RepositoryDefinitionInterface $repository_definition
@param RepositoryInterface $repository
@param EntityReflectionInterface $entity
@throws DomainErrorException
@return \Symfony\Component\HttpFoundation\Response | [
"Action",
"used",
"when",
"a",
"repository",
"listing",
"is",
"called"
] | 4abb9736fcb6b23ed08ebd14ab169867339a4785 | https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Controller/GenericController.php#L52-L82 | train |
romaricdrigon/OrchestraBundle | Controller/GenericController.php | GenericController.repositoryQueryAction | public function repositoryQueryAction(RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, EntityReflectionInterface $entity, $repository_method)
{
return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
} | php | public function repositoryQueryAction(RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, EntityReflectionInterface $entity, $repository_method)
{
return $this->render('RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig', []);
} | [
"public",
"function",
"repositoryQueryAction",
"(",
"RepositoryDefinitionInterface",
"$",
"repository_definition",
",",
"RepositoryInterface",
"$",
"repository",
",",
"EntityReflectionInterface",
"$",
"entity",
",",
"$",
"repository_method",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'RomaricDrigonOrchestraBundle:Generic:dashboard.html.twig'",
",",
"[",
"]",
")",
";",
"}"
] | Action used when a method on en Repository is called
@param RepositoryDefinitionInterface $repository_definition
@param RepositoryInterface $repository
@param EntityReflectionInterface $entity
@param string $repository_method
@return \Symfony\Component\HttpFoundation\Response | [
"Action",
"used",
"when",
"a",
"method",
"on",
"en",
"Repository",
"is",
"called"
] | 4abb9736fcb6b23ed08ebd14ab169867339a4785 | https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Controller/GenericController.php#L108-L111 | train |
romaricdrigon/OrchestraBundle | Controller/GenericController.php | GenericController.repositoryCommandAction | public function repositoryCommandAction(Request $request, RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, $repository_method, CommandInterface $command)
{
$form = $this->createForm('orchestra_command_type', $command, [
'command' => $command
]);
$repoName = $this->get('orchestra.resolver.repository_name')->getName($repository_definition);
if ($request->isMethod('POST')) {
if ($form->handleRequest($request) && $form->isValid()) {
// Pass the command to the repository, and we're done!
call_user_func([$repository, $repository_method], $command);
$this->get('session')->getFlashBag()->add(
'success',
'Command run with success!'
);
// We redirect to "listing" page/action
$listRoute = $this->get('orchestra.resolver.repository_route_name')->getRouteName($repository, 'listing');
return $this->redirect($this->generateUrl($listRoute));
} else {
$this->get('session')->getFlashBag()->add(
'error',
'An error happened!'
);
}
}
return $this->render('RomaricDrigonOrchestraBundle:Generic:repositoryCommand.html.twig', [
'form' => $form->createView(),
'title' => $repoName
]);
} | php | public function repositoryCommandAction(Request $request, RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository, $repository_method, CommandInterface $command)
{
$form = $this->createForm('orchestra_command_type', $command, [
'command' => $command
]);
$repoName = $this->get('orchestra.resolver.repository_name')->getName($repository_definition);
if ($request->isMethod('POST')) {
if ($form->handleRequest($request) && $form->isValid()) {
// Pass the command to the repository, and we're done!
call_user_func([$repository, $repository_method], $command);
$this->get('session')->getFlashBag()->add(
'success',
'Command run with success!'
);
// We redirect to "listing" page/action
$listRoute = $this->get('orchestra.resolver.repository_route_name')->getRouteName($repository, 'listing');
return $this->redirect($this->generateUrl($listRoute));
} else {
$this->get('session')->getFlashBag()->add(
'error',
'An error happened!'
);
}
}
return $this->render('RomaricDrigonOrchestraBundle:Generic:repositoryCommand.html.twig', [
'form' => $form->createView(),
'title' => $repoName
]);
} | [
"public",
"function",
"repositoryCommandAction",
"(",
"Request",
"$",
"request",
",",
"RepositoryDefinitionInterface",
"$",
"repository_definition",
",",
"RepositoryInterface",
"$",
"repository",
",",
"$",
"repository_method",
",",
"CommandInterface",
"$",
"command",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'orchestra_command_type'",
",",
"$",
"command",
",",
"[",
"'command'",
"=>",
"$",
"command",
"]",
")",
";",
"$",
"repoName",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.resolver.repository_name'",
")",
"->",
"getName",
"(",
"$",
"repository_definition",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'POST'",
")",
")",
"{",
"if",
"(",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"// Pass the command to the repository, and we're done!",
"call_user_func",
"(",
"[",
"$",
"repository",
",",
"$",
"repository_method",
"]",
",",
"$",
"command",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'Command run with success!'",
")",
";",
"// We redirect to \"listing\" page/action",
"$",
"listRoute",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.resolver.repository_route_name'",
")",
"->",
"getRouteName",
"(",
"$",
"repository",
",",
"'listing'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"$",
"listRoute",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'error'",
",",
"'An error happened!'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'RomaricDrigonOrchestraBundle:Generic:repositoryCommand.html.twig'",
",",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'title'",
"=>",
"$",
"repoName",
"]",
")",
";",
"}"
] | Action used when a method accepting a Command, on en Repository is called
@param Request $request
@param RepositoryDefinitionInterface $repository_definition
@param RepositoryInterface $repository
@param string $repository_method
@param CommandInterface $command
@return \Symfony\Component\HttpFoundation\Response | [
"Action",
"used",
"when",
"a",
"method",
"accepting",
"a",
"Command",
"on",
"en",
"Repository",
"is",
"called"
] | 4abb9736fcb6b23ed08ebd14ab169867339a4785 | https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Controller/GenericController.php#L123-L157 | train |
romaricdrigon/OrchestraBundle | Controller/GenericController.php | GenericController.entityCommandAction | public function entityCommandAction(Request $request, CommandInterface $command, EntityReflectionInterface $entity, $entity_method, EntityInterface $object = null)
{
if (null === $object) {
throw new NotFoundHttpException();
}
$form = $this->createForm('orchestra_command_type', $command, [
'command' => $command
]);
if ($request->isMethod('POST')) {
if ($form->handleRequest($request) && $form->isValid()) {
// Pass the command to the repository, and we're done!
call_user_func([$object, $entity_method], $command);
// We have to save the result!
// We use our provided ObjectManager, not Doctrine
$this->getObjectManager()->saveObject($object);
$this->get('session')->getFlashBag()->add(
'success',
'Command run with success!'
);
} else {
$this->get('session')->getFlashBag()->add(
'error',
'An error happened!'
);
}
}
return $this->render('RomaricDrigonOrchestraBundle:Generic:entityCommand.html.twig', [
'form' => $form->createView(),
'title' => $entity->getName().' - '.$entity_method
]);
} | php | public function entityCommandAction(Request $request, CommandInterface $command, EntityReflectionInterface $entity, $entity_method, EntityInterface $object = null)
{
if (null === $object) {
throw new NotFoundHttpException();
}
$form = $this->createForm('orchestra_command_type', $command, [
'command' => $command
]);
if ($request->isMethod('POST')) {
if ($form->handleRequest($request) && $form->isValid()) {
// Pass the command to the repository, and we're done!
call_user_func([$object, $entity_method], $command);
// We have to save the result!
// We use our provided ObjectManager, not Doctrine
$this->getObjectManager()->saveObject($object);
$this->get('session')->getFlashBag()->add(
'success',
'Command run with success!'
);
} else {
$this->get('session')->getFlashBag()->add(
'error',
'An error happened!'
);
}
}
return $this->render('RomaricDrigonOrchestraBundle:Generic:entityCommand.html.twig', [
'form' => $form->createView(),
'title' => $entity->getName().' - '.$entity_method
]);
} | [
"public",
"function",
"entityCommandAction",
"(",
"Request",
"$",
"request",
",",
"CommandInterface",
"$",
"command",
",",
"EntityReflectionInterface",
"$",
"entity",
",",
"$",
"entity_method",
",",
"EntityInterface",
"$",
"object",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"object",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'orchestra_command_type'",
",",
"$",
"command",
",",
"[",
"'command'",
"=>",
"$",
"command",
"]",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'POST'",
")",
")",
"{",
"if",
"(",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"// Pass the command to the repository, and we're done!",
"call_user_func",
"(",
"[",
"$",
"object",
",",
"$",
"entity_method",
"]",
",",
"$",
"command",
")",
";",
"// We have to save the result!",
"// We use our provided ObjectManager, not Doctrine",
"$",
"this",
"->",
"getObjectManager",
"(",
")",
"->",
"saveObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'Command run with success!'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'error'",
",",
"'An error happened!'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'RomaricDrigonOrchestraBundle:Generic:entityCommand.html.twig'",
",",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'title'",
"=>",
"$",
"entity",
"->",
"getName",
"(",
")",
".",
"' - '",
".",
"$",
"entity_method",
"]",
")",
";",
"}"
] | Action used when a method accepting a Command, on en Entity is called
@param Request $request
@param CommandInterface $command
@param EntityReflectionInterface $entity
@param string $entity_method
@param EntityInterface $object
@throws NotFoundHttpException
@return \Symfony\Component\HttpFoundation\Response | [
"Action",
"used",
"when",
"a",
"method",
"accepting",
"a",
"Command",
"on",
"en",
"Entity",
"is",
"called"
] | 4abb9736fcb6b23ed08ebd14ab169867339a4785 | https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Controller/GenericController.php#L170-L205 | train |
romaricdrigon/OrchestraBundle | Controller/GenericController.php | GenericController.entityEventAction | public function entityEventAction(EntityReflectionInterface $entity, $entity_method, EntityInterface $object = null, RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository)
{
if (null === $object) {
throw new NotFoundHttpException();
}
// Get the Event
$event = call_user_func([$object, $entity_method]);
// We accept "null", in that case we do nothing, but no other objects
if (null !== $event && ! $event instanceof EventInterface) {
throw new DomainErrorException('An invalid Event was emitted by '.$entity->getName().' '.$entity_method.'. Maybe you forgot to implement EventInterface? Result must be either an implementation either null.');
}
if (! $repository instanceof ReceiveEventInterface) {
throw new DomainErrorException('Repository for Entity '.$entity->getName().' can not receive Events. Maybe you forgot to implement ReceiveEventInterface?');
}
if (null !== $event) {
call_user_func([$repository, 'receive'], $event);
$this->get('session')->getFlashBag()->add(
'success',
'Success!'
);
}
// We redirect to "listing" page/action
$listRoute = $this->get('orchestra.resolver.repository_route_name')->getRouteName($repository_definition, 'listing');
return $this->redirect($this->generateUrl($listRoute));
} | php | public function entityEventAction(EntityReflectionInterface $entity, $entity_method, EntityInterface $object = null, RepositoryDefinitionInterface $repository_definition, RepositoryInterface $repository)
{
if (null === $object) {
throw new NotFoundHttpException();
}
// Get the Event
$event = call_user_func([$object, $entity_method]);
// We accept "null", in that case we do nothing, but no other objects
if (null !== $event && ! $event instanceof EventInterface) {
throw new DomainErrorException('An invalid Event was emitted by '.$entity->getName().' '.$entity_method.'. Maybe you forgot to implement EventInterface? Result must be either an implementation either null.');
}
if (! $repository instanceof ReceiveEventInterface) {
throw new DomainErrorException('Repository for Entity '.$entity->getName().' can not receive Events. Maybe you forgot to implement ReceiveEventInterface?');
}
if (null !== $event) {
call_user_func([$repository, 'receive'], $event);
$this->get('session')->getFlashBag()->add(
'success',
'Success!'
);
}
// We redirect to "listing" page/action
$listRoute = $this->get('orchestra.resolver.repository_route_name')->getRouteName($repository_definition, 'listing');
return $this->redirect($this->generateUrl($listRoute));
} | [
"public",
"function",
"entityEventAction",
"(",
"EntityReflectionInterface",
"$",
"entity",
",",
"$",
"entity_method",
",",
"EntityInterface",
"$",
"object",
"=",
"null",
",",
"RepositoryDefinitionInterface",
"$",
"repository_definition",
",",
"RepositoryInterface",
"$",
"repository",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"object",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"// Get the Event",
"$",
"event",
"=",
"call_user_func",
"(",
"[",
"$",
"object",
",",
"$",
"entity_method",
"]",
")",
";",
"// We accept \"null\", in that case we do nothing, but no other objects",
"if",
"(",
"null",
"!==",
"$",
"event",
"&&",
"!",
"$",
"event",
"instanceof",
"EventInterface",
")",
"{",
"throw",
"new",
"DomainErrorException",
"(",
"'An invalid Event was emitted by '",
".",
"$",
"entity",
"->",
"getName",
"(",
")",
".",
"' '",
".",
"$",
"entity_method",
".",
"'. Maybe you forgot to implement EventInterface? Result must be either an implementation either null.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"repository",
"instanceof",
"ReceiveEventInterface",
")",
"{",
"throw",
"new",
"DomainErrorException",
"(",
"'Repository for Entity '",
".",
"$",
"entity",
"->",
"getName",
"(",
")",
".",
"' can not receive Events. Maybe you forgot to implement ReceiveEventInterface?'",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"event",
")",
"{",
"call_user_func",
"(",
"[",
"$",
"repository",
",",
"'receive'",
"]",
",",
"$",
"event",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"'Success!'",
")",
";",
"}",
"// We redirect to \"listing\" page/action",
"$",
"listRoute",
"=",
"$",
"this",
"->",
"get",
"(",
"'orchestra.resolver.repository_route_name'",
")",
"->",
"getRouteName",
"(",
"$",
"repository_definition",
",",
"'listing'",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"$",
"listRoute",
")",
")",
";",
"}"
] | Action used when a method with a "EmitEvent" annotations is called
@param EntityReflectionInterface $entity
@param string $entity_method
@param EntityInterface $object
@param RepositoryDefinitionInterface $repository_definition
@param RepositoryInterface $repository
@throws DomainErrorException
@throws NotFoundHttpException
@return \Symfony\Component\HttpFoundation\Response | [
"Action",
"used",
"when",
"a",
"method",
"with",
"a",
"EmitEvent",
"annotations",
"is",
"called"
] | 4abb9736fcb6b23ed08ebd14ab169867339a4785 | https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Controller/GenericController.php#L219-L250 | train |
antaresproject/sample_module | src/Http/Form/Configuration.php | Configuration.controlsFieldset | protected function controlsFieldset()
{
return $this->grid->fieldset(function (Fieldset $fieldset) {
$fieldset->legend('Sample Module Configuration');
$fieldset->control('input:text', 'name')
->label(trans('antares/sample_module::messages.configuration.labels.name'))
->attributes(['placeholder' => trans('antares/sample_module::messages.configuration.placeholders.name')])
->wrapper(['class' => 'w300']);
$fieldset->control('input:text', 'url')
->label(trans('antares/sample_module::messages.configuration.labels.url'))
->attributes(['placeholder' => trans('antares/sample_module::messages.configuration.placeholders.url')])
->fieldClass('input-field--group input-field--pre')
->before('<div class="input-field__pre"><span>' . (request()->secure() ? 'https://' : 'http://') . '</span></div>')
->wrapper(['class' => 'w400']);
$fieldset->control('select', 'date_format')
->wrapper(['class' => 'w180'])
->label(trans('antares/sample_module::messages.configuration.labels.date_format'))
->options(function() {
return app(DateFormat::class)->query()->get()->pluck('format', 'id');
});
$options = app(Country::class)->query()->get()->pluck('name', 'code');
$fieldset->control('select', 'default_country')
->label(trans('antares/sample_module::messages.configuration.labels.country'))
->attributes(['data-flag-select', 'data-selectAR' => true, 'class' => 'w200'])
->fieldClass('input-field--icon')
->prepend('<span class = "input-field__icon"><span class = "flag-icon"></span></span>')
->optionsData(function() use($options) {
$codes = $options->keys()->toArray();
$return = [];
foreach ($codes as $code) {
array_set($return, $code, ['country' => $code]);
}
return $return;
})
->options($options);
$checkbox = $fieldset->control('input:checkbox', 'checkbox')
->label(trans('antares/sample_module::messages.configuration.labels.checkbox'))
->value(1);
if (array_get($this->grid->row, 'checkbox')) {
$checkbox->checked();
}
$fieldset->control('ckeditor', 'content')
->label(trans('antares/sample_module::messages.configuration.labels.description'))
->attributes(['scripts' => true, 'class' => 'richtext'])
->name('content');
$fieldset->control('button', 'button')
->attributes(['type' => 'submit', 'value' => trans('Submit'), 'class' => 'btn btn--md btn--primary mdl-button mdl-js-button mdl-js-ripple-effect'])
->value(trans('antares/foundation::label.save_changes'));
});
} | php | protected function controlsFieldset()
{
return $this->grid->fieldset(function (Fieldset $fieldset) {
$fieldset->legend('Sample Module Configuration');
$fieldset->control('input:text', 'name')
->label(trans('antares/sample_module::messages.configuration.labels.name'))
->attributes(['placeholder' => trans('antares/sample_module::messages.configuration.placeholders.name')])
->wrapper(['class' => 'w300']);
$fieldset->control('input:text', 'url')
->label(trans('antares/sample_module::messages.configuration.labels.url'))
->attributes(['placeholder' => trans('antares/sample_module::messages.configuration.placeholders.url')])
->fieldClass('input-field--group input-field--pre')
->before('<div class="input-field__pre"><span>' . (request()->secure() ? 'https://' : 'http://') . '</span></div>')
->wrapper(['class' => 'w400']);
$fieldset->control('select', 'date_format')
->wrapper(['class' => 'w180'])
->label(trans('antares/sample_module::messages.configuration.labels.date_format'))
->options(function() {
return app(DateFormat::class)->query()->get()->pluck('format', 'id');
});
$options = app(Country::class)->query()->get()->pluck('name', 'code');
$fieldset->control('select', 'default_country')
->label(trans('antares/sample_module::messages.configuration.labels.country'))
->attributes(['data-flag-select', 'data-selectAR' => true, 'class' => 'w200'])
->fieldClass('input-field--icon')
->prepend('<span class = "input-field__icon"><span class = "flag-icon"></span></span>')
->optionsData(function() use($options) {
$codes = $options->keys()->toArray();
$return = [];
foreach ($codes as $code) {
array_set($return, $code, ['country' => $code]);
}
return $return;
})
->options($options);
$checkbox = $fieldset->control('input:checkbox', 'checkbox')
->label(trans('antares/sample_module::messages.configuration.labels.checkbox'))
->value(1);
if (array_get($this->grid->row, 'checkbox')) {
$checkbox->checked();
}
$fieldset->control('ckeditor', 'content')
->label(trans('antares/sample_module::messages.configuration.labels.description'))
->attributes(['scripts' => true, 'class' => 'richtext'])
->name('content');
$fieldset->control('button', 'button')
->attributes(['type' => 'submit', 'value' => trans('Submit'), 'class' => 'btn btn--md btn--primary mdl-button mdl-js-button mdl-js-ripple-effect'])
->value(trans('antares/foundation::label.save_changes'));
});
} | [
"protected",
"function",
"controlsFieldset",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"grid",
"->",
"fieldset",
"(",
"function",
"(",
"Fieldset",
"$",
"fieldset",
")",
"{",
"$",
"fieldset",
"->",
"legend",
"(",
"'Sample Module Configuration'",
")",
";",
"$",
"fieldset",
"->",
"control",
"(",
"'input:text'",
",",
"'name'",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.name'",
")",
")",
"->",
"attributes",
"(",
"[",
"'placeholder'",
"=>",
"trans",
"(",
"'antares/sample_module::messages.configuration.placeholders.name'",
")",
"]",
")",
"->",
"wrapper",
"(",
"[",
"'class'",
"=>",
"'w300'",
"]",
")",
";",
"$",
"fieldset",
"->",
"control",
"(",
"'input:text'",
",",
"'url'",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.url'",
")",
")",
"->",
"attributes",
"(",
"[",
"'placeholder'",
"=>",
"trans",
"(",
"'antares/sample_module::messages.configuration.placeholders.url'",
")",
"]",
")",
"->",
"fieldClass",
"(",
"'input-field--group input-field--pre'",
")",
"->",
"before",
"(",
"'<div class=\"input-field__pre\"><span>'",
".",
"(",
"request",
"(",
")",
"->",
"secure",
"(",
")",
"?",
"'https://'",
":",
"'http://'",
")",
".",
"'</span></div>'",
")",
"->",
"wrapper",
"(",
"[",
"'class'",
"=>",
"'w400'",
"]",
")",
";",
"$",
"fieldset",
"->",
"control",
"(",
"'select'",
",",
"'date_format'",
")",
"->",
"wrapper",
"(",
"[",
"'class'",
"=>",
"'w180'",
"]",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.date_format'",
")",
")",
"->",
"options",
"(",
"function",
"(",
")",
"{",
"return",
"app",
"(",
"DateFormat",
"::",
"class",
")",
"->",
"query",
"(",
")",
"->",
"get",
"(",
")",
"->",
"pluck",
"(",
"'format'",
",",
"'id'",
")",
";",
"}",
")",
";",
"$",
"options",
"=",
"app",
"(",
"Country",
"::",
"class",
")",
"->",
"query",
"(",
")",
"->",
"get",
"(",
")",
"->",
"pluck",
"(",
"'name'",
",",
"'code'",
")",
";",
"$",
"fieldset",
"->",
"control",
"(",
"'select'",
",",
"'default_country'",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.country'",
")",
")",
"->",
"attributes",
"(",
"[",
"'data-flag-select'",
",",
"'data-selectAR'",
"=>",
"true",
",",
"'class'",
"=>",
"'w200'",
"]",
")",
"->",
"fieldClass",
"(",
"'input-field--icon'",
")",
"->",
"prepend",
"(",
"'<span class = \"input-field__icon\"><span class = \"flag-icon\"></span></span>'",
")",
"->",
"optionsData",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"options",
")",
"{",
"$",
"codes",
"=",
"$",
"options",
"->",
"keys",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"codes",
"as",
"$",
"code",
")",
"{",
"array_set",
"(",
"$",
"return",
",",
"$",
"code",
",",
"[",
"'country'",
"=>",
"$",
"code",
"]",
")",
";",
"}",
"return",
"$",
"return",
";",
"}",
")",
"->",
"options",
"(",
"$",
"options",
")",
";",
"$",
"checkbox",
"=",
"$",
"fieldset",
"->",
"control",
"(",
"'input:checkbox'",
",",
"'checkbox'",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.checkbox'",
")",
")",
"->",
"value",
"(",
"1",
")",
";",
"if",
"(",
"array_get",
"(",
"$",
"this",
"->",
"grid",
"->",
"row",
",",
"'checkbox'",
")",
")",
"{",
"$",
"checkbox",
"->",
"checked",
"(",
")",
";",
"}",
"$",
"fieldset",
"->",
"control",
"(",
"'ckeditor'",
",",
"'content'",
")",
"->",
"label",
"(",
"trans",
"(",
"'antares/sample_module::messages.configuration.labels.description'",
")",
")",
"->",
"attributes",
"(",
"[",
"'scripts'",
"=>",
"true",
",",
"'class'",
"=>",
"'richtext'",
"]",
")",
"->",
"name",
"(",
"'content'",
")",
";",
"$",
"fieldset",
"->",
"control",
"(",
"'button'",
",",
"'button'",
")",
"->",
"attributes",
"(",
"[",
"'type'",
"=>",
"'submit'",
",",
"'value'",
"=>",
"trans",
"(",
"'Submit'",
")",
",",
"'class'",
"=>",
"'btn btn--md btn--primary mdl-button mdl-js-button mdl-js-ripple-effect'",
"]",
")",
"->",
"value",
"(",
"trans",
"(",
"'antares/foundation::label.save_changes'",
")",
")",
";",
"}",
")",
";",
"}"
] | creates main controls fieldset
@return \Antares\Html\Form\Fieldset | [
"creates",
"main",
"controls",
"fieldset"
] | aceab14f392c25e32729018518e9d6b4e6fe23db | https://github.com/antaresproject/sample_module/blob/aceab14f392c25e32729018518e9d6b4e6fe23db/src/Http/Form/Configuration.php#L58-L113 | train |
luoxiaojun1992/lb_framework | components/helpers/FileHelper.php | FileHelper.send | public static function send($filePath, $remoteFileSystem)
{
return (new Client())->put($remoteFileSystem, ['body' => fopen($filePath, self::READ_BINARY)])
->getStatusCode() == HttpHelper::STATUS_OK;
} | php | public static function send($filePath, $remoteFileSystem)
{
return (new Client())->put($remoteFileSystem, ['body' => fopen($filePath, self::READ_BINARY)])
->getStatusCode() == HttpHelper::STATUS_OK;
} | [
"public",
"static",
"function",
"send",
"(",
"$",
"filePath",
",",
"$",
"remoteFileSystem",
")",
"{",
"return",
"(",
"new",
"Client",
"(",
")",
")",
"->",
"put",
"(",
"$",
"remoteFileSystem",
",",
"[",
"'body'",
"=>",
"fopen",
"(",
"$",
"filePath",
",",
"self",
"::",
"READ_BINARY",
")",
"]",
")",
"->",
"getStatusCode",
"(",
")",
"==",
"HttpHelper",
"::",
"STATUS_OK",
";",
"}"
] | Send a file
@param $filePath
@param $remoteFileSystem
@return bool | [
"Send",
"a",
"file"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/helpers/FileHelper.php#L183-L187 | train |
luoxiaojun1992/lb_framework | components/helpers/FileHelper.php | FileHelper.receive | public static function receive($savePath, RequestContract $request = null)
{
file_put_contents($savePath, $request ? $request->getRawContent() : RequestKit::getRawContent());
} | php | public static function receive($savePath, RequestContract $request = null)
{
file_put_contents($savePath, $request ? $request->getRawContent() : RequestKit::getRawContent());
} | [
"public",
"static",
"function",
"receive",
"(",
"$",
"savePath",
",",
"RequestContract",
"$",
"request",
"=",
"null",
")",
"{",
"file_put_contents",
"(",
"$",
"savePath",
",",
"$",
"request",
"?",
"$",
"request",
"->",
"getRawContent",
"(",
")",
":",
"RequestKit",
"::",
"getRawContent",
"(",
")",
")",
";",
"}"
] | Receive a file
@param $savePath
@param RequestContract|null $request | [
"Receive",
"a",
"file"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/helpers/FileHelper.php#L195-L198 | train |
luoxiaojun1992/lb_framework | components/helpers/FileHelper.php | FileHelper.copy | public static function copy($src, $dst, $context = null)
{
return self::resourceExists($src) ? copy($src, $dst, $context) : false;
} | php | public static function copy($src, $dst, $context = null)
{
return self::resourceExists($src) ? copy($src, $dst, $context) : false;
} | [
"public",
"static",
"function",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
",",
"$",
"context",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"resourceExists",
"(",
"$",
"src",
")",
"?",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
",",
"$",
"context",
")",
":",
"false",
";",
"}"
] | Copy a file or a directory
@param $src
@param $dst
@param null $context
@return bool | [
"Copy",
"a",
"file",
"or",
"a",
"directory"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/helpers/FileHelper.php#L208-L211 | train |
luoxiaojun1992/lb_framework | components/helpers/FileHelper.php | FileHelper.move | public static function move($oldName, $newName, $context = null)
{
return self::rename($oldName, $newName, $context);
} | php | public static function move($oldName, $newName, $context = null)
{
return self::rename($oldName, $newName, $context);
} | [
"public",
"static",
"function",
"move",
"(",
"$",
"oldName",
",",
"$",
"newName",
",",
"$",
"context",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"rename",
"(",
"$",
"oldName",
",",
"$",
"newName",
",",
"$",
"context",
")",
";",
"}"
] | Move a file or a directory
@param $oldName
@param $newName
@param null $context
@return bool | [
"Move",
"a",
"file",
"or",
"a",
"directory"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/helpers/FileHelper.php#L221-L224 | train |
luoxiaojun1992/lb_framework | components/helpers/FileHelper.php | FileHelper.rename | public static function rename($oldName, $newName, $context = null)
{
return self::resourceExists($oldName) ? rename($oldName, $newName, $context) : false;
} | php | public static function rename($oldName, $newName, $context = null)
{
return self::resourceExists($oldName) ? rename($oldName, $newName, $context) : false;
} | [
"public",
"static",
"function",
"rename",
"(",
"$",
"oldName",
",",
"$",
"newName",
",",
"$",
"context",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"resourceExists",
"(",
"$",
"oldName",
")",
"?",
"rename",
"(",
"$",
"oldName",
",",
"$",
"newName",
",",
"$",
"context",
")",
":",
"false",
";",
"}"
] | Rename a file or a directory
@param $oldName
@param $newName
@param null $context
@return bool | [
"Rename",
"a",
"file",
"or",
"a",
"directory"
] | 12a865729e7738d7d1e07371ad7203243c4571fa | https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/helpers/FileHelper.php#L234-L237 | train |
as3io/modlr | src/Events/EventDispatcher.php | EventDispatcher.getListeners | protected function getListeners($eventName)
{
if (isset($this->listeners[$eventName])) {
return $this->listeners[$eventName];
}
return null;
} | php | protected function getListeners($eventName)
{
if (isset($this->listeners[$eventName])) {
return $this->listeners[$eventName];
}
return null;
} | [
"protected",
"function",
"getListeners",
"(",
"$",
"eventName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Gets all registered listeners for an event name.
@param string $eventName
@return array|null | [
"Gets",
"all",
"registered",
"listeners",
"for",
"an",
"event",
"name",
"."
] | 7e684b88bb22a2e18397df9402075c6533084b16 | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Events/EventDispatcher.php#L91-L97 | train |
inhere/php-library-plus | libs/Log/AbstractLogger.php | AbstractLogger.log | public function log($level, $message, array $context = array())
{
$level = static::toNumberLevel($level);
return $this->addRecord($level, $message, $context);
} | php | public function log($level, $message, array $context = array())
{
$level = static::toNumberLevel($level);
return $this->addRecord($level, $message, $context);
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"level",
"=",
"static",
"::",
"toNumberLevel",
"(",
"$",
"level",
")",
";",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at an arbitrary level.
This method allows for compatibility with common interfaces.
@param int|string $level The log level
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"an",
"arbitrary",
"level",
".",
"This",
"method",
"allows",
"for",
"compatibility",
"with",
"common",
"interfaces",
"."
] | 8604e037937d31fa2338d79aaf9d0910cb48f559 | https://github.com/inhere/php-library-plus/blob/8604e037937d31fa2338d79aaf9d0910cb48f559/libs/Log/AbstractLogger.php#L202-L207 | train |
amarcinkowski/hospitalplugin | src/utils/Utils.php | Utils.diffDates | public static function diffDates($date1, $date2)
{
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
return floor($seconds_diff / 3600 / 24);
} | php | public static function diffDates($date1, $date2)
{
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
return floor($seconds_diff / 3600 / 24);
} | [
"public",
"static",
"function",
"diffDates",
"(",
"$",
"date1",
",",
"$",
"date2",
")",
"{",
"$",
"ts1",
"=",
"strtotime",
"(",
"$",
"date1",
")",
";",
"$",
"ts2",
"=",
"strtotime",
"(",
"$",
"date2",
")",
";",
"$",
"seconds_diff",
"=",
"$",
"ts2",
"-",
"$",
"ts1",
";",
"return",
"floor",
"(",
"$",
"seconds_diff",
"/",
"3600",
"/",
"24",
")",
";",
"}"
] | diff in days
@param $date1 $date1 string parsable date strtotime(date)
@param $date2 $date2 string parsable date strtotime(date)
@return number | [
"diff",
"in",
"days"
] | acdc2be5157abfbdcafb4dcf6c6ba505e291263f | https://github.com/amarcinkowski/hospitalplugin/blob/acdc2be5157abfbdcafb4dcf6c6ba505e291263f/src/utils/Utils.php#L49-L57 | train |
amarcinkowski/hospitalplugin | src/utils/Utils.php | Utils.readFileToArray | public static function readFileToArray($url, $delm = ";", $encl = "\"", $head = false)
{
$csvxrow = file($url); // ---- csv rows to array ----
$csvxrow[0] = chop($csvxrow[0]);
$csvxrow[0] = str_replace($encl, '', $csvxrow[0]);
$keydata = explode($delm, $csvxrow[0]);
$keynumb = count($keydata);
$csv_data = array();
$out = array();
if ($head === true) {
$anzdata = count($csvxrow);
$z = 0;
for ($x = 1; $x < $anzdata; $x ++) {
$csvxrow[$x] = chop($csvxrow[$x]);
$csvxrow[$x] = str_replace($encl, '', $csvxrow[$x]);
$csv_data[$x] = explode($delm, $csvxrow[$x]);
$i = 0;
foreach ($keydata as $key) {
$out[$z][$key] = $csv_data[$x][$i];
$i ++;
}
$z ++;
}
} else {
$i = 0;
foreach ($csvxrow as $item) {
$item = chop($item);
$item = str_replace($encl, '', $item);
$csv_data = explode($delm, $item);
for ($y = 0; $y < $keynumb; $y ++) {
$out[$i][$y] = $csv_data[$y];
}
$i ++;
}
}
return $out;
} | php | public static function readFileToArray($url, $delm = ";", $encl = "\"", $head = false)
{
$csvxrow = file($url); // ---- csv rows to array ----
$csvxrow[0] = chop($csvxrow[0]);
$csvxrow[0] = str_replace($encl, '', $csvxrow[0]);
$keydata = explode($delm, $csvxrow[0]);
$keynumb = count($keydata);
$csv_data = array();
$out = array();
if ($head === true) {
$anzdata = count($csvxrow);
$z = 0;
for ($x = 1; $x < $anzdata; $x ++) {
$csvxrow[$x] = chop($csvxrow[$x]);
$csvxrow[$x] = str_replace($encl, '', $csvxrow[$x]);
$csv_data[$x] = explode($delm, $csvxrow[$x]);
$i = 0;
foreach ($keydata as $key) {
$out[$z][$key] = $csv_data[$x][$i];
$i ++;
}
$z ++;
}
} else {
$i = 0;
foreach ($csvxrow as $item) {
$item = chop($item);
$item = str_replace($encl, '', $item);
$csv_data = explode($delm, $item);
for ($y = 0; $y < $keynumb; $y ++) {
$out[$i][$y] = $csv_data[$y];
}
$i ++;
}
}
return $out;
} | [
"public",
"static",
"function",
"readFileToArray",
"(",
"$",
"url",
",",
"$",
"delm",
"=",
"\";\"",
",",
"$",
"encl",
"=",
"\"\\\"\"",
",",
"$",
"head",
"=",
"false",
")",
"{",
"$",
"csvxrow",
"=",
"file",
"(",
"$",
"url",
")",
";",
"// ---- csv rows to array ----",
"$",
"csvxrow",
"[",
"0",
"]",
"=",
"chop",
"(",
"$",
"csvxrow",
"[",
"0",
"]",
")",
";",
"$",
"csvxrow",
"[",
"0",
"]",
"=",
"str_replace",
"(",
"$",
"encl",
",",
"''",
",",
"$",
"csvxrow",
"[",
"0",
"]",
")",
";",
"$",
"keydata",
"=",
"explode",
"(",
"$",
"delm",
",",
"$",
"csvxrow",
"[",
"0",
"]",
")",
";",
"$",
"keynumb",
"=",
"count",
"(",
"$",
"keydata",
")",
";",
"$",
"csv_data",
"=",
"array",
"(",
")",
";",
"$",
"out",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"head",
"===",
"true",
")",
"{",
"$",
"anzdata",
"=",
"count",
"(",
"$",
"csvxrow",
")",
";",
"$",
"z",
"=",
"0",
";",
"for",
"(",
"$",
"x",
"=",
"1",
";",
"$",
"x",
"<",
"$",
"anzdata",
";",
"$",
"x",
"++",
")",
"{",
"$",
"csvxrow",
"[",
"$",
"x",
"]",
"=",
"chop",
"(",
"$",
"csvxrow",
"[",
"$",
"x",
"]",
")",
";",
"$",
"csvxrow",
"[",
"$",
"x",
"]",
"=",
"str_replace",
"(",
"$",
"encl",
",",
"''",
",",
"$",
"csvxrow",
"[",
"$",
"x",
"]",
")",
";",
"$",
"csv_data",
"[",
"$",
"x",
"]",
"=",
"explode",
"(",
"$",
"delm",
",",
"$",
"csvxrow",
"[",
"$",
"x",
"]",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"keydata",
"as",
"$",
"key",
")",
"{",
"$",
"out",
"[",
"$",
"z",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"csv_data",
"[",
"$",
"x",
"]",
"[",
"$",
"i",
"]",
";",
"$",
"i",
"++",
";",
"}",
"$",
"z",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"csvxrow",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"chop",
"(",
"$",
"item",
")",
";",
"$",
"item",
"=",
"str_replace",
"(",
"$",
"encl",
",",
"''",
",",
"$",
"item",
")",
";",
"$",
"csv_data",
"=",
"explode",
"(",
"$",
"delm",
",",
"$",
"item",
")",
";",
"for",
"(",
"$",
"y",
"=",
"0",
";",
"$",
"y",
"<",
"$",
"keynumb",
";",
"$",
"y",
"++",
")",
"{",
"$",
"out",
"[",
"$",
"i",
"]",
"[",
"$",
"y",
"]",
"=",
"$",
"csv_data",
"[",
"$",
"y",
"]",
";",
"}",
"$",
"i",
"++",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | read file to array
@param $url file url
@param $delm default ;
@param $encl default \
@param $head default false
@return array of strings | [
"read",
"file",
"to",
"array"
] | acdc2be5157abfbdcafb4dcf6c6ba505e291263f | https://github.com/amarcinkowski/hospitalplugin/blob/acdc2be5157abfbdcafb4dcf6c6ba505e291263f/src/utils/Utils.php#L225-L263 | train |
amarcinkowski/hospitalplugin | src/utils/Utils.php | Utils.w1250_to_utf8 | public static function w1250_to_utf8($text)
{
// map based on:
// http://konfiguracja.c0.pl/iso02vscp1250en.html
// http://konfiguracja.c0.pl/webpl/index_en.html#examp
// http://www.htmlentities.com/html/entities/
$map = array(
chr(0x8A) => chr(0xA9),
chr(0x8C) => chr(0xA6),
chr(0x8D) => chr(0xAB),
chr(0x8E) => chr(0xAE),
chr(0x8F) => chr(0xAC),
chr(0x9C) => chr(0xB6),
chr(0x9D) => chr(0xBB),
chr(0xA1) => chr(0xB7),
chr(0xA5) => chr(0xA1),
//chr(0xBC) => chr(0xA5),
// chr ( 0x9F ) => chr ( 0xBC ),
chr(0xB9) => chr(0xB1),
chr(0x9A) => chr(0xB9),
chr(0xBE) => chr(0xB5),
chr(0x9E) => chr(0xBE),
chr(0x80) => '€',
chr(0x82) => '‚',
chr(0x84) => '„',
chr(0x85) => '…',
chr(0x86) => '†',
chr(0x87) => '‡',
chr(0x89) => '‰',
chr(0x8B) => '‹',
chr(0x91) => '‘',
chr(0x92) => '’',
chr(0x93) => '“',
chr(0x94) => '”',
chr(0x95) => '•',
chr(0x96) => '–',
chr(0x97) => '—',
chr(0x99) => '™',
chr(0x9B) => '’',
chr(0xA9) => '©',
chr(0xAB) => '«',
chr(0xAE) => '®',
chr(0xB1) => '±',
chr(0xB5) => 'µ',
chr(0xB7) => '·',
chr(0xBB) => '»',
// ś
chr(0xB6) => 'ś',
// ą
chr(0xB1) => 'ą',
// Ś
chr(0xA6) => 'Ś',
// ż
chr(0xBF) => 'ż',
// ź
chr(0x9F) => 'ź',
chr(0xBC) => 'ź'
);
return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8');
} | php | public static function w1250_to_utf8($text)
{
// map based on:
// http://konfiguracja.c0.pl/iso02vscp1250en.html
// http://konfiguracja.c0.pl/webpl/index_en.html#examp
// http://www.htmlentities.com/html/entities/
$map = array(
chr(0x8A) => chr(0xA9),
chr(0x8C) => chr(0xA6),
chr(0x8D) => chr(0xAB),
chr(0x8E) => chr(0xAE),
chr(0x8F) => chr(0xAC),
chr(0x9C) => chr(0xB6),
chr(0x9D) => chr(0xBB),
chr(0xA1) => chr(0xB7),
chr(0xA5) => chr(0xA1),
//chr(0xBC) => chr(0xA5),
// chr ( 0x9F ) => chr ( 0xBC ),
chr(0xB9) => chr(0xB1),
chr(0x9A) => chr(0xB9),
chr(0xBE) => chr(0xB5),
chr(0x9E) => chr(0xBE),
chr(0x80) => '€',
chr(0x82) => '‚',
chr(0x84) => '„',
chr(0x85) => '…',
chr(0x86) => '†',
chr(0x87) => '‡',
chr(0x89) => '‰',
chr(0x8B) => '‹',
chr(0x91) => '‘',
chr(0x92) => '’',
chr(0x93) => '“',
chr(0x94) => '”',
chr(0x95) => '•',
chr(0x96) => '–',
chr(0x97) => '—',
chr(0x99) => '™',
chr(0x9B) => '’',
chr(0xA9) => '©',
chr(0xAB) => '«',
chr(0xAE) => '®',
chr(0xB1) => '±',
chr(0xB5) => 'µ',
chr(0xB7) => '·',
chr(0xBB) => '»',
// ś
chr(0xB6) => 'ś',
// ą
chr(0xB1) => 'ą',
// Ś
chr(0xA6) => 'Ś',
// ż
chr(0xBF) => 'ż',
// ź
chr(0x9F) => 'ź',
chr(0xBC) => 'ź'
);
return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8');
} | [
"public",
"static",
"function",
"w1250_to_utf8",
"(",
"$",
"text",
")",
"{",
"// map based on:",
"// http://konfiguracja.c0.pl/iso02vscp1250en.html",
"// http://konfiguracja.c0.pl/webpl/index_en.html#examp",
"// http://www.htmlentities.com/html/entities/",
"$",
"map",
"=",
"array",
"(",
"chr",
"(",
"0x8A",
")",
"=>",
"chr",
"(",
"0xA9",
")",
",",
"chr",
"(",
"0x8C",
")",
"=>",
"chr",
"(",
"0xA6",
")",
",",
"chr",
"(",
"0x8D",
")",
"=>",
"chr",
"(",
"0xAB",
")",
",",
"chr",
"(",
"0x8E",
")",
"=>",
"chr",
"(",
"0xAE",
")",
",",
"chr",
"(",
"0x8F",
")",
"=>",
"chr",
"(",
"0xAC",
")",
",",
"chr",
"(",
"0x9C",
")",
"=>",
"chr",
"(",
"0xB6",
")",
",",
"chr",
"(",
"0x9D",
")",
"=>",
"chr",
"(",
"0xBB",
")",
",",
"chr",
"(",
"0xA1",
")",
"=>",
"chr",
"(",
"0xB7",
")",
",",
"chr",
"(",
"0xA5",
")",
"=>",
"chr",
"(",
"0xA1",
")",
",",
"//chr(0xBC) => chr(0xA5),",
"// chr ( 0x9F ) => chr ( 0xBC ),",
"chr",
"(",
"0xB9",
")",
"=>",
"chr",
"(",
"0xB1",
")",
",",
"chr",
"(",
"0x9A",
")",
"=>",
"chr",
"(",
"0xB9",
")",
",",
"chr",
"(",
"0xBE",
")",
"=>",
"chr",
"(",
"0xB5",
")",
",",
"chr",
"(",
"0x9E",
")",
"=>",
"chr",
"(",
"0xBE",
")",
",",
"chr",
"(",
"0x80",
")",
"=>",
"'€'",
",",
"chr",
"(",
"0x82",
")",
"=>",
"'‚'",
",",
"chr",
"(",
"0x84",
")",
"=>",
"'„'",
",",
"chr",
"(",
"0x85",
")",
"=>",
"'…'",
",",
"chr",
"(",
"0x86",
")",
"=>",
"'†'",
",",
"chr",
"(",
"0x87",
")",
"=>",
"'‡'",
",",
"chr",
"(",
"0x89",
")",
"=>",
"'‰'",
",",
"chr",
"(",
"0x8B",
")",
"=>",
"'‹'",
",",
"chr",
"(",
"0x91",
")",
"=>",
"'‘'",
",",
"chr",
"(",
"0x92",
")",
"=>",
"'’'",
",",
"chr",
"(",
"0x93",
")",
"=>",
"'“'",
",",
"chr",
"(",
"0x94",
")",
"=>",
"'”'",
",",
"chr",
"(",
"0x95",
")",
"=>",
"'•'",
",",
"chr",
"(",
"0x96",
")",
"=>",
"'–'",
",",
"chr",
"(",
"0x97",
")",
"=>",
"'—'",
",",
"chr",
"(",
"0x99",
")",
"=>",
"'™'",
",",
"chr",
"(",
"0x9B",
")",
"=>",
"'’'",
",",
"chr",
"(",
"0xA9",
")",
"=>",
"'©'",
",",
"chr",
"(",
"0xAB",
")",
"=>",
"'«'",
",",
"chr",
"(",
"0xAE",
")",
"=>",
"'®'",
",",
"chr",
"(",
"0xB1",
")",
"=>",
"'±'",
",",
"chr",
"(",
"0xB5",
")",
"=>",
"'µ'",
",",
"chr",
"(",
"0xB7",
")",
"=>",
"'·'",
",",
"chr",
"(",
"0xBB",
")",
"=>",
"'»'",
",",
"// ś",
"chr",
"(",
"0xB6",
")",
"=>",
"'ś'",
",",
"// ą",
"chr",
"(",
"0xB1",
")",
"=>",
"'ą'",
",",
"// Ś",
"chr",
"(",
"0xA6",
")",
"=>",
"'Ś'",
",",
"// ż",
"chr",
"(",
"0xBF",
")",
"=>",
"'ż'",
",",
"// ź",
"chr",
"(",
"0x9F",
")",
"=>",
"'ź'",
",",
"chr",
"(",
"0xBC",
")",
"=>",
"'ź'",
")",
";",
"return",
"html_entity_decode",
"(",
"mb_convert_encoding",
"(",
"strtr",
"(",
"$",
"text",
",",
"$",
"map",
")",
",",
"'UTF-8'",
",",
"'ISO-8859-2'",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"}"
] | PL chars conv iso8859-2 => win1250 => utf8
@param text string with PL chars
@return string encoded | [
"PL",
"chars",
"conv",
"iso8859",
"-",
"2",
"=",
">",
"win1250",
"=",
">",
"utf8"
] | acdc2be5157abfbdcafb4dcf6c6ba505e291263f | https://github.com/amarcinkowski/hospitalplugin/blob/acdc2be5157abfbdcafb4dcf6c6ba505e291263f/src/utils/Utils.php#L271-L336 | train |
thelia-modules/SmartyFilter | Model/Base/SmartyFilterQuery.php | SmartyFilterQuery.create | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \SmartyFilter\Model\SmartyFilterQuery) {
return $criteria;
}
$query = new \SmartyFilter\Model\SmartyFilterQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | php | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \SmartyFilter\Model\SmartyFilterQuery) {
return $criteria;
}
$query = new \SmartyFilter\Model\SmartyFilterQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"modelAlias",
"=",
"null",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"\\",
"SmartyFilter",
"\\",
"Model",
"\\",
"SmartyFilterQuery",
")",
"{",
"return",
"$",
"criteria",
";",
"}",
"$",
"query",
"=",
"new",
"\\",
"SmartyFilter",
"\\",
"Model",
"\\",
"SmartyFilterQuery",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"modelAlias",
")",
"{",
"$",
"query",
"->",
"setModelAlias",
"(",
"$",
"modelAlias",
")",
";",
"}",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"query",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Returns a new ChildSmartyFilterQuery object.
@param string $modelAlias The alias of a model in the query
@param Criteria $criteria Optional Criteria to build the query from
@return ChildSmartyFilterQuery | [
"Returns",
"a",
"new",
"ChildSmartyFilterQuery",
"object",
"."
] | e510d281f51ddc4344e563d0f6aaa192fa7171e9 | https://github.com/thelia-modules/SmartyFilter/blob/e510d281f51ddc4344e563d0f6aaa192fa7171e9/Model/Base/SmartyFilterQuery.php#L80-L94 | train |
thelia-modules/SmartyFilter | Model/Base/SmartyFilterQuery.php | SmartyFilterQuery.filterByActive | public function filterByActive($active = null, $comparison = null)
{
if (is_array($active)) {
$useMinMax = false;
if (isset($active['min'])) {
$this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($active['max'])) {
$this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active, $comparison);
} | php | public function filterByActive($active = null, $comparison = null)
{
if (is_array($active)) {
$useMinMax = false;
if (isset($active['min'])) {
$this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($active['max'])) {
$this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SmartyFilterTableMap::ACTIVE, $active, $comparison);
} | [
"public",
"function",
"filterByActive",
"(",
"$",
"active",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"active",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"active",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"SmartyFilterTableMap",
"::",
"ACTIVE",
",",
"$",
"active",
"[",
"'min'",
"]",
",",
"Criteria",
"::",
"GREATER_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"active",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addUsingAlias",
"(",
"SmartyFilterTableMap",
"::",
"ACTIVE",
",",
"$",
"active",
"[",
"'max'",
"]",
",",
"Criteria",
"::",
"LESS_EQUAL",
")",
";",
"$",
"useMinMax",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"useMinMax",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"SmartyFilterTableMap",
"::",
"ACTIVE",
",",
"$",
"active",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the active column
Example usage:
<code>
$query->filterByActive(1234); // WHERE active = 1234
$query->filterByActive(array(12, 34)); // WHERE active IN (12, 34)
$query->filterByActive(array('min' => 12)); // WHERE active > 12
</code>
@param mixed $active The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildSmartyFilterQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"active",
"column"
] | e510d281f51ddc4344e563d0f6aaa192fa7171e9 | https://github.com/thelia-modules/SmartyFilter/blob/e510d281f51ddc4344e563d0f6aaa192fa7171e9/Model/Base/SmartyFilterQuery.php#L289-L310 | train |
thelia-modules/SmartyFilter | Model/Base/SmartyFilterQuery.php | SmartyFilterQuery.filterByFiltertype | public function filterByFiltertype($filtertype = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($filtertype)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $filtertype)) {
$filtertype = str_replace('*', '%', $filtertype);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(SmartyFilterTableMap::FILTERTYPE, $filtertype, $comparison);
} | php | public function filterByFiltertype($filtertype = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($filtertype)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $filtertype)) {
$filtertype = str_replace('*', '%', $filtertype);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(SmartyFilterTableMap::FILTERTYPE, $filtertype, $comparison);
} | [
"public",
"function",
"filterByFiltertype",
"(",
"$",
"filtertype",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"filtertype",
")",
")",
"{",
"$",
"comparison",
"=",
"Criteria",
"::",
"IN",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/[\\%\\*]/'",
",",
"$",
"filtertype",
")",
")",
"{",
"$",
"filtertype",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"filtertype",
")",
";",
"$",
"comparison",
"=",
"Criteria",
"::",
"LIKE",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"SmartyFilterTableMap",
"::",
"FILTERTYPE",
",",
"$",
"filtertype",
",",
"$",
"comparison",
")",
";",
"}"
] | Filter the query on the filtertype column
Example usage:
<code>
$query->filterByFiltertype('fooValue'); // WHERE filtertype = 'fooValue'
$query->filterByFiltertype('%fooValue%'); // WHERE filtertype LIKE '%fooValue%'
</code>
@param string $filtertype The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildSmartyFilterQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"filtertype",
"column"
] | e510d281f51ddc4344e563d0f6aaa192fa7171e9 | https://github.com/thelia-modules/SmartyFilter/blob/e510d281f51ddc4344e563d0f6aaa192fa7171e9/Model/Base/SmartyFilterQuery.php#L327-L339 | train |
thelia-modules/SmartyFilter | Model/Base/SmartyFilterQuery.php | SmartyFilterQuery.filterBySmartyFilterI18n | public function filterBySmartyFilterI18n($smartyFilterI18n, $comparison = null)
{
if ($smartyFilterI18n instanceof \SmartyFilter\Model\SmartyFilterI18n) {
return $this
->addUsingAlias(SmartyFilterTableMap::ID, $smartyFilterI18n->getId(), $comparison);
} elseif ($smartyFilterI18n instanceof ObjectCollection) {
return $this
->useSmartyFilterI18nQuery()
->filterByPrimaryKeys($smartyFilterI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterBySmartyFilterI18n() only accepts arguments of type \SmartyFilter\Model\SmartyFilterI18n or Collection');
}
} | php | public function filterBySmartyFilterI18n($smartyFilterI18n, $comparison = null)
{
if ($smartyFilterI18n instanceof \SmartyFilter\Model\SmartyFilterI18n) {
return $this
->addUsingAlias(SmartyFilterTableMap::ID, $smartyFilterI18n->getId(), $comparison);
} elseif ($smartyFilterI18n instanceof ObjectCollection) {
return $this
->useSmartyFilterI18nQuery()
->filterByPrimaryKeys($smartyFilterI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterBySmartyFilterI18n() only accepts arguments of type \SmartyFilter\Model\SmartyFilterI18n or Collection');
}
} | [
"public",
"function",
"filterBySmartyFilterI18n",
"(",
"$",
"smartyFilterI18n",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"smartyFilterI18n",
"instanceof",
"\\",
"SmartyFilter",
"\\",
"Model",
"\\",
"SmartyFilterI18n",
")",
"{",
"return",
"$",
"this",
"->",
"addUsingAlias",
"(",
"SmartyFilterTableMap",
"::",
"ID",
",",
"$",
"smartyFilterI18n",
"->",
"getId",
"(",
")",
",",
"$",
"comparison",
")",
";",
"}",
"elseif",
"(",
"$",
"smartyFilterI18n",
"instanceof",
"ObjectCollection",
")",
"{",
"return",
"$",
"this",
"->",
"useSmartyFilterI18nQuery",
"(",
")",
"->",
"filterByPrimaryKeys",
"(",
"$",
"smartyFilterI18n",
"->",
"getPrimaryKeys",
"(",
")",
")",
"->",
"endUse",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"PropelException",
"(",
"'filterBySmartyFilterI18n() only accepts arguments of type \\SmartyFilter\\Model\\SmartyFilterI18n or Collection'",
")",
";",
"}",
"}"
] | Filter the query by a related \SmartyFilter\Model\SmartyFilterI18n object
@param \SmartyFilter\Model\SmartyFilterI18n|ObjectCollection $smartyFilterI18n the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildSmartyFilterQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"by",
"a",
"related",
"\\",
"SmartyFilter",
"\\",
"Model",
"\\",
"SmartyFilterI18n",
"object"
] | e510d281f51ddc4344e563d0f6aaa192fa7171e9 | https://github.com/thelia-modules/SmartyFilter/blob/e510d281f51ddc4344e563d0f6aaa192fa7171e9/Model/Base/SmartyFilterQuery.php#L378-L391 | train |
thelia-modules/SmartyFilter | Model/Base/SmartyFilterQuery.php | SmartyFilterQuery.useSmartyFilterI18nQuery | public function useSmartyFilterI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinSmartyFilterI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'SmartyFilterI18n', '\SmartyFilter\Model\SmartyFilterI18nQuery');
} | php | public function useSmartyFilterI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinSmartyFilterI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'SmartyFilterI18n', '\SmartyFilter\Model\SmartyFilterI18nQuery');
} | [
"public",
"function",
"useSmartyFilterI18nQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"'LEFT JOIN'",
")",
"{",
"return",
"$",
"this",
"->",
"joinSmartyFilterI18n",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"useQuery",
"(",
"$",
"relationAlias",
"?",
"$",
"relationAlias",
":",
"'SmartyFilterI18n'",
",",
"'\\SmartyFilter\\Model\\SmartyFilterI18nQuery'",
")",
";",
"}"
] | Use the SmartyFilterI18n relation SmartyFilterI18n object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \SmartyFilter\Model\SmartyFilterI18nQuery A secondary query class using the current class as primary query | [
"Use",
"the",
"SmartyFilterI18n",
"relation",
"SmartyFilterI18n",
"object"
] | e510d281f51ddc4344e563d0f6aaa192fa7171e9 | https://github.com/thelia-modules/SmartyFilter/blob/e510d281f51ddc4344e563d0f6aaa192fa7171e9/Model/Base/SmartyFilterQuery.php#L436-L441 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.