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
brick/math
src/Internal/Calculator.php
Calculator.divRound
final public function divRound(string $a, string $b, int $roundingMode) : string { [$quotient, $remainder] = $this->divQR($a, $b); $hasDiscardedFraction = ($remainder !== '0'); $isPositiveOrZero = ($a[0] === '-') === ($b[0] === '-'); $discardedFractionSign = function() use ($remainder, $b) : int { $r = $this->abs($this->mul($remainder, '2')); $b = $this->abs($b); return $this->cmp($r, $b); }; $increment = false; switch ($roundingMode) { case RoundingMode::UNNECESSARY: if ($hasDiscardedFraction) { throw RoundingNecessaryException::roundingNecessary(); } break; case RoundingMode::UP: $increment = $hasDiscardedFraction; break; case RoundingMode::DOWN: break; case RoundingMode::CEILING: $increment = $hasDiscardedFraction && $isPositiveOrZero; break; case RoundingMode::FLOOR: $increment = $hasDiscardedFraction && ! $isPositiveOrZero; break; case RoundingMode::HALF_UP: $increment = $discardedFractionSign() >= 0; break; case RoundingMode::HALF_DOWN: $increment = $discardedFractionSign() > 0; break; case RoundingMode::HALF_CEILING: $increment = $isPositiveOrZero ? $discardedFractionSign() >= 0 : $discardedFractionSign() > 0; break; case RoundingMode::HALF_FLOOR: $increment = $isPositiveOrZero ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; break; case RoundingMode::HALF_EVEN: $lastDigit = (int) $quotient[-1]; $lastDigitIsEven = ($lastDigit % 2 === 0); $increment = $lastDigitIsEven ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; break; default: throw new \InvalidArgumentException('Invalid rounding mode.'); } if ($increment) { return $this->add($quotient, $isPositiveOrZero ? '1' : '-1'); } return $quotient; }
php
final public function divRound(string $a, string $b, int $roundingMode) : string { [$quotient, $remainder] = $this->divQR($a, $b); $hasDiscardedFraction = ($remainder !== '0'); $isPositiveOrZero = ($a[0] === '-') === ($b[0] === '-'); $discardedFractionSign = function() use ($remainder, $b) : int { $r = $this->abs($this->mul($remainder, '2')); $b = $this->abs($b); return $this->cmp($r, $b); }; $increment = false; switch ($roundingMode) { case RoundingMode::UNNECESSARY: if ($hasDiscardedFraction) { throw RoundingNecessaryException::roundingNecessary(); } break; case RoundingMode::UP: $increment = $hasDiscardedFraction; break; case RoundingMode::DOWN: break; case RoundingMode::CEILING: $increment = $hasDiscardedFraction && $isPositiveOrZero; break; case RoundingMode::FLOOR: $increment = $hasDiscardedFraction && ! $isPositiveOrZero; break; case RoundingMode::HALF_UP: $increment = $discardedFractionSign() >= 0; break; case RoundingMode::HALF_DOWN: $increment = $discardedFractionSign() > 0; break; case RoundingMode::HALF_CEILING: $increment = $isPositiveOrZero ? $discardedFractionSign() >= 0 : $discardedFractionSign() > 0; break; case RoundingMode::HALF_FLOOR: $increment = $isPositiveOrZero ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; break; case RoundingMode::HALF_EVEN: $lastDigit = (int) $quotient[-1]; $lastDigitIsEven = ($lastDigit % 2 === 0); $increment = $lastDigitIsEven ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; break; default: throw new \InvalidArgumentException('Invalid rounding mode.'); } if ($increment) { return $this->add($quotient, $isPositiveOrZero ? '1' : '-1'); } return $quotient; }
[ "final", "public", "function", "divRound", "(", "string", "$", "a", ",", "string", "$", "b", ",", "int", "$", "roundingMode", ")", ":", "string", "{", "[", "$", "quotient", ",", "$", "remainder", "]", "=", "$", "this", "->", "divQR", "(", "$", "a",...
Performs a rounded division. Rounding is performed when the remainder of the division is not zero. @param string $a The dividend. @param string $b The divisor. @param int $roundingMode The rounding mode. @return string @throws \InvalidArgumentException If the rounding mode is invalid. @throws RoundingNecessaryException If RoundingMode::UNNECESSARY is provided but rounding is necessary.
[ "Performs", "a", "rounded", "division", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator.php#L416-L485
brick/math
src/Internal/Calculator.php
Calculator.bitwise
private function bitwise(string $operator, string $a, string $b) : string { $this->init($a, $b, $aDig, $bDig, $aNeg, $bNeg); $aBin = $this->toBinary($aDig); $bBin = $this->toBinary($bDig); $aLen = \strlen($aBin); $bLen = \strlen($bBin); if ($aLen > $bLen) { $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin; } elseif ($bLen > $aLen) { $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin; } if ($aNeg) { $aBin = $this->twosComplement($aBin); } if ($bNeg) { $bBin = $this->twosComplement($bBin); } switch ($operator) { case 'and': $value = $aBin & $bBin; $negative = ($aNeg and $bNeg); break; case 'or': $value = $aBin | $bBin; $negative = ($aNeg or $bNeg); break; case 'xor': $value = $aBin ^ $bBin; $negative = ($aNeg xor $bNeg); break; // @codeCoverageIgnoreStart default: throw new \InvalidArgumentException('Invalid bitwise operator.'); // @codeCoverageIgnoreEnd } if ($negative) { $value = $this->twosComplement($value); } $result = $this->toDecimal($value); return $negative ? $this->neg($result) : $result; }
php
private function bitwise(string $operator, string $a, string $b) : string { $this->init($a, $b, $aDig, $bDig, $aNeg, $bNeg); $aBin = $this->toBinary($aDig); $bBin = $this->toBinary($bDig); $aLen = \strlen($aBin); $bLen = \strlen($bBin); if ($aLen > $bLen) { $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin; } elseif ($bLen > $aLen) { $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin; } if ($aNeg) { $aBin = $this->twosComplement($aBin); } if ($bNeg) { $bBin = $this->twosComplement($bBin); } switch ($operator) { case 'and': $value = $aBin & $bBin; $negative = ($aNeg and $bNeg); break; case 'or': $value = $aBin | $bBin; $negative = ($aNeg or $bNeg); break; case 'xor': $value = $aBin ^ $bBin; $negative = ($aNeg xor $bNeg); break; // @codeCoverageIgnoreStart default: throw new \InvalidArgumentException('Invalid bitwise operator.'); // @codeCoverageIgnoreEnd } if ($negative) { $value = $this->twosComplement($value); } $result = $this->toDecimal($value); return $negative ? $this->neg($result) : $result; }
[ "private", "function", "bitwise", "(", "string", "$", "operator", ",", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "$", "this", "->", "init", "(", "$", "a", ",", "$", "b", ",", "$", "aDig", ",", "$", "bDig", ",", "$", ...
Performs a bitwise operation on a decimal number. @param string $operator The operator to use, must be "and", "or" or "xor". @param string $a The left operand. @param string $b The right operand. @return string
[ "Performs", "a", "bitwise", "operation", "on", "a", "decimal", "number", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator.php#L544-L596
brick/math
src/Internal/Calculator.php
Calculator.twosComplement
private function twosComplement(string $number) : string { $xor = \str_repeat("\xff", \strlen($number)); $number = $number ^ $xor; for ($i = \strlen($number) - 1; $i >= 0; $i--) { $byte = \ord($number[$i]); if (++$byte !== 256) { $number[$i] = \chr($byte); break; } $number[$i] = \chr(0); } return $number; }
php
private function twosComplement(string $number) : string { $xor = \str_repeat("\xff", \strlen($number)); $number = $number ^ $xor; for ($i = \strlen($number) - 1; $i >= 0; $i--) { $byte = \ord($number[$i]); if (++$byte !== 256) { $number[$i] = \chr($byte); break; } $number[$i] = \chr(0); } return $number; }
[ "private", "function", "twosComplement", "(", "string", "$", "number", ")", ":", "string", "{", "$", "xor", "=", "\\", "str_repeat", "(", "\"\\xff\"", ",", "\\", "strlen", "(", "$", "number", ")", ")", ";", "$", "number", "=", "$", "number", "^", "$"...
@param string $number A positive, binary number. @return string
[ "@param", "string", "$number", "A", "positive", "binary", "number", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator.php#L603-L621
brick/math
src/Internal/Calculator.php
Calculator.toBinary
private function toBinary(string $number) : string { $result = ''; while ($number !== '0') { [$number, $remainder] = $this->divQR($number, '256'); $result .= \chr((int) $remainder); } return \strrev($result); }
php
private function toBinary(string $number) : string { $result = ''; while ($number !== '0') { [$number, $remainder] = $this->divQR($number, '256'); $result .= \chr((int) $remainder); } return \strrev($result); }
[ "private", "function", "toBinary", "(", "string", "$", "number", ")", ":", "string", "{", "$", "result", "=", "''", ";", "while", "(", "$", "number", "!==", "'0'", ")", "{", "[", "$", "number", ",", "$", "remainder", "]", "=", "$", "this", "->", ...
Converts a decimal number to a binary string. @param string $number The number to convert, positive or zero, only digits. @return string
[ "Converts", "a", "decimal", "number", "to", "a", "binary", "string", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator.php#L630-L640
brick/math
src/Internal/Calculator.php
Calculator.toDecimal
private function toDecimal(string $bytes) : string { $result = '0'; $power = '1'; for ($i = \strlen($bytes) - 1; $i >= 0; $i--) { $index = \ord($bytes[$i]); if ($index !== 0) { $result = $this->add($result, ($index === 1) ? $power : $this->mul($power, (string) $index) ); } if ($i !== 0) { $power = $this->mul($power, '256'); } } return $result; }
php
private function toDecimal(string $bytes) : string { $result = '0'; $power = '1'; for ($i = \strlen($bytes) - 1; $i >= 0; $i--) { $index = \ord($bytes[$i]); if ($index !== 0) { $result = $this->add($result, ($index === 1) ? $power : $this->mul($power, (string) $index) ); } if ($i !== 0) { $power = $this->mul($power, '256'); } } return $result; }
[ "private", "function", "toDecimal", "(", "string", "$", "bytes", ")", ":", "string", "{", "$", "result", "=", "'0'", ";", "$", "power", "=", "'1'", ";", "for", "(", "$", "i", "=", "\\", "strlen", "(", "$", "bytes", ")", "-", "1", ";", "$", "i",...
Returns the positive decimal representation of a binary number. @param string $bytes The bytes representing the number. @return string
[ "Returns", "the", "positive", "decimal", "representation", "of", "a", "binary", "number", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator.php#L649-L670
brick/math
src/Exception/IntegerOverflowException.php
IntegerOverflowException.toIntOverflow
public static function toIntOverflow(BigInteger $value) : IntegerOverflowException { $message = '%s is out of range %d to %d and cannot be represented as an integer.'; return new self(\sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX)); }
php
public static function toIntOverflow(BigInteger $value) : IntegerOverflowException { $message = '%s is out of range %d to %d and cannot be represented as an integer.'; return new self(\sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX)); }
[ "public", "static", "function", "toIntOverflow", "(", "BigInteger", "$", "value", ")", ":", "IntegerOverflowException", "{", "$", "message", "=", "'%s is out of range %d to %d and cannot be represented as an integer.'", ";", "return", "new", "self", "(", "\\", "sprintf", ...
@param BigInteger $value @return IntegerOverflowException
[ "@param", "BigInteger", "$value" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Exception/IntegerOverflowException.php#L19-L24
brick/math
src/Internal/Calculator/BcMathCalculator.php
BcMathCalculator.divQR
public function divQR(string $a, string $b) : array { $q = \bcdiv($a, $b, 0); $r = \bcmod($a, $b); return [$q, $r]; }
php
public function divQR(string $a, string $b) : array { $q = \bcdiv($a, $b, 0); $r = \bcmod($a, $b); return [$q, $r]; }
[ "public", "function", "divQR", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "array", "{", "$", "q", "=", "\\", "bcdiv", "(", "$", "a", ",", "$", "b", ",", "0", ")", ";", "$", "r", "=", "\\", "bcmod", "(", "$", "a", ",", "$"...
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/BcMathCalculator.php#L59-L65
brick/math
src/Internal/Calculator/BcMathCalculator.php
BcMathCalculator.pow
public function pow(string $a, int $e) : string { return \bcpow($a, (string) $e, 0); }
php
public function pow(string $a, int $e) : string { return \bcpow($a, (string) $e, 0); }
[ "public", "function", "pow", "(", "string", "$", "a", ",", "int", "$", "e", ")", ":", "string", "{", "return", "\\", "bcpow", "(", "$", "a", ",", "(", "string", ")", "$", "e", ",", "0", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/BcMathCalculator.php#L70-L73
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.add
public function add(string $a, string $b) : string { return \gmp_strval(\gmp_add($a, $b)); }
php
public function add(string $a, string $b) : string { return \gmp_strval(\gmp_add($a, $b)); }
[ "public", "function", "add", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_add", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L19-L22
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.sub
public function sub(string $a, string $b) : string { return \gmp_strval(\gmp_sub($a, $b)); }
php
public function sub(string $a, string $b) : string { return \gmp_strval(\gmp_sub($a, $b)); }
[ "public", "function", "sub", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_sub", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L27-L30
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.mul
public function mul(string $a, string $b) : string { return \gmp_strval(\gmp_mul($a, $b)); }
php
public function mul(string $a, string $b) : string { return \gmp_strval(\gmp_mul($a, $b)); }
[ "public", "function", "mul", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_mul", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L35-L38
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.divQ
public function divQ(string $a, string $b) : string { return \gmp_strval(\gmp_div_q($a, $b)); }
php
public function divQ(string $a, string $b) : string { return \gmp_strval(\gmp_div_q($a, $b)); }
[ "public", "function", "divQ", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_div_q", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L43-L46
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.divR
public function divR(string $a, string $b) : string { return \gmp_strval(\gmp_div_r($a, $b)); }
php
public function divR(string $a, string $b) : string { return \gmp_strval(\gmp_div_r($a, $b)); }
[ "public", "function", "divR", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_div_r", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L51-L54
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.divQR
public function divQR(string $a, string $b) : array { [$q, $r] = \gmp_div_qr($a, $b); return [ \gmp_strval($q), \gmp_strval($r) ]; }
php
public function divQR(string $a, string $b) : array { [$q, $r] = \gmp_div_qr($a, $b); return [ \gmp_strval($q), \gmp_strval($r) ]; }
[ "public", "function", "divQR", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "array", "{", "[", "$", "q", ",", "$", "r", "]", "=", "\\", "gmp_div_qr", "(", "$", "a", ",", "$", "b", ")", ";", "return", "[", "\\", "gmp_strval", "(...
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L59-L67
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.pow
public function pow(string $a, int $e) : string { return \gmp_strval(\gmp_pow($a, $e)); }
php
public function pow(string $a, int $e) : string { return \gmp_strval(\gmp_pow($a, $e)); }
[ "public", "function", "pow", "(", "string", "$", "a", ",", "int", "$", "e", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_pow", "(", "$", "a", ",", "$", "e", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L72-L75
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.gcd
public function gcd(string $a, string $b) : string { return \gmp_strval(\gmp_gcd($a, $b)); }
php
public function gcd(string $a, string $b) : string { return \gmp_strval(\gmp_gcd($a, $b)); }
[ "public", "function", "gcd", "(", "string", "$", "a", ",", "string", "$", "b", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_gcd", "(", "$", "a", ",", "$", "b", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L80-L83
brick/math
src/Internal/Calculator/GmpCalculator.php
GmpCalculator.fromBase
public function fromBase(string $number, int $base) : string { return \gmp_strval(\gmp_init($number, $base)); }
php
public function fromBase(string $number, int $base) : string { return \gmp_strval(\gmp_init($number, $base)); }
[ "public", "function", "fromBase", "(", "string", "$", "number", ",", "int", "$", "base", ")", ":", "string", "{", "return", "\\", "gmp_strval", "(", "\\", "gmp_init", "(", "$", "number", ",", "$", "base", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/Internal/Calculator/GmpCalculator.php#L88-L91
brick/math
src/BigInteger.php
BigInteger.fromBase
public static function fromBase(string $number, int $base) : BigInteger { if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } if ($base < 2 || $base > 36) { throw new \InvalidArgumentException(\sprintf('Base %d is not in range 2 to 36.', $base)); } if ($number[0] === '-') { $sign = '-'; $number = \substr($number, 1); } elseif ($number[0] === '+') { $sign = ''; $number = \substr($number, 1); } else { $sign = ''; } if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } $number = \ltrim($number, '0'); if ($number === '') { // The result will be the same in any base, avoid further calculation. return BigInteger::zero(); } if ($number === '1') { // The result will be the same in any base, avoid further calculation. return new BigInteger($sign . '1'); } $pattern = '/[^' . \substr(Calculator::ALPHABET, 0, $base) . ']/'; if (\preg_match($pattern, \strtolower($number), $matches) === 1) { throw new NumberFormatException(\sprintf('"%s" is not a valid character in base %d.', $matches[0], $base)); } if ($base === 10) { // The number is usable as is, avoid further calculation. return new BigInteger($sign . $number); } $result = Calculator::get()->fromBase($number, $base); return new BigInteger($sign . $result); }
php
public static function fromBase(string $number, int $base) : BigInteger { if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } if ($base < 2 || $base > 36) { throw new \InvalidArgumentException(\sprintf('Base %d is not in range 2 to 36.', $base)); } if ($number[0] === '-') { $sign = '-'; $number = \substr($number, 1); } elseif ($number[0] === '+') { $sign = ''; $number = \substr($number, 1); } else { $sign = ''; } if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } $number = \ltrim($number, '0'); if ($number === '') { // The result will be the same in any base, avoid further calculation. return BigInteger::zero(); } if ($number === '1') { // The result will be the same in any base, avoid further calculation. return new BigInteger($sign . '1'); } $pattern = '/[^' . \substr(Calculator::ALPHABET, 0, $base) . ']/'; if (\preg_match($pattern, \strtolower($number), $matches) === 1) { throw new NumberFormatException(\sprintf('"%s" is not a valid character in base %d.', $matches[0], $base)); } if ($base === 10) { // The number is usable as is, avoid further calculation. return new BigInteger($sign . $number); } $result = Calculator::get()->fromBase($number, $base); return new BigInteger($sign . $result); }
[ "public", "static", "function", "fromBase", "(", "string", "$", "number", ",", "int", "$", "base", ")", ":", "BigInteger", "{", "if", "(", "$", "number", "===", "''", ")", "{", "throw", "new", "NumberFormatException", "(", "'The number cannot be empty.'", ")...
Creates a number from a string in a given base. The string can optionally be prefixed with the `+` or `-` sign. Bases greater than 36 are not supported by this method, as there is no clear consensus on which of the lowercase or uppercase characters should come first. Instead, this method accepts any base up to 36, and does not differentiate lowercase and uppercase characters, which are considered equal. For bases greater than 36, and/or custom alphabets, use the fromArbitraryBase() method. @param string $number The number to convert, in the given base. @param int $base The base of the number, between 2 and 36. @return BigInteger @throws NumberFormatException If the number is empty, or contains invalid chars for the given base. @throws \InvalidArgumentException If the base is out of range.
[ "Creates", "a", "number", "from", "a", "string", "in", "a", "given", "base", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L75-L125
brick/math
src/BigInteger.php
BigInteger.fromArbitraryBase
public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger { if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } $base = \strlen($alphabet); if ($base < 2) { throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); } $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/'; if (\preg_match($pattern, $number, $matches) === 1) { throw NumberFormatException::charNotInAlphabet($matches[0]); } $number = Calculator::get()->fromArbitraryBase($number, $alphabet, $base); return new BigInteger($number); }
php
public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger { if ($number === '') { throw new NumberFormatException('The number cannot be empty.'); } $base = \strlen($alphabet); if ($base < 2) { throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); } $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/'; if (\preg_match($pattern, $number, $matches) === 1) { throw NumberFormatException::charNotInAlphabet($matches[0]); } $number = Calculator::get()->fromArbitraryBase($number, $alphabet, $base); return new BigInteger($number); }
[ "public", "static", "function", "fromArbitraryBase", "(", "string", "$", "number", ",", "string", "$", "alphabet", ")", ":", "BigInteger", "{", "if", "(", "$", "number", "===", "''", ")", "{", "throw", "new", "NumberFormatException", "(", "'The number cannot b...
Parses a string containing an integer in an arbitrary base, using a custom alphabet. Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers. @param string $number The number to parse. @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8. @return BigInteger @throws NumberFormatException If the given number is empty or contains invalid chars for the given alphabet. @throws \InvalidArgumentException If the alphabet does not contain at least 2 chars.
[ "Parses", "a", "string", "containing", "an", "integer", "in", "an", "arbitrary", "base", "using", "a", "custom", "alphabet", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L140-L161
brick/math
src/BigInteger.php
BigInteger.plus
public function plus($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { return $this; } $value = Calculator::get()->add($this->value, $that->value); return new BigInteger($value); }
php
public function plus($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { return $this; } $value = Calculator::get()->add($this->value, $that->value); return new BigInteger($value); }
[ "public", "function", "plus", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'0'", ")", "{", "return", "$", "this", ";", "}", ...
Returns the sum of this number and the given one. @param BigNumber|number|string $that The number to add. Must be convertible to a BigInteger. @return BigInteger The result. @throws MathException If the number is not valid, or is not convertible to a BigInteger.
[ "Returns", "the", "sum", "of", "this", "number", "and", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L220-L231
brick/math
src/BigInteger.php
BigInteger.minus
public function minus($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { return $this; } $value = Calculator::get()->sub($this->value, $that->value); return new BigInteger($value); }
php
public function minus($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { return $this; } $value = Calculator::get()->sub($this->value, $that->value); return new BigInteger($value); }
[ "public", "function", "minus", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'0'", ")", "{", "return", "$", "this", ";", "}", ...
Returns the difference of this number and the given one. @param BigNumber|number|string $that The number to subtract. Must be convertible to a BigInteger. @return BigInteger The result. @throws MathException If the number is not valid, or is not convertible to a BigInteger.
[ "Returns", "the", "difference", "of", "this", "number", "and", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L242-L253
brick/math
src/BigInteger.php
BigInteger.multipliedBy
public function multipliedBy($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } $value = Calculator::get()->mul($this->value, $that->value); return new BigInteger($value); }
php
public function multipliedBy($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } $value = Calculator::get()->mul($this->value, $that->value); return new BigInteger($value); }
[ "public", "function", "multipliedBy", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'1'", ")", "{", "return", "$", "this", ";", ...
Returns the product of this number and the given one. @param BigNumber|number|string $that The multiplier. Must be convertible to a BigInteger. @return BigInteger The result. @throws MathException If the multiplier is not a valid number, or is not convertible to a BigInteger.
[ "Returns", "the", "product", "of", "this", "number", "and", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L264-L275
brick/math
src/BigInteger.php
BigInteger.dividedBy
public function dividedBy($that, int $roundingMode = RoundingMode::UNNECESSARY) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $result = Calculator::get()->divRound($this->value, $that->value, $roundingMode); return new BigInteger($result); }
php
public function dividedBy($that, int $roundingMode = RoundingMode::UNNECESSARY) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $result = Calculator::get()->divRound($this->value, $that->value, $roundingMode); return new BigInteger($result); }
[ "public", "function", "dividedBy", "(", "$", "that", ",", "int", "$", "roundingMode", "=", "RoundingMode", "::", "UNNECESSARY", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that",...
Returns the result of the division of this number by the given one. @param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger. @param int $roundingMode An optional rounding mode. @return BigInteger The result. @throws MathException If the divisor is not a valid number, is not convertible to a BigInteger, is zero, or RoundingMode::UNNECESSARY is used and the remainder is not zero.
[ "Returns", "the", "result", "of", "the", "division", "of", "this", "number", "by", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L288-L303
brick/math
src/BigInteger.php
BigInteger.quotient
public function quotient($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $quotient = Calculator::get()->divQ($this->value, $that->value); return new BigInteger($quotient); }
php
public function quotient($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '1') { return $this; } if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $quotient = Calculator::get()->divQ($this->value, $that->value); return new BigInteger($quotient); }
[ "public", "function", "quotient", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'1'", ")", "{", "return", "$", "this", ";", "}...
Returns the quotient of the division of this number by the given one. @param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger. @return BigInteger @throws DivisionByZeroException If the divisor is zero.
[ "Returns", "the", "quotient", "of", "the", "division", "of", "this", "number", "by", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L344-L359
brick/math
src/BigInteger.php
BigInteger.remainder
public function remainder($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $remainder = Calculator::get()->divR($this->value, $that->value); return new BigInteger($remainder); }
php
public function remainder($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } $remainder = Calculator::get()->divR($this->value, $that->value); return new BigInteger($remainder); }
[ "public", "function", "remainder", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'0'", ")", "{", "throw", "DivisionByZeroException",...
Returns the remainder of the division of this number by the given one. @param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger. @return BigInteger @throws DivisionByZeroException If the divisor is zero.
[ "Returns", "the", "remainder", "of", "the", "division", "of", "this", "number", "by", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L370-L381
brick/math
src/BigInteger.php
BigInteger.quotientAndRemainder
public function quotientAndRemainder($that) : array { $that = BigInteger::of($that); if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } [$quotient, $remainder] = Calculator::get()->divQR($this->value, $that->value); return [ new BigInteger($quotient), new BigInteger($remainder) ]; }
php
public function quotientAndRemainder($that) : array { $that = BigInteger::of($that); if ($that->value === '0') { throw DivisionByZeroException::divisionByZero(); } [$quotient, $remainder] = Calculator::get()->divQR($this->value, $that->value); return [ new BigInteger($quotient), new BigInteger($remainder) ]; }
[ "public", "function", "quotientAndRemainder", "(", "$", "that", ")", ":", "array", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'0'", ")", "{", "throw", "DivisionByZeroExcep...
Returns the quotient and remainder of the division of this number by the given one. @param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger. @return BigInteger[] An array containing the quotient and the remainder. @throws DivisionByZeroException If the divisor is zero.
[ "Returns", "the", "quotient", "and", "remainder", "of", "the", "division", "of", "this", "number", "by", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L392-L406
brick/math
src/BigInteger.php
BigInteger.gcd
public function gcd($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0' && $this->value[0] !== '-') { return $this; } if ($this->value === '0' && $that->value[0] !== '-') { return $that; } $value = Calculator::get()->gcd($this->value, $that->value); return new BigInteger($value); }
php
public function gcd($that) : BigInteger { $that = BigInteger::of($that); if ($that->value === '0' && $this->value[0] !== '-') { return $this; } if ($this->value === '0' && $that->value[0] !== '-') { return $that; } $value = Calculator::get()->gcd($this->value, $that->value); return new BigInteger($value); }
[ "public", "function", "gcd", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "->", "value", "===", "'0'", "&&", "$", "this", "->", "value", "[", "0", ...
Returns the greatest common divisor of this number and the given one. The GCD is always positive, unless both operands are zero, in which case it is zero. @param BigNumber|number|string $that The operand. Must be convertible to an integer number. @return BigInteger
[ "Returns", "the", "greatest", "common", "divisor", "of", "this", "number", "and", "the", "given", "one", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L417-L432
brick/math
src/BigInteger.php
BigInteger.sqrt
public function sqrt() : BigInteger { if ($this->value[0] === '-') { throw new NegativeNumberException('Cannot calculate the square root of a negative number.'); } $value = Calculator::get()->sqrt($this->value); return new BigInteger($value); }
php
public function sqrt() : BigInteger { if ($this->value[0] === '-') { throw new NegativeNumberException('Cannot calculate the square root of a negative number.'); } $value = Calculator::get()->sqrt($this->value); return new BigInteger($value); }
[ "public", "function", "sqrt", "(", ")", ":", "BigInteger", "{", "if", "(", "$", "this", "->", "value", "[", "0", "]", "===", "'-'", ")", "{", "throw", "new", "NegativeNumberException", "(", "'Cannot calculate the square root of a negative number.'", ")", ";", ...
Returns the integer square root number of this number, rounded down. The result is the largest x such that x² ≤ n. @return BigInteger @throws NegativeNumberException If this number is negative.
[ "Returns", "the", "integer", "square", "root", "number", "of", "this", "number", "rounded", "down", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L443-L452
brick/math
src/BigInteger.php
BigInteger.and
public function and($that) : BigInteger { $that = BigInteger::of($that); return new BigInteger(Calculator::get()->and($this->value, $that->value)); }
php
public function and($that) : BigInteger { $that = BigInteger::of($that); return new BigInteger(Calculator::get()->and($this->value, $that->value)); }
[ "public", "function", "and", "(", "$", "that", ")", ":", "BigInteger", "{", "$", "that", "=", "BigInteger", "::", "of", "(", "$", "that", ")", ";", "return", "new", "BigInteger", "(", "Calculator", "::", "get", "(", ")", "->", "and", "(", "$", "thi...
Returns the integer bitwise-and combined with another integer. This method returns a negative BigInteger if and only if both operands are negative. @param BigNumber|number|string $that The operand. Must be convertible to an integer number. @return BigInteger
[ "Returns", "the", "integer", "bitwise", "-", "and", "combined", "with", "another", "integer", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L483-L488
brick/math
src/BigInteger.php
BigInteger.shiftedLeft
public function shiftedLeft(int $distance) : BigInteger { if ($distance === 0) { return $this; } if ($distance < 0) { return $this->shiftedRight(- $distance); } return $this->multipliedBy(BigInteger::of(2)->power($distance)); }
php
public function shiftedLeft(int $distance) : BigInteger { if ($distance === 0) { return $this; } if ($distance < 0) { return $this->shiftedRight(- $distance); } return $this->multipliedBy(BigInteger::of(2)->power($distance)); }
[ "public", "function", "shiftedLeft", "(", "int", "$", "distance", ")", ":", "BigInteger", "{", "if", "(", "$", "distance", "===", "0", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "distance", "<", "0", ")", "{", "return", "$", "this",...
Returns the integer left shifted by a given number of bits. @param int $distance The distance to shift. @return BigInteger
[ "Returns", "the", "integer", "left", "shifted", "by", "a", "given", "number", "of", "bits", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L529-L540
brick/math
src/BigInteger.php
BigInteger.shiftedRight
public function shiftedRight(int $distance) : BigInteger { if ($distance === 0) { return $this; } if ($distance < 0) { return $this->shiftedLeft(- $distance); } $operand = BigInteger::of(2)->power($distance); if ($this->isPositiveOrZero()) { return $this->quotient($operand); } return $this->dividedBy($operand, RoundingMode::UP); }
php
public function shiftedRight(int $distance) : BigInteger { if ($distance === 0) { return $this; } if ($distance < 0) { return $this->shiftedLeft(- $distance); } $operand = BigInteger::of(2)->power($distance); if ($this->isPositiveOrZero()) { return $this->quotient($operand); } return $this->dividedBy($operand, RoundingMode::UP); }
[ "public", "function", "shiftedRight", "(", "int", "$", "distance", ")", ":", "BigInteger", "{", "if", "(", "$", "distance", "===", "0", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "distance", "<", "0", ")", "{", "return", "$", "this"...
Returns the integer right shifted by a given number of bits. @param int $distance The distance to shift. @return BigInteger
[ "Returns", "the", "integer", "right", "shifted", "by", "a", "given", "number", "of", "bits", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L549-L566
brick/math
src/BigInteger.php
BigInteger.compareTo
public function compareTo($that) : int { $that = BigNumber::of($that); if ($that instanceof BigInteger) { return Calculator::get()->cmp($this->value, $that->value); } return - $that->compareTo($this); }
php
public function compareTo($that) : int { $that = BigNumber::of($that); if ($that instanceof BigInteger) { return Calculator::get()->cmp($this->value, $that->value); } return - $that->compareTo($this); }
[ "public", "function", "compareTo", "(", "$", "that", ")", ":", "int", "{", "$", "that", "=", "BigNumber", "::", "of", "(", "$", "that", ")", ";", "if", "(", "$", "that", "instanceof", "BigInteger", ")", "{", "return", "Calculator", "::", "get", "(", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L571-L580
brick/math
src/BigInteger.php
BigInteger.toScale
public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal { return $this->toBigDecimal()->toScale($scale, $roundingMode); }
php
public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal { return $this->toBigDecimal()->toScale($scale, $roundingMode); }
[ "public", "function", "toScale", "(", "int", "$", "scale", ",", "int", "$", "roundingMode", "=", "RoundingMode", "::", "UNNECESSARY", ")", ":", "BigDecimal", "{", "return", "$", "this", "->", "toBigDecimal", "(", ")", "->", "toScale", "(", "$", "scale", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L617-L620
brick/math
src/BigInteger.php
BigInteger.toInt
public function toInt() : int { $intValue = (int) $this->value; if ($this->value !== (string) $intValue) { throw IntegerOverflowException::toIntOverflow($this); } return $intValue; }
php
public function toInt() : int { $intValue = (int) $this->value; if ($this->value !== (string) $intValue) { throw IntegerOverflowException::toIntOverflow($this); } return $intValue; }
[ "public", "function", "toInt", "(", ")", ":", "int", "{", "$", "intValue", "=", "(", "int", ")", "$", "this", "->", "value", ";", "if", "(", "$", "this", "->", "value", "!==", "(", "string", ")", "$", "intValue", ")", "{", "throw", "IntegerOverflow...
{@inheritdoc}
[ "{" ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L625-L634
brick/math
src/BigInteger.php
BigInteger.toBase
public function toBase(int $base) : string { if ($base === 10) { return $this->value; } if ($base < 2 || $base > 36) { throw new \InvalidArgumentException(\sprintf('Base %d is out of range [2, 36]', $base)); } return Calculator::get()->toBase($this->value, $base); }
php
public function toBase(int $base) : string { if ($base === 10) { return $this->value; } if ($base < 2 || $base > 36) { throw new \InvalidArgumentException(\sprintf('Base %d is out of range [2, 36]', $base)); } return Calculator::get()->toBase($this->value, $base); }
[ "public", "function", "toBase", "(", "int", "$", "base", ")", ":", "string", "{", "if", "(", "$", "base", "===", "10", ")", "{", "return", "$", "this", "->", "value", ";", "}", "if", "(", "$", "base", "<", "2", "||", "$", "base", ">", "36", "...
Returns a string representation of this number in the given base. The output will always be lowercase for bases greater than 10. @param int $base @return string @throws \InvalidArgumentException If the base is out of range.
[ "Returns", "a", "string", "representation", "of", "this", "number", "in", "the", "given", "base", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L655-L666
brick/math
src/BigInteger.php
BigInteger.toArbitraryBase
public function toArbitraryBase(string $alphabet) : string { $base = \strlen($alphabet); if ($base < 2) { throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); } if ($this->value[0] === '-') { throw new NegativeNumberException(__FUNCTION__ . '() does not support negative numbers.'); } return Calculator::get()->toArbitraryBase($this->value, $alphabet, $base); }
php
public function toArbitraryBase(string $alphabet) : string { $base = \strlen($alphabet); if ($base < 2) { throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); } if ($this->value[0] === '-') { throw new NegativeNumberException(__FUNCTION__ . '() does not support negative numbers.'); } return Calculator::get()->toArbitraryBase($this->value, $alphabet, $base); }
[ "public", "function", "toArbitraryBase", "(", "string", "$", "alphabet", ")", ":", "string", "{", "$", "base", "=", "\\", "strlen", "(", "$", "alphabet", ")", ";", "if", "(", "$", "base", "<", "2", ")", "{", "throw", "new", "\\", "InvalidArgumentExcept...
Returns a string representation of this number in an arbitrary base with a custom alphabet. Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers; a NegativeNumberException will be thrown when attempting to call this method on a negative number. @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8. @return string @throws NegativeNumberException If this number is negative. @throws \InvalidArgumentException If the given alphabet does not contain at least 2 chars.
[ "Returns", "a", "string", "representation", "of", "this", "number", "in", "an", "arbitrary", "base", "with", "a", "custom", "alphabet", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L681-L694
brick/math
src/BigInteger.php
BigInteger.unserialize
public function unserialize($value) : void { if (isset($this->value)) { throw new \LogicException('unserialize() is an internal function, it must not be called directly.'); } $this->value = $value; }
php
public function unserialize($value) : void { if (isset($this->value)) { throw new \LogicException('unserialize() is an internal function, it must not be called directly.'); } $this->value = $value; }
[ "public", "function", "unserialize", "(", "$", "value", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "value", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'unserialize() is an internal function, it must not be called directly....
This method is only here to implement interface Serializable and cannot be accessed directly. @internal @param string $value @return void @throws \LogicException
[ "This", "method", "is", "only", "here", "to", "implement", "interface", "Serializable", "and", "cannot", "be", "accessed", "directly", "." ]
train
https://github.com/brick/math/blob/5f1fff59b3413c9dafa67b9c4571c1df1898fac2/src/BigInteger.php#L727-L734
TYPO3/phar-stream-wrapper
src/Helper.php
Helper.determineBaseFile
public static function determineBaseFile(string $path) { $parts = explode('/', static::normalizePath($path)); while (count($parts)) { $currentPath = implode('/', $parts); if (@is_file($currentPath)) { return $currentPath; } array_pop($parts); } return null; }
php
public static function determineBaseFile(string $path) { $parts = explode('/', static::normalizePath($path)); while (count($parts)) { $currentPath = implode('/', $parts); if (@is_file($currentPath)) { return $currentPath; } array_pop($parts); } return null; }
[ "public", "static", "function", "determineBaseFile", "(", "string", "$", "path", ")", "{", "$", "parts", "=", "explode", "(", "'/'", ",", "static", "::", "normalizePath", "(", "$", "path", ")", ")", ";", "while", "(", "count", "(", "$", "parts", ")", ...
Determines base file that can be accessed using the regular file system. For e.g. "phar:///home/user/bundle.phar/content.txt" that would result into "/home/user/bundle.phar". @param string $path @return string|null
[ "Determines", "base", "file", "that", "can", "be", "accessed", "using", "the", "regular", "file", "system", ".", "For", "e", ".", "g", ".", "phar", ":", "///", "home", "/", "user", "/", "bundle", ".", "phar", "/", "content", ".", "txt", "that", "woul...
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Helper.php#L48-L61
TYPO3/phar-stream-wrapper
src/Helper.php
Helper.getCanonicalPath
private static function getCanonicalPath($path): string { $path = static::normalizeWindowsPath($path); $absolutePathPrefix = ''; if (static::isAbsolutePath($path)) { if (static::isWindows() && strpos($path, ':/') === 1) { $absolutePathPrefix = substr($path, 0, 3); $path = substr($path, 3); } else { $path = ltrim($path, '/'); $absolutePathPrefix = '/'; } } $pathParts = explode('/', $path); $pathPartsLength = count($pathParts); for ($partCount = 0; $partCount < $pathPartsLength; $partCount++) { // double-slashes in path: remove element if ($pathParts[$partCount] === '') { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } // "." in path: remove element if (($pathParts[$partCount] ?? '') === '.') { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } // ".." in path: if (($pathParts[$partCount] ?? '') === '..') { if ($partCount === 0) { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } elseif ($partCount >= 1) { // Rremove this and previous element array_splice($pathParts, $partCount - 1, 2); $partCount -= 2; $pathPartsLength -= 2; } elseif ($absolutePathPrefix) { // can't go higher than root dir // simply remove this part and continue array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } } } return $absolutePathPrefix . implode('/', $pathParts); }
php
private static function getCanonicalPath($path): string { $path = static::normalizeWindowsPath($path); $absolutePathPrefix = ''; if (static::isAbsolutePath($path)) { if (static::isWindows() && strpos($path, ':/') === 1) { $absolutePathPrefix = substr($path, 0, 3); $path = substr($path, 3); } else { $path = ltrim($path, '/'); $absolutePathPrefix = '/'; } } $pathParts = explode('/', $path); $pathPartsLength = count($pathParts); for ($partCount = 0; $partCount < $pathPartsLength; $partCount++) { // double-slashes in path: remove element if ($pathParts[$partCount] === '') { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } // "." in path: remove element if (($pathParts[$partCount] ?? '') === '.') { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } // ".." in path: if (($pathParts[$partCount] ?? '') === '..') { if ($partCount === 0) { array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } elseif ($partCount >= 1) { // Rremove this and previous element array_splice($pathParts, $partCount - 1, 2); $partCount -= 2; $pathPartsLength -= 2; } elseif ($absolutePathPrefix) { // can't go higher than root dir // simply remove this part and continue array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } } } return $absolutePathPrefix . implode('/', $pathParts); }
[ "private", "static", "function", "getCanonicalPath", "(", "$", "path", ")", ":", "string", "{", "$", "path", "=", "static", "::", "normalizeWindowsPath", "(", "$", "path", ")", ";", "$", "absolutePathPrefix", "=", "''", ";", "if", "(", "static", "::", "i...
Resolves all dots, slashes and removes spaces after or before a path... @param string $path Input string @return string Canonical path, always without trailing slash
[ "Resolves", "all", "dots", "slashes", "and", "removes", "spaces", "after", "or", "before", "a", "path", "..." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Helper.php#L119-L171
TYPO3/phar-stream-wrapper
src/Helper.php
Helper.isAbsolutePath
private static function isAbsolutePath($path): bool { // Path starting with a / is always absolute, on every system // On Windows also a path starting with a drive letter is absolute: X:/ return ($path[0] ?? null) === '/' || static::isWindows() && ( strpos($path, ':/') === 1 || strpos($path, ':\\') === 1 ); }
php
private static function isAbsolutePath($path): bool { // Path starting with a / is always absolute, on every system // On Windows also a path starting with a drive letter is absolute: X:/ return ($path[0] ?? null) === '/' || static::isWindows() && ( strpos($path, ':/') === 1 || strpos($path, ':\\') === 1 ); }
[ "private", "static", "function", "isAbsolutePath", "(", "$", "path", ")", ":", "bool", "{", "// Path starting with a / is always absolute, on every system", "// On Windows also a path starting with a drive letter is absolute: X:/", "return", "(", "$", "path", "[", "0", "]", "...
Checks if the $path is absolute or relative (detecting either '/' or 'x:/' as first part of string) and returns TRUE if so. @param string $path File path to evaluate @return bool
[ "Checks", "if", "the", "$path", "is", "absolute", "or", "relative", "(", "detecting", "either", "/", "or", "x", ":", "/", "as", "first", "part", "of", "string", ")", "and", "returns", "TRUE", "if", "so", "." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Helper.php#L180-L189
TYPO3/phar-stream-wrapper
src/PharStreamWrapper.php
PharStreamWrapper.invokeInternalStreamWrapper
private function invokeInternalStreamWrapper(string $functionName, ...$arguments) { $silentExecution = $functionName{0} === '@'; $functionName = ltrim($functionName, '@'); $this->restoreInternalSteamWrapper(); try { if ($silentExecution) { $result = @call_user_func_array($functionName, $arguments); } else { $result = call_user_func_array($functionName, $arguments); } } finally { $this->registerStreamWrapper(); } return $result; }
php
private function invokeInternalStreamWrapper(string $functionName, ...$arguments) { $silentExecution = $functionName{0} === '@'; $functionName = ltrim($functionName, '@'); $this->restoreInternalSteamWrapper(); try { if ($silentExecution) { $result = @call_user_func_array($functionName, $arguments); } else { $result = call_user_func_array($functionName, $arguments); } } finally { $this->registerStreamWrapper(); } return $result; }
[ "private", "function", "invokeInternalStreamWrapper", "(", "string", "$", "functionName", ",", "...", "$", "arguments", ")", "{", "$", "silentExecution", "=", "$", "functionName", "{", "0", "}", "===", "'@'", ";", "$", "functionName", "=", "ltrim", "(", "$",...
Invokes commands on the native PHP Phar stream wrapper. @param string $functionName @param mixed ...$arguments @return mixed
[ "Invokes", "commands", "on", "the", "native", "PHP", "Phar", "stream", "wrapper", "." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/PharStreamWrapper.php#L466-L483
TYPO3/phar-stream-wrapper
src/Interceptor/ConjunctionInterceptor.php
ConjunctionInterceptor.assert
public function assert(string $path, string $command): bool { if ($this->invokeAssertions($path, $command)) { return true; } throw new Exception( sprintf( 'Assertion failed in "%s"', $path ), 1539625084 ); }
php
public function assert(string $path, string $command): bool { if ($this->invokeAssertions($path, $command)) { return true; } throw new Exception( sprintf( 'Assertion failed in "%s"', $path ), 1539625084 ); }
[ "public", "function", "assert", "(", "string", "$", "path", ",", "string", "$", "command", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "invokeAssertions", "(", "$", "path", ",", "$", "command", ")", ")", "{", "return", "true", ";", "}", "t...
Executes assertions based on all contained assertions. @param string $path @param string $command @return bool @throws Exception
[ "Executes", "assertions", "based", "on", "all", "contained", "assertions", "." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Interceptor/ConjunctionInterceptor.php#L39-L51
TYPO3/phar-stream-wrapper
src/Resolver/PharInvocationResolver.php
PharInvocationResolver.resolve
public function resolve(string $path, int $flags = null) { $hasPharPrefix = Helper::hasPharPrefix($path); $flags = $flags ?? static::RESOLVE_REALPATH | static::RESOLVE_ALIAS | static::ASSERT_INTERNAL_INVOCATION; if ($hasPharPrefix && $flags & static::RESOLVE_ALIAS) { $invocation = $this->findByAlias($path); if ($invocation !== null && $this->assertInternalInvocation($invocation, $flags)) { return $invocation; } elseif ($invocation !== null) { return null; } } $baseName = Helper::determineBaseFile($path); if ($baseName === null) { return null; } if ($flags & static::RESOLVE_REALPATH) { $baseName = realpath($baseName); } if ($flags & static::RESOLVE_ALIAS) { $alias = (new Reader($baseName))->resolveContainer()->getAlias(); } else { $alias = ''; } return new PharInvocation($baseName, $alias); }
php
public function resolve(string $path, int $flags = null) { $hasPharPrefix = Helper::hasPharPrefix($path); $flags = $flags ?? static::RESOLVE_REALPATH | static::RESOLVE_ALIAS | static::ASSERT_INTERNAL_INVOCATION; if ($hasPharPrefix && $flags & static::RESOLVE_ALIAS) { $invocation = $this->findByAlias($path); if ($invocation !== null && $this->assertInternalInvocation($invocation, $flags)) { return $invocation; } elseif ($invocation !== null) { return null; } } $baseName = Helper::determineBaseFile($path); if ($baseName === null) { return null; } if ($flags & static::RESOLVE_REALPATH) { $baseName = realpath($baseName); } if ($flags & static::RESOLVE_ALIAS) { $alias = (new Reader($baseName))->resolveContainer()->getAlias(); } else { $alias = ''; } return new PharInvocation($baseName, $alias); }
[ "public", "function", "resolve", "(", "string", "$", "path", ",", "int", "$", "flags", "=", "null", ")", "{", "$", "hasPharPrefix", "=", "Helper", "::", "hasPharPrefix", "(", "$", "path", ")", ";", "$", "flags", "=", "$", "flags", "??", "static", "::...
Resolves PharInvocation value object (baseName and optional alias). Phar aliases are intended to be used only inside Phar archives, however PharStreamWrapper needs this information exposed outside of Phar as well It is possible that same alias is used for different $baseName values. That's why PharInvocationCollection behaves like a stack when resolving base-name for a given alias. On the other hand it is not possible that one $baseName is referring to multiple aliases. @see https://secure.php.net/manual/en/phar.setalias.php @see https://secure.php.net/manual/en/phar.mapphar.php @param string $path @param int|null $flags @return null|PharInvocation
[ "Resolves", "PharInvocation", "value", "object", "(", "baseName", "and", "optional", "alias", ")", "." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Resolver/PharInvocationResolver.php#L52-L81
TYPO3/phar-stream-wrapper
src/Resolver/PharInvocationCollection.php
PharInvocationCollection.assertUniqueBaseName
private function assertUniqueBaseName(PharInvocation $invocation, int $flags): bool { if (!($flags & static::UNIQUE_BASE_NAME)) { return true; } return $this->findByCallback( function (PharInvocation $candidate) use ($invocation) { return $candidate->getBaseName() === $invocation->getBaseName(); } ) === null; }
php
private function assertUniqueBaseName(PharInvocation $invocation, int $flags): bool { if (!($flags & static::UNIQUE_BASE_NAME)) { return true; } return $this->findByCallback( function (PharInvocation $candidate) use ($invocation) { return $candidate->getBaseName() === $invocation->getBaseName(); } ) === null; }
[ "private", "function", "assertUniqueBaseName", "(", "PharInvocation", "$", "invocation", ",", "int", "$", "flags", ")", ":", "bool", "{", "if", "(", "!", "(", "$", "flags", "&", "static", "::", "UNIQUE_BASE_NAME", ")", ")", "{", "return", "true", ";", "}...
Asserts that base-name is unique. This disallows having multiple invocations for same base-name but having different alias names. @param PharInvocation $invocation @param int $flags @return bool
[ "Asserts", "that", "base", "-", "name", "is", "unique", ".", "This", "disallows", "having", "multiple", "invocations", "for", "same", "base", "-", "name", "but", "having", "different", "alias", "names", "." ]
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Resolver/PharInvocationCollection.php#L76-L86
TYPO3/phar-stream-wrapper
src/Resolver/PharInvocationCollection.php
PharInvocationCollection.assertUniqueInvocation
private function assertUniqueInvocation(PharInvocation $invocation, int $flags): bool { if (!($flags & static::UNIQUE_INVOCATION)) { return true; } return $this->findByCallback( function (PharInvocation $candidate) use ($invocation) { return $candidate->equals($invocation); } ) === null; }
php
private function assertUniqueInvocation(PharInvocation $invocation, int $flags): bool { if (!($flags & static::UNIQUE_INVOCATION)) { return true; } return $this->findByCallback( function (PharInvocation $candidate) use ($invocation) { return $candidate->equals($invocation); } ) === null; }
[ "private", "function", "assertUniqueInvocation", "(", "PharInvocation", "$", "invocation", ",", "int", "$", "flags", ")", ":", "bool", "{", "if", "(", "!", "(", "$", "flags", "&", "static", "::", "UNIQUE_INVOCATION", ")", ")", "{", "return", "true", ";", ...
Asserts that combination of base-name and alias is unique. This allows having multiple invocations for same base-name but having different alias names (for whatever reason). @param PharInvocation $invocation @param int $flags @return bool
[ "Asserts", "that", "combination", "of", "base", "-", "name", "and", "alias", "is", "unique", ".", "This", "allows", "having", "multiple", "invocations", "for", "same", "base", "-", "name", "but", "having", "different", "alias", "names", "(", "for", "whatever...
train
https://github.com/TYPO3/phar-stream-wrapper/blob/dbc6f74f8cb81d08e9c56948773bcce7a5f383a5/src/Resolver/PharInvocationCollection.php#L96-L106
recca0120/laravel-tracy
src/BarManager.php
BarManager.loadPanels
public function loadPanels($panels = []) { if (isset($panels['user']) === true) { $panels['auth'] = $panels['user']; unset($panels['user']); } $ajax = $this->request->ajax(); foreach ($panels as $id => $enabled) { if ($enabled === false) { continue; } if ($ajax === true && $this->isAjaxPanel($id) === false) { continue; } $panel = static::make($id); $this->set($panel, $id); } return $this; }
php
public function loadPanels($panels = []) { if (isset($panels['user']) === true) { $panels['auth'] = $panels['user']; unset($panels['user']); } $ajax = $this->request->ajax(); foreach ($panels as $id => $enabled) { if ($enabled === false) { continue; } if ($ajax === true && $this->isAjaxPanel($id) === false) { continue; } $panel = static::make($id); $this->set($panel, $id); } return $this; }
[ "public", "function", "loadPanels", "(", "$", "panels", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "panels", "[", "'user'", "]", ")", "===", "true", ")", "{", "$", "panels", "[", "'auth'", "]", "=", "$", "panels", "[", "'user'", "]", ...
loadPanels. @param array $panels @return $this
[ "loadPanels", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/BarManager.php#L74-L96
recca0120/laravel-tracy
src/BarManager.php
BarManager.set
public function set(IBarPanel $panel, $id) { $panel->setLaravel($this->app); $this->panels[$id] = $panel; $this->bar->addPanel($panel, $id); return $this; }
php
public function set(IBarPanel $panel, $id) { $panel->setLaravel($this->app); $this->panels[$id] = $panel; $this->bar->addPanel($panel, $id); return $this; }
[ "public", "function", "set", "(", "IBarPanel", "$", "panel", ",", "$", "id", ")", "{", "$", "panel", "->", "setLaravel", "(", "$", "this", "->", "app", ")", ";", "$", "this", "->", "panels", "[", "$", "id", "]", "=", "$", "panel", ";", "$", "th...
set. @param \Tracy\IBarPanel $panel @param string $id @return $this
[ "set", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/BarManager.php#L119-L126
recca0120/laravel-tracy
src/Panels/ViewPanel.php
ViewPanel.subscribe
protected function subscribe() { if (version_compare($this->laravel->version(), 5.4, '>=') === true) { $this->laravel['events']->listen('composing:*', function ($key, $payload) { $this->logView($payload[0]); }); } else { $this->laravel['events']->listen('composing:*', function ($payload) { $this->logView($payload); }); } }
php
protected function subscribe() { if (version_compare($this->laravel->version(), 5.4, '>=') === true) { $this->laravel['events']->listen('composing:*', function ($key, $payload) { $this->logView($payload[0]); }); } else { $this->laravel['events']->listen('composing:*', function ($payload) { $this->logView($payload); }); } }
[ "protected", "function", "subscribe", "(", ")", "{", "if", "(", "version_compare", "(", "$", "this", "->", "laravel", "->", "version", "(", ")", ",", "5.4", ",", "'>='", ")", "===", "true", ")", "{", "$", "this", "->", "laravel", "[", "'events'", "]"...
subscribe.
[ "subscribe", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/ViewPanel.php#L27-L38
recca0120/laravel-tracy
src/Panels/ViewPanel.php
ViewPanel.logView
protected function logView($view) { $name = $view->getName(); $data = $this->limitCollection(Arr::except($view->getData(), ['__env', 'app'])); $path = static::editorLink($view->getPath()); preg_match('/href=\"(.+)\"/', $path, $m); $path = (count($m) > 1) ? '(<a href="'.$m[1].'">source</a>)' : ''; $this->views[] = compact('name', 'data', 'path'); }
php
protected function logView($view) { $name = $view->getName(); $data = $this->limitCollection(Arr::except($view->getData(), ['__env', 'app'])); $path = static::editorLink($view->getPath()); preg_match('/href=\"(.+)\"/', $path, $m); $path = (count($m) > 1) ? '(<a href="'.$m[1].'">source</a>)' : ''; $this->views[] = compact('name', 'data', 'path'); }
[ "protected", "function", "logView", "(", "$", "view", ")", "{", "$", "name", "=", "$", "view", "->", "getName", "(", ")", ";", "$", "data", "=", "$", "this", "->", "limitCollection", "(", "Arr", "::", "except", "(", "$", "view", "->", "getData", "(...
logView. @param \Illuminate\Contracts\View\View @return string
[ "logView", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/ViewPanel.php#L46-L54
recca0120/laravel-tracy
src/Panels/ViewPanel.php
ViewPanel.limitCollection
protected function limitCollection($data) { $results = []; foreach ($data as $key => $value) { if (is_array($value) === true && count($value) > $this->limit) { $value = array_slice($value, 0, $this->limit); } if ($value instanceof Collection && $value->count() > $this->limit) { $value = $value->take($this->limit); } $results[$key] = $value; } return $results; }
php
protected function limitCollection($data) { $results = []; foreach ($data as $key => $value) { if (is_array($value) === true && count($value) > $this->limit) { $value = array_slice($value, 0, $this->limit); } if ($value instanceof Collection && $value->count() > $this->limit) { $value = $value->take($this->limit); } $results[$key] = $value; } return $results; }
[ "protected", "function", "limitCollection", "(", "$", "data", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "===", "true", ...
limitCollection. @param array $data @return array
[ "limitCollection", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/ViewPanel.php#L62-L78
recca0120/laravel-tracy
src/Panels/TerminalPanel.php
TerminalPanel.getAttributes
protected function getAttributes() { $terminal = null; if ($this->hasLaravel() === true) { try { $controller = $this->laravel->make(TerminalController::class); $response = $this->laravel->call([$controller, 'index'], ['view' => 'panel']); $terminal = $response->getContent(); } catch (Exception $e) { $terminal = $e->getMessage(); } } return [ 'terminal' => $terminal, ]; }
php
protected function getAttributes() { $terminal = null; if ($this->hasLaravel() === true) { try { $controller = $this->laravel->make(TerminalController::class); $response = $this->laravel->call([$controller, 'index'], ['view' => 'panel']); $terminal = $response->getContent(); } catch (Exception $e) { $terminal = $e->getMessage(); } } return [ 'terminal' => $terminal, ]; }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "terminal", "=", "null", ";", "if", "(", "$", "this", "->", "hasLaravel", "(", ")", "===", "true", ")", "{", "try", "{", "$", "controller", "=", "$", "this", "->", "laravel", "->", "make",...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/TerminalPanel.php#L27-L43
recca0120/laravel-tracy
src/Panels/HtmlValidatorPanel.php
HtmlValidatorPanel.normalize
protected static function normalize($str) { $str = static::normalizeNewLines($str); // remove control characters; leave \t + \n $str = preg_replace('#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $str); // right trim $str = preg_replace('#[\t ]+$#m', '', $str); // leading and trailing blank lines $str = trim($str, "\n"); return $str; }
php
protected static function normalize($str) { $str = static::normalizeNewLines($str); // remove control characters; leave \t + \n $str = preg_replace('#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $str); // right trim $str = preg_replace('#[\t ]+$#m', '', $str); // leading and trailing blank lines $str = trim($str, "\n"); return $str; }
[ "protected", "static", "function", "normalize", "(", "$", "str", ")", "{", "$", "str", "=", "static", "::", "normalizeNewLines", "(", "$", "str", ")", ";", "// remove control characters; leave \\t + \\n", "$", "str", "=", "preg_replace", "(", "'#[\\x00-\\x08\\x0B-...
Removes special controls characters and normalizes line endings and spaces. @param string $str @return string
[ "Removes", "special", "controls", "characters", "and", "normalizes", "line", "endings", "and", "spaces", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/HtmlValidatorPanel.php#L61-L72
recca0120/laravel-tracy
src/Panels/HtmlValidatorPanel.php
HtmlValidatorPanel.getAttributes
protected function getAttributes() { libxml_use_internal_errors(true); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->resolveExternals = false; $dom->validateOnParse = true; $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = true; $dom->recover = true; @$dom->loadHTML($this->normalize($this->html)); $errors = array_filter(libxml_get_errors(), function (LibXMLError $error) { return in_array((int) $error->code, static::$ignoreErrors, true) === false; }); libxml_clear_errors(); return [ 'severenity' => static::$severenity, 'counter' => count($errors), 'errors' => $errors, 'html' => $this->html, ]; }
php
protected function getAttributes() { libxml_use_internal_errors(true); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->resolveExternals = false; $dom->validateOnParse = true; $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = true; $dom->recover = true; @$dom->loadHTML($this->normalize($this->html)); $errors = array_filter(libxml_get_errors(), function (LibXMLError $error) { return in_array((int) $error->code, static::$ignoreErrors, true) === false; }); libxml_clear_errors(); return [ 'severenity' => static::$severenity, 'counter' => count($errors), 'errors' => $errors, 'html' => $this->html, ]; }
[ "protected", "function", "getAttributes", "(", ")", "{", "libxml_use_internal_errors", "(", "true", ")", ";", "$", "dom", "=", "new", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "$", "dom", "->", "resolveExternals", "=", "false", ";", "$", "dom"...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/HtmlValidatorPanel.php#L90-L114
recca0120/laravel-tracy
src/Panels/HtmlValidatorPanel.php
HtmlValidatorPanel.subscribe
protected function subscribe() { $events = $this->laravel['events']; $events->listen(BeforeBarRender::class, function ($barRender) { $this->setHtml($barRender->response->getContent()); }); }
php
protected function subscribe() { $events = $this->laravel['events']; $events->listen(BeforeBarRender::class, function ($barRender) { $this->setHtml($barRender->response->getContent()); }); }
[ "protected", "function", "subscribe", "(", ")", "{", "$", "events", "=", "$", "this", "->", "laravel", "[", "'events'", "]", ";", "$", "events", "->", "listen", "(", "BeforeBarRender", "::", "class", ",", "function", "(", "$", "barRender", ")", "{", "$...
subscribe.
[ "subscribe", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/HtmlValidatorPanel.php#L119-L125
recca0120/laravel-tracy
src/Panels/AuthPanel.php
AuthPanel.getAttributes
protected function getAttributes() { $attributes = []; if (is_null($this->userResolver) === false) { $attributes['rows'] = call_user_func($this->userResolver); } elseif ($this->hasLaravel() === true) { $attributes = isset($this->laravel['sentinel']) === true ? $this->fromSentinel() : $this->fromGuard(); } return $this->identifier($attributes); }
php
protected function getAttributes() { $attributes = []; if (is_null($this->userResolver) === false) { $attributes['rows'] = call_user_func($this->userResolver); } elseif ($this->hasLaravel() === true) { $attributes = isset($this->laravel['sentinel']) === true ? $this->fromSentinel() : $this->fromGuard(); } return $this->identifier($attributes); }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "attributes", "=", "[", "]", ";", "if", "(", "is_null", "(", "$", "this", "->", "userResolver", ")", "===", "false", ")", "{", "$", "attributes", "[", "'rows'", "]", "=", "call_user_func", "...
getAttributes. * @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AuthPanel.php#L36-L47
recca0120/laravel-tracy
src/Panels/AuthPanel.php
AuthPanel.fromGuard
protected function fromGuard() { $auth = $this->laravel['auth']; $user = $auth->user(); return is_null($user) === true ? [] : [ 'id' => $user->getAuthIdentifier(), 'rows' => $user->toArray(), ]; }
php
protected function fromGuard() { $auth = $this->laravel['auth']; $user = $auth->user(); return is_null($user) === true ? [] : [ 'id' => $user->getAuthIdentifier(), 'rows' => $user->toArray(), ]; }
[ "protected", "function", "fromGuard", "(", ")", "{", "$", "auth", "=", "$", "this", "->", "laravel", "[", "'auth'", "]", ";", "$", "user", "=", "$", "auth", "->", "user", "(", ")", ";", "return", "is_null", "(", "$", "user", ")", "===", "true", "...
fromGuard. @return array
[ "fromGuard", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AuthPanel.php#L54-L63
recca0120/laravel-tracy
src/Panels/AuthPanel.php
AuthPanel.fromSentinel
protected function fromSentinel() { $user = $this->laravel['sentinel']->check(); return empty($user) === true ? [] : [ 'id' => null, 'rows' => $user->toArray(), ]; }
php
protected function fromSentinel() { $user = $this->laravel['sentinel']->check(); return empty($user) === true ? [] : [ 'id' => null, 'rows' => $user->toArray(), ]; }
[ "protected", "function", "fromSentinel", "(", ")", "{", "$", "user", "=", "$", "this", "->", "laravel", "[", "'sentinel'", "]", "->", "check", "(", ")", ";", "return", "empty", "(", "$", "user", ")", "===", "true", "?", "[", "]", ":", "[", "'id'", ...
fromSentinel. @return array
[ "fromSentinel", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AuthPanel.php#L70-L78
recca0120/laravel-tracy
src/Panels/AuthPanel.php
AuthPanel.identifier
protected function identifier($attributes = []) { $id = Arr::get($attributes, 'id'); $rows = Arr::get($attributes, 'rows', []); if (empty($rows) === true) { $id = 'Guest'; } elseif (is_numeric($id) === true || empty($id) === true) { $id = 'UnKnown'; foreach (['username', 'account', 'email', 'name', 'id'] as $key) { if (isset($rows[$key]) === true) { $id = $rows[$key]; break; } } } return [ 'id' => $id, 'rows' => $rows, ]; }
php
protected function identifier($attributes = []) { $id = Arr::get($attributes, 'id'); $rows = Arr::get($attributes, 'rows', []); if (empty($rows) === true) { $id = 'Guest'; } elseif (is_numeric($id) === true || empty($id) === true) { $id = 'UnKnown'; foreach (['username', 'account', 'email', 'name', 'id'] as $key) { if (isset($rows[$key]) === true) { $id = $rows[$key]; break; } } } return [ 'id' => $id, 'rows' => $rows, ]; }
[ "protected", "function", "identifier", "(", "$", "attributes", "=", "[", "]", ")", "{", "$", "id", "=", "Arr", "::", "get", "(", "$", "attributes", ",", "'id'", ")", ";", "$", "rows", "=", "Arr", "::", "get", "(", "$", "attributes", ",", "'rows'", ...
identifier. @param array $attributes @return array
[ "identifier", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AuthPanel.php#L86-L107
recca0120/laravel-tracy
src/Panels/RoutingPanel.php
RoutingPanel.getAttributes
protected function getAttributes() { $rows = [ 'uri' => 404, ]; if ($this->hasLaravel() === true) { $router = $this->laravel['router']; $currentRoute = $router->getCurrentRoute(); if (is_null($currentRoute) === false) { $rows = array_merge([ 'uri' => $currentRoute->uri(), ], $currentRoute->getAction()); } } else { $rows['uri'] = empty(Arr::get($_SERVER, 'HTTP_HOST')) === true ? 404 : Arr::get($_SERVER, 'REQUEST_URI'); } return compact('rows'); }
php
protected function getAttributes() { $rows = [ 'uri' => 404, ]; if ($this->hasLaravel() === true) { $router = $this->laravel['router']; $currentRoute = $router->getCurrentRoute(); if (is_null($currentRoute) === false) { $rows = array_merge([ 'uri' => $currentRoute->uri(), ], $currentRoute->getAction()); } } else { $rows['uri'] = empty(Arr::get($_SERVER, 'HTTP_HOST')) === true ? 404 : Arr::get($_SERVER, 'REQUEST_URI'); } return compact('rows'); }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "rows", "=", "[", "'uri'", "=>", "404", ",", "]", ";", "if", "(", "$", "this", "->", "hasLaravel", "(", ")", "===", "true", ")", "{", "$", "router", "=", "$", "this", "->", "laravel", ...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/RoutingPanel.php#L15-L34
recca0120/laravel-tracy
src/Panels/Helper.php
Helper.hightlight
public static function hightlight($sql, array $bindings = [], PDO $pdo = null) { // insert new lines $sql = " $sql "; $sql = preg_replace('#(?<=[\\s,(])('.static::KEYWORDS1.')(?=[\\s,)])#i', "\n\$1", $sql); // reduce spaces $sql = preg_replace('#[ \t]{2,}#', ' ', $sql); // syntax highlight $sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8'); $sql = preg_replace_callback('#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])('.static::KEYWORDS1.')(?=[\\s,)])|(?<=[\\s,(=])('.static::KEYWORDS2.')(?=[\\s,)=])#is', function ($matches) { if (! empty($matches[1])) { // comment return '<em style="color:gray">'.$matches[1].'</em>'; } elseif (! empty($matches[2])) { // error return '<strong style="color:red">'.$matches[2].'</strong>'; } elseif (! empty($matches[3])) { // most important keywords return '<strong style="color:blue; text-transform: uppercase;">'.$matches[3].'</strong>'; } elseif (! empty($matches[4])) { // other keywords return '<strong style="color:green">'.$matches[4].'</strong>'; } }, $sql); $bindings = array_map(function ($binding) use ($pdo) { if (is_array($binding) === true) { $binding = implode(', ', array_map(function ($value) { return is_string($value) === true ? htmlspecialchars('\''.$value.'\'', ENT_NOQUOTES, 'UTF-8') : $value; }, $binding)); return htmlspecialchars('('.$binding.')', ENT_NOQUOTES, 'UTF-8'); } if (is_string($binding) === true && (preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $binding) || preg_last_error())) { return '<i title="Length '.strlen($binding).' bytes">&lt;binary&gt;</i>'; } if (is_string($binding) === true) { $text = htmlspecialchars($pdo ? $pdo->quote($binding) : '\''.$binding.'\'', ENT_NOQUOTES, 'UTF-8'); return '<span title="Length '.strlen($text).' characters">'.$text.'</span>'; } if (is_resource($binding) === true) { $type = get_resource_type($binding); if ($type === 'stream') { $info = stream_get_meta_data($binding); } return '<i'.(isset($info['uri']) ? ' title="'.htmlspecialchars($info['uri'], ENT_NOQUOTES, 'UTF-8').'"' : null) .'>&lt;'.htmlspecialchars($type, ENT_NOQUOTES, 'UTF-8').' resource&gt;</i>'; } if ($binding instanceof DateTime) { return htmlspecialchars('\''.$binding->format('Y-m-d H:i:s').'\'', ENT_NOQUOTES, 'UTF-8'); } return htmlspecialchars($binding, ENT_NOQUOTES, 'UTF-8'); }, $bindings); $sql = str_replace(['%', '?'], ['%%', '%s'], $sql); return '<div><code>'.nl2br(trim(vsprintf($sql, $bindings))).'</code></div>'; }
php
public static function hightlight($sql, array $bindings = [], PDO $pdo = null) { // insert new lines $sql = " $sql "; $sql = preg_replace('#(?<=[\\s,(])('.static::KEYWORDS1.')(?=[\\s,)])#i', "\n\$1", $sql); // reduce spaces $sql = preg_replace('#[ \t]{2,}#', ' ', $sql); // syntax highlight $sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8'); $sql = preg_replace_callback('#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])('.static::KEYWORDS1.')(?=[\\s,)])|(?<=[\\s,(=])('.static::KEYWORDS2.')(?=[\\s,)=])#is', function ($matches) { if (! empty($matches[1])) { // comment return '<em style="color:gray">'.$matches[1].'</em>'; } elseif (! empty($matches[2])) { // error return '<strong style="color:red">'.$matches[2].'</strong>'; } elseif (! empty($matches[3])) { // most important keywords return '<strong style="color:blue; text-transform: uppercase;">'.$matches[3].'</strong>'; } elseif (! empty($matches[4])) { // other keywords return '<strong style="color:green">'.$matches[4].'</strong>'; } }, $sql); $bindings = array_map(function ($binding) use ($pdo) { if (is_array($binding) === true) { $binding = implode(', ', array_map(function ($value) { return is_string($value) === true ? htmlspecialchars('\''.$value.'\'', ENT_NOQUOTES, 'UTF-8') : $value; }, $binding)); return htmlspecialchars('('.$binding.')', ENT_NOQUOTES, 'UTF-8'); } if (is_string($binding) === true && (preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $binding) || preg_last_error())) { return '<i title="Length '.strlen($binding).' bytes">&lt;binary&gt;</i>'; } if (is_string($binding) === true) { $text = htmlspecialchars($pdo ? $pdo->quote($binding) : '\''.$binding.'\'', ENT_NOQUOTES, 'UTF-8'); return '<span title="Length '.strlen($text).' characters">'.$text.'</span>'; } if (is_resource($binding) === true) { $type = get_resource_type($binding); if ($type === 'stream') { $info = stream_get_meta_data($binding); } return '<i'.(isset($info['uri']) ? ' title="'.htmlspecialchars($info['uri'], ENT_NOQUOTES, 'UTF-8').'"' : null) .'>&lt;'.htmlspecialchars($type, ENT_NOQUOTES, 'UTF-8').' resource&gt;</i>'; } if ($binding instanceof DateTime) { return htmlspecialchars('\''.$binding->format('Y-m-d H:i:s').'\'', ENT_NOQUOTES, 'UTF-8'); } return htmlspecialchars($binding, ENT_NOQUOTES, 'UTF-8'); }, $bindings); $sql = str_replace(['%', '?'], ['%%', '%s'], $sql); return '<div><code>'.nl2br(trim(vsprintf($sql, $bindings))).'</code></div>'; }
[ "public", "static", "function", "hightlight", "(", "$", "sql", ",", "array", "$", "bindings", "=", "[", "]", ",", "PDO", "$", "pdo", "=", "null", ")", "{", "// insert new lines", "$", "sql", "=", "\" $sql \"", ";", "$", "sql", "=", "preg_replace", "(",...
Returns syntax highlighted SQL command. @param string $sql @param array $bindings @param \PDO $pdo @return string
[ "Returns", "syntax", "highlighted", "SQL", "command", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/Helper.php#L33-L94
recca0120/laravel-tracy
src/Panels/Helper.php
Helper.performQueryAnalysis
public static function performQueryAnalysis($sql, $version = null, $driver = null) { $hints = []; if (preg_match('/^\\s*SELECT\\s*`?[a-zA-Z0-9]*`?\\.?\\*/i', $sql)) { $hints[] = 'Use <code>SELECT *</code> only if you need all columns from table'; } if (preg_match('/ORDER BY RAND()/i', $sql)) { $hints[] = '<code>ORDER BY RAND()</code> is slow, try to avoid if you can. You can <a href="http://stackoverflow.com/questions/2663710/how-does-mysqls-order-by-rand-work">read this</a> or <a href="http://stackoverflow.com/questions/1244555/how-can-i-optimize-mysqls-order-by-rand-function">this</a>'; } if (strpos($sql, '!=') !== false) { $hints[] = 'The <code>!=</code> operator is not standard. Use the <code>&lt;&gt;</code> operator to test for inequality instead.'; } if (stripos($sql, 'WHERE') === false) { $hints[] = 'The <code>SELECT</code> statement has no <code>WHERE</code> clause and could examine many more rows than intended'; } if (preg_match('/LIMIT\\s/i', $sql) && stripos($sql, 'ORDER BY') === false) { $hints[] = '<code>LIMIT</code> without <code>ORDER BY</code> causes non-deterministic results, depending on the query execution plan'; } if (preg_match('/LIKE\\s[\'"](%.*?)[\'"]/i', $sql, $matches)) { $hints[] = 'An argument has a leading wildcard character: <code>'.$matches[1].'</code>. The predicate with this argument is not sargable and cannot use an index if one exists.'; } if ($version < 5.5 && $driver === 'mysql') { if (preg_match('/\\sIN\\s*\\(\\s*SELECT/i', $sql)) { $hints[] = '<code>IN()</code> and <code>NOT IN()</code> subqueries are poorly optimized in that MySQL version : '.$version. '. MySQL executes the subquery as a dependent subquery for each row in the outer query'; } } return $hints; }
php
public static function performQueryAnalysis($sql, $version = null, $driver = null) { $hints = []; if (preg_match('/^\\s*SELECT\\s*`?[a-zA-Z0-9]*`?\\.?\\*/i', $sql)) { $hints[] = 'Use <code>SELECT *</code> only if you need all columns from table'; } if (preg_match('/ORDER BY RAND()/i', $sql)) { $hints[] = '<code>ORDER BY RAND()</code> is slow, try to avoid if you can. You can <a href="http://stackoverflow.com/questions/2663710/how-does-mysqls-order-by-rand-work">read this</a> or <a href="http://stackoverflow.com/questions/1244555/how-can-i-optimize-mysqls-order-by-rand-function">this</a>'; } if (strpos($sql, '!=') !== false) { $hints[] = 'The <code>!=</code> operator is not standard. Use the <code>&lt;&gt;</code> operator to test for inequality instead.'; } if (stripos($sql, 'WHERE') === false) { $hints[] = 'The <code>SELECT</code> statement has no <code>WHERE</code> clause and could examine many more rows than intended'; } if (preg_match('/LIMIT\\s/i', $sql) && stripos($sql, 'ORDER BY') === false) { $hints[] = '<code>LIMIT</code> without <code>ORDER BY</code> causes non-deterministic results, depending on the query execution plan'; } if (preg_match('/LIKE\\s[\'"](%.*?)[\'"]/i', $sql, $matches)) { $hints[] = 'An argument has a leading wildcard character: <code>'.$matches[1].'</code>. The predicate with this argument is not sargable and cannot use an index if one exists.'; } if ($version < 5.5 && $driver === 'mysql') { if (preg_match('/\\sIN\\s*\\(\\s*SELECT/i', $sql)) { $hints[] = '<code>IN()</code> and <code>NOT IN()</code> subqueries are poorly optimized in that MySQL version : '.$version. '. MySQL executes the subquery as a dependent subquery for each row in the outer query'; } } return $hints; }
[ "public", "static", "function", "performQueryAnalysis", "(", "$", "sql", ",", "$", "version", "=", "null", ",", "$", "driver", "=", "null", ")", "{", "$", "hints", "=", "[", "]", ";", "if", "(", "preg_match", "(", "'/^\\\\s*SELECT\\\\s*`?[a-zA-Z0-9]*`?\\\\.?...
perform quer analysis hint. @param string $sql @param string $version @param float $driver @return array
[ "perform", "quer", "analysis", "hint", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/Helper.php#L104-L136
recca0120/laravel-tracy
src/Panels/Helper.php
Helper.explain
public static function explain(PDO $pdo, $sql, $bindings = []) { $explains = []; if (preg_match('#\s*\(?\s*SELECT\s#iA', $sql)) { $statement = $pdo->prepare('EXPLAIN '.$sql); $statement->execute($bindings); $explains = $statement->fetchAll(PDO::FETCH_CLASS); } return $explains; }
php
public static function explain(PDO $pdo, $sql, $bindings = []) { $explains = []; if (preg_match('#\s*\(?\s*SELECT\s#iA', $sql)) { $statement = $pdo->prepare('EXPLAIN '.$sql); $statement->execute($bindings); $explains = $statement->fetchAll(PDO::FETCH_CLASS); } return $explains; }
[ "public", "static", "function", "explain", "(", "PDO", "$", "pdo", ",", "$", "sql", ",", "$", "bindings", "=", "[", "]", ")", "{", "$", "explains", "=", "[", "]", ";", "if", "(", "preg_match", "(", "'#\\s*\\(?\\s*SELECT\\s#iA'", ",", "$", "sql", ")",...
explain sql. @param PDO $pdo @param string $sql @param array $bindings @return array
[ "explain", "sql", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/Helper.php#L146-L156
recca0120/laravel-tracy
src/Panels/SessionPanel.php
SessionPanel.getAttributes
protected function getAttributes() { $rows = []; if ($this->hasLaravel() === true) { $session = $this->laravel['session']; $rows = [ 'sessionId' => $session->getId(), 'sessionConfig' => $session->getSessionConfig(), 'laravelSession' => $session->all(), ]; } if (session_status() === PHP_SESSION_ACTIVE) { $rows['nativeSessionId'] = session_id(); $rows['nativeSession'] = $_SESSION; } return compact('rows'); }
php
protected function getAttributes() { $rows = []; if ($this->hasLaravel() === true) { $session = $this->laravel['session']; $rows = [ 'sessionId' => $session->getId(), 'sessionConfig' => $session->getSessionConfig(), 'laravelSession' => $session->all(), ]; } if (session_status() === PHP_SESSION_ACTIVE) { $rows['nativeSessionId'] = session_id(); $rows['nativeSession'] = $_SESSION; } return compact('rows'); }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "rows", "=", "[", "]", ";", "if", "(", "$", "this", "->", "hasLaravel", "(", ")", "===", "true", ")", "{", "$", "session", "=", "$", "this", "->", "laravel", "[", "'session'", "]", ";", ...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/SessionPanel.php#L14-L32
recca0120/laravel-tracy
src/Panels/AbstractSubscriablePanel.php
AbstractSubscriablePanel.setLaravel
public function setLaravel(Application $laravel = null) { parent::setLaravel($laravel); if ($this->hasLaravel() === true) { $this->subscribe(); } return $this; }
php
public function setLaravel(Application $laravel = null) { parent::setLaravel($laravel); if ($this->hasLaravel() === true) { $this->subscribe(); } return $this; }
[ "public", "function", "setLaravel", "(", "Application", "$", "laravel", "=", "null", ")", "{", "parent", "::", "setLaravel", "(", "$", "laravel", ")", ";", "if", "(", "$", "this", "->", "hasLaravel", "(", ")", "===", "true", ")", "{", "$", "this", "-...
setLaravel. @param \Illuminate\Contracts\Foundation\Application $laravel @return $this
[ "setLaravel", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractSubscriablePanel.php#L16-L24
recca0120/laravel-tracy
src/Panels/EventPanel.php
EventPanel.subscribe
protected function subscribe() { $id = get_class($this); Debugger::timer($id); $events = $this->laravel['events']; if (version_compare($this->laravel->version(), 5.4, '>=') === true) { $events->listen('*', function ($key, $payload) use ($id) { $execTime = Debugger::timer($id); $editorLink = static::editorLink(static::findSource()); $this->totalTime += $execTime; $this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); }); } else { $events->listen('*', function ($payload) use ($id, $events) { $execTime = Debugger::timer($id); $key = $events->firing(); $editorLink = static::editorLink(static::findSource()); $this->totalTime += $execTime; $this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); }); } }
php
protected function subscribe() { $id = get_class($this); Debugger::timer($id); $events = $this->laravel['events']; if (version_compare($this->laravel->version(), 5.4, '>=') === true) { $events->listen('*', function ($key, $payload) use ($id) { $execTime = Debugger::timer($id); $editorLink = static::editorLink(static::findSource()); $this->totalTime += $execTime; $this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); }); } else { $events->listen('*', function ($payload) use ($id, $events) { $execTime = Debugger::timer($id); $key = $events->firing(); $editorLink = static::editorLink(static::findSource()); $this->totalTime += $execTime; $this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); }); } }
[ "protected", "function", "subscribe", "(", ")", "{", "$", "id", "=", "get_class", "(", "$", "this", ")", ";", "Debugger", "::", "timer", "(", "$", "id", ")", ";", "$", "events", "=", "$", "this", "->", "laravel", "[", "'events'", "]", ";", "if", ...
subscribe.
[ "subscribe", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/EventPanel.php#L48-L70
recca0120/laravel-tracy
src/Exceptions/Handler.php
Handler.render
public function render($request, Exception $e) { $response = $this->exceptionHandler->render($request, $e); if ($this->shouldRenderException($response) === true) { $_SERVER = $request->server(); $response->setContent( $this->debuggerManager->exceptionHandler($e) ); } return $response; }
php
public function render($request, Exception $e) { $response = $this->exceptionHandler->render($request, $e); if ($this->shouldRenderException($response) === true) { $_SERVER = $request->server(); $response->setContent( $this->debuggerManager->exceptionHandler($e) ); } return $response; }
[ "public", "function", "render", "(", "$", "request", ",", "Exception", "$", "e", ")", "{", "$", "response", "=", "$", "this", "->", "exceptionHandler", "->", "render", "(", "$", "request", ",", "$", "e", ")", ";", "if", "(", "$", "this", "->", "sho...
Render an exception into an HTTP response. @param \Illuminate\Http\Request $request @param \Exception $e @return \Symfony\Component\HttpFoundation\Response
[ "Render", "an", "exception", "into", "an", "HTTP", "response", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Exceptions/Handler.php#L69-L81
recca0120/laravel-tracy
src/Exceptions/Handler.php
Handler.shouldRenderException
protected function shouldRenderException($response) { if ($response instanceof RedirectResponse) { return false; } if ($response instanceof JsonResponse) { return false; } if ($response->getContent() instanceof View) { return false; } if ($response instanceof Response && $response->getOriginalContent() instanceof View) { return false; } return true; }
php
protected function shouldRenderException($response) { if ($response instanceof RedirectResponse) { return false; } if ($response instanceof JsonResponse) { return false; } if ($response->getContent() instanceof View) { return false; } if ($response instanceof Response && $response->getOriginalContent() instanceof View) { return false; } return true; }
[ "protected", "function", "shouldRenderException", "(", "$", "response", ")", "{", "if", "(", "$", "response", "instanceof", "RedirectResponse", ")", "{", "return", "false", ";", "}", "if", "(", "$", "response", "instanceof", "JsonResponse", ")", "{", "return",...
shouldRenderException. @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response @return bool
[ "shouldRenderException", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Exceptions/Handler.php#L100-L119
recca0120/laravel-tracy
src/Panels/AbstractPanel.php
AbstractPanel.setLaravel
public function setLaravel(Application $laravel = null) { if (is_null($laravel) === false) { $this->laravel = $laravel; } return $this; }
php
public function setLaravel(Application $laravel = null) { if (is_null($laravel) === false) { $this->laravel = $laravel; } return $this; }
[ "public", "function", "setLaravel", "(", "Application", "$", "laravel", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "laravel", ")", "===", "false", ")", "{", "$", "this", "->", "laravel", "=", "$", "laravel", ";", "}", "return", "$", "this...
setLaravel. @param \Illuminate\Contracts\Foundation\Application $laravel @return $this
[ "setLaravel", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractPanel.php#L57-L64
recca0120/laravel-tracy
src/Panels/AbstractPanel.php
AbstractPanel.render
protected function render($view) { $view = $this->getViewPath().$view.'.php'; if (empty($this->attributes) === true) { $this->template->setAttributes( $this->attributes = $this->getAttributes() ); } return $this->template->render($view); }
php
protected function render($view) { $view = $this->getViewPath().$view.'.php'; if (empty($this->attributes) === true) { $this->template->setAttributes( $this->attributes = $this->getAttributes() ); } return $this->template->render($view); }
[ "protected", "function", "render", "(", "$", "view", ")", "{", "$", "view", "=", "$", "this", "->", "getViewPath", "(", ")", ".", "$", "view", ".", "'.php'", ";", "if", "(", "empty", "(", "$", "this", "->", "attributes", ")", "===", "true", ")", ...
render. @param string $view @return string
[ "render", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractPanel.php#L102-L112
recca0120/laravel-tracy
src/Panels/AbstractPanel.php
AbstractPanel.getViewPath
protected function getViewPath() { if (is_null($this->viewPath) === false) { return $this->viewPath; } return $this->viewPath = __DIR__.'/../../resources/views/'.ucfirst(class_basename(get_class($this))).'/'; }
php
protected function getViewPath() { if (is_null($this->viewPath) === false) { return $this->viewPath; } return $this->viewPath = __DIR__.'/../../resources/views/'.ucfirst(class_basename(get_class($this))).'/'; }
[ "protected", "function", "getViewPath", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "viewPath", ")", "===", "false", ")", "{", "return", "$", "this", "->", "viewPath", ";", "}", "return", "$", "this", "->", "viewPath", "=", "__DIR__", ...
getViewPath. @return string
[ "getViewPath", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractPanel.php#L119-L126
recca0120/laravel-tracy
src/Panels/AbstractPanel.php
AbstractPanel.findSource
protected static function findSource() { $source = ''; $trace = debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false); foreach ($trace as $row) { if (isset($row['file']) === false) { continue; } if (isset($row['function']) === true && strpos($row['function'], 'call_user_func') === 0) { continue; } if (isset($row['class']) === true && ( is_subclass_of($row['class'], '\Tracy\IBarPanel') === true || strpos(str_replace('/', '\\', $row['file']), 'Illuminate\\') !== false )) { continue; } $source = [$row['file'], (int) $row['line']]; } return $source; }
php
protected static function findSource() { $source = ''; $trace = debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false); foreach ($trace as $row) { if (isset($row['file']) === false) { continue; } if (isset($row['function']) === true && strpos($row['function'], 'call_user_func') === 0) { continue; } if (isset($row['class']) === true && ( is_subclass_of($row['class'], '\Tracy\IBarPanel') === true || strpos(str_replace('/', '\\', $row['file']), 'Illuminate\\') !== false )) { continue; } $source = [$row['file'], (int) $row['line']]; } return $source; }
[ "protected", "static", "function", "findSource", "(", ")", "{", "$", "source", "=", "''", ";", "$", "trace", "=", "debug_backtrace", "(", "PHP_VERSION_ID", ">=", "50306", "?", "DEBUG_BACKTRACE_IGNORE_ARGS", ":", "false", ")", ";", "foreach", "(", "$", "trace...
Use a backtrace to search for the origin of the query. @return string|array
[ "Use", "a", "backtrace", "to", "search", "for", "the", "origin", "of", "the", "query", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractPanel.php#L140-L164
recca0120/laravel-tracy
src/Panels/AbstractPanel.php
AbstractPanel.editorLink
protected static function editorLink($source) { if (is_string($source) === true) { $file = $source; $line = null; } else { $file = $source[0]; $line = $source[1]; } return Helpers::editorLink($file, $line); }
php
protected static function editorLink($source) { if (is_string($source) === true) { $file = $source; $line = null; } else { $file = $source[0]; $line = $source[1]; } return Helpers::editorLink($file, $line); }
[ "protected", "static", "function", "editorLink", "(", "$", "source", ")", "{", "if", "(", "is_string", "(", "$", "source", ")", "===", "true", ")", "{", "$", "file", "=", "$", "source", ";", "$", "line", "=", "null", ";", "}", "else", "{", "$", "...
editor link. @param string|array $source @return string
[ "editor", "link", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/AbstractPanel.php#L172-L183
recca0120/laravel-tracy
src/Panels/DatabasePanel.php
DatabasePanel.logQuery
public function logQuery($sql, $bindings = [], $time = 0, $name = null, PDO $pdo = null, $driver = 'mysql') { $this->counter++; $this->totalTime += $time; $source = static::findSource(); $editorLink = static::editorLink($source); $this->queries[] = [ 'sql' => $sql, 'bindings' => $bindings, 'time' => $time, 'name' => $name, 'pdo' => $pdo, 'driver' => $driver, 'source' => $source, 'editorLink' => $editorLink, 'hightlight' => null, ]; return $this; }
php
public function logQuery($sql, $bindings = [], $time = 0, $name = null, PDO $pdo = null, $driver = 'mysql') { $this->counter++; $this->totalTime += $time; $source = static::findSource(); $editorLink = static::editorLink($source); $this->queries[] = [ 'sql' => $sql, 'bindings' => $bindings, 'time' => $time, 'name' => $name, 'pdo' => $pdo, 'driver' => $driver, 'source' => $source, 'editorLink' => $editorLink, 'hightlight' => null, ]; return $this; }
[ "public", "function", "logQuery", "(", "$", "sql", ",", "$", "bindings", "=", "[", "]", ",", "$", "time", "=", "0", ",", "$", "name", "=", "null", ",", "PDO", "$", "pdo", "=", "null", ",", "$", "driver", "=", "'mysql'", ")", "{", "$", "this", ...
logQuery. @param string $sql @param array $bindings @param int $time @param string $name @param PDO $pdo @param string $driver @return $this
[ "logQuery", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/DatabasePanel.php#L43-L62
recca0120/laravel-tracy
src/Panels/DatabasePanel.php
DatabasePanel.subscribe
protected function subscribe() { $events = $this->laravel['events']; if (version_compare($this->laravel->version(), 5.2, '>=') === true) { $events->listen('Illuminate\Database\Events\QueryExecuted', function ($event) { $this->logQuery( $event->sql, $event->bindings, $event->time, $event->connectionName, $event->connection->getPdo() ); }); } else { $events->listen('illuminate.query', function ($sql, $bindings, $time, $connectionName) { $this->logQuery( $sql, $bindings, $time, $connectionName, $this->laravel['db']->connection($connectionName)->getPdo() ); }); } }
php
protected function subscribe() { $events = $this->laravel['events']; if (version_compare($this->laravel->version(), 5.2, '>=') === true) { $events->listen('Illuminate\Database\Events\QueryExecuted', function ($event) { $this->logQuery( $event->sql, $event->bindings, $event->time, $event->connectionName, $event->connection->getPdo() ); }); } else { $events->listen('illuminate.query', function ($sql, $bindings, $time, $connectionName) { $this->logQuery( $sql, $bindings, $time, $connectionName, $this->laravel['db']->connection($connectionName)->getPdo() ); }); } }
[ "protected", "function", "subscribe", "(", ")", "{", "$", "events", "=", "$", "this", "->", "laravel", "[", "'events'", "]", ";", "if", "(", "version_compare", "(", "$", "this", "->", "laravel", "->", "version", "(", ")", ",", "5.2", ",", "'>='", ")"...
subscribe.
[ "subscribe", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/DatabasePanel.php#L67-L91
recca0120/laravel-tracy
src/Panels/DatabasePanel.php
DatabasePanel.getAttributes
protected function getAttributes() { $queries = []; foreach ($this->queries as $query) { $sql = $query['sql']; $bindings = $query['bindings']; $pdo = $query['pdo']; $driver = $query['driver']; $version = 0; $hightlight = Helper::hightlight($sql, $bindings, $pdo); $explains = []; $hints = []; if ($pdo instanceof PDO) { $driver = $this->getDatabaseDriver($pdo); if ($driver === 'mysql') { $version = $this->getDatabaseVersion($pdo); $explains = Helper::explain($pdo, $sql, $bindings); $hints = Helper::performQueryAnalysis($sql, $version, $driver); } } $queries[] = array_merge($query, compact('hightlight', 'explains', 'hints', 'driver', 'version')); } return [ 'counter' => $this->counter, 'totalTime' => $this->totalTime, 'queries' => $queries, ]; }
php
protected function getAttributes() { $queries = []; foreach ($this->queries as $query) { $sql = $query['sql']; $bindings = $query['bindings']; $pdo = $query['pdo']; $driver = $query['driver']; $version = 0; $hightlight = Helper::hightlight($sql, $bindings, $pdo); $explains = []; $hints = []; if ($pdo instanceof PDO) { $driver = $this->getDatabaseDriver($pdo); if ($driver === 'mysql') { $version = $this->getDatabaseVersion($pdo); $explains = Helper::explain($pdo, $sql, $bindings); $hints = Helper::performQueryAnalysis($sql, $version, $driver); } } $queries[] = array_merge($query, compact('hightlight', 'explains', 'hints', 'driver', 'version')); } return [ 'counter' => $this->counter, 'totalTime' => $this->totalTime, 'queries' => $queries, ]; }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "queries", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "queries", "as", "$", "query", ")", "{", "$", "sql", "=", "$", "query", "[", "'sql'", "]", ";", "$", "bindings", "=", ...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/DatabasePanel.php#L98-L128
recca0120/laravel-tracy
src/Panels/DatabasePanel.php
DatabasePanel.getDatabaseDriver
protected function getDatabaseDriver(PDO $pdo) { try { $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); } catch (Exception $e) { $driver = null; } return $driver; }
php
protected function getDatabaseDriver(PDO $pdo) { try { $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); } catch (Exception $e) { $driver = null; } return $driver; }
[ "protected", "function", "getDatabaseDriver", "(", "PDO", "$", "pdo", ")", "{", "try", "{", "$", "driver", "=", "$", "pdo", "->", "getAttribute", "(", "PDO", "::", "ATTR_DRIVER_NAME", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", ...
getDatabaseDriver. @param \PDO $pdo @return string
[ "getDatabaseDriver", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/DatabasePanel.php#L136-L145
recca0120/laravel-tracy
src/Panels/DatabasePanel.php
DatabasePanel.getDatabaseVersion
protected function getDatabaseVersion(PDO $pdo) { try { $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION); } catch (Exception $e) { $version = 0; } return $version; }
php
protected function getDatabaseVersion(PDO $pdo) { try { $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION); } catch (Exception $e) { $version = 0; } return $version; }
[ "protected", "function", "getDatabaseVersion", "(", "PDO", "$", "pdo", ")", "{", "try", "{", "$", "version", "=", "$", "pdo", "->", "getAttribute", "(", "PDO", "::", "ATTR_SERVER_VERSION", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "...
getDatabaseVersion. @param \PDO $pdo @return string
[ "getDatabaseVersion", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/DatabasePanel.php#L153-L162
recca0120/laravel-tracy
src/LaravelTracyServiceProvider.php
LaravelTracyServiceProvider.boot
public function boot(Kernel $kernel, View $view, Router $router) { $config = $this->app['config']['tracy']; $this->handleRoutes($router, Arr::get($config, 'route', [])); if ($this->app->runningInConsole() === true) { $this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config'); return; } $view->getEngineResolver() ->resolve('blade') ->getCompiler() ->directive('bdump', function ($expression) { return "<?php \Tracy\Debugger::barDump({$expression}); ?>"; }); $enabled = Arr::get($config, 'enabled', true) === true; if ($enabled === false) { return; } $showException = Arr::get($config, 'showException', true); if ($showException === true) { $this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) { return new Handler($exceptionHandler, $app[DebuggerManager::class]); }); } $showBar = Arr::get($config, 'showBar', true); if ($showBar === true) { $kernel->prependMiddleware(RenderBar::class); } }
php
public function boot(Kernel $kernel, View $view, Router $router) { $config = $this->app['config']['tracy']; $this->handleRoutes($router, Arr::get($config, 'route', [])); if ($this->app->runningInConsole() === true) { $this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config'); return; } $view->getEngineResolver() ->resolve('blade') ->getCompiler() ->directive('bdump', function ($expression) { return "<?php \Tracy\Debugger::barDump({$expression}); ?>"; }); $enabled = Arr::get($config, 'enabled', true) === true; if ($enabled === false) { return; } $showException = Arr::get($config, 'showException', true); if ($showException === true) { $this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) { return new Handler($exceptionHandler, $app[DebuggerManager::class]); }); } $showBar = Arr::get($config, 'showBar', true); if ($showBar === true) { $kernel->prependMiddleware(RenderBar::class); } }
[ "public", "function", "boot", "(", "Kernel", "$", "kernel", ",", "View", "$", "view", ",", "Router", "$", "router", ")", "{", "$", "config", "=", "$", "this", "->", "app", "[", "'config'", "]", "[", "'tracy'", "]", ";", "$", "this", "->", "handleRo...
boot. @param DebuggerManager $debuggerManager @param \Illuminate\Contracts\Http\Kernel $kernel @param \Illuminate\Contracts\View\Factory $view @param \Illuminate\Routing\Router $router
[ "boot", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/LaravelTracyServiceProvider.php#L42-L76
recca0120/laravel-tracy
src/LaravelTracyServiceProvider.php
LaravelTracyServiceProvider.register
public function register() { $this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy'); $config = Arr::get($this->app['config'], 'tracy'); if (Arr::get($config, 'panels.terminal') === true) { $this->app->register(TerminalServiceProvider::class); } $this->app->singleton(BlueScreen::class, function () { return Debugger::getBlueScreen(); }); $this->app->singleton(Bar::class, function ($app) use ($config) { return (new BarManager(Debugger::getBar(), $app['request'], $app)) ->loadPanels(Arr::get($config, 'panels', [])) ->getBar(); }); $this->app->singleton(DebuggerManager::class, function ($app) use ($config) { return (new DebuggerManager( DebuggerManager::init($config), $app[Bar::class], $app[BlueScreen::class], new Session ))->setUrlGenerator($app['url']); }); }
php
public function register() { $this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy'); $config = Arr::get($this->app['config'], 'tracy'); if (Arr::get($config, 'panels.terminal') === true) { $this->app->register(TerminalServiceProvider::class); } $this->app->singleton(BlueScreen::class, function () { return Debugger::getBlueScreen(); }); $this->app->singleton(Bar::class, function ($app) use ($config) { return (new BarManager(Debugger::getBar(), $app['request'], $app)) ->loadPanels(Arr::get($config, 'panels', [])) ->getBar(); }); $this->app->singleton(DebuggerManager::class, function ($app) use ($config) { return (new DebuggerManager( DebuggerManager::init($config), $app[Bar::class], $app[BlueScreen::class], new Session ))->setUrlGenerator($app['url']); }); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "mergeConfigFrom", "(", "__DIR__", ".", "'/../config/tracy.php'", ",", "'tracy'", ")", ";", "$", "config", "=", "Arr", "::", "get", "(", "$", "this", "->", "app", "[", "'config'", "]", ...
Register the service provider.
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/LaravelTracyServiceProvider.php#L81-L109
recca0120/laravel-tracy
src/LaravelTracyServiceProvider.php
LaravelTracyServiceProvider.handleRoutes
protected function handleRoutes(Router $router, $config = []) { if ($this->app->routesAreCached() === false) { $router->group(array_merge([ 'namespace' => $this->namespace, ], $config), function (Router $router) { require __DIR__.'/../routes/web.php'; }); } }
php
protected function handleRoutes(Router $router, $config = []) { if ($this->app->routesAreCached() === false) { $router->group(array_merge([ 'namespace' => $this->namespace, ], $config), function (Router $router) { require __DIR__.'/../routes/web.php'; }); } }
[ "protected", "function", "handleRoutes", "(", "Router", "$", "router", ",", "$", "config", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "app", "->", "routesAreCached", "(", ")", "===", "false", ")", "{", "$", "router", "->", "group", "(", ...
register routes. @param \Illuminate\Routing\Router $router @param array $config
[ "register", "routes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/LaravelTracyServiceProvider.php#L127-L136
recca0120/laravel-tracy
src/Http/Controllers/LaravelTracyController.php
LaravelTracyController.bar
public function bar(DebuggerManager $debuggerManager, Request $request, ResponseFactory $responseFactory) { return $responseFactory->stream(function () use ($debuggerManager, $request) { list($headers, $content) = $debuggerManager->dispatchAssets($request->get('_tracy_bar')); if (headers_sent() === false) { foreach ($headers as $name => $value) { header(sprintf('%s: %s', $name, $value), true, 200); } } echo $content; }, 200); }
php
public function bar(DebuggerManager $debuggerManager, Request $request, ResponseFactory $responseFactory) { return $responseFactory->stream(function () use ($debuggerManager, $request) { list($headers, $content) = $debuggerManager->dispatchAssets($request->get('_tracy_bar')); if (headers_sent() === false) { foreach ($headers as $name => $value) { header(sprintf('%s: %s', $name, $value), true, 200); } } echo $content; }, 200); }
[ "public", "function", "bar", "(", "DebuggerManager", "$", "debuggerManager", ",", "Request", "$", "request", ",", "ResponseFactory", "$", "responseFactory", ")", "{", "return", "$", "responseFactory", "->", "stream", "(", "function", "(", ")", "use", "(", "$",...
bar. @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager @param \Illuminate\Http\Request $request @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory @param string $type @return \Illuminate\Http\Response
[ "bar", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Http/Controllers/LaravelTracyController.php#L21-L32
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.init
public static function init($config = []) { $config = array_merge([ 'accepts' => [], 'appendTo' => 'body', 'showBar' => false, 'editor' => Debugger::$editor, 'maxDepth' => Debugger::$maxDepth, 'maxLength' => Debugger::$maxLength, 'scream' => true, 'showLocation' => true, 'strictMode' => true, 'currentTime' => $_SERVER['REQUEST_TIME_FLOAT'] ?: microtime(true), 'editorMapping' => isset(Debugger::$editorMapping) === true ? Debugger::$editorMapping : [], ], $config); Debugger::$editor = $config['editor']; Debugger::$maxDepth = $config['maxDepth']; Debugger::$maxLength = $config['maxLength']; Debugger::$scream = $config['scream']; Debugger::$showLocation = $config['showLocation']; Debugger::$strictMode = $config['strictMode']; Debugger::$time = $config['currentTime']; if (isset(Debugger::$editorMapping) === true) { Debugger::$editorMapping = $config['editorMapping']; } return $config; }
php
public static function init($config = []) { $config = array_merge([ 'accepts' => [], 'appendTo' => 'body', 'showBar' => false, 'editor' => Debugger::$editor, 'maxDepth' => Debugger::$maxDepth, 'maxLength' => Debugger::$maxLength, 'scream' => true, 'showLocation' => true, 'strictMode' => true, 'currentTime' => $_SERVER['REQUEST_TIME_FLOAT'] ?: microtime(true), 'editorMapping' => isset(Debugger::$editorMapping) === true ? Debugger::$editorMapping : [], ], $config); Debugger::$editor = $config['editor']; Debugger::$maxDepth = $config['maxDepth']; Debugger::$maxLength = $config['maxLength']; Debugger::$scream = $config['scream']; Debugger::$showLocation = $config['showLocation']; Debugger::$strictMode = $config['strictMode']; Debugger::$time = $config['currentTime']; if (isset(Debugger::$editorMapping) === true) { Debugger::$editorMapping = $config['editorMapping']; } return $config; }
[ "public", "static", "function", "init", "(", "$", "config", "=", "[", "]", ")", "{", "$", "config", "=", "array_merge", "(", "[", "'accepts'", "=>", "[", "]", ",", "'appendTo'", "=>", "'body'", ",", "'showBar'", "=>", "false", ",", "'editor'", "=>", ...
init. @param array $config @return array
[ "init", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L72-L101
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.dispatchAssets
public function dispatchAssets($type) { switch ($type) { case 'css': case 'js': $headers = [ 'Content-Type' => $type === 'css' ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8', 'Cache-Control' => 'max-age=86400', ]; $content = $this->renderBuffer(function () { return $this->bar->dispatchAssets(); }); break; default: $headers = [ 'Content-Type' => 'text/javascript; charset=utf-8', ]; $content = $this->dispatch(); break; } return [ array_merge($headers, [ 'Content-Length' => strlen($content), ]), $content, ]; }
php
public function dispatchAssets($type) { switch ($type) { case 'css': case 'js': $headers = [ 'Content-Type' => $type === 'css' ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8', 'Cache-Control' => 'max-age=86400', ]; $content = $this->renderBuffer(function () { return $this->bar->dispatchAssets(); }); break; default: $headers = [ 'Content-Type' => 'text/javascript; charset=utf-8', ]; $content = $this->dispatch(); break; } return [ array_merge($headers, [ 'Content-Length' => strlen($content), ]), $content, ]; }
[ "public", "function", "dispatchAssets", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'css'", ":", "case", "'js'", ":", "$", "headers", "=", "[", "'Content-Type'", "=>", "$", "type", "===", "'css'", "?", "'text/css; charset=u...
dispatchAssets. @param string $type @return array
[ "dispatchAssets", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L152-L179
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.dispatch
public function dispatch() { if ($this->session->isStarted() === false) { $this->session->start(); } return $this->renderBuffer(function () { return $this->bar->dispatchAssets(); }); }
php
public function dispatch() { if ($this->session->isStarted() === false) { $this->session->start(); } return $this->renderBuffer(function () { return $this->bar->dispatchAssets(); }); }
[ "public", "function", "dispatch", "(", ")", "{", "if", "(", "$", "this", "->", "session", "->", "isStarted", "(", ")", "===", "false", ")", "{", "$", "this", "->", "session", "->", "start", "(", ")", ";", "}", "return", "$", "this", "->", "renderBu...
dispatch. @return string
[ "dispatch", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L186-L195
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.shutdownHandler
public function shutdownHandler($content, $ajax = false, $error = null) { $error = $error ?: error_get_last(); if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) { return $this->exceptionHandler( Helpers::fixStack( new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']) ) ); } return array_reduce(['renderLoader', 'renderBar'], function ($content, $method) use ($ajax) { return call_user_func([$this, $method], $content, $ajax); }, $content); }
php
public function shutdownHandler($content, $ajax = false, $error = null) { $error = $error ?: error_get_last(); if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) { return $this->exceptionHandler( Helpers::fixStack( new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']) ) ); } return array_reduce(['renderLoader', 'renderBar'], function ($content, $method) use ($ajax) { return call_user_func([$this, $method], $content, $ajax); }, $content); }
[ "public", "function", "shutdownHandler", "(", "$", "content", ",", "$", "ajax", "=", "false", ",", "$", "error", "=", "null", ")", "{", "$", "error", "=", "$", "error", "?", ":", "error_get_last", "(", ")", ";", "if", "(", "in_array", "(", "$", "er...
shutdownHandler. @param string $content @param bool $ajax @param int $error @return string
[ "shutdownHandler", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L205-L219
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.exceptionHandler
public function exceptionHandler(Exception $exception) { return $this->renderBuffer(function () use ($exception) { Helpers::improveException($exception); $this->blueScreen->render($exception); }); }
php
public function exceptionHandler(Exception $exception) { return $this->renderBuffer(function () use ($exception) { Helpers::improveException($exception); $this->blueScreen->render($exception); }); }
[ "public", "function", "exceptionHandler", "(", "Exception", "$", "exception", ")", "{", "return", "$", "this", "->", "renderBuffer", "(", "function", "(", ")", "use", "(", "$", "exception", ")", "{", "Helpers", "::", "improveException", "(", "$", "exception"...
exceptionHandler. @param \Exception $exception @return string
[ "exceptionHandler", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L227-L233
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.renderLoader
protected function renderLoader($content, $ajax = false) { if ($ajax === true || $this->session->isStarted() === false) { return $content; } return $this->render($content, 'renderLoader', ['head', 'body']); }
php
protected function renderLoader($content, $ajax = false) { if ($ajax === true || $this->session->isStarted() === false) { return $content; } return $this->render($content, 'renderLoader', ['head', 'body']); }
[ "protected", "function", "renderLoader", "(", "$", "content", ",", "$", "ajax", "=", "false", ")", "{", "if", "(", "$", "ajax", "===", "true", "||", "$", "this", "->", "session", "->", "isStarted", "(", ")", "===", "false", ")", "{", "return", "$", ...
renderLoader. @param string $content @param bool $ajax @return string
[ "renderLoader", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L242-L249
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.render
protected function render($content, $method, $appendTags = ['body']) { $appendHtml = $this->renderBuffer(function () use ($method) { $requestUri = Arr::get($_SERVER, 'REQUEST_URI'); Arr::set($_SERVER, 'REQUEST_URI', ''); call_user_func([$this->bar, $method]); Arr::set($_SERVER, 'REQUEST_URI', $requestUri); }); $appendTags = array_unique($appendTags); foreach ($appendTags as $appendTag) { $pos = strripos($content, '</'.$appendTag.'>'); if ($pos !== false) { return substr_replace($content, $appendHtml, $pos, 0); } } return $content.$appendHtml; }
php
protected function render($content, $method, $appendTags = ['body']) { $appendHtml = $this->renderBuffer(function () use ($method) { $requestUri = Arr::get($_SERVER, 'REQUEST_URI'); Arr::set($_SERVER, 'REQUEST_URI', ''); call_user_func([$this->bar, $method]); Arr::set($_SERVER, 'REQUEST_URI', $requestUri); }); $appendTags = array_unique($appendTags); foreach ($appendTags as $appendTag) { $pos = strripos($content, '</'.$appendTag.'>'); if ($pos !== false) { return substr_replace($content, $appendHtml, $pos, 0); } } return $content.$appendHtml; }
[ "protected", "function", "render", "(", "$", "content", ",", "$", "method", ",", "$", "appendTags", "=", "[", "'body'", "]", ")", "{", "$", "appendHtml", "=", "$", "this", "->", "renderBuffer", "(", "function", "(", ")", "use", "(", "$", "method", ")...
render. @param string $content @param string $method @param array $appendTo @return string
[ "render", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L274-L294
recca0120/laravel-tracy
src/DebuggerManager.php
DebuggerManager.replacePath
protected function replacePath($content) { $path = is_null($this->urlGenerator) === false ? $this->urlGenerator->route(Arr::get($this->config, 'route.as').'bar') : null; return is_null($path) === false ? str_replace('?_tracy_bar', $path.'?_tracy_bar', $content) : $content; }
php
protected function replacePath($content) { $path = is_null($this->urlGenerator) === false ? $this->urlGenerator->route(Arr::get($this->config, 'route.as').'bar') : null; return is_null($path) === false ? str_replace('?_tracy_bar', $path.'?_tracy_bar', $content) : $content; }
[ "protected", "function", "replacePath", "(", "$", "content", ")", "{", "$", "path", "=", "is_null", "(", "$", "this", "->", "urlGenerator", ")", "===", "false", "?", "$", "this", "->", "urlGenerator", "->", "route", "(", "Arr", "::", "get", "(", "$", ...
replacePath. @param string $content @return string
[ "replacePath", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/DebuggerManager.php#L316-L325
recca0120/laravel-tracy
src/Template.php
Template.render
public function render($view) { extract($this->attributes); ob_start(); require $view; return $this->minify === true ? $this->min(ob_get_clean()) : ob_get_clean(); }
php
public function render($view) { extract($this->attributes); ob_start(); require $view; return $this->minify === true ? $this->min(ob_get_clean()) : ob_get_clean(); }
[ "public", "function", "render", "(", "$", "view", ")", "{", "extract", "(", "$", "this", "->", "attributes", ")", ";", "ob_start", "(", ")", ";", "require", "$", "view", ";", "return", "$", "this", "->", "minify", "===", "true", "?", "$", "this", "...
render. @param string $view @return string
[ "render", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Template.php#L53-L63
recca0120/laravel-tracy
src/Middleware/RenderBar.php
RenderBar.handle
public function handle($request, $next) { return $request->has('_tracy_bar') === true ? $this->keepFlashSession($request, $next) : $this->render($request, $next); }
php
public function handle($request, $next) { return $request->has('_tracy_bar') === true ? $this->keepFlashSession($request, $next) : $this->render($request, $next); }
[ "public", "function", "handle", "(", "$", "request", ",", "$", "next", ")", "{", "return", "$", "request", "->", "has", "(", "'_tracy_bar'", ")", "===", "true", "?", "$", "this", "->", "keepFlashSession", "(", "$", "request", ",", "$", "next", ")", "...
handle. @param \Illuminate\Http\Request $request @param \Closure $next @return \Symfony\Component\HttpFoundation\Response
[ "handle", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Middleware/RenderBar.php#L50-L55
recca0120/laravel-tracy
src/Middleware/RenderBar.php
RenderBar.keepFlashSession
protected function keepFlashSession($request, $next) { $type = $request->get('_tracy_bar'); if ($request->hasSession() === true && in_array($type, ['js', 'css'], true) === false) { $request->session()->reflash(); } return $next($request); }
php
protected function keepFlashSession($request, $next) { $type = $request->get('_tracy_bar'); if ($request->hasSession() === true && in_array($type, ['js', 'css'], true) === false) { $request->session()->reflash(); } return $next($request); }
[ "protected", "function", "keepFlashSession", "(", "$", "request", ",", "$", "next", ")", "{", "$", "type", "=", "$", "request", "->", "get", "(", "'_tracy_bar'", ")", ";", "if", "(", "$", "request", "->", "hasSession", "(", ")", "===", "true", "&&", ...
keepFlashSession. @param \Illuminate\Http\Request $request @param \Closure $next @return \Symfony\Component\HttpFoundation\Response
[ "keepFlashSession", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Middleware/RenderBar.php#L64-L72
recca0120/laravel-tracy
src/Middleware/RenderBar.php
RenderBar.render
protected function render($request, $next) { $this->debuggerManager->dispatch(); $response = $next($request); $ajax = $request->ajax(); if ($this->reject($response, $request, $ajax) === true) { return $response; } $method = method_exists($this->events, 'dispatch') ? 'dispatch' : 'fire'; $this->events->{$method}(new BeforeBarRender($request, $response)); $response->setContent( $this->debuggerManager->shutdownHandler( $response->getContent(), $ajax ) ); return $response; }
php
protected function render($request, $next) { $this->debuggerManager->dispatch(); $response = $next($request); $ajax = $request->ajax(); if ($this->reject($response, $request, $ajax) === true) { return $response; } $method = method_exists($this->events, 'dispatch') ? 'dispatch' : 'fire'; $this->events->{$method}(new BeforeBarRender($request, $response)); $response->setContent( $this->debuggerManager->shutdownHandler( $response->getContent(), $ajax ) ); return $response; }
[ "protected", "function", "render", "(", "$", "request", ",", "$", "next", ")", "{", "$", "this", "->", "debuggerManager", "->", "dispatch", "(", ")", ";", "$", "response", "=", "$", "next", "(", "$", "request", ")", ";", "$", "ajax", "=", "$", "req...
render. @param \Illuminate\Http\Request $request @param \Closure $next @return \Symfony\Component\HttpFoundation\Response
[ "render", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Middleware/RenderBar.php#L81-L103
recca0120/laravel-tracy
src/Middleware/RenderBar.php
RenderBar.reject
protected function reject(Response $response, Request $request, $ajax) { if ( $response instanceof BinaryFileResponse || $response instanceof StreamedResponse || $response instanceof RedirectResponse ) { return true; } if ($ajax === true) { return false; } $contentType = strtolower($response->headers->get('Content-Type')); $accepts = $this->debuggerManager->accepts(); if ((empty($contentType) === true && $response->getStatusCode() >= 400) || count($accepts) === 0 ) { return false; } foreach ($accepts as $accept) { if (strpos($contentType, $accept) !== false) { return false; } } return true; }
php
protected function reject(Response $response, Request $request, $ajax) { if ( $response instanceof BinaryFileResponse || $response instanceof StreamedResponse || $response instanceof RedirectResponse ) { return true; } if ($ajax === true) { return false; } $contentType = strtolower($response->headers->get('Content-Type')); $accepts = $this->debuggerManager->accepts(); if ((empty($contentType) === true && $response->getStatusCode() >= 400) || count($accepts) === 0 ) { return false; } foreach ($accepts as $accept) { if (strpos($contentType, $accept) !== false) { return false; } } return true; }
[ "protected", "function", "reject", "(", "Response", "$", "response", ",", "Request", "$", "request", ",", "$", "ajax", ")", "{", "if", "(", "$", "response", "instanceof", "BinaryFileResponse", "||", "$", "response", "instanceof", "StreamedResponse", "||", "$",...
reject. @param \Symfony\Component\HttpFoundation\Response $response @param \Illuminate\Http\Request $request @param bool $ajax @return bool
[ "reject", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Middleware/RenderBar.php#L114-L143
recca0120/laravel-tracy
src/Tracy.php
Tracy.instance
public static function instance($config = [], BarManager $barManager = null, Bar $bar = null) { static $instance; if (is_null($instance) === false) { return $instance; } return $instance = new static($config, $barManager, $bar); }
php
public static function instance($config = [], BarManager $barManager = null, Bar $bar = null) { static $instance; if (is_null($instance) === false) { return $instance; } return $instance = new static($config, $barManager, $bar); }
[ "public", "static", "function", "instance", "(", "$", "config", "=", "[", "]", ",", "BarManager", "$", "barManager", "=", "null", ",", "Bar", "$", "bar", "=", "null", ")", "{", "static", "$", "instance", ";", "if", "(", "is_null", "(", "$", "instance...
instance. @param array$config @return static
[ "instance", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Tracy.php#L85-L94
recca0120/laravel-tracy
src/Panels/RequestPanel.php
RequestPanel.getAttributes
protected function getAttributes() { $request = $this->hasLaravel() === true ? $this->laravel['request'] : Request::capture(); $rows = [ 'ip' => $request->ip(), 'ips' => $request->ips(), 'query' => $request->query(), 'request' => $request->all(), 'file' => $request->file(), 'cookies' => $request->cookie(), 'format' => $request->format(), 'path' => $request->path(), 'server' => $request->server(), // 'headers' => $request->header(), ]; return compact('rows'); }
php
protected function getAttributes() { $request = $this->hasLaravel() === true ? $this->laravel['request'] : Request::capture(); $rows = [ 'ip' => $request->ip(), 'ips' => $request->ips(), 'query' => $request->query(), 'request' => $request->all(), 'file' => $request->file(), 'cookies' => $request->cookie(), 'format' => $request->format(), 'path' => $request->path(), 'server' => $request->server(), // 'headers' => $request->header(), ]; return compact('rows'); }
[ "protected", "function", "getAttributes", "(", ")", "{", "$", "request", "=", "$", "this", "->", "hasLaravel", "(", ")", "===", "true", "?", "$", "this", "->", "laravel", "[", "'request'", "]", ":", "Request", "::", "capture", "(", ")", ";", "$", "ro...
getAttributes. @return array
[ "getAttributes", "." ]
train
https://github.com/recca0120/laravel-tracy/blob/b61c61930f2e20a2758c83d9bf75424782477c58/src/Panels/RequestPanel.php#L15-L32
symfony/assetic-bundle
Command/WatchCommand.php
WatchCommand.checkAsset
private function checkAsset($name, array &$previously) { $formula = $this->am->hasFormula($name) ? serialize($this->am->getFormula($name)) : null; $asset = $this->am->get($name); $combinations = VarUtils::getCombinations( $asset->getVars(), $this->getContainer()->getParameter('assetic.variables') ); $mtime = 0; foreach ($combinations as $combination) { $asset->setValues($combination); $mtime = max($mtime, $this->am->getLastModified($asset)); } if (isset($previously[$name])) { $changed = $previously[$name]['mtime'] != $mtime || $previously[$name]['formula'] != $formula; } else { $changed = true; } $previously[$name] = array('mtime' => $mtime, 'formula' => $formula); return $changed; }
php
private function checkAsset($name, array &$previously) { $formula = $this->am->hasFormula($name) ? serialize($this->am->getFormula($name)) : null; $asset = $this->am->get($name); $combinations = VarUtils::getCombinations( $asset->getVars(), $this->getContainer()->getParameter('assetic.variables') ); $mtime = 0; foreach ($combinations as $combination) { $asset->setValues($combination); $mtime = max($mtime, $this->am->getLastModified($asset)); } if (isset($previously[$name])) { $changed = $previously[$name]['mtime'] != $mtime || $previously[$name]['formula'] != $formula; } else { $changed = true; } $previously[$name] = array('mtime' => $mtime, 'formula' => $formula); return $changed; }
[ "private", "function", "checkAsset", "(", "$", "name", ",", "array", "&", "$", "previously", ")", "{", "$", "formula", "=", "$", "this", "->", "am", "->", "hasFormula", "(", "$", "name", ")", "?", "serialize", "(", "$", "this", "->", "am", "->", "g...
Checks if an asset should be dumped. @param string $name The asset name @param array &$previously An array of previous visits @return Boolean Whether the asset should be dumped
[ "Checks", "if", "an", "asset", "should", "be", "dumped", "." ]
train
https://github.com/symfony/assetic-bundle/blob/7ffdefece4e809864f70ac69739567b6ed6fb274/Command/WatchCommand.php#L97-L122
symfony/assetic-bundle
Twig/AsseticNodeVisitor.php
AsseticNodeVisitor.checkNode
private function checkNode(\Twig_Node $node, \Twig_Environment $env, &$name = null) { if ($node instanceof \Twig_Node_Expression_Function) { $name = $node->getAttribute('name'); if ($env->getFunction($name) instanceof AsseticFilterFunction) { $arguments = array(); foreach ($node->getNode('arguments') as $argument) { $arguments[] = eval('return '.$env->compile($argument).';'); } $invoker = $env->getExtension('assetic')->getFilterInvoker($name); $factory = $invoker->getFactory(); $inputs = isset($arguments[0]) ? (array) $arguments[0] : array(); $filters = $invoker->getFilters(); $options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array()); if (!isset($options['name'])) { $options['name'] = $factory->generateAssetName($inputs, $filters); } return array($inputs, $filters, $options); } } }
php
private function checkNode(\Twig_Node $node, \Twig_Environment $env, &$name = null) { if ($node instanceof \Twig_Node_Expression_Function) { $name = $node->getAttribute('name'); if ($env->getFunction($name) instanceof AsseticFilterFunction) { $arguments = array(); foreach ($node->getNode('arguments') as $argument) { $arguments[] = eval('return '.$env->compile($argument).';'); } $invoker = $env->getExtension('assetic')->getFilterInvoker($name); $factory = $invoker->getFactory(); $inputs = isset($arguments[0]) ? (array) $arguments[0] : array(); $filters = $invoker->getFilters(); $options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array()); if (!isset($options['name'])) { $options['name'] = $factory->generateAssetName($inputs, $filters); } return array($inputs, $filters, $options); } } }
[ "private", "function", "checkNode", "(", "\\", "Twig_Node", "$", "node", ",", "\\", "Twig_Environment", "$", "env", ",", "&", "$", "name", "=", "null", ")", "{", "if", "(", "$", "node", "instanceof", "\\", "Twig_Node_Expression_Function", ")", "{", "$", ...
Extracts formulae from filter function nodes. @return array|null The formula
[ "Extracts", "formulae", "from", "filter", "function", "nodes", "." ]
train
https://github.com/symfony/assetic-bundle/blob/7ffdefece4e809864f70ac69739567b6ed6fb274/Twig/AsseticNodeVisitor.php#L86-L110
symfony/assetic-bundle
DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder() { $builder = new TreeBuilder(); $finder = new ExecutableFinder(); $rootNode = $builder->root('assetic'); $rootNode ->children() ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() ->arrayNode('use_controller') ->addDefaultsIfNotSet() ->treatTrueLike(array('enabled' => true)) ->treatFalseLike(array('enabled' => false)) ->children() ->booleanNode('enabled')->defaultValue('%kernel.debug%')->end() ->booleanNode('profiler')->defaultFalse()->end() ->end() ->end() ->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end() ->scalarNode('java')->defaultValue(function () use ($finder) { return $finder->find('java', '/usr/bin/java'); })->end() ->scalarNode('node')->defaultValue(function () use ($finder) { return $finder->find('node', '/usr/bin/node'); })->end() ->arrayNode('node_paths') ->prototype('scalar')->end() ->end() ->scalarNode('ruby')->defaultValue(function () use ($finder) { return $finder->find('ruby', '/usr/bin/ruby'); })->end() ->scalarNode('sass')->defaultValue(function () use ($finder) { return $finder->find('sass', '/usr/bin/sass'); })->end() ->scalarNode('reactjsx')->defaultValue(function () use ($finder) { return $finder->find('reactjsx', '/usr/bin/jsx'); })->end() ->end() ; $this->addVariablesSection($rootNode); $this->addBundlesSection($rootNode); $this->addAssetsSection($rootNode); $this->addFiltersSection($rootNode, $finder); $this->addWorkersSection($rootNode); $this->addTwigSection($rootNode); return $builder; }
php
public function getConfigTreeBuilder() { $builder = new TreeBuilder(); $finder = new ExecutableFinder(); $rootNode = $builder->root('assetic'); $rootNode ->children() ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() ->arrayNode('use_controller') ->addDefaultsIfNotSet() ->treatTrueLike(array('enabled' => true)) ->treatFalseLike(array('enabled' => false)) ->children() ->booleanNode('enabled')->defaultValue('%kernel.debug%')->end() ->booleanNode('profiler')->defaultFalse()->end() ->end() ->end() ->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end() ->scalarNode('java')->defaultValue(function () use ($finder) { return $finder->find('java', '/usr/bin/java'); })->end() ->scalarNode('node')->defaultValue(function () use ($finder) { return $finder->find('node', '/usr/bin/node'); })->end() ->arrayNode('node_paths') ->prototype('scalar')->end() ->end() ->scalarNode('ruby')->defaultValue(function () use ($finder) { return $finder->find('ruby', '/usr/bin/ruby'); })->end() ->scalarNode('sass')->defaultValue(function () use ($finder) { return $finder->find('sass', '/usr/bin/sass'); })->end() ->scalarNode('reactjsx')->defaultValue(function () use ($finder) { return $finder->find('reactjsx', '/usr/bin/jsx'); })->end() ->end() ; $this->addVariablesSection($rootNode); $this->addBundlesSection($rootNode); $this->addAssetsSection($rootNode); $this->addFiltersSection($rootNode, $finder); $this->addWorkersSection($rootNode); $this->addTwigSection($rootNode); return $builder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "finder", "=", "new", "ExecutableFinder", "(", ")", ";", "$", "rootNode", "=", "$", "builder", "->", "root", "(", "'assetic'", ")"...
Generates the configuration tree builder. @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
[ "Generates", "the", "configuration", "tree", "builder", "." ]
train
https://github.com/symfony/assetic-bundle/blob/7ffdefece4e809864f70ac69739567b6ed6fb274/DependencyInjection/Configuration.php#L47-L86
symfony/assetic-bundle
DependencyInjection/AsseticExtension.php
AsseticExtension.load
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('assetic.xml'); $loader->load('templating_twig.xml'); $loader->load('templating_php.xml'); $def = $container->getDefinition('assetic.parameter_bag'); if (method_exists($def, 'setFactory')) { // to be inlined in assetic.xml when dependency on Symfony DependencyInjection is bumped to 2.6 $def->setFactory(array(new Reference('service_container'), 'getParameterBag')); } else { // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 $def->setFactoryService('service_container'); $def->setFactoryMethod('getParameterBag'); } $processor = new Processor(); $configuration = $this->getConfiguration($configs, $container); $config = $processor->processConfiguration($configuration, $configs); $container->setParameter('assetic.debug', $config['debug']); $container->setParameter('assetic.use_controller', $config['use_controller']['enabled']); $container->setParameter('assetic.enable_profiler', $config['use_controller']['profiler']); $container->setParameter('assetic.read_from', $config['read_from']); $container->setParameter('assetic.write_to', $config['write_to']); $container->setParameter('assetic.variables', $config['variables']); $container->setParameter('assetic.java.bin', $config['java']); $container->setParameter('assetic.node.bin', $config['node']); $container->setParameter('assetic.node.paths', $config['node_paths']); $container->setParameter('assetic.ruby.bin', $config['ruby']); $container->setParameter('assetic.sass.bin', $config['sass']); $container->setParameter('assetic.reactjsx.bin', $config['reactjsx']); // register formulae $formulae = array(); foreach ($config['assets'] as $name => $formula) { $formulae[$name] = array($formula['inputs'], $formula['filters'], $formula['options']); } if ($formulae) { $container->getDefinition('assetic.config_resource')->replaceArgument(0, $formulae); } else { $container->removeDefinition('assetic.config_loader'); $container->removeDefinition('assetic.config_resource'); } // register filters foreach ($config['filters'] as $name => $filter) { if (isset($filter['resource'])) { $loader->load($container->getParameterBag()->resolveValue($filter['resource'])); unset($filter['resource']); } else { $loader->load('filters/'.$name.'.xml'); } if (isset($filter['file'])) { $container->getDefinition('assetic.filter.'.$name)->setFile($filter['file']); unset($filter['file']); } if (isset($filter['apply_to'])) { if (!is_array($filter['apply_to'])) { $filter['apply_to'] = array($filter['apply_to']); } foreach ($filter['apply_to'] as $i => $pattern) { $worker = new DefinitionDecorator('assetic.worker.ensure_filter'); $worker->replaceArgument(0, '/'.$pattern.'/'); $worker->replaceArgument(1, new Reference('assetic.filter.'.$name)); $worker->addTag('assetic.factory_worker'); $container->setDefinition('assetic.filter.'.$name.'.worker'.$i, $worker); } unset($filter['apply_to']); } foreach ($filter as $key => $value) { $container->setParameter('assetic.filter.'.$name.'.'.$key, $value); } } // twig functions $container->setParameter('assetic.twig_extension.functions', $config['twig']['functions']); // choose dynamic or static if ($useController = $container->getParameterBag()->resolveValue($container->getParameterBag()->get('assetic.use_controller'))) { $loader->load('controller.xml'); $container->getDefinition('assetic.helper.dynamic')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.static'); } else { $container->getDefinition('assetic.helper.static')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.dynamic'); } $container->setParameter('assetic.bundles', $config['bundles']); if ($config['workers']['cache_busting']['enabled']) { $container->getDefinition('assetic.worker.cache_busting')->addTag('assetic.factory_worker'); } }
php
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('assetic.xml'); $loader->load('templating_twig.xml'); $loader->load('templating_php.xml'); $def = $container->getDefinition('assetic.parameter_bag'); if (method_exists($def, 'setFactory')) { // to be inlined in assetic.xml when dependency on Symfony DependencyInjection is bumped to 2.6 $def->setFactory(array(new Reference('service_container'), 'getParameterBag')); } else { // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 $def->setFactoryService('service_container'); $def->setFactoryMethod('getParameterBag'); } $processor = new Processor(); $configuration = $this->getConfiguration($configs, $container); $config = $processor->processConfiguration($configuration, $configs); $container->setParameter('assetic.debug', $config['debug']); $container->setParameter('assetic.use_controller', $config['use_controller']['enabled']); $container->setParameter('assetic.enable_profiler', $config['use_controller']['profiler']); $container->setParameter('assetic.read_from', $config['read_from']); $container->setParameter('assetic.write_to', $config['write_to']); $container->setParameter('assetic.variables', $config['variables']); $container->setParameter('assetic.java.bin', $config['java']); $container->setParameter('assetic.node.bin', $config['node']); $container->setParameter('assetic.node.paths', $config['node_paths']); $container->setParameter('assetic.ruby.bin', $config['ruby']); $container->setParameter('assetic.sass.bin', $config['sass']); $container->setParameter('assetic.reactjsx.bin', $config['reactjsx']); // register formulae $formulae = array(); foreach ($config['assets'] as $name => $formula) { $formulae[$name] = array($formula['inputs'], $formula['filters'], $formula['options']); } if ($formulae) { $container->getDefinition('assetic.config_resource')->replaceArgument(0, $formulae); } else { $container->removeDefinition('assetic.config_loader'); $container->removeDefinition('assetic.config_resource'); } // register filters foreach ($config['filters'] as $name => $filter) { if (isset($filter['resource'])) { $loader->load($container->getParameterBag()->resolveValue($filter['resource'])); unset($filter['resource']); } else { $loader->load('filters/'.$name.'.xml'); } if (isset($filter['file'])) { $container->getDefinition('assetic.filter.'.$name)->setFile($filter['file']); unset($filter['file']); } if (isset($filter['apply_to'])) { if (!is_array($filter['apply_to'])) { $filter['apply_to'] = array($filter['apply_to']); } foreach ($filter['apply_to'] as $i => $pattern) { $worker = new DefinitionDecorator('assetic.worker.ensure_filter'); $worker->replaceArgument(0, '/'.$pattern.'/'); $worker->replaceArgument(1, new Reference('assetic.filter.'.$name)); $worker->addTag('assetic.factory_worker'); $container->setDefinition('assetic.filter.'.$name.'.worker'.$i, $worker); } unset($filter['apply_to']); } foreach ($filter as $key => $value) { $container->setParameter('assetic.filter.'.$name.'.'.$key, $value); } } // twig functions $container->setParameter('assetic.twig_extension.functions', $config['twig']['functions']); // choose dynamic or static if ($useController = $container->getParameterBag()->resolveValue($container->getParameterBag()->get('assetic.use_controller'))) { $loader->load('controller.xml'); $container->getDefinition('assetic.helper.dynamic')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.static'); } else { $container->getDefinition('assetic.helper.static')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.dynamic'); } $container->setParameter('assetic.bundles', $config['bundles']); if ($config['workers']['cache_busting']['enabled']) { $container->getDefinition('assetic.worker.cache_busting')->addTag('assetic.factory_worker'); } }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ...
Loads the configuration. @param array $configs An array of configuration settings @param ContainerBuilder $container A ContainerBuilder instance
[ "Loads", "the", "configuration", "." ]
train
https://github.com/symfony/assetic-bundle/blob/7ffdefece4e809864f70ac69739567b6ed6fb274/DependencyInjection/AsseticExtension.php#L35-L137