id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
12,600
borjaeu/kizilare-framework
src/Config.php
Config.get
public function get( $item ) { return isset( $this->config[$item] ) ? $this->config[$item] : null; }
php
public function get( $item ) { return isset( $this->config[$item] ) ? $this->config[$item] : null; }
[ "public", "function", "get", "(", "$", "item", ")", "{", "return", "isset", "(", "$", "this", "->", "config", "[", "$", "item", "]", ")", "?", "$", "this", "->", "config", "[", "$", "item", "]", ":", "null", ";", "}" ]
Gets configuration. @param string $item Item to get from config. @return mixed
[ "Gets", "configuration", "." ]
f4a27d4094466d358c51020cb632ad40b450e9e6
https://github.com/borjaeu/kizilare-framework/blob/f4a27d4094466d358c51020cb632ad40b450e9e6/src/Config.php#L58-L61
12,601
tacowordpress/util
src/Util/Str.php
Str.human
public static function human($str) { // Cleanup $out = str_replace('_', ' ', $str); $out = ucwords(strtolower($out)); $out = preg_replace('/\s{2,}/', ' ', $out); $out = preg_replace('/^\s/', '', $out); $out = preg_replace('/\s$/', '', $out); if (strlen($out) === 0) { return $out; } // Gather stopwords before looping $stop_words_lower = self::stopWordsLower(); // Handle each word $words = explode(' ', $out); $out_words = array(); foreach ($words as $n => $word) { $out_word = $word; // If we have a special match, don't do anything else $specials = array( '/^id$/i' => 'ID', '/^ids$/i' => 'IDs', '/^url$/i' => 'URL', '/^urls$/i' => 'URLs', '/^cta$/i' => 'CTA', '/^api$/i' => 'API', '/^faq$/i' => 'FAQ', '/^ip$/i' => 'IP', '/^why$/' => 'why', '/^Why$/' => 'Why', ); $special_word = false; foreach ($specials as $regex => $special) { if (!preg_match($regex, $word)) { continue; } $special_word = true; $out_word = $special; } if ($special_word) { $out_words[] = $out_word; continue; } // Handle acronyms without vowels if (!preg_match('/[aeiou]/i', $word)) { $out_word = strtoupper($out_word); } // Stop words $lower = strtolower($word); if (in_array($lower, $stop_words_lower) && $n !== 0) { $out_word = $lower; } $out_words[] = $out_word; } $out = join(' ', $out_words); // Questions $first_word_lower = strtolower($words[0]); $first_word_lower_no_contraction = preg_replace("/'s$/", '', $first_word_lower); $is_question = in_array($first_word_lower_no_contraction, self::questionWords()); $has_question_mark = (bool) preg_match('/\?+$/', $out); if ($is_question && !$has_question_mark) { $out .= '?'; } return $out; }
php
public static function human($str) { // Cleanup $out = str_replace('_', ' ', $str); $out = ucwords(strtolower($out)); $out = preg_replace('/\s{2,}/', ' ', $out); $out = preg_replace('/^\s/', '', $out); $out = preg_replace('/\s$/', '', $out); if (strlen($out) === 0) { return $out; } // Gather stopwords before looping $stop_words_lower = self::stopWordsLower(); // Handle each word $words = explode(' ', $out); $out_words = array(); foreach ($words as $n => $word) { $out_word = $word; // If we have a special match, don't do anything else $specials = array( '/^id$/i' => 'ID', '/^ids$/i' => 'IDs', '/^url$/i' => 'URL', '/^urls$/i' => 'URLs', '/^cta$/i' => 'CTA', '/^api$/i' => 'API', '/^faq$/i' => 'FAQ', '/^ip$/i' => 'IP', '/^why$/' => 'why', '/^Why$/' => 'Why', ); $special_word = false; foreach ($specials as $regex => $special) { if (!preg_match($regex, $word)) { continue; } $special_word = true; $out_word = $special; } if ($special_word) { $out_words[] = $out_word; continue; } // Handle acronyms without vowels if (!preg_match('/[aeiou]/i', $word)) { $out_word = strtoupper($out_word); } // Stop words $lower = strtolower($word); if (in_array($lower, $stop_words_lower) && $n !== 0) { $out_word = $lower; } $out_words[] = $out_word; } $out = join(' ', $out_words); // Questions $first_word_lower = strtolower($words[0]); $first_word_lower_no_contraction = preg_replace("/'s$/", '', $first_word_lower); $is_question = in_array($first_word_lower_no_contraction, self::questionWords()); $has_question_mark = (bool) preg_match('/\?+$/', $out); if ($is_question && !$has_question_mark) { $out .= '?'; } return $out; }
[ "public", "static", "function", "human", "(", "$", "str", ")", "{", "// Cleanup", "$", "out", "=", "str_replace", "(", "'_'", ",", "' '", ",", "$", "str", ")", ";", "$", "out", "=", "ucwords", "(", "strtolower", "(", "$", "out", ")", ")", ";", "$", "out", "=", "preg_replace", "(", "'/\\s{2,}/'", ",", "' '", ",", "$", "out", ")", ";", "$", "out", "=", "preg_replace", "(", "'/^\\s/'", ",", "''", ",", "$", "out", ")", ";", "$", "out", "=", "preg_replace", "(", "'/\\s$/'", ",", "''", ",", "$", "out", ")", ";", "if", "(", "strlen", "(", "$", "out", ")", "===", "0", ")", "{", "return", "$", "out", ";", "}", "// Gather stopwords before looping", "$", "stop_words_lower", "=", "self", "::", "stopWordsLower", "(", ")", ";", "// Handle each word", "$", "words", "=", "explode", "(", "' '", ",", "$", "out", ")", ";", "$", "out_words", "=", "array", "(", ")", ";", "foreach", "(", "$", "words", "as", "$", "n", "=>", "$", "word", ")", "{", "$", "out_word", "=", "$", "word", ";", "// If we have a special match, don't do anything else", "$", "specials", "=", "array", "(", "'/^id$/i'", "=>", "'ID'", ",", "'/^ids$/i'", "=>", "'IDs'", ",", "'/^url$/i'", "=>", "'URL'", ",", "'/^urls$/i'", "=>", "'URLs'", ",", "'/^cta$/i'", "=>", "'CTA'", ",", "'/^api$/i'", "=>", "'API'", ",", "'/^faq$/i'", "=>", "'FAQ'", ",", "'/^ip$/i'", "=>", "'IP'", ",", "'/^why$/'", "=>", "'why'", ",", "'/^Why$/'", "=>", "'Why'", ",", ")", ";", "$", "special_word", "=", "false", ";", "foreach", "(", "$", "specials", "as", "$", "regex", "=>", "$", "special", ")", "{", "if", "(", "!", "preg_match", "(", "$", "regex", ",", "$", "word", ")", ")", "{", "continue", ";", "}", "$", "special_word", "=", "true", ";", "$", "out_word", "=", "$", "special", ";", "}", "if", "(", "$", "special_word", ")", "{", "$", "out_words", "[", "]", "=", "$", "out_word", ";", "continue", ";", "}", "// Handle acronyms without vowels", "if", "(", "!", "preg_match", "(", "'/[aeiou]/i'", ",", "$", "word", ")", ")", "{", "$", "out_word", "=", "strtoupper", "(", "$", "out_word", ")", ";", "}", "// Stop words", "$", "lower", "=", "strtolower", "(", "$", "word", ")", ";", "if", "(", "in_array", "(", "$", "lower", ",", "$", "stop_words_lower", ")", "&&", "$", "n", "!==", "0", ")", "{", "$", "out_word", "=", "$", "lower", ";", "}", "$", "out_words", "[", "]", "=", "$", "out_word", ";", "}", "$", "out", "=", "join", "(", "' '", ",", "$", "out_words", ")", ";", "// Questions", "$", "first_word_lower", "=", "strtolower", "(", "$", "words", "[", "0", "]", ")", ";", "$", "first_word_lower_no_contraction", "=", "preg_replace", "(", "\"/'s$/\"", ",", "''", ",", "$", "first_word_lower", ")", ";", "$", "is_question", "=", "in_array", "(", "$", "first_word_lower_no_contraction", ",", "self", "::", "questionWords", "(", ")", ")", ";", "$", "has_question_mark", "=", "(", "bool", ")", "preg_match", "(", "'/\\?+$/'", ",", "$", "out", ")", ";", "if", "(", "$", "is_question", "&&", "!", "$", "has_question_mark", ")", "{", "$", "out", ".=", "'?'", ";", "}", "return", "$", "out", ";", "}" ]
Humanize the string @param string $str @return string
[ "Humanize", "the", "string" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L16-L89
12,602
tacowordpress/util
src/Util/Str.php
Str.machine
public static function machine($str, $separator = '_') { $out = strtolower($str); $out = preg_replace('/[^a-z0-9' . $separator . ']/', $separator, $out); $out = preg_replace('/' . $separator . '{2,}/', $separator, $out); $out = preg_replace('/^' . $separator . '/', '', $out); $out = preg_replace('/' . $separator . '$/', '', $out); return $out; }
php
public static function machine($str, $separator = '_') { $out = strtolower($str); $out = preg_replace('/[^a-z0-9' . $separator . ']/', $separator, $out); $out = preg_replace('/' . $separator . '{2,}/', $separator, $out); $out = preg_replace('/^' . $separator . '/', '', $out); $out = preg_replace('/' . $separator . '$/', '', $out); return $out; }
[ "public", "static", "function", "machine", "(", "$", "str", ",", "$", "separator", "=", "'_'", ")", "{", "$", "out", "=", "strtolower", "(", "$", "str", ")", ";", "$", "out", "=", "preg_replace", "(", "'/[^a-z0-9'", ".", "$", "separator", ".", "']/'", ",", "$", "separator", ",", "$", "out", ")", ";", "$", "out", "=", "preg_replace", "(", "'/'", ".", "$", "separator", ".", "'{2,}/'", ",", "$", "separator", ",", "$", "out", ")", ";", "$", "out", "=", "preg_replace", "(", "'/^'", ".", "$", "separator", ".", "'/'", ",", "''", ",", "$", "out", ")", ";", "$", "out", "=", "preg_replace", "(", "'/'", ".", "$", "separator", ".", "'$/'", ",", "''", ",", "$", "out", ")", ";", "return", "$", "out", ";", "}" ]
Machinize the string @param string $str @param string $separator @return string
[ "Machinize", "the", "string" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L98-L106
12,603
tacowordpress/util
src/Util/Str.php
Str.pascal
public static function pascal($str, $force = false) { $words = ($force) ? explode(' ', self::mechanize($str, ' ')) : preg_split('/[\W_]/', self::transliterate($str)); $words = array_map('ucfirst', $words); return join('', $words); }
php
public static function pascal($str, $force = false) { $words = ($force) ? explode(' ', self::mechanize($str, ' ')) : preg_split('/[\W_]/', self::transliterate($str)); $words = array_map('ucfirst', $words); return join('', $words); }
[ "public", "static", "function", "pascal", "(", "$", "str", ",", "$", "force", "=", "false", ")", "{", "$", "words", "=", "(", "$", "force", ")", "?", "explode", "(", "' '", ",", "self", "::", "mechanize", "(", "$", "str", ",", "' '", ")", ")", ":", "preg_split", "(", "'/[\\W_]/'", ",", "self", "::", "transliterate", "(", "$", "str", ")", ")", ";", "$", "words", "=", "array_map", "(", "'ucfirst'", ",", "$", "words", ")", ";", "return", "join", "(", "''", ",", "$", "words", ")", ";", "}" ]
Convert to Pascal case Forcing will remove any existing uppercase Example: "Fetch HTML" - Without force: "FetchHTML" - With force: "FetchHtml" @param string $str @param bool $force @return string
[ "Convert", "to", "Pascal", "case" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L252-L260
12,604
tacowordpress/util
src/Util/Str.php
Str.convert
public static function convert($input, $from, $to) { if (!method_exists(self::class, $to)) { return $input; } if (in_array($from, ['camel', 'pascal'])) { $converted = self::$from($input); $converted = preg_replace('/([a-z])([A-Z])/', '$1 $2', $converted); $converted = preg_replace('/(\D)?(\d+)(\D)?/', '$1 $2 $3', $converted); return self::$to($converted); } if (method_exists(self::class, $from)) { return self::$to(self::$from($input)); } return self::$to($input); }
php
public static function convert($input, $from, $to) { if (!method_exists(self::class, $to)) { return $input; } if (in_array($from, ['camel', 'pascal'])) { $converted = self::$from($input); $converted = preg_replace('/([a-z])([A-Z])/', '$1 $2', $converted); $converted = preg_replace('/(\D)?(\d+)(\D)?/', '$1 $2 $3', $converted); return self::$to($converted); } if (method_exists(self::class, $from)) { return self::$to(self::$from($input)); } return self::$to($input); }
[ "public", "static", "function", "convert", "(", "$", "input", ",", "$", "from", ",", "$", "to", ")", "{", "if", "(", "!", "method_exists", "(", "self", "::", "class", ",", "$", "to", ")", ")", "{", "return", "$", "input", ";", "}", "if", "(", "in_array", "(", "$", "from", ",", "[", "'camel'", ",", "'pascal'", "]", ")", ")", "{", "$", "converted", "=", "self", "::", "$", "from", "(", "$", "input", ")", ";", "$", "converted", "=", "preg_replace", "(", "'/([a-z])([A-Z])/'", ",", "'$1 $2'", ",", "$", "converted", ")", ";", "$", "converted", "=", "preg_replace", "(", "'/(\\D)?(\\d+)(\\D)?/'", ",", "'$1 $2 $3'", ",", "$", "converted", ")", ";", "return", "self", "::", "$", "to", "(", "$", "converted", ")", ";", "}", "if", "(", "method_exists", "(", "self", "::", "class", ",", "$", "from", ")", ")", "{", "return", "self", "::", "$", "to", "(", "self", "::", "$", "from", "(", "$", "input", ")", ")", ";", "}", "return", "self", "::", "$", "to", "(", "$", "input", ")", ";", "}" ]
Convert between two string formats @param string $input @param string $from @param string $to @return string
[ "Convert", "between", "two", "string", "formats" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L303-L321
12,605
tacowordpress/util
src/Util/Str.php
Str.shortenWords
public static function shortenWords($input, $num_words = 35, $hellip = '&hellip;') { $words = explode(' ', $input); return (count($words) <= $num_words) ? join(' ', $words) : join(' ', array_slice($words, 0, $num_words)) . $hellip; }
php
public static function shortenWords($input, $num_words = 35, $hellip = '&hellip;') { $words = explode(' ', $input); return (count($words) <= $num_words) ? join(' ', $words) : join(' ', array_slice($words, 0, $num_words)) . $hellip; }
[ "public", "static", "function", "shortenWords", "(", "$", "input", ",", "$", "num_words", "=", "35", ",", "$", "hellip", "=", "'&hellip;'", ")", "{", "$", "words", "=", "explode", "(", "' '", ",", "$", "input", ")", ";", "return", "(", "count", "(", "$", "words", ")", "<=", "$", "num_words", ")", "?", "join", "(", "' '", ",", "$", "words", ")", ":", "join", "(", "' '", ",", "array_slice", "(", "$", "words", ",", "0", ",", "$", "num_words", ")", ")", ".", "$", "hellip", ";", "}" ]
Shorten a string @param string $input @param integer $num_words @param string $hellip @return string
[ "Shorten", "a", "string" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L364-L370
12,606
tacowordpress/util
src/Util/Str.php
Str.shortenWordsByChar
public static function shortenWordsByChar($input, $num_chars = 35, $hellip = '&nbsp;&hellip;') { if (strlen($input) <= $num_chars) { return $input; } $shortened = substr($input, 0, $num_chars); $shortened_words = array_filter(explode(' ', $shortened)); end($shortened_words); $last_key = key($shortened_words); $words = explode(' ', $input); $words = array_slice($words, 0, $last_key + 1); if ($words[$last_key] !== $shortened_words[$last_key]) { unset($words[$last_key]); } return join(' ', $words) . $hellip; }
php
public static function shortenWordsByChar($input, $num_chars = 35, $hellip = '&nbsp;&hellip;') { if (strlen($input) <= $num_chars) { return $input; } $shortened = substr($input, 0, $num_chars); $shortened_words = array_filter(explode(' ', $shortened)); end($shortened_words); $last_key = key($shortened_words); $words = explode(' ', $input); $words = array_slice($words, 0, $last_key + 1); if ($words[$last_key] !== $shortened_words[$last_key]) { unset($words[$last_key]); } return join(' ', $words) . $hellip; }
[ "public", "static", "function", "shortenWordsByChar", "(", "$", "input", ",", "$", "num_chars", "=", "35", ",", "$", "hellip", "=", "'&nbsp;&hellip;'", ")", "{", "if", "(", "strlen", "(", "$", "input", ")", "<=", "$", "num_chars", ")", "{", "return", "$", "input", ";", "}", "$", "shortened", "=", "substr", "(", "$", "input", ",", "0", ",", "$", "num_chars", ")", ";", "$", "shortened_words", "=", "array_filter", "(", "explode", "(", "' '", ",", "$", "shortened", ")", ")", ";", "end", "(", "$", "shortened_words", ")", ";", "$", "last_key", "=", "key", "(", "$", "shortened_words", ")", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "input", ")", ";", "$", "words", "=", "array_slice", "(", "$", "words", ",", "0", ",", "$", "last_key", "+", "1", ")", ";", "if", "(", "$", "words", "[", "$", "last_key", "]", "!==", "$", "shortened_words", "[", "$", "last_key", "]", ")", "{", "unset", "(", "$", "words", "[", "$", "last_key", "]", ")", ";", "}", "return", "join", "(", "' '", ",", "$", "words", ")", ".", "$", "hellip", ";", "}" ]
Shorten a string by character limit, preserving words @param string $input @param integer $num_chars @param string $hellip @return string
[ "Shorten", "a", "string", "by", "character", "limit", "preserving", "words" ]
a27f6f1c3f96a908c7480f359fd44028e89f26c3
https://github.com/tacowordpress/util/blob/a27f6f1c3f96a908c7480f359fd44028e89f26c3/src/Util/Str.php#L380-L397
12,607
atelierspierrot/library
src/Library/Logger.php
Logger.init
protected function init(array $user_options=array(), $logname = null) { $this->logname = $logname; if (true===self::$isInited) return; foreach (self::$config as $_static=>$_value) { $this->$_static = $_value; } foreach ($user_options as $_static=>$_value) { if (isset($this->$_static) && is_array($this->$_static)) { $this->$_static = array_merge($this->$_static, is_array($_value) ? $_value : array($_value)); } else { $this->$_static = $_value; } } self::$isInited = true; }
php
protected function init(array $user_options=array(), $logname = null) { $this->logname = $logname; if (true===self::$isInited) return; foreach (self::$config as $_static=>$_value) { $this->$_static = $_value; } foreach ($user_options as $_static=>$_value) { if (isset($this->$_static) && is_array($this->$_static)) { $this->$_static = array_merge($this->$_static, is_array($_value) ? $_value : array($_value)); } else { $this->$_static = $_value; } } self::$isInited = true; }
[ "protected", "function", "init", "(", "array", "$", "user_options", "=", "array", "(", ")", ",", "$", "logname", "=", "null", ")", "{", "$", "this", "->", "logname", "=", "$", "logname", ";", "if", "(", "true", "===", "self", "::", "$", "isInited", ")", "return", ";", "foreach", "(", "self", "::", "$", "config", "as", "$", "_static", "=>", "$", "_value", ")", "{", "$", "this", "->", "$", "_static", "=", "$", "_value", ";", "}", "foreach", "(", "$", "user_options", "as", "$", "_static", "=>", "$", "_value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "$", "_static", ")", "&&", "is_array", "(", "$", "this", "->", "$", "_static", ")", ")", "{", "$", "this", "->", "$", "_static", "=", "array_merge", "(", "$", "this", "->", "$", "_static", ",", "is_array", "(", "$", "_value", ")", "?", "$", "_value", ":", "array", "(", "$", "_value", ")", ")", ";", "}", "else", "{", "$", "this", "->", "$", "_static", "=", "$", "_value", ";", "}", "}", "self", "::", "$", "isInited", "=", "true", ";", "}" ]
Load the configuration info @param array $user_options @param string $logname
[ "Load", "the", "configuration", "info" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L149-L165
12,608
atelierspierrot/library
src/Library/Logger.php
Logger.addRecord
protected function addRecord($level, $message, array $context = array()) { $message = $this->interpolate($message, $context); $record = array( 'message' => (string) $message, 'context' => $context, 'level' => self::getLevelCode($level), 'level_name' => strtoupper($level), 'datetime' => new \DateTime(), 'ip' => self::getUserIp(), 'pid' => @getmypid(), 'extra' => array(), ); return self::write(self::getLogRecord($record)."\n", $level); }
php
protected function addRecord($level, $message, array $context = array()) { $message = $this->interpolate($message, $context); $record = array( 'message' => (string) $message, 'context' => $context, 'level' => self::getLevelCode($level), 'level_name' => strtoupper($level), 'datetime' => new \DateTime(), 'ip' => self::getUserIp(), 'pid' => @getmypid(), 'extra' => array(), ); return self::write(self::getLogRecord($record)."\n", $level); }
[ "protected", "function", "addRecord", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "$", "message", "=", "$", "this", "->", "interpolate", "(", "$", "message", ",", "$", "context", ")", ";", "$", "record", "=", "array", "(", "'message'", "=>", "(", "string", ")", "$", "message", ",", "'context'", "=>", "$", "context", ",", "'level'", "=>", "self", "::", "getLevelCode", "(", "$", "level", ")", ",", "'level_name'", "=>", "strtoupper", "(", "$", "level", ")", ",", "'datetime'", "=>", "new", "\\", "DateTime", "(", ")", ",", "'ip'", "=>", "self", "::", "getUserIp", "(", ")", ",", "'pid'", "=>", "@", "getmypid", "(", ")", ",", "'extra'", "=>", "array", "(", ")", ",", ")", ";", "return", "self", "::", "write", "(", "self", "::", "getLogRecord", "(", "$", "record", ")", ".", "\"\\n\"", ",", "$", "level", ")", ";", "}" ]
Create a new log record and writes it @param string $message The message info to log @param int $level A type for the message, must be a class constant @param array $context An optional context array for the message @return bool
[ "Create", "a", "new", "log", "record", "and", "writes", "it" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L256-L270
12,609
atelierspierrot/library
src/Library/Logger.php
Logger.write
protected function write($line, $level = 100) { $logfile = $this->getFilePath($level); $rotator = $this->getRotator($logfile); $return = $rotator->write($line); if ($this->isErrorLevel($level) && true===$this->duplicate_errors) self::write($line, 100); return $return; }
php
protected function write($line, $level = 100) { $logfile = $this->getFilePath($level); $rotator = $this->getRotator($logfile); $return = $rotator->write($line); if ($this->isErrorLevel($level) && true===$this->duplicate_errors) self::write($line, 100); return $return; }
[ "protected", "function", "write", "(", "$", "line", ",", "$", "level", "=", "100", ")", "{", "$", "logfile", "=", "$", "this", "->", "getFilePath", "(", "$", "level", ")", ";", "$", "rotator", "=", "$", "this", "->", "getRotator", "(", "$", "logfile", ")", ";", "$", "return", "=", "$", "rotator", "->", "write", "(", "$", "line", ")", ";", "if", "(", "$", "this", "->", "isErrorLevel", "(", "$", "level", ")", "&&", "true", "===", "$", "this", "->", "duplicate_errors", ")", "self", "::", "write", "(", "$", "line", ",", "100", ")", ";", "return", "$", "return", ";", "}" ]
Write a new line in the logfile @param string $line The formated line to write in log file @param int $level The level of the current log info (default is 100) @return bool
[ "Write", "a", "new", "line", "in", "the", "logfile" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L279-L289
12,610
atelierspierrot/library
src/Library/Logger.php
Logger.getRotator
protected function getRotator($filename) { if (!array_key_exists($filename, self::$rotators)) { self::$rotators[$filename] = new FileRotator( $filename, FileRotator::ROTATE_PERIODIC, $this->rotator ); } return self::$rotators[$filename]; }
php
protected function getRotator($filename) { if (!array_key_exists($filename, self::$rotators)) { self::$rotators[$filename] = new FileRotator( $filename, FileRotator::ROTATE_PERIODIC, $this->rotator ); } return self::$rotators[$filename]; }
[ "protected", "function", "getRotator", "(", "$", "filename", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "filename", ",", "self", "::", "$", "rotators", ")", ")", "{", "self", "::", "$", "rotators", "[", "$", "filename", "]", "=", "new", "FileRotator", "(", "$", "filename", ",", "FileRotator", "::", "ROTATE_PERIODIC", ",", "$", "this", "->", "rotator", ")", ";", "}", "return", "self", "::", "$", "rotators", "[", "$", "filename", "]", ";", "}" ]
Get a rotator for a specific logfile @param string $filename The name (full path) of the concerned logfile @return \Library\Tool\FileRotator
[ "Get", "a", "rotator", "for", "a", "specific", "logfile" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L297-L305
12,611
atelierspierrot/library
src/Library/Logger.php
Logger.isErrorLevel
protected function isErrorLevel($level) { if (!is_numeric($level)) $level = $this->getLevelCode($level); return (bool) ($level>300); }
php
protected function isErrorLevel($level) { if (!is_numeric($level)) $level = $this->getLevelCode($level); return (bool) ($level>300); }
[ "protected", "function", "isErrorLevel", "(", "$", "level", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "level", ")", ")", "$", "level", "=", "$", "this", "->", "getLevelCode", "(", "$", "level", ")", ";", "return", "(", "bool", ")", "(", "$", "level", ">", "300", ")", ";", "}" ]
Is the current log level an error one @param int $level A type for the message, must be a class constant @return bool True if the level is more than a warning
[ "Is", "the", "current", "log", "level", "an", "error", "one" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L328-L332
12,612
atelierspierrot/library
src/Library/Logger.php
Logger.getLevelName
protected function getLevelName($level) { return in_array($level, self::$levels) ? array_search($level, self::$levels) : '--'; }
php
protected function getLevelName($level) { return in_array($level, self::$levels) ? array_search($level, self::$levels) : '--'; }
[ "protected", "function", "getLevelName", "(", "$", "level", ")", "{", "return", "in_array", "(", "$", "level", ",", "self", "::", "$", "levels", ")", "?", "array_search", "(", "$", "level", ",", "self", "::", "$", "levels", ")", ":", "'--'", ";", "}" ]
Get a level name @param int $level A type for the message, must be a class constant @return string The level name if found, '--' otherwise
[ "Get", "a", "level", "name" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L340-L343
12,613
atelierspierrot/library
src/Library/Logger.php
Logger.getLogRecord
protected function getLogRecord($record) { $prefix = $suffix = array(); // first infos $date = $record['datetime']->format( $this->datetime_format ); $prefix[] = '['.$date.']'; if (!empty($record['ip'])) $prefix[] = '[ip '.$record['ip'].']'; if (!empty($record['pid'])) $prefix[] = '[pid '.$record['pid'].']'; $prefix[] = $record['level_name'].' :'; // last infos if (!empty($record['context'])) { $suffix[] = '['.$this->writeArray($record['context']).']'; } if (!empty($record['extra'])) { $suffix[] = '['.$this->writeArray($record['extra']).']'; } return join(' ', $prefix).' '.preg_replace("/\n*$/", ' ', $record['message']).' '.join(' ', $suffix); }
php
protected function getLogRecord($record) { $prefix = $suffix = array(); // first infos $date = $record['datetime']->format( $this->datetime_format ); $prefix[] = '['.$date.']'; if (!empty($record['ip'])) $prefix[] = '[ip '.$record['ip'].']'; if (!empty($record['pid'])) $prefix[] = '[pid '.$record['pid'].']'; $prefix[] = $record['level_name'].' :'; // last infos if (!empty($record['context'])) { $suffix[] = '['.$this->writeArray($record['context']).']'; } if (!empty($record['extra'])) { $suffix[] = '['.$this->writeArray($record['extra']).']'; } return join(' ', $prefix).' '.preg_replace("/\n*$/", ' ', $record['message']).' '.join(' ', $suffix); }
[ "protected", "function", "getLogRecord", "(", "$", "record", ")", "{", "$", "prefix", "=", "$", "suffix", "=", "array", "(", ")", ";", "// first infos", "$", "date", "=", "$", "record", "[", "'datetime'", "]", "->", "format", "(", "$", "this", "->", "datetime_format", ")", ";", "$", "prefix", "[", "]", "=", "'['", ".", "$", "date", ".", "']'", ";", "if", "(", "!", "empty", "(", "$", "record", "[", "'ip'", "]", ")", ")", "$", "prefix", "[", "]", "=", "'[ip '", ".", "$", "record", "[", "'ip'", "]", ".", "']'", ";", "if", "(", "!", "empty", "(", "$", "record", "[", "'pid'", "]", ")", ")", "$", "prefix", "[", "]", "=", "'[pid '", ".", "$", "record", "[", "'pid'", "]", ".", "']'", ";", "$", "prefix", "[", "]", "=", "$", "record", "[", "'level_name'", "]", ".", "' :'", ";", "// last infos", "if", "(", "!", "empty", "(", "$", "record", "[", "'context'", "]", ")", ")", "{", "$", "suffix", "[", "]", "=", "'['", ".", "$", "this", "->", "writeArray", "(", "$", "record", "[", "'context'", "]", ")", ".", "']'", ";", "}", "if", "(", "!", "empty", "(", "$", "record", "[", "'extra'", "]", ")", ")", "{", "$", "suffix", "[", "]", "=", "'['", ".", "$", "this", "->", "writeArray", "(", "$", "record", "[", "'extra'", "]", ")", ".", "']'", ";", "}", "return", "join", "(", "' '", ",", "$", "prefix", ")", ".", "' '", ".", "preg_replace", "(", "\"/\\n*$/\"", ",", "' '", ",", "$", "record", "[", "'message'", "]", ")", ".", "' '", ".", "join", "(", "' '", ",", "$", "suffix", ")", ";", "}" ]
Build a log line from a complex array @param array $record An array built by the "addRecord()" method @return string The line formated and ready to be written @see self::addRecord()
[ "Build", "a", "log", "line", "from", "a", "complex", "array" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L363-L385
12,614
atelierspierrot/library
src/Library/Logger.php
Logger.getFilePath
protected function getFilePath($level = 100) { $filename = $this->getFileName($level); $filext = '.'.trim($this->logfile_extension, '.'); $filename = str_replace($filext, '', $filename) . $filext; return rtrim($this->directory, '/') . '/' . $filename; }
php
protected function getFilePath($level = 100) { $filename = $this->getFileName($level); $filext = '.'.trim($this->logfile_extension, '.'); $filename = str_replace($filext, '', $filename) . $filext; return rtrim($this->directory, '/') . '/' . $filename; }
[ "protected", "function", "getFilePath", "(", "$", "level", "=", "100", ")", "{", "$", "filename", "=", "$", "this", "->", "getFileName", "(", "$", "level", ")", ";", "$", "filext", "=", "'.'", ".", "trim", "(", "$", "this", "->", "logfile_extension", ",", "'.'", ")", ";", "$", "filename", "=", "str_replace", "(", "$", "filext", ",", "''", ",", "$", "filename", ")", ".", "$", "filext", ";", "return", "rtrim", "(", "$", "this", "->", "directory", ",", "'/'", ")", ".", "'/'", ".", "$", "filename", ";", "}" ]
Get the log file path @param int $level The level of the current log info (default is 100) @return string The absolute path of the logfile to write in
[ "Get", "the", "log", "file", "path" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L393-L399
12,615
atelierspierrot/library
src/Library/Logger.php
Logger.getFileName
protected function getFileName($level = 100) { return !empty($this->logname) ? $this->logname : ( $this->isErrorLevel($level) ? $this->error_logfile : $this->logfile ); }
php
protected function getFileName($level = 100) { return !empty($this->logname) ? $this->logname : ( $this->isErrorLevel($level) ? $this->error_logfile : $this->logfile ); }
[ "protected", "function", "getFileName", "(", "$", "level", "=", "100", ")", "{", "return", "!", "empty", "(", "$", "this", "->", "logname", ")", "?", "$", "this", "->", "logname", ":", "(", "$", "this", "->", "isErrorLevel", "(", "$", "level", ")", "?", "$", "this", "->", "error_logfile", ":", "$", "this", "->", "logfile", ")", ";", "}" ]
Get the log file name @param int $level The level of the current log info (default is 100) @return string The logfile name to write in
[ "Get", "the", "log", "file", "name" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L407-L410
12,616
atelierspierrot/library
src/Library/Logger.php
Logger.getUserIp
public static function getUserIp() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; elseif (isset($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; else $ip = $_SERVER['REMOTE_ADDR']; return $ip; }
php
public static function getUserIp() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; elseif (isset($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; else $ip = $_SERVER['REMOTE_ADDR']; return $ip; }
[ "public", "static", "function", "getUserIp", "(", ")", "{", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ")", ")", "$", "ip", "=", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_FOR'", "]", ";", "elseif", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_CLIENT_IP'", "]", ")", ")", "$", "ip", "=", "$", "_SERVER", "[", "'HTTP_CLIENT_IP'", "]", ";", "else", "$", "ip", "=", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ";", "return", "$", "ip", ";", "}" ]
Get the user IP address
[ "Get", "the", "user", "IP", "address" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L419-L428
12,617
atelierspierrot/library
src/Library/Logger.php
Logger.writeArray
public static function writeArray($array) { $data = array(); foreach ($array as $var=>$val) { if (is_array($val) && !is_object($val)) { $data[$var] = self::writeArray($val); } else { $data[$var] = self::writeArrayItem($val); } } return serialize($data); }
php
public static function writeArray($array) { $data = array(); foreach ($array as $var=>$val) { if (is_array($val) && !is_object($val)) { $data[$var] = self::writeArray($val); } else { $data[$var] = self::writeArrayItem($val); } } return serialize($data); }
[ "public", "static", "function", "writeArray", "(", "$", "array", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "var", "=>", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", "&&", "!", "is_object", "(", "$", "val", ")", ")", "{", "$", "data", "[", "$", "var", "]", "=", "self", "::", "writeArray", "(", "$", "val", ")", ";", "}", "else", "{", "$", "data", "[", "$", "var", "]", "=", "self", "::", "writeArrayItem", "(", "$", "val", ")", ";", "}", "}", "return", "serialize", "(", "$", "data", ")", ";", "}" ]
Write an array on one line @param array $array @return string The formatted string
[ "Write", "an", "array", "on", "one", "line" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L436-L447
12,618
atelierspierrot/library
src/Library/Logger.php
Logger.writeArrayItem
public static function writeArrayItem($item) { $str = ''; try { $str .= serialize($item); } catch (\Exception $e) { if (is_object($item)) { $str .= get_class($item).'#'; } $str .= spl_object_hash($item); } return $str; }
php
public static function writeArrayItem($item) { $str = ''; try { $str .= serialize($item); } catch (\Exception $e) { if (is_object($item)) { $str .= get_class($item).'#'; } $str .= spl_object_hash($item); } return $str; }
[ "public", "static", "function", "writeArrayItem", "(", "$", "item", ")", "{", "$", "str", "=", "''", ";", "try", "{", "$", "str", ".=", "serialize", "(", "$", "item", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "is_object", "(", "$", "item", ")", ")", "{", "$", "str", ".=", "get_class", "(", "$", "item", ")", ".", "'#'", ";", "}", "$", "str", ".=", "spl_object_hash", "(", "$", "item", ")", ";", "}", "return", "$", "str", ";", "}" ]
Safely transform an array item in string @param array $item @return string The formatted string
[ "Safely", "transform", "an", "array", "item", "in", "string" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Logger.php#L455-L467
12,619
ekyna/Characteristics
Form/EventListener/CharacteristicsResizeListener.php
CharacteristicsResizeListener.preSetData
public function preSetData(FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); if (null === $data) { throw new \InvalidArgumentException('Can\'t handle null datas.'); } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)'); } foreach ($form as $name => $child) { $form->remove($name); } foreach ($this->schema->getGroups() as $schemaGroup) { $form->add($schemaGroup->getName(), new GroupType(), array('label' => $schemaGroup->getTitle())); $groupForm = $form->get($schemaGroup->getName()); foreach ($schemaGroup->getDefinitions() as $schemaDefinition) { if (true === $schemaDefinition->getVirtual()) { continue; } $this->appendProperForm($groupForm, $schemaDefinition); $this->appendProperData($data, $schemaDefinition); } } $event->setData($data); }
php
public function preSetData(FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); if (null === $data) { throw new \InvalidArgumentException('Can\'t handle null datas.'); } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)'); } foreach ($form as $name => $child) { $form->remove($name); } foreach ($this->schema->getGroups() as $schemaGroup) { $form->add($schemaGroup->getName(), new GroupType(), array('label' => $schemaGroup->getTitle())); $groupForm = $form->get($schemaGroup->getName()); foreach ($schemaGroup->getDefinitions() as $schemaDefinition) { if (true === $schemaDefinition->getVirtual()) { continue; } $this->appendProperForm($groupForm, $schemaDefinition); $this->appendProperData($data, $schemaDefinition); } } $event->setData($data); }
[ "public", "function", "preSetData", "(", "FormEvent", "$", "event", ")", "{", "$", "form", "=", "$", "event", "->", "getForm", "(", ")", ";", "$", "data", "=", "$", "event", "->", "getData", "(", ")", ";", "if", "(", "null", "===", "$", "data", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Can\\'t handle null datas.'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", "&&", "!", "(", "$", "data", "instanceof", "\\", "Traversable", "&&", "$", "data", "instanceof", "\\", "ArrayAccess", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "data", ",", "'array or (\\Traversable and \\ArrayAccess)'", ")", ";", "}", "foreach", "(", "$", "form", "as", "$", "name", "=>", "$", "child", ")", "{", "$", "form", "->", "remove", "(", "$", "name", ")", ";", "}", "foreach", "(", "$", "this", "->", "schema", "->", "getGroups", "(", ")", "as", "$", "schemaGroup", ")", "{", "$", "form", "->", "add", "(", "$", "schemaGroup", "->", "getName", "(", ")", ",", "new", "GroupType", "(", ")", ",", "array", "(", "'label'", "=>", "$", "schemaGroup", "->", "getTitle", "(", ")", ")", ")", ";", "$", "groupForm", "=", "$", "form", "->", "get", "(", "$", "schemaGroup", "->", "getName", "(", ")", ")", ";", "foreach", "(", "$", "schemaGroup", "->", "getDefinitions", "(", ")", "as", "$", "schemaDefinition", ")", "{", "if", "(", "true", "===", "$", "schemaDefinition", "->", "getVirtual", "(", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "appendProperForm", "(", "$", "groupForm", ",", "$", "schemaDefinition", ")", ";", "$", "this", "->", "appendProperData", "(", "$", "data", ",", "$", "schemaDefinition", ")", ";", "}", "}", "$", "event", "->", "setData", "(", "$", "data", ")", ";", "}" ]
Pre set data event handler. @param \Symfony\Component\Form\FormEvent $event @throws \Symfony\Component\Form\Exception\UnexpectedTypeException @throws \InvalidArgumentException
[ "Pre", "set", "data", "event", "handler", "." ]
118a349fd98a7c28721d3cbaba67ce79d1cffada
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Form/EventListener/CharacteristicsResizeListener.php#L80-L110
12,620
ekyna/Characteristics
Form/EventListener/CharacteristicsResizeListener.php
CharacteristicsResizeListener.onSubmit
public function onSubmit(FormEvent $event) { $data = $event->getData(); if (null === $data) { $data = array(); } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)'); } foreach ($this->schema->getGroups() as $schemaGroup) { foreach ($schemaGroup->getDefinitions() as $schemaDefinition) { if (true === $schemaDefinition->getVirtual()) { continue; } $identifier = $schemaDefinition->getIdentifier(); if ($data->offsetExists($identifier)) { /** @var CharacteristicInterface $characteristic */ $characteristic = $data->offsetGet($identifier); if ($this->isNullOrEqualsParentData($characteristic)) { $data->offsetUnset($identifier); $this->em->remove($characteristic); } else { $characteristic->setIdentifier($identifier); } } else { throw new \RuntimeException(sprintf('Missing [%s] characteristic data.', $identifier)); } } } $event->setData($data); }
php
public function onSubmit(FormEvent $event) { $data = $event->getData(); if (null === $data) { $data = array(); } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)'); } foreach ($this->schema->getGroups() as $schemaGroup) { foreach ($schemaGroup->getDefinitions() as $schemaDefinition) { if (true === $schemaDefinition->getVirtual()) { continue; } $identifier = $schemaDefinition->getIdentifier(); if ($data->offsetExists($identifier)) { /** @var CharacteristicInterface $characteristic */ $characteristic = $data->offsetGet($identifier); if ($this->isNullOrEqualsParentData($characteristic)) { $data->offsetUnset($identifier); $this->em->remove($characteristic); } else { $characteristic->setIdentifier($identifier); } } else { throw new \RuntimeException(sprintf('Missing [%s] characteristic data.', $identifier)); } } } $event->setData($data); }
[ "public", "function", "onSubmit", "(", "FormEvent", "$", "event", ")", "{", "$", "data", "=", "$", "event", "->", "getData", "(", ")", ";", "if", "(", "null", "===", "$", "data", ")", "{", "$", "data", "=", "array", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", "&&", "!", "(", "$", "data", "instanceof", "\\", "Traversable", "&&", "$", "data", "instanceof", "\\", "ArrayAccess", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "data", ",", "'array or (\\Traversable and \\ArrayAccess)'", ")", ";", "}", "foreach", "(", "$", "this", "->", "schema", "->", "getGroups", "(", ")", "as", "$", "schemaGroup", ")", "{", "foreach", "(", "$", "schemaGroup", "->", "getDefinitions", "(", ")", "as", "$", "schemaDefinition", ")", "{", "if", "(", "true", "===", "$", "schemaDefinition", "->", "getVirtual", "(", ")", ")", "{", "continue", ";", "}", "$", "identifier", "=", "$", "schemaDefinition", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "data", "->", "offsetExists", "(", "$", "identifier", ")", ")", "{", "/** @var CharacteristicInterface $characteristic */", "$", "characteristic", "=", "$", "data", "->", "offsetGet", "(", "$", "identifier", ")", ";", "if", "(", "$", "this", "->", "isNullOrEqualsParentData", "(", "$", "characteristic", ")", ")", "{", "$", "data", "->", "offsetUnset", "(", "$", "identifier", ")", ";", "$", "this", "->", "em", "->", "remove", "(", "$", "characteristic", ")", ";", "}", "else", "{", "$", "characteristic", "->", "setIdentifier", "(", "$", "identifier", ")", ";", "}", "}", "else", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Missing [%s] characteristic data.'", ",", "$", "identifier", ")", ")", ";", "}", "}", "}", "$", "event", "->", "setData", "(", "$", "data", ")", ";", "}" ]
Submit event handler. @param \Symfony\Component\Form\FormEvent $event @throws \Symfony\Component\Form\Exception\UnexpectedTypeException @throws \RuntimeException
[ "Submit", "event", "handler", "." ]
118a349fd98a7c28721d3cbaba67ce79d1cffada
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Form/EventListener/CharacteristicsResizeListener.php#L119-L153
12,621
ekyna/Characteristics
Form/EventListener/CharacteristicsResizeListener.php
CharacteristicsResizeListener.isNullOrEqualsParentData
private function isNullOrEqualsParentData(CharacteristicInterface $characteristic) { if ($characteristic->isNull()) { return true; } elseif (null !== $this->parentDatas && null !== $parentCharacteristic = $this->parentDatas->findCharacteristicByIdentifier($characteristic->getIdentifier())) { return $parentCharacteristic->equals($characteristic); } return false; }
php
private function isNullOrEqualsParentData(CharacteristicInterface $characteristic) { if ($characteristic->isNull()) { return true; } elseif (null !== $this->parentDatas && null !== $parentCharacteristic = $this->parentDatas->findCharacteristicByIdentifier($characteristic->getIdentifier())) { return $parentCharacteristic->equals($characteristic); } return false; }
[ "private", "function", "isNullOrEqualsParentData", "(", "CharacteristicInterface", "$", "characteristic", ")", "{", "if", "(", "$", "characteristic", "->", "isNull", "(", ")", ")", "{", "return", "true", ";", "}", "elseif", "(", "null", "!==", "$", "this", "->", "parentDatas", "&&", "null", "!==", "$", "parentCharacteristic", "=", "$", "this", "->", "parentDatas", "->", "findCharacteristicByIdentifier", "(", "$", "characteristic", "->", "getIdentifier", "(", ")", ")", ")", "{", "return", "$", "parentCharacteristic", "->", "equals", "(", "$", "characteristic", ")", ";", "}", "return", "false", ";", "}" ]
Returns whether the characteristic is null or equals parent's or not. @param \Ekyna\Component\Characteristics\Model\CharacteristicInterface $characteristic @return bool
[ "Returns", "whether", "the", "characteristic", "is", "null", "or", "equals", "parent", "s", "or", "not", "." ]
118a349fd98a7c28721d3cbaba67ce79d1cffada
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Form/EventListener/CharacteristicsResizeListener.php#L161-L171
12,622
ekyna/Characteristics
Form/EventListener/CharacteristicsResizeListener.php
CharacteristicsResizeListener.appendProperForm
private function appendProperForm(FormInterface $form, Definition $definition) { $identifier = $definition->getIdentifier(); if ($form->has($identifier)) { return; } $type = sprintf('ekyna_%s_characteristic', $definition->getType()); $options = array(); if ($definition->getType() == 'choice') { $options['identifier'] = $identifier; } $parentData = null; if (null !== $this->parentDatas && null !== $characteristic = $this->parentDatas->findCharacteristicByIdentifier($identifier)) { $parentData = $characteristic->display($definition); } $form->add($identifier, $type, array_merge(array( 'property_path' => '[' . $identifier . ']', 'label' => $definition->getTitle(), 'parent_data' => $parentData, ), $options)); }
php
private function appendProperForm(FormInterface $form, Definition $definition) { $identifier = $definition->getIdentifier(); if ($form->has($identifier)) { return; } $type = sprintf('ekyna_%s_characteristic', $definition->getType()); $options = array(); if ($definition->getType() == 'choice') { $options['identifier'] = $identifier; } $parentData = null; if (null !== $this->parentDatas && null !== $characteristic = $this->parentDatas->findCharacteristicByIdentifier($identifier)) { $parentData = $characteristic->display($definition); } $form->add($identifier, $type, array_merge(array( 'property_path' => '[' . $identifier . ']', 'label' => $definition->getTitle(), 'parent_data' => $parentData, ), $options)); }
[ "private", "function", "appendProperForm", "(", "FormInterface", "$", "form", ",", "Definition", "$", "definition", ")", "{", "$", "identifier", "=", "$", "definition", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "form", "->", "has", "(", "$", "identifier", ")", ")", "{", "return", ";", "}", "$", "type", "=", "sprintf", "(", "'ekyna_%s_characteristic'", ",", "$", "definition", "->", "getType", "(", ")", ")", ";", "$", "options", "=", "array", "(", ")", ";", "if", "(", "$", "definition", "->", "getType", "(", ")", "==", "'choice'", ")", "{", "$", "options", "[", "'identifier'", "]", "=", "$", "identifier", ";", "}", "$", "parentData", "=", "null", ";", "if", "(", "null", "!==", "$", "this", "->", "parentDatas", "&&", "null", "!==", "$", "characteristic", "=", "$", "this", "->", "parentDatas", "->", "findCharacteristicByIdentifier", "(", "$", "identifier", ")", ")", "{", "$", "parentData", "=", "$", "characteristic", "->", "display", "(", "$", "definition", ")", ";", "}", "$", "form", "->", "add", "(", "$", "identifier", ",", "$", "type", ",", "array_merge", "(", "array", "(", "'property_path'", "=>", "'['", ".", "$", "identifier", ".", "']'", ",", "'label'", "=>", "$", "definition", "->", "getTitle", "(", ")", ",", "'parent_data'", "=>", "$", "parentData", ",", ")", ",", "$", "options", ")", ")", ";", "}" ]
Appends a form that matches the characteristic type. @param \Symfony\Component\Form\FormInterface $form @param \Ekyna\Component\Characteristics\Schema\Definition $definition
[ "Appends", "a", "form", "that", "matches", "the", "characteristic", "type", "." ]
118a349fd98a7c28721d3cbaba67ce79d1cffada
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Form/EventListener/CharacteristicsResizeListener.php#L179-L202
12,623
ekyna/Characteristics
Form/EventListener/CharacteristicsResizeListener.php
CharacteristicsResizeListener.appendProperData
private function appendProperData(Collection $data, Definition $definition) { $identifier = $definition->getIdentifier(); if ($data->offsetExists($identifier)) { return; } $characteristic = $this->manager->createCharacteristicFromDefinition($definition); $data->set($identifier, $characteristic); }
php
private function appendProperData(Collection $data, Definition $definition) { $identifier = $definition->getIdentifier(); if ($data->offsetExists($identifier)) { return; } $characteristic = $this->manager->createCharacteristicFromDefinition($definition); $data->set($identifier, $characteristic); }
[ "private", "function", "appendProperData", "(", "Collection", "$", "data", ",", "Definition", "$", "definition", ")", "{", "$", "identifier", "=", "$", "definition", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "data", "->", "offsetExists", "(", "$", "identifier", ")", ")", "{", "return", ";", "}", "$", "characteristic", "=", "$", "this", "->", "manager", "->", "createCharacteristicFromDefinition", "(", "$", "definition", ")", ";", "$", "data", "->", "set", "(", "$", "identifier", ",", "$", "characteristic", ")", ";", "}" ]
Fills the data with the proper characteristic type. @param \Doctrine\Common\Collections\Collection $data @param \Ekyna\Component\Characteristics\Schema\Definition $definition @throws \InvalidArgumentException
[ "Fills", "the", "data", "with", "the", "proper", "characteristic", "type", "." ]
118a349fd98a7c28721d3cbaba67ce79d1cffada
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Form/EventListener/CharacteristicsResizeListener.php#L211-L219
12,624
roydejong/Enlighten
lib/Routing/Route.php
Route.setSubdirectory
public function setSubdirectory($subdirectory) { $this->subdirectory = $subdirectory; $this->regexPattern = VariableUrl::createRegexMask($subdirectory . $this->pattern); return $this; }
php
public function setSubdirectory($subdirectory) { $this->subdirectory = $subdirectory; $this->regexPattern = VariableUrl::createRegexMask($subdirectory . $this->pattern); return $this; }
[ "public", "function", "setSubdirectory", "(", "$", "subdirectory", ")", "{", "$", "this", "->", "subdirectory", "=", "$", "subdirectory", ";", "$", "this", "->", "regexPattern", "=", "VariableUrl", "::", "createRegexMask", "(", "$", "subdirectory", ".", "$", "this", "->", "pattern", ")", ";", "return", "$", "this", ";", "}" ]
Sets the subdirectory prefix for this route. @param string $subdirectory @return $this
[ "Sets", "the", "subdirectory", "prefix", "for", "this", "route", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L101-L106
12,625
roydejong/Enlighten
lib/Routing/Route.php
Route.setAcceptableMethods
public function setAcceptableMethods(array $acceptableMethods) { $this->acceptableMethods = $acceptableMethods; $this->addConstraint(function (Request $request) use ($acceptableMethods) { return in_array($request->getMethod(), $acceptableMethods); }); }
php
public function setAcceptableMethods(array $acceptableMethods) { $this->acceptableMethods = $acceptableMethods; $this->addConstraint(function (Request $request) use ($acceptableMethods) { return in_array($request->getMethod(), $acceptableMethods); }); }
[ "public", "function", "setAcceptableMethods", "(", "array", "$", "acceptableMethods", ")", "{", "$", "this", "->", "acceptableMethods", "=", "$", "acceptableMethods", ";", "$", "this", "->", "addConstraint", "(", "function", "(", "Request", "$", "request", ")", "use", "(", "$", "acceptableMethods", ")", "{", "return", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "$", "acceptableMethods", ")", ";", "}", ")", ";", "}" ]
Sets a list of acceptable HTTP method for this route to match. @param array $acceptableMethods
[ "Sets", "a", "list", "of", "acceptable", "HTTP", "method", "for", "this", "route", "to", "match", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L154-L161
12,626
roydejong/Enlighten
lib/Routing/Route.php
Route.matchesPattern
public function matchesPattern(Request $request) { if (preg_match($this->regexPattern, $request->getRequestUri()) <= 0) { return false; } return true; }
php
public function matchesPattern(Request $request) { if (preg_match($this->regexPattern, $request->getRequestUri()) <= 0) { return false; } return true; }
[ "public", "function", "matchesPattern", "(", "Request", "$", "request", ")", "{", "if", "(", "preg_match", "(", "$", "this", "->", "regexPattern", ",", "$", "request", "->", "getRequestUri", "(", ")", ")", "<=", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Matches a request against the pattern configured on this route. @param Request $request @return bool
[ "Matches", "a", "request", "against", "the", "pattern", "configured", "on", "this", "route", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L179-L186
12,627
roydejong/Enlighten
lib/Routing/Route.php
Route.meetsConstraints
public function meetsConstraints(Request $request) { foreach ($this->constraints as $constraint) { if (!$constraint($request)) { return false; } } return true; }
php
public function meetsConstraints(Request $request) { foreach ($this->constraints as $constraint) { if (!$constraint($request)) { return false; } } return true; }
[ "public", "function", "meetsConstraints", "(", "Request", "$", "request", ")", "{", "foreach", "(", "$", "this", "->", "constraints", "as", "$", "constraint", ")", "{", "if", "(", "!", "$", "constraint", "(", "$", "request", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Matches a request against the constraints configured on this route. @param Request $request @return bool
[ "Matches", "a", "request", "against", "the", "constraints", "configured", "on", "this", "route", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L194-L203
12,628
roydejong/Enlighten
lib/Routing/Route.php
Route.action
public function action(Context $context = null) { $targetFunc = null; $classObject = null; // Create a dummy context if needed if (empty($context)) { $context = new Context(); } // Determine target function if ($this->isCallable()) { $targetFunc = $this->getTarget(); } else { $targetFunc = $this->translateToClassCallable($context); $classObject = $targetFunc[0]; } // Route filter: before function if (!$this->filters->trigger(Filters::BEFORE_ROUTE, $context)) { return null; } $returnValue = null; $continue = true; // Execute a "before" function, if it is defined in the target class if ($classObject != null) { $beforeCallable = [$classObject, 'before']; if (is_callable($beforeCallable)) { $returnValue = $this->executeAction($beforeCallable, $context); if ($returnValue && $returnValue instanceof Response) { // A respone was sent by the "before" function, stop execution $continue = false; } } } if ($continue) { // Invoke the specified controller function or the specified callable with the appropriate params $returnValue = $this->executeAction($targetFunc, $context); } // Route filter: After function $this->filters->trigger(Filters::AFTER_ROUTE, $context); return $returnValue; }
php
public function action(Context $context = null) { $targetFunc = null; $classObject = null; // Create a dummy context if needed if (empty($context)) { $context = new Context(); } // Determine target function if ($this->isCallable()) { $targetFunc = $this->getTarget(); } else { $targetFunc = $this->translateToClassCallable($context); $classObject = $targetFunc[0]; } // Route filter: before function if (!$this->filters->trigger(Filters::BEFORE_ROUTE, $context)) { return null; } $returnValue = null; $continue = true; // Execute a "before" function, if it is defined in the target class if ($classObject != null) { $beforeCallable = [$classObject, 'before']; if (is_callable($beforeCallable)) { $returnValue = $this->executeAction($beforeCallable, $context); if ($returnValue && $returnValue instanceof Response) { // A respone was sent by the "before" function, stop execution $continue = false; } } } if ($continue) { // Invoke the specified controller function or the specified callable with the appropriate params $returnValue = $this->executeAction($targetFunc, $context); } // Route filter: After function $this->filters->trigger(Filters::AFTER_ROUTE, $context); return $returnValue; }
[ "public", "function", "action", "(", "Context", "$", "context", "=", "null", ")", "{", "$", "targetFunc", "=", "null", ";", "$", "classObject", "=", "null", ";", "// Create a dummy context if needed", "if", "(", "empty", "(", "$", "context", ")", ")", "{", "$", "context", "=", "new", "Context", "(", ")", ";", "}", "// Determine target function", "if", "(", "$", "this", "->", "isCallable", "(", ")", ")", "{", "$", "targetFunc", "=", "$", "this", "->", "getTarget", "(", ")", ";", "}", "else", "{", "$", "targetFunc", "=", "$", "this", "->", "translateToClassCallable", "(", "$", "context", ")", ";", "$", "classObject", "=", "$", "targetFunc", "[", "0", "]", ";", "}", "// Route filter: before function", "if", "(", "!", "$", "this", "->", "filters", "->", "trigger", "(", "Filters", "::", "BEFORE_ROUTE", ",", "$", "context", ")", ")", "{", "return", "null", ";", "}", "$", "returnValue", "=", "null", ";", "$", "continue", "=", "true", ";", "// Execute a \"before\" function, if it is defined in the target class", "if", "(", "$", "classObject", "!=", "null", ")", "{", "$", "beforeCallable", "=", "[", "$", "classObject", ",", "'before'", "]", ";", "if", "(", "is_callable", "(", "$", "beforeCallable", ")", ")", "{", "$", "returnValue", "=", "$", "this", "->", "executeAction", "(", "$", "beforeCallable", ",", "$", "context", ")", ";", "if", "(", "$", "returnValue", "&&", "$", "returnValue", "instanceof", "Response", ")", "{", "// A respone was sent by the \"before\" function, stop execution", "$", "continue", "=", "false", ";", "}", "}", "}", "if", "(", "$", "continue", ")", "{", "// Invoke the specified controller function or the specified callable with the appropriate params", "$", "returnValue", "=", "$", "this", "->", "executeAction", "(", "$", "targetFunc", ",", "$", "context", ")", ";", "}", "// Route filter: After function", "$", "this", "->", "filters", "->", "trigger", "(", "Filters", "::", "AFTER_ROUTE", ",", "$", "context", ")", ";", "return", "$", "returnValue", ";", "}" ]
Executes this route's action. @param Context $context @throws RoutingException For unsupported or invalid action configurations. @throws \Exception If an Exception is raised during the route's action, and no onException filter is registered, the Exception will be rethrown here. @return mixed Action return value
[ "Executes", "this", "route", "s", "action", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L261-L309
12,629
roydejong/Enlighten
lib/Routing/Route.php
Route.executeAction
private function executeAction(callable $targetFunc, Context $context) { $returnValue = null; $paramValues = $context->determineParamValues($targetFunc); try { $returnValue = call_user_func_array($targetFunc, $paramValues); } catch (\Exception $ex) { $context->registerInstance($ex); $this->filters->trigger(Filters::ON_EXCEPTION, $context); if (!$this->filters->anyHandlersForEvent(Filters::ON_EXCEPTION)) { // If this exception was unhandled, rethrow it so it can be handled in the global scope throw $ex; } } return $returnValue; }
php
private function executeAction(callable $targetFunc, Context $context) { $returnValue = null; $paramValues = $context->determineParamValues($targetFunc); try { $returnValue = call_user_func_array($targetFunc, $paramValues); } catch (\Exception $ex) { $context->registerInstance($ex); $this->filters->trigger(Filters::ON_EXCEPTION, $context); if (!$this->filters->anyHandlersForEvent(Filters::ON_EXCEPTION)) { // If this exception was unhandled, rethrow it so it can be handled in the global scope throw $ex; } } return $returnValue; }
[ "private", "function", "executeAction", "(", "callable", "$", "targetFunc", ",", "Context", "$", "context", ")", "{", "$", "returnValue", "=", "null", ";", "$", "paramValues", "=", "$", "context", "->", "determineParamValues", "(", "$", "targetFunc", ")", ";", "try", "{", "$", "returnValue", "=", "call_user_func_array", "(", "$", "targetFunc", ",", "$", "paramValues", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "$", "context", "->", "registerInstance", "(", "$", "ex", ")", ";", "$", "this", "->", "filters", "->", "trigger", "(", "Filters", "::", "ON_EXCEPTION", ",", "$", "context", ")", ";", "if", "(", "!", "$", "this", "->", "filters", "->", "anyHandlersForEvent", "(", "Filters", "::", "ON_EXCEPTION", ")", ")", "{", "// If this exception was unhandled, rethrow it so it can be handled in the global scope", "throw", "$", "ex", ";", "}", "}", "return", "$", "returnValue", ";", "}" ]
Executes a route action, given a callable and a context. @param callable $targetFunc The target function to be executed. @param Context $context The context the target function should be executed under (for dependency injection). @return mixed The function's return value. @throws \Exception If an exception is raised during execution, it will be rethrown.
[ "Executes", "a", "route", "action", "given", "a", "callable", "and", "a", "context", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L319-L339
12,630
roydejong/Enlighten
lib/Routing/Route.php
Route.translateToClassCallable
private function translateToClassCallable(Context $context) { // Load the class and create an instance of it $targetParts = explode('@', strval($this->getTarget()), 2); $targetClass = $targetParts[0]; $targetFuncName = count($targetParts) > 1 ? $targetParts[1] : 'action'; if (!class_exists($targetClass, true)) { throw new RoutingException('Could not locate class: ' . $targetClass); } $classObj = null; // Invoke constructor with dependency injection $parameterList = $context->determineParamValuesForConstructor($targetClass); try { $reflection = new \ReflectionClass($targetClass); $classObj = $reflection->newInstanceArgs($parameterList); } catch (\TypeError $ex) { throw new RoutingException('Type error thrown when calling constructor on ' . $targetClass, 0, $ex); } // Verify target function and return a callable $targetFunc = [$classObj, $targetFuncName]; if (!is_callable($targetFunc)) { throw new RoutingException('Route target function is not callable: ' . $this->getTarget()); } return $targetFunc; }
php
private function translateToClassCallable(Context $context) { // Load the class and create an instance of it $targetParts = explode('@', strval($this->getTarget()), 2); $targetClass = $targetParts[0]; $targetFuncName = count($targetParts) > 1 ? $targetParts[1] : 'action'; if (!class_exists($targetClass, true)) { throw new RoutingException('Could not locate class: ' . $targetClass); } $classObj = null; // Invoke constructor with dependency injection $parameterList = $context->determineParamValuesForConstructor($targetClass); try { $reflection = new \ReflectionClass($targetClass); $classObj = $reflection->newInstanceArgs($parameterList); } catch (\TypeError $ex) { throw new RoutingException('Type error thrown when calling constructor on ' . $targetClass, 0, $ex); } // Verify target function and return a callable $targetFunc = [$classObj, $targetFuncName]; if (!is_callable($targetFunc)) { throw new RoutingException('Route target function is not callable: ' . $this->getTarget()); } return $targetFunc; }
[ "private", "function", "translateToClassCallable", "(", "Context", "$", "context", ")", "{", "// Load the class and create an instance of it", "$", "targetParts", "=", "explode", "(", "'@'", ",", "strval", "(", "$", "this", "->", "getTarget", "(", ")", ")", ",", "2", ")", ";", "$", "targetClass", "=", "$", "targetParts", "[", "0", "]", ";", "$", "targetFuncName", "=", "count", "(", "$", "targetParts", ")", ">", "1", "?", "$", "targetParts", "[", "1", "]", ":", "'action'", ";", "if", "(", "!", "class_exists", "(", "$", "targetClass", ",", "true", ")", ")", "{", "throw", "new", "RoutingException", "(", "'Could not locate class: '", ".", "$", "targetClass", ")", ";", "}", "$", "classObj", "=", "null", ";", "// Invoke constructor with dependency injection", "$", "parameterList", "=", "$", "context", "->", "determineParamValuesForConstructor", "(", "$", "targetClass", ")", ";", "try", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "targetClass", ")", ";", "$", "classObj", "=", "$", "reflection", "->", "newInstanceArgs", "(", "$", "parameterList", ")", ";", "}", "catch", "(", "\\", "TypeError", "$", "ex", ")", "{", "throw", "new", "RoutingException", "(", "'Type error thrown when calling constructor on '", ".", "$", "targetClass", ",", "0", ",", "$", "ex", ")", ";", "}", "// Verify target function and return a callable", "$", "targetFunc", "=", "[", "$", "classObj", ",", "$", "targetFuncName", "]", ";", "if", "(", "!", "is_callable", "(", "$", "targetFunc", ")", ")", "{", "throw", "new", "RoutingException", "(", "'Route target function is not callable: '", ".", "$", "this", "->", "getTarget", "(", ")", ")", ";", "}", "return", "$", "targetFunc", ";", "}" ]
Attempts to translate this route's target to a function within a controller class. @param Context $context @return array @throws RoutingException
[ "Attempts", "to", "translate", "this", "route", "s", "target", "to", "a", "function", "within", "a", "controller", "class", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Route.php#L348-L379
12,631
stakhanovist/worker
library/AbstractWorkerController.php
AbstractWorkerController.process
public function process(MessageInterface $message) { $event = $this->getProcessEvent(); $event->setWorker($this); $event->setMessage($message); $events = $this->getEventManager(); $results = $events->trigger(ProcessEvent::EVENT_PROCESSOR, $event, function ($result) { return ($result instanceof ProcessorInterface); }); $processor = $results->last(); if (!$processor instanceof ProcessorInterface) { throw new \RuntimeException(sprintf( '%s: no processor selected!', __METHOD__ )); } $processor->setWorker($this); $event->setProcessor($processor); $result = $processor->process($message); $event->setResult($result); $events->trigger(ProcessEvent::EVENT_PROCESS_POST, $event); return $result; }
php
public function process(MessageInterface $message) { $event = $this->getProcessEvent(); $event->setWorker($this); $event->setMessage($message); $events = $this->getEventManager(); $results = $events->trigger(ProcessEvent::EVENT_PROCESSOR, $event, function ($result) { return ($result instanceof ProcessorInterface); }); $processor = $results->last(); if (!$processor instanceof ProcessorInterface) { throw new \RuntimeException(sprintf( '%s: no processor selected!', __METHOD__ )); } $processor->setWorker($this); $event->setProcessor($processor); $result = $processor->process($message); $event->setResult($result); $events->trigger(ProcessEvent::EVENT_PROCESS_POST, $event); return $result; }
[ "public", "function", "process", "(", "MessageInterface", "$", "message", ")", "{", "$", "event", "=", "$", "this", "->", "getProcessEvent", "(", ")", ";", "$", "event", "->", "setWorker", "(", "$", "this", ")", ";", "$", "event", "->", "setMessage", "(", "$", "message", ")", ";", "$", "events", "=", "$", "this", "->", "getEventManager", "(", ")", ";", "$", "results", "=", "$", "events", "->", "trigger", "(", "ProcessEvent", "::", "EVENT_PROCESSOR", ",", "$", "event", ",", "function", "(", "$", "result", ")", "{", "return", "(", "$", "result", "instanceof", "ProcessorInterface", ")", ";", "}", ")", ";", "$", "processor", "=", "$", "results", "->", "last", "(", ")", ";", "if", "(", "!", "$", "processor", "instanceof", "ProcessorInterface", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'%s: no processor selected!'", ",", "__METHOD__", ")", ")", ";", "}", "$", "processor", "->", "setWorker", "(", "$", "this", ")", ";", "$", "event", "->", "setProcessor", "(", "$", "processor", ")", ";", "$", "result", "=", "$", "processor", "->", "process", "(", "$", "message", ")", ";", "$", "event", "->", "setResult", "(", "$", "result", ")", ";", "$", "events", "->", "trigger", "(", "ProcessEvent", "::", "EVENT_PROCESS_POST", ",", "$", "event", ")", ";", "return", "$", "result", ";", "}" ]
Process a message @param MessageInterface $message @return mixed @throws Exception\InvalidMessageException
[ "Process", "a", "message" ]
63f6aaeb06986a7c39b5e5c4be742b92942b5d3f
https://github.com/stakhanovist/worker/blob/63f6aaeb06986a7c39b5e5c4be742b92942b5d3f/library/AbstractWorkerController.php#L195-L224
12,632
stakhanovist/worker
library/AbstractWorkerController.php
AbstractWorkerController.send
public function send(QueueClientInterface $queue, $message, SendParametersInterface $params = null) { $queue->send($message, $params); }
php
public function send(QueueClientInterface $queue, $message, SendParametersInterface $params = null) { $queue->send($message, $params); }
[ "public", "function", "send", "(", "QueueClientInterface", "$", "queue", ",", "$", "message", ",", "SendParametersInterface", "$", "params", "=", "null", ")", "{", "$", "queue", "->", "send", "(", "$", "message", ",", "$", "params", ")", ";", "}" ]
Send a message to the queue @param QueueClientInterface $queue @param mixed $message @param SendParametersInterface $params @return MessageInterface
[ "Send", "a", "message", "to", "the", "queue" ]
63f6aaeb06986a7c39b5e5c4be742b92942b5d3f
https://github.com/stakhanovist/worker/blob/63f6aaeb06986a7c39b5e5c4be742b92942b5d3f/library/AbstractWorkerController.php#L234-L237
12,633
stakhanovist/worker
library/AbstractWorkerController.php
AbstractWorkerController.receive
public function receive(QueueClientInterface $queue, $maxMessages = 1, ReceiveParametersInterface $params = null) { $messages = $queue->receive($maxMessages, $params); $lastResult = []; foreach ($messages as $message) { if ($message instanceof MessageInterface) { $lastResult = $this->process($message); if ($queue->canDeleteMessage()) { $queue->delete($message); } } // TODO: else? } return $lastResult; }
php
public function receive(QueueClientInterface $queue, $maxMessages = 1, ReceiveParametersInterface $params = null) { $messages = $queue->receive($maxMessages, $params); $lastResult = []; foreach ($messages as $message) { if ($message instanceof MessageInterface) { $lastResult = $this->process($message); if ($queue->canDeleteMessage()) { $queue->delete($message); } } // TODO: else? } return $lastResult; }
[ "public", "function", "receive", "(", "QueueClientInterface", "$", "queue", ",", "$", "maxMessages", "=", "1", ",", "ReceiveParametersInterface", "$", "params", "=", "null", ")", "{", "$", "messages", "=", "$", "queue", "->", "receive", "(", "$", "maxMessages", ",", "$", "params", ")", ";", "$", "lastResult", "=", "[", "]", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "if", "(", "$", "message", "instanceof", "MessageInterface", ")", "{", "$", "lastResult", "=", "$", "this", "->", "process", "(", "$", "message", ")", ";", "if", "(", "$", "queue", "->", "canDeleteMessage", "(", ")", ")", "{", "$", "queue", "->", "delete", "(", "$", "message", ")", ";", "}", "}", "// TODO: else?", "}", "return", "$", "lastResult", ";", "}" ]
Receive and process one or more incoming messages @param QueueClientInterface $queue @param int $maxMessages @param ReceiveParametersInterface $params @return mixed
[ "Receive", "and", "process", "one", "or", "more", "incoming", "messages" ]
63f6aaeb06986a7c39b5e5c4be742b92942b5d3f
https://github.com/stakhanovist/worker/blob/63f6aaeb06986a7c39b5e5c4be742b92942b5d3f/library/AbstractWorkerController.php#L248-L266
12,634
stakhanovist/worker
library/AbstractWorkerController.php
AbstractWorkerController.await
public function await(QueueClientInterface $queue, ReceiveParametersInterface $params = null) { $worker = $this; $this->await = true; $lastResult = []; $callback = function(QueueEvent $event) use($worker, $queue, &$lastResult) { $messages = $event->getMessages(); foreach ($messages as $message) { $lastResult = $worker->process($message); if ($queue->canDeleteMessage()) { $queue->delete($message); } } if ($worker->isAwaitingStopped()) { $event->stopAwait(true); } return !$worker->isAwaitingStopped(); }; $callbackHandler = $queue->getEventManager()->attach(QueueEvent::EVENT_RECEIVE, $callback); $queue->await($params); $queue->getEventManager()->detach($callbackHandler); return $lastResult; }
php
public function await(QueueClientInterface $queue, ReceiveParametersInterface $params = null) { $worker = $this; $this->await = true; $lastResult = []; $callback = function(QueueEvent $event) use($worker, $queue, &$lastResult) { $messages = $event->getMessages(); foreach ($messages as $message) { $lastResult = $worker->process($message); if ($queue->canDeleteMessage()) { $queue->delete($message); } } if ($worker->isAwaitingStopped()) { $event->stopAwait(true); } return !$worker->isAwaitingStopped(); }; $callbackHandler = $queue->getEventManager()->attach(QueueEvent::EVENT_RECEIVE, $callback); $queue->await($params); $queue->getEventManager()->detach($callbackHandler); return $lastResult; }
[ "public", "function", "await", "(", "QueueClientInterface", "$", "queue", ",", "ReceiveParametersInterface", "$", "params", "=", "null", ")", "{", "$", "worker", "=", "$", "this", ";", "$", "this", "->", "await", "=", "true", ";", "$", "lastResult", "=", "[", "]", ";", "$", "callback", "=", "function", "(", "QueueEvent", "$", "event", ")", "use", "(", "$", "worker", ",", "$", "queue", ",", "&", "$", "lastResult", ")", "{", "$", "messages", "=", "$", "event", "->", "getMessages", "(", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "lastResult", "=", "$", "worker", "->", "process", "(", "$", "message", ")", ";", "if", "(", "$", "queue", "->", "canDeleteMessage", "(", ")", ")", "{", "$", "queue", "->", "delete", "(", "$", "message", ")", ";", "}", "}", "if", "(", "$", "worker", "->", "isAwaitingStopped", "(", ")", ")", "{", "$", "event", "->", "stopAwait", "(", "true", ")", ";", "}", "return", "!", "$", "worker", "->", "isAwaitingStopped", "(", ")", ";", "}", ";", "$", "callbackHandler", "=", "$", "queue", "->", "getEventManager", "(", ")", "->", "attach", "(", "QueueEvent", "::", "EVENT_RECEIVE", ",", "$", "callback", ")", ";", "$", "queue", "->", "await", "(", "$", "params", ")", ";", "$", "queue", "->", "getEventManager", "(", ")", "->", "detach", "(", "$", "callbackHandler", ")", ";", "return", "$", "lastResult", ";", "}" ]
Wait for and process incoming messages TODO: handle idle @param QueueClientInterface $queue @param ReceiveParametersInterface $params @return boolean|\Stakhanovist\Worker\mixed
[ "Wait", "for", "and", "process", "incoming", "messages" ]
63f6aaeb06986a7c39b5e5c4be742b92942b5d3f
https://github.com/stakhanovist/worker/blob/63f6aaeb06986a7c39b5e5c4be742b92942b5d3f/library/AbstractWorkerController.php#L276-L310
12,635
clagiordano/weblibs-dbabstraction
src/AbstractMapper.php
AbstractMapper.setEntityTable
public function setEntityTable($entityTable) { if (!is_string($entityTable) || empty($entityTable)) { throw new \InvalidArgumentException('The entity table is invalid.'); } $this->entityTable = $entityTable; return $this; }
php
public function setEntityTable($entityTable) { if (!is_string($entityTable) || empty($entityTable)) { throw new \InvalidArgumentException('The entity table is invalid.'); } $this->entityTable = $entityTable; return $this; }
[ "public", "function", "setEntityTable", "(", "$", "entityTable", ")", "{", "if", "(", "!", "is_string", "(", "$", "entityTable", ")", "||", "empty", "(", "$", "entityTable", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The entity table is invalid.'", ")", ";", "}", "$", "this", "->", "entityTable", "=", "$", "entityTable", ";", "return", "$", "this", ";", "}" ]
Set the entity table @param string $entityTable @return $this
[ "Set", "the", "entity", "table" ]
167988f73f1d6d0a013179c4a211bdc673a4667e
https://github.com/clagiordano/weblibs-dbabstraction/blob/167988f73f1d6d0a013179c4a211bdc673a4667e/src/AbstractMapper.php#L76-L84
12,636
clagiordano/weblibs-dbabstraction
src/AbstractMapper.php
AbstractMapper.findById
public function findById($entityId) { $this->adapter->select($this->entityTable, "id = {$entityId}"); if (($data = $this->adapter->fetch()) !== false) { return $this->createEntity($data); } return null; }
php
public function findById($entityId) { $this->adapter->select($this->entityTable, "id = {$entityId}"); if (($data = $this->adapter->fetch()) !== false) { return $this->createEntity($data); } return null; }
[ "public", "function", "findById", "(", "$", "entityId", ")", "{", "$", "this", "->", "adapter", "->", "select", "(", "$", "this", "->", "entityTable", ",", "\"id = {$entityId}\"", ")", ";", "if", "(", "(", "$", "data", "=", "$", "this", "->", "adapter", "->", "fetch", "(", ")", ")", "!==", "false", ")", "{", "return", "$", "this", "->", "createEntity", "(", "$", "data", ")", ";", "}", "return", "null", ";", "}" ]
Find an entity by its ID @param $entityId @return mixed|null
[ "Find", "an", "entity", "by", "its", "ID" ]
167988f73f1d6d0a013179c4a211bdc673a4667e
https://github.com/clagiordano/weblibs-dbabstraction/blob/167988f73f1d6d0a013179c4a211bdc673a4667e/src/AbstractMapper.php#L119-L128
12,637
clagiordano/weblibs-dbabstraction
src/AbstractMapper.php
AbstractMapper.insert
public function insert($entity) { if (!$entity instanceof $this->entityClass) { throw new \InvalidArgumentException( "The entity to be inserted must be an instance of {$this->entityClass}." ); } return $this->adapter->insert($this->entityTable, $entity->toArray()); }
php
public function insert($entity) { if (!$entity instanceof $this->entityClass) { throw new \InvalidArgumentException( "The entity to be inserted must be an instance of {$this->entityClass}." ); } return $this->adapter->insert($this->entityTable, $entity->toArray()); }
[ "public", "function", "insert", "(", "$", "entity", ")", "{", "if", "(", "!", "$", "entity", "instanceof", "$", "this", "->", "entityClass", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The entity to be inserted must be an instance of {$this->entityClass}.\"", ")", ";", "}", "return", "$", "this", "->", "adapter", "->", "insert", "(", "$", "this", "->", "entityTable", ",", "$", "entity", "->", "toArray", "(", ")", ")", ";", "}" ]
Insert a new entity in the storage @param AbstractEntity $entity @return mixed
[ "Insert", "a", "new", "entity", "in", "the", "storage" ]
167988f73f1d6d0a013179c4a211bdc673a4667e
https://github.com/clagiordano/weblibs-dbabstraction/blob/167988f73f1d6d0a013179c4a211bdc673a4667e/src/AbstractMapper.php#L162-L171
12,638
clagiordano/weblibs-dbabstraction
src/AbstractMapper.php
AbstractMapper.update
public function update($entity) { if (!$entity instanceof $this->entityClass) { throw new \InvalidArgumentException( "The entity to be updated must be an instance of {$this->entityClass}." ); } $entityId = $entity->id; $data = $entity->toArray(); unset($data['id']); return $this->adapter->update($this->entityTable, $data, "id = $entityId"); }
php
public function update($entity) { if (!$entity instanceof $this->entityClass) { throw new \InvalidArgumentException( "The entity to be updated must be an instance of {$this->entityClass}." ); } $entityId = $entity->id; $data = $entity->toArray(); unset($data['id']); return $this->adapter->update($this->entityTable, $data, "id = $entityId"); }
[ "public", "function", "update", "(", "$", "entity", ")", "{", "if", "(", "!", "$", "entity", "instanceof", "$", "this", "->", "entityClass", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The entity to be updated must be an instance of {$this->entityClass}.\"", ")", ";", "}", "$", "entityId", "=", "$", "entity", "->", "id", ";", "$", "data", "=", "$", "entity", "->", "toArray", "(", ")", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "adapter", "->", "update", "(", "$", "this", "->", "entityTable", ",", "$", "data", ",", "\"id = $entityId\"", ")", ";", "}" ]
Update an existing entity in the storage @param AbstractEntity $entity @return mixed
[ "Update", "an", "existing", "entity", "in", "the", "storage" ]
167988f73f1d6d0a013179c4a211bdc673a4667e
https://github.com/clagiordano/weblibs-dbabstraction/blob/167988f73f1d6d0a013179c4a211bdc673a4667e/src/AbstractMapper.php#L178-L191
12,639
clagiordano/weblibs-dbabstraction
src/AbstractMapper.php
AbstractMapper.delete
public function delete($entityId, $col = 'id') { if (is_null($entityId) || (!is_numeric($entityId) && !is_a($entityId, $this->entityClass))) { throw new \InvalidArgumentException( "Invalid entity or entityId argument." ); } if ($entityId instanceof $this->entityClass) { $entityId = $entityId->id; } return $this->adapter->delete($this->entityTable, "$col = $entityId"); }
php
public function delete($entityId, $col = 'id') { if (is_null($entityId) || (!is_numeric($entityId) && !is_a($entityId, $this->entityClass))) { throw new \InvalidArgumentException( "Invalid entity or entityId argument." ); } if ($entityId instanceof $this->entityClass) { $entityId = $entityId->id; } return $this->adapter->delete($this->entityTable, "$col = $entityId"); }
[ "public", "function", "delete", "(", "$", "entityId", ",", "$", "col", "=", "'id'", ")", "{", "if", "(", "is_null", "(", "$", "entityId", ")", "||", "(", "!", "is_numeric", "(", "$", "entityId", ")", "&&", "!", "is_a", "(", "$", "entityId", ",", "$", "this", "->", "entityClass", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid entity or entityId argument.\"", ")", ";", "}", "if", "(", "$", "entityId", "instanceof", "$", "this", "->", "entityClass", ")", "{", "$", "entityId", "=", "$", "entityId", "->", "id", ";", "}", "return", "$", "this", "->", "adapter", "->", "delete", "(", "$", "this", "->", "entityTable", ",", "\"$col = $entityId\"", ")", ";", "}" ]
Delete one or more entities from the storage @param $entityId @param string $col @return mixed
[ "Delete", "one", "or", "more", "entities", "from", "the", "storage" ]
167988f73f1d6d0a013179c4a211bdc673a4667e
https://github.com/clagiordano/weblibs-dbabstraction/blob/167988f73f1d6d0a013179c4a211bdc673a4667e/src/AbstractMapper.php#L199-L213
12,640
native5/native5-sdk-common-php
src/Native5/Core/Database/DBFactory.php
DBFactory.makeDB
public static function makeDB(\Native5\Core\Database\DBConfig $configuration) { if (empty($configuration)) throw new \Exception('Empty connection settings provided'); $port = $configuration->getPort(); $port = !empty($port) ? $port : 3306; $dsn = $configuration->getType().':host='.$configuration->getHost().';port='.$port.';dbname='.$configuration->getName(); $dbKey = md5($dsn.'.'.$configuration->getUser()); if (isset(self::$_dbs[$dbKey]) && !empty(self::$_dbs[$dbKey]) && self::$_dbs[$dbKey]->checkConnection()) return self::$_dbs[$dbKey]; // Create a DB Instance for this user + database combination return (self::$_dbs[$dbKey] = new \Native5\Core\Database\DB($configuration)); }
php
public static function makeDB(\Native5\Core\Database\DBConfig $configuration) { if (empty($configuration)) throw new \Exception('Empty connection settings provided'); $port = $configuration->getPort(); $port = !empty($port) ? $port : 3306; $dsn = $configuration->getType().':host='.$configuration->getHost().';port='.$port.';dbname='.$configuration->getName(); $dbKey = md5($dsn.'.'.$configuration->getUser()); if (isset(self::$_dbs[$dbKey]) && !empty(self::$_dbs[$dbKey]) && self::$_dbs[$dbKey]->checkConnection()) return self::$_dbs[$dbKey]; // Create a DB Instance for this user + database combination return (self::$_dbs[$dbKey] = new \Native5\Core\Database\DB($configuration)); }
[ "public", "static", "function", "makeDB", "(", "\\", "Native5", "\\", "Core", "\\", "Database", "\\", "DBConfig", "$", "configuration", ")", "{", "if", "(", "empty", "(", "$", "configuration", ")", ")", "throw", "new", "\\", "Exception", "(", "'Empty connection settings provided'", ")", ";", "$", "port", "=", "$", "configuration", "->", "getPort", "(", ")", ";", "$", "port", "=", "!", "empty", "(", "$", "port", ")", "?", "$", "port", ":", "3306", ";", "$", "dsn", "=", "$", "configuration", "->", "getType", "(", ")", ".", "':host='", ".", "$", "configuration", "->", "getHost", "(", ")", ".", "';port='", ".", "$", "port", ".", "';dbname='", ".", "$", "configuration", "->", "getName", "(", ")", ";", "$", "dbKey", "=", "md5", "(", "$", "dsn", ".", "'.'", ".", "$", "configuration", "->", "getUser", "(", ")", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "_dbs", "[", "$", "dbKey", "]", ")", "&&", "!", "empty", "(", "self", "::", "$", "_dbs", "[", "$", "dbKey", "]", ")", "&&", "self", "::", "$", "_dbs", "[", "$", "dbKey", "]", "->", "checkConnection", "(", ")", ")", "return", "self", "::", "$", "_dbs", "[", "$", "dbKey", "]", ";", "// Create a DB Instance for this user + database combination", "return", "(", "self", "::", "$", "_dbs", "[", "$", "dbKey", "]", "=", "new", "\\", "Native5", "\\", "Core", "\\", "Database", "\\", "DB", "(", "$", "configuration", ")", ")", ";", "}" ]
instance method for instantiating a DB object @param mixed $configuration Database configuration @static @access private @return void
[ "instance", "method", "for", "instantiating", "a", "DB", "object" ]
c8bd5b219bd05ea4d317d21ae9c0c8dddcede7fe
https://github.com/native5/native5-sdk-common-php/blob/c8bd5b219bd05ea4d317d21ae9c0c8dddcede7fe/src/Native5/Core/Database/DBFactory.php#L39-L54
12,641
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.BuildCache
protected static function BuildCache() { self::CalculateData(self::$Categories); self::JoinRecentPosts(self::$Categories); Gdn::Cache()->Store(self::CACHE_KEY, self::$Categories, array(Gdn_Cache::FEATURE_EXPIRY => 600)); }
php
protected static function BuildCache() { self::CalculateData(self::$Categories); self::JoinRecentPosts(self::$Categories); Gdn::Cache()->Store(self::CACHE_KEY, self::$Categories, array(Gdn_Cache::FEATURE_EXPIRY => 600)); }
[ "protected", "static", "function", "BuildCache", "(", ")", "{", "self", "::", "CalculateData", "(", "self", "::", "$", "Categories", ")", ";", "self", "::", "JoinRecentPosts", "(", "self", "::", "$", "Categories", ")", ";", "Gdn", "::", "Cache", "(", ")", "->", "Store", "(", "self", "::", "CACHE_KEY", ",", "self", "::", "$", "Categories", ",", "array", "(", "Gdn_Cache", "::", "FEATURE_EXPIRY", "=>", "600", ")", ")", ";", "}" ]
Build and augment the category cache @param array $Categories
[ "Build", "and", "augment", "the", "category", "cache" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L132-L136
12,642
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GivePoints
public static function GivePoints($UserID, $Points, $Source = 'Other', $CategoryID = 0, $Timestamp = FALSE) { // Figure out whether or not the category tracks points seperately. if ($CategoryID) { $Category = self::Categories($CategoryID); if ($Category) $CategoryID = GetValue('PointsCategoryID', $Category); else $CategoryID = 0; } UserModel::GivePoints($UserID, $Points, array($Source, 'CategoryID' => $CategoryID), $Timestamp); }
php
public static function GivePoints($UserID, $Points, $Source = 'Other', $CategoryID = 0, $Timestamp = FALSE) { // Figure out whether or not the category tracks points seperately. if ($CategoryID) { $Category = self::Categories($CategoryID); if ($Category) $CategoryID = GetValue('PointsCategoryID', $Category); else $CategoryID = 0; } UserModel::GivePoints($UserID, $Points, array($Source, 'CategoryID' => $CategoryID), $Timestamp); }
[ "public", "static", "function", "GivePoints", "(", "$", "UserID", ",", "$", "Points", ",", "$", "Source", "=", "'Other'", ",", "$", "CategoryID", "=", "0", ",", "$", "Timestamp", "=", "FALSE", ")", "{", "// Figure out whether or not the category tracks points seperately.", "if", "(", "$", "CategoryID", ")", "{", "$", "Category", "=", "self", "::", "Categories", "(", "$", "CategoryID", ")", ";", "if", "(", "$", "Category", ")", "$", "CategoryID", "=", "GetValue", "(", "'PointsCategoryID'", ",", "$", "Category", ")", ";", "else", "$", "CategoryID", "=", "0", ";", "}", "UserModel", "::", "GivePoints", "(", "$", "UserID", ",", "$", "Points", ",", "array", "(", "$", "Source", ",", "'CategoryID'", "=>", "$", "CategoryID", ")", ",", "$", "Timestamp", ")", ";", "}" ]
Give a user points specific to this category. @param int $UserID The user to give the points to. @param int $Points The number of points to give. @param string $Source The source of the points. @param int $CategoryID The category to give the points for. @param int $Timestamp The time the points were given.
[ "Give", "a", "user", "points", "specific", "to", "this", "category", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L335-L346
12,643
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetID
public function GetID($CategoryID, $DatasetType = DATASET_TYPE_OBJECT) { return $this->SQL->GetWhere('Category', array('CategoryID' => $CategoryID))->FirstRow($DatasetType); }
php
public function GetID($CategoryID, $DatasetType = DATASET_TYPE_OBJECT) { return $this->SQL->GetWhere('Category', array('CategoryID' => $CategoryID))->FirstRow($DatasetType); }
[ "public", "function", "GetID", "(", "$", "CategoryID", ",", "$", "DatasetType", "=", "DATASET_TYPE_OBJECT", ")", "{", "return", "$", "this", "->", "SQL", "->", "GetWhere", "(", "'Category'", ",", "array", "(", "'CategoryID'", "=>", "$", "CategoryID", ")", ")", "->", "FirstRow", "(", "$", "DatasetType", ")", ";", "}" ]
Get data for a single category selected by ID. Disregards permissions. @since 2.0.0 @access public @param int $CategoryID Unique ID of category we're getting data for. @return object SQL results.
[ "Get", "data", "for", "a", "single", "category", "selected", "by", "ID", ".", "Disregards", "permissions", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L698-L700
12,644
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetDescendantCountByCode
public function GetDescendantCountByCode($Code) { $Category = $this->GetByCode($Code); if ($Category) return round(($Category->TreeRight - $Category->TreeLeft - 1) / 2); return 0; }
php
public function GetDescendantCountByCode($Code) { $Category = $this->GetByCode($Code); if ($Category) return round(($Category->TreeRight - $Category->TreeLeft - 1) / 2); return 0; }
[ "public", "function", "GetDescendantCountByCode", "(", "$", "Code", ")", "{", "$", "Category", "=", "$", "this", "->", "GetByCode", "(", "$", "Code", ")", ";", "if", "(", "$", "Category", ")", "return", "round", "(", "(", "$", "Category", "->", "TreeRight", "-", "$", "Category", "->", "TreeLeft", "-", "1", ")", "/", "2", ")", ";", "return", "0", ";", "}" ]
Return the number of descendants for a specific category.
[ "Return", "the", "number", "of", "descendants", "for", "a", "specific", "category", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L759-L765
12,645
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetAncestors
public static function GetAncestors($CategoryID, $CheckPermissions = TRUE) { $Categories = self::Categories(); $Result = array(); // Grab the category by ID or url code. if (is_numeric($CategoryID)) { if (isset($Categories[$CategoryID])) $Category = $Categories[$CategoryID]; } else { foreach ($Categories as $ID => $Value) { if ($Value['UrlCode'] == $CategoryID) { $Category = $Categories[$ID]; break; } } } if (!isset($Category)) return $Result; // Build up the ancestor array by tracing back through parents. $Result[$Category['CategoryID']] = $Category; $Max = 20; while (isset($Categories[$Category['ParentCategoryID']])) { // Check for an infinite loop. if ($Max <= 0) break; $Max--; if ($CheckPermissions && !$Category['PermsDiscussionsView']) { $Category = $Categories[$Category['ParentCategoryID']]; continue; } if ($Category['CategoryID'] == -1) break; // Return by ID or code. if (is_numeric($CategoryID)) $ID = $Category['CategoryID']; else $ID = $Category['UrlCode']; $Result[$ID] = $Category; $Category = $Categories[$Category['ParentCategoryID']]; } $Result = array_reverse($Result, TRUE); // order for breadcrumbs return $Result; }
php
public static function GetAncestors($CategoryID, $CheckPermissions = TRUE) { $Categories = self::Categories(); $Result = array(); // Grab the category by ID or url code. if (is_numeric($CategoryID)) { if (isset($Categories[$CategoryID])) $Category = $Categories[$CategoryID]; } else { foreach ($Categories as $ID => $Value) { if ($Value['UrlCode'] == $CategoryID) { $Category = $Categories[$ID]; break; } } } if (!isset($Category)) return $Result; // Build up the ancestor array by tracing back through parents. $Result[$Category['CategoryID']] = $Category; $Max = 20; while (isset($Categories[$Category['ParentCategoryID']])) { // Check for an infinite loop. if ($Max <= 0) break; $Max--; if ($CheckPermissions && !$Category['PermsDiscussionsView']) { $Category = $Categories[$Category['ParentCategoryID']]; continue; } if ($Category['CategoryID'] == -1) break; // Return by ID or code. if (is_numeric($CategoryID)) $ID = $Category['CategoryID']; else $ID = $Category['UrlCode']; $Result[$ID] = $Category; $Category = $Categories[$Category['ParentCategoryID']]; } $Result = array_reverse($Result, TRUE); // order for breadcrumbs return $Result; }
[ "public", "static", "function", "GetAncestors", "(", "$", "CategoryID", ",", "$", "CheckPermissions", "=", "TRUE", ")", "{", "$", "Categories", "=", "self", "::", "Categories", "(", ")", ";", "$", "Result", "=", "array", "(", ")", ";", "// Grab the category by ID or url code.", "if", "(", "is_numeric", "(", "$", "CategoryID", ")", ")", "{", "if", "(", "isset", "(", "$", "Categories", "[", "$", "CategoryID", "]", ")", ")", "$", "Category", "=", "$", "Categories", "[", "$", "CategoryID", "]", ";", "}", "else", "{", "foreach", "(", "$", "Categories", "as", "$", "ID", "=>", "$", "Value", ")", "{", "if", "(", "$", "Value", "[", "'UrlCode'", "]", "==", "$", "CategoryID", ")", "{", "$", "Category", "=", "$", "Categories", "[", "$", "ID", "]", ";", "break", ";", "}", "}", "}", "if", "(", "!", "isset", "(", "$", "Category", ")", ")", "return", "$", "Result", ";", "// Build up the ancestor array by tracing back through parents.", "$", "Result", "[", "$", "Category", "[", "'CategoryID'", "]", "]", "=", "$", "Category", ";", "$", "Max", "=", "20", ";", "while", "(", "isset", "(", "$", "Categories", "[", "$", "Category", "[", "'ParentCategoryID'", "]", "]", ")", ")", "{", "// Check for an infinite loop.", "if", "(", "$", "Max", "<=", "0", ")", "break", ";", "$", "Max", "--", ";", "if", "(", "$", "CheckPermissions", "&&", "!", "$", "Category", "[", "'PermsDiscussionsView'", "]", ")", "{", "$", "Category", "=", "$", "Categories", "[", "$", "Category", "[", "'ParentCategoryID'", "]", "]", ";", "continue", ";", "}", "if", "(", "$", "Category", "[", "'CategoryID'", "]", "==", "-", "1", ")", "break", ";", "// Return by ID or code.", "if", "(", "is_numeric", "(", "$", "CategoryID", ")", ")", "$", "ID", "=", "$", "Category", "[", "'CategoryID'", "]", ";", "else", "$", "ID", "=", "$", "Category", "[", "'UrlCode'", "]", ";", "$", "Result", "[", "$", "ID", "]", "=", "$", "Category", ";", "$", "Category", "=", "$", "Categories", "[", "$", "Category", "[", "'ParentCategoryID'", "]", "]", ";", "}", "$", "Result", "=", "array_reverse", "(", "$", "Result", ",", "TRUE", ")", ";", "// order for breadcrumbs", "return", "$", "Result", ";", "}" ]
Get all of the ancestor categories above this one. @param int|string $Category The category ID or url code. @param bool $CheckPermissions Whether or not to only return the categories with view permission. @return array
[ "Get", "all", "of", "the", "ancestor", "categories", "above", "this", "one", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L773-L822
12,646
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetFiltered
public function GetFiltered($RestrictIDs = FALSE, $Permissions = FALSE, $ExcludeWhere = FALSE) { // Get the current category list $Categories = self::Categories(); // Filter out the categories we aren't supposed to view. if ($RestrictIDs && !is_array($RestrictIDs)) $RestrictIDs = array($RestrictIDs); elseif ($this->Watching) $RestrictIDs = self::CategoryWatch(); switch ($Permissions) { case 'Vanilla.Discussions.Add': $Permissions = 'PermsDiscussionsAdd'; break; case 'Vanilla.Disussions.Edit': $Permissions = 'PermsDiscussionsEdit'; break; default: $Permissions = 'PermsDiscussionsView'; break; } $IDs = array_keys($Categories); foreach ($IDs as $ID) { // Exclude the root category if ($ID < 0) unset($Categories[$ID]); // No categories where we don't have permission elseif (!$Categories[$ID][$Permissions]) unset($Categories[$ID]); // No categories whose filter fields match the provided filter values elseif (is_array($ExcludeWhere)) { foreach ($ExcludeWhere as $Filter => $FilterValue) if (GetValue($Filter, $Categories[$ID], FALSE) == $FilterValue) unset($Categories[$ID]); } // No categories that are otherwise filtered out elseif (is_array($RestrictIDs) && !in_array($ID, $RestrictIDs)) unset($Categories[$ID]); } Gdn::UserModel()->JoinUsers($Categories, array('LastUserID')); $Result = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY); $Result->DatasetType(DATASET_TYPE_OBJECT); return $Result; }
php
public function GetFiltered($RestrictIDs = FALSE, $Permissions = FALSE, $ExcludeWhere = FALSE) { // Get the current category list $Categories = self::Categories(); // Filter out the categories we aren't supposed to view. if ($RestrictIDs && !is_array($RestrictIDs)) $RestrictIDs = array($RestrictIDs); elseif ($this->Watching) $RestrictIDs = self::CategoryWatch(); switch ($Permissions) { case 'Vanilla.Discussions.Add': $Permissions = 'PermsDiscussionsAdd'; break; case 'Vanilla.Disussions.Edit': $Permissions = 'PermsDiscussionsEdit'; break; default: $Permissions = 'PermsDiscussionsView'; break; } $IDs = array_keys($Categories); foreach ($IDs as $ID) { // Exclude the root category if ($ID < 0) unset($Categories[$ID]); // No categories where we don't have permission elseif (!$Categories[$ID][$Permissions]) unset($Categories[$ID]); // No categories whose filter fields match the provided filter values elseif (is_array($ExcludeWhere)) { foreach ($ExcludeWhere as $Filter => $FilterValue) if (GetValue($Filter, $Categories[$ID], FALSE) == $FilterValue) unset($Categories[$ID]); } // No categories that are otherwise filtered out elseif (is_array($RestrictIDs) && !in_array($ID, $RestrictIDs)) unset($Categories[$ID]); } Gdn::UserModel()->JoinUsers($Categories, array('LastUserID')); $Result = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY); $Result->DatasetType(DATASET_TYPE_OBJECT); return $Result; }
[ "public", "function", "GetFiltered", "(", "$", "RestrictIDs", "=", "FALSE", ",", "$", "Permissions", "=", "FALSE", ",", "$", "ExcludeWhere", "=", "FALSE", ")", "{", "// Get the current category list", "$", "Categories", "=", "self", "::", "Categories", "(", ")", ";", "// Filter out the categories we aren't supposed to view.", "if", "(", "$", "RestrictIDs", "&&", "!", "is_array", "(", "$", "RestrictIDs", ")", ")", "$", "RestrictIDs", "=", "array", "(", "$", "RestrictIDs", ")", ";", "elseif", "(", "$", "this", "->", "Watching", ")", "$", "RestrictIDs", "=", "self", "::", "CategoryWatch", "(", ")", ";", "switch", "(", "$", "Permissions", ")", "{", "case", "'Vanilla.Discussions.Add'", ":", "$", "Permissions", "=", "'PermsDiscussionsAdd'", ";", "break", ";", "case", "'Vanilla.Disussions.Edit'", ":", "$", "Permissions", "=", "'PermsDiscussionsEdit'", ";", "break", ";", "default", ":", "$", "Permissions", "=", "'PermsDiscussionsView'", ";", "break", ";", "}", "$", "IDs", "=", "array_keys", "(", "$", "Categories", ")", ";", "foreach", "(", "$", "IDs", "as", "$", "ID", ")", "{", "// Exclude the root category", "if", "(", "$", "ID", "<", "0", ")", "unset", "(", "$", "Categories", "[", "$", "ID", "]", ")", ";", "// No categories where we don't have permission", "elseif", "(", "!", "$", "Categories", "[", "$", "ID", "]", "[", "$", "Permissions", "]", ")", "unset", "(", "$", "Categories", "[", "$", "ID", "]", ")", ";", "// No categories whose filter fields match the provided filter values", "elseif", "(", "is_array", "(", "$", "ExcludeWhere", ")", ")", "{", "foreach", "(", "$", "ExcludeWhere", "as", "$", "Filter", "=>", "$", "FilterValue", ")", "if", "(", "GetValue", "(", "$", "Filter", ",", "$", "Categories", "[", "$", "ID", "]", ",", "FALSE", ")", "==", "$", "FilterValue", ")", "unset", "(", "$", "Categories", "[", "$", "ID", "]", ")", ";", "}", "// No categories that are otherwise filtered out", "elseif", "(", "is_array", "(", "$", "RestrictIDs", ")", "&&", "!", "in_array", "(", "$", "ID", ",", "$", "RestrictIDs", ")", ")", "unset", "(", "$", "Categories", "[", "$", "ID", "]", ")", ";", "}", "Gdn", "::", "UserModel", "(", ")", "->", "JoinUsers", "(", "$", "Categories", ",", "array", "(", "'LastUserID'", ")", ")", ";", "$", "Result", "=", "new", "Gdn_DataSet", "(", "$", "Categories", ",", "DATASET_TYPE_ARRAY", ")", ";", "$", "Result", "->", "DatasetType", "(", "DATASET_TYPE_OBJECT", ")", ";", "return", "$", "Result", ";", "}" ]
Get a list of categories, considering several filters @param array $RestrictIDs Optional list of category ids to mask the dataset @param string $Permissions Optional permission to require. Defaults to Vanilla.Discussions.View. @param array $ExcludeWhere Exclude categories with any of these flags @return \Gdn_DataSet
[ "Get", "a", "list", "of", "categories", "considering", "several", "filters" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L920-L971
12,647
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetFullByUrlCode
public function GetFullByUrlCode($UrlCode) { $Data = (object)self::Categories($UrlCode); // Check to see if the user has permission for this category. // Get the category IDs. $CategoryIDs = DiscussionModel::CategoryPermissions(); if (is_array($CategoryIDs) && !in_array(GetValue('CategoryID', $Data), $CategoryIDs)) $Data = FALSE; return $Data; }
php
public function GetFullByUrlCode($UrlCode) { $Data = (object)self::Categories($UrlCode); // Check to see if the user has permission for this category. // Get the category IDs. $CategoryIDs = DiscussionModel::CategoryPermissions(); if (is_array($CategoryIDs) && !in_array(GetValue('CategoryID', $Data), $CategoryIDs)) $Data = FALSE; return $Data; }
[ "public", "function", "GetFullByUrlCode", "(", "$", "UrlCode", ")", "{", "$", "Data", "=", "(", "object", ")", "self", "::", "Categories", "(", "$", "UrlCode", ")", ";", "// Check to see if the user has permission for this category.", "// Get the category IDs.", "$", "CategoryIDs", "=", "DiscussionModel", "::", "CategoryPermissions", "(", ")", ";", "if", "(", "is_array", "(", "$", "CategoryIDs", ")", "&&", "!", "in_array", "(", "GetValue", "(", "'CategoryID'", ",", "$", "Data", ")", ",", "$", "CategoryIDs", ")", ")", "$", "Data", "=", "FALSE", ";", "return", "$", "Data", ";", "}" ]
Get full data for a single category by its URL slug. Respects permissions. @since 2.0.0 @access public @param string $UrlCode Unique category slug from URL. @return object SQL results.
[ "Get", "full", "data", "for", "a", "single", "category", "by", "its", "URL", "slug", ".", "Respects", "permissions", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L982-L991
12,648
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.GetWhereCache
public function GetWhereCache($Where) { $Result = array(); foreach (self::Categories() as $Index => $Row) { $Match = true; foreach ($Where as $Column => $Value) { $RowValue = GetValue($Column, $Row, NULL); if ($RowValue != $Value && !(is_array($Value) && in_array($RowValue, $Value))) { $Match = false; break; } } if ($Match) $Result[$Index] = $Row; } return $Result; }
php
public function GetWhereCache($Where) { $Result = array(); foreach (self::Categories() as $Index => $Row) { $Match = true; foreach ($Where as $Column => $Value) { $RowValue = GetValue($Column, $Row, NULL); if ($RowValue != $Value && !(is_array($Value) && in_array($RowValue, $Value))) { $Match = false; break; } } if ($Match) $Result[$Index] = $Row; } return $Result; }
[ "public", "function", "GetWhereCache", "(", "$", "Where", ")", "{", "$", "Result", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "Categories", "(", ")", "as", "$", "Index", "=>", "$", "Row", ")", "{", "$", "Match", "=", "true", ";", "foreach", "(", "$", "Where", "as", "$", "Column", "=>", "$", "Value", ")", "{", "$", "RowValue", "=", "GetValue", "(", "$", "Column", ",", "$", "Row", ",", "NULL", ")", ";", "if", "(", "$", "RowValue", "!=", "$", "Value", "&&", "!", "(", "is_array", "(", "$", "Value", ")", "&&", "in_array", "(", "$", "RowValue", ",", "$", "Value", ")", ")", ")", "{", "$", "Match", "=", "false", ";", "break", ";", "}", "}", "if", "(", "$", "Match", ")", "$", "Result", "[", "$", "Index", "]", "=", "$", "Row", ";", "}", "return", "$", "Result", ";", "}" ]
A simplified version of GetWhere that polls the cache instead of the database. @param array $Where @return array @since 2.2.2
[ "A", "simplified", "version", "of", "GetWhere", "that", "polls", "the", "cache", "instead", "of", "the", "database", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L999-L1017
12,649
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.HasChildren
public function HasChildren($CategoryID) { $ChildData = $this->SQL ->Select('CategoryID') ->From('Category') ->Where('ParentCategoryID', $CategoryID) ->Get(); return $ChildData->NumRows() > 0 ? TRUE : FALSE; }
php
public function HasChildren($CategoryID) { $ChildData = $this->SQL ->Select('CategoryID') ->From('Category') ->Where('ParentCategoryID', $CategoryID) ->Get(); return $ChildData->NumRows() > 0 ? TRUE : FALSE; }
[ "public", "function", "HasChildren", "(", "$", "CategoryID", ")", "{", "$", "ChildData", "=", "$", "this", "->", "SQL", "->", "Select", "(", "'CategoryID'", ")", "->", "From", "(", "'Category'", ")", "->", "Where", "(", "'ParentCategoryID'", ",", "$", "CategoryID", ")", "->", "Get", "(", ")", ";", "return", "$", "ChildData", "->", "NumRows", "(", ")", ">", "0", "?", "TRUE", ":", "FALSE", ";", "}" ]
Check whether category has any children categories. @since 2.0.0 @access public @param string $CategoryID Unique ID for category being checked. @return bool
[ "Check", "whether", "category", "has", "any", "children", "categories", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L1028-L1035
12,650
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.SaveTree
public function SaveTree($TreeArray) { /* TreeArray comes in the format: '0' ... 'item_id' => "root" 'parent_id' => "none" 'depth' => "0" 'left' => "1" 'right' => "34" '1' ... 'item_id' => "1" 'parent_id' => "root" 'depth' => "1" 'left' => "2" 'right' => "3" etc... */ // Grab all of the categories so that permissions can be properly saved. $PermTree = $this->SQL->Select('CategoryID, PermissionCategoryID, TreeLeft, TreeRight, Depth, Sort, ParentCategoryID')->From('Category')->Get(); $PermTree = $PermTree->Index($PermTree->ResultArray(), 'CategoryID'); // The tree must be walked in order for the permissions to save properly. usort($TreeArray, array('CategoryModel', '_TreeSort')); $Saves = array(); foreach($TreeArray as $I => $Node) { $CategoryID = GetValue('item_id', $Node); if ($CategoryID == 'root') $CategoryID = -1; $ParentCategoryID = GetValue('parent_id', $Node); if (in_array($ParentCategoryID, array('root', 'none'))) $ParentCategoryID = -1; $PermissionCategoryID = GetValueR("$CategoryID.PermissionCategoryID", $PermTree, 0); $PermCatChanged = FALSE; if ($PermissionCategoryID != $CategoryID) { // This category does not have custom permissions so must inherit its parent's permissions. $PermissionCategoryID = GetValueR("$ParentCategoryID.PermissionCategoryID", $PermTree, 0); if ($CategoryID != -1 && !GetValueR("$ParentCategoryID.Touched", $PermTree)) { throw new Exception("Category $ParentCategoryID not touched before touching $CategoryID."); } if ($PermTree[$CategoryID]['PermissionCategoryID'] != $PermissionCategoryID) $PermCatChanged = TRUE; $PermTree[$CategoryID]['PermissionCategoryID'] = $PermissionCategoryID; } $PermTree[$CategoryID]['Touched'] = TRUE; // Only update if the tree doesn't match the database. $Row = $PermTree[$CategoryID]; if ($Node['left'] != $Row['TreeLeft'] || $Node['right'] != $Row['TreeRight'] || $Node['depth'] != $Row['Depth'] || $ParentCategoryID != $Row['ParentCategoryID'] || $Node['left'] != $Row['Sort'] || $PermCatChanged) { $Set = array( 'TreeLeft' => $Node['left'], 'TreeRight' => $Node['right'], 'Depth' => $Node['depth'], 'Sort' => $Node['left'], 'ParentCategoryID' => $ParentCategoryID, 'PermissionCategoryID' => $PermissionCategoryID ); $this->SQL->Update( 'Category', $Set, array('CategoryID' => $CategoryID) )->Put(); $Saves[] = array_merge(array('CategoryID' => $CategoryID), $Set); } } self::ClearCache(); return $Saves; }
php
public function SaveTree($TreeArray) { /* TreeArray comes in the format: '0' ... 'item_id' => "root" 'parent_id' => "none" 'depth' => "0" 'left' => "1" 'right' => "34" '1' ... 'item_id' => "1" 'parent_id' => "root" 'depth' => "1" 'left' => "2" 'right' => "3" etc... */ // Grab all of the categories so that permissions can be properly saved. $PermTree = $this->SQL->Select('CategoryID, PermissionCategoryID, TreeLeft, TreeRight, Depth, Sort, ParentCategoryID')->From('Category')->Get(); $PermTree = $PermTree->Index($PermTree->ResultArray(), 'CategoryID'); // The tree must be walked in order for the permissions to save properly. usort($TreeArray, array('CategoryModel', '_TreeSort')); $Saves = array(); foreach($TreeArray as $I => $Node) { $CategoryID = GetValue('item_id', $Node); if ($CategoryID == 'root') $CategoryID = -1; $ParentCategoryID = GetValue('parent_id', $Node); if (in_array($ParentCategoryID, array('root', 'none'))) $ParentCategoryID = -1; $PermissionCategoryID = GetValueR("$CategoryID.PermissionCategoryID", $PermTree, 0); $PermCatChanged = FALSE; if ($PermissionCategoryID != $CategoryID) { // This category does not have custom permissions so must inherit its parent's permissions. $PermissionCategoryID = GetValueR("$ParentCategoryID.PermissionCategoryID", $PermTree, 0); if ($CategoryID != -1 && !GetValueR("$ParentCategoryID.Touched", $PermTree)) { throw new Exception("Category $ParentCategoryID not touched before touching $CategoryID."); } if ($PermTree[$CategoryID]['PermissionCategoryID'] != $PermissionCategoryID) $PermCatChanged = TRUE; $PermTree[$CategoryID]['PermissionCategoryID'] = $PermissionCategoryID; } $PermTree[$CategoryID]['Touched'] = TRUE; // Only update if the tree doesn't match the database. $Row = $PermTree[$CategoryID]; if ($Node['left'] != $Row['TreeLeft'] || $Node['right'] != $Row['TreeRight'] || $Node['depth'] != $Row['Depth'] || $ParentCategoryID != $Row['ParentCategoryID'] || $Node['left'] != $Row['Sort'] || $PermCatChanged) { $Set = array( 'TreeLeft' => $Node['left'], 'TreeRight' => $Node['right'], 'Depth' => $Node['depth'], 'Sort' => $Node['left'], 'ParentCategoryID' => $ParentCategoryID, 'PermissionCategoryID' => $PermissionCategoryID ); $this->SQL->Update( 'Category', $Set, array('CategoryID' => $CategoryID) )->Put(); $Saves[] = array_merge(array('CategoryID' => $CategoryID), $Set); } } self::ClearCache(); return $Saves; }
[ "public", "function", "SaveTree", "(", "$", "TreeArray", ")", "{", "/*\n TreeArray comes in the format:\n '0' ...\n 'item_id' => \"root\"\n 'parent_id' => \"none\"\n 'depth' => \"0\"\n 'left' => \"1\"\n 'right' => \"34\"\n '1' ...\n 'item_id' => \"1\"\n 'parent_id' => \"root\"\n 'depth' => \"1\"\n 'left' => \"2\"\n 'right' => \"3\"\n etc...\n */", "// Grab all of the categories so that permissions can be properly saved.", "$", "PermTree", "=", "$", "this", "->", "SQL", "->", "Select", "(", "'CategoryID, PermissionCategoryID, TreeLeft, TreeRight, Depth, Sort, ParentCategoryID'", ")", "->", "From", "(", "'Category'", ")", "->", "Get", "(", ")", ";", "$", "PermTree", "=", "$", "PermTree", "->", "Index", "(", "$", "PermTree", "->", "ResultArray", "(", ")", ",", "'CategoryID'", ")", ";", "// The tree must be walked in order for the permissions to save properly.", "usort", "(", "$", "TreeArray", ",", "array", "(", "'CategoryModel'", ",", "'_TreeSort'", ")", ")", ";", "$", "Saves", "=", "array", "(", ")", ";", "foreach", "(", "$", "TreeArray", "as", "$", "I", "=>", "$", "Node", ")", "{", "$", "CategoryID", "=", "GetValue", "(", "'item_id'", ",", "$", "Node", ")", ";", "if", "(", "$", "CategoryID", "==", "'root'", ")", "$", "CategoryID", "=", "-", "1", ";", "$", "ParentCategoryID", "=", "GetValue", "(", "'parent_id'", ",", "$", "Node", ")", ";", "if", "(", "in_array", "(", "$", "ParentCategoryID", ",", "array", "(", "'root'", ",", "'none'", ")", ")", ")", "$", "ParentCategoryID", "=", "-", "1", ";", "$", "PermissionCategoryID", "=", "GetValueR", "(", "\"$CategoryID.PermissionCategoryID\"", ",", "$", "PermTree", ",", "0", ")", ";", "$", "PermCatChanged", "=", "FALSE", ";", "if", "(", "$", "PermissionCategoryID", "!=", "$", "CategoryID", ")", "{", "// This category does not have custom permissions so must inherit its parent's permissions.", "$", "PermissionCategoryID", "=", "GetValueR", "(", "\"$ParentCategoryID.PermissionCategoryID\"", ",", "$", "PermTree", ",", "0", ")", ";", "if", "(", "$", "CategoryID", "!=", "-", "1", "&&", "!", "GetValueR", "(", "\"$ParentCategoryID.Touched\"", ",", "$", "PermTree", ")", ")", "{", "throw", "new", "Exception", "(", "\"Category $ParentCategoryID not touched before touching $CategoryID.\"", ")", ";", "}", "if", "(", "$", "PermTree", "[", "$", "CategoryID", "]", "[", "'PermissionCategoryID'", "]", "!=", "$", "PermissionCategoryID", ")", "$", "PermCatChanged", "=", "TRUE", ";", "$", "PermTree", "[", "$", "CategoryID", "]", "[", "'PermissionCategoryID'", "]", "=", "$", "PermissionCategoryID", ";", "}", "$", "PermTree", "[", "$", "CategoryID", "]", "[", "'Touched'", "]", "=", "TRUE", ";", "// Only update if the tree doesn't match the database.", "$", "Row", "=", "$", "PermTree", "[", "$", "CategoryID", "]", ";", "if", "(", "$", "Node", "[", "'left'", "]", "!=", "$", "Row", "[", "'TreeLeft'", "]", "||", "$", "Node", "[", "'right'", "]", "!=", "$", "Row", "[", "'TreeRight'", "]", "||", "$", "Node", "[", "'depth'", "]", "!=", "$", "Row", "[", "'Depth'", "]", "||", "$", "ParentCategoryID", "!=", "$", "Row", "[", "'ParentCategoryID'", "]", "||", "$", "Node", "[", "'left'", "]", "!=", "$", "Row", "[", "'Sort'", "]", "||", "$", "PermCatChanged", ")", "{", "$", "Set", "=", "array", "(", "'TreeLeft'", "=>", "$", "Node", "[", "'left'", "]", ",", "'TreeRight'", "=>", "$", "Node", "[", "'right'", "]", ",", "'Depth'", "=>", "$", "Node", "[", "'depth'", "]", ",", "'Sort'", "=>", "$", "Node", "[", "'left'", "]", ",", "'ParentCategoryID'", "=>", "$", "ParentCategoryID", ",", "'PermissionCategoryID'", "=>", "$", "PermissionCategoryID", ")", ";", "$", "this", "->", "SQL", "->", "Update", "(", "'Category'", ",", "$", "Set", ",", "array", "(", "'CategoryID'", "=>", "$", "CategoryID", ")", ")", "->", "Put", "(", ")", ";", "$", "Saves", "[", "]", "=", "array_merge", "(", "array", "(", "'CategoryID'", "=>", "$", "CategoryID", ")", ",", "$", "Set", ")", ";", "}", "}", "self", "::", "ClearCache", "(", ")", ";", "return", "$", "Saves", ";", "}" ]
Saves the category tree based on a provided tree array. We are using the Nested Set tree model. @ref http://articles.sitepoint.com/article/hierarchical-data-database/2 @ref http://en.wikipedia.org/wiki/Nested_set_model @since 2.0.16 @access public @param array $TreeArray A fully defined nested set model of the category tree.
[ "Saves", "the", "category", "tree", "based", "on", "a", "provided", "tree", "array", ".", "We", "are", "using", "the", "Nested", "Set", "tree", "model", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L1224-L1296
12,651
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.SaveUserTree
public function SaveUserTree($CategoryID, $Set) { $Categories = $this->GetSubtree($CategoryID); foreach ($Categories as $Category) { $this->SQL->Replace( 'UserCategory', $Set, array('UserID' => Gdn::Session()->UserID, 'CategoryID' => $Category['CategoryID'])); } $Key = 'UserCategory_'.Gdn::Session()->UserID; Gdn::Cache()->Remove($Key); }
php
public function SaveUserTree($CategoryID, $Set) { $Categories = $this->GetSubtree($CategoryID); foreach ($Categories as $Category) { $this->SQL->Replace( 'UserCategory', $Set, array('UserID' => Gdn::Session()->UserID, 'CategoryID' => $Category['CategoryID'])); } $Key = 'UserCategory_'.Gdn::Session()->UserID; Gdn::Cache()->Remove($Key); }
[ "public", "function", "SaveUserTree", "(", "$", "CategoryID", ",", "$", "Set", ")", "{", "$", "Categories", "=", "$", "this", "->", "GetSubtree", "(", "$", "CategoryID", ")", ";", "foreach", "(", "$", "Categories", "as", "$", "Category", ")", "{", "$", "this", "->", "SQL", "->", "Replace", "(", "'UserCategory'", ",", "$", "Set", ",", "array", "(", "'UserID'", "=>", "Gdn", "::", "Session", "(", ")", "->", "UserID", ",", "'CategoryID'", "=>", "$", "Category", "[", "'CategoryID'", "]", ")", ")", ";", "}", "$", "Key", "=", "'UserCategory_'", ".", "Gdn", "::", "Session", "(", ")", "->", "UserID", ";", "Gdn", "::", "Cache", "(", ")", "->", "Remove", "(", "$", "Key", ")", ";", "}" ]
Grab the Category IDs of the tree. @since 2.0.18 @access public @param int $CategoryID @param mixed $Set
[ "Grab", "the", "Category", "IDs", "of", "the", "tree", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L1472-L1482
12,652
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.SetCache
public static function SetCache($ID = FALSE, $Data = FALSE) { $Categories = Gdn::Cache()->Get(self::CACHE_KEY); self::$Categories = NULL; if (!$Categories) return; if (!$ID || !is_array($Categories)) { Gdn::Cache()->Remove(self::CACHE_KEY); return; } if (!array_key_exists($ID, $Categories)) { Gdn::Cache()->Remove(self::CACHE_KEY); return; } $Category = $Categories[$ID]; $Category = array_merge($Category, $Data); $Categories[$ID] = $Category; self::$Categories = $Categories; unset($Categories); self::BuildCache(); self::JoinUserData(self::$Categories, TRUE); }
php
public static function SetCache($ID = FALSE, $Data = FALSE) { $Categories = Gdn::Cache()->Get(self::CACHE_KEY); self::$Categories = NULL; if (!$Categories) return; if (!$ID || !is_array($Categories)) { Gdn::Cache()->Remove(self::CACHE_KEY); return; } if (!array_key_exists($ID, $Categories)) { Gdn::Cache()->Remove(self::CACHE_KEY); return; } $Category = $Categories[$ID]; $Category = array_merge($Category, $Data); $Categories[$ID] = $Category; self::$Categories = $Categories; unset($Categories); self::BuildCache(); self::JoinUserData(self::$Categories, TRUE); }
[ "public", "static", "function", "SetCache", "(", "$", "ID", "=", "FALSE", ",", "$", "Data", "=", "FALSE", ")", "{", "$", "Categories", "=", "Gdn", "::", "Cache", "(", ")", "->", "Get", "(", "self", "::", "CACHE_KEY", ")", ";", "self", "::", "$", "Categories", "=", "NULL", ";", "if", "(", "!", "$", "Categories", ")", "return", ";", "if", "(", "!", "$", "ID", "||", "!", "is_array", "(", "$", "Categories", ")", ")", "{", "Gdn", "::", "Cache", "(", ")", "->", "Remove", "(", "self", "::", "CACHE_KEY", ")", ";", "return", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "ID", ",", "$", "Categories", ")", ")", "{", "Gdn", "::", "Cache", "(", ")", "->", "Remove", "(", "self", "::", "CACHE_KEY", ")", ";", "return", ";", "}", "$", "Category", "=", "$", "Categories", "[", "$", "ID", "]", ";", "$", "Category", "=", "array_merge", "(", "$", "Category", ",", "$", "Data", ")", ";", "$", "Categories", "[", "$", "ID", "]", "=", "$", "Category", ";", "self", "::", "$", "Categories", "=", "$", "Categories", ";", "unset", "(", "$", "Categories", ")", ";", "self", "::", "BuildCache", "(", ")", ";", "self", "::", "JoinUserData", "(", "self", "::", "$", "Categories", ",", "TRUE", ")", ";", "}" ]
Grab and update the category cache @since 2.0.18 @access public @param int $ID @param array $Data
[ "Grab", "and", "update", "the", "category", "cache" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L1492-L1517
12,653
bishopb/vanilla
applications/vanilla/models/class.categorymodel.php
CategoryModel.ApplyUpdates
public function ApplyUpdates() { if (!C('Vanilla.NestedCategoriesUpdate')) { // Add new columns $Construct = Gdn::Database()->Structure(); $Construct->Table('Category') ->Column('TreeLeft', 'int', TRUE) ->Column('TreeRight', 'int', TRUE) ->Column('Depth', 'int', TRUE) ->Column('CountComments', 'int', '0') ->Column('LastCommentID', 'int', TRUE) ->Set(0, 0); // Insert the root node if ($this->SQL->GetWhere('Category', array('CategoryID' => -1))->NumRows() == 0) $this->SQL->Insert('Category', array('CategoryID' => -1, 'TreeLeft' => 1, 'TreeRight' => 4, 'Depth' => 0, 'InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'Name' => 'Root', 'UrlCode' => '', 'Description' => 'Root of category tree. Users should never see this.')); // Build up the TreeLeft & TreeRight values. $this->RebuildTree(); SaveToConfig('Vanilla.NestedCategoriesUpdate', 1); } }
php
public function ApplyUpdates() { if (!C('Vanilla.NestedCategoriesUpdate')) { // Add new columns $Construct = Gdn::Database()->Structure(); $Construct->Table('Category') ->Column('TreeLeft', 'int', TRUE) ->Column('TreeRight', 'int', TRUE) ->Column('Depth', 'int', TRUE) ->Column('CountComments', 'int', '0') ->Column('LastCommentID', 'int', TRUE) ->Set(0, 0); // Insert the root node if ($this->SQL->GetWhere('Category', array('CategoryID' => -1))->NumRows() == 0) $this->SQL->Insert('Category', array('CategoryID' => -1, 'TreeLeft' => 1, 'TreeRight' => 4, 'Depth' => 0, 'InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'Name' => 'Root', 'UrlCode' => '', 'Description' => 'Root of category tree. Users should never see this.')); // Build up the TreeLeft & TreeRight values. $this->RebuildTree(); SaveToConfig('Vanilla.NestedCategoriesUpdate', 1); } }
[ "public", "function", "ApplyUpdates", "(", ")", "{", "if", "(", "!", "C", "(", "'Vanilla.NestedCategoriesUpdate'", ")", ")", "{", "// Add new columns", "$", "Construct", "=", "Gdn", "::", "Database", "(", ")", "->", "Structure", "(", ")", ";", "$", "Construct", "->", "Table", "(", "'Category'", ")", "->", "Column", "(", "'TreeLeft'", ",", "'int'", ",", "TRUE", ")", "->", "Column", "(", "'TreeRight'", ",", "'int'", ",", "TRUE", ")", "->", "Column", "(", "'Depth'", ",", "'int'", ",", "TRUE", ")", "->", "Column", "(", "'CountComments'", ",", "'int'", ",", "'0'", ")", "->", "Column", "(", "'LastCommentID'", ",", "'int'", ",", "TRUE", ")", "->", "Set", "(", "0", ",", "0", ")", ";", "// Insert the root node", "if", "(", "$", "this", "->", "SQL", "->", "GetWhere", "(", "'Category'", ",", "array", "(", "'CategoryID'", "=>", "-", "1", ")", ")", "->", "NumRows", "(", ")", "==", "0", ")", "$", "this", "->", "SQL", "->", "Insert", "(", "'Category'", ",", "array", "(", "'CategoryID'", "=>", "-", "1", ",", "'TreeLeft'", "=>", "1", ",", "'TreeRight'", "=>", "4", ",", "'Depth'", "=>", "0", ",", "'InsertUserID'", "=>", "1", ",", "'UpdateUserID'", "=>", "1", ",", "'DateInserted'", "=>", "Gdn_Format", "::", "ToDateTime", "(", ")", ",", "'DateUpdated'", "=>", "Gdn_Format", "::", "ToDateTime", "(", ")", ",", "'Name'", "=>", "'Root'", ",", "'UrlCode'", "=>", "''", ",", "'Description'", "=>", "'Root of category tree. Users should never see this.'", ")", ")", ";", "// Build up the TreeLeft & TreeRight values.", "$", "this", "->", "RebuildTree", "(", ")", ";", "SaveToConfig", "(", "'Vanilla.NestedCategoriesUpdate'", ",", "1", ")", ";", "}", "}" ]
If looking at the root node, make sure it exists and that the nested set columns exist in the table. @since 2.0.15 @access public
[ "If", "looking", "at", "the", "root", "node", "make", "sure", "it", "exists", "and", "that", "the", "nested", "set", "columns", "exist", "in", "the", "table", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.categorymodel.php#L1551-L1572
12,654
open-orchestra/open-orchestra-media-bundle
Media/BBcode/AbstractMediaCodeDefinition.php
AbstractMediaCodeDefinition.getAttribute
protected function getAttribute(BBcodeElementNodeInterface $el, $attribute) { $attributes = $el->getAttribute(); if (isset($attributes[self::TAG_NAME])) { $attributes = json_decode($attributes[self::TAG_NAME]); if (isset($attributes->$attribute)) { return $attributes->$attribute; } } return ''; }
php
protected function getAttribute(BBcodeElementNodeInterface $el, $attribute) { $attributes = $el->getAttribute(); if (isset($attributes[self::TAG_NAME])) { $attributes = json_decode($attributes[self::TAG_NAME]); if (isset($attributes->$attribute)) { return $attributes->$attribute; } } return ''; }
[ "protected", "function", "getAttribute", "(", "BBcodeElementNodeInterface", "$", "el", ",", "$", "attribute", ")", "{", "$", "attributes", "=", "$", "el", "->", "getAttribute", "(", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "self", "::", "TAG_NAME", "]", ")", ")", "{", "$", "attributes", "=", "json_decode", "(", "$", "attributes", "[", "self", "::", "TAG_NAME", "]", ")", ";", "if", "(", "isset", "(", "$", "attributes", "->", "$", "attribute", ")", ")", "{", "return", "$", "attributes", "->", "$", "attribute", ";", "}", "}", "return", "''", ";", "}" ]
Get requested media legend @param BBcodeElementNodeInterface $el @param string $attribute @return string
[ "Get", "requested", "media", "legend" ]
702121d1329c70c3a93dc216a1b47917e186365c
https://github.com/open-orchestra/open-orchestra-media-bundle/blob/702121d1329c70c3a93dc216a1b47917e186365c/Media/BBcode/AbstractMediaCodeDefinition.php#L154-L167
12,655
jnjxp/jnjxp.routeless
src/RoutingFailedResponder.php
RoutingFailedResponder.getResponderForFailedRoute
protected function getResponderForFailedRoute(Route $route) { $rule = $route->failedRule; if ($this->has($rule)) { return $this->get($rule); } if (isset($this->defaults[$rule])) { return [$this, $this->defaults[$rule]]; } return [$this, 'other']; }
php
protected function getResponderForFailedRoute(Route $route) { $rule = $route->failedRule; if ($this->has($rule)) { return $this->get($rule); } if (isset($this->defaults[$rule])) { return [$this, $this->defaults[$rule]]; } return [$this, 'other']; }
[ "protected", "function", "getResponderForFailedRoute", "(", "Route", "$", "route", ")", "{", "$", "rule", "=", "$", "route", "->", "failedRule", ";", "if", "(", "$", "this", "->", "has", "(", "$", "rule", ")", ")", "{", "return", "$", "this", "->", "get", "(", "$", "rule", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "defaults", "[", "$", "rule", "]", ")", ")", "{", "return", "[", "$", "this", ",", "$", "this", "->", "defaults", "[", "$", "rule", "]", "]", ";", "}", "return", "[", "$", "this", ",", "'other'", "]", ";", "}" ]
Get responder for failed route @param Route $route Failed Route @return callable @access protected
[ "Get", "responder", "for", "failed", "route" ]
73ae5b931355626f7138b3c397ce692af4ca7636
https://github.com/jnjxp/jnjxp.routeless/blob/73ae5b931355626f7138b3c397ce692af4ca7636/src/RoutingFailedResponder.php#L159-L171
12,656
jnjxp/jnjxp.routeless
src/RoutingFailedResponder.php
RoutingFailedResponder.methodNotAllowed
protected function methodNotAllowed( Request $request, Response $response, Route $route ) { $request; $response = $response->withStatus(405) ->withHeader('Allow', implode(', ', $route->allows)) ->withHeader('Content-Type', 'application/json'); $response->getBody()->write(json_encode($route->allows)); return $response; }
php
protected function methodNotAllowed( Request $request, Response $response, Route $route ) { $request; $response = $response->withStatus(405) ->withHeader('Allow', implode(', ', $route->allows)) ->withHeader('Content-Type', 'application/json'); $response->getBody()->write(json_encode($route->allows)); return $response; }
[ "protected", "function", "methodNotAllowed", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "Route", "$", "route", ")", "{", "$", "request", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "405", ")", "->", "withHeader", "(", "'Allow'", ",", "implode", "(", "', '", ",", "$", "route", "->", "allows", ")", ")", "->", "withHeader", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "json_encode", "(", "$", "route", "->", "allows", ")", ")", ";", "return", "$", "response", ";", "}" ]
Method not allowed Builds the Response when the failed route method was not allowed. @param Request $request PSR7 Request @param Response $response PSR7 Response @param Route $route Failed Route @return Response @access protected
[ "Method", "not", "allowed" ]
73ae5b931355626f7138b3c397ce692af4ca7636
https://github.com/jnjxp/jnjxp.routeless/blob/73ae5b931355626f7138b3c397ce692af4ca7636/src/RoutingFailedResponder.php#L186-L197
12,657
jnjxp/jnjxp.routeless
src/RoutingFailedResponder.php
RoutingFailedResponder.notFound
protected function notFound(Request $request, Response $response, Route $route) { $request; $route; $response = $response->withStatus(404); $response->getBody()->write('404 Not Found'); return $response; }
php
protected function notFound(Request $request, Response $response, Route $route) { $request; $route; $response = $response->withStatus(404); $response->getBody()->write('404 Not Found'); return $response; }
[ "protected", "function", "notFound", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "Route", "$", "route", ")", "{", "$", "request", ";", "$", "route", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "404", ")", ";", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "'404 Not Found'", ")", ";", "return", "$", "response", ";", "}" ]
Resource not found Builds the Response when the failed route host or path was not found. @param Request $request PSR7 Request @param Response $response PSR7 Response @param Route $route Failed Route @return Response @access protected
[ "Resource", "not", "found" ]
73ae5b931355626f7138b3c397ce692af4ca7636
https://github.com/jnjxp/jnjxp.routeless/blob/73ae5b931355626f7138b3c397ce692af4ca7636/src/RoutingFailedResponder.php#L238-L244
12,658
jnjxp/jnjxp.routeless
src/RoutingFailedResponder.php
RoutingFailedResponder.other
protected function other(Request $request, Response $response, Route $route) { $request; $response = $response->withStatus(500) ->withHeader('Content-Type', 'text/plain'); $message = sprintf( 'Route "%s" failed for rule "%s"', $route->name, $route->failedRule ); $response->getBody()->write($message); return $response; }
php
protected function other(Request $request, Response $response, Route $route) { $request; $response = $response->withStatus(500) ->withHeader('Content-Type', 'text/plain'); $message = sprintf( 'Route "%s" failed for rule "%s"', $route->name, $route->failedRule ); $response->getBody()->write($message); return $response; }
[ "protected", "function", "other", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "Route", "$", "route", ")", "{", "$", "request", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "500", ")", "->", "withHeader", "(", "'Content-Type'", ",", "'text/plain'", ")", ";", "$", "message", "=", "sprintf", "(", "'Route \"%s\" failed for rule \"%s\"'", ",", "$", "route", "->", "name", ",", "$", "route", "->", "failedRule", ")", ";", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "$", "message", ")", ";", "return", "$", "response", ";", "}" ]
Other rule failed Builds the Response when routing failed for some other reason. @param Request $request PSR7 Request @param Response $response PSR7 Response @param Route $route Failed Route @return Response @access protected
[ "Other", "rule", "failed" ]
73ae5b931355626f7138b3c397ce692af4ca7636
https://github.com/jnjxp/jnjxp.routeless/blob/73ae5b931355626f7138b3c397ce692af4ca7636/src/RoutingFailedResponder.php#L259-L271
12,659
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getRepository
protected function getRepository(): AbstractRepository { return $this->getRepositoryFactory()->getRepositoryForEntity( AbstractRepository::getEntityNameFromClassName($this->getEntityClassName()), $this->connectionName ); }
php
protected function getRepository(): AbstractRepository { return $this->getRepositoryFactory()->getRepositoryForEntity( AbstractRepository::getEntityNameFromClassName($this->getEntityClassName()), $this->connectionName ); }
[ "protected", "function", "getRepository", "(", ")", ":", "AbstractRepository", "{", "return", "$", "this", "->", "getRepositoryFactory", "(", ")", "->", "getRepositoryForEntity", "(", "AbstractRepository", "::", "getEntityNameFromClassName", "(", "$", "this", "->", "getEntityClassName", "(", ")", ")", ",", "$", "this", "->", "connectionName", ")", ";", "}" ]
Gets the repository corresponding to the managed entity @return \Thuata\FrameworkBundle\Repository\AbstractRepository
[ "Gets", "the", "repository", "corresponding", "to", "the", "managed", "entity" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L74-L80
12,660
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.entityImplements
protected function entityImplements(string $interfaceName): bool { $reflectionClass = new \ReflectionClass($this->getEntityClassName()); return $reflectionClass->implementsInterface($interfaceName); }
php
protected function entityImplements(string $interfaceName): bool { $reflectionClass = new \ReflectionClass($this->getEntityClassName()); return $reflectionClass->implementsInterface($interfaceName); }
[ "protected", "function", "entityImplements", "(", "string", "$", "interfaceName", ")", ":", "bool", "{", "$", "reflectionClass", "=", "new", "\\", "ReflectionClass", "(", "$", "this", "->", "getEntityClassName", "(", ")", ")", ";", "return", "$", "reflectionClass", "->", "implementsInterface", "(", "$", "interfaceName", ")", ";", "}" ]
Checks if entity class name implements interface @param string $interfaceName @return bool
[ "Checks", "if", "entity", "class", "name", "implements", "interface" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L103-L108
12,661
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getNew
public function getNew(): AbstractEntity { $newEntity = $this->getRepository()->getNew(); $this->prepareEntityForNew($newEntity); return $newEntity; }
php
public function getNew(): AbstractEntity { $newEntity = $this->getRepository()->getNew(); $this->prepareEntityForNew($newEntity); return $newEntity; }
[ "public", "function", "getNew", "(", ")", ":", "AbstractEntity", "{", "$", "newEntity", "=", "$", "this", "->", "getRepository", "(", ")", "->", "getNew", "(", ")", ";", "$", "this", "->", "prepareEntityForNew", "(", "$", "newEntity", ")", ";", "return", "$", "newEntity", ";", "}" ]
Gets a new intance of an entity @return AbstractEntity
[ "Gets", "a", "new", "intance", "of", "an", "entity" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L115-L122
12,662
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.prepareEntityForNew
protected function prepareEntityForNew(AbstractEntity $entity): bool { if ($entity instanceof TimestampableInterface) { $entity->setCreationDate(new DateTime()); $entity->setEditionDate(new DateTime()); } return $this->prepareEntityForGet($entity); }
php
protected function prepareEntityForNew(AbstractEntity $entity): bool { if ($entity instanceof TimestampableInterface) { $entity->setCreationDate(new DateTime()); $entity->setEditionDate(new DateTime()); } return $this->prepareEntityForGet($entity); }
[ "protected", "function", "prepareEntityForNew", "(", "AbstractEntity", "$", "entity", ")", ":", "bool", "{", "if", "(", "$", "entity", "instanceof", "TimestampableInterface", ")", "{", "$", "entity", "->", "setCreationDate", "(", "new", "DateTime", "(", ")", ")", ";", "$", "entity", "->", "setEditionDate", "(", "new", "DateTime", "(", ")", ")", ";", "}", "return", "$", "this", "->", "prepareEntityForGet", "(", "$", "entity", ")", ";", "}" ]
Prepares an entity, setting its default values @param AbstractEntity $entity @return boolean
[ "Prepares", "an", "entity", "setting", "its", "default", "values" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L131-L139
12,663
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.prepareEntityForGet
protected function prepareEntityForGet(AbstractEntity $entity): bool { if ($entity instanceof AbstractDocument) { $this->prepareDocumentForGet($entity); } return true; }
php
protected function prepareEntityForGet(AbstractEntity $entity): bool { if ($entity instanceof AbstractDocument) { $this->prepareDocumentForGet($entity); } return true; }
[ "protected", "function", "prepareEntityForGet", "(", "AbstractEntity", "$", "entity", ")", ":", "bool", "{", "if", "(", "$", "entity", "instanceof", "AbstractDocument", ")", "{", "$", "this", "->", "prepareDocumentForGet", "(", "$", "entity", ")", ";", "}", "return", "true", ";", "}" ]
Prepares an entity when retrieved from database @param AbstractEntity $entity @return boolean
[ "Prepares", "an", "entity", "when", "retrieved", "from", "database" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L148-L154
12,664
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.prepareDocumentForGet
protected function prepareDocumentForGet(AbstractDocument $entity): bool { $document = $entity->getMongoDocument(); if (!$document or empty($document)) { return true; } foreach ($document as $key => $value) { if ($value instanceof BSONDocument) { $value = $value->getArrayCopy(); } if (is_array($value) and array_key_exists('document_serialization', $value)){ $documentEntity = $this->loadDocumentSerializedEntity($value); $entity->__set($key, $documentEntity); } } return true; }
php
protected function prepareDocumentForGet(AbstractDocument $entity): bool { $document = $entity->getMongoDocument(); if (!$document or empty($document)) { return true; } foreach ($document as $key => $value) { if ($value instanceof BSONDocument) { $value = $value->getArrayCopy(); } if (is_array($value) and array_key_exists('document_serialization', $value)){ $documentEntity = $this->loadDocumentSerializedEntity($value); $entity->__set($key, $documentEntity); } } return true; }
[ "protected", "function", "prepareDocumentForGet", "(", "AbstractDocument", "$", "entity", ")", ":", "bool", "{", "$", "document", "=", "$", "entity", "->", "getMongoDocument", "(", ")", ";", "if", "(", "!", "$", "document", "or", "empty", "(", "$", "document", ")", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "document", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "BSONDocument", ")", "{", "$", "value", "=", "$", "value", "->", "getArrayCopy", "(", ")", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "and", "array_key_exists", "(", "'document_serialization'", ",", "$", "value", ")", ")", "{", "$", "documentEntity", "=", "$", "this", "->", "loadDocumentSerializedEntity", "(", "$", "value", ")", ";", "$", "entity", "->", "__set", "(", "$", "key", ",", "$", "documentEntity", ")", ";", "}", "}", "return", "true", ";", "}" ]
Prepares a document from MongoDB to be gotten @param AbstractDocument $entity @return bool
[ "Prepares", "a", "document", "from", "MongoDB", "to", "be", "gotten" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L163-L183
12,665
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.prepareEntityForPersist
protected function prepareEntityForPersist(AbstractEntity $entity): bool { if ($entity instanceof TimestampableInterface) { $entity->setEditionDate(new DateTime()); } return true; }
php
protected function prepareEntityForPersist(AbstractEntity $entity): bool { if ($entity instanceof TimestampableInterface) { $entity->setEditionDate(new DateTime()); } return true; }
[ "protected", "function", "prepareEntityForPersist", "(", "AbstractEntity", "$", "entity", ")", ":", "bool", "{", "if", "(", "$", "entity", "instanceof", "TimestampableInterface", ")", "{", "$", "entity", "->", "setEditionDate", "(", "new", "DateTime", "(", ")", ")", ";", "}", "return", "true", ";", "}" ]
Prepares an entity for persist @param AbstractEntity $entity @return boolean
[ "Prepares", "an", "entity", "for", "persist" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L213-L220
12,666
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.prepareEntitesForGet
protected function prepareEntitesForGet($entities): bool { foreach ($entities as $entity) { if ($this->prepareEntityForGet($entity) === false) { return false; } } return true; }
php
protected function prepareEntitesForGet($entities): bool { foreach ($entities as $entity) { if ($this->prepareEntityForGet($entity) === false) { return false; } } return true; }
[ "protected", "function", "prepareEntitesForGet", "(", "$", "entities", ")", ":", "bool", "{", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "prepareEntityForGet", "(", "$", "entity", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Prepares multiple entities for get @param Collection|array $entities @return boolean
[ "Prepares", "multiple", "entities", "for", "get" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L241-L250
12,667
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getById
public function getById($id): ?AbstractEntity { $entity = $this->getRepository()->findById($id); if ($entity instanceof AbstractEntity) { $this->prepareEntityForGet($entity); } return $entity; }
php
public function getById($id): ?AbstractEntity { $entity = $this->getRepository()->findById($id); if ($entity instanceof AbstractEntity) { $this->prepareEntityForGet($entity); } return $entity; }
[ "public", "function", "getById", "(", "$", "id", ")", ":", "?", "AbstractEntity", "{", "$", "entity", "=", "$", "this", "->", "getRepository", "(", ")", "->", "findById", "(", "$", "id", ")", ";", "if", "(", "$", "entity", "instanceof", "AbstractEntity", ")", "{", "$", "this", "->", "prepareEntityForGet", "(", "$", "entity", ")", ";", "}", "return", "$", "entity", ";", "}" ]
Gets an entity by its ids @param integer $id @return AbstractEntity
[ "Gets", "an", "entity", "by", "its", "ids" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L259-L268
12,668
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getEntitiesBy
public function getEntitiesBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array { $entities = $this->getRepository()->findBy($criteria, $orders, $limit, $offset); $this->prepareEntitesForGet($entities); return $entities; }
php
public function getEntitiesBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array { $entities = $this->getRepository()->findBy($criteria, $orders, $limit, $offset); $this->prepareEntitesForGet($entities); return $entities; }
[ "public", "function", "getEntitiesBy", "(", "array", "$", "criteria", "=", "[", "]", ",", "array", "$", "orders", "=", "[", "]", ",", "$", "limit", "=", "null", ",", "$", "offset", "=", "null", ")", ":", "array", "{", "$", "entities", "=", "$", "this", "->", "getRepository", "(", ")", "->", "findBy", "(", "$", "criteria", ",", "$", "orders", ",", "$", "limit", ",", "$", "offset", ")", ";", "$", "this", "->", "prepareEntitesForGet", "(", "$", "entities", ")", ";", "return", "$", "entities", ";", "}" ]
Gets Entities by criteria ... @param array $criteria @param array $orders @param int $limit @param int $offset @return array
[ "Gets", "Entities", "by", "criteria", "..." ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L280-L286
12,669
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getOneEntityBy
public function getOneEntityBy(array $criteria = [], array $orders = [], $offset = null): ?AbstractEntity { $entity = $this->getRepository()->findOneBy($criteria, $orders, $offset); if ($entity instanceof AbstractEntity) { $this->prepareEntityForGet($entity); } return $entity; }
php
public function getOneEntityBy(array $criteria = [], array $orders = [], $offset = null): ?AbstractEntity { $entity = $this->getRepository()->findOneBy($criteria, $orders, $offset); if ($entity instanceof AbstractEntity) { $this->prepareEntityForGet($entity); } return $entity; }
[ "public", "function", "getOneEntityBy", "(", "array", "$", "criteria", "=", "[", "]", ",", "array", "$", "orders", "=", "[", "]", ",", "$", "offset", "=", "null", ")", ":", "?", "AbstractEntity", "{", "$", "entity", "=", "$", "this", "->", "getRepository", "(", ")", "->", "findOneBy", "(", "$", "criteria", ",", "$", "orders", ",", "$", "offset", ")", ";", "if", "(", "$", "entity", "instanceof", "AbstractEntity", ")", "{", "$", "this", "->", "prepareEntityForGet", "(", "$", "entity", ")", ";", "}", "return", "$", "entity", ";", "}" ]
Gets all entities matching a Criteria @param array $criteria @param array $orders @param int $offset @return AbstractEntity
[ "Gets", "all", "entities", "matching", "a", "Criteria" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L297-L306
12,670
Thuata/FrameworkBundle
Manager/AbstractManager.php
AbstractManager.getAllNotDeleted
public function getAllNotDeleted(): array { if (!$this->entityImplements(SoftDeleteInterface::class)) { throw new \Exception(sprintf('Entities of class "%s" do not implement interface "%s"', $this->getEntityClassName(), SoftDeleteInterface::class)); } return $this->getEntitiesBy(['deleted' => false]); }
php
public function getAllNotDeleted(): array { if (!$this->entityImplements(SoftDeleteInterface::class)) { throw new \Exception(sprintf('Entities of class "%s" do not implement interface "%s"', $this->getEntityClassName(), SoftDeleteInterface::class)); } return $this->getEntitiesBy(['deleted' => false]); }
[ "public", "function", "getAllNotDeleted", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "entityImplements", "(", "SoftDeleteInterface", "::", "class", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Entities of class \"%s\" do not implement interface \"%s\"'", ",", "$", "this", "->", "getEntityClassName", "(", ")", ",", "SoftDeleteInterface", "::", "class", ")", ")", ";", "}", "return", "$", "this", "->", "getEntitiesBy", "(", "[", "'deleted'", "=>", "false", "]", ")", ";", "}" ]
Gets all entities not deleted @return array @throws \Exception
[ "Gets", "all", "entities", "not", "deleted" ]
78c38a5103256d829d7f7574b4e15c9087d0cfd9
https://github.com/Thuata/FrameworkBundle/blob/78c38a5103256d829d7f7574b4e15c9087d0cfd9/Manager/AbstractManager.php#L378-L385
12,671
face-orm/face
lib/Face/Core/FaceLoader/CachableLoader.php
CachableLoader.loadAndCacheFaces
protected function loadAndCacheFaces(){ $faces = $this->_loadFaces(); foreach($faces as $face){ $this->cacheFace($face); $this->addFace($face); } }
php
protected function loadAndCacheFaces(){ $faces = $this->_loadFaces(); foreach($faces as $face){ $this->cacheFace($face); $this->addFace($face); } }
[ "protected", "function", "loadAndCacheFaces", "(", ")", "{", "$", "faces", "=", "$", "this", "->", "_loadFaces", "(", ")", ";", "foreach", "(", "$", "faces", "as", "$", "face", ")", "{", "$", "this", "->", "cacheFace", "(", "$", "face", ")", ";", "$", "this", "->", "addFace", "(", "$", "face", ")", ";", "}", "}" ]
Load all faces and cache them
[ "Load", "all", "faces", "and", "cache", "them" ]
85b412c66ff41d0fe73b7e7b69bc9a5ac5f7f428
https://github.com/face-orm/face/blob/85b412c66ff41d0fe73b7e7b69bc9a5ac5f7f428/lib/Face/Core/FaceLoader/CachableLoader.php#L88-L95
12,672
face-orm/face
lib/Face/Core/FaceLoader/CachableLoader.php
CachableLoader.cacheFace
protected function cacheFace(EntityFace $face){ // todo : improve $serialized = serialize($face); $this->getCache()->set("name_".$face->getName(),$serialized); $this->getCache()->set("class_".$face->getClass(),$serialized); }
php
protected function cacheFace(EntityFace $face){ // todo : improve $serialized = serialize($face); $this->getCache()->set("name_".$face->getName(),$serialized); $this->getCache()->set("class_".$face->getClass(),$serialized); }
[ "protected", "function", "cacheFace", "(", "EntityFace", "$", "face", ")", "{", "// todo : improve", "$", "serialized", "=", "serialize", "(", "$", "face", ")", ";", "$", "this", "->", "getCache", "(", ")", "->", "set", "(", "\"name_\"", ".", "$", "face", "->", "getName", "(", ")", ",", "$", "serialized", ")", ";", "$", "this", "->", "getCache", "(", ")", "->", "set", "(", "\"class_\"", ".", "$", "face", "->", "getClass", "(", ")", ",", "$", "serialized", ")", ";", "}" ]
register a face in the cache @param EntityFace $faces
[ "register", "a", "face", "in", "the", "cache" ]
85b412c66ff41d0fe73b7e7b69bc9a5ac5f7f428
https://github.com/face-orm/face/blob/85b412c66ff41d0fe73b7e7b69bc9a5ac5f7f428/lib/Face/Core/FaceLoader/CachableLoader.php#L101-L106
12,673
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.eagerLoadRelations
protected function eagerLoadRelations() { $query = $this->model; if (is_array($this->eagerLoadRelations)) { $eagerLoads = []; foreach ($this->eagerLoadRelations as $relation => $rules) { // case for relations[]=relation_name // with relation that is numeric $relation = (is_integer($relation)) ? $rules : $relation; // case for relations[relation_name][attributes][]=attrib_name // with relation that is a relation name if (is_array($rules) && array_key_exists('attributes', $rules)) { $eagerLoads[$relation] = function ($q) use ($rules) { // If query is instance of HasOneOrMany, // make sure to select the parent key name as foreign key. if ( $q instanceof HasOneOrMany && !in_array($fk = $q->getParent()->getForeignKey(), $rules['attributes']) ) { array_push($rules['attributes'], $fk); } $q->select($rules['attributes']); }; } else { array_push($eagerLoads, $relation); } } return $query->with($eagerLoads); } return $query->with($this->eagerLoadRelations); }
php
protected function eagerLoadRelations() { $query = $this->model; if (is_array($this->eagerLoadRelations)) { $eagerLoads = []; foreach ($this->eagerLoadRelations as $relation => $rules) { // case for relations[]=relation_name // with relation that is numeric $relation = (is_integer($relation)) ? $rules : $relation; // case for relations[relation_name][attributes][]=attrib_name // with relation that is a relation name if (is_array($rules) && array_key_exists('attributes', $rules)) { $eagerLoads[$relation] = function ($q) use ($rules) { // If query is instance of HasOneOrMany, // make sure to select the parent key name as foreign key. if ( $q instanceof HasOneOrMany && !in_array($fk = $q->getParent()->getForeignKey(), $rules['attributes']) ) { array_push($rules['attributes'], $fk); } $q->select($rules['attributes']); }; } else { array_push($eagerLoads, $relation); } } return $query->with($eagerLoads); } return $query->with($this->eagerLoadRelations); }
[ "protected", "function", "eagerLoadRelations", "(", ")", "{", "$", "query", "=", "$", "this", "->", "model", ";", "if", "(", "is_array", "(", "$", "this", "->", "eagerLoadRelations", ")", ")", "{", "$", "eagerLoads", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "eagerLoadRelations", "as", "$", "relation", "=>", "$", "rules", ")", "{", "// case for relations[]=relation_name", "// with relation that is numeric", "$", "relation", "=", "(", "is_integer", "(", "$", "relation", ")", ")", "?", "$", "rules", ":", "$", "relation", ";", "// case for relations[relation_name][attributes][]=attrib_name", "// with relation that is a relation name", "if", "(", "is_array", "(", "$", "rules", ")", "&&", "array_key_exists", "(", "'attributes'", ",", "$", "rules", ")", ")", "{", "$", "eagerLoads", "[", "$", "relation", "]", "=", "function", "(", "$", "q", ")", "use", "(", "$", "rules", ")", "{", "// If query is instance of HasOneOrMany,", "// make sure to select the parent key name as foreign key.", "if", "(", "$", "q", "instanceof", "HasOneOrMany", "&&", "!", "in_array", "(", "$", "fk", "=", "$", "q", "->", "getParent", "(", ")", "->", "getForeignKey", "(", ")", ",", "$", "rules", "[", "'attributes'", "]", ")", ")", "{", "array_push", "(", "$", "rules", "[", "'attributes'", "]", ",", "$", "fk", ")", ";", "}", "$", "q", "->", "select", "(", "$", "rules", "[", "'attributes'", "]", ")", ";", "}", ";", "}", "else", "{", "array_push", "(", "$", "eagerLoads", ",", "$", "relation", ")", ";", "}", "}", "return", "$", "query", "->", "with", "(", "$", "eagerLoads", ")", ";", "}", "return", "$", "query", "->", "with", "(", "$", "this", "->", "eagerLoadRelations", ")", ";", "}" ]
Eagerload relations. @return \Illuminate\Database\Eloquent\Builder|\Eloquent
[ "Eagerload", "relations", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L108-L144
12,674
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.first
public function first(array $attributes = null) { $query = $this->eagerLoadRelations(); if (!is_null($attributes)) { $query = $query->where($attributes); } return $query->first(); }
php
public function first(array $attributes = null) { $query = $this->eagerLoadRelations(); if (!is_null($attributes)) { $query = $query->where($attributes); } return $query->first(); }
[ "public", "function", "first", "(", "array", "$", "attributes", "=", "null", ")", "{", "$", "query", "=", "$", "this", "->", "eagerLoadRelations", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "attributes", ")", ")", "{", "$", "query", "=", "$", "query", "->", "where", "(", "$", "attributes", ")", ";", "}", "return", "$", "query", "->", "first", "(", ")", ";", "}" ]
Get the first model or the first model for the given attributes. @param array $attributes @return \Illuminate\Database\Eloquent\Model|null
[ "Get", "the", "first", "model", "or", "the", "first", "model", "for", "the", "given", "attributes", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L223-L232
12,675
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.create
public function create(array $attributes) { /* * Check if is single associate array item. */ if (array_is_assoc(head($attributes))) { throw new InvalidArgumentException('Trying to pass multiple items in create() method. Please use createMany() instead.'); } // Unset primary key when $updateWhenIdExists is true, to make sure to create new record in database. if (array_is_assoc($attributes) && $this->updateWhenIdExists && array_key_exists($pk = $this->model->getKeyName(), $attributes)) { unset($attributes[$pk]); } $this->validation()->validate('create', $attributes); $model = $this->model->newInstance($attributes); $this->beforeSaveModel($model); $model->save(); return $model; }
php
public function create(array $attributes) { /* * Check if is single associate array item. */ if (array_is_assoc(head($attributes))) { throw new InvalidArgumentException('Trying to pass multiple items in create() method. Please use createMany() instead.'); } // Unset primary key when $updateWhenIdExists is true, to make sure to create new record in database. if (array_is_assoc($attributes) && $this->updateWhenIdExists && array_key_exists($pk = $this->model->getKeyName(), $attributes)) { unset($attributes[$pk]); } $this->validation()->validate('create', $attributes); $model = $this->model->newInstance($attributes); $this->beforeSaveModel($model); $model->save(); return $model; }
[ "public", "function", "create", "(", "array", "$", "attributes", ")", "{", "/*\n * Check if is single associate array item.\n */", "if", "(", "array_is_assoc", "(", "head", "(", "$", "attributes", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Trying to pass multiple items in create() method. Please use createMany() instead.'", ")", ";", "}", "// Unset primary key when $updateWhenIdExists is true, to make sure to create new record in database.", "if", "(", "array_is_assoc", "(", "$", "attributes", ")", "&&", "$", "this", "->", "updateWhenIdExists", "&&", "array_key_exists", "(", "$", "pk", "=", "$", "this", "->", "model", "->", "getKeyName", "(", ")", ",", "$", "attributes", ")", ")", "{", "unset", "(", "$", "attributes", "[", "$", "pk", "]", ")", ";", "}", "$", "this", "->", "validation", "(", ")", "->", "validate", "(", "'create'", ",", "$", "attributes", ")", ";", "$", "model", "=", "$", "this", "->", "model", "->", "newInstance", "(", "$", "attributes", ")", ";", "$", "this", "->", "beforeSaveModel", "(", "$", "model", ")", ";", "$", "model", "->", "save", "(", ")", ";", "return", "$", "model", ";", "}" ]
Create and store a new model. @param array $attributes @return \Illuminate\Database\Eloquent\Model
[ "Create", "and", "store", "a", "new", "model", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L272-L295
12,676
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.createMany
public function createMany(array $items) { $models = collection(); foreach ($items as $item) { $models[] = $this->create($item); } return $models; }
php
public function createMany(array $items) { $models = collection(); foreach ($items as $item) { $models[] = $this->create($item); } return $models; }
[ "public", "function", "createMany", "(", "array", "$", "items", ")", "{", "$", "models", "=", "collection", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "models", "[", "]", "=", "$", "this", "->", "create", "(", "$", "item", ")", ";", "}", "return", "$", "models", ";", "}" ]
Create and store multiple new models. @param array $items @return \Illuminate\Database\Eloquent\Collection
[ "Create", "and", "store", "multiple", "new", "models", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L303-L312
12,677
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.update
public function update($id, array $attributes) { $model = $this->model->findOrFail($id); $this->validation()->validate('update', array_merge($attributes, [$this->model->getKeyName() => $id])); $model->fill($attributes); $model->save(); return $model; }
php
public function update($id, array $attributes) { $model = $this->model->findOrFail($id); $this->validation()->validate('update', array_merge($attributes, [$this->model->getKeyName() => $id])); $model->fill($attributes); $model->save(); return $model; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "attributes", ")", "{", "$", "model", "=", "$", "this", "->", "model", "->", "findOrFail", "(", "$", "id", ")", ";", "$", "this", "->", "validation", "(", ")", "->", "validate", "(", "'update'", ",", "array_merge", "(", "$", "attributes", ",", "[", "$", "this", "->", "model", "->", "getKeyName", "(", ")", "=>", "$", "id", "]", ")", ")", ";", "$", "model", "->", "fill", "(", "$", "attributes", ")", ";", "$", "model", "->", "save", "(", ")", ";", "return", "$", "model", ";", "}" ]
Update the model or models attributes. @param int|null $id @param array $attributes @throws \Exception When id is not given @throws \Illuminate\Database\Eloquent\ModelNotFoundException @return \Illuminate\Database\Eloquent\Model
[ "Update", "the", "model", "or", "models", "attributes", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L321-L332
12,678
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.updateMany
public function updateMany(array $items) { $ids = array_pluck($items, $this->model->getKeyName()); $models = $this->model->find($ids); foreach ($models as $model) { $attributes = array_first($items, function ($i, $attributes) use ($model) { if (!array_key_exists($model->getKeyName(), $attributes)) { return false; } return $attributes[$model->getKeyName()] == $model->getKey(); }); $this->validation()->validate('update', array_merge($attributes, [$model->getKeyName() => $model->getKey()])); $model->fill($attributes); $model->save(); } return $models; }
php
public function updateMany(array $items) { $ids = array_pluck($items, $this->model->getKeyName()); $models = $this->model->find($ids); foreach ($models as $model) { $attributes = array_first($items, function ($i, $attributes) use ($model) { if (!array_key_exists($model->getKeyName(), $attributes)) { return false; } return $attributes[$model->getKeyName()] == $model->getKey(); }); $this->validation()->validate('update', array_merge($attributes, [$model->getKeyName() => $model->getKey()])); $model->fill($attributes); $model->save(); } return $models; }
[ "public", "function", "updateMany", "(", "array", "$", "items", ")", "{", "$", "ids", "=", "array_pluck", "(", "$", "items", ",", "$", "this", "->", "model", "->", "getKeyName", "(", ")", ")", ";", "$", "models", "=", "$", "this", "->", "model", "->", "find", "(", "$", "ids", ")", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "attributes", "=", "array_first", "(", "$", "items", ",", "function", "(", "$", "i", ",", "$", "attributes", ")", "use", "(", "$", "model", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "model", "->", "getKeyName", "(", ")", ",", "$", "attributes", ")", ")", "{", "return", "false", ";", "}", "return", "$", "attributes", "[", "$", "model", "->", "getKeyName", "(", ")", "]", "==", "$", "model", "->", "getKey", "(", ")", ";", "}", ")", ";", "$", "this", "->", "validation", "(", ")", "->", "validate", "(", "'update'", ",", "array_merge", "(", "$", "attributes", ",", "[", "$", "model", "->", "getKeyName", "(", ")", "=>", "$", "model", "->", "getKey", "(", ")", "]", ")", ")", ";", "$", "model", "->", "fill", "(", "$", "attributes", ")", ";", "$", "model", "->", "save", "(", ")", ";", "}", "return", "$", "models", ";", "}" ]
Update multiple models attributes in the storage. @param array $items @return \Illuminate\Database\Eloquent\Collection
[ "Update", "multiple", "models", "attributes", "in", "the", "storage", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L340-L361
12,679
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.save
public function save($model) { if ($model instanceof Collection || is_array($model)) { throw new InvalidArgumentException('Parameter $model must be an instance of \Illuminate\Database\Eloquent\Model'); } $this->validation()->validate('save', $model->getAttributes()); $this->beforeSaveModel($model); return $model->save(); }
php
public function save($model) { if ($model instanceof Collection || is_array($model)) { throw new InvalidArgumentException('Parameter $model must be an instance of \Illuminate\Database\Eloquent\Model'); } $this->validation()->validate('save', $model->getAttributes()); $this->beforeSaveModel($model); return $model->save(); }
[ "public", "function", "save", "(", "$", "model", ")", "{", "if", "(", "$", "model", "instanceof", "Collection", "||", "is_array", "(", "$", "model", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Parameter $model must be an instance of \\Illuminate\\Database\\Eloquent\\Model'", ")", ";", "}", "$", "this", "->", "validation", "(", ")", "->", "validate", "(", "'save'", ",", "$", "model", "->", "getAttributes", "(", ")", ")", ";", "$", "this", "->", "beforeSaveModel", "(", "$", "model", ")", ";", "return", "$", "model", "->", "save", "(", ")", ";", "}" ]
Save the model. @param \Illuminate\Database\Eloquent\Model $model @return bool
[ "Save", "the", "model", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L369-L380
12,680
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.saveMany
public function saveMany($models) { // Convert to collection if array $models = is_array($models) ? collection($models) : $models; foreach ($models as &$model) { $model = $this->save($model); } return $models; }
php
public function saveMany($models) { // Convert to collection if array $models = is_array($models) ? collection($models) : $models; foreach ($models as &$model) { $model = $this->save($model); } return $models; }
[ "public", "function", "saveMany", "(", "$", "models", ")", "{", "// Convert to collection if array", "$", "models", "=", "is_array", "(", "$", "models", ")", "?", "collection", "(", "$", "models", ")", ":", "$", "models", ";", "foreach", "(", "$", "models", "as", "&", "$", "model", ")", "{", "$", "model", "=", "$", "this", "->", "save", "(", "$", "model", ")", ";", "}", "return", "$", "models", ";", "}" ]
Save multiple models. @param array|\Illuminate\Database\Eloquent\Collection $models @return \Illuminate\Database\Eloquent\Collection
[ "Save", "multiple", "models", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L388-L398
12,681
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.has
public function has($relation, $operator = '>=', $count = 1) { $this->hasRelations[$relation] = [$operator, $count]; return $this; }
php
public function has($relation, $operator = '>=', $count = 1) { $this->hasRelations[$relation] = [$operator, $count]; return $this; }
[ "public", "function", "has", "(", "$", "relation", ",", "$", "operator", "=", "'>='", ",", "$", "count", "=", "1", ")", "{", "$", "this", "->", "hasRelations", "[", "$", "relation", "]", "=", "[", "$", "operator", ",", "$", "count", "]", ";", "return", "$", "this", ";", "}" ]
Query model if it has a given relation. @param string $relation @param string $operator @param int $count @return $this
[ "Query", "model", "if", "it", "has", "a", "given", "relation", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L457-L462
12,682
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.queryHasRelations
protected function queryHasRelations($query, $hasRelations = []) { $hasRelations = $hasRelations ?: $this->hasRelations; foreach ($hasRelations as $relation => $operatorCount) { list($operator, $count) = $operatorCount; $query->has($relation, $operator, $count); } return $query; }
php
protected function queryHasRelations($query, $hasRelations = []) { $hasRelations = $hasRelations ?: $this->hasRelations; foreach ($hasRelations as $relation => $operatorCount) { list($operator, $count) = $operatorCount; $query->has($relation, $operator, $count); } return $query; }
[ "protected", "function", "queryHasRelations", "(", "$", "query", ",", "$", "hasRelations", "=", "[", "]", ")", "{", "$", "hasRelations", "=", "$", "hasRelations", "?", ":", "$", "this", "->", "hasRelations", ";", "foreach", "(", "$", "hasRelations", "as", "$", "relation", "=>", "$", "operatorCount", ")", "{", "list", "(", "$", "operator", ",", "$", "count", ")", "=", "$", "operatorCount", ";", "$", "query", "->", "has", "(", "$", "relation", ",", "$", "operator", ",", "$", "count", ")", ";", "}", "return", "$", "query", ";", "}" ]
Query has relations. @param \Illuminate\Database\Eloquent\Builder $query @param array $hasRelations @return \Illuminate\Database\Eloquent\Builder
[ "Query", "has", "relations", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L471-L481
12,683
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.queryFilters
protected function queryFilters($query, $filters = []) { $filters = $filters ?: $this->filters; foreach ($filters as $key => $filter) { foreach ($filter as $operator => $values) { $values = is_array($values) ? $values : [$values]; $operator = is_numeric($operator) ? '=' : $operator; if ($operator == '=') { $query->whereIn($key, $values); } elseif ($operator == '!=') { $query->whereNotIn($key, $values); } elseif ($operator == 'null') { $query->whereNull($key); } elseif ($operator == 'not_null') { $query->whereNotNull($key); } else { $query->where($key, $operator, head($values)); } } } return $query; }
php
protected function queryFilters($query, $filters = []) { $filters = $filters ?: $this->filters; foreach ($filters as $key => $filter) { foreach ($filter as $operator => $values) { $values = is_array($values) ? $values : [$values]; $operator = is_numeric($operator) ? '=' : $operator; if ($operator == '=') { $query->whereIn($key, $values); } elseif ($operator == '!=') { $query->whereNotIn($key, $values); } elseif ($operator == 'null') { $query->whereNull($key); } elseif ($operator == 'not_null') { $query->whereNotNull($key); } else { $query->where($key, $operator, head($values)); } } } return $query; }
[ "protected", "function", "queryFilters", "(", "$", "query", ",", "$", "filters", "=", "[", "]", ")", "{", "$", "filters", "=", "$", "filters", "?", ":", "$", "this", "->", "filters", ";", "foreach", "(", "$", "filters", "as", "$", "key", "=>", "$", "filter", ")", "{", "foreach", "(", "$", "filter", "as", "$", "operator", "=>", "$", "values", ")", "{", "$", "values", "=", "is_array", "(", "$", "values", ")", "?", "$", "values", ":", "[", "$", "values", "]", ";", "$", "operator", "=", "is_numeric", "(", "$", "operator", ")", "?", "'='", ":", "$", "operator", ";", "if", "(", "$", "operator", "==", "'='", ")", "{", "$", "query", "->", "whereIn", "(", "$", "key", ",", "$", "values", ")", ";", "}", "elseif", "(", "$", "operator", "==", "'!='", ")", "{", "$", "query", "->", "whereNotIn", "(", "$", "key", ",", "$", "values", ")", ";", "}", "elseif", "(", "$", "operator", "==", "'null'", ")", "{", "$", "query", "->", "whereNull", "(", "$", "key", ")", ";", "}", "elseif", "(", "$", "operator", "==", "'not_null'", ")", "{", "$", "query", "->", "whereNotNull", "(", "$", "key", ")", ";", "}", "else", "{", "$", "query", "->", "where", "(", "$", "key", ",", "$", "operator", ",", "head", "(", "$", "values", ")", ")", ";", "}", "}", "}", "return", "$", "query", ";", "}" ]
Query filters. @param \Illuminate\Database\Eloquent\Builder $query @return \Illuminate\Database\Eloquent\Builder
[ "Query", "filters", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L489-L514
12,684
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.querySort
protected function querySort($query, $sort = []) { $sort = $sort ?: $this->sort; foreach ($sort as $attribute => $order) { $query->orderBy($attribute, $order); } return $query; }
php
protected function querySort($query, $sort = []) { $sort = $sort ?: $this->sort; foreach ($sort as $attribute => $order) { $query->orderBy($attribute, $order); } return $query; }
[ "protected", "function", "querySort", "(", "$", "query", ",", "$", "sort", "=", "[", "]", ")", "{", "$", "sort", "=", "$", "sort", "?", ":", "$", "this", "->", "sort", ";", "foreach", "(", "$", "sort", "as", "$", "attribute", "=>", "$", "order", ")", "{", "$", "query", "->", "orderBy", "(", "$", "attribute", ",", "$", "order", ")", ";", "}", "return", "$", "query", ";", "}" ]
Query sort. @param \Illuminate\Database\Eloquent\Builder $query @param array $sort @return \Illuminate\Database\Eloquent\Builder
[ "Query", "sort", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L523-L532
12,685
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.queryLimitOffset
protected function queryLimitOffset($query, $limit = null, $offset = 0) { $limit = $limit ?: $this->limit; $offset = $offset ?: $this->offset; if ($limit) { $query->take($limit)->skip($offset); } return $query; }
php
protected function queryLimitOffset($query, $limit = null, $offset = 0) { $limit = $limit ?: $this->limit; $offset = $offset ?: $this->offset; if ($limit) { $query->take($limit)->skip($offset); } return $query; }
[ "protected", "function", "queryLimitOffset", "(", "$", "query", ",", "$", "limit", "=", "null", ",", "$", "offset", "=", "0", ")", "{", "$", "limit", "=", "$", "limit", "?", ":", "$", "this", "->", "limit", ";", "$", "offset", "=", "$", "offset", "?", ":", "$", "this", "->", "offset", ";", "if", "(", "$", "limit", ")", "{", "$", "query", "->", "take", "(", "$", "limit", ")", "->", "skip", "(", "$", "offset", ")", ";", "}", "return", "$", "query", ";", "}" ]
Query limit and offset. @param \Illuminate\Database\Eloquent\Builder $query @param int|null $limit @param int $offset @return \Illuminate\Database\Eloquent\Builder
[ "Query", "limit", "and", "offset", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L542-L552
12,686
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.paginate
public function paginate($perPage = 15, $page = null, $attributes = ['*']) { $pagelo = new PageLimitOffset($perPage, $page); return $this->limit($pagelo->limit()) ->offset($pagelo->offset()) ->get($attributes); }
php
public function paginate($perPage = 15, $page = null, $attributes = ['*']) { $pagelo = new PageLimitOffset($perPage, $page); return $this->limit($pagelo->limit()) ->offset($pagelo->offset()) ->get($attributes); }
[ "public", "function", "paginate", "(", "$", "perPage", "=", "15", ",", "$", "page", "=", "null", ",", "$", "attributes", "=", "[", "'*'", "]", ")", "{", "$", "pagelo", "=", "new", "PageLimitOffset", "(", "$", "perPage", ",", "$", "page", ")", ";", "return", "$", "this", "->", "limit", "(", "$", "pagelo", "->", "limit", "(", ")", ")", "->", "offset", "(", "$", "pagelo", "->", "offset", "(", ")", ")", "->", "get", "(", "$", "attributes", ")", ";", "}" ]
Return a collection of models by paginated approach. @param int $perPage @param int|null $page @param array $attributes @return \Illuminate\Database\Eloquent\Collection
[ "Return", "a", "collection", "of", "models", "by", "paginated", "approach", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L562-L569
12,687
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.prepareQuery
protected function prepareQuery() { // relations $query = $this->eagerLoadRelations(); // has relations $this->queryHasRelations($query); // filters $this->queryFilters($query); // sort $this->querySort($query); // limit and offset $this->queryLimitOffset($query); return $query; }
php
protected function prepareQuery() { // relations $query = $this->eagerLoadRelations(); // has relations $this->queryHasRelations($query); // filters $this->queryFilters($query); // sort $this->querySort($query); // limit and offset $this->queryLimitOffset($query); return $query; }
[ "protected", "function", "prepareQuery", "(", ")", "{", "// relations", "$", "query", "=", "$", "this", "->", "eagerLoadRelations", "(", ")", ";", "// has relations", "$", "this", "->", "queryHasRelations", "(", "$", "query", ")", ";", "// filters", "$", "this", "->", "queryFilters", "(", "$", "query", ")", ";", "// sort", "$", "this", "->", "querySort", "(", "$", "query", ")", ";", "// limit and offset", "$", "this", "->", "queryLimitOffset", "(", "$", "query", ")", ";", "return", "$", "query", ";", "}" ]
Prepare query to fetch models. @return \Illuminate\Database\Eloquent\Builder
[ "Prepare", "query", "to", "fetch", "models", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L673-L691
12,688
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.selectAttributes
protected function selectAttributes($attributes = ['*']) { $attributes = $attributes ?: ['*']; if ($attributes == ['*'] && $this->attributes != ['*']) { $attributes = $this->attributes; } return $attributes; }
php
protected function selectAttributes($attributes = ['*']) { $attributes = $attributes ?: ['*']; if ($attributes == ['*'] && $this->attributes != ['*']) { $attributes = $this->attributes; } return $attributes; }
[ "protected", "function", "selectAttributes", "(", "$", "attributes", "=", "[", "'*'", "]", ")", "{", "$", "attributes", "=", "$", "attributes", "?", ":", "[", "'*'", "]", ";", "if", "(", "$", "attributes", "==", "[", "'*'", "]", "&&", "$", "this", "->", "attributes", "!=", "[", "'*'", "]", ")", "{", "$", "attributes", "=", "$", "this", "->", "attributes", ";", "}", "return", "$", "attributes", ";", "}" ]
Return the final attributes to be selected. @param array $attributes @return array
[ "Return", "the", "final", "attributes", "to", "be", "selected", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L699-L708
12,689
sedp-mis/base-repository
src/BaseRepositoryEloquent.php
BaseRepositoryEloquent.search
public function search($input, $compareAttributes = ['*'], $attributes = ['*']) { $query = $this->query(); $compareAttributes = $compareAttributes ?: ['*']; if ($compareAttributes == ['*']) { $compareAttributes = Schema::getColumnListing($this->model->getTable()); } foreach ($compareAttributes as $column) { $query->orWhere($column, 'like', '%'.join('%', str_split($input)).'%'); } return $query->get($this->selectAttributes($attributes)); }
php
public function search($input, $compareAttributes = ['*'], $attributes = ['*']) { $query = $this->query(); $compareAttributes = $compareAttributes ?: ['*']; if ($compareAttributes == ['*']) { $compareAttributes = Schema::getColumnListing($this->model->getTable()); } foreach ($compareAttributes as $column) { $query->orWhere($column, 'like', '%'.join('%', str_split($input)).'%'); } return $query->get($this->selectAttributes($attributes)); }
[ "public", "function", "search", "(", "$", "input", ",", "$", "compareAttributes", "=", "[", "'*'", "]", ",", "$", "attributes", "=", "[", "'*'", "]", ")", "{", "$", "query", "=", "$", "this", "->", "query", "(", ")", ";", "$", "compareAttributes", "=", "$", "compareAttributes", "?", ":", "[", "'*'", "]", ";", "if", "(", "$", "compareAttributes", "==", "[", "'*'", "]", ")", "{", "$", "compareAttributes", "=", "Schema", "::", "getColumnListing", "(", "$", "this", "->", "model", "->", "getTable", "(", ")", ")", ";", "}", "foreach", "(", "$", "compareAttributes", "as", "$", "column", ")", "{", "$", "query", "->", "orWhere", "(", "$", "column", ",", "'like'", ",", "'%'", ".", "join", "(", "'%'", ",", "str_split", "(", "$", "input", ")", ")", ".", "'%'", ")", ";", "}", "return", "$", "query", "->", "get", "(", "$", "this", "->", "selectAttributes", "(", "$", "attributes", ")", ")", ";", "}" ]
Search any input against the given attributes. @param string $input @param array $compareAttributes @param array $attributes @return \Illuminate\Database\Eloquent\Collection
[ "Search", "any", "input", "against", "the", "given", "attributes", "." ]
a55ac631bad78c6318f7efaa6a82dc1fbc3cc444
https://github.com/sedp-mis/base-repository/blob/a55ac631bad78c6318f7efaa6a82dc1fbc3cc444/src/BaseRepositoryEloquent.php#L729-L744
12,690
laravel-commode/common
src/LaravelCommode/Common/Registry/ResolverAccess.php
ResolverAccess.onSet
protected function onSet(&$offset, $value) { if (is_string($value)) { $value = app()->make($value); } return $value; }
php
protected function onSet(&$offset, $value) { if (is_string($value)) { $value = app()->make($value); } return $value; }
[ "protected", "function", "onSet", "(", "&", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "app", "(", ")", "->", "make", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Resolves value that's being set @param string $offset offset key @param mixed $value offset value @return mixed
[ "Resolves", "value", "that", "s", "being", "set" ]
5c9289c3ce5bbd934281c4ac7537657d32c5a9ec
https://github.com/laravel-commode/common/blob/5c9289c3ce5bbd934281c4ac7537657d32c5a9ec/src/LaravelCommode/Common/Registry/ResolverAccess.php#L24-L31
12,691
elnebuloso/flex-commons
src/elnebuloso-flex/Uuid.php
Uuid.get
public static function get() { mt_srand((int) (microtime(true) * 1000)); $b = md5(uniqid(mt_rand(), true), true); $b[6] = chr((ord($b[6]) & 0x0F) | 0x40); $b[8] = chr((ord($b[8]) & 0x3F) | 0x80); return implode('-', unpack('H8a/H4b/H4c/H4d/H12e', $b)); }
php
public static function get() { mt_srand((int) (microtime(true) * 1000)); $b = md5(uniqid(mt_rand(), true), true); $b[6] = chr((ord($b[6]) & 0x0F) | 0x40); $b[8] = chr((ord($b[8]) & 0x3F) | 0x80); return implode('-', unpack('H8a/H4b/H4c/H4d/H12e', $b)); }
[ "public", "static", "function", "get", "(", ")", "{", "mt_srand", "(", "(", "int", ")", "(", "microtime", "(", "true", ")", "*", "1000", ")", ")", ";", "$", "b", "=", "md5", "(", "uniqid", "(", "mt_rand", "(", ")", ",", "true", ")", ",", "true", ")", ";", "$", "b", "[", "6", "]", "=", "chr", "(", "(", "ord", "(", "$", "b", "[", "6", "]", ")", "&", "0x0F", ")", "|", "0x40", ")", ";", "$", "b", "[", "8", "]", "=", "chr", "(", "(", "ord", "(", "$", "b", "[", "8", "]", ")", "&", "0x3F", ")", "|", "0x80", ")", ";", "return", "implode", "(", "'-'", ",", "unpack", "(", "'H8a/H4b/H4c/H4d/H12e'", ",", "$", "b", ")", ")", ";", "}" ]
erstellt eine 36 stellige uuid nach dce standard @return string
[ "erstellt", "eine", "36", "stellige", "uuid", "nach", "dce", "standard" ]
4ededc9ea13e7e1d0da53df8f1aac297ef51b771
https://github.com/elnebuloso/flex-commons/blob/4ededc9ea13e7e1d0da53df8f1aac297ef51b771/src/elnebuloso-flex/Uuid.php#L28-L37
12,692
themichaelhall/bluemvc-forms
src/Base/AbstractTextElement.php
AbstractTextElement.onFormatText
protected function onFormatText(string &$text): void { $lines = preg_split("/\r\n|\n|\r/", $text); $result = []; $lastEmptyLinesCount = 0; $hasFoundNonEmptyLines = false; foreach ($lines as $line) { if (($this->textFormatOptions & TextFormatOptions::TRIM) !== 0) { $line = trim($line); } if (($this->textFormatOptions & TextFormatOptions::COMPACT) !== 0) { $line = preg_replace('/\s+/', ' ', $line); } if ($line === '') { if (($this->textFormatOptions & TextFormatOptions::COMPACT_LINES) !== 0 && $lastEmptyLinesCount > 0) { continue; } if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && !$hasFoundNonEmptyLines) { continue; } $lastEmptyLinesCount++; } else { $lastEmptyLinesCount = 0; $hasFoundNonEmptyLines = true; } $result[] = $line; } if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && $lastEmptyLinesCount > 0) { // Trim the last empty lines (we did not know until now that those were at the end). array_splice($result, -$lastEmptyLinesCount); } $text = implode("\r\n", $result); }
php
protected function onFormatText(string &$text): void { $lines = preg_split("/\r\n|\n|\r/", $text); $result = []; $lastEmptyLinesCount = 0; $hasFoundNonEmptyLines = false; foreach ($lines as $line) { if (($this->textFormatOptions & TextFormatOptions::TRIM) !== 0) { $line = trim($line); } if (($this->textFormatOptions & TextFormatOptions::COMPACT) !== 0) { $line = preg_replace('/\s+/', ' ', $line); } if ($line === '') { if (($this->textFormatOptions & TextFormatOptions::COMPACT_LINES) !== 0 && $lastEmptyLinesCount > 0) { continue; } if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && !$hasFoundNonEmptyLines) { continue; } $lastEmptyLinesCount++; } else { $lastEmptyLinesCount = 0; $hasFoundNonEmptyLines = true; } $result[] = $line; } if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && $lastEmptyLinesCount > 0) { // Trim the last empty lines (we did not know until now that those were at the end). array_splice($result, -$lastEmptyLinesCount); } $text = implode("\r\n", $result); }
[ "protected", "function", "onFormatText", "(", "string", "&", "$", "text", ")", ":", "void", "{", "$", "lines", "=", "preg_split", "(", "\"/\\r\\n|\\n|\\r/\"", ",", "$", "text", ")", ";", "$", "result", "=", "[", "]", ";", "$", "lastEmptyLinesCount", "=", "0", ";", "$", "hasFoundNonEmptyLines", "=", "false", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "(", "$", "this", "->", "textFormatOptions", "&", "TextFormatOptions", "::", "TRIM", ")", "!==", "0", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "}", "if", "(", "(", "$", "this", "->", "textFormatOptions", "&", "TextFormatOptions", "::", "COMPACT", ")", "!==", "0", ")", "{", "$", "line", "=", "preg_replace", "(", "'/\\s+/'", ",", "' '", ",", "$", "line", ")", ";", "}", "if", "(", "$", "line", "===", "''", ")", "{", "if", "(", "(", "$", "this", "->", "textFormatOptions", "&", "TextFormatOptions", "::", "COMPACT_LINES", ")", "!==", "0", "&&", "$", "lastEmptyLinesCount", ">", "0", ")", "{", "continue", ";", "}", "if", "(", "(", "$", "this", "->", "textFormatOptions", "&", "TextFormatOptions", "::", "TRIM_LINES", ")", "!==", "0", "&&", "!", "$", "hasFoundNonEmptyLines", ")", "{", "continue", ";", "}", "$", "lastEmptyLinesCount", "++", ";", "}", "else", "{", "$", "lastEmptyLinesCount", "=", "0", ";", "$", "hasFoundNonEmptyLines", "=", "true", ";", "}", "$", "result", "[", "]", "=", "$", "line", ";", "}", "if", "(", "(", "$", "this", "->", "textFormatOptions", "&", "TextFormatOptions", "::", "TRIM_LINES", ")", "!==", "0", "&&", "$", "lastEmptyLinesCount", ">", "0", ")", "{", "// Trim the last empty lines (we did not know until now that those were at the end).", "array_splice", "(", "$", "result", ",", "-", "$", "lastEmptyLinesCount", ")", ";", "}", "$", "text", "=", "implode", "(", "\"\\r\\n\"", ",", "$", "result", ")", ";", "}" ]
Called when text should be formatted. @since 1.0.0 @param string $text The text.
[ "Called", "when", "text", "should", "be", "formatted", "." ]
8f0e29aaf71eba70b50697384b22edaf72f2f45b
https://github.com/themichaelhall/bluemvc-forms/blob/8f0e29aaf71eba70b50697384b22edaf72f2f45b/src/Base/AbstractTextElement.php#L79-L118
12,693
themichaelhall/bluemvc-forms
src/Base/AbstractTextElement.php
AbstractTextElement.sanitizeText
private function sanitizeText(string $text): string { $text = preg_replace($this->isMultiLine() ? '/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/u' : '/[\x00-\x1F\x7F]/u', '', $text); return $text; }
php
private function sanitizeText(string $text): string { $text = preg_replace($this->isMultiLine() ? '/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/u' : '/[\x00-\x1F\x7F]/u', '', $text); return $text; }
[ "private", "function", "sanitizeText", "(", "string", "$", "text", ")", ":", "string", "{", "$", "text", "=", "preg_replace", "(", "$", "this", "->", "isMultiLine", "(", ")", "?", "'/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/u'", ":", "'/[\\x00-\\x1F\\x7F]/u'", ",", "''", ",", "$", "text", ")", ";", "return", "$", "text", ";", "}" ]
Sanitizes the text. @param string $text The text. @return string The sanitized text.
[ "Sanitizes", "the", "text", "." ]
8f0e29aaf71eba70b50697384b22edaf72f2f45b
https://github.com/themichaelhall/bluemvc-forms/blob/8f0e29aaf71eba70b50697384b22edaf72f2f45b/src/Base/AbstractTextElement.php#L156-L161
12,694
laasti/response
src/ViewResponse.php
ViewResponse.create
public static function create($template = null, $view = '', $viewdata = [], $status = 200, $headers = array()) { if (!$template instanceof TemplateEngineInterface) { throw new InvalidArgumentException('The first argument of ViewResponse::create must be an instance of Laasti\Response\Engines\TemplateEngineInterface'); } return new static($template, $view, $viewdata, $status, $headers); }
php
public static function create($template = null, $view = '', $viewdata = [], $status = 200, $headers = array()) { if (!$template instanceof TemplateEngineInterface) { throw new InvalidArgumentException('The first argument of ViewResponse::create must be an instance of Laasti\Response\Engines\TemplateEngineInterface'); } return new static($template, $view, $viewdata, $status, $headers); }
[ "public", "static", "function", "create", "(", "$", "template", "=", "null", ",", "$", "view", "=", "''", ",", "$", "viewdata", "=", "[", "]", ",", "$", "status", "=", "200", ",", "$", "headers", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "template", "instanceof", "TemplateEngineInterface", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The first argument of ViewResponse::create must be an instance of Laasti\\Response\\Engines\\TemplateEngineInterface'", ")", ";", "}", "return", "new", "static", "(", "$", "template", ",", "$", "view", ",", "$", "viewdata", ",", "$", "status", ",", "$", "headers", ")", ";", "}" ]
Instantiates a new ViewResponse @param TemplateEngineInterface $template @param string $view @param array $viewdata @param int $status @param array $headers @return \static @throws InvalidArgumentException
[ "Instantiates", "a", "new", "ViewResponse" ]
72ae76bc6d8fb9d134cc4dc52a88766e6360e115
https://github.com/laasti/response/blob/72ae76bc6d8fb9d134cc4dc52a88766e6360e115/src/ViewResponse.php#L53-L59
12,695
gossi/trixionary
src/model/Base/SkillGroupQuery.php
SkillGroupQuery.filterByGroupId
public function filterByGroupId($groupId = null, $comparison = null) { if (is_array($groupId)) { $useMinMax = false; if (isset($groupId['min'])) { $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($groupId['max'])) { $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId, $comparison); }
php
public function filterByGroupId($groupId = null, $comparison = null) { if (is_array($groupId)) { $useMinMax = false; if (isset($groupId['min'])) { $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($groupId['max'])) { $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { return $this; } if (null === $comparison) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SkillGroupTableMap::COL_GROUP_ID, $groupId, $comparison); }
[ "public", "function", "filterByGroupId", "(", "$", "groupId", "=", "null", ",", "$", "comparison", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "groupId", ")", ")", "{", "$", "useMinMax", "=", "false", ";", "if", "(", "isset", "(", "$", "groupId", "[", "'min'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "SkillGroupTableMap", "::", "COL_GROUP_ID", ",", "$", "groupId", "[", "'min'", "]", ",", "Criteria", "::", "GREATER_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "groupId", "[", "'max'", "]", ")", ")", "{", "$", "this", "->", "addUsingAlias", "(", "SkillGroupTableMap", "::", "COL_GROUP_ID", ",", "$", "groupId", "[", "'max'", "]", ",", "Criteria", "::", "LESS_EQUAL", ")", ";", "$", "useMinMax", "=", "true", ";", "}", "if", "(", "$", "useMinMax", ")", "{", "return", "$", "this", ";", "}", "if", "(", "null", "===", "$", "comparison", ")", "{", "$", "comparison", "=", "Criteria", "::", "IN", ";", "}", "}", "return", "$", "this", "->", "addUsingAlias", "(", "SkillGroupTableMap", "::", "COL_GROUP_ID", ",", "$", "groupId", ",", "$", "comparison", ")", ";", "}" ]
Filter the query on the group_id column Example usage: <code> $query->filterByGroupId(1234); // WHERE group_id = 1234 $query->filterByGroupId(array(12, 34)); // WHERE group_id IN (12, 34) $query->filterByGroupId(array('min' => 12)); // WHERE group_id > 12 </code> @see filterByGroup() @param mixed $groupId The value to use as filter. Use scalar values for equality. Use array values for in_array() equivalent. Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL @return $this|ChildSkillGroupQuery The current query, for fluid interface
[ "Filter", "the", "query", "on", "the", "group_id", "column" ]
221a6c5322473d7d7f8e322958a3ee46d87da150
https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/SkillGroupQuery.php#L315-L336
12,696
gossi/trixionary
src/model/Base/SkillGroupQuery.php
SkillGroupQuery.findRelatedGroupSkillCounts
protected function findRelatedGroupSkillCounts($con) { $criteria = clone $this; if ($this->useAliasInSQL) { $alias = $this->getModelAlias(); $criteria->removeAlias($alias); } else { $alias = ''; } $this->groupSkillCounts = \gossi\trixionary\model\GroupQuery::create() ->joinSkillGroup($alias) ->mergeWith($criteria) ->find($con); }
php
protected function findRelatedGroupSkillCounts($con) { $criteria = clone $this; if ($this->useAliasInSQL) { $alias = $this->getModelAlias(); $criteria->removeAlias($alias); } else { $alias = ''; } $this->groupSkillCounts = \gossi\trixionary\model\GroupQuery::create() ->joinSkillGroup($alias) ->mergeWith($criteria) ->find($con); }
[ "protected", "function", "findRelatedGroupSkillCounts", "(", "$", "con", ")", "{", "$", "criteria", "=", "clone", "$", "this", ";", "if", "(", "$", "this", "->", "useAliasInSQL", ")", "{", "$", "alias", "=", "$", "this", "->", "getModelAlias", "(", ")", ";", "$", "criteria", "->", "removeAlias", "(", "$", "alias", ")", ";", "}", "else", "{", "$", "alias", "=", "''", ";", "}", "$", "this", "->", "groupSkillCounts", "=", "\\", "gossi", "\\", "trixionary", "\\", "model", "\\", "GroupQuery", "::", "create", "(", ")", "->", "joinSkillGroup", "(", "$", "alias", ")", "->", "mergeWith", "(", "$", "criteria", ")", "->", "find", "(", "$", "con", ")", ";", "}" ]
Finds the related Group objects and keep them for later @param ConnectionInterface $con A connection object
[ "Finds", "the", "related", "Group", "objects", "and", "keep", "them", "for", "later" ]
221a6c5322473d7d7f8e322958a3ee46d87da150
https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/SkillGroupQuery.php#L634-L647
12,697
jianfengye/hades
src/Hades/Http/Request.php
Request.route
public function route($key, $default = null) { if (isset($this->routeParams[$key])){ return $this->routeParams[$key]; } return $default; }
php
public function route($key, $default = null) { if (isset($this->routeParams[$key])){ return $this->routeParams[$key]; } return $default; }
[ "public", "function", "route", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "routeParams", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "routeParams", "[", "$", "key", "]", ";", "}", "return", "$", "default", ";", "}" ]
data from routeParams
[ "data", "from", "routeParams" ]
a0690d96dada070b4cf4b9ff63ab3aa024c34a67
https://github.com/jianfengye/hades/blob/a0690d96dada070b4cf4b9ff63ab3aa024c34a67/src/Hades/Http/Request.php#L64-L70
12,698
jianfengye/hades
src/Hades/Http/Request.php
Request.uri
public function uri() { // in iis and forward proxy, uri in X_ORIGINAL_URL if (isset($this->server['X_ORIGINAL_URL']) && !empty($this->server['X_ORIGINAL_URL'])) { return $this->server['X_ORIGINAL_URL']; } return $this->server['REQUEST_URI']; }
php
public function uri() { // in iis and forward proxy, uri in X_ORIGINAL_URL if (isset($this->server['X_ORIGINAL_URL']) && !empty($this->server['X_ORIGINAL_URL'])) { return $this->server['X_ORIGINAL_URL']; } return $this->server['REQUEST_URI']; }
[ "public", "function", "uri", "(", ")", "{", "// in iis and forward proxy, uri in X_ORIGINAL_URL", "if", "(", "isset", "(", "$", "this", "->", "server", "[", "'X_ORIGINAL_URL'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "server", "[", "'X_ORIGINAL_URL'", "]", ")", ")", "{", "return", "$", "this", "->", "server", "[", "'X_ORIGINAL_URL'", "]", ";", "}", "return", "$", "this", "->", "server", "[", "'REQUEST_URI'", "]", ";", "}" ]
get request uri
[ "get", "request", "uri" ]
a0690d96dada070b4cf4b9ff63ab3aa024c34a67
https://github.com/jianfengye/hades/blob/a0690d96dada070b4cf4b9ff63ab3aa024c34a67/src/Hades/Http/Request.php#L116-L124
12,699
jianfengye/hades
src/Hades/Http/Request.php
Request.create
public function create($method, $params) { if (strtolower($method) == 'get') { $this->get = $params; } else { $this->post = $params; } return $this; }
php
public function create($method, $params) { if (strtolower($method) == 'get') { $this->get = $params; } else { $this->post = $params; } return $this; }
[ "public", "function", "create", "(", "$", "method", ",", "$", "params", ")", "{", "if", "(", "strtolower", "(", "$", "method", ")", "==", "'get'", ")", "{", "$", "this", "->", "get", "=", "$", "params", ";", "}", "else", "{", "$", "this", "->", "post", "=", "$", "params", ";", "}", "return", "$", "this", ";", "}" ]
create request by create
[ "create", "request", "by", "create" ]
a0690d96dada070b4cf4b9ff63ab3aa024c34a67
https://github.com/jianfengye/hades/blob/a0690d96dada070b4cf4b9ff63ab3aa024c34a67/src/Hades/Http/Request.php#L133-L141