repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.normalize
public function normalize(float $score, int $alpha=15) { $normalizedScore = $score/sqrt(($score^2) + $alpha); if ($normalizedScore < -1.0) { return -1.0; } elseif ($normalizedScore > 1.0) { return 1.0; } return $normalizedScore; }
php
public function normalize(float $score, int $alpha=15) { $normalizedScore = $score/sqrt(($score^2) + $alpha); if ($normalizedScore < -1.0) { return -1.0; } elseif ($normalizedScore > 1.0) { return 1.0; } return $normalizedScore; }
[ "public", "function", "normalize", "(", "float", "$", "score", ",", "int", "$", "alpha", "=", "15", ")", "{", "$", "normalizedScore", "=", "$", "score", "/", "sqrt", "(", "(", "$", "score", "^", "2", ")", "+", "$", "alpha", ")", ";", "if", "(", ...
Normalize the score to be between -1 and 1 using an alpha that approximates the max expected value @param float $score @param int $alpha
[ "Normalize", "the", "score", "to", "be", "between", "-", "1", "and", "1", "using", "an", "alpha", "that", "approximates", "the", "max", "expected", "value" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L127-L136
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.scalarIncDec
public function scalarIncDec(string $word, float $valence, bool $isCapDiff) { $scalar = 0.0; $wordLower = strtolower($word); if(isset($this->boosterDict[$wordLower])) { $scalar = $this->boosterDict[$wordLower]; if($valence < 0) { $scalar *= -1; } //check if booster/dampener word is in ALLCAPS (while others aren't) if(strtoupper($word) && $isCapDiff) { if ($valence > 0) { $scalar += Vader::C_INCR; } else { $scalar -= Vader::C_INCR; } } } return $scalar; }
php
public function scalarIncDec(string $word, float $valence, bool $isCapDiff) { $scalar = 0.0; $wordLower = strtolower($word); if(isset($this->boosterDict[$wordLower])) { $scalar = $this->boosterDict[$wordLower]; if($valence < 0) { $scalar *= -1; } //check if booster/dampener word is in ALLCAPS (while others aren't) if(strtoupper($word) && $isCapDiff) { if ($valence > 0) { $scalar += Vader::C_INCR; } else { $scalar -= Vader::C_INCR; } } } return $scalar; }
[ "public", "function", "scalarIncDec", "(", "string", "$", "word", ",", "float", "$", "valence", ",", "bool", "$", "isCapDiff", ")", "{", "$", "scalar", "=", "0.0", ";", "$", "wordLower", "=", "strtolower", "(", "$", "word", ")", ";", "if", "(", "isse...
Check if the preceding words increase, decrease, or negate/nullify the valence @param string $word @param float $valence @param bool $isCapDiff @return float
[ "Check", "if", "the", "preceding", "words", "increase", "decrease", "or", "negate", "/", "nullify", "the", "valence" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L145-L165
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.getPolarityScores
public function getPolarityScores(array $tokens) : array { $sentiments = []; for($index = 0; $index < count($tokens); $index++) { $valence = 0.0; $lcToken = strtolower($tokens[$index]); if( $lcToken === "kind" && strtolower($tokens[$index+1]) === 'of' || isset(self::$this->boosterDict[$lcToken]) ) { $sentiments[] = $valence; } else { $sentiments[] = $this->getSentimentValence($valence, $tokens, $index, $sentiments); } } $sentiments = $this->butCheck($tokens, $sentiments); return $this->scoreValence($sentiments, $tokens); }
php
public function getPolarityScores(array $tokens) : array { $sentiments = []; for($index = 0; $index < count($tokens); $index++) { $valence = 0.0; $lcToken = strtolower($tokens[$index]); if( $lcToken === "kind" && strtolower($tokens[$index+1]) === 'of' || isset(self::$this->boosterDict[$lcToken]) ) { $sentiments[] = $valence; } else { $sentiments[] = $this->getSentimentValence($valence, $tokens, $index, $sentiments); } } $sentiments = $this->butCheck($tokens, $sentiments); return $this->scoreValence($sentiments, $tokens); }
[ "public", "function", "getPolarityScores", "(", "array", "$", "tokens", ")", ":", "array", "{", "$", "sentiments", "=", "[", "]", ";", "for", "(", "$", "index", "=", "0", ";", "$", "index", "<", "count", "(", "$", "tokens", ")", ";", "$", "index", ...
Return a float for sentiment strength based on the input text. Positive values are positive valence, negative value are negative valence. @param array $tokens
[ "Return", "a", "float", "for", "sentiment", "strength", "based", "on", "the", "input", "text", ".", "Positive", "values", "are", "positive", "valence", "negative", "value", "are", "negative", "valence", "." ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L172-L190
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.leastCheck
public function leastCheck(float $valence, array $tokens, int $index) : float { if($index === 0) { return $valence; } $inLexicon = isset($this->getLexicon()[strtolower($tokens[$index-1])]); if($inLexicon) { return $valence; } $leastIndex = array_searchi('least', $tokens); $atIndex = array_searchi('at', $tokens); $veryIndex = array_searchi('very', $tokens); if($leastIndex == $index-1 && $atIndex != $index-2 && $veryIndex != $index-2) { $valence *= self::N_SCALAR; } elseif( $leastIndex == $index-1) { $valence *= self::N_SCALAR; } return $valence; }
php
public function leastCheck(float $valence, array $tokens, int $index) : float { if($index === 0) { return $valence; } $inLexicon = isset($this->getLexicon()[strtolower($tokens[$index-1])]); if($inLexicon) { return $valence; } $leastIndex = array_searchi('least', $tokens); $atIndex = array_searchi('at', $tokens); $veryIndex = array_searchi('very', $tokens); if($leastIndex == $index-1 && $atIndex != $index-2 && $veryIndex != $index-2) { $valence *= self::N_SCALAR; } elseif( $leastIndex == $index-1) { $valence *= self::N_SCALAR; } return $valence; }
[ "public", "function", "leastCheck", "(", "float", "$", "valence", ",", "array", "$", "tokens", ",", "int", "$", "index", ")", ":", "float", "{", "if", "(", "$", "index", "===", "0", ")", "{", "return", "$", "valence", ";", "}", "$", "inLexicon", "=...
check for negation case using "least" @param float $valence @param array $tokens @param int $index @return float
[ "check", "for", "negation", "case", "using", "least" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L313-L336
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.butCheck
public function butCheck(array $tokens, array $sentiments) { $index = array_searchi('but', $tokens); // no modification required if($index === false) { return $sentiments; } for($i = 0; $i < count($sentiments); $i++) { if( $index < $i) { $sentiments[$i] *= 0.5; } elseif($index > $i) { $sentiments[$i] *= 1.5; } } return $sentiments; }
php
public function butCheck(array $tokens, array $sentiments) { $index = array_searchi('but', $tokens); // no modification required if($index === false) { return $sentiments; } for($i = 0; $i < count($sentiments); $i++) { if( $index < $i) { $sentiments[$i] *= 0.5; } elseif($index > $i) { $sentiments[$i] *= 1.5; } } return $sentiments; }
[ "public", "function", "butCheck", "(", "array", "$", "tokens", ",", "array", "$", "sentiments", ")", "{", "$", "index", "=", "array_searchi", "(", "'but'", ",", "$", "tokens", ")", ";", "// no modification required", "if", "(", "$", "index", "===", "false"...
check for modification in sentiment due to contrastive conjunction 'but' @param array $tokens @param array $sentiments @return array|real
[ "check", "for", "modification", "in", "sentiment", "due", "to", "contrastive", "conjunction", "but" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L344-L361
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.allCapDifferential
public function allCapDifferential(array $tokens) : bool { $upperCase = array_map('strtoupper', $tokens); $intersection = array_values( array_intersect( $tokens, $upperCase)); return count($intersection) > 0 && count($intersection) < count($tokens); }
php
public function allCapDifferential(array $tokens) : bool { $upperCase = array_map('strtoupper', $tokens); $intersection = array_values( array_intersect( $tokens, $upperCase)); return count($intersection) > 0 && count($intersection) < count($tokens); }
[ "public", "function", "allCapDifferential", "(", "array", "$", "tokens", ")", ":", "bool", "{", "$", "upperCase", "=", "array_map", "(", "'strtoupper'", ",", "$", "tokens", ")", ";", "$", "intersection", "=", "array_values", "(", "array_intersect", "(", "$",...
Check whether just some words in the input are ALL CAPS param list words: The words to inspect returns: `True` if some but not all items in `words` are ALL CAPS @param array $tokens @return boolean
[ "Check", "whether", "just", "some", "words", "in", "the", "input", "are", "ALL", "CAPS", "param", "list", "words", ":", "The", "words", "to", "inspect", "returns", ":", "True", "if", "some", "but", "not", "all", "items", "in", "words", "are", "ALL", "C...
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L394-L399
yooper/php-text-analysis
src/Sentiment/Vader.php
Vader.getLexicon
public function getLexicon() : array { if(!file_exists($this->getTxtFilePath())) { throw new \RuntimeException('Package vader_lexicon must be installed, php textconsole pta:install:package vader_lexicon'); } if(empty($this->lexicon)) { $fh = fopen($this->getTxtFilePath(), "r"); while (($rows[] = fgetcsv($fh, 4096, "\t")) !== FALSE); fclose($fh); foreach($rows as $row) { $this->lexicon[$row[0]] = $row[1]; } } return $this->lexicon; }
php
public function getLexicon() : array { if(!file_exists($this->getTxtFilePath())) { throw new \RuntimeException('Package vader_lexicon must be installed, php textconsole pta:install:package vader_lexicon'); } if(empty($this->lexicon)) { $fh = fopen($this->getTxtFilePath(), "r"); while (($rows[] = fgetcsv($fh, 4096, "\t")) !== FALSE); fclose($fh); foreach($rows as $row) { $this->lexicon[$row[0]] = $row[1]; } } return $this->lexicon; }
[ "public", "function", "getLexicon", "(", ")", ":", "array", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "getTxtFilePath", "(", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Package vader_lexicon must be installed, php textc...
Loads the flat file data set @return array
[ "Loads", "the", "flat", "file", "data", "set" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Sentiment/Vader.php#L405-L423
yooper/php-text-analysis
src/Analysis/DateAnalysis.php
DateAnalysis.normalize
protected function normalize(string $text) : string { $search = ['jan.','feb.','mar.','apr.','may.','jun.','jul.','aug.','sep.','oct.','nov.','dec.']; $replace = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ]; return str_ireplace($search, $replace, $text); }
php
protected function normalize(string $text) : string { $search = ['jan.','feb.','mar.','apr.','may.','jun.','jul.','aug.','sep.','oct.','nov.','dec.']; $replace = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ]; return str_ireplace($search, $replace, $text); }
[ "protected", "function", "normalize", "(", "string", "$", "text", ")", ":", "string", "{", "$", "search", "=", "[", "'jan.'", ",", "'feb.'", ",", "'mar.'", ",", "'apr.'", ",", "'may.'", ",", "'jun.'", ",", "'jul.'", ",", "'aug.'", ",", "'sep.'", ",", ...
Remove any periods from abbreviated month names ie Mar. to March @param string $text
[ "Remove", "any", "periods", "from", "abbreviated", "month", "names", "ie", "Mar", ".", "to", "March" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Analysis/DateAnalysis.php#L42-L60
yooper/php-text-analysis
src/Comparisons/MostFreqCharComparison.php
MostFreqCharComparison.similarity
public function similarity($text1, $text2) { $similarity = 0; $hash1 = $this->hashString($text1); $hash2 = $this->hashString($text2); $keys = array_keys(array_intersect_key($hash1, $hash2)); foreach($keys as $key) { if($hash1[$key] === $hash2[$key] && $hash1[$key] >= $this->limit) { $similarity += $hash1[$key]; } } return $similarity; }
php
public function similarity($text1, $text2) { $similarity = 0; $hash1 = $this->hashString($text1); $hash2 = $this->hashString($text2); $keys = array_keys(array_intersect_key($hash1, $hash2)); foreach($keys as $key) { if($hash1[$key] === $hash2[$key] && $hash1[$key] >= $this->limit) { $similarity += $hash1[$key]; } } return $similarity; }
[ "public", "function", "similarity", "(", "$", "text1", ",", "$", "text2", ")", "{", "$", "similarity", "=", "0", ";", "$", "hash1", "=", "$", "this", "->", "hashString", "(", "$", "text1", ")", ";", "$", "hash2", "=", "$", "this", "->", "hashString...
Returns the most frequently used letter with the same frequency @param string $text1 @param string $text2 @return int
[ "Returns", "the", "most", "frequently", "used", "letter", "with", "the", "same", "frequency" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Comparisons/MostFreqCharComparison.php#L38-L53
yooper/php-text-analysis
src/Comparisons/MostFreqCharComparison.php
MostFreqCharComparison.hashString
public function hashString($text) { $charList = str_split($text); $chars = array_fill_keys( $charList, 0); foreach($charList as $char) { $chars[$char]++; } return $chars; }
php
public function hashString($text) { $charList = str_split($text); $chars = array_fill_keys( $charList, 0); foreach($charList as $char) { $chars[$char]++; } return $chars; }
[ "public", "function", "hashString", "(", "$", "text", ")", "{", "$", "charList", "=", "str_split", "(", "$", "text", ")", ";", "$", "chars", "=", "array_fill_keys", "(", "$", "charList", ",", "0", ")", ";", "foreach", "(", "$", "charList", "as", "$",...
Returns a sorted hashed array with the frequency counts per character @param string $text
[ "Returns", "a", "sorted", "hashed", "array", "with", "the", "frequency", "counts", "per", "character" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Comparisons/MostFreqCharComparison.php#L61-L69
yooper/php-text-analysis
src/Comparisons/MostFreqCharComparison.php
MostFreqCharComparison.distance
public function distance($text1, $text2) { return max(strlen($text1), strlen($text2)) - $this->similarity($text1, $text2); }
php
public function distance($text1, $text2) { return max(strlen($text1), strlen($text2)) - $this->similarity($text1, $text2); }
[ "public", "function", "distance", "(", "$", "text1", ",", "$", "text2", ")", "{", "return", "max", "(", "strlen", "(", "$", "text1", ")", ",", "strlen", "(", "$", "text2", ")", ")", "-", "$", "this", "->", "similarity", "(", "$", "text1", ",", "$...
Returns the distance max string length minus similarity @param string $text1 @param string $text2 @return int
[ "Returns", "the", "distance", "max", "string", "length", "minus", "similarity" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Comparisons/MostFreqCharComparison.php#L77-L80
yooper/php-text-analysis
src/Taggers/StanfordAbstract.php
StanfordAbstract.exec
protected function exec() { $descriptors = [ 0 => ["pipe", "r"], // stdin is a pipe that the child will read from 1 => ["pipe", "w"], // stdout is a pipe that the child will write to 2 => ["pipe", "w"] // stderr is a file to write to ]; $process = proc_open($this->getCommand(), $descriptors, $pipes, dirname($this->getJarPath()), []); if (is_resource($process)) { fclose($pipes[0]); // close stdin pipe $this->output = stream_get_contents($pipes[1]); $this->errors = stream_get_contents($pipes[2]); fclose($pipes[2]); fclose($pipes[1]); if(proc_close($process) === -1) { throw new RuntimeException($this->errors); } } }
php
protected function exec() { $descriptors = [ 0 => ["pipe", "r"], // stdin is a pipe that the child will read from 1 => ["pipe", "w"], // stdout is a pipe that the child will write to 2 => ["pipe", "w"] // stderr is a file to write to ]; $process = proc_open($this->getCommand(), $descriptors, $pipes, dirname($this->getJarPath()), []); if (is_resource($process)) { fclose($pipes[0]); // close stdin pipe $this->output = stream_get_contents($pipes[1]); $this->errors = stream_get_contents($pipes[2]); fclose($pipes[2]); fclose($pipes[1]); if(proc_close($process) === -1) { throw new RuntimeException($this->errors); } } }
[ "protected", "function", "exec", "(", ")", "{", "$", "descriptors", "=", "[", "0", "=>", "[", "\"pipe\"", ",", "\"r\"", "]", ",", "// stdin is a pipe that the child will read from", "1", "=>", "[", "\"pipe\"", ",", "\"w\"", "]", ",", "// stdout is a pipe that th...
Calls the stanford jar file @throws RuntimeException
[ "Calls", "the", "stanford", "jar", "file" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Taggers/StanfordAbstract.php#L188-L208
yooper/php-text-analysis
src/Utilities/Vowels/EnglishVowels.php
EnglishVowels.isVowel
public function isVowel($word, $index) { if(strpbrk($word[$index], 'aeiou') !== false) { return true; } elseif($word[$index] === 'y' && strpbrk($word[--$index], 'aeiou') === false) { return true; } return false; }
php
public function isVowel($word, $index) { if(strpbrk($word[$index], 'aeiou') !== false) { return true; } elseif($word[$index] === 'y' && strpbrk($word[--$index], 'aeiou') === false) { return true; } return false; }
[ "public", "function", "isVowel", "(", "$", "word", ",", "$", "index", ")", "{", "if", "(", "strpbrk", "(", "$", "word", "[", "$", "index", "]", ",", "'aeiou'", ")", "!==", "false", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "word",...
Returns true if the letter at the given index is a vowel, works with y @param string $word the word to use @param int $index the index in the string to inspect @return boolean True letter at the provided index is a vowel
[ "Returns", "true", "if", "the", "letter", "at", "the", "given", "index", "is", "a", "vowel", "works", "with", "y" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Utilities/Vowels/EnglishVowels.php#L17-L25
yooper/php-text-analysis
src/Comparisons/JaccardIndexComparison.php
JaccardIndexComparison.similarity
public function similarity($text1, $text2) { if(is_string($text1) && is_string($text2)) { $text1 = str_split($text1); $text2 = str_split($text2); } $inter = array_intersect( $text1, $text2 ); $union = array_unique( ($text1 + $text2) ); return count($inter) / count($union); }
php
public function similarity($text1, $text2) { if(is_string($text1) && is_string($text2)) { $text1 = str_split($text1); $text2 = str_split($text2); } $inter = array_intersect( $text1, $text2 ); $union = array_unique( ($text1 + $text2) ); return count($inter) / count($union); }
[ "public", "function", "similarity", "(", "$", "text1", ",", "$", "text2", ")", "{", "if", "(", "is_string", "(", "$", "text1", ")", "&&", "is_string", "(", "$", "text2", ")", ")", "{", "$", "text1", "=", "str_split", "(", "$", "text1", ")", ";", ...
Returns the Jaccard Index @param string|array $text1 @param string|array $text2 @return float
[ "Returns", "the", "Jaccard", "Index" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Comparisons/JaccardIndexComparison.php#L19-L28
yooper/php-text-analysis
src/Stemmers/DictionaryStemmer.php
DictionaryStemmer.stem
public function stem($token) { if(in_array($token, $this->whiteList)) { return $token; } return $this->spell->suggest( $this->stemmer->stem($token) )[0]; }
php
public function stem($token) { if(in_array($token, $this->whiteList)) { return $token; } return $this->spell->suggest( $this->stemmer->stem($token) )[0]; }
[ "public", "function", "stem", "(", "$", "token", ")", "{", "if", "(", "in_array", "(", "$", "token", ",", "$", "this", "->", "whiteList", ")", ")", "{", "return", "$", "token", ";", "}", "return", "$", "this", "->", "spell", "->", "suggest", "(", ...
Stem and then look up the word @param string $token
[ "Stem", "and", "then", "look", "up", "the", "word" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Stemmers/DictionaryStemmer.php#L51-L57
yooper/php-text-analysis
src/Tokenizers/RegexTokenizer.php
RegexTokenizer.tokenize
public function tokenize($string) { $matches = array(); $count = preg_match_all($this->pattern, $string, $matches, $this->flags, $this->offset); if($count === false) { return array(); } return $matches[0]; }
php
public function tokenize($string) { $matches = array(); $count = preg_match_all($this->pattern, $string, $matches, $this->flags, $this->offset); if($count === false) { return array(); } return $matches[0]; }
[ "public", "function", "tokenize", "(", "$", "string", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "$", "count", "=", "preg_match_all", "(", "$", "this", "->", "pattern", ",", "$", "string", ",", "$", "matches", ",", "$", "this", "->", "f...
Wraps preg_match_all @param string $string @return array
[ "Wraps", "preg_match_all" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Tokenizers/RegexTokenizer.php#L28-L37
yooper/php-text-analysis
src/Analysis/FreqDist.php
FreqDist.getKeyValuesByWeight
public function getKeyValuesByWeight() { if(empty($this->keysByWeight)) { $weightPerToken = $this->getWeightPerToken(); //make a copy of the array $keyValuesByWeight = $this->keyValues; array_walk($keyValuesByWeight, function(&$value, $key, $weightPerToken) { $value /= $weightPerToken; }, $this->totalTokens); $this->keysByWeight = $keyValuesByWeight; } return $this->keysByWeight; }
php
public function getKeyValuesByWeight() { if(empty($this->keysByWeight)) { $weightPerToken = $this->getWeightPerToken(); //make a copy of the array $keyValuesByWeight = $this->keyValues; array_walk($keyValuesByWeight, function(&$value, $key, $weightPerToken) { $value /= $weightPerToken; }, $this->totalTokens); $this->keysByWeight = $keyValuesByWeight; } return $this->keysByWeight; }
[ "public", "function", "getKeyValuesByWeight", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "keysByWeight", ")", ")", "{", "$", "weightPerToken", "=", "$", "this", "->", "getWeightPerToken", "(", ")", ";", "//make a copy of the array", "$", "key...
Return an array with key weight pairs @return array
[ "Return", "an", "array", "with", "key", "weight", "pairs" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Analysis/FreqDist.php#L115-L128
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.verifyChecksum
public function verifyChecksum() { if(empty($this->getPackage()->getChecksum())) { return true; } return $this->getPackage()->getChecksum() === md5_file($this->getDownloadFullPath()); }
php
public function verifyChecksum() { if(empty($this->getPackage()->getChecksum())) { return true; } return $this->getPackage()->getChecksum() === md5_file($this->getDownloadFullPath()); }
[ "public", "function", "verifyChecksum", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "getPackage", "(", ")", "->", "getChecksum", "(", ")", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "getPackage", "(", ")", ...
Verify the packages checksum against the downloaded file if the package has a checksum @return boolean
[ "Verify", "the", "packages", "checksum", "against", "the", "downloaded", "file", "if", "the", "package", "has", "a", "checksum" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L52-L58
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.unpackPackage
public function unpackPackage() { // it is zipped, we must unzip it if($this->getPackage()->getUnzip()) { $this->extractZip($this->getDownloadFullPath(), $this->getInstallDir()); } else { $this->recursiveCopy($this->getDownloadFullPath(), $this->getInstallDir()); } }
php
public function unpackPackage() { // it is zipped, we must unzip it if($this->getPackage()->getUnzip()) { $this->extractZip($this->getDownloadFullPath(), $this->getInstallDir()); } else { $this->recursiveCopy($this->getDownloadFullPath(), $this->getInstallDir()); } }
[ "public", "function", "unpackPackage", "(", ")", "{", "// it is zipped, we must unzip it", "if", "(", "$", "this", "->", "getPackage", "(", ")", "->", "getUnzip", "(", ")", ")", "{", "$", "this", "->", "extractZip", "(", "$", "this", "->", "getDownloadFullPa...
de-compress the downloaded corpus into the install directory, or copy the files into the install directory
[ "de", "-", "compress", "the", "downloaded", "corpus", "into", "the", "install", "directory", "or", "copy", "the", "files", "into", "the", "install", "directory" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L64-L72
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.recursiveCopy
protected function recursiveCopy($src,$dst) { if($this->isZip($src)) { $this->extractZip($src, $this->getInstallDir()); return; } $dir = opendir($src); if(!is_dir($dst)) { mkdir($dst); } while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { recursiveCopy($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . '/' . $file); } } } closedir($dir); }
php
protected function recursiveCopy($src,$dst) { if($this->isZip($src)) { $this->extractZip($src, $this->getInstallDir()); return; } $dir = opendir($src); if(!is_dir($dst)) { mkdir($dst); } while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { recursiveCopy($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . '/' . $file); } } } closedir($dir); }
[ "protected", "function", "recursiveCopy", "(", "$", "src", ",", "$", "dst", ")", "{", "if", "(", "$", "this", "->", "isZip", "(", "$", "src", ")", ")", "{", "$", "this", "->", "extractZip", "(", "$", "src", ",", "$", "this", "->", "getInstallDir", ...
Recursive copy the directory @param string $src @param string $dst
[ "Recursive", "copy", "the", "directory" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L81-L102
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.extractZip
protected function extractZip($srcPath, $extractToDir) { $zip = new ZipArchive(); $r = $zip->open($srcPath); if($r) { $zip->extractTo($extractToDir); $zip->close(); } }
php
protected function extractZip($srcPath, $extractToDir) { $zip = new ZipArchive(); $r = $zip->open($srcPath); if($r) { $zip->extractTo($extractToDir); $zip->close(); } }
[ "protected", "function", "extractZip", "(", "$", "srcPath", ",", "$", "extractToDir", ")", "{", "$", "zip", "=", "new", "ZipArchive", "(", ")", ";", "$", "r", "=", "$", "zip", "->", "open", "(", "$", "srcPath", ")", ";", "if", "(", "$", "r", ")",...
Use PHP's ZipArchive to extract out the data
[ "Use", "PHP", "s", "ZipArchive", "to", "extract", "out", "the", "data" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L122-L130
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.initialize
public function initialize() { if(!is_dir(dirname($this->getDownloadFullPath()))) { mkdir(dirname($this->getDownloadFullPath()), 0755, true); } if(!is_dir($this->getInstallDir())) { mkdir($this->getInstallDir(), 0755, true); } }
php
public function initialize() { if(!is_dir(dirname($this->getDownloadFullPath()))) { mkdir(dirname($this->getDownloadFullPath()), 0755, true); } if(!is_dir($this->getInstallDir())) { mkdir($this->getInstallDir(), 0755, true); } }
[ "public", "function", "initialize", "(", ")", "{", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "this", "->", "getDownloadFullPath", "(", ")", ")", ")", ")", "{", "mkdir", "(", "dirname", "(", "$", "this", "->", "getDownloadFullPath", "(", ")", ...
Initialize the directories required for the download
[ "Initialize", "the", "directories", "required", "for", "the", "download" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L135-L145
yooper/php-text-analysis
src/Downloaders/DownloadPackageFactory.php
DownloadPackageFactory.getDownloadFullPath
public function getDownloadFullPath() { return sys_get_temp_dir().DIRECTORY_SEPARATOR.'pta-downloads' .DIRECTORY_SEPARATOR.$this->getPackage()->getSubdir() .DIRECTORY_SEPARATOR.basename($this->getPackage()->getUrl()); }
php
public function getDownloadFullPath() { return sys_get_temp_dir().DIRECTORY_SEPARATOR.'pta-downloads' .DIRECTORY_SEPARATOR.$this->getPackage()->getSubdir() .DIRECTORY_SEPARATOR.basename($this->getPackage()->getUrl()); }
[ "public", "function", "getDownloadFullPath", "(", ")", "{", "return", "sys_get_temp_dir", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'pta-downloads'", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "getPackage", "(", ")", "->", "getSubdir", "(", ")", ".", ...
Has the full path to where the download should go @return string
[ "Has", "the", "full", "path", "to", "where", "the", "download", "should", "go" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Downloaders/DownloadPackageFactory.php#L152-L157
yooper/php-text-analysis
src/Generators/StopwordGenerator.php
StopwordGenerator.getStopwords
public function getStopwords() { if(!empty($this->stopWords)) { return $this->stopWords; } foreach($this->getFilePaths() as $filePath) { $content = $this->getFileContent($filePath); $doc = new TokensDocument((new GeneralTokenizer()) ->tokenize($content) ); $doc->applyTransformation(new LowerCaseFilter()) ->applyTransformation(new PossessiveNounFilter()) ->applyTransformation(new PunctuationFilter()) ->applyTransformation(new CharFilter()); if($this->mode === self::MODE_FREQ) { $this->computeUsingFreqDist($doc->getDocumentData()); } } arsort($this->stopWords); return $this->stopWords; }
php
public function getStopwords() { if(!empty($this->stopWords)) { return $this->stopWords; } foreach($this->getFilePaths() as $filePath) { $content = $this->getFileContent($filePath); $doc = new TokensDocument((new GeneralTokenizer()) ->tokenize($content) ); $doc->applyTransformation(new LowerCaseFilter()) ->applyTransformation(new PossessiveNounFilter()) ->applyTransformation(new PunctuationFilter()) ->applyTransformation(new CharFilter()); if($this->mode === self::MODE_FREQ) { $this->computeUsingFreqDist($doc->getDocumentData()); } } arsort($this->stopWords); return $this->stopWords; }
[ "public", "function", "getStopwords", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "stopWords", ")", ")", "{", "return", "$", "this", "->", "stopWords", ";", "}", "foreach", "(", "$", "this", "->", "getFilePaths", "(", ")", "as", ...
Returns an array of stop words and their frequencies @return string[]
[ "Returns", "an", "array", "of", "stop", "words", "and", "their", "frequencies" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Generators/StopwordGenerator.php#L60-L83
yooper/php-text-analysis
src/Generators/StopwordGenerator.php
StopwordGenerator.computeUsingFreqDist
protected function computeUsingFreqDist(array $tokens) { $freqDist = (new FreqDist($tokens)) ->getKeyValuesByFrequency(); foreach($freqDist as $token => $freqValue) { if(!isset($this->stopWords[$token])) { $this->stopWords[$token] = $freqValue; } else { $this->stopWords[$token] += $freqValue; } } }
php
protected function computeUsingFreqDist(array $tokens) { $freqDist = (new FreqDist($tokens)) ->getKeyValuesByFrequency(); foreach($freqDist as $token => $freqValue) { if(!isset($this->stopWords[$token])) { $this->stopWords[$token] = $freqValue; } else { $this->stopWords[$token] += $freqValue; } } }
[ "protected", "function", "computeUsingFreqDist", "(", "array", "$", "tokens", ")", "{", "$", "freqDist", "=", "(", "new", "FreqDist", "(", "$", "tokens", ")", ")", "->", "getKeyValuesByFrequency", "(", ")", ";", "foreach", "(", "$", "freqDist", "as", "$", ...
Adds frequency counts to the stopWords property @param array $tokens
[ "Adds", "frequency", "counts", "to", "the", "stopWords", "property" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Generators/StopwordGenerator.php#L89-L102
yooper/php-text-analysis
src/Indexes/WordnetIndex.php
WordnetIndex.getLemma
public function getLemma($word, $pos = '') { if(empty($this->lemmasIdx)) { foreach($this->getWordnetCorpus()->getLemmas() as &$lemma) { $this->lemmasIdx["{$lemma->getWord()}.{$lemma->getPos()}"] = $lemma; } // sort the keys for faster lookup ksort($this->lemmasIdx); } $found = []; // found 1 if(isset($this->lemmasIdx["{$word}.{$pos}"])) { $found[] = $this->lemmasIdx["{$word}.{$pos}"]; } else { foreach($this->getWordnetCorpus()->getPosFileMaps() as $key => $value) { if(isset($this->lemmasIdx["{$word}.{$key}"])) { $found[] = $this->lemmasIdx["{$word}.{$key}"]; } } } //attach the synsets for the lemmas foreach($found as $lemma) { if(empty($lemma->getSynsets())) { $synsets = []; foreach($lemma->getSynsetOffsets() as $fileOffset) { $synsets[] = $this->getWordnetCorpus()->getSynsetByOffsetAndPos((int)$fileOffset, $lemma->getPos()); } $lemma->setSynsets($synsets); } } return $found; }
php
public function getLemma($word, $pos = '') { if(empty($this->lemmasIdx)) { foreach($this->getWordnetCorpus()->getLemmas() as &$lemma) { $this->lemmasIdx["{$lemma->getWord()}.{$lemma->getPos()}"] = $lemma; } // sort the keys for faster lookup ksort($this->lemmasIdx); } $found = []; // found 1 if(isset($this->lemmasIdx["{$word}.{$pos}"])) { $found[] = $this->lemmasIdx["{$word}.{$pos}"]; } else { foreach($this->getWordnetCorpus()->getPosFileMaps() as $key => $value) { if(isset($this->lemmasIdx["{$word}.{$key}"])) { $found[] = $this->lemmasIdx["{$word}.{$key}"]; } } } //attach the synsets for the lemmas foreach($found as $lemma) { if(empty($lemma->getSynsets())) { $synsets = []; foreach($lemma->getSynsetOffsets() as $fileOffset) { $synsets[] = $this->getWordnetCorpus()->getSynsetByOffsetAndPos((int)$fileOffset, $lemma->getPos()); } $lemma->setSynsets($synsets); } } return $found; }
[ "public", "function", "getLemma", "(", "$", "word", ",", "$", "pos", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "lemmasIdx", ")", ")", "{", "foreach", "(", "$", "this", "->", "getWordnetCorpus", "(", ")", "->", "getLemmas", "(...
Return the lemmas that are linked to the given word, provide a pos to filter down the results @param string $word @param string $pos @return \TextAnalysis\Models\Wordnet\Lemma[]
[ "Return", "the", "lemmas", "that", "are", "linked", "to", "the", "given", "word", "provide", "a", "pos", "to", "filter", "down", "the", "results" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Indexes/WordnetIndex.php#L54-L91
yooper/php-text-analysis
src/Indexes/WordnetIndex.php
WordnetIndex.getMorph
public function getMorph($word, $pos = '') { if(mb_strlen($word) < 3) { return ""; } $searchForFuncWithPos = function(ExceptionMap $exceptionMap) use($word, $pos) { return $exceptionMap->getPos() === $pos && in_array($word, $exceptionMap->getExceptionList()); }; $searchForFuncWithoutPos = function(ExceptionMap $exceptionMap) use($word) { return in_array($word, $exceptionMap->getExceptionList()); }; $found = []; if(!empty($pos)) { $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithPos); } else { $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithoutPos); } // found a match in the exceptions data if(!empty($found)) { return array_values($found)[0]->getTarget(); } foreach($this->getMorphilogicalSubstitutions() as $keyPos => $keyValues) { foreach($keyValues as $key => $value) { if(Text::endsWith($word, $key)) { $morphedWord = substr($word, 0, -strlen($key)).$value; $r = $this->getLemma($morphedWord, $keyPos); if(!empty($r)) { $found += array_map(function($lemma){ return $lemma->getWord();}, $r); return $found[0]; } } } } if(empty($found)) { return ""; } return $found[0]; }
php
public function getMorph($word, $pos = '') { if(mb_strlen($word) < 3) { return ""; } $searchForFuncWithPos = function(ExceptionMap $exceptionMap) use($word, $pos) { return $exceptionMap->getPos() === $pos && in_array($word, $exceptionMap->getExceptionList()); }; $searchForFuncWithoutPos = function(ExceptionMap $exceptionMap) use($word) { return in_array($word, $exceptionMap->getExceptionList()); }; $found = []; if(!empty($pos)) { $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithPos); } else { $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithoutPos); } // found a match in the exceptions data if(!empty($found)) { return array_values($found)[0]->getTarget(); } foreach($this->getMorphilogicalSubstitutions() as $keyPos => $keyValues) { foreach($keyValues as $key => $value) { if(Text::endsWith($word, $key)) { $morphedWord = substr($word, 0, -strlen($key)).$value; $r = $this->getLemma($morphedWord, $keyPos); if(!empty($r)) { $found += array_map(function($lemma){ return $lemma->getWord();}, $r); return $found[0]; } } } } if(empty($found)) { return ""; } return $found[0]; }
[ "public", "function", "getMorph", "(", "$", "word", ",", "$", "pos", "=", "''", ")", "{", "if", "(", "mb_strlen", "(", "$", "word", ")", "<", "3", ")", "{", "return", "\"\"", ";", "}", "$", "searchForFuncWithPos", "=", "function", "(", "ExceptionMap"...
Concept taken from nltk Find a possible base form for the given form, with the given part of speech, by checking WordNet's list of exceptional forms, and by recursively stripping affixes for this part of speech until a form in WordNet is found. @todo improve the algorithm, it is really slow @param string $word @param string|null $pos @return string return the base word
[ "Concept", "taken", "from", "nltk", "Find", "a", "possible", "base", "form", "for", "the", "given", "form", "with", "the", "given", "part", "of", "speech", "by", "checking", "WordNet", "s", "list", "of", "exceptional", "forms", "and", "by", "recursively", ...
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Indexes/WordnetIndex.php#L104-L153
yooper/php-text-analysis
src/Corpus/ImportCorpus.php
ImportCorpus.getWords
public function getWords($fileId = null, $tokenizer = null) { if(!$tokenizer) { $tokenizer = new GeneralTokenizer(); } $fileIds = []; if(empty($fileId)) { $fileIds = $this->getFileIds(); } else { $fileIds = [$fileId]; } $words = []; foreach($fileIds as $filename ) { $content = file_get_contents($this->getPackage()->getInstallationPath().$filename); $words = array_merge($words, $tokenizer->tokenize($content)); unset($content); } return $words; }
php
public function getWords($fileId = null, $tokenizer = null) { if(!$tokenizer) { $tokenizer = new GeneralTokenizer(); } $fileIds = []; if(empty($fileId)) { $fileIds = $this->getFileIds(); } else { $fileIds = [$fileId]; } $words = []; foreach($fileIds as $filename ) { $content = file_get_contents($this->getPackage()->getInstallationPath().$filename); $words = array_merge($words, $tokenizer->tokenize($content)); unset($content); } return $words; }
[ "public", "function", "getWords", "(", "$", "fileId", "=", "null", ",", "$", "tokenizer", "=", "null", ")", "{", "if", "(", "!", "$", "tokenizer", ")", "{", "$", "tokenizer", "=", "new", "GeneralTokenizer", "(", ")", ";", "}", "$", "fileIds", "=", ...
Return an array of tokenized words @param string|null $fileId @param \TextAnalysis\Tokenizers\TokenizerAbstract @return array
[ "Return", "an", "array", "of", "tokenized", "words" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Corpus/ImportCorpus.php#L46-L66
yooper/php-text-analysis
src/Corpus/ImportCorpus.php
ImportCorpus.getRaw
public function getRaw($fileId = null) { // does nothing with the text $lamdaFunction = function($text){ return [$text]; }; return $this->getWords($fileId, new LambdaTokenizer($lamdaFunction)); }
php
public function getRaw($fileId = null) { // does nothing with the text $lamdaFunction = function($text){ return [$text]; }; return $this->getWords($fileId, new LambdaTokenizer($lamdaFunction)); }
[ "public", "function", "getRaw", "(", "$", "fileId", "=", "null", ")", "{", "// does nothing with the text", "$", "lamdaFunction", "=", "function", "(", "$", "text", ")", "{", "return", "[", "$", "text", "]", ";", "}", ";", "return", "$", "this", "->", ...
Each array element is the text of the selected file loaded file, see getWords @param $fileId @return array of strings
[ "Each", "array", "element", "is", "the", "text", "of", "the", "selected", "file", "loaded", "file", "see", "getWords" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Corpus/ImportCorpus.php#L83-L90
yooper/php-text-analysis
src/Indexes/TfIdf.php
TfIdf.getTermFrequency
public function getTermFrequency(DocumentAbstract $document, $token, $mode = 1) { $freqDist = new FreqDist($document->getDocumentData()); $keyValuesByWeight = $freqDist->getKeyValuesByFrequency(); //The token does not exist in the document if(!isset($keyValuesByWeight[$token])) { return 0; } switch($mode) { case self::BOOLEAN_MODE: //a test was already performed if the token exists in the document //just return true return 1; case self::LOGARITHMIC_MODE: return log($keyValuesByWeight[$token]+1); case self::AUGMENTED_MODE: //FreqDist getKeyValuesByFrequency is already sorted //in ascending order $maxFrequency = current($keyValuesByWeight); return 0.5 + (0.5 * $keyValuesByWeight[$token]) / $maxFrequency; case self::FREQUENCY_MODE: default: return $keyValuesByWeight[$token]; } }
php
public function getTermFrequency(DocumentAbstract $document, $token, $mode = 1) { $freqDist = new FreqDist($document->getDocumentData()); $keyValuesByWeight = $freqDist->getKeyValuesByFrequency(); //The token does not exist in the document if(!isset($keyValuesByWeight[$token])) { return 0; } switch($mode) { case self::BOOLEAN_MODE: //a test was already performed if the token exists in the document //just return true return 1; case self::LOGARITHMIC_MODE: return log($keyValuesByWeight[$token]+1); case self::AUGMENTED_MODE: //FreqDist getKeyValuesByFrequency is already sorted //in ascending order $maxFrequency = current($keyValuesByWeight); return 0.5 + (0.5 * $keyValuesByWeight[$token]) / $maxFrequency; case self::FREQUENCY_MODE: default: return $keyValuesByWeight[$token]; } }
[ "public", "function", "getTermFrequency", "(", "DocumentAbstract", "$", "document", ",", "$", "token", ",", "$", "mode", "=", "1", ")", "{", "$", "freqDist", "=", "new", "FreqDist", "(", "$", "document", "->", "getDocumentData", "(", ")", ")", ";", "$", ...
Get the term frequency @param DocumentAbstract $document - the document to evaluate @param string $token The token to look for @param int $mode The type of term frequency to use @return int|float
[ "Get", "the", "term", "frequency" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Indexes/TfIdf.php#L76-L105
yooper/php-text-analysis
src/Indexes/TfIdf.php
TfIdf.getTfIdf
public function getTfIdf(DocumentAbstract $document, $token, $mode = 1) { return $this->getTermFrequency($document, $token, $mode) * $this->getIdf($token); }
php
public function getTfIdf(DocumentAbstract $document, $token, $mode = 1) { return $this->getTermFrequency($document, $token, $mode) * $this->getIdf($token); }
[ "public", "function", "getTfIdf", "(", "DocumentAbstract", "$", "document", ",", "$", "token", ",", "$", "mode", "=", "1", ")", "{", "return", "$", "this", "->", "getTermFrequency", "(", "$", "document", ",", "$", "token", ",", "$", "mode", ")", "*", ...
Get the term frequency @param DocumentAbstract $document - the document to evaluate @param string $token The token to look for @param int $mode The type of term frequency to use @return float
[ "Get", "the", "term", "frequency" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Indexes/TfIdf.php#L114-L117
yooper/php-text-analysis
src/Tokenizers/TwitterTokenizer.php
TwitterTokenizer.getRegexes
public function getRegexes() : array { return [ $this->getPhoneNumbers(), $this->getUrls(), $this->getEmoticons(), $this->getHashTags(), $this->getAsciiArrows(), $this->getUsernames(), $this->getHashTags(), $this->getWordsWith(), $this->getNumbers(), $this->getWordsWithout(), $this->getEllipsisDots(), $this->getEverythingElse() ]; }
php
public function getRegexes() : array { return [ $this->getPhoneNumbers(), $this->getUrls(), $this->getEmoticons(), $this->getHashTags(), $this->getAsciiArrows(), $this->getUsernames(), $this->getHashTags(), $this->getWordsWith(), $this->getNumbers(), $this->getWordsWithout(), $this->getEllipsisDots(), $this->getEverythingElse() ]; }
[ "public", "function", "getRegexes", "(", ")", ":", "array", "{", "return", "[", "$", "this", "->", "getPhoneNumbers", "(", ")", ",", "$", "this", "->", "getUrls", "(", ")", ",", "$", "this", "->", "getEmoticons", "(", ")", ",", "$", "this", "->", "...
Return an array of regexes, ordered by priority
[ "Return", "an", "array", "of", "regexes", "ordered", "by", "priority" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Tokenizers/TwitterTokenizer.php#L25-L41
yooper/php-text-analysis
src/Tokenizers/TwitterTokenizer.php
TwitterTokenizer.getUrls
public function getUrls() : string { $regex = '((https?|ftp)://)?'; // SCHEME $regex .= '([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?'; // User and Pass $regex .= '([a-z0-9\-\.]*)\.(([a-z]{2,4})|([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3})))'; // Host or IP $regex .= "(:[0-9]{2,5})?"; // Port $regex .= '(/([a-z0-9+$_%-]\.?)+)*/?'; // Path $regex .= '(\?[a-z+&\$_.-][a-z0-9;:@&%=+/$_.-]*)?'; // GET Query $regex .= '(#[a-z_.-][a-z0-9+$%_.-]*)?'; // Anchor return $regex; }
php
public function getUrls() : string { $regex = '((https?|ftp)://)?'; // SCHEME $regex .= '([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?'; // User and Pass $regex .= '([a-z0-9\-\.]*)\.(([a-z]{2,4})|([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3})))'; // Host or IP $regex .= "(:[0-9]{2,5})?"; // Port $regex .= '(/([a-z0-9+$_%-]\.?)+)*/?'; // Path $regex .= '(\?[a-z+&\$_.-][a-z0-9;:@&%=+/$_.-]*)?'; // GET Query $regex .= '(#[a-z_.-][a-z0-9+$%_.-]*)?'; // Anchor return $regex; }
[ "public", "function", "getUrls", "(", ")", ":", "string", "{", "$", "regex", "=", "'((https?|ftp)://)?'", ";", "// SCHEME", "$", "regex", ".=", "'([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?'", ";", "// User and Pass", "$", "regex", ".=", "'([a-z0-9\\-\\.]*)\\...
Taken from https://stackoverflow.com/questions/6427530/regular-expression-pattern-to-match-url-with-or-without-http-www @return string
[ "Taken", "from", "https", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "6427530", "/", "regular", "-", "expression", "-", "pattern", "-", "to", "-", "match", "-", "url", "-", "with", "-", "or", "-", "without", "-", "http", "-", "www...
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Tokenizers/TwitterTokenizer.php#L127-L137
yooper/php-text-analysis
src/Analysis/Keywords/Rake.php
Rake.getPhrases
public function getPhrases() { $phrases = []; for($index = $this->nGramSize; $index >= 2; $index--) { $phrases = array_merge($phrases, NGramFactory::create($this->getTokens(), $index)); } // you cannot use a phrase if it is a substring of a longer phrase // we must exclude all of the substring phrases $add = []; $remove = []; foreach($phrases as $phrase) { if(isset($remove[$phrase])) { continue; } elseif (!isset($add[$phrase])) { $add[$phrase] = true; // remove the suffix word $remove[substr($phrase, 0, strrpos($phrase," "))] = true; //remove the prefix $remove[substr($phrase, strpos($phrase," ")+1)] = true; } } return array_keys($add); }
php
public function getPhrases() { $phrases = []; for($index = $this->nGramSize; $index >= 2; $index--) { $phrases = array_merge($phrases, NGramFactory::create($this->getTokens(), $index)); } // you cannot use a phrase if it is a substring of a longer phrase // we must exclude all of the substring phrases $add = []; $remove = []; foreach($phrases as $phrase) { if(isset($remove[$phrase])) { continue; } elseif (!isset($add[$phrase])) { $add[$phrase] = true; // remove the suffix word $remove[substr($phrase, 0, strrpos($phrase," "))] = true; //remove the prefix $remove[substr($phrase, strpos($phrase," ")+1)] = true; } } return array_keys($add); }
[ "public", "function", "getPhrases", "(", ")", "{", "$", "phrases", "=", "[", "]", ";", "for", "(", "$", "index", "=", "$", "this", "->", "nGramSize", ";", "$", "index", ">=", "2", ";", "$", "index", "--", ")", "{", "$", "phrases", "=", "array_mer...
Get all the possible phrases @return array
[ "Get", "all", "the", "possible", "phrases" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Analysis/Keywords/Rake.php#L68-L94
yooper/php-text-analysis
src/Stemmers/RegexStemmer.php
RegexStemmer.stem
public function stem($token) { if(strlen($token) < $this->minimumTokenLength) { return $token; } return preg_replace("/".$this->regexExpression."/i", '', $token); }
php
public function stem($token) { if(strlen($token) < $this->minimumTokenLength) { return $token; } return preg_replace("/".$this->regexExpression."/i", '', $token); }
[ "public", "function", "stem", "(", "$", "token", ")", "{", "if", "(", "strlen", "(", "$", "token", ")", "<", "$", "this", "->", "minimumTokenLength", ")", "{", "return", "$", "token", ";", "}", "return", "preg_replace", "(", "\"/\"", ".", "$", "this"...
Return a stemmed word @param string $token @return string
[ "Return", "a", "stemmed", "word" ]
train
https://github.com/yooper/php-text-analysis/blob/a0332ed4ed76bcd9fe280f82f519fa9ce8ab20c4/src/Stemmers/RegexStemmer.php#L27-L33
dermatthes/text-template
src/TextTemplate.php
TextTemplate.addFunctionClass
public function addFunctionClass ($obj) { $ref = new \ReflectionObject($obj); foreach ($ref->getMethods() as $curMethod) { if ( ! $curMethod->isPublic()) continue; $this->addFunction($curMethod->getName(), [$obj, $curMethod->getName()]); } return $this; }
php
public function addFunctionClass ($obj) { $ref = new \ReflectionObject($obj); foreach ($ref->getMethods() as $curMethod) { if ( ! $curMethod->isPublic()) continue; $this->addFunction($curMethod->getName(), [$obj, $curMethod->getName()]); } return $this; }
[ "public", "function", "addFunctionClass", "(", "$", "obj", ")", "{", "$", "ref", "=", "new", "\\", "ReflectionObject", "(", "$", "obj", ")", ";", "foreach", "(", "$", "ref", "->", "getMethods", "(", ")", "as", "$", "curMethod", ")", "{", "if", "(", ...
Register all public Functions from an Object @param \stdClass $obj @return $this
[ "Register", "all", "public", "Functions", "from", "an", "Object" ]
train
https://github.com/dermatthes/text-template/blob/5ab7b350f4356621e2e26ad06e1265aaec162520/src/TextTemplate.php#L138-L146
dermatthes/text-template
src/TextTemplate.php
TextTemplate._replaceNestingLevels
public function _replaceNestingLevels ($input) { $indexCounter = 0; $nestingIndex = []; $blockTags = array_keys($this->sections); $blockTags[] = "if"; $blockTags[] = "for"; $lines = explode("\n", $input); for ($li=0; $li < count ($lines); $li++) { $lines[$li] = preg_replace_callback('/\{(?!=)\s*(\/?)\s*([a-z0-9\_]+)(.*?)\}/im', function ($matches) use (&$nestingIndex, &$indexCounter, &$li, $blockTags) { $slash = $matches[1]; $tag = $matches[2]; $rest = $matches[3]; if ($tag == "else" || $tag == "elseif"){ if ( ! isset ($nestingIndex["if"])) throw new TemplateParsingException("Line {$li}: 'if' Opening tag not found for else/elseif tag: '{$matches[0]}'"); if (count ($nestingIndex["if"]) == 0) throw new TemplateParsingException("Line {$li}: Nesting level does not match for closing tag: '{$matches[0]}'"); $curIndex = $nestingIndex["if"][count ($nestingIndex["if"])-1]; $out = "{" . $tag . $curIndex[0] . rtrim($rest) . "}"; return $out; } if ($slash == "" && in_array($tag, $blockTags)) { if ( ! isset ($nestingIndex[$tag])) $nestingIndex[$tag] = []; $nestingIndex[$tag][] = [$indexCounter, $li]; $out = "{" . $tag . $indexCounter . rtrim($rest) . "}"; $indexCounter++; return $out; } else if ($slash == "/") { if ( ! isset ($nestingIndex[$tag])) { if ( ! isset ($this->sections[$tag]) && ! in_array($tag, ["if", "for"])) throw new TemplateParsingException("Line {$li}: No callback registred for section {{$tag}}{/{$tag}}"); throw new TemplateParsingException( "Line {$li}: Opening tag not found for closing tag: '{$matches[0]}'" ); } if (count ($nestingIndex[$tag]) == 0) throw new TemplateParsingException("Line {$li}: Nesting level does not match for closing tag: '{$matches[0]}'"); $curIndex = array_pop($nestingIndex[$tag]); return "{/" . $tag . $curIndex[0] . "}"; } else { return $matches[0]; // ignore - is Function } }, $lines[$li] ); } foreach ($nestingIndex as $tag => $curNestingIndex) { if (count ($curNestingIndex) > 0) throw new TemplateParsingException("Unclosed tag '{$tag}' opened in line {$curNestingIndex[0][1]} "); } return implode ("\n", $lines); }
php
public function _replaceNestingLevels ($input) { $indexCounter = 0; $nestingIndex = []; $blockTags = array_keys($this->sections); $blockTags[] = "if"; $blockTags[] = "for"; $lines = explode("\n", $input); for ($li=0; $li < count ($lines); $li++) { $lines[$li] = preg_replace_callback('/\{(?!=)\s*(\/?)\s*([a-z0-9\_]+)(.*?)\}/im', function ($matches) use (&$nestingIndex, &$indexCounter, &$li, $blockTags) { $slash = $matches[1]; $tag = $matches[2]; $rest = $matches[3]; if ($tag == "else" || $tag == "elseif"){ if ( ! isset ($nestingIndex["if"])) throw new TemplateParsingException("Line {$li}: 'if' Opening tag not found for else/elseif tag: '{$matches[0]}'"); if (count ($nestingIndex["if"]) == 0) throw new TemplateParsingException("Line {$li}: Nesting level does not match for closing tag: '{$matches[0]}'"); $curIndex = $nestingIndex["if"][count ($nestingIndex["if"])-1]; $out = "{" . $tag . $curIndex[0] . rtrim($rest) . "}"; return $out; } if ($slash == "" && in_array($tag, $blockTags)) { if ( ! isset ($nestingIndex[$tag])) $nestingIndex[$tag] = []; $nestingIndex[$tag][] = [$indexCounter, $li]; $out = "{" . $tag . $indexCounter . rtrim($rest) . "}"; $indexCounter++; return $out; } else if ($slash == "/") { if ( ! isset ($nestingIndex[$tag])) { if ( ! isset ($this->sections[$tag]) && ! in_array($tag, ["if", "for"])) throw new TemplateParsingException("Line {$li}: No callback registred for section {{$tag}}{/{$tag}}"); throw new TemplateParsingException( "Line {$li}: Opening tag not found for closing tag: '{$matches[0]}'" ); } if (count ($nestingIndex[$tag]) == 0) throw new TemplateParsingException("Line {$li}: Nesting level does not match for closing tag: '{$matches[0]}'"); $curIndex = array_pop($nestingIndex[$tag]); return "{/" . $tag . $curIndex[0] . "}"; } else { return $matches[0]; // ignore - is Function } }, $lines[$li] ); } foreach ($nestingIndex as $tag => $curNestingIndex) { if (count ($curNestingIndex) > 0) throw new TemplateParsingException("Unclosed tag '{$tag}' opened in line {$curNestingIndex[0][1]} "); } return implode ("\n", $lines); }
[ "public", "function", "_replaceNestingLevels", "(", "$", "input", ")", "{", "$", "indexCounter", "=", "0", ";", "$", "nestingIndex", "=", "[", "]", ";", "$", "blockTags", "=", "array_keys", "(", "$", "this", "->", "sections", ")", ";", "$", "blockTags", ...
Tag-Nesting is done by initially adding an index to both the opening and the closing tag. (By the way some cleanup is done) Example {if xyz} {/if} Becomes: {if0 xyz} {/if0} This trick makes it possible to add tag nesting functionality @param $input @return mixed @throws \Exception
[ "Tag", "-", "Nesting", "is", "done", "by", "initially", "adding", "an", "index", "to", "both", "the", "opening", "and", "the", "closing", "tag", ".", "(", "By", "the", "way", "some", "cleanup", "is", "done", ")" ]
train
https://github.com/dermatthes/text-template/blob/5ab7b350f4356621e2e26ad06e1265aaec162520/src/TextTemplate.php#L191-L249
dermatthes/text-template
src/TextTemplate.php
TextTemplate.apply
public function apply ($params, $softFail=TRUE, &$context=[]) { $text = $this->mTemplateText; $context = $params; $text = $this->_removeComments($text); $text = $this->_replaceNestingLevels($text); $text = $this->_replaceElseIf($text); $text = $this->_removeWhitespace($text); $result = $this->_parseBlock($context, $text, $softFail); return $result; }
php
public function apply ($params, $softFail=TRUE, &$context=[]) { $text = $this->mTemplateText; $context = $params; $text = $this->_removeComments($text); $text = $this->_replaceNestingLevels($text); $text = $this->_replaceElseIf($text); $text = $this->_removeWhitespace($text); $result = $this->_parseBlock($context, $text, $softFail); return $result; }
[ "public", "function", "apply", "(", "$", "params", ",", "$", "softFail", "=", "TRUE", ",", "&", "$", "context", "=", "[", "]", ")", "{", "$", "text", "=", "$", "this", "->", "mTemplateText", ";", "$", "context", "=", "$", "params", ";", "$", "tex...
Parse Tokens in Text (Search for $(name.subname.subname)) of @throws TemplateParsingException @return string
[ "Parse", "Tokens", "in", "Text", "(", "Search", "for", "$", "(", "name", ".", "subname", ".", "subname", "))", "of" ]
train
https://github.com/dermatthes/text-template/blob/5ab7b350f4356621e2e26ad06e1265aaec162520/src/TextTemplate.php#L652-L667
preprocess/pre-plugin
source/Composer/Plugin.php
Plugin.onPreAutoloadDump
public function onPreAutoloadDump(Event $event) { $basePath = $this->getBasePath($event); $lockPath = "{$basePath}/pre.lock"; $shouldOptimize = $this->shouldOptimize($event); if ($shouldOptimize) { file_put_contents($lockPath, time()); if (!file_exists("{$basePath}/vendor/autoload.php")) { return; } require_once "{$basePath}/vendor/autoload.php"; $directory = new RecursiveDirectoryIterator($basePath); $files = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST ); foreach ($files as $file) { if (stripos($file, "{$basePath}/vendor") === 0) { continue; } if ($file->getExtension() !== "pre") { continue; } $pre = $file->getPathname(); $php = preg_replace("/pre$/", "php", $pre); compile( $pre, $php, $format = true, $comment = false ); } } else { if (file_exists($lockPath)) { unlink($basePath . "/pre.lock"); } } }
php
public function onPreAutoloadDump(Event $event) { $basePath = $this->getBasePath($event); $lockPath = "{$basePath}/pre.lock"; $shouldOptimize = $this->shouldOptimize($event); if ($shouldOptimize) { file_put_contents($lockPath, time()); if (!file_exists("{$basePath}/vendor/autoload.php")) { return; } require_once "{$basePath}/vendor/autoload.php"; $directory = new RecursiveDirectoryIterator($basePath); $files = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST ); foreach ($files as $file) { if (stripos($file, "{$basePath}/vendor") === 0) { continue; } if ($file->getExtension() !== "pre") { continue; } $pre = $file->getPathname(); $php = preg_replace("/pre$/", "php", $pre); compile( $pre, $php, $format = true, $comment = false ); } } else { if (file_exists($lockPath)) { unlink($basePath . "/pre.lock"); } } }
[ "public", "function", "onPreAutoloadDump", "(", "Event", "$", "event", ")", "{", "$", "basePath", "=", "$", "this", "->", "getBasePath", "(", "$", "event", ")", ";", "$", "lockPath", "=", "\"{$basePath}/pre.lock\"", ";", "$", "shouldOptimize", "=", "$", "t...
Preprocesses all files if the autoloader should be optimized. @param Event $event
[ "Preprocesses", "all", "files", "if", "the", "autoloader", "should", "be", "optimized", "." ]
train
https://github.com/preprocess/pre-plugin/blob/189d12a11a2729f5f7538df7315199ce9470ff5f/source/Composer/Plugin.php#L62-L105
preprocess/pre-plugin
source/Composer/Plugin.php
Plugin.getBasePath
private function getBasePath(Event $event) { $config = $event->getComposer()->getConfig(); return realpath($config->get("vendor-dir") . "/../"); }
php
private function getBasePath(Event $event) { $config = $event->getComposer()->getConfig(); return realpath($config->get("vendor-dir") . "/../"); }
[ "private", "function", "getBasePath", "(", "Event", "$", "event", ")", "{", "$", "config", "=", "$", "event", "->", "getComposer", "(", ")", "->", "getConfig", "(", ")", ";", "return", "realpath", "(", "$", "config", "->", "get", "(", "\"vendor-dir\"", ...
Finds the base application path. @param Event $event @return string
[ "Finds", "the", "base", "application", "path", "." ]
train
https://github.com/preprocess/pre-plugin/blob/189d12a11a2729f5f7538df7315199ce9470ff5f/source/Composer/Plugin.php#L114-L118
preprocess/pre-plugin
source/Composer/Plugin.php
Plugin.shouldOptimize
private function shouldOptimize(Event $event) { $io = $event->getIO(); // I will surely burn for this. $class = new ReflectionClass(ConsoleIO::class); $property = $class->getProperty("input"); $property->setAccessible(true); $input = $property->getValue($io); if ($input->hasOption("optimize")) { return $input->getOption("optimize"); } if ($input->hasOption("optimize-autoloader")) { return $input->getOption("optimize-autoloader"); } return false; }
php
private function shouldOptimize(Event $event) { $io = $event->getIO(); // I will surely burn for this. $class = new ReflectionClass(ConsoleIO::class); $property = $class->getProperty("input"); $property->setAccessible(true); $input = $property->getValue($io); if ($input->hasOption("optimize")) { return $input->getOption("optimize"); } if ($input->hasOption("optimize-autoloader")) { return $input->getOption("optimize-autoloader"); } return false; }
[ "private", "function", "shouldOptimize", "(", "Event", "$", "event", ")", "{", "$", "io", "=", "$", "event", "->", "getIO", "(", ")", ";", "// I will surely burn for this.", "$", "class", "=", "new", "ReflectionClass", "(", "ConsoleIO", "::", "class", ")", ...
Checks whether the autoloader should be optimized, based on --optimize / --optimize-autoloader command line options. @param Event $event @return bool
[ "Checks", "whether", "the", "autoloader", "should", "be", "optimized", "based", "on", "--", "optimize", "/", "--", "optimize", "-", "autoloader", "command", "line", "options", "." ]
train
https://github.com/preprocess/pre-plugin/blob/189d12a11a2729f5f7538df7315199ce9470ff5f/source/Composer/Plugin.php#L128-L149
spatie/laravel-html
src/Elements/Element.php
Element.withTag
public static function withTag($tag) { $element = (new ReflectionClass(static::class))->newInstanceWithoutConstructor(); $element->tag = $tag; $element->attributes = new Attributes(); $element->children = new Collection(); return $element; }
php
public static function withTag($tag) { $element = (new ReflectionClass(static::class))->newInstanceWithoutConstructor(); $element->tag = $tag; $element->attributes = new Attributes(); $element->children = new Collection(); return $element; }
[ "public", "static", "function", "withTag", "(", "$", "tag", ")", "{", "$", "element", "=", "(", "new", "ReflectionClass", "(", "static", "::", "class", ")", ")", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "element", "->", "tag", "=", "$",...
@param string $tag @return static
[ "@param", "string", "$tag" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Elements/Element.php#L17-L26
spatie/laravel-html
src/Html.php
Html.a
public function a($href = null, $contents = null) { return A::create() ->attributeIf($href, 'href', $href) ->html($contents); }
php
public function a($href = null, $contents = null) { return A::create() ->attributeIf($href, 'href', $href) ->html($contents); }
[ "public", "function", "a", "(", "$", "href", "=", "null", ",", "$", "contents", "=", "null", ")", "{", "return", "A", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "href", ",", "'href'", ",", "$", "href", ")", "->", "html", "(", "$", ...
@param string|null $href @param string|null $text @return \Spatie\Html\Elements\A
[ "@param", "string|null", "$href", "@param", "string|null", "$text" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L48-L53
spatie/laravel-html
src/Html.php
Html.button
public function button($contents = null, $type = null, $name = '') { return Button::create() ->attributeIf($type, 'type', $type) ->attributeIf($name, 'name', $this->fieldName($name)) ->html($contents); }
php
public function button($contents = null, $type = null, $name = '') { return Button::create() ->attributeIf($type, 'type', $type) ->attributeIf($name, 'name', $this->fieldName($name)) ->html($contents); }
[ "public", "function", "button", "(", "$", "contents", "=", "null", ",", "$", "type", "=", "null", ",", "$", "name", "=", "''", ")", "{", "return", "Button", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "type", ",", "'type'", ",", "$", ...
@param string|null $type @param string|null $text @return \Spatie\Html\Elements\Button
[ "@param", "string|null", "$type", "@param", "string|null", "$text" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L73-L79
spatie/laravel-html
src/Html.php
Html.class
public function class($classes): Htmlable { if ($classes instanceof Collection) { $classes = $classes->toArray(); } $attributes = new Attributes(); $attributes->addClass($classes); return new HtmlString( $attributes->render() ); }
php
public function class($classes): Htmlable { if ($classes instanceof Collection) { $classes = $classes->toArray(); } $attributes = new Attributes(); $attributes->addClass($classes); return new HtmlString( $attributes->render() ); }
[ "public", "function", "class", "(", "$", "classes", ")", ":", "Htmlable", "{", "if", "(", "$", "classes", "instanceof", "Collection", ")", "{", "$", "classes", "=", "$", "classes", "->", "toArray", "(", ")", ";", "}", "$", "attributes", "=", "new", "...
@param \Illuminate\Support\Collection|iterable|string $classes @return \Illuminate\Contracts\Support\Htmlable
[ "@param", "\\", "Illuminate", "\\", "Support", "\\", "Collection|iterable|string", "$classes" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L86-L98
spatie/laravel-html
src/Html.php
Html.checkbox
public function checkbox($name = null, $checked = false, $value = '1') { return $this->input('checkbox', $name, $value) ->attributeIf(! is_null($value), 'value', $value) ->attributeIf((bool) $this->old($name, $checked), 'checked'); }
php
public function checkbox($name = null, $checked = false, $value = '1') { return $this->input('checkbox', $name, $value) ->attributeIf(! is_null($value), 'value', $value) ->attributeIf((bool) $this->old($name, $checked), 'checked'); }
[ "public", "function", "checkbox", "(", "$", "name", "=", "null", ",", "$", "checked", "=", "false", ",", "$", "value", "=", "'1'", ")", "{", "return", "$", "this", "->", "input", "(", "'checkbox'", ",", "$", "name", ",", "$", "value", ")", "->", ...
@param string|null $name @param bool $checked @param string|null $value @return \Spatie\Html\Elements\Input
[ "@param", "string|null", "$name", "@param", "bool", "$checked", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L107-L112
spatie/laravel-html
src/Html.php
Html.input
public function input($type = null, $name = null, $value = null) { $hasValue = $name && (! is_null($this->old($name, $value)) || ! is_null($value)); return Input::create() ->attributeIf($type, 'type', $type) ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->attributeIf($hasValue, 'value', $this->old($name, $value)); }
php
public function input($type = null, $name = null, $value = null) { $hasValue = $name && (! is_null($this->old($name, $value)) || ! is_null($value)); return Input::create() ->attributeIf($type, 'type', $type) ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->attributeIf($hasValue, 'value', $this->old($name, $value)); }
[ "public", "function", "input", "(", "$", "type", "=", "null", ",", "$", "name", "=", "null", ",", "$", "value", "=", "null", ")", "{", "$", "hasValue", "=", "$", "name", "&&", "(", "!", "is_null", "(", "$", "this", "->", "old", "(", "$", "name"...
@param string|null $type @param string|null $name @param string|null $value @return \Spatie\Html\Elements\Input
[ "@param", "string|null", "$type", "@param", "string|null", "$name", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L174-L183
spatie/laravel-html
src/Html.php
Html.fieldset
public function fieldset($legend = null) { return $legend ? Fieldset::create()->legend($legend) : Fieldset::create(); }
php
public function fieldset($legend = null) { return $legend ? Fieldset::create()->legend($legend) : Fieldset::create(); }
[ "public", "function", "fieldset", "(", "$", "legend", "=", "null", ")", "{", "return", "$", "legend", "?", "Fieldset", "::", "create", "(", ")", "->", "legend", "(", "$", "legend", ")", ":", "Fieldset", "::", "create", "(", ")", ";", "}" ]
@param \Spatie\Html\HtmlElement|string|null $legend @return \Spatie\Html\Elements\Fieldset
[ "@param", "\\", "Spatie", "\\", "Html", "\\", "HtmlElement|string|null", "$legend" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L190-L195
spatie/laravel-html
src/Html.php
Html.form
public function form($method = 'POST', $action = null) { $method = strtoupper($method); $form = Form::create(); // If Laravel needs to spoof the form's method, we'll append a hidden // field containing the actual method if (in_array($method, ['DELETE', 'PATCH', 'PUT'])) { $form = $form->addChild($this->hidden('_method')->value($method)); } // On any other method that get, the form needs a CSRF token if ($method !== 'GET') { $form = $form->addChild($this->token()); } return $form ->method($method === 'GET' ? 'GET' : 'POST') ->attributeIf($action, 'action', $action); }
php
public function form($method = 'POST', $action = null) { $method = strtoupper($method); $form = Form::create(); // If Laravel needs to spoof the form's method, we'll append a hidden // field containing the actual method if (in_array($method, ['DELETE', 'PATCH', 'PUT'])) { $form = $form->addChild($this->hidden('_method')->value($method)); } // On any other method that get, the form needs a CSRF token if ($method !== 'GET') { $form = $form->addChild($this->token()); } return $form ->method($method === 'GET' ? 'GET' : 'POST') ->attributeIf($action, 'action', $action); }
[ "public", "function", "form", "(", "$", "method", "=", "'POST'", ",", "$", "action", "=", "null", ")", "{", "$", "method", "=", "strtoupper", "(", "$", "method", ")", ";", "$", "form", "=", "Form", "::", "create", "(", ")", ";", "// If Laravel needs ...
@param string $method @param string|null $action @return \Spatie\Html\Elements\Form
[ "@param", "string", "$method", "@param", "string|null", "$action" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L203-L222
spatie/laravel-html
src/Html.php
Html.img
public function img($src = null, $alt = null) { return Img::create() ->attributeIf($src, 'src', $src) ->attributeIf($alt, 'alt', $alt); }
php
public function img($src = null, $alt = null) { return Img::create() ->attributeIf($src, 'src', $src) ->attributeIf($alt, 'alt', $alt); }
[ "public", "function", "img", "(", "$", "src", "=", "null", ",", "$", "alt", "=", "null", ")", "{", "return", "Img", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "src", ",", "'src'", ",", "$", "src", ")", "->", "attributeIf", "(", "$",...
@param string|null $src @param string|null $alt @return \Spatie\Html\Elements\Img
[ "@param", "string|null", "$src", "@param", "string|null", "$alt" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L241-L246
spatie/laravel-html
src/Html.php
Html.label
public function label($contents = null, $for = null) { return Label::create() ->attributeIf($for, 'for', $this->fieldName($for)) ->children($contents); }
php
public function label($contents = null, $for = null) { return Label::create() ->attributeIf($for, 'for', $this->fieldName($for)) ->children($contents); }
[ "public", "function", "label", "(", "$", "contents", "=", "null", ",", "$", "for", "=", "null", ")", "{", "return", "Label", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "for", ",", "'for'", ",", "$", "this", "->", "fieldName", "(", "$"...
@param \Spatie\Html\HtmlElement|iterable|string|null $contents @param string|null $for @return \Spatie\Html\Elements\Label
[ "@param", "\\", "Spatie", "\\", "Html", "\\", "HtmlElement|iterable|string|null", "$contents", "@param", "string|null", "$for" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L254-L259
spatie/laravel-html
src/Html.php
Html.multiselect
public function multiselect($name = null, $options = [], $value = null) { return Select::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->options($options) ->value($name ? $this->old($name, $value) : $value) ->multiple(); }
php
public function multiselect($name = null, $options = [], $value = null) { return Select::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->options($options) ->value($name ? $this->old($name, $value) : $value) ->multiple(); }
[ "public", "function", "multiselect", "(", "$", "name", "=", "null", ",", "$", "options", "=", "[", "]", ",", "$", "value", "=", "null", ")", "{", "return", "Select", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "name", ",", "'name'", ",...
@param string|null $name @param iterable $options @param string|iterable|null $value @return \Spatie\Html\Elements\Select
[ "@param", "string|null", "$name", "@param", "iterable", "$options", "@param", "string|iterable|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L289-L297
spatie/laravel-html
src/Html.php
Html.option
public function option($text = null, $value = null, $selected = false) { return Option::create() ->text($text) ->value($value) ->selectedIf($selected); }
php
public function option($text = null, $value = null, $selected = false) { return Option::create() ->text($text) ->value($value) ->selectedIf($selected); }
[ "public", "function", "option", "(", "$", "text", "=", "null", ",", "$", "value", "=", "null", ",", "$", "selected", "=", "false", ")", "{", "return", "Option", "::", "create", "(", ")", "->", "text", "(", "$", "text", ")", "->", "value", "(", "$...
@param string|null $text @param string|null $value @param bool $selected @return \Spatie\Html\Elements\Option
[ "@param", "string|null", "$text", "@param", "string|null", "$value", "@param", "bool", "$selected" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L306-L312
spatie/laravel-html
src/Html.php
Html.radio
public function radio($name = null, $checked = false, $value = null) { return $this->input('radio', $name, $value) ->attributeIf($name, 'id', $value === null ? $name : ($name.'_'.str_slug($value))) ->attributeIf(! is_null($value), 'value', $value) ->attributeIf((! is_null($value) && $this->old($name) == $value) || $checked, 'checked'); }
php
public function radio($name = null, $checked = false, $value = null) { return $this->input('radio', $name, $value) ->attributeIf($name, 'id', $value === null ? $name : ($name.'_'.str_slug($value))) ->attributeIf(! is_null($value), 'value', $value) ->attributeIf((! is_null($value) && $this->old($name) == $value) || $checked, 'checked'); }
[ "public", "function", "radio", "(", "$", "name", "=", "null", ",", "$", "checked", "=", "false", ",", "$", "value", "=", "null", ")", "{", "return", "$", "this", "->", "input", "(", "'radio'", ",", "$", "name", ",", "$", "value", ")", "->", "attr...
@param string|null $name @param bool $checked @param string|null $value @return \Spatie\Html\Elements\Input
[ "@param", "string|null", "$name", "@param", "bool", "$checked", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L331-L337
spatie/laravel-html
src/Html.php
Html.select
public function select($name = null, $options = [], $value = null) { return Select::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->options($options) ->value($name ? $this->old($name, $value) : $value); }
php
public function select($name = null, $options = [], $value = null) { return Select::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->options($options) ->value($name ? $this->old($name, $value) : $value); }
[ "public", "function", "select", "(", "$", "name", "=", "null", ",", "$", "options", "=", "[", "]", ",", "$", "value", "=", "null", ")", "{", "return", "Select", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "name", ",", "'name'", ",", ...
@param string|null $name @param iterable $options @param string|iterable|null $value @return \Spatie\Html\Elements\Select
[ "@param", "string|null", "$name", "@param", "iterable", "$options", "@param", "string|iterable|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L346-L353
spatie/laravel-html
src/Html.php
Html.file
public function file($name = null) { return File::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)); }
php
public function file($name = null) { return File::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)); }
[ "public", "function", "file", "(", "$", "name", "=", "null", ")", "{", "return", "File", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "name", ",", "'name'", ",", "$", "this", "->", "fieldName", "(", "$", "name", ")", ")", "->", "attribu...
@param string|null $name @return \Spatie\Html\Elements\File
[ "@param", "string|null", "$name" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L412-L417
spatie/laravel-html
src/Html.php
Html.textarea
public function textarea($name = null, $value = null) { return Textarea::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->value($this->old($name, $value)); }
php
public function textarea($name = null, $value = null) { return Textarea::create() ->attributeIf($name, 'name', $this->fieldName($name)) ->attributeIf($name, 'id', $this->fieldName($name)) ->value($this->old($name, $value)); }
[ "public", "function", "textarea", "(", "$", "name", "=", "null", ",", "$", "value", "=", "null", ")", "{", "return", "Textarea", "::", "create", "(", ")", "->", "attributeIf", "(", "$", "name", ",", "'name'", ",", "$", "this", "->", "fieldName", "(",...
@param string|null $name @param string|null $value @return \Spatie\Html\Elements\Textarea
[ "@param", "string|null", "$name", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L425-L431
spatie/laravel-html
src/Html.php
Html.modelForm
public function modelForm($model, $method = 'POST', $action = null): Form { $this->model($model); return $this->form($method, $action); }
php
public function modelForm($model, $method = 'POST', $action = null): Form { $this->model($model); return $this->form($method, $action); }
[ "public", "function", "modelForm", "(", "$", "model", ",", "$", "method", "=", "'POST'", ",", "$", "action", "=", "null", ")", ":", "Form", "{", "$", "this", "->", "model", "(", "$", "model", ")", ";", "return", "$", "this", "->", "form", "(", "$...
@param \ArrayAccess|array $model @param string|null $method @param string|null $action @return \Spatie\Html\Elements\Form
[ "@param", "\\", "ArrayAccess|array", "$model", "@param", "string|null", "$method", "@param", "string|null", "$action" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L463-L468
spatie/laravel-html
src/Html.php
Html.old
protected function old($name, $value = null) { if (empty($name)) { return; } // Convert array format (sth[1]) to dot notation (sth.1) $name = preg_replace('/\[(.+)\]/U', '.$1', $name); // If there's no default value provided, the html builder currently // has a model assigned and there aren't old input items, // try to retrieve a value from the model. if (empty($value) && $this->model && empty($this->request->old())) { $value = data_get($this->model, $name) ?? ''; } return $this->request->old($name, $value); }
php
protected function old($name, $value = null) { if (empty($name)) { return; } // Convert array format (sth[1]) to dot notation (sth.1) $name = preg_replace('/\[(.+)\]/U', '.$1', $name); // If there's no default value provided, the html builder currently // has a model assigned and there aren't old input items, // try to retrieve a value from the model. if (empty($value) && $this->model && empty($this->request->old())) { $value = data_get($this->model, $name) ?? ''; } return $this->request->old($name, $value); }
[ "protected", "function", "old", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", ";", "}", "// Convert array format (sth[1]) to dot notation (sth.1)", "$", "name", "=", "preg_replace",...
@param string $name @param mixed $value @return mixed
[ "@param", "string", "$name", "@param", "mixed", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Html.php#L496-L513
spatie/laravel-html
src/Elements/Select.php
Select.options
public function options($options) { return $this->addChildren($options, function ($text, $value) { if (is_array($text)) { return $this->optgroup($value, $text); } return Option::create() ->value($value) ->text($text) ->selectedIf($value === $this->value); }); }
php
public function options($options) { return $this->addChildren($options, function ($text, $value) { if (is_array($text)) { return $this->optgroup($value, $text); } return Option::create() ->value($value) ->text($text) ->selectedIf($value === $this->value); }); }
[ "public", "function", "options", "(", "$", "options", ")", "{", "return", "$", "this", "->", "addChildren", "(", "$", "options", ",", "function", "(", "$", "text", ",", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "text", ")", ")", "{",...
@param iterable $options @return static
[ "@param", "iterable", "$options" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Elements/Select.php#L56-L68
spatie/laravel-html
src/Elements/Select.php
Select.optgroup
public function optgroup($label, $options) { return Optgroup::create() ->label($label) ->addChildren($options, function ($text, $value) { return Option::create() ->value($value) ->text($text) ->selectedIf($value === $this->value); }); return $this->addChild($optgroup); }
php
public function optgroup($label, $options) { return Optgroup::create() ->label($label) ->addChildren($options, function ($text, $value) { return Option::create() ->value($value) ->text($text) ->selectedIf($value === $this->value); }); return $this->addChild($optgroup); }
[ "public", "function", "optgroup", "(", "$", "label", ",", "$", "options", ")", "{", "return", "Optgroup", "::", "create", "(", ")", "->", "label", "(", "$", "label", ")", "->", "addChildren", "(", "$", "options", ",", "function", "(", "$", "text", ",...
@param string $label @param iterable $options @return static
[ "@param", "string", "$label", "@param", "iterable", "$options" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Elements/Select.php#L76-L88
spatie/laravel-html
src/Elements/Select.php
Select.placeholder
public function placeholder($text) { return $this->prependChild( Option::create() ->value(null) ->text($text) ->selectedIf(! $this->hasSelection()) ); }
php
public function placeholder($text) { return $this->prependChild( Option::create() ->value(null) ->text($text) ->selectedIf(! $this->hasSelection()) ); }
[ "public", "function", "placeholder", "(", "$", "text", ")", "{", "return", "$", "this", "->", "prependChild", "(", "Option", "::", "create", "(", ")", "->", "value", "(", "null", ")", "->", "text", "(", "$", "text", ")", "->", "selectedIf", "(", "!",...
@param string|null $text @return static
[ "@param", "string|null", "$text" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Elements/Select.php#L95-L103
spatie/laravel-html
src/Elements/Select.php
Select.value
public function value($value = null) { $element = clone $this; $element->value = $value; $element->applyValueToOptions(); return $element; }
php
public function value($value = null) { $element = clone $this; $element->value = $value; $element->applyValueToOptions(); return $element; }
[ "public", "function", "value", "(", "$", "value", "=", "null", ")", "{", "$", "element", "=", "clone", "$", "this", ";", "$", "element", "->", "value", "=", "$", "value", ";", "$", "element", "->", "applyValueToOptions", "(", ")", ";", "return", "$",...
@param string|iterable $value @return static
[ "@param", "string|iterable", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Elements/Select.php#L118-L127
spatie/laravel-html
src/Helpers/Arr.php
Arr.getToggledValues
public static function getToggledValues($map) { return Collection::make($map)->map(function ($condition, $value) { if (is_numeric($value)) { return $condition; } return $condition ? $value : null; })->filter()->toArray(); }
php
public static function getToggledValues($map) { return Collection::make($map)->map(function ($condition, $value) { if (is_numeric($value)) { return $condition; } return $condition ? $value : null; })->filter()->toArray(); }
[ "public", "static", "function", "getToggledValues", "(", "$", "map", ")", "{", "return", "Collection", "::", "make", "(", "$", "map", ")", "->", "map", "(", "function", "(", "$", "condition", ",", "$", "value", ")", "{", "if", "(", "is_numeric", "(", ...
Return an array of enabled values. Enabled values are either: - Keys that have a truthy value; - Values that don't have keys. Example: Arr::getToggledValues(['foo' => true, 'bar' => false, 'baz']) // => ['foo', 'baz'] @param mixed $map @return array
[ "Return", "an", "array", "of", "enabled", "values", ".", "Enabled", "values", "are", "either", ":", "-", "Keys", "that", "have", "a", "truthy", "value", ";", "-", "Values", "that", "don", "t", "have", "keys", "." ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Helpers/Arr.php#L23-L32
spatie/laravel-html
src/Attributes.php
Attributes.setAttributes
public function setAttributes($attributes) { foreach ($attributes as $attribute => $value) { if ($attribute === 'class') { $this->addClass($value); continue; } if (is_int($attribute)) { $attribute = $value; $value = ''; } $this->setAttribute($attribute, (string) $value); } return $this; }
php
public function setAttributes($attributes) { foreach ($attributes as $attribute => $value) { if ($attribute === 'class') { $this->addClass($value); continue; } if (is_int($attribute)) { $attribute = $value; $value = ''; } $this->setAttribute($attribute, (string) $value); } return $this; }
[ "public", "function", "setAttributes", "(", "$", "attributes", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", "=>", "$", "value", ")", "{", "if", "(", "$", "attribute", "===", "'class'", ")", "{", "$", "this", "->", "addClass", "(...
@param iterable $attributes @return $this
[ "@param", "iterable", "$attributes" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Attributes.php#L20-L37
spatie/laravel-html
src/Attributes.php
Attributes.setAttribute
public function setAttribute($attribute, $value = null) { if ($attribute === 'class') { $this->addClass($value); return $this; } $this->attributes[$attribute] = $value; return $this; }
php
public function setAttribute($attribute, $value = null) { if ($attribute === 'class') { $this->addClass($value); return $this; } $this->attributes[$attribute] = $value; return $this; }
[ "public", "function", "setAttribute", "(", "$", "attribute", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "attribute", "===", "'class'", ")", "{", "$", "this", "->", "addClass", "(", "$", "value", ")", ";", "return", "$", "this", ";", ...
@param string $attribute @param string|null $value @return $this
[ "@param", "string", "$attribute", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Attributes.php#L45-L56
spatie/laravel-html
src/Attributes.php
Attributes.forgetAttribute
public function forgetAttribute($attribute) { if ($attribute === 'class') { $this->classes = []; return $this; } if (isset($this->attributes[$attribute])) { unset($this->attributes[$attribute]); } return $this; }
php
public function forgetAttribute($attribute) { if ($attribute === 'class') { $this->classes = []; return $this; } if (isset($this->attributes[$attribute])) { unset($this->attributes[$attribute]); } return $this; }
[ "public", "function", "forgetAttribute", "(", "$", "attribute", ")", "{", "if", "(", "$", "attribute", "===", "'class'", ")", "{", "$", "this", "->", "classes", "=", "[", "]", ";", "return", "$", "this", ";", "}", "if", "(", "isset", "(", "$", "thi...
@param string $attribute @return $this
[ "@param", "string", "$attribute" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Attributes.php#L63-L76
spatie/laravel-html
src/Attributes.php
Attributes.getAttribute
public function getAttribute($attribute, $fallback = null) { if ($attribute === 'class') { return implode(' ', $this->classes); } return $this->attributes[$attribute] ?? $fallback; }
php
public function getAttribute($attribute, $fallback = null) { if ($attribute === 'class') { return implode(' ', $this->classes); } return $this->attributes[$attribute] ?? $fallback; }
[ "public", "function", "getAttribute", "(", "$", "attribute", ",", "$", "fallback", "=", "null", ")", "{", "if", "(", "$", "attribute", "===", "'class'", ")", "{", "return", "implode", "(", "' '", ",", "$", "this", "->", "classes", ")", ";", "}", "ret...
@param string $attribute @param mixed $fallback @return mixed
[ "@param", "string", "$attribute", "@param", "mixed", "$fallback" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/Attributes.php#L84-L91
spatie/laravel-html
src/BaseElement.php
BaseElement.attribute
public function attribute($attribute, $value = null) { $element = clone $this; $element->attributes->setAttribute($attribute, (string) $value); return $element; }
php
public function attribute($attribute, $value = null) { $element = clone $this; $element->attributes->setAttribute($attribute, (string) $value); return $element; }
[ "public", "function", "attribute", "(", "$", "attribute", ",", "$", "value", "=", "null", ")", "{", "$", "element", "=", "clone", "$", "this", ";", "$", "element", "->", "attributes", "->", "setAttribute", "(", "$", "attribute", ",", "(", "string", ")"...
@param string $attribute @param string|null $value @return static
[ "@param", "string", "$attribute", "@param", "string|null", "$value" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/BaseElement.php#L50-L57
spatie/laravel-html
src/BaseElement.php
BaseElement.style
public function style($style) { if (is_array($style)) { $style = implode('; ', array_map(function ($value, $attribute) { return "{$attribute}: {$value}"; }, $style, array_keys($style))); } return $this->attribute('style', $style); }
php
public function style($style) { if (is_array($style)) { $style = implode('; ', array_map(function ($value, $attribute) { return "{$attribute}: {$value}"; }, $style, array_keys($style))); } return $this->attribute('style', $style); }
[ "public", "function", "style", "(", "$", "style", ")", "{", "if", "(", "is_array", "(", "$", "style", ")", ")", "{", "$", "style", "=", "implode", "(", "'; '", ",", "array_map", "(", "function", "(", "$", "value", ",", "$", "attribute", ")", "{", ...
@param array|string|null $style @return static
[ "@param", "array|string|null", "$style" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/BaseElement.php#L149-L158
spatie/laravel-html
src/BaseElement.php
BaseElement.addChildren
public function addChildren($children, $mapper = null) { if (is_null($children)) { return $this; } $children = $this->parseChildren($children, $mapper); $element = clone $this; $element->children = $element->children->merge($children); return $element; }
php
public function addChildren($children, $mapper = null) { if (is_null($children)) { return $this; } $children = $this->parseChildren($children, $mapper); $element = clone $this; $element->children = $element->children->merge($children); return $element; }
[ "public", "function", "addChildren", "(", "$", "children", ",", "$", "mapper", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "children", ")", ")", "{", "return", "$", "this", ";", "}", "$", "children", "=", "$", "this", "->", "parseChildren"...
@param \Spatie\Html\HtmlElement|string|iterable|null $children @param callable|null $mapper @return static
[ "@param", "\\", "Spatie", "\\", "Html", "\\", "HtmlElement|string|iterable|null", "$children", "@param", "callable|null", "$mapper" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/BaseElement.php#L177-L190
spatie/laravel-html
src/BaseElement.php
BaseElement.setChildren
public function setChildren($children, $mapper = null) { $element = clone $this; $element->children = new Collection(); return $element->addChildren($children, $mapper); }
php
public function setChildren($children, $mapper = null) { $element = clone $this; $element->children = new Collection(); return $element->addChildren($children, $mapper); }
[ "public", "function", "setChildren", "(", "$", "children", ",", "$", "mapper", "=", "null", ")", "{", "$", "element", "=", "clone", "$", "this", ";", "$", "element", "->", "children", "=", "new", "Collection", "(", ")", ";", "return", "$", "element", ...
Replace all children with an array of elements. @param \Spatie\Html\HtmlElement[] $children @param callable|null $mapper @return static
[ "Replace", "all", "children", "with", "an", "array", "of", "elements", "." ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/BaseElement.php#L239-L246
spatie/laravel-html
src/BaseElement.php
BaseElement.prependChildren
public function prependChildren($children, $mapper = null) { $children = $this->parseChildren($children, $mapper); $element = clone $this; $element->children = $children->merge($element->children); return $element; }
php
public function prependChildren($children, $mapper = null) { $children = $this->parseChildren($children, $mapper); $element = clone $this; $element->children = $children->merge($element->children); return $element; }
[ "public", "function", "prependChildren", "(", "$", "children", ",", "$", "mapper", "=", "null", ")", "{", "$", "children", "=", "$", "this", "->", "parseChildren", "(", "$", "children", ",", "$", "mapper", ")", ";", "$", "element", "=", "clone", "$", ...
@param \Spatie\Html\HtmlElement|string|iterable|null $children @param callable|null $mapper @return static
[ "@param", "\\", "Spatie", "\\", "Html", "\\", "HtmlElement|string|iterable|null", "$children", "@param", "callable|null", "$mapper" ]
train
https://github.com/spatie/laravel-html/blob/1ee56b4fad6147beab6bee02da6b8b8a704526f8/src/BaseElement.php#L254-L263
ryakad/pandoc-php
src/Pandoc/Pandoc.php
Pandoc.convert
public function convert($content, $from, $to) { if ( ! in_array($from, $this->inputFormats)) { throw new PandocException( sprintf('%s is not a valid input format for pandoc', $from) ); } if ( ! in_array($to, $this->outputFormats)) { throw new PandocException( sprintf('%s is not a valid output format for pandoc', $to) ); } file_put_contents($this->tmpFile, $content); $command = sprintf( '%s --from=%s --to=%s %s', $this->executable, $from, $to, $this->tmpFile ); exec(escapeshellcmd($command), $output); return implode("\n", $output); }
php
public function convert($content, $from, $to) { if ( ! in_array($from, $this->inputFormats)) { throw new PandocException( sprintf('%s is not a valid input format for pandoc', $from) ); } if ( ! in_array($to, $this->outputFormats)) { throw new PandocException( sprintf('%s is not a valid output format for pandoc', $to) ); } file_put_contents($this->tmpFile, $content); $command = sprintf( '%s --from=%s --to=%s %s', $this->executable, $from, $to, $this->tmpFile ); exec(escapeshellcmd($command), $output); return implode("\n", $output); }
[ "public", "function", "convert", "(", "$", "content", ",", "$", "from", ",", "$", "to", ")", "{", "if", "(", "!", "in_array", "(", "$", "from", ",", "$", "this", "->", "inputFormats", ")", ")", "{", "throw", "new", "PandocException", "(", "sprintf", ...
Run the conversion from one type to another @param string $from The type we are converting from @param string $to The type we want to convert the document to @return string
[ "Run", "the", "conversion", "from", "one", "type", "to", "another" ]
train
https://github.com/ryakad/pandoc-php/blob/1e8f9f21509d56819a60de726318218fb80042c9/src/Pandoc/Pandoc.php#L153-L180
ryakad/pandoc-php
src/Pandoc/Pandoc.php
Pandoc.runWith
public function runWith($content, $options) { $commandOptions = array(); $extFilesFormat = array( 'docx', 'odt', 'epub', 'fb2', 'pdf' ); $extFilesHtmlSlide = array( 's5', 'slidy', 'dzslides', 'slideous' ); foreach ($options as $key => $value) { if ($key == 'to' && in_array($value, $extFilesFormat)) { $commandOptions[] = '-s -S -o '.$this->tmpFile.'.'.$value; $format = $value; continue; } else if ($key == 'to' && in_array($value, $extFilesHtmlSlide)) { $commandOptions[] = '-s -t '.$value.' -o '.$this->tmpFile.'.html'; $format = 'html'; continue; } else if ($key == 'to' && $value == 'epub3') { $commandOptions[] = '-S -o '.$this->tmpFile.'.epub'; $format = 'epub'; continue; } else if ($key == 'to' && $value == 'beamer') { $commandOptions[] = '-s -t beamer -o '.$this->tmpFile.'.pdf'; $format = 'pdf'; continue; } else if ($key == 'to' && $value == 'latex') { $commandOptions[] = '-s -o '.$this->tmpFile.'.tex'; $format = 'tex'; continue; } else if ($key == 'to' && $value == 'rst') { $commandOptions[] = '-s -t rst --toc -o '.$this->tmpFile.'.text'; $format = 'text'; continue; } else if ($key == 'to' && $value == 'rtf') { $commandOptions[] = '-s -o '.$this->tmpFile.'.'.$value; $format = $value; continue; } else if ($key == 'to' && $value == 'docbook') { $commandOptions[] = '-s -S -t docbook -o '.$this->tmpFile.'.db'; $format = 'db'; continue; } else if ($key == 'to' && $value == 'context') { $commandOptions[] = '-s -t context -o '.$this->tmpFile.'.tex'; $format = 'tex'; continue; } else if ($key == 'to' && $value == 'asciidoc') { $commandOptions[] = '-s -S -t asciidoc -o '.$this->tmpFile.'.txt'; $format = 'txt'; continue; } if (null === $value) { $commandOptions[] = "--$key"; continue; } $commandOptions[] = "--$key=$value"; } file_put_contents($this->tmpFile, $content); chmod($this->tmpFile, 0777); $command = sprintf( "%s %s %s", $this->executable, implode(' ', $commandOptions), $this->tmpFile ); exec(escapeshellcmd($command), $output, $returnval); if($returnval === 0) { if (isset($format)) { return file_get_contents($this->tmpFile.'.'.$format); } else { return implode("\n", $output); } }else { throw new PandocException( sprintf('Pandoc could not convert successfully, error code: %s. Tried to run the following command: %s', $returnval, $command) ); } }
php
public function runWith($content, $options) { $commandOptions = array(); $extFilesFormat = array( 'docx', 'odt', 'epub', 'fb2', 'pdf' ); $extFilesHtmlSlide = array( 's5', 'slidy', 'dzslides', 'slideous' ); foreach ($options as $key => $value) { if ($key == 'to' && in_array($value, $extFilesFormat)) { $commandOptions[] = '-s -S -o '.$this->tmpFile.'.'.$value; $format = $value; continue; } else if ($key == 'to' && in_array($value, $extFilesHtmlSlide)) { $commandOptions[] = '-s -t '.$value.' -o '.$this->tmpFile.'.html'; $format = 'html'; continue; } else if ($key == 'to' && $value == 'epub3') { $commandOptions[] = '-S -o '.$this->tmpFile.'.epub'; $format = 'epub'; continue; } else if ($key == 'to' && $value == 'beamer') { $commandOptions[] = '-s -t beamer -o '.$this->tmpFile.'.pdf'; $format = 'pdf'; continue; } else if ($key == 'to' && $value == 'latex') { $commandOptions[] = '-s -o '.$this->tmpFile.'.tex'; $format = 'tex'; continue; } else if ($key == 'to' && $value == 'rst') { $commandOptions[] = '-s -t rst --toc -o '.$this->tmpFile.'.text'; $format = 'text'; continue; } else if ($key == 'to' && $value == 'rtf') { $commandOptions[] = '-s -o '.$this->tmpFile.'.'.$value; $format = $value; continue; } else if ($key == 'to' && $value == 'docbook') { $commandOptions[] = '-s -S -t docbook -o '.$this->tmpFile.'.db'; $format = 'db'; continue; } else if ($key == 'to' && $value == 'context') { $commandOptions[] = '-s -t context -o '.$this->tmpFile.'.tex'; $format = 'tex'; continue; } else if ($key == 'to' && $value == 'asciidoc') { $commandOptions[] = '-s -S -t asciidoc -o '.$this->tmpFile.'.txt'; $format = 'txt'; continue; } if (null === $value) { $commandOptions[] = "--$key"; continue; } $commandOptions[] = "--$key=$value"; } file_put_contents($this->tmpFile, $content); chmod($this->tmpFile, 0777); $command = sprintf( "%s %s %s", $this->executable, implode(' ', $commandOptions), $this->tmpFile ); exec(escapeshellcmd($command), $output, $returnval); if($returnval === 0) { if (isset($format)) { return file_get_contents($this->tmpFile.'.'.$format); } else { return implode("\n", $output); } }else { throw new PandocException( sprintf('Pandoc could not convert successfully, error code: %s. Tried to run the following command: %s', $returnval, $command) ); } }
[ "public", "function", "runWith", "(", "$", "content", ",", "$", "options", ")", "{", "$", "commandOptions", "=", "array", "(", ")", ";", "$", "extFilesFormat", "=", "array", "(", "'docx'", ",", "'odt'", ",", "'epub'", ",", "'fb2'", ",", "'pdf'", ")", ...
Run the pandoc command with specific options. Provides more control over what happens. You simply pass an array of key value pairs of the command options omitting the -- from the start. If you want to pass a command that takes no argument you set its value to null. @param string $content The content to run the command on @param array $options The options to use @return string The returned content
[ "Run", "the", "pandoc", "command", "with", "specific", "options", "." ]
train
https://github.com/ryakad/pandoc-php/blob/1e8f9f21509d56819a60de726318218fb80042c9/src/Pandoc/Pandoc.php#L195-L291
yadahan/laravel-authentication-log
src/Notifications/NewDevice.php
NewDevice.toMail
public function toMail($notifiable) { return (new MailMessage) ->subject(trans('authentication-log::messages.subject')) ->markdown('authentication-log::emails.new', [ 'account' => $notifiable, 'time' => $this->authenticationLog->login_at, 'ipAddress' => $this->authenticationLog->ip_address, 'browser' => $this->authenticationLog->user_agent, ]); }
php
public function toMail($notifiable) { return (new MailMessage) ->subject(trans('authentication-log::messages.subject')) ->markdown('authentication-log::emails.new', [ 'account' => $notifiable, 'time' => $this->authenticationLog->login_at, 'ipAddress' => $this->authenticationLog->ip_address, 'browser' => $this->authenticationLog->user_agent, ]); }
[ "public", "function", "toMail", "(", "$", "notifiable", ")", "{", "return", "(", "new", "MailMessage", ")", "->", "subject", "(", "trans", "(", "'authentication-log::messages.subject'", ")", ")", "->", "markdown", "(", "'authentication-log::emails.new'", ",", "[",...
Get the mail representation of the notification. @param mixed $notifiable @return \Illuminate\Notifications\Messages\MailMessage
[ "Get", "the", "mail", "representation", "of", "the", "notification", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/src/Notifications/NewDevice.php#L51-L61
yadahan/laravel-authentication-log
src/Notifications/NewDevice.php
NewDevice.toSlack
public function toSlack($notifiable) { return (new SlackMessage) ->from(config('app.name')) ->warning() ->content(trans('authentication-log::messages.content', ['app' => config('app.name')])) ->attachment(function ($attachment) use ($notifiable) { $attachment->fields([ 'Account' => $notifiable->email, 'Time' => $this->authenticationLog->login_at->toCookieString(), 'IP Address' => $this->authenticationLog->ip_address, 'Browser' => $this->authenticationLog->user_agent, ]); }); }
php
public function toSlack($notifiable) { return (new SlackMessage) ->from(config('app.name')) ->warning() ->content(trans('authentication-log::messages.content', ['app' => config('app.name')])) ->attachment(function ($attachment) use ($notifiable) { $attachment->fields([ 'Account' => $notifiable->email, 'Time' => $this->authenticationLog->login_at->toCookieString(), 'IP Address' => $this->authenticationLog->ip_address, 'Browser' => $this->authenticationLog->user_agent, ]); }); }
[ "public", "function", "toSlack", "(", "$", "notifiable", ")", "{", "return", "(", "new", "SlackMessage", ")", "->", "from", "(", "config", "(", "'app.name'", ")", ")", "->", "warning", "(", ")", "->", "content", "(", "trans", "(", "'authentication-log::mes...
Get the Slack representation of the notification. @param mixed $notifiable @return \Illuminate\Notifications\Messages\SlackMessage
[ "Get", "the", "Slack", "representation", "of", "the", "notification", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/src/Notifications/NewDevice.php#L69-L83
yadahan/laravel-authentication-log
src/Listeners/LogSuccessfulLogout.php
LogSuccessfulLogout.handle
public function handle(Logout $event) { if ($event->user) { $user = $event->user; $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); $authenticationLog = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); if (! $authenticationLog) { $authenticationLog = new AuthenticationLog([ 'ip_address' => $ip, 'user_agent' => $userAgent, ]); } $authenticationLog->logout_at = Carbon::now(); $user->authentications()->save($authenticationLog); } }
php
public function handle(Logout $event) { if ($event->user) { $user = $event->user; $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); $authenticationLog = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); if (! $authenticationLog) { $authenticationLog = new AuthenticationLog([ 'ip_address' => $ip, 'user_agent' => $userAgent, ]); } $authenticationLog->logout_at = Carbon::now(); $user->authentications()->save($authenticationLog); } }
[ "public", "function", "handle", "(", "Logout", "$", "event", ")", "{", "if", "(", "$", "event", "->", "user", ")", "{", "$", "user", "=", "$", "event", "->", "user", ";", "$", "ip", "=", "$", "this", "->", "request", "->", "ip", "(", ")", ";", ...
Handle the event. @param Logout $event @return void
[ "Handle", "the", "event", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/src/Listeners/LogSuccessfulLogout.php#L36-L55
yadahan/laravel-authentication-log
src/Console/ClearCommand.php
ClearCommand.handle
public function handle() { $this->comment('Clearing authentication log...'); $days = config('authentication-log.older'); $from = Carbon::now()->subDays($days)->format('Y-m-d H:i:s'); AuthenticationLog::where('login_at', '<', $from)->delete(); $this->info('Authentication log cleared successfully.'); }
php
public function handle() { $this->comment('Clearing authentication log...'); $days = config('authentication-log.older'); $from = Carbon::now()->subDays($days)->format('Y-m-d H:i:s'); AuthenticationLog::where('login_at', '<', $from)->delete(); $this->info('Authentication log cleared successfully.'); }
[ "public", "function", "handle", "(", ")", "{", "$", "this", "->", "comment", "(", "'Clearing authentication log...'", ")", ";", "$", "days", "=", "config", "(", "'authentication-log.older'", ")", ";", "$", "from", "=", "Carbon", "::", "now", "(", ")", "->"...
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/src/Console/ClearCommand.php#L30-L40
yadahan/laravel-authentication-log
database/migrations/2017_09_01_000000_create_authentication_log_table.php
CreateAuthenticationLogTable.up
public function up() { Schema::create('authentication_log', function (Blueprint $table) { $table->bigIncrements('id'); $table->morphs('authenticatable'); $table->string('ip_address', 45)->nullable(); $table->text('user_agent')->nullable(); $table->timestamp('login_at')->nullable(); $table->timestamp('logout_at')->nullable(); }); }
php
public function up() { Schema::create('authentication_log', function (Blueprint $table) { $table->bigIncrements('id'); $table->morphs('authenticatable'); $table->string('ip_address', 45)->nullable(); $table->text('user_agent')->nullable(); $table->timestamp('login_at')->nullable(); $table->timestamp('logout_at')->nullable(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "'authentication_log'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "bigIncrements", "(", "'id'", ")", ";", "$", "table", "->", "morphs", "(", ...
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/database/migrations/2017_09_01_000000_create_authentication_log_table.php#L14-L24
yadahan/laravel-authentication-log
src/Listeners/LogSuccessfulLogin.php
LogSuccessfulLogin.handle
public function handle(Login $event) { $user = $event->user; $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); $known = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); $authenticationLog = new AuthenticationLog([ 'ip_address' => $ip, 'user_agent' => $userAgent, 'login_at' => Carbon::now(), ]); $user->authentications()->save($authenticationLog); if (! $known && config('authentication-log.notify')) { $user->notify(new NewDevice($authenticationLog)); } }
php
public function handle(Login $event) { $user = $event->user; $ip = $this->request->ip(); $userAgent = $this->request->userAgent(); $known = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); $authenticationLog = new AuthenticationLog([ 'ip_address' => $ip, 'user_agent' => $userAgent, 'login_at' => Carbon::now(), ]); $user->authentications()->save($authenticationLog); if (! $known && config('authentication-log.notify')) { $user->notify(new NewDevice($authenticationLog)); } }
[ "public", "function", "handle", "(", "Login", "$", "event", ")", "{", "$", "user", "=", "$", "event", "->", "user", ";", "$", "ip", "=", "$", "this", "->", "request", "->", "ip", "(", ")", ";", "$", "userAgent", "=", "$", "this", "->", "request",...
Handle the event. @param Login $event @return void
[ "Handle", "the", "event", "." ]
train
https://github.com/yadahan/laravel-authentication-log/blob/d6297e9f573305325effa4b0fa48e5b9f6b36144/src/Listeners/LogSuccessfulLogin.php#L37-L55
zofe/rapyd-laravel
src/DataForm/Field/File.php
File.move
public function move($path, $name = '', $unlinkable = true, $deferred = false) { $this->path = rtrim($path,"/")."/"; $this->filename = $name; $this->unlink_file = $unlinkable; $this->upload_deferred = $deferred; if (!$this->web_path) $this->web_path = $this->path; return $this; }
php
public function move($path, $name = '', $unlinkable = true, $deferred = false) { $this->path = rtrim($path,"/")."/"; $this->filename = $name; $this->unlink_file = $unlinkable; $this->upload_deferred = $deferred; if (!$this->web_path) $this->web_path = $this->path; return $this; }
[ "public", "function", "move", "(", "$", "path", ",", "$", "name", "=", "''", ",", "$", "unlinkable", "=", "true", ",", "$", "deferred", "=", "false", ")", "{", "$", "this", "->", "path", "=", "rtrim", "(", "$", "path", ",", "\"/\"", ")", ".", "...
move uploaded file to the destination path, optionally raname it name param can be passed also as blade syntax unlinkable is a bool, tell to the field to unlink or not if "remove" is checked @param $path @param string $name @param bool $unlinkable @return $this
[ "move", "uploaded", "file", "to", "the", "destination", "path", "optionally", "raname", "it", "name", "param", "can", "be", "passed", "also", "as", "blade", "syntax", "unlinkable", "is", "a", "bool", "tell", "to", "the", "field", "to", "unlink", "or", "not...
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/File.php#L185-L193
zofe/rapyd-laravel
src/DataForm/Field/File.php
File.moveDeferred
public function moveDeferred($path, $name = '', $unlinkable = true) { return $this->move($path, $name, $unlinkable, true); }
php
public function moveDeferred($path, $name = '', $unlinkable = true) { return $this->move($path, $name, $unlinkable, true); }
[ "public", "function", "moveDeferred", "(", "$", "path", ",", "$", "name", "=", "''", ",", "$", "unlinkable", "=", "true", ")", "{", "return", "$", "this", "->", "move", "(", "$", "path", ",", "$", "name", ",", "$", "unlinkable", ",", "true", ")", ...
as move but deferred after model->save() this way you can use ->move('upload/folder/{{ $id }}/'); using blade and pk reference @param $path @param string $name @param bool $unlinkable @return $this
[ "as", "move", "but", "deferred", "after", "model", "-", ">", "save", "()", "this", "way", "you", "can", "use", "-", ">", "move", "(", "upload", "/", "folder", "/", "{{", "$id", "}}", "/", ")", ";", "using", "blade", "and", "pk", "reference" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/File.php#L204-L207
zofe/rapyd-laravel
src/DataFilter/DataFilter.php
DataFilter.source
public static function source($source = null) { $ins = new static(); $ins->source = $source; $ins->query = $source; if (is_object($source) && (is_a($source, "\Illuminate\Database\Eloquent\Builder") || is_a($source, "\Illuminate\Database\Eloquent\Model"))) { $ins->model = $source->getModel(); } $ins->cid = $ins->getIdentifier(); $ins->sniffStatus(); $ins->sniffAction(); return $ins; }
php
public static function source($source = null) { $ins = new static(); $ins->source = $source; $ins->query = $source; if (is_object($source) && (is_a($source, "\Illuminate\Database\Eloquent\Builder") || is_a($source, "\Illuminate\Database\Eloquent\Model"))) { $ins->model = $source->getModel(); } $ins->cid = $ins->getIdentifier(); $ins->sniffStatus(); $ins->sniffAction(); return $ins; }
[ "public", "static", "function", "source", "(", "$", "source", "=", "null", ")", "{", "$", "ins", "=", "new", "static", "(", ")", ";", "$", "ins", "->", "source", "=", "$", "source", ";", "$", "ins", "->", "query", "=", "$", "source", ";", "if", ...
@param $source @return static
[ "@param", "$source" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataFilter/DataFilter.php#L29-L43
zofe/rapyd-laravel
src/DataForm/Field/Field.php
Field.setName
protected function setName($name) { //detect relation or relation.field $relation = null; if (preg_match('#^([a-z0-9_-]+)\.([a-z0-9_-]+)$#i', $name, $matches)) { $relation = $matches[1]; $name = $matches[2]; } elseif (preg_match('#^[a-z0-9_-]+$#i', $name)) { $relation = $name; } if (isset($this->model) && method_exists($this->model, $relation) && is_a(@$this->model->$relation(), 'Illuminate\Database\Eloquent\Relations\Relation') ) { $this->relation = $this->model->$relation($relation); $this->rel_key = $this->relation->getModel()->getKeyName(); $this->rel_fq_key = $this->relation->getModel()->getQualifiedKeyName(); $this->rel_name = $relation; $this->rel_field = $name; $this->name = ($name != $relation) ? $relation . "_" . $name : $name; if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')){ $this->db_name = $this->relation->getForeignKey(); } else { $this->db_name = $name; } if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsToMany')){ if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) { $this->rel_other_key = $this->relation->getQualifiedRelatedPivotKeyName(); } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) { $this->rel_other_key = $this->relation->getQualifiedRelatedKeyName(); } else { $this->rel_other_key = $this->relation->getOtherKey(); } } return; } //otherwise replace dots with underscores so field names are html/js friendly $this->name = str_replace(array(".", ",", "`"), array("_", "_", "_"), $name); if (!isset($this->db_name)) $this->db_name = $name; }
php
protected function setName($name) { //detect relation or relation.field $relation = null; if (preg_match('#^([a-z0-9_-]+)\.([a-z0-9_-]+)$#i', $name, $matches)) { $relation = $matches[1]; $name = $matches[2]; } elseif (preg_match('#^[a-z0-9_-]+$#i', $name)) { $relation = $name; } if (isset($this->model) && method_exists($this->model, $relation) && is_a(@$this->model->$relation(), 'Illuminate\Database\Eloquent\Relations\Relation') ) { $this->relation = $this->model->$relation($relation); $this->rel_key = $this->relation->getModel()->getKeyName(); $this->rel_fq_key = $this->relation->getModel()->getQualifiedKeyName(); $this->rel_name = $relation; $this->rel_field = $name; $this->name = ($name != $relation) ? $relation . "_" . $name : $name; if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')){ $this->db_name = $this->relation->getForeignKey(); } else { $this->db_name = $name; } if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsToMany')){ if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) { $this->rel_other_key = $this->relation->getQualifiedRelatedPivotKeyName(); } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) { $this->rel_other_key = $this->relation->getQualifiedRelatedKeyName(); } else { $this->rel_other_key = $this->relation->getOtherKey(); } } return; } //otherwise replace dots with underscores so field names are html/js friendly $this->name = str_replace(array(".", ",", "`"), array("_", "_", "_"), $name); if (!isset($this->db_name)) $this->db_name = $name; }
[ "protected", "function", "setName", "(", "$", "name", ")", "{", "//detect relation or relation.field", "$", "relation", "=", "null", ";", "if", "(", "preg_match", "(", "'#^([a-z0-9_-]+)\\.([a-z0-9_-]+)$#i'", ",", "$", "name", ",", "$", "matches", ")", ")", "{", ...
check for relation notation and split relation-name and fiel-dname @param $name
[ "check", "for", "relation", "notation", "and", "split", "relation", "-", "name", "and", "fiel", "-", "dname" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Field.php#L111-L160
zofe/rapyd-laravel
src/DataForm/Field/Field.php
Field.unique
public function unique($id = null, $idClumn = null, $extra = null) { $id = $id ?: $this->model->id ?: 'NULL'; $idClumn = $idClumn ?: $this->model->getKeyName(); $parts = [ "unique:{$this->model->getConnectionName()}.{$this->model->getTable()}", $this->db_name, $id, $idClumn ]; if ($extra) { $parts []= trim($extra, ','); } $this->rule(join(',', $parts)); return $this; }
php
public function unique($id = null, $idClumn = null, $extra = null) { $id = $id ?: $this->model->id ?: 'NULL'; $idClumn = $idClumn ?: $this->model->getKeyName(); $parts = [ "unique:{$this->model->getConnectionName()}.{$this->model->getTable()}", $this->db_name, $id, $idClumn ]; if ($extra) { $parts []= trim($extra, ','); } $this->rule(join(',', $parts)); return $this; }
[ "public", "function", "unique", "(", "$", "id", "=", "null", ",", "$", "idClumn", "=", "null", ",", "$", "extra", "=", "null", ")", "{", "$", "id", "=", "$", "id", "?", ":", "$", "this", "->", "model", "->", "id", "?", ":", "'NULL'", ";", "$"...
Laravel Validation unique Auto except current model http://laravel.com/docs/5.1/validation#rule-unique
[ "Laravel", "Validation", "unique" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Field.php#L194-L213
zofe/rapyd-laravel
src/DataForm/Field/Field.php
Field.parseString
protected function parseString($string, $is_view = false) { if (is_object($this->model) && (strpos($string,'{{') !== false || strpos($string,'{!!') !== false || $is_view)) { $fields = $this->model->getAttributes(); $relations = $this->model->getRelations(); $array = array_merge($fields, $relations, ['model'=>$this->model]) ; $string = ($is_view) ? view($string, $array) : $this->parser->compileString($string, $array); } return $string; }
php
protected function parseString($string, $is_view = false) { if (is_object($this->model) && (strpos($string,'{{') !== false || strpos($string,'{!!') !== false || $is_view)) { $fields = $this->model->getAttributes(); $relations = $this->model->getRelations(); $array = array_merge($fields, $relations, ['model'=>$this->model]) ; $string = ($is_view) ? view($string, $array) : $this->parser->compileString($string, $array); } return $string; }
[ "protected", "function", "parseString", "(", "$", "string", ",", "$", "is_view", "=", "false", ")", "{", "if", "(", "is_object", "(", "$", "this", "->", "model", ")", "&&", "(", "strpos", "(", "$", "string", ",", "'{{'", ")", "!==", "false", "||", ...
parse blade syntax string using current model @param $string @param bool $is_view @return string
[ "parse", "blade", "syntax", "string", "using", "current", "model" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Field.php#L633-L643
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.add
public function add($name, $label, $type, $validation = '') { if (strpos($type, "\\") !== false) { $field_class = $type; } else { $field_class = '\Zofe\Rapyd\DataForm\Field\\' . ucfirst($type); } //instancing if (isset($this->model)) { $field_obj = new $field_class($name, $label, $this->model, $this->model_relations); } else { $field_obj = new $field_class($name, $label); } if (!$field_obj instanceof Field) { throw new \InvalidArgumentException('Third argument («type») must point to class inherited Field class'); } if ($field_obj->type == "file") { $this->multipart = true; } //default group if (isset($this->default_group) && !isset($field_obj->group)) { $field_obj->group = $this->default_group; } $this->fields[$name] = $field_obj; return $field_obj; }
php
public function add($name, $label, $type, $validation = '') { if (strpos($type, "\\") !== false) { $field_class = $type; } else { $field_class = '\Zofe\Rapyd\DataForm\Field\\' . ucfirst($type); } //instancing if (isset($this->model)) { $field_obj = new $field_class($name, $label, $this->model, $this->model_relations); } else { $field_obj = new $field_class($name, $label); } if (!$field_obj instanceof Field) { throw new \InvalidArgumentException('Third argument («type») must point to class inherited Field class'); } if ($field_obj->type == "file") { $this->multipart = true; } //default group if (isset($this->default_group) && !isset($field_obj->group)) { $field_obj->group = $this->default_group; } $this->fields[$name] = $field_obj; return $field_obj; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "label", ",", "$", "type", ",", "$", "validation", "=", "''", ")", "{", "if", "(", "strpos", "(", "$", "type", ",", "\"\\\\\"", ")", "!==", "false", ")", "{", "$", "field_class", "=", "$", ...
@param string $name @param string $label @param string $type @param string $validation @return mixed
[ "@param", "string", "$name", "@param", "string", "$label", "@param", "string", "$type", "@param", "string", "$validation" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L110-L140
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.remove
public function remove($fieldname) { if (isset($this->fields[$fieldname])) unset($this->fields[$fieldname]); return $this; }
php
public function remove($fieldname) { if (isset($this->fields[$fieldname])) unset($this->fields[$fieldname]); return $this; }
[ "public", "function", "remove", "(", "$", "fieldname", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "fieldname", "]", ")", ")", "unset", "(", "$", "this", "->", "fields", "[", "$", "fieldname", "]", ")", ";", "return", ...
remove field from list @param $fieldname @return $this
[ "remove", "field", "from", "list" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L147-L153
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.removeType
public function removeType($type) { foreach ($this->fields as $fieldname => $field) { if ($field->type == $type) { unset($this->fields[$fieldname]); } } foreach ($this->button_container as $container => $buttons) { foreach ($buttons as $key=>$button) { if (strpos($button, 'type="'.$type.'"')!==false) { $this->button_container[$container][$key] = ""; } } } return $this; }
php
public function removeType($type) { foreach ($this->fields as $fieldname => $field) { if ($field->type == $type) { unset($this->fields[$fieldname]); } } foreach ($this->button_container as $container => $buttons) { foreach ($buttons as $key=>$button) { if (strpos($button, 'type="'.$type.'"')!==false) { $this->button_container[$container][$key] = ""; } } } return $this; }
[ "public", "function", "removeType", "(", "$", "type", ")", "{", "foreach", "(", "$", "this", "->", "fields", "as", "$", "fieldname", "=>", "$", "field", ")", "{", "if", "(", "$", "field", "->", "type", "==", "$", "type", ")", "{", "unset", "(", "...
remove field where type==$type from field list and button container @param $type @return $this
[ "remove", "field", "where", "type", "==", "$type", "from", "field", "list", "and", "button", "container" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L160-L176
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.submit
public function submit($name, $position = "BL", $options = array()) { $options = array_merge(array("class" => "btn btn-primary"), $options); $this->button_container[$position][] = Form::submit($name, $options); return $this; }
php
public function submit($name, $position = "BL", $options = array()) { $options = array_merge(array("class" => "btn btn-primary"), $options); $this->button_container[$position][] = Form::submit($name, $options); return $this; }
[ "public", "function", "submit", "(", "$", "name", ",", "$", "position", "=", "\"BL\"", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "options", "=", "array_merge", "(", "array", "(", "\"class\"", "=>", "\"btn btn-primary\"", ")", ",", "$"...
@param string $name @param string $position @param array $options @return $this
[ "@param", "string", "$name", "@param", "string", "$position", "@param", "array", "$options" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L185-L191
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.reset
public function reset($name = "", $position = "BL", $options = array()) { if ($name == "") $name = trans('rapyd::rapyd.reset'); $this->link($this->url->current(true), $name, $position, $options); return $this; }
php
public function reset($name = "", $position = "BL", $options = array()) { if ($name == "") $name = trans('rapyd::rapyd.reset'); $this->link($this->url->current(true), $name, $position, $options); return $this; }
[ "public", "function", "reset", "(", "$", "name", "=", "\"\"", ",", "$", "position", "=", "\"BL\"", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "$", "name", "==", "\"\"", ")", "$", "name", "=", "trans", "(", "'rapyd::rapyd.rese...
@param string $name @param string $position @param array $options @return $this
[ "@param", "string", "$name", "@param", "string", "$position", "@param", "array", "$options" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L200-L206
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.field
public function field($field_name, array $attributes = array()) { if (isset($this->fields[$field_name])) { $field = $this->fields[$field_name]; if (count($attributes)) { $field->attributes($attributes); $field->build(); } return $field; } }
php
public function field($field_name, array $attributes = array()) { if (isset($this->fields[$field_name])) { $field = $this->fields[$field_name]; if (count($attributes)) { $field->attributes($attributes); $field->build(); } return $field; } }
[ "public", "function", "field", "(", "$", "field_name", ",", "array", "$", "attributes", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "field_name", "]", ")", ")", "{", "$", "field", "=", "$", "t...
get field instance from fields array @param string $field_name @param array $attributes @return \Zofe\Rapyd\DataForm\Field $field
[ "get", "field", "instance", "from", "fields", "array" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L214-L225
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.render
public function render($field_name, array $attributes = array()) { $field = $this->field($field_name, $attributes); return $field->all(); }
php
public function render($field_name, array $attributes = array()) { $field = $this->field($field_name, $attributes); return $field->all(); }
[ "public", "function", "render", "(", "$", "field_name", ",", "array", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "field", "=", "$", "this", "->", "field", "(", "$", "field_name", ",", "$", "attributes", ")", ";", "return", "$", "field"...
get entire field output (label, output, and messages) @param $field_name @param array $ttributes @return string
[ "get", "entire", "field", "output", "(", "label", "output", "and", "messages", ")" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L233-L238
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.source
public static function source($source = '') { $ins = new static(); if (is_object($source) && is_a($source, "\Illuminate\Database\Eloquent\Model")) { $ins->model = $source; } $ins->cid = $ins->getIdentifier(); $ins->sniffStatus(); $ins->sniffAction(); return $ins; }
php
public static function source($source = '') { $ins = new static(); if (is_object($source) && is_a($source, "\Illuminate\Database\Eloquent\Model")) { $ins->model = $source; } $ins->cid = $ins->getIdentifier(); $ins->sniffStatus(); $ins->sniffAction(); return $ins; }
[ "public", "static", "function", "source", "(", "$", "source", "=", "''", ")", "{", "$", "ins", "=", "new", "static", "(", ")", ";", "if", "(", "is_object", "(", "$", "source", ")", "&&", "is_a", "(", "$", "source", ",", "\"\\Illuminate\\Database\\Eloqu...
@param \Illuminate\Database\Eloquent\Model $source @return static
[ "@param", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Model", "$source" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L258-L269
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.error
public function error($error) { $this->process_status = 'error'; $this->message = ''; $this->error .= $error; return $this; }
php
public function error($error) { $this->process_status = 'error'; $this->message = ''; $this->error .= $error; return $this; }
[ "public", "function", "error", "(", "$", "error", ")", "{", "$", "this", "->", "process_status", "=", "'error'", ";", "$", "this", "->", "message", "=", "''", ";", "$", "this", "->", "error", ".=", "$", "error", ";", "return", "$", "this", ";", "}"...
append error (to be used in passed/saved closure) @param string $url @param string $name @param string $position @param array $attributes @return $this
[ "append", "error", "(", "to", "be", "used", "in", "passed", "/", "saved", "closure", ")", "@param", "string", "$url", "@param", "string", "$name", "@param", "string", "$position", "@param", "array", "$attributes" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L317-L324
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.on
public function on($process_status = "false") { if (is_array($process_status)) return (bool) in_array($this->process_status, $process_status); return ($this->process_status == $process_status); }
php
public function on($process_status = "false") { if (is_array($process_status)) return (bool) in_array($this->process_status, $process_status); return ($this->process_status == $process_status); }
[ "public", "function", "on", "(", "$", "process_status", "=", "\"false\"", ")", "{", "if", "(", "is_array", "(", "$", "process_status", ")", ")", "return", "(", "bool", ")", "in_array", "(", "$", "this", "->", "process_status", ",", "$", "process_status", ...
@param string $process_status @return bool
[ "@param", "string", "$process_status" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L331-L336
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.buildFields
protected function buildFields() { $messages = (isset($this->validator)) ? $this->validator->messages() : false; foreach ($this->fields as $field) { $field->status = $this->status; $field->orientation = $this->orientation; $field->has_label = $this->has_labels; $field->has_placeholder = $this->has_placeholders; if ($messages and $messages->has($field->name)) { $field->messages = $messages->get($field->name); $field->has_error = " has-error"; } $field->build(); } }
php
protected function buildFields() { $messages = (isset($this->validator)) ? $this->validator->messages() : false; foreach ($this->fields as $field) { $field->status = $this->status; $field->orientation = $this->orientation; $field->has_label = $this->has_labels; $field->has_placeholder = $this->has_placeholders; if ($messages and $messages->has($field->name)) { $field->messages = $messages->get($field->name); $field->has_error = " has-error"; } $field->build(); } }
[ "protected", "function", "buildFields", "(", ")", "{", "$", "messages", "=", "(", "isset", "(", "$", "this", "->", "validator", ")", ")", "?", "$", "this", "->", "validator", "->", "messages", "(", ")", ":", "false", ";", "foreach", "(", "$", "this",...
build each field and share some data from dataform to field (form status, validation errors)
[ "build", "each", "field", "and", "share", "some", "data", "from", "dataform", "to", "field", "(", "form", "status", "validation", "errors", ")" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L358-L373
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.build
public function build($view = '') { if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'form-inline') !== false) { $this->view = 'rapyd::dataform_inline'; $this->orientation = 'inline'; $this->has_labels = false; } if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'without-labels') !== false) { $this->has_labels = false; } if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'with-placeholders') !== false) { $this->has_placeholders = true; } if ($this->output != '') return; if ($view != '') $this->view = $view; $this->process(); //callable if ($this->form_callable && $this->process_status == "success") { $callable = $this->form_callable; $result = $callable($this); if ($result && is_a($result, 'Illuminate\Http\RedirectResponse')) { $this->redirect = $result; } elseif ($result && is_a($result, 'Illuminate\View\View')) { $this->custom_output = $result; } //reprocess if an error is added in closure if ($this->process_status == 'error') { $this->process(); } } //cleanup submits if success if ($this->process_status == 'success') { $this->removeType('submit'); } $this->buildButtons(); $this->buildFields(); $dataform = $this->buildForm(); $this->output = $dataform->render(); $sections = $dataform->renderSections(); $this->header = $sections['df.header']; $this->footer = $sections['df.footer']; $this->body = @$sections['df.fields']; Rapyd::setForm($this); }
php
public function build($view = '') { if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'form-inline') !== false) { $this->view = 'rapyd::dataform_inline'; $this->orientation = 'inline'; $this->has_labels = false; } if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'without-labels') !== false) { $this->has_labels = false; } if (isset($this->attributes['class']) and strpos($this->attributes['class'], 'with-placeholders') !== false) { $this->has_placeholders = true; } if ($this->output != '') return; if ($view != '') $this->view = $view; $this->process(); //callable if ($this->form_callable && $this->process_status == "success") { $callable = $this->form_callable; $result = $callable($this); if ($result && is_a($result, 'Illuminate\Http\RedirectResponse')) { $this->redirect = $result; } elseif ($result && is_a($result, 'Illuminate\View\View')) { $this->custom_output = $result; } //reprocess if an error is added in closure if ($this->process_status == 'error') { $this->process(); } } //cleanup submits if success if ($this->process_status == 'success') { $this->removeType('submit'); } $this->buildButtons(); $this->buildFields(); $dataform = $this->buildForm(); $this->output = $dataform->render(); $sections = $dataform->renderSections(); $this->header = $sections['df.header']; $this->footer = $sections['df.footer']; $this->body = @$sections['df.fields']; Rapyd::setForm($this); }
[ "public", "function", "build", "(", "$", "view", "=", "''", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "'class'", "]", ")", "and", "strpos", "(", "$", "this", "->", "attributes", "[", "'class'", "]", ",", "'form-inline'"...
build form output and prepare form partials (header / footer / ..) @param string $view
[ "build", "form", "output", "and", "prepare", "form", "partials", "(", "header", "/", "footer", "/", "..", ")" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L486-L533
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.view
public function view($viewname = 'rapyd::form', $array = []) { if (!isset($array['form'])) { $form = $this->getForm(); $array['form'] = $form; } if ($this->hasRedirect()) { return (is_a($this->redirect, 'Illuminate\Http\RedirectResponse')) ? $this->redirect : Redirect::to($this->redirect); } if ($this->hasCustomOutput()) { return $this->custom_output; } return View::make($viewname, $array); }
php
public function view($viewname = 'rapyd::form', $array = []) { if (!isset($array['form'])) { $form = $this->getForm(); $array['form'] = $form; } if ($this->hasRedirect()) { return (is_a($this->redirect, 'Illuminate\Http\RedirectResponse')) ? $this->redirect : Redirect::to($this->redirect); } if ($this->hasCustomOutput()) { return $this->custom_output; } return View::make($viewname, $array); }
[ "public", "function", "view", "(", "$", "viewname", "=", "'rapyd::form'", ",", "$", "array", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "'form'", "]", ")", ")", "{", "$", "form", "=", "$", "this", "->", "getForm", ...
@param string $viewname @param array $array of values for view @return View|Redirect
[ "@param", "string", "$viewname", "@param", "array", "$array", "of", "values", "for", "view" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L597-L610