repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
squareproton/Bond
src/Bond/Set.php
Set.add
public function add() { if( !$args = func_get_args() ) { return $this; } $intervals = array_map( array($this, 'addHelper'), $args ); $intervals[] = $this->intervals; $output = array(); // merge the lot $intervals = call_user_func_array( 'array_merge', $intervals ); usort( $intervals, array( $this, "sortIntervals" ) ); $working = null; while( list(,$current) = each($intervals) ) { // we got anything to compare against if( $working === null ) { $working = $current; // we've maxed out - everything else is going to match this! } elseif ( $working[1] === null ) { break; // is current lower bound contained in our working interval // or isContinuous() } elseif ( $this->sort( $working[1], $current[0], self::NULL_IS_HIGH ) >= 0 or $this->isContinuous( $working[1], $current[0] ) ) { // get the maximum upper bound $working[1] = $this->max( $working[1], $current[1], self::NULL_IS_HIGH ); // intervals are distinct, add to output } else { $output[] = $working; $working = $current; } } if( !is_null( $working ) ) { $output[] = $working; } $this->intervals = $output; return $this; }
php
public function add() { if( !$args = func_get_args() ) { return $this; } $intervals = array_map( array($this, 'addHelper'), $args ); $intervals[] = $this->intervals; $output = array(); // merge the lot $intervals = call_user_func_array( 'array_merge', $intervals ); usort( $intervals, array( $this, "sortIntervals" ) ); $working = null; while( list(,$current) = each($intervals) ) { // we got anything to compare against if( $working === null ) { $working = $current; // we've maxed out - everything else is going to match this! } elseif ( $working[1] === null ) { break; // is current lower bound contained in our working interval // or isContinuous() } elseif ( $this->sort( $working[1], $current[0], self::NULL_IS_HIGH ) >= 0 or $this->isContinuous( $working[1], $current[0] ) ) { // get the maximum upper bound $working[1] = $this->max( $working[1], $current[1], self::NULL_IS_HIGH ); // intervals are distinct, add to output } else { $output[] = $working; $working = $current; } } if( !is_null( $working ) ) { $output[] = $working; } $this->intervals = $output; return $this; }
[ "public", "function", "add", "(", ")", "{", "if", "(", "!", "$", "args", "=", "func_get_args", "(", ")", ")", "{", "return", "$", "this", ";", "}", "$", "intervals", "=", "array_map", "(", "array", "(", "$", "this", ",", "'addHelper'", ")", ",", "$", "args", ")", ";", "$", "intervals", "[", "]", "=", "$", "this", "->", "intervals", ";", "$", "output", "=", "array", "(", ")", ";", "// merge the lot", "$", "intervals", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "intervals", ")", ";", "usort", "(", "$", "intervals", ",", "array", "(", "$", "this", ",", "\"sortIntervals\"", ")", ")", ";", "$", "working", "=", "null", ";", "while", "(", "list", "(", ",", "$", "current", ")", "=", "each", "(", "$", "intervals", ")", ")", "{", "// we got anything to compare against", "if", "(", "$", "working", "===", "null", ")", "{", "$", "working", "=", "$", "current", ";", "// we've maxed out - everything else is going to match this!", "}", "elseif", "(", "$", "working", "[", "1", "]", "===", "null", ")", "{", "break", ";", "// is current lower bound contained in our working interval", "// or isContinuous()", "}", "elseif", "(", "$", "this", "->", "sort", "(", "$", "working", "[", "1", "]", ",", "$", "current", "[", "0", "]", ",", "self", "::", "NULL_IS_HIGH", ")", ">=", "0", "or", "$", "this", "->", "isContinuous", "(", "$", "working", "[", "1", "]", ",", "$", "current", "[", "0", "]", ")", ")", "{", "// get the maximum upper bound", "$", "working", "[", "1", "]", "=", "$", "this", "->", "max", "(", "$", "working", "[", "1", "]", ",", "$", "current", "[", "1", "]", ",", "self", "::", "NULL_IS_HIGH", ")", ";", "// intervals are distinct, add to output", "}", "else", "{", "$", "output", "[", "]", "=", "$", "working", ";", "$", "working", "=", "$", "current", ";", "}", "}", "if", "(", "!", "is_null", "(", "$", "working", ")", ")", "{", "$", "output", "[", "]", "=", "$", "working", ";", "}", "$", "this", "->", "intervals", "=", "$", "output", ";", "return", "$", "this", ";", "}" ]
Variable number of argument of things we're likey to be able to make a set out of. @param See $this->addHelper() .. @return $this
[ "Variable", "number", "of", "argument", "of", "things", "we", "re", "likey", "to", "be", "able", "to", "make", "a", "set", "out", "of", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L73-L133
train
squareproton/Bond
src/Bond/Set.php
Set.contains
public function contains() { // build new set from passed arguments $reflection = new \ReflectionClass( get_called_class() ); $comparing = $reflection->newInstanceArgs( func_get_args() ); // we don't have a null but the set we're comparing against has it if( !$this->containsNull and $comparing->containsNull ) { return false; } reset( $this->intervals ); reset( $comparing->intervals ); list(,$compare) = each($comparing->intervals); list(,$current) = each($this->intervals); while( $compare and $current) { // Intervals are maximal. They're either entirely contained or not at all if( $compare[0] !== null and $this->sort( $compare[0], $current[1], self::NULL_IS_HIGH ) > 0 ) { list(,$current) = each($this->intervals); continue; } // are intervals contained? if( // compare lower is >= current lower $this->sort( $compare[0], $current[0], self::NULL_IS_LOW ) >= 0 and // compare upper is <= current upper $this->sort( $compare[1], $current[1], self::NULL_IS_HIGH ) <= 0 ) { list(,$compare) = each($comparing->intervals); // interval can't be contained } else { return false; } } // if we're still got something to comparing something we've not been able to match it up with a interval return !$compare; }
php
public function contains() { // build new set from passed arguments $reflection = new \ReflectionClass( get_called_class() ); $comparing = $reflection->newInstanceArgs( func_get_args() ); // we don't have a null but the set we're comparing against has it if( !$this->containsNull and $comparing->containsNull ) { return false; } reset( $this->intervals ); reset( $comparing->intervals ); list(,$compare) = each($comparing->intervals); list(,$current) = each($this->intervals); while( $compare and $current) { // Intervals are maximal. They're either entirely contained or not at all if( $compare[0] !== null and $this->sort( $compare[0], $current[1], self::NULL_IS_HIGH ) > 0 ) { list(,$current) = each($this->intervals); continue; } // are intervals contained? if( // compare lower is >= current lower $this->sort( $compare[0], $current[0], self::NULL_IS_LOW ) >= 0 and // compare upper is <= current upper $this->sort( $compare[1], $current[1], self::NULL_IS_HIGH ) <= 0 ) { list(,$compare) = each($comparing->intervals); // interval can't be contained } else { return false; } } // if we're still got something to comparing something we've not been able to match it up with a interval return !$compare; }
[ "public", "function", "contains", "(", ")", "{", "// build new set from passed arguments", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "get_called_class", "(", ")", ")", ";", "$", "comparing", "=", "$", "reflection", "->", "newInstanceArgs", "(", "func_get_args", "(", ")", ")", ";", "// we don't have a null but the set we're comparing against has it", "if", "(", "!", "$", "this", "->", "containsNull", "and", "$", "comparing", "->", "containsNull", ")", "{", "return", "false", ";", "}", "reset", "(", "$", "this", "->", "intervals", ")", ";", "reset", "(", "$", "comparing", "->", "intervals", ")", ";", "list", "(", ",", "$", "compare", ")", "=", "each", "(", "$", "comparing", "->", "intervals", ")", ";", "list", "(", ",", "$", "current", ")", "=", "each", "(", "$", "this", "->", "intervals", ")", ";", "while", "(", "$", "compare", "and", "$", "current", ")", "{", "// Intervals are maximal. They're either entirely contained or not at all", "if", "(", "$", "compare", "[", "0", "]", "!==", "null", "and", "$", "this", "->", "sort", "(", "$", "compare", "[", "0", "]", ",", "$", "current", "[", "1", "]", ",", "self", "::", "NULL_IS_HIGH", ")", ">", "0", ")", "{", "list", "(", ",", "$", "current", ")", "=", "each", "(", "$", "this", "->", "intervals", ")", ";", "continue", ";", "}", "// are intervals contained?", "if", "(", "// compare lower is >= current lower", "$", "this", "->", "sort", "(", "$", "compare", "[", "0", "]", ",", "$", "current", "[", "0", "]", ",", "self", "::", "NULL_IS_LOW", ")", ">=", "0", "and", "// compare upper is <= current upper", "$", "this", "->", "sort", "(", "$", "compare", "[", "1", "]", ",", "$", "current", "[", "1", "]", ",", "self", "::", "NULL_IS_HIGH", ")", "<=", "0", ")", "{", "list", "(", ",", "$", "compare", ")", "=", "each", "(", "$", "comparing", "->", "intervals", ")", ";", "// interval can't be contained", "}", "else", "{", "return", "false", ";", "}", "}", "// if we're still got something to comparing something we've not been able to match it up with a interval", "return", "!", "$", "compare", ";", "}" ]
Is a set contained within another set @return <type>
[ "Is", "a", "set", "contained", "within", "another", "set" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L262-L310
train
squareproton/Bond
src/Bond/Set.php
Set.invert
public function invert() { $this->containsNull = !$this->containsNull; if( $this->intervals === array( array(null, null) ) ) { $this->intervals = array(); return $this; } $output = array(); $working = array( null, null ); reset( $this->intervals ); while( list(,$interval) = each($this->intervals) ) { if( $interval[0] === null ) { $working[0] = $this->nextHighestValue( $interval[1] ); } elseif( $interval[1] === null ) { $working[1] = $this->nextLowestValue( $interval[0] ); break; } else { $working[1] = $this->nextLowestValue( $interval[0] ); $output[] = $working; $working = array( $this->nextHighestValue( $interval[1] ), null ); } } $output[] = $working; $this->intervals = $output; return $this; }
php
public function invert() { $this->containsNull = !$this->containsNull; if( $this->intervals === array( array(null, null) ) ) { $this->intervals = array(); return $this; } $output = array(); $working = array( null, null ); reset( $this->intervals ); while( list(,$interval) = each($this->intervals) ) { if( $interval[0] === null ) { $working[0] = $this->nextHighestValue( $interval[1] ); } elseif( $interval[1] === null ) { $working[1] = $this->nextLowestValue( $interval[0] ); break; } else { $working[1] = $this->nextLowestValue( $interval[0] ); $output[] = $working; $working = array( $this->nextHighestValue( $interval[1] ), null ); } } $output[] = $working; $this->intervals = $output; return $this; }
[ "public", "function", "invert", "(", ")", "{", "$", "this", "->", "containsNull", "=", "!", "$", "this", "->", "containsNull", ";", "if", "(", "$", "this", "->", "intervals", "===", "array", "(", "array", "(", "null", ",", "null", ")", ")", ")", "{", "$", "this", "->", "intervals", "=", "array", "(", ")", ";", "return", "$", "this", ";", "}", "$", "output", "=", "array", "(", ")", ";", "$", "working", "=", "array", "(", "null", ",", "null", ")", ";", "reset", "(", "$", "this", "->", "intervals", ")", ";", "while", "(", "list", "(", ",", "$", "interval", ")", "=", "each", "(", "$", "this", "->", "intervals", ")", ")", "{", "if", "(", "$", "interval", "[", "0", "]", "===", "null", ")", "{", "$", "working", "[", "0", "]", "=", "$", "this", "->", "nextHighestValue", "(", "$", "interval", "[", "1", "]", ")", ";", "}", "elseif", "(", "$", "interval", "[", "1", "]", "===", "null", ")", "{", "$", "working", "[", "1", "]", "=", "$", "this", "->", "nextLowestValue", "(", "$", "interval", "[", "0", "]", ")", ";", "break", ";", "}", "else", "{", "$", "working", "[", "1", "]", "=", "$", "this", "->", "nextLowestValue", "(", "$", "interval", "[", "0", "]", ")", ";", "$", "output", "[", "]", "=", "$", "working", ";", "$", "working", "=", "array", "(", "$", "this", "->", "nextHighestValue", "(", "$", "interval", "[", "1", "]", ")", ",", "null", ")", ";", "}", "}", "$", "output", "[", "]", "=", "$", "working", ";", "$", "this", "->", "intervals", "=", "$", "output", ";", "return", "$", "this", ";", "}" ]
Invert a set. @return $this;
[ "Invert", "a", "set", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L316-L360
train
squareproton/Bond
src/Bond/Set.php
Set.addHelper
protected function addHelper( $data ) { // array of values if( is_array( $data ) ) { $originalSize = count( $data ); $data = array_filter( $data, '\Bond\is_not_null' ); // have null if( $originalSize !== count( $data ) ) { $this->containsNull = true; } $argIntervals = array_map( null, $data, $data ); $argIntervals = array_map( array($this, 'prepInterval'), $argIntervals ); return array_filter( $argIntervals ); } elseif( $data instanceof static ) { return $data->intervals; } elseif( $data === null ) { $this->containsNull = true; return array(); } elseif( is_int($data) ) { return $this->parseStringToIntervals( $this->escape( $data ) ); } elseif( is_scalar( $data ) ) { return $this->parseStringToIntervals( (string) $data ); } throw new \RuntimeException( "Don't know how to handle this `{$data}`." ); }
php
protected function addHelper( $data ) { // array of values if( is_array( $data ) ) { $originalSize = count( $data ); $data = array_filter( $data, '\Bond\is_not_null' ); // have null if( $originalSize !== count( $data ) ) { $this->containsNull = true; } $argIntervals = array_map( null, $data, $data ); $argIntervals = array_map( array($this, 'prepInterval'), $argIntervals ); return array_filter( $argIntervals ); } elseif( $data instanceof static ) { return $data->intervals; } elseif( $data === null ) { $this->containsNull = true; return array(); } elseif( is_int($data) ) { return $this->parseStringToIntervals( $this->escape( $data ) ); } elseif( is_scalar( $data ) ) { return $this->parseStringToIntervals( (string) $data ); } throw new \RuntimeException( "Don't know how to handle this `{$data}`." ); }
[ "protected", "function", "addHelper", "(", "$", "data", ")", "{", "// array of values", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "originalSize", "=", "count", "(", "$", "data", ")", ";", "$", "data", "=", "array_filter", "(", "$", "data", ",", "'\\Bond\\is_not_null'", ")", ";", "// have null", "if", "(", "$", "originalSize", "!==", "count", "(", "$", "data", ")", ")", "{", "$", "this", "->", "containsNull", "=", "true", ";", "}", "$", "argIntervals", "=", "array_map", "(", "null", ",", "$", "data", ",", "$", "data", ")", ";", "$", "argIntervals", "=", "array_map", "(", "array", "(", "$", "this", ",", "'prepInterval'", ")", ",", "$", "argIntervals", ")", ";", "return", "array_filter", "(", "$", "argIntervals", ")", ";", "}", "elseif", "(", "$", "data", "instanceof", "static", ")", "{", "return", "$", "data", "->", "intervals", ";", "}", "elseif", "(", "$", "data", "===", "null", ")", "{", "$", "this", "->", "containsNull", "=", "true", ";", "return", "array", "(", ")", ";", "}", "elseif", "(", "is_int", "(", "$", "data", ")", ")", "{", "return", "$", "this", "->", "parseStringToIntervals", "(", "$", "this", "->", "escape", "(", "$", "data", ")", ")", ";", "}", "elseif", "(", "is_scalar", "(", "$", "data", ")", ")", "{", "return", "$", "this", "->", "parseStringToIntervals", "(", "(", "string", ")", "$", "data", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"Don't know how to handle this `{$data}`.\"", ")", ";", "}" ]
Convert something that looks like it's going to be a set castable into a array of intervals Not nessisarily sorted @param mixed $data @return array Intervals
[ "Convert", "something", "that", "looks", "like", "it", "s", "going", "to", "be", "a", "set", "castable", "into", "a", "array", "of", "intervals", "Not", "nessisarily", "sorted" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L392-L432
train
squareproton/Bond
src/Bond/Set.php
Set.parseStringToIntervals
private function parseStringToIntervals( $string ) { if( !$length = mb_strlen( $string ) ) { return array(); } // The following isn't as bat shit crazy loco nutjob wtf loony as it looks. // People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex. // Imagine the following // 200-300 => array( 200, 300 ); great // \\200-300 => array( \200, 300 ); fine, you can do a regex for that // 200\\\-300 => array( 200\-300 ); but not easily for this or something more insane-o // Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly. // The following works fine for non-multibyte char separators and is very quick. $intervals = array(); $interval = array(''); $c = 0; $isCharEscaped = false; for( $i = 0; $i < $length; $i++ ) { $char = mb_substr( $string, $i, 1 ); if( $isCharEscaped ) { if( $char === self::NULL_CHARACTER ) { if( $interval[$c] === '') { $interval[$c] = null; } } else { $interval[$c] .= $char; } $isCharEscaped = false; } else { switch( $char ) { case self::ESCAPE_CHARACTER; $isCharEscaped = true; break; case self::RANGE_SEPARATOR; $interval[++$c] = ''; break; case self::INTERVAL_SEPARATOR; if( $interval = $this->prepInterval( $interval ) ) { $intervals[] = $interval; } $interval = array(''); $c = 0; break; default: $interval[$c] .= $char; break; } } } if( $interval = $this->prepInterval( $interval ) ) { $intervals[] = $interval; } return $intervals; }
php
private function parseStringToIntervals( $string ) { if( !$length = mb_strlen( $string ) ) { return array(); } // The following isn't as bat shit crazy loco nutjob wtf loony as it looks. // People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex. // Imagine the following // 200-300 => array( 200, 300 ); great // \\200-300 => array( \200, 300 ); fine, you can do a regex for that // 200\\\-300 => array( 200\-300 ); but not easily for this or something more insane-o // Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly. // The following works fine for non-multibyte char separators and is very quick. $intervals = array(); $interval = array(''); $c = 0; $isCharEscaped = false; for( $i = 0; $i < $length; $i++ ) { $char = mb_substr( $string, $i, 1 ); if( $isCharEscaped ) { if( $char === self::NULL_CHARACTER ) { if( $interval[$c] === '') { $interval[$c] = null; } } else { $interval[$c] .= $char; } $isCharEscaped = false; } else { switch( $char ) { case self::ESCAPE_CHARACTER; $isCharEscaped = true; break; case self::RANGE_SEPARATOR; $interval[++$c] = ''; break; case self::INTERVAL_SEPARATOR; if( $interval = $this->prepInterval( $interval ) ) { $intervals[] = $interval; } $interval = array(''); $c = 0; break; default: $interval[$c] .= $char; break; } } } if( $interval = $this->prepInterval( $interval ) ) { $intervals[] = $interval; } return $intervals; }
[ "private", "function", "parseStringToIntervals", "(", "$", "string", ")", "{", "if", "(", "!", "$", "length", "=", "mb_strlen", "(", "$", "string", ")", ")", "{", "return", "array", "(", ")", ";", "}", "// The following isn't as bat shit crazy loco nutjob wtf loony as it looks.", "// People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex.", "// Imagine the following", "// 200-300 => array( 200, 300 ); great", "// \\\\200-300 => array( \\200, 300 ); fine, you can do a regex for that", "// 200\\\\\\-300 => array( 200\\-300 ); but not easily for this or something more insane-o", "// Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly.", "// The following works fine for non-multibyte char separators and is very quick.", "$", "intervals", "=", "array", "(", ")", ";", "$", "interval", "=", "array", "(", "''", ")", ";", "$", "c", "=", "0", ";", "$", "isCharEscaped", "=", "false", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "char", "=", "mb_substr", "(", "$", "string", ",", "$", "i", ",", "1", ")", ";", "if", "(", "$", "isCharEscaped", ")", "{", "if", "(", "$", "char", "===", "self", "::", "NULL_CHARACTER", ")", "{", "if", "(", "$", "interval", "[", "$", "c", "]", "===", "''", ")", "{", "$", "interval", "[", "$", "c", "]", "=", "null", ";", "}", "}", "else", "{", "$", "interval", "[", "$", "c", "]", ".=", "$", "char", ";", "}", "$", "isCharEscaped", "=", "false", ";", "}", "else", "{", "switch", "(", "$", "char", ")", "{", "case", "self", "::", "ESCAPE_CHARACTER", ";", "$", "isCharEscaped", "=", "true", ";", "break", ";", "case", "self", "::", "RANGE_SEPARATOR", ";", "$", "interval", "[", "++", "$", "c", "]", "=", "''", ";", "break", ";", "case", "self", "::", "INTERVAL_SEPARATOR", ";", "if", "(", "$", "interval", "=", "$", "this", "->", "prepInterval", "(", "$", "interval", ")", ")", "{", "$", "intervals", "[", "]", "=", "$", "interval", ";", "}", "$", "interval", "=", "array", "(", "''", ")", ";", "$", "c", "=", "0", ";", "break", ";", "default", ":", "$", "interval", "[", "$", "c", "]", ".=", "$", "char", ";", "break", ";", "}", "}", "}", "if", "(", "$", "interval", "=", "$", "this", "->", "prepInterval", "(", "$", "interval", ")", ")", "{", "$", "intervals", "[", "]", "=", "$", "interval", ";", "}", "return", "$", "intervals", ";", "}" ]
Parse the data into an array of unique values @param string $string String represensation of a set which we're going to parse into a valid, sorted array of intervals @return array
[ "Parse", "the", "data", "into", "an", "array", "of", "unique", "values" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L516-L586
train
squareproton/Bond
src/Bond/Set.php
Set.sortIntervals
private final function sortIntervals( $a, $b ) { if( 0 !== $lowerCompare = $this->sort( $a[0], $b[0], self::NULL_IS_LOW ) ) { return $lowerCompare; } return -$this->sort( $a[1], $b[1], self::NULL_IS_HIGH ); }
php
private final function sortIntervals( $a, $b ) { if( 0 !== $lowerCompare = $this->sort( $a[0], $b[0], self::NULL_IS_LOW ) ) { return $lowerCompare; } return -$this->sort( $a[1], $b[1], self::NULL_IS_HIGH ); }
[ "private", "final", "function", "sortIntervals", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "0", "!==", "$", "lowerCompare", "=", "$", "this", "->", "sort", "(", "$", "a", "[", "0", "]", ",", "$", "b", "[", "0", "]", ",", "self", "::", "NULL_IS_LOW", ")", ")", "{", "return", "$", "lowerCompare", ";", "}", "return", "-", "$", "this", "->", "sort", "(", "$", "a", "[", "1", "]", ",", "$", "b", "[", "1", "]", ",", "self", "::", "NULL_IS_HIGH", ")", ";", "}" ]
Sort two intervals @param array $a @param array $b @return -1,0,1
[ "Sort", "two", "intervals" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L631-L637
train
squareproton/Bond
src/Bond/Set.php
Set.max
protected function max( $a, $b, $handleNull ) { return $this->sort( $a, $b, $handleNull ) > 0 ? $a : $b; }
php
protected function max( $a, $b, $handleNull ) { return $this->sort( $a, $b, $handleNull ) > 0 ? $a : $b; }
[ "protected", "function", "max", "(", "$", "a", ",", "$", "b", ",", "$", "handleNull", ")", "{", "return", "$", "this", "->", "sort", "(", "$", "a", ",", "$", "b", ",", "$", "handleNull", ")", ">", "0", "?", "$", "a", ":", "$", "b", ";", "}" ]
Return the max of two things @param mixed $a @param mixed $b @param mixed $handleNull Is null treated as a high value or a low value. See, self::NULL_IS_HIGH @return mixed
[ "Return", "the", "max", "of", "two", "things" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L665-L668
train
squareproton/Bond
src/Bond/Set.php
Set.min
protected function min( $a, $b, $handleNull ) { return $this->sort( $a, $b, $handleNull ) > 0 ? $b : $a; }
php
protected function min( $a, $b, $handleNull ) { return $this->sort( $a, $b, $handleNull ) > 0 ? $b : $a; }
[ "protected", "function", "min", "(", "$", "a", ",", "$", "b", ",", "$", "handleNull", ")", "{", "return", "$", "this", "->", "sort", "(", "$", "a", ",", "$", "b", ",", "$", "handleNull", ")", ">", "0", "?", "$", "b", ":", "$", "a", ";", "}" ]
Return the min of two things. @param mixed $a @param mixed $b @param mixed $handleNull Is null treated as a high value or a low value. See, self::NULL_IS_HIGH @return mixed
[ "Return", "the", "min", "of", "two", "things", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L677-L680
train
squareproton/Bond
src/Bond/Set.php
Set.escape
public static function escape( $value, $escapeNull = true ) { if( $value === null ) { return $escapeNull ? self::ESCAPE_CHARACTER . self::NULL_CHARACTER : ''; } $value = str_replace( self::ESCAPE_CHARACTER, self::ESCAPE_CHARACTER . self::ESCAPE_CHARACTER, $value ); $value = str_replace( self::RANGE_SEPARATOR, self::ESCAPE_CHARACTER . self::RANGE_SEPARATOR, $value ); $value = str_replace( self::INTERVAL_SEPARATOR, self::ESCAPE_CHARACTER . self::INTERVAL_SEPARATOR, $value ); return $value; }
php
public static function escape( $value, $escapeNull = true ) { if( $value === null ) { return $escapeNull ? self::ESCAPE_CHARACTER . self::NULL_CHARACTER : ''; } $value = str_replace( self::ESCAPE_CHARACTER, self::ESCAPE_CHARACTER . self::ESCAPE_CHARACTER, $value ); $value = str_replace( self::RANGE_SEPARATOR, self::ESCAPE_CHARACTER . self::RANGE_SEPARATOR, $value ); $value = str_replace( self::INTERVAL_SEPARATOR, self::ESCAPE_CHARACTER . self::INTERVAL_SEPARATOR, $value ); return $value; }
[ "public", "static", "function", "escape", "(", "$", "value", ",", "$", "escapeNull", "=", "true", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "$", "escapeNull", "?", "self", "::", "ESCAPE_CHARACTER", ".", "self", "::", "NULL_CHARACTER", ":", "''", ";", "}", "$", "value", "=", "str_replace", "(", "self", "::", "ESCAPE_CHARACTER", ",", "self", "::", "ESCAPE_CHARACTER", ".", "self", "::", "ESCAPE_CHARACTER", ",", "$", "value", ")", ";", "$", "value", "=", "str_replace", "(", "self", "::", "RANGE_SEPARATOR", ",", "self", "::", "ESCAPE_CHARACTER", ".", "self", "::", "RANGE_SEPARATOR", ",", "$", "value", ")", ";", "$", "value", "=", "str_replace", "(", "self", "::", "INTERVAL_SEPARATOR", ",", "self", "::", "ESCAPE_CHARACTER", ".", "self", "::", "INTERVAL_SEPARATOR", ",", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
Escape a interval fragments @param scalar $value @return string
[ "Escape", "a", "interval", "fragments" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Set.php#L718-L731
train
TuumPHP/Router
src/ReverseRoute.php
ReverseRoute.prepare
public function prepare() { $this->preparedRoutes = true; foreach($this->routers as $router) { $this->prepareRoutes($router->routes); } }
php
public function prepare() { $this->preparedRoutes = true; foreach($this->routers as $router) { $this->prepareRoutes($router->routes); } }
[ "public", "function", "prepare", "(", ")", "{", "$", "this", "->", "preparedRoutes", "=", "true", ";", "foreach", "(", "$", "this", "->", "routers", "as", "$", "router", ")", "{", "$", "this", "->", "prepareRoutes", "(", "$", "router", "->", "routes", ")", ";", "}", "}" ]
prepares reverse routes from added routers.
[ "prepares", "reverse", "routes", "from", "added", "routers", "." ]
781e40b387fd1c7deb8175ccddd758a10e2cd0bd
https://github.com/TuumPHP/Router/blob/781e40b387fd1c7deb8175ccddd758a10e2cd0bd/src/ReverseRoute.php#L44-L50
train
congraphcms/core
Traits/MapperTrait.php
MapperTrait.maps
public static function maps(array $mappings, $key = 'default') { self::$mappings = array_merge_recursive(self::$mappings, [ $key => $mappings ]); }
php
public static function maps(array $mappings, $key = 'default') { self::$mappings = array_merge_recursive(self::$mappings, [ $key => $mappings ]); }
[ "public", "static", "function", "maps", "(", "array", "$", "mappings", ",", "$", "key", "=", "'default'", ")", "{", "self", "::", "$", "mappings", "=", "array_merge_recursive", "(", "self", "::", "$", "mappings", ",", "[", "$", "key", "=>", "$", "mappings", "]", ")", ";", "}" ]
Register mappings. @param array $mappings @return void
[ "Register", "mappings", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/MapperTrait.php#L58-L61
train
congraphcms/core
Traits/MapperTrait.php
MapperTrait.getMappings
public static function getMappings($resource, $key = 'default') { $resourceName = $resource; if( is_object($resource) ) { $resourceName = get_class($resource); } $mappings = []; if( isset(self::$mappers[$key]) ) { $mappings = array_merge_recursive( $mappings, call_user_func(self::$mappers[$key], $resourceName) ); } if( isset(self::$mappings[$key]) && isset(self::$mappings[$key][$resourceName]) ) { $mappings = array_merge_recursive( $mappings, (array) self::$mappings[$key][$resourceName] ); } return $mappings; }
php
public static function getMappings($resource, $key = 'default') { $resourceName = $resource; if( is_object($resource) ) { $resourceName = get_class($resource); } $mappings = []; if( isset(self::$mappers[$key]) ) { $mappings = array_merge_recursive( $mappings, call_user_func(self::$mappers[$key], $resourceName) ); } if( isset(self::$mappings[$key]) && isset(self::$mappings[$key][$resourceName]) ) { $mappings = array_merge_recursive( $mappings, (array) self::$mappings[$key][$resourceName] ); } return $mappings; }
[ "public", "static", "function", "getMappings", "(", "$", "resource", ",", "$", "key", "=", "'default'", ")", "{", "$", "resourceName", "=", "$", "resource", ";", "if", "(", "is_object", "(", "$", "resource", ")", ")", "{", "$", "resourceName", "=", "get_class", "(", "$", "resource", ")", ";", "}", "$", "mappings", "=", "[", "]", ";", "if", "(", "isset", "(", "self", "::", "$", "mappers", "[", "$", "key", "]", ")", ")", "{", "$", "mappings", "=", "array_merge_recursive", "(", "$", "mappings", ",", "call_user_func", "(", "self", "::", "$", "mappers", "[", "$", "key", "]", ",", "$", "resourceName", ")", ")", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "mappings", "[", "$", "key", "]", ")", "&&", "isset", "(", "self", "::", "$", "mappings", "[", "$", "key", "]", "[", "$", "resourceName", "]", ")", ")", "{", "$", "mappings", "=", "array_merge_recursive", "(", "$", "mappings", ",", "(", "array", ")", "self", "::", "$", "mappings", "[", "$", "key", "]", "[", "$", "resourceName", "]", ")", ";", "}", "return", "$", "mappings", ";", "}" ]
Get mappings for the resource. @param mixed $command @return string
[ "Get", "mappings", "for", "the", "resource", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/MapperTrait.php#L80-L101
train
congraphcms/core
Traits/MapperTrait.php
MapperTrait.resolveMapping
public function resolveMapping($resource, $parameters = [], $key = 'default', $method = null) { $resourceName = $resource; if( is_object($resource) ) { $resourceName = get_class($resource); } $mappings = $this->getMappings($resourceName, $key); if(empty($mappings)) { throw new Exception('No resolvers mapped for resource: ' . $resourceName . '.'); } $result = null; if(is_array($mappings)) { return $this->runResolver($mappings[0], $parameters, $method); } return $this->runResolver($mappings, $parameters, $method); }
php
public function resolveMapping($resource, $parameters = [], $key = 'default', $method = null) { $resourceName = $resource; if( is_object($resource) ) { $resourceName = get_class($resource); } $mappings = $this->getMappings($resourceName, $key); if(empty($mappings)) { throw new Exception('No resolvers mapped for resource: ' . $resourceName . '.'); } $result = null; if(is_array($mappings)) { return $this->runResolver($mappings[0], $parameters, $method); } return $this->runResolver($mappings, $parameters, $method); }
[ "public", "function", "resolveMapping", "(", "$", "resource", ",", "$", "parameters", "=", "[", "]", ",", "$", "key", "=", "'default'", ",", "$", "method", "=", "null", ")", "{", "$", "resourceName", "=", "$", "resource", ";", "if", "(", "is_object", "(", "$", "resource", ")", ")", "{", "$", "resourceName", "=", "get_class", "(", "$", "resource", ")", ";", "}", "$", "mappings", "=", "$", "this", "->", "getMappings", "(", "$", "resourceName", ",", "$", "key", ")", ";", "if", "(", "empty", "(", "$", "mappings", ")", ")", "{", "throw", "new", "Exception", "(", "'No resolvers mapped for resource: '", ".", "$", "resourceName", ".", "'.'", ")", ";", "}", "$", "result", "=", "null", ";", "if", "(", "is_array", "(", "$", "mappings", ")", ")", "{", "return", "$", "this", "->", "runResolver", "(", "$", "mappings", "[", "0", "]", ",", "$", "parameters", ",", "$", "method", ")", ";", "}", "return", "$", "this", "->", "runResolver", "(", "$", "mappings", ",", "$", "parameters", ",", "$", "method", ")", ";", "}" ]
Resolve mapping end return result @param mixed $resource - mapping name to be resolved @param array $parameters - params for resolver @param string $key - mapping section @throws Exception @return mixed
[ "Resolve", "mapping", "end", "return", "result" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/MapperTrait.php#L114-L138
train
congraphcms/core
Traits/MapperTrait.php
MapperTrait.runResolver
public function runResolver($resolver, $parameters = [], $method = null) { if (is_callable($resolver)) { return call_user_func_array($resolver, $parameters); } if(class_exists($resolver)) { $instance = $this->container->make($resolver, $parameters); if($instance instanceof Command) { return Bus::dispatch($instance, $parameters); } if(is_callable([$instance, $method])) { return call_user_func_array([$instance, $method], $parameters); } } if(strpos($resolver, '@') !== false) { list($class, $method) = explode('@', $this->action['uses']); if (!method_exists($instance = $this->container->make($class), $method)) { throw new Exception('Invalid method mapped on object: ' . $class . '.'); } return call_user_func_array([$instance, $method], $parameters); } throw new Exception('Invalid resolver: ' . $resolver . '.'); }
php
public function runResolver($resolver, $parameters = [], $method = null) { if (is_callable($resolver)) { return call_user_func_array($resolver, $parameters); } if(class_exists($resolver)) { $instance = $this->container->make($resolver, $parameters); if($instance instanceof Command) { return Bus::dispatch($instance, $parameters); } if(is_callable([$instance, $method])) { return call_user_func_array([$instance, $method], $parameters); } } if(strpos($resolver, '@') !== false) { list($class, $method) = explode('@', $this->action['uses']); if (!method_exists($instance = $this->container->make($class), $method)) { throw new Exception('Invalid method mapped on object: ' . $class . '.'); } return call_user_func_array([$instance, $method], $parameters); } throw new Exception('Invalid resolver: ' . $resolver . '.'); }
[ "public", "function", "runResolver", "(", "$", "resolver", ",", "$", "parameters", "=", "[", "]", ",", "$", "method", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "resolver", ")", ")", "{", "return", "call_user_func_array", "(", "$", "resolver", ",", "$", "parameters", ")", ";", "}", "if", "(", "class_exists", "(", "$", "resolver", ")", ")", "{", "$", "instance", "=", "$", "this", "->", "container", "->", "make", "(", "$", "resolver", ",", "$", "parameters", ")", ";", "if", "(", "$", "instance", "instanceof", "Command", ")", "{", "return", "Bus", "::", "dispatch", "(", "$", "instance", ",", "$", "parameters", ")", ";", "}", "if", "(", "is_callable", "(", "[", "$", "instance", ",", "$", "method", "]", ")", ")", "{", "return", "call_user_func_array", "(", "[", "$", "instance", ",", "$", "method", "]", ",", "$", "parameters", ")", ";", "}", "}", "if", "(", "strpos", "(", "$", "resolver", ",", "'@'", ")", "!==", "false", ")", "{", "list", "(", "$", "class", ",", "$", "method", ")", "=", "explode", "(", "'@'", ",", "$", "this", "->", "action", "[", "'uses'", "]", ")", ";", "if", "(", "!", "method_exists", "(", "$", "instance", "=", "$", "this", "->", "container", "->", "make", "(", "$", "class", ")", ",", "$", "method", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid method mapped on object: '", ".", "$", "class", ".", "'.'", ")", ";", "}", "return", "call_user_func_array", "(", "[", "$", "instance", ",", "$", "method", "]", ",", "$", "parameters", ")", ";", "}", "throw", "new", "Exception", "(", "'Invalid resolver: '", ".", "$", "resolver", ".", "'.'", ")", ";", "}" ]
Handle and run the resolver @param mixed $resolver @param array $parameters - params for resolver @return mixed
[ "Handle", "and", "run", "the", "resolver" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/MapperTrait.php#L148-L181
train
Soneritics/Buckaroo
Soneritics/Buckaroo/ServiceOperations/TransactionRequest.php
TransactionRequest.getPostFields
public function getPostFields() { $this->validate(); $mappedFields = $this->getMappedFields(); $this->paymentMethod->addAdditionalFields($mappedFields); return $mappedFields; }
php
public function getPostFields() { $this->validate(); $mappedFields = $this->getMappedFields(); $this->paymentMethod->addAdditionalFields($mappedFields); return $mappedFields; }
[ "public", "function", "getPostFields", "(", ")", "{", "$", "this", "->", "validate", "(", ")", ";", "$", "mappedFields", "=", "$", "this", "->", "getMappedFields", "(", ")", ";", "$", "this", "->", "paymentMethod", "->", "addAdditionalFields", "(", "$", "mappedFields", ")", ";", "return", "$", "mappedFields", ";", "}" ]
Get the post fields for the requests. @return array
[ "Get", "the", "post", "fields", "for", "the", "requests", "." ]
cb345dce9b96c996e47121d6145a7e314943c8f1
https://github.com/Soneritics/Buckaroo/blob/cb345dce9b96c996e47121d6145a7e314943c8f1/Soneritics/Buckaroo/ServiceOperations/TransactionRequest.php#L93-L99
train
RSQueue/RSQueue
src/RSQueue/RedisFactory.php
RedisFactory.createSimple
private function createSimple(): Redis { $redis = new Redis(); $redis->connect($this->config['host'], (int) $this->config['port']); $redis->setOption(Redis::OPT_READ_TIMEOUT, '-1'); if ($this->config['database']) { $redis->select($this->config['database']); } return $redis; }
php
private function createSimple(): Redis { $redis = new Redis(); $redis->connect($this->config['host'], (int) $this->config['port']); $redis->setOption(Redis::OPT_READ_TIMEOUT, '-1'); if ($this->config['database']) { $redis->select($this->config['database']); } return $redis; }
[ "private", "function", "createSimple", "(", ")", ":", "Redis", "{", "$", "redis", "=", "new", "Redis", "(", ")", ";", "$", "redis", "->", "connect", "(", "$", "this", "->", "config", "[", "'host'", "]", ",", "(", "int", ")", "$", "this", "->", "config", "[", "'port'", "]", ")", ";", "$", "redis", "->", "setOption", "(", "Redis", "::", "OPT_READ_TIMEOUT", ",", "'-1'", ")", ";", "if", "(", "$", "this", "->", "config", "[", "'database'", "]", ")", "{", "$", "redis", "->", "select", "(", "$", "this", "->", "config", "[", "'database'", "]", ")", ";", "}", "return", "$", "redis", ";", "}" ]
Create single redis. @return Redis
[ "Create", "single", "redis", "." ]
1a8d72a2b025ed65684644febf9493d4f6ac9333
https://github.com/RSQueue/RSQueue/blob/1a8d72a2b025ed65684644febf9493d4f6ac9333/src/RSQueue/RedisFactory.php#L74-L84
train
zicht/tinymce-bundle
src/Zicht/Bundle/TinymceBundle/Twig/Extension/ZichtTinymceExtension.php
ZichtTinymceExtension.getAssetsUrl
protected function getAssetsUrl($inputUrl) { /** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */ $assets = $this->getService('assets.packages'); $url = preg_replace('/^asset\[(.+)\]$/i', '$1', $inputUrl); if ($inputUrl !== $url) { return $assets->getUrl($this->baseUrl . $url); } return $inputUrl; }
php
protected function getAssetsUrl($inputUrl) { /** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */ $assets = $this->getService('assets.packages'); $url = preg_replace('/^asset\[(.+)\]$/i', '$1', $inputUrl); if ($inputUrl !== $url) { return $assets->getUrl($this->baseUrl . $url); } return $inputUrl; }
[ "protected", "function", "getAssetsUrl", "(", "$", "inputUrl", ")", "{", "/** @var $assets \\Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper */", "$", "assets", "=", "$", "this", "->", "getService", "(", "'assets.packages'", ")", ";", "$", "url", "=", "preg_replace", "(", "'/^asset\\[(.+)\\]$/i'", ",", "'$1'", ",", "$", "inputUrl", ")", ";", "if", "(", "$", "inputUrl", "!==", "$", "url", ")", "{", "return", "$", "assets", "->", "getUrl", "(", "$", "this", "->", "baseUrl", ".", "$", "url", ")", ";", "}", "return", "$", "inputUrl", ";", "}" ]
Get url from config string @param string $inputUrl @return string
[ "Get", "url", "from", "config", "string" ]
43d2eb4eb3f7f0e4752fb496f4aada6f2d805c96
https://github.com/zicht/tinymce-bundle/blob/43d2eb4eb3f7f0e4752fb496f4aada6f2d805c96/src/Zicht/Bundle/TinymceBundle/Twig/Extension/ZichtTinymceExtension.php#L211-L223
train
Wedeto/DB
src/DAO.php
DAO.getSelector
public function getSelector($pkey, array $record) { if ($pkey !== null && !is_array($pkey)) throw new InvalidTypeException("Invalid primary key: " . WF::str($pkey)); // When no primary key is available, we match on all fields $is_primary_key = true; if ($pkey === null) { $pkey = array(); foreach ($record as $k => $v) $pkey[$k] = $this->table->getColumn($v); $is_primary_key = false; } // Make sure there are fields to match on if (empty($pkey)) throw new InvalidTypeException("No fields to match on"); $condition = null; foreach ($pkey as $pkey_column => $coldef) { if ($is_primary_key && (!array_key_exists($pkey_column, $record) || $record[$pkey_column] === null)) throw new DAOException("Record does not have value for primary key column {$pkey_column}"); $pkey_value = $coldef->beforeInsertFilter($record[$pkey_column]); $comparator = new Query\ComparisonOperator("=", $pkey_column, $pkey_value); $condition = $condition === null ? $comparator : new Query\BooleanOperator("AND", $condition, $comparator); } return $condition; }
php
public function getSelector($pkey, array $record) { if ($pkey !== null && !is_array($pkey)) throw new InvalidTypeException("Invalid primary key: " . WF::str($pkey)); // When no primary key is available, we match on all fields $is_primary_key = true; if ($pkey === null) { $pkey = array(); foreach ($record as $k => $v) $pkey[$k] = $this->table->getColumn($v); $is_primary_key = false; } // Make sure there are fields to match on if (empty($pkey)) throw new InvalidTypeException("No fields to match on"); $condition = null; foreach ($pkey as $pkey_column => $coldef) { if ($is_primary_key && (!array_key_exists($pkey_column, $record) || $record[$pkey_column] === null)) throw new DAOException("Record does not have value for primary key column {$pkey_column}"); $pkey_value = $coldef->beforeInsertFilter($record[$pkey_column]); $comparator = new Query\ComparisonOperator("=", $pkey_column, $pkey_value); $condition = $condition === null ? $comparator : new Query\BooleanOperator("AND", $condition, $comparator); } return $condition; }
[ "public", "function", "getSelector", "(", "$", "pkey", ",", "array", "$", "record", ")", "{", "if", "(", "$", "pkey", "!==", "null", "&&", "!", "is_array", "(", "$", "pkey", ")", ")", "throw", "new", "InvalidTypeException", "(", "\"Invalid primary key: \"", ".", "WF", "::", "str", "(", "$", "pkey", ")", ")", ";", "// When no primary key is available, we match on all fields", "$", "is_primary_key", "=", "true", ";", "if", "(", "$", "pkey", "===", "null", ")", "{", "$", "pkey", "=", "array", "(", ")", ";", "foreach", "(", "$", "record", "as", "$", "k", "=>", "$", "v", ")", "$", "pkey", "[", "$", "k", "]", "=", "$", "this", "->", "table", "->", "getColumn", "(", "$", "v", ")", ";", "$", "is_primary_key", "=", "false", ";", "}", "// Make sure there are fields to match on", "if", "(", "empty", "(", "$", "pkey", ")", ")", "throw", "new", "InvalidTypeException", "(", "\"No fields to match on\"", ")", ";", "$", "condition", "=", "null", ";", "foreach", "(", "$", "pkey", "as", "$", "pkey_column", "=>", "$", "coldef", ")", "{", "if", "(", "$", "is_primary_key", "&&", "(", "!", "array_key_exists", "(", "$", "pkey_column", ",", "$", "record", ")", "||", "$", "record", "[", "$", "pkey_column", "]", "===", "null", ")", ")", "throw", "new", "DAOException", "(", "\"Record does not have value for primary key column {$pkey_column}\"", ")", ";", "$", "pkey_value", "=", "$", "coldef", "->", "beforeInsertFilter", "(", "$", "record", "[", "$", "pkey_column", "]", ")", ";", "$", "comparator", "=", "new", "Query", "\\", "ComparisonOperator", "(", "\"=\"", ",", "$", "pkey_column", ",", "$", "pkey_value", ")", ";", "$", "condition", "=", "$", "condition", "===", "null", "?", "$", "comparator", ":", "new", "Query", "\\", "BooleanOperator", "(", "\"AND\"", ",", "$", "condition", ",", "$", "comparator", ")", ";", "}", "return", "$", "condition", ";", "}" ]
Form a condition that matches the record using the values in the provided record. @param array $pkey The column names in the primary key @param array $record The record to match
[ "Form", "a", "condition", "that", "matches", "the", "record", "using", "the", "values", "in", "the", "provided", "record", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L131-L162
train
Wedeto/DB
src/DAO.php
DAO.save
public function save(Model $model) { $database = $model->getSourceDB(); $pkey = $model->getID(); if ($database === null || $database !== $this->db) $this->insert($model); else $this->update($model); return $this; }
php
public function save(Model $model) { $database = $model->getSourceDB(); $pkey = $model->getID(); if ($database === null || $database !== $this->db) $this->insert($model); else $this->update($model); return $this; }
[ "public", "function", "save", "(", "Model", "$", "model", ")", "{", "$", "database", "=", "$", "model", "->", "getSourceDB", "(", ")", ";", "$", "pkey", "=", "$", "model", "->", "getID", "(", ")", ";", "if", "(", "$", "database", "===", "null", "||", "$", "database", "!==", "$", "this", "->", "db", ")", "$", "this", "->", "insert", "(", "$", "model", ")", ";", "else", "$", "this", "->", "update", "(", "$", "model", ")", ";", "return", "$", "this", ";", "}" ]
Save the current record to the database. @param Wedeto\DB\Model $model The model instance to save. If the model does not have a source database, it is inserted, otherwise an update is executed. @return Wedeto\DB\DAO Provides fluent interface
[ "Save", "the", "current", "record", "to", "the", "database", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L173-L184
train
Wedeto/DB
src/DAO.php
DAO.getByID
public function getByID($id) { $pkey = $this->getPrimaryKey(); if ($pkey === null) throw new DAOException("A primary key is required to select a record by ID"); // If there's a unary primary key, the value can be specified as a // single scalar, rather than an array if (count($pkey) === 1 && is_scalar($id)) foreach ($pkey as $colname => $def) $id = [$colname => $id]; $condition = $this->getSelector($pkey, $id); $rec = $this->fetchSingle(QB::where($condition)); if (empty($rec)) throw new DAOEXception("Object not found with " . WF::str($id)); $model = new $this->model_class; $model->assignRecord($rec, $this->db); return $model; }
php
public function getByID($id) { $pkey = $this->getPrimaryKey(); if ($pkey === null) throw new DAOException("A primary key is required to select a record by ID"); // If there's a unary primary key, the value can be specified as a // single scalar, rather than an array if (count($pkey) === 1 && is_scalar($id)) foreach ($pkey as $colname => $def) $id = [$colname => $id]; $condition = $this->getSelector($pkey, $id); $rec = $this->fetchSingle(QB::where($condition)); if (empty($rec)) throw new DAOEXception("Object not found with " . WF::str($id)); $model = new $this->model_class; $model->assignRecord($rec, $this->db); return $model; }
[ "public", "function", "getByID", "(", "$", "id", ")", "{", "$", "pkey", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "$", "pkey", "===", "null", ")", "throw", "new", "DAOException", "(", "\"A primary key is required to select a record by ID\"", ")", ";", "// If there's a unary primary key, the value can be specified as a", "// single scalar, rather than an array", "if", "(", "count", "(", "$", "pkey", ")", "===", "1", "&&", "is_scalar", "(", "$", "id", ")", ")", "foreach", "(", "$", "pkey", "as", "$", "colname", "=>", "$", "def", ")", "$", "id", "=", "[", "$", "colname", "=>", "$", "id", "]", ";", "$", "condition", "=", "$", "this", "->", "getSelector", "(", "$", "pkey", ",", "$", "id", ")", ";", "$", "rec", "=", "$", "this", "->", "fetchSingle", "(", "QB", "::", "where", "(", "$", "condition", ")", ")", ";", "if", "(", "empty", "(", "$", "rec", ")", ")", "throw", "new", "DAOEXception", "(", "\"Object not found with \"", ".", "WF", "::", "str", "(", "$", "id", ")", ")", ";", "$", "model", "=", "new", "$", "this", "->", "model_class", ";", "$", "model", "->", "assignRecord", "(", "$", "rec", ",", "$", "this", "->", "db", ")", ";", "return", "$", "model", ";", "}" ]
Load the record from the database @param mixed $id The record to load, indicating the primary key. The type should match the primary key: scalar for unary primary keys, associative array for combined primary keys.
[ "Load", "the", "record", "from", "the", "database" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L193-L214
train
Wedeto/DB
src/DAO.php
DAO.get
public function get(...$args) { $record = $this->fetchSingle($args); if (!$record) return null; $obj = new $this->model_class; $obj->assignRecord($record, $this->db); return $obj; }
php
public function get(...$args) { $record = $this->fetchSingle($args); if (!$record) return null; $obj = new $this->model_class; $obj->assignRecord($record, $this->db); return $obj; }
[ "public", "function", "get", "(", "...", "$", "args", ")", "{", "$", "record", "=", "$", "this", "->", "fetchSingle", "(", "$", "args", ")", ";", "if", "(", "!", "$", "record", ")", "return", "null", ";", "$", "obj", "=", "new", "$", "this", "->", "model_class", ";", "$", "obj", "->", "assignRecord", "(", "$", "record", ",", "$", "this", "->", "db", ")", ";", "return", "$", "obj", ";", "}" ]
Retrieve a single record based on a provided query @param args The provided arguments for the select query. @return Model The fetch model @see Wedeto\DB\DAO::select
[ "Retrieve", "a", "single", "record", "based", "on", "a", "provided", "query" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L222-L230
train
Wedeto/DB
src/DAO.php
DAO.getAll
public function getAll(...$args) { $pkey = $this->getPrimaryKey(); if (count($pkey) === 1) { reset($pkey); $pkey_as_index = key($pkey); } else $pkey_as_index = false; $list = array(); $records = $this->fetchAll($args); foreach ($records as $record) { $obj = new $this->model_class; $obj->assignRecord($record, $this->db); if ($pkey_as_index) $list[$obj->getField($pkey_as_index)] = $obj; else $list[] = $obj; } return $list; }
php
public function getAll(...$args) { $pkey = $this->getPrimaryKey(); if (count($pkey) === 1) { reset($pkey); $pkey_as_index = key($pkey); } else $pkey_as_index = false; $list = array(); $records = $this->fetchAll($args); foreach ($records as $record) { $obj = new $this->model_class; $obj->assignRecord($record, $this->db); if ($pkey_as_index) $list[$obj->getField($pkey_as_index)] = $obj; else $list[] = $obj; } return $list; }
[ "public", "function", "getAll", "(", "...", "$", "args", ")", "{", "$", "pkey", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "count", "(", "$", "pkey", ")", "===", "1", ")", "{", "reset", "(", "$", "pkey", ")", ";", "$", "pkey_as_index", "=", "key", "(", "$", "pkey", ")", ";", "}", "else", "$", "pkey_as_index", "=", "false", ";", "$", "list", "=", "array", "(", ")", ";", "$", "records", "=", "$", "this", "->", "fetchAll", "(", "$", "args", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "obj", "=", "new", "$", "this", "->", "model_class", ";", "$", "obj", "->", "assignRecord", "(", "$", "record", ",", "$", "this", "->", "db", ")", ";", "if", "(", "$", "pkey_as_index", ")", "$", "list", "[", "$", "obj", "->", "getField", "(", "$", "pkey_as_index", ")", "]", "=", "$", "obj", ";", "else", "$", "list", "[", "]", "=", "$", "obj", ";", "}", "return", "$", "list", ";", "}" ]
Retrieve a set of records, create object from them and return the resulting list. @param $args The provided arguments for the select query. @return array The retrieved DAO objects. If the primary key is a single field, the indices correspond to the primary key @see Wedeto\DB\DAO::select
[ "Retrieve", "a", "set", "of", "records", "create", "object", "from", "them", "and", "return", "the", "resulting", "list", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L238-L263
train
Wedeto/DB
src/DAO.php
DAO.fetchSingle
public function fetchSingle(...$args) { $args[] = QB::limit(1); $select = $this->select($args); return $select->fetch(); }
php
public function fetchSingle(...$args) { $args[] = QB::limit(1); $select = $this->select($args); return $select->fetch(); }
[ "public", "function", "fetchSingle", "(", "...", "$", "args", ")", "{", "$", "args", "[", "]", "=", "QB", "::", "limit", "(", "1", ")", ";", "$", "select", "=", "$", "this", "->", "select", "(", "$", "args", ")", ";", "return", "$", "select", "->", "fetch", "(", ")", ";", "}" ]
Execute a query, retrieve the first record and return it. @param $args The provided arguments for the select query. @return array The retrieved record @see Wedeto\DB\DAO::select
[ "Execute", "a", "query", "retrieve", "the", "first", "record", "and", "return", "it", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L272-L277
train
Wedeto/DB
src/DAO.php
DAO.select
public function select(...$args) { $args = WF::flatten_array($args); $select = new Query\Select; $select->add(new Query\SourceTableClause($this->tablename)); $cols = $this->getColumns(); foreach ($cols as $name => $def) $select->add(new Query\GetClause($name)); foreach ($args as $arg) $select->add($arg); $drv = $this->db->getDriver(); return $drv->select($select); }
php
public function select(...$args) { $args = WF::flatten_array($args); $select = new Query\Select; $select->add(new Query\SourceTableClause($this->tablename)); $cols = $this->getColumns(); foreach ($cols as $name => $def) $select->add(new Query\GetClause($name)); foreach ($args as $arg) $select->add($arg); $drv = $this->db->getDriver(); return $drv->select($select); }
[ "public", "function", "select", "(", "...", "$", "args", ")", "{", "$", "args", "=", "WF", "::", "flatten_array", "(", "$", "args", ")", ";", "$", "select", "=", "new", "Query", "\\", "Select", ";", "$", "select", "->", "add", "(", "new", "Query", "\\", "SourceTableClause", "(", "$", "this", "->", "tablename", ")", ")", ";", "$", "cols", "=", "$", "this", "->", "getColumns", "(", ")", ";", "foreach", "(", "$", "cols", "as", "$", "name", "=>", "$", "def", ")", "$", "select", "->", "add", "(", "new", "Query", "\\", "GetClause", "(", "$", "name", ")", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "$", "select", "->", "add", "(", "$", "arg", ")", ";", "$", "drv", "=", "$", "this", "->", "db", "->", "getDriver", "(", ")", ";", "return", "$", "drv", "->", "select", "(", "$", "select", ")", ";", "}" ]
Select one or more records from the database. @param $args The provided arguments should contain query parts passed to the Select constructor. These can be objects such as: FieldName, JoinClause, WhereClause, OrderClause, LimitClause, OffsetClause. A Wedeto\DB\DB object can also be passed in to use as a Database. @return PreparedStatement The executed select query @see Wedeto\DB\Query\Select
[ "Select", "one", "or", "more", "records", "from", "the", "database", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L303-L317
train
Wedeto/DB
src/DAO.php
DAO.update
public function update($id, array $record = null) { $model = is_a($id, $this->model_class) ? $id : null; if (null !== $model) { if ($record !== null) throw new DAOException("You should not pass an array of updates when supplying a Model"); if ($id->getSourceDB() !== $this->db) throw new DAOException("Cannot update object - it did not originate in this database"); $record = $id->getChanges(); $id = $id->getID(); } if ($record === null) throw new DAOException("No update provided"); // Check if there's anything to update if (count($record) === 0) return 0; $table = $this->table; $columns = $table->getColumns(); $pkey = $table->getPrimaryColumns(); if ($pkey === null) throw new DAOException("Cannot update record without primary key"); if (is_scalar($id) && count($pkey) === 1) foreach ($pkey as $colname => $def) $id = [$colname => $id]; $condition = $this->getSelector($pkey, $id); // Remove primary key from the to-be-updated fields foreach ($pkey as $column) unset($record[$column->getName()]); $update = new Query\Update; $update->add(new Query\SourceTableClause($this->tablename)); $update->add(new Query\WhereClause($condition)); foreach ($record as $field => $value) { if (!isset($columns[$field])) throw new DAOException("Invalid field: " . $field); $coldef = $columns[$field]; $value = $coldef->beforeInsertFilter($value); $update->add(new Query\UpdateField($field, $value)); } $drv = $this->db->getDriver(); $rows = $drv->update($update); if (null !== $model) { $model->markClean(); } return $rows; }
php
public function update($id, array $record = null) { $model = is_a($id, $this->model_class) ? $id : null; if (null !== $model) { if ($record !== null) throw new DAOException("You should not pass an array of updates when supplying a Model"); if ($id->getSourceDB() !== $this->db) throw new DAOException("Cannot update object - it did not originate in this database"); $record = $id->getChanges(); $id = $id->getID(); } if ($record === null) throw new DAOException("No update provided"); // Check if there's anything to update if (count($record) === 0) return 0; $table = $this->table; $columns = $table->getColumns(); $pkey = $table->getPrimaryColumns(); if ($pkey === null) throw new DAOException("Cannot update record without primary key"); if (is_scalar($id) && count($pkey) === 1) foreach ($pkey as $colname => $def) $id = [$colname => $id]; $condition = $this->getSelector($pkey, $id); // Remove primary key from the to-be-updated fields foreach ($pkey as $column) unset($record[$column->getName()]); $update = new Query\Update; $update->add(new Query\SourceTableClause($this->tablename)); $update->add(new Query\WhereClause($condition)); foreach ($record as $field => $value) { if (!isset($columns[$field])) throw new DAOException("Invalid field: " . $field); $coldef = $columns[$field]; $value = $coldef->beforeInsertFilter($value); $update->add(new Query\UpdateField($field, $value)); } $drv = $this->db->getDriver(); $rows = $drv->update($update); if (null !== $model) { $model->markClean(); } return $rows; }
[ "public", "function", "update", "(", "$", "id", ",", "array", "$", "record", "=", "null", ")", "{", "$", "model", "=", "is_a", "(", "$", "id", ",", "$", "this", "->", "model_class", ")", "?", "$", "id", ":", "null", ";", "if", "(", "null", "!==", "$", "model", ")", "{", "if", "(", "$", "record", "!==", "null", ")", "throw", "new", "DAOException", "(", "\"You should not pass an array of updates when supplying a Model\"", ")", ";", "if", "(", "$", "id", "->", "getSourceDB", "(", ")", "!==", "$", "this", "->", "db", ")", "throw", "new", "DAOException", "(", "\"Cannot update object - it did not originate in this database\"", ")", ";", "$", "record", "=", "$", "id", "->", "getChanges", "(", ")", ";", "$", "id", "=", "$", "id", "->", "getID", "(", ")", ";", "}", "if", "(", "$", "record", "===", "null", ")", "throw", "new", "DAOException", "(", "\"No update provided\"", ")", ";", "// Check if there's anything to update", "if", "(", "count", "(", "$", "record", ")", "===", "0", ")", "return", "0", ";", "$", "table", "=", "$", "this", "->", "table", ";", "$", "columns", "=", "$", "table", "->", "getColumns", "(", ")", ";", "$", "pkey", "=", "$", "table", "->", "getPrimaryColumns", "(", ")", ";", "if", "(", "$", "pkey", "===", "null", ")", "throw", "new", "DAOException", "(", "\"Cannot update record without primary key\"", ")", ";", "if", "(", "is_scalar", "(", "$", "id", ")", "&&", "count", "(", "$", "pkey", ")", "===", "1", ")", "foreach", "(", "$", "pkey", "as", "$", "colname", "=>", "$", "def", ")", "$", "id", "=", "[", "$", "colname", "=>", "$", "id", "]", ";", "$", "condition", "=", "$", "this", "->", "getSelector", "(", "$", "pkey", ",", "$", "id", ")", ";", "// Remove primary key from the to-be-updated fields", "foreach", "(", "$", "pkey", "as", "$", "column", ")", "unset", "(", "$", "record", "[", "$", "column", "->", "getName", "(", ")", "]", ")", ";", "$", "update", "=", "new", "Query", "\\", "Update", ";", "$", "update", "->", "add", "(", "new", "Query", "\\", "SourceTableClause", "(", "$", "this", "->", "tablename", ")", ")", ";", "$", "update", "->", "add", "(", "new", "Query", "\\", "WhereClause", "(", "$", "condition", ")", ")", ";", "foreach", "(", "$", "record", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "columns", "[", "$", "field", "]", ")", ")", "throw", "new", "DAOException", "(", "\"Invalid field: \"", ".", "$", "field", ")", ";", "$", "coldef", "=", "$", "columns", "[", "$", "field", "]", ";", "$", "value", "=", "$", "coldef", "->", "beforeInsertFilter", "(", "$", "value", ")", ";", "$", "update", "->", "add", "(", "new", "Query", "\\", "UpdateField", "(", "$", "field", ",", "$", "value", ")", ")", ";", "}", "$", "drv", "=", "$", "this", "->", "db", "->", "getDriver", "(", ")", ";", "$", "rows", "=", "$", "drv", "->", "update", "(", "$", "update", ")", ";", "if", "(", "null", "!==", "$", "model", ")", "{", "$", "model", "->", "markClean", "(", ")", ";", "}", "return", "$", "rows", ";", "}" ]
Update records in the database. @param mixed $id The values for the primary key to select the record to update. You can also supply an instance of the accompanying Model class. @param array $record The record to update. Should contain key/value pairs where keys are fieldnames, values are the values to update them to. Should also contain the value for the primary key. which will be used to find the record to be updated. When providing a Model as $id, this should be omitted. @return int The number of updated records
[ "Update", "records", "in", "the", "database", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L331-L393
train
Wedeto/DB
src/DAO.php
DAO.delete
public function delete($where) { $is_model = is_a($where, $this->model_class); if (!$is_model && !is_a($where, Query\WhereClause::class)) throw new InvalidTypeException("Must provide a WhereClause or an instance of {$this->model_class} to delete"); $modelInstance = null; if ($is_model) { $database = $where->getSourceDB(); if ($database === null || $database !== $this->db) throw new DAOException("Cannot remove this record - it did not originate in this database"); $modelInstance = $where; $where = $this->getSelector($this->getPrimaryKey(), $modelInstance->getRecord()); } $delete = new Query\Delete($this->tablename, $where); $drv = $this->db->getDriver(); $rows = $drv->delete($delete); if ($is_model) $modelInstance->destruct(); return $rows; }
php
public function delete($where) { $is_model = is_a($where, $this->model_class); if (!$is_model && !is_a($where, Query\WhereClause::class)) throw new InvalidTypeException("Must provide a WhereClause or an instance of {$this->model_class} to delete"); $modelInstance = null; if ($is_model) { $database = $where->getSourceDB(); if ($database === null || $database !== $this->db) throw new DAOException("Cannot remove this record - it did not originate in this database"); $modelInstance = $where; $where = $this->getSelector($this->getPrimaryKey(), $modelInstance->getRecord()); } $delete = new Query\Delete($this->tablename, $where); $drv = $this->db->getDriver(); $rows = $drv->delete($delete); if ($is_model) $modelInstance->destruct(); return $rows; }
[ "public", "function", "delete", "(", "$", "where", ")", "{", "$", "is_model", "=", "is_a", "(", "$", "where", ",", "$", "this", "->", "model_class", ")", ";", "if", "(", "!", "$", "is_model", "&&", "!", "is_a", "(", "$", "where", ",", "Query", "\\", "WhereClause", "::", "class", ")", ")", "throw", "new", "InvalidTypeException", "(", "\"Must provide a WhereClause or an instance of {$this->model_class} to delete\"", ")", ";", "$", "modelInstance", "=", "null", ";", "if", "(", "$", "is_model", ")", "{", "$", "database", "=", "$", "where", "->", "getSourceDB", "(", ")", ";", "if", "(", "$", "database", "===", "null", "||", "$", "database", "!==", "$", "this", "->", "db", ")", "throw", "new", "DAOException", "(", "\"Cannot remove this record - it did not originate in this database\"", ")", ";", "$", "modelInstance", "=", "$", "where", ";", "$", "where", "=", "$", "this", "->", "getSelector", "(", "$", "this", "->", "getPrimaryKey", "(", ")", ",", "$", "modelInstance", "->", "getRecord", "(", ")", ")", ";", "}", "$", "delete", "=", "new", "Query", "\\", "Delete", "(", "$", "this", "->", "tablename", ",", "$", "where", ")", ";", "$", "drv", "=", "$", "this", "->", "db", "->", "getDriver", "(", ")", ";", "$", "rows", "=", "$", "drv", "->", "delete", "(", "$", "delete", ")", ";", "if", "(", "$", "is_model", ")", "$", "modelInstance", "->", "destruct", "(", ")", ";", "return", "$", "rows", ";", "}" ]
Delete records from the database. @param Wedeto\DB\Query\WhereClause Specifies which records to delete. You can use Wedeto\DB\Query\Builder to create it, or provide a string that will be interpreted as custom SQL. A third option is to provide an associative array where keys indicate field names and values their values to match them with. @return int The number of rows deleted
[ "Delete", "records", "from", "the", "database", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DAO.php#L475-L500
train
JumpGateio/Core
src/JumpGate/Core/Services/Response.php
Response.route
public function route($name, $details = []) { $this->route = route($name, $details); $this->routeName = $name; return $this; }
php
public function route($name, $details = []) { $this->route = route($name, $details); $this->routeName = $name; return $this; }
[ "public", "function", "route", "(", "$", "name", ",", "$", "details", "=", "[", "]", ")", "{", "$", "this", "->", "route", "=", "route", "(", "$", "name", ",", "$", "details", ")", ";", "$", "this", "->", "routeName", "=", "$", "name", ";", "return", "$", "this", ";", "}" ]
Add a route to redirect the request to. @param string $name @param array $details @return $this
[ "Add", "a", "route", "to", "redirect", "the", "request", "to", "." ]
485b5cf03b3072267bffbee428b81e48d407d6b6
https://github.com/JumpGateio/Core/blob/485b5cf03b3072267bffbee428b81e48d407d6b6/src/JumpGate/Core/Services/Response.php#L71-L77
train
JumpGateio/Core
src/JumpGate/Core/Services/Response.php
Response.redirectIntended
public function redirectIntended() { // Make sure we have a route. if (is_null($this->route)) { throw new \Exception('No route has been provided. Please use route() to add one.'); } // If this response passed, show the success message. if ($this->success) { return redirect() ->intended($this->route) ->with('message', $this->message); } // If this response failed, show the error message. return redirect($this->route) ->with('error', $this->message); }
php
public function redirectIntended() { // Make sure we have a route. if (is_null($this->route)) { throw new \Exception('No route has been provided. Please use route() to add one.'); } // If this response passed, show the success message. if ($this->success) { return redirect() ->intended($this->route) ->with('message', $this->message); } // If this response failed, show the error message. return redirect($this->route) ->with('error', $this->message); }
[ "public", "function", "redirectIntended", "(", ")", "{", "// Make sure we have a route.", "if", "(", "is_null", "(", "$", "this", "->", "route", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No route has been provided. Please use route() to add one.'", ")", ";", "}", "// If this response passed, show the success message.", "if", "(", "$", "this", "->", "success", ")", "{", "return", "redirect", "(", ")", "->", "intended", "(", "$", "this", "->", "route", ")", "->", "with", "(", "'message'", ",", "$", "this", "->", "message", ")", ";", "}", "// If this response failed, show the error message.", "return", "redirect", "(", "$", "this", "->", "route", ")", "->", "with", "(", "'error'", ",", "$", "this", "->", "message", ")", ";", "}" ]
Redirect the request to the intended route or the provided one. @return \Illuminate\Http\RedirectResponse @throws \Exception
[ "Redirect", "the", "request", "to", "the", "intended", "route", "or", "the", "provided", "one", "." ]
485b5cf03b3072267bffbee428b81e48d407d6b6
https://github.com/JumpGateio/Core/blob/485b5cf03b3072267bffbee428b81e48d407d6b6/src/JumpGate/Core/Services/Response.php#L109-L126
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/Persist.php
Persist.associateRelatedRecordsToNewRecord
public function associateRelatedRecordsToNewRecord($modelInstance, $associatedRecords, $relatedNamespace, $relatedModelClass) { // Check if there are any records to insert into the pivot table if (count($associatedRecords) > 0) { // What is the namespace.class of the related table? $namespaceModelclass = $relatedNamespace . "\\". $relatedModelClass; // We need the repository of the related table (model?!). That repository is... well, it is // this repository class: the base repository class! We need a new instance with the related model. // So, create the new base repository instance... $relatedRepository = new \Lasallecms\Lasallecmsapi\Repositories\BaseRepository(); /// ... and inject the related model class into it $relatedRepository->injectModelIntoRepository($namespaceModelclass); // For the purpose of saving to the pivot table, we need the method name of the related model as // it is in the model. As the method would be capitalized, let's un-capitalize it $relatedMethod = strtolower($relatedModelClass); // for each record that needs to be INSERTed into the pivot table foreach ($associatedRecords as $associatedRecordId) { // get the record in the related table, so we can use the info to save to the pivot table $associatedRecord = $relatedRepository->getFind($associatedRecordId); // save to the pivot table $modelInstance->$relatedMethod()->save($associatedRecord); } } }
php
public function associateRelatedRecordsToNewRecord($modelInstance, $associatedRecords, $relatedNamespace, $relatedModelClass) { // Check if there are any records to insert into the pivot table if (count($associatedRecords) > 0) { // What is the namespace.class of the related table? $namespaceModelclass = $relatedNamespace . "\\". $relatedModelClass; // We need the repository of the related table (model?!). That repository is... well, it is // this repository class: the base repository class! We need a new instance with the related model. // So, create the new base repository instance... $relatedRepository = new \Lasallecms\Lasallecmsapi\Repositories\BaseRepository(); /// ... and inject the related model class into it $relatedRepository->injectModelIntoRepository($namespaceModelclass); // For the purpose of saving to the pivot table, we need the method name of the related model as // it is in the model. As the method would be capitalized, let's un-capitalize it $relatedMethod = strtolower($relatedModelClass); // for each record that needs to be INSERTed into the pivot table foreach ($associatedRecords as $associatedRecordId) { // get the record in the related table, so we can use the info to save to the pivot table $associatedRecord = $relatedRepository->getFind($associatedRecordId); // save to the pivot table $modelInstance->$relatedMethod()->save($associatedRecord); } } }
[ "public", "function", "associateRelatedRecordsToNewRecord", "(", "$", "modelInstance", ",", "$", "associatedRecords", ",", "$", "relatedNamespace", ",", "$", "relatedModelClass", ")", "{", "// Check if there are any records to insert into the pivot table", "if", "(", "count", "(", "$", "associatedRecords", ")", ">", "0", ")", "{", "// What is the namespace.class of the related table?", "$", "namespaceModelclass", "=", "$", "relatedNamespace", ".", "\"\\\\\"", ".", "$", "relatedModelClass", ";", "// We need the repository of the related table (model?!). That repository is... well, it is", "// this repository class: the base repository class! We need a new instance with the related model.", "// So, create the new base repository instance...", "$", "relatedRepository", "=", "new", "\\", "Lasallecms", "\\", "Lasallecmsapi", "\\", "Repositories", "\\", "BaseRepository", "(", ")", ";", "/// ... and inject the related model class into it", "$", "relatedRepository", "->", "injectModelIntoRepository", "(", "$", "namespaceModelclass", ")", ";", "// For the purpose of saving to the pivot table, we need the method name of the related model as", "// it is in the model. As the method would be capitalized, let's un-capitalize it", "$", "relatedMethod", "=", "strtolower", "(", "$", "relatedModelClass", ")", ";", "// for each record that needs to be INSERTed into the pivot table", "foreach", "(", "$", "associatedRecords", "as", "$", "associatedRecordId", ")", "{", "// get the record in the related table, so we can use the info to save to the pivot table", "$", "associatedRecord", "=", "$", "relatedRepository", "->", "getFind", "(", "$", "associatedRecordId", ")", ";", "// save to the pivot table", "$", "modelInstance", "->", "$", "relatedMethod", "(", ")", "->", "save", "(", "$", "associatedRecord", ")", ";", "}", "}", "}" ]
Associate each related record with the record just created @param object $modelInstance object just created @param array $associatedRecords array of id's associated with the record just created @param string $relatedNamespace Namespace of the associated model @param string $relatedModelClass Class of the associated model @return void
[ "Associate", "each", "related", "record", "with", "the", "record", "just", "created" ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/Persist.php#L194-L225
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/Persist.php
Persist.associateRelatedRecordsToUpdatedRecord
public function associateRelatedRecordsToUpdatedRecord($modelInstance, $associatedRecords, $relatedModelClass) { // Check if there are any records to sync with the pivot table if (count($associatedRecords) > 0) { // There's probably a function for this, but for now: // (i) create an array of the related IDs // (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC // (i) create an array of the related IDs $newIds = array(); foreach ($associatedRecords as $associatedId) { $newIds[] = $associatedId; } // For the purpose of saving to the pivot table, we need the method name of the related model as // it is in the model. As the method would be capitalized, let's un-capitalize it $relatedMethod = strtolower($relatedModelClass); // (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC $modelInstance->$relatedMethod()->sync($newIds); } }
php
public function associateRelatedRecordsToUpdatedRecord($modelInstance, $associatedRecords, $relatedModelClass) { // Check if there are any records to sync with the pivot table if (count($associatedRecords) > 0) { // There's probably a function for this, but for now: // (i) create an array of the related IDs // (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC // (i) create an array of the related IDs $newIds = array(); foreach ($associatedRecords as $associatedId) { $newIds[] = $associatedId; } // For the purpose of saving to the pivot table, we need the method name of the related model as // it is in the model. As the method would be capitalized, let's un-capitalize it $relatedMethod = strtolower($relatedModelClass); // (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC $modelInstance->$relatedMethod()->sync($newIds); } }
[ "public", "function", "associateRelatedRecordsToUpdatedRecord", "(", "$", "modelInstance", ",", "$", "associatedRecords", ",", "$", "relatedModelClass", ")", "{", "// Check if there are any records to sync with the pivot table", "if", "(", "count", "(", "$", "associatedRecords", ")", ">", "0", ")", "{", "// There's probably a function for this, but for now:", "// (i) create an array of the related IDs", "// (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC", "// (i) create an array of the related IDs", "$", "newIds", "=", "array", "(", ")", ";", "foreach", "(", "$", "associatedRecords", "as", "$", "associatedId", ")", "{", "$", "newIds", "[", "]", "=", "$", "associatedId", ";", "}", "// For the purpose of saving to the pivot table, we need the method name of the related model as", "// it is in the model. As the method would be capitalized, let's un-capitalize it", "$", "relatedMethod", "=", "strtolower", "(", "$", "relatedModelClass", ")", ";", "// (ii) detach the existing tag IDs and attach the new tag IDs, by using SYNC", "$", "modelInstance", "->", "$", "relatedMethod", "(", ")", "->", "sync", "(", "$", "newIds", ")", ";", "}", "}" ]
Associate each related record with the record just updated. @param object $modelInstance object just updated @param array $associatedRecords array of id's associated with the record just updated @param string $relatedNamespace Namespace of the associated model @param string $relatedModelClass Class of the associated model @return void
[ "Associate", "each", "related", "record", "with", "the", "record", "just", "updated", "." ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/Persist.php#L350-L373
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.get
public function get($idOrKey, array $fields = null) { $parameters = $fields ? sprintf( '?%s', $this->createUriParameters( ['fields' => implode(',', $fields)] ) ) : '' ; return $this->getRequest(sprintf('issue/%s%s', $idOrKey, $parameters)); }
php
public function get($idOrKey, array $fields = null) { $parameters = $fields ? sprintf( '?%s', $this->createUriParameters( ['fields' => implode(',', $fields)] ) ) : '' ; return $this->getRequest(sprintf('issue/%s%s', $idOrKey, $parameters)); }
[ "public", "function", "get", "(", "$", "idOrKey", ",", "array", "$", "fields", "=", "null", ")", "{", "$", "parameters", "=", "$", "fields", "?", "sprintf", "(", "'?%s'", ",", "$", "this", "->", "createUriParameters", "(", "[", "'fields'", "=>", "implode", "(", "','", ",", "$", "fields", ")", "]", ")", ")", ":", "''", ";", "return", "$", "this", "->", "getRequest", "(", "sprintf", "(", "'issue/%s%s'", ",", "$", "idOrKey", ",", "$", "parameters", ")", ")", ";", "}" ]
Returns issue by id or key. @link https://docs.atlassian.com/jira/REST/latest/#d2e1375 @param integer|string $idOrKey @param array $fields array of fields to be returns (return all by default) @return \GuzzleHttp\Message\Response
[ "Returns", "issue", "by", "id", "or", "key", "." ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L28-L41
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.delete
public function delete($idOrKey, $deleteSubtasks = false) { $parameters = sprintf('?deleteSubtasks=%s', $deleteSubtasks); return $this->deleteRequest(sprintf('issue/%s%s', $idOrKey, $parameters)); }
php
public function delete($idOrKey, $deleteSubtasks = false) { $parameters = sprintf('?deleteSubtasks=%s', $deleteSubtasks); return $this->deleteRequest(sprintf('issue/%s%s', $idOrKey, $parameters)); }
[ "public", "function", "delete", "(", "$", "idOrKey", ",", "$", "deleteSubtasks", "=", "false", ")", "{", "$", "parameters", "=", "sprintf", "(", "'?deleteSubtasks=%s'", ",", "$", "deleteSubtasks", ")", ";", "return", "$", "this", "->", "deleteRequest", "(", "sprintf", "(", "'issue/%s%s'", ",", "$", "idOrKey", ",", "$", "parameters", ")", ")", ";", "}" ]
Deletes an issue by id or key @link https://docs.atlassian.com/jira/REST/latest/#d2e1401 @param integer|string $idOrKey @param boolean $deleteSubtasks @return \GuzzleHttp\Message\Response
[ "Deletes", "an", "issue", "by", "id", "or", "key" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L67-L72
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.createAttachment
public function createAttachment($idOrKey, $fileHandle) { if (gettype($fileHandle) != 'resource') { throw new \RuntimeException(sprintf('createAttachment() expects parameter 2 to be resource, %s given', gettype($fileHandle))); } return $this->postFile(sprintf('issue/%s/attachments', $idOrKey), $fileHandle); }
php
public function createAttachment($idOrKey, $fileHandle) { if (gettype($fileHandle) != 'resource') { throw new \RuntimeException(sprintf('createAttachment() expects parameter 2 to be resource, %s given', gettype($fileHandle))); } return $this->postFile(sprintf('issue/%s/attachments', $idOrKey), $fileHandle); }
[ "public", "function", "createAttachment", "(", "$", "idOrKey", ",", "$", "fileHandle", ")", "{", "if", "(", "gettype", "(", "$", "fileHandle", ")", "!=", "'resource'", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'createAttachment() expects parameter 2 to be resource, %s given'", ",", "gettype", "(", "$", "fileHandle", ")", ")", ")", ";", "}", "return", "$", "this", "->", "postFile", "(", "sprintf", "(", "'issue/%s/attachments'", ",", "$", "idOrKey", ")", ",", "$", "fileHandle", ")", ";", "}" ]
Create issue attachment by its id or key @link https://docs.atlassian.com/jira/REST/latest/#d2e1228 @param integer|string $idOrKey @param array $data @return \GuzzleHttp\Message\Response
[ "Create", "issue", "attachment", "by", "its", "id", "or", "key" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L99-L106
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.updateComment
public function updateComment($idOrKey, $commentId, array $data) { return $this->putRequest(sprintf('issue/%s/comment/%s', $idOrKey, $commentId), $data); }
php
public function updateComment($idOrKey, $commentId, array $data) { return $this->putRequest(sprintf('issue/%s/comment/%s', $idOrKey, $commentId), $data); }
[ "public", "function", "updateComment", "(", "$", "idOrKey", ",", "$", "commentId", ",", "array", "$", "data", ")", "{", "return", "$", "this", "->", "putRequest", "(", "sprintf", "(", "'issue/%s/comment/%s'", ",", "$", "idOrKey", ",", "$", "commentId", ")", ",", "$", "data", ")", ";", "}" ]
Updates a comment by issue id or key, comment id with given data @link https://docs.atlassian.com/jira/REST/latest/#d2e1221 @param integer|string $idOrKey @param integer $commentId @param array $data @return \GuzzleHttp\Message\Response
[ "Updates", "a", "comment", "by", "issue", "id", "or", "key", "comment", "id", "with", "given", "data" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L177-L180
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.createWorklog
public function createWorklog($idOrKey, array $data, $adjustEstimate = null, $newEstimate = null, $reduceBy = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, 'reduceBy' => $reduceBy, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->postRequest(sprintf('issue/%s/worklog%s', $idOrKey, $parameters), $data); }
php
public function createWorklog($idOrKey, array $data, $adjustEstimate = null, $newEstimate = null, $reduceBy = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, 'reduceBy' => $reduceBy, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->postRequest(sprintf('issue/%s/worklog%s', $idOrKey, $parameters), $data); }
[ "public", "function", "createWorklog", "(", "$", "idOrKey", ",", "array", "$", "data", ",", "$", "adjustEstimate", "=", "null", ",", "$", "newEstimate", "=", "null", ",", "$", "reduceBy", "=", "null", ")", "{", "$", "parameters", "=", "http_build_query", "(", "[", "'adjustEstimate'", "=>", "$", "adjustEstimate", ",", "'newEstimate'", "=>", "$", "newEstimate", ",", "'reduceBy'", "=>", "$", "reduceBy", ",", "]", ")", ";", "if", "(", "$", "parameters", ")", "{", "$", "parameters", "=", "sprintf", "(", "'?%s'", ",", "$", "parameters", ")", ";", "}", "return", "$", "this", "->", "postRequest", "(", "sprintf", "(", "'issue/%s/worklog%s'", ",", "$", "idOrKey", ",", "$", "parameters", ")", ",", "$", "data", ")", ";", "}" ]
Creates worklog for the issue by issue id or key @link https://docs.atlassian.com/jira/REST/latest/#d2e1788 @param integer|string $idOrKey @param array $data @param string $adjustEstimate ("new", "leave", "manual", "auto") @param string $newEstimate (required for "new" adjustEstimate) @param string $reduceBy (required for "manual" adjustEstimate) @return \GuzzleHttp\Message\Response
[ "Creates", "worklog", "for", "the", "issue", "by", "issue", "id", "or", "key" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L224-L239
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.updateWorklog
public function updateWorklog($idOrKey, $worklogId, array $data, $adjustEstimate = null, $newEstimate = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->putRequest(sprintf('issue/%s/worklog/%s%s', $idOrKey, $worklogId, $parameters), $data); }
php
public function updateWorklog($idOrKey, $worklogId, array $data, $adjustEstimate = null, $newEstimate = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->putRequest(sprintf('issue/%s/worklog/%s%s', $idOrKey, $worklogId, $parameters), $data); }
[ "public", "function", "updateWorklog", "(", "$", "idOrKey", ",", "$", "worklogId", ",", "array", "$", "data", ",", "$", "adjustEstimate", "=", "null", ",", "$", "newEstimate", "=", "null", ")", "{", "$", "parameters", "=", "http_build_query", "(", "[", "'adjustEstimate'", "=>", "$", "adjustEstimate", ",", "'newEstimate'", "=>", "$", "newEstimate", ",", "]", ")", ";", "if", "(", "$", "parameters", ")", "{", "$", "parameters", "=", "sprintf", "(", "'?%s'", ",", "$", "parameters", ")", ";", "}", "return", "$", "this", "->", "putRequest", "(", "sprintf", "(", "'issue/%s/worklog/%s%s'", ",", "$", "idOrKey", ",", "$", "worklogId", ",", "$", "parameters", ")", ",", "$", "data", ")", ";", "}" ]
Updates worklog for the issue by issue id or key and worklog id @link https://docs.atlassian.com/jira/REST/latest/#d2e1843 @param integer|string $idOrKey @param integer $worklogId @param array $data @param string $adjustEstimate @param string $newEstimate @return \GuzzleHttp\Message\Response
[ "Updates", "worklog", "for", "the", "issue", "by", "issue", "id", "or", "key", "and", "worklog", "id" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L269-L283
train
AlexKovalevych/jira-api
src/Clients/IssueClient.php
IssueClient.deleteWorklog
public function deleteWorklog($idOrKey, $worklogId, $adjustEstimate = null, $newEstimate = null, $increaseBy = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, 'increaseBy' => $increaseBy, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->deleteRequest(sprintf('issue/%s/worklog/%s%s', $idOrKey, $worklogId, $parameters)); }
php
public function deleteWorklog($idOrKey, $worklogId, $adjustEstimate = null, $newEstimate = null, $increaseBy = null) { $parameters = http_build_query( [ 'adjustEstimate' => $adjustEstimate, 'newEstimate' => $newEstimate, 'increaseBy' => $increaseBy, ] ); if ($parameters) { $parameters = sprintf('?%s', $parameters); } return $this->deleteRequest(sprintf('issue/%s/worklog/%s%s', $idOrKey, $worklogId, $parameters)); }
[ "public", "function", "deleteWorklog", "(", "$", "idOrKey", ",", "$", "worklogId", ",", "$", "adjustEstimate", "=", "null", ",", "$", "newEstimate", "=", "null", ",", "$", "increaseBy", "=", "null", ")", "{", "$", "parameters", "=", "http_build_query", "(", "[", "'adjustEstimate'", "=>", "$", "adjustEstimate", ",", "'newEstimate'", "=>", "$", "newEstimate", ",", "'increaseBy'", "=>", "$", "increaseBy", ",", "]", ")", ";", "if", "(", "$", "parameters", ")", "{", "$", "parameters", "=", "sprintf", "(", "'?%s'", ",", "$", "parameters", ")", ";", "}", "return", "$", "this", "->", "deleteRequest", "(", "sprintf", "(", "'issue/%s/worklog/%s%s'", ",", "$", "idOrKey", ",", "$", "worklogId", ",", "$", "parameters", ")", ")", ";", "}" ]
Deletes worklog for the issue by issue id or key and worklog id @link https://docs.atlassian.com/jira/REST/latest/#d2e1878 @param integer|string $idOrKey @param integer $worklogId @param string $adjustEstimate @param string $newEstimate @param string $increaseBy @return \GuzzleHttp\Message\Response
[ "Deletes", "worklog", "for", "the", "issue", "by", "issue", "id", "or", "key", "and", "worklog", "id" ]
29f1ac3239f49d7e3ad658c1360c6ae582370a5d
https://github.com/AlexKovalevych/jira-api/blob/29f1ac3239f49d7e3ad658c1360c6ae582370a5d/src/Clients/IssueClient.php#L298-L313
train
congraphcms/core
Events/EventDispatcher.php
EventDispatcher.getListeners
public function getListeners($event) { $parentListeners = []; $wildcards = []; if( is_object($event) ) { $eventName = get_class($event); $parentListeners = $this->getParentListeners($event); } else { $eventName = $event; $wildcards = $this->getWildcardListeners($event); } if (!isset($this->sorted[$eventName])) { $this->sortListeners($eventName); } return array_merge($this->sorted[$eventName], $wildcards, $parentListeners); }
php
public function getListeners($event) { $parentListeners = []; $wildcards = []; if( is_object($event) ) { $eventName = get_class($event); $parentListeners = $this->getParentListeners($event); } else { $eventName = $event; $wildcards = $this->getWildcardListeners($event); } if (!isset($this->sorted[$eventName])) { $this->sortListeners($eventName); } return array_merge($this->sorted[$eventName], $wildcards, $parentListeners); }
[ "public", "function", "getListeners", "(", "$", "event", ")", "{", "$", "parentListeners", "=", "[", "]", ";", "$", "wildcards", "=", "[", "]", ";", "if", "(", "is_object", "(", "$", "event", ")", ")", "{", "$", "eventName", "=", "get_class", "(", "$", "event", ")", ";", "$", "parentListeners", "=", "$", "this", "->", "getParentListeners", "(", "$", "event", ")", ";", "}", "else", "{", "$", "eventName", "=", "$", "event", ";", "$", "wildcards", "=", "$", "this", "->", "getWildcardListeners", "(", "$", "event", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "sorted", "[", "$", "eventName", "]", ")", ")", "{", "$", "this", "->", "sortListeners", "(", "$", "eventName", ")", ";", "}", "return", "array_merge", "(", "$", "this", "->", "sorted", "[", "$", "eventName", "]", ",", "$", "wildcards", ",", "$", "parentListeners", ")", ";", "}" ]
Get all of the listeners for a given event. @param mixed $event @return array
[ "Get", "all", "of", "the", "listeners", "for", "a", "given", "event", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Events/EventDispatcher.php#L130-L151
train
congraphcms/core
Events/EventDispatcher.php
EventDispatcher.getParentListeners
protected function getParentListeners($event) { $parentListeners = []; foreach ($this->listeners as $key => $listeners) { if ($event instanceof $key) { $parentListeners = array_merge($parentListeners, $listeners); } } return $parentListeners; }
php
protected function getParentListeners($event) { $parentListeners = []; foreach ($this->listeners as $key => $listeners) { if ($event instanceof $key) { $parentListeners = array_merge($parentListeners, $listeners); } } return $parentListeners; }
[ "protected", "function", "getParentListeners", "(", "$", "event", ")", "{", "$", "parentListeners", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "listeners", "as", "$", "key", "=>", "$", "listeners", ")", "{", "if", "(", "$", "event", "instanceof", "$", "key", ")", "{", "$", "parentListeners", "=", "array_merge", "(", "$", "parentListeners", ",", "$", "listeners", ")", ";", "}", "}", "return", "$", "parentListeners", ";", "}" ]
Get the parent class or interface listeners for the event. @param object $event @return array
[ "Get", "the", "parent", "class", "or", "interface", "listeners", "for", "the", "event", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Events/EventDispatcher.php#L159-L172
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/LockedFields.php
LockedFields.unlockMyRecords
public function unlockMyRecords($tableName) { $results = $this->lockedRecordsByUser($tableName, Auth::user()->id); foreach($results as $result) { $this->unpopulateLockFields($result->id); } }
php
public function unlockMyRecords($tableName) { $results = $this->lockedRecordsByUser($tableName, Auth::user()->id); foreach($results as $result) { $this->unpopulateLockFields($result->id); } }
[ "public", "function", "unlockMyRecords", "(", "$", "tableName", ")", "{", "$", "results", "=", "$", "this", "->", "lockedRecordsByUser", "(", "$", "tableName", ",", "Auth", "::", "user", "(", ")", "->", "id", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "this", "->", "unpopulateLockFields", "(", "$", "result", "->", "id", ")", ";", "}", "}" ]
Unlock records belonging to the current user. @param string $tableName @return bool
[ "Unlock", "records", "belonging", "to", "the", "current", "user", "." ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/LockedFields.php#L52-L60
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/LockedFields.php
LockedFields.isLocked
public function isLocked($id) { $record = $this->model->findOrFail($id); if ($record->locked_by > 0) return true; return false; }
php
public function isLocked($id) { $record = $this->model->findOrFail($id); if ($record->locked_by > 0) return true; return false; }
[ "public", "function", "isLocked", "(", "$", "id", ")", "{", "$", "record", "=", "$", "this", "->", "model", "->", "findOrFail", "(", "$", "id", ")", ";", "if", "(", "$", "record", "->", "locked_by", ">", "0", ")", "return", "true", ";", "return", "false", ";", "}" ]
Is the record locked? "Locked" is defined as the 'locked_by' field being populated; that is,> 0 @param int $id @return bool
[ "Is", "the", "record", "locked?", "Locked", "is", "defined", "as", "the", "locked_by", "field", "being", "populated", ";", "that", "is", ">", "0" ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/LockedFields.php#L83-L90
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/LockedFields.php
LockedFields.populateLockFields
public function populateLockFields($id) { // $this->getSave($data); --> creates new record ;-( // $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or // update a parent row: a foreign key constraint fails ;-( // use the model, not the repository, to UPDATE $record = $this->model->findOrFail($id); $record->locked_by = Auth::user()->id; $record->locked_at = date('Y-m-d H:i:s'); return $record->save(); }
php
public function populateLockFields($id) { // $this->getSave($data); --> creates new record ;-( // $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or // update a parent row: a foreign key constraint fails ;-( // use the model, not the repository, to UPDATE $record = $this->model->findOrFail($id); $record->locked_by = Auth::user()->id; $record->locked_at = date('Y-m-d H:i:s'); return $record->save(); }
[ "public", "function", "populateLockFields", "(", "$", "id", ")", "{", "// $this->getSave($data); --> creates new record ;-(", "// $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or", "// update a parent row: a foreign key constraint fails ;-(", "// use the model, not the repository, to UPDATE", "$", "record", "=", "$", "this", "->", "model", "->", "findOrFail", "(", "$", "id", ")", ";", "$", "record", "->", "locked_by", "=", "Auth", "::", "user", "(", ")", "->", "id", ";", "$", "record", "->", "locked_at", "=", "date", "(", "'Y-m-d H:i:s'", ")", ";", "return", "$", "record", "->", "save", "(", ")", ";", "}" ]
Populate the locked_at and locked_by fields. By definition, this must be an UPDATE All that is needed is the ID @param int $id @return bool
[ "Populate", "the", "locked_at", "and", "locked_by", "fields", ".", "By", "definition", "this", "must", "be", "an", "UPDATE" ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/LockedFields.php#L102-L114
train
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/Repositories/Traits/LockedFields.php
LockedFields.unpopulateLockFields
public function unpopulateLockFields($id) { // $this->getSave($data); --> creates new record ;-( // $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or // update a parent row: a foreign key constraint fails ;-( // use the model, not the repository, to UPDATE $record = $this->model->findOrFail($id); // Locked by field allowed to be null $record->locked_by = null; $record->locked_at = null; return $record->save(); }
php
public function unpopulateLockFields($id) { // $this->getSave($data); --> creates new record ;-( // $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or // update a parent row: a foreign key constraint fails ;-( // use the model, not the repository, to UPDATE $record = $this->model->findOrFail($id); // Locked by field allowed to be null $record->locked_by = null; $record->locked_at = null; return $record->save(); }
[ "public", "function", "unpopulateLockFields", "(", "$", "id", ")", "{", "// $this->getSave($data); --> creates new record ;-(", "// $this->getUpdate($data); --> integrity constraint violation: 1451 Cannot delete or", "// update a parent row: a foreign key constraint fails ;-(", "// use the model, not the repository, to UPDATE", "$", "record", "=", "$", "this", "->", "model", "->", "findOrFail", "(", "$", "id", ")", ";", "// Locked by field allowed to be null", "$", "record", "->", "locked_by", "=", "null", ";", "$", "record", "->", "locked_at", "=", "null", ";", "return", "$", "record", "->", "save", "(", ")", ";", "}" ]
Un-populate the locked_at and locked_by fields. By definition, this must be an UPDATE All that is needed is the ID @param int $id @return mixed(?)
[ "Un", "-", "populate", "the", "locked_at", "and", "locked_by", "fields", ".", "By", "definition", "this", "must", "be", "an", "UPDATE" ]
05083be19645d52be86d8ba4f322773db348a11d
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/LockedFields.php#L126-L139
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.to
public static function to( $model, $target, $position ) { $instance = new static( $model, $target, $position ); return $instance->perform(); }
php
public static function to( $model, $target, $position ) { $instance = new static( $model, $target, $position ); return $instance->perform(); }
[ "public", "static", "function", "to", "(", "$", "model", ",", "$", "target", ",", "$", "position", ")", "{", "$", "instance", "=", "new", "static", "(", "$", "model", ",", "$", "target", ",", "$", "position", ")", ";", "return", "$", "instance", "->", "perform", "(", ")", ";", "}" ]
Easy static accessor for performing a move operation. @param NestedModel $model @param NestedModel|int $target @param string $position @return NestedModel
[ "Easy", "static", "accessor", "for", "performing", "a", "move", "operation", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L73-L78
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.perform
public function perform() { $this->guardAgainstImpossibleMove(); if ( $this->fireMoveEvent( 'moving' ) === false ) return $this->model; if ( $this->hasChange() ) { $self = $this; $this->model->getConnection()->transaction( function () use ( $self ) { $self->updateStructure(); } ); $this->target->reload(); $this->model->setDepthWithSubtree(); $this->model->reload(); } $this->fireMoveEvent( 'moved', false ); return $this->model; }
php
public function perform() { $this->guardAgainstImpossibleMove(); if ( $this->fireMoveEvent( 'moving' ) === false ) return $this->model; if ( $this->hasChange() ) { $self = $this; $this->model->getConnection()->transaction( function () use ( $self ) { $self->updateStructure(); } ); $this->target->reload(); $this->model->setDepthWithSubtree(); $this->model->reload(); } $this->fireMoveEvent( 'moved', false ); return $this->model; }
[ "public", "function", "perform", "(", ")", "{", "$", "this", "->", "guardAgainstImpossibleMove", "(", ")", ";", "if", "(", "$", "this", "->", "fireMoveEvent", "(", "'moving'", ")", "===", "false", ")", "return", "$", "this", "->", "model", ";", "if", "(", "$", "this", "->", "hasChange", "(", ")", ")", "{", "$", "self", "=", "$", "this", ";", "$", "this", "->", "model", "->", "getConnection", "(", ")", "->", "transaction", "(", "function", "(", ")", "use", "(", "$", "self", ")", "{", "$", "self", "->", "updateStructure", "(", ")", ";", "}", ")", ";", "$", "this", "->", "target", "->", "reload", "(", ")", ";", "$", "this", "->", "model", "->", "setDepthWithSubtree", "(", ")", ";", "$", "this", "->", "model", "->", "reload", "(", ")", ";", "}", "$", "this", "->", "fireMoveEvent", "(", "'moved'", ",", "false", ")", ";", "return", "$", "this", "->", "model", ";", "}" ]
Perform the move operation. @return NestedModel
[ "Perform", "the", "move", "operation", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L85-L111
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.resolveNode
protected function resolveNode( $model ) { if ( $model instanceof NestedModel ) return $model->reload(); return $this->model->newNestedSetQuery()->find( $model ); }
php
protected function resolveNode( $model ) { if ( $model instanceof NestedModel ) return $model->reload(); return $this->model->newNestedSetQuery()->find( $model ); }
[ "protected", "function", "resolveNode", "(", "$", "model", ")", "{", "if", "(", "$", "model", "instanceof", "NestedModel", ")", "return", "$", "model", "->", "reload", "(", ")", ";", "return", "$", "this", "->", "model", "->", "newNestedSetQuery", "(", ")", "->", "find", "(", "$", "model", ")", ";", "}" ]
Resolves suplied node. Basically returns the node unchanged if supplied parameter is an instance of NestedModel. Otherwise it will try to find the node in the database. @param NestedModel|int @return NestedModel
[ "Resolves", "suplied", "node", ".", "Basically", "returns", "the", "node", "unchanged", "if", "supplied", "parameter", "is", "an", "instance", "of", "NestedModel", ".", "Otherwise", "it", "will", "try", "to", "find", "the", "node", "in", "the", "database", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L176-L182
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.guardAgainstImpossibleMove
protected function guardAgainstImpossibleMove() { if ( !$this->model->exists ) throw new MoveNotPossibleException( 'A new node cannot be moved.' ); if ( array_search( $this->position, ['child', 'left', 'right', 'root'] ) === false ) throw new MoveNotPossibleException( "Position should be one of ['child', 'left', 'right'] but is {$this->position}." ); if ( !$this->promotingToRoot() ) { if ( is_null( $this->target ) ) { if ( $this->position === 'left' || $this->position === 'right' ) throw new MoveNotPossibleException( "Could not resolve target node. This node cannot move any further to the {$this->position}." ); else throw new MoveNotPossibleException( 'Could not resolve target node.' ); } if ( $this->model->equals( $this->target ) ) throw new MoveNotPossibleException( 'A node cannot be moved to itself.' ); if ( $this->target->insideSubtree( $this->model ) ) throw new MoveNotPossibleException( 'A node cannot be moved to a descendant of itself (inside moved tree).' ); if ( !$this->model->inSameScope( $this->target ) ) throw new MoveNotPossibleException( 'A node cannot be moved to a different scope.' ); } }
php
protected function guardAgainstImpossibleMove() { if ( !$this->model->exists ) throw new MoveNotPossibleException( 'A new node cannot be moved.' ); if ( array_search( $this->position, ['child', 'left', 'right', 'root'] ) === false ) throw new MoveNotPossibleException( "Position should be one of ['child', 'left', 'right'] but is {$this->position}." ); if ( !$this->promotingToRoot() ) { if ( is_null( $this->target ) ) { if ( $this->position === 'left' || $this->position === 'right' ) throw new MoveNotPossibleException( "Could not resolve target node. This node cannot move any further to the {$this->position}." ); else throw new MoveNotPossibleException( 'Could not resolve target node.' ); } if ( $this->model->equals( $this->target ) ) throw new MoveNotPossibleException( 'A node cannot be moved to itself.' ); if ( $this->target->insideSubtree( $this->model ) ) throw new MoveNotPossibleException( 'A node cannot be moved to a descendant of itself (inside moved tree).' ); if ( !$this->model->inSameScope( $this->target ) ) throw new MoveNotPossibleException( 'A node cannot be moved to a different scope.' ); } }
[ "protected", "function", "guardAgainstImpossibleMove", "(", ")", "{", "if", "(", "!", "$", "this", "->", "model", "->", "exists", ")", "throw", "new", "MoveNotPossibleException", "(", "'A new node cannot be moved.'", ")", ";", "if", "(", "array_search", "(", "$", "this", "->", "position", ",", "[", "'child'", ",", "'left'", ",", "'right'", ",", "'root'", "]", ")", "===", "false", ")", "throw", "new", "MoveNotPossibleException", "(", "\"Position should be one of ['child', 'left', 'right'] but is {$this->position}.\"", ")", ";", "if", "(", "!", "$", "this", "->", "promotingToRoot", "(", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "target", ")", ")", "{", "if", "(", "$", "this", "->", "position", "===", "'left'", "||", "$", "this", "->", "position", "===", "'right'", ")", "throw", "new", "MoveNotPossibleException", "(", "\"Could not resolve target node. This node cannot move any further to the {$this->position}.\"", ")", ";", "else", "throw", "new", "MoveNotPossibleException", "(", "'Could not resolve target node.'", ")", ";", "}", "if", "(", "$", "this", "->", "model", "->", "equals", "(", "$", "this", "->", "target", ")", ")", "throw", "new", "MoveNotPossibleException", "(", "'A node cannot be moved to itself.'", ")", ";", "if", "(", "$", "this", "->", "target", "->", "insideSubtree", "(", "$", "this", "->", "model", ")", ")", "throw", "new", "MoveNotPossibleException", "(", "'A node cannot be moved to a descendant of itself (inside moved tree).'", ")", ";", "if", "(", "!", "$", "this", "->", "model", "->", "inSameScope", "(", "$", "this", "->", "target", ")", ")", "throw", "new", "MoveNotPossibleException", "(", "'A node cannot be moved to a different scope.'", ")", ";", "}", "}" ]
Check wether the current move is possible and if not, rais an exception. @return void
[ "Check", "wether", "the", "current", "move", "is", "possible", "and", "if", "not", "rais", "an", "exception", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L189-L216
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.bound1
protected function bound1() { if ( !is_null( $this->_bound1 ) ) return $this->_bound1; switch ( $this->position ) { case 'child': $this->_bound1 = $this->target->getRight(); break; case 'left': $this->_bound1 = $this->target->getLeft(); break; case 'right': $this->_bound1 = $this->target->getRight() + 1; break; case 'root': $this->_bound1 = $this->model->newNestedSetQuery()->max( $this->model->getRightColumnName() ) + 1; break; } $this->_bound1 = ( ( $this->_bound1 > $this->model->getRight() ) ? $this->_bound1 - 1 : $this->_bound1 ); return $this->_bound1; }
php
protected function bound1() { if ( !is_null( $this->_bound1 ) ) return $this->_bound1; switch ( $this->position ) { case 'child': $this->_bound1 = $this->target->getRight(); break; case 'left': $this->_bound1 = $this->target->getLeft(); break; case 'right': $this->_bound1 = $this->target->getRight() + 1; break; case 'root': $this->_bound1 = $this->model->newNestedSetQuery()->max( $this->model->getRightColumnName() ) + 1; break; } $this->_bound1 = ( ( $this->_bound1 > $this->model->getRight() ) ? $this->_bound1 - 1 : $this->_bound1 ); return $this->_bound1; }
[ "protected", "function", "bound1", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "_bound1", ")", ")", "return", "$", "this", "->", "_bound1", ";", "switch", "(", "$", "this", "->", "position", ")", "{", "case", "'child'", ":", "$", "this", "->", "_bound1", "=", "$", "this", "->", "target", "->", "getRight", "(", ")", ";", "break", ";", "case", "'left'", ":", "$", "this", "->", "_bound1", "=", "$", "this", "->", "target", "->", "getLeft", "(", ")", ";", "break", ";", "case", "'right'", ":", "$", "this", "->", "_bound1", "=", "$", "this", "->", "target", "->", "getRight", "(", ")", "+", "1", ";", "break", ";", "case", "'root'", ":", "$", "this", "->", "_bound1", "=", "$", "this", "->", "model", "->", "newNestedSetQuery", "(", ")", "->", "max", "(", "$", "this", "->", "model", "->", "getRightColumnName", "(", ")", ")", "+", "1", ";", "break", ";", "}", "$", "this", "->", "_bound1", "=", "(", "(", "$", "this", "->", "_bound1", ">", "$", "this", "->", "model", "->", "getRight", "(", ")", ")", "?", "$", "this", "->", "_bound1", "-", "1", ":", "$", "this", "->", "_bound1", ")", ";", "return", "$", "this", "->", "_bound1", ";", "}" ]
Computes the boundary. @return int
[ "Computes", "the", "boundary", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L223-L250
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.boundaries
protected function boundaries() { if ( !is_null( $this->_boundaries ) ) return $this->_boundaries; // we have defined the boundaries of two non-overlapping intervals, // so sorting puts both the intervals and their boundaries in order $this->_boundaries = [ $this->model->getLeft(), $this->model->getRight(), $this->bound1(), $this->bound2() ]; sort( $this->_boundaries ); return $this->_boundaries; }
php
protected function boundaries() { if ( !is_null( $this->_boundaries ) ) return $this->_boundaries; // we have defined the boundaries of two non-overlapping intervals, // so sorting puts both the intervals and their boundaries in order $this->_boundaries = [ $this->model->getLeft(), $this->model->getRight(), $this->bound1(), $this->bound2() ]; sort( $this->_boundaries ); return $this->_boundaries; }
[ "protected", "function", "boundaries", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "_boundaries", ")", ")", "return", "$", "this", "->", "_boundaries", ";", "// we have defined the boundaries of two non-overlapping intervals,", "// so sorting puts both the intervals and their boundaries in order", "$", "this", "->", "_boundaries", "=", "[", "$", "this", "->", "model", "->", "getLeft", "(", ")", ",", "$", "this", "->", "model", "->", "getRight", "(", ")", ",", "$", "this", "->", "bound1", "(", ")", ",", "$", "this", "->", "bound2", "(", ")", "]", ";", "sort", "(", "$", "this", "->", "_boundaries", ")", ";", "return", "$", "this", "->", "_boundaries", ";", "}" ]
Computes the boundaries array. @return array
[ "Computes", "the", "boundaries", "array", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L273-L289
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.parentId
protected function parentId() { switch ( $this->position ) { case 'root': return null; case 'child': return $this->target->getKey(); default: return $this->target->getParentId(); } }
php
protected function parentId() { switch ( $this->position ) { case 'root': return null; case 'child': return $this->target->getKey(); default: return $this->target->getParentId(); } }
[ "protected", "function", "parentId", "(", ")", "{", "switch", "(", "$", "this", "->", "position", ")", "{", "case", "'root'", ":", "return", "null", ";", "case", "'child'", ":", "return", "$", "this", "->", "target", "->", "getKey", "(", ")", ";", "default", ":", "return", "$", "this", "->", "target", "->", "getParentId", "(", ")", ";", "}", "}" ]
Computes the new parent id for the node being moved. @return int
[ "Computes", "the", "new", "parent", "id", "for", "the", "node", "being", "moved", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L296-L309
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.hasChange
protected function hasChange() { return !( $this->bound1() == $this->model->getRight() || $this->bound1() == $this->model->getLeft() ); }
php
protected function hasChange() { return !( $this->bound1() == $this->model->getRight() || $this->bound1() == $this->model->getLeft() ); }
[ "protected", "function", "hasChange", "(", ")", "{", "return", "!", "(", "$", "this", "->", "bound1", "(", ")", "==", "$", "this", "->", "model", "->", "getRight", "(", ")", "||", "$", "this", "->", "bound1", "(", ")", "==", "$", "this", "->", "model", "->", "getLeft", "(", ")", ")", ";", "}" ]
Check wether there should be changes in the downward tree structure. @return boolean
[ "Check", "wether", "there", "should", "be", "changes", "in", "the", "downward", "tree", "structure", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L316-L319
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.fireMoveEvent
protected function fireMoveEvent( $event, $halt = true ) { // Basically the same as \Illuminate\Database\Eloquent\Model->fireModelEvent // but we relay the event into the node instance. $event = "eloquent.{$event}: " . get_class( $this->model ); $method = $halt ? 'until' : 'fire'; Hooks::trigger( $event, ['model' => $this->model] ); }
php
protected function fireMoveEvent( $event, $halt = true ) { // Basically the same as \Illuminate\Database\Eloquent\Model->fireModelEvent // but we relay the event into the node instance. $event = "eloquent.{$event}: " . get_class( $this->model ); $method = $halt ? 'until' : 'fire'; Hooks::trigger( $event, ['model' => $this->model] ); }
[ "protected", "function", "fireMoveEvent", "(", "$", "event", ",", "$", "halt", "=", "true", ")", "{", "// Basically the same as \\Illuminate\\Database\\Eloquent\\Model->fireModelEvent", "// but we relay the event into the node instance.", "$", "event", "=", "\"eloquent.{$event}: \"", ".", "get_class", "(", "$", "this", "->", "model", ")", ";", "$", "method", "=", "$", "halt", "?", "'until'", ":", "'fire'", ";", "Hooks", "::", "trigger", "(", "$", "event", ",", "[", "'model'", "=>", "$", "this", "->", "model", "]", ")", ";", "}" ]
Fire the given move event for the model. @param string $event @param bool $halt @return mixed
[ "Fire", "the", "given", "move", "event", "for", "the", "model", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L338-L347
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Move.php
Move.applyLockBetween
protected function applyLockBetween( $lft, $rgt ) { $this->model->newQuery()->where( $this->model->getLeftColumnName(), '>=', $lft )->where( $this->model->getRightColumnName(), '<=', $rgt )->select( $this->model->getKeyName() )->lockForUpdate()->get(); }
php
protected function applyLockBetween( $lft, $rgt ) { $this->model->newQuery()->where( $this->model->getLeftColumnName(), '>=', $lft )->where( $this->model->getRightColumnName(), '<=', $rgt )->select( $this->model->getKeyName() )->lockForUpdate()->get(); }
[ "protected", "function", "applyLockBetween", "(", "$", "lft", ",", "$", "rgt", ")", "{", "$", "this", "->", "model", "->", "newQuery", "(", ")", "->", "where", "(", "$", "this", "->", "model", "->", "getLeftColumnName", "(", ")", ",", "'>='", ",", "$", "lft", ")", "->", "where", "(", "$", "this", "->", "model", "->", "getRightColumnName", "(", ")", ",", "'<='", ",", "$", "rgt", ")", "->", "select", "(", "$", "this", "->", "model", "->", "getKeyName", "(", ")", ")", "->", "lockForUpdate", "(", ")", "->", "get", "(", ")", ";", "}" ]
Applies a lock to the rows between the supplied index boundaries. @param int $lft @param int $rgt @return void
[ "Applies", "a", "lock", "to", "the", "rows", "between", "the", "supplied", "index", "boundaries", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Move.php#L374-L377
train
CampaignChain/security-authentication-client-oauth
EntityService/TokenService.php
TokenService.cleanUpUnassignedTokens
public function cleanUpUnassignedTokens(array $tokens) { $this->em->clear(); foreach ($tokens as $token) { $token = $this->em->merge($token); $this->em->remove($token); } $this->em->flush(); }
php
public function cleanUpUnassignedTokens(array $tokens) { $this->em->clear(); foreach ($tokens as $token) { $token = $this->em->merge($token); $this->em->remove($token); } $this->em->flush(); }
[ "public", "function", "cleanUpUnassignedTokens", "(", "array", "$", "tokens", ")", "{", "$", "this", "->", "em", "->", "clear", "(", ")", ";", "foreach", "(", "$", "tokens", "as", "$", "token", ")", "{", "$", "token", "=", "$", "this", "->", "em", "->", "merge", "(", "$", "token", ")", ";", "$", "this", "->", "em", "->", "remove", "(", "$", "token", ")", ";", "}", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}" ]
Removes the not assigned tokens. @param Token[] $tokens
[ "Removes", "the", "not", "assigned", "tokens", "." ]
06800ccd0ee6b5ca9f53b85146228467ff6a7529
https://github.com/CampaignChain/security-authentication-client-oauth/blob/06800ccd0ee6b5ca9f53b85146228467ff6a7529/EntityService/TokenService.php#L199-L208
train
danielgp/common-lib
source/DomBasicComponentsByDanielGP.php
DomBasicComponentsByDanielGP.setCleanUrl
protected function setCleanUrl($urlString) { $arrayToReplace = [ '&#038;' => '&amp;', '&' => '&amp;', '&amp;amp;' => '&amp;', ' ' => '%20', ]; $kys = array_keys($arrayToReplace); $vls = array_values($arrayToReplace); return str_replace($kys, $vls, filter_var($urlString, FILTER_SANITIZE_URL)); }
php
protected function setCleanUrl($urlString) { $arrayToReplace = [ '&#038;' => '&amp;', '&' => '&amp;', '&amp;amp;' => '&amp;', ' ' => '%20', ]; $kys = array_keys($arrayToReplace); $vls = array_values($arrayToReplace); return str_replace($kys, $vls, filter_var($urlString, FILTER_SANITIZE_URL)); }
[ "protected", "function", "setCleanUrl", "(", "$", "urlString", ")", "{", "$", "arrayToReplace", "=", "[", "'&#038;'", "=>", "'&amp;'", ",", "'&'", "=>", "'&amp;'", ",", "'&amp;amp;'", "=>", "'&amp;'", ",", "' '", "=>", "'%20'", ",", "]", ";", "$", "kys", "=", "array_keys", "(", "$", "arrayToReplace", ")", ";", "$", "vls", "=", "array_values", "(", "$", "arrayToReplace", ")", ";", "return", "str_replace", "(", "$", "kys", ",", "$", "vls", ",", "filter_var", "(", "$", "urlString", ",", "FILTER_SANITIZE_URL", ")", ")", ";", "}" ]
Cleans a string for certain internal rules @param string $urlString @return string
[ "Cleans", "a", "string", "for", "certain", "internal", "rules" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomBasicComponentsByDanielGP.php#L85-L96
train
danielgp/common-lib
source/DomBasicComponentsByDanielGP.php
DomBasicComponentsByDanielGP.setFeedbackModern
protected function setFeedbackModern($sType, $sTitle, $sMsg, $skipBr = false) { if ($sTitle == 'light') { return $sMsg; } $legend = $this->setStringIntoTag($sTitle, 'legend', ['style' => $this->setFeedbackStyle($sType)]); return implode('', [ ($skipBr ? '' : '<br/>'), $this->setStringIntoTag($legend . $sMsg, 'fieldset', ['style' => $this->setFeedbackStyle($sType)]), ]); }
php
protected function setFeedbackModern($sType, $sTitle, $sMsg, $skipBr = false) { if ($sTitle == 'light') { return $sMsg; } $legend = $this->setStringIntoTag($sTitle, 'legend', ['style' => $this->setFeedbackStyle($sType)]); return implode('', [ ($skipBr ? '' : '<br/>'), $this->setStringIntoTag($legend . $sMsg, 'fieldset', ['style' => $this->setFeedbackStyle($sType)]), ]); }
[ "protected", "function", "setFeedbackModern", "(", "$", "sType", ",", "$", "sTitle", ",", "$", "sMsg", ",", "$", "skipBr", "=", "false", ")", "{", "if", "(", "$", "sTitle", "==", "'light'", ")", "{", "return", "$", "sMsg", ";", "}", "$", "legend", "=", "$", "this", "->", "setStringIntoTag", "(", "$", "sTitle", ",", "'legend'", ",", "[", "'style'", "=>", "$", "this", "->", "setFeedbackStyle", "(", "$", "sType", ")", "]", ")", ";", "return", "implode", "(", "''", ",", "[", "(", "$", "skipBr", "?", "''", ":", "'<br/>'", ")", ",", "$", "this", "->", "setStringIntoTag", "(", "$", "legend", ".", "$", "sMsg", ",", "'fieldset'", ",", "[", "'style'", "=>", "$", "this", "->", "setFeedbackStyle", "(", "$", "sType", ")", "]", ")", ",", "]", ")", ";", "}" ]
Builds a structured modern message @param string $sType @param string $sTitle @param string $sMsg @param boolean $skipBr
[ "Builds", "a", "structured", "modern", "message" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomBasicComponentsByDanielGP.php#L123-L133
train
danielgp/common-lib
source/DomBasicComponentsByDanielGP.php
DomBasicComponentsByDanielGP.setHeaderNoCache
protected function setHeaderNoCache($contentType = 'application/json') { header("Content-Type: " . $contentType . "; charset=utf-8"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); }
php
protected function setHeaderNoCache($contentType = 'application/json') { header("Content-Type: " . $contentType . "; charset=utf-8"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); }
[ "protected", "function", "setHeaderNoCache", "(", "$", "contentType", "=", "'application/json'", ")", "{", "header", "(", "\"Content-Type: \"", ".", "$", "contentType", ".", "\"; charset=utf-8\"", ")", ";", "header", "(", "\"Last-Modified: \"", ".", "gmdate", "(", "\"D, d M Y H:i:s\"", ")", ".", "\" GMT\"", ")", ";", "header", "(", "\"Cache-Control: no-store, no-cache, must-revalidate\"", ")", ";", "header", "(", "\"Cache-Control: post-check=0, pre-check=0\"", ",", "false", ")", ";", "header", "(", "\"Pragma: no-cache\"", ")", ";", "}" ]
Sets the no-cache header
[ "Sets", "the", "no", "-", "cache", "header" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomBasicComponentsByDanielGP.php#L206-L213
train
danielgp/common-lib
source/DomBasicComponentsByDanielGP.php
DomBasicComponentsByDanielGP.setStringIntoShortTag
protected function setStringIntoShortTag($sTag, $features = null) { return '<' . $sTag . $this->buildAttributesForTag($features) . (isset($features['dont_close']) ? '' : '/') . '>'; }
php
protected function setStringIntoShortTag($sTag, $features = null) { return '<' . $sTag . $this->buildAttributesForTag($features) . (isset($features['dont_close']) ? '' : '/') . '>'; }
[ "protected", "function", "setStringIntoShortTag", "(", "$", "sTag", ",", "$", "features", "=", "null", ")", "{", "return", "'<'", ".", "$", "sTag", ".", "$", "this", "->", "buildAttributesForTag", "(", "$", "features", ")", ".", "(", "isset", "(", "$", "features", "[", "'dont_close'", "]", ")", "?", "''", ":", "'/'", ")", ".", "'>'", ";", "}" ]
Puts a given string into a specific short tag @param string $sTag @param array $features @return string
[ "Puts", "a", "given", "string", "into", "a", "specific", "short", "tag" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomBasicComponentsByDanielGP.php#L222-L226
train
danielgp/common-lib
source/DomBasicComponentsByDanielGP.php
DomBasicComponentsByDanielGP.setStringIntoTag
protected function setStringIntoTag($sString, $sTag, $features = null) { return '<' . $sTag . $this->buildAttributesForTag($features) . '>' . $sString . '</' . $sTag . '>'; }
php
protected function setStringIntoTag($sString, $sTag, $features = null) { return '<' . $sTag . $this->buildAttributesForTag($features) . '>' . $sString . '</' . $sTag . '>'; }
[ "protected", "function", "setStringIntoTag", "(", "$", "sString", ",", "$", "sTag", ",", "$", "features", "=", "null", ")", "{", "return", "'<'", ".", "$", "sTag", ".", "$", "this", "->", "buildAttributesForTag", "(", "$", "features", ")", ".", "'>'", ".", "$", "sString", ".", "'</'", ".", "$", "sTag", ".", "'>'", ";", "}" ]
Puts a given string into a specific tag @param string $sString @param string $sTag @param array $features @return string
[ "Puts", "a", "given", "string", "into", "a", "specific", "tag" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomBasicComponentsByDanielGP.php#L236-L239
train
SugiPHP/Filter
Filter.php
Filter.int
public function int($value, $min = false, $max = false, $default = false) { $options = array("options" => array()); if (isset($default)) { $options["options"]["default"] = $default; } if (is_numeric($min)) { $options["options"]["min_range"] = $min; } if (is_numeric($max)) { $options["options"]["max_range"] = $max; } // We really DO NOT need to validate user inputs like 010 or 0x10 // so this is not needed: $options["flags"] = FILTER_FLAG_ALLOW_OCTAL | FILTER_FLAG_ALLOW_HEX; // If in the code we use something like $this->int(010) this is the // same as $this->int(8) - so it will pass and return 8 // But if we read it from user input, a file etc, it should fail by // default. Example Right padding some currencies like 0010.00 USD return filter_var($value, FILTER_VALIDATE_INT, $options); }
php
public function int($value, $min = false, $max = false, $default = false) { $options = array("options" => array()); if (isset($default)) { $options["options"]["default"] = $default; } if (is_numeric($min)) { $options["options"]["min_range"] = $min; } if (is_numeric($max)) { $options["options"]["max_range"] = $max; } // We really DO NOT need to validate user inputs like 010 or 0x10 // so this is not needed: $options["flags"] = FILTER_FLAG_ALLOW_OCTAL | FILTER_FLAG_ALLOW_HEX; // If in the code we use something like $this->int(010) this is the // same as $this->int(8) - so it will pass and return 8 // But if we read it from user input, a file etc, it should fail by // default. Example Right padding some currencies like 0010.00 USD return filter_var($value, FILTER_VALIDATE_INT, $options); }
[ "public", "function", "int", "(", "$", "value", ",", "$", "min", "=", "false", ",", "$", "max", "=", "false", ",", "$", "default", "=", "false", ")", "{", "$", "options", "=", "array", "(", "\"options\"", "=>", "array", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "default", ")", ")", "{", "$", "options", "[", "\"options\"", "]", "[", "\"default\"", "]", "=", "$", "default", ";", "}", "if", "(", "is_numeric", "(", "$", "min", ")", ")", "{", "$", "options", "[", "\"options\"", "]", "[", "\"min_range\"", "]", "=", "$", "min", ";", "}", "if", "(", "is_numeric", "(", "$", "max", ")", ")", "{", "$", "options", "[", "\"options\"", "]", "[", "\"max_range\"", "]", "=", "$", "max", ";", "}", "// We really DO NOT need to validate user inputs like 010 or 0x10", "// so this is not needed: $options[\"flags\"] = FILTER_FLAG_ALLOW_OCTAL | FILTER_FLAG_ALLOW_HEX;", "// If in the code we use something like $this->int(010) this is the", "// same as $this->int(8) - so it will pass and return 8", "// But if we read it from user input, a file etc, it should fail by", "// default. Example Right padding some currencies like 0010.00 USD", "return", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_INT", ",", "$", "options", ")", ";", "}" ]
Validates integer value. @param mixed $value Integer or string @param integer $min @param integer $max @param mixed $default What to be returned if the filter fails @return mixed
[ "Validates", "integer", "value", "." ]
1fc455efc5e3405c4186c2c997aee81eeb1eb59c
https://github.com/SugiPHP/Filter/blob/1fc455efc5e3405c4186c2c997aee81eeb1eb59c/Filter.php#L35-L55
train
SugiPHP/Filter
Filter.php
Filter.str
public function str($value, $minLength = 0, $maxLength = false, $default = false) { $value = trim($value); if ((!empty($minLength) && (mb_strlen($value, $this->encoding) < $minLength)) || (!empty($maxLength) && (mb_strlen($value, $this->encoding) > $maxLength)) ) { return $default; } return (string) $value; }
php
public function str($value, $minLength = 0, $maxLength = false, $default = false) { $value = trim($value); if ((!empty($minLength) && (mb_strlen($value, $this->encoding) < $minLength)) || (!empty($maxLength) && (mb_strlen($value, $this->encoding) > $maxLength)) ) { return $default; } return (string) $value; }
[ "public", "function", "str", "(", "$", "value", ",", "$", "minLength", "=", "0", ",", "$", "maxLength", "=", "false", ",", "$", "default", "=", "false", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "if", "(", "(", "!", "empty", "(", "$", "minLength", ")", "&&", "(", "mb_strlen", "(", "$", "value", ",", "$", "this", "->", "encoding", ")", "<", "$", "minLength", ")", ")", "||", "(", "!", "empty", "(", "$", "maxLength", ")", "&&", "(", "mb_strlen", "(", "$", "value", ",", "$", "this", "->", "encoding", ")", ">", "$", "maxLength", ")", ")", ")", "{", "return", "$", "default", ";", "}", "return", "(", "string", ")", "$", "value", ";", "}" ]
Validates string value. @param string $value @param integer $minLength @param mixed $maxLength @param mixed $default @return mixed
[ "Validates", "string", "value", "." ]
1fc455efc5e3405c4186c2c997aee81eeb1eb59c
https://github.com/SugiPHP/Filter/blob/1fc455efc5e3405c4186c2c997aee81eeb1eb59c/Filter.php#L67-L77
train
SugiPHP/Filter
Filter.php
Filter.plain
public function plain($value, $minLength = 0, $maxLength = false, $default = false) { $value = strip_tags($value); return $this->str($value, $minLength, $maxLength, $default); }
php
public function plain($value, $minLength = 0, $maxLength = false, $default = false) { $value = strip_tags($value); return $this->str($value, $minLength, $maxLength, $default); }
[ "public", "function", "plain", "(", "$", "value", ",", "$", "minLength", "=", "0", ",", "$", "maxLength", "=", "false", ",", "$", "default", "=", "false", ")", "{", "$", "value", "=", "strip_tags", "(", "$", "value", ")", ";", "return", "$", "this", "->", "str", "(", "$", "value", ",", "$", "minLength", ",", "$", "maxLength", ",", "$", "default", ")", ";", "}" ]
Validates string and is removing tags from it. @param string $value @param integer $minLength @param mixed $maxLength @param mixed $default @return mixed
[ "Validates", "string", "and", "is", "removing", "tags", "from", "it", "." ]
1fc455efc5e3405c4186c2c997aee81eeb1eb59c
https://github.com/SugiPHP/Filter/blob/1fc455efc5e3405c4186c2c997aee81eeb1eb59c/Filter.php#L89-L94
train
SugiPHP/Filter
Filter.php
Filter.email
public function email($value, $default = false, $checkMxRecord = false) { if (!$value = filter_var($value, FILTER_VALIDATE_EMAIL)) { return $default; } $dom = explode("@", $value); $dom = array_pop($dom); if (!$this->url("http://$dom")) { return $default; } return (!$checkMxRecord || checkdnsrr($dom, "MX")) ? $value : $default; }
php
public function email($value, $default = false, $checkMxRecord = false) { if (!$value = filter_var($value, FILTER_VALIDATE_EMAIL)) { return $default; } $dom = explode("@", $value); $dom = array_pop($dom); if (!$this->url("http://$dom")) { return $default; } return (!$checkMxRecord || checkdnsrr($dom, "MX")) ? $value : $default; }
[ "public", "function", "email", "(", "$", "value", ",", "$", "default", "=", "false", ",", "$", "checkMxRecord", "=", "false", ")", "{", "if", "(", "!", "$", "value", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_EMAIL", ")", ")", "{", "return", "$", "default", ";", "}", "$", "dom", "=", "explode", "(", "\"@\"", ",", "$", "value", ")", ";", "$", "dom", "=", "array_pop", "(", "$", "dom", ")", ";", "if", "(", "!", "$", "this", "->", "url", "(", "\"http://$dom\"", ")", ")", "{", "return", "$", "default", ";", "}", "return", "(", "!", "$", "checkMxRecord", "||", "checkdnsrr", "(", "$", "dom", ",", "\"MX\"", ")", ")", "?", "$", "value", ":", "$", "default", ";", "}" ]
Validates email. @param string $value @param mixed $default - default value to return on validation failure @param boolean $checkMxRecord - check existence of MX record. If check fails default value will be returned. @return mixed
[ "Validates", "email", "." ]
1fc455efc5e3405c4186c2c997aee81eeb1eb59c
https://github.com/SugiPHP/Filter/blob/1fc455efc5e3405c4186c2c997aee81eeb1eb59c/Filter.php#L132-L144
train
railken/lem
src/Attributes/TextAttribute.php
TextAttribute.setRequired
public function setRequired(bool $required): BaseAttribute { parent::setRequired($required); if ($this->getMinLength() === 0) { $this->setMinLength(1); } return $this; }
php
public function setRequired(bool $required): BaseAttribute { parent::setRequired($required); if ($this->getMinLength() === 0) { $this->setMinLength(1); } return $this; }
[ "public", "function", "setRequired", "(", "bool", "$", "required", ")", ":", "BaseAttribute", "{", "parent", "::", "setRequired", "(", "$", "required", ")", ";", "if", "(", "$", "this", "->", "getMinLength", "(", ")", "===", "0", ")", "{", "$", "this", "->", "setMinLength", "(", "1", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set Required. @param bool $required @return $this
[ "Set", "Required", "." ]
cff1efcd090a9504b2faf5594121885786dea67a
https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Attributes/TextAttribute.php#L99-L108
train
fridge-project/dbal
src/Fridge/DBAL/Schema/ForeignKey.php
ForeignKey.setLocalColumnNames
public function setLocalColumnNames(array $localColumnNames) { $this->localColumnNames = array(); foreach ($localColumnNames as $localColumnName) { $this->addLocalColumnName($localColumnName); } }
php
public function setLocalColumnNames(array $localColumnNames) { $this->localColumnNames = array(); foreach ($localColumnNames as $localColumnName) { $this->addLocalColumnName($localColumnName); } }
[ "public", "function", "setLocalColumnNames", "(", "array", "$", "localColumnNames", ")", "{", "$", "this", "->", "localColumnNames", "=", "array", "(", ")", ";", "foreach", "(", "$", "localColumnNames", "as", "$", "localColumnName", ")", "{", "$", "this", "->", "addLocalColumnName", "(", "$", "localColumnName", ")", ";", "}", "}" ]
Sets the local column names. @param array $localColumnNames The local column names.
[ "Sets", "the", "local", "column", "names", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/ForeignKey.php#L96-L103
train
fridge-project/dbal
src/Fridge/DBAL/Schema/ForeignKey.php
ForeignKey.addLocalColumnName
public function addLocalColumnName($localColumnName) { if (!is_string($localColumnName) || (strlen($localColumnName) <= 0)) { throw SchemaException::invalidForeignKeyLocalColumnName($this->getName()); } $this->localColumnNames[] = $localColumnName; }
php
public function addLocalColumnName($localColumnName) { if (!is_string($localColumnName) || (strlen($localColumnName) <= 0)) { throw SchemaException::invalidForeignKeyLocalColumnName($this->getName()); } $this->localColumnNames[] = $localColumnName; }
[ "public", "function", "addLocalColumnName", "(", "$", "localColumnName", ")", "{", "if", "(", "!", "is_string", "(", "$", "localColumnName", ")", "||", "(", "strlen", "(", "$", "localColumnName", ")", "<=", "0", ")", ")", "{", "throw", "SchemaException", "::", "invalidForeignKeyLocalColumnName", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "localColumnNames", "[", "]", "=", "$", "localColumnName", ";", "}" ]
Adds a local column name to the foreign key. @param string $localColumnName The local column name to add. @throws \Fridge\DBAL\Exception\SchemaException If the local column name is not a valid string.
[ "Adds", "a", "local", "column", "name", "to", "the", "foreign", "key", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/ForeignKey.php#L112-L119
train
fridge-project/dbal
src/Fridge/DBAL/Schema/ForeignKey.php
ForeignKey.setForeignTableName
public function setForeignTableName($foreignTableName) { if (!is_string($foreignTableName) || (strlen($foreignTableName) <= 0)) { throw SchemaException::invalidForeignKeyForeignTableName($this->getName()); } $this->foreignTableName = $foreignTableName; }
php
public function setForeignTableName($foreignTableName) { if (!is_string($foreignTableName) || (strlen($foreignTableName) <= 0)) { throw SchemaException::invalidForeignKeyForeignTableName($this->getName()); } $this->foreignTableName = $foreignTableName; }
[ "public", "function", "setForeignTableName", "(", "$", "foreignTableName", ")", "{", "if", "(", "!", "is_string", "(", "$", "foreignTableName", ")", "||", "(", "strlen", "(", "$", "foreignTableName", ")", "<=", "0", ")", ")", "{", "throw", "SchemaException", "::", "invalidForeignKeyForeignTableName", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "foreignTableName", "=", "$", "foreignTableName", ";", "}" ]
Sets the foreign table name. @param string $foreignTableName The foreign table name. @throws \Fridge\DBAL\Exception\SchemaException If the foreign table name is not a valid string.
[ "Sets", "the", "foreign", "table", "name", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/ForeignKey.php#L138-L145
train
fridge-project/dbal
src/Fridge/DBAL/Schema/ForeignKey.php
ForeignKey.addForeignColumnName
public function addForeignColumnName($foreignColumnName) { if (!is_string($foreignColumnName) || (strlen($foreignColumnName) <= 0)) { throw SchemaException::invalidForeignKeyForeignColumnName($this->getName()); } $this->foreignColumnNames[] = $foreignColumnName; }
php
public function addForeignColumnName($foreignColumnName) { if (!is_string($foreignColumnName) || (strlen($foreignColumnName) <= 0)) { throw SchemaException::invalidForeignKeyForeignColumnName($this->getName()); } $this->foreignColumnNames[] = $foreignColumnName; }
[ "public", "function", "addForeignColumnName", "(", "$", "foreignColumnName", ")", "{", "if", "(", "!", "is_string", "(", "$", "foreignColumnName", ")", "||", "(", "strlen", "(", "$", "foreignColumnName", ")", "<=", "0", ")", ")", "{", "throw", "SchemaException", "::", "invalidForeignKeyForeignColumnName", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "foreignColumnNames", "[", "]", "=", "$", "foreignColumnName", ";", "}" ]
Adds a foreign column name to the foreign key. @param string $foreignColumnName The foreign column name to add. @throws \Fridge\DBAL\Exception\SchemaException If the foreign column name is not a valid string.
[ "Adds", "a", "foreign", "column", "name", "to", "the", "foreign", "key", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/ForeignKey.php#L176-L183
train
JoeBengalen/Config
src/AbstractConfig.php
AbstractConfig.setDotNotationKey
protected function setDotNotationKey($key, $value) { $splitKey = explode('.', $key); $root = &$this->data; // Look for the key, creating nested keys if needed while ($part = array_shift($splitKey)) { if (!isset($root[$part]) && count($splitKey)) { $root[$part] = []; } $root = &$root[$part]; } $root = $value; }
php
protected function setDotNotationKey($key, $value) { $splitKey = explode('.', $key); $root = &$this->data; // Look for the key, creating nested keys if needed while ($part = array_shift($splitKey)) { if (!isset($root[$part]) && count($splitKey)) { $root[$part] = []; } $root = &$root[$part]; } $root = $value; }
[ "protected", "function", "setDotNotationKey", "(", "$", "key", ",", "$", "value", ")", "{", "$", "splitKey", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "root", "=", "&", "$", "this", "->", "data", ";", "// Look for the key, creating nested keys if needed", "while", "(", "$", "part", "=", "array_shift", "(", "$", "splitKey", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "root", "[", "$", "part", "]", ")", "&&", "count", "(", "$", "splitKey", ")", ")", "{", "$", "root", "[", "$", "part", "]", "=", "[", "]", ";", "}", "$", "root", "=", "&", "$", "root", "[", "$", "part", "]", ";", "}", "$", "root", "=", "$", "value", ";", "}" ]
Handle setting a configuration value with a dot notation key. @param string $key Dot notation key. @param mixed $value Configuration value.
[ "Handle", "setting", "a", "configuration", "value", "with", "a", "dot", "notation", "key", "." ]
1a13f3153374224aad52da4669bd69655f037546
https://github.com/JoeBengalen/Config/blob/1a13f3153374224aad52da4669bd69655f037546/src/AbstractConfig.php#L141-L154
train
Hnto/nuki
src/Drivers/PDO.php
PDO.compileAndSetName
private function compileAndSetName() { $name = \Nuki\Handlers\Core\Assist::classNameShort($this); $this->name = strtolower($name); }
php
private function compileAndSetName() { $name = \Nuki\Handlers\Core\Assist::classNameShort($this); $this->name = strtolower($name); }
[ "private", "function", "compileAndSetName", "(", ")", "{", "$", "name", "=", "\\", "Nuki", "\\", "Handlers", "\\", "Core", "\\", "Assist", "::", "classNameShort", "(", "$", "this", ")", ";", "$", "this", "->", "name", "=", "strtolower", "(", "$", "name", ")", ";", "}" ]
Private function to compile and set the driver name
[ "Private", "function", "to", "compile", "and", "set", "the", "driver", "name" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Drivers/PDO.php#L70-L74
train
theopera/framework
src/App/Command/InstallCommand.php
InstallCommand.isAlreadyInstalled
private function isAlreadyInstalled() : bool { $public = new SplFileInfo(self::PROJECT_ROOT . '/public'); $src = new SplFileInfo(self::PROJECT_ROOT . '/src'); return $public->isDir() && $src->isDir(); }
php
private function isAlreadyInstalled() : bool { $public = new SplFileInfo(self::PROJECT_ROOT . '/public'); $src = new SplFileInfo(self::PROJECT_ROOT . '/src'); return $public->isDir() && $src->isDir(); }
[ "private", "function", "isAlreadyInstalled", "(", ")", ":", "bool", "{", "$", "public", "=", "new", "SplFileInfo", "(", "self", "::", "PROJECT_ROOT", ".", "'/public'", ")", ";", "$", "src", "=", "new", "SplFileInfo", "(", "self", "::", "PROJECT_ROOT", ".", "'/src'", ")", ";", "return", "$", "public", "->", "isDir", "(", ")", "&&", "$", "src", "->", "isDir", "(", ")", ";", "}" ]
Finds out if the framework has already been installed @return bool
[ "Finds", "out", "if", "the", "framework", "has", "already", "been", "installed" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/App/Command/InstallCommand.php#L102-L108
train
theopera/framework
src/App/Command/InstallCommand.php
InstallCommand.modifyComposerFile
private function modifyComposerFile() { if (!is_writeable('composer.json')) { throw new Exception('Make sure a composer.json file exists and is writable'); } $json = file_get_contents('composer.json'); $composer = json_decode($json); if (!isset($composer->autoload) || !isset($composer->autoload->{'psr-4'})) { $composer->autoload = new stdClass(); $composer->autoload->{'psr-4'} = new stdClass(); } // Composer namespaces requires an extra slash at the end $namespace = $this->namespace . '\\'; $composer->autoload->{'psr-4'}->{$namespace} = 'src'; file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT)); }
php
private function modifyComposerFile() { if (!is_writeable('composer.json')) { throw new Exception('Make sure a composer.json file exists and is writable'); } $json = file_get_contents('composer.json'); $composer = json_decode($json); if (!isset($composer->autoload) || !isset($composer->autoload->{'psr-4'})) { $composer->autoload = new stdClass(); $composer->autoload->{'psr-4'} = new stdClass(); } // Composer namespaces requires an extra slash at the end $namespace = $this->namespace . '\\'; $composer->autoload->{'psr-4'}->{$namespace} = 'src'; file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT)); }
[ "private", "function", "modifyComposerFile", "(", ")", "{", "if", "(", "!", "is_writeable", "(", "'composer.json'", ")", ")", "{", "throw", "new", "Exception", "(", "'Make sure a composer.json file exists and is writable'", ")", ";", "}", "$", "json", "=", "file_get_contents", "(", "'composer.json'", ")", ";", "$", "composer", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "!", "isset", "(", "$", "composer", "->", "autoload", ")", "||", "!", "isset", "(", "$", "composer", "->", "autoload", "->", "{", "'psr-4'", "}", ")", ")", "{", "$", "composer", "->", "autoload", "=", "new", "stdClass", "(", ")", ";", "$", "composer", "->", "autoload", "->", "{", "'psr-4'", "}", "=", "new", "stdClass", "(", ")", ";", "}", "// Composer namespaces requires an extra slash at the end", "$", "namespace", "=", "$", "this", "->", "namespace", ".", "'\\\\'", ";", "$", "composer", "->", "autoload", "->", "{", "'psr-4'", "}", "->", "{", "$", "namespace", "}", "=", "'src'", ";", "file_put_contents", "(", "'composer.json'", ",", "json_encode", "(", "$", "composer", ",", "JSON_PRETTY_PRINT", ")", ")", ";", "}" ]
Modifies the composer file - Add the new project namespace to the autoload list
[ "Modifies", "the", "composer", "file", "-", "Add", "the", "new", "project", "namespace", "to", "the", "autoload", "list" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/App/Command/InstallCommand.php#L183-L202
train
RocketPropelledTortoise/Core
src/Utilities/Format.php
Format.getReadableSize
public static function getReadableSize($bytes) { $unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $exp = floor(log($bytes, 1024)) | 0; return round($bytes / (pow(1024, $exp)), 2) . " $unit[$exp]"; }
php
public static function getReadableSize($bytes) { $unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $exp = floor(log($bytes, 1024)) | 0; return round($bytes / (pow(1024, $exp)), 2) . " $unit[$exp]"; }
[ "public", "static", "function", "getReadableSize", "(", "$", "bytes", ")", "{", "$", "unit", "=", "[", "'B'", ",", "'KB'", ",", "'MB'", ",", "'GB'", ",", "'TB'", ",", "'PB'", ",", "'EB'", ",", "'ZB'", ",", "'YB'", "]", ";", "$", "exp", "=", "floor", "(", "log", "(", "$", "bytes", ",", "1024", ")", ")", "|", "0", ";", "return", "round", "(", "$", "bytes", "/", "(", "pow", "(", "1024", ",", "$", "exp", ")", ")", ",", "2", ")", ".", "\" $unit[$exp]\"", ";", "}" ]
Get file size with correct extension @param int $bytes @return string
[ "Get", "file", "size", "with", "correct", "extension" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Utilities/Format.php#L19-L25
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/validation/AbstractValidator.php
AbstractValidator.validateFor
public function validateFor($context) { $this->errors = new Errors(); // create camelized method name $methodResolved = ActionUtils::parseMethod($context); // check method exists if(!method_exists($this, $methodResolved)) throw new Exception('Method ['.$methodResolved.'] does not exist on class ['.get_class($this).']'); $this->preValidate(); // if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']'); $arr = array_slice(func_get_args(), 1); // CALL THE METHOD call_user_func_array(array($this, $methodResolved), $arr); $this->postValidate(); return $this->errors; }
php
public function validateFor($context) { $this->errors = new Errors(); // create camelized method name $methodResolved = ActionUtils::parseMethod($context); // check method exists if(!method_exists($this, $methodResolved)) throw new Exception('Method ['.$methodResolved.'] does not exist on class ['.get_class($this).']'); $this->preValidate(); // if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']'); $arr = array_slice(func_get_args(), 1); // CALL THE METHOD call_user_func_array(array($this, $methodResolved), $arr); $this->postValidate(); return $this->errors; }
[ "public", "function", "validateFor", "(", "$", "context", ")", "{", "$", "this", "->", "errors", "=", "new", "Errors", "(", ")", ";", "// create camelized method name", "$", "methodResolved", "=", "ActionUtils", "::", "parseMethod", "(", "$", "context", ")", ";", "// check method exists", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "methodResolved", ")", ")", "throw", "new", "Exception", "(", "'Method ['", ".", "$", "methodResolved", ".", "'] does not exist on class ['", ".", "get_class", "(", "$", "this", ")", ".", "']'", ")", ";", "$", "this", "->", "preValidate", "(", ")", ";", "// if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']');", "$", "arr", "=", "array_slice", "(", "func_get_args", "(", ")", ",", "1", ")", ";", "// CALL THE METHOD", "call_user_func_array", "(", "array", "(", "$", "this", ",", "$", "methodResolved", ")", ",", "$", "arr", ")", ";", "$", "this", "->", "postValidate", "(", ")", ";", "return", "$", "this", "->", "errors", ";", "}" ]
This method is called to perform validation @param string $context A string representing the name of the context in which the validation occurs. For example: 'add', 'edit', 'delete', etc. @param mixed $arg, $arg, ... Using func_get_args() these arguments will be passed to the validator function invoked by this function. @return array an array of Errors (or empty array)
[ "This", "method", "is", "called", "to", "perform", "validation" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/validation/AbstractValidator.php#L77-L101
train
nemundo/core
src/Type/Geo/GeoCoordinateAltitude.php
GeoCoordinateAltitude.fromGeoCoordinate
public function fromGeoCoordinate(GeoCoordinate $geoCoordinate = null) { if ($geoCoordinate !== null) { $this->latitude = $geoCoordinate->latitude; $this->longitude = $geoCoordinate->longitude; } return $this; }
php
public function fromGeoCoordinate(GeoCoordinate $geoCoordinate = null) { if ($geoCoordinate !== null) { $this->latitude = $geoCoordinate->latitude; $this->longitude = $geoCoordinate->longitude; } return $this; }
[ "public", "function", "fromGeoCoordinate", "(", "GeoCoordinate", "$", "geoCoordinate", "=", "null", ")", "{", "if", "(", "$", "geoCoordinate", "!==", "null", ")", "{", "$", "this", "->", "latitude", "=", "$", "geoCoordinate", "->", "latitude", ";", "$", "this", "->", "longitude", "=", "$", "geoCoordinate", "->", "longitude", ";", "}", "return", "$", "this", ";", "}" ]
= 0;
[ "=", "0", ";" ]
5ca14889fdfb9155b52fedb364b34502d14e21ed
https://github.com/nemundo/core/blob/5ca14889fdfb9155b52fedb364b34502d14e21ed/src/Type/Geo/GeoCoordinateAltitude.php#L15-L22
train
hiqdev/minii-helpers
src/BaseFileHelper.php
BaseFileHelper.getExtensionsByMimeType
public static function getExtensionsByMimeType($mimeType, $magicFile = null) { $mimeTypes = static::loadMimeTypes($magicFile); return array_keys($mimeTypes, mb_strtolower($mimeType, 'utf-8'), true); }
php
public static function getExtensionsByMimeType($mimeType, $magicFile = null) { $mimeTypes = static::loadMimeTypes($magicFile); return array_keys($mimeTypes, mb_strtolower($mimeType, 'utf-8'), true); }
[ "public", "static", "function", "getExtensionsByMimeType", "(", "$", "mimeType", ",", "$", "magicFile", "=", "null", ")", "{", "$", "mimeTypes", "=", "static", "::", "loadMimeTypes", "(", "$", "magicFile", ")", ";", "return", "array_keys", "(", "$", "mimeTypes", ",", "mb_strtolower", "(", "$", "mimeType", ",", "'utf-8'", ")", ",", "true", ")", ";", "}" ]
Determines the extensions by given MIME type. This method will use a local map between extension names and MIME types. @param string $mimeType file MIME type. @param string $magicFile the path (or alias) of the file that contains all available MIME type information. If this is not set, the file specified by [[mimeMagicFile]] will be used. @return array the extensions corresponding to the specified MIME type
[ "Determines", "the", "extensions", "by", "given", "MIME", "type", ".", "This", "method", "will", "use", "a", "local", "map", "between", "extension", "names", "and", "MIME", "types", "." ]
001b7a56a6ebdc432c4683fe47c00a913f8e57d7
https://github.com/hiqdev/minii-helpers/blob/001b7a56a6ebdc432c4683fe47c00a913f8e57d7/src/BaseFileHelper.php#L188-L192
train
hiqdev/minii-helpers
src/BaseFileHelper.php
BaseFileHelper.matchBasename
private static function matchBasename($baseName, $pattern, $firstWildcard, $flags) { if ($firstWildcard === false) { if ($pattern === $baseName) { return true; } } elseif ($flags & self::PATTERN_ENDSWITH) { /* "*literal" matching against "fooliteral" */ $n = StringHelper::byteLength($pattern); if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) { return true; } } $fnmatchFlags = 0; if ($flags & self::PATTERN_CASE_INSENSITIVE) { $fnmatchFlags |= FNM_CASEFOLD; } return fnmatch($pattern, $baseName, $fnmatchFlags); }
php
private static function matchBasename($baseName, $pattern, $firstWildcard, $flags) { if ($firstWildcard === false) { if ($pattern === $baseName) { return true; } } elseif ($flags & self::PATTERN_ENDSWITH) { /* "*literal" matching against "fooliteral" */ $n = StringHelper::byteLength($pattern); if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) { return true; } } $fnmatchFlags = 0; if ($flags & self::PATTERN_CASE_INSENSITIVE) { $fnmatchFlags |= FNM_CASEFOLD; } return fnmatch($pattern, $baseName, $fnmatchFlags); }
[ "private", "static", "function", "matchBasename", "(", "$", "baseName", ",", "$", "pattern", ",", "$", "firstWildcard", ",", "$", "flags", ")", "{", "if", "(", "$", "firstWildcard", "===", "false", ")", "{", "if", "(", "$", "pattern", "===", "$", "baseName", ")", "{", "return", "true", ";", "}", "}", "elseif", "(", "$", "flags", "&", "self", "::", "PATTERN_ENDSWITH", ")", "{", "/* \"*literal\" matching against \"fooliteral\" */", "$", "n", "=", "StringHelper", "::", "byteLength", "(", "$", "pattern", ")", ";", "if", "(", "StringHelper", "::", "byteSubstr", "(", "$", "pattern", ",", "1", ",", "$", "n", ")", "===", "StringHelper", "::", "byteSubstr", "(", "$", "baseName", ",", "-", "$", "n", ",", "$", "n", ")", ")", "{", "return", "true", ";", "}", "}", "$", "fnmatchFlags", "=", "0", ";", "if", "(", "$", "flags", "&", "self", "::", "PATTERN_CASE_INSENSITIVE", ")", "{", "$", "fnmatchFlags", "|=", "FNM_CASEFOLD", ";", "}", "return", "fnmatch", "(", "$", "pattern", ",", "$", "baseName", ",", "$", "fnmatchFlags", ")", ";", "}" ]
Performs a simple comparison of file or directory names. Based on match_basename() from dir.c of git 1.8.5.3 sources. @param string $baseName file or directory name to compare with the pattern @param string $pattern the pattern that $baseName will be compared against @param integer|boolean $firstWildcard location of first wildcard character in the $pattern @param integer $flags pattern flags @return boolean whether the name matches against pattern
[ "Performs", "a", "simple", "comparison", "of", "file", "or", "directory", "names", "." ]
001b7a56a6ebdc432c4683fe47c00a913f8e57d7
https://github.com/hiqdev/minii-helpers/blob/001b7a56a6ebdc432c4683fe47c00a913f8e57d7/src/BaseFileHelper.php#L482-L502
train
hiqdev/minii-helpers
src/BaseFileHelper.php
BaseFileHelper.matchPathname
private static function matchPathname($path, $basePath, $pattern, $firstWildcard, $flags) { // match with FNM_PATHNAME; the pattern has base implicitly in front of it. if (isset($pattern[0]) && $pattern[0] == '/') { $pattern = StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern)); if ($firstWildcard !== false && $firstWildcard !== 0) { $firstWildcard--; } } $namelen = StringHelper::byteLength($path) - (empty($basePath) ? 0 : StringHelper::byteLength($basePath) + 1); $name = StringHelper::byteSubstr($path, -$namelen, $namelen); if ($firstWildcard !== 0) { if ($firstWildcard === false) { $firstWildcard = StringHelper::byteLength($pattern); } // if the non-wildcard part is longer than the remaining pathname, surely it cannot match. if ($firstWildcard > $namelen) { return false; } if (strncmp($pattern, $name, $firstWildcard)) { return false; } $pattern = StringHelper::byteSubstr($pattern, $firstWildcard, StringHelper::byteLength($pattern)); $name = StringHelper::byteSubstr($name, $firstWildcard, $namelen); // If the whole pattern did not have a wildcard, then our prefix match is all we need; we do not need to call fnmatch at all. if (empty($pattern) && empty($name)) { return true; } } $fnmatchFlags = FNM_PATHNAME; if ($flags & self::PATTERN_CASE_INSENSITIVE) { $fnmatchFlags |= FNM_CASEFOLD; } return fnmatch($pattern, $name, $fnmatchFlags); }
php
private static function matchPathname($path, $basePath, $pattern, $firstWildcard, $flags) { // match with FNM_PATHNAME; the pattern has base implicitly in front of it. if (isset($pattern[0]) && $pattern[0] == '/') { $pattern = StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern)); if ($firstWildcard !== false && $firstWildcard !== 0) { $firstWildcard--; } } $namelen = StringHelper::byteLength($path) - (empty($basePath) ? 0 : StringHelper::byteLength($basePath) + 1); $name = StringHelper::byteSubstr($path, -$namelen, $namelen); if ($firstWildcard !== 0) { if ($firstWildcard === false) { $firstWildcard = StringHelper::byteLength($pattern); } // if the non-wildcard part is longer than the remaining pathname, surely it cannot match. if ($firstWildcard > $namelen) { return false; } if (strncmp($pattern, $name, $firstWildcard)) { return false; } $pattern = StringHelper::byteSubstr($pattern, $firstWildcard, StringHelper::byteLength($pattern)); $name = StringHelper::byteSubstr($name, $firstWildcard, $namelen); // If the whole pattern did not have a wildcard, then our prefix match is all we need; we do not need to call fnmatch at all. if (empty($pattern) && empty($name)) { return true; } } $fnmatchFlags = FNM_PATHNAME; if ($flags & self::PATTERN_CASE_INSENSITIVE) { $fnmatchFlags |= FNM_CASEFOLD; } return fnmatch($pattern, $name, $fnmatchFlags); }
[ "private", "static", "function", "matchPathname", "(", "$", "path", ",", "$", "basePath", ",", "$", "pattern", ",", "$", "firstWildcard", ",", "$", "flags", ")", "{", "// match with FNM_PATHNAME; the pattern has base implicitly in front of it.", "if", "(", "isset", "(", "$", "pattern", "[", "0", "]", ")", "&&", "$", "pattern", "[", "0", "]", "==", "'/'", ")", "{", "$", "pattern", "=", "StringHelper", "::", "byteSubstr", "(", "$", "pattern", ",", "1", ",", "StringHelper", "::", "byteLength", "(", "$", "pattern", ")", ")", ";", "if", "(", "$", "firstWildcard", "!==", "false", "&&", "$", "firstWildcard", "!==", "0", ")", "{", "$", "firstWildcard", "--", ";", "}", "}", "$", "namelen", "=", "StringHelper", "::", "byteLength", "(", "$", "path", ")", "-", "(", "empty", "(", "$", "basePath", ")", "?", "0", ":", "StringHelper", "::", "byteLength", "(", "$", "basePath", ")", "+", "1", ")", ";", "$", "name", "=", "StringHelper", "::", "byteSubstr", "(", "$", "path", ",", "-", "$", "namelen", ",", "$", "namelen", ")", ";", "if", "(", "$", "firstWildcard", "!==", "0", ")", "{", "if", "(", "$", "firstWildcard", "===", "false", ")", "{", "$", "firstWildcard", "=", "StringHelper", "::", "byteLength", "(", "$", "pattern", ")", ";", "}", "// if the non-wildcard part is longer than the remaining pathname, surely it cannot match.", "if", "(", "$", "firstWildcard", ">", "$", "namelen", ")", "{", "return", "false", ";", "}", "if", "(", "strncmp", "(", "$", "pattern", ",", "$", "name", ",", "$", "firstWildcard", ")", ")", "{", "return", "false", ";", "}", "$", "pattern", "=", "StringHelper", "::", "byteSubstr", "(", "$", "pattern", ",", "$", "firstWildcard", ",", "StringHelper", "::", "byteLength", "(", "$", "pattern", ")", ")", ";", "$", "name", "=", "StringHelper", "::", "byteSubstr", "(", "$", "name", ",", "$", "firstWildcard", ",", "$", "namelen", ")", ";", "// If the whole pattern did not have a wildcard, then our prefix match is all we need; we do not need to call fnmatch at all.", "if", "(", "empty", "(", "$", "pattern", ")", "&&", "empty", "(", "$", "name", ")", ")", "{", "return", "true", ";", "}", "}", "$", "fnmatchFlags", "=", "FNM_PATHNAME", ";", "if", "(", "$", "flags", "&", "self", "::", "PATTERN_CASE_INSENSITIVE", ")", "{", "$", "fnmatchFlags", "|=", "FNM_CASEFOLD", ";", "}", "return", "fnmatch", "(", "$", "pattern", ",", "$", "name", ",", "$", "fnmatchFlags", ")", ";", "}" ]
Compares a path part against a pattern with optional wildcards. Based on match_pathname() from dir.c of git 1.8.5.3 sources. @param string $path full path to compare @param string $basePath base of path that will not be compared @param string $pattern the pattern that path part will be compared against @param integer|boolean $firstWildcard location of first wildcard character in the $pattern @param integer $flags pattern flags @return boolean whether the path part matches against pattern
[ "Compares", "a", "path", "part", "against", "a", "pattern", "with", "optional", "wildcards", "." ]
001b7a56a6ebdc432c4683fe47c00a913f8e57d7
https://github.com/hiqdev/minii-helpers/blob/001b7a56a6ebdc432c4683fe47c00a913f8e57d7/src/BaseFileHelper.php#L516-L556
train
rollerworks/search-core
Value/ValuesGroup.php
ValuesGroup.countValues
public function countValues(): int { $count = 0; foreach ($this->fields as $field) { $count += $field->count(); } return $count; }
php
public function countValues(): int { $count = 0; foreach ($this->fields as $field) { $count += $field->count(); } return $count; }
[ "public", "function", "countValues", "(", ")", ":", "int", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "field", ")", "{", "$", "count", "+=", "$", "field", "->", "count", "(", ")", ";", "}", "return", "$", "count", ";", "}" ]
Gets the total number of values in the fields list structure.
[ "Gets", "the", "total", "number", "of", "values", "in", "the", "fields", "list", "structure", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesGroup.php#L152-L161
train
DoSomething/mb-toolbox
src/MB_Slack.php
MB_Slack.lookupChannelKey
private function lookupChannelKey($channelName) { if ($channelName == '#niche_monitoring') { $channelKey = $this->slackConfig['webhookURL_niche_monitoring']; } elseif ($channelName == '#after-school-internal') { $channelKey = $this->slackConfig['webhookURL_after-school-internal']; } else { $channelKey = $this->slackConfig['webhookURL_message-broker']; } return $channelKey; }
php
private function lookupChannelKey($channelName) { if ($channelName == '#niche_monitoring') { $channelKey = $this->slackConfig['webhookURL_niche_monitoring']; } elseif ($channelName == '#after-school-internal') { $channelKey = $this->slackConfig['webhookURL_after-school-internal']; } else { $channelKey = $this->slackConfig['webhookURL_message-broker']; } return $channelKey; }
[ "private", "function", "lookupChannelKey", "(", "$", "channelName", ")", "{", "if", "(", "$", "channelName", "==", "'#niche_monitoring'", ")", "{", "$", "channelKey", "=", "$", "this", "->", "slackConfig", "[", "'webhookURL_niche_monitoring'", "]", ";", "}", "elseif", "(", "$", "channelName", "==", "'#after-school-internal'", ")", "{", "$", "channelKey", "=", "$", "this", "->", "slackConfig", "[", "'webhookURL_after-school-internal'", "]", ";", "}", "else", "{", "$", "channelKey", "=", "$", "this", "->", "slackConfig", "[", "'webhookURL_message-broker'", "]", ";", "}", "return", "$", "channelKey", ";", "}" ]
Lookup channel key value based on channel name. @param string $channelName The name of the channel. @return string $channelKey A key value based on the channel name.
[ "Lookup", "channel", "key", "value", "based", "on", "channel", "name", "." ]
ceec5fc594bae137d1ab1f447344800343b62ac6
https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_Slack.php#L59-L71
train
DoSomething/mb-toolbox
src/MB_Slack.php
MB_Slack.alert
public function alert($channelNames, $message, $tos = ['@dee']) { $to = implode(',', $tos); foreach ($channelNames as $channelName) { $channelKey = $this->lookupChannelKey($channelName); $slack = new Client($channelKey); $slack->to($to)->attach($message)->send(); $this->statHat->ezCount('MB_Toolbox: MB_Slack: alert', 1); } }
php
public function alert($channelNames, $message, $tos = ['@dee']) { $to = implode(',', $tos); foreach ($channelNames as $channelName) { $channelKey = $this->lookupChannelKey($channelName); $slack = new Client($channelKey); $slack->to($to)->attach($message)->send(); $this->statHat->ezCount('MB_Toolbox: MB_Slack: alert', 1); } }
[ "public", "function", "alert", "(", "$", "channelNames", ",", "$", "message", ",", "$", "tos", "=", "[", "'@dee'", "]", ")", "{", "$", "to", "=", "implode", "(", "','", ",", "$", "tos", ")", ";", "foreach", "(", "$", "channelNames", "as", "$", "channelName", ")", "{", "$", "channelKey", "=", "$", "this", "->", "lookupChannelKey", "(", "$", "channelName", ")", ";", "$", "slack", "=", "new", "Client", "(", "$", "channelKey", ")", ";", "$", "slack", "->", "to", "(", "$", "to", ")", "->", "attach", "(", "$", "message", ")", "->", "send", "(", ")", ";", "$", "this", "->", "statHat", "->", "ezCount", "(", "'MB_Toolbox: MB_Slack: alert'", ",", "1", ")", ";", "}", "}" ]
Send report to Slack. $param array $to Comma separated list of Slack channels ("#") and/or users ("@") to send message to. @param string $message List of message attachment options. https://github.com/maknz/slack#send-an-attachment-with-fields @param array $channelNames The name of the channel to send the message to.
[ "Send", "report", "to", "Slack", "." ]
ceec5fc594bae137d1ab1f447344800343b62ac6
https://github.com/DoSomething/mb-toolbox/blob/ceec5fc594bae137d1ab1f447344800343b62ac6/src/MB_Slack.php#L83-L93
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php
RestApiControllerTrait.createJsonResponse
protected function createJsonResponse($data = null, $scope = null, $status = 200) { if ($data !== null) { $data = is_string($data) ? $data : $this->container->get('serializer')->serialize( $data, 'json', empty($scope) ? array() : array('scope' => $scope) ) ; } $response = new Response(null === $data ? '' : $data, $status); $response->headers->set('Content-Type', 'application/json'); return $response; }
php
protected function createJsonResponse($data = null, $scope = null, $status = 200) { if ($data !== null) { $data = is_string($data) ? $data : $this->container->get('serializer')->serialize( $data, 'json', empty($scope) ? array() : array('scope' => $scope) ) ; } $response = new Response(null === $data ? '' : $data, $status); $response->headers->set('Content-Type', 'application/json'); return $response; }
[ "protected", "function", "createJsonResponse", "(", "$", "data", "=", "null", ",", "$", "scope", "=", "null", ",", "$", "status", "=", "200", ")", "{", "if", "(", "$", "data", "!==", "null", ")", "{", "$", "data", "=", "is_string", "(", "$", "data", ")", "?", "$", "data", ":", "$", "this", "->", "container", "->", "get", "(", "'serializer'", ")", "->", "serialize", "(", "$", "data", ",", "'json'", ",", "empty", "(", "$", "scope", ")", "?", "array", "(", ")", ":", "array", "(", "'scope'", "=>", "$", "scope", ")", ")", ";", "}", "$", "response", "=", "new", "Response", "(", "null", "===", "$", "data", "?", "''", ":", "$", "data", ",", "$", "status", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "return", "$", "response", ";", "}" ]
Create a JsonResponse with given data, if object given, it will be serialize with registered serializer. @param mixed $data @param string $scope @param int $status @return Response
[ "Create", "a", "JsonResponse", "with", "given", "data", "if", "object", "given", "it", "will", "be", "serialize", "with", "registered", "serializer", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php#L34-L49
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php
RestApiControllerTrait.createJsonBadRequestResponse
protected function createJsonBadRequestResponse(array $errors = array()) { // try to extract proper validation errors foreach ($errors as $key => $error) { if (!$error instanceof FormError) { continue; } $errors['errors'][$key] = array( 'message' => $error->getMessage(), 'parameters' => $error->getMessageParameters(), ); unset($errors[$key]); } $response = new Response( is_string($errors) ? $errors : json_encode($errors), 400 ); $response->headers->set('Content-Type', 'application/json'); return $response; }
php
protected function createJsonBadRequestResponse(array $errors = array()) { // try to extract proper validation errors foreach ($errors as $key => $error) { if (!$error instanceof FormError) { continue; } $errors['errors'][$key] = array( 'message' => $error->getMessage(), 'parameters' => $error->getMessageParameters(), ); unset($errors[$key]); } $response = new Response( is_string($errors) ? $errors : json_encode($errors), 400 ); $response->headers->set('Content-Type', 'application/json'); return $response; }
[ "protected", "function", "createJsonBadRequestResponse", "(", "array", "$", "errors", "=", "array", "(", ")", ")", "{", "// try to extract proper validation errors", "foreach", "(", "$", "errors", "as", "$", "key", "=>", "$", "error", ")", "{", "if", "(", "!", "$", "error", "instanceof", "FormError", ")", "{", "continue", ";", "}", "$", "errors", "[", "'errors'", "]", "[", "$", "key", "]", "=", "array", "(", "'message'", "=>", "$", "error", "->", "getMessage", "(", ")", ",", "'parameters'", "=>", "$", "error", "->", "getMessageParameters", "(", ")", ",", ")", ";", "unset", "(", "$", "errors", "[", "$", "key", "]", ")", ";", "}", "$", "response", "=", "new", "Response", "(", "is_string", "(", "$", "errors", ")", "?", "$", "errors", ":", "json_encode", "(", "$", "errors", ")", ",", "400", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "return", "$", "response", ";", "}" ]
create and returns a 400 Bad Request response. @param array $errors @return JsonResponse
[ "create", "and", "returns", "a", "400", "Bad", "Request", "response", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php#L71-L93
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php
RestApiControllerTrait.getRequestData
protected function getRequestData(Request $request, $inflection = 'camelize') { switch ($request->headers->get('content-type')) { case 'application/json': if (!($data = @json_decode($request->getContent(), true)) && ($error = json_last_error()) != JSON_ERROR_NONE ) { throw new HttpException(400, sprintf( 'Invalid submitted json data, error %s : %s', $error, json_last_error_msg() )); } break; default: $data = array_replace_recursive( $request->request->all(), $request->files->all() ); break; } // data camel case normalization return $inflection && $this->container->has('majora.inflector')? $this->container->get('majora.inflector')->normalize($data, $inflection) : $data ; }
php
protected function getRequestData(Request $request, $inflection = 'camelize') { switch ($request->headers->get('content-type')) { case 'application/json': if (!($data = @json_decode($request->getContent(), true)) && ($error = json_last_error()) != JSON_ERROR_NONE ) { throw new HttpException(400, sprintf( 'Invalid submitted json data, error %s : %s', $error, json_last_error_msg() )); } break; default: $data = array_replace_recursive( $request->request->all(), $request->files->all() ); break; } // data camel case normalization return $inflection && $this->container->has('majora.inflector')? $this->container->get('majora.inflector')->normalize($data, $inflection) : $data ; }
[ "protected", "function", "getRequestData", "(", "Request", "$", "request", ",", "$", "inflection", "=", "'camelize'", ")", "{", "switch", "(", "$", "request", "->", "headers", "->", "get", "(", "'content-type'", ")", ")", "{", "case", "'application/json'", ":", "if", "(", "!", "(", "$", "data", "=", "@", "json_decode", "(", "$", "request", "->", "getContent", "(", ")", ",", "true", ")", ")", "&&", "(", "$", "error", "=", "json_last_error", "(", ")", ")", "!=", "JSON_ERROR_NONE", ")", "{", "throw", "new", "HttpException", "(", "400", ",", "sprintf", "(", "'Invalid submitted json data, error %s : %s'", ",", "$", "error", ",", "json_last_error_msg", "(", ")", ")", ")", ";", "}", "break", ";", "default", ":", "$", "data", "=", "array_replace_recursive", "(", "$", "request", "->", "request", "->", "all", "(", ")", ",", "$", "request", "->", "files", "->", "all", "(", ")", ")", ";", "break", ";", "}", "// data camel case normalization", "return", "$", "inflection", "&&", "$", "this", "->", "container", "->", "has", "(", "'majora.inflector'", ")", "?", "$", "this", "->", "container", "->", "get", "(", "'majora.inflector'", ")", "->", "normalize", "(", "$", "data", ",", "$", "inflection", ")", ":", "$", "data", ";", "}" ]
Retrieve given request data depending on its content type. @param Request $request @param string $inflection optional inflector to tuse on parameter keys @return array @throws HttpException if JSON content-type and invalid JSON data
[ "Retrieve", "given", "request", "data", "depending", "on", "its", "content", "type", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php#L105-L134
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php
RestApiControllerTrait.assertSubmitedFormIsValid
protected function assertSubmitedFormIsValid(Request $request, FormInterface $form) { $form->submit( $this->getRequestData($request), $request->getMethod() !== 'PATCH' ); if (!$valid = $form->isValid()) { throw new ValidationException( $form->getData(), $form->getErrors(true, true) // deep & flattened ); } }
php
protected function assertSubmitedFormIsValid(Request $request, FormInterface $form) { $form->submit( $this->getRequestData($request), $request->getMethod() !== 'PATCH' ); if (!$valid = $form->isValid()) { throw new ValidationException( $form->getData(), $form->getErrors(true, true) // deep & flattened ); } }
[ "protected", "function", "assertSubmitedFormIsValid", "(", "Request", "$", "request", ",", "FormInterface", "$", "form", ")", "{", "$", "form", "->", "submit", "(", "$", "this", "->", "getRequestData", "(", "$", "request", ")", ",", "$", "request", "->", "getMethod", "(", ")", "!==", "'PATCH'", ")", ";", "if", "(", "!", "$", "valid", "=", "$", "form", "->", "isValid", "(", ")", ")", "{", "throw", "new", "ValidationException", "(", "$", "form", "->", "getData", "(", ")", ",", "$", "form", "->", "getErrors", "(", "true", ",", "true", ")", "// deep & flattened", ")", ";", "}", "}" ]
Custom method for form submission to handle http method bugs, and extra fields error options. @param Request $request @param FormInterface $form @throws HttpException if invalid json data @throws ValidationException if invalid form
[ "Custom", "method", "for", "form", "submission", "to", "handle", "http", "method", "bugs", "and", "extra", "fields", "error", "options", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Bundle/FrameworkExtraBundle/Controller/RestApiControllerTrait.php#L146-L159
train
Becklyn/Gluggi
src/Application/LayoutApplication.php
LayoutApplication.bootstrap
public function bootstrap ($webDir, array $config = []) { $baseDir = dirname($webDir); $this["gluggi.config"] = $this->resolveConfig($config); $this["gluggi.baseDir"] = $baseDir; $this->registerProviders(); $this->registerCoreTwigNamespace(); $this->registerModelsAndTwigLayoutNamespaces($baseDir); $this->registerControllers(); $this->registerTwigExtensions(); $this->defineCoreRouting(); }
php
public function bootstrap ($webDir, array $config = []) { $baseDir = dirname($webDir); $this["gluggi.config"] = $this->resolveConfig($config); $this["gluggi.baseDir"] = $baseDir; $this->registerProviders(); $this->registerCoreTwigNamespace(); $this->registerModelsAndTwigLayoutNamespaces($baseDir); $this->registerControllers(); $this->registerTwigExtensions(); $this->defineCoreRouting(); }
[ "public", "function", "bootstrap", "(", "$", "webDir", ",", "array", "$", "config", "=", "[", "]", ")", "{", "$", "baseDir", "=", "dirname", "(", "$", "webDir", ")", ";", "$", "this", "[", "\"gluggi.config\"", "]", "=", "$", "this", "->", "resolveConfig", "(", "$", "config", ")", ";", "$", "this", "[", "\"gluggi.baseDir\"", "]", "=", "$", "baseDir", ";", "$", "this", "->", "registerProviders", "(", ")", ";", "$", "this", "->", "registerCoreTwigNamespace", "(", ")", ";", "$", "this", "->", "registerModelsAndTwigLayoutNamespaces", "(", "$", "baseDir", ")", ";", "$", "this", "->", "registerControllers", "(", ")", ";", "$", "this", "->", "registerTwigExtensions", "(", ")", ";", "$", "this", "->", "defineCoreRouting", "(", ")", ";", "}" ]
Bootstraps the complete application @param string $webDir the path to the web dir @param array $config the config
[ "Bootstraps", "the", "complete", "application" ]
837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786
https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Application/LayoutApplication.php#L31-L43
train
Becklyn/Gluggi
src/Application/LayoutApplication.php
LayoutApplication.registerProviders
private function registerProviders () { $this->register(new TwigServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new ServiceControllerServiceProvider()); }
php
private function registerProviders () { $this->register(new TwigServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new ServiceControllerServiceProvider()); }
[ "private", "function", "registerProviders", "(", ")", "{", "$", "this", "->", "register", "(", "new", "TwigServiceProvider", "(", ")", ")", ";", "$", "this", "->", "register", "(", "new", "UrlGeneratorServiceProvider", "(", ")", ")", ";", "$", "this", "->", "register", "(", "new", "ServiceControllerServiceProvider", "(", ")", ")", ";", "}" ]
Registers all used service providers
[ "Registers", "all", "used", "service", "providers" ]
837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786
https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Application/LayoutApplication.php#L49-L54
train
Becklyn/Gluggi
src/Application/LayoutApplication.php
LayoutApplication.registerModelsAndTwigLayoutNamespaces
private function registerModelsAndTwigLayoutNamespaces ($baseDir) { $elementTypesModel = new ElementTypesModel($baseDir); // model $this["model.element_types"] = $elementTypesModel; $this["model.download"] = new DownloadModel($baseDir); // twig template namespaces foreach ($elementTypesModel->getAllElementTypes() as $elementType) { $this["twig.loader.filesystem"]->addPath($elementTypesModel->getUserSubDirectory("{$elementType}s"), $elementType); } $this["twig.loader.filesystem"]->addPath($elementTypesModel->getUserSubDirectory("_base"), "base"); }
php
private function registerModelsAndTwigLayoutNamespaces ($baseDir) { $elementTypesModel = new ElementTypesModel($baseDir); // model $this["model.element_types"] = $elementTypesModel; $this["model.download"] = new DownloadModel($baseDir); // twig template namespaces foreach ($elementTypesModel->getAllElementTypes() as $elementType) { $this["twig.loader.filesystem"]->addPath($elementTypesModel->getUserSubDirectory("{$elementType}s"), $elementType); } $this["twig.loader.filesystem"]->addPath($elementTypesModel->getUserSubDirectory("_base"), "base"); }
[ "private", "function", "registerModelsAndTwigLayoutNamespaces", "(", "$", "baseDir", ")", "{", "$", "elementTypesModel", "=", "new", "ElementTypesModel", "(", "$", "baseDir", ")", ";", "// model", "$", "this", "[", "\"model.element_types\"", "]", "=", "$", "elementTypesModel", ";", "$", "this", "[", "\"model.download\"", "]", "=", "new", "DownloadModel", "(", "$", "baseDir", ")", ";", "// twig template namespaces", "foreach", "(", "$", "elementTypesModel", "->", "getAllElementTypes", "(", ")", "as", "$", "elementType", ")", "{", "$", "this", "[", "\"twig.loader.filesystem\"", "]", "->", "addPath", "(", "$", "elementTypesModel", "->", "getUserSubDirectory", "(", "\"{$elementType}s\"", ")", ",", "$", "elementType", ")", ";", "}", "$", "this", "[", "\"twig.loader.filesystem\"", "]", "->", "addPath", "(", "$", "elementTypesModel", "->", "getUserSubDirectory", "(", "\"_base\"", ")", ",", "\"base\"", ")", ";", "}" ]
Registers all models and all twig layout namespaces @param string $baseDir
[ "Registers", "all", "models", "and", "all", "twig", "layout", "namespaces" ]
837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786
https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Application/LayoutApplication.php#L71-L87
train
Becklyn/Gluggi
src/Application/LayoutApplication.php
LayoutApplication.registerTwigExtensions
private function registerTwigExtensions () { $this['twig'] = $this->share($this->extend('twig', function (Twig_Environment $twig, Application $app) { // add custom extension $twig->addExtension(new TwigExtension($app)); // add global gluggi variable $twig->addGlobal("gluggi", [ "config" => $this["gluggi.config"] ]); return $twig; } )); }
php
private function registerTwigExtensions () { $this['twig'] = $this->share($this->extend('twig', function (Twig_Environment $twig, Application $app) { // add custom extension $twig->addExtension(new TwigExtension($app)); // add global gluggi variable $twig->addGlobal("gluggi", [ "config" => $this["gluggi.config"] ]); return $twig; } )); }
[ "private", "function", "registerTwigExtensions", "(", ")", "{", "$", "this", "[", "'twig'", "]", "=", "$", "this", "->", "share", "(", "$", "this", "->", "extend", "(", "'twig'", ",", "function", "(", "Twig_Environment", "$", "twig", ",", "Application", "$", "app", ")", "{", "// add custom extension", "$", "twig", "->", "addExtension", "(", "new", "TwigExtension", "(", "$", "app", ")", ")", ";", "// add global gluggi variable", "$", "twig", "->", "addGlobal", "(", "\"gluggi\"", ",", "[", "\"config\"", "=>", "$", "this", "[", "\"gluggi.config\"", "]", "]", ")", ";", "return", "$", "twig", ";", "}", ")", ")", ";", "}" ]
Registers all used twig extensions
[ "Registers", "all", "used", "twig", "extensions" ]
837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786
https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Application/LayoutApplication.php#L106-L122
train
Becklyn/Gluggi
src/Application/LayoutApplication.php
LayoutApplication.defineCoreRouting
private function defineCoreRouting () { $this->get("/", "controller.core:indexAction")->bind("index"); $this->get("/all/{elementType}", "controller.core:elementsOverviewAction")->bind("elements_overview"); $this->get("/{elementType}/{key}", "controller.core:showElementAction")->bind("element"); }
php
private function defineCoreRouting () { $this->get("/", "controller.core:indexAction")->bind("index"); $this->get("/all/{elementType}", "controller.core:elementsOverviewAction")->bind("elements_overview"); $this->get("/{elementType}/{key}", "controller.core:showElementAction")->bind("element"); }
[ "private", "function", "defineCoreRouting", "(", ")", "{", "$", "this", "->", "get", "(", "\"/\"", ",", "\"controller.core:indexAction\"", ")", "->", "bind", "(", "\"index\"", ")", ";", "$", "this", "->", "get", "(", "\"/all/{elementType}\"", ",", "\"controller.core:elementsOverviewAction\"", ")", "->", "bind", "(", "\"elements_overview\"", ")", ";", "$", "this", "->", "get", "(", "\"/{elementType}/{key}\"", ",", "\"controller.core:showElementAction\"", ")", "->", "bind", "(", "\"element\"", ")", ";", "}" ]
Defines the routes of the core app
[ "Defines", "the", "routes", "of", "the", "core", "app" ]
837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786
https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Application/LayoutApplication.php#L128-L133
train
sil-project/VarietyBundle
src/Entity/Species.php
Species.setGenus
public function setGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus = null) { $this->genus = $genus; return $this; }
php
public function setGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus = null) { $this->genus = $genus; return $this; }
[ "public", "function", "setGenus", "(", "\\", "Librinfo", "\\", "VarietiesBundle", "\\", "Entity", "\\", "Genus", "$", "genus", "=", "null", ")", "{", "$", "this", "->", "genus", "=", "$", "genus", ";", "return", "$", "this", ";", "}" ]
Set genus. @param \Librinfo\VarietiesBundle\Entity\Genus $genus @return Species
[ "Set", "genus", "." ]
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Species.php#L373-L378
train
sil-project/VarietyBundle
src/Entity/Species.php
Species.addSubspecies
public function addSubspecies(\Librinfo\VarietiesBundle\Entity\Species $subspecies) { $subspecies->setParentSpecies($this); $this->subspecieses[] = $subspecies; return $this; }
php
public function addSubspecies(\Librinfo\VarietiesBundle\Entity\Species $subspecies) { $subspecies->setParentSpecies($this); $this->subspecieses[] = $subspecies; return $this; }
[ "public", "function", "addSubspecies", "(", "\\", "Librinfo", "\\", "VarietiesBundle", "\\", "Entity", "\\", "Species", "$", "subspecies", ")", "{", "$", "subspecies", "->", "setParentSpecies", "(", "$", "this", ")", ";", "$", "this", "->", "subspecieses", "[", "]", "=", "$", "subspecies", ";", "return", "$", "this", ";", "}" ]
Add subspecies. @param \Librinfo\VarietiesBundle\Entity\Species $subspecies @return Species
[ "Add", "subspecies", "." ]
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Species.php#L434-L440
train
sil-project/VarietyBundle
src/Entity/Species.php
Species.removeSubspeciese
public function removeSubspeciese(\Librinfo\VarietiesBundle\Entity\Species $subspecies) { return $this->subspecieses->removeElement($subspecies); }
php
public function removeSubspeciese(\Librinfo\VarietiesBundle\Entity\Species $subspecies) { return $this->subspecieses->removeElement($subspecies); }
[ "public", "function", "removeSubspeciese", "(", "\\", "Librinfo", "\\", "VarietiesBundle", "\\", "Entity", "\\", "Species", "$", "subspecies", ")", "{", "return", "$", "this", "->", "subspecieses", "->", "removeElement", "(", "$", "subspecies", ")", ";", "}" ]
Remove subspecies. @param \Librinfo\VarietiesBundle\Entity\Species $subspecies @return bool tRUE if this collection contained the specified element, FALSE otherwise
[ "Remove", "subspecies", "." ]
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Species.php#L449-L452
train
sil-project/VarietyBundle
src/Entity/Species.php
Species.setParentSpecies
public function setParentSpecies(\Librinfo\VarietiesBundle\Entity\Species $parentSpecies = null) { $this->parent_species = $parentSpecies; return $this; }
php
public function setParentSpecies(\Librinfo\VarietiesBundle\Entity\Species $parentSpecies = null) { $this->parent_species = $parentSpecies; return $this; }
[ "public", "function", "setParentSpecies", "(", "\\", "Librinfo", "\\", "VarietiesBundle", "\\", "Entity", "\\", "Species", "$", "parentSpecies", "=", "null", ")", "{", "$", "this", "->", "parent_species", "=", "$", "parentSpecies", ";", "return", "$", "this", ";", "}" ]
Set parentSpecies. @param \Librinfo\VarietiesBundle\Entity\Species $parentSpecies @return Species
[ "Set", "parentSpecies", "." ]
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Species.php#L481-L486
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.setOffset
public function setOffset($offset) { $this->checkStreamAvailable(); fseek($this->fileDescriptor, $offset < 0 ? $this->getSize() + $offset : $offset); }
php
public function setOffset($offset) { $this->checkStreamAvailable(); fseek($this->fileDescriptor, $offset < 0 ? $this->getSize() + $offset : $offset); }
[ "public", "function", "setOffset", "(", "$", "offset", ")", "{", "$", "this", "->", "checkStreamAvailable", "(", ")", ";", "fseek", "(", "$", "this", "->", "fileDescriptor", ",", "$", "offset", "<", "0", "?", "$", "this", "->", "getSize", "(", ")", "+", "$", "offset", ":", "$", "offset", ")", ";", "}" ]
Sets the point of operation, ie the cursor offset value. The offset may also be set to a negative value when it is interpreted as an offset from the end of the stream instead of the beginning. @param integer $offset The new point of operation. @return void @throws InvalidStreamException if an I/O error occurs
[ "Sets", "the", "point", "of", "operation", "ie", "the", "cursor", "offset", "value", ".", "The", "offset", "may", "also", "be", "set", "to", "a", "negative", "value", "when", "it", "is", "interpreted", "as", "an", "offset", "from", "the", "end", "of", "the", "stream", "instead", "of", "the", "beginning", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L111-L115
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.readInt16LE
final public function readInt16LE() { if ($this->isBigEndian()) { return $this->fromInt16(strrev($this->read(2))); } else { return $this->fromInt16($this->read(2)); } }
php
final public function readInt16LE() { if ($this->isBigEndian()) { return $this->fromInt16(strrev($this->read(2))); } else { return $this->fromInt16($this->read(2)); } }
[ "final", "public", "function", "readInt16LE", "(", ")", "{", "if", "(", "$", "this", "->", "isBigEndian", "(", ")", ")", "{", "return", "$", "this", "->", "fromInt16", "(", "strrev", "(", "$", "this", "->", "read", "(", "2", ")", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "fromInt16", "(", "$", "this", "->", "read", "(", "2", ")", ")", ";", "}", "}" ]
Reads 2 bytes from the stream and returns little-endian ordered binary data as signed 16-bit integer. @return integer @throws InvalidStreamException if an I/O error occurs
[ "Reads", "2", "bytes", "from", "the", "stream", "and", "returns", "little", "-", "endian", "ordered", "binary", "data", "as", "signed", "16", "-", "bit", "integer", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L224-L231
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.readInt16BE
final public function readInt16BE() { if ($this->isLittleEndian()) { return $this->fromInt16(strrev($this->read(2))); } else { return $this->fromInt16($this->read(2)); } }
php
final public function readInt16BE() { if ($this->isLittleEndian()) { return $this->fromInt16(strrev($this->read(2))); } else { return $this->fromInt16($this->read(2)); } }
[ "final", "public", "function", "readInt16BE", "(", ")", "{", "if", "(", "$", "this", "->", "isLittleEndian", "(", ")", ")", "{", "return", "$", "this", "->", "fromInt16", "(", "strrev", "(", "$", "this", "->", "read", "(", "2", ")", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "fromInt16", "(", "$", "this", "->", "read", "(", "2", ")", ")", ";", "}", "}" ]
Reads 2 bytes from the stream and returns big-endian ordered binary data as signed 16-bit integer. @return integer @throws InvalidStreamException if an I/O error occurs
[ "Reads", "2", "bytes", "from", "the", "stream", "and", "returns", "big", "-", "endian", "ordered", "binary", "data", "as", "signed", "16", "-", "bit", "integer", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L240-L247
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.fromUInt16
private function fromUInt16($value, $order = 0) { list(, $int) = unpack( ($order == self::BIG_ENDIAN_ORDER ? 'n' : ($order == self::LITTLE_ENDIAN_ORDER ? 'v' : 'S')) . '*', $value ); return $int; }
php
private function fromUInt16($value, $order = 0) { list(, $int) = unpack( ($order == self::BIG_ENDIAN_ORDER ? 'n' : ($order == self::LITTLE_ENDIAN_ORDER ? 'v' : 'S')) . '*', $value ); return $int; }
[ "private", "function", "fromUInt16", "(", "$", "value", ",", "$", "order", "=", "0", ")", "{", "list", "(", ",", "$", "int", ")", "=", "unpack", "(", "(", "$", "order", "==", "self", "::", "BIG_ENDIAN_ORDER", "?", "'n'", ":", "(", "$", "order", "==", "self", "::", "LITTLE_ENDIAN_ORDER", "?", "'v'", ":", "'S'", ")", ")", ".", "'*'", ",", "$", "value", ")", ";", "return", "$", "int", ";", "}" ]
Returns machine endian ordered binary data as unsigned 16-bit integer. @param string $value The binary data string. @param integer $order The byte order of the binary data string. @return integer
[ "Returns", "machine", "endian", "ordered", "binary", "data", "as", "unsigned", "16", "-", "bit", "integer", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L268-L275
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.fromInt24
private function fromInt24($value) { list(, $int) = unpack('l*', $this->isLittleEndian() ? ("\x00" . $value) : ($value . "\x00")); return $int; }
php
private function fromInt24($value) { list(, $int) = unpack('l*', $this->isLittleEndian() ? ("\x00" . $value) : ($value . "\x00")); return $int; }
[ "private", "function", "fromInt24", "(", "$", "value", ")", "{", "list", "(", ",", "$", "int", ")", "=", "unpack", "(", "'l*'", ",", "$", "this", "->", "isLittleEndian", "(", ")", "?", "(", "\"\\x00\"", ".", "$", "value", ")", ":", "(", "$", "value", ".", "\"\\x00\"", ")", ")", ";", "return", "$", "int", ";", "}" ]
Returns machine endian ordered binary data as signed 24-bit integer. @param string $value The binary data string. @return integer
[ "Returns", "machine", "endian", "ordered", "binary", "data", "as", "signed", "24", "-", "bit", "integer", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L319-L323
train
MetaSyntactical/Io
src/MetaSyntactical/Io/Reader.php
Reader.readInt24LE
final public function readInt24LE() { if ($this->isBigEndian()) { return $this->fromInt24(strrev($this->read(3))); } else { return $this->fromInt24($this->read(3)); } }
php
final public function readInt24LE() { if ($this->isBigEndian()) { return $this->fromInt24(strrev($this->read(3))); } else { return $this->fromInt24($this->read(3)); } }
[ "final", "public", "function", "readInt24LE", "(", ")", "{", "if", "(", "$", "this", "->", "isBigEndian", "(", ")", ")", "{", "return", "$", "this", "->", "fromInt24", "(", "strrev", "(", "$", "this", "->", "read", "(", "3", ")", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "fromInt24", "(", "$", "this", "->", "read", "(", "3", ")", ")", ";", "}", "}" ]
Reads 3 bytes from the stream and returns little-endian ordered binary data as signed 24-bit integer. @return integer @throws InvalidStreamException if an I/O error occurs
[ "Reads", "3", "bytes", "from", "the", "stream", "and", "returns", "little", "-", "endian", "ordered", "binary", "data", "as", "signed", "24", "-", "bit", "integer", "." ]
d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c
https://github.com/MetaSyntactical/Io/blob/d9272c6cf7f3cf24cbd5e4069a6695b26ef0b50c/src/MetaSyntactical/Io/Reader.php#L332-L339
train