repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
153
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequence
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
sequence
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
headzoo/core
src/Headzoo/Core/Strings.php
Strings.startsWith
public static function startsWith($str, $find, $match_case = true) { if ($match_case) { return self::$use_mbstring ? mb_strpos($str, $find) === 0 : strpos($str, $find) === 0; } else { return self::$use_mbstring ? mb_stripos($str, $find) === 0 : stripos($str, $find) === 0; } }
php
public static function startsWith($str, $find, $match_case = true) { if ($match_case) { return self::$use_mbstring ? mb_strpos($str, $find) === 0 : strpos($str, $find) === 0; } else { return self::$use_mbstring ? mb_stripos($str, $find) === 0 : stripos($str, $find) === 0; } }
[ "public", "static", "function", "startsWith", "(", "$", "str", ",", "$", "find", ",", "$", "match_case", "=", "true", ")", "{", "if", "(", "$", "match_case", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_strpos", "(", "$", "str", ",", "$", "find", ")", "===", "0", ":", "strpos", "(", "$", "str", ",", "$", "find", ")", "===", "0", ";", "}", "else", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_stripos", "(", "$", "str", ",", "$", "find", ")", "===", "0", ":", "stripos", "(", "$", "str", ",", "$", "find", ")", "===", "0", ";", "}", "}" ]
Returns whether the string starts with another string Returns a boolean value indicating whether a string starts with another string. The comparison is case-sensitive when $match_case is true, and case-insensitive when false. Examples: ```php $is = Strings::startsWith("How I wish, how I wish you were here.", "How"); var_dump($is); // Outputs: bool(true) $is = Strings::startsWith("We're just two lost souls, Swimming in a fish bowl", "we're"); var_dump($is); // Outputs: bool(false) $is = Strings::startsWith("We're just two lost souls, Swimming in a fish bowl", "we're", false); var_dump($is); // Outputs: bool(true) ``` @param string $str The string to search @param string $find The string to find @param bool $match_case True to match the exact case, false for case-insensitive match @return bool
[ "Returns", "whether", "the", "string", "starts", "with", "another", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L410-L421
headzoo/core
src/Headzoo/Core/Strings.php
Strings.endsWith
public static function endsWith($str, $find, $match_case = true) { if (!$match_case) { $str = self::toLower($str); $find = self::toLower($find); } if (self::$use_mbstring) { $len = mb_strlen($find); $is_ends = mb_substr($str, "-{$len}") === $find; } else { $len = strlen($find); $is_ends = substr($str, "-{$len}") === $find; } return $is_ends; }
php
public static function endsWith($str, $find, $match_case = true) { if (!$match_case) { $str = self::toLower($str); $find = self::toLower($find); } if (self::$use_mbstring) { $len = mb_strlen($find); $is_ends = mb_substr($str, "-{$len}") === $find; } else { $len = strlen($find); $is_ends = substr($str, "-{$len}") === $find; } return $is_ends; }
[ "public", "static", "function", "endsWith", "(", "$", "str", ",", "$", "find", ",", "$", "match_case", "=", "true", ")", "{", "if", "(", "!", "$", "match_case", ")", "{", "$", "str", "=", "self", "::", "toLower", "(", "$", "str", ")", ";", "$", "find", "=", "self", "::", "toLower", "(", "$", "find", ")", ";", "}", "if", "(", "self", "::", "$", "use_mbstring", ")", "{", "$", "len", "=", "mb_strlen", "(", "$", "find", ")", ";", "$", "is_ends", "=", "mb_substr", "(", "$", "str", ",", "\"-{$len}\"", ")", "===", "$", "find", ";", "}", "else", "{", "$", "len", "=", "strlen", "(", "$", "find", ")", ";", "$", "is_ends", "=", "substr", "(", "$", "str", ",", "\"-{$len}\"", ")", "===", "$", "find", ";", "}", "return", "$", "is_ends", ";", "}" ]
Returns whether the string ends with another string Returns a boolean value indicating whether a string ends with another string. The comparison is case-sensitive when $match_case is true, and case-insensitive when false. Examples: ```php $is = Strings::endsWith("Running over the same old ground.", "ground."); var_dump($is); // Outputs: bool(true) $is = Strings::endsWith("What have we found? The same old fears.", "Fears."); var_dump($is); // Outputs: bool(false) $is = Strings::endsWith("What have we found? The same old fears.", "Fears.", false); var_dump($is); // Outputs: bool(true) ``` @param string $str The string to search @param string $find The string to find @param bool $match_case True to match the exact case, false for case-insensitive match @return bool
[ "Returns", "whether", "the", "string", "ends", "with", "another", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L452-L467
headzoo/core
src/Headzoo/Core/Strings.php
Strings.startsUpper
public static function startsUpper($str) { $char = self::sub($str, 0, 1); return self::toUpper($char) === $char; }
php
public static function startsUpper($str) { $char = self::sub($str, 0, 1); return self::toUpper($char) === $char; }
[ "public", "static", "function", "startsUpper", "(", "$", "str", ")", "{", "$", "char", "=", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "1", ")", ";", "return", "self", "::", "toUpper", "(", "$", "char", ")", "===", "$", "char", ";", "}" ]
Returns whether the string starts with an upper case character Returns a boolean value indicating whether the first character in a string is upper case. Examples: ```php $is = Strings::startsUpper("Welcome my son, welcome to the machine."); var_dump($is); // Output: bool(true); $is = Strings::startsUpper("you've been in the pipeline, filling in time"); var_dump($is); // Output: bool(false) ``` @param string $str The string to search @return bool
[ "Returns", "whether", "the", "string", "starts", "with", "an", "upper", "case", "character" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L491-L495
headzoo/core
src/Headzoo/Core/Strings.php
Strings.startsLower
public static function startsLower($str) { $char = self::sub($str, 0, 1); return self::toLower($char) === $char; }
php
public static function startsLower($str) { $char = self::sub($str, 0, 1); return self::toLower($char) === $char; }
[ "public", "static", "function", "startsLower", "(", "$", "str", ")", "{", "$", "char", "=", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "1", ")", ";", "return", "self", "::", "toLower", "(", "$", "char", ")", "===", "$", "char", ";", "}" ]
Returns whether the string starts with a lower case character Returns a boolean value indicating whether the first character in a string is lower case. Examples: ```php $is = Strings::startsLower("And sail on the steel breeze."); var_dump($is); // Output: bool(false); $is = Strings::startsLower("come on you miner for truth and delusion, and shine!"); var_dump($is); // Output: bool(true) ``` @param string $str The string to search @return bool
[ "Returns", "whether", "the", "string", "starts", "with", "a", "lower", "case", "character" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L519-L523
headzoo/core
src/Headzoo/Core/Strings.php
Strings.replace
public static function replace($str, $search, $replace) { if (self::$use_mbstring) { $search_len = mb_strlen($search); $replace_len = mb_strlen($replace); $search_pos = mb_strpos($str, $search); while ($search_pos !== false) { $str = mb_substr($str, 0, $search_pos) . $replace . mb_substr($str, $search_pos + $search_len); $search_pos = mb_strpos($str, $search, $search_pos + $replace_len); } } else { $str = str_replace($search, $replace, $str); } return $str; }
php
public static function replace($str, $search, $replace) { if (self::$use_mbstring) { $search_len = mb_strlen($search); $replace_len = mb_strlen($replace); $search_pos = mb_strpos($str, $search); while ($search_pos !== false) { $str = mb_substr($str, 0, $search_pos) . $replace . mb_substr($str, $search_pos + $search_len); $search_pos = mb_strpos($str, $search, $search_pos + $replace_len); } } else { $str = str_replace($search, $replace, $str); } return $str; }
[ "public", "static", "function", "replace", "(", "$", "str", ",", "$", "search", ",", "$", "replace", ")", "{", "if", "(", "self", "::", "$", "use_mbstring", ")", "{", "$", "search_len", "=", "mb_strlen", "(", "$", "search", ")", ";", "$", "replace_len", "=", "mb_strlen", "(", "$", "replace", ")", ";", "$", "search_pos", "=", "mb_strpos", "(", "$", "str", ",", "$", "search", ")", ";", "while", "(", "$", "search_pos", "!==", "false", ")", "{", "$", "str", "=", "mb_substr", "(", "$", "str", ",", "0", ",", "$", "search_pos", ")", ".", "$", "replace", ".", "mb_substr", "(", "$", "str", ",", "$", "search_pos", "+", "$", "search_len", ")", ";", "$", "search_pos", "=", "mb_strpos", "(", "$", "str", ",", "$", "search", ",", "$", "search_pos", "+", "$", "replace_len", ")", ";", "}", "}", "else", "{", "$", "str", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "str", ")", ";", "}", "return", "$", "str", ";", "}" ]
Replaces characters in a string Example: ```php $str = "With flowers and my love both never to come back"; $search = "flowers"; $replace = "roses"; echo Strings::replace($str, $search, $replace); // Outputs: "With roses and my love both never to come back" ``` @param string $str The string to transform @param string $search The string to find @param string $replace The replacement string @return string
[ "Replaces", "characters", "in", "a", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L543-L560
headzoo/core
src/Headzoo/Core/Strings.php
Strings.length
public static function length($str) { return self::$use_mbstring ? mb_strlen($str, self::$char_set) : strlen($str); }
php
public static function length($str) { return self::$use_mbstring ? mb_strlen($str, self::$char_set) : strlen($str); }
[ "public", "static", "function", "length", "(", "$", "str", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_strlen", "(", "$", "str", ",", "self", "::", "$", "char_set", ")", ":", "strlen", "(", "$", "str", ")", ";", "}" ]
Returns the number of characters in the string Note: When multi-byte support is enabled, the method returns the true number of characters instead of the number of bytes. Example: ```php echo Strings::length("You can't say we're satisfied"); // Outputs: 29 ``` @param string $str The string to count @return int
[ "Returns", "the", "number", "of", "characters", "in", "the", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L578-L583
headzoo/core
src/Headzoo/Core/Strings.php
Strings.chars
public static function chars($str) { if (self::$use_mbstring) { $chars = []; for($i = 0, $l = self::length($str); $i < $l; $i++) { $chars[] = mb_substr($str, $i, 1, self::$char_set); } } else { $chars = str_split($str); } return $chars; }
php
public static function chars($str) { if (self::$use_mbstring) { $chars = []; for($i = 0, $l = self::length($str); $i < $l; $i++) { $chars[] = mb_substr($str, $i, 1, self::$char_set); } } else { $chars = str_split($str); } return $chars; }
[ "public", "static", "function", "chars", "(", "$", "str", ")", "{", "if", "(", "self", "::", "$", "use_mbstring", ")", "{", "$", "chars", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ",", "$", "l", "=", "self", "::", "length", "(", "$", "str", ")", ";", "$", "i", "<", "$", "l", ";", "$", "i", "++", ")", "{", "$", "chars", "[", "]", "=", "mb_substr", "(", "$", "str", ",", "$", "i", ",", "1", ",", "self", "::", "$", "char_set", ")", ";", "}", "}", "else", "{", "$", "chars", "=", "str_split", "(", "$", "str", ")", ";", "}", "return", "$", "chars", ";", "}" ]
Splits a string into individual characters Returns an array with the individual characters from a string. Example: ```php $chars = Strings::chars("Yeah!"); print_r($chars); // Outputs: // [ // "Y", // "e", // "a", // "h", // "!" // ] ``` @param string $str The string to split @return array
[ "Splits", "a", "string", "into", "individual", "characters" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L608-L620
headzoo/core
src/Headzoo/Core/Strings.php
Strings.toUpper
public static function toUpper($str) { return self::$use_mbstring ? mb_strtoupper($str, self::$char_set) : strtoupper($str); }
php
public static function toUpper($str) { return self::$use_mbstring ? mb_strtoupper($str, self::$char_set) : strtoupper($str); }
[ "public", "static", "function", "toUpper", "(", "$", "str", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_strtoupper", "(", "$", "str", ",", "self", "::", "$", "char_set", ")", ":", "strtoupper", "(", "$", "str", ")", ";", "}" ]
Transforms a string to upper case Example: ```php echo Strings::toUpper("With no loving in our souls and no money in our coats"); // Outputs: "WITH NO LOVING IN OUR SOULS AND NO MONEY IN OUR COATS" ``` @param string $str The string to transform @return string
[ "Transforms", "a", "string", "to", "upper", "case" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L635-L640
headzoo/core
src/Headzoo/Core/Strings.php
Strings.toLower
public static function toLower($str) { return self::$use_mbstring ? mb_strtolower($str, self::$char_set) : strtolower($str); }
php
public static function toLower($str) { return self::$use_mbstring ? mb_strtolower($str, self::$char_set) : strtolower($str); }
[ "public", "static", "function", "toLower", "(", "$", "str", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_strtolower", "(", "$", "str", ",", "self", "::", "$", "char_set", ")", ":", "strtolower", "(", "$", "str", ")", ";", "}" ]
Transforms a string to lower case Example: ```php echo Strings::toLower("But Angie, Angie, you can't say we never tried"); // Outputs: "but angie, angie, you can't say we never tried" ``` @param string $str The string to transform @return string
[ "Transforms", "a", "string", "to", "lower", "case" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L655-L660
headzoo/core
src/Headzoo/Core/Strings.php
Strings.ucFirst
public static function ucFirst($str) { if (self::$use_mbstring) { $first = self::toUpper(self::sub($str, 0, 1)); $str = $first . self::sub($str, 1); } else { $str = ucfirst($str); } return $str; }
php
public static function ucFirst($str) { if (self::$use_mbstring) { $first = self::toUpper(self::sub($str, 0, 1)); $str = $first . self::sub($str, 1); } else { $str = ucfirst($str); } return $str; }
[ "public", "static", "function", "ucFirst", "(", "$", "str", ")", "{", "if", "(", "self", "::", "$", "use_mbstring", ")", "{", "$", "first", "=", "self", "::", "toUpper", "(", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "1", ")", ")", ";", "$", "str", "=", "$", "first", ".", "self", "::", "sub", "(", "$", "str", ",", "1", ")", ";", "}", "else", "{", "$", "str", "=", "ucfirst", "(", "$", "str", ")", ";", "}", "return", "$", "str", ";", "}" ]
Transforms the first letter of a string to upper case Example: ```php echo Strings::ucFirst("people say that I've found a way"); // Outputs: "People say that I've found a way" ``` @param string $str The string to transform @return string
[ "Transforms", "the", "first", "letter", "of", "a", "string", "to", "upper", "case" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L675-L685
headzoo/core
src/Headzoo/Core/Strings.php
Strings.lcFirst
public static function lcFirst($str) { if (self::$use_mbstring) { $first = self::toLower(self::sub($str, 0, 1)); $str = $first . self::sub($str, 1); } else { $str = lcfirst($str); } return $str; }
php
public static function lcFirst($str) { if (self::$use_mbstring) { $first = self::toLower(self::sub($str, 0, 1)); $str = $first . self::sub($str, 1); } else { $str = lcfirst($str); } return $str; }
[ "public", "static", "function", "lcFirst", "(", "$", "str", ")", "{", "if", "(", "self", "::", "$", "use_mbstring", ")", "{", "$", "first", "=", "self", "::", "toLower", "(", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "1", ")", ")", ";", "$", "str", "=", "$", "first", ".", "self", "::", "sub", "(", "$", "str", ",", "1", ")", ";", "}", "else", "{", "$", "str", "=", "lcfirst", "(", "$", "str", ")", ";", "}", "return", "$", "str", ";", "}" ]
Transforms the first letter of a string to lower case Example: ```php echo Strings::lcFirst("To make you say that you love me"); // Outputs: "to make you say that you love me" ``` @param string $str The string to transform @return string
[ "Transforms", "the", "first", "letter", "of", "a", "string", "to", "lower", "case" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L700-L710
headzoo/core
src/Headzoo/Core/Strings.php
Strings.title
public static function title($str) { return self::$use_mbstring ? mb_convert_case($str, MB_CASE_TITLE, self::$char_set) : ucwords(strtolower($str)); }
php
public static function title($str) { return self::$use_mbstring ? mb_convert_case($str, MB_CASE_TITLE, self::$char_set) : ucwords(strtolower($str)); }
[ "public", "static", "function", "title", "(", "$", "str", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_convert_case", "(", "$", "str", ",", "MB_CASE_TITLE", ",", "self", "::", "$", "char_set", ")", ":", "ucwords", "(", "strtolower", "(", "$", "str", ")", ")", ";", "}" ]
Upper cases the first letter of each word in the string Example: ```php echo Strings::title("Hey hey hey hey, and I'm cryin' tears all through the years"); // Outputs: "Hey Hey Hey Hey, And I'm Cryin' Tears All Through The Years" ``` @param string $str The string to transform @return string
[ "Upper", "cases", "the", "first", "letter", "of", "each", "word", "in", "the", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L725-L730
headzoo/core
src/Headzoo/Core/Strings.php
Strings.sub
public static function sub($str, $start, $end = null) { // The $end argument must be left out of the function call when it's not used. // Passing null to these functions doesn't work. if (null !== $end) { return self::$use_mbstring ? mb_substr($str, $start, $end) : substr($str, $start, $end); } else { return self::$use_mbstring ? mb_substr($str, $start) : substr($str, $start); } }
php
public static function sub($str, $start, $end = null) { // The $end argument must be left out of the function call when it's not used. // Passing null to these functions doesn't work. if (null !== $end) { return self::$use_mbstring ? mb_substr($str, $start, $end) : substr($str, $start, $end); } else { return self::$use_mbstring ? mb_substr($str, $start) : substr($str, $start); } }
[ "public", "static", "function", "sub", "(", "$", "str", ",", "$", "start", ",", "$", "end", "=", "null", ")", "{", "// The $end argument must be left out of the function call when it's not used.", "// Passing null to these functions doesn't work.", "if", "(", "null", "!==", "$", "end", ")", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_substr", "(", "$", "str", ",", "$", "start", ",", "$", "end", ")", ":", "substr", "(", "$", "str", ",", "$", "start", ",", "$", "end", ")", ";", "}", "else", "{", "return", "self", "::", "$", "use_mbstring", "?", "mb_substr", "(", "$", "str", ",", "$", "start", ")", ":", "substr", "(", "$", "str", ",", "$", "start", ")", ";", "}", "}" ]
Returns a portion of the string See the documentation for substr for details of each argument. Example: ```php echo Strings::sub("Make you do right, love", 19, 4); // Outputs: "love" ``` @param string $str The string @param int $start The start position @param int $end The end position @return string
[ "Returns", "a", "portion", "of", "the", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L749-L762
headzoo/core
src/Headzoo/Core/Strings.php
Strings.truncate
public static function truncate($str, $max_len, $pos = self::TRUNC_END, $ellipsis = "...") { if (self::length($str) > $max_len) { $ellipsis_len = self::length($ellipsis); switch($pos) { case self::TRUNC_START: $max_len -= $ellipsis_len; $str = $ellipsis . self::sub($str, "-{$max_len}"); break; case self::TRUNC_MIDDLE: $start = self::sub($str, 0, round($max_len / 2) - $ellipsis_len); $max_len = $max_len - self::length($start) - $ellipsis_len; $end = self::sub($str, "-{$max_len}"); $str = "{$start}{$ellipsis}{$end}"; break; case self::TRUNC_END: $max_len -= $ellipsis_len; $str = self::sub($str, 0, $max_len) . $ellipsis; break; default: self::toss( "InvalidArgumentException", "Invalid truncate position '{0}'.", $pos ); break; } } return $str; }
php
public static function truncate($str, $max_len, $pos = self::TRUNC_END, $ellipsis = "...") { if (self::length($str) > $max_len) { $ellipsis_len = self::length($ellipsis); switch($pos) { case self::TRUNC_START: $max_len -= $ellipsis_len; $str = $ellipsis . self::sub($str, "-{$max_len}"); break; case self::TRUNC_MIDDLE: $start = self::sub($str, 0, round($max_len / 2) - $ellipsis_len); $max_len = $max_len - self::length($start) - $ellipsis_len; $end = self::sub($str, "-{$max_len}"); $str = "{$start}{$ellipsis}{$end}"; break; case self::TRUNC_END: $max_len -= $ellipsis_len; $str = self::sub($str, 0, $max_len) . $ellipsis; break; default: self::toss( "InvalidArgumentException", "Invalid truncate position '{0}'.", $pos ); break; } } return $str; }
[ "public", "static", "function", "truncate", "(", "$", "str", ",", "$", "max_len", ",", "$", "pos", "=", "self", "::", "TRUNC_END", ",", "$", "ellipsis", "=", "\"...\"", ")", "{", "if", "(", "self", "::", "length", "(", "$", "str", ")", ">", "$", "max_len", ")", "{", "$", "ellipsis_len", "=", "self", "::", "length", "(", "$", "ellipsis", ")", ";", "switch", "(", "$", "pos", ")", "{", "case", "self", "::", "TRUNC_START", ":", "$", "max_len", "-=", "$", "ellipsis_len", ";", "$", "str", "=", "$", "ellipsis", ".", "self", "::", "sub", "(", "$", "str", ",", "\"-{$max_len}\"", ")", ";", "break", ";", "case", "self", "::", "TRUNC_MIDDLE", ":", "$", "start", "=", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "round", "(", "$", "max_len", "/", "2", ")", "-", "$", "ellipsis_len", ")", ";", "$", "max_len", "=", "$", "max_len", "-", "self", "::", "length", "(", "$", "start", ")", "-", "$", "ellipsis_len", ";", "$", "end", "=", "self", "::", "sub", "(", "$", "str", ",", "\"-{$max_len}\"", ")", ";", "$", "str", "=", "\"{$start}{$ellipsis}{$end}\"", ";", "break", ";", "case", "self", "::", "TRUNC_END", ":", "$", "max_len", "-=", "$", "ellipsis_len", ";", "$", "str", "=", "self", "::", "sub", "(", "$", "str", ",", "0", ",", "$", "max_len", ")", ".", "$", "ellipsis", ";", "break", ";", "default", ":", "self", "::", "toss", "(", "\"InvalidArgumentException\"", ",", "\"Invalid truncate position '{0}'.\"", ",", "$", "pos", ")", ";", "break", ";", "}", "}", "return", "$", "str", ";", "}" ]
Truncates strings which exceed a maximum length An ellipsis is added to the string to indicate it's been shortened. The final length of the string, including ellipsis, will be the length specified by $max_len. Strings may be truncated in three places: the start, middle, and end. Examples: ```php // Truncating a string at the end. echo Strings::truncate("Mary had a little lamb, whose fleece was white as snow.", 20, Strings::TRUNC_END); // Outputs: "Mary had a little..." // Truncating a string at the start. echo Strings::truncate("Mary had a little lamb, whose fleece was white as snow.", 20, Strings::TRUNC_START); // Outputs: "...as white as snow." // Truncating a string in the middle. echo Strings::truncate("Mary had a little lamb, whose fleece was white as snow.", 20, Strings::TRUNC_MIDDLE); // Outputs: "Mary ha...e as snow." ``` @param string $str The string to truncate @param int $max_len The maximum length @param int $pos Where in the string the cut should be made @param string $ellipsis A string which indicates the string was truncated @return string
[ "Truncates", "strings", "which", "exceed", "a", "maximum", "length" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L796-L826
headzoo/core
src/Headzoo/Core/Strings.php
Strings.transform
public static function transform(&$str, $transformation = self::TR_LOWER) { switch($transformation) { case self::TR_LOWER: $str = self::toLower($str); break; case self::TR_UPPER: $str = self::toUpper($str); break; case self::TR_TITLE: $str = self::title($str); break; case self::TR_UC_FIRST: $str = self::ucFirst($str); break; case self::TR_LC_FIRST: $str = self::lcFirst($str); break; case self::TR_UNDERSCORE: $str = self::camelCaseToUnderscore($str); break; case self::TR_CAMEL_CASE: $str = self::underscoreToCamelCase($str); break; default: self::toss( "InvalidArgumentException", "Transforming argument {0}({1}) must be one of the {me}::TR constants", __METHOD__, $transformation ); break; } }
php
public static function transform(&$str, $transformation = self::TR_LOWER) { switch($transformation) { case self::TR_LOWER: $str = self::toLower($str); break; case self::TR_UPPER: $str = self::toUpper($str); break; case self::TR_TITLE: $str = self::title($str); break; case self::TR_UC_FIRST: $str = self::ucFirst($str); break; case self::TR_LC_FIRST: $str = self::lcFirst($str); break; case self::TR_UNDERSCORE: $str = self::camelCaseToUnderscore($str); break; case self::TR_CAMEL_CASE: $str = self::underscoreToCamelCase($str); break; default: self::toss( "InvalidArgumentException", "Transforming argument {0}({1}) must be one of the {me}::TR constants", __METHOD__, $transformation ); break; } }
[ "public", "static", "function", "transform", "(", "&", "$", "str", ",", "$", "transformation", "=", "self", "::", "TR_LOWER", ")", "{", "switch", "(", "$", "transformation", ")", "{", "case", "self", "::", "TR_LOWER", ":", "$", "str", "=", "self", "::", "toLower", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_UPPER", ":", "$", "str", "=", "self", "::", "toUpper", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_TITLE", ":", "$", "str", "=", "self", "::", "title", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_UC_FIRST", ":", "$", "str", "=", "self", "::", "ucFirst", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_LC_FIRST", ":", "$", "str", "=", "self", "::", "lcFirst", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_UNDERSCORE", ":", "$", "str", "=", "self", "::", "camelCaseToUnderscore", "(", "$", "str", ")", ";", "break", ";", "case", "self", "::", "TR_CAMEL_CASE", ":", "$", "str", "=", "self", "::", "underscoreToCamelCase", "(", "$", "str", ")", ";", "break", ";", "default", ":", "self", "::", "toss", "(", "\"InvalidArgumentException\"", ",", "\"Transforming argument {0}({1}) must be one of the {me}::TR constants\"", ",", "__METHOD__", ",", "$", "transformation", ")", ";", "break", ";", "}", "}" ]
Transform a string This method wraps the functions ::toLower(), ::toUpper(), ::title(), ::ucFirst(), ::lcFirst(), ::camelCaseToUnderscore(), and ::underscoreToCamelCase() . The notable difference is strings are passed by reference to this method. The value of $transformation must be one of the Strings::TR constants, which map to the following methods: ::TR_LOWER - ::toLower(). ::TR_UPPER - ::toUpper(). ::TR_TITLE - ::title(). ::TR_UC_FIRST - ::ucFirst(). ::TR_LC_FIRST - ::lcFirst(). ::TR_UNDERSCORE - ::camelCaseToUnderscore() ::TR_CAMEL_CASE - ::underscoreToCamelCase() @param string $str The string to transform @param int $transformation The transformation to apply @throws Exceptions\InvalidArgumentException When $transformation is not one of the ::TR constants
[ "Transform", "a", "string" ]
train
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L849-L882
mvccore/ext-form
src/MvcCore/Ext/Forms/Field/Props/AutoFocus.php
AutoFocus.&
public function & SetAutoFocus ($autoFocus = TRUE, $duplicateBehaviour = \MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_EXCEPTION) { /** @var $this \MvcCore\Ext\Forms\IField */ $this->autoFocus = $autoFocus; if ($autoFocus && $duplicateBehaviour !== \MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_QUIETLY_SET_NEW) { $form = & $this->form; $form::SetAutoFocusedFormField($form->GetId(), $this->name, $duplicateBehaviour); } return $this; }
php
public function & SetAutoFocus ($autoFocus = TRUE, $duplicateBehaviour = \MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_EXCEPTION) { /** @var $this \MvcCore\Ext\Forms\IField */ $this->autoFocus = $autoFocus; if ($autoFocus && $duplicateBehaviour !== \MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_QUIETLY_SET_NEW) { $form = & $this->form; $form::SetAutoFocusedFormField($form->GetId(), $this->name, $duplicateBehaviour); } return $this; }
[ "public", "function", "&", "SetAutoFocus", "(", "$", "autoFocus", "=", "TRUE", ",", "$", "duplicateBehaviour", "=", "\\", "MvcCore", "\\", "Ext", "\\", "Forms", "\\", "IField", "::", "AUTOFOCUS_DUPLICITY_EXCEPTION", ")", "{", "/** @var $this \\MvcCore\\Ext\\Forms\\IField */", "$", "this", "->", "autoFocus", "=", "$", "autoFocus", ";", "if", "(", "$", "autoFocus", "&&", "$", "duplicateBehaviour", "!==", "\\", "MvcCore", "\\", "Ext", "\\", "Forms", "\\", "IField", "::", "AUTOFOCUS_DUPLICITY_QUIETLY_SET_NEW", ")", "{", "$", "form", "=", "&", "$", "this", "->", "form", ";", "$", "form", "::", "SetAutoFocusedFormField", "(", "$", "form", "->", "GetId", "(", ")", ",", "$", "this", "->", "name", ",", "$", "duplicateBehaviour", ")", ";", "}", "return", "$", "this", ";", "}" ]
This Boolean attribute lets you specify that a form control should have input focus when the page loads. Only one form-associated element in a document can have this attribute specified. If there is already defined any previously configured autofocused form field, you can use second argument `$duplicateBehaviour` to solve the problem. Second argument possible values: - `0` (`\MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_EXCEPTION`) Default value, an exception is thrown when there is already defined other autofocused form element. - `1` (`\MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_UNSET_OLD_SET_NEW`) There will be removed previously defined autofocused element and configured new given one. - `-1` (`\MvcCore\Ext\Forms\IField::AUTOFOCUS_DUPLICITY_QUIETLY_SET_NEW`) There will be quietly configured another field autofocused. Be careful!!! This is not standard behaviour! @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autofocus @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attr-autofocus @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#attr-autofocus @param bool|NULL $autoFocus @param int $duplicateBehaviour @return \MvcCore\Ext\Forms\Field|\MvcCore\Ext\Forms\IField
[ "This", "Boolean", "attribute", "lets", "you", "specify", "that", "a", "form", "control", "should", "have", "input", "focus", "when", "the", "page", "loads", ".", "Only", "one", "form", "-", "associated", "element", "in", "a", "document", "can", "have", "this", "attribute", "specified", ".", "If", "there", "is", "already", "defined", "any", "previously", "configured", "autofocused", "form", "field", "you", "can", "use", "second", "argument", "$duplicateBehaviour", "to", "solve", "the", "problem", ".", "Second", "argument", "possible", "values", ":", "-", "0", "(", "\\", "MvcCore", "\\", "Ext", "\\", "Forms", "\\", "IField", "::", "AUTOFOCUS_DUPLICITY_EXCEPTION", ")", "Default", "value", "an", "exception", "is", "thrown", "when", "there", "is", "already", "defined", "other", "autofocused", "form", "element", ".", "-", "1", "(", "\\", "MvcCore", "\\", "Ext", "\\", "Forms", "\\", "IField", "::", "AUTOFOCUS_DUPLICITY_UNSET_OLD_SET_NEW", ")", "There", "will", "be", "removed", "previously", "defined", "autofocused", "element", "and", "configured", "new", "given", "one", ".", "-", "-", "1", "(", "\\", "MvcCore", "\\", "Ext", "\\", "Forms", "\\", "IField", "::", "AUTOFOCUS_DUPLICITY_QUIETLY_SET_NEW", ")", "There", "will", "be", "quietly", "configured", "another", "field", "autofocused", ".", "Be", "careful!!!", "This", "is", "not", "standard", "behaviour!" ]
train
https://github.com/mvccore/ext-form/blob/8d81a3c7326236702f37dc4b9d968907b3230b9f/src/MvcCore/Ext/Forms/Field/Props/AutoFocus.php#L92-L100
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.createButtonLink
public static function createButtonLink($label, $location, $confirm=false, $confMessage="") { $confirmAttribute = ""; if ($confirm) { $onclick = "return confirm('" . $confMessage . "')"; $confirmAttribute = 'onsubmit="' . $onclick . '"'; } $html = '<form method="post" action="' . $location . '" ' . $confirmAttribute . '>' . self::generateSubmitButton($label) . '</form>'; return $html; }
php
public static function createButtonLink($label, $location, $confirm=false, $confMessage="") { $confirmAttribute = ""; if ($confirm) { $onclick = "return confirm('" . $confMessage . "')"; $confirmAttribute = 'onsubmit="' . $onclick . '"'; } $html = '<form method="post" action="' . $location . '" ' . $confirmAttribute . '>' . self::generateSubmitButton($label) . '</form>'; return $html; }
[ "public", "static", "function", "createButtonLink", "(", "$", "label", ",", "$", "location", ",", "$", "confirm", "=", "false", ",", "$", "confMessage", "=", "\"\"", ")", "{", "$", "confirmAttribute", "=", "\"\"", ";", "if", "(", "$", "confirm", ")", "{", "$", "onclick", "=", "\"return confirm('\"", ".", "$", "confMessage", ".", "\"')\"", ";", "$", "confirmAttribute", "=", "'onsubmit=\"'", ".", "$", "onclick", ".", "'\"'", ";", "}", "$", "html", "=", "'<form method=\"post\" action=\"'", ".", "$", "location", ".", "'\" '", ".", "$", "confirmAttribute", ".", "'>'", ".", "self", "::", "generateSubmitButton", "(", "$", "label", ")", ".", "'</form>'", ";", "return", "$", "html", ";", "}" ]
Effectively generates a normal link, but rendered as a button. e.g <a href=''>; The main advantage is that you can specify a confirm message or create a better/different look. Note that this will be a form submit button and not a javascript button. @param label - the label to appear on the button. @param location - where you want the link to go @param confirm - set to true if you want a confirm dialogue to confirm. @param confMessage - if confirm set to true, this will be the message that is displayed. @return string - the generated html for the button.
[ "Effectively", "generates", "a", "normal", "link", "but", "rendered", "as", "a", "button", ".", "e", ".", "g", "<a", "href", "=", ">", ";", "The", "main", "advantage", "is", "that", "you", "can", "specify", "a", "confirm", "message", "or", "create", "a", "better", "/", "different", "look", ".", "Note", "that", "this", "will", "be", "a", "form", "submit", "button", "and", "not", "a", "javascript", "button", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L25-L44
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateAjaxButton
public static function generateAjaxButton($label, $postData, $updateButtonText=true, $onSuccess = '', $onError = '', $onAlways = '') { $ajaxParams = array( 'data' => $postData, 'type' => 'POST', 'dataType' => $postData ); $callbacks = ''; if ($updateButtonText) { $callbacks .= 'var originalText = this.value;' . PHP_EOL . 'this.value = "Updating...";' . PHP_EOL . 'ajaxRequest.fail(function(){this.value="Error"});' . PHP_EOL; 'ajaxRequest.done(function(){this.value="Complete"});' . PHP_EOL; 'var timeoutFunc = function(){this.value=originalText};' . PHP_EOL . 'ajaxRequest.done(function(){setTimeout(timeoutFunc, 2000)});' . PHP_EOL; } if ($onSuccess != '') { $callbacks .= 'ajaxRequest.done(' . $onSuccess . ');' . PHP_EOL; } if ($onError != '') { $callbacks .= 'ajaxRequest.fail(' . $onError . ');' . PHP_EOL; } if ($onAlways != '') { $callbacks .= 'ajaxRequest.always(' . $onAlways . ');' . PHP_EOL; } # Important that only double quotes appear within onclick not singles. $onclick = 'var ajaxUrl = "ajax_handler.php";' . PHP_EOL . 'var ajaxParams = ' . json_encode($ajaxParams) . ';' . PHP_EOL . 'var ajaxRequest = $.ajax(ajaxUrl, ajaxParams);' . PHP_EOL . $callbacks; # Have to use an 'input type=button' rather than button here because we # want to change value property $html = "<input " . "type='button' " . "value='" . $label . "' " . "onclick='" . $onclick . "' " . "/>"; return $html; }
php
public static function generateAjaxButton($label, $postData, $updateButtonText=true, $onSuccess = '', $onError = '', $onAlways = '') { $ajaxParams = array( 'data' => $postData, 'type' => 'POST', 'dataType' => $postData ); $callbacks = ''; if ($updateButtonText) { $callbacks .= 'var originalText = this.value;' . PHP_EOL . 'this.value = "Updating...";' . PHP_EOL . 'ajaxRequest.fail(function(){this.value="Error"});' . PHP_EOL; 'ajaxRequest.done(function(){this.value="Complete"});' . PHP_EOL; 'var timeoutFunc = function(){this.value=originalText};' . PHP_EOL . 'ajaxRequest.done(function(){setTimeout(timeoutFunc, 2000)});' . PHP_EOL; } if ($onSuccess != '') { $callbacks .= 'ajaxRequest.done(' . $onSuccess . ');' . PHP_EOL; } if ($onError != '') { $callbacks .= 'ajaxRequest.fail(' . $onError . ');' . PHP_EOL; } if ($onAlways != '') { $callbacks .= 'ajaxRequest.always(' . $onAlways . ');' . PHP_EOL; } # Important that only double quotes appear within onclick not singles. $onclick = 'var ajaxUrl = "ajax_handler.php";' . PHP_EOL . 'var ajaxParams = ' . json_encode($ajaxParams) . ';' . PHP_EOL . 'var ajaxRequest = $.ajax(ajaxUrl, ajaxParams);' . PHP_EOL . $callbacks; # Have to use an 'input type=button' rather than button here because we # want to change value property $html = "<input " . "type='button' " . "value='" . $label . "' " . "onclick='" . $onclick . "' " . "/>"; return $html; }
[ "public", "static", "function", "generateAjaxButton", "(", "$", "label", ",", "$", "postData", ",", "$", "updateButtonText", "=", "true", ",", "$", "onSuccess", "=", "''", ",", "$", "onError", "=", "''", ",", "$", "onAlways", "=", "''", ")", "{", "$", "ajaxParams", "=", "array", "(", "'data'", "=>", "$", "postData", ",", "'type'", "=>", "'POST'", ",", "'dataType'", "=>", "$", "postData", ")", ";", "$", "callbacks", "=", "''", ";", "if", "(", "$", "updateButtonText", ")", "{", "$", "callbacks", ".=", "'var originalText = this.value;'", ".", "PHP_EOL", ".", "'this.value = \"Updating...\";'", ".", "PHP_EOL", ".", "'ajaxRequest.fail(function(){this.value=\"Error\"});'", ".", "PHP_EOL", ";", "'ajaxRequest.done(function(){this.value=\"Complete\"});'", ".", "PHP_EOL", ";", "'var timeoutFunc = function(){this.value=originalText};'", ".", "PHP_EOL", ".", "'ajaxRequest.done(function(){setTimeout(timeoutFunc, 2000)});'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "onSuccess", "!=", "''", ")", "{", "$", "callbacks", ".=", "'ajaxRequest.done('", ".", "$", "onSuccess", ".", "');'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "onError", "!=", "''", ")", "{", "$", "callbacks", ".=", "'ajaxRequest.fail('", ".", "$", "onError", ".", "');'", ".", "PHP_EOL", ";", "}", "if", "(", "$", "onAlways", "!=", "''", ")", "{", "$", "callbacks", ".=", "'ajaxRequest.always('", ".", "$", "onAlways", ".", "');'", ".", "PHP_EOL", ";", "}", "# Important that only double quotes appear within onclick not singles.", "$", "onclick", "=", "'var ajaxUrl = \"ajax_handler.php\";'", ".", "PHP_EOL", ".", "'var ajaxParams = '", ".", "json_encode", "(", "$", "ajaxParams", ")", ".", "';'", ".", "PHP_EOL", ".", "'var ajaxRequest = $.ajax(ajaxUrl, ajaxParams);'", ".", "PHP_EOL", ".", "$", "callbacks", ";", "# Have to use an 'input type=button' rather than button here because we ", "# want to change value property", "$", "html", "=", "\"<input \"", ".", "\"type='button' \"", ".", "\"value='\"", ".", "$", "label", ".", "\"' \"", ".", "\"onclick='\"", ".", "$", "onclick", ".", "\"' \"", ".", "\"/>\"", ";", "return", "$", "html", ";", "}" ]
Generates a button that triggers an ajax request. (using POST and expecting json response) @param string label - label to appear on the ajax button. e.g. 'click me' @param postData - associative array of name/value pairs to send in the ajax request. @param updateButtonText - flag for whether the buttons text should change to reflect status @param onSuccess - name of javascript function to run upon successful request @param onError - name of javascript function to run if there was an ajax comms error. @param onAlways - name of javascript function to run if success or error. @return string - the generated html for the ajax button.
[ "Generates", "a", "button", "that", "triggers", "an", "ajax", "request", ".", "(", "using", "POST", "and", "expecting", "json", "response", ")" ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L59-L117
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateAjaxTextfield
public static function generateAjaxTextfield($fieldName, $staticData = array(), $currentValue = "", $placeholder = '', $offscreenSubmit = true) { $html = "<form action='' onsubmit='ajaxPostForm(this, \"" . $fieldName . "\")'>" . self::generateHiddenInputFields($staticData) . self::generateInputField($fieldName, 'text', $currentValue, $placeholder) . self::generateSubmitButton('', $offscreenSubmit) . '</form>'; return $html; }
php
public static function generateAjaxTextfield($fieldName, $staticData = array(), $currentValue = "", $placeholder = '', $offscreenSubmit = true) { $html = "<form action='' onsubmit='ajaxPostForm(this, \"" . $fieldName . "\")'>" . self::generateHiddenInputFields($staticData) . self::generateInputField($fieldName, 'text', $currentValue, $placeholder) . self::generateSubmitButton('', $offscreenSubmit) . '</form>'; return $html; }
[ "public", "static", "function", "generateAjaxTextfield", "(", "$", "fieldName", ",", "$", "staticData", "=", "array", "(", ")", ",", "$", "currentValue", "=", "\"\"", ",", "$", "placeholder", "=", "''", ",", "$", "offscreenSubmit", "=", "true", ")", "{", "$", "html", "=", "\"<form action='' onsubmit='ajaxPostForm(this, \\\"\"", ".", "$", "fieldName", ".", "\"\\\")'>\"", ".", "self", "::", "generateHiddenInputFields", "(", "$", "staticData", ")", ".", "self", "::", "generateInputField", "(", "$", "fieldName", ",", "'text'", ",", "$", "currentValue", ",", "$", "placeholder", ")", ".", "self", "::", "generateSubmitButton", "(", "''", ",", "$", "offscreenSubmit", ")", ".", "'</form>'", ";", "return", "$", "html", ";", "}" ]
Generates an textfield (not textarea) that can be submitted by hitting return/enter. @param string label - the display text to put next to the input field. @param string name - the name/id of the generated input field. @param onSubmit - javascript string of what to run when the buttons onClick is activated. @param value - an optional parameter of the default/current value to stick in the input box. @return stringString - the generated html to create this submittable row.
[ "Generates", "an", "textfield", "(", "not", "textarea", ")", "that", "can", "be", "submitted", "by", "hitting", "return", "/", "enter", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L131-L145
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateButton
public static function generateButton($label, $functionName, $parameters = array(), $confirm = false, $confMessage = "") { $parameterString = ""; if (count($parameters) > 0) { foreach ($parameters as $parameter) { $literals = array('this', 'true', 'false'); $lowerCaseParam = strtolower($parameter); # Handle cases where we want to pass `this`, 'true' or 'false'. if (in_array($lowerCaseParam, $literals)) { $parameterString .= $parameter . ", "; } else { $parameterString .= "'" . $parameter . "', "; } } // Remove the last character which should be an excess , $parameterString = substr($parameterString, 0, -2); } $onclick = $functionName . "(" . $parameterString . ")"; if ($confirm) { $onclick = "if (confirm('" . $confMessage . "')){" . $onclick . "}"; } $onclick = '"' . $onclick . '"'; $htmlString = '<button onclick=' . $onclick . '>' . $label . '</button>'; return $htmlString; }
php
public static function generateButton($label, $functionName, $parameters = array(), $confirm = false, $confMessage = "") { $parameterString = ""; if (count($parameters) > 0) { foreach ($parameters as $parameter) { $literals = array('this', 'true', 'false'); $lowerCaseParam = strtolower($parameter); # Handle cases where we want to pass `this`, 'true' or 'false'. if (in_array($lowerCaseParam, $literals)) { $parameterString .= $parameter . ", "; } else { $parameterString .= "'" . $parameter . "', "; } } // Remove the last character which should be an excess , $parameterString = substr($parameterString, 0, -2); } $onclick = $functionName . "(" . $parameterString . ")"; if ($confirm) { $onclick = "if (confirm('" . $confMessage . "')){" . $onclick . "}"; } $onclick = '"' . $onclick . '"'; $htmlString = '<button onclick=' . $onclick . '>' . $label . '</button>'; return $htmlString; }
[ "public", "static", "function", "generateButton", "(", "$", "label", ",", "$", "functionName", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "confirm", "=", "false", ",", "$", "confMessage", "=", "\"\"", ")", "{", "$", "parameterString", "=", "\"\"", ";", "if", "(", "count", "(", "$", "parameters", ")", ">", "0", ")", "{", "foreach", "(", "$", "parameters", "as", "$", "parameter", ")", "{", "$", "literals", "=", "array", "(", "'this'", ",", "'true'", ",", "'false'", ")", ";", "$", "lowerCaseParam", "=", "strtolower", "(", "$", "parameter", ")", ";", "# Handle cases where we want to pass `this`, 'true' or 'false'.", "if", "(", "in_array", "(", "$", "lowerCaseParam", ",", "$", "literals", ")", ")", "{", "$", "parameterString", ".=", "$", "parameter", ".", "\", \"", ";", "}", "else", "{", "$", "parameterString", ".=", "\"'\"", ".", "$", "parameter", ".", "\"', \"", ";", "}", "}", "// Remove the last character which should be an excess ,", "$", "parameterString", "=", "substr", "(", "$", "parameterString", ",", "0", ",", "-", "2", ")", ";", "}", "$", "onclick", "=", "$", "functionName", ".", "\"(\"", ".", "$", "parameterString", ".", "\")\"", ";", "if", "(", "$", "confirm", ")", "{", "$", "onclick", "=", "\"if (confirm('\"", ".", "$", "confMessage", ".", "\"')){\"", ".", "$", "onclick", ".", "\"}\"", ";", "}", "$", "onclick", "=", "'\"'", ".", "$", "onclick", ".", "'\"'", ";", "$", "htmlString", "=", "'<button onclick='", ".", "$", "onclick", ".", "'>'", ".", "$", "label", ".", "'</button>'", ";", "return", "$", "htmlString", ";", "}" ]
Generates the html for a button which runs the provided javascript functionName when clicked. This is a button element e.g. <button> and NOT an input type='button'. There are subtle differences, but the main one is that the text for a button is NOT changed by changingt the .value but the .textContent attribute, and input type buttons are supposed to be inside a form and will submit data with the form. Both can have an onclick. @param string label - text user can see on the button @param string functionName - name of javascript function to call when the button is clicked. @param array parameters - parameters to pass to the js function. @param bool confirm - whether the user needs to confirm that they meant to click the button. @param string confMessage - if confirm set to true, the confirmation message as it will appear. @return stringString - the html for the button.
[ "Generates", "the", "html", "for", "a", "button", "which", "runs", "the", "provided", "javascript", "functionName", "when", "clicked", ".", "This", "is", "a", "button", "element", "e", ".", "g", ".", "<button", ">", "and", "NOT", "an", "input", "type", "=", "button", ".", "There", "are", "subtle", "differences", "but", "the", "main", "one", "is", "that", "the", "text", "for", "a", "button", "is", "NOT", "changed", "by", "changingt", "the", ".", "value", "but", "the", ".", "textContent", "attribute", "and", "input", "type", "buttons", "are", "supposed", "to", "be", "inside", "a", "form", "and", "will", "submit", "data", "with", "the", "form", ".", "Both", "can", "have", "an", "onclick", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L168-L213
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateHiddenInputFields
public static function generateHiddenInputFields($pairs) { $html = ''; foreach ($pairs as $name => $value) { $html .= self::generateHiddenInputField($name, $value); } return $html; }
php
public static function generateHiddenInputFields($pairs) { $html = ''; foreach ($pairs as $name => $value) { $html .= self::generateHiddenInputField($name, $value); } return $html; }
[ "public", "static", "function", "generateHiddenInputFields", "(", "$", "pairs", ")", "{", "$", "html", "=", "''", ";", "foreach", "(", "$", "pairs", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "html", ".=", "self", "::", "generateHiddenInputField", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "html", ";", "}" ]
Given an array of name/value pairs, this will generate all the hidden input fields for them to be inserted into a form. @param pairs - assoc array of name/value pairs to post @return string - the generated html.
[ "Given", "an", "array", "of", "name", "/", "value", "pairs", "this", "will", "generate", "all", "the", "hidden", "input", "fields", "for", "them", "to", "be", "inserted", "into", "a", "form", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L237-L247
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateSubmittableTextfield
public static function generateSubmittableTextfield($fieldName, $postfields = array(), $value = "", $placeholder = '', $formId = '') { if ($formId != '') { $formId = ' id="' . $formId . '" '; } $htmlString = '<form method="POST" action="" ' . $formId . '>' . self::generateInputField($fieldName, 'text', $value, $placeholder) . self::generateHiddenInputFields($postfields) . self::generateSubmitButton('submit', $offscreen=true) . "</form>"; return $htmlString; }
php
public static function generateSubmittableTextfield($fieldName, $postfields = array(), $value = "", $placeholder = '', $formId = '') { if ($formId != '') { $formId = ' id="' . $formId . '" '; } $htmlString = '<form method="POST" action="" ' . $formId . '>' . self::generateInputField($fieldName, 'text', $value, $placeholder) . self::generateHiddenInputFields($postfields) . self::generateSubmitButton('submit', $offscreen=true) . "</form>"; return $htmlString; }
[ "public", "static", "function", "generateSubmittableTextfield", "(", "$", "fieldName", ",", "$", "postfields", "=", "array", "(", ")", ",", "$", "value", "=", "\"\"", ",", "$", "placeholder", "=", "''", ",", "$", "formId", "=", "''", ")", "{", "if", "(", "$", "formId", "!=", "''", ")", "{", "$", "formId", "=", "' id=\"'", ".", "$", "formId", ".", "'\" '", ";", "}", "$", "htmlString", "=", "'<form method=\"POST\" action=\"\" '", ".", "$", "formId", ".", "'>'", ".", "self", "::", "generateInputField", "(", "$", "fieldName", ",", "'text'", ",", "$", "value", ",", "$", "placeholder", ")", ".", "self", "::", "generateHiddenInputFields", "(", "$", "postfields", ")", ".", "self", "::", "generateSubmitButton", "(", "'submit'", ",", "$", "offscreen", "=", "true", ")", ".", "\"</form>\"", ";", "return", "$", "htmlString", ";", "}" ]
Generates an textfield (not textarea) that can be submitted by hitting return/enter. @param label - the display text to put next to the input field. @param name - the name/id of the generated input field. @param onSubmit - javascript string of what to run when the buttons onClick is activated. @param value - an optional parameter of the default/current value to stick in the input box. @return stringString - the generated html to create this submittable row.
[ "Generates", "an", "textfield", "(", "not", "textarea", ")", "that", "can", "be", "submitted", "by", "hitting", "return", "/", "enter", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L298-L317
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateButtonForm
public static function generateButtonForm($label, $postfields, $postUrl='') { $html = '<form method="POST" action="' . $postUrl . '">' . self::generateHiddenInputFields($postfields) . self::generateSubmitButton($label) . '</form>'; return $html; }
php
public static function generateButtonForm($label, $postfields, $postUrl='') { $html = '<form method="POST" action="' . $postUrl . '">' . self::generateHiddenInputFields($postfields) . self::generateSubmitButton($label) . '</form>'; return $html; }
[ "public", "static", "function", "generateButtonForm", "(", "$", "label", ",", "$", "postfields", ",", "$", "postUrl", "=", "''", ")", "{", "$", "html", "=", "'<form method=\"POST\" action=\"'", ".", "$", "postUrl", ".", "'\">'", ".", "self", "::", "generateHiddenInputFields", "(", "$", "postfields", ")", ".", "self", "::", "generateSubmitButton", "(", "$", "label", ")", ".", "'</form>'", ";", "return", "$", "html", ";", "}" ]
Generates what appears to be just a button but is actually a submittable form that will post itself or the specified postUrl. @param label - the text to display on the button @param postfields - name/value pairs of data posted when the form submits @param postUrl - optional address where the form should be posted. @return string - the generated html for the button form.
[ "Generates", "what", "appears", "to", "be", "just", "a", "button", "but", "is", "actually", "a", "submittable", "form", "that", "will", "post", "itself", "or", "the", "specified", "postUrl", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L330-L338
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateInputField
public static function generateInputField($name, $type, $currentValue="", $placeholder="") { $type = strtolower($type); if ($type === 'button') { $msg = 'Developer error: please use the generateButton function ' . 'instead to create buttons.'; throw new \Exception($msg); } if ($type == 'submit') { $msg = 'Developer error: please use the generateSubmitButton ' . 'function instead to create submit buttons.'; throw new \Exception($msg); } $html = '<input ' . 'type="' . $type . '" ' . 'name="' . $name .'" ' . 'placeholder="' . $placeholder . '" ' . 'value="' . $currentValue . '" >'; return $html; }
php
public static function generateInputField($name, $type, $currentValue="", $placeholder="") { $type = strtolower($type); if ($type === 'button') { $msg = 'Developer error: please use the generateButton function ' . 'instead to create buttons.'; throw new \Exception($msg); } if ($type == 'submit') { $msg = 'Developer error: please use the generateSubmitButton ' . 'function instead to create submit buttons.'; throw new \Exception($msg); } $html = '<input ' . 'type="' . $type . '" ' . 'name="' . $name .'" ' . 'placeholder="' . $placeholder . '" ' . 'value="' . $currentValue . '" >'; return $html; }
[ "public", "static", "function", "generateInputField", "(", "$", "name", ",", "$", "type", ",", "$", "currentValue", "=", "\"\"", ",", "$", "placeholder", "=", "\"\"", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "$", "type", "===", "'button'", ")", "{", "$", "msg", "=", "'Developer error: please use the generateButton function '", ".", "'instead to create buttons.'", ";", "throw", "new", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "if", "(", "$", "type", "==", "'submit'", ")", "{", "$", "msg", "=", "'Developer error: please use the generateSubmitButton '", ".", "'function instead to create submit buttons.'", ";", "throw", "new", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "$", "html", "=", "'<input '", ".", "'type=\"'", ".", "$", "type", ".", "'\" '", ".", "'name=\"'", ".", "$", "name", ".", "'\" '", ".", "'placeholder=\"'", ".", "$", "placeholder", ".", "'\" '", ".", "'value=\"'", ".", "$", "currentValue", ".", "'\" >'", ";", "return", "$", "html", ";", "}" ]
Generates a html input field @param string name - name of the input field so we can retrieve the value with GET or POST @param string type - type of input field. e.g. text, password, checkbox should not be 'submit' or 'button', use other funcs for those @param string currentValue - (optional) the current value of the input field. @param string placeholder - (optional) specify the placeholder text @return string - the generated html.
[ "Generates", "a", "html", "input", "field" ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L354-L382
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateTextArea
public static function generateTextArea($name, $currentValue = "", $placeholder = "", $class = "", $rows = "", $cols = "", $id = "", $disabled = false) { $idAttribute = ''; $rowAttribute = ''; $colsAttribute = ''; $disabledAttribute = ''; if ($rows != "") { $rowAttribute = ' rows="' . $rows . '" '; } if ($cols != "") { $colsAttribute = ' cols="' . $cols . '" '; } if ($id != "") { $idAttribute = ' id="' . $id . '" '; } if ($disabled) { $disabledAttribute = ' disabled '; } $html = '<textarea ' . 'name="' . $name . '" ' . 'class="' . $class . '" ' . 'placeholder="' . $placeholder . '" ' . $idAttribute . $rowAttribute . $colsAttribute . $disabledAttribute . '>' . $currentValue . '</textarea>'; return $html; }
php
public static function generateTextArea($name, $currentValue = "", $placeholder = "", $class = "", $rows = "", $cols = "", $id = "", $disabled = false) { $idAttribute = ''; $rowAttribute = ''; $colsAttribute = ''; $disabledAttribute = ''; if ($rows != "") { $rowAttribute = ' rows="' . $rows . '" '; } if ($cols != "") { $colsAttribute = ' cols="' . $cols . '" '; } if ($id != "") { $idAttribute = ' id="' . $id . '" '; } if ($disabled) { $disabledAttribute = ' disabled '; } $html = '<textarea ' . 'name="' . $name . '" ' . 'class="' . $class . '" ' . 'placeholder="' . $placeholder . '" ' . $idAttribute . $rowAttribute . $colsAttribute . $disabledAttribute . '>' . $currentValue . '</textarea>'; return $html; }
[ "public", "static", "function", "generateTextArea", "(", "$", "name", ",", "$", "currentValue", "=", "\"\"", ",", "$", "placeholder", "=", "\"\"", ",", "$", "class", "=", "\"\"", ",", "$", "rows", "=", "\"\"", ",", "$", "cols", "=", "\"\"", ",", "$", "id", "=", "\"\"", ",", "$", "disabled", "=", "false", ")", "{", "$", "idAttribute", "=", "''", ";", "$", "rowAttribute", "=", "''", ";", "$", "colsAttribute", "=", "''", ";", "$", "disabledAttribute", "=", "''", ";", "if", "(", "$", "rows", "!=", "\"\"", ")", "{", "$", "rowAttribute", "=", "' rows=\"'", ".", "$", "rows", ".", "'\" '", ";", "}", "if", "(", "$", "cols", "!=", "\"\"", ")", "{", "$", "colsAttribute", "=", "' cols=\"'", ".", "$", "cols", ".", "'\" '", ";", "}", "if", "(", "$", "id", "!=", "\"\"", ")", "{", "$", "idAttribute", "=", "' id=\"'", ".", "$", "id", ".", "'\" '", ";", "}", "if", "(", "$", "disabled", ")", "{", "$", "disabledAttribute", "=", "' disabled '", ";", "}", "$", "html", "=", "'<textarea '", ".", "'name=\"'", ".", "$", "name", ".", "'\" '", ".", "'class=\"'", ".", "$", "class", ".", "'\" '", ".", "'placeholder=\"'", ".", "$", "placeholder", ".", "'\" '", ".", "$", "idAttribute", ".", "$", "rowAttribute", ".", "$", "colsAttribute", ".", "$", "disabledAttribute", ".", "'>'", ".", "$", "currentValue", ".", "'</textarea>'", ";", "return", "$", "html", ";", "}" ]
Generates a textaread form element @param string name - name attribute of the textarea @param currentValue - text that should appear in the texatrea as the current value. @param string placeholder - any text that should show in the textarea if there is no value. @param string class - class to specify for the textarea (style) @param int rows - number of rows the textarea should have @param int cols - number of columns (width) of the textarea @param string id (optional) - if set the id will be set to this. @param bool disabled @return string - the generated html for the textarea.
[ "Generates", "a", "textaread", "form", "element" ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L401-L449
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateInputFieldRow
public static function generateInputFieldRow($name, $type, $label, $value="") { $html = "<div class ='row'>" . "<div class='label'>" . $label . "</div>" . "<div class='inputs'>" . self::generateInputField($name, $type, $value) . "</div>" . "</div>"; return $html; }
php
public static function generateInputFieldRow($name, $type, $label, $value="") { $html = "<div class ='row'>" . "<div class='label'>" . $label . "</div>" . "<div class='inputs'>" . self::generateInputField($name, $type, $value) . "</div>" . "</div>"; return $html; }
[ "public", "static", "function", "generateInputFieldRow", "(", "$", "name", ",", "$", "type", ",", "$", "label", ",", "$", "value", "=", "\"\"", ")", "{", "$", "html", "=", "\"<div class ='row'>\"", ".", "\"<div class='label'>\"", ".", "$", "label", ".", "\"</div>\"", ".", "\"<div class='inputs'>\"", ".", "self", "::", "generateInputField", "(", "$", "name", ",", "$", "type", ",", "$", "value", ")", ".", "\"</div>\"", ".", "\"</div>\"", ";", "return", "$", "html", ";", "}" ]
Generates an input field row with a label beside it (making placeholder usage pointless). This is useful for when you are displaying input fields with existing values. When this is the case, placeholders would not be visible, thus useless, but the user still needs to know what the fields represent. @param name - the name of the fild (name we use to get value from GET / POST) @param type - text, password, submit @param label - the human readable name to display next to the input field. @param value - the current value of the input field. @return string - the generated html
[ "Generates", "an", "input", "field", "row", "with", "a", "label", "beside", "it", "(", "making", "placeholder", "usage", "pointless", ")", ".", "This", "is", "useful", "for", "when", "you", "are", "displaying", "input", "fields", "with", "existing", "values", ".", "When", "this", "is", "the", "case", "placeholders", "would", "not", "be", "visible", "thus", "useless", "but", "the", "user", "still", "needs", "to", "know", "what", "the", "fields", "represent", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L465-L476
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateDropDownMenu
public static function generateDropDownMenu($name, $currentValue, $options, $rowSize = 1, $multipleSelect = false, $onChange = "", $id = "") { $isAssoc = self::isAssoc($options); $optionsHtml = ""; foreach ($options as $key => $option) { $optionValue = $option; $optionLabel = $option; if ($isAssoc) { $optionValue = $key; } $selectedAttribute = ""; if ($optionValue == $currentValue) { $selectedAttribute = " selected='true' "; } $optionsHtml .= "<option " . $selectedAttribute . 'value="' . $optionValue . '"' . ">" . $optionLabel . "</option>" . PHP_EOL; } $nameAttribute = " name='" . $name . "' "; $idAttribute = ""; if ($id != "") { $idAttribute = " id='" . $name . "' "; } $sizeAttribute = " size='" . $rowSize . "' "; $onChangeAttribute = ""; if ($onChange != "") { $onChangeAttribute = " onchange='" . $onChange . "' "; } $multipleAttribute = ""; if ($multipleSelect) { $multipleAttribute = " multiple "; } $htmlString = "<select" . $idAttribute . $nameAttribute . $sizeAttribute . $onChangeAttribute . $multipleAttribute . ">" . $optionsHtml . "</select>"; return $htmlString; }
php
public static function generateDropDownMenu($name, $currentValue, $options, $rowSize = 1, $multipleSelect = false, $onChange = "", $id = "") { $isAssoc = self::isAssoc($options); $optionsHtml = ""; foreach ($options as $key => $option) { $optionValue = $option; $optionLabel = $option; if ($isAssoc) { $optionValue = $key; } $selectedAttribute = ""; if ($optionValue == $currentValue) { $selectedAttribute = " selected='true' "; } $optionsHtml .= "<option " . $selectedAttribute . 'value="' . $optionValue . '"' . ">" . $optionLabel . "</option>" . PHP_EOL; } $nameAttribute = " name='" . $name . "' "; $idAttribute = ""; if ($id != "") { $idAttribute = " id='" . $name . "' "; } $sizeAttribute = " size='" . $rowSize . "' "; $onChangeAttribute = ""; if ($onChange != "") { $onChangeAttribute = " onchange='" . $onChange . "' "; } $multipleAttribute = ""; if ($multipleSelect) { $multipleAttribute = " multiple "; } $htmlString = "<select" . $idAttribute . $nameAttribute . $sizeAttribute . $onChangeAttribute . $multipleAttribute . ">" . $optionsHtml . "</select>"; return $htmlString; }
[ "public", "static", "function", "generateDropDownMenu", "(", "$", "name", ",", "$", "currentValue", ",", "$", "options", ",", "$", "rowSize", "=", "1", ",", "$", "multipleSelect", "=", "false", ",", "$", "onChange", "=", "\"\"", ",", "$", "id", "=", "\"\"", ")", "{", "$", "isAssoc", "=", "self", "::", "isAssoc", "(", "$", "options", ")", ";", "$", "optionsHtml", "=", "\"\"", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "option", ")", "{", "$", "optionValue", "=", "$", "option", ";", "$", "optionLabel", "=", "$", "option", ";", "if", "(", "$", "isAssoc", ")", "{", "$", "optionValue", "=", "$", "key", ";", "}", "$", "selectedAttribute", "=", "\"\"", ";", "if", "(", "$", "optionValue", "==", "$", "currentValue", ")", "{", "$", "selectedAttribute", "=", "\" selected='true' \"", ";", "}", "$", "optionsHtml", ".=", "\"<option \"", ".", "$", "selectedAttribute", ".", "'value=\"'", ".", "$", "optionValue", ".", "'\"'", ".", "\">\"", ".", "$", "optionLabel", ".", "\"</option>\"", ".", "PHP_EOL", ";", "}", "$", "nameAttribute", "=", "\" name='\"", ".", "$", "name", ".", "\"' \"", ";", "$", "idAttribute", "=", "\"\"", ";", "if", "(", "$", "id", "!=", "\"\"", ")", "{", "$", "idAttribute", "=", "\" id='\"", ".", "$", "name", ".", "\"' \"", ";", "}", "$", "sizeAttribute", "=", "\" size='\"", ".", "$", "rowSize", ".", "\"' \"", ";", "$", "onChangeAttribute", "=", "\"\"", ";", "if", "(", "$", "onChange", "!=", "\"\"", ")", "{", "$", "onChangeAttribute", "=", "\" onchange='\"", ".", "$", "onChange", ".", "\"' \"", ";", "}", "$", "multipleAttribute", "=", "\"\"", ";", "if", "(", "$", "multipleSelect", ")", "{", "$", "multipleAttribute", "=", "\" multiple \"", ";", "}", "$", "htmlString", "=", "\"<select\"", ".", "$", "idAttribute", ".", "$", "nameAttribute", ".", "$", "sizeAttribute", ".", "$", "onChangeAttribute", ".", "$", "multipleAttribute", ".", "\">\"", ".", "$", "optionsHtml", ".", "\"</select>\"", ";", "return", "$", "htmlString", ";", "}" ]
Generates an html drop down menu for forms. If the array of drop down options passed in is an array, then the value posted will be the key, and the display label for the option will be the value. @param name - name to assign to the input field (the lookup name when retrieving POST) @param currentValue - the current/default/selected value of that attribute. @param options - array of all the possible options/values that the user can pick if this is an associative array, the key will be used as the value. @param rowSize - manually set the number of rows to show @param multipleSelect - optional - set true if user should be able to select multiple values. @param onChange - specify javascript that should run when the dropdown changes. Note that this should not contain the text onchange= and if quotes are used (for js function parameters, then these should be encapsulated in double quotes. @param id - (optional) set an id for the dropdown menu. @return stringString - the generated html to be put on the page.
[ "Generates", "an", "html", "drop", "down", "menu", "for", "forms", ".", "If", "the", "array", "of", "drop", "down", "options", "passed", "in", "is", "an", "array", "then", "the", "value", "posted", "will", "be", "the", "key", "and", "the", "display", "label", "for", "the", "option", "will", "be", "the", "value", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L499-L570
iRAP-software/package-core-libs
src/HtmlGenerator.php
HtmlGenerator.generateSubmitButton
public static function generateSubmitButton($label="Submit", $offscreen=false) { $styleAttribute = ''; if ($offscreen) { $styleAttribute = ' style="position: absolute; left: -9999px" '; } $html = '<input ' . 'type="submit" ' . 'value="' . $label . '" ' . $styleAttribute . '/>'; return $html; }
php
public static function generateSubmitButton($label="Submit", $offscreen=false) { $styleAttribute = ''; if ($offscreen) { $styleAttribute = ' style="position: absolute; left: -9999px" '; } $html = '<input ' . 'type="submit" ' . 'value="' . $label . '" ' . $styleAttribute . '/>'; return $html; }
[ "public", "static", "function", "generateSubmitButton", "(", "$", "label", "=", "\"Submit\"", ",", "$", "offscreen", "=", "false", ")", "{", "$", "styleAttribute", "=", "''", ";", "if", "(", "$", "offscreen", ")", "{", "$", "styleAttribute", "=", "' style=\"position: absolute; left: -9999px\" '", ";", "}", "$", "html", "=", "'<input '", ".", "'type=\"submit\" '", ".", "'value=\"'", ".", "$", "label", ".", "'\" '", ".", "$", "styleAttribute", ".", "'/>'", ";", "return", "$", "html", ";", "}" ]
Generates a submit button for a form. @param string label - The text that will be displayed over the button @param bool offscreen - render the submit button offscreen so that it does not appear within the form, but allows the form to be submitted by hitting enter. Setting display:none would work in FF but not chrome @return string - The html code for the button
[ "Generates", "a", "submit", "button", "for", "a", "form", "." ]
train
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/HtmlGenerator.php#L585-L602
codenamephp/prototype.utils
src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php
TemplateCopy.copy
public function copy(string $templateFolder, string $targetFolder, array $context) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($templateFolder, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); foreach($iterator as $file) { $targetPath = $this->getTargetPath($templateFolder, $targetFolder, $this->replacePathVariables($file->getPathname(), $context)); if($file->isDir()) { $this->getFilesystem()->mkdir($targetPath); }else { $this->getFilesystem()->dumpFile($targetPath, $this->getTwig()->render($file->getPathname(), $context)); } } }
php
public function copy(string $templateFolder, string $targetFolder, array $context) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($templateFolder, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); foreach($iterator as $file) { $targetPath = $this->getTargetPath($templateFolder, $targetFolder, $this->replacePathVariables($file->getPathname(), $context)); if($file->isDir()) { $this->getFilesystem()->mkdir($targetPath); }else { $this->getFilesystem()->dumpFile($targetPath, $this->getTwig()->render($file->getPathname(), $context)); } } }
[ "public", "function", "copy", "(", "string", "$", "templateFolder", ",", "string", "$", "targetFolder", ",", "array", "$", "context", ")", "{", "$", "iterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "templateFolder", ",", "\\", "FilesystemIterator", "::", "KEY_AS_PATHNAME", "|", "\\", "FilesystemIterator", "::", "CURRENT_AS_FILEINFO", "|", "\\", "FilesystemIterator", "::", "SKIP_DOTS", ")", ",", "\\", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "file", ")", "{", "$", "targetPath", "=", "$", "this", "->", "getTargetPath", "(", "$", "templateFolder", ",", "$", "targetFolder", ",", "$", "this", "->", "replacePathVariables", "(", "$", "file", "->", "getPathname", "(", ")", ",", "$", "context", ")", ")", ";", "if", "(", "$", "file", "->", "isDir", "(", ")", ")", "{", "$", "this", "->", "getFilesystem", "(", ")", "->", "mkdir", "(", "$", "targetPath", ")", ";", "}", "else", "{", "$", "this", "->", "getFilesystem", "(", ")", "->", "dumpFile", "(", "$", "targetPath", ",", "$", "this", "->", "getTwig", "(", ")", "->", "render", "(", "$", "file", "->", "getPathname", "(", ")", ",", "$", "context", ")", ")", ";", "}", "}", "}" ]
Recursivly iterates over the contents in the given templateFolder, building the targetPath while replaceing variables in the path. If the current item is a directory, it is created respecting the current umask. If the current item is a file, it will be copied by rendering it throgh twig with the given context, so all twig variables will be replaced with the context values. The result is dumped into the target file. @param string $templateFolder @param string $targetFolder @param string[string] $context
[ "Recursivly", "iterates", "over", "the", "contents", "in", "the", "given", "templateFolder", "building", "the", "targetPath", "while", "replaceing", "variables", "in", "the", "path", "." ]
train
https://github.com/codenamephp/prototype.utils/blob/aeb81e1e03624534e8b3e38d6466efda04e435d6/src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php#L98-L110
codenamephp/prototype.utils
src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php
TemplateCopy.replacePathVariables
public function replacePathVariables(string $path, array $variables): string { $newPath = $path; foreach($variables as $name => $value) { $newPath = str_replace(sprintf('__%s__', $name), $value, $newPath); } return $newPath; }
php
public function replacePathVariables(string $path, array $variables): string { $newPath = $path; foreach($variables as $name => $value) { $newPath = str_replace(sprintf('__%s__', $name), $value, $newPath); } return $newPath; }
[ "public", "function", "replacePathVariables", "(", "string", "$", "path", ",", "array", "$", "variables", ")", ":", "string", "{", "$", "newPath", "=", "$", "path", ";", "foreach", "(", "$", "variables", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "newPath", "=", "str_replace", "(", "sprintf", "(", "'__%s__'", ",", "$", "name", ")", ",", "$", "value", ",", "$", "newPath", ")", ";", "}", "return", "$", "newPath", ";", "}" ]
Replaces the variables in the path with the values from the variables array. The variables must be in form __key__ to be found. The same variable can occure multiple times in the path. Example: /some/path/__var1__/some/file/__var1__ ['var1' => 'some/var'] will be: /some/path/some/var/some/file/some/var @param string $path The path containing the variables @param string[string] $variables The array containing the variable names as keys and the replacements as values @return string The path with the replaces variables
[ "Replaces", "the", "variables", "in", "the", "path", "with", "the", "values", "from", "the", "variables", "array", ".", "The", "variables", "must", "be", "in", "form", "__key__", "to", "be", "found", ".", "The", "same", "variable", "can", "occure", "multiple", "times", "in", "the", "path", "." ]
train
https://github.com/codenamephp/prototype.utils/blob/aeb81e1e03624534e8b3e38d6466efda04e435d6/src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php#L129-L135
codenamephp/prototype.utils
src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php
TemplateCopy.getTargetPath
public function getTargetPath(string $templateFolder, string $targetFolder, string $currentPath): string { $trimPath = function($path) { return rtrim($path, DIRECTORY_SEPARATOR . ' '); }; return str_replace($trimPath($templateFolder), $trimPath($targetFolder), $trimPath($currentPath)); }
php
public function getTargetPath(string $templateFolder, string $targetFolder, string $currentPath): string { $trimPath = function($path) { return rtrim($path, DIRECTORY_SEPARATOR . ' '); }; return str_replace($trimPath($templateFolder), $trimPath($targetFolder), $trimPath($currentPath)); }
[ "public", "function", "getTargetPath", "(", "string", "$", "templateFolder", ",", "string", "$", "targetFolder", ",", "string", "$", "currentPath", ")", ":", "string", "{", "$", "trimPath", "=", "function", "(", "$", "path", ")", "{", "return", "rtrim", "(", "$", "path", ",", "DIRECTORY_SEPARATOR", ".", "' '", ")", ";", "}", ";", "return", "str_replace", "(", "$", "trimPath", "(", "$", "templateFolder", ")", ",", "$", "trimPath", "(", "$", "targetFolder", ")", ",", "$", "trimPath", "(", "$", "currentPath", ")", ")", ";", "}" ]
Replaces the part of the templateFolder in the currentPath with the part of the target folder. The currentPath should be the absolute path to the template file. @param string $templateFolder The path to the template folder where the templates are in @param stirng $targetFolder The target folder to where the templates will be rendered @param string $currentPath The path of the current file @return string The new target path
[ "Replaces", "the", "part", "of", "the", "templateFolder", "in", "the", "currentPath", "with", "the", "part", "of", "the", "target", "folder", ".", "The", "currentPath", "should", "be", "the", "absolute", "path", "to", "the", "template", "file", "." ]
train
https://github.com/codenamephp/prototype.utils/blob/aeb81e1e03624534e8b3e38d6466efda04e435d6/src/main/php/de/codenamephp/prototype/utils/TemplateCopy.php#L145-L150
jotaelesalinas/php-rwgen
src/WithOptions.php
WithOptions.preloadDefaults
private function preloadDefaults() { $this->options = array(); $defaults = static::getDefaults() ?: array(); foreach ($defaults as $k => $v) { $this->options[$k] = $v; } }
php
private function preloadDefaults() { $this->options = array(); $defaults = static::getDefaults() ?: array(); foreach ($defaults as $k => $v) { $this->options[$k] = $v; } }
[ "private", "function", "preloadDefaults", "(", ")", "{", "$", "this", "->", "options", "=", "array", "(", ")", ";", "$", "defaults", "=", "static", "::", "getDefaults", "(", ")", "?", ":", "array", "(", ")", ";", "foreach", "(", "$", "defaults", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "options", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}" ]
Reset $options to static::$default_options, if it exists.
[ "Reset", "$options", "to", "static", "::", "$default_options", "if", "it", "exists", "." ]
train
https://github.com/jotaelesalinas/php-rwgen/blob/51c1b01c705aef7c0f746c41b1c0db42a57366ab/src/WithOptions.php#L37-L44
jotaelesalinas/php-rwgen
src/WithOptions.php
WithOptions.setOptions
protected function setOptions($options) { if (is_null($this->options)) { $this->preloadDefaults(true); } foreach ($options as $k => $v) { if (!isset($this->options[$k])) { throw new \Exception("Option $k not allowed."); } $this->options[$k] = $v; } }
php
protected function setOptions($options) { if (is_null($this->options)) { $this->preloadDefaults(true); } foreach ($options as $k => $v) { if (!isset($this->options[$k])) { throw new \Exception("Option $k not allowed."); } $this->options[$k] = $v; } }
[ "protected", "function", "setOptions", "(", "$", "options", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "preloadDefaults", "(", "true", ")", ";", "}", "foreach", "(", "$", "options", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "$", "k", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Option $k not allowed.\"", ")", ";", "}", "$", "this", "->", "options", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}" ]
/* Set the options for the current instance. @param array $options Associative array with option-name => option-value pairs. The name of all the options (the keys of the array) must exist in static::$default_options.
[ "/", "*", "Set", "the", "options", "for", "the", "current", "instance", "." ]
train
https://github.com/jotaelesalinas/php-rwgen/blob/51c1b01c705aef7c0f746c41b1c0db42a57366ab/src/WithOptions.php#L52-L64
jotaelesalinas/php-rwgen
src/WithOptions.php
WithOptions.getOption
public function getOption($key = null) { if (is_null($this->options)) { $this->preloadDefaults(true); } return $key === null ? $this->options : $this->options[$key]; }
php
public function getOption($key = null) { if (is_null($this->options)) { $this->preloadDefaults(true); } return $key === null ? $this->options : $this->options[$key]; }
[ "public", "function", "getOption", "(", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "preloadDefaults", "(", "true", ")", ";", "}", "return", "$", "key", "===", "null", "?", "$", "this", "->", "options", ":", "$", "this", "->", "options", "[", "$", "key", "]", ";", "}" ]
/* Retrieves the value of an option or all of them. @param string $key Optional name of the option to retrieve. @return mixed The value of the option with name $key or the whole $options array if no $key argument is provided.
[ "/", "*", "Retrieves", "the", "value", "of", "an", "option", "or", "all", "of", "them", "." ]
train
https://github.com/jotaelesalinas/php-rwgen/blob/51c1b01c705aef7c0f746c41b1c0db42a57366ab/src/WithOptions.php#L73-L80
GrupaZero/core
src/Gzero/Core/Parsers/NumericParser.php
NumericParser.apply
public function apply(QueryBuilder $builder) { $builder->where($this->name, $this->operation, $this->value); }
php
public function apply(QueryBuilder $builder) { $builder->where($this->name, $this->operation, $this->value); }
[ "public", "function", "apply", "(", "QueryBuilder", "$", "builder", ")", "{", "$", "builder", "->", "where", "(", "$", "this", "->", "name", ",", "$", "this", "->", "operation", ",", "$", "this", "->", "value", ")", ";", "}" ]
It returns query builder that can be pass further to read repository @param QueryBuilder $builder Query builder @return void
[ "It", "returns", "query", "builder", "that", "can", "be", "pass", "further", "to", "read", "repository" ]
train
https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/Parsers/NumericParser.php#L140-L143
GrupaZero/core
src/Gzero/Core/Parsers/NumericParser.php
NumericParser.checkValue
protected function checkValue(): void { if (!ctype_digit($this->value) && !is_numeric($this->value) && !empty($this->value)) { throw new InvalidArgumentException('NumericParser: Value must be of type numeric'); } }
php
protected function checkValue(): void { if (!ctype_digit($this->value) && !is_numeric($this->value) && !empty($this->value)) { throw new InvalidArgumentException('NumericParser: Value must be of type numeric'); } }
[ "protected", "function", "checkValue", "(", ")", ":", "void", "{", "if", "(", "!", "ctype_digit", "(", "$", "this", "->", "value", ")", "&&", "!", "is_numeric", "(", "$", "this", "->", "value", ")", "&&", "!", "empty", "(", "$", "this", "->", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'NumericParser: Value must be of type numeric'", ")", ";", "}", "}" ]
Check if value is not a number. @throws InvalidArgumentException @return void
[ "Check", "if", "value", "is", "not", "a", "number", "." ]
train
https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/Parsers/NumericParser.php#L152-L157
cundd/test-flight
src/FileAnalysis/FileProvider.php
FileProvider.findMatchingFiles
public function findMatchingFiles(string $path): array { $path = $this->validatePath($path); if (is_dir($path)) { $pathCollection = $this->findMatchingFilesInDirectory($path); } elseif (is_file($path)) { $pathCollection = [$path]; } else { throw new FileException(sprintf('Could not get file(s) for path %s', $path)); } $fileIncludingTests = []; foreach ($pathCollection as $path) { $file = new File($path); if ($this->getFileIncludesTest($file)) { $fileIncludingTests[] = $file; } } return $fileIncludingTests; }
php
public function findMatchingFiles(string $path): array { $path = $this->validatePath($path); if (is_dir($path)) { $pathCollection = $this->findMatchingFilesInDirectory($path); } elseif (is_file($path)) { $pathCollection = [$path]; } else { throw new FileException(sprintf('Could not get file(s) for path %s', $path)); } $fileIncludingTests = []; foreach ($pathCollection as $path) { $file = new File($path); if ($this->getFileIncludesTest($file)) { $fileIncludingTests[] = $file; } } return $fileIncludingTests; }
[ "public", "function", "findMatchingFiles", "(", "string", "$", "path", ")", ":", "array", "{", "$", "path", "=", "$", "this", "->", "validatePath", "(", "$", "path", ")", ";", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "$", "pathCollection", "=", "$", "this", "->", "findMatchingFilesInDirectory", "(", "$", "path", ")", ";", "}", "elseif", "(", "is_file", "(", "$", "path", ")", ")", "{", "$", "pathCollection", "=", "[", "$", "path", "]", ";", "}", "else", "{", "throw", "new", "FileException", "(", "sprintf", "(", "'Could not get file(s) for path %s'", ",", "$", "path", ")", ")", ";", "}", "$", "fileIncludingTests", "=", "[", "]", ";", "foreach", "(", "$", "pathCollection", "as", "$", "path", ")", "{", "$", "file", "=", "new", "File", "(", "$", "path", ")", ";", "if", "(", "$", "this", "->", "getFileIncludesTest", "(", "$", "file", ")", ")", "{", "$", "fileIncludingTests", "[", "]", "=", "$", "file", ";", "}", "}", "return", "$", "fileIncludingTests", ";", "}" ]
Returns the matching files containing the test doc comment If path is a single file and it contains test it will be returned, if it is a directory it will be scanned for files with test in it's content @param string $path @return FileInterface[]
[ "Returns", "the", "matching", "files", "containing", "the", "test", "doc", "comment" ]
train
https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/FileAnalysis/FileProvider.php#L43-L64
fazland/elastica-odm
src/Metadata/Processor/DocumentProcessor.php
DocumentProcessor.process
public function process(MetadataInterface $metadata, $subject): void { $metadata->document = true; $metadata->collectionName = $subject->type; $metadata->customRepositoryClassName = $subject->repositoryClass; }
php
public function process(MetadataInterface $metadata, $subject): void { $metadata->document = true; $metadata->collectionName = $subject->type; $metadata->customRepositoryClassName = $subject->repositoryClass; }
[ "public", "function", "process", "(", "MetadataInterface", "$", "metadata", ",", "$", "subject", ")", ":", "void", "{", "$", "metadata", "->", "document", "=", "true", ";", "$", "metadata", "->", "collectionName", "=", "$", "subject", "->", "type", ";", "$", "metadata", "->", "customRepositoryClassName", "=", "$", "subject", "->", "repositoryClass", ";", "}" ]
{@inheritdoc} @param DocumentMetadata $metadata @param Document $subject
[ "{", "@inheritdoc", "}" ]
train
https://github.com/fazland/elastica-odm/blob/9d7276ea9ea9103c670f13f889bf59568ff35274/src/Metadata/Processor/DocumentProcessor.php#L18-L23
webriq/core
module/User/src/Grid/User/Model/ConfirmHash.php
ConfirmHash.create
public function create( $email ) { $store = $this->getCacheStorage(); do { $hash = String::generateRandom( self::HASH_LENGTH, null, true ); } while ( $store->hasItem( $hash ) ); $store->setItem( $hash, $email ); return $hash; }
php
public function create( $email ) { $store = $this->getCacheStorage(); do { $hash = String::generateRandom( self::HASH_LENGTH, null, true ); } while ( $store->hasItem( $hash ) ); $store->setItem( $hash, $email ); return $hash; }
[ "public", "function", "create", "(", "$", "email", ")", "{", "$", "store", "=", "$", "this", "->", "getCacheStorage", "(", ")", ";", "do", "{", "$", "hash", "=", "String", "::", "generateRandom", "(", "self", "::", "HASH_LENGTH", ",", "null", ",", "true", ")", ";", "}", "while", "(", "$", "store", "->", "hasItem", "(", "$", "hash", ")", ")", ";", "$", "store", "->", "setItem", "(", "$", "hash", ",", "$", "email", ")", ";", "return", "$", "hash", ";", "}" ]
Request a password-change @param string $email @return string hash
[ "Request", "a", "password", "-", "change" ]
train
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/User/src/Grid/User/Model/ConfirmHash.php#L27-L39
phlexible/phlexible
src/Phlexible/Bundle/MediaManagerBundle/Command/VersionCommand.php
VersionCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); $id = $input->getArgument('fileId'); $version = $input->getArgument('fileVersion'); $userId = $this->getContainer()->get('phlexible_user.user_manager')->findByUsername($username)->getId(); $volumeManager = $this->getContainer()->get('phlexible_media_manager.volume_manager'); $volume = $volumeManager->getByFileId($id); $file = $volume->findFile($id); if ($version) { $fileVersion = $volume->findFileVersion($id, $version); } else { $fileVersion = $volume->findOneFileVersion($id, ['fileVersion' => 'DESC']); } $volume->activateFileVersion($file, $fileVersion, $userId); $output->writeln("Activated version {$fileVersion->getVersion()} for file {$file->getName()}"); return 0; }
php
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); $id = $input->getArgument('fileId'); $version = $input->getArgument('fileVersion'); $userId = $this->getContainer()->get('phlexible_user.user_manager')->findByUsername($username)->getId(); $volumeManager = $this->getContainer()->get('phlexible_media_manager.volume_manager'); $volume = $volumeManager->getByFileId($id); $file = $volume->findFile($id); if ($version) { $fileVersion = $volume->findFileVersion($id, $version); } else { $fileVersion = $volume->findOneFileVersion($id, ['fileVersion' => 'DESC']); } $volume->activateFileVersion($file, $fileVersion, $userId); $output->writeln("Activated version {$fileVersion->getVersion()} for file {$file->getName()}"); return 0; }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "username", "=", "$", "input", "->", "getArgument", "(", "'username'", ")", ";", "$", "id", "=", "$", "input", "->", "getArgument", "(", "'fileId'", ")", ";", "$", "version", "=", "$", "input", "->", "getArgument", "(", "'fileVersion'", ")", ";", "$", "userId", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'phlexible_user.user_manager'", ")", "->", "findByUsername", "(", "$", "username", ")", "->", "getId", "(", ")", ";", "$", "volumeManager", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'phlexible_media_manager.volume_manager'", ")", ";", "$", "volume", "=", "$", "volumeManager", "->", "getByFileId", "(", "$", "id", ")", ";", "$", "file", "=", "$", "volume", "->", "findFile", "(", "$", "id", ")", ";", "if", "(", "$", "version", ")", "{", "$", "fileVersion", "=", "$", "volume", "->", "findFileVersion", "(", "$", "id", ",", "$", "version", ")", ";", "}", "else", "{", "$", "fileVersion", "=", "$", "volume", "->", "findOneFileVersion", "(", "$", "id", ",", "[", "'fileVersion'", "=>", "'DESC'", "]", ")", ";", "}", "$", "volume", "->", "activateFileVersion", "(", "$", "file", ",", "$", "fileVersion", ",", "$", "userId", ")", ";", "$", "output", "->", "writeln", "(", "\"Activated version {$fileVersion->getVersion()} for file {$file->getName()}\"", ")", ";", "return", "0", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/MediaManagerBundle/Command/VersionCommand.php#L42-L64
tux-rampage/rampage-php
library/rampage/core/controllers/ControllerManager.php
ControllerManager.has
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false) { if (parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers)) { return true; } if (is_array($name)) { return false; } $class = strtr($name, '.', '\\'); if ($this->autoAddInvokableClass && class_exists($class)) { $this->setInvokableClass($name, $class); return true; } return false; }
php
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false) { if (parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers)) { return true; } if (is_array($name)) { return false; } $class = strtr($name, '.', '\\'); if ($this->autoAddInvokableClass && class_exists($class)) { $this->setInvokableClass($name, $class); return true; } return false; }
[ "public", "function", "has", "(", "$", "name", ",", "$", "checkAbstractFactories", "=", "true", ",", "$", "usePeeringServiceManagers", "=", "false", ")", "{", "if", "(", "parent", "::", "has", "(", "$", "name", ",", "$", "checkAbstractFactories", ",", "$", "usePeeringServiceManagers", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "return", "false", ";", "}", "$", "class", "=", "strtr", "(", "$", "name", ",", "'.'", ",", "'\\\\'", ")", ";", "if", "(", "$", "this", "->", "autoAddInvokableClass", "&&", "class_exists", "(", "$", "class", ")", ")", "{", "$", "this", "->", "setInvokableClass", "(", "$", "name", ",", "$", "class", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc} @see \Zend\Mvc\Controller\ControllerManager::has()
[ "{" ]
train
https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/controllers/ControllerManager.php#L73-L90
leadthread/php-viddler
src/Viddler.php
Viddler.call
protected function call($method, $args) { $method = str_replace("_", ".", $method); $request = new $this->requestClass($this->apiKey, $method, $args, $this->secure); return $request->execute(); }
php
protected function call($method, $args) { $method = str_replace("_", ".", $method); $request = new $this->requestClass($this->apiKey, $method, $args, $this->secure); return $request->execute(); }
[ "protected", "function", "call", "(", "$", "method", ",", "$", "args", ")", "{", "$", "method", "=", "str_replace", "(", "\"_\"", ",", "\".\"", ",", "$", "method", ")", ";", "$", "request", "=", "new", "$", "this", "->", "requestClass", "(", "$", "this", "->", "apiKey", ",", "$", "method", ",", "$", "args", ",", "$", "this", "->", "secure", ")", ";", "return", "$", "request", "->", "execute", "(", ")", ";", "}" ]
Format the Method Accepted Formats: $viddler->viddler_users_auth();
[ "Format", "the", "Method", "Accepted", "Formats", ":" ]
train
https://github.com/leadthread/php-viddler/blob/7167b58995cf75099c75add4aecfd63c08c5dcdc/src/Viddler.php#L39-L44
agalbourdin/agl-core
src/Mvc/View/ViewAbstract.php
ViewAbstract.getTemplateConfig
public static function getTemplateConfig() { if (self::$_templateConfig === 0) { $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $action = $request->getAction(); self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '#action#' . $action . '/template'); if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '/template'); } if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '/template'); } if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/template'); } } if (! isset(self::$_templateConfig['type'])) { self::$_templateConfig['type'] = ViewInterface::TYPE_HTML; } return self::$_templateConfig; }
php
public static function getTemplateConfig() { if (self::$_templateConfig === 0) { $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $action = $request->getAction(); self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '#action#' . $action . '/template'); if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '/template'); } if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '/template'); } if (self::$_templateConfig === NULL) { self::$_templateConfig = Agl::app()->getConfig('core-layout/template'); } } if (! isset(self::$_templateConfig['type'])) { self::$_templateConfig['type'] = ViewInterface::TYPE_HTML; } return self::$_templateConfig; }
[ "public", "static", "function", "getTemplateConfig", "(", ")", "{", "if", "(", "self", "::", "$", "_templateConfig", "===", "0", ")", "{", "$", "request", "=", "Agl", "::", "getRequest", "(", ")", ";", "$", "module", "=", "$", "request", "->", "getModule", "(", ")", ";", "$", "view", "=", "$", "request", "->", "getView", "(", ")", ";", "$", "action", "=", "$", "request", "->", "getAction", "(", ")", ";", "self", "::", "$", "_templateConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'#'", ".", "$", "view", ".", "'#action#'", ".", "$", "action", ".", "'/template'", ")", ";", "if", "(", "self", "::", "$", "_templateConfig", "===", "NULL", ")", "{", "self", "::", "$", "_templateConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'#'", ".", "$", "view", ".", "'/template'", ")", ";", "}", "if", "(", "self", "::", "$", "_templateConfig", "===", "NULL", ")", "{", "self", "::", "$", "_templateConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'/template'", ")", ";", "}", "if", "(", "self", "::", "$", "_templateConfig", "===", "NULL", ")", "{", "self", "::", "$", "_templateConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/template'", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "_templateConfig", "[", "'type'", "]", ")", ")", "{", "self", "::", "$", "_templateConfig", "[", "'type'", "]", "=", "ViewInterface", "::", "TYPE_HTML", ";", "}", "return", "self", "::", "$", "_templateConfig", ";", "}" ]
Get the template configuration. @return mixed
[ "Get", "the", "template", "configuration", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/View/ViewAbstract.php#L66-L94
agalbourdin/agl-core
src/Mvc/View/ViewAbstract.php
ViewAbstract.render
public function render() { $this->_path = $this->getPath(); if (! is_readable($this->_path)) { Request::setHttpHeader(Request::HEADER_404); $this->setFile(static::ERROR_404); $this->_path = $this->getPath(); if (! is_readable($this->_path)) { throw new Exception("View file '" . $this->_path . "' doesn't exists"); } } $template = self::getTemplateConfig(); if (! is_array($template) or ! isset($template['type'])) { throw new Exception("A template and a template type are required to render the view"); } $this->_type = $template['type']; if (isset($template['file'])) { $template = APP_PATH . Agl::APP_TEMPLATE_DIR . $template['file'] . Agl::PHP_EXT; require($template); } else { require($this->_path); } $buffer = ob_get_clean(); Observer::dispatch(Observer::EVENT_VIEW_RENDER_BUFFER_BEFORE, array( 'view' => $this, 'buffer' => &$buffer )); return $this->_prepareRender($buffer); }
php
public function render() { $this->_path = $this->getPath(); if (! is_readable($this->_path)) { Request::setHttpHeader(Request::HEADER_404); $this->setFile(static::ERROR_404); $this->_path = $this->getPath(); if (! is_readable($this->_path)) { throw new Exception("View file '" . $this->_path . "' doesn't exists"); } } $template = self::getTemplateConfig(); if (! is_array($template) or ! isset($template['type'])) { throw new Exception("A template and a template type are required to render the view"); } $this->_type = $template['type']; if (isset($template['file'])) { $template = APP_PATH . Agl::APP_TEMPLATE_DIR . $template['file'] . Agl::PHP_EXT; require($template); } else { require($this->_path); } $buffer = ob_get_clean(); Observer::dispatch(Observer::EVENT_VIEW_RENDER_BUFFER_BEFORE, array( 'view' => $this, 'buffer' => &$buffer )); return $this->_prepareRender($buffer); }
[ "public", "function", "render", "(", ")", "{", "$", "this", "->", "_path", "=", "$", "this", "->", "getPath", "(", ")", ";", "if", "(", "!", "is_readable", "(", "$", "this", "->", "_path", ")", ")", "{", "Request", "::", "setHttpHeader", "(", "Request", "::", "HEADER_404", ")", ";", "$", "this", "->", "setFile", "(", "static", "::", "ERROR_404", ")", ";", "$", "this", "->", "_path", "=", "$", "this", "->", "getPath", "(", ")", ";", "if", "(", "!", "is_readable", "(", "$", "this", "->", "_path", ")", ")", "{", "throw", "new", "Exception", "(", "\"View file '\"", ".", "$", "this", "->", "_path", ".", "\"' doesn't exists\"", ")", ";", "}", "}", "$", "template", "=", "self", "::", "getTemplateConfig", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "template", ")", "or", "!", "isset", "(", "$", "template", "[", "'type'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"A template and a template type are required to render the view\"", ")", ";", "}", "$", "this", "->", "_type", "=", "$", "template", "[", "'type'", "]", ";", "if", "(", "isset", "(", "$", "template", "[", "'file'", "]", ")", ")", "{", "$", "template", "=", "APP_PATH", ".", "Agl", "::", "APP_TEMPLATE_DIR", ".", "$", "template", "[", "'file'", "]", ".", "Agl", "::", "PHP_EXT", ";", "require", "(", "$", "template", ")", ";", "}", "else", "{", "require", "(", "$", "this", "->", "_path", ")", ";", "}", "$", "buffer", "=", "ob_get_clean", "(", ")", ";", "Observer", "::", "dispatch", "(", "Observer", "::", "EVENT_VIEW_RENDER_BUFFER_BEFORE", ",", "array", "(", "'view'", "=>", "$", "this", ",", "'buffer'", "=>", "&", "$", "buffer", ")", ")", ";", "return", "$", "this", "->", "_prepareRender", "(", "$", "buffer", ")", ";", "}" ]
Include the template in the current page. @return View
[ "Include", "the", "template", "in", "the", "current", "page", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/View/ViewAbstract.php#L171-L211
agalbourdin/agl-core
src/Mvc/View/ViewAbstract.php
ViewAbstract.getBlock
public function getBlock($pBlock, array $pVars = array()) { if (! preg_match('#^([a-z0-9]+)/([a-z0-9_-]+)$#', $pBlock, $blockPathInfos) or ! isset($blockPathInfos[1]) or ! isset($blockPathInfos[2])) { throw new Exception("Block identifier '$pBlock' is not correct"); } $this->_blocks[] = array( 'group' => $blockPathInfos[1], 'block' => $blockPathInfos[2] ); $blockConfig = Agl::app()->getConfig('core-layout/blocks/' . $blockPathInfos[1] . '#' . $blockPathInfos[2]); if ($blockConfig === NULL) { $blockConfig = array(); } if (! BlockAbstract::checkAcl($blockPathInfos[1], $blockPathInfos[2])) { return ''; } $isCacheEnabled = Agl::app()->isCacheEnabled(); if ($isCacheEnabled) { $cacheInfo = BlockAbstract::getCacheInfo($blockPathInfos, $blockConfig); if (! empty($cacheInfo) and $cacheInstance = Agl::getCache() and $cacheInstance->has($cacheInfo[CacheInterface::CACHE_KEY])) { return $cacheInstance->get($cacheInfo[CacheInterface::CACHE_KEY]); } } $blockPath = APP_PATH . Agl::APP_PHP_DIR . BlockInterface::APP_PHP_DIR . DS . $blockPathInfos[1] . DS . $blockPathInfos[2] . Agl::PHP_EXT; if (file_exists($blockPath)) { $className = $blockPathInfos[1] . ucfirst($blockPathInfos[2]) . BlockInterface::APP_SUFFIX; $blockModel = Agl::getInstance($className); } else { $blockModel = new Block(); } ob_start(); $blockModel ->setFile($blockPathInfos[1] . DS . $blockPathInfos[2] . Agl::PHP_EXT) ->setVars($pVars) ->render(); $content = ob_get_clean(); if ($isCacheEnabled and ! empty($cacheInfo)) { $cacheInstance->set($cacheInfo[CacheInterface::CACHE_KEY], $content, $cacheInfo[ConfigInterface::CONFIG_CACHE_TTL_NAME]); } return $content; }
php
public function getBlock($pBlock, array $pVars = array()) { if (! preg_match('#^([a-z0-9]+)/([a-z0-9_-]+)$#', $pBlock, $blockPathInfos) or ! isset($blockPathInfos[1]) or ! isset($blockPathInfos[2])) { throw new Exception("Block identifier '$pBlock' is not correct"); } $this->_blocks[] = array( 'group' => $blockPathInfos[1], 'block' => $blockPathInfos[2] ); $blockConfig = Agl::app()->getConfig('core-layout/blocks/' . $blockPathInfos[1] . '#' . $blockPathInfos[2]); if ($blockConfig === NULL) { $blockConfig = array(); } if (! BlockAbstract::checkAcl($blockPathInfos[1], $blockPathInfos[2])) { return ''; } $isCacheEnabled = Agl::app()->isCacheEnabled(); if ($isCacheEnabled) { $cacheInfo = BlockAbstract::getCacheInfo($blockPathInfos, $blockConfig); if (! empty($cacheInfo) and $cacheInstance = Agl::getCache() and $cacheInstance->has($cacheInfo[CacheInterface::CACHE_KEY])) { return $cacheInstance->get($cacheInfo[CacheInterface::CACHE_KEY]); } } $blockPath = APP_PATH . Agl::APP_PHP_DIR . BlockInterface::APP_PHP_DIR . DS . $blockPathInfos[1] . DS . $blockPathInfos[2] . Agl::PHP_EXT; if (file_exists($blockPath)) { $className = $blockPathInfos[1] . ucfirst($blockPathInfos[2]) . BlockInterface::APP_SUFFIX; $blockModel = Agl::getInstance($className); } else { $blockModel = new Block(); } ob_start(); $blockModel ->setFile($blockPathInfos[1] . DS . $blockPathInfos[2] . Agl::PHP_EXT) ->setVars($pVars) ->render(); $content = ob_get_clean(); if ($isCacheEnabled and ! empty($cacheInfo)) { $cacheInstance->set($cacheInfo[CacheInterface::CACHE_KEY], $content, $cacheInfo[ConfigInterface::CONFIG_CACHE_TTL_NAME]); } return $content; }
[ "public", "function", "getBlock", "(", "$", "pBlock", ",", "array", "$", "pVars", "=", "array", "(", ")", ")", "{", "if", "(", "!", "preg_match", "(", "'#^([a-z0-9]+)/([a-z0-9_-]+)$#'", ",", "$", "pBlock", ",", "$", "blockPathInfos", ")", "or", "!", "isset", "(", "$", "blockPathInfos", "[", "1", "]", ")", "or", "!", "isset", "(", "$", "blockPathInfos", "[", "2", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"Block identifier '$pBlock' is not correct\"", ")", ";", "}", "$", "this", "->", "_blocks", "[", "]", "=", "array", "(", "'group'", "=>", "$", "blockPathInfos", "[", "1", "]", ",", "'block'", "=>", "$", "blockPathInfos", "[", "2", "]", ")", ";", "$", "blockConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/blocks/'", ".", "$", "blockPathInfos", "[", "1", "]", ".", "'#'", ".", "$", "blockPathInfos", "[", "2", "]", ")", ";", "if", "(", "$", "blockConfig", "===", "NULL", ")", "{", "$", "blockConfig", "=", "array", "(", ")", ";", "}", "if", "(", "!", "BlockAbstract", "::", "checkAcl", "(", "$", "blockPathInfos", "[", "1", "]", ",", "$", "blockPathInfos", "[", "2", "]", ")", ")", "{", "return", "''", ";", "}", "$", "isCacheEnabled", "=", "Agl", "::", "app", "(", ")", "->", "isCacheEnabled", "(", ")", ";", "if", "(", "$", "isCacheEnabled", ")", "{", "$", "cacheInfo", "=", "BlockAbstract", "::", "getCacheInfo", "(", "$", "blockPathInfos", ",", "$", "blockConfig", ")", ";", "if", "(", "!", "empty", "(", "$", "cacheInfo", ")", "and", "$", "cacheInstance", "=", "Agl", "::", "getCache", "(", ")", "and", "$", "cacheInstance", "->", "has", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ")", ")", "{", "return", "$", "cacheInstance", "->", "get", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ")", ";", "}", "}", "$", "blockPath", "=", "APP_PATH", ".", "Agl", "::", "APP_PHP_DIR", ".", "BlockInterface", "::", "APP_PHP_DIR", ".", "DS", ".", "$", "blockPathInfos", "[", "1", "]", ".", "DS", ".", "$", "blockPathInfos", "[", "2", "]", ".", "Agl", "::", "PHP_EXT", ";", "if", "(", "file_exists", "(", "$", "blockPath", ")", ")", "{", "$", "className", "=", "$", "blockPathInfos", "[", "1", "]", ".", "ucfirst", "(", "$", "blockPathInfos", "[", "2", "]", ")", ".", "BlockInterface", "::", "APP_SUFFIX", ";", "$", "blockModel", "=", "Agl", "::", "getInstance", "(", "$", "className", ")", ";", "}", "else", "{", "$", "blockModel", "=", "new", "Block", "(", ")", ";", "}", "ob_start", "(", ")", ";", "$", "blockModel", "->", "setFile", "(", "$", "blockPathInfos", "[", "1", "]", ".", "DS", ".", "$", "blockPathInfos", "[", "2", "]", ".", "Agl", "::", "PHP_EXT", ")", "->", "setVars", "(", "$", "pVars", ")", "->", "render", "(", ")", ";", "$", "content", "=", "ob_get_clean", "(", ")", ";", "if", "(", "$", "isCacheEnabled", "and", "!", "empty", "(", "$", "cacheInfo", ")", ")", "{", "$", "cacheInstance", "->", "set", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ",", "$", "content", ",", "$", "cacheInfo", "[", "ConfigInterface", "::", "CONFIG_CACHE_TTL_NAME", "]", ")", ";", "}", "return", "$", "content", ";", "}" ]
Create a block and include it into the view. @param string $pBlock Block identifier @param array $pVars Array of variables (key => value) that will be passed to block @return Block
[ "Create", "a", "block", "and", "include", "it", "into", "the", "view", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/View/ViewAbstract.php#L233-L297
railsphp/framework
src/Rails/ActiveModel/Validator/ModelValidator.php
ModelValidator.validate
public function validate($record) { $record->errors()->clear(); foreach ($this->validations as $attribute => $validators) { if ($attribute === 'validateWith') { foreach ($validators as $validatorClass => $options) { if (is_int($validatorClass)) { $validatorClass = $options; $options = []; } $validator = new $validatorClass($options); $validator->validate($record); } } elseif (is_int($attribute)) { if (is_string($validators)) { $record->$validators(); } elseif (is_array($validators)) { $attributes = array_shift($validators); $validators = array_shift($validators); foreach ($attributes as $attribute) { $this->validateAttribute($record, $attribute, $validators); } } } else { $this->validateAttribute($record, $attribute, $validators); } } return $record->errors()->none(); }
php
public function validate($record) { $record->errors()->clear(); foreach ($this->validations as $attribute => $validators) { if ($attribute === 'validateWith') { foreach ($validators as $validatorClass => $options) { if (is_int($validatorClass)) { $validatorClass = $options; $options = []; } $validator = new $validatorClass($options); $validator->validate($record); } } elseif (is_int($attribute)) { if (is_string($validators)) { $record->$validators(); } elseif (is_array($validators)) { $attributes = array_shift($validators); $validators = array_shift($validators); foreach ($attributes as $attribute) { $this->validateAttribute($record, $attribute, $validators); } } } else { $this->validateAttribute($record, $attribute, $validators); } } return $record->errors()->none(); }
[ "public", "function", "validate", "(", "$", "record", ")", "{", "$", "record", "->", "errors", "(", ")", "->", "clear", "(", ")", ";", "foreach", "(", "$", "this", "->", "validations", "as", "$", "attribute", "=>", "$", "validators", ")", "{", "if", "(", "$", "attribute", "===", "'validateWith'", ")", "{", "foreach", "(", "$", "validators", "as", "$", "validatorClass", "=>", "$", "options", ")", "{", "if", "(", "is_int", "(", "$", "validatorClass", ")", ")", "{", "$", "validatorClass", "=", "$", "options", ";", "$", "options", "=", "[", "]", ";", "}", "$", "validator", "=", "new", "$", "validatorClass", "(", "$", "options", ")", ";", "$", "validator", "->", "validate", "(", "$", "record", ")", ";", "}", "}", "elseif", "(", "is_int", "(", "$", "attribute", ")", ")", "{", "if", "(", "is_string", "(", "$", "validators", ")", ")", "{", "$", "record", "->", "$", "validators", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "validators", ")", ")", "{", "$", "attributes", "=", "array_shift", "(", "$", "validators", ")", ";", "$", "validators", "=", "array_shift", "(", "$", "validators", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "this", "->", "validateAttribute", "(", "$", "record", ",", "$", "attribute", ",", "$", "validators", ")", ";", "}", "}", "}", "else", "{", "$", "this", "->", "validateAttribute", "(", "$", "record", ",", "$", "attribute", ",", "$", "validators", ")", ";", "}", "}", "return", "$", "record", "->", "errors", "(", ")", "->", "none", "(", ")", ";", "}" ]
Returns true if all validations passed, false otherwise. @return bool
[ "Returns", "true", "if", "all", "validations", "passed", "false", "otherwise", "." ]
train
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveModel/Validator/ModelValidator.php#L45-L75
Niirrty/Niirrty.Web
src/MailAddress.php
MailAddress.equals
public function equals( $value, bool $strict = false ) : bool { if ( null === $value ) { return false; } if ( $value instanceof MailAddress ) { return ( $value->_userPart === $this->_userPart ) && ( ( (string) $value->_domainPart ) === ( (string) $this->_domainPart ) ); } if ( $strict ) { return false; } $val = null; if ( \is_string( $value ) ) { if ( false !== ( $val = MailAddress::Parse( $value ) ) ) { return ( $val->_userPart === $this->_userPart ) && ( ( (string) $val->_domainPart ) === ( (string) $this->_domainPart ) ); } return false; } if ( $value instanceof Domain ) { return ( ( (string) $value ) === ( (string) $this->_domainPart ) ); } try { $typeInfo = new Type( $value ); if ( ! $typeInfo->hasAssociatedString() ) { return false; } } catch ( \Throwable $ex ) { unset ( $ex ); return false; } if ( false === ( $val = MailAddress::Parse( $typeInfo->getStringValue(), false, false, true ) ) ) { return false; } return ( $val->_userPart === $this->_userPart ) && ( ( (string) $val->_domainPart ) === ( (string) $this->_domainPart ) ); }
php
public function equals( $value, bool $strict = false ) : bool { if ( null === $value ) { return false; } if ( $value instanceof MailAddress ) { return ( $value->_userPart === $this->_userPart ) && ( ( (string) $value->_domainPart ) === ( (string) $this->_domainPart ) ); } if ( $strict ) { return false; } $val = null; if ( \is_string( $value ) ) { if ( false !== ( $val = MailAddress::Parse( $value ) ) ) { return ( $val->_userPart === $this->_userPart ) && ( ( (string) $val->_domainPart ) === ( (string) $this->_domainPart ) ); } return false; } if ( $value instanceof Domain ) { return ( ( (string) $value ) === ( (string) $this->_domainPart ) ); } try { $typeInfo = new Type( $value ); if ( ! $typeInfo->hasAssociatedString() ) { return false; } } catch ( \Throwable $ex ) { unset ( $ex ); return false; } if ( false === ( $val = MailAddress::Parse( $typeInfo->getStringValue(), false, false, true ) ) ) { return false; } return ( $val->_userPart === $this->_userPart ) && ( ( (string) $val->_domainPart ) === ( (string) $this->_domainPart ) ); }
[ "public", "function", "equals", "(", "$", "value", ",", "bool", "$", "strict", "=", "false", ")", ":", "bool", "{", "if", "(", "null", "===", "$", "value", ")", "{", "return", "false", ";", "}", "if", "(", "$", "value", "instanceof", "MailAddress", ")", "{", "return", "(", "$", "value", "->", "_userPart", "===", "$", "this", "->", "_userPart", ")", "&&", "(", "(", "(", "string", ")", "$", "value", "->", "_domainPart", ")", "===", "(", "(", "string", ")", "$", "this", "->", "_domainPart", ")", ")", ";", "}", "if", "(", "$", "strict", ")", "{", "return", "false", ";", "}", "$", "val", "=", "null", ";", "if", "(", "\\", "is_string", "(", "$", "value", ")", ")", "{", "if", "(", "false", "!==", "(", "$", "val", "=", "MailAddress", "::", "Parse", "(", "$", "value", ")", ")", ")", "{", "return", "(", "$", "val", "->", "_userPart", "===", "$", "this", "->", "_userPart", ")", "&&", "(", "(", "(", "string", ")", "$", "val", "->", "_domainPart", ")", "===", "(", "(", "string", ")", "$", "this", "->", "_domainPart", ")", ")", ";", "}", "return", "false", ";", "}", "if", "(", "$", "value", "instanceof", "Domain", ")", "{", "return", "(", "(", "(", "string", ")", "$", "value", ")", "===", "(", "(", "string", ")", "$", "this", "->", "_domainPart", ")", ")", ";", "}", "try", "{", "$", "typeInfo", "=", "new", "Type", "(", "$", "value", ")", ";", "if", "(", "!", "$", "typeInfo", "->", "hasAssociatedString", "(", ")", ")", "{", "return", "false", ";", "}", "}", "catch", "(", "\\", "Throwable", "$", "ex", ")", "{", "unset", "(", "$", "ex", ")", ";", "return", "false", ";", "}", "if", "(", "false", "===", "(", "$", "val", "=", "MailAddress", "::", "Parse", "(", "$", "typeInfo", "->", "getStringValue", "(", ")", ",", "false", ",", "false", ",", "true", ")", ")", ")", "{", "return", "false", ";", "}", "return", "(", "$", "val", "->", "_userPart", "===", "$", "this", "->", "_userPart", ")", "&&", "(", "(", "(", "string", ")", "$", "val", "->", "_domainPart", ")", "===", "(", "(", "string", ")", "$", "this", "->", "_domainPart", ")", ")", ";", "}" ]
Checks if the defined value is equal to current mail address value. @param mixed $value The value to check against. @param boolean $strict Can only be equal if value is of type {@see \Niirrty\Web\MailAddress} @return boolean
[ "Checks", "if", "the", "defined", "value", "is", "equal", "to", "current", "mail", "address", "value", "." ]
train
https://github.com/Niirrty/Niirrty.Web/blob/66185109561e734f8a45e626369de5ac05afc2d5/src/MailAddress.php#L110-L170
Niirrty/Niirrty.Web
src/MailAddress.php
MailAddress.Parse
public static function Parse( string $mailAddressString, bool $requireTLD = true, bool $requireKnownTLD = true, bool $allowReserved = false ) { if ( false === ( $firstAtIndex = \Niirrty\strPos( $mailAddressString, '@' ) ) ) { // If $mailAddressString do not contain the @ char, parsing fails return false; } // Ensure we have not some unicode stuff inside the mail address string $mailAddressString = idnToASCII( $mailAddressString ); // Get the user part string $user = \strtolower( \substr( $mailAddressString, 0, $firstAtIndex ) ); // Get the domain part string $domain = \strtolower( \substr( $mailAddressString, $firstAtIndex + 1 ) ); if ( ! \preg_match( '~^[a-z_][a-z0-9_.%+-]*$~i', $user ) ) { // If the user part uses invalid characters, parsing fails return false; } if ( false === ( $_domain = Domain::Parse( $domain, $requireTLD && $requireKnownTLD, false ) ) ) { return false; } /** @noinspection PhpUndefinedVariableInspection */ if ( $requireTLD && ! $_domain->hasTLD() ) { // If a TLD is required but not defined, parsing fails return false; } /** @noinspection PhpUndefinedVariableInspection */ if ( ! $allowReserved && $_domain->isReserved() ) { // If the domain part points to a reserved domain name or TLD, parsing fails if this is forbidden return false; } // All is fine, return the resulting MailAddress instance. /** @noinspection PhpUndefinedVariableInspection */ return new MailAddress( $user, $_domain ); }
php
public static function Parse( string $mailAddressString, bool $requireTLD = true, bool $requireKnownTLD = true, bool $allowReserved = false ) { if ( false === ( $firstAtIndex = \Niirrty\strPos( $mailAddressString, '@' ) ) ) { // If $mailAddressString do not contain the @ char, parsing fails return false; } // Ensure we have not some unicode stuff inside the mail address string $mailAddressString = idnToASCII( $mailAddressString ); // Get the user part string $user = \strtolower( \substr( $mailAddressString, 0, $firstAtIndex ) ); // Get the domain part string $domain = \strtolower( \substr( $mailAddressString, $firstAtIndex + 1 ) ); if ( ! \preg_match( '~^[a-z_][a-z0-9_.%+-]*$~i', $user ) ) { // If the user part uses invalid characters, parsing fails return false; } if ( false === ( $_domain = Domain::Parse( $domain, $requireTLD && $requireKnownTLD, false ) ) ) { return false; } /** @noinspection PhpUndefinedVariableInspection */ if ( $requireTLD && ! $_domain->hasTLD() ) { // If a TLD is required but not defined, parsing fails return false; } /** @noinspection PhpUndefinedVariableInspection */ if ( ! $allowReserved && $_domain->isReserved() ) { // If the domain part points to a reserved domain name or TLD, parsing fails if this is forbidden return false; } // All is fine, return the resulting MailAddress instance. /** @noinspection PhpUndefinedVariableInspection */ return new MailAddress( $user, $_domain ); }
[ "public", "static", "function", "Parse", "(", "string", "$", "mailAddressString", ",", "bool", "$", "requireTLD", "=", "true", ",", "bool", "$", "requireKnownTLD", "=", "true", ",", "bool", "$", "allowReserved", "=", "false", ")", "{", "if", "(", "false", "===", "(", "$", "firstAtIndex", "=", "\\", "Niirrty", "\\", "strPos", "(", "$", "mailAddressString", ",", "'@'", ")", ")", ")", "{", "// If $mailAddressString do not contain the @ char, parsing fails", "return", "false", ";", "}", "// Ensure we have not some unicode stuff inside the mail address string", "$", "mailAddressString", "=", "idnToASCII", "(", "$", "mailAddressString", ")", ";", "// Get the user part string", "$", "user", "=", "\\", "strtolower", "(", "\\", "substr", "(", "$", "mailAddressString", ",", "0", ",", "$", "firstAtIndex", ")", ")", ";", "// Get the domain part string", "$", "domain", "=", "\\", "strtolower", "(", "\\", "substr", "(", "$", "mailAddressString", ",", "$", "firstAtIndex", "+", "1", ")", ")", ";", "if", "(", "!", "\\", "preg_match", "(", "'~^[a-z_][a-z0-9_.%+-]*$~i'", ",", "$", "user", ")", ")", "{", "// If the user part uses invalid characters, parsing fails", "return", "false", ";", "}", "if", "(", "false", "===", "(", "$", "_domain", "=", "Domain", "::", "Parse", "(", "$", "domain", ",", "$", "requireTLD", "&&", "$", "requireKnownTLD", ",", "false", ")", ")", ")", "{", "return", "false", ";", "}", "/** @noinspection PhpUndefinedVariableInspection */", "if", "(", "$", "requireTLD", "&&", "!", "$", "_domain", "->", "hasTLD", "(", ")", ")", "{", "// If a TLD is required but not defined, parsing fails", "return", "false", ";", "}", "/** @noinspection PhpUndefinedVariableInspection */", "if", "(", "!", "$", "allowReserved", "&&", "$", "_domain", "->", "isReserved", "(", ")", ")", "{", "// If the domain part points to a reserved domain name or TLD, parsing fails if this is forbidden", "return", "false", ";", "}", "// All is fine, return the resulting MailAddress instance.", "/** @noinspection PhpUndefinedVariableInspection */", "return", "new", "MailAddress", "(", "$", "user", ",", "$", "_domain", ")", ";", "}" ]
Parses a string with an e-mail address to a {@see \Niirrty\Web\MailAddress} instance. @param string $mailAddressString The e-mail address string. @param boolean $requireTLD Must the mail address contain an TLD to be parsed as valid? (default=true) @param boolean $requireKnownTLD Must the mail address contain an known TLD to be parsed as valid? (default=true) @param boolean $allowReserved Are reserved hosts/domains/TLDs allowed to be parsed as valid? (default=false) @return \Niirrty\Web\MailAddress|bool returns the MailAddress instance, or FALSE if parsing fails.
[ "Parses", "a", "string", "with", "an", "e", "-", "mail", "address", "to", "a", "{", "@see", "\\", "Niirrty", "\\", "Web", "\\", "MailAddress", "}", "instance", "." ]
train
https://github.com/Niirrty/Niirrty.Web/blob/66185109561e734f8a45e626369de5ac05afc2d5/src/MailAddress.php#L186-L232
xpl-php/Common
src/ArrayObject.php
ArrayObject.import
public function import($data) { if (! is_array($data)) { $data = is_callable(array($data, 'toArray')) ? $data->toArray() : (array)$data; } foreach($data as $key => $value) { $this[$key] = $value; } return $this; }
php
public function import($data) { if (! is_array($data)) { $data = is_callable(array($data, 'toArray')) ? $data->toArray() : (array)$data; } foreach($data as $key => $value) { $this[$key] = $value; } return $this; }
[ "public", "function", "import", "(", "$", "data", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "is_callable", "(", "array", "(", "$", "data", ",", "'toArray'", ")", ")", "?", "$", "data", "->", "toArray", "(", ")", ":", "(", "array", ")", "$", "data", ";", "}", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Implements \xpl\Common\Importable
[ "Implements", "\\", "xpl", "\\", "Common", "\\", "Importable" ]
train
https://github.com/xpl-php/Common/blob/0669bdcca29f1f8835297c2397c62fee3be5dce3/src/ArrayObject.php#L33-L44
bestit/hipchat-api
src/Client.php
Client.post
public function post($uri, $body, array $headers = []) { $defaultHeaders = [ 'Authorization' => "Bearer {$this->token}", 'Content-Type' => 'application/json', 'Accept' => 'application/json' ]; $headers = array_merge($headers, $defaultHeaders); return $this->client->post($uri, [ 'headers' => $headers, 'body' => $body ]); }
php
public function post($uri, $body, array $headers = []) { $defaultHeaders = [ 'Authorization' => "Bearer {$this->token}", 'Content-Type' => 'application/json', 'Accept' => 'application/json' ]; $headers = array_merge($headers, $defaultHeaders); return $this->client->post($uri, [ 'headers' => $headers, 'body' => $body ]); }
[ "public", "function", "post", "(", "$", "uri", ",", "$", "body", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "$", "defaultHeaders", "=", "[", "'Authorization'", "=>", "\"Bearer {$this->token}\"", ",", "'Content-Type'", "=>", "'application/json'", ",", "'Accept'", "=>", "'application/json'", "]", ";", "$", "headers", "=", "array_merge", "(", "$", "headers", ",", "$", "defaultHeaders", ")", ";", "return", "$", "this", "->", "client", "->", "post", "(", "$", "uri", ",", "[", "'headers'", "=>", "$", "headers", ",", "'body'", "=>", "$", "body", "]", ")", ";", "}" ]
Execute a POST request with the given parameters. @param string $uri @param array|string $body @param array $headers @return \Psr\Http\Message\ResponseInterface
[ "Execute", "a", "POST", "request", "with", "the", "given", "parameters", "." ]
train
https://github.com/bestit/hipchat-api/blob/2ad37856da53c17ac52e6e1c04392f6e0665d402/src/Client.php#L69-L83
devworks/sculpin-scss-bundle
src/ScssConverter.php
ScssConverter.getCompiler
protected function getCompiler() { if ($this->compiler === null) { $this->compiler = new Compiler(); $this->compiler->setFormatter($this->formatter); } return $this->compiler; }
php
protected function getCompiler() { if ($this->compiler === null) { $this->compiler = new Compiler(); $this->compiler->setFormatter($this->formatter); } return $this->compiler; }
[ "protected", "function", "getCompiler", "(", ")", "{", "if", "(", "$", "this", "->", "compiler", "===", "null", ")", "{", "$", "this", "->", "compiler", "=", "new", "Compiler", "(", ")", ";", "$", "this", "->", "compiler", "->", "setFormatter", "(", "$", "this", "->", "formatter", ")", ";", "}", "return", "$", "this", "->", "compiler", ";", "}" ]
Get the SCSS compiler. @return \Leafo\ScssPhp\Compiler
[ "Get", "the", "SCSS", "compiler", "." ]
train
https://github.com/devworks/sculpin-scss-bundle/blob/09e17ac5beec3a5067d30779f1efb0ff2c358177/src/ScssConverter.php#L83-L90
calgamo/di
sample/modules/MobileContainerModule.php
MobileContainerModule.install
public function install(ContainerInterface $container) { // david factory $container['david'] = function(){ $component = new Person('David Smith',24,179.2,function($target){ return 'throws '.$target.'.'; }); $component->smile(); return $component; }; $container->slot('david')->lock()->mustBeTypeOf('object')->mustBeInstanceOf('\Sample\PersonInterface'); // david's car factory $container['david\'s car'] = function(ContainerInterface $c){ $component = new Car($c['string.my_model_name'],$c['integer.car_seats_sedan'],true,$c['david'],$c['toyota']); $component->moveTo($c['tokyo'],true); $component->serial_number = 123456; return $component; }; $container->slot('david\'s car')->mustBeTypeOf('object'); }
php
public function install(ContainerInterface $container) { // david factory $container['david'] = function(){ $component = new Person('David Smith',24,179.2,function($target){ return 'throws '.$target.'.'; }); $component->smile(); return $component; }; $container->slot('david')->lock()->mustBeTypeOf('object')->mustBeInstanceOf('\Sample\PersonInterface'); // david's car factory $container['david\'s car'] = function(ContainerInterface $c){ $component = new Car($c['string.my_model_name'],$c['integer.car_seats_sedan'],true,$c['david'],$c['toyota']); $component->moveTo($c['tokyo'],true); $component->serial_number = 123456; return $component; }; $container->slot('david\'s car')->mustBeTypeOf('object'); }
[ "public", "function", "install", "(", "ContainerInterface", "$", "container", ")", "{", "// david factory", "$", "container", "[", "'david'", "]", "=", "function", "(", ")", "{", "$", "component", "=", "new", "Person", "(", "'David Smith'", ",", "24", ",", "179.2", ",", "function", "(", "$", "target", ")", "{", "return", "'throws '", ".", "$", "target", ".", "'.'", ";", "}", ")", ";", "$", "component", "->", "smile", "(", ")", ";", "return", "$", "component", ";", "}", ";", "$", "container", "->", "slot", "(", "'david'", ")", "->", "lock", "(", ")", "->", "mustBeTypeOf", "(", "'object'", ")", "->", "mustBeInstanceOf", "(", "'\\Sample\\PersonInterface'", ")", ";", "// david's car factory", "$", "container", "[", "'david\\'s car'", "]", "=", "function", "(", "ContainerInterface", "$", "c", ")", "{", "$", "component", "=", "new", "Car", "(", "$", "c", "[", "'string.my_model_name'", "]", ",", "$", "c", "[", "'integer.car_seats_sedan'", "]", ",", "true", ",", "$", "c", "[", "'david'", "]", ",", "$", "c", "[", "'toyota'", "]", ")", ";", "$", "component", "->", "moveTo", "(", "$", "c", "[", "'tokyo'", "]", ",", "true", ")", ";", "$", "component", "->", "serial_number", "=", "123456", ";", "return", "$", "component", ";", "}", ";", "$", "container", "->", "slot", "(", "'david\\'s car'", ")", "->", "mustBeTypeOf", "(", "'object'", ")", ";", "}" ]
Install service(s) into container @param ContainerInterface $container
[ "Install", "service", "(", "s", ")", "into", "container" ]
train
https://github.com/calgamo/di/blob/d7630628a1d6f385839a9d0a8de41aadbea657a9/sample/modules/MobileContainerModule.php#L14-L31
MindyPHP/UserBundle
Provider/UserProvider.php
UserProvider.loadUserByUsername
public function loadUserByUsername($username) { $user = $this->fetchUser($username); if (null === $user) { throw new UsernameNotFoundException(); } return $user; }
php
public function loadUserByUsername($username) { $user = $this->fetchUser($username); if (null === $user) { throw new UsernameNotFoundException(); } return $user; }
[ "public", "function", "loadUserByUsername", "(", "$", "username", ")", "{", "$", "user", "=", "$", "this", "->", "fetchUser", "(", "$", "username", ")", ";", "if", "(", "null", "===", "$", "user", ")", "{", "throw", "new", "UsernameNotFoundException", "(", ")", ";", "}", "return", "$", "user", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/MindyPHP/UserBundle/blob/c8a4b8be459793efa0690de88e5ca5abfce7ee18/Provider/UserProvider.php#L37-L45
SocietyCMS/Core
Traits/Entities/EloquentUuid.php
EloquentUuid.bootEloquentUuid
public static function bootEloquentUuid() { static::creating(function ($model) { $model->incrementing = false; $model->{$model->getKeyName()} = (string) Uuid::uuid4(); }); }
php
public static function bootEloquentUuid() { static::creating(function ($model) { $model->incrementing = false; $model->{$model->getKeyName()} = (string) Uuid::uuid4(); }); }
[ "public", "static", "function", "bootEloquentUuid", "(", ")", "{", "static", "::", "creating", "(", "function", "(", "$", "model", ")", "{", "$", "model", "->", "incrementing", "=", "false", ";", "$", "model", "->", "{", "$", "model", "->", "getKeyName", "(", ")", "}", "=", "(", "string", ")", "Uuid", "::", "uuid4", "(", ")", ";", "}", ")", ";", "}" ]
Boot EloquentUuid trait for the model. @return void
[ "Boot", "EloquentUuid", "trait", "for", "the", "model", "." ]
train
https://github.com/SocietyCMS/Core/blob/fb6be1b1dd46c89a976c02feb998e9af01ddca54/Traits/Entities/EloquentUuid.php#L18-L24
satooshi/ltsv-encoder
src/Contrib/Component/Serializer/Encoder/LtsvEncoder.php
LtsvEncoder.encode
public function encode($data, $format, array $context = array()) { return $this->encodingImpl->encode($data, self::FORMAT, $context); }
php
public function encode($data, $format, array $context = array()) { return $this->encodingImpl->encode($data, self::FORMAT, $context); }
[ "public", "function", "encode", "(", "$", "data", ",", "$", "format", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "encodingImpl", "->", "encode", "(", "$", "data", ",", "self", "::", "FORMAT", ",", "$", "context", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/satooshi/ltsv-encoder/blob/ef906c2ffe33315ae63678fc6dc116ed26fea959/src/Contrib/Component/Serializer/Encoder/LtsvEncoder.php#L49-L52
satooshi/ltsv-encoder
src/Contrib/Component/Serializer/Encoder/LtsvEncoder.php
LtsvEncoder.decode
public function decode($data, $format, array $context = array()) { return $this->decodingImpl->decode($data, self::FORMAT, $context); }
php
public function decode($data, $format, array $context = array()) { return $this->decodingImpl->decode($data, self::FORMAT, $context); }
[ "public", "function", "decode", "(", "$", "data", ",", "$", "format", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "decodingImpl", "->", "decode", "(", "$", "data", ",", "self", "::", "FORMAT", ",", "$", "context", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/satooshi/ltsv-encoder/blob/ef906c2ffe33315ae63678fc6dc116ed26fea959/src/Contrib/Component/Serializer/Encoder/LtsvEncoder.php#L57-L60
OpenResourceManager/client-php
src/Client/Room.php
Room.store
public function store( $code, $room_number, $room_label = null, $building_id = null, $building_code = null, $floor_number = null, $floor_label = null ) { $fields = []; //@todo validate params, throw exception when they are missing $fields['code'] = $code; $fields['room_number'] = $room_number; if (!is_null($room_label)) $fields['room_label'] = $room_label; if (!is_null($building_id)) $fields['building_id'] = $building_id; if (!is_null($building_code)) $fields['building_code'] = $building_code; if (!is_null($floor_number)) $fields['floor_number'] = $floor_number; if (!is_null($floor_label)) $fields['floor_label'] = $floor_label; return $this->_post($fields); }
php
public function store( $code, $room_number, $room_label = null, $building_id = null, $building_code = null, $floor_number = null, $floor_label = null ) { $fields = []; //@todo validate params, throw exception when they are missing $fields['code'] = $code; $fields['room_number'] = $room_number; if (!is_null($room_label)) $fields['room_label'] = $room_label; if (!is_null($building_id)) $fields['building_id'] = $building_id; if (!is_null($building_code)) $fields['building_code'] = $building_code; if (!is_null($floor_number)) $fields['floor_number'] = $floor_number; if (!is_null($floor_label)) $fields['floor_label'] = $floor_label; return $this->_post($fields); }
[ "public", "function", "store", "(", "$", "code", ",", "$", "room_number", ",", "$", "room_label", "=", "null", ",", "$", "building_id", "=", "null", ",", "$", "building_code", "=", "null", ",", "$", "floor_number", "=", "null", ",", "$", "floor_label", "=", "null", ")", "{", "$", "fields", "=", "[", "]", ";", "//@todo validate params, throw exception when they are missing", "$", "fields", "[", "'code'", "]", "=", "$", "code", ";", "$", "fields", "[", "'room_number'", "]", "=", "$", "room_number", ";", "if", "(", "!", "is_null", "(", "$", "room_label", ")", ")", "$", "fields", "[", "'room_label'", "]", "=", "$", "room_label", ";", "if", "(", "!", "is_null", "(", "$", "building_id", ")", ")", "$", "fields", "[", "'building_id'", "]", "=", "$", "building_id", ";", "if", "(", "!", "is_null", "(", "$", "building_code", ")", ")", "$", "fields", "[", "'building_code'", "]", "=", "$", "building_code", ";", "if", "(", "!", "is_null", "(", "$", "floor_number", ")", ")", "$", "fields", "[", "'floor_number'", "]", "=", "$", "floor_number", ";", "if", "(", "!", "is_null", "(", "$", "floor_label", ")", ")", "$", "fields", "[", "'floor_label'", "]", "=", "$", "floor_label", ";", "return", "$", "this", "->", "_post", "(", "$", "fields", ")", ";", "}" ]
Store Room Create or update a room, by it's code. @param string $code @param int $room_number @param string $room_label @param int $building_id @param string $building_code @param int $floor_number @param string $floor_label @return \Unirest\Response
[ "Store", "Room" ]
train
https://github.com/OpenResourceManager/client-php/blob/fa468e3425d32f97294fefed77a7f096f3f8cc86/src/Client/Room.php#L84-L105
dankempster/axstrad-doctrine-extensions-bundle
DependencyInjection/AxstradDoctrineExtensionsExtension.php
AxstradDoctrineExtensionsExtension.load
public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); foreach ($config['orm'] as $name => $listeners) { foreach ($listeners as $ext => $enabled) { $listener = sprintf('axstrad_doctrine_extensions.listener.%s', $ext); if ($enabled && $container->hasDefinition($listener)) { $attributes = array('connection' => $name); $definition = $container->getDefinition($listener); $definition->addTag('doctrine.event_subscriber', $attributes); } } $this->entityManagers[$name] = $listeners; } foreach ($config['class'] as $listener => $class) { $container->setParameter(sprintf('axstrad_doctrine_extensions.listener.%s.class', $listener), $class); } }
php
public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); foreach ($config['orm'] as $name => $listeners) { foreach ($listeners as $ext => $enabled) { $listener = sprintf('axstrad_doctrine_extensions.listener.%s', $ext); if ($enabled && $container->hasDefinition($listener)) { $attributes = array('connection' => $name); $definition = $container->getDefinition($listener); $definition->addTag('doctrine.event_subscriber', $attributes); } } $this->entityManagers[$name] = $listeners; } foreach ($config['class'] as $listener => $class) { $container->setParameter(sprintf('axstrad_doctrine_extensions.listener.%s.class', $listener), $class); } }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "configuration", "=", "new", "Configuration", "(", ")", ";", "$", "config", "=", "$", "this", "->", "processConfiguration", "(", "$", "configuration", ",", "$", "configs", ")", ";", "$", "loader", "=", "new", "Loader", "\\", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.xml'", ")", ";", "foreach", "(", "$", "config", "[", "'orm'", "]", "as", "$", "name", "=>", "$", "listeners", ")", "{", "foreach", "(", "$", "listeners", "as", "$", "ext", "=>", "$", "enabled", ")", "{", "$", "listener", "=", "sprintf", "(", "'axstrad_doctrine_extensions.listener.%s'", ",", "$", "ext", ")", ";", "if", "(", "$", "enabled", "&&", "$", "container", "->", "hasDefinition", "(", "$", "listener", ")", ")", "{", "$", "attributes", "=", "array", "(", "'connection'", "=>", "$", "name", ")", ";", "$", "definition", "=", "$", "container", "->", "getDefinition", "(", "$", "listener", ")", ";", "$", "definition", "->", "addTag", "(", "'doctrine.event_subscriber'", ",", "$", "attributes", ")", ";", "}", "}", "$", "this", "->", "entityManagers", "[", "$", "name", "]", "=", "$", "listeners", ";", "}", "foreach", "(", "$", "config", "[", "'class'", "]", "as", "$", "listener", "=>", "$", "class", ")", "{", "$", "container", "->", "setParameter", "(", "sprintf", "(", "'axstrad_doctrine_extensions.listener.%s.class'", ",", "$", "listener", ")", ",", "$", "class", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/dankempster/axstrad-doctrine-extensions-bundle/blob/0691037d66734d2c21f4aac43c98551b9ac102ba/DependencyInjection/AxstradDoctrineExtensionsExtension.php#L38-L62
bugadani/Validatiny
src/Rules/StringRule.php
StringRule.validate
public function validate(Validator $validator, $object, $forScenario) { if (!is_string($object)) { return false; } $length = strlen($object); if ($this->minLength !== null) { if ($length < $this->minLength) { return false; } } if ($this->maxLength !== null) { if ($length > $this->maxLength) { return false; } } return true; }
php
public function validate(Validator $validator, $object, $forScenario) { if (!is_string($object)) { return false; } $length = strlen($object); if ($this->minLength !== null) { if ($length < $this->minLength) { return false; } } if ($this->maxLength !== null) { if ($length > $this->maxLength) { return false; } } return true; }
[ "public", "function", "validate", "(", "Validator", "$", "validator", ",", "$", "object", ",", "$", "forScenario", ")", "{", "if", "(", "!", "is_string", "(", "$", "object", ")", ")", "{", "return", "false", ";", "}", "$", "length", "=", "strlen", "(", "$", "object", ")", ";", "if", "(", "$", "this", "->", "minLength", "!==", "null", ")", "{", "if", "(", "$", "length", "<", "$", "this", "->", "minLength", ")", "{", "return", "false", ";", "}", "}", "if", "(", "$", "this", "->", "maxLength", "!==", "null", ")", "{", "if", "(", "$", "length", ">", "$", "this", "->", "maxLength", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
@param Validator $validator @param $object @param $forScenario @return bool
[ "@param", "Validator", "$validator", "@param", "$object" ]
train
https://github.com/bugadani/Validatiny/blob/c35f1b29089c49528761418c229842d30dacfbdc/src/Rules/StringRule.php#L40-L59
Oktopost/Objection
src/Objection/Mapper/DataBuilders/ArrayTargetBuilder.php
ArrayTargetBuilder.addChild
public function addChild($key) { $object = new ArrayTargetBuilder(); $this->data[$key] = []; $object->data = &$this->data[$key]; return $object; }
php
public function addChild($key) { $object = new ArrayTargetBuilder(); $this->data[$key] = []; $object->data = &$this->data[$key]; return $object; }
[ "public", "function", "addChild", "(", "$", "key", ")", "{", "$", "object", "=", "new", "ArrayTargetBuilder", "(", ")", ";", "$", "this", "->", "data", "[", "$", "key", "]", "=", "[", "]", ";", "$", "object", "->", "data", "=", "&", "$", "this", "->", "data", "[", "$", "key", "]", ";", "return", "$", "object", ";", "}" ]
Add a new sub set of values under the key. The returned values will be a new builder. @param string $key @return IObjectToTargetBuilder
[ "Add", "a", "new", "sub", "set", "of", "values", "under", "the", "key", ".", "The", "returned", "values", "will", "be", "a", "new", "builder", "." ]
train
https://github.com/Oktopost/Objection/blob/71b05f9dd5ad1bbfe5f810ec5d1b1d3eb363240e/src/Objection/Mapper/DataBuilders/ArrayTargetBuilder.php#L45-L52
coolms/common
src/Listener/PhpSettingsListener.php
PhpSettingsListener.onBootstrap
public function onBootstrap(MvcEvent $e) { $config = $e->getApplication()->getServiceManager()->get('Config'); if (!empty($config[$this->configKey])) { $phpSettings = (array) $config[$this->configKey]; foreach($phpSettings as $key => $value) { @ini_set($key, $value); } } }
php
public function onBootstrap(MvcEvent $e) { $config = $e->getApplication()->getServiceManager()->get('Config'); if (!empty($config[$this->configKey])) { $phpSettings = (array) $config[$this->configKey]; foreach($phpSettings as $key => $value) { @ini_set($key, $value); } } }
[ "public", "function", "onBootstrap", "(", "MvcEvent", "$", "e", ")", "{", "$", "config", "=", "$", "e", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", "->", "get", "(", "'Config'", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "$", "this", "->", "configKey", "]", ")", ")", "{", "$", "phpSettings", "=", "(", "array", ")", "$", "config", "[", "$", "this", "->", "configKey", "]", ";", "foreach", "(", "$", "phpSettings", "as", "$", "key", "=>", "$", "value", ")", "{", "@", "ini_set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "}" ]
Event callback to be triggered on bootstrap @param MvcEvent $e @return void
[ "Event", "callback", "to", "be", "triggered", "on", "bootstrap" ]
train
https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Listener/PhpSettingsListener.php#L43-L52
clacy-builders/xml-express-php
src/Adhoc.php
Adhoc.__callstatic
public static function __callstatic($method, $arguments) { $content = count($arguments) ? $arguments[0] : null; return self::createSub($method, $content); }
php
public static function __callstatic($method, $arguments) { $content = count($arguments) ? $arguments[0] : null; return self::createSub($method, $content); }
[ "public", "static", "function", "__callstatic", "(", "$", "method", ",", "$", "arguments", ")", "{", "$", "content", "=", "count", "(", "$", "arguments", ")", "?", "$", "arguments", "[", "0", "]", ":", "null", ";", "return", "self", "::", "createSub", "(", "$", "method", ",", "$", "content", ")", ";", "}" ]
Generates the markup for an XML element. @param string $method Name of the XML element. @param array $arguments Expected length is 0 or 1 (content). @return string
[ "Generates", "the", "markup", "for", "an", "XML", "element", "." ]
train
https://github.com/clacy-builders/xml-express-php/blob/9c66fd640738b0e87b05047c3f3b8f1cba8aa7e0/src/Adhoc.php#L46-L50
php-elementary/pinba
src/Pinba.php
Pinba.timerAdd
public function timerAdd(array $tags, $value) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_add($tags, $value); } else { return null; } }
php
public function timerAdd(array $tags, $value) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_add($tags, $value); } else { return null; } }
[ "public", "function", "timerAdd", "(", "array", "$", "tags", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "$", "tags", "=", "array_merge", "(", "$", "tags", ",", "$", "this", "->", "getPinboardTags", "(", ")", ")", ";", "return", "pinba_timer_add", "(", "$", "tags", ",", "$", "value", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Creates new timer. This timer is already stopped and have specified time value. @param array $tags An array of tags and their values in the form of "tag" => "value". Cannot contain numeric indexes for obvious reasons. @param float $value Timer value for new timer. @return null|resource Always returns new timer resource. @link https://github.com/tony2001/pinba_engine/wiki/PHP-extension#pinba_timer_add
[ "Creates", "new", "timer", ".", "This", "timer", "is", "already", "stopped", "and", "have", "specified", "time", "value", "." ]
train
https://github.com/php-elementary/pinba/blob/e14724b17d5843131ed4c2802a9d1008c6ea49c8/src/Pinba.php#L44-L52
php-elementary/pinba
src/Pinba.php
Pinba.timerStart
public function timerStart(array $tags) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_start($tags); } else { return null; } }
php
public function timerStart(array $tags) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_start($tags); } else { return null; } }
[ "public", "function", "timerStart", "(", "array", "$", "tags", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "$", "tags", "=", "array_merge", "(", "$", "tags", ",", "$", "this", "->", "getPinboardTags", "(", ")", ")", ";", "return", "pinba_timer_start", "(", "$", "tags", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Creates and starts new timer. @param array $tags An array of tags and their values in the form of "tag" => "value". Cannot contain numeric indexes for obvious reasons. @return null|resource New timer resource. @link https://github.com/tony2001/pinba_engine/wiki/PHP-extension#pinba_timer_start @example <pre> $time = pinba_timer_start(array('tag' => 'value'), array('customData', 1, 2)); </pre>
[ "Creates", "and", "starts", "new", "timer", "." ]
train
https://github.com/php-elementary/pinba/blob/e14724b17d5843131ed4c2802a9d1008c6ea49c8/src/Pinba.php#L67-L75
php-elementary/pinba
src/Pinba.php
Pinba.timerTagsReplace
public function timerTagsReplace($timer, array $tags) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_tags_replace($timer, $tags); } else { return false; } }
php
public function timerTagsReplace($timer, array $tags) { if ($this->isEnabled()) { $tags = array_merge($tags, $this->getPinboardTags()); return pinba_timer_tags_replace($timer, $tags); } else { return false; } }
[ "public", "function", "timerTagsReplace", "(", "$", "timer", ",", "array", "$", "tags", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "$", "tags", "=", "array_merge", "(", "$", "tags", ",", "$", "this", "->", "getPinboardTags", "(", ")", ")", ";", "return", "pinba_timer_tags_replace", "(", "$", "timer", ",", "$", "tags", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Replaces timer tags with the passed $tags array. @param resource $timer Valid timer resource @param array $tags An array of tags and their values in the form of "tag" => "value". Cannot contain numeric indexes for obvious reasons. @return bool Returns true on success and false on failure. @link https://github.com/tony2001/pinba_engine/wiki/PHP-extension#pinba_timer_tags_replace
[ "Replaces", "timer", "tags", "with", "the", "passed", "$tags", "array", "." ]
train
https://github.com/php-elementary/pinba/blob/e14724b17d5843131ed4c2802a9d1008c6ea49c8/src/Pinba.php#L221-L229
php-elementary/pinba
src/Pinba.php
Pinba.flush
public function flush($scriptName = '', $flag = self::PINBA_FLUSH_ONLY_STOPPED_TIMERS) { if ($this->isEnabled()) { if ($scriptName || $flag) { pinba_flush($scriptName, $flag); } else { pinba_flush(); } } return $this; }
php
public function flush($scriptName = '', $flag = self::PINBA_FLUSH_ONLY_STOPPED_TIMERS) { if ($this->isEnabled()) { if ($scriptName || $flag) { pinba_flush($scriptName, $flag); } else { pinba_flush(); } } return $this; }
[ "public", "function", "flush", "(", "$", "scriptName", "=", "''", ",", "$", "flag", "=", "self", "::", "PINBA_FLUSH_ONLY_STOPPED_TIMERS", ")", "{", "if", "(", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "if", "(", "$", "scriptName", "||", "$", "flag", ")", "{", "pinba_flush", "(", "$", "scriptName", ",", "$", "flag", ")", ";", "}", "else", "{", "pinba_flush", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Useful when you need to send request data to the server immediately (for long running scripts). @param string $scriptName @param int $flag @return $this
[ "Useful", "when", "you", "need", "to", "send", "request", "data", "to", "the", "server", "immediately", "(", "for", "long", "running", "scripts", ")", "." ]
train
https://github.com/php-elementary/pinba/blob/e14724b17d5843131ed4c2802a9d1008c6ea49c8/src/Pinba.php#L383-L394
Opifer/ContentBundle
Controller/Backend/TemplateController.php
TemplateController.editorAction
public function editorAction(Request $request, Template $template) { $form = $this->createForm(new PageManagerType, $template); $form->handleRequest($request); if ($form->isValid()) { $this->get('opifer.content.block_manager')->save($template); } $parameters = [ 'subject' => $template, 'subject_type' => 'template', 'subject_id' => $template->getId(), 'view_url' => $this->generateUrl('opifer_content_template_editor_view', ['id' => $template->getId()]), 'form' => $form->createView()]; return $this->render('OpiferContentBundle:PageManager:editor.html.twig', $parameters); }
php
public function editorAction(Request $request, Template $template) { $form = $this->createForm(new PageManagerType, $template); $form->handleRequest($request); if ($form->isValid()) { $this->get('opifer.content.block_manager')->save($template); } $parameters = [ 'subject' => $template, 'subject_type' => 'template', 'subject_id' => $template->getId(), 'view_url' => $this->generateUrl('opifer_content_template_editor_view', ['id' => $template->getId()]), 'form' => $form->createView()]; return $this->render('OpiferContentBundle:PageManager:editor.html.twig', $parameters); }
[ "public", "function", "editorAction", "(", "Request", "$", "request", ",", "Template", "$", "template", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "new", "PageManagerType", ",", "$", "template", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "this", "->", "get", "(", "'opifer.content.block_manager'", ")", "->", "save", "(", "$", "template", ")", ";", "}", "$", "parameters", "=", "[", "'subject'", "=>", "$", "template", ",", "'subject_type'", "=>", "'template'", ",", "'subject_id'", "=>", "$", "template", "->", "getId", "(", ")", ",", "'view_url'", "=>", "$", "this", "->", "generateUrl", "(", "'opifer_content_template_editor_view'", ",", "[", "'id'", "=>", "$", "template", "->", "getId", "(", ")", "]", ")", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", "]", ";", "return", "$", "this", "->", "render", "(", "'OpiferContentBundle:PageManager:editor.html.twig'", ",", "$", "parameters", ")", ";", "}" ]
Graphical Template editor @param Request $request @param Template $template @return Response
[ "Graphical", "Template", "editor" ]
train
https://github.com/Opifer/ContentBundle/blob/df44ef36b81a839ce87ea9a92f7728618111541f/Controller/Backend/TemplateController.php#L74-L91
mszewcz/php-light-framework
src/Validator/Specific/Nip.php
Nip.validateNip
private function validateNip(): bool { if (!\preg_match('/^[0-9]{10}$/', $this->value)) { $this->setError(self::VALIDATOR_ERROR_NIP_INCORRECT_FORMAT); return false; } $checksum = 0; $weightArray = [6, 5, 7, 2, 3, 4, 5, 6, 7]; for ($i = 0; $i < 9; $i++) { $checksum += $weightArray[$i] * $this->value[$i]; } $isValid = $checksum % 11 == $this->value[9] ? true : false; if (!$isValid) { $this->setError(self::VALIDATOR_ERROR_NIP_INVALID_NUMBER); } return $isValid; }
php
private function validateNip(): bool { if (!\preg_match('/^[0-9]{10}$/', $this->value)) { $this->setError(self::VALIDATOR_ERROR_NIP_INCORRECT_FORMAT); return false; } $checksum = 0; $weightArray = [6, 5, 7, 2, 3, 4, 5, 6, 7]; for ($i = 0; $i < 9; $i++) { $checksum += $weightArray[$i] * $this->value[$i]; } $isValid = $checksum % 11 == $this->value[9] ? true : false; if (!$isValid) { $this->setError(self::VALIDATOR_ERROR_NIP_INVALID_NUMBER); } return $isValid; }
[ "private", "function", "validateNip", "(", ")", ":", "bool", "{", "if", "(", "!", "\\", "preg_match", "(", "'/^[0-9]{10}$/'", ",", "$", "this", "->", "value", ")", ")", "{", "$", "this", "->", "setError", "(", "self", "::", "VALIDATOR_ERROR_NIP_INCORRECT_FORMAT", ")", ";", "return", "false", ";", "}", "$", "checksum", "=", "0", ";", "$", "weightArray", "=", "[", "6", ",", "5", ",", "7", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "9", ";", "$", "i", "++", ")", "{", "$", "checksum", "+=", "$", "weightArray", "[", "$", "i", "]", "*", "$", "this", "->", "value", "[", "$", "i", "]", ";", "}", "$", "isValid", "=", "$", "checksum", "%", "11", "==", "$", "this", "->", "value", "[", "9", "]", "?", "true", ":", "false", ";", "if", "(", "!", "$", "isValid", ")", "{", "$", "this", "->", "setError", "(", "self", "::", "VALIDATOR_ERROR_NIP_INVALID_NUMBER", ")", ";", "}", "return", "$", "isValid", ";", "}" ]
Validates Nip @return bool
[ "Validates", "Nip" ]
train
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Nip.php#L39-L58
mszewcz/php-light-framework
src/Validator/Specific/Nip.php
Nip.isValid
public function isValid($value = null, array $options = []): bool { $this->setOptions($options); $this->setValue(\str_replace(['-', ' '], '', $value)); $this->errors = []; return $this->validateNip(); }
php
public function isValid($value = null, array $options = []): bool { $this->setOptions($options); $this->setValue(\str_replace(['-', ' '], '', $value)); $this->errors = []; return $this->validateNip(); }
[ "public", "function", "isValid", "(", "$", "value", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", ":", "bool", "{", "$", "this", "->", "setOptions", "(", "$", "options", ")", ";", "$", "this", "->", "setValue", "(", "\\", "str_replace", "(", "[", "'-'", ",", "' '", "]", ",", "''", ",", "$", "value", ")", ")", ";", "$", "this", "->", "errors", "=", "[", "]", ";", "return", "$", "this", "->", "validateNip", "(", ")", ";", "}" ]
Validates value @param null $value @param array $options @return bool
[ "Validates", "value" ]
train
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Nip.php#L67-L74
xervice/config
src/Xervice/Config/Business/XerviceConfig.php
XerviceConfig.set
public static function set(string $key, $value) { return self::getInstance()->getConfig()->set($key, $value); }
php
public static function set(string $key, $value) { return self::getInstance()->getConfig()->set($key, $value); }
[ "public", "static", "function", "set", "(", "string", "$", "key", ",", "$", "value", ")", "{", "return", "self", "::", "getInstance", "(", ")", "->", "getConfig", "(", ")", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
@param string $key @param mixed $value @return \Xervice\Config\Business\Container\ConfigContainer
[ "@param", "string", "$key", "@param", "mixed", "$value" ]
train
https://github.com/xervice/config/blob/11b6d9eeba9a22539a40cb9b313f4bed2fc5bdbb/src/Xervice/Config/Business/XerviceConfig.php#L71-L74
wb-crowdfusion/wb-lib
classes/eventhandlers/WbValidationHandler.php
WbValidationHandler.rejectInlineKaltura
public function rejectInlineKaltura(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), 'kaltura') !== false && stristr((string)$meta->getValue(), 'entry_id') !== false) { $errors->reject('You cannot embed Kaltura videos inline, use the provided video fields and input [[video]] into the contents instead.'); } }
php
public function rejectInlineKaltura(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), 'kaltura') !== false && stristr((string)$meta->getValue(), 'entry_id') !== false) { $errors->reject('You cannot embed Kaltura videos inline, use the provided video fields and input [[video]] into the contents instead.'); } }
[ "public", "function", "rejectInlineKaltura", "(", "Errors", "&", "$", "errors", ",", "Meta", "&", "$", "meta", ")", "{", "if", "(", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'kaltura'", ")", "!==", "false", "&&", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'entry_id'", ")", "!==", "false", ")", "{", "$", "errors", "->", "reject", "(", "'You cannot embed Kaltura videos inline, use the provided video fields and input [[video]] into the contents instead.'", ")", ";", "}", "}" ]
/* Rejects a meta field if it contains embedded kaltura video code. this forces people to use the fields and short code [[video]] rather than having blobs of kaltura code in meta fields. modified apr 25, 2012 to look for "entry_id" instead of "uiconf" so that for the most part only site specific videos are rejected, i.e. ones where the embed code was copied directly from the kmc and not via kaltura's fuck you share options. when users are embedding videos from external sites, using the share options from the player it won't have an "entry_id" setting, instead some other random shit like wid (which is normally, you know a widget id) is actually a magic pointer to the entry id. so fuck you.
[ "/", "*", "Rejects", "a", "meta", "field", "if", "it", "contains", "embedded", "kaltura", "video", "code", ".", "this", "forces", "people", "to", "use", "the", "fields", "and", "short", "code", "[[", "video", "]]", "rather", "than", "having", "blobs", "of", "kaltura", "code", "in", "meta", "fields", "." ]
train
https://github.com/wb-crowdfusion/wb-lib/blob/972b0f1d4aa2fa538ee6c6b436ac84849a579326/classes/eventhandlers/WbValidationHandler.php#L45-L50
wb-crowdfusion/wb-lib
classes/eventhandlers/WbValidationHandler.php
WbValidationHandler.rejectInlineListTool
public function rejectInlineListTool(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), '://listtool') !== false) { $errors->reject('You cannot embed the List Tool inline, use the provided fields and input [[listtool]] into the contents instead.'); } }
php
public function rejectInlineListTool(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), '://listtool') !== false) { $errors->reject('You cannot embed the List Tool inline, use the provided fields and input [[listtool]] into the contents instead.'); } }
[ "public", "function", "rejectInlineListTool", "(", "Errors", "&", "$", "errors", ",", "Meta", "&", "$", "meta", ")", "{", "if", "(", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'://listtool'", ")", "!==", "false", ")", "{", "$", "errors", "->", "reject", "(", "'You cannot embed the List Tool inline, use the provided fields and input [[listtool]] into the contents instead.'", ")", ";", "}", "}" ]
/* Rejects a meta field if it contains embedded listtool code. this forces people to use the fields and short code [[listtool]]
[ "/", "*", "Rejects", "a", "meta", "field", "if", "it", "contains", "embedded", "listtool", "code", ".", "this", "forces", "people", "to", "use", "the", "fields", "and", "short", "code", "[[", "listtool", "]]" ]
train
https://github.com/wb-crowdfusion/wb-lib/blob/972b0f1d4aa2fa538ee6c6b436ac84849a579326/classes/eventhandlers/WbValidationHandler.php#L57-L62
wb-crowdfusion/wb-lib
classes/eventhandlers/WbValidationHandler.php
WbValidationHandler.rejectInlinePoll
public function rejectInlinePoll(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), '://cdn.polls') !== false || stristr((string)$meta->getValue(), '://polls') !== false || stristr((string)$meta->getValue(), 'wb-polls/') !== false) { $errors->reject('You cannot embed Polls inline, use the provided fields and input [[poll]] into the contents instead.'); } }
php
public function rejectInlinePoll(Errors &$errors, Meta &$meta) { if (stristr((string)$meta->getValue(), '://cdn.polls') !== false || stristr((string)$meta->getValue(), '://polls') !== false || stristr((string)$meta->getValue(), 'wb-polls/') !== false) { $errors->reject('You cannot embed Polls inline, use the provided fields and input [[poll]] into the contents instead.'); } }
[ "public", "function", "rejectInlinePoll", "(", "Errors", "&", "$", "errors", ",", "Meta", "&", "$", "meta", ")", "{", "if", "(", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'://cdn.polls'", ")", "!==", "false", "||", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'://polls'", ")", "!==", "false", "||", "stristr", "(", "(", "string", ")", "$", "meta", "->", "getValue", "(", ")", ",", "'wb-polls/'", ")", "!==", "false", ")", "{", "$", "errors", "->", "reject", "(", "'You cannot embed Polls inline, use the provided fields and input [[poll]] into the contents instead.'", ")", ";", "}", "}" ]
/* Rejects a meta field if it contains embedded poll code. this forces people to use the fields and short code [[poll]]
[ "/", "*", "Rejects", "a", "meta", "field", "if", "it", "contains", "embedded", "poll", "code", ".", "this", "forces", "people", "to", "use", "the", "fields", "and", "short", "code", "[[", "poll", "]]" ]
train
https://github.com/wb-crowdfusion/wb-lib/blob/972b0f1d4aa2fa538ee6c6b436ac84849a579326/classes/eventhandlers/WbValidationHandler.php#L69-L74
webbuilders-group/silverstripe-kapost-bridge
code/extensions/KapostPageSettingsControllerExtension.php
KapostPageSettingsControllerExtension.updateEditForm
public function updateEditForm(Form $form) { $record=$form->getRecord(); if($record) { $kapostRefID=$record->KapostRefID; if(empty($kapostRefID)) { return; } //Make the fields all read only $oldFields=$form->Fields(); $form->setFields($oldFields->makeReadonly()); //Make the fields that should be non-readonly editable again if(is_array($record->config()->non_readonly_settings_fields)) { foreach($record->config()->non_readonly_settings_fields as $fieldName) { $oldField=$oldFields->dataFieldByName($fieldName); if($oldField) { $form->Fields()->replaceField($fieldName, $oldField); } } } } }
php
public function updateEditForm(Form $form) { $record=$form->getRecord(); if($record) { $kapostRefID=$record->KapostRefID; if(empty($kapostRefID)) { return; } //Make the fields all read only $oldFields=$form->Fields(); $form->setFields($oldFields->makeReadonly()); //Make the fields that should be non-readonly editable again if(is_array($record->config()->non_readonly_settings_fields)) { foreach($record->config()->non_readonly_settings_fields as $fieldName) { $oldField=$oldFields->dataFieldByName($fieldName); if($oldField) { $form->Fields()->replaceField($fieldName, $oldField); } } } } }
[ "public", "function", "updateEditForm", "(", "Form", "$", "form", ")", "{", "$", "record", "=", "$", "form", "->", "getRecord", "(", ")", ";", "if", "(", "$", "record", ")", "{", "$", "kapostRefID", "=", "$", "record", "->", "KapostRefID", ";", "if", "(", "empty", "(", "$", "kapostRefID", ")", ")", "{", "return", ";", "}", "//Make the fields all read only", "$", "oldFields", "=", "$", "form", "->", "Fields", "(", ")", ";", "$", "form", "->", "setFields", "(", "$", "oldFields", "->", "makeReadonly", "(", ")", ")", ";", "//Make the fields that should be non-readonly editable again", "if", "(", "is_array", "(", "$", "record", "->", "config", "(", ")", "->", "non_readonly_settings_fields", ")", ")", "{", "foreach", "(", "$", "record", "->", "config", "(", ")", "->", "non_readonly_settings_fields", "as", "$", "fieldName", ")", "{", "$", "oldField", "=", "$", "oldFields", "->", "dataFieldByName", "(", "$", "fieldName", ")", ";", "if", "(", "$", "oldField", ")", "{", "$", "form", "->", "Fields", "(", ")", "->", "replaceField", "(", "$", "fieldName", ",", "$", "oldField", ")", ";", "}", "}", "}", "}", "}" ]
Updates the form to make all of the fields read only with the exception of a few fields @param Form $form Form to be adjusted
[ "Updates", "the", "form", "to", "make", "all", "of", "the", "fields", "read", "only", "with", "the", "exception", "of", "a", "few", "fields" ]
train
https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/extensions/KapostPageSettingsControllerExtension.php#L12-L34
solo-framework/solo-logger
src/Parsers/IpParser.php
IpParser.parse
public function parse() { $ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unavailable'; $this->record->formatted = str_replace("{ip-address}", $ip, $this->record->formatted); return $this->record; }
php
public function parse() { $ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unavailable'; $this->record->formatted = str_replace("{ip-address}", $ip, $this->record->formatted); return $this->record; }
[ "public", "function", "parse", "(", ")", "{", "$", "ip", "=", "!", "empty", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", "?", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ":", "'unavailable'", ";", "$", "this", "->", "record", "->", "formatted", "=", "str_replace", "(", "\"{ip-address}\"", ",", "$", "ip", ",", "$", "this", "->", "record", "->", "formatted", ")", ";", "return", "$", "this", "->", "record", ";", "}" ]
Замена макросов в шаблоне лога на значения @return LogRecord
[ "Замена", "макросов", "в", "шаблоне", "лога", "на", "значения" ]
train
https://github.com/solo-framework/solo-logger/blob/2f0a9f789479c4e9ab6ee9fe5817f256eb18db70/src/Parsers/IpParser.php#L21-L26
agalbourdin/agl-core
src/Request/Request.php
Request._setRequest
private function _setRequest() { if ($this->_requestUri !== NULL) { $this->_request = preg_replace('#(^/)|(^' . ROOT . ')|(/$)#', '', $this->_requestUri); if (! $this->_request) { $this->_request = self::DEFAULT_MODULE . '/' . self::DEFAULT_VIEW; } $this->_requestVars = explode('/', $this->_request); if (count($this->_requestVars) == 1) { $this->_request .= '/' . self::DEFAULT_VIEW; $this->_requestVars[] = self::DEFAULT_VIEW; } return $this; } throw new Exception('Request URI is not available'); }
php
private function _setRequest() { if ($this->_requestUri !== NULL) { $this->_request = preg_replace('#(^/)|(^' . ROOT . ')|(/$)#', '', $this->_requestUri); if (! $this->_request) { $this->_request = self::DEFAULT_MODULE . '/' . self::DEFAULT_VIEW; } $this->_requestVars = explode('/', $this->_request); if (count($this->_requestVars) == 1) { $this->_request .= '/' . self::DEFAULT_VIEW; $this->_requestVars[] = self::DEFAULT_VIEW; } return $this; } throw new Exception('Request URI is not available'); }
[ "private", "function", "_setRequest", "(", ")", "{", "if", "(", "$", "this", "->", "_requestUri", "!==", "NULL", ")", "{", "$", "this", "->", "_request", "=", "preg_replace", "(", "'#(^/)|(^'", ".", "ROOT", ".", "')|(/$)#'", ",", "''", ",", "$", "this", "->", "_requestUri", ")", ";", "if", "(", "!", "$", "this", "->", "_request", ")", "{", "$", "this", "->", "_request", "=", "self", "::", "DEFAULT_MODULE", ".", "'/'", ".", "self", "::", "DEFAULT_VIEW", ";", "}", "$", "this", "->", "_requestVars", "=", "explode", "(", "'/'", ",", "$", "this", "->", "_request", ")", ";", "if", "(", "count", "(", "$", "this", "->", "_requestVars", ")", "==", "1", ")", "{", "$", "this", "->", "_request", ".=", "'/'", ".", "self", "::", "DEFAULT_VIEW", ";", "$", "this", "->", "_requestVars", "[", "]", "=", "self", "::", "DEFAULT_VIEW", ";", "}", "return", "$", "this", ";", "}", "throw", "new", "Exception", "(", "'Request URI is not available'", ")", ";", "}" ]
Save the request string and an equivalent as array. @return Request
[ "Save", "the", "request", "string", "and", "an", "equivalent", "as", "array", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L159-L178
agalbourdin/agl-core
src/Request/Request.php
Request._setModule
private function _setModule() { if (preg_match('/^[a-z0-9_-]+$/', $this->_requestVars[0])) { $this->_module = $this->_requestVars[0]; } else { $this->_module = $this->_requestVars[0] = self::DEFAULT_MODULE; } return $this; }
php
private function _setModule() { if (preg_match('/^[a-z0-9_-]+$/', $this->_requestVars[0])) { $this->_module = $this->_requestVars[0]; } else { $this->_module = $this->_requestVars[0] = self::DEFAULT_MODULE; } return $this; }
[ "private", "function", "_setModule", "(", ")", "{", "if", "(", "preg_match", "(", "'/^[a-z0-9_-]+$/'", ",", "$", "this", "->", "_requestVars", "[", "0", "]", ")", ")", "{", "$", "this", "->", "_module", "=", "$", "this", "->", "_requestVars", "[", "0", "]", ";", "}", "else", "{", "$", "this", "->", "_module", "=", "$", "this", "->", "_requestVars", "[", "0", "]", "=", "self", "::", "DEFAULT_MODULE", ";", "}", "return", "$", "this", ";", "}" ]
Check the module syntax and save it. @return Request|Exception
[ "Check", "the", "module", "syntax", "and", "save", "it", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L185-L194
agalbourdin/agl-core
src/Request/Request.php
Request._setView
private function _setView() { if (preg_match('/^[a-z0-9_-]+$/', $this->_requestVars[1])) { $this->_view = $this->_requestVars[1]; } else { $this->_view = $this->_requestVars[1] = self::DEFAULT_VIEW; } return $this; }
php
private function _setView() { if (preg_match('/^[a-z0-9_-]+$/', $this->_requestVars[1])) { $this->_view = $this->_requestVars[1]; } else { $this->_view = $this->_requestVars[1] = self::DEFAULT_VIEW; } return $this; }
[ "private", "function", "_setView", "(", ")", "{", "if", "(", "preg_match", "(", "'/^[a-z0-9_-]+$/'", ",", "$", "this", "->", "_requestVars", "[", "1", "]", ")", ")", "{", "$", "this", "->", "_view", "=", "$", "this", "->", "_requestVars", "[", "1", "]", ";", "}", "else", "{", "$", "this", "->", "_view", "=", "$", "this", "->", "_requestVars", "[", "1", "]", "=", "self", "::", "DEFAULT_VIEW", ";", "}", "return", "$", "this", ";", "}" ]
Check the view syntax and save it. @return Request|Exception
[ "Check", "the", "view", "syntax", "and", "save", "it", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L201-L210
agalbourdin/agl-core
src/Request/Request.php
Request._setParams
private function _setParams() { foreach ($_GET as $key => $value) { $this->_params[$key] = $this->_sanitize($value); } foreach ($_POST as $key => $value) { $_POST[$key] = $this->_sanitize($value); } $nbElements = count($this->_requestVars); if ($nbElements > 3) { $i = 2; while ($i < $nbElements and $i + 1 < $nbElements) { if (ctype_digit($this->_requestVars[$i])) { $i += 2; continue; } $this->_params[$this->_requestVars[$i]] = $this->_sanitize($this->_requestVars[$i + 1]); $i += 2; } } if ($nbElements > 2) { $i = 2; while ($i < $nbElements) { $this->_params[$i - 2] = $this->_sanitize($this->_requestVars[$i]); $i++; } } return $this; }
php
private function _setParams() { foreach ($_GET as $key => $value) { $this->_params[$key] = $this->_sanitize($value); } foreach ($_POST as $key => $value) { $_POST[$key] = $this->_sanitize($value); } $nbElements = count($this->_requestVars); if ($nbElements > 3) { $i = 2; while ($i < $nbElements and $i + 1 < $nbElements) { if (ctype_digit($this->_requestVars[$i])) { $i += 2; continue; } $this->_params[$this->_requestVars[$i]] = $this->_sanitize($this->_requestVars[$i + 1]); $i += 2; } } if ($nbElements > 2) { $i = 2; while ($i < $nbElements) { $this->_params[$i - 2] = $this->_sanitize($this->_requestVars[$i]); $i++; } } return $this; }
[ "private", "function", "_setParams", "(", ")", "{", "foreach", "(", "$", "_GET", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "$", "this", "->", "_sanitize", "(", "$", "value", ")", ";", "}", "foreach", "(", "$", "_POST", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "_POST", "[", "$", "key", "]", "=", "$", "this", "->", "_sanitize", "(", "$", "value", ")", ";", "}", "$", "nbElements", "=", "count", "(", "$", "this", "->", "_requestVars", ")", ";", "if", "(", "$", "nbElements", ">", "3", ")", "{", "$", "i", "=", "2", ";", "while", "(", "$", "i", "<", "$", "nbElements", "and", "$", "i", "+", "1", "<", "$", "nbElements", ")", "{", "if", "(", "ctype_digit", "(", "$", "this", "->", "_requestVars", "[", "$", "i", "]", ")", ")", "{", "$", "i", "+=", "2", ";", "continue", ";", "}", "$", "this", "->", "_params", "[", "$", "this", "->", "_requestVars", "[", "$", "i", "]", "]", "=", "$", "this", "->", "_sanitize", "(", "$", "this", "->", "_requestVars", "[", "$", "i", "+", "1", "]", ")", ";", "$", "i", "+=", "2", ";", "}", "}", "if", "(", "$", "nbElements", ">", "2", ")", "{", "$", "i", "=", "2", ";", "while", "(", "$", "i", "<", "$", "nbElements", ")", "{", "$", "this", "->", "_params", "[", "$", "i", "-", "2", "]", "=", "$", "this", "->", "_sanitize", "(", "$", "this", "->", "_requestVars", "[", "$", "i", "]", ")", ";", "$", "i", "++", ";", "}", "}", "return", "$", "this", ";", "}" ]
Save the URL params and sanitize POST and GET values. @return Request
[ "Save", "the", "URL", "params", "and", "sanitize", "POST", "and", "GET", "values", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L217-L250
agalbourdin/agl-core
src/Request/Request.php
Request._sanitize
private function _sanitize($pValue) { $value = trim($pValue); $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); $value = (string)$value; return $value; }
php
private function _sanitize($pValue) { $value = trim($pValue); $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); $value = (string)$value; return $value; }
[ "private", "function", "_sanitize", "(", "$", "pValue", ")", "{", "$", "value", "=", "trim", "(", "$", "pValue", ")", ";", "$", "value", "=", "htmlspecialchars", "(", "$", "value", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ";", "$", "value", "=", "(", "string", ")", "$", "value", ";", "return", "$", "value", ";", "}" ]
Sanitize the given value. @param string $pValue @return string
[ "Sanitize", "the", "given", "value", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L258-L264
agalbourdin/agl-core
src/Request/Request.php
Request.getAction
public function getAction() { $action = strtolower($this->getParam(self::ACTION_PARAM)); if ($action === '' or ! preg_match('/^[a-z0-9_-]+$/', $action)) { return Controller::DEFAULT_ACTION; } return $action; }
php
public function getAction() { $action = strtolower($this->getParam(self::ACTION_PARAM)); if ($action === '' or ! preg_match('/^[a-z0-9_-]+$/', $action)) { return Controller::DEFAULT_ACTION; } return $action; }
[ "public", "function", "getAction", "(", ")", "{", "$", "action", "=", "strtolower", "(", "$", "this", "->", "getParam", "(", "self", "::", "ACTION_PARAM", ")", ")", ";", "if", "(", "$", "action", "===", "''", "or", "!", "preg_match", "(", "'/^[a-z0-9_-]+$/'", ",", "$", "action", ")", ")", "{", "return", "Controller", "::", "DEFAULT_ACTION", ";", "}", "return", "$", "action", ";", "}" ]
Return the requested action, or the default action. @return string
[ "Return", "the", "requested", "action", "or", "the", "default", "action", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L291-L299
agalbourdin/agl-core
src/Request/Request.php
Request.getPost
public function getPost($pParam = '') { if (empty($pParam)) { return $_POST; } else if (isset($_POST[$pParam])) { return $_POST[$pParam]; } return ''; }
php
public function getPost($pParam = '') { if (empty($pParam)) { return $_POST; } else if (isset($_POST[$pParam])) { return $_POST[$pParam]; } return ''; }
[ "public", "function", "getPost", "(", "$", "pParam", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "pParam", ")", ")", "{", "return", "$", "_POST", ";", "}", "else", "if", "(", "isset", "(", "$", "_POST", "[", "$", "pParam", "]", ")", ")", "{", "return", "$", "_POST", "[", "$", "pParam", "]", ";", "}", "return", "''", ";", "}" ]
Return the POST or a POST entry if $pParam is specified. @param string $pParam @return string
[ "Return", "the", "POST", "or", "a", "POST", "entry", "if", "$pParam", "is", "specified", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L351-L360
agalbourdin/agl-core
src/Request/Request.php
Request.redirect
public static function redirect($pPath = '', array $pParams = array(), $pType = self::HTTP_CODE_REDIRECT_TEMPORARILY) { if ($pPath === '' or preg_match('#^[a-z0-9-_\*]+/[a-z0-9-_\*]+(/)?$#', $pPath)) { header('Location: ' . Url::get($pPath, $pParams), true, $pType); } else { header('Location: ' . $pPath, true, $pType); } exit; }
php
public static function redirect($pPath = '', array $pParams = array(), $pType = self::HTTP_CODE_REDIRECT_TEMPORARILY) { if ($pPath === '' or preg_match('#^[a-z0-9-_\*]+/[a-z0-9-_\*]+(/)?$#', $pPath)) { header('Location: ' . Url::get($pPath, $pParams), true, $pType); } else { header('Location: ' . $pPath, true, $pType); } exit; }
[ "public", "static", "function", "redirect", "(", "$", "pPath", "=", "''", ",", "array", "$", "pParams", "=", "array", "(", ")", ",", "$", "pType", "=", "self", "::", "HTTP_CODE_REDIRECT_TEMPORARILY", ")", "{", "if", "(", "$", "pPath", "===", "''", "or", "preg_match", "(", "'#^[a-z0-9-_\\*]+/[a-z0-9-_\\*]+(/)?$#'", ",", "$", "pPath", ")", ")", "{", "header", "(", "'Location: '", ".", "Url", "::", "get", "(", "$", "pPath", ",", "$", "pParams", ")", ",", "true", ",", "$", "pType", ")", ";", "}", "else", "{", "header", "(", "'Location: '", ".", "$", "pPath", ",", "true", ",", "$", "pType", ")", ";", "}", "exit", ";", "}" ]
Redirect the user to another page. $pPath could be an AGL formated URL (module/view) or * / to redirect to the current module, or * / * / to redirect to the current module and to the current view. @param string $pPath @param array $pParams @param int $pType Type of redirection
[ "Redirect", "the", "user", "to", "another", "page", ".", "$pPath", "could", "be", "an", "AGL", "formated", "URL", "(", "module", "/", "view", ")", "or", "*", "/", "to", "redirect", "to", "the", "current", "module", "or", "*", "/", "*", "/", "to", "redirect", "to", "the", "current", "module", "and", "to", "the", "current", "view", "." ]
train
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Request/Request.php#L372-L381
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.addItem
public function addItem($title) { if (is_object($title) && $title instanceof Item) { $item = $title; } else { $item = new Item($this, $title); } $this->item_collection->push($item); return $item; }
php
public function addItem($title) { if (is_object($title) && $title instanceof Item) { $item = $title; } else { $item = new Item($this, $title); } $this->item_collection->push($item); return $item; }
[ "public", "function", "addItem", "(", "$", "title", ")", "{", "if", "(", "is_object", "(", "$", "title", ")", "&&", "$", "title", "instanceof", "Item", ")", "{", "$", "item", "=", "$", "title", ";", "}", "else", "{", "$", "item", "=", "new", "Item", "(", "$", "this", ",", "$", "title", ")", ";", "}", "$", "this", "->", "item_collection", "->", "push", "(", "$", "item", ")", ";", "return", "$", "item", ";", "}" ]
Add item to the menu. @param string $title @return HnhDigital\NavigationBuilder\Item
[ "Add", "item", "to", "the", "menu", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L74-L85
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.filter
public function filter($property_name, $value, $include_children = false) { // Result collection. $filter_result = new Collection(); $this->item_collection->filter(function ($item) use ($property_name, $value, $include_children, &$filter_result) { if (!isset($item->$property_name)) { return false; } if ($item->$property_name == $value) { $filter_result->push($item); // Check if item has any children if ($include_children && $item->hasChildren()) { $filter_result = $filter_result->merge($this->filter('parent_id', $item->id, $include_children)); } } return false; }); return $filter_result; }
php
public function filter($property_name, $value, $include_children = false) { // Result collection. $filter_result = new Collection(); $this->item_collection->filter(function ($item) use ($property_name, $value, $include_children, &$filter_result) { if (!isset($item->$property_name)) { return false; } if ($item->$property_name == $value) { $filter_result->push($item); // Check if item has any children if ($include_children && $item->hasChildren()) { $filter_result = $filter_result->merge($this->filter('parent_id', $item->id, $include_children)); } } return false; }); return $filter_result; }
[ "public", "function", "filter", "(", "$", "property_name", ",", "$", "value", ",", "$", "include_children", "=", "false", ")", "{", "// Result collection.", "$", "filter_result", "=", "new", "Collection", "(", ")", ";", "$", "this", "->", "item_collection", "->", "filter", "(", "function", "(", "$", "item", ")", "use", "(", "$", "property_name", ",", "$", "value", ",", "$", "include_children", ",", "&", "$", "filter_result", ")", "{", "if", "(", "!", "isset", "(", "$", "item", "->", "$", "property_name", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "item", "->", "$", "property_name", "==", "$", "value", ")", "{", "$", "filter_result", "->", "push", "(", "$", "item", ")", ";", "// Check if item has any children", "if", "(", "$", "include_children", "&&", "$", "item", "->", "hasChildren", "(", ")", ")", "{", "$", "filter_result", "=", "$", "filter_result", "->", "merge", "(", "$", "this", "->", "filter", "(", "'parent_id'", ",", "$", "item", "->", "id", ",", "$", "include_children", ")", ")", ";", "}", "}", "return", "false", ";", "}", ")", ";", "return", "$", "filter_result", ";", "}" ]
Filter items by property. @param string $property_name @param string $value @param bool $include_children @return \HnhDigital\NavigationBuilder\Collection
[ "Filter", "items", "by", "property", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L147-L170
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.setAttribute
public function setAttribute($name, ...$value) { $value = is_array(array_get($value, 0, '')) ? array_get($value, 0) : $value; $this->updateAttribute($name, $value, $this->getAttributeValueSeparator($name)); return $this; }
php
public function setAttribute($name, ...$value) { $value = is_array(array_get($value, 0, '')) ? array_get($value, 0) : $value; $this->updateAttribute($name, $value, $this->getAttributeValueSeparator($name)); return $this; }
[ "public", "function", "setAttribute", "(", "$", "name", ",", "...", "$", "value", ")", "{", "$", "value", "=", "is_array", "(", "array_get", "(", "$", "value", ",", "0", ",", "''", ")", ")", "?", "array_get", "(", "$", "value", ",", "0", ")", ":", "$", "value", ";", "$", "this", "->", "updateAttribute", "(", "$", "name", ",", "$", "value", ",", "$", "this", "->", "getAttributeValueSeparator", "(", "$", "name", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set attribute by name. @param string $name @param mixed $value @return \HnhDigital\NavigationBuilder\Item
[ "Set", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L244-L250
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.addAttribute
public function addAttribute($name, ...$value) { $value = is_array(array_get($value, 0, '')) ? array_get($value, 0) : $value; list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { $current_value[] = $attribute_value; } $this->updateAttribute($name, $current_value, $separator); return $this; }
php
public function addAttribute($name, ...$value) { $value = is_array(array_get($value, 0, '')) ? array_get($value, 0) : $value; list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { $current_value[] = $attribute_value; } $this->updateAttribute($name, $current_value, $separator); return $this; }
[ "public", "function", "addAttribute", "(", "$", "name", ",", "...", "$", "value", ")", "{", "$", "value", "=", "is_array", "(", "array_get", "(", "$", "value", ",", "0", ",", "''", ")", ")", "?", "array_get", "(", "$", "value", ",", "0", ")", ":", "$", "value", ";", "list", "(", "$", "current_value", ",", "$", "separator", ")", "=", "$", "this", "->", "manipulateAttribute", "(", "$", "name", ",", "$", "value", ")", ";", "foreach", "(", "$", "value", "as", "$", "attribute_value", ")", "{", "$", "current_value", "[", "]", "=", "$", "attribute_value", ";", "}", "$", "this", "->", "updateAttribute", "(", "$", "name", ",", "$", "current_value", ",", "$", "separator", ")", ";", "return", "$", "this", ";", "}" ]
Add attribute by name. @param string $name @param mixed $value @return \HnhDigital\NavigationBuilder\Item
[ "Add", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L260-L272
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.removeAttribute
public function removeAttribute($name, $value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); $this->updateAttribute($name, $current_value, $separator); return $this; }
php
public function removeAttribute($name, $value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); $this->updateAttribute($name, $current_value, $separator); return $this; }
[ "public", "function", "removeAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "list", "(", "$", "current_value", ",", "$", "separator", ")", "=", "$", "this", "->", "manipulateAttribute", "(", "$", "name", ",", "$", "value", ")", ";", "$", "this", "->", "updateAttribute", "(", "$", "name", ",", "$", "current_value", ",", "$", "separator", ")", ";", "return", "$", "this", ";", "}" ]
Remove attribute by name. @param string $name @param mixed $value @return \HnhDigital\NavigationBuilder\Item
[ "Remove", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L282-L289
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.appendAttribute
public function appendAttribute($name, ...$value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { $current_value[] = $attribute_value; } $this->updateAttribute($name, $current_value, $separator); return $this; }
php
public function appendAttribute($name, ...$value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { $current_value[] = $attribute_value; } $this->updateAttribute($name, $current_value, $separator); return $this; }
[ "public", "function", "appendAttribute", "(", "$", "name", ",", "...", "$", "value", ")", "{", "list", "(", "$", "current_value", ",", "$", "separator", ")", "=", "$", "this", "->", "manipulateAttribute", "(", "$", "name", ",", "$", "value", ")", ";", "foreach", "(", "$", "value", "as", "$", "attribute_value", ")", "{", "$", "current_value", "[", "]", "=", "$", "attribute_value", ";", "}", "$", "this", "->", "updateAttribute", "(", "$", "name", ",", "$", "current_value", ",", "$", "separator", ")", ";", "return", "$", "this", ";", "}" ]
Append to attribute by name. @param string $name @param mixed $value @return \HnhDigital\NavigationBuilder\Item
[ "Append", "to", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L299-L310
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.prependAttribute
public function prependAttribute($name, ...$value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { array_unshift($current_value, $attribute_value); } $this->updateAttribute($name, $current_value, $separator); return $this; }
php
public function prependAttribute($name, ...$value) { list($current_value, $separator) = $this->manipulateAttribute($name, $value); foreach ($value as $attribute_value) { array_unshift($current_value, $attribute_value); } $this->updateAttribute($name, $current_value, $separator); return $this; }
[ "public", "function", "prependAttribute", "(", "$", "name", ",", "...", "$", "value", ")", "{", "list", "(", "$", "current_value", ",", "$", "separator", ")", "=", "$", "this", "->", "manipulateAttribute", "(", "$", "name", ",", "$", "value", ")", ";", "foreach", "(", "$", "value", "as", "$", "attribute_value", ")", "{", "array_unshift", "(", "$", "current_value", ",", "$", "attribute_value", ")", ";", "}", "$", "this", "->", "updateAttribute", "(", "$", "name", ",", "$", "current_value", ",", "$", "separator", ")", ";", "return", "$", "this", ";", "}" ]
Prepend to attribute by name. @param string $name @param mixed $value @return \HnhDigital\NavigationBuilder\Item
[ "Prepend", "to", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L320-L331
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.manipulateAttribute
private function manipulateAttribute($name, $value) { $current_value = array_get($this->attribute, $name, ''); $separator = (strlen(trim($current_value)) > 0) ? $this->getAttributeValueSeparator($name) : ''; $current_value = $separator !== '' ? explode($separator, $current_value) : [$current_value]; if ($name == 'class' || $name == 'style') { $value = is_array($value) ? $value : [$value]; $current_value = array_diff($current_value, $value); } return [$current_value, $separator]; }
php
private function manipulateAttribute($name, $value) { $current_value = array_get($this->attribute, $name, ''); $separator = (strlen(trim($current_value)) > 0) ? $this->getAttributeValueSeparator($name) : ''; $current_value = $separator !== '' ? explode($separator, $current_value) : [$current_value]; if ($name == 'class' || $name == 'style') { $value = is_array($value) ? $value : [$value]; $current_value = array_diff($current_value, $value); } return [$current_value, $separator]; }
[ "private", "function", "manipulateAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "$", "current_value", "=", "array_get", "(", "$", "this", "->", "attribute", ",", "$", "name", ",", "''", ")", ";", "$", "separator", "=", "(", "strlen", "(", "trim", "(", "$", "current_value", ")", ")", ">", "0", ")", "?", "$", "this", "->", "getAttributeValueSeparator", "(", "$", "name", ")", ":", "''", ";", "$", "current_value", "=", "$", "separator", "!==", "''", "?", "explode", "(", "$", "separator", ",", "$", "current_value", ")", ":", "[", "$", "current_value", "]", ";", "if", "(", "$", "name", "==", "'class'", "||", "$", "name", "==", "'style'", ")", "{", "$", "value", "=", "is_array", "(", "$", "value", ")", "?", "$", "value", ":", "[", "$", "value", "]", ";", "$", "current_value", "=", "array_diff", "(", "$", "current_value", ",", "$", "value", ")", ";", "}", "return", "[", "$", "current_value", ",", "$", "separator", "]", ";", "}" ]
Clean attribute value before required change. @param string $name @param mixed $value @return array
[ "Clean", "attribute", "value", "before", "required", "change", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L341-L353
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.updateAttribute
private function updateAttribute($name, $value, $separator) { array_set($this->attribute, $name, implode($separator, $value)); return $this; }
php
private function updateAttribute($name, $value, $separator) { array_set($this->attribute, $name, implode($separator, $value)); return $this; }
[ "private", "function", "updateAttribute", "(", "$", "name", ",", "$", "value", ",", "$", "separator", ")", "{", "array_set", "(", "$", "this", "->", "attribute", ",", "$", "name", ",", "implode", "(", "$", "separator", ",", "$", "value", ")", ")", ";", "return", "$", "this", ";", "}" ]
Update attribute by name. @param string $name @param array $value @return \HnhDigital\NavigationBuilder\Item
[ "Update", "attribute", "by", "name", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L363-L368
hnhdigital-os/laravel-navigation-builder
src/Menu.php
Menu.render
public function render($parent_id = false) { // Available options for this menu. $container_tag = array_get($this->option, 'tag', 'ul'); $item_tag = array_get($this->option, 'item_tag', 'li'); $item_callback = array_get($this->option, 'item_callback', null); $text_only = array_get($this->option, 'text_only', false); $html = ''; $items = $this->item_collection; // Render from a specific menu item. if ($parent_id !== false) { $items = $this->whereParentId($parent_id)->all(); } // Generate each of the items. foreach ($items as $item) { $item->setItemTagOption($item_tag) ->setContainerTagOption($container_tag); if (!is_null($item_callback) && is_callable($item_callback)) { $item_callback($item); $item->setItemCallbackOption($item_callback); } $html .= $item->render(2, $text_only); } // Create the container and allocate the link. return $html; }
php
public function render($parent_id = false) { // Available options for this menu. $container_tag = array_get($this->option, 'tag', 'ul'); $item_tag = array_get($this->option, 'item_tag', 'li'); $item_callback = array_get($this->option, 'item_callback', null); $text_only = array_get($this->option, 'text_only', false); $html = ''; $items = $this->item_collection; // Render from a specific menu item. if ($parent_id !== false) { $items = $this->whereParentId($parent_id)->all(); } // Generate each of the items. foreach ($items as $item) { $item->setItemTagOption($item_tag) ->setContainerTagOption($container_tag); if (!is_null($item_callback) && is_callable($item_callback)) { $item_callback($item); $item->setItemCallbackOption($item_callback); } $html .= $item->render(2, $text_only); } // Create the container and allocate the link. return $html; }
[ "public", "function", "render", "(", "$", "parent_id", "=", "false", ")", "{", "// Available options for this menu.", "$", "container_tag", "=", "array_get", "(", "$", "this", "->", "option", ",", "'tag'", ",", "'ul'", ")", ";", "$", "item_tag", "=", "array_get", "(", "$", "this", "->", "option", ",", "'item_tag'", ",", "'li'", ")", ";", "$", "item_callback", "=", "array_get", "(", "$", "this", "->", "option", ",", "'item_callback'", ",", "null", ")", ";", "$", "text_only", "=", "array_get", "(", "$", "this", "->", "option", ",", "'text_only'", ",", "false", ")", ";", "$", "html", "=", "''", ";", "$", "items", "=", "$", "this", "->", "item_collection", ";", "// Render from a specific menu item.", "if", "(", "$", "parent_id", "!==", "false", ")", "{", "$", "items", "=", "$", "this", "->", "whereParentId", "(", "$", "parent_id", ")", "->", "all", "(", ")", ";", "}", "// Generate each of the items.", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "item", "->", "setItemTagOption", "(", "$", "item_tag", ")", "->", "setContainerTagOption", "(", "$", "container_tag", ")", ";", "if", "(", "!", "is_null", "(", "$", "item_callback", ")", "&&", "is_callable", "(", "$", "item_callback", ")", ")", "{", "$", "item_callback", "(", "$", "item", ")", ";", "$", "item", "->", "setItemCallbackOption", "(", "$", "item_callback", ")", ";", "}", "$", "html", ".=", "$", "item", "->", "render", "(", "2", ",", "$", "text_only", ")", ";", "}", "// Create the container and allocate the link.", "return", "$", "html", ";", "}" ]
Render this menu and it's children. @param string $tag @return string
[ "Render", "this", "menu", "and", "it", "s", "children", "." ]
train
https://github.com/hnhdigital-os/laravel-navigation-builder/blob/37c3868a18b6cbb582a58800dbda64963828994b/src/Menu.php#L512-L542
undefined-exception-coders/UECMediaBundle
Services/MediaManager.php
MediaManager.processForm
public function processForm(FormInterface $form, $andFlush = true) { $data = $form->getData(); $this->save($data); return $data; }
php
public function processForm(FormInterface $form, $andFlush = true) { $data = $form->getData(); $this->save($data); return $data; }
[ "public", "function", "processForm", "(", "FormInterface", "$", "form", ",", "$", "andFlush", "=", "true", ")", "{", "$", "data", "=", "$", "form", "->", "getData", "(", ")", ";", "$", "this", "->", "save", "(", "$", "data", ")", ";", "return", "$", "data", ";", "}" ]
Process the Form and return the persisted MediaProvider @param FormInterface $form @param boolean $andFlush @return MediaProviderInterface
[ "Process", "the", "Form", "and", "return", "the", "persisted", "MediaProvider" ]
train
https://github.com/undefined-exception-coders/UECMediaBundle/blob/93c7bd6b3e1185ef716c26368677c08f95200f0b/Services/MediaManager.php#L68-L75
undefined-exception-coders/UECMediaBundle
Services/MediaManager.php
MediaManager.save
public function save(MediaProviderInterface $mediaProvider, $andFlush = true) { $context = $mediaProvider->getMedia()->getContext(); $provider = $this->providerService->getProviderManager($context); if (null !== $mediaProvider->getMedia()->getFile()) { $this->uploadProcess($provider, $mediaProvider); } $this->persistProcess($provider, $mediaProvider, $andFlush); }
php
public function save(MediaProviderInterface $mediaProvider, $andFlush = true) { $context = $mediaProvider->getMedia()->getContext(); $provider = $this->providerService->getProviderManager($context); if (null !== $mediaProvider->getMedia()->getFile()) { $this->uploadProcess($provider, $mediaProvider); } $this->persistProcess($provider, $mediaProvider, $andFlush); }
[ "public", "function", "save", "(", "MediaProviderInterface", "$", "mediaProvider", ",", "$", "andFlush", "=", "true", ")", "{", "$", "context", "=", "$", "mediaProvider", "->", "getMedia", "(", ")", "->", "getContext", "(", ")", ";", "$", "provider", "=", "$", "this", "->", "providerService", "->", "getProviderManager", "(", "$", "context", ")", ";", "if", "(", "null", "!==", "$", "mediaProvider", "->", "getMedia", "(", ")", "->", "getFile", "(", ")", ")", "{", "$", "this", "->", "uploadProcess", "(", "$", "provider", ",", "$", "mediaProvider", ")", ";", "}", "$", "this", "->", "persistProcess", "(", "$", "provider", ",", "$", "mediaProvider", ",", "$", "andFlush", ")", ";", "}" ]
Execute the full process for upload and persist MediaProvider @param MediaProviderInterface $mediaProvider @param boolean $andFlush
[ "Execute", "the", "full", "process", "for", "upload", "and", "persist", "MediaProvider" ]
train
https://github.com/undefined-exception-coders/UECMediaBundle/blob/93c7bd6b3e1185ef716c26368677c08f95200f0b/Services/MediaManager.php#L83-L93
webriq/core
module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php
SnippetController.createAction
public function createAction() { $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->create(); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Create' ); /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( $request->getPost() ); if ( $form->isValid() && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, ); }
php
public function createAction() { $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->create(); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Create' ); /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( $request->getPost() ); if ( $form->isValid() && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, ); }
[ "public", "function", "createAction", "(", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "locator", "=", "$", "this", "->", "getServiceLocator", "(", ")", ";", "$", "model", "=", "$", "locator", "->", "get", "(", "'Grid\\Paragraph\\Model\\Snippet\\Model'", ")", ";", "$", "snippet", "=", "$", "model", "->", "create", "(", ")", ";", "$", "form", "=", "$", "locator", "->", "get", "(", "'Form'", ")", "->", "create", "(", "'Grid\\Paragraph\\Snippet\\Create'", ")", ";", "/* @var $form \\Zend\\Form\\Form */", "$", "form", "->", "setHydrator", "(", "$", "model", "->", "getMapper", "(", ")", ")", "->", "bind", "(", "$", "snippet", ")", ";", "if", "(", "$", "request", "->", "isPost", "(", ")", ")", "{", "$", "form", "->", "setData", "(", "$", "request", "->", "getPost", "(", ")", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", "&&", "$", "snippet", "->", "save", "(", ")", ")", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.success'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_INFO", ")", ";", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ";", "}", "else", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.failed'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_ERROR", ")", ";", "}", "}", "$", "form", "->", "setCancel", "(", "$", "this", "->", "url", "(", ")", "->", "fromRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ")", ";", "return", "array", "(", "'form'", "=>", "$", "form", ",", ")", ";", "}" ]
Create a snippet
[ "Create", "a", "snippet" ]
train
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php#L53-L99
webriq/core
module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php
SnippetController.uploadAction
public function uploadAction() { $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->create(); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Upload' ); /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( ArrayUtils::merge( $request->getPost()->toArray(), $request->getFiles()->toArray() ) ); if ( $form->isValid() && ( $form->getData() ->getOption( 'overwrite' ) || $model->isNameAvailable( $snippet->name ) ) && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, ); }
php
public function uploadAction() { $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->create(); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Upload' ); /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( ArrayUtils::merge( $request->getPost()->toArray(), $request->getFiles()->toArray() ) ); if ( $form->isValid() && ( $form->getData() ->getOption( 'overwrite' ) || $model->isNameAvailable( $snippet->name ) ) && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, ); }
[ "public", "function", "uploadAction", "(", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "locator", "=", "$", "this", "->", "getServiceLocator", "(", ")", ";", "$", "model", "=", "$", "locator", "->", "get", "(", "'Grid\\Paragraph\\Model\\Snippet\\Model'", ")", ";", "$", "snippet", "=", "$", "model", "->", "create", "(", ")", ";", "$", "form", "=", "$", "locator", "->", "get", "(", "'Form'", ")", "->", "create", "(", "'Grid\\Paragraph\\Snippet\\Upload'", ")", ";", "/* @var $form \\Zend\\Form\\Form */", "$", "form", "->", "setHydrator", "(", "$", "model", "->", "getMapper", "(", ")", ")", "->", "bind", "(", "$", "snippet", ")", ";", "if", "(", "$", "request", "->", "isPost", "(", ")", ")", "{", "$", "form", "->", "setData", "(", "ArrayUtils", "::", "merge", "(", "$", "request", "->", "getPost", "(", ")", "->", "toArray", "(", ")", ",", "$", "request", "->", "getFiles", "(", ")", "->", "toArray", "(", ")", ")", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", "&&", "(", "$", "form", "->", "getData", "(", ")", "->", "getOption", "(", "'overwrite'", ")", "||", "$", "model", "->", "isNameAvailable", "(", "$", "snippet", "->", "name", ")", ")", "&&", "$", "snippet", "->", "save", "(", ")", ")", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.success'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_INFO", ")", ";", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ";", "}", "else", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.failed'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_ERROR", ")", ";", "}", "}", "$", "form", "->", "setCancel", "(", "$", "this", "->", "url", "(", ")", "->", "fromRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ")", ";", "return", "array", "(", "'form'", "=>", "$", "form", ",", ")", ";", "}" ]
Upload a snippet
[ "Upload", "a", "snippet" ]
train
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php#L104-L157
webriq/core
module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php
SnippetController.editAction
public function editAction() { static $typeToMime = array( 'css' => 'text/css', 'js' => 'text/javascript', ); /* @var $form \Zork\Form\Form */ $params = $this->params(); $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->find( $params->fromRoute( 'name' ) ); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Edit' ); if ( empty( $snippet ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $type = $snippet->type; if ( ! empty( $typeToMime[$type] ) ) { $form->get( 'code' ) ->setAttribute( 'data-js-codeeditor-mode', $typeToMime[$type] ); } /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( $request->getPost() ); if ( $form->isValid() && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, 'snippet' => $snippet, ); }
php
public function editAction() { static $typeToMime = array( 'css' => 'text/css', 'js' => 'text/javascript', ); /* @var $form \Zork\Form\Form */ $params = $this->params(); $request = $this->getRequest(); $locator = $this->getServiceLocator(); $model = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' ); $snippet = $model->find( $params->fromRoute( 'name' ) ); $form = $locator->get( 'Form' ) ->create( 'Grid\Paragraph\Snippet\Edit' ); if ( empty( $snippet ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $type = $snippet->type; if ( ! empty( $typeToMime[$type] ) ) { $form->get( 'code' ) ->setAttribute( 'data-js-codeeditor-mode', $typeToMime[$type] ); } /* @var $form \Zend\Form\Form */ $form->setHydrator( $model->getMapper() ) ->bind( $snippet ); if ( $request->isPost() ) { $form->setData( $request->getPost() ); if ( $form->isValid() && $snippet->save() ) { $this->messenger() ->add( 'paragraph.form.snippet.success', 'paragraph', Message::LEVEL_INFO ); return $this->redirect() ->toRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ); } else { $this->messenger() ->add( 'paragraph.form.snippet.failed', 'paragraph', Message::LEVEL_ERROR ); } } $form->setCancel( $this->url() ->fromRoute( 'Grid\Paragraph\Snippet\List', array( 'locale' => (string) $this->locale(), ) ) ); return array( 'form' => $form, 'snippet' => $snippet, ); }
[ "public", "function", "editAction", "(", ")", "{", "static", "$", "typeToMime", "=", "array", "(", "'css'", "=>", "'text/css'", ",", "'js'", "=>", "'text/javascript'", ",", ")", ";", "/* @var $form \\Zork\\Form\\Form */", "$", "params", "=", "$", "this", "->", "params", "(", ")", ";", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "locator", "=", "$", "this", "->", "getServiceLocator", "(", ")", ";", "$", "model", "=", "$", "locator", "->", "get", "(", "'Grid\\Paragraph\\Model\\Snippet\\Model'", ")", ";", "$", "snippet", "=", "$", "model", "->", "find", "(", "$", "params", "->", "fromRoute", "(", "'name'", ")", ")", ";", "$", "form", "=", "$", "locator", "->", "get", "(", "'Form'", ")", "->", "create", "(", "'Grid\\Paragraph\\Snippet\\Edit'", ")", ";", "if", "(", "empty", "(", "$", "snippet", ")", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "404", ")", ";", "return", ";", "}", "$", "type", "=", "$", "snippet", "->", "type", ";", "if", "(", "!", "empty", "(", "$", "typeToMime", "[", "$", "type", "]", ")", ")", "{", "$", "form", "->", "get", "(", "'code'", ")", "->", "setAttribute", "(", "'data-js-codeeditor-mode'", ",", "$", "typeToMime", "[", "$", "type", "]", ")", ";", "}", "/* @var $form \\Zend\\Form\\Form */", "$", "form", "->", "setHydrator", "(", "$", "model", "->", "getMapper", "(", ")", ")", "->", "bind", "(", "$", "snippet", ")", ";", "if", "(", "$", "request", "->", "isPost", "(", ")", ")", "{", "$", "form", "->", "setData", "(", "$", "request", "->", "getPost", "(", ")", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", "&&", "$", "snippet", "->", "save", "(", ")", ")", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.success'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_INFO", ")", ";", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ";", "}", "else", "{", "$", "this", "->", "messenger", "(", ")", "->", "add", "(", "'paragraph.form.snippet.failed'", ",", "'paragraph'", ",", "Message", "::", "LEVEL_ERROR", ")", ";", "}", "}", "$", "form", "->", "setCancel", "(", "$", "this", "->", "url", "(", ")", "->", "fromRoute", "(", "'Grid\\Paragraph\\Snippet\\List'", ",", "array", "(", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", ")", ")", ")", ";", "return", "array", "(", "'form'", "=>", "$", "form", ",", "'snippet'", "=>", "$", "snippet", ",", ")", ";", "}" ]
Edit a snippet
[ "Edit", "a", "snippet" ]
train
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/Controller/SnippetController.php#L162-L235
onesimus-systems/oslogger
src/Adaptors/FileAdaptor.php
FileAdaptor.setLogLevelFile
public function setLogLevelFile($level, $filename) { $dir = dirname($this->defaultFile); if (!is_array($level)) { $level = array($level); } foreach ($level as $loglevel) { $this->filenameLevels[$loglevel] = $dir.DIRECTORY_SEPARATOR.$filename; } }
php
public function setLogLevelFile($level, $filename) { $dir = dirname($this->defaultFile); if (!is_array($level)) { $level = array($level); } foreach ($level as $loglevel) { $this->filenameLevels[$loglevel] = $dir.DIRECTORY_SEPARATOR.$filename; } }
[ "public", "function", "setLogLevelFile", "(", "$", "level", ",", "$", "filename", ")", "{", "$", "dir", "=", "dirname", "(", "$", "this", "->", "defaultFile", ")", ";", "if", "(", "!", "is_array", "(", "$", "level", ")", ")", "{", "$", "level", "=", "array", "(", "$", "level", ")", ";", "}", "foreach", "(", "$", "level", "as", "$", "loglevel", ")", "{", "$", "this", "->", "filenameLevels", "[", "$", "loglevel", "]", "=", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "filename", ";", "}", "}" ]
Assign a file for specific log levels @param string/array $level Log level(s) that use the given $filename @param string $filename File to write logs
[ "Assign", "a", "file", "for", "specific", "log", "levels" ]
train
https://github.com/onesimus-systems/oslogger/blob/98138d4fbcae83b9cedac13ab173a3f8273de3e0/src/Adaptors/FileAdaptor.php#L57-L68
onesimus-systems/oslogger
src/Adaptors/FileAdaptor.php
FileAdaptor.separateLogFiles
public function separateLogFiles($ext = '.txt') { foreach ($this->filenameLevels as $level => $filename) { $this->setLogLevelFile($level, $level.$ext); } }
php
public function separateLogFiles($ext = '.txt') { foreach ($this->filenameLevels as $level => $filename) { $this->setLogLevelFile($level, $level.$ext); } }
[ "public", "function", "separateLogFiles", "(", "$", "ext", "=", "'.txt'", ")", "{", "foreach", "(", "$", "this", "->", "filenameLevels", "as", "$", "level", "=>", "$", "filename", ")", "{", "$", "this", "->", "setLogLevelFile", "(", "$", "level", ",", "$", "level", ".", "$", "ext", ")", ";", "}", "}" ]
Convenience function to make each log level go to a separate file. It uses the directory name of the current default file.
[ "Convenience", "function", "to", "make", "each", "log", "level", "go", "to", "a", "separate", "file", ".", "It", "uses", "the", "directory", "name", "of", "the", "current", "default", "file", "." ]
train
https://github.com/onesimus-systems/oslogger/blob/98138d4fbcae83b9cedac13ab173a3f8273de3e0/src/Adaptors/FileAdaptor.php#L79-L84