repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
myerscode/utilities-strings
src/Utility.php
Utility.replace
public function replace($find, $with): Utility { $replace = []; foreach ($this->parameters($find) as $parameter) { $replace[] = preg_quote($parameter->value()); } $withString = new static($with, $this->encoding); $string = preg_replace('#(' . implode('|', $replace) . ')#', $withString->value(), $this->string); return new static($string, $this->encoding); }
php
public function replace($find, $with): Utility { $replace = []; foreach ($this->parameters($find) as $parameter) { $replace[] = preg_quote($parameter->value()); } $withString = new static($with, $this->encoding); $string = preg_replace('#(' . implode('|', $replace) . ')#', $withString->value(), $this->string); return new static($string, $this->encoding); }
[ "public", "function", "replace", "(", "$", "find", ",", "$", "with", ")", ":", "Utility", "{", "$", "replace", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "parameters", "(", "$", "find", ")", "as", "$", "parameter", ")", "{", "$", "replace", "[", "]", "=", "preg_quote", "(", "$", "parameter", "->", "value", "(", ")", ")", ";", "}", "$", "withString", "=", "new", "static", "(", "$", "with", ",", "$", "this", "->", "encoding", ")", ";", "$", "string", "=", "preg_replace", "(", "'#('", ".", "implode", "(", "'|'", ",", "$", "replace", ")", ".", "')#'", ",", "$", "withString", "->", "value", "(", ")", ",", "$", "this", "->", "string", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Replace occurrences in the string with a given value @param string|array $find Value(s) in the string to replace @param string $with Value to replace occurrences with @return $this
[ "Replace", "occurrences", "in", "the", "string", "with", "a", "given", "value" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L723-L736
train
myerscode/utilities-strings
src/Utility.php
Utility.replaceNonAlpha
public function replaceNonAlpha(string $replacement = '', bool $strict = false): Utility { if ($strict) { $pattern = '/[^a-zA-Z]/'; } else { $pattern = '/[^a-zA-Z ]/'; } $string = preg_replace($pattern, $replacement, trim($this->string)); return new static($string, $this->encoding); }
php
public function replaceNonAlpha(string $replacement = '', bool $strict = false): Utility { if ($strict) { $pattern = '/[^a-zA-Z]/'; } else { $pattern = '/[^a-zA-Z ]/'; } $string = preg_replace($pattern, $replacement, trim($this->string)); return new static($string, $this->encoding); }
[ "public", "function", "replaceNonAlpha", "(", "string", "$", "replacement", "=", "''", ",", "bool", "$", "strict", "=", "false", ")", ":", "Utility", "{", "if", "(", "$", "strict", ")", "{", "$", "pattern", "=", "'/[^a-zA-Z]/'", ";", "}", "else", "{", "$", "pattern", "=", "'/[^a-zA-Z ]/'", ";", "}", "$", "string", "=", "preg_replace", "(", "$", "pattern", ",", "$", "replacement", ",", "trim", "(", "$", "this", "->", "string", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Replace none alpha characters in the string with the given value @param string $replacement Value to replace none alpha characters with @param boolean $strict Should spaces be preserved @return $this
[ "Replace", "none", "alpha", "characters", "in", "the", "string", "with", "the", "given", "value" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L746-L757
train
myerscode/utilities-strings
src/Utility.php
Utility.reverse
public function reverse(): Utility { $string = ''; for ($i = $this->length() - 1; $i >= 0; $i--) { $string .= \mb_substr($this->string, $i, 1, $this->encoding); } return new static($string, $this->encoding); }
php
public function reverse(): Utility { $string = ''; for ($i = $this->length() - 1; $i >= 0; $i--) { $string .= \mb_substr($this->string, $i, 1, $this->encoding); } return new static($string, $this->encoding); }
[ "public", "function", "reverse", "(", ")", ":", "Utility", "{", "$", "string", "=", "''", ";", "for", "(", "$", "i", "=", "$", "this", "->", "length", "(", ")", "-", "1", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "string", ".=", "\\", "mb_substr", "(", "$", "this", "->", "string", ",", "$", "i", ",", "1", ",", "$", "this", "->", "encoding", ")", ";", "}", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Reverse the string @return $this
[ "Reverse", "the", "string" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L806-L815
train
myerscode/utilities-strings
src/Utility.php
Utility.surround
public function surround($with): Utility { $surrounding = new static($with, $this->encoding); return new static(implode('', [$surrounding, $this->string, $surrounding]), $this->encoding); }
php
public function surround($with): Utility { $surrounding = new static($with, $this->encoding); return new static(implode('', [$surrounding, $this->string, $surrounding]), $this->encoding); }
[ "public", "function", "surround", "(", "$", "with", ")", ":", "Utility", "{", "$", "surrounding", "=", "new", "static", "(", "$", "with", ",", "$", "this", "->", "encoding", ")", ";", "return", "new", "static", "(", "implode", "(", "''", ",", "[", "$", "surrounding", ",", "$", "this", "->", "string", ",", "$", "surrounding", "]", ")", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Wrap the the string with a value @param $with @return Utility
[ "Wrap", "the", "the", "string", "with", "a", "value" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L881-L886
train
myerscode/utilities-strings
src/Utility.php
Utility.toCamelCase
public function toCamelCase(): Utility { // separate existing joined words $string = preg_replace('/([a-z0-9])(?=[A-Z])/', '$1 ', $this->string); $words = preg_split('/[\W_]/', $string); $words = array_map(function ($word) { return ucfirst(strtolower($word)); }, $words); $string = lcfirst(implode('', $words)); return new static($string, $this->encoding); }
php
public function toCamelCase(): Utility { // separate existing joined words $string = preg_replace('/([a-z0-9])(?=[A-Z])/', '$1 ', $this->string); $words = preg_split('/[\W_]/', $string); $words = array_map(function ($word) { return ucfirst(strtolower($word)); }, $words); $string = lcfirst(implode('', $words)); return new static($string, $this->encoding); }
[ "public", "function", "toCamelCase", "(", ")", ":", "Utility", "{", "// separate existing joined words", "$", "string", "=", "preg_replace", "(", "'/([a-z0-9])(?=[A-Z])/'", ",", "'$1 '", ",", "$", "this", "->", "string", ")", ";", "$", "words", "=", "preg_split", "(", "'/[\\W_]/'", ",", "$", "string", ")", ";", "$", "words", "=", "array_map", "(", "function", "(", "$", "word", ")", "{", "return", "ucfirst", "(", "strtolower", "(", "$", "word", ")", ")", ";", "}", ",", "$", "words", ")", ";", "$", "string", "=", "lcfirst", "(", "implode", "(", "''", ",", "$", "words", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Transform the value to into camelCase format @return $this
[ "Transform", "the", "value", "to", "into", "camelCase", "format" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L913-L927
train
myerscode/utilities-strings
src/Utility.php
Utility.toPascalCase
public function toPascalCase(): Utility { $string = ucfirst($this->toCamelCase()->value()); return new static($string, $this->encoding); }
php
public function toPascalCase(): Utility { $string = ucfirst($this->toCamelCase()->value()); return new static($string, $this->encoding); }
[ "public", "function", "toPascalCase", "(", ")", ":", "Utility", "{", "$", "string", "=", "ucfirst", "(", "$", "this", "->", "toCamelCase", "(", ")", "->", "value", "(", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Transform the value to into PascalCase format @return $this
[ "Transform", "the", "value", "to", "into", "PascalCase", "format" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L966-L971
train
myerscode/utilities-strings
src/Utility.php
Utility.toSentence
public function toSentence(): Utility { $sentences = preg_split( '/([^\.\!\?;]+[\.\!\?;"]+)/', $this->string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); $sentences = array_map(function ($sentence) { $sentence = trim($sentence); if (!ctype_upper($sentence[0])) { $sentence = ucfirst($sentence); } return $sentence; }, $sentences); $string = implode(' ', $sentences); if (preg_match('/[\p{P}]$/', $string)) { return new static($string, $this->encoding); } return (new static($string, $this->encoding))->ensureEndsWith('.'); }
php
public function toSentence(): Utility { $sentences = preg_split( '/([^\.\!\?;]+[\.\!\?;"]+)/', $this->string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); $sentences = array_map(function ($sentence) { $sentence = trim($sentence); if (!ctype_upper($sentence[0])) { $sentence = ucfirst($sentence); } return $sentence; }, $sentences); $string = implode(' ', $sentences); if (preg_match('/[\p{P}]$/', $string)) { return new static($string, $this->encoding); } return (new static($string, $this->encoding))->ensureEndsWith('.'); }
[ "public", "function", "toSentence", "(", ")", ":", "Utility", "{", "$", "sentences", "=", "preg_split", "(", "'/([^\\.\\!\\?;]+[\\.\\!\\?;\"]+)/'", ",", "$", "this", "->", "string", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", "|", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "$", "sentences", "=", "array_map", "(", "function", "(", "$", "sentence", ")", "{", "$", "sentence", "=", "trim", "(", "$", "sentence", ")", ";", "if", "(", "!", "ctype_upper", "(", "$", "sentence", "[", "0", "]", ")", ")", "{", "$", "sentence", "=", "ucfirst", "(", "$", "sentence", ")", ";", "}", "return", "$", "sentence", ";", "}", ",", "$", "sentences", ")", ";", "$", "string", "=", "implode", "(", "' '", ",", "$", "sentences", ")", ";", "if", "(", "preg_match", "(", "'/[\\p{P}]$/'", ",", "$", "string", ")", ")", "{", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}", "return", "(", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ")", "->", "ensureEndsWith", "(", "'.'", ")", ";", "}" ]
Turn the string into a sentence. @return $this
[ "Turn", "the", "string", "into", "a", "sentence", "." ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L978-L1002
train
myerscode/utilities-strings
src/Utility.php
Utility.toSlug
public function toSlug(string $separator = '-'): Utility { $string = mb_convert_encoding($this->string, 'UTF-8', $this->encoding); $string = preg_replace('/[^\s\p{L}0-9\-' . $separator . ']/u', '', $string); $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); $string = preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $string); $string = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $string); $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8'); $string = preg_replace('~[^0-9a-z]+~i', $separator, $string); $string = trim($string, $separator); $string = mb_strtolower($string); return new static($string, $this->encoding); }
php
public function toSlug(string $separator = '-'): Utility { $string = mb_convert_encoding($this->string, 'UTF-8', $this->encoding); $string = preg_replace('/[^\s\p{L}0-9\-' . $separator . ']/u', '', $string); $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); $string = preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $string); $string = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $string); $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8'); $string = preg_replace('~[^0-9a-z]+~i', $separator, $string); $string = trim($string, $separator); $string = mb_strtolower($string); return new static($string, $this->encoding); }
[ "public", "function", "toSlug", "(", "string", "$", "separator", "=", "'-'", ")", ":", "Utility", "{", "$", "string", "=", "mb_convert_encoding", "(", "$", "this", "->", "string", ",", "'UTF-8'", ",", "$", "this", "->", "encoding", ")", ";", "$", "string", "=", "preg_replace", "(", "'/[^\\s\\p{L}0-9\\-'", ".", "$", "separator", ".", "']/u'", ",", "''", ",", "$", "string", ")", ";", "$", "string", "=", "htmlentities", "(", "$", "string", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ";", "$", "string", "=", "preg_replace", "(", "'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i'", ",", "'$1'", ",", "$", "string", ")", ";", "$", "string", "=", "iconv", "(", "'utf-8'", ",", "'ASCII//TRANSLIT//IGNORE'", ",", "$", "string", ")", ";", "$", "string", "=", "html_entity_decode", "(", "$", "string", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ";", "$", "string", "=", "preg_replace", "(", "'~[^0-9a-z]+~i'", ",", "$", "separator", ",", "$", "string", ")", ";", "$", "string", "=", "trim", "(", "$", "string", ",", "$", "separator", ")", ";", "$", "string", "=", "mb_strtolower", "(", "$", "string", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Clean a string to only have alpha numeric characters, turn spaces into a separator slug @param string $separator Value to separate chunks with @return $this
[ "Clean", "a", "string", "to", "only", "have", "alpha", "numeric", "characters", "turn", "spaces", "into", "a", "separator", "slug" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1012-L1025
train
myerscode/utilities-strings
src/Utility.php
Utility.toSlugUtf8
public function toSlugUtf8(string $separator = '-'): Utility { $string = mb_convert_encoding($this->string, 'UTF-8', $this->encoding); $string = preg_replace('/[^\s\p{L}0-9\-' . $separator . ']/u', '', $string); $string = preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $string); $string = preg_replace('/[\s_\-]/', $separator, $string); $string = trim($string, $separator); $string = mb_strtolower($string, 'utf-8'); return new static($string, $this->encoding); }
php
public function toSlugUtf8(string $separator = '-'): Utility { $string = mb_convert_encoding($this->string, 'UTF-8', $this->encoding); $string = preg_replace('/[^\s\p{L}0-9\-' . $separator . ']/u', '', $string); $string = preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $string); $string = preg_replace('/[\s_\-]/', $separator, $string); $string = trim($string, $separator); $string = mb_strtolower($string, 'utf-8'); return new static($string, $this->encoding); }
[ "public", "function", "toSlugUtf8", "(", "string", "$", "separator", "=", "'-'", ")", ":", "Utility", "{", "$", "string", "=", "mb_convert_encoding", "(", "$", "this", "->", "string", ",", "'UTF-8'", ",", "$", "this", "->", "encoding", ")", ";", "$", "string", "=", "preg_replace", "(", "'/[^\\s\\p{L}0-9\\-'", ".", "$", "separator", ".", "']/u'", ",", "''", ",", "$", "string", ")", ";", "$", "string", "=", "preg_replace", "(", "'~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i'", ",", "'$1'", ",", "$", "string", ")", ";", "$", "string", "=", "preg_replace", "(", "'/[\\s_\\-]/'", ",", "$", "separator", ",", "$", "string", ")", ";", "$", "string", "=", "trim", "(", "$", "string", ",", "$", "separator", ")", ";", "$", "string", "=", "mb_strtolower", "(", "$", "string", ",", "'utf-8'", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Same as toSlug but preserves UTF8 characters @param string $separator Value to separate chunks with @return $this
[ "Same", "as", "toSlug", "but", "preserves", "UTF8", "characters" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1034-L1043
train
myerscode/utilities-strings
src/Utility.php
Utility.toSnakeCase
public function toSnakeCase(): Utility { $string = mb_ereg_replace('\B([A-Z])', '-\1', trim($this->string)); $string = mb_strtolower($string, $this->encoding); $string = mb_ereg_replace('[-_\s]+', '_', $string); return new static($string, $this->encoding); }
php
public function toSnakeCase(): Utility { $string = mb_ereg_replace('\B([A-Z])', '-\1', trim($this->string)); $string = mb_strtolower($string, $this->encoding); $string = mb_ereg_replace('[-_\s]+', '_', $string); return new static($string, $this->encoding); }
[ "public", "function", "toSnakeCase", "(", ")", ":", "Utility", "{", "$", "string", "=", "mb_ereg_replace", "(", "'\\B([A-Z])'", ",", "'-\\1'", ",", "trim", "(", "$", "this", "->", "string", ")", ")", ";", "$", "string", "=", "mb_strtolower", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "$", "string", "=", "mb_ereg_replace", "(", "'[-_\\s]+'", ",", "'_'", ",", "$", "string", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Transform the value to snake_case format @return $this
[ "Transform", "the", "value", "to", "snake_case", "format" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1050-L1059
train
myerscode/utilities-strings
src/Utility.php
Utility.toStudlyCase
public function toStudlyCase(): Utility { $string = implode(' ', $this->prepareForCasing($this->string)); $string = str_replace(' ', '', ucwords($string)); return new static($string, $this->encoding); }
php
public function toStudlyCase(): Utility { $string = implode(' ', $this->prepareForCasing($this->string)); $string = str_replace(' ', '', ucwords($string)); return new static($string, $this->encoding); }
[ "public", "function", "toStudlyCase", "(", ")", ":", "Utility", "{", "$", "string", "=", "implode", "(", "' '", ",", "$", "this", "->", "prepareForCasing", "(", "$", "this", "->", "string", ")", ")", ";", "$", "string", "=", "str_replace", "(", "' '", ",", "''", ",", "ucwords", "(", "$", "string", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Transform the value to StudlyCase format @return $this
[ "Transform", "the", "value", "to", "StudlyCase", "format" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1066-L1073
train
myerscode/utilities-strings
src/Utility.php
Utility.toTitleCase
public function toTitleCase(): Utility { $words = explode(' ', $this->string); $string = mb_convert_case(implode(' ', $words), MB_CASE_TITLE, $this->encoding()); return new static($string, $this->encoding); }
php
public function toTitleCase(): Utility { $words = explode(' ', $this->string); $string = mb_convert_case(implode(' ', $words), MB_CASE_TITLE, $this->encoding()); return new static($string, $this->encoding); }
[ "public", "function", "toTitleCase", "(", ")", ":", "Utility", "{", "$", "words", "=", "explode", "(", "' '", ",", "$", "this", "->", "string", ")", ";", "$", "string", "=", "mb_convert_case", "(", "implode", "(", "' '", ",", "$", "words", ")", ",", "MB_CASE_TITLE", ",", "$", "this", "->", "encoding", "(", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Transform the value to into Title Case format @return $this
[ "Transform", "the", "value", "to", "into", "Title", "Case", "format" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1080-L1087
train
myerscode/utilities-strings
src/Utility.php
Utility.trim
public function trim($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = trim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
php
public function trim($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = trim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
[ "public", "function", "trim", "(", "$", "values", "=", "\" \\t\\n\\r\\0\\x0B\"", ")", ":", "Utility", "{", "$", "parameters", "=", "$", "this", "->", "parameters", "(", "$", "values", ")", ";", "$", "string", "=", "trim", "(", "$", "this", "->", "string", ",", "implode", "(", "''", ",", "$", "parameters", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Trim a collection of values from the string using trim @param mixed $values Values to be trimmed from the string @return $this
[ "Trim", "a", "collection", "of", "values", "from", "the", "string", "using", "trim" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1106-L1113
train
myerscode/utilities-strings
src/Utility.php
Utility.trimLeft
public function trimLeft($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = ltrim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
php
public function trimLeft($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = ltrim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
[ "public", "function", "trimLeft", "(", "$", "values", "=", "\" \\t\\n\\r\\0\\x0B\"", ")", ":", "Utility", "{", "$", "parameters", "=", "$", "this", "->", "parameters", "(", "$", "values", ")", ";", "$", "string", "=", "ltrim", "(", "$", "this", "->", "string", ",", "implode", "(", "''", ",", "$", "parameters", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Trim a collection of values from the string using rtrim @param mixed $values Values to be trimmed from the string @return $this
[ "Trim", "a", "collection", "of", "values", "from", "the", "string", "using", "rtrim" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1122-L1129
train
myerscode/utilities-strings
src/Utility.php
Utility.trimRight
public function trimRight($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = rtrim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
php
public function trimRight($values = " \t\n\r\0\x0B"): Utility { $parameters = $this->parameters($values); $string = rtrim($this->string, implode('', $parameters)); return new static($string, $this->encoding); }
[ "public", "function", "trimRight", "(", "$", "values", "=", "\" \\t\\n\\r\\0\\x0B\"", ")", ":", "Utility", "{", "$", "parameters", "=", "$", "this", "->", "parameters", "(", "$", "values", ")", ";", "$", "string", "=", "rtrim", "(", "$", "this", "->", "string", ",", "implode", "(", "''", ",", "$", "parameters", ")", ")", ";", "return", "new", "static", "(", "$", "string", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Trim a collection of values from the string using ltrim @param mixed $values Values to be trimmed from the string @return $this
[ "Trim", "a", "collection", "of", "values", "from", "the", "string", "using", "ltrim" ]
e7adb907a57de060295a7f3886d43230f66f6b76
https://github.com/myerscode/utilities-strings/blob/e7adb907a57de060295a7f3886d43230f66f6b76/src/Utility.php#L1138-L1145
train
hschletz/NADA
src/Table/Sqlite.php
Sqlite.alterColumn
public function alterColumn($name, $attrib, $value) { $this->requireColumn($name); // Derive new column specification from existing one $newColumns = $this->_columns; if ($attrib === null) { unset($newColumns[$name]); } else { $newColumn = $newColumns[$name]->toArray(); $newColumn[$attrib] = $value; $newColumns[$name] = $this->_database->createColumnFromArray($newColumn); } // Preserve PK // TODO preserve other constraints $pkColumns = array(); if ($this->_primaryKey) { foreach ($this->_primaryKey as $column) { if ($name == $column->getName()) { if ($attrib === null) { // Skip column about to be deleted continue; } elseif ($attrib == 'name') { // Use new column name for PK $pkColumns[] = $value; continue; } } $pkColumns[] = $column->getName(); } } // Start exclusive operations $savepoint = uniqid(__FUNCTION__); $this->_database->exec('SAVEPOINT ' . $savepoint); $this->_database->exec('PRAGMA locking_mode = EXCLUSIVE'); $tmpTableName = $this->_renameToTmp(); // Create table with new column specifications $this->_database->clearCache($this->_name); $this->_database->createTable($this->_name, $newColumns, $pkColumns); // Copy data from old table $columnsOld = array(); $columnsNew = array(); foreach ($newColumns as $column) { if ($attrib == 'name' and $column->getName() == $value) { // Special treatment for renamed columns $columnsOld[] = $this->_database->prepareIdentifier($name); $columnsNew[] = $this->_database->prepareIdentifier($value); } else { $columnsOld[] = $this->_database->prepareIdentifier($column->getName()); $columnsNew[] = $this->_database->prepareIdentifier($column->getName()); } } $columnsOld = implode (', ', $columnsOld); $columnsNew = implode (', ', $columnsNew); $tableName = $this->_database->prepareIdentifier($this->_name); $this->_database->exec( "INSERT INTO $tableName ($columnsNew) SELECT $columnsOld FROM $tmpTableName" ); // Clean up $this->_database->exec("DROP TABLE $tmpTableName"); $this->_database->exec('PRAGMA locking_mode = NORMAL'); $this->_database->exec('RELEASE ' . $savepoint); // Update column cache (update keys as well in case of renamed columns) $this->_columns = array(); foreach ($newColumns as $column) { $this->_columns[$column->getName()] = $column; } }
php
public function alterColumn($name, $attrib, $value) { $this->requireColumn($name); // Derive new column specification from existing one $newColumns = $this->_columns; if ($attrib === null) { unset($newColumns[$name]); } else { $newColumn = $newColumns[$name]->toArray(); $newColumn[$attrib] = $value; $newColumns[$name] = $this->_database->createColumnFromArray($newColumn); } // Preserve PK // TODO preserve other constraints $pkColumns = array(); if ($this->_primaryKey) { foreach ($this->_primaryKey as $column) { if ($name == $column->getName()) { if ($attrib === null) { // Skip column about to be deleted continue; } elseif ($attrib == 'name') { // Use new column name for PK $pkColumns[] = $value; continue; } } $pkColumns[] = $column->getName(); } } // Start exclusive operations $savepoint = uniqid(__FUNCTION__); $this->_database->exec('SAVEPOINT ' . $savepoint); $this->_database->exec('PRAGMA locking_mode = EXCLUSIVE'); $tmpTableName = $this->_renameToTmp(); // Create table with new column specifications $this->_database->clearCache($this->_name); $this->_database->createTable($this->_name, $newColumns, $pkColumns); // Copy data from old table $columnsOld = array(); $columnsNew = array(); foreach ($newColumns as $column) { if ($attrib == 'name' and $column->getName() == $value) { // Special treatment for renamed columns $columnsOld[] = $this->_database->prepareIdentifier($name); $columnsNew[] = $this->_database->prepareIdentifier($value); } else { $columnsOld[] = $this->_database->prepareIdentifier($column->getName()); $columnsNew[] = $this->_database->prepareIdentifier($column->getName()); } } $columnsOld = implode (', ', $columnsOld); $columnsNew = implode (', ', $columnsNew); $tableName = $this->_database->prepareIdentifier($this->_name); $this->_database->exec( "INSERT INTO $tableName ($columnsNew) SELECT $columnsOld FROM $tmpTableName" ); // Clean up $this->_database->exec("DROP TABLE $tmpTableName"); $this->_database->exec('PRAGMA locking_mode = NORMAL'); $this->_database->exec('RELEASE ' . $savepoint); // Update column cache (update keys as well in case of renamed columns) $this->_columns = array(); foreach ($newColumns as $column) { $this->_columns[$column->getName()] = $column; } }
[ "public", "function", "alterColumn", "(", "$", "name", ",", "$", "attrib", ",", "$", "value", ")", "{", "$", "this", "->", "requireColumn", "(", "$", "name", ")", ";", "// Derive new column specification from existing one", "$", "newColumns", "=", "$", "this", "->", "_columns", ";", "if", "(", "$", "attrib", "===", "null", ")", "{", "unset", "(", "$", "newColumns", "[", "$", "name", "]", ")", ";", "}", "else", "{", "$", "newColumn", "=", "$", "newColumns", "[", "$", "name", "]", "->", "toArray", "(", ")", ";", "$", "newColumn", "[", "$", "attrib", "]", "=", "$", "value", ";", "$", "newColumns", "[", "$", "name", "]", "=", "$", "this", "->", "_database", "->", "createColumnFromArray", "(", "$", "newColumn", ")", ";", "}", "// Preserve PK", "// TODO preserve other constraints", "$", "pkColumns", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "_primaryKey", ")", "{", "foreach", "(", "$", "this", "->", "_primaryKey", "as", "$", "column", ")", "{", "if", "(", "$", "name", "==", "$", "column", "->", "getName", "(", ")", ")", "{", "if", "(", "$", "attrib", "===", "null", ")", "{", "// Skip column about to be deleted", "continue", ";", "}", "elseif", "(", "$", "attrib", "==", "'name'", ")", "{", "// Use new column name for PK", "$", "pkColumns", "[", "]", "=", "$", "value", ";", "continue", ";", "}", "}", "$", "pkColumns", "[", "]", "=", "$", "column", "->", "getName", "(", ")", ";", "}", "}", "// Start exclusive operations", "$", "savepoint", "=", "uniqid", "(", "__FUNCTION__", ")", ";", "$", "this", "->", "_database", "->", "exec", "(", "'SAVEPOINT '", ".", "$", "savepoint", ")", ";", "$", "this", "->", "_database", "->", "exec", "(", "'PRAGMA locking_mode = EXCLUSIVE'", ")", ";", "$", "tmpTableName", "=", "$", "this", "->", "_renameToTmp", "(", ")", ";", "// Create table with new column specifications", "$", "this", "->", "_database", "->", "clearCache", "(", "$", "this", "->", "_name", ")", ";", "$", "this", "->", "_database", "->", "createTable", "(", "$", "this", "->", "_name", ",", "$", "newColumns", ",", "$", "pkColumns", ")", ";", "// Copy data from old table", "$", "columnsOld", "=", "array", "(", ")", ";", "$", "columnsNew", "=", "array", "(", ")", ";", "foreach", "(", "$", "newColumns", "as", "$", "column", ")", "{", "if", "(", "$", "attrib", "==", "'name'", "and", "$", "column", "->", "getName", "(", ")", "==", "$", "value", ")", "{", "// Special treatment for renamed columns", "$", "columnsOld", "[", "]", "=", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "name", ")", ";", "$", "columnsNew", "[", "]", "=", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "value", ")", ";", "}", "else", "{", "$", "columnsOld", "[", "]", "=", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "columnsNew", "[", "]", "=", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "}", "}", "$", "columnsOld", "=", "implode", "(", "', '", ",", "$", "columnsOld", ")", ";", "$", "columnsNew", "=", "implode", "(", "', '", ",", "$", "columnsNew", ")", ";", "$", "tableName", "=", "$", "this", "->", "_database", "->", "prepareIdentifier", "(", "$", "this", "->", "_name", ")", ";", "$", "this", "->", "_database", "->", "exec", "(", "\"INSERT INTO $tableName ($columnsNew) SELECT $columnsOld FROM $tmpTableName\"", ")", ";", "// Clean up", "$", "this", "->", "_database", "->", "exec", "(", "\"DROP TABLE $tmpTableName\"", ")", ";", "$", "this", "->", "_database", "->", "exec", "(", "'PRAGMA locking_mode = NORMAL'", ")", ";", "$", "this", "->", "_database", "->", "exec", "(", "'RELEASE '", ".", "$", "savepoint", ")", ";", "// Update column cache (update keys as well in case of renamed columns)", "$", "this", "->", "_columns", "=", "array", "(", ")", ";", "foreach", "(", "$", "newColumns", "as", "$", "column", ")", "{", "$", "this", "->", "_columns", "[", "$", "column", "->", "getName", "(", ")", "]", "=", "$", "column", ";", "}", "}" ]
Internal method to alter a column Since SQLite's ALTER TABLE statement only supports renaming tables and adding columns, this method does everything else: 1. The table is renamed to a unique temporary name. 2. A new table with the original name and altered columns is created. 3. Data is copied to the new table. 4. The old table is dropped. NOTE: Primary keys are preserved, but all other contraints are lost for every column in this table, not just for the altered one. @param string $name Column to be altered @param string $attrib Attribute to be altered or NULL for dropping the column @param mixed $value New value for altered attibute @internal
[ "Internal", "method", "to", "alter", "a", "column" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Table/Sqlite.php#L115-L189
train
hschletz/NADA
src/Table/Sqlite.php
Sqlite._renameToTmp
protected function _renameToTmp() { $tmpTableName = $this->_name; $tableNames = $this->_database->getTableNames(); do { $tmpTableName .= '_bak'; } while (in_array($tmpTableName, $tableNames)); // Use quoteIdentifier() instead of prepareIdentifier() because the // temporary name is not identified as a keyword. $tmpTableName = $this->_database->quoteIdentifier($tmpTableName); $this->alter("RENAME TO $tmpTableName"); return $tmpTableName; }
php
protected function _renameToTmp() { $tmpTableName = $this->_name; $tableNames = $this->_database->getTableNames(); do { $tmpTableName .= '_bak'; } while (in_array($tmpTableName, $tableNames)); // Use quoteIdentifier() instead of prepareIdentifier() because the // temporary name is not identified as a keyword. $tmpTableName = $this->_database->quoteIdentifier($tmpTableName); $this->alter("RENAME TO $tmpTableName"); return $tmpTableName; }
[ "protected", "function", "_renameToTmp", "(", ")", "{", "$", "tmpTableName", "=", "$", "this", "->", "_name", ";", "$", "tableNames", "=", "$", "this", "->", "_database", "->", "getTableNames", "(", ")", ";", "do", "{", "$", "tmpTableName", ".=", "'_bak'", ";", "}", "while", "(", "in_array", "(", "$", "tmpTableName", ",", "$", "tableNames", ")", ")", ";", "// Use quoteIdentifier() instead of prepareIdentifier() because the", "// temporary name is not identified as a keyword.", "$", "tmpTableName", "=", "$", "this", "->", "_database", "->", "quoteIdentifier", "(", "$", "tmpTableName", ")", ";", "$", "this", "->", "alter", "(", "\"RENAME TO $tmpTableName\"", ")", ";", "return", "$", "tmpTableName", ";", "}" ]
Rename table to a unique temporary name @return string New table name
[ "Rename", "table", "to", "a", "unique", "temporary", "name" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Table/Sqlite.php#L248-L260
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
YamlDumper.dump
public function dump(array $options = array()) { if (!class_exists('zxf\Symfony\Component\Yaml\Dumper')) { throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.'); } if (null === $this->dumper) { $this->dumper = new YmlDumper(); } return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices()); }
php
public function dump(array $options = array()) { if (!class_exists('zxf\Symfony\Component\Yaml\Dumper')) { throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.'); } if (null === $this->dumper) { $this->dumper = new YmlDumper(); } return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices()); }
[ "public", "function", "dump", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "class_exists", "(", "'zxf\\Symfony\\Component\\Yaml\\Dumper'", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Unable to dump the container as the Symfony Yaml Component is not installed.'", ")", ";", "}", "if", "(", "null", "===", "$", "this", "->", "dumper", ")", "{", "$", "this", "->", "dumper", "=", "new", "YmlDumper", "(", ")", ";", "}", "return", "$", "this", "->", "container", "->", "resolveEnvPlaceholders", "(", "$", "this", "->", "addParameters", "(", ")", ".", "\"\\n\"", ".", "$", "this", "->", "addServices", "(", ")", ")", ";", "}" ]
Dumps the service container as an YAML string. @return string A YAML string representing of the service container
[ "Dumps", "the", "service", "container", "as", "an", "YAML", "string", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php#L44-L55
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
YamlDumper.addServices
private function addServices() { if (!$this->container->getDefinitions()) { return ''; } $code = "services:\n"; foreach ($this->container->getDefinitions() as $id => $definition) { $code .= $this->addService($id, $definition); } $aliases = $this->container->getAliases(); foreach ($aliases as $alias => $id) { while (isset($aliases[(string) $id])) { $id = $aliases[(string) $id]; } $code .= $this->addServiceAlias($alias, $id); } return $code; }
php
private function addServices() { if (!$this->container->getDefinitions()) { return ''; } $code = "services:\n"; foreach ($this->container->getDefinitions() as $id => $definition) { $code .= $this->addService($id, $definition); } $aliases = $this->container->getAliases(); foreach ($aliases as $alias => $id) { while (isset($aliases[(string) $id])) { $id = $aliases[(string) $id]; } $code .= $this->addServiceAlias($alias, $id); } return $code; }
[ "private", "function", "addServices", "(", ")", "{", "if", "(", "!", "$", "this", "->", "container", "->", "getDefinitions", "(", ")", ")", "{", "return", "''", ";", "}", "$", "code", "=", "\"services:\\n\"", ";", "foreach", "(", "$", "this", "->", "container", "->", "getDefinitions", "(", ")", "as", "$", "id", "=>", "$", "definition", ")", "{", "$", "code", ".=", "$", "this", "->", "addService", "(", "$", "id", ",", "$", "definition", ")", ";", "}", "$", "aliases", "=", "$", "this", "->", "container", "->", "getAliases", "(", ")", ";", "foreach", "(", "$", "aliases", "as", "$", "alias", "=>", "$", "id", ")", "{", "while", "(", "isset", "(", "$", "aliases", "[", "(", "string", ")", "$", "id", "]", ")", ")", "{", "$", "id", "=", "$", "aliases", "[", "(", "string", ")", "$", "id", "]", ";", "}", "$", "code", ".=", "$", "this", "->", "addServiceAlias", "(", "$", "alias", ",", "$", "id", ")", ";", "}", "return", "$", "code", ";", "}" ]
Adds services. @return string
[ "Adds", "services", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php#L192-L212
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
YamlDumper.prepareParameters
private function prepareParameters(array $parameters, $escape = true) { $filtered = array(); foreach ($parameters as $key => $value) { if (is_array($value)) { $value = $this->prepareParameters($value, $escape); } elseif ($value instanceof Reference || is_string($value) && 0 === strpos($value, '@')) { $value = '@'.$value; } $filtered[$key] = $value; } return $escape ? $this->escape($filtered) : $filtered; }
php
private function prepareParameters(array $parameters, $escape = true) { $filtered = array(); foreach ($parameters as $key => $value) { if (is_array($value)) { $value = $this->prepareParameters($value, $escape); } elseif ($value instanceof Reference || is_string($value) && 0 === strpos($value, '@')) { $value = '@'.$value; } $filtered[$key] = $value; } return $escape ? $this->escape($filtered) : $filtered; }
[ "private", "function", "prepareParameters", "(", "array", "$", "parameters", ",", "$", "escape", "=", "true", ")", "{", "$", "filtered", "=", "array", "(", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "prepareParameters", "(", "$", "value", ",", "$", "escape", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "Reference", "||", "is_string", "(", "$", "value", ")", "&&", "0", "===", "strpos", "(", "$", "value", ",", "'@'", ")", ")", "{", "$", "value", "=", "'@'", ".", "$", "value", ";", "}", "$", "filtered", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "escape", "?", "$", "this", "->", "escape", "(", "$", "filtered", ")", ":", "$", "filtered", ";", "}" ]
Prepares parameters. @param array $parameters @param bool $escape @return array
[ "Prepares", "parameters", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php#L345-L359
train
werx/core
src/Template.php
Template.render
public function render($view, array $data = null) { // Sanitize variables already in the template. foreach (get_object_vars($this) as $key => $value) { if (!in_array($key, $this->unguarded)) { $this->$key = $this->scrub($value); } } // Also sanitize any variables we are passing in to the template $data = $this->scrub($data); return parent::render($view, $data); }
php
public function render($view, array $data = null) { // Sanitize variables already in the template. foreach (get_object_vars($this) as $key => $value) { if (!in_array($key, $this->unguarded)) { $this->$key = $this->scrub($value); } } // Also sanitize any variables we are passing in to the template $data = $this->scrub($data); return parent::render($view, $data); }
[ "public", "function", "render", "(", "$", "view", ",", "array", "$", "data", "=", "null", ")", "{", "// Sanitize variables already in the template.", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "unguarded", ")", ")", "{", "$", "this", "->", "$", "key", "=", "$", "this", "->", "scrub", "(", "$", "value", ")", ";", "}", "}", "// Also sanitize any variables we are passing in to the template", "$", "data", "=", "$", "this", "->", "scrub", "(", "$", "data", ")", ";", "return", "parent", "::", "render", "(", "$", "view", ",", "$", "data", ")", ";", "}" ]
Return our compiled view. Sanitize the data before rendering. @param string $view @param array $data @return string
[ "Return", "our", "compiled", "view", ".", "Sanitize", "the", "data", "before", "rendering", "." ]
9ab7a9f7a8c02e1d41ca40301afada8129ea0a79
https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Template.php#L46-L59
train
werx/core
src/Template.php
Template.output
public function output($view, array $data = null) { $response = new Response($this->render($view, $data), Response::HTTP_OK, ['Content-Type' => 'text/html']); $response->send(); }
php
public function output($view, array $data = null) { $response = new Response($this->render($view, $data), Response::HTTP_OK, ['Content-Type' => 'text/html']); $response->send(); }
[ "public", "function", "output", "(", "$", "view", ",", "array", "$", "data", "=", "null", ")", "{", "$", "response", "=", "new", "Response", "(", "$", "this", "->", "render", "(", "$", "view", ",", "$", "data", ")", ",", "Response", "::", "HTTP_OK", ",", "[", "'Content-Type'", "=>", "'text/html'", "]", ")", ";", "$", "response", "->", "send", "(", ")", ";", "}" ]
Output the content instead of just render. @param $view @param array $data
[ "Output", "the", "content", "instead", "of", "just", "render", "." ]
9ab7a9f7a8c02e1d41ca40301afada8129ea0a79
https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Template.php#L66-L70
train
werx/core
src/Template.php
Template.scrub
public function scrub($var) { if (is_string($var)) { // Sanitize strings return $this->escape($var); } elseif (is_array($var)) { // Sanitize arrays foreach($var as $key => $value){ // casting key to string for the case of numeric indexed arrays // i.e. 0, 1, etc. b/c 0 == any string in php if (!in_array((string)$key, $this->unguarded)) { $var[$key] = $this->scrub($value); } } return $var; } elseif (is_object($var)) { // Sanitize objects $values = get_object_vars($var); foreach ($values as $key => $value) { $var->$key = $this->scrub($value); } return $var; } else { // Not sure what this is. null or bool? Just return it. return $var; } }
php
public function scrub($var) { if (is_string($var)) { // Sanitize strings return $this->escape($var); } elseif (is_array($var)) { // Sanitize arrays foreach($var as $key => $value){ // casting key to string for the case of numeric indexed arrays // i.e. 0, 1, etc. b/c 0 == any string in php if (!in_array((string)$key, $this->unguarded)) { $var[$key] = $this->scrub($value); } } return $var; } elseif (is_object($var)) { // Sanitize objects $values = get_object_vars($var); foreach ($values as $key => $value) { $var->$key = $this->scrub($value); } return $var; } else { // Not sure what this is. null or bool? Just return it. return $var; } }
[ "public", "function", "scrub", "(", "$", "var", ")", "{", "if", "(", "is_string", "(", "$", "var", ")", ")", "{", "// Sanitize strings", "return", "$", "this", "->", "escape", "(", "$", "var", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "var", ")", ")", "{", "// Sanitize arrays", "foreach", "(", "$", "var", "as", "$", "key", "=>", "$", "value", ")", "{", "// casting key to string for the case of numeric indexed arrays", "// i.e. 0, 1, etc. b/c 0 == any string in php", "if", "(", "!", "in_array", "(", "(", "string", ")", "$", "key", ",", "$", "this", "->", "unguarded", ")", ")", "{", "$", "var", "[", "$", "key", "]", "=", "$", "this", "->", "scrub", "(", "$", "value", ")", ";", "}", "}", "return", "$", "var", ";", "}", "elseif", "(", "is_object", "(", "$", "var", ")", ")", "{", "// Sanitize objects", "$", "values", "=", "get_object_vars", "(", "$", "var", ")", ";", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "var", "->", "$", "key", "=", "$", "this", "->", "scrub", "(", "$", "value", ")", ";", "}", "return", "$", "var", ";", "}", "else", "{", "// Not sure what this is. null or bool? Just return it.", "return", "$", "var", ";", "}", "}" ]
Recursively sanitize output. @param $var @return array
[ "Recursively", "sanitize", "output", "." ]
9ab7a9f7a8c02e1d41ca40301afada8129ea0a79
https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Template.php#L89-L119
train
werx/core
src/Template.php
Template.unguard
public function unguard($key) { if (is_array($key)) { foreach ($key as $k) { $this->unguard($k); } } else { $this->unguarded[] = $key; } }
php
public function unguard($key) { if (is_array($key)) { foreach ($key as $k) { $this->unguard($k); } } else { $this->unguarded[] = $key; } }
[ "public", "function", "unguard", "(", "$", "key", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "foreach", "(", "$", "key", "as", "$", "k", ")", "{", "$", "this", "->", "unguard", "(", "$", "k", ")", ";", "}", "}", "else", "{", "$", "this", "->", "unguarded", "[", "]", "=", "$", "key", ";", "}", "}" ]
Don't escape template variables with the specified name. @param $key
[ "Don", "t", "escape", "template", "variables", "with", "the", "specified", "name", "." ]
9ab7a9f7a8c02e1d41ca40301afada8129ea0a79
https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Template.php#L126-L135
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Rectangle.php
Rectangle.contains
public final function contains( Rectangle $rect ) : bool { return ( ( ( ( $this->point->x <= $rect->point->x ) && ( ( $rect->point->x + $rect->size->width ) <= ( $this->point->x + $this->size->width ) ) ) && ( $this->point->y <= $rect->point->y ) ) && ( ( $rect->point->y + $rect->size->height ) <= ( $this->point->y + $this->size->height ) ) ); }
php
public final function contains( Rectangle $rect ) : bool { return ( ( ( ( $this->point->x <= $rect->point->x ) && ( ( $rect->point->x + $rect->size->width ) <= ( $this->point->x + $this->size->width ) ) ) && ( $this->point->y <= $rect->point->y ) ) && ( ( $rect->point->y + $rect->size->height ) <= ( $this->point->y + $this->size->height ) ) ); }
[ "public", "final", "function", "contains", "(", "Rectangle", "$", "rect", ")", ":", "bool", "{", "return", "(", "(", "(", "(", "$", "this", "->", "point", "->", "x", "<=", "$", "rect", "->", "point", "->", "x", ")", "&&", "(", "(", "$", "rect", "->", "point", "->", "x", "+", "$", "rect", "->", "size", "->", "width", ")", "<=", "(", "$", "this", "->", "point", "->", "x", "+", "$", "this", "->", "size", "->", "width", ")", ")", ")", "&&", "(", "$", "this", "->", "point", "->", "y", "<=", "$", "rect", "->", "point", "->", "y", ")", ")", "&&", "(", "(", "$", "rect", "->", "point", "->", "y", "+", "$", "rect", "->", "size", "->", "height", ")", "<=", "(", "$", "this", "->", "point", "->", "y", "+", "$", "this", "->", "size", "->", "height", ")", ")", ")", ";", "}" ]
Returns, if the current rectangle contains the defined rectangle. @param \Beluga\Drawing\Rectangle $rect @return boolean
[ "Returns", "if", "the", "current", "rectangle", "contains", "the", "defined", "rectangle", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Rectangle.php#L125-L149
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Rectangle.php
Rectangle.containsLocation
public final function containsLocation( $xOrPoint, int $y = null ) : bool { $x = $xOrPoint; if ( $x instanceof Point ) { $y = $x->y; $x = $x->x; } else if ( \is_integer( $xOrPoint ) ) { $x = $xOrPoint; } else if ( TypeTool::IsInteger( $xOrPoint ) ) { $x = \intval( $xOrPoint ); } else { $x = 0; } if ( ! \is_int( $y ) ) { $y = \intval( $y ); } return ( ( ( ( $this->point->x <= $x ) && ( $x < ( $this->point->x + $this->size->width ) ) ) && ( $this->point->y <= $y ) ) && ( $y < ( $this->point->y + $this->size->height ) ) ); }
php
public final function containsLocation( $xOrPoint, int $y = null ) : bool { $x = $xOrPoint; if ( $x instanceof Point ) { $y = $x->y; $x = $x->x; } else if ( \is_integer( $xOrPoint ) ) { $x = $xOrPoint; } else if ( TypeTool::IsInteger( $xOrPoint ) ) { $x = \intval( $xOrPoint ); } else { $x = 0; } if ( ! \is_int( $y ) ) { $y = \intval( $y ); } return ( ( ( ( $this->point->x <= $x ) && ( $x < ( $this->point->x + $this->size->width ) ) ) && ( $this->point->y <= $y ) ) && ( $y < ( $this->point->y + $this->size->height ) ) ); }
[ "public", "final", "function", "containsLocation", "(", "$", "xOrPoint", ",", "int", "$", "y", "=", "null", ")", ":", "bool", "{", "$", "x", "=", "$", "xOrPoint", ";", "if", "(", "$", "x", "instanceof", "Point", ")", "{", "$", "y", "=", "$", "x", "->", "y", ";", "$", "x", "=", "$", "x", "->", "x", ";", "}", "else", "if", "(", "\\", "is_integer", "(", "$", "xOrPoint", ")", ")", "{", "$", "x", "=", "$", "xOrPoint", ";", "}", "else", "if", "(", "TypeTool", "::", "IsInteger", "(", "$", "xOrPoint", ")", ")", "{", "$", "x", "=", "\\", "intval", "(", "$", "xOrPoint", ")", ";", "}", "else", "{", "$", "x", "=", "0", ";", "}", "if", "(", "!", "\\", "is_int", "(", "$", "y", ")", ")", "{", "$", "y", "=", "\\", "intval", "(", "$", "y", ")", ";", "}", "return", "(", "(", "(", "(", "$", "this", "->", "point", "->", "x", "<=", "$", "x", ")", "&&", "(", "$", "x", "<", "(", "$", "this", "->", "point", "->", "x", "+", "$", "this", "->", "size", "->", "width", ")", ")", ")", "&&", "(", "$", "this", "->", "point", "->", "y", "<=", "$", "y", ")", ")", "&&", "(", "$", "y", "<", "(", "$", "this", "->", "point", "->", "y", "+", "$", "this", "->", "size", "->", "height", ")", ")", ")", ";", "}" ]
Returns, if the current rectangle contains the defined location. @param int|\Beluga\Drawing\Point $xOrPoint @param int|null $y @return boolean
[ "Returns", "if", "the", "current", "rectangle", "contains", "the", "defined", "location", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Rectangle.php#L158-L200
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Rectangle.php
Rectangle.containsSize
public final function containsSize( $widthOrSize, int $height = null ) : bool { $width = $widthOrSize; if ( $width instanceof Size ) { $height = $width->height; $width = $width->width; } else if ( \is_integer( $widthOrSize ) ) { $width = $widthOrSize; } else if ( TypeTool::IsInteger( $widthOrSize ) ) { $width = \intval( $widthOrSize ); } else { $width = 0; } if ( ! \is_int( $height ) ) { $height = \intval( $height ); } return $this->size->width >= $width && $this->size->height >= $height; }
php
public final function containsSize( $widthOrSize, int $height = null ) : bool { $width = $widthOrSize; if ( $width instanceof Size ) { $height = $width->height; $width = $width->width; } else if ( \is_integer( $widthOrSize ) ) { $width = $widthOrSize; } else if ( TypeTool::IsInteger( $widthOrSize ) ) { $width = \intval( $widthOrSize ); } else { $width = 0; } if ( ! \is_int( $height ) ) { $height = \intval( $height ); } return $this->size->width >= $width && $this->size->height >= $height; }
[ "public", "final", "function", "containsSize", "(", "$", "widthOrSize", ",", "int", "$", "height", "=", "null", ")", ":", "bool", "{", "$", "width", "=", "$", "widthOrSize", ";", "if", "(", "$", "width", "instanceof", "Size", ")", "{", "$", "height", "=", "$", "width", "->", "height", ";", "$", "width", "=", "$", "width", "->", "width", ";", "}", "else", "if", "(", "\\", "is_integer", "(", "$", "widthOrSize", ")", ")", "{", "$", "width", "=", "$", "widthOrSize", ";", "}", "else", "if", "(", "TypeTool", "::", "IsInteger", "(", "$", "widthOrSize", ")", ")", "{", "$", "width", "=", "\\", "intval", "(", "$", "widthOrSize", ")", ";", "}", "else", "{", "$", "width", "=", "0", ";", "}", "if", "(", "!", "\\", "is_int", "(", "$", "height", ")", ")", "{", "$", "height", "=", "\\", "intval", "(", "$", "height", ")", ";", "}", "return", "$", "this", "->", "size", "->", "width", ">=", "$", "width", "&&", "$", "this", "->", "size", "->", "height", ">=", "$", "height", ";", "}" ]
Returns, if the current rectangle contains the defined Size. @param \Beluga\Drawing\Size|integer $widthOrSize @param integer $height @return boolean
[ "Returns", "if", "the", "current", "rectangle", "contains", "the", "defined", "Size", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Rectangle.php#L209-L242
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Rectangle.php
Rectangle.getClone
public function getClone() : Rectangle { return new Rectangle( new Point( $this->point->x , $this->point->y ), new Size ( $this->size->width, $this->size->height ) ); }
php
public function getClone() : Rectangle { return new Rectangle( new Point( $this->point->x , $this->point->y ), new Size ( $this->size->width, $this->size->height ) ); }
[ "public", "function", "getClone", "(", ")", ":", "Rectangle", "{", "return", "new", "Rectangle", "(", "new", "Point", "(", "$", "this", "->", "point", "->", "x", ",", "$", "this", "->", "point", "->", "y", ")", ",", "new", "Size", "(", "$", "this", "->", "size", "->", "width", ",", "$", "this", "->", "size", "->", "height", ")", ")", ";", "}" ]
Gets a clone of the current instance. @return \Beluga\Drawing\Rectangle
[ "Gets", "a", "clone", "of", "the", "current", "instance", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Rectangle.php#L249-L257
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Rectangle.php
Rectangle.toArray
public function toArray() : array { return [ 'x' => $this->point->x, 'y' => $this->point->y, 'width' => $this->size->width, 'height' => $this->size->height ]; }
php
public function toArray() : array { return [ 'x' => $this->point->x, 'y' => $this->point->y, 'width' => $this->size->width, 'height' => $this->size->height ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'x'", "=>", "$", "this", "->", "point", "->", "x", ",", "'y'", "=>", "$", "this", "->", "point", "->", "y", ",", "'width'", "=>", "$", "this", "->", "size", "->", "width", ",", "'height'", "=>", "$", "this", "->", "size", "->", "height", "]", ";", "}" ]
Returns a array with all instance data. Used array keys are 'x', 'y', 'width' and 'height'. @return array
[ "Returns", "a", "array", "with", "all", "instance", "data", ".", "Used", "array", "keys", "are", "x", "y", "width", "and", "height", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Rectangle.php#L401-L411
train
kitpages/KitpagesStepBundle
Proxy/ProxyGenerator.php
ProxyGenerator.generateProcessProxy
public function generateProcessProxy($arguments = array()) { if (!$this->isProxyLoaded()) { $this->loadProxyClass(); } $reflect = new ReflectionClass($this->proxyClass); return $reflect->newInstanceArgs($arguments); }
php
public function generateProcessProxy($arguments = array()) { if (!$this->isProxyLoaded()) { $this->loadProxyClass(); } $reflect = new ReflectionClass($this->proxyClass); return $reflect->newInstanceArgs($arguments); }
[ "public", "function", "generateProcessProxy", "(", "$", "arguments", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "isProxyLoaded", "(", ")", ")", "{", "$", "this", "->", "loadProxyClass", "(", ")", ";", "}", "$", "reflect", "=", "new", "ReflectionClass", "(", "$", "this", "->", "proxyClass", ")", ";", "return", "$", "reflect", "->", "newInstanceArgs", "(", "$", "arguments", ")", ";", "}" ]
Instantiate and returns a step proxy. @param array $arguments (optionnal) The arguments to pass to the constructor of the Proxy Class if needed @return mixed The instanciated Proxy
[ "Instantiate", "and", "returns", "a", "step", "proxy", "." ]
2ac421c8364d41b87b515a91a94513f3d1ab20c1
https://github.com/kitpages/KitpagesStepBundle/blob/2ac421c8364d41b87b515a91a94513f3d1ab20c1/Proxy/ProxyGenerator.php#L84-L93
train
kitpages/KitpagesStepBundle
Proxy/ProxyGenerator.php
ProxyGenerator.writeProxyClassCache
public function writeProxyClassCache() { $parameters = array( 'proxyNameSpace' => $this->getProxyNameSpace(), 'proxyClassName' => $this->proxyClass, 'shortClassName' => $this->getShortClassName(), 'originalClassName' => $this->class, ); $proxyClassDefinition = $this->render($this->template, $parameters); $this->fs->dumpFile($this->proxyClassCacheFilename, $proxyClassDefinition); return $this; }
php
public function writeProxyClassCache() { $parameters = array( 'proxyNameSpace' => $this->getProxyNameSpace(), 'proxyClassName' => $this->proxyClass, 'shortClassName' => $this->getShortClassName(), 'originalClassName' => $this->class, ); $proxyClassDefinition = $this->render($this->template, $parameters); $this->fs->dumpFile($this->proxyClassCacheFilename, $proxyClassDefinition); return $this; }
[ "public", "function", "writeProxyClassCache", "(", ")", "{", "$", "parameters", "=", "array", "(", "'proxyNameSpace'", "=>", "$", "this", "->", "getProxyNameSpace", "(", ")", ",", "'proxyClassName'", "=>", "$", "this", "->", "proxyClass", ",", "'shortClassName'", "=>", "$", "this", "->", "getShortClassName", "(", ")", ",", "'originalClassName'", "=>", "$", "this", "->", "class", ",", ")", ";", "$", "proxyClassDefinition", "=", "$", "this", "->", "render", "(", "$", "this", "->", "template", ",", "$", "parameters", ")", ";", "$", "this", "->", "fs", "->", "dumpFile", "(", "$", "this", "->", "proxyClassCacheFilename", ",", "$", "proxyClassDefinition", ")", ";", "return", "$", "this", ";", "}" ]
Writes the proxy class definition into a cache file. @return $this
[ "Writes", "the", "proxy", "class", "definition", "into", "a", "cache", "file", "." ]
2ac421c8364d41b87b515a91a94513f3d1ab20c1
https://github.com/kitpages/KitpagesStepBundle/blob/2ac421c8364d41b87b515a91a94513f3d1ab20c1/Proxy/ProxyGenerator.php#L100-L112
train
kitpages/KitpagesStepBundle
Proxy/ProxyGenerator.php
ProxyGenerator.loadProxyClass
public function loadProxyClass() { if (!$this->cacheFileExists() || $this->debug) { $this->writeProxyClassCache(); } if (!$this->isProxyLoaded()) { require $this->proxyClassCacheFilename; } return $this; }
php
public function loadProxyClass() { if (!$this->cacheFileExists() || $this->debug) { $this->writeProxyClassCache(); } if (!$this->isProxyLoaded()) { require $this->proxyClassCacheFilename; } return $this; }
[ "public", "function", "loadProxyClass", "(", ")", "{", "if", "(", "!", "$", "this", "->", "cacheFileExists", "(", ")", "||", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "writeProxyClassCache", "(", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isProxyLoaded", "(", ")", ")", "{", "require", "$", "this", "->", "proxyClassCacheFilename", ";", "}", "return", "$", "this", ";", "}" ]
Loads the proxy class for usage. @return self
[ "Loads", "the", "proxy", "class", "for", "usage", "." ]
2ac421c8364d41b87b515a91a94513f3d1ab20c1
https://github.com/kitpages/KitpagesStepBundle/blob/2ac421c8364d41b87b515a91a94513f3d1ab20c1/Proxy/ProxyGenerator.php#L119-L130
train
MatiasNAmendola/slimpower-slim
src/DownloadView.php
DownloadView.render
protected function render($filepath, $data = NULL) { if (!file_exists($filepath)) { throw new \RuntimeException("View cannot render `$filepath` because the template does not exist"); } $data = $this->getData(); $contentType = 'application/octet-stream'; if (isset($data["CONTENT_TYPE"])) { $cType = $data["CONTENT_TYPE"]; if (!empty($cType)) { $contentType = $cType; } } $filename = basename($filepath); if (isset($data["FILENAME"])) { $fname = $data["FILENAME"]; if (!empty($fname)) { $filename = $fname; } } header("HTTP/1.1 200 OK"); header("Content-type: " . $contentType); header('Content-Transfer-Encoding: binary'); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); header("Content-Length: " . filesize($filepath)); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); ob_clean(); ob_start(); readfile($filepath); return ob_get_clean(); }
php
protected function render($filepath, $data = NULL) { if (!file_exists($filepath)) { throw new \RuntimeException("View cannot render `$filepath` because the template does not exist"); } $data = $this->getData(); $contentType = 'application/octet-stream'; if (isset($data["CONTENT_TYPE"])) { $cType = $data["CONTENT_TYPE"]; if (!empty($cType)) { $contentType = $cType; } } $filename = basename($filepath); if (isset($data["FILENAME"])) { $fname = $data["FILENAME"]; if (!empty($fname)) { $filename = $fname; } } header("HTTP/1.1 200 OK"); header("Content-type: " . $contentType); header('Content-Transfer-Encoding: binary'); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); header("Content-Length: " . filesize($filepath)); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); ob_clean(); ob_start(); readfile($filepath); return ob_get_clean(); }
[ "protected", "function", "render", "(", "$", "filepath", ",", "$", "data", "=", "NULL", ")", "{", "if", "(", "!", "file_exists", "(", "$", "filepath", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"View cannot render `$filepath` because the template does not exist\"", ")", ";", "}", "$", "data", "=", "$", "this", "->", "getData", "(", ")", ";", "$", "contentType", "=", "'application/octet-stream'", ";", "if", "(", "isset", "(", "$", "data", "[", "\"CONTENT_TYPE\"", "]", ")", ")", "{", "$", "cType", "=", "$", "data", "[", "\"CONTENT_TYPE\"", "]", ";", "if", "(", "!", "empty", "(", "$", "cType", ")", ")", "{", "$", "contentType", "=", "$", "cType", ";", "}", "}", "$", "filename", "=", "basename", "(", "$", "filepath", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "\"FILENAME\"", "]", ")", ")", "{", "$", "fname", "=", "$", "data", "[", "\"FILENAME\"", "]", ";", "if", "(", "!", "empty", "(", "$", "fname", ")", ")", "{", "$", "filename", "=", "$", "fname", ";", "}", "}", "header", "(", "\"HTTP/1.1 200 OK\"", ")", ";", "header", "(", "\"Content-type: \"", ".", "$", "contentType", ")", ";", "header", "(", "'Content-Transfer-Encoding: binary'", ")", ";", "header", "(", "\"Content-Disposition: attachment; filename=\\\"\"", ".", "$", "filename", ".", "\"\\\"\"", ")", ";", "header", "(", "\"Content-Length: \"", ".", "filesize", "(", "$", "filepath", ")", ")", ";", "header", "(", "\"Expires: 0\"", ")", ";", "header", "(", "\"Cache-Control: must-revalidate, post-check=0, pre-check=0\"", ")", ";", "header", "(", "\"Pragma: public\"", ")", ";", "ob_clean", "(", ")", ";", "ob_start", "(", ")", ";", "readfile", "(", "$", "filepath", ")", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Render -> Download file. @param string $filepath Filepath @param array|null $data @return void @throws \RuntimeException
[ "Render", "-", ">", "Download", "file", "." ]
c78ebbd4124d75ec82fe19b6dd62504da097fd15
https://github.com/MatiasNAmendola/slimpower-slim/blob/c78ebbd4124d75ec82fe19b6dd62504da097fd15/src/DownloadView.php#L43-L82
train
dms-org/common.structure
src/FileSystem/RelativePathCalculator.php
RelativePathCalculator.getRelativePath
public function getRelativePath(string $fromDir, string $to) : string { if (strpos($to, 'data://') === 0) { return $to; } list($fromStreamWrapper, $fromDirPath) = $this->splitStreamWrapperAndPath($fromDir); list($toStreamWrapper, $toPath) = $this->splitStreamWrapperAndPath($to); if ($fromStreamWrapper !== $toStreamWrapper) { return $to; } // some compatibility fixes for Windows paths $fromDirPath = str_replace('\\', '/', $fromDirPath); $toPath = str_replace('\\', '/', $toPath); if (substr($fromDirPath, -1) !== '/') { $fromDirPath .= '/'; } // Optimize common case where $to is a sub path of $from if (strpos($toPath, $fromDirPath) === 0) { return PathHelper::normalize(substr($toPath, strlen($fromDirPath)) ?: './'); } $fromDirPath = explode('/', $fromDirPath); $toPath = explode('/', $toPath); $relPath = $toPath; foreach ($fromDirPath as $depth => $dir) { // find first non-matching dir if (isset($toPath[$depth]) && $dir === $toPath[$depth]) { // ignore this directory array_shift($relPath); } else { // get number of remaining dirs to $from $remaining = count($fromDirPath) - $depth; if ($remaining > 1) { // add traversals up to first matching dir $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); break; } else { $relPath[0] = './' . (isset($relPath[0]) ? $relPath[0] : ''); } } } $relPath = implode('/', $relPath); return PathHelper::normalize( $relPath === '..' || $relPath === '.' ? $relPath . '/' : $relPath ); }
php
public function getRelativePath(string $fromDir, string $to) : string { if (strpos($to, 'data://') === 0) { return $to; } list($fromStreamWrapper, $fromDirPath) = $this->splitStreamWrapperAndPath($fromDir); list($toStreamWrapper, $toPath) = $this->splitStreamWrapperAndPath($to); if ($fromStreamWrapper !== $toStreamWrapper) { return $to; } // some compatibility fixes for Windows paths $fromDirPath = str_replace('\\', '/', $fromDirPath); $toPath = str_replace('\\', '/', $toPath); if (substr($fromDirPath, -1) !== '/') { $fromDirPath .= '/'; } // Optimize common case where $to is a sub path of $from if (strpos($toPath, $fromDirPath) === 0) { return PathHelper::normalize(substr($toPath, strlen($fromDirPath)) ?: './'); } $fromDirPath = explode('/', $fromDirPath); $toPath = explode('/', $toPath); $relPath = $toPath; foreach ($fromDirPath as $depth => $dir) { // find first non-matching dir if (isset($toPath[$depth]) && $dir === $toPath[$depth]) { // ignore this directory array_shift($relPath); } else { // get number of remaining dirs to $from $remaining = count($fromDirPath) - $depth; if ($remaining > 1) { // add traversals up to first matching dir $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); break; } else { $relPath[0] = './' . (isset($relPath[0]) ? $relPath[0] : ''); } } } $relPath = implode('/', $relPath); return PathHelper::normalize( $relPath === '..' || $relPath === '.' ? $relPath . '/' : $relPath ); }
[ "public", "function", "getRelativePath", "(", "string", "$", "fromDir", ",", "string", "$", "to", ")", ":", "string", "{", "if", "(", "strpos", "(", "$", "to", ",", "'data://'", ")", "===", "0", ")", "{", "return", "$", "to", ";", "}", "list", "(", "$", "fromStreamWrapper", ",", "$", "fromDirPath", ")", "=", "$", "this", "->", "splitStreamWrapperAndPath", "(", "$", "fromDir", ")", ";", "list", "(", "$", "toStreamWrapper", ",", "$", "toPath", ")", "=", "$", "this", "->", "splitStreamWrapperAndPath", "(", "$", "to", ")", ";", "if", "(", "$", "fromStreamWrapper", "!==", "$", "toStreamWrapper", ")", "{", "return", "$", "to", ";", "}", "// some compatibility fixes for Windows paths", "$", "fromDirPath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "fromDirPath", ")", ";", "$", "toPath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "toPath", ")", ";", "if", "(", "substr", "(", "$", "fromDirPath", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "fromDirPath", ".=", "'/'", ";", "}", "// Optimize common case where $to is a sub path of $from", "if", "(", "strpos", "(", "$", "toPath", ",", "$", "fromDirPath", ")", "===", "0", ")", "{", "return", "PathHelper", "::", "normalize", "(", "substr", "(", "$", "toPath", ",", "strlen", "(", "$", "fromDirPath", ")", ")", "?", ":", "'./'", ")", ";", "}", "$", "fromDirPath", "=", "explode", "(", "'/'", ",", "$", "fromDirPath", ")", ";", "$", "toPath", "=", "explode", "(", "'/'", ",", "$", "toPath", ")", ";", "$", "relPath", "=", "$", "toPath", ";", "foreach", "(", "$", "fromDirPath", "as", "$", "depth", "=>", "$", "dir", ")", "{", "// find first non-matching dir", "if", "(", "isset", "(", "$", "toPath", "[", "$", "depth", "]", ")", "&&", "$", "dir", "===", "$", "toPath", "[", "$", "depth", "]", ")", "{", "// ignore this directory", "array_shift", "(", "$", "relPath", ")", ";", "}", "else", "{", "// get number of remaining dirs to $from", "$", "remaining", "=", "count", "(", "$", "fromDirPath", ")", "-", "$", "depth", ";", "if", "(", "$", "remaining", ">", "1", ")", "{", "// add traversals up to first matching dir", "$", "padLength", "=", "(", "count", "(", "$", "relPath", ")", "+", "$", "remaining", "-", "1", ")", "*", "-", "1", ";", "$", "relPath", "=", "array_pad", "(", "$", "relPath", ",", "$", "padLength", ",", "'..'", ")", ";", "break", ";", "}", "else", "{", "$", "relPath", "[", "0", "]", "=", "'./'", ".", "(", "isset", "(", "$", "relPath", "[", "0", "]", ")", "?", "$", "relPath", "[", "0", "]", ":", "''", ")", ";", "}", "}", "}", "$", "relPath", "=", "implode", "(", "'/'", ",", "$", "relPath", ")", ";", "return", "PathHelper", "::", "normalize", "(", "$", "relPath", "===", "'..'", "||", "$", "relPath", "===", "'.'", "?", "$", "relPath", ".", "'/'", ":", "$", "relPath", ")", ";", "}" ]
Gets the relative path from the first path to the second path. @param string $fromDir @param string $to @return string @throws InvalidArgumentException
[ "Gets", "the", "relative", "path", "from", "the", "first", "path", "to", "the", "second", "path", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FileSystem/RelativePathCalculator.php#L27-L83
train
dms-org/common.structure
src/FileSystem/RelativePathCalculator.php
RelativePathCalculator.resolveRelativePath
public function resolveRelativePath(string $basePath, string $relativePath) : string { if (strpos($relativePath, 'data://') === 0) { return $relativePath; } list($basePathStreamWrapper, $basePath) = $this->splitStreamWrapperAndPath($basePath); list($relativeStreamWrapper, $relativePathWithoutStreamWrapper) = $this->splitStreamWrapperAndPath($relativePath); $isAbsolutePath = $relativeStreamWrapper !== null; if ($isAbsolutePath) { return $relativePath; } else { $relativePath = $relativePathWithoutStreamWrapper; } $basePath = str_replace('\\', '/', $basePath); $relativePath = str_replace('\\', '/', $relativePath); if (substr($basePath, -1) !== '/') { $basePath .= '/'; } if (strpos($relativePath, '.') === false) { return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '') . PathHelper::normalize(str_replace('//', '/', $basePath . '/' . $relativePath)); } $parts = explode('/', $basePath); $relativeParts = explode('/', trim($relativePath, '/')); $isDrivePath = substr($basePath, 1, 1) === ':'; $precedingSlash = $basePathStreamWrapper || $isDrivePath ? '' : '/'; $trailingSlash = !$basePathStreamWrapper && substr($relativePath, -1) === '/' ? '/' : ''; foreach ($parts as $key => $part) { if ($part === '') { unset($parts[$key]); } } foreach ($relativeParts as $part) { if ($part === '.') { continue; } elseif ($part === '..') { array_pop($parts); } elseif ($part !== '') { $parts[] = $part; } } return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '') . PathHelper::normalize($precedingSlash . implode('/', $parts) . ($parts ? $trailingSlash : '')); }
php
public function resolveRelativePath(string $basePath, string $relativePath) : string { if (strpos($relativePath, 'data://') === 0) { return $relativePath; } list($basePathStreamWrapper, $basePath) = $this->splitStreamWrapperAndPath($basePath); list($relativeStreamWrapper, $relativePathWithoutStreamWrapper) = $this->splitStreamWrapperAndPath($relativePath); $isAbsolutePath = $relativeStreamWrapper !== null; if ($isAbsolutePath) { return $relativePath; } else { $relativePath = $relativePathWithoutStreamWrapper; } $basePath = str_replace('\\', '/', $basePath); $relativePath = str_replace('\\', '/', $relativePath); if (substr($basePath, -1) !== '/') { $basePath .= '/'; } if (strpos($relativePath, '.') === false) { return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '') . PathHelper::normalize(str_replace('//', '/', $basePath . '/' . $relativePath)); } $parts = explode('/', $basePath); $relativeParts = explode('/', trim($relativePath, '/')); $isDrivePath = substr($basePath, 1, 1) === ':'; $precedingSlash = $basePathStreamWrapper || $isDrivePath ? '' : '/'; $trailingSlash = !$basePathStreamWrapper && substr($relativePath, -1) === '/' ? '/' : ''; foreach ($parts as $key => $part) { if ($part === '') { unset($parts[$key]); } } foreach ($relativeParts as $part) { if ($part === '.') { continue; } elseif ($part === '..') { array_pop($parts); } elseif ($part !== '') { $parts[] = $part; } } return ($basePathStreamWrapper ? $basePathStreamWrapper . '://' : '') . PathHelper::normalize($precedingSlash . implode('/', $parts) . ($parts ? $trailingSlash : '')); }
[ "public", "function", "resolveRelativePath", "(", "string", "$", "basePath", ",", "string", "$", "relativePath", ")", ":", "string", "{", "if", "(", "strpos", "(", "$", "relativePath", ",", "'data://'", ")", "===", "0", ")", "{", "return", "$", "relativePath", ";", "}", "list", "(", "$", "basePathStreamWrapper", ",", "$", "basePath", ")", "=", "$", "this", "->", "splitStreamWrapperAndPath", "(", "$", "basePath", ")", ";", "list", "(", "$", "relativeStreamWrapper", ",", "$", "relativePathWithoutStreamWrapper", ")", "=", "$", "this", "->", "splitStreamWrapperAndPath", "(", "$", "relativePath", ")", ";", "$", "isAbsolutePath", "=", "$", "relativeStreamWrapper", "!==", "null", ";", "if", "(", "$", "isAbsolutePath", ")", "{", "return", "$", "relativePath", ";", "}", "else", "{", "$", "relativePath", "=", "$", "relativePathWithoutStreamWrapper", ";", "}", "$", "basePath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "basePath", ")", ";", "$", "relativePath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "relativePath", ")", ";", "if", "(", "substr", "(", "$", "basePath", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "basePath", ".=", "'/'", ";", "}", "if", "(", "strpos", "(", "$", "relativePath", ",", "'.'", ")", "===", "false", ")", "{", "return", "(", "$", "basePathStreamWrapper", "?", "$", "basePathStreamWrapper", ".", "'://'", ":", "''", ")", ".", "PathHelper", "::", "normalize", "(", "str_replace", "(", "'//'", ",", "'/'", ",", "$", "basePath", ".", "'/'", ".", "$", "relativePath", ")", ")", ";", "}", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "basePath", ")", ";", "$", "relativeParts", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "relativePath", ",", "'/'", ")", ")", ";", "$", "isDrivePath", "=", "substr", "(", "$", "basePath", ",", "1", ",", "1", ")", "===", "':'", ";", "$", "precedingSlash", "=", "$", "basePathStreamWrapper", "||", "$", "isDrivePath", "?", "''", ":", "'/'", ";", "$", "trailingSlash", "=", "!", "$", "basePathStreamWrapper", "&&", "substr", "(", "$", "relativePath", ",", "-", "1", ")", "===", "'/'", "?", "'/'", ":", "''", ";", "foreach", "(", "$", "parts", "as", "$", "key", "=>", "$", "part", ")", "{", "if", "(", "$", "part", "===", "''", ")", "{", "unset", "(", "$", "parts", "[", "$", "key", "]", ")", ";", "}", "}", "foreach", "(", "$", "relativeParts", "as", "$", "part", ")", "{", "if", "(", "$", "part", "===", "'.'", ")", "{", "continue", ";", "}", "elseif", "(", "$", "part", "===", "'..'", ")", "{", "array_pop", "(", "$", "parts", ")", ";", "}", "elseif", "(", "$", "part", "!==", "''", ")", "{", "$", "parts", "[", "]", "=", "$", "part", ";", "}", "}", "return", "(", "$", "basePathStreamWrapper", "?", "$", "basePathStreamWrapper", ".", "'://'", ":", "''", ")", ".", "PathHelper", "::", "normalize", "(", "$", "precedingSlash", ".", "implode", "(", "'/'", ",", "$", "parts", ")", ".", "(", "$", "parts", "?", "$", "trailingSlash", ":", "''", ")", ")", ";", "}" ]
Combines the two paths and resolves '..' and '.' relative traversals. @param string $basePath @param string $relativePath @return string
[ "Combines", "the", "two", "paths", "and", "resolves", "..", "and", ".", "relative", "traversals", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FileSystem/RelativePathCalculator.php#L93-L146
train
gocom/rah_cache_minify
rah_cache_minify.php
Rah_Cache_Minify.isHTML
protected function isHTML() { if (function_exists('headers_list') && $headers = headers_list()) { foreach ((array) $headers as $header) { $header = strtolower($header); if (strpos($header, 'content-type:') === 0 && !strpos($header, 'text/html')) { return false; } } } return true; }
php
protected function isHTML() { if (function_exists('headers_list') && $headers = headers_list()) { foreach ((array) $headers as $header) { $header = strtolower($header); if (strpos($header, 'content-type:') === 0 && !strpos($header, 'text/html')) { return false; } } } return true; }
[ "protected", "function", "isHTML", "(", ")", "{", "if", "(", "function_exists", "(", "'headers_list'", ")", "&&", "$", "headers", "=", "headers_list", "(", ")", ")", "{", "foreach", "(", "(", "array", ")", "$", "headers", "as", "$", "header", ")", "{", "$", "header", "=", "strtolower", "(", "$", "header", ")", ";", "if", "(", "strpos", "(", "$", "header", ",", "'content-type:'", ")", "===", "0", "&&", "!", "strpos", "(", "$", "header", ",", "'text/html'", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Whether the page is a plain old HTML. @return bool
[ "Whether", "the", "page", "is", "a", "plain", "old", "HTML", "." ]
dc5fc02b74213f65fddb2de2a2eb6e30378e5014
https://github.com/gocom/rah_cache_minify/blob/dc5fc02b74213f65fddb2de2a2eb6e30378e5014/rah_cache_minify.php#L48-L64
train
gocom/rah_cache_minify
rah_cache_minify.php
Rah_Cache_Minify.minify
public function minify() { if ($this->isHTML() && class_exists('Minify_HTML')) { $page = ob_get_contents(); ob_clean(); echo Minify_HTML::minify($page); } }
php
public function minify() { if ($this->isHTML() && class_exists('Minify_HTML')) { $page = ob_get_contents(); ob_clean(); echo Minify_HTML::minify($page); } }
[ "public", "function", "minify", "(", ")", "{", "if", "(", "$", "this", "->", "isHTML", "(", ")", "&&", "class_exists", "(", "'Minify_HTML'", ")", ")", "{", "$", "page", "=", "ob_get_contents", "(", ")", ";", "ob_clean", "(", ")", ";", "echo", "Minify_HTML", "::", "minify", "(", "$", "page", ")", ";", "}", "}" ]
Minifies the HTML page. Replaces output buffer with minified HTML.
[ "Minifies", "the", "HTML", "page", "." ]
dc5fc02b74213f65fddb2de2a2eb6e30378e5014
https://github.com/gocom/rah_cache_minify/blob/dc5fc02b74213f65fddb2de2a2eb6e30378e5014/rah_cache_minify.php#L72-L80
train
ibonly/Potato-ORM
src/Database/DBConfig.php
DBConfig.pgsqlConnectionString
protected function pgsqlConnectionString() { return $this->driver . ':host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';user=' . $this->user . ';password=' . $this->password; }
php
protected function pgsqlConnectionString() { return $this->driver . ':host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';user=' . $this->user . ';password=' . $this->password; }
[ "protected", "function", "pgsqlConnectionString", "(", ")", "{", "return", "$", "this", "->", "driver", ".", "':host='", ".", "$", "this", "->", "host", ".", "';port='", ".", "$", "this", "->", "port", ".", "';dbname='", ".", "$", "this", "->", "dbname", ".", "';user='", ".", "$", "this", "->", "user", ".", "';password='", ".", "$", "this", "->", "password", ";", "}" ]
pgsqlConnectionString Postgres connection string @return string
[ "pgsqlConnectionString", "Postgres", "connection", "string" ]
644962a99e1c0191b732d7729cd466d52c5d8652
https://github.com/ibonly/Potato-ORM/blob/644962a99e1c0191b732d7729cd466d52c5d8652/src/Database/DBConfig.php#L64-L67
train
phossa/phossa-shared
src/Phossa/Shared/Pattern/SetPropertiesTrait.php
SetPropertiesTrait.setProperties
protected function setProperties(array $properties = []) { foreach ($properties as $name => $value) { // set property if (property_exists($this, $name)) { $this->$name = $value; // unknown property found } else { trigger_error( sprintf( 'unknown property "%s" for "%s"', $name, get_class($this) ), E_USER_WARNING ); } } }
php
protected function setProperties(array $properties = []) { foreach ($properties as $name => $value) { // set property if (property_exists($this, $name)) { $this->$name = $value; // unknown property found } else { trigger_error( sprintf( 'unknown property "%s" for "%s"', $name, get_class($this) ), E_USER_WARNING ); } } }
[ "protected", "function", "setProperties", "(", "array", "$", "properties", "=", "[", "]", ")", "{", "foreach", "(", "$", "properties", "as", "$", "name", "=>", "$", "value", ")", "{", "// set property", "if", "(", "property_exists", "(", "$", "this", ",", "$", "name", ")", ")", "{", "$", "this", "->", "$", "name", "=", "$", "value", ";", "// unknown property found", "}", "else", "{", "trigger_error", "(", "sprintf", "(", "'unknown property \"%s\" for \"%s\"'", ",", "$", "name", ",", "get_class", "(", "$", "this", ")", ")", ",", "E_USER_WARNING", ")", ";", "}", "}", "}" ]
Set properties, trigger warning if unknown property found @param array $properties (optional) object properties @access protected
[ "Set", "properties", "trigger", "warning", "if", "unknown", "property", "found" ]
fcf140c09e94c3a441ee4e285de0b4c18cb6504b
https://github.com/phossa/phossa-shared/blob/fcf140c09e94c3a441ee4e285de0b4c18cb6504b/src/Phossa/Shared/Pattern/SetPropertiesTrait.php#L35-L54
train
nicodevs/laito
src/Laito/App.php
App.config
public function config($name, $value = null) { // Check for massive assignaments if (is_array($name)) { foreach ($name as $key => $value) { $this->config($key, $value); } return true; } // Assign a new value if (isset($value)) { $this->container['settings'][$name] = $value; } // Abort if the configuration key does not exist if (!isset($this->container['settings'][$name])) { throw new \Exception('Configuration key not defined: ' . $name, 500); } // Return value return $this->container['settings'][$name]; }
php
public function config($name, $value = null) { // Check for massive assignaments if (is_array($name)) { foreach ($name as $key => $value) { $this->config($key, $value); } return true; } // Assign a new value if (isset($value)) { $this->container['settings'][$name] = $value; } // Abort if the configuration key does not exist if (!isset($this->container['settings'][$name])) { throw new \Exception('Configuration key not defined: ' . $name, 500); } // Return value return $this->container['settings'][$name]; }
[ "public", "function", "config", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "// Check for massive assignaments", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "foreach", "(", "$", "name", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "config", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "true", ";", "}", "// Assign a new value", "if", "(", "isset", "(", "$", "value", ")", ")", "{", "$", "this", "->", "container", "[", "'settings'", "]", "[", "$", "name", "]", "=", "$", "value", ";", "}", "// Abort if the configuration key does not exist", "if", "(", "!", "isset", "(", "$", "this", "->", "container", "[", "'settings'", "]", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Configuration key not defined: '", ".", "$", "name", ",", "500", ")", ";", "}", "// Return value", "return", "$", "this", "->", "container", "[", "'settings'", "]", "[", "$", "name", "]", ";", "}" ]
Configure application settings @param string|array $name Setting to set or retrieve @param mixed $value If passed, value to apply on the setting @return mixed Value of a setting
[ "Configure", "application", "settings" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L99-L121
train
nicodevs/laito
src/Laito/App.php
App.make
public function make($className) { // Create a reflection to access the class properties $reflection = new \ReflectionClass($className); // If the class has no constructor, just return a new instance $constructor = $reflection->getConstructor(); if (is_null($constructor)) { return new $className; } // Or get the constructor parameters and instance dependencies $dependencies = []; $parameters = $reflection->getConstructor()->getParameters(); foreach ($parameters as $param) { $class = $param->getClass(); if ($class && $class->getName() === 'Laito\App') { // If the dependency is the app itself, inject the current instance $dependencies[] = $this; } else { // Otherwise, inject the instantiated dependency or a null value $dependencies[] = $class? $this->make($class->name) : 'NULL'; } } // Return the class instance $instance = $reflection->newInstanceArgs($dependencies); // If the class has a boot method, run it if (method_exists($instance, 'boot')) { $instance->boot(); } // Return instance return $instance; }
php
public function make($className) { // Create a reflection to access the class properties $reflection = new \ReflectionClass($className); // If the class has no constructor, just return a new instance $constructor = $reflection->getConstructor(); if (is_null($constructor)) { return new $className; } // Or get the constructor parameters and instance dependencies $dependencies = []; $parameters = $reflection->getConstructor()->getParameters(); foreach ($parameters as $param) { $class = $param->getClass(); if ($class && $class->getName() === 'Laito\App') { // If the dependency is the app itself, inject the current instance $dependencies[] = $this; } else { // Otherwise, inject the instantiated dependency or a null value $dependencies[] = $class? $this->make($class->name) : 'NULL'; } } // Return the class instance $instance = $reflection->newInstanceArgs($dependencies); // If the class has a boot method, run it if (method_exists($instance, 'boot')) { $instance->boot(); } // Return instance return $instance; }
[ "public", "function", "make", "(", "$", "className", ")", "{", "// Create a reflection to access the class properties", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "// If the class has no constructor, just return a new instance", "$", "constructor", "=", "$", "reflection", "->", "getConstructor", "(", ")", ";", "if", "(", "is_null", "(", "$", "constructor", ")", ")", "{", "return", "new", "$", "className", ";", "}", "// Or get the constructor parameters and instance dependencies", "$", "dependencies", "=", "[", "]", ";", "$", "parameters", "=", "$", "reflection", "->", "getConstructor", "(", ")", "->", "getParameters", "(", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "param", ")", "{", "$", "class", "=", "$", "param", "->", "getClass", "(", ")", ";", "if", "(", "$", "class", "&&", "$", "class", "->", "getName", "(", ")", "===", "'Laito\\App'", ")", "{", "// If the dependency is the app itself, inject the current instance", "$", "dependencies", "[", "]", "=", "$", "this", ";", "}", "else", "{", "// Otherwise, inject the instantiated dependency or a null value", "$", "dependencies", "[", "]", "=", "$", "class", "?", "$", "this", "->", "make", "(", "$", "class", "->", "name", ")", ":", "'NULL'", ";", "}", "}", "// Return the class instance", "$", "instance", "=", "$", "reflection", "->", "newInstanceArgs", "(", "$", "dependencies", ")", ";", "// If the class has a boot method, run it", "if", "(", "method_exists", "(", "$", "instance", ",", "'boot'", ")", ")", "{", "$", "instance", "->", "boot", "(", ")", ";", "}", "// Return instance", "return", "$", "instance", ";", "}" ]
Makes an instance of a class @param string $className Class name @return object Class instance
[ "Makes", "an", "instance", "of", "a", "class" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L129-L166
train
nicodevs/laito
src/Laito/App.php
App.runAction
private function runAction() { // Get URL $url = $this->request->url(); // Get route action $action = $this->router->getAction($url); // Perform the filter if ($action['filter']) { $filter = $this->router->performFilter($action['filter']); } // Check if the controller exists if (!isset($action) || !is_string($action['class']) || !class_exists($action['class'])) { throw new \Exception('Controller not found', 404); } // Create the required controller $controller = $this->make($action['class']); // Execute the required method and return the response return $this->response->output(call_user_func_array([$controller, $action['method']], $action['params']? : [])); }
php
private function runAction() { // Get URL $url = $this->request->url(); // Get route action $action = $this->router->getAction($url); // Perform the filter if ($action['filter']) { $filter = $this->router->performFilter($action['filter']); } // Check if the controller exists if (!isset($action) || !is_string($action['class']) || !class_exists($action['class'])) { throw new \Exception('Controller not found', 404); } // Create the required controller $controller = $this->make($action['class']); // Execute the required method and return the response return $this->response->output(call_user_func_array([$controller, $action['method']], $action['params']? : [])); }
[ "private", "function", "runAction", "(", ")", "{", "// Get URL", "$", "url", "=", "$", "this", "->", "request", "->", "url", "(", ")", ";", "// Get route action", "$", "action", "=", "$", "this", "->", "router", "->", "getAction", "(", "$", "url", ")", ";", "// Perform the filter", "if", "(", "$", "action", "[", "'filter'", "]", ")", "{", "$", "filter", "=", "$", "this", "->", "router", "->", "performFilter", "(", "$", "action", "[", "'filter'", "]", ")", ";", "}", "// Check if the controller exists", "if", "(", "!", "isset", "(", "$", "action", ")", "||", "!", "is_string", "(", "$", "action", "[", "'class'", "]", ")", "||", "!", "class_exists", "(", "$", "action", "[", "'class'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Controller not found'", ",", "404", ")", ";", "}", "// Create the required controller", "$", "controller", "=", "$", "this", "->", "make", "(", "$", "action", "[", "'class'", "]", ")", ";", "// Execute the required method and return the response", "return", "$", "this", "->", "response", "->", "output", "(", "call_user_func_array", "(", "[", "$", "controller", ",", "$", "action", "[", "'method'", "]", "]", ",", "$", "action", "[", "'params'", "]", "?", ":", "[", "]", ")", ")", ";", "}" ]
Setups a database connection for models @return void
[ "Setups", "a", "database", "connection", "for", "models" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L243-L266
train
nicodevs/laito
src/Laito/App.php
App.returnValidationErrorResponse
private function returnValidationErrorResponse($e) { return $this->response->error($e->getCode(), $e->getMessage(), ['error' => ['errors' => $e->getErrors()]]); }
php
private function returnValidationErrorResponse($e) { return $this->response->error($e->getCode(), $e->getMessage(), ['error' => ['errors' => $e->getErrors()]]); }
[ "private", "function", "returnValidationErrorResponse", "(", "$", "e", ")", "{", "return", "$", "this", "->", "response", "->", "error", "(", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", "->", "getMessage", "(", ")", ",", "[", "'error'", "=>", "[", "'errors'", "=>", "$", "e", "->", "getErrors", "(", ")", "]", "]", ")", ";", "}" ]
Returns a validation error response @return array Response
[ "Returns", "a", "validation", "error", "response" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L273-L276
train
nicodevs/laito
src/Laito/App.php
App.returnDatabaseErrorResponse
private function returnDatabaseErrorResponse($e) { $info = $this->config('debug.queries')? ['error' => ['errors' => $this->db->statement->errorInfo(), 'last_query' => $this->db->lastQuery()]] : []; return $this->response->error(500, 'Database error', $info); }
php
private function returnDatabaseErrorResponse($e) { $info = $this->config('debug.queries')? ['error' => ['errors' => $this->db->statement->errorInfo(), 'last_query' => $this->db->lastQuery()]] : []; return $this->response->error(500, 'Database error', $info); }
[ "private", "function", "returnDatabaseErrorResponse", "(", "$", "e", ")", "{", "$", "info", "=", "$", "this", "->", "config", "(", "'debug.queries'", ")", "?", "[", "'error'", "=>", "[", "'errors'", "=>", "$", "this", "->", "db", "->", "statement", "->", "errorInfo", "(", ")", ",", "'last_query'", "=>", "$", "this", "->", "db", "->", "lastQuery", "(", ")", "]", "]", ":", "[", "]", ";", "return", "$", "this", "->", "response", "->", "error", "(", "500", ",", "'Database error'", ",", "$", "info", ")", ";", "}" ]
Returns a database error response @return array Response
[ "Returns", "a", "database", "error", "response" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L283-L287
train
nicodevs/laito
src/Laito/App.php
App.returnGeneralErrorResponse
private function returnGeneralErrorResponse($e) { $backtrace = $this->config('debug.backtrace')? ['error' => ['backtrace' => $e->getTrace()]] : []; return $this->response->error($e->getCode(), $e->getMessage(), $backtrace); }
php
private function returnGeneralErrorResponse($e) { $backtrace = $this->config('debug.backtrace')? ['error' => ['backtrace' => $e->getTrace()]] : []; return $this->response->error($e->getCode(), $e->getMessage(), $backtrace); }
[ "private", "function", "returnGeneralErrorResponse", "(", "$", "e", ")", "{", "$", "backtrace", "=", "$", "this", "->", "config", "(", "'debug.backtrace'", ")", "?", "[", "'error'", "=>", "[", "'backtrace'", "=>", "$", "e", "->", "getTrace", "(", ")", "]", "]", ":", "[", "]", ";", "return", "$", "this", "->", "response", "->", "error", "(", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", "->", "getMessage", "(", ")", ",", "$", "backtrace", ")", ";", "}" ]
Returns a generic error response @return array Response
[ "Returns", "a", "generic", "error", "response" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/App.php#L294-L298
train
mikyprog/LocationBundle
Manager/CountryManager.php
CountryManager.updateCountry
public function updateCountry(Country $country, $andFlush = true) { $this->objectManager->persist($country); if ($andFlush) { $this->objectManager->flush(); } }
php
public function updateCountry(Country $country, $andFlush = true) { $this->objectManager->persist($country); if ($andFlush) { $this->objectManager->flush(); } }
[ "public", "function", "updateCountry", "(", "Country", "$", "country", ",", "$", "andFlush", "=", "true", ")", "{", "$", "this", "->", "objectManager", "->", "persist", "(", "$", "country", ")", ";", "if", "(", "$", "andFlush", ")", "{", "$", "this", "->", "objectManager", "->", "flush", "(", ")", ";", "}", "}" ]
Updates a Country. @param Country $country @param Boolean $andFlush Whether to flush the changes (default true)
[ "Updates", "a", "Country", "." ]
ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23
https://github.com/mikyprog/LocationBundle/blob/ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23/Manager/CountryManager.php#L134-L140
train
mikyprog/LocationBundle
Manager/CountryManager.php
CountryManager.refreshCountry
public function refreshCountry(Country $country) { $refreshedCountry = $this->findCountryBy(array('id' => $country->getId())); if (null === $refreshedCountry) { throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $country->getId())); } return $refreshedCountry; }
php
public function refreshCountry(Country $country) { $refreshedCountry = $this->findCountryBy(array('id' => $country->getId())); if (null === $refreshedCountry) { throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $country->getId())); } return $refreshedCountry; }
[ "public", "function", "refreshCountry", "(", "Country", "$", "country", ")", "{", "$", "refreshedCountry", "=", "$", "this", "->", "findCountryBy", "(", "array", "(", "'id'", "=>", "$", "country", "->", "getId", "(", ")", ")", ")", ";", "if", "(", "null", "===", "$", "refreshedCountry", ")", "{", "throw", "new", "UsernameNotFoundException", "(", "sprintf", "(", "'User with ID \"%d\" could not be reloaded.'", ",", "$", "country", "->", "getId", "(", ")", ")", ")", ";", "}", "return", "$", "refreshedCountry", ";", "}" ]
Refreshed a Country by Country Instance @param Country $country @return Ad
[ "Refreshed", "a", "Country", "by", "Country", "Instance" ]
ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23
https://github.com/mikyprog/LocationBundle/blob/ffbbc8e6b7c759f0dbf0dec6d36a8f3150322f23/Manager/CountryManager.php#L161-L169
train
rollerworks/search-core
Field/SearchField.php
SearchField.finalizeConfig
public function finalizeConfig(): void { if ($this->locked) { return; } if (null === $this->valueComparator) { foreach ($this->supportedValueTypes as $type => $supported) { if ($supported && isset(class_implements($type)[RequiresComparatorValueHolder::class])) { throw new InvalidConfigurationException( sprintf( 'Supported value-type "%s" requires a value comparator but none is set for field "%s" with type "%s".', $type, $this->getName(), \get_class($this->getType()->getInnerType()) ) ); } } } $this->locked = true; }
php
public function finalizeConfig(): void { if ($this->locked) { return; } if (null === $this->valueComparator) { foreach ($this->supportedValueTypes as $type => $supported) { if ($supported && isset(class_implements($type)[RequiresComparatorValueHolder::class])) { throw new InvalidConfigurationException( sprintf( 'Supported value-type "%s" requires a value comparator but none is set for field "%s" with type "%s".', $type, $this->getName(), \get_class($this->getType()->getInnerType()) ) ); } } } $this->locked = true; }
[ "public", "function", "finalizeConfig", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "locked", ")", "{", "return", ";", "}", "if", "(", "null", "===", "$", "this", "->", "valueComparator", ")", "{", "foreach", "(", "$", "this", "->", "supportedValueTypes", "as", "$", "type", "=>", "$", "supported", ")", "{", "if", "(", "$", "supported", "&&", "isset", "(", "class_implements", "(", "$", "type", ")", "[", "RequiresComparatorValueHolder", "::", "class", "]", ")", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "sprintf", "(", "'Supported value-type \"%s\" requires a value comparator but none is set for field \"%s\" with type \"%s\".'", ",", "$", "type", ",", "$", "this", "->", "getName", "(", ")", ",", "\\", "get_class", "(", "$", "this", "->", "getType", "(", ")", "->", "getInnerType", "(", ")", ")", ")", ")", ";", "}", "}", "}", "$", "this", "->", "locked", "=", "true", ";", "}" ]
Finalize the configuration and mark config as locked. After calling this method, setter methods can be no longer called. @throws InvalidConfigurationException when a supported value-type requires a value comparator but none is set
[ "Finalize", "the", "configuration", "and", "mark", "config", "as", "locked", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Field/SearchField.php#L189-L211
train
modulusphp/http
Redirect.php
Redirect.to
public static function to(?string $path = '/', ?int $code = null) { $redirect = new Redirect; $redirect->url = $path; if ($code !== null) { $redirect->code = $code; return $redirect->send(); } return $redirect; }
php
public static function to(?string $path = '/', ?int $code = null) { $redirect = new Redirect; $redirect->url = $path; if ($code !== null) { $redirect->code = $code; return $redirect->send(); } return $redirect; }
[ "public", "static", "function", "to", "(", "?", "string", "$", "path", "=", "'/'", ",", "?", "int", "$", "code", "=", "null", ")", "{", "$", "redirect", "=", "new", "Redirect", ";", "$", "redirect", "->", "url", "=", "$", "path", ";", "if", "(", "$", "code", "!==", "null", ")", "{", "$", "redirect", "->", "code", "=", "$", "code", ";", "return", "$", "redirect", "->", "send", "(", ")", ";", "}", "return", "$", "redirect", ";", "}" ]
Redirect to path @param string $path @param integer $code @return Redirect
[ "Redirect", "to", "path" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L52-L63
train
modulusphp/http
Redirect.php
Redirect.back
public static function back(?int $code = null) { if (isset(getallheaders()['Referer'])) { return Redirect::to(getallheaders()['Referer'], $code); } return new Redirect('/'); }
php
public static function back(?int $code = null) { if (isset(getallheaders()['Referer'])) { return Redirect::to(getallheaders()['Referer'], $code); } return new Redirect('/'); }
[ "public", "static", "function", "back", "(", "?", "int", "$", "code", "=", "null", ")", "{", "if", "(", "isset", "(", "getallheaders", "(", ")", "[", "'Referer'", "]", ")", ")", "{", "return", "Redirect", "::", "to", "(", "getallheaders", "(", ")", "[", "'Referer'", "]", ",", "$", "code", ")", ";", "}", "return", "new", "Redirect", "(", "'/'", ")", ";", "}" ]
Redirect back to the previous page @param mixed ?int @return void
[ "Redirect", "back", "to", "the", "previous", "page" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L71-L78
train
modulusphp/http
Redirect.php
Redirect.route
public function route(string $name, ?array $parameters = [], ?int $code = null) { $this->url = Route::url($name, $parameters); if ($code !== null) { $this->code = $code; return $this->send(); } return $this; }
php
public function route(string $name, ?array $parameters = [], ?int $code = null) { $this->url = Route::url($name, $parameters); if ($code !== null) { $this->code = $code; return $this->send(); } return $this; }
[ "public", "function", "route", "(", "string", "$", "name", ",", "?", "array", "$", "parameters", "=", "[", "]", ",", "?", "int", "$", "code", "=", "null", ")", "{", "$", "this", "->", "url", "=", "Route", "::", "url", "(", "$", "name", ",", "$", "parameters", ")", ";", "if", "(", "$", "code", "!==", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Redirect to route @param string $name @param mixed ?array @param integer $code @return Redirect
[ "Redirect", "to", "route" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L88-L98
train
modulusphp/http
Redirect.php
Redirect.with
public function with(string $name, $value, ?int $code = null) { $this->with = array_merge([$name => $value], $this->with); if ($code != null) { $this->code = $code; return $this->send(); } return $this; }
php
public function with(string $name, $value, ?int $code = null) { $this->with = array_merge([$name => $value], $this->with); if ($code != null) { $this->code = $code; return $this->send(); } return $this; }
[ "public", "function", "with", "(", "string", "$", "name", ",", "$", "value", ",", "?", "int", "$", "code", "=", "null", ")", "{", "$", "this", "->", "with", "=", "array_merge", "(", "[", "$", "name", "=>", "$", "value", "]", ",", "$", "this", "->", "with", ")", ";", "if", "(", "$", "code", "!=", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Attach variables with redirect @param string $name @param mixed $value @param integer $code @return Redirect
[ "Attach", "variables", "with", "redirect" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L108-L118
train
modulusphp/http
Redirect.php
Redirect.old
public function old(array $value, ?int $code = null) { $this->with = array_merge(['form.old' => $value], $this->with); if ($code != null) { $this->code = $code; return $this->send(); } return $this; }
php
public function old(array $value, ?int $code = null) { $this->with = array_merge(['form.old' => $value], $this->with); if ($code != null) { $this->code = $code; return $this->send(); } return $this; }
[ "public", "function", "old", "(", "array", "$", "value", ",", "?", "int", "$", "code", "=", "null", ")", "{", "$", "this", "->", "with", "=", "array_merge", "(", "[", "'form.old'", "=>", "$", "value", "]", ",", "$", "this", "->", "with", ")", ";", "if", "(", "$", "code", "!=", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Attach old variables with redirect @param array $value @param integer $code @return Redirect
[ "Attach", "old", "variables", "with", "redirect" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L127-L137
train
modulusphp/http
Redirect.php
Redirect.return
public function return(?int $code = null, ?string $path = null) { $info = ((isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/') === '/' ? '' : $_SERVER['PATH_INFO']); if ($info !== '') $path = '?url=' . $info; if (count($_GET) > 0) { $path .= '&' . $_SERVER['QUERY_STRING']; } $this->url .= $path; if ($code !== null) { $this->code = $code; return $this->send(); } return $this; }
php
public function return(?int $code = null, ?string $path = null) { $info = ((isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/') === '/' ? '' : $_SERVER['PATH_INFO']); if ($info !== '') $path = '?url=' . $info; if (count($_GET) > 0) { $path .= '&' . $_SERVER['QUERY_STRING']; } $this->url .= $path; if ($code !== null) { $this->code = $code; return $this->send(); } return $this; }
[ "public", "function", "return", "(", "?", "int", "$", "code", "=", "null", ",", "?", "string", "$", "path", "=", "null", ")", "{", "$", "info", "=", "(", "(", "isset", "(", "$", "_SERVER", "[", "'PATH_INFO'", "]", ")", "?", "$", "_SERVER", "[", "'PATH_INFO'", "]", ":", "'/'", ")", "===", "'/'", "?", "''", ":", "$", "_SERVER", "[", "'PATH_INFO'", "]", ")", ";", "if", "(", "$", "info", "!==", "''", ")", "$", "path", "=", "'?url='", ".", "$", "info", ";", "if", "(", "count", "(", "$", "_GET", ")", ">", "0", ")", "{", "$", "path", ".=", "'&'", ".", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ";", "}", "$", "this", "->", "url", ".=", "$", "path", ";", "if", "(", "$", "code", "!==", "null", ")", "{", "$", "this", "->", "code", "=", "$", "code", ";", "return", "$", "this", "->", "send", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Allow redirect to return to current url @param integer $code @return Redirect
[ "Allow", "redirect", "to", "return", "to", "current", "url" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Redirect.php#L145-L163
train
mosbth/phpmvc-comment
src/Comment/CommentsInSession.php
CommentsInSession.add
public function add($comment) { $comments = $this->session->get('comments', []); $comments[] = $comment; $this->session->set('comments', $comments); }
php
public function add($comment) { $comments = $this->session->get('comments', []); $comments[] = $comment; $this->session->set('comments', $comments); }
[ "public", "function", "add", "(", "$", "comment", ")", "{", "$", "comments", "=", "$", "this", "->", "session", "->", "get", "(", "'comments'", ",", "[", "]", ")", ";", "$", "comments", "[", "]", "=", "$", "comment", ";", "$", "this", "->", "session", "->", "set", "(", "'comments'", ",", "$", "comments", ")", ";", "}" ]
Add a new comment. @param array $comment with all details. @return void
[ "Add", "a", "new", "comment", "." ]
ea5c43e8bb3f723d6fb69c892500d26c7390eb37
https://github.com/mosbth/phpmvc-comment/blob/ea5c43e8bb3f723d6fb69c892500d26c7390eb37/src/Comment/CommentsInSession.php#L22-L27
train
fulgurio/LightCMSBundle
EventListener/BeforeListener.php
BeforeListener.onKernelController
public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); /** * $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen. * If it is a class, it comes in array format */ if (!is_array($controller)) { return; } $fullpath = $event->getRequest()->get('fullpath'); if ($fullpath != '' && $fullpath[mb_strlen($fullpath) - 1] == '/') { $fullpath = mb_substr($fullpath, 0, -1); } if (isset($controller[0])) { if ($controller[0] instanceof FrontPageController) { if (!($this->page = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findOneBy(array('fullpath' => $fullpath)))) { throw new NotFoundHttpException(); } if ($this->page->getStatus() === 'draft' && !( $this->securityContext->isGranted('ROLE_ADMIN') && !is_null($event->getRequest()->server->get('HTTP_REFERER')) )) { throw new NotFoundHttpException(); } //@todo : check access $models = $this->kernel->getContainer()->getParameter('fulgurio_light_cms.models'); if (isset($models[$this->page->getModel()]['front']['controller'])) { $controller = $this->getController($models[$this->page->getModel()]['front']['controller']); $controller[0]->setContainer($this->kernel->getContainer()); $event->setController($controller); } if (method_exists($controller[0], 'setPage')) { $controller[0]->setPage($this->page); } } } }
php
public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); /** * $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen. * If it is a class, it comes in array format */ if (!is_array($controller)) { return; } $fullpath = $event->getRequest()->get('fullpath'); if ($fullpath != '' && $fullpath[mb_strlen($fullpath) - 1] == '/') { $fullpath = mb_substr($fullpath, 0, -1); } if (isset($controller[0])) { if ($controller[0] instanceof FrontPageController) { if (!($this->page = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findOneBy(array('fullpath' => $fullpath)))) { throw new NotFoundHttpException(); } if ($this->page->getStatus() === 'draft' && !( $this->securityContext->isGranted('ROLE_ADMIN') && !is_null($event->getRequest()->server->get('HTTP_REFERER')) )) { throw new NotFoundHttpException(); } //@todo : check access $models = $this->kernel->getContainer()->getParameter('fulgurio_light_cms.models'); if (isset($models[$this->page->getModel()]['front']['controller'])) { $controller = $this->getController($models[$this->page->getModel()]['front']['controller']); $controller[0]->setContainer($this->kernel->getContainer()); $event->setController($controller); } if (method_exists($controller[0], 'setPage')) { $controller[0]->setPage($this->page); } } } }
[ "public", "function", "onKernelController", "(", "FilterControllerEvent", "$", "event", ")", "{", "$", "controller", "=", "$", "event", "->", "getController", "(", ")", ";", "/**\n * $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen.\n * If it is a class, it comes in array format\n */", "if", "(", "!", "is_array", "(", "$", "controller", ")", ")", "{", "return", ";", "}", "$", "fullpath", "=", "$", "event", "->", "getRequest", "(", ")", "->", "get", "(", "'fullpath'", ")", ";", "if", "(", "$", "fullpath", "!=", "''", "&&", "$", "fullpath", "[", "mb_strlen", "(", "$", "fullpath", ")", "-", "1", "]", "==", "'/'", ")", "{", "$", "fullpath", "=", "mb_substr", "(", "$", "fullpath", ",", "0", ",", "-", "1", ")", ";", "}", "if", "(", "isset", "(", "$", "controller", "[", "0", "]", ")", ")", "{", "if", "(", "$", "controller", "[", "0", "]", "instanceof", "FrontPageController", ")", "{", "if", "(", "!", "(", "$", "this", "->", "page", "=", "$", "this", "->", "doctrine", "->", "getRepository", "(", "'FulgurioLightCMSBundle:Page'", ")", "->", "findOneBy", "(", "array", "(", "'fullpath'", "=>", "$", "fullpath", ")", ")", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", ")", ";", "}", "if", "(", "$", "this", "->", "page", "->", "getStatus", "(", ")", "===", "'draft'", "&&", "!", "(", "$", "this", "->", "securityContext", "->", "isGranted", "(", "'ROLE_ADMIN'", ")", "&&", "!", "is_null", "(", "$", "event", "->", "getRequest", "(", ")", "->", "server", "->", "get", "(", "'HTTP_REFERER'", ")", ")", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", ")", ";", "}", "//@todo : check access", "$", "models", "=", "$", "this", "->", "kernel", "->", "getContainer", "(", ")", "->", "getParameter", "(", "'fulgurio_light_cms.models'", ")", ";", "if", "(", "isset", "(", "$", "models", "[", "$", "this", "->", "page", "->", "getModel", "(", ")", "]", "[", "'front'", "]", "[", "'controller'", "]", ")", ")", "{", "$", "controller", "=", "$", "this", "->", "getController", "(", "$", "models", "[", "$", "this", "->", "page", "->", "getModel", "(", ")", "]", "[", "'front'", "]", "[", "'controller'", "]", ")", ";", "$", "controller", "[", "0", "]", "->", "setContainer", "(", "$", "this", "->", "kernel", "->", "getContainer", "(", ")", ")", ";", "$", "event", "->", "setController", "(", "$", "controller", ")", ";", "}", "if", "(", "method_exists", "(", "$", "controller", "[", "0", "]", ",", "'setPage'", ")", ")", "{", "$", "controller", "[", "0", "]", "->", "setPage", "(", "$", "this", "->", "page", ")", ";", "}", "}", "}", "}" ]
OnKernelControler event filter Try to find the page into database. @param FilterControllerEvent $event @throws NotFoundHttpException @throws AccessDeniedHttpException @return void|\Fulgurio\LightCMSBundle\EventListener\RedirectResponse
[ "OnKernelControler", "event", "filter", "Try", "to", "find", "the", "page", "into", "database", "." ]
66319af52b97b6552b7c391ee370538263f42d10
https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/EventListener/BeforeListener.php#L59-L104
train
Bistro/session
lib/Bistro/Session/Native.php
Native.setOptions
protected function setOptions(array $options) { $whitelist = array('save_path', 'name', 'save_handler', 'auto_start', 'gc_probability', 'gc_divisor', 'gc_maxlifetime', 'serialize_handler', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'use_only_cookies', 'referer_check', 'entropy_file', 'entropy_length', 'cache_limiter', 'cache_expire', 'use_trans_sid ', 'hash_function', 'hash_bits_per_character'); foreach ($options as $key => $value) { if (\in_array($key, $whitelist)) { \ini_set("session.{$key}", $value); } } if (\array_key_exists('url_rewriter.tags', $options)) { \ini_set('url_rewriter.tags', $options['url_rewriter.tags']); } }
php
protected function setOptions(array $options) { $whitelist = array('save_path', 'name', 'save_handler', 'auto_start', 'gc_probability', 'gc_divisor', 'gc_maxlifetime', 'serialize_handler', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'use_only_cookies', 'referer_check', 'entropy_file', 'entropy_length', 'cache_limiter', 'cache_expire', 'use_trans_sid ', 'hash_function', 'hash_bits_per_character'); foreach ($options as $key => $value) { if (\in_array($key, $whitelist)) { \ini_set("session.{$key}", $value); } } if (\array_key_exists('url_rewriter.tags', $options)) { \ini_set('url_rewriter.tags', $options['url_rewriter.tags']); } }
[ "protected", "function", "setOptions", "(", "array", "$", "options", ")", "{", "$", "whitelist", "=", "array", "(", "'save_path'", ",", "'name'", ",", "'save_handler'", ",", "'auto_start'", ",", "'gc_probability'", ",", "'gc_divisor'", ",", "'gc_maxlifetime'", ",", "'serialize_handler'", ",", "'cookie_lifetime'", ",", "'cookie_path'", ",", "'cookie_domain'", ",", "'cookie_secure'", ",", "'cookie_httponly'", ",", "'use_cookies'", ",", "'use_only_cookies'", ",", "'referer_check'", ",", "'entropy_file'", ",", "'entropy_length'", ",", "'cache_limiter'", ",", "'cache_expire'", ",", "'use_trans_sid '", ",", "'hash_function'", ",", "'hash_bits_per_character'", ")", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "\\", "in_array", "(", "$", "key", ",", "$", "whitelist", ")", ")", "{", "\\", "ini_set", "(", "\"session.{$key}\"", ",", "$", "value", ")", ";", "}", "}", "if", "(", "\\", "array_key_exists", "(", "'url_rewriter.tags'", ",", "$", "options", ")", ")", "{", "\\", "ini_set", "(", "'url_rewriter.tags'", ",", "$", "options", "[", "'url_rewriter.tags'", "]", ")", ";", "}", "}" ]
Sets session options. @param array $options Options array
[ "Sets", "session", "options", "." ]
cebd8c77288458abde9ffdcd8efd69004a536a49
https://github.com/Bistro/session/blob/cebd8c77288458abde9ffdcd8efd69004a536a49/lib/Bistro/Session/Native.php#L64-L85
train
shgysk8zer0/core_api
traits/domimporthtml.php
DOMImportHTML.importHTML
final public function importHTML($html) { $tmp_doc = new \DOMDocument('1.0', 'UTF-8'); $tmp_doc->loadHTML($html); $nodes = array(); foreach ($tmp_doc->documentElement->childNodes as $node) { array_push($nodes, $node); $this->appendChild($this->ownerDocument->importNode($node, true)); } return $nodes; }
php
final public function importHTML($html) { $tmp_doc = new \DOMDocument('1.0', 'UTF-8'); $tmp_doc->loadHTML($html); $nodes = array(); foreach ($tmp_doc->documentElement->childNodes as $node) { array_push($nodes, $node); $this->appendChild($this->ownerDocument->importNode($node, true)); } return $nodes; }
[ "final", "public", "function", "importHTML", "(", "$", "html", ")", "{", "$", "tmp_doc", "=", "new", "\\", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "$", "tmp_doc", "->", "loadHTML", "(", "$", "html", ")", ";", "$", "nodes", "=", "array", "(", ")", ";", "foreach", "(", "$", "tmp_doc", "->", "documentElement", "->", "childNodes", "as", "$", "node", ")", "{", "array_push", "(", "$", "nodes", ",", "$", "node", ")", ";", "$", "this", "->", "appendChild", "(", "$", "this", "->", "ownerDocument", "->", "importNode", "(", "$", "node", ",", "true", ")", ")", ";", "}", "return", "$", "nodes", ";", "}" ]
Import HTML into a DOMElement @param string $html A string of HTML @return void
[ "Import", "HTML", "into", "a", "DOMElement" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/domimporthtml.php#L35-L45
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getSet
protected function getSet(array $queryParts) { if (isset($queryParts['set']) && !empty($queryParts['set'])) { $updates = array(); foreach ($queryParts['set'] as $k => $v) { $updates[] = sprintf( '%s = %s', $this->quoteIdentifier($k), $this->quote($v) ); } return 'SET ' . implode(', ', $updates); } return null; }
php
protected function getSet(array $queryParts) { if (isset($queryParts['set']) && !empty($queryParts['set'])) { $updates = array(); foreach ($queryParts['set'] as $k => $v) { $updates[] = sprintf( '%s = %s', $this->quoteIdentifier($k), $this->quote($v) ); } return 'SET ' . implode(', ', $updates); } return null; }
[ "protected", "function", "getSet", "(", "array", "$", "queryParts", ")", "{", "if", "(", "isset", "(", "$", "queryParts", "[", "'set'", "]", ")", "&&", "!", "empty", "(", "$", "queryParts", "[", "'set'", "]", ")", ")", "{", "$", "updates", "=", "array", "(", ")", ";", "foreach", "(", "$", "queryParts", "[", "'set'", "]", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "updates", "[", "]", "=", "sprintf", "(", "'%s = %s'", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "k", ")", ",", "$", "this", "->", "quote", "(", "$", "v", ")", ")", ";", "}", "return", "'SET '", ".", "implode", "(", "', '", ",", "$", "updates", ")", ";", "}", "return", "null", ";", "}" ]
Prepare the SET part of the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "SET", "part", "of", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L134-L151
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getTable
protected function getTable(array $queryParts) { if (isset($queryParts['table'])) { $from = (isset($queryParts['fields']) && !empty($queryParts['fields'])) || strtoupper($queryParts['type']) === 'DELETE' ? 'FROM ' : ''; if (is_a($queryParts['table'], 'Database\Table')) { $select = !empty($from) ? $from . '%s' : '%s'; if (!empty($from) && strtoupper($queryParts['type']) !== 'DELETE') { $select .= ' AS %s'; } return sprintf( $select, $this->quoteTable($queryParts['table']->getTable()), $this->quoteTable($queryParts['table']->getName()) ); } else { return $from . $this->quoteTable($queryParts['table']); } } return null; }
php
protected function getTable(array $queryParts) { if (isset($queryParts['table'])) { $from = (isset($queryParts['fields']) && !empty($queryParts['fields'])) || strtoupper($queryParts['type']) === 'DELETE' ? 'FROM ' : ''; if (is_a($queryParts['table'], 'Database\Table')) { $select = !empty($from) ? $from . '%s' : '%s'; if (!empty($from) && strtoupper($queryParts['type']) !== 'DELETE') { $select .= ' AS %s'; } return sprintf( $select, $this->quoteTable($queryParts['table']->getTable()), $this->quoteTable($queryParts['table']->getName()) ); } else { return $from . $this->quoteTable($queryParts['table']); } } return null; }
[ "protected", "function", "getTable", "(", "array", "$", "queryParts", ")", "{", "if", "(", "isset", "(", "$", "queryParts", "[", "'table'", "]", ")", ")", "{", "$", "from", "=", "(", "isset", "(", "$", "queryParts", "[", "'fields'", "]", ")", "&&", "!", "empty", "(", "$", "queryParts", "[", "'fields'", "]", ")", ")", "||", "strtoupper", "(", "$", "queryParts", "[", "'type'", "]", ")", "===", "'DELETE'", "?", "'FROM '", ":", "''", ";", "if", "(", "is_a", "(", "$", "queryParts", "[", "'table'", "]", ",", "'Database\\Table'", ")", ")", "{", "$", "select", "=", "!", "empty", "(", "$", "from", ")", "?", "$", "from", ".", "'%s'", ":", "'%s'", ";", "if", "(", "!", "empty", "(", "$", "from", ")", "&&", "strtoupper", "(", "$", "queryParts", "[", "'type'", "]", ")", "!==", "'DELETE'", ")", "{", "$", "select", ".=", "' AS %s'", ";", "}", "return", "sprintf", "(", "$", "select", ",", "$", "this", "->", "quoteTable", "(", "$", "queryParts", "[", "'table'", "]", "->", "getTable", "(", ")", ")", ",", "$", "this", "->", "quoteTable", "(", "$", "queryParts", "[", "'table'", "]", "->", "getName", "(", ")", ")", ")", ";", "}", "else", "{", "return", "$", "from", ".", "$", "this", "->", "quoteTable", "(", "$", "queryParts", "[", "'table'", "]", ")", ";", "}", "}", "return", "null", ";", "}" ]
Prepare the table name for use in the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "table", "name", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L158-L185
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getJoins
protected function getJoins(array $queryParts) { $result = null; if (isset($queryParts['join']) && !empty($queryParts['join'])) { $result = []; foreach ($queryParts['join'] as $join) { $piece = trim($join[0] . ' JOIN') . ' '; $piece .= is_a($join[1], 'Database\Table') ? sprintf( '%s AS %s', $this->quoteTable($join[1]->getTable()), $this->quoteTable($join[1]->getName()) ) : (string)$join[1]; $piece .= ' ON ' . $join[2]; $result[] = $piece; } $result = implode(' ', $result); } return $result; }
php
protected function getJoins(array $queryParts) { $result = null; if (isset($queryParts['join']) && !empty($queryParts['join'])) { $result = []; foreach ($queryParts['join'] as $join) { $piece = trim($join[0] . ' JOIN') . ' '; $piece .= is_a($join[1], 'Database\Table') ? sprintf( '%s AS %s', $this->quoteTable($join[1]->getTable()), $this->quoteTable($join[1]->getName()) ) : (string)$join[1]; $piece .= ' ON ' . $join[2]; $result[] = $piece; } $result = implode(' ', $result); } return $result; }
[ "protected", "function", "getJoins", "(", "array", "$", "queryParts", ")", "{", "$", "result", "=", "null", ";", "if", "(", "isset", "(", "$", "queryParts", "[", "'join'", "]", ")", "&&", "!", "empty", "(", "$", "queryParts", "[", "'join'", "]", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "queryParts", "[", "'join'", "]", "as", "$", "join", ")", "{", "$", "piece", "=", "trim", "(", "$", "join", "[", "0", "]", ".", "' JOIN'", ")", ".", "' '", ";", "$", "piece", ".=", "is_a", "(", "$", "join", "[", "1", "]", ",", "'Database\\Table'", ")", "?", "sprintf", "(", "'%s AS %s'", ",", "$", "this", "->", "quoteTable", "(", "$", "join", "[", "1", "]", "->", "getTable", "(", ")", ")", ",", "$", "this", "->", "quoteTable", "(", "$", "join", "[", "1", "]", "->", "getName", "(", ")", ")", ")", ":", "(", "string", ")", "$", "join", "[", "1", "]", ";", "$", "piece", ".=", "' ON '", ".", "$", "join", "[", "2", "]", ";", "$", "result", "[", "]", "=", "$", "piece", ";", "}", "$", "result", "=", "implode", "(", "' '", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Prepare the joins for use in the MySQL query. @param array $queryParts @return array|null|string
[ "Prepare", "the", "joins", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L192-L216
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.formatWhere
private function formatWhere($where, $operator = 'AND') { if (is_string($where)) { return $where; } $fullWhere = []; if (is_array($where)) { foreach ($where as $key => $value) { $fullWhere[] = sprintf( '%s = %s', $this->quoteIdentifier($key), $this->quote($value) ); } } elseif (is_a($where, 'Database\Query\Where')) { $operator = $where->getOperator(); $whereClause = $where->getWhereClause(); if (!empty($whereClause)) { foreach ($whereClause as $part) { if ($part[0] === '=') { $fullWhere[] = $this->formatWhere($part[1], $operator); } else { $q = sprintf( '%s %s', $this->quoteIdentifier($part[1]), $part[0] ); if (isset($part[2])) { $q .= ' ' . $this->quote($part[2]); } $fullWhere[] = $q; } } } } return '(' . implode(" {$operator} ", $fullWhere) . ')'; }
php
private function formatWhere($where, $operator = 'AND') { if (is_string($where)) { return $where; } $fullWhere = []; if (is_array($where)) { foreach ($where as $key => $value) { $fullWhere[] = sprintf( '%s = %s', $this->quoteIdentifier($key), $this->quote($value) ); } } elseif (is_a($where, 'Database\Query\Where')) { $operator = $where->getOperator(); $whereClause = $where->getWhereClause(); if (!empty($whereClause)) { foreach ($whereClause as $part) { if ($part[0] === '=') { $fullWhere[] = $this->formatWhere($part[1], $operator); } else { $q = sprintf( '%s %s', $this->quoteIdentifier($part[1]), $part[0] ); if (isset($part[2])) { $q .= ' ' . $this->quote($part[2]); } $fullWhere[] = $q; } } } } return '(' . implode(" {$operator} ", $fullWhere) . ')'; }
[ "private", "function", "formatWhere", "(", "$", "where", ",", "$", "operator", "=", "'AND'", ")", "{", "if", "(", "is_string", "(", "$", "where", ")", ")", "{", "return", "$", "where", ";", "}", "$", "fullWhere", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "where", ")", ")", "{", "foreach", "(", "$", "where", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "fullWhere", "[", "]", "=", "sprintf", "(", "'%s = %s'", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "key", ")", ",", "$", "this", "->", "quote", "(", "$", "value", ")", ")", ";", "}", "}", "elseif", "(", "is_a", "(", "$", "where", ",", "'Database\\Query\\Where'", ")", ")", "{", "$", "operator", "=", "$", "where", "->", "getOperator", "(", ")", ";", "$", "whereClause", "=", "$", "where", "->", "getWhereClause", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "whereClause", ")", ")", "{", "foreach", "(", "$", "whereClause", "as", "$", "part", ")", "{", "if", "(", "$", "part", "[", "0", "]", "===", "'='", ")", "{", "$", "fullWhere", "[", "]", "=", "$", "this", "->", "formatWhere", "(", "$", "part", "[", "1", "]", ",", "$", "operator", ")", ";", "}", "else", "{", "$", "q", "=", "sprintf", "(", "'%s %s'", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "part", "[", "1", "]", ")", ",", "$", "part", "[", "0", "]", ")", ";", "if", "(", "isset", "(", "$", "part", "[", "2", "]", ")", ")", "{", "$", "q", ".=", "' '", ".", "$", "this", "->", "quote", "(", "$", "part", "[", "2", "]", ")", ";", "}", "$", "fullWhere", "[", "]", "=", "$", "q", ";", "}", "}", "}", "}", "return", "'('", ".", "implode", "(", "\" {$operator} \"", ",", "$", "fullWhere", ")", ".", "')'", ";", "}" ]
Format the where clause of a MySQL query from a mixed range of types. @param $where @param string $operator @return string
[ "Format", "the", "where", "clause", "of", "a", "MySQL", "query", "from", "a", "mixed", "range", "of", "types", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L224-L266
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getWhere
protected function getWhere(array $queryParts) { if (!isset($queryParts['where']) || empty($queryParts['where'])) { return null; } $where = array(); foreach ($queryParts['where'] as $w) { $where[] = $this->formatWhere($w); } return 'WHERE ' . implode(' AND ', $where); }
php
protected function getWhere(array $queryParts) { if (!isset($queryParts['where']) || empty($queryParts['where'])) { return null; } $where = array(); foreach ($queryParts['where'] as $w) { $where[] = $this->formatWhere($w); } return 'WHERE ' . implode(' AND ', $where); }
[ "protected", "function", "getWhere", "(", "array", "$", "queryParts", ")", "{", "if", "(", "!", "isset", "(", "$", "queryParts", "[", "'where'", "]", ")", "||", "empty", "(", "$", "queryParts", "[", "'where'", "]", ")", ")", "{", "return", "null", ";", "}", "$", "where", "=", "array", "(", ")", ";", "foreach", "(", "$", "queryParts", "[", "'where'", "]", "as", "$", "w", ")", "{", "$", "where", "[", "]", "=", "$", "this", "->", "formatWhere", "(", "$", "w", ")", ";", "}", "return", "'WHERE '", ".", "implode", "(", "' AND '", ",", "$", "where", ")", ";", "}" ]
Prepare the where clause for use in the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "where", "clause", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L273-L285
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getGroup
protected function getGroup(array $queryParts) { if (isset($queryParts['group'])) { $group = []; foreach ($queryParts['group'] as $column) { $group[] = $this->quoteIdentifier($column); } return 'GROUP BY ' . implode(', ', $group); } return null; }
php
protected function getGroup(array $queryParts) { if (isset($queryParts['group'])) { $group = []; foreach ($queryParts['group'] as $column) { $group[] = $this->quoteIdentifier($column); } return 'GROUP BY ' . implode(', ', $group); } return null; }
[ "protected", "function", "getGroup", "(", "array", "$", "queryParts", ")", "{", "if", "(", "isset", "(", "$", "queryParts", "[", "'group'", "]", ")", ")", "{", "$", "group", "=", "[", "]", ";", "foreach", "(", "$", "queryParts", "[", "'group'", "]", "as", "$", "column", ")", "{", "$", "group", "[", "]", "=", "$", "this", "->", "quoteIdentifier", "(", "$", "column", ")", ";", "}", "return", "'GROUP BY '", ".", "implode", "(", "', '", ",", "$", "group", ")", ";", "}", "return", "null", ";", "}" ]
Prepare the group for use in the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "group", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L292-L305
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getOrder
protected function getOrder(array $queryParts) { if (isset($queryParts['order'])) { $order = []; foreach ($queryParts['order'] as $array) { $order[] = $this->quoteIdentifier($array[0]) . (strtolower($array[1]) === 'asc' ? ' ASC' : ' DESC'); } return 'ORDER BY ' . implode(', ', $order); } return null; }
php
protected function getOrder(array $queryParts) { if (isset($queryParts['order'])) { $order = []; foreach ($queryParts['order'] as $array) { $order[] = $this->quoteIdentifier($array[0]) . (strtolower($array[1]) === 'asc' ? ' ASC' : ' DESC'); } return 'ORDER BY ' . implode(', ', $order); } return null; }
[ "protected", "function", "getOrder", "(", "array", "$", "queryParts", ")", "{", "if", "(", "isset", "(", "$", "queryParts", "[", "'order'", "]", ")", ")", "{", "$", "order", "=", "[", "]", ";", "foreach", "(", "$", "queryParts", "[", "'order'", "]", "as", "$", "array", ")", "{", "$", "order", "[", "]", "=", "$", "this", "->", "quoteIdentifier", "(", "$", "array", "[", "0", "]", ")", ".", "(", "strtolower", "(", "$", "array", "[", "1", "]", ")", "===", "'asc'", "?", "' ASC'", ":", "' DESC'", ")", ";", "}", "return", "'ORDER BY '", ".", "implode", "(", "', '", ",", "$", "order", ")", ";", "}", "return", "null", ";", "}" ]
Prepare the order for use in the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "order", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L312-L327
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.getLimit
protected function getLimit(array $queryParts) { if (isset($queryParts['limit']) && !empty($queryParts['limit'])) { $limit = []; foreach ($queryParts['limit'] as $int) { $limit[] = (int)$int; } return 'LIMIT ' . implode(', ', $limit); } return null; }
php
protected function getLimit(array $queryParts) { if (isset($queryParts['limit']) && !empty($queryParts['limit'])) { $limit = []; foreach ($queryParts['limit'] as $int) { $limit[] = (int)$int; } return 'LIMIT ' . implode(', ', $limit); } return null; }
[ "protected", "function", "getLimit", "(", "array", "$", "queryParts", ")", "{", "if", "(", "isset", "(", "$", "queryParts", "[", "'limit'", "]", ")", "&&", "!", "empty", "(", "$", "queryParts", "[", "'limit'", "]", ")", ")", "{", "$", "limit", "=", "[", "]", ";", "foreach", "(", "$", "queryParts", "[", "'limit'", "]", "as", "$", "int", ")", "{", "$", "limit", "[", "]", "=", "(", "int", ")", "$", "int", ";", "}", "return", "'LIMIT '", ".", "implode", "(", "', '", ",", "$", "limit", ")", ";", "}", "return", "null", ";", "}" ]
Prepare the limit for use in the MySQL query. @param array $queryParts @return null|string
[ "Prepare", "the", "limit", "for", "use", "in", "the", "MySQL", "query", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L334-L346
train
Soneritics/Database
Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php
MySQLTrait.buildQuery
public function buildQuery(QueryAbstract $query) { $queryParts = $query->getQueryParts(); return implode( ' ', array_filter( [ $queryParts['type'], $this->getFields($queryParts), $this->getTable($queryParts), $this->getSet($queryParts), $this->getValues($queryParts), $this->getJoins($queryParts), $this->getWhere($queryParts), $this->getGroup($queryParts), $this->getOrder($queryParts), $this->getLimit($queryParts) ], function ($var) { return $var !== null; } ) ); }
php
public function buildQuery(QueryAbstract $query) { $queryParts = $query->getQueryParts(); return implode( ' ', array_filter( [ $queryParts['type'], $this->getFields($queryParts), $this->getTable($queryParts), $this->getSet($queryParts), $this->getValues($queryParts), $this->getJoins($queryParts), $this->getWhere($queryParts), $this->getGroup($queryParts), $this->getOrder($queryParts), $this->getLimit($queryParts) ], function ($var) { return $var !== null; } ) ); }
[ "public", "function", "buildQuery", "(", "QueryAbstract", "$", "query", ")", "{", "$", "queryParts", "=", "$", "query", "->", "getQueryParts", "(", ")", ";", "return", "implode", "(", "' '", ",", "array_filter", "(", "[", "$", "queryParts", "[", "'type'", "]", ",", "$", "this", "->", "getFields", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getTable", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getSet", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getValues", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getJoins", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getWhere", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getGroup", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getOrder", "(", "$", "queryParts", ")", ",", "$", "this", "->", "getLimit", "(", "$", "queryParts", ")", "]", ",", "function", "(", "$", "var", ")", "{", "return", "$", "var", "!==", "null", ";", "}", ")", ")", ";", "}" ]
Build a query string from a QueryAbstract @param QueryAbstract $query @return string
[ "Build", "a", "query", "string", "from", "a", "QueryAbstract" ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/DatabaseTypeTraits/MySQLTrait.php#L353-L376
train
MichaelRShelton/attribute-translator
src/AttributeTranslator.php
AttributeTranslator.offsetUnset
public function offsetUnset($offset) { unset($this->map[$offset]); $this->origin = $this->map->keys(); return $this; }
php
public function offsetUnset($offset) { unset($this->map[$offset]); $this->origin = $this->map->keys(); return $this; }
[ "public", "function", "offsetUnset", "(", "$", "offset", ")", "{", "unset", "(", "$", "this", "->", "map", "[", "$", "offset", "]", ")", ";", "$", "this", "->", "origin", "=", "$", "this", "->", "map", "->", "keys", "(", ")", ";", "return", "$", "this", ";", "}" ]
ArrayAccess. Deletes the given key offset. @param $offset @return $this;
[ "ArrayAccess", ".", "Deletes", "the", "given", "key", "offset", "." ]
48a0ef01058647eeeeeeb8954f93b479bd713b82
https://github.com/MichaelRShelton/attribute-translator/blob/48a0ef01058647eeeeeeb8954f93b479bd713b82/src/AttributeTranslator.php#L234-L239
train
MichaelRShelton/attribute-translator
src/AttributeTranslator.php
AttributeTranslator.castToArray
protected function castToArray(&$subject) { if (is_array($subject) === false) { if (Arr::accessible($subject) === false) { $subject = new Collection($subject); } $subject = $subject instanceof Arrayable ? $subject->toArray() : (array)$subject; } return $this; }
php
protected function castToArray(&$subject) { if (is_array($subject) === false) { if (Arr::accessible($subject) === false) { $subject = new Collection($subject); } $subject = $subject instanceof Arrayable ? $subject->toArray() : (array)$subject; } return $this; }
[ "protected", "function", "castToArray", "(", "&", "$", "subject", ")", "{", "if", "(", "is_array", "(", "$", "subject", ")", "===", "false", ")", "{", "if", "(", "Arr", "::", "accessible", "(", "$", "subject", ")", "===", "false", ")", "{", "$", "subject", "=", "new", "Collection", "(", "$", "subject", ")", ";", "}", "$", "subject", "=", "$", "subject", "instanceof", "Arrayable", "?", "$", "subject", "->", "toArray", "(", ")", ":", "(", "array", ")", "$", "subject", ";", "}", "return", "$", "this", ";", "}" ]
Because of the enumerable ways non-arrays can act like arrays, we create a Collection, which has useful normalizer functions, and return that as an array. @param mixed $subject @return $this
[ "Because", "of", "the", "enumerable", "ways", "non", "-", "arrays", "can", "act", "like", "arrays", "we", "create", "a", "Collection", "which", "has", "useful", "normalizer", "functions", "and", "return", "that", "as", "an", "array", "." ]
48a0ef01058647eeeeeeb8954f93b479bd713b82
https://github.com/MichaelRShelton/attribute-translator/blob/48a0ef01058647eeeeeeb8954f93b479bd713b82/src/AttributeTranslator.php#L410-L419
train
MichaelRShelton/attribute-translator
src/AttributeTranslator.php
AttributeTranslator.defineKeys
protected function defineKeys(&$subject, array $attributes, $value = null) { foreach ($attributes as $attribute) { $subject[$attribute] = $value; } return $this; }
php
protected function defineKeys(&$subject, array $attributes, $value = null) { foreach ($attributes as $attribute) { $subject[$attribute] = $value; } return $this; }
[ "protected", "function", "defineKeys", "(", "&", "$", "subject", ",", "array", "$", "attributes", ",", "$", "value", "=", "null", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "subject", "[", "$", "attribute", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Define the given array of attributes as keys in the given subject. @param array $subject @param array $attributes @param mixed|null $value @return $this
[ "Define", "the", "given", "array", "of", "attributes", "as", "keys", "in", "the", "given", "subject", "." ]
48a0ef01058647eeeeeeb8954f93b479bd713b82
https://github.com/MichaelRShelton/attribute-translator/blob/48a0ef01058647eeeeeeb8954f93b479bd713b82/src/AttributeTranslator.php#L429-L435
train
MichaelRShelton/attribute-translator
src/AttributeTranslator.php
AttributeTranslator.pushAttributes
protected function pushAttributes(&$subject, array $attributes, bool $unique = true) { foreach ($attributes as $attribute) { if ($unique === false || in_array($attribute, $subject) === false) { $subject[] = $attribute; } } return $this; }
php
protected function pushAttributes(&$subject, array $attributes, bool $unique = true) { foreach ($attributes as $attribute) { if ($unique === false || in_array($attribute, $subject) === false) { $subject[] = $attribute; } } return $this; }
[ "protected", "function", "pushAttributes", "(", "&", "$", "subject", ",", "array", "$", "attributes", ",", "bool", "$", "unique", "=", "true", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "if", "(", "$", "unique", "===", "false", "||", "in_array", "(", "$", "attribute", ",", "$", "subject", ")", "===", "false", ")", "{", "$", "subject", "[", "]", "=", "$", "attribute", ";", "}", "}", "return", "$", "this", ";", "}" ]
Push the given array of attributes to the given subject. @param array $subject @param array $attributes @param bool $unique @return $this
[ "Push", "the", "given", "array", "of", "attributes", "to", "the", "given", "subject", "." ]
48a0ef01058647eeeeeeb8954f93b479bd713b82
https://github.com/MichaelRShelton/attribute-translator/blob/48a0ef01058647eeeeeeb8954f93b479bd713b82/src/AttributeTranslator.php#L445-L453
train
phpffcms/ffcms-core
src/Helper/Crypt.php
Crypt.passwordHash
public static function passwordHash(string $text): ?string { return password_hash($text, self::PASSWORD_CRYPT_ALGO, [ 'cost' => self::PASSWORD_CRYPT_COST ]); }
php
public static function passwordHash(string $text): ?string { return password_hash($text, self::PASSWORD_CRYPT_ALGO, [ 'cost' => self::PASSWORD_CRYPT_COST ]); }
[ "public", "static", "function", "passwordHash", "(", "string", "$", "text", ")", ":", "?", "string", "{", "return", "password_hash", "(", "$", "text", ",", "self", "::", "PASSWORD_CRYPT_ALGO", ",", "[", "'cost'", "=>", "self", "::", "PASSWORD_CRYPT_COST", "]", ")", ";", "}" ]
Generate password hash using php password_hash with predefined algo @param string $text @return null|string
[ "Generate", "password", "hash", "using", "php", "password_hash", "with", "predefined", "algo" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Crypt.php#L21-L26
train
phpffcms/ffcms-core
src/Helper/Crypt.php
Crypt.passwordVerify
public static function passwordVerify(string $password, string $hash): bool { return (Str::length($hash) > 0 && password_verify($password, $hash)); }
php
public static function passwordVerify(string $password, string $hash): bool { return (Str::length($hash) > 0 && password_verify($password, $hash)); }
[ "public", "static", "function", "passwordVerify", "(", "string", "$", "password", ",", "string", "$", "hash", ")", ":", "bool", "{", "return", "(", "Str", "::", "length", "(", "$", "hash", ")", ">", "0", "&&", "password_verify", "(", "$", "password", ",", "$", "hash", ")", ")", ";", "}" ]
Verify password to hash equality @param string $password @param string $hash @return bool
[ "Verify", "password", "to", "hash", "equality" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Crypt.php#L34-L37
train
phpffcms/ffcms-core
src/Helper/Crypt.php
Crypt.randomString
public static function randomString(int $length): string { try { $rand = bin2hex(random_bytes($length)); // bytes_length = length * 2 $rand = substr($rand, 0, $length); } catch (\Exception $ce) { $rand = Str::randomLatinNumeric($length); } return $rand; }
php
public static function randomString(int $length): string { try { $rand = bin2hex(random_bytes($length)); // bytes_length = length * 2 $rand = substr($rand, 0, $length); } catch (\Exception $ce) { $rand = Str::randomLatinNumeric($length); } return $rand; }
[ "public", "static", "function", "randomString", "(", "int", "$", "length", ")", ":", "string", "{", "try", "{", "$", "rand", "=", "bin2hex", "(", "random_bytes", "(", "$", "length", ")", ")", ";", "// bytes_length = length * 2", "$", "rand", "=", "substr", "(", "$", "rand", ",", "0", ",", "$", "length", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ce", ")", "{", "$", "rand", "=", "Str", "::", "randomLatinNumeric", "(", "$", "length", ")", ";", "}", "return", "$", "rand", ";", "}" ]
Generate random string with numbers from secure function random_bytes @param int $length @return string
[ "Generate", "random", "string", "with", "numbers", "from", "secure", "function", "random_bytes" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Crypt.php#L54-L65
train
prolic/HumusPHPUnitModule
src/HumusPHPUnitModule/Controller/IndexController.php
IndexController.runAction
public function runAction() { $request = $this->getRequest(); /* @var $request \Zend\Console\Request */ $serviceParameters = array(); foreach ($this->paramsToTest as $params) { foreach ($params as $param) { if ($result = $request->getParam($param)) { $serviceParameters[$params[0]] = $result; continue; } } } $runner = $this->runner; $runner->setParams($serviceParameters); $output = $runner->run(); $response = $this->getResponse(); /* @var $response \Zend\Console\Response */ $response->setContent($output); $response->setErrorLevel($runner->getExitCode()); return $response; }
php
public function runAction() { $request = $this->getRequest(); /* @var $request \Zend\Console\Request */ $serviceParameters = array(); foreach ($this->paramsToTest as $params) { foreach ($params as $param) { if ($result = $request->getParam($param)) { $serviceParameters[$params[0]] = $result; continue; } } } $runner = $this->runner; $runner->setParams($serviceParameters); $output = $runner->run(); $response = $this->getResponse(); /* @var $response \Zend\Console\Response */ $response->setContent($output); $response->setErrorLevel($runner->getExitCode()); return $response; }
[ "public", "function", "runAction", "(", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "/* @var $request \\Zend\\Console\\Request */", "$", "serviceParameters", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "paramsToTest", "as", "$", "params", ")", "{", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "if", "(", "$", "result", "=", "$", "request", "->", "getParam", "(", "$", "param", ")", ")", "{", "$", "serviceParameters", "[", "$", "params", "[", "0", "]", "]", "=", "$", "result", ";", "continue", ";", "}", "}", "}", "$", "runner", "=", "$", "this", "->", "runner", ";", "$", "runner", "->", "setParams", "(", "$", "serviceParameters", ")", ";", "$", "output", "=", "$", "runner", "->", "run", "(", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", ";", "/* @var $response \\Zend\\Console\\Response */", "$", "response", "->", "setContent", "(", "$", "output", ")", ";", "$", "response", "->", "setErrorLevel", "(", "$", "runner", "->", "getExitCode", "(", ")", ")", ";", "return", "$", "response", ";", "}" ]
Runs all tests and sets the exit code @return \Zend\Console\Response|\Zend\Stdlib\ResponseInterface
[ "Runs", "all", "tests", "and", "sets", "the", "exit", "code" ]
ee7c4a01c915a53506c5395e41ec8c26ac4ed7e9
https://github.com/prolic/HumusPHPUnitModule/blob/ee7c4a01c915a53506c5395e41ec8c26ac4ed7e9/src/HumusPHPUnitModule/Controller/IndexController.php#L58-L83
train
netbull/CoreBundle
Form/DataTransformer/EntitiesToPropertyTransformer.php
EntitiesToPropertyTransformer.transform
public function transform($entities) { if (is_null($entities) || count($entities) === 0) { return []; } $data = []; $accessor = PropertyAccess::createPropertyAccessor(); foreach ($entities as $entity) { $text = is_null($this->textProperty) ? (string)$entity : $accessor->getValue($entity, $this->textProperty); $data[$accessor->getValue($entity, $this->primaryKey)] = [ 'text' => $text ]; } return $data; }
php
public function transform($entities) { if (is_null($entities) || count($entities) === 0) { return []; } $data = []; $accessor = PropertyAccess::createPropertyAccessor(); foreach ($entities as $entity) { $text = is_null($this->textProperty) ? (string)$entity : $accessor->getValue($entity, $this->textProperty); $data[$accessor->getValue($entity, $this->primaryKey)] = [ 'text' => $text ]; } return $data; }
[ "public", "function", "transform", "(", "$", "entities", ")", "{", "if", "(", "is_null", "(", "$", "entities", ")", "||", "count", "(", "$", "entities", ")", "===", "0", ")", "{", "return", "[", "]", ";", "}", "$", "data", "=", "[", "]", ";", "$", "accessor", "=", "PropertyAccess", "::", "createPropertyAccessor", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "text", "=", "is_null", "(", "$", "this", "->", "textProperty", ")", "?", "(", "string", ")", "$", "entity", ":", "$", "accessor", "->", "getValue", "(", "$", "entity", ",", "$", "this", "->", "textProperty", ")", ";", "$", "data", "[", "$", "accessor", "->", "getValue", "(", "$", "entity", ",", "$", "this", "->", "primaryKey", ")", "]", "=", "[", "'text'", "=>", "$", "text", "]", ";", "}", "return", "$", "data", ";", "}" ]
Transform initial entities to array @param mixed $entities @return array
[ "Transform", "initial", "entities", "to", "array" ]
0bacc1d9e4733b6da613027400c48421e5a14645
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Form/DataTransformer/EntitiesToPropertyTransformer.php#L57-L76
train
Weblab-nl/curl
src/Result.php
Result.setHeaders
private function setHeaders($headers) { // Make array of the different headers $headers = explode(PHP_EOL, $headers); foreach ($headers as $header) { // Cut the header into pieces $header = explode(': ', $header); // Skip header if it's not in the default format if (!is_array($header) && count($header) === 1) { continue; } // Get the header type $type = strtolower(array_shift($header)); // Glue the header back together $value = implode(': ', $header); // Skip header if the type or value is empty if (empty($type) || empty($value)) { continue; } // Store the header $this->headers[$type] = trim($value); } }
php
private function setHeaders($headers) { // Make array of the different headers $headers = explode(PHP_EOL, $headers); foreach ($headers as $header) { // Cut the header into pieces $header = explode(': ', $header); // Skip header if it's not in the default format if (!is_array($header) && count($header) === 1) { continue; } // Get the header type $type = strtolower(array_shift($header)); // Glue the header back together $value = implode(': ', $header); // Skip header if the type or value is empty if (empty($type) || empty($value)) { continue; } // Store the header $this->headers[$type] = trim($value); } }
[ "private", "function", "setHeaders", "(", "$", "headers", ")", "{", "// Make array of the different headers", "$", "headers", "=", "explode", "(", "PHP_EOL", ",", "$", "headers", ")", ";", "foreach", "(", "$", "headers", "as", "$", "header", ")", "{", "// Cut the header into pieces", "$", "header", "=", "explode", "(", "': '", ",", "$", "header", ")", ";", "// Skip header if it's not in the default format", "if", "(", "!", "is_array", "(", "$", "header", ")", "&&", "count", "(", "$", "header", ")", "===", "1", ")", "{", "continue", ";", "}", "// Get the header type", "$", "type", "=", "strtolower", "(", "array_shift", "(", "$", "header", ")", ")", ";", "// Glue the header back together", "$", "value", "=", "implode", "(", "': '", ",", "$", "header", ")", ";", "// Skip header if the type or value is empty", "if", "(", "empty", "(", "$", "type", ")", "||", "empty", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "// Store the header", "$", "this", "->", "headers", "[", "$", "type", "]", "=", "trim", "(", "$", "value", ")", ";", "}", "}" ]
Parse and store the headers @param string $headers
[ "Parse", "and", "store", "the", "headers" ]
e2879ab970e0d8161d5a49b46805bc36a8ba94a9
https://github.com/Weblab-nl/curl/blob/e2879ab970e0d8161d5a49b46805bc36a8ba94a9/src/Result.php#L52-L79
train
agentmedia/phine-core
src/Core/Snippets/BackendRights/ContentRights.php
ContentRights.Save
function Save() { if (!$this->rights) { $this->rights = new BackendContentRights(); } $this->rights->SetCreateIn($this->Value('CreateIn')); $this->rights->SetEdit($this->Value('Edit')); $this->rights->SetMove($this->Value('Move')); $this->rights->SetRemove($this->Value('Remove')); $this->rights->Save(); }
php
function Save() { if (!$this->rights) { $this->rights = new BackendContentRights(); } $this->rights->SetCreateIn($this->Value('CreateIn')); $this->rights->SetEdit($this->Value('Edit')); $this->rights->SetMove($this->Value('Move')); $this->rights->SetRemove($this->Value('Remove')); $this->rights->Save(); }
[ "function", "Save", "(", ")", "{", "if", "(", "!", "$", "this", "->", "rights", ")", "{", "$", "this", "->", "rights", "=", "new", "BackendContentRights", "(", ")", ";", "}", "$", "this", "->", "rights", "->", "SetCreateIn", "(", "$", "this", "->", "Value", "(", "'CreateIn'", ")", ")", ";", "$", "this", "->", "rights", "->", "SetEdit", "(", "$", "this", "->", "Value", "(", "'Edit'", ")", ")", ";", "$", "this", "->", "rights", "->", "SetMove", "(", "$", "this", "->", "Value", "(", "'Move'", ")", ")", ";", "$", "this", "->", "rights", "->", "SetRemove", "(", "$", "this", "->", "Value", "(", "'Remove'", ")", ")", ";", "$", "this", "->", "rights", "->", "Save", "(", ")", ";", "}" ]
Saves the content rights
[ "Saves", "the", "content", "rights" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Snippets/BackendRights/ContentRights.php#L39-L50
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getAncestorsNames
public function getAncestorsNames() { $names = []; if ($this->hasParent()) { $names = $this->getParent()->getAncestorsNames(); } $names[] = $this->getName(); return $names; }
php
public function getAncestorsNames() { $names = []; if ($this->hasParent()) { $names = $this->getParent()->getAncestorsNames(); } $names[] = $this->getName(); return $names; }
[ "public", "function", "getAncestorsNames", "(", ")", "{", "$", "names", "=", "[", "]", ";", "if", "(", "$", "this", "->", "hasParent", "(", ")", ")", "{", "$", "names", "=", "$", "this", "->", "getParent", "(", ")", "->", "getAncestorsNames", "(", ")", ";", "}", "$", "names", "[", "]", "=", "$", "this", "->", "getName", "(", ")", ";", "return", "$", "names", ";", "}" ]
Get all ancestors names. It includes the name of the object itself. @return array
[ "Get", "all", "ancestors", "names", ".", "It", "includes", "the", "name", "of", "the", "object", "itself", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L196-L204
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getDescendants
public function getDescendants() { $descendants = []; if ($this->hasChildren()) { foreach ($this->getChildren() as $child) { $childDescendants = $child->hasChildren() ? $child->getDescendants() : []; $descendants = ArrayUtils::merge($descendants, ArrayUtils::merge([$child], $childDescendants)); } } return $descendants; }
php
public function getDescendants() { $descendants = []; if ($this->hasChildren()) { foreach ($this->getChildren() as $child) { $childDescendants = $child->hasChildren() ? $child->getDescendants() : []; $descendants = ArrayUtils::merge($descendants, ArrayUtils::merge([$child], $childDescendants)); } } return $descendants; }
[ "public", "function", "getDescendants", "(", ")", "{", "$", "descendants", "=", "[", "]", ";", "if", "(", "$", "this", "->", "hasChildren", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "$", "childDescendants", "=", "$", "child", "->", "hasChildren", "(", ")", "?", "$", "child", "->", "getDescendants", "(", ")", ":", "[", "]", ";", "$", "descendants", "=", "ArrayUtils", "::", "merge", "(", "$", "descendants", ",", "ArrayUtils", "::", "merge", "(", "[", "$", "child", "]", ",", "$", "childDescendants", ")", ")", ";", "}", "}", "return", "$", "descendants", ";", "}" ]
Get all descendants. @return EnvironmentInterface[]
[ "Get", "all", "descendants", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L263-L273
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getUsers
public function getUsers() { if ($this->users === null) { $this->setUsers($this->userRepository->getAllByEnvironment($this)); } return $this->users; }
php
public function getUsers() { if ($this->users === null) { $this->setUsers($this->userRepository->getAllByEnvironment($this)); } return $this->users; }
[ "public", "function", "getUsers", "(", ")", "{", "if", "(", "$", "this", "->", "users", "===", "null", ")", "{", "$", "this", "->", "setUsers", "(", "$", "this", "->", "userRepository", "->", "getAllByEnvironment", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "users", ";", "}" ]
Get Users. @return UserInterface[]
[ "Get", "Users", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L412-L418
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getCurrentRevision
public function getCurrentRevision() { if ($this->currentRevision === null) { $this->setCurrentRevision($this->revisionRepository->getCurrentByEnvironment($this)); } return $this->currentRevision; }
php
public function getCurrentRevision() { if ($this->currentRevision === null) { $this->setCurrentRevision($this->revisionRepository->getCurrentByEnvironment($this)); } return $this->currentRevision; }
[ "public", "function", "getCurrentRevision", "(", ")", "{", "if", "(", "$", "this", "->", "currentRevision", "===", "null", ")", "{", "$", "this", "->", "setCurrentRevision", "(", "$", "this", "->", "revisionRepository", "->", "getCurrentByEnvironment", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "currentRevision", ";", "}" ]
Get CurrentRevision. @return \KmbDomain\Model\RevisionInterface
[ "Get", "CurrentRevision", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L480-L486
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getLastReleasedRevision
public function getLastReleasedRevision() { if ($this->lastReleasedRevision === null) { $this->setLastReleasedRevision($this->revisionRepository->getLastReleasedByEnvironment($this)); } return $this->lastReleasedRevision; }
php
public function getLastReleasedRevision() { if ($this->lastReleasedRevision === null) { $this->setLastReleasedRevision($this->revisionRepository->getLastReleasedByEnvironment($this)); } return $this->lastReleasedRevision; }
[ "public", "function", "getLastReleasedRevision", "(", ")", "{", "if", "(", "$", "this", "->", "lastReleasedRevision", "===", "null", ")", "{", "$", "this", "->", "setLastReleasedRevision", "(", "$", "this", "->", "revisionRepository", "->", "getLastReleasedByEnvironment", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "lastReleasedRevision", ";", "}" ]
Get LastReleasedRevision. @return \KmbDomain\Model\RevisionInterface
[ "Get", "LastReleasedRevision", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L505-L511
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php
EnvironmentProxy.getReleasedRevisions
public function getReleasedRevisions() { if ($this->releasedRevisions === null) { $this->setReleasedRevisions($this->revisionRepository->getAllReleasedByEnvironment($this)); } return $this->releasedRevisions; }
php
public function getReleasedRevisions() { if ($this->releasedRevisions === null) { $this->setReleasedRevisions($this->revisionRepository->getAllReleasedByEnvironment($this)); } return $this->releasedRevisions; }
[ "public", "function", "getReleasedRevisions", "(", ")", "{", "if", "(", "$", "this", "->", "releasedRevisions", "===", "null", ")", "{", "$", "this", "->", "setReleasedRevisions", "(", "$", "this", "->", "revisionRepository", "->", "getAllReleasedByEnvironment", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "releasedRevisions", ";", "}" ]
Get ReleasedRevisions. @return \KmbDomain\Model\RevisionInterface[]
[ "Get", "ReleasedRevisions", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/EnvironmentProxy.php#L530-L536
train
libreworks/caridea-acl
src/CacheStrategy.php
CacheStrategy.load
public function load(Target $target, array $subjects, Service $service): Acl { $key = $this->buildKey($target, $subjects); if (!isset($this->cache[$key])) { $acl = $this->delegate->load($target, $subjects, $service); $this->cache[$key] = $acl; } return $this->cache[$key]; }
php
public function load(Target $target, array $subjects, Service $service): Acl { $key = $this->buildKey($target, $subjects); if (!isset($this->cache[$key])) { $acl = $this->delegate->load($target, $subjects, $service); $this->cache[$key] = $acl; } return $this->cache[$key]; }
[ "public", "function", "load", "(", "Target", "$", "target", ",", "array", "$", "subjects", ",", "Service", "$", "service", ")", ":", "Acl", "{", "$", "key", "=", "$", "this", "->", "buildKey", "(", "$", "target", ",", "$", "subjects", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "key", "]", ")", ")", "{", "$", "acl", "=", "$", "this", "->", "delegate", "->", "load", "(", "$", "target", ",", "$", "subjects", ",", "$", "service", ")", ";", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "$", "acl", ";", "}", "return", "$", "this", "->", "cache", "[", "$", "key", "]", ";", "}" ]
Loads the ACL for a Target. @param \Caridea\Acl\Target $target The `Target` whose ACL will be loaded @param \Caridea\Acl\Subject[] $subjects An array of `Subject`s @param \Caridea\Acl\Service $service The ACL service (to load parent ACLs) @return \Caridea\Acl\Acl The loaded ACL @throws \Caridea\Acl\Exception\Unloadable If the resource provided is invalid @throws \InvalidArgumentException If the `subjects` argument contains invalid values
[ "Loads", "the", "ACL", "for", "a", "Target", "." ]
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/CacheStrategy.php#L60-L68
train
libreworks/caridea-acl
src/CacheStrategy.php
CacheStrategy.loadAll
public function loadAll(array $targets, array $subjects, Service $service): array { $acls = []; if ($this->delegate instanceof MultiStrategy) { $oids = array_merge($targets); foreach ($targets as $i => $target) { if (!($target instanceof Target)) { throw new \InvalidArgumentException("Only instances of Target are permitted in the targets argument"); } $key = $this->buildKey($target, $subjects); if (isset($this->cache[$key])) { $acls[(string)$target] = $this->cache[$key]; unset($oids[$i]); } } if (!empty($oids)) { $a = $this->delegate->loadAll($oids, $subjects, $service); foreach ($a as $acl) { $key = $this->buildKey($acl->getTarget(), $subjects); $this->cache[$key] = $acl; $acls[(string)$acl->getTarget()] = $acl; } } } else { foreach ($targets as $target) { if (!($target instanceof Target)) { throw new \InvalidArgumentException("Only instances of Target are permitted in the targets argument"); } $acls[(string) $target] = $this->load($target, $subjects, $service); } } return $acls; }
php
public function loadAll(array $targets, array $subjects, Service $service): array { $acls = []; if ($this->delegate instanceof MultiStrategy) { $oids = array_merge($targets); foreach ($targets as $i => $target) { if (!($target instanceof Target)) { throw new \InvalidArgumentException("Only instances of Target are permitted in the targets argument"); } $key = $this->buildKey($target, $subjects); if (isset($this->cache[$key])) { $acls[(string)$target] = $this->cache[$key]; unset($oids[$i]); } } if (!empty($oids)) { $a = $this->delegate->loadAll($oids, $subjects, $service); foreach ($a as $acl) { $key = $this->buildKey($acl->getTarget(), $subjects); $this->cache[$key] = $acl; $acls[(string)$acl->getTarget()] = $acl; } } } else { foreach ($targets as $target) { if (!($target instanceof Target)) { throw new \InvalidArgumentException("Only instances of Target are permitted in the targets argument"); } $acls[(string) $target] = $this->load($target, $subjects, $service); } } return $acls; }
[ "public", "function", "loadAll", "(", "array", "$", "targets", ",", "array", "$", "subjects", ",", "Service", "$", "service", ")", ":", "array", "{", "$", "acls", "=", "[", "]", ";", "if", "(", "$", "this", "->", "delegate", "instanceof", "MultiStrategy", ")", "{", "$", "oids", "=", "array_merge", "(", "$", "targets", ")", ";", "foreach", "(", "$", "targets", "as", "$", "i", "=>", "$", "target", ")", "{", "if", "(", "!", "(", "$", "target", "instanceof", "Target", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Only instances of Target are permitted in the targets argument\"", ")", ";", "}", "$", "key", "=", "$", "this", "->", "buildKey", "(", "$", "target", ",", "$", "subjects", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "key", "]", ")", ")", "{", "$", "acls", "[", "(", "string", ")", "$", "target", "]", "=", "$", "this", "->", "cache", "[", "$", "key", "]", ";", "unset", "(", "$", "oids", "[", "$", "i", "]", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "oids", ")", ")", "{", "$", "a", "=", "$", "this", "->", "delegate", "->", "loadAll", "(", "$", "oids", ",", "$", "subjects", ",", "$", "service", ")", ";", "foreach", "(", "$", "a", "as", "$", "acl", ")", "{", "$", "key", "=", "$", "this", "->", "buildKey", "(", "$", "acl", "->", "getTarget", "(", ")", ",", "$", "subjects", ")", ";", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "$", "acl", ";", "$", "acls", "[", "(", "string", ")", "$", "acl", "->", "getTarget", "(", ")", "]", "=", "$", "acl", ";", "}", "}", "}", "else", "{", "foreach", "(", "$", "targets", "as", "$", "target", ")", "{", "if", "(", "!", "(", "$", "target", "instanceof", "Target", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Only instances of Target are permitted in the targets argument\"", ")", ";", "}", "$", "acls", "[", "(", "string", ")", "$", "target", "]", "=", "$", "this", "->", "load", "(", "$", "target", ",", "$", "subjects", ",", "$", "service", ")", ";", "}", "}", "return", "$", "acls", ";", "}" ]
Loads the ACLs for several Targets. @since 2.1.0 @param \Caridea\Acl\Target[] $targets The `Target` whose ACL will be loaded @param \Caridea\Acl\Subject[] $subjects An array of `Subject`s @param \Caridea\Acl\Service $service The ACL service (to load parent ACLs) @return array<string,\Caridea\Acl\Acl> The loaded ACLs @throws \Caridea\Acl\Exception\Unloadable If the target provided is invalid @throws \InvalidArgumentException If the `subjects` argument contains invalid values
[ "Loads", "the", "ACLs", "for", "several", "Targets", "." ]
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/CacheStrategy.php#L81-L113
train
libreworks/caridea-acl
src/CacheStrategy.php
CacheStrategy.buildKey
protected function buildKey(Target $target, array $subjects): string { $key = (string) $target; foreach ($subjects as $subject) { if (!($subject instanceof Subject)) { throw new \InvalidArgumentException("Only instances of Subject are permitted in the subjects argument"); } $key .= ";{$subject}"; } return $key; }
php
protected function buildKey(Target $target, array $subjects): string { $key = (string) $target; foreach ($subjects as $subject) { if (!($subject instanceof Subject)) { throw new \InvalidArgumentException("Only instances of Subject are permitted in the subjects argument"); } $key .= ";{$subject}"; } return $key; }
[ "protected", "function", "buildKey", "(", "Target", "$", "target", ",", "array", "$", "subjects", ")", ":", "string", "{", "$", "key", "=", "(", "string", ")", "$", "target", ";", "foreach", "(", "$", "subjects", "as", "$", "subject", ")", "{", "if", "(", "!", "(", "$", "subject", "instanceof", "Subject", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Only instances of Subject are permitted in the subjects argument\"", ")", ";", "}", "$", "key", ".=", "\";{$subject}\"", ";", "}", "return", "$", "key", ";", "}" ]
Generates the key to use for caching the ACL. @param \Caridea\Acl\Target $target The `Target` whose ACL will be loaded @param array $subjects An array of `Subject`s @return string The cache key @throws \InvalidArgumentException If the `subjects` argument contains invalid values
[ "Generates", "the", "key", "to", "use", "for", "caching", "the", "ACL", "." ]
64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/CacheStrategy.php#L123-L133
train
nirou8/php-multiple-saml
lib/Saml2/Utils.php
OneLogin_Saml2_Utils.getSelfURL
public static function getSelfURL() { $selfURLhost = self::getSelfURLhost(); $requestURI = ''; if (!empty($_SERVER['REQUEST_URI'])) { $requestURI = $_SERVER['REQUEST_URI']; if ($requestURI[0] !== '/') { if (preg_match('#^https?://[^/]*(/.*)#i', $requestURI, $matches)) { $requestURI = $matches[1]; } } } $infoWithBaseURLPath = self::buildWithBaseURLPath($requestURI); if (!empty($infoWithBaseURLPath)) { $requestURI = $infoWithBaseURLPath; } return $selfURLhost . $requestURI; }
php
public static function getSelfURL() { $selfURLhost = self::getSelfURLhost(); $requestURI = ''; if (!empty($_SERVER['REQUEST_URI'])) { $requestURI = $_SERVER['REQUEST_URI']; if ($requestURI[0] !== '/') { if (preg_match('#^https?://[^/]*(/.*)#i', $requestURI, $matches)) { $requestURI = $matches[1]; } } } $infoWithBaseURLPath = self::buildWithBaseURLPath($requestURI); if (!empty($infoWithBaseURLPath)) { $requestURI = $infoWithBaseURLPath; } return $selfURLhost . $requestURI; }
[ "public", "static", "function", "getSelfURL", "(", ")", "{", "$", "selfURLhost", "=", "self", "::", "getSelfURLhost", "(", ")", ";", "$", "requestURI", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", "{", "$", "requestURI", "=", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ";", "if", "(", "$", "requestURI", "[", "0", "]", "!==", "'/'", ")", "{", "if", "(", "preg_match", "(", "'#^https?://[^/]*(/.*)#i'", ",", "$", "requestURI", ",", "$", "matches", ")", ")", "{", "$", "requestURI", "=", "$", "matches", "[", "1", "]", ";", "}", "}", "}", "$", "infoWithBaseURLPath", "=", "self", "::", "buildWithBaseURLPath", "(", "$", "requestURI", ")", ";", "if", "(", "!", "empty", "(", "$", "infoWithBaseURLPath", ")", ")", "{", "$", "requestURI", "=", "$", "infoWithBaseURLPath", ";", "}", "return", "$", "selfURLhost", ".", "$", "requestURI", ";", "}" ]
Returns the URL of the current host + current view + query. @return string
[ "Returns", "the", "URL", "of", "the", "current", "host", "+", "current", "view", "+", "query", "." ]
7eb5786e678db7d45459ce3441fa187946ae9a3b
https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Utils.php#L583-L603
train
nirou8/php-multiple-saml
lib/Saml2/Utils.php
OneLogin_Saml2_Utils.castKey
public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public') { assert('is_string($algorithm)'); assert('$type === "public" || $type === "private"'); // do nothing if algorithm is already the type of the key if ($key->type === $algorithm) { return $key; } if (!OneLogin_Saml2_Utils::isSupportedSigningAlgorithm($algorithm)) { throw new \Exception('Unsupported signing algorithm.'); } $keyInfo = openssl_pkey_get_details($key->key); if ($keyInfo === false) { throw new Exception('Unable to get key details from XMLSecurityKey.'); } if (!isset($keyInfo['key'])) { throw new Exception('Missing key in public key details.'); } $newKey = new XMLSecurityKey($algorithm, array('type'=>$type)); $newKey->loadKey($keyInfo['key']); return $newKey; }
php
public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public') { assert('is_string($algorithm)'); assert('$type === "public" || $type === "private"'); // do nothing if algorithm is already the type of the key if ($key->type === $algorithm) { return $key; } if (!OneLogin_Saml2_Utils::isSupportedSigningAlgorithm($algorithm)) { throw new \Exception('Unsupported signing algorithm.'); } $keyInfo = openssl_pkey_get_details($key->key); if ($keyInfo === false) { throw new Exception('Unable to get key details from XMLSecurityKey.'); } if (!isset($keyInfo['key'])) { throw new Exception('Missing key in public key details.'); } $newKey = new XMLSecurityKey($algorithm, array('type'=>$type)); $newKey->loadKey($keyInfo['key']); return $newKey; }
[ "public", "static", "function", "castKey", "(", "XMLSecurityKey", "$", "key", ",", "$", "algorithm", ",", "$", "type", "=", "'public'", ")", "{", "assert", "(", "'is_string($algorithm)'", ")", ";", "assert", "(", "'$type === \"public\" || $type === \"private\"'", ")", ";", "// do nothing if algorithm is already the type of the key", "if", "(", "$", "key", "->", "type", "===", "$", "algorithm", ")", "{", "return", "$", "key", ";", "}", "if", "(", "!", "OneLogin_Saml2_Utils", "::", "isSupportedSigningAlgorithm", "(", "$", "algorithm", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unsupported signing algorithm.'", ")", ";", "}", "$", "keyInfo", "=", "openssl_pkey_get_details", "(", "$", "key", "->", "key", ")", ";", "if", "(", "$", "keyInfo", "===", "false", ")", "{", "throw", "new", "Exception", "(", "'Unable to get key details from XMLSecurityKey.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "keyInfo", "[", "'key'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "'Missing key in public key details.'", ")", ";", "}", "$", "newKey", "=", "new", "XMLSecurityKey", "(", "$", "algorithm", ",", "array", "(", "'type'", "=>", "$", "type", ")", ")", ";", "$", "newKey", "->", "loadKey", "(", "$", "keyInfo", "[", "'key'", "]", ")", ";", "return", "$", "newKey", ";", "}" ]
Converts a XMLSecurityKey to the correct algorithm. @param XMLSecurityKey $key The key. @param string $algorithm The desired algorithm. @param string $type Public or private key, defaults to public. @return XMLSecurityKey The new key. @throws Exception
[ "Converts", "a", "XMLSecurityKey", "to", "the", "correct", "algorithm", "." ]
7eb5786e678db7d45459ce3441fa187946ae9a3b
https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Utils.php#L1183-L1206
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Expression/Operand/Operand.php
Operand.equality
protected function equality($comparison, $operand) { return $this->expr->addCondition(new Operator\Equality( $this, $comparison, $this->expr->value($operand) )); }
php
protected function equality($comparison, $operand) { return $this->expr->addCondition(new Operator\Equality( $this, $comparison, $this->expr->value($operand) )); }
[ "protected", "function", "equality", "(", "$", "comparison", ",", "$", "operand", ")", "{", "return", "$", "this", "->", "expr", "->", "addCondition", "(", "new", "Operator", "\\", "Equality", "(", "$", "this", ",", "$", "comparison", ",", "$", "this", "->", "expr", "->", "value", "(", "$", "operand", ")", ")", ")", ";", "}" ]
Add a comparison to the current expression. @param string $comparison @param Operand|mixed $operand @return QueryBuilder|Expr
[ "Add", "a", "comparison", "to", "the", "current", "expression", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Expression/Operand/Operand.php#L60-L67
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.labels
public static function labels($q) { $e = explode('.', $q); $r = ''; for ($i = 0, $s = sizeof($e); $i < $s; ++$i) { $r .= chr(strlen($e[$i])) . $e[$i]; } if (static::binarySubstr($r, -1) !== "\x00") { $r .= "\x00"; } return $r; }
php
public static function labels($q) { $e = explode('.', $q); $r = ''; for ($i = 0, $s = sizeof($e); $i < $s; ++$i) { $r .= chr(strlen($e[$i])) . $e[$i]; } if (static::binarySubstr($r, -1) !== "\x00") { $r .= "\x00"; } return $r; }
[ "public", "static", "function", "labels", "(", "$", "q", ")", "{", "$", "e", "=", "explode", "(", "'.'", ",", "$", "q", ")", ";", "$", "r", "=", "''", ";", "for", "(", "$", "i", "=", "0", ",", "$", "s", "=", "sizeof", "(", "$", "e", ")", ";", "$", "i", "<", "$", "s", ";", "++", "$", "i", ")", "{", "$", "r", ".=", "chr", "(", "strlen", "(", "$", "e", "[", "$", "i", "]", ")", ")", ".", "$", "e", "[", "$", "i", "]", ";", "}", "if", "(", "static", "::", "binarySubstr", "(", "$", "r", ",", "-", "1", ")", "!==", "\"\\x00\"", ")", "{", "$", "r", ".=", "\"\\x00\"", ";", "}", "return", "$", "r", ";", "}" ]
Build structure of labels. @param string $q dot-separated labels list. @return string
[ "Build", "structure", "of", "labels", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L15-L27
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.parseLabels
public static function parseLabels(&$data, $orig = null) { $str = ''; while (strlen($data) > 0) { $l = ord($data[0]); if ($l >= 192) { $pos = static::bytes2int(chr($l - 192) . static::binarySubstr($data, 1, 1)); $data = static::binarySubstr($data, 2); $ref = static::binarySubstr($orig, $pos); return $str . static::parseLabels($ref); } $p = substr($data, 1, $l); $str .= $p . (($l !== 0) ? '.' : ''); $data = substr($data, $l + 1); if ($l === 0) { break; } } return $str; }
php
public static function parseLabels(&$data, $orig = null) { $str = ''; while (strlen($data) > 0) { $l = ord($data[0]); if ($l >= 192) { $pos = static::bytes2int(chr($l - 192) . static::binarySubstr($data, 1, 1)); $data = static::binarySubstr($data, 2); $ref = static::binarySubstr($orig, $pos); return $str . static::parseLabels($ref); } $p = substr($data, 1, $l); $str .= $p . (($l !== 0) ? '.' : ''); $data = substr($data, $l + 1); if ($l === 0) { break; } } return $str; }
[ "public", "static", "function", "parseLabels", "(", "&", "$", "data", ",", "$", "orig", "=", "null", ")", "{", "$", "str", "=", "''", ";", "while", "(", "strlen", "(", "$", "data", ")", ">", "0", ")", "{", "$", "l", "=", "ord", "(", "$", "data", "[", "0", "]", ")", ";", "if", "(", "$", "l", ">=", "192", ")", "{", "$", "pos", "=", "static", "::", "bytes2int", "(", "chr", "(", "$", "l", "-", "192", ")", ".", "static", "::", "binarySubstr", "(", "$", "data", ",", "1", ",", "1", ")", ")", ";", "$", "data", "=", "static", "::", "binarySubstr", "(", "$", "data", ",", "2", ")", ";", "$", "ref", "=", "static", "::", "binarySubstr", "(", "$", "orig", ",", "$", "pos", ")", ";", "return", "$", "str", ".", "static", "::", "parseLabels", "(", "$", "ref", ")", ";", "}", "$", "p", "=", "substr", "(", "$", "data", ",", "1", ",", "$", "l", ")", ";", "$", "str", ".=", "$", "p", ".", "(", "(", "$", "l", "!==", "0", ")", "?", "'.'", ":", "''", ")", ";", "$", "data", "=", "substr", "(", "$", "data", ",", "$", "l", "+", "1", ")", ";", "if", "(", "$", "l", "===", "0", ")", "{", "break", ";", "}", "}", "return", "$", "str", ";", "}" ]
Parse structure of labels. @param string $data @param string $orig @return string Dot-separated labels list.
[ "Parse", "structure", "of", "labels", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L36-L59
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.LV
public static function LV($str, $len = 1, $lrev = false) { $l = static::i2b($len, strlen($str)); if ($lrev) { $l = strrev($l); } return $l . $str; }
php
public static function LV($str, $len = 1, $lrev = false) { $l = static::i2b($len, strlen($str)); if ($lrev) { $l = strrev($l); } return $l . $str; }
[ "public", "static", "function", "LV", "(", "$", "str", ",", "$", "len", "=", "1", ",", "$", "lrev", "=", "false", ")", "{", "$", "l", "=", "static", "::", "i2b", "(", "$", "len", ",", "strlen", "(", "$", "str", ")", ")", ";", "if", "(", "$", "lrev", ")", "{", "$", "l", "=", "strrev", "(", "$", "l", ")", ";", "}", "return", "$", "l", ".", "$", "str", ";", "}" ]
Build length-value binary snippet. @param string $str Data. @param int $len Number of bytes to encode length, defaults to 1. @return string
[ "Build", "length", "-", "value", "binary", "snippet", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L68-L75
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.getByte
public static function getByte(&$p) { $r = static::bytes2int($p{0}); $p = static::binarySubstr($p, 1); return (int) $r; }
php
public static function getByte(&$p) { $r = static::bytes2int($p{0}); $p = static::binarySubstr($p, 1); return (int) $r; }
[ "public", "static", "function", "getByte", "(", "&", "$", "p", ")", "{", "$", "r", "=", "static", "::", "bytes2int", "(", "$", "p", "{", "0", "}", ")", ";", "$", "p", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "1", ")", ";", "return", "(", "int", ")", "$", "r", ";", "}" ]
Parse byte, and remove it. @param &string $p Data @return int
[ "Parse", "byte", "and", "remove", "it", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L171-L177
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.getString
public static function getString(&$str) { $p = strpos($str, "\x00"); if ($p === false) { return ''; } $r = static::binarySubstr($str, 0, $p); $str = static::binarySubstr($str, $p + 1); return $r; }
php
public static function getString(&$str) { $p = strpos($str, "\x00"); if ($p === false) { return ''; } $r = static::binarySubstr($str, 0, $p); $str = static::binarySubstr($str, $p + 1); return $r; }
[ "public", "static", "function", "getString", "(", "&", "$", "str", ")", "{", "$", "p", "=", "strpos", "(", "$", "str", ",", "\"\\x00\"", ")", ";", "if", "(", "$", "p", "===", "false", ")", "{", "return", "''", ";", "}", "$", "r", "=", "static", "::", "binarySubstr", "(", "$", "str", ",", "0", ",", "$", "p", ")", ";", "$", "str", "=", "static", "::", "binarySubstr", "(", "$", "str", ",", "$", "p", "+", "1", ")", ";", "return", "$", "r", ";", "}" ]
Parse null-terminated string. @param &string $str @return string
[ "Parse", "null", "-", "terminated", "string", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L279-L289
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.getLV
public static function getLV(&$p, $l = 1, $nul = false, $lrev = false) { $s = static::b2i(static::binarySubstr($p, 0, $l), !!$lrev); $p = static::binarySubstr($p, $l); if ($s == 0) { return ''; } $r = ''; if (strlen($p) < $s) { echo("getLV error: buf length (" . strlen($p) . "): " . Debug::exportBytes($p) . ", must be >= string length (" . $s . ")\n"); } else if ($nul) { if ($p{$s - 1} != "\x00") { echo("getLV error: Wrong end of NUL-string (" . Debug::exportBytes($p{$s - 1}) . "), len " . $s . "\n"); } else { $d = $s - 1; if ($d < 0) { $d = 0; } $r = static::binarySubstr($p, 0, $d); $p = static::binarySubstr($p, $s); } } else { $r = static::binarySubstr($p, 0, $s); $p = static::binarySubstr($p, $s); } return $r; }
php
public static function getLV(&$p, $l = 1, $nul = false, $lrev = false) { $s = static::b2i(static::binarySubstr($p, 0, $l), !!$lrev); $p = static::binarySubstr($p, $l); if ($s == 0) { return ''; } $r = ''; if (strlen($p) < $s) { echo("getLV error: buf length (" . strlen($p) . "): " . Debug::exportBytes($p) . ", must be >= string length (" . $s . ")\n"); } else if ($nul) { if ($p{$s - 1} != "\x00") { echo("getLV error: Wrong end of NUL-string (" . Debug::exportBytes($p{$s - 1}) . "), len " . $s . "\n"); } else { $d = $s - 1; if ($d < 0) { $d = 0; } $r = static::binarySubstr($p, 0, $d); $p = static::binarySubstr($p, $s); } } else { $r = static::binarySubstr($p, 0, $s); $p = static::binarySubstr($p, $s); } return $r; }
[ "public", "static", "function", "getLV", "(", "&", "$", "p", ",", "$", "l", "=", "1", ",", "$", "nul", "=", "false", ",", "$", "lrev", "=", "false", ")", "{", "$", "s", "=", "static", "::", "b2i", "(", "static", "::", "binarySubstr", "(", "$", "p", ",", "0", ",", "$", "l", ")", ",", "!", "!", "$", "lrev", ")", ";", "$", "p", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "$", "l", ")", ";", "if", "(", "$", "s", "==", "0", ")", "{", "return", "''", ";", "}", "$", "r", "=", "''", ";", "if", "(", "strlen", "(", "$", "p", ")", "<", "$", "s", ")", "{", "echo", "(", "\"getLV error: buf length (\"", ".", "strlen", "(", "$", "p", ")", ".", "\"): \"", ".", "Debug", "::", "exportBytes", "(", "$", "p", ")", ".", "\", must be >= string length (\"", ".", "$", "s", ".", "\")\\n\"", ")", ";", "}", "else", "if", "(", "$", "nul", ")", "{", "if", "(", "$", "p", "{", "$", "s", "-", "1", "}", "!=", "\"\\x00\"", ")", "{", "echo", "(", "\"getLV error: Wrong end of NUL-string (\"", ".", "Debug", "::", "exportBytes", "(", "$", "p", "{", "$", "s", "-", "1", "}", ")", ".", "\"), len \"", ".", "$", "s", ".", "\"\\n\"", ")", ";", "}", "else", "{", "$", "d", "=", "$", "s", "-", "1", ";", "if", "(", "$", "d", "<", "0", ")", "{", "$", "d", "=", "0", ";", "}", "$", "r", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "0", ",", "$", "d", ")", ";", "$", "p", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "$", "s", ")", ";", "}", "}", "else", "{", "$", "r", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "0", ",", "$", "s", ")", ";", "$", "p", "=", "static", "::", "binarySubstr", "(", "$", "p", ",", "$", "s", ")", ";", "}", "return", "$", "r", ";", "}" ]
Parse length-value structure. @param &string $p @param int $l number of length bytes. @param bool $nul Null-terminated, defaults to false. @param bool $lrev Little-endian, default to false. @return string
[ "Parse", "length", "-", "value", "structure", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L300-L333
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.int2bytes
public static function int2bytes($len, $int = 0, $l = false) { $hexstr = dechex($int); if ($len === null) { if (strlen($hexstr) % 2) { $hexstr = "0" . $hexstr; } } else { $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr; } $bytes = strlen($hexstr) / 2; $bin = ''; for ($i = 0; $i < $bytes; ++$i) { $bin .= chr(hexdec(substr($hexstr, $i * 2, 2))); } return $l ? strrev($bin) : $bin; }
php
public static function int2bytes($len, $int = 0, $l = false) { $hexstr = dechex($int); if ($len === null) { if (strlen($hexstr) % 2) { $hexstr = "0" . $hexstr; } } else { $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr; } $bytes = strlen($hexstr) / 2; $bin = ''; for ($i = 0; $i < $bytes; ++$i) { $bin .= chr(hexdec(substr($hexstr, $i * 2, 2))); } return $l ? strrev($bin) : $bin; }
[ "public", "static", "function", "int2bytes", "(", "$", "len", ",", "$", "int", "=", "0", ",", "$", "l", "=", "false", ")", "{", "$", "hexstr", "=", "dechex", "(", "$", "int", ")", ";", "if", "(", "$", "len", "===", "null", ")", "{", "if", "(", "strlen", "(", "$", "hexstr", ")", "%", "2", ")", "{", "$", "hexstr", "=", "\"0\"", ".", "$", "hexstr", ";", "}", "}", "else", "{", "$", "hexstr", "=", "str_repeat", "(", "'0'", ",", "$", "len", "*", "2", "-", "strlen", "(", "$", "hexstr", ")", ")", ".", "$", "hexstr", ";", "}", "$", "bytes", "=", "strlen", "(", "$", "hexstr", ")", "/", "2", ";", "$", "bin", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "bytes", ";", "++", "$", "i", ")", "{", "$", "bin", ".=", "chr", "(", "hexdec", "(", "substr", "(", "$", "hexstr", ",", "$", "i", "*", "2", ",", "2", ")", ")", ")", ";", "}", "return", "$", "l", "?", "strrev", "(", "$", "bin", ")", ":", "$", "bin", ";", "}" ]
Converts integer to binary string. @param int $len @param int $int @param bool $l Little-endian, defaults to false. @return string
[ "Converts", "integer", "to", "binary", "string", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L343-L364
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.bytes2int
public static function bytes2int($str, $l = false) { if ($l) { $str = strrev($str); } $dec = 0; $len = strlen($str); for ($i = 0; $i < $len; ++$i) { $dec += ord(static::binarySubstr($str, $i, 1)) * pow(0x100, $len - $i - 1); } return $dec; }
php
public static function bytes2int($str, $l = false) { if ($l) { $str = strrev($str); } $dec = 0; $len = strlen($str); for ($i = 0; $i < $len; ++$i) { $dec += ord(static::binarySubstr($str, $i, 1)) * pow(0x100, $len - $i - 1); } return $dec; }
[ "public", "static", "function", "bytes2int", "(", "$", "str", ",", "$", "l", "=", "false", ")", "{", "if", "(", "$", "l", ")", "{", "$", "str", "=", "strrev", "(", "$", "str", ")", ";", "}", "$", "dec", "=", "0", ";", "$", "len", "=", "strlen", "(", "$", "str", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "++", "$", "i", ")", "{", "$", "dec", "+=", "ord", "(", "static", "::", "binarySubstr", "(", "$", "str", ",", "$", "i", ",", "1", ")", ")", "*", "pow", "(", "0x100", ",", "$", "len", "-", "$", "i", "-", "1", ")", ";", "}", "return", "$", "dec", ";", "}" ]
Convert bytes into integer. @param string $str @param bool $l little-endian encoding, defaults to false @return int
[ "Convert", "bytes", "into", "integer", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L398-L413
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.bitmap2bytes
public static function bitmap2bytes($bitmap, $checkLen = 0) { $r = ''; $bitmap = str_pad($bitmap, ceil(strlen($bitmap) / 8) * 8, '0', STR_PAD_LEFT); for ($i = 0, $n = strlen($bitmap) / 8; $i < $n; ++$i) { $r .= chr((int) bindec(static::binarySubstr($bitmap, $i * 8, 8))); } if ($checkLen && (strlen($r) != $checkLen)) { throw new Exception('Warning! Bitmap incorrect.'); } return $r; }
php
public static function bitmap2bytes($bitmap, $checkLen = 0) { $r = ''; $bitmap = str_pad($bitmap, ceil(strlen($bitmap) / 8) * 8, '0', STR_PAD_LEFT); for ($i = 0, $n = strlen($bitmap) / 8; $i < $n; ++$i) { $r .= chr((int) bindec(static::binarySubstr($bitmap, $i * 8, 8))); } if ($checkLen && (strlen($r) != $checkLen)) { throw new Exception('Warning! Bitmap incorrect.'); } return $r; }
[ "public", "static", "function", "bitmap2bytes", "(", "$", "bitmap", ",", "$", "checkLen", "=", "0", ")", "{", "$", "r", "=", "''", ";", "$", "bitmap", "=", "str_pad", "(", "$", "bitmap", ",", "ceil", "(", "strlen", "(", "$", "bitmap", ")", "/", "8", ")", "*", "8", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "n", "=", "strlen", "(", "$", "bitmap", ")", "/", "8", ";", "$", "i", "<", "$", "n", ";", "++", "$", "i", ")", "{", "$", "r", ".=", "chr", "(", "(", "int", ")", "bindec", "(", "static", "::", "binarySubstr", "(", "$", "bitmap", ",", "$", "i", "*", "8", ",", "8", ")", ")", ")", ";", "}", "if", "(", "$", "checkLen", "&&", "(", "strlen", "(", "$", "r", ")", "!=", "$", "checkLen", ")", ")", "{", "throw", "new", "Exception", "(", "'Warning! Bitmap incorrect.'", ")", ";", "}", "return", "$", "r", ";", "}" ]
Convert bitmap into bytes. @param string $bitmap @param int $checkLen @return string @throws Exception
[ "Convert", "bitmap", "into", "bytes", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L431-L445
train
BinPHP/BinPHP
src/BinSupport.php
BinSupport.binarySubstr
protected static function binarySubstr($s, $p, $len = null) { if ($len === null) { $ret = substr($s, $p); } else { $ret = substr($s, $p, $len); } if ($ret === false) { $ret = ''; } return $ret; }
php
protected static function binarySubstr($s, $p, $len = null) { if ($len === null) { $ret = substr($s, $p); } else { $ret = substr($s, $p, $len); } if ($ret === false) { $ret = ''; } return $ret; }
[ "protected", "static", "function", "binarySubstr", "(", "$", "s", ",", "$", "p", ",", "$", "len", "=", "null", ")", "{", "if", "(", "$", "len", "===", "null", ")", "{", "$", "ret", "=", "substr", "(", "$", "s", ",", "$", "p", ")", ";", "}", "else", "{", "$", "ret", "=", "substr", "(", "$", "s", ",", "$", "p", ",", "$", "len", ")", ";", "}", "if", "(", "$", "ret", "===", "false", ")", "{", "$", "ret", "=", "''", ";", "}", "return", "$", "ret", ";", "}" ]
Binary Substring. @param string $s @param string $p @param int|null $len @return string
[ "Binary", "Substring", "." ]
b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b
https://github.com/BinPHP/BinPHP/blob/b517eed0c89b3bc3ca3771ae70c2f47aa41a8c8b/src/BinSupport.php#L466-L479
train