id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
33,300 | clue/reactphp-zenity | src/Dialog/AbstractDialog.php | AbstractDialog.getArgs | public function getArgs()
{
$args = array(
'--' . $this->getType()
);
foreach ($this as $name => $value) {
if (!in_array($name, array('inbuffer')) && $value !== null && $value !== false && !is_array($value)) {
$name = $this->decamelize($name);
if ($value !== true) {
// append value if this is not a boolean arg
$name .= '=' . $value;
}
// all arguments start with a double dash
$args []= '--' . $name;
}
}
return $args;
} | php | public function getArgs()
{
$args = array(
'--' . $this->getType()
);
foreach ($this as $name => $value) {
if (!in_array($name, array('inbuffer')) && $value !== null && $value !== false && !is_array($value)) {
$name = $this->decamelize($name);
if ($value !== true) {
// append value if this is not a boolean arg
$name .= '=' . $value;
}
// all arguments start with a double dash
$args []= '--' . $name;
}
}
return $args;
} | [
"public",
"function",
"getArgs",
"(",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'--'",
".",
"$",
"this",
"->",
"getType",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"array",
"(",
"'inbuffer'",
")",
")",
"&&",
"$",
"value",
"!==",
"null",
"&&",
"$",
"value",
"!==",
"false",
"&&",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"decamelize",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"true",
")",
"{",
"// append value if this is not a boolean arg",
"$",
"name",
".=",
"'='",
".",
"$",
"value",
";",
"}",
"// all arguments start with a double dash",
"$",
"args",
"[",
"]",
"=",
"'--'",
".",
"$",
"name",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}"
] | Returns an array of arguments to pass to the zenity bin to produce the current dialog.
Internally, this will automatically fetch all properties of the current
instance and format them accordingly to zenity arguments.
@return string[]
@internal | [
"Returns",
"an",
"array",
"of",
"arguments",
"to",
"pass",
"to",
"the",
"zenity",
"bin",
"to",
"produce",
"the",
"current",
"dialog",
"."
] | f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964 | https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Dialog/AbstractDialog.php#L168-L189 |
33,301 | clue/reactphp-zenity | src/Zen/ListZen.php | ListZen.parseValue | public function parseValue($value)
{
if (trim($value) === '') {
// TODO: move logic
return false;
}
// always split on separator, even if we only return a single value (explicitly or a checklist)
// work around an issue in zenity 3.8: https://bugzilla.gnome.org/show_bug.cgi?id=698683
$value = explode($this->separator, $value);
if ($this->single) {
$value = $value[0];
}
return $value;
} | php | public function parseValue($value)
{
if (trim($value) === '') {
// TODO: move logic
return false;
}
// always split on separator, even if we only return a single value (explicitly or a checklist)
// work around an issue in zenity 3.8: https://bugzilla.gnome.org/show_bug.cgi?id=698683
$value = explode($this->separator, $value);
if ($this->single) {
$value = $value[0];
}
return $value;
} | [
"public",
"function",
"parseValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"value",
")",
"===",
"''",
")",
"{",
"// TODO: move logic",
"return",
"false",
";",
"}",
"// always split on separator, even if we only return a single value (explicitly or a checklist)",
"// work around an issue in zenity 3.8: https://bugzilla.gnome.org/show_bug.cgi?id=698683",
"$",
"value",
"=",
"explode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"single",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Parses the string returned from the dialog
Usually, this will return a single string.
If the `setMultiple(true)` option is active or this is a checklist, this
will return an array of strings instead. The size of the array depends on
the number of rows selected by the user.
@internal
@see parent::parseValue()
@return string|string[] a single or any number of strings depending on the multiple setting
@see ListDialog::setMultiple() | [
"Parses",
"the",
"string",
"returned",
"from",
"the",
"dialog"
] | f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964 | https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Zen/ListZen.php#L32-L46 |
33,302 | clue/reactphp-zenity | src/Dialog/FormsDialog.php | FormsDialog.addList | public function addList($name, array $values, array $columns = null, $showHeaders = null)
{
$this->fields[] = '--add-list=' . $name;
$this->fields[] = '--list-values=' . implode('|', $values);
// columns given => show headers if it's not explicitly disabled
if ($columns !== null && $showHeaders === null) {
$showHeaders = true;
}
if ($showHeaders) {
$this->fields[] = '--show-header';
}
if ($columns !== null) {
$this->fields[] = '--column-values=' . implode('|', $columns);
}
return $this;
} | php | public function addList($name, array $values, array $columns = null, $showHeaders = null)
{
$this->fields[] = '--add-list=' . $name;
$this->fields[] = '--list-values=' . implode('|', $values);
// columns given => show headers if it's not explicitly disabled
if ($columns !== null && $showHeaders === null) {
$showHeaders = true;
}
if ($showHeaders) {
$this->fields[] = '--show-header';
}
if ($columns !== null) {
$this->fields[] = '--column-values=' . implode('|', $columns);
}
return $this;
} | [
"public",
"function",
"addList",
"(",
"$",
"name",
",",
"array",
"$",
"values",
",",
"array",
"$",
"columns",
"=",
"null",
",",
"$",
"showHeaders",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"'--add-list='",
".",
"$",
"name",
";",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"'--list-values='",
".",
"implode",
"(",
"'|'",
",",
"$",
"values",
")",
";",
"// columns given => show headers if it's not explicitly disabled",
"if",
"(",
"$",
"columns",
"!==",
"null",
"&&",
"$",
"showHeaders",
"===",
"null",
")",
"{",
"$",
"showHeaders",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"showHeaders",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"'--show-header'",
";",
"}",
"if",
"(",
"$",
"columns",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"'--column-values='",
".",
"implode",
"(",
"'|'",
",",
"$",
"columns",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a new List in forms dialog.
Only one single row can be selected in the list. The default selection is
the first row.
A simple list can be added like this:
<code>
$values = array('blue', 'red');
$dialog->addList('Favorite color', $values);
</code>
Selecting a value in this list will return either 'blue' (which is also
the default selection) or 'red'.
A table can be added like this:
<code>
$values = array('Nobody', 'nobody@example.com', 'Frank', 'frank@example.org');
$dialog->addList('Target', $values, array('Name', 'Email'));
</code>
The $columns will be uses as headers in the table. If you do not want this,
you can pass a `$showHeaders = false` flag. This will present a table
to the user with no column headers, so the actual column names will not
be visible at all.
Selecting a row in this table will return all values in this row
concatenated with no separator. The default will be 'Nobodynobody@example.com'.
Unfortunately, there does not appear to be a way to change this behavior.
You can work around this limitation by adding a unique separator to the
field values yourself, for example like this:
<code>
$values = array('Nobody ', 'nobody@example.com');
</code>
This will return the string 'Nobody nobody@example.com'.
Make sure the values do not contain a "|" character. Internally, this
character will be used to separate multiple values from one another.
As such, the following two examples are equivalent:
<code>
$values = array('my|name', 'test');
$values = array('my', 'name', 'test');
</code>
Unfortunately, there does not appear to be a way to change this behavior.
Attention, support for lists within forms is somewhat limited. Adding a
single list works fine, but anything beyond that will *very* likely
either confuse or segfault zenity. Neither the man page nor the online
documentation seem to list this feature (2014-08-02), see
`zenity --help-forms` for (some) details.
@param string $name
@param array $values
@param array|null $columns
@param boolean|null $showHeaders
@return self chainable
@link https://mail.gnome.org/archives/commits-list/2011-October/msg04739.html | [
"Add",
"a",
"new",
"List",
"in",
"forms",
"dialog",
"."
] | f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964 | https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Dialog/FormsDialog.php#L120-L140 |
33,303 | clue/reactphp-zenity | src/Launcher.php | Launcher.waitFor | public function waitFor(AbstractDialog $dialog)
{
$done = false;
$ret = null;
$loop = $this->loop;
$process = $this->launch($dialog);
$process->then(function ($result) use (&$ret, &$done, $loop) {
$ret = $result;
$done = true;
$loop->stop();
}, function () use (&$ret, &$done, $loop) {
$ret = false;
$done = true;
$loop->stop();
});
if (!$done) {
$loop->run();
}
return $ret;
} | php | public function waitFor(AbstractDialog $dialog)
{
$done = false;
$ret = null;
$loop = $this->loop;
$process = $this->launch($dialog);
$process->then(function ($result) use (&$ret, &$done, $loop) {
$ret = $result;
$done = true;
$loop->stop();
}, function () use (&$ret, &$done, $loop) {
$ret = false;
$done = true;
$loop->stop();
});
if (!$done) {
$loop->run();
}
return $ret;
} | [
"public",
"function",
"waitFor",
"(",
"AbstractDialog",
"$",
"dialog",
")",
"{",
"$",
"done",
"=",
"false",
";",
"$",
"ret",
"=",
"null",
";",
"$",
"loop",
"=",
"$",
"this",
"->",
"loop",
";",
"$",
"process",
"=",
"$",
"this",
"->",
"launch",
"(",
"$",
"dialog",
")",
";",
"$",
"process",
"->",
"then",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"&",
"$",
"ret",
",",
"&",
"$",
"done",
",",
"$",
"loop",
")",
"{",
"$",
"ret",
"=",
"$",
"result",
";",
"$",
"done",
"=",
"true",
";",
"$",
"loop",
"->",
"stop",
"(",
")",
";",
"}",
",",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"ret",
",",
"&",
"$",
"done",
",",
"$",
"loop",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"$",
"done",
"=",
"true",
";",
"$",
"loop",
"->",
"stop",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"done",
")",
"{",
"$",
"loop",
"->",
"run",
"(",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Block while waiting for the given dialog to return
If the dialog is already closed, this returns immediately, without doing
much at all. If the dialog is not yet opened, it will be opened and this
method will wait for the dialog to be handled (i.e. either completed or
closed). Clicking "ok" will result in a boolean true value, clicking
"cancel" or hitten escape key will or running into a timeout will result
in a boolean false. For all other input fields, their respective (parsed)
value will be returned.
For this to work, this method will temporarily start the event loop and
stop it afterwards. Thus, it is *NOT* a good idea to mix this if anything
else is listening on the event loop. The recommended way in this case is
to avoid using this blocking method call and go for a fully async
`self::then()` instead.
@param AbstractDialog $dialog
@return boolean|string dialog return value
@uses Launcher::waitFor() | [
"Block",
"while",
"waiting",
"for",
"the",
"given",
"dialog",
"to",
"return"
] | f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964 | https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Launcher.php#L81-L106 |
33,304 | clue/reactphp-zenity | src/Zen/FileSelectionZen.php | FileSelectionZen.parseValue | public function parseValue($value)
{
if ($this->multiple) {
$ret = array();
foreach(explode($this->separator, $value) as $path) {
$ret[] = new SplFileInfo($path);
}
return $ret;
}
return new SplFileInfo($value);
} | php | public function parseValue($value)
{
if ($this->multiple) {
$ret = array();
foreach(explode($this->separator, $value) as $path) {
$ret[] = new SplFileInfo($path);
}
return $ret;
}
return new SplFileInfo($value);
} | [
"public",
"function",
"parseValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"multiple",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"value",
")",
"as",
"$",
"path",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"new",
"SplFileInfo",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"return",
"new",
"SplFileInfo",
"(",
"$",
"value",
")",
";",
"}"
] | Parses the path string returned from the dialog into a SplFileInfo object
Usually, this will return a single SplFileInfo object.
If the `setMultiple(true)` option is active, this will return an array
of SplFileInfo objects instead. The size of the array depends on the
number of files selected by the user.
@internal
@see parent::parseValue()
@return SplFileInfo|SplFileInfo[] a single or any number of SplFileInfo objects depending on the multiple setting
@see FileSelectionDialog::setMultiple() | [
"Parses",
"the",
"path",
"string",
"returned",
"from",
"the",
"dialog",
"into",
"a",
"SplFileInfo",
"object"
] | f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964 | https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Zen/FileSelectionZen.php#L33-L45 |
33,305 | kktsvetkov/krumo | class.krumo.php | krumo.headers | public static function headers()
{
// disabled ?
//
if (!self::_debug())
{
return false;
}
if (!function_exists('getallheaders'))
{
function getallheaders()
{
$headers = array ();
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$key = str_replace(
' ',
'-',
ucwords(strtolower(
str_replace('_', ' ', substr($name, 5))
))
);
$headers[$key] = $value;
}
}
return $headers;
}
}
// render it
//
?>
<div class="krumo-title">
This is a list of all HTTP request headers.
</div>
<?php
return self::dump(getallheaders());
} | php | public static function headers()
{
// disabled ?
//
if (!self::_debug())
{
return false;
}
if (!function_exists('getallheaders'))
{
function getallheaders()
{
$headers = array ();
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$key = str_replace(
' ',
'-',
ucwords(strtolower(
str_replace('_', ' ', substr($name, 5))
))
);
$headers[$key] = $value;
}
}
return $headers;
}
}
// render it
//
?>
<div class="krumo-title">
This is a list of all HTTP request headers.
</div>
<?php
return self::dump(getallheaders());
} | [
"public",
"static",
"function",
"headers",
"(",
")",
"{",
"// disabled ?\r",
"//\r",
"if",
"(",
"!",
"self",
"::",
"_debug",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"function_exists",
"(",
"'getallheaders'",
")",
")",
"{",
"function",
"getallheaders",
"(",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"_SERVER",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"5",
")",
"==",
"'HTTP_'",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"ucwords",
"(",
"strtolower",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"substr",
"(",
"$",
"name",
",",
"5",
")",
")",
")",
")",
")",
";",
"$",
"headers",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"headers",
";",
"}",
"}",
"// render it\r",
"//\r",
"?>\r\n<div class=\"krumo-title\">\r\nThis is a list of all HTTP request headers.\r\n</div>\r\n\t\t<?php",
"return",
"self",
"::",
"dump",
"(",
"getallheaders",
"(",
")",
")",
";",
"}"
] | Prints a list of all HTTP request headers. | [
"Prints",
"a",
"list",
"of",
"all",
"HTTP",
"request",
"headers",
"."
] | fc8bfbb350ca481446820a665afe93ab98423e1e | https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L213-L253 |
33,306 | kktsvetkov/krumo | class.krumo.php | krumo.fetch | public static function fetch($data)
{
// disabled ?
//
if (!self::_debug())
{
return false;
}
ob_start();
call_user_func_array(
array(__CLASS__, 'dump'),
func_get_args()
);
return ob_get_clean();
} | php | public static function fetch($data)
{
// disabled ?
//
if (!self::_debug())
{
return false;
}
ob_start();
call_user_func_array(
array(__CLASS__, 'dump'),
func_get_args()
);
return ob_get_clean();
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"data",
")",
"{",
"// disabled ?\r",
"//\r",
"if",
"(",
"!",
"self",
"::",
"_debug",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"ob_start",
"(",
")",
";",
"call_user_func_array",
"(",
"array",
"(",
"__CLASS__",
",",
"'dump'",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] | Return the dump information about a variable
@param mixed $data,... | [
"Return",
"the",
"dump",
"information",
"about",
"a",
"variable"
] | fc8bfbb350ca481446820a665afe93ab98423e1e | https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L649-L665 |
33,307 | kktsvetkov/krumo | class.krumo.php | krumo.& | private static function &_hive(&$bee)
{
static $_ = array();
// new bee ?
//
if (!is_null($bee))
{
// stain it
//
$_recursion_marker = self::_marker();
(is_object($bee))
? (empty($bee->$_recursion_marker)
? $bee->$_recursion_marker = 1
: $bee->$_recursion_marker++
)
: (empty($bee[$_recursion_marker])
? $bee[$_recursion_marker] = 1
: $bee[$_recursion_marker]++
);
$_[0][] =& $bee; // KT: stupid PHP4 static reference hack
}
// return all bees
//
return $_[0];
} | php | private static function &_hive(&$bee)
{
static $_ = array();
// new bee ?
//
if (!is_null($bee))
{
// stain it
//
$_recursion_marker = self::_marker();
(is_object($bee))
? (empty($bee->$_recursion_marker)
? $bee->$_recursion_marker = 1
: $bee->$_recursion_marker++
)
: (empty($bee[$_recursion_marker])
? $bee[$_recursion_marker] = 1
: $bee[$_recursion_marker]++
);
$_[0][] =& $bee; // KT: stupid PHP4 static reference hack
}
// return all bees
//
return $_[0];
} | [
"private",
"static",
"function",
"&",
"_hive",
"(",
"&",
"$",
"bee",
")",
"{",
"static",
"$",
"_",
"=",
"array",
"(",
")",
";",
"// new bee ?\r",
"//\r",
"if",
"(",
"!",
"is_null",
"(",
"$",
"bee",
")",
")",
"{",
"// stain it\r",
"//\r",
"$",
"_recursion_marker",
"=",
"self",
"::",
"_marker",
"(",
")",
";",
"(",
"is_object",
"(",
"$",
"bee",
")",
")",
"?",
"(",
"empty",
"(",
"$",
"bee",
"->",
"$",
"_recursion_marker",
")",
"?",
"$",
"bee",
"->",
"$",
"_recursion_marker",
"=",
"1",
":",
"$",
"bee",
"->",
"$",
"_recursion_marker",
"++",
")",
":",
"(",
"empty",
"(",
"$",
"bee",
"[",
"$",
"_recursion_marker",
"]",
")",
"?",
"$",
"bee",
"[",
"$",
"_recursion_marker",
"]",
"=",
"1",
":",
"$",
"bee",
"[",
"$",
"_recursion_marker",
"]",
"++",
")",
";",
"$",
"_",
"[",
"0",
"]",
"[",
"]",
"=",
"&",
"$",
"bee",
";",
"// KT: stupid PHP4 static reference hack\r",
"}",
"// return all bees\r",
"//\r",
"return",
"$",
"_",
"[",
"0",
"]",
";",
"}"
] | Adds a variable to the hive of arrays and objects which
are tracked for whether they have recursive entries
@param mixed &$bee either array or object, not a scallar vale
@return array all the bees | [
"Adds",
"a",
"variable",
"to",
"the",
"hive",
"of",
"arrays",
"and",
"objects",
"which",
"are",
"tracked",
"for",
"whether",
"they",
"have",
"recursive",
"entries"
] | fc8bfbb350ca481446820a665afe93ab98423e1e | https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L944-L972 |
33,308 | netgen-layouts/content-browser | bundle/EventListener/SetCurrentBackendListener.php | SetCurrentBackendListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
if (!$attributes->has('itemType')) {
return;
}
$backend = $this->backendRegistry->getBackend($attributes->get('itemType'));
$this->container->set('netgen_content_browser.current_backend', $backend);
} | php | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
if (!$attributes->has('itemType')) {
return;
}
$backend = $this->backendRegistry->getBackend($attributes->get('itemType'));
$this->container->set('netgen_content_browser.current_backend', $backend);
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
";",
"if",
"(",
"$",
"attributes",
"->",
"get",
"(",
"SetIsApiRequestListener",
"::",
"API_FLAG_NAME",
")",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"attributes",
"->",
"has",
"(",
"'itemType'",
")",
")",
"{",
"return",
";",
"}",
"$",
"backend",
"=",
"$",
"this",
"->",
"backendRegistry",
"->",
"getBackend",
"(",
"$",
"attributes",
"->",
"get",
"(",
"'itemType'",
")",
")",
";",
"$",
"this",
"->",
"container",
"->",
"set",
"(",
"'netgen_content_browser.current_backend'",
",",
"$",
"backend",
")",
";",
"}"
] | Injects the current backend into container. | [
"Injects",
"the",
"current",
"backend",
"into",
"container",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentBackendListener.php#L39-L56 |
33,309 | zicht/symfony-util | src/Zicht/SymfonyUtil/HttpKernel/Kernel.php | Kernel.getConfigFiles | protected function getConfigFiles()
{
$ret = [];
foreach ($this->getCandidateConfigFiles() as $configFile) {
if (is_file($configFile)) {
$ret[]= $configFile;
break;
}
}
$configFile = join(
'/',
[
$this->getRootDir(),
'config',
sprintf('kernel_%s.yml', $this->getName())
]
);
if (is_file($configFile)) {
$ret[]= $configFile;
}
return $ret;
} | php | protected function getConfigFiles()
{
$ret = [];
foreach ($this->getCandidateConfigFiles() as $configFile) {
if (is_file($configFile)) {
$ret[]= $configFile;
break;
}
}
$configFile = join(
'/',
[
$this->getRootDir(),
'config',
sprintf('kernel_%s.yml', $this->getName())
]
);
if (is_file($configFile)) {
$ret[]= $configFile;
}
return $ret;
} | [
"protected",
"function",
"getConfigFiles",
"(",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getCandidateConfigFiles",
"(",
")",
"as",
"$",
"configFile",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"configFile",
")",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"configFile",
";",
"break",
";",
"}",
"}",
"$",
"configFile",
"=",
"join",
"(",
"'/'",
",",
"[",
"$",
"this",
"->",
"getRootDir",
"(",
")",
",",
"'config'",
",",
"sprintf",
"(",
"'kernel_%s.yml'",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
"]",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"configFile",
")",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"configFile",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get all config files which should be loaded. Can be overridden for custom logic.
By default, following files are loaded (relativy to `getRootDir()`)
- if `config/config_local.yml` exists, load that.
- if `config/config_local.yml` does not exist, load `config/config_{environment}.yml`
- additionally: `config/kernel_{name}.yml`
@return array | [
"Get",
"all",
"config",
"files",
"which",
"should",
"be",
"loaded",
".",
"Can",
"be",
"overridden",
"for",
"custom",
"logic",
"."
] | ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d | https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L126-L147 |
33,310 | zicht/symfony-util | src/Zicht/SymfonyUtil/HttpKernel/Kernel.php | Kernel.attachSession | protected function attachSession(Request $request)
{
// TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI.
$container = $this->bootLightweightContainer();
if ($this->sessionConfig && @is_readable($this->getRootDir() . '/' . $this->sessionConfig)) {
require_once $this->getRootDir() . '/' . $this->sessionConfig;
if ($request->cookies->has($container->getParameter('session.name'))) {
if (is_readable($this->getCacheDir() . '/classes.php')) {
require_once $this->getCacheDir() . '/classes.php';
}
$class = $container->getParameter('session.handler.class');
$session = new Session\Session(
new Session\Storage\NativeSessionStorage(
array(
'cookie_path' => $container->getParameter('session.cookie_path'),
'cookie_domain' => $container->getParameter('session.cookie_domain'),
'name' => $container->getParameter('session.name')
),
new $class($container->getParameter('session.handler.save_path')),
new Session\Storage\MetadataBag()
),
new Session\Attribute\AttributeBag(),
new Session\Flash\FlashBag()
);
$this->lightweightContainer->set('session', $session);
$request->setSession($session);
}
}
} | php | protected function attachSession(Request $request)
{
// TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI.
$container = $this->bootLightweightContainer();
if ($this->sessionConfig && @is_readable($this->getRootDir() . '/' . $this->sessionConfig)) {
require_once $this->getRootDir() . '/' . $this->sessionConfig;
if ($request->cookies->has($container->getParameter('session.name'))) {
if (is_readable($this->getCacheDir() . '/classes.php')) {
require_once $this->getCacheDir() . '/classes.php';
}
$class = $container->getParameter('session.handler.class');
$session = new Session\Session(
new Session\Storage\NativeSessionStorage(
array(
'cookie_path' => $container->getParameter('session.cookie_path'),
'cookie_domain' => $container->getParameter('session.cookie_domain'),
'name' => $container->getParameter('session.name')
),
new $class($container->getParameter('session.handler.save_path')),
new Session\Storage\MetadataBag()
),
new Session\Attribute\AttributeBag(),
new Session\Flash\FlashBag()
);
$this->lightweightContainer->set('session', $session);
$request->setSession($session);
}
}
} | [
"protected",
"function",
"attachSession",
"(",
"Request",
"$",
"request",
")",
"{",
"// TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI.",
"$",
"container",
"=",
"$",
"this",
"->",
"bootLightweightContainer",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sessionConfig",
"&&",
"@",
"is_readable",
"(",
"$",
"this",
"->",
"getRootDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"sessionConfig",
")",
")",
"{",
"require_once",
"$",
"this",
"->",
"getRootDir",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"sessionConfig",
";",
"if",
"(",
"$",
"request",
"->",
"cookies",
"->",
"has",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'session.name'",
")",
")",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"this",
"->",
"getCacheDir",
"(",
")",
".",
"'/classes.php'",
")",
")",
"{",
"require_once",
"$",
"this",
"->",
"getCacheDir",
"(",
")",
".",
"'/classes.php'",
";",
"}",
"$",
"class",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'session.handler.class'",
")",
";",
"$",
"session",
"=",
"new",
"Session",
"\\",
"Session",
"(",
"new",
"Session",
"\\",
"Storage",
"\\",
"NativeSessionStorage",
"(",
"array",
"(",
"'cookie_path'",
"=>",
"$",
"container",
"->",
"getParameter",
"(",
"'session.cookie_path'",
")",
",",
"'cookie_domain'",
"=>",
"$",
"container",
"->",
"getParameter",
"(",
"'session.cookie_domain'",
")",
",",
"'name'",
"=>",
"$",
"container",
"->",
"getParameter",
"(",
"'session.name'",
")",
")",
",",
"new",
"$",
"class",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'session.handler.save_path'",
")",
")",
",",
"new",
"Session",
"\\",
"Storage",
"\\",
"MetadataBag",
"(",
")",
")",
",",
"new",
"Session",
"\\",
"Attribute",
"\\",
"AttributeBag",
"(",
")",
",",
"new",
"Session",
"\\",
"Flash",
"\\",
"FlashBag",
"(",
")",
")",
";",
"$",
"this",
"->",
"lightweightContainer",
"->",
"set",
"(",
"'session'",
",",
"$",
"session",
")",
";",
"$",
"request",
"->",
"setSession",
"(",
"$",
"session",
")",
";",
"}",
"}",
"}"
] | Attach a session to the request.
@param Request $request
@return void | [
"Attach",
"a",
"session",
"to",
"the",
"request",
"."
] | ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d | https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L187-L218 |
33,311 | zicht/symfony-util | src/Zicht/SymfonyUtil/HttpKernel/Kernel.php | Kernel.bootLightweightContainer | protected function bootLightweightContainer()
{
if (null === $this->lightweightContainer) {
$this->lightweightContainer
= $container
= new Container();
foreach ($this->getKernelParameters() as $param => $value) {
$this->lightweightContainer->setParameter($param, $value);
}
}
return $this->lightweightContainer;
} | php | protected function bootLightweightContainer()
{
if (null === $this->lightweightContainer) {
$this->lightweightContainer
= $container
= new Container();
foreach ($this->getKernelParameters() as $param => $value) {
$this->lightweightContainer->setParameter($param, $value);
}
}
return $this->lightweightContainer;
} | [
"protected",
"function",
"bootLightweightContainer",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"lightweightContainer",
")",
"{",
"$",
"this",
"->",
"lightweightContainer",
"=",
"$",
"container",
"=",
"new",
"Container",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getKernelParameters",
"(",
")",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"lightweightContainer",
"->",
"setParameter",
"(",
"$",
"param",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"lightweightContainer",
";",
"}"
] | Boot a lightweight container which can be used for early request handling
@return null|Container | [
"Boot",
"a",
"lightweight",
"container",
"which",
"can",
"be",
"used",
"for",
"early",
"request",
"handling"
] | ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d | https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L225-L237 |
33,312 | netgen-layouts/content-browser | bundle/Controller/API/LoadConfig.php | LoadConfig.getAvailableColumns | private function getAvailableColumns(): array
{
$availableColumns = [];
foreach ($this->config->getColumns() as $identifier => $columnData) {
$availableColumns[] = [
'id' => $identifier,
'name' => $this->translator->trans($columnData['name'], [], 'ngcb'),
];
}
return $availableColumns;
} | php | private function getAvailableColumns(): array
{
$availableColumns = [];
foreach ($this->config->getColumns() as $identifier => $columnData) {
$availableColumns[] = [
'id' => $identifier,
'name' => $this->translator->trans($columnData['name'], [], 'ngcb'),
];
}
return $availableColumns;
} | [
"private",
"function",
"getAvailableColumns",
"(",
")",
":",
"array",
"{",
"$",
"availableColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"getColumns",
"(",
")",
"as",
"$",
"identifier",
"=>",
"$",
"columnData",
")",
"{",
"$",
"availableColumns",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"identifier",
",",
"'name'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"columnData",
"[",
"'name'",
"]",
",",
"[",
"]",
",",
"'ngcb'",
")",
",",
"]",
";",
"}",
"return",
"$",
"availableColumns",
";",
"}"
] | Returns the list of available columns from configuration. | [
"Returns",
"the",
"list",
"of",
"available",
"columns",
"from",
"configuration",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/Controller/API/LoadConfig.php#L76-L88 |
33,313 | PhpGt/Input | src/Input.php | Input.contains | public function contains(string $key, string $method = null):bool {
if(is_null($method)) {
$method = self::DATA_COMBINED;
}
switch($method) {
case self::DATA_QUERYSTRING:
$isset = $this->containsQueryStringParameter($key);
break;
case self::DATA_BODY:
$isset =$this->containsBodyParameter($key);
break;
case self::DATA_FILES:
$isset =$this->containsFile($key);
break;
case self::DATA_COMBINED:
$isset = isset($this->parameters[$key]);
break;
default:
throw new InvalidInputMethodException($method);
}
return $isset;
} | php | public function contains(string $key, string $method = null):bool {
if(is_null($method)) {
$method = self::DATA_COMBINED;
}
switch($method) {
case self::DATA_QUERYSTRING:
$isset = $this->containsQueryStringParameter($key);
break;
case self::DATA_BODY:
$isset =$this->containsBodyParameter($key);
break;
case self::DATA_FILES:
$isset =$this->containsFile($key);
break;
case self::DATA_COMBINED:
$isset = isset($this->parameters[$key]);
break;
default:
throw new InvalidInputMethodException($method);
}
return $isset;
} | [
"public",
"function",
"contains",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"method",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"is_null",
"(",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"self",
"::",
"DATA_COMBINED",
";",
"}",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"self",
"::",
"DATA_QUERYSTRING",
":",
"$",
"isset",
"=",
"$",
"this",
"->",
"containsQueryStringParameter",
"(",
"$",
"key",
")",
";",
"break",
";",
"case",
"self",
"::",
"DATA_BODY",
":",
"$",
"isset",
"=",
"$",
"this",
"->",
"containsBodyParameter",
"(",
"$",
"key",
")",
";",
"break",
";",
"case",
"self",
"::",
"DATA_FILES",
":",
"$",
"isset",
"=",
"$",
"this",
"->",
"containsFile",
"(",
"$",
"key",
")",
";",
"break",
";",
"case",
"self",
"::",
"DATA_COMBINED",
":",
"$",
"isset",
"=",
"isset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"key",
"]",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidInputMethodException",
"(",
"$",
"method",
")",
";",
"}",
"return",
"$",
"isset",
";",
"}"
] | Does the input contain the specified key? | [
"Does",
"the",
"input",
"contain",
"the",
"specified",
"key?"
] | 2a93bb01d1cb05a958309c0d777bd0085726a198 | https://github.com/PhpGt/Input/blob/2a93bb01d1cb05a958309c0d777bd0085726a198/src/Input.php#L146-L173 |
33,314 | PhpGt/Input | src/Input.php | Input.with | public function with(string...$keys):Trigger {
foreach($keys as $key) {
if(!$this->parameters->contains($key)) {
throw new MissingInputParameterException($key);
}
}
return $this->newTrigger("with", ...$keys);
} | php | public function with(string...$keys):Trigger {
foreach($keys as $key) {
if(!$this->parameters->contains($key)) {
throw new MissingInputParameterException($key);
}
}
return $this->newTrigger("with", ...$keys);
} | [
"public",
"function",
"with",
"(",
"string",
"...",
"$",
"keys",
")",
":",
"Trigger",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parameters",
"->",
"contains",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"MissingInputParameterException",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"newTrigger",
"(",
"\"with\"",
",",
"...",
"$",
"keys",
")",
";",
"}"
] | Return a Trigger that will only pass the provided keys to its callback. | [
"Return",
"a",
"Trigger",
"that",
"will",
"only",
"pass",
"the",
"provided",
"keys",
"to",
"its",
"callback",
"."
] | 2a93bb01d1cb05a958309c0d777bd0085726a198 | https://github.com/PhpGt/Input/blob/2a93bb01d1cb05a958309c0d777bd0085726a198/src/Input.php#L234-L242 |
33,315 | netgen-layouts/content-browser | lib/Form/Type/ContentBrowserMultipleType.php | ContentBrowserMultipleType.getItems | private function getItems($itemValues, string $itemType): array
{
$items = [];
foreach ((array) $itemValues as $itemValue) {
try {
$backend = $this->backendRegistry->getBackend($itemType);
$item = $backend->loadItem($itemValue);
$items[$item->getValue()] = $item;
} catch (NotFoundException $e) {
// Do nothing
}
}
return $items;
} | php | private function getItems($itemValues, string $itemType): array
{
$items = [];
foreach ((array) $itemValues as $itemValue) {
try {
$backend = $this->backendRegistry->getBackend($itemType);
$item = $backend->loadItem($itemValue);
$items[$item->getValue()] = $item;
} catch (NotFoundException $e) {
// Do nothing
}
}
return $items;
} | [
"private",
"function",
"getItems",
"(",
"$",
"itemValues",
",",
"string",
"$",
"itemType",
")",
":",
"array",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"itemValues",
"as",
"$",
"itemValue",
")",
"{",
"try",
"{",
"$",
"backend",
"=",
"$",
"this",
"->",
"backendRegistry",
"->",
"getBackend",
"(",
"$",
"itemType",
")",
";",
"$",
"item",
"=",
"$",
"backend",
"->",
"loadItem",
"(",
"$",
"itemValue",
")",
";",
"$",
"items",
"[",
"$",
"item",
"->",
"getValue",
"(",
")",
"]",
"=",
"$",
"item",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"// Do nothing",
"}",
"}",
"return",
"$",
"items",
";",
"}"
] | Returns the array of items for all provided item values.
@param mixed $itemValues
@param string $itemType
@return array | [
"Returns",
"the",
"array",
"of",
"items",
"for",
"all",
"provided",
"item",
"values",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Form/Type/ContentBrowserMultipleType.php#L130-L145 |
33,316 | netgen-layouts/content-browser | bundle/EventListener/SetCurrentConfigListener.php | SetCurrentConfigListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$attributes = $request->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
if (!$attributes->has('itemType')) {
return;
}
$config = $this->loadConfig($attributes->get('itemType'));
$customParams = $request->query->get('customParams', []);
if (!is_array($customParams)) {
throw new RuntimeException(
sprintf(
'Invalid custom parameters specification for "%s" item type.',
$attributes->get('itemType')
)
);
}
$config->addParameters($customParams);
$configLoadEvent = new ConfigLoadEvent($config);
Kernel::VERSION_ID >= 40300 ?
$this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
$this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);
$this->container->set('netgen_content_browser.current_config', $config);
} | php | public function onKernelRequest(GetResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$attributes = $request->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
if (!$attributes->has('itemType')) {
return;
}
$config = $this->loadConfig($attributes->get('itemType'));
$customParams = $request->query->get('customParams', []);
if (!is_array($customParams)) {
throw new RuntimeException(
sprintf(
'Invalid custom parameters specification for "%s" item type.',
$attributes->get('itemType')
)
);
}
$config->addParameters($customParams);
$configLoadEvent = new ConfigLoadEvent($config);
Kernel::VERSION_ID >= 40300 ?
$this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
$this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);
$this->container->set('netgen_content_browser.current_config', $config);
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"request",
"->",
"attributes",
";",
"if",
"(",
"$",
"attributes",
"->",
"get",
"(",
"SetIsApiRequestListener",
"::",
"API_FLAG_NAME",
")",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"attributes",
"->",
"has",
"(",
"'itemType'",
")",
")",
"{",
"return",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"loadConfig",
"(",
"$",
"attributes",
"->",
"get",
"(",
"'itemType'",
")",
")",
";",
"$",
"customParams",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'customParams'",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"customParams",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid custom parameters specification for \"%s\" item type.'",
",",
"$",
"attributes",
"->",
"get",
"(",
"'itemType'",
")",
")",
")",
";",
"}",
"$",
"config",
"->",
"addParameters",
"(",
"$",
"customParams",
")",
";",
"$",
"configLoadEvent",
"=",
"new",
"ConfigLoadEvent",
"(",
"$",
"config",
")",
";",
"Kernel",
"::",
"VERSION_ID",
">=",
"40300",
"?",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"$",
"configLoadEvent",
",",
"ContentBrowserEvents",
"::",
"CONFIG_LOAD",
")",
":",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"ContentBrowserEvents",
"::",
"CONFIG_LOAD",
",",
"$",
"configLoadEvent",
")",
";",
"$",
"this",
"->",
"container",
"->",
"set",
"(",
"'netgen_content_browser.current_config'",
",",
"$",
"config",
")",
";",
"}"
] | Injects the current config into container. | [
"Injects",
"the",
"current",
"config",
"into",
"container",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentConfigListener.php#L45-L82 |
33,317 | netgen-layouts/content-browser | bundle/EventListener/SetCurrentConfigListener.php | SetCurrentConfigListener.loadConfig | private function loadConfig(string $itemType): Configuration
{
$service = 'netgen_content_browser.config.' . $itemType;
if (!$this->container->has($service)) {
throw new InvalidArgumentException(
sprintf(
'Configuration for "%s" item type does not exist.',
$itemType
)
);
}
$config = $this->container->get($service);
if (!$config instanceof Configuration) {
throw new InvalidArgumentException(
sprintf(
'Configuration for "%s" item type is invalid.',
$itemType
)
);
}
return $config;
} | php | private function loadConfig(string $itemType): Configuration
{
$service = 'netgen_content_browser.config.' . $itemType;
if (!$this->container->has($service)) {
throw new InvalidArgumentException(
sprintf(
'Configuration for "%s" item type does not exist.',
$itemType
)
);
}
$config = $this->container->get($service);
if (!$config instanceof Configuration) {
throw new InvalidArgumentException(
sprintf(
'Configuration for "%s" item type is invalid.',
$itemType
)
);
}
return $config;
} | [
"private",
"function",
"loadConfig",
"(",
"string",
"$",
"itemType",
")",
":",
"Configuration",
"{",
"$",
"service",
"=",
"'netgen_content_browser.config.'",
".",
"$",
"itemType",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"service",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Configuration for \"%s\" item type does not exist.'",
",",
"$",
"itemType",
")",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"service",
")",
";",
"if",
"(",
"!",
"$",
"config",
"instanceof",
"Configuration",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Configuration for \"%s\" item type is invalid.'",
",",
"$",
"itemType",
")",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Loads the configuration for provided item type from the container.
@throws \Netgen\ContentBrowser\Exceptions\InvalidArgumentException If config could not be found | [
"Loads",
"the",
"configuration",
"for",
"provided",
"item",
"type",
"from",
"the",
"container",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentConfigListener.php#L89-L113 |
33,318 | netgen-layouts/content-browser | lib/Item/ColumnProvider/ColumnProvider.php | ColumnProvider.provideColumn | private function provideColumn(ItemInterface $item, array $columnConfig): string
{
if (isset($columnConfig['template'])) {
return $this->itemRenderer->renderItem(
$item,
$columnConfig['template']
);
}
if (!isset($this->columnValueProviders[$columnConfig['value_provider']])) {
throw new InvalidArgumentException(
sprintf(
'Column value provider "%s" does not exist',
$columnConfig['value_provider']
)
);
}
$columnValue = $this
->columnValueProviders[$columnConfig['value_provider']]
->getValue($item);
return $columnValue ?? '';
} | php | private function provideColumn(ItemInterface $item, array $columnConfig): string
{
if (isset($columnConfig['template'])) {
return $this->itemRenderer->renderItem(
$item,
$columnConfig['template']
);
}
if (!isset($this->columnValueProviders[$columnConfig['value_provider']])) {
throw new InvalidArgumentException(
sprintf(
'Column value provider "%s" does not exist',
$columnConfig['value_provider']
)
);
}
$columnValue = $this
->columnValueProviders[$columnConfig['value_provider']]
->getValue($item);
return $columnValue ?? '';
} | [
"private",
"function",
"provideColumn",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"columnConfig",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"columnConfig",
"[",
"'template'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"itemRenderer",
"->",
"renderItem",
"(",
"$",
"item",
",",
"$",
"columnConfig",
"[",
"'template'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"columnValueProviders",
"[",
"$",
"columnConfig",
"[",
"'value_provider'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Column value provider \"%s\" does not exist'",
",",
"$",
"columnConfig",
"[",
"'value_provider'",
"]",
")",
")",
";",
"}",
"$",
"columnValue",
"=",
"$",
"this",
"->",
"columnValueProviders",
"[",
"$",
"columnConfig",
"[",
"'value_provider'",
"]",
"]",
"->",
"getValue",
"(",
"$",
"item",
")",
";",
"return",
"$",
"columnValue",
"??",
"''",
";",
"}"
] | Provides the column with specified identifier for selected item.
@throws \Netgen\ContentBrowser\Exceptions\InvalidArgumentException If value provider for the column does not exist | [
"Provides",
"the",
"column",
"with",
"specified",
"identifier",
"for",
"selected",
"item",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Item/ColumnProvider/ColumnProvider.php#L65-L88 |
33,319 | netgen-layouts/content-browser | lib/Form/Type/ContentBrowserDynamicType.php | ContentBrowserDynamicType.getEnabledItemTypes | private function getEnabledItemTypes(array $itemTypes): array
{
$allItemTypes = array_flip(
array_map(
static function (Configuration $config): string {
return $config->getItemName();
},
$this->configRegistry->getConfigs()
)
);
if (count($itemTypes) === 0) {
return $allItemTypes;
}
return array_filter(
$allItemTypes,
static function (string $itemType) use ($itemTypes): bool {
return in_array($itemType, $itemTypes, true);
}
);
} | php | private function getEnabledItemTypes(array $itemTypes): array
{
$allItemTypes = array_flip(
array_map(
static function (Configuration $config): string {
return $config->getItemName();
},
$this->configRegistry->getConfigs()
)
);
if (count($itemTypes) === 0) {
return $allItemTypes;
}
return array_filter(
$allItemTypes,
static function (string $itemType) use ($itemTypes): bool {
return in_array($itemType, $itemTypes, true);
}
);
} | [
"private",
"function",
"getEnabledItemTypes",
"(",
"array",
"$",
"itemTypes",
")",
":",
"array",
"{",
"$",
"allItemTypes",
"=",
"array_flip",
"(",
"array_map",
"(",
"static",
"function",
"(",
"Configuration",
"$",
"config",
")",
":",
"string",
"{",
"return",
"$",
"config",
"->",
"getItemName",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"configRegistry",
"->",
"getConfigs",
"(",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"itemTypes",
")",
"===",
"0",
")",
"{",
"return",
"$",
"allItemTypes",
";",
"}",
"return",
"array_filter",
"(",
"$",
"allItemTypes",
",",
"static",
"function",
"(",
"string",
"$",
"itemType",
")",
"use",
"(",
"$",
"itemTypes",
")",
":",
"bool",
"{",
"return",
"in_array",
"(",
"$",
"itemType",
",",
"$",
"itemTypes",
",",
"true",
")",
";",
"}",
")",
";",
"}"
] | Returns the enabled item types based on provided list. | [
"Returns",
"the",
"enabled",
"item",
"types",
"based",
"on",
"provided",
"list",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Form/Type/ContentBrowserDynamicType.php#L147-L168 |
33,320 | netgen-layouts/content-browser | bundle/EventListener/ExceptionSerializerListener.php | ExceptionSerializerListener.onException | public function onException(GetResponseForExceptionEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
$exception = $event->getException();
$this->logException($exception);
$data = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
];
if ($exception instanceof HttpExceptionInterface) {
$statusCode = $exception->getStatusCode();
if (isset(Response::$statusTexts[$statusCode])) {
$data['status_code'] = $statusCode;
$data['status_text'] = Response::$statusTexts[$statusCode];
}
}
if ($this->outputDebugInfo) {
$debugException = $exception;
if ($exception->getPrevious() instanceof Exception) {
$debugException = $exception->getPrevious();
}
$debugException = FlattenException::create($debugException);
$data['debug'] = [
'file' => $debugException->getFile(),
'line' => $debugException->getLine(),
'trace' => $debugException->getTrace(),
];
}
$event->setResponse(new JsonResponse($data));
} | php | public function onException(GetResponseForExceptionEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$attributes = $event->getRequest()->attributes;
if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
return;
}
$exception = $event->getException();
$this->logException($exception);
$data = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
];
if ($exception instanceof HttpExceptionInterface) {
$statusCode = $exception->getStatusCode();
if (isset(Response::$statusTexts[$statusCode])) {
$data['status_code'] = $statusCode;
$data['status_text'] = Response::$statusTexts[$statusCode];
}
}
if ($this->outputDebugInfo) {
$debugException = $exception;
if ($exception->getPrevious() instanceof Exception) {
$debugException = $exception->getPrevious();
}
$debugException = FlattenException::create($debugException);
$data['debug'] = [
'file' => $debugException->getFile(),
'line' => $debugException->getLine(),
'trace' => $debugException->getTrace(),
];
}
$event->setResponse(new JsonResponse($data));
} | [
"public",
"function",
"onException",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"attributes",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
";",
"if",
"(",
"$",
"attributes",
"->",
"get",
"(",
"SetIsApiRequestListener",
"::",
"API_FLAG_NAME",
")",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"$",
"exception",
"=",
"$",
"event",
"->",
"getException",
"(",
")",
";",
"$",
"this",
"->",
"logException",
"(",
"$",
"exception",
")",
";",
"$",
"data",
"=",
"[",
"'code'",
"=>",
"$",
"exception",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"HttpExceptionInterface",
")",
"{",
"$",
"statusCode",
"=",
"$",
"exception",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"Response",
"::",
"$",
"statusTexts",
"[",
"$",
"statusCode",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'status_code'",
"]",
"=",
"$",
"statusCode",
";",
"$",
"data",
"[",
"'status_text'",
"]",
"=",
"Response",
"::",
"$",
"statusTexts",
"[",
"$",
"statusCode",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"outputDebugInfo",
")",
"{",
"$",
"debugException",
"=",
"$",
"exception",
";",
"if",
"(",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
"instanceof",
"Exception",
")",
"{",
"$",
"debugException",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
";",
"}",
"$",
"debugException",
"=",
"FlattenException",
"::",
"create",
"(",
"$",
"debugException",
")",
";",
"$",
"data",
"[",
"'debug'",
"]",
"=",
"[",
"'file'",
"=>",
"$",
"debugException",
"->",
"getFile",
"(",
")",
",",
"'line'",
"=>",
"$",
"debugException",
"->",
"getLine",
"(",
")",
",",
"'trace'",
"=>",
"$",
"debugException",
"->",
"getTrace",
"(",
")",
",",
"]",
";",
"}",
"$",
"event",
"->",
"setResponse",
"(",
"new",
"JsonResponse",
"(",
"$",
"data",
")",
")",
";",
"}"
] | Serializes the exception. | [
"Serializes",
"the",
"exception",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/ExceptionSerializerListener.php#L45-L89 |
33,321 | netgen-layouts/content-browser | bundle/EventListener/ExceptionSerializerListener.php | ExceptionSerializerListener.logException | private function logException(Exception $exception): void
{
if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
return;
}
$this->logger->critical(
sprintf(
'Uncaught PHP Exception %s: "%s" at %s line %s',
get_class($exception),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
),
['exception' => $exception]
);
} | php | private function logException(Exception $exception): void
{
if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
return;
}
$this->logger->critical(
sprintf(
'Uncaught PHP Exception %s: "%s" at %s line %s',
get_class($exception),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
),
['exception' => $exception]
);
} | [
"private",
"function",
"logException",
"(",
"Exception",
"$",
"exception",
")",
":",
"void",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
"HttpExceptionInterface",
"&&",
"$",
"exception",
"->",
"getStatusCode",
"(",
")",
"<",
"500",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"sprintf",
"(",
"'Uncaught PHP Exception %s: \"%s\" at %s line %s'",
",",
"get_class",
"(",
"$",
"exception",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"$",
"exception",
"->",
"getLine",
"(",
")",
")",
",",
"[",
"'exception'",
"=>",
"$",
"exception",
"]",
")",
";",
"}"
] | Logs all critical errors. | [
"Logs",
"all",
"critical",
"errors",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/ExceptionSerializerListener.php#L94-L110 |
33,322 | netgen-layouts/content-browser | bundle/Controller/API/LoadSubItems.php | LoadSubItems.buildPath | private function buildPath(LocationInterface $location): array
{
$path = [];
while (true) {
$path[] = [
'id' => $location->getLocationId(),
'name' => $location->getName(),
];
if ($location->getParentId() === null) {
break;
}
try {
$location = $this->backend->loadLocation($location->getParentId());
} catch (NotFoundException $e) {
break;
}
}
return array_reverse($path);
} | php | private function buildPath(LocationInterface $location): array
{
$path = [];
while (true) {
$path[] = [
'id' => $location->getLocationId(),
'name' => $location->getName(),
];
if ($location->getParentId() === null) {
break;
}
try {
$location = $this->backend->loadLocation($location->getParentId());
} catch (NotFoundException $e) {
break;
}
}
return array_reverse($path);
} | [
"private",
"function",
"buildPath",
"(",
"LocationInterface",
"$",
"location",
")",
":",
"array",
"{",
"$",
"path",
"=",
"[",
"]",
";",
"while",
"(",
"true",
")",
"{",
"$",
"path",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"location",
"->",
"getLocationId",
"(",
")",
",",
"'name'",
"=>",
"$",
"location",
"->",
"getName",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"location",
"->",
"getParentId",
"(",
")",
"===",
"null",
")",
"{",
"break",
";",
"}",
"try",
"{",
"$",
"location",
"=",
"$",
"this",
"->",
"backend",
"->",
"loadLocation",
"(",
"$",
"location",
"->",
"getParentId",
"(",
")",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"break",
";",
"}",
"}",
"return",
"array_reverse",
"(",
"$",
"path",
")",
";",
"}"
] | Builds the path array for specified item. | [
"Builds",
"the",
"path",
"array",
"for",
"specified",
"item",
"."
] | 34403d59b73b0e804f12746d4418ba44e4991d74 | https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/Controller/API/LoadSubItems.php#L82-L104 |
33,323 | koolkode/bpmn | src/Runtime/RuntimeService.php | RuntimeService.startProcessInstance | public function startProcessInstance(ProcessDefinition $def, $businessKey = null, array $variables = [])
{
$startNode = $def->findNoneStartEvent();
$id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables));
return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne();
} | php | public function startProcessInstance(ProcessDefinition $def, $businessKey = null, array $variables = [])
{
$startNode = $def->findNoneStartEvent();
$id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables));
return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne();
} | [
"public",
"function",
"startProcessInstance",
"(",
"ProcessDefinition",
"$",
"def",
",",
"$",
"businessKey",
"=",
"null",
",",
"array",
"$",
"variables",
"=",
"[",
"]",
")",
"{",
"$",
"startNode",
"=",
"$",
"def",
"->",
"findNoneStartEvent",
"(",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"engine",
"->",
"executeCommand",
"(",
"new",
"StartProcessInstanceCommand",
"(",
"$",
"def",
",",
"$",
"startNode",
",",
"$",
"businessKey",
",",
"$",
"variables",
")",
")",
";",
"return",
"$",
"this",
"->",
"engine",
"->",
"getHistoryService",
"(",
")",
"->",
"createHistoricProcessInstanceQuery",
"(",
")",
"->",
"processInstanceId",
"(",
"$",
"id",
")",
"->",
"findOne",
"(",
")",
";",
"}"
] | Start a process from the given definition using a singular
@param ProcessDefinition $def
@param string $businessKey
@param array<string, mixed> $variables
@return HistoricProcessInstance | [
"Start",
"a",
"process",
"from",
"the",
"given",
"definition",
"using",
"a",
"singular"
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L107-L114 |
33,324 | koolkode/bpmn | src/Runtime/RuntimeService.php | RuntimeService.startProcessInstanceByKey | public function startProcessInstanceByKey($processDefinitionKey, $businessKey = null, array $variables = [])
{
$query = $this->engine->getRepositoryService()->createProcessDefinitionQuery();
$def = $query->processDefinitionKey($processDefinitionKey)->latestVersion()->findOne();
return $this->startProcessInstance($def, $businessKey, $variables);
} | php | public function startProcessInstanceByKey($processDefinitionKey, $businessKey = null, array $variables = [])
{
$query = $this->engine->getRepositoryService()->createProcessDefinitionQuery();
$def = $query->processDefinitionKey($processDefinitionKey)->latestVersion()->findOne();
return $this->startProcessInstance($def, $businessKey, $variables);
} | [
"public",
"function",
"startProcessInstanceByKey",
"(",
"$",
"processDefinitionKey",
",",
"$",
"businessKey",
"=",
"null",
",",
"array",
"$",
"variables",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"engine",
"->",
"getRepositoryService",
"(",
")",
"->",
"createProcessDefinitionQuery",
"(",
")",
";",
"$",
"def",
"=",
"$",
"query",
"->",
"processDefinitionKey",
"(",
"$",
"processDefinitionKey",
")",
"->",
"latestVersion",
"(",
")",
"->",
"findOne",
"(",
")",
";",
"return",
"$",
"this",
"->",
"startProcessInstance",
"(",
"$",
"def",
",",
"$",
"businessKey",
",",
"$",
"variables",
")",
";",
"}"
] | Start a process using the latest version of the given process definition.
@param string $processDefinitionKey
@param string $businessKey
@param array<string, mixed> $variables
@return HistoricProcessInstance | [
"Start",
"a",
"process",
"using",
"the",
"latest",
"version",
"of",
"the",
"given",
"process",
"definition",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L124-L130 |
33,325 | koolkode/bpmn | src/Runtime/RuntimeService.php | RuntimeService.startProcessInstanceByMessage | public function startProcessInstanceByMessage($messageName, $businessKey = null, array $variables = [])
{
$query = $this->engine->getRepositoryService()->createProcessDefinitionQuery();
$def = $query->messageEventSubscriptionName($messageName)->latestVersion()->findOne();
$startNode = $def->findMessageStartEvent($messageName);
$id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables));
return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne();
} | php | public function startProcessInstanceByMessage($messageName, $businessKey = null, array $variables = [])
{
$query = $this->engine->getRepositoryService()->createProcessDefinitionQuery();
$def = $query->messageEventSubscriptionName($messageName)->latestVersion()->findOne();
$startNode = $def->findMessageStartEvent($messageName);
$id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables));
return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne();
} | [
"public",
"function",
"startProcessInstanceByMessage",
"(",
"$",
"messageName",
",",
"$",
"businessKey",
"=",
"null",
",",
"array",
"$",
"variables",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"engine",
"->",
"getRepositoryService",
"(",
")",
"->",
"createProcessDefinitionQuery",
"(",
")",
";",
"$",
"def",
"=",
"$",
"query",
"->",
"messageEventSubscriptionName",
"(",
"$",
"messageName",
")",
"->",
"latestVersion",
"(",
")",
"->",
"findOne",
"(",
")",
";",
"$",
"startNode",
"=",
"$",
"def",
"->",
"findMessageStartEvent",
"(",
"$",
"messageName",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"engine",
"->",
"executeCommand",
"(",
"new",
"StartProcessInstanceCommand",
"(",
"$",
"def",
",",
"$",
"startNode",
",",
"$",
"businessKey",
",",
"$",
"variables",
")",
")",
";",
"return",
"$",
"this",
"->",
"engine",
"->",
"getHistoryService",
"(",
")",
"->",
"createHistoricProcessInstanceQuery",
"(",
")",
"->",
"processInstanceId",
"(",
"$",
"id",
")",
"->",
"findOne",
"(",
")",
";",
"}"
] | Start a process instance by message start event.
@param string $messageName
@param string $businessKey
@param array<string, mixed> $variables
@return HistoricProcessInstance | [
"Start",
"a",
"process",
"instance",
"by",
"message",
"start",
"event",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L140-L149 |
33,326 | koolkode/bpmn | src/Engine/ProcessEngine.php | ProcessEngine.scheduleJob | public function scheduleJob(UUID $executionId, string $handlerType, $data, ?\DateTimeImmutable $runAt = null): ?JobInterface
{
if ($this->jobExecutor !== null) {
return $this->jobExecutor->scheduleJob($executionId, $handlerType, $data, $runAt);
}
} | php | public function scheduleJob(UUID $executionId, string $handlerType, $data, ?\DateTimeImmutable $runAt = null): ?JobInterface
{
if ($this->jobExecutor !== null) {
return $this->jobExecutor->scheduleJob($executionId, $handlerType, $data, $runAt);
}
} | [
"public",
"function",
"scheduleJob",
"(",
"UUID",
"$",
"executionId",
",",
"string",
"$",
"handlerType",
",",
"$",
"data",
",",
"?",
"\\",
"DateTimeImmutable",
"$",
"runAt",
"=",
"null",
")",
":",
"?",
"JobInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"jobExecutor",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"jobExecutor",
"->",
"scheduleJob",
"(",
"$",
"executionId",
",",
"$",
"handlerType",
",",
"$",
"data",
",",
"$",
"runAt",
")",
";",
"}",
"}"
] | Schedule a job for execution.
This method will not cause an error in case of a missing job executor!
@param UUID $executionId Target execution being used by the job.
@param string $handlerType The name of the job handler.
@param mixed $data Arbitrary data to be passed to the job handler.
@param \DateTimeImmutable $runAt Scheduled execution time, a value of null schedules the job for immediate execution.
@return JobInterface The persisted job instance or null when no job executor has been configured. | [
"Schedule",
"a",
"job",
"for",
"execution",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/ProcessEngine.php#L218-L223 |
33,327 | koolkode/bpmn | migration/Version20150212110141.php | Version20150212110141.down | public function down()
{
$def = $this->table('#__bpmn_process_definition');
$def->removeColumn('resource_id');
$def->update();
$subscription = $this->table('#__bpmn_event_subscription');
$subscription->removeColumn('job_id');
$subscription->removeColumn('boundary');
$subscription->update();
$this->dropTable('#__bpmn_job');
} | php | public function down()
{
$def = $this->table('#__bpmn_process_definition');
$def->removeColumn('resource_id');
$def->update();
$subscription = $this->table('#__bpmn_event_subscription');
$subscription->removeColumn('job_id');
$subscription->removeColumn('boundary');
$subscription->update();
$this->dropTable('#__bpmn_job');
} | [
"public",
"function",
"down",
"(",
")",
"{",
"$",
"def",
"=",
"$",
"this",
"->",
"table",
"(",
"'#__bpmn_process_definition'",
")",
";",
"$",
"def",
"->",
"removeColumn",
"(",
"'resource_id'",
")",
";",
"$",
"def",
"->",
"update",
"(",
")",
";",
"$",
"subscription",
"=",
"$",
"this",
"->",
"table",
"(",
"'#__bpmn_event_subscription'",
")",
";",
"$",
"subscription",
"->",
"removeColumn",
"(",
"'job_id'",
")",
";",
"$",
"subscription",
"->",
"removeColumn",
"(",
"'boundary'",
")",
";",
"$",
"subscription",
"->",
"update",
"(",
")",
";",
"$",
"this",
"->",
"dropTable",
"(",
"'#__bpmn_job'",
")",
";",
"}"
] | Migrate down. | [
"Migrate",
"down",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/migration/Version20150212110141.php#L64-L76 |
33,328 | koolkode/bpmn | src/Job/Scheduler/AbstractJobScheduler.php | AbstractJobScheduler.markJobAsScheduled | protected function markJobAsScheduled(Job $job, ?string $externalId = null): void
{
$stmt = $this->engine->prepareQuery("UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id");
$stmt->bindValue('scheduled', \time());
$stmt->bindValue('ex', $externalId);
$stmt->bindValue('id', $job->getId());
$stmt->execute();
} | php | protected function markJobAsScheduled(Job $job, ?string $externalId = null): void
{
$stmt = $this->engine->prepareQuery("UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id");
$stmt->bindValue('scheduled', \time());
$stmt->bindValue('ex', $externalId);
$stmt->bindValue('id', $job->getId());
$stmt->execute();
} | [
"protected",
"function",
"markJobAsScheduled",
"(",
"Job",
"$",
"job",
",",
"?",
"string",
"$",
"externalId",
"=",
"null",
")",
":",
"void",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"engine",
"->",
"prepareQuery",
"(",
"\"UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id\"",
")",
";",
"$",
"stmt",
"->",
"bindValue",
"(",
"'scheduled'",
",",
"\\",
"time",
"(",
")",
")",
";",
"$",
"stmt",
"->",
"bindValue",
"(",
"'ex'",
",",
"$",
"externalId",
")",
";",
"$",
"stmt",
"->",
"bindValue",
"(",
"'id'",
",",
"$",
"job",
"->",
"getId",
"(",
")",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"}"
] | Marks the job is being scheduled by writing a timestamp to the DB.
@param Job $job | [
"Marks",
"the",
"job",
"is",
"being",
"scheduled",
"by",
"writing",
"a",
"timestamp",
"to",
"the",
"DB",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Job/Scheduler/AbstractJobScheduler.php#L41-L48 |
33,329 | koolkode/bpmn | src/Engine/AbstractScopeActivity.php | AbstractScopeActivity.interrupt | public function interrupt(VirtualExecution $execution, ?array $transitions = null): void
{
$this->leave($execution, $transitions, true);
} | php | public function interrupt(VirtualExecution $execution, ?array $transitions = null): void
{
$this->leave($execution, $transitions, true);
} | [
"public",
"function",
"interrupt",
"(",
"VirtualExecution",
"$",
"execution",
",",
"?",
"array",
"$",
"transitions",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"leave",
"(",
"$",
"execution",
",",
"$",
"transitions",
",",
"true",
")",
";",
"}"
] | Interrupt the scope activity. | [
"Interrupt",
"the",
"scope",
"activity",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L88-L91 |
33,330 | koolkode/bpmn | src/Engine/AbstractScopeActivity.php | AbstractScopeActivity.leaveConcurrent | public function leaveConcurrent(VirtualExecution $execution, ?Node $node = null, ?array $transitions = null): VirtualExecution
{
$root = $execution->getScope();
$parent = $root->getParentExecution();
$exec = $parent->createExecution(true);
$exec->setNode(($node === null) ? $execution->getNode() : $node);
$root->setConcurrent(true);
$this->createEventSubscriptions($root, $this->activityId, $execution->getProcessModel()->findNode($this->activityId));
$exec->takeAll($transitions);
return $exec;
} | php | public function leaveConcurrent(VirtualExecution $execution, ?Node $node = null, ?array $transitions = null): VirtualExecution
{
$root = $execution->getScope();
$parent = $root->getParentExecution();
$exec = $parent->createExecution(true);
$exec->setNode(($node === null) ? $execution->getNode() : $node);
$root->setConcurrent(true);
$this->createEventSubscriptions($root, $this->activityId, $execution->getProcessModel()->findNode($this->activityId));
$exec->takeAll($transitions);
return $exec;
} | [
"public",
"function",
"leaveConcurrent",
"(",
"VirtualExecution",
"$",
"execution",
",",
"?",
"Node",
"$",
"node",
"=",
"null",
",",
"?",
"array",
"$",
"transitions",
"=",
"null",
")",
":",
"VirtualExecution",
"{",
"$",
"root",
"=",
"$",
"execution",
"->",
"getScope",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"root",
"->",
"getParentExecution",
"(",
")",
";",
"$",
"exec",
"=",
"$",
"parent",
"->",
"createExecution",
"(",
"true",
")",
";",
"$",
"exec",
"->",
"setNode",
"(",
"(",
"$",
"node",
"===",
"null",
")",
"?",
"$",
"execution",
"->",
"getNode",
"(",
")",
":",
"$",
"node",
")",
";",
"$",
"root",
"->",
"setConcurrent",
"(",
"true",
")",
";",
"$",
"this",
"->",
"createEventSubscriptions",
"(",
"$",
"root",
",",
"$",
"this",
"->",
"activityId",
",",
"$",
"execution",
"->",
"getProcessModel",
"(",
")",
"->",
"findNode",
"(",
"$",
"this",
"->",
"activityId",
")",
")",
";",
"$",
"exec",
"->",
"takeAll",
"(",
"$",
"transitions",
")",
";",
"return",
"$",
"exec",
";",
"}"
] | Create a new execution concurrent to the given execution and have it take the given transitions.
If the given execution is concurrent this method will create a new child execution from the parent execution.
Otherwise a new concurrent root will be introduced as parent of the given execution. | [
"Create",
"a",
"new",
"execution",
"concurrent",
"to",
"the",
"given",
"execution",
"and",
"have",
"it",
"take",
"the",
"given",
"transitions",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L129-L144 |
33,331 | koolkode/bpmn | src/Engine/AbstractScopeActivity.php | AbstractScopeActivity.findAttachedBoundaryActivities | public function findAttachedBoundaryActivities(VirtualExecution $execution): array
{
$model = $execution->getProcessModel();
$activities = [];
foreach ($model->findNodes() as $node) {
$behavior = $node->getBehavior();
if ($behavior instanceof AbstractBoundaryActivity) {
if ($this->activityId == $behavior->getAttachedTo()) {
$activities[] = $node;
}
}
}
return $activities;
} | php | public function findAttachedBoundaryActivities(VirtualExecution $execution): array
{
$model = $execution->getProcessModel();
$activities = [];
foreach ($model->findNodes() as $node) {
$behavior = $node->getBehavior();
if ($behavior instanceof AbstractBoundaryActivity) {
if ($this->activityId == $behavior->getAttachedTo()) {
$activities[] = $node;
}
}
}
return $activities;
} | [
"public",
"function",
"findAttachedBoundaryActivities",
"(",
"VirtualExecution",
"$",
"execution",
")",
":",
"array",
"{",
"$",
"model",
"=",
"$",
"execution",
"->",
"getProcessModel",
"(",
")",
";",
"$",
"activities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"model",
"->",
"findNodes",
"(",
")",
"as",
"$",
"node",
")",
"{",
"$",
"behavior",
"=",
"$",
"node",
"->",
"getBehavior",
"(",
")",
";",
"if",
"(",
"$",
"behavior",
"instanceof",
"AbstractBoundaryActivity",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"activityId",
"==",
"$",
"behavior",
"->",
"getAttachedTo",
"(",
")",
")",
"{",
"$",
"activities",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"}",
"return",
"$",
"activities",
";",
"}"
] | Collect all boundary events connected to the activity of the given execution. | [
"Collect",
"all",
"boundary",
"events",
"connected",
"to",
"the",
"activity",
"of",
"the",
"given",
"execution",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L149-L165 |
33,332 | koolkode/bpmn | src/Runtime/Command/AbstractCreateSubscriptionCommand.php | AbstractCreateSubscriptionCommand.createSubscription | protected function createSubscription(ProcessEngine $engine, ?Job $job = null): void
{
$execution = $engine->findExecution($this->executionId);
$nodeId = ($this->nodeId === null) ? null : $execution->getProcessModel()->findNode($this->nodeId)->getId();
$data = [
'id' => UUID::createRandom(),
'execution_id' => $execution->getId(),
'activity_id' => $this->activityId,
'node' => $nodeId,
'process_instance_id' => $execution->getRootExecution()->getId(),
'flags' => $this->getSubscriptionFlag(),
'boundary' => $this->boundaryEvent ? 1 : 0,
'name' => $this->name,
'created_at' => \time()
];
if ($job !== null) {
$data['job_id'] = $job->getId();
}
$engine->getConnection()->insert('#__bpmn_event_subscription', $data);
} | php | protected function createSubscription(ProcessEngine $engine, ?Job $job = null): void
{
$execution = $engine->findExecution($this->executionId);
$nodeId = ($this->nodeId === null) ? null : $execution->getProcessModel()->findNode($this->nodeId)->getId();
$data = [
'id' => UUID::createRandom(),
'execution_id' => $execution->getId(),
'activity_id' => $this->activityId,
'node' => $nodeId,
'process_instance_id' => $execution->getRootExecution()->getId(),
'flags' => $this->getSubscriptionFlag(),
'boundary' => $this->boundaryEvent ? 1 : 0,
'name' => $this->name,
'created_at' => \time()
];
if ($job !== null) {
$data['job_id'] = $job->getId();
}
$engine->getConnection()->insert('#__bpmn_event_subscription', $data);
} | [
"protected",
"function",
"createSubscription",
"(",
"ProcessEngine",
"$",
"engine",
",",
"?",
"Job",
"$",
"job",
"=",
"null",
")",
":",
"void",
"{",
"$",
"execution",
"=",
"$",
"engine",
"->",
"findExecution",
"(",
"$",
"this",
"->",
"executionId",
")",
";",
"$",
"nodeId",
"=",
"(",
"$",
"this",
"->",
"nodeId",
"===",
"null",
")",
"?",
"null",
":",
"$",
"execution",
"->",
"getProcessModel",
"(",
")",
"->",
"findNode",
"(",
"$",
"this",
"->",
"nodeId",
")",
"->",
"getId",
"(",
")",
";",
"$",
"data",
"=",
"[",
"'id'",
"=>",
"UUID",
"::",
"createRandom",
"(",
")",
",",
"'execution_id'",
"=>",
"$",
"execution",
"->",
"getId",
"(",
")",
",",
"'activity_id'",
"=>",
"$",
"this",
"->",
"activityId",
",",
"'node'",
"=>",
"$",
"nodeId",
",",
"'process_instance_id'",
"=>",
"$",
"execution",
"->",
"getRootExecution",
"(",
")",
"->",
"getId",
"(",
")",
",",
"'flags'",
"=>",
"$",
"this",
"->",
"getSubscriptionFlag",
"(",
")",
",",
"'boundary'",
"=>",
"$",
"this",
"->",
"boundaryEvent",
"?",
"1",
":",
"0",
",",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'created_at'",
"=>",
"\\",
"time",
"(",
")",
"]",
";",
"if",
"(",
"$",
"job",
"!==",
"null",
")",
"{",
"$",
"data",
"[",
"'job_id'",
"]",
"=",
"$",
"job",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"engine",
"->",
"getConnection",
"(",
")",
"->",
"insert",
"(",
"'#__bpmn_event_subscription'",
",",
"$",
"data",
")",
";",
"}"
] | Create an event subscription entry in the DB. | [
"Create",
"an",
"event",
"subscription",
"entry",
"in",
"the",
"DB",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/Command/AbstractCreateSubscriptionCommand.php#L96-L118 |
33,333 | koolkode/bpmn | src/Engine/AbstractActivity.php | AbstractActivity.leave | public function leave(VirtualExecution $execution, ?array $transitions = null): void
{
$execution->getEngine()->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $execution->getEngine()));
$this->clearEventSubscriptions($execution, $execution->getNode()->getId());
$execution->takeAll($transitions);
} | php | public function leave(VirtualExecution $execution, ?array $transitions = null): void
{
$execution->getEngine()->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $execution->getEngine()));
$this->clearEventSubscriptions($execution, $execution->getNode()->getId());
$execution->takeAll($transitions);
} | [
"public",
"function",
"leave",
"(",
"VirtualExecution",
"$",
"execution",
",",
"?",
"array",
"$",
"transitions",
"=",
"null",
")",
":",
"void",
"{",
"$",
"execution",
"->",
"getEngine",
"(",
")",
"->",
"notify",
"(",
"new",
"ActivityCompletedEvent",
"(",
"$",
"execution",
"->",
"getNode",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"execution",
",",
"$",
"execution",
"->",
"getEngine",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"clearEventSubscriptions",
"(",
"$",
"execution",
",",
"$",
"execution",
"->",
"getNode",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"execution",
"->",
"takeAll",
"(",
"$",
"transitions",
")",
";",
"}"
] | Have the given execution leave the activity. | [
"Have",
"the",
"given",
"execution",
"leave",
"the",
"activity",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L133-L140 |
33,334 | koolkode/bpmn | src/Engine/AbstractActivity.php | AbstractActivity.passVariablesToExecution | protected function passVariablesToExecution(VirtualExecution $execution, array $variables): void
{
foreach ($variables as $k => $v) {
$execution->setVariable($k, $v);
}
} | php | protected function passVariablesToExecution(VirtualExecution $execution, array $variables): void
{
foreach ($variables as $k => $v) {
$execution->setVariable($k, $v);
}
} | [
"protected",
"function",
"passVariablesToExecution",
"(",
"VirtualExecution",
"$",
"execution",
",",
"array",
"$",
"variables",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"execution",
"->",
"setVariable",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"}"
] | Pass all variables given to the execution setting them in the executions's scope. | [
"Pass",
"all",
"variables",
"given",
"to",
"the",
"execution",
"setting",
"them",
"in",
"the",
"executions",
"s",
"scope",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L145-L150 |
33,335 | koolkode/bpmn | src/Engine/AbstractActivity.php | AbstractActivity.delegateSignal | protected function delegateSignal(VirtualExecution $execution, ?string $signal, array $variables, array $delegation): bool
{
if (empty($delegation['nodeId'])) {
return false;
}
$node = $execution->getProcessModel()->findNode($delegation['nodeId']);
$execution->getEngine()->debug('Delegating signal <{signal}> to {node}', [
'signal' => ($signal === null) ? 'null' : $signal,
'node' => (string) $node
]);
$execution->setNode($node);
$execution->waitForSignal();
$execution->signal($signal, $variables);
return true;
} | php | protected function delegateSignal(VirtualExecution $execution, ?string $signal, array $variables, array $delegation): bool
{
if (empty($delegation['nodeId'])) {
return false;
}
$node = $execution->getProcessModel()->findNode($delegation['nodeId']);
$execution->getEngine()->debug('Delegating signal <{signal}> to {node}', [
'signal' => ($signal === null) ? 'null' : $signal,
'node' => (string) $node
]);
$execution->setNode($node);
$execution->waitForSignal();
$execution->signal($signal, $variables);
return true;
} | [
"protected",
"function",
"delegateSignal",
"(",
"VirtualExecution",
"$",
"execution",
",",
"?",
"string",
"$",
"signal",
",",
"array",
"$",
"variables",
",",
"array",
"$",
"delegation",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"delegation",
"[",
"'nodeId'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"node",
"=",
"$",
"execution",
"->",
"getProcessModel",
"(",
")",
"->",
"findNode",
"(",
"$",
"delegation",
"[",
"'nodeId'",
"]",
")",
";",
"$",
"execution",
"->",
"getEngine",
"(",
")",
"->",
"debug",
"(",
"'Delegating signal <{signal}> to {node}'",
",",
"[",
"'signal'",
"=>",
"(",
"$",
"signal",
"===",
"null",
")",
"?",
"'null'",
":",
"$",
"signal",
",",
"'node'",
"=>",
"(",
"string",
")",
"$",
"node",
"]",
")",
";",
"$",
"execution",
"->",
"setNode",
"(",
"$",
"node",
")",
";",
"$",
"execution",
"->",
"waitForSignal",
"(",
")",
";",
"$",
"execution",
"->",
"signal",
"(",
"$",
"signal",
",",
"$",
"variables",
")",
";",
"return",
"true",
";",
"}"
] | Delegate signal to a target node using the same execution.
@param VirtualExecution $execution
@param string $signal
@param array $variables
@param array $delegation
@return boolean Returns true if the signal could be delegated. | [
"Delegate",
"signal",
"to",
"a",
"target",
"node",
"using",
"the",
"same",
"execution",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L161-L180 |
33,336 | koolkode/bpmn | src/Repository/DeploymentBuilder.php | DeploymentBuilder.addExtensions | public function addExtensions($extensions): self
{
$this->fileExtensions = \array_unique(\array_merge($this->fileExtensions, \array_map('strtolower', (array) $extensions)));
return $this;
} | php | public function addExtensions($extensions): self
{
$this->fileExtensions = \array_unique(\array_merge($this->fileExtensions, \array_map('strtolower', (array) $extensions)));
return $this;
} | [
"public",
"function",
"addExtensions",
"(",
"$",
"extensions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"fileExtensions",
"=",
"\\",
"array_unique",
"(",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"fileExtensions",
",",
"\\",
"array_map",
"(",
"'strtolower'",
",",
"(",
"array",
")",
"$",
"extensions",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a file extension that shoul be parsed for BPMN 2.0 process definitions.
The deployment mechanism will parse ".bpmn" files by default. | [
"Add",
"a",
"file",
"extension",
"that",
"shoul",
"be",
"parsed",
"for",
"BPMN",
"2",
".",
"0",
"process",
"definitions",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L60-L65 |
33,337 | koolkode/bpmn | src/Repository/DeploymentBuilder.php | DeploymentBuilder.isProcessResource | public function isProcessResource(string $name): bool
{
return \in_array(\strtolower(\pathinfo($name, \PATHINFO_EXTENSION)), $this->fileExtensions);
} | php | public function isProcessResource(string $name): bool
{
return \in_array(\strtolower(\pathinfo($name, \PATHINFO_EXTENSION)), $this->fileExtensions);
} | [
"public",
"function",
"isProcessResource",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"\\",
"in_array",
"(",
"\\",
"strtolower",
"(",
"\\",
"pathinfo",
"(",
"$",
"name",
",",
"\\",
"PATHINFO_EXTENSION",
")",
")",
",",
"$",
"this",
"->",
"fileExtensions",
")",
";",
"}"
] | Check if the given file will be parsed for BPMN 2.0 process definitions. | [
"Check",
"if",
"the",
"given",
"file",
"will",
"be",
"parsed",
"for",
"BPMN",
"2",
".",
"0",
"process",
"definitions",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L70-L73 |
33,338 | koolkode/bpmn | src/Repository/DeploymentBuilder.php | DeploymentBuilder.addResource | public function addResource(string $name, $resource): self
{
if ($resource instanceof StreamInterface) {
$in = $resource;
} elseif (\is_resource($resource)) {
$in = new ResourceInputStream($resource);
} else {
$resource = (string) $resource;
if (\preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $resource)) {
$in = ResourceInputStream::fromUrl($resource);
} else {
$in = new StringStream($resource);
}
}
$this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $in;
return $this;
} | php | public function addResource(string $name, $resource): self
{
if ($resource instanceof StreamInterface) {
$in = $resource;
} elseif (\is_resource($resource)) {
$in = new ResourceInputStream($resource);
} else {
$resource = (string) $resource;
if (\preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $resource)) {
$in = ResourceInputStream::fromUrl($resource);
} else {
$in = new StringStream($resource);
}
}
$this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $in;
return $this;
} | [
"public",
"function",
"addResource",
"(",
"string",
"$",
"name",
",",
"$",
"resource",
")",
":",
"self",
"{",
"if",
"(",
"$",
"resource",
"instanceof",
"StreamInterface",
")",
"{",
"$",
"in",
"=",
"$",
"resource",
";",
"}",
"elseif",
"(",
"\\",
"is_resource",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"in",
"=",
"new",
"ResourceInputStream",
"(",
"$",
"resource",
")",
";",
"}",
"else",
"{",
"$",
"resource",
"=",
"(",
"string",
")",
"$",
"resource",
";",
"if",
"(",
"\\",
"preg_match",
"(",
"\"'^/|(?:[^:\\\\\\\\/]+://)|(?:[a-z]:[\\\\\\\\/])'i\"",
",",
"$",
"resource",
")",
")",
"{",
"$",
"in",
"=",
"ResourceInputStream",
"::",
"fromUrl",
"(",
"$",
"resource",
")",
";",
"}",
"else",
"{",
"$",
"in",
"=",
"new",
"StringStream",
"(",
"$",
"resource",
")",
";",
"}",
"}",
"$",
"this",
"->",
"resources",
"[",
"\\",
"trim",
"(",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"name",
")",
",",
"'/'",
")",
"]",
"=",
"$",
"in",
";",
"return",
"$",
"this",
";",
"}"
] | Add a resource to the deployment.
@param string $name Local path and filename of the resource within the deployment.
@param mixed $resource Deployable resource (file), that can be loaded using a stream. | [
"Add",
"a",
"resource",
"to",
"the",
"deployment",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L81-L100 |
33,339 | koolkode/bpmn | src/Repository/DeploymentBuilder.php | DeploymentBuilder.addArchive | public function addArchive(string $file): self
{
if (!\is_file($file)) {
throw new \InvalidArgumentException(\sprintf('Archive not found: "%s"', $file));
}
if (!\is_readable($file)) {
throw new \RuntimeException(\sprintf('Archive not readable: "%s"', $file));
}
$zip = new \ZipArchive();
$zip->open($file);
try {
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = (array) $zip->statIndex($i);
// This will skip empty files as well... need a better way to this eventually.
if (empty($stat['size'])) {
continue;
}
$name = $zip->getNameIndex($i);
// Cap memory at 256KB to allow for large deployments when necessary.
$stream = new StringStream('', 262144);
$resource = $zip->getStream($name);
try {
while (!\feof($resource)) {
$stream->write(\fread($resource, 8192));
}
$stream->rewind();
} finally {
@\fclose($resource);
}
$this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $stream;
}
} finally {
@$zip->close();
}
return $this;
} | php | public function addArchive(string $file): self
{
if (!\is_file($file)) {
throw new \InvalidArgumentException(\sprintf('Archive not found: "%s"', $file));
}
if (!\is_readable($file)) {
throw new \RuntimeException(\sprintf('Archive not readable: "%s"', $file));
}
$zip = new \ZipArchive();
$zip->open($file);
try {
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = (array) $zip->statIndex($i);
// This will skip empty files as well... need a better way to this eventually.
if (empty($stat['size'])) {
continue;
}
$name = $zip->getNameIndex($i);
// Cap memory at 256KB to allow for large deployments when necessary.
$stream = new StringStream('', 262144);
$resource = $zip->getStream($name);
try {
while (!\feof($resource)) {
$stream->write(\fread($resource, 8192));
}
$stream->rewind();
} finally {
@\fclose($resource);
}
$this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $stream;
}
} finally {
@$zip->close();
}
return $this;
} | [
"public",
"function",
"addArchive",
"(",
"string",
"$",
"file",
")",
":",
"self",
"{",
"if",
"(",
"!",
"\\",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'Archive not found: \"%s\"'",
",",
"$",
"file",
")",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\\",
"sprintf",
"(",
"'Archive not readable: \"%s\"'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"$",
"zip",
"->",
"open",
"(",
"$",
"file",
")",
";",
"try",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"zip",
"->",
"numFiles",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stat",
"=",
"(",
"array",
")",
"$",
"zip",
"->",
"statIndex",
"(",
"$",
"i",
")",
";",
"// This will skip empty files as well... need a better way to this eventually.",
"if",
"(",
"empty",
"(",
"$",
"stat",
"[",
"'size'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"name",
"=",
"$",
"zip",
"->",
"getNameIndex",
"(",
"$",
"i",
")",
";",
"// Cap memory at 256KB to allow for large deployments when necessary.",
"$",
"stream",
"=",
"new",
"StringStream",
"(",
"''",
",",
"262144",
")",
";",
"$",
"resource",
"=",
"$",
"zip",
"->",
"getStream",
"(",
"$",
"name",
")",
";",
"try",
"{",
"while",
"(",
"!",
"\\",
"feof",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"stream",
"->",
"write",
"(",
"\\",
"fread",
"(",
"$",
"resource",
",",
"8192",
")",
")",
";",
"}",
"$",
"stream",
"->",
"rewind",
"(",
")",
";",
"}",
"finally",
"{",
"@",
"\\",
"fclose",
"(",
"$",
"resource",
")",
";",
"}",
"$",
"this",
"->",
"resources",
"[",
"\\",
"trim",
"(",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"name",
")",
",",
"'/'",
")",
"]",
"=",
"$",
"stream",
";",
"}",
"}",
"finally",
"{",
"@",
"$",
"zip",
"->",
"close",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a ZIP archives file contents to the deployment.
@throws \InvalidArgumentException When the given archive could not be found.
@throws \RuntimeException When the given archive could not be read. | [
"Add",
"a",
"ZIP",
"archives",
"file",
"contents",
"to",
"the",
"deployment",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L108-L153 |
33,340 | koolkode/bpmn | src/Repository/DeploymentBuilder.php | DeploymentBuilder.collectFiles | protected function collectFiles(string $dir, string $basePath): array
{
$files = [];
$dh = \opendir($dir);
try {
while (false !== ($entry = \readdir($dh))) {
if ($entry == '.' || $entry == '..') {
continue;
}
$check = $dir . \DIRECTORY_SEPARATOR . $entry;
if (\is_dir($check)) {
foreach ($this->collectFiles($check, $basePath . '/' . $entry) as $k => $v) {
$files[$k] = $v;
}
} elseif (\is_file($check)) {
$files[$basePath . '/' . $entry] = $check;
}
}
return $files;
} finally {
\closedir($dh);
}
} | php | protected function collectFiles(string $dir, string $basePath): array
{
$files = [];
$dh = \opendir($dir);
try {
while (false !== ($entry = \readdir($dh))) {
if ($entry == '.' || $entry == '..') {
continue;
}
$check = $dir . \DIRECTORY_SEPARATOR . $entry;
if (\is_dir($check)) {
foreach ($this->collectFiles($check, $basePath . '/' . $entry) as $k => $v) {
$files[$k] = $v;
}
} elseif (\is_file($check)) {
$files[$basePath . '/' . $entry] = $check;
}
}
return $files;
} finally {
\closedir($dh);
}
} | [
"protected",
"function",
"collectFiles",
"(",
"string",
"$",
"dir",
",",
"string",
"$",
"basePath",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"dh",
"=",
"\\",
"opendir",
"(",
"$",
"dir",
")",
";",
"try",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"\\",
"readdir",
"(",
"$",
"dh",
")",
")",
")",
"{",
"if",
"(",
"$",
"entry",
"==",
"'.'",
"||",
"$",
"entry",
"==",
"'..'",
")",
"{",
"continue",
";",
"}",
"$",
"check",
"=",
"$",
"dir",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"entry",
";",
"if",
"(",
"\\",
"is_dir",
"(",
"$",
"check",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"collectFiles",
"(",
"$",
"check",
",",
"$",
"basePath",
".",
"'/'",
".",
"$",
"entry",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"files",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"elseif",
"(",
"\\",
"is_file",
"(",
"$",
"check",
")",
")",
"{",
"$",
"files",
"[",
"$",
"basePath",
".",
"'/'",
".",
"$",
"entry",
"]",
"=",
"$",
"check",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}",
"finally",
"{",
"\\",
"closedir",
"(",
"$",
"dh",
")",
";",
"}",
"}"
] | Collect all files from the directory, uses recursion to grab files from sub-directories. | [
"Collect",
"all",
"files",
"from",
"the",
"directory",
"uses",
"recursion",
"to",
"grab",
"files",
"from",
"sub",
"-",
"directories",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L183-L209 |
33,341 | koolkode/bpmn | src/Engine/ExecutionInterceptorChain.php | ExecutionInterceptorChain.performExecution | public function performExecution()
{
if (!$this->interceptors->isEmpty()) {
return $this->interceptors->extract()->interceptExecution($this, $this->executionDepth);
}
return ($this->callback)();
} | php | public function performExecution()
{
if (!$this->interceptors->isEmpty()) {
return $this->interceptors->extract()->interceptExecution($this, $this->executionDepth);
}
return ($this->callback)();
} | [
"public",
"function",
"performExecution",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"interceptors",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"interceptors",
"->",
"extract",
"(",
")",
"->",
"interceptExecution",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"executionDepth",
")",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"callback",
")",
"(",
")",
";",
"}"
] | Delegate to the next interceptor or actually perform the queued execution.
@return mixed The result of the command execution. | [
"Delegate",
"to",
"the",
"next",
"interceptor",
"or",
"actually",
"perform",
"the",
"queued",
"execution",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/ExecutionInterceptorChain.php#L45-L52 |
33,342 | koolkode/bpmn | src/Job/Executor/JobExecutor.php | JobExecutor.findJobHandler | protected function findJobHandler(Job $job)
{
foreach ($this->handlers as $type => $handler) {
if ($job->getHandlerType() == $type) {
return $handler;
}
}
throw new \OutOfBoundsException(\sprintf('Job handler "%s" not found for job %s', $job->getHandlerType(), $job->getId()));
} | php | protected function findJobHandler(Job $job)
{
foreach ($this->handlers as $type => $handler) {
if ($job->getHandlerType() == $type) {
return $handler;
}
}
throw new \OutOfBoundsException(\sprintf('Job handler "%s" not found for job %s', $job->getHandlerType(), $job->getId()));
} | [
"protected",
"function",
"findJobHandler",
"(",
"Job",
"$",
"job",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handlers",
"as",
"$",
"type",
"=>",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"job",
"->",
"getHandlerType",
"(",
")",
"==",
"$",
"type",
")",
"{",
"return",
"$",
"handler",
";",
"}",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\\",
"sprintf",
"(",
"'Job handler \"%s\" not found for job %s'",
",",
"$",
"job",
"->",
"getHandlerType",
"(",
")",
",",
"$",
"job",
"->",
"getId",
"(",
")",
")",
")",
";",
"}"
] | Find a handler for the given job by matching the handler type value of the job.
@param Job $job
@return JobHandlerInterface
@throws \OutOfBoundsException When no handler for the job could be resolved. | [
"Find",
"a",
"handler",
"for",
"the",
"given",
"job",
"by",
"matching",
"the",
"handler",
"type",
"value",
"of",
"the",
"job",
"."
] | 49ff924fa97e0bbe1b74e914393b22760dcf7281 | https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Job/Executor/JobExecutor.php#L291-L300 |
33,343 | LaravelCollective/iron-queue | src/IronQueueServiceProvider.php | IronQueueServiceProvider.registerIronRequestBinder | protected function registerIronRequestBinder()
{
$this->app->rebinding('request', function ($app, $request) {
if ($app['queue']->connected('iron')) {
$app['queue']->connection('iron')->setRequest($request);
}
});
} | php | protected function registerIronRequestBinder()
{
$this->app->rebinding('request', function ($app, $request) {
if ($app['queue']->connected('iron')) {
$app['queue']->connection('iron')->setRequest($request);
}
});
} | [
"protected",
"function",
"registerIronRequestBinder",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"rebinding",
"(",
"'request'",
",",
"function",
"(",
"$",
"app",
",",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"app",
"[",
"'queue'",
"]",
"->",
"connected",
"(",
"'iron'",
")",
")",
"{",
"$",
"app",
"[",
"'queue'",
"]",
"->",
"connection",
"(",
"'iron'",
")",
"->",
"setRequest",
"(",
"$",
"request",
")",
";",
"}",
"}",
")",
";",
"}"
] | Register the request rebinding event for the Iron queue.
@return void | [
"Register",
"the",
"request",
"rebinding",
"event",
"for",
"the",
"Iron",
"queue",
"."
] | a873575da0ebec506db3631b9835074e06543060 | https://github.com/LaravelCollective/iron-queue/blob/a873575da0ebec506db3631b9835074e06543060/src/IronQueueServiceProvider.php#L28-L35 |
33,344 | LaravelCollective/iron-queue | src/IronQueue.php | IronQueue.deleteMessage | public function deleteMessage($queue, $id, $reservation_id)
{
$this->iron->deleteMessage($queue, $id, $reservation_id);
} | php | public function deleteMessage($queue, $id, $reservation_id)
{
$this->iron->deleteMessage($queue, $id, $reservation_id);
} | [
"public",
"function",
"deleteMessage",
"(",
"$",
"queue",
",",
"$",
"id",
",",
"$",
"reservation_id",
")",
"{",
"$",
"this",
"->",
"iron",
"->",
"deleteMessage",
"(",
"$",
"queue",
",",
"$",
"id",
",",
"$",
"reservation_id",
")",
";",
"}"
] | Delete a message from the Iron queue.
@param string $queue
@param string $id
@param string $reservation_id
@return void | [
"Delete",
"a",
"message",
"from",
"the",
"Iron",
"queue",
"."
] | a873575da0ebec506db3631b9835074e06543060 | https://github.com/LaravelCollective/iron-queue/blob/a873575da0ebec506db3631b9835074e06543060/src/IronQueue.php#L167-L170 |
33,345 | brainworxx/kreXX | src/Analyse/Callback/Iterate/ThroughGetter.php | ThroughGetter.callMe | public function callMe()
{
$output = $this->dispatchStartEvent();
$this->parameters[static::CURRENT_PREFIX] = 'get';
$output .= $this->goThroughMethodList($this->parameters[static::PARAM_NORMAL_GETTER]);
$this->parameters[static::CURRENT_PREFIX] = 'is';
$output .= $this->goThroughMethodList($this->parameters[static::PARAM_IS_GETTER]);
$this->parameters[static::CURRENT_PREFIX] = 'has';
return $output . $this->goThroughMethodList($this->parameters[static::PARAM_HAS_GETTER]);
} | php | public function callMe()
{
$output = $this->dispatchStartEvent();
$this->parameters[static::CURRENT_PREFIX] = 'get';
$output .= $this->goThroughMethodList($this->parameters[static::PARAM_NORMAL_GETTER]);
$this->parameters[static::CURRENT_PREFIX] = 'is';
$output .= $this->goThroughMethodList($this->parameters[static::PARAM_IS_GETTER]);
$this->parameters[static::CURRENT_PREFIX] = 'has';
return $output . $this->goThroughMethodList($this->parameters[static::PARAM_HAS_GETTER]);
} | [
"public",
"function",
"callMe",
"(",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"dispatchStartEvent",
"(",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"CURRENT_PREFIX",
"]",
"=",
"'get'",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"goThroughMethodList",
"(",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_NORMAL_GETTER",
"]",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"CURRENT_PREFIX",
"]",
"=",
"'is'",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"goThroughMethodList",
"(",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_IS_GETTER",
"]",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"CURRENT_PREFIX",
"]",
"=",
"'has'",
";",
"return",
"$",
"output",
".",
"$",
"this",
"->",
"goThroughMethodList",
"(",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_HAS_GETTER",
"]",
")",
";",
"}"
] | Try to get the possible result of all getter methods.
@return string
The generated markup. | [
"Try",
"to",
"get",
"the",
"possible",
"result",
"of",
"all",
"getter",
"methods",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Iterate/ThroughGetter.php#L107-L119 |
33,346 | brainworxx/kreXX | src/Analyse/Callback/Iterate/ThroughGetter.php | ThroughGetter.goThroughMethodList | protected function goThroughMethodList(array $methodList)
{
$output = '';
/** @var \ReflectionMethod $reflectionMethod */
foreach ($methodList as $reflectionMethod) {
// Back to level 0, we reset the deep counter.
$this->deep = 0;
// Now we have three possible outcomes:
// 1.) We have an actual value
// 2.) We got NULL as a value
// 3.) We were unable to get any info at all.
$comments = nl2br($this->commentAnalysis->getComment(
$reflectionMethod,
$this->parameters[static::PARAM_REF]
));
/** @var Model $model */
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')
->setName($reflectionMethod->getName())
->addToJson(static::META_METHOD_COMMENT, $comments);
// We need to decide if we are handling static getters.
if ($reflectionMethod->isStatic() === true) {
$model->setConnectorType(Connectors::STATIC_METHOD);
} else {
$model->setConnectorType(Connectors::METHOD);
}
// Get ourselves a possible return value
$output .= $this->retrievePropertyValue(
$reflectionMethod,
$this->dispatchEventWithModel(
__FUNCTION__ . static::EVENT_MARKER_END,
$model
)
);
}
return $output;
} | php | protected function goThroughMethodList(array $methodList)
{
$output = '';
/** @var \ReflectionMethod $reflectionMethod */
foreach ($methodList as $reflectionMethod) {
// Back to level 0, we reset the deep counter.
$this->deep = 0;
// Now we have three possible outcomes:
// 1.) We have an actual value
// 2.) We got NULL as a value
// 3.) We were unable to get any info at all.
$comments = nl2br($this->commentAnalysis->getComment(
$reflectionMethod,
$this->parameters[static::PARAM_REF]
));
/** @var Model $model */
$model = $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')
->setName($reflectionMethod->getName())
->addToJson(static::META_METHOD_COMMENT, $comments);
// We need to decide if we are handling static getters.
if ($reflectionMethod->isStatic() === true) {
$model->setConnectorType(Connectors::STATIC_METHOD);
} else {
$model->setConnectorType(Connectors::METHOD);
}
// Get ourselves a possible return value
$output .= $this->retrievePropertyValue(
$reflectionMethod,
$this->dispatchEventWithModel(
__FUNCTION__ . static::EVENT_MARKER_END,
$model
)
);
}
return $output;
} | [
"protected",
"function",
"goThroughMethodList",
"(",
"array",
"$",
"methodList",
")",
"{",
"$",
"output",
"=",
"''",
";",
"/** @var \\ReflectionMethod $reflectionMethod */",
"foreach",
"(",
"$",
"methodList",
"as",
"$",
"reflectionMethod",
")",
"{",
"// Back to level 0, we reset the deep counter.",
"$",
"this",
"->",
"deep",
"=",
"0",
";",
"// Now we have three possible outcomes:",
"// 1.) We have an actual value",
"// 2.) We got NULL as a value",
"// 3.) We were unable to get any info at all.",
"$",
"comments",
"=",
"nl2br",
"(",
"$",
"this",
"->",
"commentAnalysis",
"->",
"getComment",
"(",
"$",
"reflectionMethod",
",",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_REF",
"]",
")",
")",
";",
"/** @var Model $model */",
"$",
"model",
"=",
"$",
"this",
"->",
"pool",
"->",
"createClass",
"(",
"'Brainworxx\\\\Krexx\\\\Analyse\\\\Model'",
")",
"->",
"setName",
"(",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
")",
"->",
"addToJson",
"(",
"static",
"::",
"META_METHOD_COMMENT",
",",
"$",
"comments",
")",
";",
"// We need to decide if we are handling static getters.",
"if",
"(",
"$",
"reflectionMethod",
"->",
"isStatic",
"(",
")",
"===",
"true",
")",
"{",
"$",
"model",
"->",
"setConnectorType",
"(",
"Connectors",
"::",
"STATIC_METHOD",
")",
";",
"}",
"else",
"{",
"$",
"model",
"->",
"setConnectorType",
"(",
"Connectors",
"::",
"METHOD",
")",
";",
"}",
"// Get ourselves a possible return value",
"$",
"output",
".=",
"$",
"this",
"->",
"retrievePropertyValue",
"(",
"$",
"reflectionMethod",
",",
"$",
"this",
"->",
"dispatchEventWithModel",
"(",
"__FUNCTION__",
".",
"static",
"::",
"EVENT_MARKER_END",
",",
"$",
"model",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Iterating through a list of reflection methods.
@param array $methodList
The list of methods we are going through, consisting of \ReflectionMethod
@return string
The generated DOM. | [
"Iterating",
"through",
"a",
"list",
"of",
"reflection",
"methods",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Iterate/ThroughGetter.php#L130-L171 |
33,347 | brainworxx/kreXX | src/Analyse/Callback/Iterate/ThroughGetter.php | ThroughGetter.retrievePropertyValue | protected function retrievePropertyValue(\ReflectionMethod $reflectionMethod, Model $model)
{
/** @var \Brainworxx\Krexx\Service\Reflection\ReflectionClass $reflectionClass */
$reflectionClass = $this->parameters[static::PARAM_REF];
$refProp = $this->getReflectionProperty($reflectionClass, $reflectionMethod);
$nothingFound = true;
$value = null;
if (empty($refProp) === false) {
// We've got ourselves a possible result!
$nothingFound = false;
$value = $reflectionClass->retrieveValue($refProp);
$model->setData($value);
if ($value === null) {
// A NULL value might mean that the values does not
// exist, until the getter computes it.
$model->addToJson(static::META_HINT, $this->pool->messages->getHelp('getterNull'));
}
}
// Give the plugins the opportunity to do something with the value, or
// try to resolve it, if nothing was found.
// We also add the stuff, that we were able to do so far.
$this->parameters[static::PARAM_ADDITIONAL] = array(
'nothingFound' => $nothingFound,
'value' => $value,
'refProperty' => $refProp,
'refMethod' => $reflectionMethod
);
$this->dispatchEventWithModel(__FUNCTION__ . '::resolving', $model);
if ($this->parameters[static::PARAM_ADDITIONAL]['nothingFound'] === true) {
// Found nothing :-(
// We literally have no info. We need to tell the user.
$model->setType(static::TYPE_UNKNOWN)
->setNormal(static::TYPE_UNKNOWN);
// We render this right away, without any routing.
return $this->pool->render->renderSingleChild($model);
}
return $this->pool->routing->analysisHub(
$this->dispatchEventWithModel(
__FUNCTION__ . static::EVENT_MARKER_END,
$model
)
);
} | php | protected function retrievePropertyValue(\ReflectionMethod $reflectionMethod, Model $model)
{
/** @var \Brainworxx\Krexx\Service\Reflection\ReflectionClass $reflectionClass */
$reflectionClass = $this->parameters[static::PARAM_REF];
$refProp = $this->getReflectionProperty($reflectionClass, $reflectionMethod);
$nothingFound = true;
$value = null;
if (empty($refProp) === false) {
// We've got ourselves a possible result!
$nothingFound = false;
$value = $reflectionClass->retrieveValue($refProp);
$model->setData($value);
if ($value === null) {
// A NULL value might mean that the values does not
// exist, until the getter computes it.
$model->addToJson(static::META_HINT, $this->pool->messages->getHelp('getterNull'));
}
}
// Give the plugins the opportunity to do something with the value, or
// try to resolve it, if nothing was found.
// We also add the stuff, that we were able to do so far.
$this->parameters[static::PARAM_ADDITIONAL] = array(
'nothingFound' => $nothingFound,
'value' => $value,
'refProperty' => $refProp,
'refMethod' => $reflectionMethod
);
$this->dispatchEventWithModel(__FUNCTION__ . '::resolving', $model);
if ($this->parameters[static::PARAM_ADDITIONAL]['nothingFound'] === true) {
// Found nothing :-(
// We literally have no info. We need to tell the user.
$model->setType(static::TYPE_UNKNOWN)
->setNormal(static::TYPE_UNKNOWN);
// We render this right away, without any routing.
return $this->pool->render->renderSingleChild($model);
}
return $this->pool->routing->analysisHub(
$this->dispatchEventWithModel(
__FUNCTION__ . static::EVENT_MARKER_END,
$model
)
);
} | [
"protected",
"function",
"retrievePropertyValue",
"(",
"\\",
"ReflectionMethod",
"$",
"reflectionMethod",
",",
"Model",
"$",
"model",
")",
"{",
"/** @var \\Brainworxx\\Krexx\\Service\\Reflection\\ReflectionClass $reflectionClass */",
"$",
"reflectionClass",
"=",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_REF",
"]",
";",
"$",
"refProp",
"=",
"$",
"this",
"->",
"getReflectionProperty",
"(",
"$",
"reflectionClass",
",",
"$",
"reflectionMethod",
")",
";",
"$",
"nothingFound",
"=",
"true",
";",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"refProp",
")",
"===",
"false",
")",
"{",
"// We've got ourselves a possible result!",
"$",
"nothingFound",
"=",
"false",
";",
"$",
"value",
"=",
"$",
"reflectionClass",
"->",
"retrieveValue",
"(",
"$",
"refProp",
")",
";",
"$",
"model",
"->",
"setData",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"// A NULL value might mean that the values does not",
"// exist, until the getter computes it.",
"$",
"model",
"->",
"addToJson",
"(",
"static",
"::",
"META_HINT",
",",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"getHelp",
"(",
"'getterNull'",
")",
")",
";",
"}",
"}",
"// Give the plugins the opportunity to do something with the value, or",
"// try to resolve it, if nothing was found.",
"// We also add the stuff, that we were able to do so far.",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_ADDITIONAL",
"]",
"=",
"array",
"(",
"'nothingFound'",
"=>",
"$",
"nothingFound",
",",
"'value'",
"=>",
"$",
"value",
",",
"'refProperty'",
"=>",
"$",
"refProp",
",",
"'refMethod'",
"=>",
"$",
"reflectionMethod",
")",
";",
"$",
"this",
"->",
"dispatchEventWithModel",
"(",
"__FUNCTION__",
".",
"'::resolving'",
",",
"$",
"model",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"PARAM_ADDITIONAL",
"]",
"[",
"'nothingFound'",
"]",
"===",
"true",
")",
"{",
"// Found nothing :-(",
"// We literally have no info. We need to tell the user.",
"$",
"model",
"->",
"setType",
"(",
"static",
"::",
"TYPE_UNKNOWN",
")",
"->",
"setNormal",
"(",
"static",
"::",
"TYPE_UNKNOWN",
")",
";",
"// We render this right away, without any routing.",
"return",
"$",
"this",
"->",
"pool",
"->",
"render",
"->",
"renderSingleChild",
"(",
"$",
"model",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pool",
"->",
"routing",
"->",
"analysisHub",
"(",
"$",
"this",
"->",
"dispatchEventWithModel",
"(",
"__FUNCTION__",
".",
"static",
"::",
"EVENT_MARKER_END",
",",
"$",
"model",
")",
")",
";",
"}"
] | Try to get a possible return value and render the result.
@param \ReflectionMethod $reflectionMethod
A reflection ot the method we are analysing
@param Model $model
The model so far.
@return string
The rendered markup. | [
"Try",
"to",
"get",
"a",
"possible",
"return",
"value",
"and",
"render",
"the",
"result",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Iterate/ThroughGetter.php#L184-L230 |
33,348 | brainworxx/kreXX | src/Analyse/Callback/Iterate/ThroughGetter.php | ThroughGetter.preparePropertyName | protected function preparePropertyName(\ReflectionMethod $reflectionMethod)
{
$currentPrefix = $this->parameters[static::CURRENT_PREFIX];
// Get the name and remove the 'get' . . .
$getterName = $reflectionMethod->getName();
if (strpos($getterName, $currentPrefix) === 0) {
return lcfirst(substr($getterName, strlen($currentPrefix)));
}
// . . . or the '_get'.
if (strpos($getterName, '_' . $currentPrefix) === 0) {
return lcfirst(substr($getterName, strlen($currentPrefix) + 1));
}
// Still here?!? At least make the first letter lowercase.
return lcfirst($getterName);
} | php | protected function preparePropertyName(\ReflectionMethod $reflectionMethod)
{
$currentPrefix = $this->parameters[static::CURRENT_PREFIX];
// Get the name and remove the 'get' . . .
$getterName = $reflectionMethod->getName();
if (strpos($getterName, $currentPrefix) === 0) {
return lcfirst(substr($getterName, strlen($currentPrefix)));
}
// . . . or the '_get'.
if (strpos($getterName, '_' . $currentPrefix) === 0) {
return lcfirst(substr($getterName, strlen($currentPrefix) + 1));
}
// Still here?!? At least make the first letter lowercase.
return lcfirst($getterName);
} | [
"protected",
"function",
"preparePropertyName",
"(",
"\\",
"ReflectionMethod",
"$",
"reflectionMethod",
")",
"{",
"$",
"currentPrefix",
"=",
"$",
"this",
"->",
"parameters",
"[",
"static",
"::",
"CURRENT_PREFIX",
"]",
";",
"// Get the name and remove the 'get' . . .",
"$",
"getterName",
"=",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"getterName",
",",
"$",
"currentPrefix",
")",
"===",
"0",
")",
"{",
"return",
"lcfirst",
"(",
"substr",
"(",
"$",
"getterName",
",",
"strlen",
"(",
"$",
"currentPrefix",
")",
")",
")",
";",
"}",
"// . . . or the '_get'.",
"if",
"(",
"strpos",
"(",
"$",
"getterName",
",",
"'_'",
".",
"$",
"currentPrefix",
")",
"===",
"0",
")",
"{",
"return",
"lcfirst",
"(",
"substr",
"(",
"$",
"getterName",
",",
"strlen",
"(",
"$",
"currentPrefix",
")",
"+",
"1",
")",
")",
";",
"}",
"// Still here?!? At least make the first letter lowercase.",
"return",
"lcfirst",
"(",
"$",
"getterName",
")",
";",
"}"
] | Get a first impression ot the possible property name for the getter.
@param \ReflectionMethod $reflectionMethod
A reflection of the getter method we are analysing.
@return string
The first impression of the property name. | [
"Get",
"a",
"first",
"impression",
"ot",
"the",
"possible",
"property",
"name",
"for",
"the",
"getter",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Iterate/ThroughGetter.php#L329-L346 |
33,349 | brainworxx/kreXX | src/Analyse/Callback/Iterate/ThroughGetter.php | ThroughGetter.findIt | protected function findIt(array $searchArray, $haystack)
{
// Defining our regex.
$regex = '/(?<=###0###).*?(?=###1###)/';
// Regex escaping our search stuff
$searchArray[0] = $this->regexEscaping($searchArray[0]);
$searchArray[1] = $this->regexEscaping($searchArray[1]);
// Add the search stuff to the regex
$regex = str_replace('###0###', $searchArray[0], $regex);
$regex = str_replace('###1###', $searchArray[1], $regex);
// Trigger the search.
preg_match_all($regex, $haystack, $findings);
// Return the file name as well as stuff from the path.
return $findings[0];
} | php | protected function findIt(array $searchArray, $haystack)
{
// Defining our regex.
$regex = '/(?<=###0###).*?(?=###1###)/';
// Regex escaping our search stuff
$searchArray[0] = $this->regexEscaping($searchArray[0]);
$searchArray[1] = $this->regexEscaping($searchArray[1]);
// Add the search stuff to the regex
$regex = str_replace('###0###', $searchArray[0], $regex);
$regex = str_replace('###1###', $searchArray[1], $regex);
// Trigger the search.
preg_match_all($regex, $haystack, $findings);
// Return the file name as well as stuff from the path.
return $findings[0];
} | [
"protected",
"function",
"findIt",
"(",
"array",
"$",
"searchArray",
",",
"$",
"haystack",
")",
"{",
"// Defining our regex.",
"$",
"regex",
"=",
"'/(?<=###0###).*?(?=###1###)/'",
";",
"// Regex escaping our search stuff",
"$",
"searchArray",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"regexEscaping",
"(",
"$",
"searchArray",
"[",
"0",
"]",
")",
";",
"$",
"searchArray",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"regexEscaping",
"(",
"$",
"searchArray",
"[",
"1",
"]",
")",
";",
"// Add the search stuff to the regex",
"$",
"regex",
"=",
"str_replace",
"(",
"'###0###'",
",",
"$",
"searchArray",
"[",
"0",
"]",
",",
"$",
"regex",
")",
";",
"$",
"regex",
"=",
"str_replace",
"(",
"'###1###'",
",",
"$",
"searchArray",
"[",
"1",
"]",
",",
"$",
"regex",
")",
";",
"// Trigger the search.",
"preg_match_all",
"(",
"$",
"regex",
",",
"$",
"haystack",
",",
"$",
"findings",
")",
";",
"// Return the file name as well as stuff from the path.",
"return",
"$",
"findings",
"[",
"0",
"]",
";",
"}"
] | Searching for stuff via regex.
Yay, dynamic regex stuff for fun and profit!
@param array $searchArray
The search definition.
@param string $haystack
The haystack, obviously.
@return array
The findings. | [
"Searching",
"for",
"stuff",
"via",
"regex",
".",
"Yay",
"dynamic",
"regex",
"stuff",
"for",
"fun",
"and",
"profit!"
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Analyse/Callback/Iterate/ThroughGetter.php#L432-L451 |
33,350 | silverorange/swat | Swat/SwatAccordion.php | SwatAccordion.getInlineJavaScript | protected function getInlineJavaScript()
{
$javascript = sprintf(
"var %1\$s_obj = new %2\$s('%1\$s', %3\$s);",
$this->id,
$this->getJavascriptClassName(),
$this->animate ? 'true' : 'false'
);
$javascript .= sprintf(
"\n%s_obj.animate = %s;",
$this->id,
$this->animate ? 'true' : 'false'
);
$javascript .= sprintf(
"\n%s_obj.always_open = %s;",
$this->id,
$this->always_open ? 'true' : 'false'
);
return $javascript;
} | php | protected function getInlineJavaScript()
{
$javascript = sprintf(
"var %1\$s_obj = new %2\$s('%1\$s', %3\$s);",
$this->id,
$this->getJavascriptClassName(),
$this->animate ? 'true' : 'false'
);
$javascript .= sprintf(
"\n%s_obj.animate = %s;",
$this->id,
$this->animate ? 'true' : 'false'
);
$javascript .= sprintf(
"\n%s_obj.always_open = %s;",
$this->id,
$this->always_open ? 'true' : 'false'
);
return $javascript;
} | [
"protected",
"function",
"getInlineJavaScript",
"(",
")",
"{",
"$",
"javascript",
"=",
"sprintf",
"(",
"\"var %1\\$s_obj = new %2\\$s('%1\\$s', %3\\$s);\"",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"getJavascriptClassName",
"(",
")",
",",
"$",
"this",
"->",
"animate",
"?",
"'true'",
":",
"'false'",
")",
";",
"$",
"javascript",
".=",
"sprintf",
"(",
"\"\\n%s_obj.animate = %s;\"",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"animate",
"?",
"'true'",
":",
"'false'",
")",
";",
"$",
"javascript",
".=",
"sprintf",
"(",
"\"\\n%s_obj.always_open = %s;\"",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"always_open",
"?",
"'true'",
":",
"'false'",
")",
";",
"return",
"$",
"javascript",
";",
"}"
] | Gets the inline JavaScript used by this accordion view
@return string the inline JavaScript used by this accordion view. | [
"Gets",
"the",
"inline",
"JavaScript",
"used",
"by",
"this",
"accordion",
"view"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatAccordion.php#L138-L160 |
33,351 | brainworxx/kreXX | src/Service/Misc/Encoding.php | Encoding.encodeString | public function encodeString($data, $code = false)
{
// We will not encode an empty string.
if ($data === '') {
return '';
}
// Initialize the encoding configuration.
if ($code === true) {
// We encoding @, because we need them for our chunks.
// The { are needed in the marker of the skin.
// We also replace tabs with two nbsp's.
$sortingCallback = array($this, 'arrayMapCallbackCode');
$search = array('@', '{', chr(9));
$replace = array('@', '{', ' ');
} else {
// We encoding @, because we need them for our chunks.
// The { are needed in the marker of the skin.
$sortingCallback = array($this, 'arrayMapCallbackNormal');
$search = array('@', '{', ' ');
$replace = array('@', '{', ' ');
}
// There are several places here, that may throw a warning.
set_error_handler(
function () {
// Do nothing.
}
);
$result = str_replace($search, $replace, htmlentities($data));
// Check if encoding was successful.
// 99.99% of the time, the encoding works.
if (empty($result) === true) {
// Here we have another SPOF. When the string is large enough
// we will run out of memory!
// @see https://sourceforge.net/p/krexx/bugs/21/
// We will *NOT* return the unescaped string. So we must check if it
// is small enough for the unpack().
// 100 kb should be save enough.
if (strlen($data) > 102400) {
$result = $this->pool->messages->getHelp('stringTooLarge');
} else {
// Something went wrong with the encoding, we need to
// completely encode this one to be able to display it at all!
$data = mb_convert_encoding($data, 'UTF-32', mb_detect_encoding($data));
$result = implode("", array_map($sortingCallback, unpack("N*", $data)));
}
}
// Reactivate whatever error handling we had previously.
restore_error_handler();
return $result;
} | php | public function encodeString($data, $code = false)
{
// We will not encode an empty string.
if ($data === '') {
return '';
}
// Initialize the encoding configuration.
if ($code === true) {
// We encoding @, because we need them for our chunks.
// The { are needed in the marker of the skin.
// We also replace tabs with two nbsp's.
$sortingCallback = array($this, 'arrayMapCallbackCode');
$search = array('@', '{', chr(9));
$replace = array('@', '{', ' ');
} else {
// We encoding @, because we need them for our chunks.
// The { are needed in the marker of the skin.
$sortingCallback = array($this, 'arrayMapCallbackNormal');
$search = array('@', '{', ' ');
$replace = array('@', '{', ' ');
}
// There are several places here, that may throw a warning.
set_error_handler(
function () {
// Do nothing.
}
);
$result = str_replace($search, $replace, htmlentities($data));
// Check if encoding was successful.
// 99.99% of the time, the encoding works.
if (empty($result) === true) {
// Here we have another SPOF. When the string is large enough
// we will run out of memory!
// @see https://sourceforge.net/p/krexx/bugs/21/
// We will *NOT* return the unescaped string. So we must check if it
// is small enough for the unpack().
// 100 kb should be save enough.
if (strlen($data) > 102400) {
$result = $this->pool->messages->getHelp('stringTooLarge');
} else {
// Something went wrong with the encoding, we need to
// completely encode this one to be able to display it at all!
$data = mb_convert_encoding($data, 'UTF-32', mb_detect_encoding($data));
$result = implode("", array_map($sortingCallback, unpack("N*", $data)));
}
}
// Reactivate whatever error handling we had previously.
restore_error_handler();
return $result;
} | [
"public",
"function",
"encodeString",
"(",
"$",
"data",
",",
"$",
"code",
"=",
"false",
")",
"{",
"// We will not encode an empty string.",
"if",
"(",
"$",
"data",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"// Initialize the encoding configuration.",
"if",
"(",
"$",
"code",
"===",
"true",
")",
"{",
"// We encoding @, because we need them for our chunks.",
"// The { are needed in the marker of the skin.",
"// We also replace tabs with two nbsp's.",
"$",
"sortingCallback",
"=",
"array",
"(",
"$",
"this",
",",
"'arrayMapCallbackCode'",
")",
";",
"$",
"search",
"=",
"array",
"(",
"'@'",
",",
"'{'",
",",
"chr",
"(",
"9",
")",
")",
";",
"$",
"replace",
"=",
"array",
"(",
"'@'",
",",
"'{'",
",",
"' '",
")",
";",
"}",
"else",
"{",
"// We encoding @, because we need them for our chunks.",
"// The { are needed in the marker of the skin.",
"$",
"sortingCallback",
"=",
"array",
"(",
"$",
"this",
",",
"'arrayMapCallbackNormal'",
")",
";",
"$",
"search",
"=",
"array",
"(",
"'@'",
",",
"'{'",
",",
"' '",
")",
";",
"$",
"replace",
"=",
"array",
"(",
"'@'",
",",
"'{'",
",",
"' '",
")",
";",
"}",
"// There are several places here, that may throw a warning.",
"set_error_handler",
"(",
"function",
"(",
")",
"{",
"// Do nothing.",
"}",
")",
";",
"$",
"result",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"htmlentities",
"(",
"$",
"data",
")",
")",
";",
"// Check if encoding was successful.",
"// 99.99% of the time, the encoding works.",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
"===",
"true",
")",
"{",
"// Here we have another SPOF. When the string is large enough",
"// we will run out of memory!",
"// @see https://sourceforge.net/p/krexx/bugs/21/",
"// We will *NOT* return the unescaped string. So we must check if it",
"// is small enough for the unpack().",
"// 100 kb should be save enough.",
"if",
"(",
"strlen",
"(",
"$",
"data",
")",
">",
"102400",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"getHelp",
"(",
"'stringTooLarge'",
")",
";",
"}",
"else",
"{",
"// Something went wrong with the encoding, we need to",
"// completely encode this one to be able to display it at all!",
"$",
"data",
"=",
"mb_convert_encoding",
"(",
"$",
"data",
",",
"'UTF-32'",
",",
"mb_detect_encoding",
"(",
"$",
"data",
")",
")",
";",
"$",
"result",
"=",
"implode",
"(",
"\"\"",
",",
"array_map",
"(",
"$",
"sortingCallback",
",",
"unpack",
"(",
"\"N*\"",
",",
"$",
"data",
")",
")",
")",
";",
"}",
"}",
"// Reactivate whatever error handling we had previously.",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Sanitizes a string, by completely encoding it.
Should work with mixed encoding.
@param string $data
The data which needs to be sanitized.
@param boolean $code
Do we need to format the string as code?
@return string
The encoded string. | [
"Sanitizes",
"a",
"string",
"by",
"completely",
"encoding",
"it",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Misc/Encoding.php#L151-L206 |
33,352 | brainworxx/kreXX | src/Service/Misc/Encoding.php | Encoding.mbStrLen | public function mbStrLen($string, $encoding = null)
{
// Meh, the original mb_strlen interprets a null here as an empty string.
if ($encoding === null) {
return mb_strlen($string);
}
return mb_strlen($string, $encoding);
} | php | public function mbStrLen($string, $encoding = null)
{
// Meh, the original mb_strlen interprets a null here as an empty string.
if ($encoding === null) {
return mb_strlen($string);
}
return mb_strlen($string, $encoding);
} | [
"public",
"function",
"mbStrLen",
"(",
"$",
"string",
",",
"$",
"encoding",
"=",
"null",
")",
"{",
"// Meh, the original mb_strlen interprets a null here as an empty string.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"return",
"mb_strlen",
"(",
"$",
"string",
")",
";",
"}",
"return",
"mb_strlen",
"(",
"$",
"string",
",",
"$",
"encoding",
")",
";",
"}"
] | Wrapper around mb_strlen, to circumvent a not installed
mb_string php extension.
@param string $string
The string we want to analyse
@param string $encoding
The known encoding of the string, if known.
@return integer
The result. | [
"Wrapper",
"around",
"mb_strlen",
"to",
"circumvent",
"a",
"not",
"installed",
"mb_string",
"php",
"extension",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Service/Misc/Encoding.php#L239-L246 |
33,353 | silverorange/swat | Swat/SwatCalendar.php | SwatCalendar.display | public function display()
{
if (!$this->visible) {
return;
}
parent::display();
$container_div_tag = new SwatHtmlTag('div');
$container_div_tag->id = $this->id;
$container_div_tag->class = $this->getCSSClassString();
$container_div_tag->open();
// toggle button content is displayed with JavaScript
if ($this->valid_range_start === null) {
$today = new SwatDate();
$value = $today->formatLikeIntl('MM/dd/yyyy');
} else {
$value = $this->valid_range_start->formatLikeIntl('MM/dd/yyyy');
}
$input_tag = new SwatHtmlTag('input');
$input_tag->type = 'hidden';
$input_tag->id = $this->id . '_value';
$input_tag->name = $this->id . '_value';
$input_tag->value = $value;
$input_tag->display();
$container_div_tag->close();
Swat::displayInlineJavaScript($this->getInlineJavaScript());
} | php | public function display()
{
if (!$this->visible) {
return;
}
parent::display();
$container_div_tag = new SwatHtmlTag('div');
$container_div_tag->id = $this->id;
$container_div_tag->class = $this->getCSSClassString();
$container_div_tag->open();
// toggle button content is displayed with JavaScript
if ($this->valid_range_start === null) {
$today = new SwatDate();
$value = $today->formatLikeIntl('MM/dd/yyyy');
} else {
$value = $this->valid_range_start->formatLikeIntl('MM/dd/yyyy');
}
$input_tag = new SwatHtmlTag('input');
$input_tag->type = 'hidden';
$input_tag->id = $this->id . '_value';
$input_tag->name = $this->id . '_value';
$input_tag->value = $value;
$input_tag->display();
$container_div_tag->close();
Swat::displayInlineJavaScript($this->getInlineJavaScript());
} | [
"public",
"function",
"display",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"visible",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"display",
"(",
")",
";",
"$",
"container_div_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'div'",
")",
";",
"$",
"container_div_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"container_div_tag",
"->",
"class",
"=",
"$",
"this",
"->",
"getCSSClassString",
"(",
")",
";",
"$",
"container_div_tag",
"->",
"open",
"(",
")",
";",
"// toggle button content is displayed with JavaScript",
"if",
"(",
"$",
"this",
"->",
"valid_range_start",
"===",
"null",
")",
"{",
"$",
"today",
"=",
"new",
"SwatDate",
"(",
")",
";",
"$",
"value",
"=",
"$",
"today",
"->",
"formatLikeIntl",
"(",
"'MM/dd/yyyy'",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"valid_range_start",
"->",
"formatLikeIntl",
"(",
"'MM/dd/yyyy'",
")",
";",
"}",
"$",
"input_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'input'",
")",
";",
"$",
"input_tag",
"->",
"type",
"=",
"'hidden'",
";",
"$",
"input_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
".",
"'_value'",
";",
"$",
"input_tag",
"->",
"name",
"=",
"$",
"this",
"->",
"id",
".",
"'_value'",
";",
"$",
"input_tag",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"input_tag",
"->",
"display",
"(",
")",
";",
"$",
"container_div_tag",
"->",
"close",
"(",
")",
";",
"Swat",
"::",
"displayInlineJavaScript",
"(",
"$",
"this",
"->",
"getInlineJavaScript",
"(",
")",
")",
";",
"}"
] | Displays this calendar widget | [
"Displays",
"this",
"calendar",
"widget"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCalendar.php#L63-L95 |
33,354 | silverorange/swat | Swat/SwatCalendar.php | SwatCalendar.getInlineJavaScript | protected function getInlineJavaScript()
{
static $shown = false;
if (!$shown) {
$javascript = $this->getInlineJavaScriptTranslations();
$shown = true;
} else {
$javascript = '';
}
if (isset($this->valid_range_start)) {
$start_date = $this->valid_range_start->formatLikeIntl(
'MM/dd/yyyy'
);
} else {
$start_date = '';
}
if (isset($this->valid_range_end)) {
// JavaScript calendar is inclusive, subtract one second from range
$tmp = clone $this->valid_range_end;
$tmp->subtractSeconds(1);
$end_date = $tmp->formatLikeIntl('MM/dd/yyyy');
} else {
$end_date = '';
}
$javascript .= sprintf(
"var %s_obj = new SwatCalendar('%s', '%s', '%s');",
$this->id,
$this->id,
$start_date,
$end_date
);
return $javascript;
} | php | protected function getInlineJavaScript()
{
static $shown = false;
if (!$shown) {
$javascript = $this->getInlineJavaScriptTranslations();
$shown = true;
} else {
$javascript = '';
}
if (isset($this->valid_range_start)) {
$start_date = $this->valid_range_start->formatLikeIntl(
'MM/dd/yyyy'
);
} else {
$start_date = '';
}
if (isset($this->valid_range_end)) {
// JavaScript calendar is inclusive, subtract one second from range
$tmp = clone $this->valid_range_end;
$tmp->subtractSeconds(1);
$end_date = $tmp->formatLikeIntl('MM/dd/yyyy');
} else {
$end_date = '';
}
$javascript .= sprintf(
"var %s_obj = new SwatCalendar('%s', '%s', '%s');",
$this->id,
$this->id,
$start_date,
$end_date
);
return $javascript;
} | [
"protected",
"function",
"getInlineJavaScript",
"(",
")",
"{",
"static",
"$",
"shown",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"shown",
")",
"{",
"$",
"javascript",
"=",
"$",
"this",
"->",
"getInlineJavaScriptTranslations",
"(",
")",
";",
"$",
"shown",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"javascript",
"=",
"''",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"valid_range_start",
")",
")",
"{",
"$",
"start_date",
"=",
"$",
"this",
"->",
"valid_range_start",
"->",
"formatLikeIntl",
"(",
"'MM/dd/yyyy'",
")",
";",
"}",
"else",
"{",
"$",
"start_date",
"=",
"''",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"valid_range_end",
")",
")",
"{",
"// JavaScript calendar is inclusive, subtract one second from range",
"$",
"tmp",
"=",
"clone",
"$",
"this",
"->",
"valid_range_end",
";",
"$",
"tmp",
"->",
"subtractSeconds",
"(",
"1",
")",
";",
"$",
"end_date",
"=",
"$",
"tmp",
"->",
"formatLikeIntl",
"(",
"'MM/dd/yyyy'",
")",
";",
"}",
"else",
"{",
"$",
"end_date",
"=",
"''",
";",
"}",
"$",
"javascript",
".=",
"sprintf",
"(",
"\"var %s_obj = new SwatCalendar('%s', '%s', '%s');\"",
",",
"$",
"this",
"->",
"id",
",",
"$",
"this",
"->",
"id",
",",
"$",
"start_date",
",",
"$",
"end_date",
")",
";",
"return",
"$",
"javascript",
";",
"}"
] | Gets inline calendar JavaScript
Inline JavaScript is the majority of the calendar code. | [
"Gets",
"inline",
"calendar",
"JavaScript"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatCalendar.php#L121-L158 |
33,355 | rhoone/yii2-rhoone | Module.php | Module.bootstrapExtensions | protected function bootstrapExtensions($app)
{
$rhoone = Yii::$app->rhoone;
/* @var $rhoone \rhoone\base\Rhoone */
$extensions = $rhoone->extensions;
if (empty($extensions)) {
return 0;
}
foreach ($extensions as $id => $extension) {
if ($extension instanceof BootstrapInterface) {
try {
$extension->bootstrap($app);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
continue;
}
}
}
$count = 0;
foreach ($extensions as $ext) {
$moduleConfig = [];
try {
$moduleConfig = $ext->getModule();
} catch (\Exception $ex) {
continue;
}
if (empty($moduleConfig)) {
continue;
}
Yii::info("`" . $moduleConfig['id'] . '` enabled.', __METHOD__);
$app->setModule($moduleConfig['id'], $moduleConfig);
$module = $app->getModule($moduleConfig['id']);
if ($module instanceof BootstrapInterface) {
$app->bootstrap[] = $module->id;
Yii::trace('Bootstrap with ' . $module->className() . '::' . 'bootstrap()', __METHOD__);
$module->bootstrap($app);
$count++;
}
}
return $count;
} | php | protected function bootstrapExtensions($app)
{
$rhoone = Yii::$app->rhoone;
/* @var $rhoone \rhoone\base\Rhoone */
$extensions = $rhoone->extensions;
if (empty($extensions)) {
return 0;
}
foreach ($extensions as $id => $extension) {
if ($extension instanceof BootstrapInterface) {
try {
$extension->bootstrap($app);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
continue;
}
}
}
$count = 0;
foreach ($extensions as $ext) {
$moduleConfig = [];
try {
$moduleConfig = $ext->getModule();
} catch (\Exception $ex) {
continue;
}
if (empty($moduleConfig)) {
continue;
}
Yii::info("`" . $moduleConfig['id'] . '` enabled.', __METHOD__);
$app->setModule($moduleConfig['id'], $moduleConfig);
$module = $app->getModule($moduleConfig['id']);
if ($module instanceof BootstrapInterface) {
$app->bootstrap[] = $module->id;
Yii::trace('Bootstrap with ' . $module->className() . '::' . 'bootstrap()', __METHOD__);
$module->bootstrap($app);
$count++;
}
}
return $count;
} | [
"protected",
"function",
"bootstrapExtensions",
"(",
"$",
"app",
")",
"{",
"$",
"rhoone",
"=",
"Yii",
"::",
"$",
"app",
"->",
"rhoone",
";",
"/* @var $rhoone \\rhoone\\base\\Rhoone */",
"$",
"extensions",
"=",
"$",
"rhoone",
"->",
"extensions",
";",
"if",
"(",
"empty",
"(",
"$",
"extensions",
")",
")",
"{",
"return",
"0",
";",
"}",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"id",
"=>",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"extension",
"instanceof",
"BootstrapInterface",
")",
"{",
"try",
"{",
"$",
"extension",
"->",
"bootstrap",
"(",
"$",
"app",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"continue",
";",
"}",
"}",
"}",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"ext",
")",
"{",
"$",
"moduleConfig",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"moduleConfig",
"=",
"$",
"ext",
"->",
"getModule",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"moduleConfig",
")",
")",
"{",
"continue",
";",
"}",
"Yii",
"::",
"info",
"(",
"\"`\"",
".",
"$",
"moduleConfig",
"[",
"'id'",
"]",
".",
"'` enabled.'",
",",
"__METHOD__",
")",
";",
"$",
"app",
"->",
"setModule",
"(",
"$",
"moduleConfig",
"[",
"'id'",
"]",
",",
"$",
"moduleConfig",
")",
";",
"$",
"module",
"=",
"$",
"app",
"->",
"getModule",
"(",
"$",
"moduleConfig",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"$",
"module",
"instanceof",
"BootstrapInterface",
")",
"{",
"$",
"app",
"->",
"bootstrap",
"[",
"]",
"=",
"$",
"module",
"->",
"id",
";",
"Yii",
"::",
"trace",
"(",
"'Bootstrap with '",
".",
"$",
"module",
"->",
"className",
"(",
")",
".",
"'::'",
".",
"'bootstrap()'",
",",
"__METHOD__",
")",
";",
"$",
"module",
"->",
"bootstrap",
"(",
"$",
"app",
")",
";",
"$",
"count",
"++",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Bootstrap with Extensions.
@param \yii\base\Application $app
@return int | [
"Bootstrap",
"with",
"Extensions",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/Module.php#L104-L145 |
33,356 | silverorange/swat | Swat/SwatSelectList.php | SwatSelectList.display | public function display()
{
$options = $this->getOptions();
if (!$this->visible || count($options) === 0) {
return;
}
SwatWidget::display();
$this->getForm()->addHiddenField($this->id . '_submitted', 1);
$select_tag = new SwatHtmlTag('select');
$select_tag->id = $this->id;
$select_tag->name = $this->id . '[]';
$select_tag->class = 'swat-select-list';
$select_tag->multiple = 'multiple';
$select_tag->size = $this->size;
$select_tag->open();
foreach ($options as $key => $option) {
$option_tag = new SwatHtmlTag('option');
$option_tag->value = (string) $option->value;
$option_tag->id = $this->id . '_' . $key . '_' . $option_tag->value;
$option_tag->selected = null;
if (in_array($option->value, $this->values)) {
$option_tag->selected = 'selected';
}
$option_tag->setContent($option->title, $option->content_type);
$option_tag->display();
}
$select_tag->close();
} | php | public function display()
{
$options = $this->getOptions();
if (!$this->visible || count($options) === 0) {
return;
}
SwatWidget::display();
$this->getForm()->addHiddenField($this->id . '_submitted', 1);
$select_tag = new SwatHtmlTag('select');
$select_tag->id = $this->id;
$select_tag->name = $this->id . '[]';
$select_tag->class = 'swat-select-list';
$select_tag->multiple = 'multiple';
$select_tag->size = $this->size;
$select_tag->open();
foreach ($options as $key => $option) {
$option_tag = new SwatHtmlTag('option');
$option_tag->value = (string) $option->value;
$option_tag->id = $this->id . '_' . $key . '_' . $option_tag->value;
$option_tag->selected = null;
if (in_array($option->value, $this->values)) {
$option_tag->selected = 'selected';
}
$option_tag->setContent($option->title, $option->content_type);
$option_tag->display();
}
$select_tag->close();
} | [
"public",
"function",
"display",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"visible",
"||",
"count",
"(",
"$",
"options",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"SwatWidget",
"::",
"display",
"(",
")",
";",
"$",
"this",
"->",
"getForm",
"(",
")",
"->",
"addHiddenField",
"(",
"$",
"this",
"->",
"id",
".",
"'_submitted'",
",",
"1",
")",
";",
"$",
"select_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'select'",
")",
";",
"$",
"select_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"select_tag",
"->",
"name",
"=",
"$",
"this",
"->",
"id",
".",
"'[]'",
";",
"$",
"select_tag",
"->",
"class",
"=",
"'swat-select-list'",
";",
"$",
"select_tag",
"->",
"multiple",
"=",
"'multiple'",
";",
"$",
"select_tag",
"->",
"size",
"=",
"$",
"this",
"->",
"size",
";",
"$",
"select_tag",
"->",
"open",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"option",
")",
"{",
"$",
"option_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'option'",
")",
";",
"$",
"option_tag",
"->",
"value",
"=",
"(",
"string",
")",
"$",
"option",
"->",
"value",
";",
"$",
"option_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
".",
"'_'",
".",
"$",
"key",
".",
"'_'",
".",
"$",
"option_tag",
"->",
"value",
";",
"$",
"option_tag",
"->",
"selected",
"=",
"null",
";",
"if",
"(",
"in_array",
"(",
"$",
"option",
"->",
"value",
",",
"$",
"this",
"->",
"values",
")",
")",
"{",
"$",
"option_tag",
"->",
"selected",
"=",
"'selected'",
";",
"}",
"$",
"option_tag",
"->",
"setContent",
"(",
"$",
"option",
"->",
"title",
",",
"$",
"option",
"->",
"content_type",
")",
";",
"$",
"option_tag",
"->",
"display",
"(",
")",
";",
"}",
"$",
"select_tag",
"->",
"close",
"(",
")",
";",
"}"
] | Displays this select list | [
"Displays",
"this",
"select",
"list"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatSelectList.php#L27-L61 |
33,357 | rhoone/yii2-rhoone | base/ExtensionHelperTrait.php | ExtensionHelperTrait.getModel | public static function getModel($class)
{
if ($class instanceof \rhoone\extension\Extension) {
$class = $class->className();
}
if (is_string($class)) {
return \rhoone\models\Extension::find()->where(['classname' => static::normalizeClass($class)])->one();
}
if ($class instanceof \rhoone\models\Extension) {
return \rhoone\models\Extension::find()->guid($class->guid)->one();
}
return null;
} | php | public static function getModel($class)
{
if ($class instanceof \rhoone\extension\Extension) {
$class = $class->className();
}
if (is_string($class)) {
return \rhoone\models\Extension::find()->where(['classname' => static::normalizeClass($class)])->one();
}
if ($class instanceof \rhoone\models\Extension) {
return \rhoone\models\Extension::find()->guid($class->guid)->one();
}
return null;
} | [
"public",
"static",
"function",
"getModel",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"instanceof",
"\\",
"rhoone",
"\\",
"extension",
"\\",
"Extension",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"->",
"className",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
")",
"{",
"return",
"\\",
"rhoone",
"\\",
"models",
"\\",
"Extension",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'classname'",
"=>",
"static",
"::",
"normalizeClass",
"(",
"$",
"class",
")",
"]",
")",
"->",
"one",
"(",
")",
";",
"}",
"if",
"(",
"$",
"class",
"instanceof",
"\\",
"rhoone",
"\\",
"models",
"\\",
"Extension",
")",
"{",
"return",
"\\",
"rhoone",
"\\",
"models",
"\\",
"Extension",
"::",
"find",
"(",
")",
"->",
"guid",
"(",
"$",
"class",
"->",
"guid",
")",
"->",
"one",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get extension model.
@param string|\rhoone\extension\Extension|\rhoone\models\Extension $class
@return \rhoone\models\Extension | [
"Get",
"extension",
"model",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/base/ExtensionHelperTrait.php#L123-L135 |
33,358 | rhoone/yii2-rhoone | base/ExtensionHelperTrait.php | ExtensionHelperTrait.validate | public static function validate($class)
{
if ($class instanceof \rhoone\extension\Extension) {
$class = $class->className();
}
if ($class instanceof \rhoone\models\Extension) {
$class = $class->classname;
}
if (!is_string($class)) {
Yii::error('the class name is not a string.', __METHOD__);
throw new InvalidParamException('the class name is not a string. (' . __METHOD__ . ')');
}
Yii::trace('validate extension: `' . $class . '`', __METHOD__);
$class = static::normalizeClass($class);
$extension = static::validateExtension($class);
$dic = DictionaryManager::validate($extension);
return $extension;
} | php | public static function validate($class)
{
if ($class instanceof \rhoone\extension\Extension) {
$class = $class->className();
}
if ($class instanceof \rhoone\models\Extension) {
$class = $class->classname;
}
if (!is_string($class)) {
Yii::error('the class name is not a string.', __METHOD__);
throw new InvalidParamException('the class name is not a string. (' . __METHOD__ . ')');
}
Yii::trace('validate extension: `' . $class . '`', __METHOD__);
$class = static::normalizeClass($class);
$extension = static::validateExtension($class);
$dic = DictionaryManager::validate($extension);
return $extension;
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"instanceof",
"\\",
"rhoone",
"\\",
"extension",
"\\",
"Extension",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"->",
"className",
"(",
")",
";",
"}",
"if",
"(",
"$",
"class",
"instanceof",
"\\",
"rhoone",
"\\",
"models",
"\\",
"Extension",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"->",
"classname",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"class",
")",
")",
"{",
"Yii",
"::",
"error",
"(",
"'the class name is not a string.'",
",",
"__METHOD__",
")",
";",
"throw",
"new",
"InvalidParamException",
"(",
"'the class name is not a string. ('",
".",
"__METHOD__",
".",
"')'",
")",
";",
"}",
"Yii",
"::",
"trace",
"(",
"'validate extension: `'",
".",
"$",
"class",
".",
"'`'",
",",
"__METHOD__",
")",
";",
"$",
"class",
"=",
"static",
"::",
"normalizeClass",
"(",
"$",
"class",
")",
";",
"$",
"extension",
"=",
"static",
"::",
"validateExtension",
"(",
"$",
"class",
")",
";",
"$",
"dic",
"=",
"DictionaryManager",
"::",
"validate",
"(",
"$",
"extension",
")",
";",
"return",
"$",
"extension",
";",
"}"
] | Validate extension class.
@param string|\rhoone\extension\Extension|\rhoone\models\Extension $class
`string` if extension class name.
`\rhoone\extension\Extension` if extension instance.
`\rhoone\models\Extension` if extension record.
@return \rhoone\extension\Extension
@throws InvalidParamException | [
"Validate",
"extension",
"class",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/base/ExtensionHelperTrait.php#L271-L289 |
33,359 | rhoone/yii2-rhoone | base/ExtensionHelperTrait.php | ExtensionHelperTrait.deregister | public static function deregister($class, $force = false)
{
$model = static::getModel($class);
if (!$model) {
throw new InvalidParamException("`$class` does not exist.");
}
if ($model->isEnabled && !$force) {
throw new InvalidParamException("Unable to remove the enabled extensions.");
}
return $model->delete() == 1;
} | php | public static function deregister($class, $force = false)
{
$model = static::getModel($class);
if (!$model) {
throw new InvalidParamException("`$class` does not exist.");
}
if ($model->isEnabled && !$force) {
throw new InvalidParamException("Unable to remove the enabled extensions.");
}
return $model->delete() == 1;
} | [
"public",
"static",
"function",
"deregister",
"(",
"$",
"class",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"model",
"=",
"static",
"::",
"getModel",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"throw",
"new",
"InvalidParamException",
"(",
"\"`$class` does not exist.\"",
")",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"isEnabled",
"&&",
"!",
"$",
"force",
")",
"{",
"throw",
"new",
"InvalidParamException",
"(",
"\"Unable to remove the enabled extensions.\"",
")",
";",
"}",
"return",
"$",
"model",
"->",
"delete",
"(",
")",
"==",
"1",
";",
"}"
] | Deregister extension.
@param string|\rhoone\extension\Extension|\rhoone\models\Extension $class
@return boolean True if extension deregistered. | [
"Deregister",
"extension",
"."
] | f6ae90d466ea6f34bba404be0aba03e37ef369ad | https://github.com/rhoone/yii2-rhoone/blob/f6ae90d466ea6f34bba404be0aba03e37ef369ad/base/ExtensionHelperTrait.php#L296-L306 |
33,360 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.get | public static function get($locale = null)
{
$locale_object = null;
if ($locale === null) {
$locale_key = self::setlocale(LC_ALL, '0');
if (array_key_exists($locale_key, self::$locales)) {
$locale_object = self::$locales[$locale_key];
}
} elseif (is_array($locale)) {
foreach ($locale as $locale_key) {
if (array_key_exists($locale_key, self::$locales)) {
$locale_object = self::$locales[$locale_key];
break;
}
}
} else {
if (array_key_exists($locale, self::$locales)) {
$locale_object = self::$locales[$locale];
}
}
if ($locale_object === null) {
$locale_object = new SwatI18NLocale($locale);
if ($locale === null) {
$locale_key = $locale_object->__toString();
self::$locales[$locale_key] = $locale_object;
} elseif (is_array($locale)) {
foreach ($locale as $locale_key) {
self::$locales[$locale_key] = $locale_object;
}
} else {
self::$locales[$locale] = $locale_object;
}
}
return $locale_object;
} | php | public static function get($locale = null)
{
$locale_object = null;
if ($locale === null) {
$locale_key = self::setlocale(LC_ALL, '0');
if (array_key_exists($locale_key, self::$locales)) {
$locale_object = self::$locales[$locale_key];
}
} elseif (is_array($locale)) {
foreach ($locale as $locale_key) {
if (array_key_exists($locale_key, self::$locales)) {
$locale_object = self::$locales[$locale_key];
break;
}
}
} else {
if (array_key_exists($locale, self::$locales)) {
$locale_object = self::$locales[$locale];
}
}
if ($locale_object === null) {
$locale_object = new SwatI18NLocale($locale);
if ($locale === null) {
$locale_key = $locale_object->__toString();
self::$locales[$locale_key] = $locale_object;
} elseif (is_array($locale)) {
foreach ($locale as $locale_key) {
self::$locales[$locale_key] = $locale_object;
}
} else {
self::$locales[$locale] = $locale_object;
}
}
return $locale_object;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"locale_object",
"=",
"null",
";",
"if",
"(",
"$",
"locale",
"===",
"null",
")",
"{",
"$",
"locale_key",
"=",
"self",
"::",
"setlocale",
"(",
"LC_ALL",
",",
"'0'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"locale_key",
",",
"self",
"::",
"$",
"locales",
")",
")",
"{",
"$",
"locale_object",
"=",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale_key",
"]",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"locale",
")",
")",
"{",
"foreach",
"(",
"$",
"locale",
"as",
"$",
"locale_key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"locale_key",
",",
"self",
"::",
"$",
"locales",
")",
")",
"{",
"$",
"locale_object",
"=",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale_key",
"]",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"locale",
",",
"self",
"::",
"$",
"locales",
")",
")",
"{",
"$",
"locale_object",
"=",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"locale_object",
"===",
"null",
")",
"{",
"$",
"locale_object",
"=",
"new",
"SwatI18NLocale",
"(",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"locale",
"===",
"null",
")",
"{",
"$",
"locale_key",
"=",
"$",
"locale_object",
"->",
"__toString",
"(",
")",
";",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale_key",
"]",
"=",
"$",
"locale_object",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"locale",
")",
")",
"{",
"foreach",
"(",
"$",
"locale",
"as",
"$",
"locale_key",
")",
"{",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale_key",
"]",
"=",
"$",
"locale_object",
";",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"locales",
"[",
"$",
"locale",
"]",
"=",
"$",
"locale_object",
";",
"}",
"}",
"return",
"$",
"locale_object",
";",
"}"
] | Gets a locale object
@param array|string $locale the locale identifier of this locale object.
If the locale is not valid for the current
operating system, an exception is thrown.
If no locale is specified, the current
locale is used. Multiple locale identifiers
may be specified in an array. In this case,
the first valid locale is used.
@return SwatI18NLocale a locale object for the requested <i>$locale</i>.
@throws SwatException if the specified <i>$locale</i> is not valid for
the current operating system. | [
"Gets",
"a",
"locale",
"object"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L106-L143 |
33,361 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.setlocale | public static function setlocale($category, $locale)
{
$return = false;
static $categories = array(
'LC_COLLATE' => LC_COLLATE,
'LC_CTYPE' => LC_CTYPE,
'LC_MONETARY' => LC_MONETARY,
'LC_NUMERIC' => LC_NUMERIC,
'LC_TIME' => LC_TIME,
'LC_MESSAGES' => LC_MESSAGES
);
$parts = explode(';', $locale);
if ($category === LC_ALL && count($parts) > 1) {
// Handle case when LC_ALL is undefined and we're passing a giant
// string with all the separate lc-type values.
foreach ($parts as $part) {
$part_exp = explode('=', $part, 2);
if (
count($part_exp) === 2 &&
array_key_exists($part_exp[0], $categories)
) {
$return = setlocale(
$categories[$part_exp[0]],
$part_exp[1]
);
}
}
} else {
$return = setlocale($category, $locale);
}
return $return;
} | php | public static function setlocale($category, $locale)
{
$return = false;
static $categories = array(
'LC_COLLATE' => LC_COLLATE,
'LC_CTYPE' => LC_CTYPE,
'LC_MONETARY' => LC_MONETARY,
'LC_NUMERIC' => LC_NUMERIC,
'LC_TIME' => LC_TIME,
'LC_MESSAGES' => LC_MESSAGES
);
$parts = explode(';', $locale);
if ($category === LC_ALL && count($parts) > 1) {
// Handle case when LC_ALL is undefined and we're passing a giant
// string with all the separate lc-type values.
foreach ($parts as $part) {
$part_exp = explode('=', $part, 2);
if (
count($part_exp) === 2 &&
array_key_exists($part_exp[0], $categories)
) {
$return = setlocale(
$categories[$part_exp[0]],
$part_exp[1]
);
}
}
} else {
$return = setlocale($category, $locale);
}
return $return;
} | [
"public",
"static",
"function",
"setlocale",
"(",
"$",
"category",
",",
"$",
"locale",
")",
"{",
"$",
"return",
"=",
"false",
";",
"static",
"$",
"categories",
"=",
"array",
"(",
"'LC_COLLATE'",
"=>",
"LC_COLLATE",
",",
"'LC_CTYPE'",
"=>",
"LC_CTYPE",
",",
"'LC_MONETARY'",
"=>",
"LC_MONETARY",
",",
"'LC_NUMERIC'",
"=>",
"LC_NUMERIC",
",",
"'LC_TIME'",
"=>",
"LC_TIME",
",",
"'LC_MESSAGES'",
"=>",
"LC_MESSAGES",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"';'",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"category",
"===",
"LC_ALL",
"&&",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"// Handle case when LC_ALL is undefined and we're passing a giant",
"// string with all the separate lc-type values.",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"part_exp",
"=",
"explode",
"(",
"'='",
",",
"$",
"part",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"part_exp",
")",
"===",
"2",
"&&",
"array_key_exists",
"(",
"$",
"part_exp",
"[",
"0",
"]",
",",
"$",
"categories",
")",
")",
"{",
"$",
"return",
"=",
"setlocale",
"(",
"$",
"categories",
"[",
"$",
"part_exp",
"[",
"0",
"]",
"]",
",",
"$",
"part_exp",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"return",
"=",
"setlocale",
"(",
"$",
"category",
",",
"$",
"locale",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Sets the current locale
This is a wrapper for the system setlocale() function that provides
extra compatibility.
@param integer $category optional. The lc-type constant specifying the
category of functions affected by setting
the system locale.
@param array|string $locale the locale identifier. Use '0' to return
the current system locale. Multiple locale
identifiers may be specified in an array.
In this case, the first valid locale is
used.
@return string|boolean the new or current locale, or false if an invalid
<i>$locale</i> is specified. | [
"Sets",
"the",
"current",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L166-L200 |
33,362 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.set | public function set($category = LC_ALL)
{
$this->old_locale_by_category[$category] = self::setlocale(
$category,
'0'
);
self::setlocale($category, $this->locale);
} | php | public function set($category = LC_ALL)
{
$this->old_locale_by_category[$category] = self::setlocale(
$category,
'0'
);
self::setlocale($category, $this->locale);
} | [
"public",
"function",
"set",
"(",
"$",
"category",
"=",
"LC_ALL",
")",
"{",
"$",
"this",
"->",
"old_locale_by_category",
"[",
"$",
"category",
"]",
"=",
"self",
"::",
"setlocale",
"(",
"$",
"category",
",",
"'0'",
")",
";",
"self",
"::",
"setlocale",
"(",
"$",
"category",
",",
"$",
"this",
"->",
"locale",
")",
";",
"}"
] | Sets the system locale to this locale
@param integer $category optional. The lc-type constant specifying the
category of functions affected by setting the
system locale. If not specified, defaults to
LC_ALL. | [
"Sets",
"the",
"system",
"locale",
"to",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L213-L221 |
33,363 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.formatNumber | public function formatNumber(
$value,
$decimals = null,
array $format = array()
) {
$value = (float) $value;
$format = $this->getNumberFormat()->override($format);
if ($decimals === null) {
$decimals = $this->getFractionalPrecision($value);
}
$value = round($value, $decimals);
$integer_part = $this->formatIntegerGroupings($value, $format);
$fractional_part = $this->formatFractionalPart(
$value,
$decimals,
$format
);
$sign = $value < 0 ? '-' : '';
$formatted_value = $sign . $integer_part . $fractional_part;
return $formatted_value;
} | php | public function formatNumber(
$value,
$decimals = null,
array $format = array()
) {
$value = (float) $value;
$format = $this->getNumberFormat()->override($format);
if ($decimals === null) {
$decimals = $this->getFractionalPrecision($value);
}
$value = round($value, $decimals);
$integer_part = $this->formatIntegerGroupings($value, $format);
$fractional_part = $this->formatFractionalPart(
$value,
$decimals,
$format
);
$sign = $value < 0 ? '-' : '';
$formatted_value = $sign . $integer_part . $fractional_part;
return $formatted_value;
} | [
"public",
"function",
"formatNumber",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"null",
",",
"array",
"$",
"format",
"=",
"array",
"(",
")",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"getNumberFormat",
"(",
")",
"->",
"override",
"(",
"$",
"format",
")",
";",
"if",
"(",
"$",
"decimals",
"===",
"null",
")",
"{",
"$",
"decimals",
"=",
"$",
"this",
"->",
"getFractionalPrecision",
"(",
"$",
"value",
")",
";",
"}",
"$",
"value",
"=",
"round",
"(",
"$",
"value",
",",
"$",
"decimals",
")",
";",
"$",
"integer_part",
"=",
"$",
"this",
"->",
"formatIntegerGroupings",
"(",
"$",
"value",
",",
"$",
"format",
")",
";",
"$",
"fractional_part",
"=",
"$",
"this",
"->",
"formatFractionalPart",
"(",
"$",
"value",
",",
"$",
"decimals",
",",
"$",
"format",
")",
";",
"$",
"sign",
"=",
"$",
"value",
"<",
"0",
"?",
"'-'",
":",
"''",
";",
"$",
"formatted_value",
"=",
"$",
"sign",
".",
"$",
"integer_part",
".",
"$",
"fractional_part",
";",
"return",
"$",
"formatted_value",
";",
"}"
] | Formats a numeric value for this locale
This methods uses the POSIX.2 LC_NUMERIC specification for formatting
numeric values.
Numeric values are rounded to the specified number of fractional digits
using a round-half-up rounding method (PHP's default round).
@param float $value the numeric value to format.
@param integer $decimals optional. The number of fractional digits to
include in the returned string. If not
specified, all fractional digits are included.
@param array $format optional. An associative array of number formatting
information that overrides the formatting for this
locale. The array is of the form
<i>'property' => value</i>. For example, use the
value <code>array('grouping' => 0)</code> to turn
off numeric groupings.
@return string a UTF-8 encoded string containing the formatted numeric
value.
@throws SwatException if a property name specified in the <i>$format</i>
parameter is invalid. | [
"Formats",
"a",
"numeric",
"value",
"for",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L562-L589 |
33,364 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.parseFloat | public function parseFloat($string)
{
$value = null;
$lc = $this->getLocaleInfo();
$string = $this->parseNegativeNotation($string);
$search = array(
$lc['thousands_sep'],
$lc['decimal_point'],
$lc['positive_sign'],
' '
);
$replace = array('', '.', '', '');
$string = str_replace($search, $replace, $string);
if (is_numeric($string)) {
$value = floatval($string);
}
return $value;
} | php | public function parseFloat($string)
{
$value = null;
$lc = $this->getLocaleInfo();
$string = $this->parseNegativeNotation($string);
$search = array(
$lc['thousands_sep'],
$lc['decimal_point'],
$lc['positive_sign'],
' '
);
$replace = array('', '.', '', '');
$string = str_replace($search, $replace, $string);
if (is_numeric($string)) {
$value = floatval($string);
}
return $value;
} | [
"public",
"function",
"parseFloat",
"(",
"$",
"string",
")",
"{",
"$",
"value",
"=",
"null",
";",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"string",
"=",
"$",
"this",
"->",
"parseNegativeNotation",
"(",
"$",
"string",
")",
";",
"$",
"search",
"=",
"array",
"(",
"$",
"lc",
"[",
"'thousands_sep'",
"]",
",",
"$",
"lc",
"[",
"'decimal_point'",
"]",
",",
"$",
"lc",
"[",
"'positive_sign'",
"]",
",",
"' '",
")",
";",
"$",
"replace",
"=",
"array",
"(",
"''",
",",
"'.'",
",",
"''",
",",
"''",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"string",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"string",
")",
")",
"{",
"$",
"value",
"=",
"floatval",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Parses a numeric string formatted for this locale into a floating-point
number
Note: The number does not have to be formatted exactly correctly to be
parsed. Checking too closely how well a formatted number matches its
locale would be annoying for users. For example, '1000' should not be
rejected because it wasn't formatted as '1,000'.
@param string $string the formatted string.
@return float the numeric value of the parsed string. If the given
value could not be parsed, null is returned. | [
"Parses",
"a",
"numeric",
"string",
"formatted",
"for",
"this",
"locale",
"into",
"a",
"floating",
"-",
"point",
"number"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L657-L681 |
33,365 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.parseInteger | public function parseInteger($string)
{
$value = null;
$lc = $this->getLocaleInfo();
$string = $this->parseNegativeNotation($string);
$search = array($lc['thousands_sep'], $lc['positive_sign'], ' ');
$replace = array('', '', '');
$string = str_replace($search, $replace, $string);
if (is_numeric($string)) {
if ($string > (float) PHP_INT_MAX) {
throw new SwatIntegerOverflowException(
'Floating point value is too big to be an integer',
null,
1
);
}
if ($string < (float) (-PHP_INT_MAX - 1)) {
throw new SwatIntegerOverflowException(
'Floating point value is too small to be an integer',
null,
-1
);
}
$value = intval($string);
}
return $value;
} | php | public function parseInteger($string)
{
$value = null;
$lc = $this->getLocaleInfo();
$string = $this->parseNegativeNotation($string);
$search = array($lc['thousands_sep'], $lc['positive_sign'], ' ');
$replace = array('', '', '');
$string = str_replace($search, $replace, $string);
if (is_numeric($string)) {
if ($string > (float) PHP_INT_MAX) {
throw new SwatIntegerOverflowException(
'Floating point value is too big to be an integer',
null,
1
);
}
if ($string < (float) (-PHP_INT_MAX - 1)) {
throw new SwatIntegerOverflowException(
'Floating point value is too small to be an integer',
null,
-1
);
}
$value = intval($string);
}
return $value;
} | [
"public",
"function",
"parseInteger",
"(",
"$",
"string",
")",
"{",
"$",
"value",
"=",
"null",
";",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"string",
"=",
"$",
"this",
"->",
"parseNegativeNotation",
"(",
"$",
"string",
")",
";",
"$",
"search",
"=",
"array",
"(",
"$",
"lc",
"[",
"'thousands_sep'",
"]",
",",
"$",
"lc",
"[",
"'positive_sign'",
"]",
",",
"' '",
")",
";",
"$",
"replace",
"=",
"array",
"(",
"''",
",",
"''",
",",
"''",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"string",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"string",
")",
")",
"{",
"if",
"(",
"$",
"string",
">",
"(",
"float",
")",
"PHP_INT_MAX",
")",
"{",
"throw",
"new",
"SwatIntegerOverflowException",
"(",
"'Floating point value is too big to be an integer'",
",",
"null",
",",
"1",
")",
";",
"}",
"if",
"(",
"$",
"string",
"<",
"(",
"float",
")",
"(",
"-",
"PHP_INT_MAX",
"-",
"1",
")",
")",
"{",
"throw",
"new",
"SwatIntegerOverflowException",
"(",
"'Floating point value is too small to be an integer'",
",",
"null",
",",
"-",
"1",
")",
";",
"}",
"$",
"value",
"=",
"intval",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Parses a numeric string formatted for this locale into an integer number
If the string has fractional digits, the returned integer value is
rounded according to the rounding rules for
{@link http://php.net/manual/en/function.intval.php intval()}.
Note: The number does not have to be formatted exactly correctly to be
parsed. Checking too closely how well a formatted number matches its
locale would be annoying for users. For example, '1000' should not be
rejected because it wasn't formatted as '1,000'.
If the number is too large to fit in PHP's integer range (depends on
system architecture), an exception is thrown.
@param string $string the formatted string.
@return integer the numeric value of the parsed string. If the given
value could not be parsed, null is returned.
@throws SwatIntegerOverflowException if the converted number is too large
to fit in an integer or if the converted number is too
small to fit in an integer. | [
"Parses",
"a",
"numeric",
"string",
"formatted",
"for",
"this",
"locale",
"into",
"an",
"integer",
"number"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L710-L745 |
33,366 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.detectCharacterEncoding | protected function detectCharacterEncoding()
{
$encoding = null;
if (function_exists('nl_langinfo') && is_callable('nl_langinfo')) {
$encoding = nl_langinfo(CODESET);
} else {
// try to detect encoding from locale identifier
$lc_ctype = null;
$lc_all = self::setlocale(LC_ALL, '0');
$lc_all_exp = explode(';', $lc_all);
if (count($lc_all_exp) === 1) {
$lc_ctype = reset($lc_all_exp);
} else {
foreach ($lc_all_exp as $lc) {
if (strncmp($lc, 'LC_CTYPE', 8) === 0) {
$lc_ctype = $lc;
break;
}
}
}
if ($lc_ctype !== null) {
$lc_ctype_exp = explode('.', $lc_ctype, 2);
if (count($lc_ctype_exp) === 2) {
$encoding = $lc_ctype_exp[1];
}
}
}
// assume encoding is a code-page if encoding is numeric
if ($encoding !== null && ctype_digit($encoding)) {
$encoding = 'CP' . $encoding;
}
return $encoding;
} | php | protected function detectCharacterEncoding()
{
$encoding = null;
if (function_exists('nl_langinfo') && is_callable('nl_langinfo')) {
$encoding = nl_langinfo(CODESET);
} else {
// try to detect encoding from locale identifier
$lc_ctype = null;
$lc_all = self::setlocale(LC_ALL, '0');
$lc_all_exp = explode(';', $lc_all);
if (count($lc_all_exp) === 1) {
$lc_ctype = reset($lc_all_exp);
} else {
foreach ($lc_all_exp as $lc) {
if (strncmp($lc, 'LC_CTYPE', 8) === 0) {
$lc_ctype = $lc;
break;
}
}
}
if ($lc_ctype !== null) {
$lc_ctype_exp = explode('.', $lc_ctype, 2);
if (count($lc_ctype_exp) === 2) {
$encoding = $lc_ctype_exp[1];
}
}
}
// assume encoding is a code-page if encoding is numeric
if ($encoding !== null && ctype_digit($encoding)) {
$encoding = 'CP' . $encoding;
}
return $encoding;
} | [
"protected",
"function",
"detectCharacterEncoding",
"(",
")",
"{",
"$",
"encoding",
"=",
"null",
";",
"if",
"(",
"function_exists",
"(",
"'nl_langinfo'",
")",
"&&",
"is_callable",
"(",
"'nl_langinfo'",
")",
")",
"{",
"$",
"encoding",
"=",
"nl_langinfo",
"(",
"CODESET",
")",
";",
"}",
"else",
"{",
"// try to detect encoding from locale identifier",
"$",
"lc_ctype",
"=",
"null",
";",
"$",
"lc_all",
"=",
"self",
"::",
"setlocale",
"(",
"LC_ALL",
",",
"'0'",
")",
";",
"$",
"lc_all_exp",
"=",
"explode",
"(",
"';'",
",",
"$",
"lc_all",
")",
";",
"if",
"(",
"count",
"(",
"$",
"lc_all_exp",
")",
"===",
"1",
")",
"{",
"$",
"lc_ctype",
"=",
"reset",
"(",
"$",
"lc_all_exp",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"lc_all_exp",
"as",
"$",
"lc",
")",
"{",
"if",
"(",
"strncmp",
"(",
"$",
"lc",
",",
"'LC_CTYPE'",
",",
"8",
")",
"===",
"0",
")",
"{",
"$",
"lc_ctype",
"=",
"$",
"lc",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"lc_ctype",
"!==",
"null",
")",
"{",
"$",
"lc_ctype_exp",
"=",
"explode",
"(",
"'.'",
",",
"$",
"lc_ctype",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"lc_ctype_exp",
")",
"===",
"2",
")",
"{",
"$",
"encoding",
"=",
"$",
"lc_ctype_exp",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"// assume encoding is a code-page if encoding is numeric",
"if",
"(",
"$",
"encoding",
"!==",
"null",
"&&",
"ctype_digit",
"(",
"$",
"encoding",
")",
")",
"{",
"$",
"encoding",
"=",
"'CP'",
".",
"$",
"encoding",
";",
"}",
"return",
"$",
"encoding",
";",
"}"
] | Detects the character encoding used by this locale
@return string the character encoding used by this locale. If the
encoding could not be detected, null is returned. | [
"Detects",
"the",
"character",
"encoding",
"used",
"by",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L854-L890 |
33,367 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.buildNumberFormat | protected function buildNumberFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NNumberFormat();
$format->decimal_separator = $lc['decimal_point'];
$format->thousands_separator = $lc['thousands_sep'];
$format->grouping = $lc['grouping'];
$this->number_format = $format;
} | php | protected function buildNumberFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NNumberFormat();
$format->decimal_separator = $lc['decimal_point'];
$format->thousands_separator = $lc['thousands_sep'];
$format->grouping = $lc['grouping'];
$this->number_format = $format;
} | [
"protected",
"function",
"buildNumberFormat",
"(",
")",
"{",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"format",
"=",
"new",
"SwatI18NNumberFormat",
"(",
")",
";",
"$",
"format",
"->",
"decimal_separator",
"=",
"$",
"lc",
"[",
"'decimal_point'",
"]",
";",
"$",
"format",
"->",
"thousands_separator",
"=",
"$",
"lc",
"[",
"'thousands_sep'",
"]",
";",
"$",
"format",
"->",
"grouping",
"=",
"$",
"lc",
"[",
"'grouping'",
"]",
";",
"$",
"this",
"->",
"number_format",
"=",
"$",
"format",
";",
"}"
] | Builds the number format of this locale | [
"Builds",
"the",
"number",
"format",
"of",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L937-L948 |
33,368 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.buildNationalCurrencyFormat | protected function buildNationalCurrencyFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NCurrencyFormat();
$format->fractional_digits = $lc['frac_digits'];
$format->p_cs_precedes = $lc['p_cs_precedes'];
$format->n_cs_precedes = $lc['n_cs_precedes'];
$format->p_separate_by_space = $lc['p_sep_by_space'];
$format->n_separate_by_space = $lc['n_sep_by_space'];
$format->p_sign_position = $lc['p_sign_posn'];
$format->n_sign_position = $lc['n_sign_posn'];
$format->decimal_separator =
$lc['mon_decimal_point'] == ''
? $lc['decimal_point']
: $lc['mon_decimal_point'];
$format->thousands_separator = $lc['mon_thousands_sep'];
$format->symbol = $lc['currency_symbol'];
$format->grouping = $lc['mon_grouping'];
$format->p_sign = $lc['positive_sign'];
$format->n_sign = $lc['negative_sign'];
// special-cases and workarounds
switch ($this->preferred_locale) {
// Hebrew-Israeli
case 'he_IL':
case 'he_IL.utf8':
$format->p_sign_position = 1;
$format->n_sign_position = 1;
$format->p_cs_precedes = false;
$format->n_cs_precedes = false;
break;
}
$this->national_currency_format = $format;
} | php | protected function buildNationalCurrencyFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NCurrencyFormat();
$format->fractional_digits = $lc['frac_digits'];
$format->p_cs_precedes = $lc['p_cs_precedes'];
$format->n_cs_precedes = $lc['n_cs_precedes'];
$format->p_separate_by_space = $lc['p_sep_by_space'];
$format->n_separate_by_space = $lc['n_sep_by_space'];
$format->p_sign_position = $lc['p_sign_posn'];
$format->n_sign_position = $lc['n_sign_posn'];
$format->decimal_separator =
$lc['mon_decimal_point'] == ''
? $lc['decimal_point']
: $lc['mon_decimal_point'];
$format->thousands_separator = $lc['mon_thousands_sep'];
$format->symbol = $lc['currency_symbol'];
$format->grouping = $lc['mon_grouping'];
$format->p_sign = $lc['positive_sign'];
$format->n_sign = $lc['negative_sign'];
// special-cases and workarounds
switch ($this->preferred_locale) {
// Hebrew-Israeli
case 'he_IL':
case 'he_IL.utf8':
$format->p_sign_position = 1;
$format->n_sign_position = 1;
$format->p_cs_precedes = false;
$format->n_cs_precedes = false;
break;
}
$this->national_currency_format = $format;
} | [
"protected",
"function",
"buildNationalCurrencyFormat",
"(",
")",
"{",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"format",
"=",
"new",
"SwatI18NCurrencyFormat",
"(",
")",
";",
"$",
"format",
"->",
"fractional_digits",
"=",
"$",
"lc",
"[",
"'frac_digits'",
"]",
";",
"$",
"format",
"->",
"p_cs_precedes",
"=",
"$",
"lc",
"[",
"'p_cs_precedes'",
"]",
";",
"$",
"format",
"->",
"n_cs_precedes",
"=",
"$",
"lc",
"[",
"'n_cs_precedes'",
"]",
";",
"$",
"format",
"->",
"p_separate_by_space",
"=",
"$",
"lc",
"[",
"'p_sep_by_space'",
"]",
";",
"$",
"format",
"->",
"n_separate_by_space",
"=",
"$",
"lc",
"[",
"'n_sep_by_space'",
"]",
";",
"$",
"format",
"->",
"p_sign_position",
"=",
"$",
"lc",
"[",
"'p_sign_posn'",
"]",
";",
"$",
"format",
"->",
"n_sign_position",
"=",
"$",
"lc",
"[",
"'n_sign_posn'",
"]",
";",
"$",
"format",
"->",
"decimal_separator",
"=",
"$",
"lc",
"[",
"'mon_decimal_point'",
"]",
"==",
"''",
"?",
"$",
"lc",
"[",
"'decimal_point'",
"]",
":",
"$",
"lc",
"[",
"'mon_decimal_point'",
"]",
";",
"$",
"format",
"->",
"thousands_separator",
"=",
"$",
"lc",
"[",
"'mon_thousands_sep'",
"]",
";",
"$",
"format",
"->",
"symbol",
"=",
"$",
"lc",
"[",
"'currency_symbol'",
"]",
";",
"$",
"format",
"->",
"grouping",
"=",
"$",
"lc",
"[",
"'mon_grouping'",
"]",
";",
"$",
"format",
"->",
"p_sign",
"=",
"$",
"lc",
"[",
"'positive_sign'",
"]",
";",
"$",
"format",
"->",
"n_sign",
"=",
"$",
"lc",
"[",
"'negative_sign'",
"]",
";",
"// special-cases and workarounds",
"switch",
"(",
"$",
"this",
"->",
"preferred_locale",
")",
"{",
"// Hebrew-Israeli",
"case",
"'he_IL'",
":",
"case",
"'he_IL.utf8'",
":",
"$",
"format",
"->",
"p_sign_position",
"=",
"1",
";",
"$",
"format",
"->",
"n_sign_position",
"=",
"1",
";",
"$",
"format",
"->",
"p_cs_precedes",
"=",
"false",
";",
"$",
"format",
"->",
"n_cs_precedes",
"=",
"false",
";",
"break",
";",
"}",
"$",
"this",
"->",
"national_currency_format",
"=",
"$",
"format",
";",
"}"
] | Builds the national currency format of this locale | [
"Builds",
"the",
"national",
"currency",
"format",
"of",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L956-L993 |
33,369 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.buildInternationalCurrencyFormat | protected function buildInternationalCurrencyFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NCurrencyFormat();
$format->fractional_digits = $lc['int_frac_digits'];
$format->p_cs_precedes = $lc['p_cs_precedes'];
$format->n_cs_precedes = $lc['n_cs_precedes'];
$format->p_separate_by_space = $lc['p_sep_by_space'];
$format->n_separate_by_space = $lc['n_sep_by_space'];
$format->p_sign_position = $lc['p_sign_posn'];
$format->n_sign_position = $lc['n_sign_posn'];
$format->decimal_separator =
$lc['mon_decimal_point'] == ''
? $lc['decimal_point']
: $lc['mon_decimal_point'];
$format->thousands_separator = $lc['mon_thousands_sep'];
$format->symbol = $lc['int_curr_symbol'];
$format->grouping = $lc['mon_grouping'];
$format->p_sign = $lc['positive_sign'];
$format->n_sign = $lc['negative_sign'];
$this->international_currency_format = $format;
} | php | protected function buildInternationalCurrencyFormat()
{
$lc = $this->getLocaleInfo();
$format = new SwatI18NCurrencyFormat();
$format->fractional_digits = $lc['int_frac_digits'];
$format->p_cs_precedes = $lc['p_cs_precedes'];
$format->n_cs_precedes = $lc['n_cs_precedes'];
$format->p_separate_by_space = $lc['p_sep_by_space'];
$format->n_separate_by_space = $lc['n_sep_by_space'];
$format->p_sign_position = $lc['p_sign_posn'];
$format->n_sign_position = $lc['n_sign_posn'];
$format->decimal_separator =
$lc['mon_decimal_point'] == ''
? $lc['decimal_point']
: $lc['mon_decimal_point'];
$format->thousands_separator = $lc['mon_thousands_sep'];
$format->symbol = $lc['int_curr_symbol'];
$format->grouping = $lc['mon_grouping'];
$format->p_sign = $lc['positive_sign'];
$format->n_sign = $lc['negative_sign'];
$this->international_currency_format = $format;
} | [
"protected",
"function",
"buildInternationalCurrencyFormat",
"(",
")",
"{",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"format",
"=",
"new",
"SwatI18NCurrencyFormat",
"(",
")",
";",
"$",
"format",
"->",
"fractional_digits",
"=",
"$",
"lc",
"[",
"'int_frac_digits'",
"]",
";",
"$",
"format",
"->",
"p_cs_precedes",
"=",
"$",
"lc",
"[",
"'p_cs_precedes'",
"]",
";",
"$",
"format",
"->",
"n_cs_precedes",
"=",
"$",
"lc",
"[",
"'n_cs_precedes'",
"]",
";",
"$",
"format",
"->",
"p_separate_by_space",
"=",
"$",
"lc",
"[",
"'p_sep_by_space'",
"]",
";",
"$",
"format",
"->",
"n_separate_by_space",
"=",
"$",
"lc",
"[",
"'n_sep_by_space'",
"]",
";",
"$",
"format",
"->",
"p_sign_position",
"=",
"$",
"lc",
"[",
"'p_sign_posn'",
"]",
";",
"$",
"format",
"->",
"n_sign_position",
"=",
"$",
"lc",
"[",
"'n_sign_posn'",
"]",
";",
"$",
"format",
"->",
"decimal_separator",
"=",
"$",
"lc",
"[",
"'mon_decimal_point'",
"]",
"==",
"''",
"?",
"$",
"lc",
"[",
"'decimal_point'",
"]",
":",
"$",
"lc",
"[",
"'mon_decimal_point'",
"]",
";",
"$",
"format",
"->",
"thousands_separator",
"=",
"$",
"lc",
"[",
"'mon_thousands_sep'",
"]",
";",
"$",
"format",
"->",
"symbol",
"=",
"$",
"lc",
"[",
"'int_curr_symbol'",
"]",
";",
"$",
"format",
"->",
"grouping",
"=",
"$",
"lc",
"[",
"'mon_grouping'",
"]",
";",
"$",
"format",
"->",
"p_sign",
"=",
"$",
"lc",
"[",
"'positive_sign'",
"]",
";",
"$",
"format",
"->",
"n_sign",
"=",
"$",
"lc",
"[",
"'negative_sign'",
"]",
";",
"$",
"this",
"->",
"international_currency_format",
"=",
"$",
"format",
";",
"}"
] | Builds the internatiobal currency format for this locale | [
"Builds",
"the",
"internatiobal",
"currency",
"format",
"for",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1001-L1026 |
33,370 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.formatIntegerGroupings | protected function formatIntegerGroupings(
$value,
SwatI18NNumberFormat $format
) {
// group integer part with thousands separators
$grouping_values = array();
$groupings = $format->grouping;
$grouping_total = intval(floor(abs($value)));
if (
count($groupings) === 0 ||
$grouping_total === 0 ||
$format->thousands_separator == ''
) {
array_push($grouping_values, $grouping_total);
} else {
$grouping_previous = 0;
while (count($groupings) > 1 && $grouping_total > 0) {
$grouping = array_shift($groupings);
if ($grouping === 0) {
// a grouping of 0 means use previous grouping
$grouping = $grouping_previous;
} elseif ($grouping === CHAR_MAX) {
// a grouping of CHAR_MAX means no more grouping
array_push($grouping_values, $grouping_total);
break;
} else {
$grouping_previous = $grouping;
}
$grouping_value = floor(
fmod($grouping_total, pow(10, $grouping))
);
$grouping_total = floor($grouping_total / pow(10, $grouping));
if ($grouping_total > 0) {
$grouping_value = str_pad(
$grouping_value,
$grouping,
'0',
STR_PAD_LEFT
);
}
array_push($grouping_values, $grouping_value);
}
// last grouping repeats until integer part is finished
$grouping = array_shift($groupings);
// a grouping of CHAR_MAX means no more grouping
if ($grouping === CHAR_MAX) {
array_push($grouping_values, $grouping_total);
} else {
// a grouping of 0 means use previous grouping
if ($grouping === 0) {
$grouping = $grouping_previous;
}
// a grouping of 0 as the last grouping means no more grouping
if ($grouping === 0) {
array_push($grouping_values, $grouping_total);
} else {
while ($grouping_total > 0) {
$grouping_value = floor(
fmod($grouping_total, pow(10, $grouping))
);
$grouping_total = floor(
$grouping_total / pow(10, $grouping)
);
if ($grouping_total > 0) {
$grouping_value = str_pad(
$grouping_value,
$grouping,
'0',
STR_PAD_LEFT
);
}
array_push($grouping_values, $grouping_value);
}
}
}
}
$grouping_values = array_reverse($grouping_values);
// join groupings using thousands separator
$formatted_value = implode(
$format->thousands_separator,
$grouping_values
);
return $formatted_value;
} | php | protected function formatIntegerGroupings(
$value,
SwatI18NNumberFormat $format
) {
// group integer part with thousands separators
$grouping_values = array();
$groupings = $format->grouping;
$grouping_total = intval(floor(abs($value)));
if (
count($groupings) === 0 ||
$grouping_total === 0 ||
$format->thousands_separator == ''
) {
array_push($grouping_values, $grouping_total);
} else {
$grouping_previous = 0;
while (count($groupings) > 1 && $grouping_total > 0) {
$grouping = array_shift($groupings);
if ($grouping === 0) {
// a grouping of 0 means use previous grouping
$grouping = $grouping_previous;
} elseif ($grouping === CHAR_MAX) {
// a grouping of CHAR_MAX means no more grouping
array_push($grouping_values, $grouping_total);
break;
} else {
$grouping_previous = $grouping;
}
$grouping_value = floor(
fmod($grouping_total, pow(10, $grouping))
);
$grouping_total = floor($grouping_total / pow(10, $grouping));
if ($grouping_total > 0) {
$grouping_value = str_pad(
$grouping_value,
$grouping,
'0',
STR_PAD_LEFT
);
}
array_push($grouping_values, $grouping_value);
}
// last grouping repeats until integer part is finished
$grouping = array_shift($groupings);
// a grouping of CHAR_MAX means no more grouping
if ($grouping === CHAR_MAX) {
array_push($grouping_values, $grouping_total);
} else {
// a grouping of 0 means use previous grouping
if ($grouping === 0) {
$grouping = $grouping_previous;
}
// a grouping of 0 as the last grouping means no more grouping
if ($grouping === 0) {
array_push($grouping_values, $grouping_total);
} else {
while ($grouping_total > 0) {
$grouping_value = floor(
fmod($grouping_total, pow(10, $grouping))
);
$grouping_total = floor(
$grouping_total / pow(10, $grouping)
);
if ($grouping_total > 0) {
$grouping_value = str_pad(
$grouping_value,
$grouping,
'0',
STR_PAD_LEFT
);
}
array_push($grouping_values, $grouping_value);
}
}
}
}
$grouping_values = array_reverse($grouping_values);
// join groupings using thousands separator
$formatted_value = implode(
$format->thousands_separator,
$grouping_values
);
return $formatted_value;
} | [
"protected",
"function",
"formatIntegerGroupings",
"(",
"$",
"value",
",",
"SwatI18NNumberFormat",
"$",
"format",
")",
"{",
"// group integer part with thousands separators",
"$",
"grouping_values",
"=",
"array",
"(",
")",
";",
"$",
"groupings",
"=",
"$",
"format",
"->",
"grouping",
";",
"$",
"grouping_total",
"=",
"intval",
"(",
"floor",
"(",
"abs",
"(",
"$",
"value",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"groupings",
")",
"===",
"0",
"||",
"$",
"grouping_total",
"===",
"0",
"||",
"$",
"format",
"->",
"thousands_separator",
"==",
"''",
")",
"{",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_total",
")",
";",
"}",
"else",
"{",
"$",
"grouping_previous",
"=",
"0",
";",
"while",
"(",
"count",
"(",
"$",
"groupings",
")",
">",
"1",
"&&",
"$",
"grouping_total",
">",
"0",
")",
"{",
"$",
"grouping",
"=",
"array_shift",
"(",
"$",
"groupings",
")",
";",
"if",
"(",
"$",
"grouping",
"===",
"0",
")",
"{",
"// a grouping of 0 means use previous grouping",
"$",
"grouping",
"=",
"$",
"grouping_previous",
";",
"}",
"elseif",
"(",
"$",
"grouping",
"===",
"CHAR_MAX",
")",
"{",
"// a grouping of CHAR_MAX means no more grouping",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_total",
")",
";",
"break",
";",
"}",
"else",
"{",
"$",
"grouping_previous",
"=",
"$",
"grouping",
";",
"}",
"$",
"grouping_value",
"=",
"floor",
"(",
"fmod",
"(",
"$",
"grouping_total",
",",
"pow",
"(",
"10",
",",
"$",
"grouping",
")",
")",
")",
";",
"$",
"grouping_total",
"=",
"floor",
"(",
"$",
"grouping_total",
"/",
"pow",
"(",
"10",
",",
"$",
"grouping",
")",
")",
";",
"if",
"(",
"$",
"grouping_total",
">",
"0",
")",
"{",
"$",
"grouping_value",
"=",
"str_pad",
"(",
"$",
"grouping_value",
",",
"$",
"grouping",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_value",
")",
";",
"}",
"// last grouping repeats until integer part is finished",
"$",
"grouping",
"=",
"array_shift",
"(",
"$",
"groupings",
")",
";",
"// a grouping of CHAR_MAX means no more grouping",
"if",
"(",
"$",
"grouping",
"===",
"CHAR_MAX",
")",
"{",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_total",
")",
";",
"}",
"else",
"{",
"// a grouping of 0 means use previous grouping",
"if",
"(",
"$",
"grouping",
"===",
"0",
")",
"{",
"$",
"grouping",
"=",
"$",
"grouping_previous",
";",
"}",
"// a grouping of 0 as the last grouping means no more grouping",
"if",
"(",
"$",
"grouping",
"===",
"0",
")",
"{",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_total",
")",
";",
"}",
"else",
"{",
"while",
"(",
"$",
"grouping_total",
">",
"0",
")",
"{",
"$",
"grouping_value",
"=",
"floor",
"(",
"fmod",
"(",
"$",
"grouping_total",
",",
"pow",
"(",
"10",
",",
"$",
"grouping",
")",
")",
")",
";",
"$",
"grouping_total",
"=",
"floor",
"(",
"$",
"grouping_total",
"/",
"pow",
"(",
"10",
",",
"$",
"grouping",
")",
")",
";",
"if",
"(",
"$",
"grouping_total",
">",
"0",
")",
"{",
"$",
"grouping_value",
"=",
"str_pad",
"(",
"$",
"grouping_value",
",",
"$",
"grouping",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"array_push",
"(",
"$",
"grouping_values",
",",
"$",
"grouping_value",
")",
";",
"}",
"}",
"}",
"}",
"$",
"grouping_values",
"=",
"array_reverse",
"(",
"$",
"grouping_values",
")",
";",
"// join groupings using thousands separator",
"$",
"formatted_value",
"=",
"implode",
"(",
"$",
"format",
"->",
"thousands_separator",
",",
"$",
"grouping_values",
")",
";",
"return",
"$",
"formatted_value",
";",
"}"
] | Formats the integer part of a value according to format-specific numeric
groupings
This is a number formatting helper method. It is responsible for
grouping integer-part digits. Grouped digits are separated using the
thousands separator character specified by the format object.
@param float $value the value to format.
@param SwatI18NNumberFormat the number format to use.
@return string the grouped integer part of the value. | [
"Formats",
"the",
"integer",
"part",
"of",
"a",
"value",
"according",
"to",
"format",
"-",
"specific",
"numeric",
"groupings"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1044-L1140 |
33,371 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.formatFractionalPart | protected function formatFractionalPart(
$value,
$fractional_digits,
SwatI18NNumberFormat $format
) {
if ($fractional_digits === 0) {
$formatted_value = '';
} else {
$frac_part = abs(fmod($value, 1));
$frac_part = round($frac_part * pow(10, $fractional_digits));
$frac_part = str_pad(
$frac_part,
$fractional_digits,
'0',
STR_PAD_LEFT
);
$formatted_value = $format->decimal_separator . $frac_part;
}
return $formatted_value;
} | php | protected function formatFractionalPart(
$value,
$fractional_digits,
SwatI18NNumberFormat $format
) {
if ($fractional_digits === 0) {
$formatted_value = '';
} else {
$frac_part = abs(fmod($value, 1));
$frac_part = round($frac_part * pow(10, $fractional_digits));
$frac_part = str_pad(
$frac_part,
$fractional_digits,
'0',
STR_PAD_LEFT
);
$formatted_value = $format->decimal_separator . $frac_part;
}
return $formatted_value;
} | [
"protected",
"function",
"formatFractionalPart",
"(",
"$",
"value",
",",
"$",
"fractional_digits",
",",
"SwatI18NNumberFormat",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"fractional_digits",
"===",
"0",
")",
"{",
"$",
"formatted_value",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"frac_part",
"=",
"abs",
"(",
"fmod",
"(",
"$",
"value",
",",
"1",
")",
")",
";",
"$",
"frac_part",
"=",
"round",
"(",
"$",
"frac_part",
"*",
"pow",
"(",
"10",
",",
"$",
"fractional_digits",
")",
")",
";",
"$",
"frac_part",
"=",
"str_pad",
"(",
"$",
"frac_part",
",",
"$",
"fractional_digits",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"$",
"formatted_value",
"=",
"$",
"format",
"->",
"decimal_separator",
".",
"$",
"frac_part",
";",
"}",
"return",
"$",
"formatted_value",
";",
"}"
] | Formats the fractional part of a value
@param float $value the value to format.
@param integer $fractional_digits the number of fractional digits to
include in the returned string.
@param SwatI18NNumberFormat $format the number formatting object to use
to format the fractional digits.
@return string the formatted fractional digits. If the number of
displayed fractional digits is greater than zero, the
string is prepended with the decimal separator character
of the format object. | [
"Formats",
"the",
"fractional",
"part",
"of",
"a",
"value"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1159-L1180 |
33,372 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.parseNegativeNotation | protected function parseNegativeNotation(
$string,
$n_sign = null,
$n_sign_position = 1
) {
$lc = $this->getLocaleInfo();
$negative = false;
if ($n_sign == '') {
if ($lc['negative_sign'] == '') {
$negative_sign = '-';
} else {
$negative_sign = $lc['negative_sign'];
}
} else {
$negative_sign = $n_sign;
}
// filter out all chars except for digits and negative formatting chars
$char_class = '0-9' . preg_quote($negative_sign, '/');
if ($n_sign_position === 0) {
$char_class = '()' . $char_class;
}
$exp = '/[^' . $char_class . ']/u';
$filtered = preg_replace($exp, '', $string);
if ($filtered != '') {
if ($filtered[0] === '-' || mb_substr($filtered, -1) === '-') {
// always allow parsing by negative sign
$negative = true;
$string = str_replace($negative_sign, '', $string);
} elseif (
$n_sign_position === 0 &&
$filtered[0] === '(' &&
mb_substr($filtered, -1) === ')'
) {
// parse parenthetical negative shown as: (5.00)
$negative = true;
$string = str_replace(array('(', ')'), '', $string);
}
}
if ($negative) {
$string = '-' . $string;
}
return $string;
} | php | protected function parseNegativeNotation(
$string,
$n_sign = null,
$n_sign_position = 1
) {
$lc = $this->getLocaleInfo();
$negative = false;
if ($n_sign == '') {
if ($lc['negative_sign'] == '') {
$negative_sign = '-';
} else {
$negative_sign = $lc['negative_sign'];
}
} else {
$negative_sign = $n_sign;
}
// filter out all chars except for digits and negative formatting chars
$char_class = '0-9' . preg_quote($negative_sign, '/');
if ($n_sign_position === 0) {
$char_class = '()' . $char_class;
}
$exp = '/[^' . $char_class . ']/u';
$filtered = preg_replace($exp, '', $string);
if ($filtered != '') {
if ($filtered[0] === '-' || mb_substr($filtered, -1) === '-') {
// always allow parsing by negative sign
$negative = true;
$string = str_replace($negative_sign, '', $string);
} elseif (
$n_sign_position === 0 &&
$filtered[0] === '(' &&
mb_substr($filtered, -1) === ')'
) {
// parse parenthetical negative shown as: (5.00)
$negative = true;
$string = str_replace(array('(', ')'), '', $string);
}
}
if ($negative) {
$string = '-' . $string;
}
return $string;
} | [
"protected",
"function",
"parseNegativeNotation",
"(",
"$",
"string",
",",
"$",
"n_sign",
"=",
"null",
",",
"$",
"n_sign_position",
"=",
"1",
")",
"{",
"$",
"lc",
"=",
"$",
"this",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"negative",
"=",
"false",
";",
"if",
"(",
"$",
"n_sign",
"==",
"''",
")",
"{",
"if",
"(",
"$",
"lc",
"[",
"'negative_sign'",
"]",
"==",
"''",
")",
"{",
"$",
"negative_sign",
"=",
"'-'",
";",
"}",
"else",
"{",
"$",
"negative_sign",
"=",
"$",
"lc",
"[",
"'negative_sign'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"negative_sign",
"=",
"$",
"n_sign",
";",
"}",
"// filter out all chars except for digits and negative formatting chars",
"$",
"char_class",
"=",
"'0-9'",
".",
"preg_quote",
"(",
"$",
"negative_sign",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"n_sign_position",
"===",
"0",
")",
"{",
"$",
"char_class",
"=",
"'()'",
".",
"$",
"char_class",
";",
"}",
"$",
"exp",
"=",
"'/[^'",
".",
"$",
"char_class",
".",
"']/u'",
";",
"$",
"filtered",
"=",
"preg_replace",
"(",
"$",
"exp",
",",
"''",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"filtered",
"!=",
"''",
")",
"{",
"if",
"(",
"$",
"filtered",
"[",
"0",
"]",
"===",
"'-'",
"||",
"mb_substr",
"(",
"$",
"filtered",
",",
"-",
"1",
")",
"===",
"'-'",
")",
"{",
"// always allow parsing by negative sign",
"$",
"negative",
"=",
"true",
";",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"negative_sign",
",",
"''",
",",
"$",
"string",
")",
";",
"}",
"elseif",
"(",
"$",
"n_sign_position",
"===",
"0",
"&&",
"$",
"filtered",
"[",
"0",
"]",
"===",
"'('",
"&&",
"mb_substr",
"(",
"$",
"filtered",
",",
"-",
"1",
")",
"===",
"')'",
")",
"{",
"// parse parenthetical negative shown as: (5.00)",
"$",
"negative",
"=",
"true",
";",
"$",
"string",
"=",
"str_replace",
"(",
"array",
"(",
"'('",
",",
"')'",
")",
",",
"''",
",",
"$",
"string",
")",
";",
"}",
"}",
"if",
"(",
"$",
"negative",
")",
"{",
"$",
"string",
"=",
"'-'",
".",
"$",
"string",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Parses the negative notation for a numeric string formatted in this
locale
@param string $string the formatted string.
@param string $n_sign optional. The negative sign to parse. If not
specified, the negative sign for this locale is
used.
@param integer $n_sign_position optional. The position of the negative
sign in the formatted string. If not
specified, the value 1 is assumed. This
may be used to allow parsing
parenthetical formatted negative values
as used by some currencies.
@return string the formatted string with the negative notation parsed
and normalized into a form readable by intval() and
floatval(). | [
"Parses",
"the",
"negative",
"notation",
"for",
"a",
"numeric",
"string",
"formatted",
"in",
"this",
"locale"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1204-L1252 |
33,373 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.getFractionalPrecision | protected function getFractionalPrecision($value)
{
/*
* This is a bit hacky (and probably slow). We get the string
* representation and then count the number of digits after the decimal
* separator. This may or may not be faster than the equivalent
* IEEE-754 decomposition (written in PHP). The string-based code has
* not been profiled against the equivalent IEEE-754 code.
*/
$value = (float) $value;
// get current locale
$locale = self::get();
$precision = 0;
$lc = $locale->getLocaleInfo();
$str_value = (string) $value;
$e_pos = mb_stripos($str_value, 'E-');
if ($e_pos !== false) {
$precision += (int) mb_substr($str_value, $e_pos + 2);
$str_value = mb_substr($str_value, 0, $e_pos);
}
$decimal_pos = mb_strpos($str_value, $lc['decimal_point']);
if ($decimal_pos !== false) {
$precision +=
mb_strlen($str_value) -
$decimal_pos -
mb_strlen($lc['decimal_point']);
}
return $precision;
} | php | protected function getFractionalPrecision($value)
{
/*
* This is a bit hacky (and probably slow). We get the string
* representation and then count the number of digits after the decimal
* separator. This may or may not be faster than the equivalent
* IEEE-754 decomposition (written in PHP). The string-based code has
* not been profiled against the equivalent IEEE-754 code.
*/
$value = (float) $value;
// get current locale
$locale = self::get();
$precision = 0;
$lc = $locale->getLocaleInfo();
$str_value = (string) $value;
$e_pos = mb_stripos($str_value, 'E-');
if ($e_pos !== false) {
$precision += (int) mb_substr($str_value, $e_pos + 2);
$str_value = mb_substr($str_value, 0, $e_pos);
}
$decimal_pos = mb_strpos($str_value, $lc['decimal_point']);
if ($decimal_pos !== false) {
$precision +=
mb_strlen($str_value) -
$decimal_pos -
mb_strlen($lc['decimal_point']);
}
return $precision;
} | [
"protected",
"function",
"getFractionalPrecision",
"(",
"$",
"value",
")",
"{",
"/*\n * This is a bit hacky (and probably slow). We get the string\n * representation and then count the number of digits after the decimal\n * separator. This may or may not be faster than the equivalent\n * IEEE-754 decomposition (written in PHP). The string-based code has\n * not been profiled against the equivalent IEEE-754 code.\n */",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"// get current locale",
"$",
"locale",
"=",
"self",
"::",
"get",
"(",
")",
";",
"$",
"precision",
"=",
"0",
";",
"$",
"lc",
"=",
"$",
"locale",
"->",
"getLocaleInfo",
"(",
")",
";",
"$",
"str_value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"e_pos",
"=",
"mb_stripos",
"(",
"$",
"str_value",
",",
"'E-'",
")",
";",
"if",
"(",
"$",
"e_pos",
"!==",
"false",
")",
"{",
"$",
"precision",
"+=",
"(",
"int",
")",
"mb_substr",
"(",
"$",
"str_value",
",",
"$",
"e_pos",
"+",
"2",
")",
";",
"$",
"str_value",
"=",
"mb_substr",
"(",
"$",
"str_value",
",",
"0",
",",
"$",
"e_pos",
")",
";",
"}",
"$",
"decimal_pos",
"=",
"mb_strpos",
"(",
"$",
"str_value",
",",
"$",
"lc",
"[",
"'decimal_point'",
"]",
")",
";",
"if",
"(",
"$",
"decimal_pos",
"!==",
"false",
")",
"{",
"$",
"precision",
"+=",
"mb_strlen",
"(",
"$",
"str_value",
")",
"-",
"$",
"decimal_pos",
"-",
"mb_strlen",
"(",
"$",
"lc",
"[",
"'decimal_point'",
"]",
")",
";",
"}",
"return",
"$",
"precision",
";",
"}"
] | Gets the fractional precision of a floating point number
This gets the number of digits after the decimal point.
@param float $value the value for which to get the fractional precision.
@return integer the fractional precision of the value. | [
"Gets",
"the",
"fractional",
"precision",
"of",
"a",
"floating",
"point",
"number"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1266-L1300 |
33,374 | silverorange/swat | SwatI18N/SwatI18NLocale.php | SwatI18NLocale.iconvArray | private function iconvArray($from, $to, array $array)
{
if ($from != $to) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = $this->iconvArray($from, $to, $value);
} elseif (is_string($value)) {
$output = iconv($from, $to, $value);
if ($output === false) {
throw new SwatException(
sprintf(
'Could not convert %s output to %s',
$from,
$to
)
);
}
$array[$key] = $output;
}
}
}
return $array;
} | php | private function iconvArray($from, $to, array $array)
{
if ($from != $to) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = $this->iconvArray($from, $to, $value);
} elseif (is_string($value)) {
$output = iconv($from, $to, $value);
if ($output === false) {
throw new SwatException(
sprintf(
'Could not convert %s output to %s',
$from,
$to
)
);
}
$array[$key] = $output;
}
}
}
return $array;
} | [
"private",
"function",
"iconvArray",
"(",
"$",
"from",
",",
"$",
"to",
",",
"array",
"$",
"array",
")",
"{",
"if",
"(",
"$",
"from",
"!=",
"$",
"to",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"iconvArray",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"output",
"=",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"output",
"===",
"false",
")",
"{",
"throw",
"new",
"SwatException",
"(",
"sprintf",
"(",
"'Could not convert %s output to %s'",
",",
"$",
"from",
",",
"$",
"to",
")",
")",
";",
"}",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"output",
";",
"}",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Recursivly converts the character encoding of all strings in an array
@param string $from the character encoding to convert from.
@param string $to the character encoding to convert to.
@param array $array the array to convert.
@return array a new array with all strings converted to the given
character encoding.
@throws SwatException if any component of the array can not be converted
from the <i>$from</i> character encoding to the
<i>$to</i> character encoding. | [
"Recursivly",
"converts",
"the",
"character",
"encoding",
"of",
"all",
"strings",
"in",
"an",
"array"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/SwatI18N/SwatI18NLocale.php#L1406-L1430 |
33,375 | brainworxx/kreXX | src/Controller/ErrorController.php | ErrorController.errorAction | public function errorAction(array $errorData)
{
$this->pool->reset();
// Get the main part.
$main = $this->pool->render->renderFatalMain(
$errorData[static::TRACE_TYPE],
$errorData[static::TRACE_ERROR_STRING],
$errorData[static::TRACE_ERROR_FILE],
$errorData[static::TRACE_ERROR_LINE]
);
// Get the backtrace.
$backtrace = $this->pool
->createClass('Brainworxx\\Krexx\\Analyse\\Routing\\Process\\ProcessBacktrace')
->process($errorData[static::TRACE_BACKTRACE]);
if ($this->pool->emergencyHandler->checkEmergencyBreak() === true) {
return $this;
}
// Detect the encoding on the start-chunk-string of the analysis
// for a complete encoding picture.
$this->pool->chunks->detectEncoding($main . $backtrace);
// Get the header, footer and messages
$footer = $this->outputFooter(array());
$header = $this->pool->render->renderFatalHeader($this->outputCssAndJs());
$messages = $this->pool->messages->outputMessages();
// Add the caller as metadata to the chunks class. It will be saved as
// additional info, in case we are logging to a file.
$this->pool->chunks->addMetadata(
array(
static::TRACE_FILE => $errorData[static::TRACE_ERROR_FILE],
static::TRACE_LINE => $errorData[static::TRACE_ERROR_LINE] + 1,
static::TRACE_VARNAME => ' Fatal Error',
)
);
$this->outputService->addChunkString($header)
->addChunkString($messages)
->addChunkString($main)
->addChunkString($backtrace)
->addChunkString($footer)
->finalize();
return $this;
} | php | public function errorAction(array $errorData)
{
$this->pool->reset();
// Get the main part.
$main = $this->pool->render->renderFatalMain(
$errorData[static::TRACE_TYPE],
$errorData[static::TRACE_ERROR_STRING],
$errorData[static::TRACE_ERROR_FILE],
$errorData[static::TRACE_ERROR_LINE]
);
// Get the backtrace.
$backtrace = $this->pool
->createClass('Brainworxx\\Krexx\\Analyse\\Routing\\Process\\ProcessBacktrace')
->process($errorData[static::TRACE_BACKTRACE]);
if ($this->pool->emergencyHandler->checkEmergencyBreak() === true) {
return $this;
}
// Detect the encoding on the start-chunk-string of the analysis
// for a complete encoding picture.
$this->pool->chunks->detectEncoding($main . $backtrace);
// Get the header, footer and messages
$footer = $this->outputFooter(array());
$header = $this->pool->render->renderFatalHeader($this->outputCssAndJs());
$messages = $this->pool->messages->outputMessages();
// Add the caller as metadata to the chunks class. It will be saved as
// additional info, in case we are logging to a file.
$this->pool->chunks->addMetadata(
array(
static::TRACE_FILE => $errorData[static::TRACE_ERROR_FILE],
static::TRACE_LINE => $errorData[static::TRACE_ERROR_LINE] + 1,
static::TRACE_VARNAME => ' Fatal Error',
)
);
$this->outputService->addChunkString($header)
->addChunkString($messages)
->addChunkString($main)
->addChunkString($backtrace)
->addChunkString($footer)
->finalize();
return $this;
} | [
"public",
"function",
"errorAction",
"(",
"array",
"$",
"errorData",
")",
"{",
"$",
"this",
"->",
"pool",
"->",
"reset",
"(",
")",
";",
"// Get the main part.",
"$",
"main",
"=",
"$",
"this",
"->",
"pool",
"->",
"render",
"->",
"renderFatalMain",
"(",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_TYPE",
"]",
",",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_ERROR_STRING",
"]",
",",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_ERROR_FILE",
"]",
",",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_ERROR_LINE",
"]",
")",
";",
"// Get the backtrace.",
"$",
"backtrace",
"=",
"$",
"this",
"->",
"pool",
"->",
"createClass",
"(",
"'Brainworxx\\\\Krexx\\\\Analyse\\\\Routing\\\\Process\\\\ProcessBacktrace'",
")",
"->",
"process",
"(",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_BACKTRACE",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"pool",
"->",
"emergencyHandler",
"->",
"checkEmergencyBreak",
"(",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
";",
"}",
"// Detect the encoding on the start-chunk-string of the analysis",
"// for a complete encoding picture.",
"$",
"this",
"->",
"pool",
"->",
"chunks",
"->",
"detectEncoding",
"(",
"$",
"main",
".",
"$",
"backtrace",
")",
";",
"// Get the header, footer and messages",
"$",
"footer",
"=",
"$",
"this",
"->",
"outputFooter",
"(",
"array",
"(",
")",
")",
";",
"$",
"header",
"=",
"$",
"this",
"->",
"pool",
"->",
"render",
"->",
"renderFatalHeader",
"(",
"$",
"this",
"->",
"outputCssAndJs",
"(",
")",
")",
";",
"$",
"messages",
"=",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"outputMessages",
"(",
")",
";",
"// Add the caller as metadata to the chunks class. It will be saved as",
"// additional info, in case we are logging to a file.",
"$",
"this",
"->",
"pool",
"->",
"chunks",
"->",
"addMetadata",
"(",
"array",
"(",
"static",
"::",
"TRACE_FILE",
"=>",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_ERROR_FILE",
"]",
",",
"static",
"::",
"TRACE_LINE",
"=>",
"$",
"errorData",
"[",
"static",
"::",
"TRACE_ERROR_LINE",
"]",
"+",
"1",
",",
"static",
"::",
"TRACE_VARNAME",
"=>",
"' Fatal Error'",
",",
")",
")",
";",
"$",
"this",
"->",
"outputService",
"->",
"addChunkString",
"(",
"$",
"header",
")",
"->",
"addChunkString",
"(",
"$",
"messages",
")",
"->",
"addChunkString",
"(",
"$",
"main",
")",
"->",
"addChunkString",
"(",
"$",
"backtrace",
")",
"->",
"addChunkString",
"(",
"$",
"footer",
")",
"->",
"finalize",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders the info to the error, warning or notice.
@param array $errorData
The data from the error. This should be a backtrace
with code samples.
@return $this
Return $this for chaining | [
"Renders",
"the",
"info",
"to",
"the",
"error",
"warning",
"or",
"notice",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/ErrorController.php#L56-L104 |
33,376 | brainworxx/kreXX | src/Controller/ErrorController.php | ErrorController.registerFatalAction | public function registerFatalAction()
{
// As of PHP Version 7.0.2, the register_tick_function() causes PHP to
// crash, with a connection reset! We need to check the version to avoid
// this, and then tell the dev what happened.
// Not to mention that fatals got removed anyway.
if (version_compare(phpversion(), '7.0.0', '>=')) {
// Too high! 420 Method Failure :-(
$this->pool->messages->addMessage($this->pool->messages->getHelp('php7yellow'));
krexx($this->pool->messages->getHelp('php7'));
// Just return, there is nothing more to do here.
return $this;
}
// Do we need another shutdown handler?
if (static::$krexxFatal === null) {
static::$krexxFatal = $this->pool->createClass('Brainworxx\\Krexx\\Errorhandler\\Fatal');
declare(ticks = 1);
register_shutdown_function(
array(
static::$krexxFatal,
'shutdownCallback',
)
);
}
static::$krexxFatal->setIsActive(true);
$this->fatalShouldActive = true;
register_tick_function(array($this::$krexxFatal, 'tickCallback'));
return $this;
} | php | public function registerFatalAction()
{
// As of PHP Version 7.0.2, the register_tick_function() causes PHP to
// crash, with a connection reset! We need to check the version to avoid
// this, and then tell the dev what happened.
// Not to mention that fatals got removed anyway.
if (version_compare(phpversion(), '7.0.0', '>=')) {
// Too high! 420 Method Failure :-(
$this->pool->messages->addMessage($this->pool->messages->getHelp('php7yellow'));
krexx($this->pool->messages->getHelp('php7'));
// Just return, there is nothing more to do here.
return $this;
}
// Do we need another shutdown handler?
if (static::$krexxFatal === null) {
static::$krexxFatal = $this->pool->createClass('Brainworxx\\Krexx\\Errorhandler\\Fatal');
declare(ticks = 1);
register_shutdown_function(
array(
static::$krexxFatal,
'shutdownCallback',
)
);
}
static::$krexxFatal->setIsActive(true);
$this->fatalShouldActive = true;
register_tick_function(array($this::$krexxFatal, 'tickCallback'));
return $this;
} | [
"public",
"function",
"registerFatalAction",
"(",
")",
"{",
"// As of PHP Version 7.0.2, the register_tick_function() causes PHP to",
"// crash, with a connection reset! We need to check the version to avoid",
"// this, and then tell the dev what happened.",
"// Not to mention that fatals got removed anyway.",
"if",
"(",
"version_compare",
"(",
"phpversion",
"(",
")",
",",
"'7.0.0'",
",",
"'>='",
")",
")",
"{",
"// Too high! 420 Method Failure :-(",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"getHelp",
"(",
"'php7yellow'",
")",
")",
";",
"krexx",
"(",
"$",
"this",
"->",
"pool",
"->",
"messages",
"->",
"getHelp",
"(",
"'php7'",
")",
")",
";",
"// Just return, there is nothing more to do here.",
"return",
"$",
"this",
";",
"}",
"// Do we need another shutdown handler?",
"if",
"(",
"static",
"::",
"$",
"krexxFatal",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"krexxFatal",
"=",
"$",
"this",
"->",
"pool",
"->",
"createClass",
"(",
"'Brainworxx\\\\Krexx\\\\Errorhandler\\\\Fatal'",
")",
";",
"declare",
"(",
"ticks",
"=",
"1",
")",
";",
"register_shutdown_function",
"(",
"array",
"(",
"static",
"::",
"$",
"krexxFatal",
",",
"'shutdownCallback'",
",",
")",
")",
";",
"}",
"static",
"::",
"$",
"krexxFatal",
"->",
"setIsActive",
"(",
"true",
")",
";",
"$",
"this",
"->",
"fatalShouldActive",
"=",
"true",
";",
"register_tick_function",
"(",
"array",
"(",
"$",
"this",
"::",
"$",
"krexxFatal",
",",
"'tickCallback'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register the fatal error handler.
@return $this
Return $this for chaining | [
"Register",
"the",
"fatal",
"error",
"handler",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/ErrorController.php#L112-L144 |
33,377 | brainworxx/kreXX | src/Controller/ErrorController.php | ErrorController.unregisterFatalAction | public function unregisterFatalAction()
{
$this->fatalShouldActive = false;
if ($this::$krexxFatal === null) {
// There is no fatal error handler to begin with.
return $this;
}
// Now we need to tell the shutdown function, that is must
// not do anything on shutdown.
$this::$krexxFatal->setIsActive(false);
unregister_tick_function(array($this::$krexxFatal, 'tickCallback'));
return $this;
} | php | public function unregisterFatalAction()
{
$this->fatalShouldActive = false;
if ($this::$krexxFatal === null) {
// There is no fatal error handler to begin with.
return $this;
}
// Now we need to tell the shutdown function, that is must
// not do anything on shutdown.
$this::$krexxFatal->setIsActive(false);
unregister_tick_function(array($this::$krexxFatal, 'tickCallback'));
return $this;
} | [
"public",
"function",
"unregisterFatalAction",
"(",
")",
"{",
"$",
"this",
"->",
"fatalShouldActive",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"::",
"$",
"krexxFatal",
"===",
"null",
")",
"{",
"// There is no fatal error handler to begin with.",
"return",
"$",
"this",
";",
"}",
"// Now we need to tell the shutdown function, that is must",
"// not do anything on shutdown.",
"$",
"this",
"::",
"$",
"krexxFatal",
"->",
"setIsActive",
"(",
"false",
")",
";",
"unregister_tick_function",
"(",
"array",
"(",
"$",
"this",
"::",
"$",
"krexxFatal",
",",
"'tickCallback'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | "Unregister" the fatal error handler.
Actually we can not unregister it. We simply tell it to not activate
and we unregister the tick function which provides us with the
backtrace.
@return $this
Return $this for chaining | [
"Unregister",
"the",
"fatal",
"error",
"handler",
"."
] | a03beaa4507ffb391412b9ac61593d263d3f8bca | https://github.com/brainworxx/kreXX/blob/a03beaa4507ffb391412b9ac61593d263d3f8bca/src/Controller/ErrorController.php#L156-L170 |
33,378 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.init | public function init()
{
parent::init();
$this->createEmbeddedWidgets();
$this->enter_another_link->title = $this->enter_text;
$this->enter_another_link->link = sprintf(
"javascript:%s_obj.addRow();",
$this->getId()
);
$this->enter_another_link->init();
// init input cells
foreach ($this->input_cells as $cell) {
$cell->init();
}
/*
* Initialize replicators
*
* Don't use getHiddenField() here because the serialized field is not
* updated by the controlling JavaScript and will not contain added
* replicator ids.
*/
$data = $this->getForm()->getFormData();
$replicator_field = isset($data[$this->getId() . '_replicators'])
? $data[$this->getId() . '_replicators']
: null;
if ($replicator_field === null || $replicator_field == '') {
// use generated ids
for ($i = 0; $i < $this->number; $i++) {
$this->replicators[] = $i;
}
} else {
// retrieve ids from form
$this->replicators = explode(',', $replicator_field);
}
} | php | public function init()
{
parent::init();
$this->createEmbeddedWidgets();
$this->enter_another_link->title = $this->enter_text;
$this->enter_another_link->link = sprintf(
"javascript:%s_obj.addRow();",
$this->getId()
);
$this->enter_another_link->init();
// init input cells
foreach ($this->input_cells as $cell) {
$cell->init();
}
/*
* Initialize replicators
*
* Don't use getHiddenField() here because the serialized field is not
* updated by the controlling JavaScript and will not contain added
* replicator ids.
*/
$data = $this->getForm()->getFormData();
$replicator_field = isset($data[$this->getId() . '_replicators'])
? $data[$this->getId() . '_replicators']
: null;
if ($replicator_field === null || $replicator_field == '') {
// use generated ids
for ($i = 0; $i < $this->number; $i++) {
$this->replicators[] = $i;
}
} else {
// retrieve ids from form
$this->replicators = explode(',', $replicator_field);
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"$",
"this",
"->",
"createEmbeddedWidgets",
"(",
")",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"title",
"=",
"$",
"this",
"->",
"enter_text",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"link",
"=",
"sprintf",
"(",
"\"javascript:%s_obj.addRow();\"",
",",
"$",
"this",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"init",
"(",
")",
";",
"// init input cells",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"$",
"cell",
"->",
"init",
"(",
")",
";",
"}",
"/*\n * Initialize replicators\n *\n * Don't use getHiddenField() here because the serialized field is not\n * updated by the controlling JavaScript and will not contain added\n * replicator ids.\n */",
"$",
"data",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
"->",
"getFormData",
"(",
")",
";",
"$",
"replicator_field",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_replicators'",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_replicators'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"replicator_field",
"===",
"null",
"||",
"$",
"replicator_field",
"==",
"''",
")",
"{",
"// use generated ids",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"number",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"replicators",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"else",
"{",
"// retrieve ids from form",
"$",
"this",
"->",
"replicators",
"=",
"explode",
"(",
"','",
",",
"$",
"replicator_field",
")",
";",
"}",
"}"
] | Initializes this input row
This initializes each input cell in this row.
@see SwatTableViewRow::init() | [
"Initializes",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L128-L167 |
33,379 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.process | public function process()
{
parent::process();
// process input cells
foreach ($this->replicators as $replicator_id) {
foreach ($this->input_cells as $cell) {
$cell->process($replicator_id);
}
}
} | php | public function process()
{
parent::process();
// process input cells
foreach ($this->replicators as $replicator_id) {
foreach ($this->input_cells as $cell) {
$cell->process($replicator_id);
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"parent",
"::",
"process",
"(",
")",
";",
"// process input cells",
"foreach",
"(",
"$",
"this",
"->",
"replicators",
"as",
"$",
"replicator_id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"$",
"cell",
"->",
"process",
"(",
"$",
"replicator_id",
")",
";",
"}",
"}",
"}"
] | Processes this input row
This gets the replicator ids of rows the user entered as well as
processing all cloned widgets in input cells that the user submitted. | [
"Processes",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L178-L188 |
33,380 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.display | public function display()
{
if (!$this->isVisible()) {
return;
}
parent::display();
if (count($this->replicators) < $this->number) {
$diff = $this->number - count($this->replicators);
$next_replicator =
count($this->replicators) === 0
? 0
: end($this->replicators) + 1;
for ($i = $next_replicator; $i < $diff + $next_replicator; $i++) {
$this->replicators[] = $i;
}
}
// add replicator ids to the form as a hidden field
$this->getForm()->addHiddenField(
$this->getId() . '_replicators',
implode(',', $this->replicators)
);
$this->displayInputRows();
$this->displayEnterAnotherRow();
} | php | public function display()
{
if (!$this->isVisible()) {
return;
}
parent::display();
if (count($this->replicators) < $this->number) {
$diff = $this->number - count($this->replicators);
$next_replicator =
count($this->replicators) === 0
? 0
: end($this->replicators) + 1;
for ($i = $next_replicator; $i < $diff + $next_replicator; $i++) {
$this->replicators[] = $i;
}
}
// add replicator ids to the form as a hidden field
$this->getForm()->addHiddenField(
$this->getId() . '_replicators',
implode(',', $this->replicators)
);
$this->displayInputRows();
$this->displayEnterAnotherRow();
} | [
"public",
"function",
"display",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isVisible",
"(",
")",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"display",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"replicators",
")",
"<",
"$",
"this",
"->",
"number",
")",
"{",
"$",
"diff",
"=",
"$",
"this",
"->",
"number",
"-",
"count",
"(",
"$",
"this",
"->",
"replicators",
")",
";",
"$",
"next_replicator",
"=",
"count",
"(",
"$",
"this",
"->",
"replicators",
")",
"===",
"0",
"?",
"0",
":",
"end",
"(",
"$",
"this",
"->",
"replicators",
")",
"+",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"next_replicator",
";",
"$",
"i",
"<",
"$",
"diff",
"+",
"$",
"next_replicator",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"replicators",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"// add replicator ids to the form as a hidden field",
"$",
"this",
"->",
"getForm",
"(",
")",
"->",
"addHiddenField",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_replicators'",
",",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"replicators",
")",
")",
";",
"$",
"this",
"->",
"displayInputRows",
"(",
")",
";",
"$",
"this",
"->",
"displayEnterAnotherRow",
"(",
")",
";",
"}"
] | Displays this row
Uses widget cloning inside {@link SwatInputCell} to display rows and
also displays the 'enter-another-row' button. The number of rows
displayed is set either through {SwatTableViewInputRow::$number} or
by the number of rows the user submitted. When a user submits a
different number of rows than {SwatTableViewInputRow::$number} it
the user submitted number takes precedence. | [
"Displays",
"this",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L225-L253 |
33,381 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getWidget | public function getWidget($column_id, $row_identifier, $widget_id = null)
{
if (isset($this->input_cells[$column_id])) {
return $this->input_cells[$column_id]->getWidget(
$row_identifier,
$widget_id
);
}
throw new SwatException(
'No input cell for this row exists for the ' .
'given column identifier.'
);
} | php | public function getWidget($column_id, $row_identifier, $widget_id = null)
{
if (isset($this->input_cells[$column_id])) {
return $this->input_cells[$column_id]->getWidget(
$row_identifier,
$widget_id
);
}
throw new SwatException(
'No input cell for this row exists for the ' .
'given column identifier.'
);
} | [
"public",
"function",
"getWidget",
"(",
"$",
"column_id",
",",
"$",
"row_identifier",
",",
"$",
"widget_id",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column_id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column_id",
"]",
"->",
"getWidget",
"(",
"$",
"row_identifier",
",",
"$",
"widget_id",
")",
";",
"}",
"throw",
"new",
"SwatException",
"(",
"'No input cell for this row exists for the '",
".",
"'given column identifier.'",
")",
";",
"}"
] | Gets a particular widget in this row
This method is used to get or set properties of specific cloned widgets
within this input row. The most common case is when you want to
iterate through the user submitted data in this input row.
@param string $column_id the unique identifier of the table-view column
the widget resides in.
@param integer $row_identifier the numeric row identifier of the widget.
@param string $widget_id the unique identifier of the widget. If no id
is specified, the root widget of the column's
cell is returned for the given row.
@return SwatWidget
@see SwatInputCell::getWidget()
@throws SwatException | [
"Gets",
"a",
"particular",
"widget",
"in",
"this",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L314-L327 |
33,382 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getPrototypeWidget | public function getPrototypeWidget($column_id)
{
if (isset($this->input_cells[$column_id])) {
return $this->input_cells[$column_id]->getPrototypeWidget();
}
throw new SwatException(
'The specified column does not have an input ' .
'cell bound to this row or the column does not exist.'
);
} | php | public function getPrototypeWidget($column_id)
{
if (isset($this->input_cells[$column_id])) {
return $this->input_cells[$column_id]->getPrototypeWidget();
}
throw new SwatException(
'The specified column does not have an input ' .
'cell bound to this row or the column does not exist.'
);
} | [
"public",
"function",
"getPrototypeWidget",
"(",
"$",
"column_id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column_id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column_id",
"]",
"->",
"getPrototypeWidget",
"(",
")",
";",
"}",
"throw",
"new",
"SwatException",
"(",
"'The specified column does not have an input '",
".",
"'cell bound to this row or the column does not exist.'",
")",
";",
"}"
] | Gets the prototype widget for a column attached to this row
Note: The UI tree must be inited before this method works correctly.
This is because the column identifiers are not finalized until
init() has run and this method uses colum identifiers for lookup.
This method is useful for setting properties on the prototype widget;
however, the {@link SwatTableViewColumn::getInputCell()} method is even
more useful because it may be safely used before init() is called on the
UI tree. You can then call {@link SwatInputCell::getPrototypeWidget()}
on the returned input cell.
@param string $column_id the unique identifier of the column to get the
prototype widget from.
@return SwatWidget the prototype widget from the given column.
@see SwatTableViewColumn::getInputCell()
@throws SwatException | [
"Gets",
"the",
"prototype",
"widget",
"for",
"a",
"column",
"attached",
"to",
"this",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L353-L363 |
33,383 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.removeReplicatedRow | public function removeReplicatedRow($replicator_id)
{
$this->replicators = array_diff($this->replicators, array(
$replicator_id
));
foreach ($this->input_cells as $cell) {
$cell->unsetWidget($replicator_id);
}
} | php | public function removeReplicatedRow($replicator_id)
{
$this->replicators = array_diff($this->replicators, array(
$replicator_id
));
foreach ($this->input_cells as $cell) {
$cell->unsetWidget($replicator_id);
}
} | [
"public",
"function",
"removeReplicatedRow",
"(",
"$",
"replicator_id",
")",
"{",
"$",
"this",
"->",
"replicators",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"replicators",
",",
"array",
"(",
"$",
"replicator_id",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"$",
"cell",
"->",
"unsetWidget",
"(",
"$",
"replicator_id",
")",
";",
"}",
"}"
] | Removes a row from this input row by its replicator id
This also unsets any cloned widgets from this row's input cells.
@param integer $replicator_id the replicator id of the row to remove. | [
"Removes",
"a",
"row",
"from",
"this",
"input",
"row",
"by",
"its",
"replicator",
"id"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L375-L384 |
33,384 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.rowHasMessage | public function rowHasMessage($replicator_id)
{
$row_has_message = false;
foreach ($this->input_cells as $cell) {
if ($cell->getWidget($replicator_id)->hasMessage()) {
$row_has_message = true;
break;
}
}
return $row_has_message;
} | php | public function rowHasMessage($replicator_id)
{
$row_has_message = false;
foreach ($this->input_cells as $cell) {
if ($cell->getWidget($replicator_id)->hasMessage()) {
$row_has_message = true;
break;
}
}
return $row_has_message;
} | [
"public",
"function",
"rowHasMessage",
"(",
"$",
"replicator_id",
")",
"{",
"$",
"row_has_message",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"if",
"(",
"$",
"cell",
"->",
"getWidget",
"(",
"$",
"replicator_id",
")",
"->",
"hasMessage",
"(",
")",
")",
"{",
"$",
"row_has_message",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"row_has_message",
";",
"}"
] | Gets whether or not a given replicated row has messages
@param integer $replicator_id the replicator id of the row to check for
messages.
@return boolean true if the replicated row has one or more messages and
false if it does not. | [
"Gets",
"whether",
"or",
"not",
"a",
"given",
"replicated",
"row",
"has",
"messages"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L418-L430 |
33,385 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getMessages | public function getMessages()
{
$messages = array();
foreach ($this->replicators as $replicator_id) {
foreach ($this->input_cells as $cell) {
$messages = array_merge(
$messages,
$cell->getWidget($replicator_id)->getMessages()
);
}
}
return $messages;
} | php | public function getMessages()
{
$messages = array();
foreach ($this->replicators as $replicator_id) {
foreach ($this->input_cells as $cell) {
$messages = array_merge(
$messages,
$cell->getWidget($replicator_id)->getMessages()
);
}
}
return $messages;
} | [
"public",
"function",
"getMessages",
"(",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"replicators",
"as",
"$",
"replicator_id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"$",
"messages",
"=",
"array_merge",
"(",
"$",
"messages",
",",
"$",
"cell",
"->",
"getWidget",
"(",
"$",
"replicator_id",
")",
"->",
"getMessages",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"messages",
";",
"}"
] | Gathers all messages from this table-view row
@return array an array of {@link SwatMessage} objects. | [
"Gathers",
"all",
"messages",
"from",
"this",
"table",
"-",
"view",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L440-L454 |
33,386 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getInlineJavaScript | public function getInlineJavaScript()
{
/*
* Encode row string
*
* Mimize entities so that we do not have to specify a DTD when parsing
* the final XML string. If we specify a DTD, Internet Explorer takes a
* long time to strictly parse everything. If we do not specify a DTD
* and try to parse the final XML string with XHTML entities in it we
* get an undefined entity error.
*/
$row_string = $this->getRowString();
// these entities need to be double escaped
$row_string = str_replace('&', '&amp;', $row_string);
$row_string = str_replace('"', '&quot;', $row_string);
$row_string = str_replace('<', '&lt;', $row_string);
$row_string = SwatString::minimizeEntities($row_string);
$row_string = str_replace("'", "\'", $row_string);
// encode newlines for JavaScript string
$row_string = str_replace("\n", '\n', $row_string);
return sprintf(
"var %s_obj = new SwatTableViewInputRow('%s', '%s');",
$this->getId(),
$this->getId(),
trim($row_string)
);
} | php | public function getInlineJavaScript()
{
/*
* Encode row string
*
* Mimize entities so that we do not have to specify a DTD when parsing
* the final XML string. If we specify a DTD, Internet Explorer takes a
* long time to strictly parse everything. If we do not specify a DTD
* and try to parse the final XML string with XHTML entities in it we
* get an undefined entity error.
*/
$row_string = $this->getRowString();
// these entities need to be double escaped
$row_string = str_replace('&', '&amp;', $row_string);
$row_string = str_replace('"', '&quot;', $row_string);
$row_string = str_replace('<', '&lt;', $row_string);
$row_string = SwatString::minimizeEntities($row_string);
$row_string = str_replace("'", "\'", $row_string);
// encode newlines for JavaScript string
$row_string = str_replace("\n", '\n', $row_string);
return sprintf(
"var %s_obj = new SwatTableViewInputRow('%s', '%s');",
$this->getId(),
$this->getId(),
trim($row_string)
);
} | [
"public",
"function",
"getInlineJavaScript",
"(",
")",
"{",
"/*\n * Encode row string\n *\n * Mimize entities so that we do not have to specify a DTD when parsing\n * the final XML string. If we specify a DTD, Internet Explorer takes a\n * long time to strictly parse everything. If we do not specify a DTD\n * and try to parse the final XML string with XHTML entities in it we\n * get an undefined entity error.\n */",
"$",
"row_string",
"=",
"$",
"this",
"->",
"getRowString",
"(",
")",
";",
"// these entities need to be double escaped",
"$",
"row_string",
"=",
"str_replace",
"(",
"'&'",
",",
"'&amp;'",
",",
"$",
"row_string",
")",
";",
"$",
"row_string",
"=",
"str_replace",
"(",
"'"'",
",",
"'&quot;'",
",",
"$",
"row_string",
")",
";",
"$",
"row_string",
"=",
"str_replace",
"(",
"'<'",
",",
"'&lt;'",
",",
"$",
"row_string",
")",
";",
"$",
"row_string",
"=",
"SwatString",
"::",
"minimizeEntities",
"(",
"$",
"row_string",
")",
";",
"$",
"row_string",
"=",
"str_replace",
"(",
"\"'\"",
",",
"\"\\'\"",
",",
"$",
"row_string",
")",
";",
"// encode newlines for JavaScript string",
"$",
"row_string",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"'\\n'",
",",
"$",
"row_string",
")",
";",
"return",
"sprintf",
"(",
"\"var %s_obj = new SwatTableViewInputRow('%s', '%s');\"",
",",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"trim",
"(",
"$",
"row_string",
")",
")",
";",
"}"
] | Creates a JavaScript object to control the client behaviour of this
input row
@return string the inline JavaScript required by this row. | [
"Creates",
"a",
"JavaScript",
"object",
"to",
"control",
"the",
"client",
"behaviour",
"of",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L490-L518 |
33,387 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getHtmlHeadEntrySet | public function getHtmlHeadEntrySet()
{
$set = parent::getHtmlHeadEntrySet();
$this->createEmbeddedWidgets();
$set->addEntrySet($this->enter_another_link->getHtmlHeadEntrySet());
return $set;
} | php | public function getHtmlHeadEntrySet()
{
$set = parent::getHtmlHeadEntrySet();
$this->createEmbeddedWidgets();
$set->addEntrySet($this->enter_another_link->getHtmlHeadEntrySet());
return $set;
} | [
"public",
"function",
"getHtmlHeadEntrySet",
"(",
")",
"{",
"$",
"set",
"=",
"parent",
"::",
"getHtmlHeadEntrySet",
"(",
")",
";",
"$",
"this",
"->",
"createEmbeddedWidgets",
"(",
")",
";",
"$",
"set",
"->",
"addEntrySet",
"(",
"$",
"this",
"->",
"enter_another_link",
"->",
"getHtmlHeadEntrySet",
"(",
")",
")",
";",
"return",
"$",
"set",
";",
"}"
] | Gets the SwatHtmlHeadEntry objects needed by this input row
@return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects needed by
this input row.
@see SwatUIObject::getHtmlHeadEntrySet() | [
"Gets",
"the",
"SwatHtmlHeadEntry",
"objects",
"needed",
"by",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L531-L539 |
33,388 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getAvailableHtmlHeadEntrySet | public function getAvailableHtmlHeadEntrySet()
{
$set = parent::getAvailableHtmlHeadEntrySet();
$this->createEmbeddedWidgets();
$set->addEntrySet(
$this->enter_another_link->getAvailableHtmlHeadEntrySet()
);
return $set;
} | php | public function getAvailableHtmlHeadEntrySet()
{
$set = parent::getAvailableHtmlHeadEntrySet();
$this->createEmbeddedWidgets();
$set->addEntrySet(
$this->enter_another_link->getAvailableHtmlHeadEntrySet()
);
return $set;
} | [
"public",
"function",
"getAvailableHtmlHeadEntrySet",
"(",
")",
"{",
"$",
"set",
"=",
"parent",
"::",
"getAvailableHtmlHeadEntrySet",
"(",
")",
";",
"$",
"this",
"->",
"createEmbeddedWidgets",
"(",
")",
";",
"$",
"set",
"->",
"addEntrySet",
"(",
"$",
"this",
"->",
"enter_another_link",
"->",
"getAvailableHtmlHeadEntrySet",
"(",
")",
")",
";",
"return",
"$",
"set",
";",
"}"
] | Gets the SwatHtmlHeadEntry objects that may be needed by this input row
@return SwatHtmlHeadEntrySet the SwatHtmlHeadEntry objects that may be
needed by this input row.
@see SwatUIObject::getAvailableHtmlHeadEntrySet() | [
"Gets",
"the",
"SwatHtmlHeadEntry",
"objects",
"that",
"may",
"be",
"needed",
"by",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L552-L562 |
33,389 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.displayInputRows | private function displayInputRows()
{
$columns = $this->parent->getVisibleColumns();
foreach ($this->replicators as $replicator_id) {
$messages = array();
$row_has_messages = false;
foreach ($this->input_cells as $cell) {
if ($cell->getWidget($replicator_id)->hasMessage()) {
$row_has_messages = true;
break;
}
}
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->class = 'swat-table-view-input-row';
$tr_tag->id = $this->getId() . '_row_' . $replicator_id;
if ($row_has_messages && $this->show_row_messages) {
$tr_tag->class .= ' swat-error';
}
$tr_tag->open();
foreach ($columns as $column) {
// use the same style as table-view column
$td_attributes = $column->getTdAttributes();
$td_tag = new SwatHtmlTag('td', $td_attributes);
if (isset($this->input_cells[$column->id])) {
$widget = $this->input_cells[$column->id]->getWidget(
$replicator_id
);
if (
$this->show_row_messages &&
count($widget->getMessages()) > 0
) {
$messages = array_merge(
$messages,
$widget->getMessages()
);
$td_tag->class .= ' swat-error';
}
}
$td_tag->open();
if (isset($this->input_cells[$column->id])) {
$this->input_cells[$column->id]->display($replicator_id);
} else {
echo ' ';
}
$td_tag->close();
}
$tr_tag->close();
if ($this->show_row_messages && count($messages) > 0) {
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->class = 'swat-table-view-input-row-messages';
$tr_tag->open();
$td_tag = new SwatHtmlTag('td');
$td_tag->colspan = count($columns);
$td_tag->open();
$ul_tag = new SwatHtmlTag('ul');
$ul_tag->class = 'swat-table-view-input-row-messages';
$ul_tag->open();
$li_tag = new SwatHtmlTag('li');
foreach ($messages as &$message) {
$li_tag->setContent(
$message->primary_content,
$message->content_type
);
$li_tag->class = $message->getCSSClassString();
$li_tag->display();
}
$ul_tag->close();
$td_tag->close();
$tr_tag->close();
}
}
} | php | private function displayInputRows()
{
$columns = $this->parent->getVisibleColumns();
foreach ($this->replicators as $replicator_id) {
$messages = array();
$row_has_messages = false;
foreach ($this->input_cells as $cell) {
if ($cell->getWidget($replicator_id)->hasMessage()) {
$row_has_messages = true;
break;
}
}
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->class = 'swat-table-view-input-row';
$tr_tag->id = $this->getId() . '_row_' . $replicator_id;
if ($row_has_messages && $this->show_row_messages) {
$tr_tag->class .= ' swat-error';
}
$tr_tag->open();
foreach ($columns as $column) {
// use the same style as table-view column
$td_attributes = $column->getTdAttributes();
$td_tag = new SwatHtmlTag('td', $td_attributes);
if (isset($this->input_cells[$column->id])) {
$widget = $this->input_cells[$column->id]->getWidget(
$replicator_id
);
if (
$this->show_row_messages &&
count($widget->getMessages()) > 0
) {
$messages = array_merge(
$messages,
$widget->getMessages()
);
$td_tag->class .= ' swat-error';
}
}
$td_tag->open();
if (isset($this->input_cells[$column->id])) {
$this->input_cells[$column->id]->display($replicator_id);
} else {
echo ' ';
}
$td_tag->close();
}
$tr_tag->close();
if ($this->show_row_messages && count($messages) > 0) {
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->class = 'swat-table-view-input-row-messages';
$tr_tag->open();
$td_tag = new SwatHtmlTag('td');
$td_tag->colspan = count($columns);
$td_tag->open();
$ul_tag = new SwatHtmlTag('ul');
$ul_tag->class = 'swat-table-view-input-row-messages';
$ul_tag->open();
$li_tag = new SwatHtmlTag('li');
foreach ($messages as &$message) {
$li_tag->setContent(
$message->primary_content,
$message->content_type
);
$li_tag->class = $message->getCSSClassString();
$li_tag->display();
}
$ul_tag->close();
$td_tag->close();
$tr_tag->close();
}
}
} | [
"private",
"function",
"displayInputRows",
"(",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"parent",
"->",
"getVisibleColumns",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"replicators",
"as",
"$",
"replicator_id",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"$",
"row_has_messages",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"input_cells",
"as",
"$",
"cell",
")",
"{",
"if",
"(",
"$",
"cell",
"->",
"getWidget",
"(",
"$",
"replicator_id",
")",
"->",
"hasMessage",
"(",
")",
")",
"{",
"$",
"row_has_messages",
"=",
"true",
";",
"break",
";",
"}",
"}",
"$",
"tr_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'tr'",
")",
";",
"$",
"tr_tag",
"->",
"class",
"=",
"'swat-table-view-input-row'",
";",
"$",
"tr_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_row_'",
".",
"$",
"replicator_id",
";",
"if",
"(",
"$",
"row_has_messages",
"&&",
"$",
"this",
"->",
"show_row_messages",
")",
"{",
"$",
"tr_tag",
"->",
"class",
".=",
"' swat-error'",
";",
"}",
"$",
"tr_tag",
"->",
"open",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"// use the same style as table-view column",
"$",
"td_attributes",
"=",
"$",
"column",
"->",
"getTdAttributes",
"(",
")",
";",
"$",
"td_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
",",
"$",
"td_attributes",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
")",
")",
"{",
"$",
"widget",
"=",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
"->",
"getWidget",
"(",
"$",
"replicator_id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"show_row_messages",
"&&",
"count",
"(",
"$",
"widget",
"->",
"getMessages",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"messages",
"=",
"array_merge",
"(",
"$",
"messages",
",",
"$",
"widget",
"->",
"getMessages",
"(",
")",
")",
";",
"$",
"td_tag",
"->",
"class",
".=",
"' swat-error'",
";",
"}",
"}",
"$",
"td_tag",
"->",
"open",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
"->",
"display",
"(",
"$",
"replicator_id",
")",
";",
"}",
"else",
"{",
"echo",
"' '",
";",
"}",
"$",
"td_tag",
"->",
"close",
"(",
")",
";",
"}",
"$",
"tr_tag",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"show_row_messages",
"&&",
"count",
"(",
"$",
"messages",
")",
">",
"0",
")",
"{",
"$",
"tr_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'tr'",
")",
";",
"$",
"tr_tag",
"->",
"class",
"=",
"'swat-table-view-input-row-messages'",
";",
"$",
"tr_tag",
"->",
"open",
"(",
")",
";",
"$",
"td_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
")",
";",
"$",
"td_tag",
"->",
"colspan",
"=",
"count",
"(",
"$",
"columns",
")",
";",
"$",
"td_tag",
"->",
"open",
"(",
")",
";",
"$",
"ul_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'ul'",
")",
";",
"$",
"ul_tag",
"->",
"class",
"=",
"'swat-table-view-input-row-messages'",
";",
"$",
"ul_tag",
"->",
"open",
"(",
")",
";",
"$",
"li_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'li'",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"&",
"$",
"message",
")",
"{",
"$",
"li_tag",
"->",
"setContent",
"(",
"$",
"message",
"->",
"primary_content",
",",
"$",
"message",
"->",
"content_type",
")",
";",
"$",
"li_tag",
"->",
"class",
"=",
"$",
"message",
"->",
"getCSSClassString",
"(",
")",
";",
"$",
"li_tag",
"->",
"display",
"(",
")",
";",
"}",
"$",
"ul_tag",
"->",
"close",
"(",
")",
";",
"$",
"td_tag",
"->",
"close",
"(",
")",
";",
"$",
"tr_tag",
"->",
"close",
"(",
")",
";",
"}",
"}",
"}"
] | Displays the actual XHTML input rows for this input row
Displays a row for each replicator id in this input row. Each row is
displayed using cloned widgets inside {@link SwatInputCell} objects.
@see SwatTableViewInputRow::display() | [
"Displays",
"the",
"actual",
"XHTML",
"input",
"rows",
"for",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L589-L679 |
33,390 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.createEmbeddedWidgets | private function createEmbeddedWidgets()
{
if (!$this->widgets_created) {
$this->enter_another_link = new SwatToolLink();
$this->enter_another_link->parent = $this;
$this->enter_another_link->stock_id = 'add';
$this->enter_another_link->classes[] =
'swat-table-view-input-row-add';
$this->widgets_created = true;
}
} | php | private function createEmbeddedWidgets()
{
if (!$this->widgets_created) {
$this->enter_another_link = new SwatToolLink();
$this->enter_another_link->parent = $this;
$this->enter_another_link->stock_id = 'add';
$this->enter_another_link->classes[] =
'swat-table-view-input-row-add';
$this->widgets_created = true;
}
} | [
"private",
"function",
"createEmbeddedWidgets",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"widgets_created",
")",
"{",
"$",
"this",
"->",
"enter_another_link",
"=",
"new",
"SwatToolLink",
"(",
")",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"parent",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"stock_id",
"=",
"'add'",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"classes",
"[",
"]",
"=",
"'swat-table-view-input-row-add'",
";",
"$",
"this",
"->",
"widgets_created",
"=",
"true",
";",
"}",
"}"
] | Instantiates the tool-link for this input row | [
"Instantiates",
"the",
"tool",
"-",
"link",
"for",
"this",
"input",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L687-L698 |
33,391 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.displayEnterAnotherRow | private function displayEnterAnotherRow()
{
$columns = $this->parent->getVisibleColumns();
$this->createEmbeddedWidgets();
/*
* Get column position of enter-a-new-row text. The text is displayed
* underneath the first input cell that is not blank. If all cells are
* blank, text is displayed underneath the first cell.
*/
$position = 0;
$colspan = 0;
foreach ($columns as $column) {
if (
array_key_exists($column->id, $this->input_cells) &&
!(
$this->input_cells[$column->id] instanceof
SwatRemoveInputCell
)
) {
$position = $colspan;
break;
}
$colspan += $column->getXhtmlColspan();
}
$close_length = $this->parent->getXhtmlColspan() - $position - 1;
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->id = $this->getId() . '_enter_row';
$tr_tag->class = 'swat-table-view-input-row-add-row';
$tr_tag->open();
if ($position > 0) {
$td = new SwatHtmlTag('td');
$td->colspan = $position;
$td->open();
echo ' ';
$td->close();
}
// use the same style as table-view column
$td = new SwatHtmlTag('td', $column->getTdAttributes());
$td->open();
$this->enter_another_link->display();
$td->close();
if ($close_length > 0) {
$td = new SwatHtmlTag('td');
$td->colspan = $close_length;
$td->open();
echo ' ';
$td->close();
}
$tr_tag->close();
} | php | private function displayEnterAnotherRow()
{
$columns = $this->parent->getVisibleColumns();
$this->createEmbeddedWidgets();
/*
* Get column position of enter-a-new-row text. The text is displayed
* underneath the first input cell that is not blank. If all cells are
* blank, text is displayed underneath the first cell.
*/
$position = 0;
$colspan = 0;
foreach ($columns as $column) {
if (
array_key_exists($column->id, $this->input_cells) &&
!(
$this->input_cells[$column->id] instanceof
SwatRemoveInputCell
)
) {
$position = $colspan;
break;
}
$colspan += $column->getXhtmlColspan();
}
$close_length = $this->parent->getXhtmlColspan() - $position - 1;
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->id = $this->getId() . '_enter_row';
$tr_tag->class = 'swat-table-view-input-row-add-row';
$tr_tag->open();
if ($position > 0) {
$td = new SwatHtmlTag('td');
$td->colspan = $position;
$td->open();
echo ' ';
$td->close();
}
// use the same style as table-view column
$td = new SwatHtmlTag('td', $column->getTdAttributes());
$td->open();
$this->enter_another_link->display();
$td->close();
if ($close_length > 0) {
$td = new SwatHtmlTag('td');
$td->colspan = $close_length;
$td->open();
echo ' ';
$td->close();
}
$tr_tag->close();
} | [
"private",
"function",
"displayEnterAnotherRow",
"(",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"parent",
"->",
"getVisibleColumns",
"(",
")",
";",
"$",
"this",
"->",
"createEmbeddedWidgets",
"(",
")",
";",
"/*\n * Get column position of enter-a-new-row text. The text is displayed\n * underneath the first input cell that is not blank. If all cells are\n * blank, text is displayed underneath the first cell.\n */",
"$",
"position",
"=",
"0",
";",
"$",
"colspan",
"=",
"0",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"column",
"->",
"id",
",",
"$",
"this",
"->",
"input_cells",
")",
"&&",
"!",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
"instanceof",
"SwatRemoveInputCell",
")",
")",
"{",
"$",
"position",
"=",
"$",
"colspan",
";",
"break",
";",
"}",
"$",
"colspan",
"+=",
"$",
"column",
"->",
"getXhtmlColspan",
"(",
")",
";",
"}",
"$",
"close_length",
"=",
"$",
"this",
"->",
"parent",
"->",
"getXhtmlColspan",
"(",
")",
"-",
"$",
"position",
"-",
"1",
";",
"$",
"tr_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'tr'",
")",
";",
"$",
"tr_tag",
"->",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_enter_row'",
";",
"$",
"tr_tag",
"->",
"class",
"=",
"'swat-table-view-input-row-add-row'",
";",
"$",
"tr_tag",
"->",
"open",
"(",
")",
";",
"if",
"(",
"$",
"position",
">",
"0",
")",
"{",
"$",
"td",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
")",
";",
"$",
"td",
"->",
"colspan",
"=",
"$",
"position",
";",
"$",
"td",
"->",
"open",
"(",
")",
";",
"echo",
"' '",
";",
"$",
"td",
"->",
"close",
"(",
")",
";",
"}",
"// use the same style as table-view column",
"$",
"td",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
",",
"$",
"column",
"->",
"getTdAttributes",
"(",
")",
")",
";",
"$",
"td",
"->",
"open",
"(",
")",
";",
"$",
"this",
"->",
"enter_another_link",
"->",
"display",
"(",
")",
";",
"$",
"td",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"close_length",
">",
"0",
")",
"{",
"$",
"td",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
")",
";",
"$",
"td",
"->",
"colspan",
"=",
"$",
"close_length",
";",
"$",
"td",
"->",
"open",
"(",
")",
";",
"echo",
"' '",
";",
"$",
"td",
"->",
"close",
"(",
")",
";",
"}",
"$",
"tr_tag",
"->",
"close",
"(",
")",
";",
"}"
] | Displays the enter-another-row row | [
"Displays",
"the",
"enter",
"-",
"another",
"-",
"row",
"row"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L706-L763 |
33,392 | silverorange/swat | Swat/SwatTableViewInputRow.php | SwatTableViewInputRow.getRowString | private function getRowString()
{
$columns = $this->parent->getVisibleColumns();
ob_start();
// properties of the dynamic tr's are set in javascript
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->open();
foreach ($columns as $column) {
$td_attributes = $column->getTdAttributes();
$td_tag = new SwatHtmlTag('td', $td_attributes);
$td_tag->open();
$suffix = '_' . $this->getId() . '_%s';
if (isset($this->input_cells[$column->id])) {
$widget = $this->input_cells[$column->id]->getPrototypeWidget();
$widget = $widget->copy($suffix);
$widget->parent = $this->getForm(); // so display will work.
$widget->display();
unset($widget);
} else {
echo ' ';
}
$td_tag->close();
}
$tr_tag->close();
return ob_get_clean();
} | php | private function getRowString()
{
$columns = $this->parent->getVisibleColumns();
ob_start();
// properties of the dynamic tr's are set in javascript
$tr_tag = new SwatHtmlTag('tr');
$tr_tag->open();
foreach ($columns as $column) {
$td_attributes = $column->getTdAttributes();
$td_tag = new SwatHtmlTag('td', $td_attributes);
$td_tag->open();
$suffix = '_' . $this->getId() . '_%s';
if (isset($this->input_cells[$column->id])) {
$widget = $this->input_cells[$column->id]->getPrototypeWidget();
$widget = $widget->copy($suffix);
$widget->parent = $this->getForm(); // so display will work.
$widget->display();
unset($widget);
} else {
echo ' ';
}
$td_tag->close();
}
$tr_tag->close();
return ob_get_clean();
} | [
"private",
"function",
"getRowString",
"(",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"parent",
"->",
"getVisibleColumns",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"// properties of the dynamic tr's are set in javascript",
"$",
"tr_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'tr'",
")",
";",
"$",
"tr_tag",
"->",
"open",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"td_attributes",
"=",
"$",
"column",
"->",
"getTdAttributes",
"(",
")",
";",
"$",
"td_tag",
"=",
"new",
"SwatHtmlTag",
"(",
"'td'",
",",
"$",
"td_attributes",
")",
";",
"$",
"td_tag",
"->",
"open",
"(",
")",
";",
"$",
"suffix",
"=",
"'_'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"'_%s'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
")",
")",
"{",
"$",
"widget",
"=",
"$",
"this",
"->",
"input_cells",
"[",
"$",
"column",
"->",
"id",
"]",
"->",
"getPrototypeWidget",
"(",
")",
";",
"$",
"widget",
"=",
"$",
"widget",
"->",
"copy",
"(",
"$",
"suffix",
")",
";",
"$",
"widget",
"->",
"parent",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
";",
"// so display will work.",
"$",
"widget",
"->",
"display",
"(",
")",
";",
"unset",
"(",
"$",
"widget",
")",
";",
"}",
"else",
"{",
"echo",
"' '",
";",
"}",
"$",
"td_tag",
"->",
"close",
"(",
")",
";",
"}",
"$",
"tr_tag",
"->",
"close",
"(",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] | Gets this input row as an XHTML table row with the row identifier as a
placeholder '%s'
Returning the row identifier as a placeholder means we can use this
function to display multiple copies of this row just by substituting
a new identifier.
@return string this input row as an XHTML table row with the row
identifier as a placeholder '%s'. | [
"Gets",
"this",
"input",
"row",
"as",
"an",
"XHTML",
"table",
"row",
"with",
"the",
"row",
"identifier",
"as",
"a",
"placeholder",
"%s"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatTableViewInputRow.php#L779-L812 |
33,393 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.process | public function process()
{
parent::process();
// The $_FILES[$this->id] array is always set unless the POST data
// was greater than the PHP's post_max_size ini setting.
if (!isset($_FILES[$this->id]) || !$this->isSensitive()) {
return;
}
if ($_FILES[$this->id]['error'] === UPLOAD_ERR_OK) {
$this->file = $_FILES[$this->id];
if (!$this->hasValidMimeType()) {
$this->addMessage($this->getValidationMessage('mime-type'));
}
} elseif ($_FILES[$this->id]['error'] === UPLOAD_ERR_NO_FILE) {
if ($this->required) {
$this->addMessage($this->getValidationMessage('required'));
}
} elseif (
$_FILES[$this->id]['error'] === UPLOAD_ERR_INI_SIZE ||
$_FILES[$this->id]['error'] === UPLOAD_ERR_FORM_SIZE
) {
$this->addMessage($this->getValidationMessage('too-large'));
} else {
// There are other status codes we may want to check for in the
// future. Upload status codes can be found here:
// http://php.net/manual/en/features.file-upload.errors.php
$this->addMessage($this->getValidationMessage('upload-error'));
}
} | php | public function process()
{
parent::process();
// The $_FILES[$this->id] array is always set unless the POST data
// was greater than the PHP's post_max_size ini setting.
if (!isset($_FILES[$this->id]) || !$this->isSensitive()) {
return;
}
if ($_FILES[$this->id]['error'] === UPLOAD_ERR_OK) {
$this->file = $_FILES[$this->id];
if (!$this->hasValidMimeType()) {
$this->addMessage($this->getValidationMessage('mime-type'));
}
} elseif ($_FILES[$this->id]['error'] === UPLOAD_ERR_NO_FILE) {
if ($this->required) {
$this->addMessage($this->getValidationMessage('required'));
}
} elseif (
$_FILES[$this->id]['error'] === UPLOAD_ERR_INI_SIZE ||
$_FILES[$this->id]['error'] === UPLOAD_ERR_FORM_SIZE
) {
$this->addMessage($this->getValidationMessage('too-large'));
} else {
// There are other status codes we may want to check for in the
// future. Upload status codes can be found here:
// http://php.net/manual/en/features.file-upload.errors.php
$this->addMessage($this->getValidationMessage('upload-error'));
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"parent",
"::",
"process",
"(",
")",
";",
"// The $_FILES[$this->id] array is always set unless the POST data",
"// was greater than the PHP's post_max_size ini setting.",
"if",
"(",
"!",
"isset",
"(",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"isSensitive",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
"[",
"'error'",
"]",
"===",
"UPLOAD_ERR_OK",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasValidMimeType",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"getValidationMessage",
"(",
"'mime-type'",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
"[",
"'error'",
"]",
"===",
"UPLOAD_ERR_NO_FILE",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"required",
")",
"{",
"$",
"this",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"getValidationMessage",
"(",
"'required'",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
"[",
"'error'",
"]",
"===",
"UPLOAD_ERR_INI_SIZE",
"||",
"$",
"_FILES",
"[",
"$",
"this",
"->",
"id",
"]",
"[",
"'error'",
"]",
"===",
"UPLOAD_ERR_FORM_SIZE",
")",
"{",
"$",
"this",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"getValidationMessage",
"(",
"'too-large'",
")",
")",
";",
"}",
"else",
"{",
"// There are other status codes we may want to check for in the",
"// future. Upload status codes can be found here:",
"// http://php.net/manual/en/features.file-upload.errors.php",
"$",
"this",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"getValidationMessage",
"(",
"'upload-error'",
")",
")",
";",
"}",
"}"
] | Processes this file entry widget
If any validation type errors occur, an error message is attached to
this entry widget. | [
"Processes",
"this",
"file",
"entry",
"widget"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L163-L194 |
33,394 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.getNote | public function getNote()
{
$message = null;
if ($this->accept_mime_types !== null && $this->display_mime_types) {
$displayable_types = $this->getDisplayableTypes();
$message = new SwatMessage(
sprintf(
Swat::ngettext(
'Valid files are the following type: %s.',
'Valid files are the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
)
);
}
return $message;
} | php | public function getNote()
{
$message = null;
if ($this->accept_mime_types !== null && $this->display_mime_types) {
$displayable_types = $this->getDisplayableTypes();
$message = new SwatMessage(
sprintf(
Swat::ngettext(
'Valid files are the following type: %s.',
'Valid files are the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
)
);
}
return $message;
} | [
"public",
"function",
"getNote",
"(",
")",
"{",
"$",
"message",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"accept_mime_types",
"!==",
"null",
"&&",
"$",
"this",
"->",
"display_mime_types",
")",
"{",
"$",
"displayable_types",
"=",
"$",
"this",
"->",
"getDisplayableTypes",
"(",
")",
";",
"$",
"message",
"=",
"new",
"SwatMessage",
"(",
"sprintf",
"(",
"Swat",
"::",
"ngettext",
"(",
"'Valid files are the following type: %s.'",
",",
"'Valid files are the following type(s): %s.'",
",",
"count",
"(",
"$",
"displayable_types",
")",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"displayable_types",
")",
")",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Gets a note specifying the mime types this file entry accepts
The file types are only returned if
{@link SwatFileEntry::$display_mime_types} is set to true and
{@link SwatFileEntry::$accept_mime_types} has entries. If
{@link SwatFileEntry::$human_file_types} is set, the note displays the
human-readable file types where possible.
@return SwatMessage a note listing the accepted mime-types for this
file entry widget or null if any mime-type is
accepted.
@see SwatControl::getNote() | [
"Gets",
"a",
"note",
"specifying",
"the",
"mime",
"types",
"this",
"file",
"entry",
"accepts"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L214-L233 |
33,395 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.getMimeType | public function getMimeType()
{
if ($this->isUploaded() && $this->mime_type === null) {
$temp_file_name = $this->getTempFileName();
if (file_exists($temp_file_name)) {
if (extension_loaded('fileinfo')) {
// Use the fileinfo extension if available.
$finfo = $this->getFinfo();
$this->mime_type = explode(
';',
$finfo->file($temp_file_name)
)[0];
} elseif (function_exists('mime_content_type')) {
// Fall back to mime_content_type() if available.
$this->mime_type = mime_content_type($temp_file_name);
}
// No mime-detection functions, or mime-detection function
// failed to detect the type. Default to
// 'application/octet-stream'. Relying on HTTP headers could
// be a security problem so we never fall back to that option.
if ($this->mime_type == '') {
$this->mime_type = 'application/octet-stream';
}
} else {
$this->mime_type = $this->file['type'];
}
}
return $this->mime_type;
} | php | public function getMimeType()
{
if ($this->isUploaded() && $this->mime_type === null) {
$temp_file_name = $this->getTempFileName();
if (file_exists($temp_file_name)) {
if (extension_loaded('fileinfo')) {
// Use the fileinfo extension if available.
$finfo = $this->getFinfo();
$this->mime_type = explode(
';',
$finfo->file($temp_file_name)
)[0];
} elseif (function_exists('mime_content_type')) {
// Fall back to mime_content_type() if available.
$this->mime_type = mime_content_type($temp_file_name);
}
// No mime-detection functions, or mime-detection function
// failed to detect the type. Default to
// 'application/octet-stream'. Relying on HTTP headers could
// be a security problem so we never fall back to that option.
if ($this->mime_type == '') {
$this->mime_type = 'application/octet-stream';
}
} else {
$this->mime_type = $this->file['type'];
}
}
return $this->mime_type;
} | [
"public",
"function",
"getMimeType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isUploaded",
"(",
")",
"&&",
"$",
"this",
"->",
"mime_type",
"===",
"null",
")",
"{",
"$",
"temp_file_name",
"=",
"$",
"this",
"->",
"getTempFileName",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"temp_file_name",
")",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"'fileinfo'",
")",
")",
"{",
"// Use the fileinfo extension if available.",
"$",
"finfo",
"=",
"$",
"this",
"->",
"getFinfo",
"(",
")",
";",
"$",
"this",
"->",
"mime_type",
"=",
"explode",
"(",
"';'",
",",
"$",
"finfo",
"->",
"file",
"(",
"$",
"temp_file_name",
")",
")",
"[",
"0",
"]",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'mime_content_type'",
")",
")",
"{",
"// Fall back to mime_content_type() if available.",
"$",
"this",
"->",
"mime_type",
"=",
"mime_content_type",
"(",
"$",
"temp_file_name",
")",
";",
"}",
"// No mime-detection functions, or mime-detection function",
"// failed to detect the type. Default to",
"// 'application/octet-stream'. Relying on HTTP headers could",
"// be a security problem so we never fall back to that option.",
"if",
"(",
"$",
"this",
"->",
"mime_type",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"mime_type",
"=",
"'application/octet-stream'",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"mime_type",
"=",
"$",
"this",
"->",
"file",
"[",
"'type'",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"mime_type",
";",
"}"
] | Gets the mime type of the uploaded file
@return mixed the mime type of the uploaded file or null if no file was
uploaded. | [
"Gets",
"the",
"mime",
"type",
"of",
"the",
"uploaded",
"file"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L329-L359 |
33,396 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.saveFile | public function saveFile($dst_dir, $dst_filename = null)
{
if (!$this->isUploaded()) {
return false;
}
if ($dst_filename === null) {
$dst_filename = $this->getUniqueFileName($dst_dir);
}
if (is_dir($dst_dir)) {
return move_uploaded_file(
$this->file['tmp_name'],
$dst_dir . '/' . $dst_filename
);
} else {
throw new SwatException(
"Destination of '{$dst_dir}' is not a " .
'directory or does not exist.'
);
}
} | php | public function saveFile($dst_dir, $dst_filename = null)
{
if (!$this->isUploaded()) {
return false;
}
if ($dst_filename === null) {
$dst_filename = $this->getUniqueFileName($dst_dir);
}
if (is_dir($dst_dir)) {
return move_uploaded_file(
$this->file['tmp_name'],
$dst_dir . '/' . $dst_filename
);
} else {
throw new SwatException(
"Destination of '{$dst_dir}' is not a " .
'directory or does not exist.'
);
}
} | [
"public",
"function",
"saveFile",
"(",
"$",
"dst_dir",
",",
"$",
"dst_filename",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isUploaded",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"dst_filename",
"===",
"null",
")",
"{",
"$",
"dst_filename",
"=",
"$",
"this",
"->",
"getUniqueFileName",
"(",
"$",
"dst_dir",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"dst_dir",
")",
")",
"{",
"return",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"file",
"[",
"'tmp_name'",
"]",
",",
"$",
"dst_dir",
".",
"'/'",
".",
"$",
"dst_filename",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"SwatException",
"(",
"\"Destination of '{$dst_dir}' is not a \"",
".",
"'directory or does not exist.'",
")",
";",
"}",
"}"
] | Saves the uploaded file to the server
@param string $dst_dir the directory on the server to save the uploaded
file in.
@param string $dst_filename an optional filename to save the file under.
If no filename is specified, the file is
saved with the original filename.
@return boolean true if the file was saved correctly and false if there
was an error or no file was uploaded.
@throws SwatException if the destination directory does not exist. | [
"Saves",
"the",
"uploaded",
"file",
"to",
"the",
"server"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L378-L399 |
33,397 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.getValidationMessage | protected function getValidationMessage($id)
{
switch ($id) {
case 'mime-type':
$displayable_types = $this->getDisplayableTypes();
if ($this->show_field_title_in_messages) {
$text = sprintf(
Swat::ngettext(
'The %%s field must be of the following type: %s.',
'The %%s field must be of the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
);
} else {
$text = sprintf(
Swat::ngettext(
'This field must be of the following type: %s.',
'This field must be of the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
);
}
$message = new SwatMessage($text, 'error');
break;
case 'too-large':
if ($this->show_field_title_in_messages) {
$text = Swat::_(
'The %s field exceeds the maximum allowable file size.'
);
} else {
$text = Swat::_(
'This field exceeds the maximum allowable file size.'
);
}
$message = new SwatMessage($text, 'error');
break;
case 'upload-error':
if ($this->show_field_title_in_messages) {
$text = Swat::_(
'The %s field encounted an error when trying to upload ' .
'the file. Please try again.'
);
} else {
$text = Swat::_(
'This field encounted an error when trying to upload the ' .
'file. Please try again.'
);
}
$message = new SwatMessage($text, 'error');
break;
default:
$message = parent::getValidationMessage($id);
break;
}
return $message;
} | php | protected function getValidationMessage($id)
{
switch ($id) {
case 'mime-type':
$displayable_types = $this->getDisplayableTypes();
if ($this->show_field_title_in_messages) {
$text = sprintf(
Swat::ngettext(
'The %%s field must be of the following type: %s.',
'The %%s field must be of the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
);
} else {
$text = sprintf(
Swat::ngettext(
'This field must be of the following type: %s.',
'This field must be of the following type(s): %s.',
count($displayable_types)
),
implode(', ', $displayable_types)
);
}
$message = new SwatMessage($text, 'error');
break;
case 'too-large':
if ($this->show_field_title_in_messages) {
$text = Swat::_(
'The %s field exceeds the maximum allowable file size.'
);
} else {
$text = Swat::_(
'This field exceeds the maximum allowable file size.'
);
}
$message = new SwatMessage($text, 'error');
break;
case 'upload-error':
if ($this->show_field_title_in_messages) {
$text = Swat::_(
'The %s field encounted an error when trying to upload ' .
'the file. Please try again.'
);
} else {
$text = Swat::_(
'This field encounted an error when trying to upload the ' .
'file. Please try again.'
);
}
$message = new SwatMessage($text, 'error');
break;
default:
$message = parent::getValidationMessage($id);
break;
}
return $message;
} | [
"protected",
"function",
"getValidationMessage",
"(",
"$",
"id",
")",
"{",
"switch",
"(",
"$",
"id",
")",
"{",
"case",
"'mime-type'",
":",
"$",
"displayable_types",
"=",
"$",
"this",
"->",
"getDisplayableTypes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"show_field_title_in_messages",
")",
"{",
"$",
"text",
"=",
"sprintf",
"(",
"Swat",
"::",
"ngettext",
"(",
"'The %%s field must be of the following type: %s.'",
",",
"'The %%s field must be of the following type(s): %s.'",
",",
"count",
"(",
"$",
"displayable_types",
")",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"displayable_types",
")",
")",
";",
"}",
"else",
"{",
"$",
"text",
"=",
"sprintf",
"(",
"Swat",
"::",
"ngettext",
"(",
"'This field must be of the following type: %s.'",
",",
"'This field must be of the following type(s): %s.'",
",",
"count",
"(",
"$",
"displayable_types",
")",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"displayable_types",
")",
")",
";",
"}",
"$",
"message",
"=",
"new",
"SwatMessage",
"(",
"$",
"text",
",",
"'error'",
")",
";",
"break",
";",
"case",
"'too-large'",
":",
"if",
"(",
"$",
"this",
"->",
"show_field_title_in_messages",
")",
"{",
"$",
"text",
"=",
"Swat",
"::",
"_",
"(",
"'The %s field exceeds the maximum allowable file size.'",
")",
";",
"}",
"else",
"{",
"$",
"text",
"=",
"Swat",
"::",
"_",
"(",
"'This field exceeds the maximum allowable file size.'",
")",
";",
"}",
"$",
"message",
"=",
"new",
"SwatMessage",
"(",
"$",
"text",
",",
"'error'",
")",
";",
"break",
";",
"case",
"'upload-error'",
":",
"if",
"(",
"$",
"this",
"->",
"show_field_title_in_messages",
")",
"{",
"$",
"text",
"=",
"Swat",
"::",
"_",
"(",
"'The %s field encounted an error when trying to upload '",
".",
"'the file. Please try again.'",
")",
";",
"}",
"else",
"{",
"$",
"text",
"=",
"Swat",
"::",
"_",
"(",
"'This field encounted an error when trying to upload the '",
".",
"'file. Please try again.'",
")",
";",
"}",
"$",
"message",
"=",
"new",
"SwatMessage",
"(",
"$",
"text",
",",
"'error'",
")",
";",
"break",
";",
"default",
":",
"$",
"message",
"=",
"parent",
"::",
"getValidationMessage",
"(",
"$",
"id",
")",
";",
"break",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Gets a validation message for this file entry
Can be used by sub-classes to change the validation messages.
@param string $id the string identifier of the validation message.
@return SwatMessage the validation message. | [
"Gets",
"a",
"validation",
"message",
"for",
"this",
"file",
"entry"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L453-L518 |
33,398 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.hasValidMimeType | protected function hasValidMimeType()
{
$valid = false;
if ($this->isUploaded()) {
// Some container formats can contain return multiple mime-types.
// If any of the contained types are valid, we consider the file
// valid.
$mime_types = explode(' ', $this->getMimeType());
if (
is_array($this->accept_mime_types) &&
count($this->accept_mime_types) > 0
) {
$types = array_intersect($mime_types, $this->accept_mime_types);
$valid = count($types) > 0;
} else {
$valid = true;
}
}
return $valid;
} | php | protected function hasValidMimeType()
{
$valid = false;
if ($this->isUploaded()) {
// Some container formats can contain return multiple mime-types.
// If any of the contained types are valid, we consider the file
// valid.
$mime_types = explode(' ', $this->getMimeType());
if (
is_array($this->accept_mime_types) &&
count($this->accept_mime_types) > 0
) {
$types = array_intersect($mime_types, $this->accept_mime_types);
$valid = count($types) > 0;
} else {
$valid = true;
}
}
return $valid;
} | [
"protected",
"function",
"hasValidMimeType",
"(",
")",
"{",
"$",
"valid",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isUploaded",
"(",
")",
")",
"{",
"// Some container formats can contain return multiple mime-types.",
"// If any of the contained types are valid, we consider the file",
"// valid.",
"$",
"mime_types",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"getMimeType",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"accept_mime_types",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"accept_mime_types",
")",
">",
"0",
")",
"{",
"$",
"types",
"=",
"array_intersect",
"(",
"$",
"mime_types",
",",
"$",
"this",
"->",
"accept_mime_types",
")",
";",
"$",
"valid",
"=",
"count",
"(",
"$",
"types",
")",
">",
"0",
";",
"}",
"else",
"{",
"$",
"valid",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"valid",
";",
"}"
] | Whether or not the uploaded file's mime type is valid
Gets whether or not the upload file's mime type matches the accepted
mime types of this widget. Valid mime types for this widget are stored in
the {@link SwatFileEntry::$accept_mime_types} array. If the
<kbd>$accept_mime_types</kbd> array is empty, the uploaded file's mime
type is always valid.
Some container formats may have multiple mime-types. In this case, if
any of the contained types are valid, we consider the file valid.
@return boolean whether or not this file's mime type is valid. | [
"Whether",
"or",
"not",
"the",
"uploaded",
"file",
"s",
"mime",
"type",
"is",
"valid"
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L553-L574 |
33,399 | silverorange/swat | Swat/SwatFileEntry.php | SwatFileEntry.getDisplayableTypes | protected function getDisplayableTypes()
{
$displayable_types = array();
foreach ($this->accept_mime_types as $mime_type) {
$displayable_type = isset($this->human_file_types[$mime_type])
? $this->human_file_types[$mime_type]
: $mime_type;
// Use the value as the key to de-dupe.
$displayable_types[$displayable_type] = $displayable_type;
}
return $displayable_types;
} | php | protected function getDisplayableTypes()
{
$displayable_types = array();
foreach ($this->accept_mime_types as $mime_type) {
$displayable_type = isset($this->human_file_types[$mime_type])
? $this->human_file_types[$mime_type]
: $mime_type;
// Use the value as the key to de-dupe.
$displayable_types[$displayable_type] = $displayable_type;
}
return $displayable_types;
} | [
"protected",
"function",
"getDisplayableTypes",
"(",
")",
"{",
"$",
"displayable_types",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"accept_mime_types",
"as",
"$",
"mime_type",
")",
"{",
"$",
"displayable_type",
"=",
"isset",
"(",
"$",
"this",
"->",
"human_file_types",
"[",
"$",
"mime_type",
"]",
")",
"?",
"$",
"this",
"->",
"human_file_types",
"[",
"$",
"mime_type",
"]",
":",
"$",
"mime_type",
";",
"// Use the value as the key to de-dupe.",
"$",
"displayable_types",
"[",
"$",
"displayable_type",
"]",
"=",
"$",
"displayable_type",
";",
"}",
"return",
"$",
"displayable_types",
";",
"}"
] | Gets a unique array of acceptable human-readable file and mime types for
display.
If {@link SwatFileEntry::$human_file_types} is set, and the mime type
exists within it, we display the corresponding human-readable file type.
Otherwise we fall back to the mime type.
@return array unique mime and human-readable file types. | [
"Gets",
"a",
"unique",
"array",
"of",
"acceptable",
"human",
"-",
"readable",
"file",
"and",
"mime",
"types",
"for",
"display",
"."
] | e65dc5bc351927c61f594068430cdeeb874c8bc5 | https://github.com/silverorange/swat/blob/e65dc5bc351927c61f594068430cdeeb874c8bc5/Swat/SwatFileEntry.php#L621-L635 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.