repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.add
public static function add(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $sums = array_fill(0, $length_of_arrays, 0); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 0; $j < $number_of_arrays; $j++) { $sums[$i] += $arrays[$j][$i]; } } return $sums; }
php
public static function add(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $sums = array_fill(0, $length_of_arrays, 0); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 0; $j < $number_of_arrays; $j++) { $sums[$i] += $arrays[$j][$i]; } } return $sums; }
[ "public", "static", "function", "add", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_array...
Map add against multiple arrays [x₁ + y₁, x₂ + y₂, ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "add", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L22-L37
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.subtract
public static function subtract(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $differences = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $differences[$i] -= $arrays[$j][$i]; } } return $differences; }
php
public static function subtract(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $differences = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $differences[$i] -= $arrays[$j][$i]; } } return $differences; }
[ "public", "static", "function", "subtract", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_...
Map subtract against multiple arrays [x₁ - y₁, x₂ - y₂, ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "subtract", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L50-L70
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.multiply
public static function multiply(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $products = array_fill(0, $length_of_arrays, 1); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 0; $j < $number_of_arrays; $j++) { $products[$i] *= $arrays[$j][$i]; } } return $products; }
php
public static function multiply(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $products = array_fill(0, $length_of_arrays, 1); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 0; $j < $number_of_arrays; $j++) { $products[$i] *= $arrays[$j][$i]; } } return $products; }
[ "public", "static", "function", "multiply", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_...
Map multiply against multiple arrays [x₁ * y₁, x₂ * y₂, ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "multiply", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L83-L98
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.divide
public static function divide(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $quotients = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $quotients[$i] /= $arrays[$j][$i]; } } return $quotients; }
php
public static function divide(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $quotients = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $quotients[$i] /= $arrays[$j][$i]; } } return $quotients; }
[ "public", "static", "function", "divide", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_ar...
Map divide against multiple arrays [x₁ / y₁, x₂ / y₂, ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "divide", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L111-L131
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.max
public static function max(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $maxes = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $maxes[$i] = max($maxes[$i], $arrays[$j][$i]); } } return $maxes; }
php
public static function max(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $maxes = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $maxes[$i] = max($maxes[$i], $arrays[$j][$i]); } } return $maxes; }
[ "public", "static", "function", "max", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_array...
Map max against multiple arrays [max(x₁, y₁), max(x₂, y₂), ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "max", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L144-L164
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.min
public static function min(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $mins = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $mins[$i] = min($mins[$i], $arrays[$j][$i]); } } return $mins; }
php
public static function min(array ...$arrays): array { self::checkArrayLengths($arrays); $number_of_arrays = count($arrays); $length_of_arrays = count($arrays[0]); $mins = array_map( function ($x) { return $x; }, $arrays[0] ); for ($i = 0; $i < $length_of_arrays; $i++) { for ($j = 1; $j < $number_of_arrays; $j++) { $mins[$i] = min($mins[$i], $arrays[$j][$i]); } } return $mins; }
[ "public", "static", "function", "min", "(", "array", "...", "$", "arrays", ")", ":", "array", "{", "self", "::", "checkArrayLengths", "(", "$", "arrays", ")", ";", "$", "number_of_arrays", "=", "count", "(", "$", "arrays", ")", ";", "$", "length_of_array...
Map min against multiple arrays [max(x₁, y₁), max(x₂, y₂), ... ] @param array ...$arrays Two or more arrays of numbers @return array @throws Exception\BadDataException
[ "Map", "min", "against", "multiple", "arrays" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L177-L197
train
markrogoyski/math-php
src/Functions/Map/Multi.php
Multi.checkArrayLengths
private static function checkArrayLengths(array $arrays): bool { if (count($arrays) < 2) { throw new Exception\BadDataException('Need at least two arrays to map over'); } $n = count($arrays[0]); foreach ($arrays as $array) { if (count($array) !== $n) { throw new Exception\BadDataException('Lengths of arrays are not equal'); } } return true; }
php
private static function checkArrayLengths(array $arrays): bool { if (count($arrays) < 2) { throw new Exception\BadDataException('Need at least two arrays to map over'); } $n = count($arrays[0]); foreach ($arrays as $array) { if (count($array) !== $n) { throw new Exception\BadDataException('Lengths of arrays are not equal'); } } return true; }
[ "private", "static", "function", "checkArrayLengths", "(", "array", "$", "arrays", ")", ":", "bool", "{", "if", "(", "count", "(", "$", "arrays", ")", "<", "2", ")", "{", "throw", "new", "Exception", "\\", "BadDataException", "(", "'Need at least two arrays ...
Check that two or more arrays are all the same length @param array[] $arrays @return bool @throws Exception\BadDataException if there are not at least two arrays @throws Exception\BadDataException if arrays are not equal lengths
[ "Check", "that", "two", "or", "more", "arrays", "are", "all", "the", "same", "length" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Functions/Map/Multi.php#L213-L227
train
markrogoyski/math-php
src/Number/Rational.php
Rational.toFloat
public function toFloat(): float { $frac = $this->numerator / $this->denominator; $sum = $this->whole + $frac; return $sum; }
php
public function toFloat(): float { $frac = $this->numerator / $this->denominator; $sum = $this->whole + $frac; return $sum; }
[ "public", "function", "toFloat", "(", ")", ":", "float", "{", "$", "frac", "=", "$", "this", "->", "numerator", "/", "$", "this", "->", "denominator", ";", "$", "sum", "=", "$", "this", "->", "whole", "+", "$", "frac", ";", "return", "$", "sum", ...
Rational number as a float @return float
[ "Rational", "number", "as", "a", "float" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L128-L133
train
markrogoyski/math-php
src/Number/Rational.php
Rational.abs
public function abs(): Rational { return new Rational(abs($this->whole), abs($this->numerator), abs($this->denominator)); }
php
public function abs(): Rational { return new Rational(abs($this->whole), abs($this->numerator), abs($this->denominator)); }
[ "public", "function", "abs", "(", ")", ":", "Rational", "{", "return", "new", "Rational", "(", "abs", "(", "$", "this", "->", "whole", ")", ",", "abs", "(", "$", "this", "->", "numerator", ")", ",", "abs", "(", "$", "this", "->", "denominator", ")"...
The absolute value of a rational number @return Rational
[ "The", "absolute", "value", "of", "a", "rational", "number" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L144-L147
train
markrogoyski/math-php
src/Number/Rational.php
Rational.addInt
private function addInt(int $int): Rational { $w = $this->whole + $int; return new Rational($w, $this->numerator, $this->denominator); }
php
private function addInt(int $int): Rational { $w = $this->whole + $int; return new Rational($w, $this->numerator, $this->denominator); }
[ "private", "function", "addInt", "(", "int", "$", "int", ")", ":", "Rational", "{", "$", "w", "=", "$", "this", "->", "whole", "+", "$", "int", ";", "return", "new", "Rational", "(", "$", "w", ",", "$", "this", "->", "numerator", ",", "$", "this"...
Add an integer @param int $int @return Rational
[ "Add", "an", "integer" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L180-L184
train
markrogoyski/math-php
src/Number/Rational.php
Rational.addRational
private function addRational(Rational $r): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; $rn = $r->numerator; $rd = $r->denominator; $rw = $r->whole; $w += $rw; $lcm = Algebra::lcm($d, $rd); $n = $n * intdiv($lcm, $d) + $rn * intdiv($lcm, $rd); $d = $lcm; return new Rational($w, $n, $d); }
php
private function addRational(Rational $r): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; $rn = $r->numerator; $rd = $r->denominator; $rw = $r->whole; $w += $rw; $lcm = Algebra::lcm($d, $rd); $n = $n * intdiv($lcm, $d) + $rn * intdiv($lcm, $rd); $d = $lcm; return new Rational($w, $n, $d); }
[ "private", "function", "addRational", "(", "Rational", "$", "r", ")", ":", "Rational", "{", "$", "w", "=", "$", "this", "->", "whole", ";", "$", "n", "=", "$", "this", "->", "numerator", ";", "$", "d", "=", "$", "this", "->", "denominator", ";", ...
Add a rational number @param Rational $r @return Rational
[ "Add", "a", "rational", "number" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L193-L210
train
markrogoyski/math-php
src/Number/Rational.php
Rational.multiply
public function multiply($r): Rational { if (is_int($r)) { return $this->multiplyInt($r); } elseif ($r instanceof Rational) { return $this->multiplyRational($r); } else { throw new Exception\IncorrectTypeException('Argument must be an integer or RationalNumber'); } }
php
public function multiply($r): Rational { if (is_int($r)) { return $this->multiplyInt($r); } elseif ($r instanceof Rational) { return $this->multiplyRational($r); } else { throw new Exception\IncorrectTypeException('Argument must be an integer or RationalNumber'); } }
[ "public", "function", "multiply", "(", "$", "r", ")", ":", "Rational", "{", "if", "(", "is_int", "(", "$", "r", ")", ")", "{", "return", "$", "this", "->", "multiplyInt", "(", "$", "r", ")", ";", "}", "elseif", "(", "$", "r", "instanceof", "Ratio...
Multiply Return the result of multiplying two rational numbers, or a rational number and an integer. @param Rational|int $r @return Rational @throws Exception\IncorrectTypeException if the argument is not numeric or Rational.
[ "Multiply", "Return", "the", "result", "of", "multiplying", "two", "rational", "numbers", "or", "a", "rational", "number", "and", "an", "integer", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L242-L251
train
markrogoyski/math-php
src/Number/Rational.php
Rational.multiplyInt
private function multiplyInt(int $int): Rational { $w = $this->whole * $int; $n = $this->numerator * $int; return new Rational($w, $n, $this->denominator); }
php
private function multiplyInt(int $int): Rational { $w = $this->whole * $int; $n = $this->numerator * $int; return new Rational($w, $n, $this->denominator); }
[ "private", "function", "multiplyInt", "(", "int", "$", "int", ")", ":", "Rational", "{", "$", "w", "=", "$", "this", "->", "whole", "*", "$", "int", ";", "$", "n", "=", "$", "this", "->", "numerator", "*", "$", "int", ";", "return", "new", "Ratio...
Multiply an integer @param int $int @return Rational
[ "Multiply", "an", "integer" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L260-L265
train
markrogoyski/math-php
src/Number/Rational.php
Rational.multiplyRational
private function multiplyRational(Rational $r): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; $w2 = $r->whole; $n2 = $r->numerator; $d2 = $r->denominator; $new_w = $w * $w2; $new_n = $w * $n2 * $d + $w2 * $n * $d2 + $n2 * $n; $new_d = $d * $d2; return new Rational($new_w, $new_n, $new_d); }
php
private function multiplyRational(Rational $r): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; $w2 = $r->whole; $n2 = $r->numerator; $d2 = $r->denominator; $new_w = $w * $w2; $new_n = $w * $n2 * $d + $w2 * $n * $d2 + $n2 * $n; $new_d = $d * $d2; return new Rational($new_w, $new_n, $new_d); }
[ "private", "function", "multiplyRational", "(", "Rational", "$", "r", ")", ":", "Rational", "{", "$", "w", "=", "$", "this", "->", "whole", ";", "$", "n", "=", "$", "this", "->", "numerator", ";", "$", "d", "=", "$", "this", "->", "denominator", ";...
Multiply a rational number @param Rational $r @return Rational
[ "Multiply", "a", "rational", "number" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L274-L289
train
markrogoyski/math-php
src/Number/Rational.php
Rational.divide
public function divide($r): Rational { if (is_int($r)) { return $this->divideInt($r); } elseif ($r instanceof Rational) { return $this->divideRational($r); } else { throw new Exception\IncorrectTypeException('Argument must be an integer or RationalNumber'); } }
php
public function divide($r): Rational { if (is_int($r)) { return $this->divideInt($r); } elseif ($r instanceof Rational) { return $this->divideRational($r); } else { throw new Exception\IncorrectTypeException('Argument must be an integer or RationalNumber'); } }
[ "public", "function", "divide", "(", "$", "r", ")", ":", "Rational", "{", "if", "(", "is_int", "(", "$", "r", ")", ")", "{", "return", "$", "this", "->", "divideInt", "(", "$", "r", ")", ";", "}", "elseif", "(", "$", "r", "instanceof", "Rational"...
Divide Return the result of dividing two rational numbers, or a rational number by an integer. @param Rational|int $r @return Rational @throws Exception\IncorrectTypeException if the argument is not numeric or Rational.
[ "Divide", "Return", "the", "result", "of", "dividing", "two", "rational", "numbers", "or", "a", "rational", "number", "by", "an", "integer", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L301-L310
train
markrogoyski/math-php
src/Number/Rational.php
Rational.divideInt
private function divideInt(int $int): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; return new Rational(0, $w * $d + $n, $int * $d); }
php
private function divideInt(int $int): Rational { $w = $this->whole; $n = $this->numerator; $d = $this->denominator; return new Rational(0, $w * $d + $n, $int * $d); }
[ "private", "function", "divideInt", "(", "int", "$", "int", ")", ":", "Rational", "{", "$", "w", "=", "$", "this", "->", "whole", ";", "$", "n", "=", "$", "this", "->", "numerator", ";", "$", "d", "=", "$", "this", "->", "denominator", ";", "retu...
Divide by an integer @param int $int @return Rational
[ "Divide", "by", "an", "integer" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L319-L325
train
markrogoyski/math-php
src/Number/Rational.php
Rational.equals
public function equals(Rational $rn): bool { return $this->whole == $rn->whole && $this->numerator == $rn->numerator && $this->denominator == $rn->denominator; }
php
public function equals(Rational $rn): bool { return $this->whole == $rn->whole && $this->numerator == $rn->numerator && $this->denominator == $rn->denominator; }
[ "public", "function", "equals", "(", "Rational", "$", "rn", ")", ":", "bool", "{", "return", "$", "this", "->", "whole", "==", "$", "rn", "->", "whole", "&&", "$", "this", "->", "numerator", "==", "$", "rn", "->", "numerator", "&&", "$", "this", "-...
Test for equality Two normalized RationalNumbers are equal IFF all three parts are equal. @param Rational $rn @return bool
[ "Test", "for", "equality" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L364-L369
train
markrogoyski/math-php
src/Number/Rational.php
Rational.normalize
private function normalize(int $w, int $n, int $d): array { if ($d == 0) { throw new Exception\BadDataException('Denominator cannot be zero'); } // Make sure $d is positive if ($d < 0) { $n *= -1; $d *= -1; } // Reduce the fraction if (abs($n) >= $d) { $w += intdiv($n, $d); $n = $n % $d; } $gcd = 0; while ($gcd != 1 && $n !== 0) { $gcd = abs(Algebra::gcd($n, $d)); $n /= $gcd; $d /= $gcd; } // Make the signs of $n and $w match if (Special::sgn($w) !== Special::sgn($n) && $w !== 0 && $n !== 0) { $w = $w - Special::sgn($w); $n = ($d - abs($n)) * Special::sgn($w); } if ($n == 0) { $d = 1; } return [$w, $n, $d]; }
php
private function normalize(int $w, int $n, int $d): array { if ($d == 0) { throw new Exception\BadDataException('Denominator cannot be zero'); } // Make sure $d is positive if ($d < 0) { $n *= -1; $d *= -1; } // Reduce the fraction if (abs($n) >= $d) { $w += intdiv($n, $d); $n = $n % $d; } $gcd = 0; while ($gcd != 1 && $n !== 0) { $gcd = abs(Algebra::gcd($n, $d)); $n /= $gcd; $d /= $gcd; } // Make the signs of $n and $w match if (Special::sgn($w) !== Special::sgn($n) && $w !== 0 && $n !== 0) { $w = $w - Special::sgn($w); $n = ($d - abs($n)) * Special::sgn($w); } if ($n == 0) { $d = 1; } return [$w, $n, $d]; }
[ "private", "function", "normalize", "(", "int", "$", "w", ",", "int", "$", "n", ",", "int", "$", "d", ")", ":", "array", "{", "if", "(", "$", "d", "==", "0", ")", "{", "throw", "new", "Exception", "\\", "BadDataException", "(", "'Denominator cannot b...
Normalize the input We want to ensure that the format of the data in the object is correct. We will ensure that the numerator is smaller than the denominator, the sign of the denominator is always positive, and the signs of the numerator and whole number match. @param int $w whole number @param int $n numerator @param int $d denominator @return array
[ "Normalize", "the", "input" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Number/Rational.php#L385-L418
train
markrogoyski/math-php
src/LinearAlgebra/Eigenvector.php
Eigenvector.countSolutions
private static function countSolutions(Matrix $M): int { $number_of_solutions = 0; // There are solutions to be found. $more_solutions = true; $m = $M->getM(); // We will count the number of rows with all zeros, starting at the bottom. for ($i = $m - 1; $i >= 0 && $more_solutions; $i--) { // Every row of zeros is a degree of freedom (a solution) with that eigenvalue if ($M->getRow($i) == array_fill(0, $m, 0)) { $number_of_solutions++; } else { // Once we find a row with nonzero values, there are no more. $more_solutions = false; } } return $number_of_solutions; }
php
private static function countSolutions(Matrix $M): int { $number_of_solutions = 0; // There are solutions to be found. $more_solutions = true; $m = $M->getM(); // We will count the number of rows with all zeros, starting at the bottom. for ($i = $m - 1; $i >= 0 && $more_solutions; $i--) { // Every row of zeros is a degree of freedom (a solution) with that eigenvalue if ($M->getRow($i) == array_fill(0, $m, 0)) { $number_of_solutions++; } else { // Once we find a row with nonzero values, there are no more. $more_solutions = false; } } return $number_of_solutions; }
[ "private", "static", "function", "countSolutions", "(", "Matrix", "$", "M", ")", ":", "int", "{", "$", "number_of_solutions", "=", "0", ";", "// There are solutions to be found.", "$", "more_solutions", "=", "true", ";", "$", "m", "=", "$", "M", "->", "getM"...
Count the number of rows that contain all zeroes, starting at the bottom. In reduced row echelon form, all the rows of zero will be on the bottom. @param Matrix $M @return int
[ "Count", "the", "number", "of", "rows", "that", "contain", "all", "zeroes", "starting", "at", "the", "bottom", ".", "In", "reduced", "row", "echelon", "form", "all", "the", "rows", "of", "zero", "will", "be", "on", "the", "bottom", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/LinearAlgebra/Eigenvector.php#L159-L176
train
markrogoyski/math-php
src/LinearAlgebra/Eigenvector.php
Eigenvector.findZeroColumns
private static function findZeroColumns(Matrix $M): array { $m = $M->getM(); $zero_columns = []; for ($i = 0; $i < $M->getN(); $i++) { if ($M->getColumn($i) == array_fill(0, $m, 0)) { $zero_columns[] = $i; } } return $zero_columns; }
php
private static function findZeroColumns(Matrix $M): array { $m = $M->getM(); $zero_columns = []; for ($i = 0; $i < $M->getN(); $i++) { if ($M->getColumn($i) == array_fill(0, $m, 0)) { $zero_columns[] = $i; } } return $zero_columns; }
[ "private", "static", "function", "findZeroColumns", "(", "Matrix", "$", "M", ")", ":", "array", "{", "$", "m", "=", "$", "M", "->", "getM", "(", ")", ";", "$", "zero_columns", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", ...
Find the zero columns @param Matrix $M @return array
[ "Find", "the", "zero", "columns" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/LinearAlgebra/Eigenvector.php#L185-L195
train
markrogoyski/math-php
src/Statistics/Regression/Models/LinearModel.php
LinearModel.evaluateModel
public static function evaluateModel(float $x, array $params): float { $m = $params[self::$M]; $b = $params[self::$B]; return $m * $x + $b; }
php
public static function evaluateModel(float $x, array $params): float { $m = $params[self::$M]; $b = $params[self::$B]; return $m * $x + $b; }
[ "public", "static", "function", "evaluateModel", "(", "float", "$", "x", ",", "array", "$", "params", ")", ":", "float", "{", "$", "m", "=", "$", "params", "[", "self", "::", "$", "M", "]", ";", "$", "b", "=", "$", "params", "[", "self", "::", ...
Evaluate the model given all the model parameters y = mx + b @param float $x @param array $params @return float y evaluated
[ "Evaluate", "the", "model", "given", "all", "the", "model", "parameters", "y", "=", "mx", "+", "b" ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Statistics/Regression/Models/LinearModel.php#L21-L27
train
markrogoyski/math-php
src/Finance.php
Finance.pmt
public static function pmt(float $rate, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { return - ($future_value + $present_value) / $periods; } return - ($future_value + ($present_value * pow(1 + $rate, $periods))) / ((1 + $rate*$when) / $rate * (pow(1 + $rate, $periods) - 1)); }
php
public static function pmt(float $rate, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { return - ($future_value + $present_value) / $periods; } return - ($future_value + ($present_value * pow(1 + $rate, $periods))) / ((1 + $rate*$when) / $rate * (pow(1 + $rate, $periods) - 1)); }
[ "public", "static", "function", "pmt", "(", "float", "$", "rate", ",", "int", "$", "periods", ",", "float", "$", "present_value", ",", "float", "$", "future_value", "=", "0.0", ",", "bool", "$", "beginning", "=", "false", ")", ":", "float", "{", "$", ...
Financial payment for a loan or annuity with compound interest. Determines the periodic payment amount for a given interest rate, principal, targeted payment goal, life of the annuity as number of payments, and whether the payments are made at the start or end of each payment period. Same as the =PMT() function in most spreadsheet software. The basic monthly payment formula derivation: https://en.wikipedia.org/wiki/Mortgage_calculator#Monthly_payment_formula rP(1+r)ᴺ PMT = -------- (1+r)ᴺ-1 The formula is adjusted to allow targeting any future value rather than 0. The 1/(1+r*when) factor adjusts the payment to the beginning or end of the period. In the common case of a payment at the end of a period, the factor is 1 and reduces to the formula above. Setting when=1 computes an "annuity due" with an immediate payment. Examples: The payment on a 30-year fixed mortgage note of $265000 at 3.5% interest paid at the end of every month. pmt(0.035/12, 30*12, 265000, 0, false) The payment on a 30-year fixed mortgage note of $265000 at 3.5% interest needed to half the principal in half in 5 years: pmt(0.035/12, 5*12, 265000, 265000/2, false) The weekly payment into a savings account with 1% interest rate and current balance of $1500 needed to reach $10000 after 3 years: pmt(0.01/52, 3*52, -1500, 10000, false) The present_value is negative indicating money put into the savings account, whereas future_value is positive, indicating money that will be withdrawn from the account. Similarly, the payment value is negative How much money can be withdrawn at the end of every quarter from an account with $1000000 earning 4% so the money lasts 20 years: pmt(0.04/4, 20*4, 1000000, 0, false) @param float $rate @param int $periods @param float $present_value @param float $future_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Financial", "payment", "for", "a", "loan", "or", "annuity", "with", "compound", "interest", ".", "Determines", "the", "periodic", "payment", "amount", "for", "a", "given", "interest", "rate", "principal", "targeted", "payment", "goal", "life", "of", "the", "a...
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L83-L94
train
markrogoyski/math-php
src/Finance.php
Finance.ipmt
public static function ipmt(float $rate, int $period, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { if ($period < 1 || $period > $periods) { return \NAN; } if ($rate == 0) { return 0; } if ($beginning && $period == 1) { return 0.0; } $payment = self::pmt($rate, $periods, $present_value, $future_value, $beginning); if ($beginning) { $interest = (self::fv($rate, $period - 2, $payment, $present_value, $beginning) - $payment) * $rate; } else { $interest = self::fv($rate, $period - 1, $payment, $present_value, $beginning) * $rate; } return self::checkZero($interest); }
php
public static function ipmt(float $rate, int $period, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { if ($period < 1 || $period > $periods) { return \NAN; } if ($rate == 0) { return 0; } if ($beginning && $period == 1) { return 0.0; } $payment = self::pmt($rate, $periods, $present_value, $future_value, $beginning); if ($beginning) { $interest = (self::fv($rate, $period - 2, $payment, $present_value, $beginning) - $payment) * $rate; } else { $interest = self::fv($rate, $period - 1, $payment, $present_value, $beginning) * $rate; } return self::checkZero($interest); }
[ "public", "static", "function", "ipmt", "(", "float", "$", "rate", ",", "int", "$", "period", ",", "int", "$", "periods", ",", "float", "$", "present_value", ",", "float", "$", "future_value", "=", "0.0", ",", "bool", "$", "beginning", "=", "false", ")...
Interest on a financial payment for a loan or annuity with compound interest. Determines the interest payment at a particular period of the annuity. For a typical loan paid down to zero, the amount of interest and principle paid throughout the lifetime of the loan will change, with the interest portion of the payment decreasing over time as the loan principle decreases. Same as the =IPMT() function in most spreadsheet software. See the PMT function for derivation of the formula. For IPMT, we have the payment equal to the interest portion and principle portion of the payment: PMT = IPMT + PPMT The interest portion IPMT on a regular annuity can be calculated by computing the future value of the annuity for the prior period and computing the compound interest for one period: IPMT = FV(p=n-1) * rate For an "annuity due" where payment is at the start of the period, period=1 has no interest portion of the payment because no time has elapsed for compounding. To compute the interest portion of the payment, the future value of 2 periods back needs to be computed, as the definition of a period is different, giving: IPMT = (FV(p=n-2) - PMT) * rate By thinking of the future value at period 0 instead of the present value, the given formulas are computed. Example of regular annuity and annuity due for a loan of $10.00 paid back in 3 periods. Although the principle payments are equal, the total payment and interest portion are lower with the annuity due because a principle payment is made immediately. Regular Annuity | Annuity Due Period FV PMT IPMT PPMT | PMT IPMT PPMT 0 -10.00 | 1 -6.83 -3.67 -0.50 -3.17 | -3.50 0.00 -3.50 2 -3.50 -3.67 -0.34 -3.33 | -3.50 -0.33 -3.17 3 0.00 -3.67 -0.17 -3.50 | -3.50 -0.17 -3.33 -----------------------|---------------------- SUM -11.01 -1.01 -10.00 | -10.50 -0.50 -10.00 Examples: The interest on a payment on a 30-year fixed mortgage note of $265000 at 3.5% interest paid at the end of every month, looking at the first payment: ipmt(0.035/12, 1, 30*12, 265000, 0, false) @param float $rate @param int $period @param int $periods @param float $present_value @param float $future_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Interest", "on", "a", "financial", "payment", "for", "a", "loan", "or", "annuity", "with", "compound", "interest", ".", "Determines", "the", "interest", "payment", "at", "a", "particular", "period", "of", "the", "annuity", ".", "For", "a", "typical", "loan"...
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L153-L174
train
markrogoyski/math-php
src/Finance.php
Finance.ppmt
public static function ppmt(float $rate, int $period, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { $payment = self::pmt($rate, $periods, $present_value, $future_value, $beginning); $ipmt = self::ipmt($rate, $period, $periods, $present_value, $future_value, $beginning); return $payment - $ipmt; }
php
public static function ppmt(float $rate, int $period, int $periods, float $present_value, float $future_value = 0.0, bool $beginning = false): float { $payment = self::pmt($rate, $periods, $present_value, $future_value, $beginning); $ipmt = self::ipmt($rate, $period, $periods, $present_value, $future_value, $beginning); return $payment - $ipmt; }
[ "public", "static", "function", "ppmt", "(", "float", "$", "rate", ",", "int", "$", "period", ",", "int", "$", "periods", ",", "float", "$", "present_value", ",", "float", "$", "future_value", "=", "0.0", ",", "bool", "$", "beginning", "=", "false", ")...
Principle on a financial payment for a loan or annuity with compound interest. Determines the principle payment at a particular period of the annuity. For a typical loan paid down to zero, the amount of interest and principle paid throughout the lifetime of the loan will change, with the principle portion of the payment increasing over time as the loan principle decreases. Same as the =PPMT() function in most spreadsheet software. See the PMT function for derivation of the formula. See the IPMT function for derivation and use of PMT, IPMT, and PPMT. With derivations for PMT and IPMT, we simply compute: PPMT = PMT - IPMT Examples: The principle on a payment on a 30-year fixed mortgage note of $265000 at 3.5% interest paid at the end of every month, looking at the first payment: ppmt(0.035/12, 1, 30*12, 265000, 0, false) @param float $rate @param int $period @param int $periods @param float $present_value @param float $future_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Principle", "on", "a", "financial", "payment", "for", "a", "loan", "or", "annuity", "with", "compound", "interest", ".", "Determines", "the", "principle", "payment", "at", "a", "particular", "period", "of", "the", "annuity", ".", "For", "a", "typical", "loa...
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L206-L211
train
markrogoyski/math-php
src/Finance.php
Finance.periods
public static function periods(float $rate, float $payment, float $present_value, float $future_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { return - ($present_value + $future_value) / $payment; } $initial = $payment * (1.0 + $rate * $when); return log(($initial - $future_value*$rate) / ($initial + $present_value*$rate)) / log(1.0 + $rate); }
php
public static function periods(float $rate, float $payment, float $present_value, float $future_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { return - ($present_value + $future_value) / $payment; } $initial = $payment * (1.0 + $rate * $when); return log(($initial - $future_value*$rate) / ($initial + $present_value*$rate)) / log(1.0 + $rate); }
[ "public", "static", "function", "periods", "(", "float", "$", "rate", ",", "float", "$", "payment", ",", "float", "$", "present_value", ",", "float", "$", "future_value", ",", "bool", "$", "beginning", "=", "false", ")", ":", "float", "{", "$", "when", ...
Number of payment periods of an annuity. Solves for the number of periods in the annuity formula. Same as the =NPER() function in most spreadsheet software. Solving the basic annuity formula for number of periods: log(PMT - FV*r) --------------- log(PMT + PV*r) n = -------------------- log(1 + r) The (1+r*when) factor adjusts the payment to the beginning or end of the period. In the common case of a payment at the end of a period, the factor is 1 and reduces to the formula above. Setting when=1 computes an "annuity due" with an immediate payment. Examples: The number of periods of a $475000 mortgage with interest rate 3.5% and monthly payment of $2132.96 paid in full: nper(0.035/12, -2132.96, 475000, 0) @param float $rate @param float $payment @param float $present_value @param float $future_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Number", "of", "payment", "periods", "of", "an", "annuity", ".", "Solves", "for", "the", "number", "of", "periods", "in", "the", "annuity", "formula", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L244-L254
train
markrogoyski/math-php
src/Finance.php
Finance.fv
public static function fv(float $rate, int $periods, float $payment, float $present_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { $fv = -($present_value + ($payment * $periods)); return self::checkZero($fv); } $initial = 1 + ($rate * $when); $compound = pow(1 + $rate, $periods); $fv = - (($present_value * $compound) + (($payment * $initial * ($compound - 1)) / $rate)); return self::checkZero($fv); }
php
public static function fv(float $rate, int $periods, float $payment, float $present_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { $fv = -($present_value + ($payment * $periods)); return self::checkZero($fv); } $initial = 1 + ($rate * $when); $compound = pow(1 + $rate, $periods); $fv = - (($present_value * $compound) + (($payment * $initial * ($compound - 1)) / $rate)); return self::checkZero($fv); }
[ "public", "static", "function", "fv", "(", "float", "$", "rate", ",", "int", "$", "periods", ",", "float", "$", "payment", ",", "float", "$", "present_value", ",", "bool", "$", "beginning", "=", "false", ")", ":", "float", "{", "$", "when", "=", "$",...
Future value for a loan or annuity with compound interest. Same as the =FV() function in most spreadsheet software. The basic future-value formula derivation: https://en.wikipedia.org/wiki/Future_value PMT*((1+r)ᴺ - 1) FV = -PV*(1+r)ᴺ - ---------------- r The (1+r*when) factor adjusts the payment to the beginning or end of the period. In the common case of a payment at the end of a period, the factor is 1 and reduces to the formula above. Setting when=1 computes an "annuity due" with an immediate payment. Examples: The future value in 5 years on a 30-year fixed mortgage note of $265000 at 3.5% interest paid at the end of every month. This is how much loan principle would be outstanding: fv(0.035/12, 5*12, 1189.97, -265000, false) The present_value is negative indicating money borrowed for the mortgage, whereas payment is positive, indicating money that will be paid to the mortgage. @param float $rate @param int $periods @param float $payment @param float $present_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Future", "value", "for", "a", "loan", "or", "annuity", "with", "compound", "interest", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L355-L369
train
markrogoyski/math-php
src/Finance.php
Finance.pv
public static function pv(float $rate, int $periods, float $payment, float $future_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { $pv = -$future_value - ($payment * $periods); return self::checkZero($pv); } $initial = 1 + ($rate * $when); $compound = pow(1 + $rate, $periods); $pv = (-$future_value - (($payment * $initial * ($compound - 1)) / $rate)) / $compound; return self::checkZero($pv); }
php
public static function pv(float $rate, int $periods, float $payment, float $future_value, bool $beginning = false): float { $when = $beginning ? 1 : 0; if ($rate == 0) { $pv = -$future_value - ($payment * $periods); return self::checkZero($pv); } $initial = 1 + ($rate * $when); $compound = pow(1 + $rate, $periods); $pv = (-$future_value - (($payment * $initial * ($compound - 1)) / $rate)) / $compound; return self::checkZero($pv); }
[ "public", "static", "function", "pv", "(", "float", "$", "rate", ",", "int", "$", "periods", ",", "float", "$", "payment", ",", "float", "$", "future_value", ",", "bool", "$", "beginning", "=", "false", ")", ":", "float", "{", "$", "when", "=", "$", ...
Present value for a loan or annuity with compound interest. Same as the =PV() function in most spreadsheet software. The basic present-value formula derivation: https://en.wikipedia.org/wiki/Present_value PMT*((1+r)ᴺ - 1) PV = -FV - ---------------- r --------------------- (1 + r)ᴺ The (1+r*when) factor adjusts the payment to the beginning or end of the period. In the common case of a payment at the end of a period, the factor is 1 and reduces to the formula above. Setting when=1 computes an "annuity due" with an immediate payment. Examples: The present value of a band's $1000 face value paid in 5 year's time with a constant discount rate of 3.5% compounded monthly: pv(0.035/12, 5*12, 0, -1000, false) The present value of a $1000 5-year bond that pays a fixed 7% ($70) coupon at the end of each year with a discount rate of 5%: pv(0.5, 5, -70, -1000, false) The payment and future_value is negative indicating money paid out. @param float $rate @param int $periods @param float $payment @param float $future_value @param bool $beginning adjust the payment to the beginning or end of the period @return float
[ "Present", "value", "for", "a", "loan", "or", "annuity", "with", "compound", "interest", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L409-L423
train
markrogoyski/math-php
src/Finance.php
Finance.npv
public static function npv(float $rate, array $values): float { $result = 0.0; for ($i = 0; $i < count($values); ++$i) { $result += $values[$i] / (1 + $rate)**$i; } return $result; }
php
public static function npv(float $rate, array $values): float { $result = 0.0; for ($i = 0; $i < count($values); ++$i) { $result += $values[$i] / (1 + $rate)**$i; } return $result; }
[ "public", "static", "function", "npv", "(", "float", "$", "rate", ",", "array", "$", "values", ")", ":", "float", "{", "$", "result", "=", "0.0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "values", ")", ";", ...
Net present value of cash flows. Cash flows are periodic starting from an initial time and with a uniform discount rate. Similar to the =NPV() function in most spreadsheet software, except the initial (usually negative) cash flow at time 0 is given as the first element of the array rather than subtracted. For example, spreadsheet: =NPV(0.01, 100, 200, 300, 400) - 1000 is done as MathPHP::npv(0.01, [-1000, 100, 200, 300, 400]) The basic net-present-value formula derivation: https://en.wikipedia.org/wiki/Net_present_value n Rt Σ -------- t=0 (1 / r)ᵗ Examples: The net present value of 5 yearly cash flows after an initial $1000 investment with a 3% discount rate: npv(0.03, [-1000, 100, 500, 300, 700, 700]) @param float $rate @param array $values @return float
[ "Net", "present", "value", "of", "cash", "flows", ".", "Cash", "flows", "are", "periodic", "starting", "from", "an", "initial", "time", "and", "with", "a", "uniform", "discount", "rate", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L453-L462
train
markrogoyski/math-php
src/Finance.php
Finance.rate
public static function rate(float $periods, float $payment, float $present_value, float $future_value, bool $beginning = false, float $initial_guess = 0.1): float { $when = $beginning ? 1 : 0; $func = function ($x, $periods, $payment, $present_value, $future_value, $when) { return $future_value + $present_value*(1+$x)**$periods + $payment*(1+$x*$when)/$x * ((1+$x)**$periods - 1); }; return self::checkZero(NumericalAnalysis\RootFinding\NewtonsMethod::solve($func, [$initial_guess, $periods, $payment, $present_value, $future_value, $when], 0, self::EPSILON, 0)); }
php
public static function rate(float $periods, float $payment, float $present_value, float $future_value, bool $beginning = false, float $initial_guess = 0.1): float { $when = $beginning ? 1 : 0; $func = function ($x, $periods, $payment, $present_value, $future_value, $when) { return $future_value + $present_value*(1+$x)**$periods + $payment*(1+$x*$when)/$x * ((1+$x)**$periods - 1); }; return self::checkZero(NumericalAnalysis\RootFinding\NewtonsMethod::solve($func, [$initial_guess, $periods, $payment, $present_value, $future_value, $when], 0, self::EPSILON, 0)); }
[ "public", "static", "function", "rate", "(", "float", "$", "periods", ",", "float", "$", "payment", ",", "float", "$", "present_value", ",", "float", "$", "future_value", ",", "bool", "$", "beginning", "=", "false", ",", "float", "$", "initial_guess", "=",...
Interest rate per period of an Annuity. Same as the =RATE() formula in most spreadsheet software. The basic rate formula derivation is to solve for the future value taking into account the present value: https://en.wikipedia.org/wiki/Future_value ((1+r)ᴺ - 1) FV + PV*(1+r)ᴺ + PMT * ------------ = 0 r The (1+r*when) factor adjusts the payment to the beginning or end of the period. In the common case of a payment at the end of a period, the factor is 1 and reduces to the formula above. Setting when=1 computes an "annuity due" with an immediate payment. Not all solutions for the rate have real-value solutions or converge. In these cases, NAN is returned. @param float $periods @param float $payment @param float $present_value @param float $future_value @param bool $beginning @param float $initial_guess @return float
[ "Interest", "rate", "per", "period", "of", "an", "Annuity", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L493-L502
train
markrogoyski/math-php
src/Finance.php
Finance.payback
public static function payback(array $values, float $rate = 0.0): float { $last_outflow = -1; for ($i = 0; $i < sizeof($values); $i++) { if ($values[$i] < 0) { $last_outflow = $i; } } if ($last_outflow < 0) { return 0.0; } $sum = $values[0]; $payback_period = -1; for ($i = 1; $i < sizeof($values); $i++) { $prevsum = $sum; $discounted_flow = $values[$i] / (1 + $rate)**$i; $sum += $discounted_flow; if ($sum >= 0) { if ($i > $last_outflow) { return ($i - 1) + (-$prevsum / $discounted_flow); } if ($payback_period == -1) { $payback_period = ($i - 1) + (-$prevsum / $discounted_flow); } } else { $payback_period = -1; } } if ($sum >= 0) { return $payback_period; } return \NAN; }
php
public static function payback(array $values, float $rate = 0.0): float { $last_outflow = -1; for ($i = 0; $i < sizeof($values); $i++) { if ($values[$i] < 0) { $last_outflow = $i; } } if ($last_outflow < 0) { return 0.0; } $sum = $values[0]; $payback_period = -1; for ($i = 1; $i < sizeof($values); $i++) { $prevsum = $sum; $discounted_flow = $values[$i] / (1 + $rate)**$i; $sum += $discounted_flow; if ($sum >= 0) { if ($i > $last_outflow) { return ($i - 1) + (-$prevsum / $discounted_flow); } if ($payback_period == -1) { $payback_period = ($i - 1) + (-$prevsum / $discounted_flow); } } else { $payback_period = -1; } } if ($sum >= 0) { return $payback_period; } return \NAN; }
[ "public", "static", "function", "payback", "(", "array", "$", "values", ",", "float", "$", "rate", "=", "0.0", ")", ":", "float", "{", "$", "last_outflow", "=", "-", "1", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "sizeof", "(", "...
Discounted Payback of an investment. The number of periods to recoup cash outlays of an investment. This is commonly used with discount rate=0 as simple payback period, but it is not a real financial measurement when it doesn't consider the discount rate. Even with a discount rate, it doesn't consider the cost of capital or re-investment of returns. Avoid this when possible. Consider NPV, MIRR, IRR, and other financial functions. Reference: https://en.wikipedia.org/wiki/Payback_period The result is given assuming cash flows are continous throughout a period. To compute payback in terms of whole periods, use ceil() on the result. An investment could reach its payback period before future cash outlays occur. The payback period returned is defined to be the final point at which the sum of returns becomes positive. Examples: The payback period of an investment with a $1,000 investment and future returns of $100, $200, $300, $400, $500: payback([-1000, 100, 200, 300, 400, 500]) The discounted payback period of an investment with a $1,000 investment, future returns of $100, $200, $300, $400, $500, and a discount rate of 0.10: payback([-1000, 100, 200, 300, 400, 500], 0.1) @param array $values @param float $rate @return float
[ "Discounted", "Payback", "of", "an", "investment", ".", "The", "number", "of", "periods", "to", "recoup", "cash", "outlays", "of", "an", "investment", "." ]
4a2934a23bcb1fe7767c9205d630e38018c16556
https://github.com/markrogoyski/math-php/blob/4a2934a23bcb1fe7767c9205d630e38018c16556/src/Finance.php#L629-L663
train
franzliedke/studio
src/Console/CreateCommand.php
CreateCommand.makeCreator
protected function makeCreator(InputInterface $input) { $path = $input->getArgument('path'); if ($input->getOption('git')) { return new GitRepoCreator($input->getOption('git'), $path); } elseif ($input->getOption('submodule')) { return new GitSubmoduleCreator($input->getOption('submodule'), $path); } else { $creator = new SkeletonCreator($path); $this->installParts($creator); return $creator; } }
php
protected function makeCreator(InputInterface $input) { $path = $input->getArgument('path'); if ($input->getOption('git')) { return new GitRepoCreator($input->getOption('git'), $path); } elseif ($input->getOption('submodule')) { return new GitSubmoduleCreator($input->getOption('submodule'), $path); } else { $creator = new SkeletonCreator($path); $this->installParts($creator); return $creator; } }
[ "protected", "function", "makeCreator", "(", "InputInterface", "$", "input", ")", "{", "$", "path", "=", "$", "input", "->", "getArgument", "(", "'path'", ")", ";", "if", "(", "$", "input", "->", "getOption", "(", "'git'", ")", ")", "{", "return", "new...
Build a package creator from the given input options. @param InputInterface $input @return CreatorInterface
[ "Build", "a", "package", "creator", "from", "the", "given", "input", "options", "." ]
64096b2e74df895638158fb597054ea17c643a84
https://github.com/franzliedke/studio/blob/64096b2e74df895638158fb597054ea17c643a84/src/Console/CreateCommand.php#L85-L98
train
franzliedke/studio
src/Composer/StudioPlugin.php
StudioPlugin.registerStudioPackages
public function registerStudioPackages() { $repoManager = $this->composer->getRepositoryManager(); $composerConfig = $this->composer->getConfig(); foreach ($this->getManagedPaths() as $path) { $this->io->writeError("[Studio] Loading path $path"); $repoManager->prependRepository(new PathRepository( ['url' => $path], $this->io, $composerConfig )); } }
php
public function registerStudioPackages() { $repoManager = $this->composer->getRepositoryManager(); $composerConfig = $this->composer->getConfig(); foreach ($this->getManagedPaths() as $path) { $this->io->writeError("[Studio] Loading path $path"); $repoManager->prependRepository(new PathRepository( ['url' => $path], $this->io, $composerConfig )); } }
[ "public", "function", "registerStudioPackages", "(", ")", "{", "$", "repoManager", "=", "$", "this", "->", "composer", "->", "getRepositoryManager", "(", ")", ";", "$", "composerConfig", "=", "$", "this", "->", "composer", "->", "getConfig", "(", ")", ";", ...
Register all managed paths with Composer. This function configures Composer to treat all Studio-managed paths as local path repositories, so that packages therein will be symlinked directly.
[ "Register", "all", "managed", "paths", "with", "Composer", "." ]
64096b2e74df895638158fb597054ea17c643a84
https://github.com/franzliedke/studio/blob/64096b2e74df895638158fb597054ea17c643a84/src/Composer/StudioPlugin.php#L46-L60
train
franzliedke/studio
src/Composer/StudioPlugin.php
StudioPlugin.getManagedPaths
private function getManagedPaths() { $targetDir = realpath($this->composer->getPackage()->getTargetDir()); $config = Config::make("{$targetDir}/studio.json"); return $config->getPaths(); }
php
private function getManagedPaths() { $targetDir = realpath($this->composer->getPackage()->getTargetDir()); $config = Config::make("{$targetDir}/studio.json"); return $config->getPaths(); }
[ "private", "function", "getManagedPaths", "(", ")", "{", "$", "targetDir", "=", "realpath", "(", "$", "this", "->", "composer", "->", "getPackage", "(", ")", "->", "getTargetDir", "(", ")", ")", ";", "$", "config", "=", "Config", "::", "make", "(", "\"...
Get the list of paths that are being managed by Studio. @return array
[ "Get", "the", "list", "of", "paths", "that", "are", "being", "managed", "by", "Studio", "." ]
64096b2e74df895638158fb597054ea17c643a84
https://github.com/franzliedke/studio/blob/64096b2e74df895638158fb597054ea17c643a84/src/Composer/StudioPlugin.php#L67-L73
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/Plugin.php
Plugin.addVersion
public function addVersion(PackageEvent $event) { $package = $this->getPackageFromOperation($event->getOperation()); if ($package->getName() === self::ACF_PRO_PACKAGE_NAME) { $version = $this->validateVersion($package->getPrettyVersion()); $package->setDistUrl( $this->addParameterToUrl($package->getDistUrl(), 't', $version) ); } }
php
public function addVersion(PackageEvent $event) { $package = $this->getPackageFromOperation($event->getOperation()); if ($package->getName() === self::ACF_PRO_PACKAGE_NAME) { $version = $this->validateVersion($package->getPrettyVersion()); $package->setDistUrl( $this->addParameterToUrl($package->getDistUrl(), 't', $version) ); } }
[ "public", "function", "addVersion", "(", "PackageEvent", "$", "event", ")", "{", "$", "package", "=", "$", "this", "->", "getPackageFromOperation", "(", "$", "event", "->", "getOperation", "(", ")", ")", ";", "if", "(", "$", "package", "->", "getName", "...
Add the version to the package url The version needs to be added in the PRE_PACKAGE_INSTALL/UPDATE event to make sure that different version save different urls in composer.lock. Composer would load any available version from cache although the version numbers might differ (because they have the same url). @access public @param PackageEvent $event The event that called the method @throws UnexpectedValueException
[ "Add", "the", "version", "to", "the", "package", "url" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/Plugin.php#L110-L120
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/Plugin.php
Plugin.addKey
public function addKey(PreFileDownloadEvent $event) { $processedUrl = $event->getProcessedUrl(); if ($this->isAcfProPackageUrl($processedUrl)) { $rfs = $event->getRemoteFilesystem(); $acfRfs = new RemoteFilesystem( $this->addParameterToUrl( $processedUrl, 'k', $this->getKeyFromEnv() ), $this->io, $this->composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled() ); $event->setRemoteFilesystem($acfRfs); } }
php
public function addKey(PreFileDownloadEvent $event) { $processedUrl = $event->getProcessedUrl(); if ($this->isAcfProPackageUrl($processedUrl)) { $rfs = $event->getRemoteFilesystem(); $acfRfs = new RemoteFilesystem( $this->addParameterToUrl( $processedUrl, 'k', $this->getKeyFromEnv() ), $this->io, $this->composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled() ); $event->setRemoteFilesystem($acfRfs); } }
[ "public", "function", "addKey", "(", "PreFileDownloadEvent", "$", "event", ")", "{", "$", "processedUrl", "=", "$", "event", "->", "getProcessedUrl", "(", ")", ";", "if", "(", "$", "this", "->", "isAcfProPackageUrl", "(", "$", "processedUrl", ")", ")", "{"...
Add the key from the environment to the event url The key is not added to the package because it would show up in the composer.lock file in this case. A custom file system is used to swap out the ACF PRO url with a url that contains the key. @access public @param PreFileDownloadEvent $event The event that called this method @throws MissingKeyException
[ "Add", "the", "key", "from", "the", "environment", "to", "the", "event", "url" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/Plugin.php#L134-L153
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/Plugin.php
Plugin.validateVersion
protected function validateVersion($version) { // \A = start of string, \Z = end of string // See: http://stackoverflow.com/a/34994075 $major_minor_patch_optional = '/\A\d\.\d\.\d{1,2}(?:\.\d)?\Z/'; if (!preg_match($major_minor_patch_optional, $version)) { throw new \UnexpectedValueException( 'The version constraint of ' . self::ACF_PRO_PACKAGE_NAME . ' should be exact (with 3 or 4 digits). ' . 'Invalid version string "' . $version . '"' ); } return $version; }
php
protected function validateVersion($version) { // \A = start of string, \Z = end of string // See: http://stackoverflow.com/a/34994075 $major_minor_patch_optional = '/\A\d\.\d\.\d{1,2}(?:\.\d)?\Z/'; if (!preg_match($major_minor_patch_optional, $version)) { throw new \UnexpectedValueException( 'The version constraint of ' . self::ACF_PRO_PACKAGE_NAME . ' should be exact (with 3 or 4 digits). ' . 'Invalid version string "' . $version . '"' ); } return $version; }
[ "protected", "function", "validateVersion", "(", "$", "version", ")", "{", "// \\A = start of string, \\Z = end of string", "// See: http://stackoverflow.com/a/34994075", "$", "major_minor_patch_optional", "=", "'/\\A\\d\\.\\d\\.\\d{1,2}(?:\\.\\d)?\\Z/'", ";", "if", "(", "!", "pr...
Validate that the version is an exact major.minor.patch.optional version The url to download the code for the package only works with exact version numbers with 3 or 4 digits: e.g. 1.2.3 or 1.2.3.4 @access protected @param string $version The version that should be validated @return string The valid version @throws UnexpectedValueException
[ "Validate", "that", "the", "version", "is", "an", "exact", "major", ".", "minor", ".", "patch", ".", "optional", "version" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/Plugin.php#L183-L198
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/Plugin.php
Plugin.getKeyFromEnv
protected function getKeyFromEnv() { $this->loadDotEnv(); $key = getenv(self::KEY_ENV_VARIABLE); if (!$key) { throw new MissingKeyException(self::KEY_ENV_VARIABLE); } return $key; }
php
protected function getKeyFromEnv() { $this->loadDotEnv(); $key = getenv(self::KEY_ENV_VARIABLE); if (!$key) { throw new MissingKeyException(self::KEY_ENV_VARIABLE); } return $key; }
[ "protected", "function", "getKeyFromEnv", "(", ")", "{", "$", "this", "->", "loadDotEnv", "(", ")", ";", "$", "key", "=", "getenv", "(", "self", "::", "KEY_ENV_VARIABLE", ")", ";", "if", "(", "!", "$", "key", ")", "{", "throw", "new", "MissingKeyExcept...
Get the ACF PRO key from the environment Loads the .env file that is in the same directory as composer.json and gets the key from the environment variable KEY_ENV_VARIABLE. Already set variables will not be overwritten by the variables in .env @link https://github.com/vlucas/phpdotenv#immutability @access protected @return string The key from the environment @throws PhilippBaschke\ACFProInstaller\Exceptions\MissingKeyException
[ "Get", "the", "ACF", "PRO", "key", "from", "the", "environment" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/Plugin.php#L224-L234
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/Plugin.php
Plugin.addParameterToUrl
protected function addParameterToUrl($url, $parameter, $value) { $cleanUrl = $this->removeParameterFromUrl($url, $parameter); $urlParameter = '&' . $parameter . '=' . urlencode($value); return $cleanUrl .= $urlParameter; }
php
protected function addParameterToUrl($url, $parameter, $value) { $cleanUrl = $this->removeParameterFromUrl($url, $parameter); $urlParameter = '&' . $parameter . '=' . urlencode($value); return $cleanUrl .= $urlParameter; }
[ "protected", "function", "addParameterToUrl", "(", "$", "url", ",", "$", "parameter", ",", "$", "value", ")", "{", "$", "cleanUrl", "=", "$", "this", "->", "removeParameterFromUrl", "(", "$", "url", ",", "$", "parameter", ")", ";", "$", "urlParameter", "...
Add a parameter to the given url Adds the given parameter at the end of the given url. It only works with urls that already have parameters (e.g. test.com?p=true) because it uses & as a separation character. @access protected @param string $url The url that should be appended @param string $parameter The name of the parameter @param string $value The value of the parameter @return string The url appended with &parameter=value
[ "Add", "a", "parameter", "to", "the", "given", "url" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/Plugin.php#L264-L270
train
PhilippBaschke/acf-pro-installer
src/ACFProInstaller/RemoteFilesystem.php
RemoteFilesystem.copy
public function copy( $originUrl, $fileUrl, $fileName, $progress = true, $options = [] ) { return parent::copy( $originUrl, $this->acfFileUrl, $fileName, $progress, $options ); }
php
public function copy( $originUrl, $fileUrl, $fileName, $progress = true, $options = [] ) { return parent::copy( $originUrl, $this->acfFileUrl, $fileName, $progress, $options ); }
[ "public", "function", "copy", "(", "$", "originUrl", ",", "$", "fileUrl", ",", "$", "fileName", ",", "$", "progress", "=", "true", ",", "$", "options", "=", "[", "]", ")", "{", "return", "parent", "::", "copy", "(", "$", "originUrl", ",", "$", "thi...
Copy the remote file in local Use $acfFileUrl instead of the provided $fileUrl @param string $originUrl The origin URL @param string $fileUrl The file URL (ignored) @param string $fileName the local filename @param bool $progress Display the progression @param array $options Additional context options @return bool true
[ "Copy", "the", "remote", "file", "in", "local" ]
772cec99c6ef8bc67ba6768419014cc60d141b27
https://github.com/PhilippBaschke/acf-pro-installer/blob/772cec99c6ef8bc67ba6768419014cc60d141b27/src/ACFProInstaller/RemoteFilesystem.php#L55-L69
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.get_many
public function get_many($values) { $this->_database->where_in($this->primary_key, $values); return $this->get_all(); }
php
public function get_many($values) { $this->_database->where_in($this->primary_key, $values); return $this->get_all(); }
[ "public", "function", "get_many", "(", "$", "values", ")", "{", "$", "this", "->", "_database", "->", "where_in", "(", "$", "this", "->", "primary_key", ",", "$", "values", ")", ";", "return", "$", "this", "->", "get_all", "(", ")", ";", "}" ]
Fetch an array of records based on an array of primary values.
[ "Fetch", "an", "array", "of", "records", "based", "on", "an", "array", "of", "primary", "values", "." ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L158-L163
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.insert_many
public function insert_many($data, $skip_validation = FALSE) { $ids = array(); foreach ($data as $key => $row) { $ids[] = $this->insert($row, $skip_validation, ($key == count($data) - 1)); } return $ids; }
php
public function insert_many($data, $skip_validation = FALSE) { $ids = array(); foreach ($data as $key => $row) { $ids[] = $this->insert($row, $skip_validation, ($key == count($data) - 1)); } return $ids; }
[ "public", "function", "insert_many", "(", "$", "data", ",", "$", "skip_validation", "=", "FALSE", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "row", ")", "{", "$", "ids", "[", "]", ...
Insert multiple rows into the table. Returns an array of multiple IDs.
[ "Insert", "multiple", "rows", "into", "the", "table", ".", "Returns", "an", "array", "of", "multiple", "IDs", "." ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L234-L244
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.update_by
public function update_by() { $args = func_get_args(); $data = array_pop($args); $data = $this->trigger('before_update', $data); if ($this->validate($data) !== FALSE) { $this->_set_where($args); $result = $this->_database->set($data) ->update($this->_table); $this->trigger('after_update', array($data, $result)); return $result; } else { return FALSE; } }
php
public function update_by() { $args = func_get_args(); $data = array_pop($args); $data = $this->trigger('before_update', $data); if ($this->validate($data) !== FALSE) { $this->_set_where($args); $result = $this->_database->set($data) ->update($this->_table); $this->trigger('after_update', array($data, $result)); return $result; } else { return FALSE; } }
[ "public", "function", "update_by", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "data", "=", "array_pop", "(", "$", "args", ")", ";", "$", "data", "=", "$", "this", "->", "trigger", "(", "'before_update'", ",", "$", "data", ...
Updated a record based on an arbitrary WHERE clause.
[ "Updated", "a", "record", "based", "on", "an", "arbitrary", "WHERE", "clause", "." ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L305-L325
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.update_all
public function update_all($data) { $data = $this->trigger('before_update', $data); $result = $this->_database->set($data) ->update($this->_table); $this->trigger('after_update', array($data, $result)); return $result; }
php
public function update_all($data) { $data = $this->trigger('before_update', $data); $result = $this->_database->set($data) ->update($this->_table); $this->trigger('after_update', array($data, $result)); return $result; }
[ "public", "function", "update_all", "(", "$", "data", ")", "{", "$", "data", "=", "$", "this", "->", "trigger", "(", "'before_update'", ",", "$", "data", ")", ";", "$", "result", "=", "$", "this", "->", "_database", "->", "set", "(", "$", "data", "...
Update all records
[ "Update", "all", "records" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L330-L338
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.delete
public function delete($id) { $this->trigger('before_delete', $id); $this->_database->where($this->primary_key, $id); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
php
public function delete($id) { $this->trigger('before_delete', $id); $this->_database->where($this->primary_key, $id); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "this", "->", "trigger", "(", "'before_delete'", ",", "$", "id", ")", ";", "$", "this", "->", "_database", "->", "where", "(", "$", "this", "->", "primary_key", ",", "$", "id", ")", ";"...
Delete a row from the table by the primary value
[ "Delete", "a", "row", "from", "the", "table", "by", "the", "primary", "value" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L343-L361
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.delete_by
public function delete_by() { $where = func_get_args(); $where = $this->trigger('before_delete', $where); $this->_set_where($where); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
php
public function delete_by() { $where = func_get_args(); $where = $this->trigger('before_delete', $where); $this->_set_where($where); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
[ "public", "function", "delete_by", "(", ")", "{", "$", "where", "=", "func_get_args", "(", ")", ";", "$", "where", "=", "$", "this", "->", "trigger", "(", "'before_delete'", ",", "$", "where", ")", ";", "$", "this", "->", "_set_where", "(", "$", "whe...
Delete a row from the database table by an arbitrary WHERE clause
[ "Delete", "a", "row", "from", "the", "database", "table", "by", "an", "arbitrary", "WHERE", "clause" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L366-L387
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.delete_many
public function delete_many($primary_values) { $primary_values = $this->trigger('before_delete', $primary_values); $this->_database->where_in($this->primary_key, $primary_values); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
php
public function delete_many($primary_values) { $primary_values = $this->trigger('before_delete', $primary_values); $this->_database->where_in($this->primary_key, $primary_values); if ($this->soft_delete) { $result = $this->_database->update($this->_table, array( $this->soft_delete_key => TRUE )); } else { $result = $this->_database->delete($this->_table); } $this->trigger('after_delete', $result); return $result; }
[ "public", "function", "delete_many", "(", "$", "primary_values", ")", "{", "$", "primary_values", "=", "$", "this", "->", "trigger", "(", "'before_delete'", ",", "$", "primary_values", ")", ";", "$", "this", "->", "_database", "->", "where_in", "(", "$", "...
Delete many rows from the database table by multiple primary values
[ "Delete", "many", "rows", "from", "the", "database", "table", "by", "multiple", "primary", "values" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L392-L410
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.dropdown
function dropdown() { $args = func_get_args(); if(count($args) == 2) { list($key, $value) = $args; } else { $key = $this->primary_key; $value = $args[0]; } $this->trigger('before_dropdown', array( $key, $value )); if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, FALSE); } $result = $this->_database->select(array($key, $value)) ->get($this->_table) ->result(); $options = array(); foreach ($result as $row) { $options[$row->{$key}] = $row->{$value}; } $options = $this->trigger('after_dropdown', $options); return $options; }
php
function dropdown() { $args = func_get_args(); if(count($args) == 2) { list($key, $value) = $args; } else { $key = $this->primary_key; $value = $args[0]; } $this->trigger('before_dropdown', array( $key, $value )); if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, FALSE); } $result = $this->_database->select(array($key, $value)) ->get($this->_table) ->result(); $options = array(); foreach ($result as $row) { $options[$row->{$key}] = $row->{$value}; } $options = $this->trigger('after_dropdown', $options); return $options; }
[ "function", "dropdown", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", "==", "2", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "$", "args", ";", "}", "else", "{",...
Retrieve and generate a form_dropdown friendly array
[ "Retrieve", "and", "generate", "a", "form_dropdown", "friendly", "array" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L512-L547
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.count_by
public function count_by() { if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); } $where = func_get_args(); $this->_set_where($where); return $this->_database->count_all_results($this->_table); }
php
public function count_by() { if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); } $where = func_get_args(); $this->_set_where($where); return $this->_database->count_all_results($this->_table); }
[ "public", "function", "count_by", "(", ")", "{", "if", "(", "$", "this", "->", "soft_delete", "&&", "$", "this", "->", "_temporary_with_deleted", "!==", "TRUE", ")", "{", "$", "this", "->", "_database", "->", "where", "(", "$", "this", "->", "soft_delete...
Fetch a count of rows based on an arbitrary WHERE call.
[ "Fetch", "a", "count", "of", "rows", "based", "on", "an", "arbitrary", "WHERE", "call", "." ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L552-L563
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.count_all
public function count_all() { if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); } return $this->_database->count_all($this->_table); }
php
public function count_all() { if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) { $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); } return $this->_database->count_all($this->_table); }
[ "public", "function", "count_all", "(", ")", "{", "if", "(", "$", "this", "->", "soft_delete", "&&", "$", "this", "->", "_temporary_with_deleted", "!==", "TRUE", ")", "{", "$", "this", "->", "_database", "->", "where", "(", "$", "this", "->", "soft_delet...
Fetch a total count of rows, disregarding any previous conditions
[ "Fetch", "a", "total", "count", "of", "rows", "disregarding", "any", "previous", "conditions" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L568-L576
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.get_next_id
public function get_next_id() { return (int) $this->_database->select('AUTO_INCREMENT') ->from('information_schema.TABLES') ->where('TABLE_NAME', $this->_table) ->where('TABLE_SCHEMA', $this->_database->database)->get()->row()->AUTO_INCREMENT; }
php
public function get_next_id() { return (int) $this->_database->select('AUTO_INCREMENT') ->from('information_schema.TABLES') ->where('TABLE_NAME', $this->_table) ->where('TABLE_SCHEMA', $this->_database->database)->get()->row()->AUTO_INCREMENT; }
[ "public", "function", "get_next_id", "(", ")", "{", "return", "(", "int", ")", "$", "this", "->", "_database", "->", "select", "(", "'AUTO_INCREMENT'", ")", "->", "from", "(", "'information_schema.TABLES'", ")", "->", "where", "(", "'TABLE_NAME'", ",", "$", ...
Return the next auto increment of the table. Only tested on MySQL.
[ "Return", "the", "next", "auto", "increment", "of", "the", "table", ".", "Only", "tested", "on", "MySQL", "." ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L598-L604
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.created_at
public function created_at($row) { if (is_object($row)) { $row->created_at = date('Y-m-d H:i:s'); } else { $row['created_at'] = date('Y-m-d H:i:s'); } return $row; }
php
public function created_at($row) { if (is_object($row)) { $row->created_at = date('Y-m-d H:i:s'); } else { $row['created_at'] = date('Y-m-d H:i:s'); } return $row; }
[ "public", "function", "created_at", "(", "$", "row", ")", "{", "if", "(", "is_object", "(", "$", "row", ")", ")", "{", "$", "row", "->", "created_at", "=", "date", "(", "'Y-m-d H:i:s'", ")", ";", "}", "else", "{", "$", "row", "[", "'created_at'", "...
MySQL DATETIME created_at and updated_at
[ "MySQL", "DATETIME", "created_at", "and", "updated_at" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L661-L673
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model.validate
public function validate($data) { if($this->skip_validation) { return $data; } if(!empty($this->validate)) { foreach($data as $key => $val) { $_POST[$key] = $val; } $this->load->library('form_validation'); if(is_array($this->validate)) { $this->form_validation->set_rules($this->validate); if ($this->form_validation->run() === TRUE) { return $data; } else { return FALSE; } } else { if ($this->form_validation->run($this->validate) === TRUE) { return $data; } else { return FALSE; } } } else { return $data; } }
php
public function validate($data) { if($this->skip_validation) { return $data; } if(!empty($this->validate)) { foreach($data as $key => $val) { $_POST[$key] = $val; } $this->load->library('form_validation'); if(is_array($this->validate)) { $this->form_validation->set_rules($this->validate); if ($this->form_validation->run() === TRUE) { return $data; } else { return FALSE; } } else { if ($this->form_validation->run($this->validate) === TRUE) { return $data; } else { return FALSE; } } } else { return $data; } }
[ "public", "function", "validate", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "skip_validation", ")", "{", "return", "$", "data", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "validate", ")", ")", "{", "foreach", "(", ...
Run validation on the passed data
[ "Run", "validation", "on", "the", "passed", "data" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L805-L850
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model._fetch_table
private function _fetch_table() { if ($this->_table == NULL) { $this->_table = plural(preg_replace('/(_m|_model)?$/', '', strtolower(get_class($this)))); } }
php
private function _fetch_table() { if ($this->_table == NULL) { $this->_table = plural(preg_replace('/(_m|_model)?$/', '', strtolower(get_class($this)))); } }
[ "private", "function", "_fetch_table", "(", ")", "{", "if", "(", "$", "this", "->", "_table", "==", "NULL", ")", "{", "$", "this", "->", "_table", "=", "plural", "(", "preg_replace", "(", "'/(_m|_model)?$/'", ",", "''", ",", "strtolower", "(", "get_class...
Guess the table name by pluralising the model name
[ "Guess", "the", "table", "name", "by", "pluralising", "the", "model", "name" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L855-L861
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model._fetch_primary_key
private function _fetch_primary_key() { if($this->primary_key == NULl) { $this->primary_key = $this->_database->query("SHOW KEYS FROM `".$this->_table."` WHERE Key_name = 'PRIMARY'")->row()->Column_name; } }
php
private function _fetch_primary_key() { if($this->primary_key == NULl) { $this->primary_key = $this->_database->query("SHOW KEYS FROM `".$this->_table."` WHERE Key_name = 'PRIMARY'")->row()->Column_name; } }
[ "private", "function", "_fetch_primary_key", "(", ")", "{", "if", "(", "$", "this", "->", "primary_key", "==", "NULl", ")", "{", "$", "this", "->", "primary_key", "=", "$", "this", "->", "_database", "->", "query", "(", "\"SHOW KEYS FROM `\"", ".", "$", ...
Guess the primary key for current table
[ "Guess", "the", "primary", "key", "for", "current", "table" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L866-L872
train
jamierumbelow/codeigniter-base-model
core/MY_Model.php
MY_Model._set_where
protected function _set_where($params) { if (count($params) == 1 && is_array($params[0])) { foreach ($params[0] as $field => $filter) { if (is_array($filter)) { $this->_database->where_in($field, $filter); } else { if (is_int($field)) { $this->_database->where($filter); } else { $this->_database->where($field, $filter); } } } } else if (count($params) == 1) { $this->_database->where($params[0]); } else if(count($params) == 2) { if (is_array($params[1])) { $this->_database->where_in($params[0], $params[1]); } else { $this->_database->where($params[0], $params[1]); } } else if(count($params) == 3) { $this->_database->where($params[0], $params[1], $params[2]); } else { if (is_array($params[1])) { $this->_database->where_in($params[0], $params[1]); } else { $this->_database->where($params[0], $params[1]); } } }
php
protected function _set_where($params) { if (count($params) == 1 && is_array($params[0])) { foreach ($params[0] as $field => $filter) { if (is_array($filter)) { $this->_database->where_in($field, $filter); } else { if (is_int($field)) { $this->_database->where($filter); } else { $this->_database->where($field, $filter); } } } } else if (count($params) == 1) { $this->_database->where($params[0]); } else if(count($params) == 2) { if (is_array($params[1])) { $this->_database->where_in($params[0], $params[1]); } else { $this->_database->where($params[0], $params[1]); } } else if(count($params) == 3) { $this->_database->where($params[0], $params[1], $params[2]); } else { if (is_array($params[1])) { $this->_database->where_in($params[0], $params[1]); } else { $this->_database->where($params[0], $params[1]); } } }
[ "protected", "function", "_set_where", "(", "$", "params", ")", "{", "if", "(", "count", "(", "$", "params", ")", "==", "1", "&&", "is_array", "(", "$", "params", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "params", "[", "0", "]", "as", ...
Set WHERE parameters, cleverly
[ "Set", "WHERE", "parameters", "cleverly" ]
22e120a48205fe155d3d34bca881e5f1941970e9
https://github.com/jamierumbelow/codeigniter-base-model/blob/22e120a48205fe155d3d34bca881e5f1941970e9/core/MY_Model.php#L877-L930
train
samayo/bulletproof
src/bulletproof.php
Image.offsetGet
public function offsetGet($offset) { // return false if $_FILES['key'] isn't found if (!isset($this->_files[$offset])) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_02'], $offset); return false; } $this->_files = $this->_files[$offset]; // check for common upload errors if (isset($this->_files['error'])) { $this->error = $this->commonUploadErrors[$this->language][$this->_files['error']]; } return true; }
php
public function offsetGet($offset) { // return false if $_FILES['key'] isn't found if (!isset($this->_files[$offset])) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_02'], $offset); return false; } $this->_files = $this->_files[$offset]; // check for common upload errors if (isset($this->_files['error'])) { $this->error = $this->commonUploadErrors[$this->language][$this->_files['error']]; } return true; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "// return false if $_FILES['key'] isn't found", "if", "(", "!", "isset", "(", "$", "this", "->", "_files", "[", "$", "offset", "]", ")", ")", "{", "$", "this", "->", "error", "=", "sprintf",...
\ArrayAccess - get array value from object @param mixed $offset @return string|bool
[ "\\", "ArrayAccess", "-", "get", "array", "value", "from", "object" ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L154-L170
train
samayo/bulletproof
src/bulletproof.php
Image.setDimension
public function setDimension($maxWidth, $maxHeight) { if ( (int) $maxWidth && (int) $maxHeight) { $this->dimensions = array($maxWidth, $maxHeight); } else { $this->error = $this->commonUploadErrors[$this->language]['ERROR_03']; } return $this; }
php
public function setDimension($maxWidth, $maxHeight) { if ( (int) $maxWidth && (int) $maxHeight) { $this->dimensions = array($maxWidth, $maxHeight); } else { $this->error = $this->commonUploadErrors[$this->language]['ERROR_03']; } return $this; }
[ "public", "function", "setDimension", "(", "$", "maxWidth", ",", "$", "maxHeight", ")", "{", "if", "(", "(", "int", ")", "$", "maxWidth", "&&", "(", "int", ")", "$", "maxHeight", ")", "{", "$", "this", "->", "dimensions", "=", "array", "(", "$", "m...
Sets max image height and width limit. @param $maxWidth int max width value @param $maxHeight int max height value @return $this
[ "Sets", "max", "image", "height", "and", "width", "limit", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L180-L189
train
samayo/bulletproof
src/bulletproof.php
Image.setLanguage
public function setLanguage($lang) { if (isset($this->commonUploadErrors[$lang])) { $this->language = $lang; } else { $this->error = $this->commonUploadErrors[$this->language]['ERROR_09']; } return $this; }
php
public function setLanguage($lang) { if (isset($this->commonUploadErrors[$lang])) { $this->language = $lang; } else { $this->error = $this->commonUploadErrors[$this->language]['ERROR_09']; } return $this; }
[ "public", "function", "setLanguage", "(", "$", "lang", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "commonUploadErrors", "[", "$", "lang", "]", ")", ")", "{", "$", "this", "->", "language", "=", "$", "lang", ";", "}", "else", "{", "$", ...
Define a language @param $lang string language code @return $this
[ "Define", "a", "language" ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L208-L217
train
samayo/bulletproof
src/bulletproof.php
Image.getJson
public function getJson() { return json_encode( array( 'name' => $this->name, 'mime' => $this->mime, 'height' => $this->height, 'width' => $this->width, 'size' => $this->_files['size'], 'location' => $this->location, 'fullpath' => $this->fullPath, ) ); }
php
public function getJson() { return json_encode( array( 'name' => $this->name, 'mime' => $this->mime, 'height' => $this->height, 'width' => $this->width, 'size' => $this->_files['size'], 'location' => $this->location, 'fullpath' => $this->fullPath, ) ); }
[ "public", "function", "getJson", "(", ")", "{", "return", "json_encode", "(", "array", "(", "'name'", "=>", "$", "this", "->", "name", ",", "'mime'", "=>", "$", "this", "->", "mime", ",", "'height'", "=>", "$", "this", "->", "height", ",", "'width'", ...
Returns a JSON format of the image width, height, name, mime ... @return string
[ "Returns", "a", "JSON", "format", "of", "the", "image", "width", "height", "name", "mime", "..." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L248-L261
train
samayo/bulletproof
src/bulletproof.php
Image.getMime
public function getMime() { if (!$this->mime) { $this->mime = $this->getImageMime($this->_files['tmp_name']); } return $this->mime; }
php
public function getMime() { if (!$this->mime) { $this->mime = $this->getImageMime($this->_files['tmp_name']); } return $this->mime; }
[ "public", "function", "getMime", "(", ")", "{", "if", "(", "!", "$", "this", "->", "mime", ")", "{", "$", "this", "->", "mime", "=", "$", "this", "->", "getImageMime", "(", "$", "this", "->", "_files", "[", "'tmp_name'", "]", ")", ";", "}", "retu...
Returns the image mime type. @return null|string
[ "Returns", "the", "image", "mime", "type", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L268-L275
train
samayo/bulletproof
src/bulletproof.php
Image.getImageMime
protected function getImageMime($tmp_name) { $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; if (!$this->mime) { return null; } return $this->mime; }
php
protected function getImageMime($tmp_name) { $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; if (!$this->mime) { return null; } return $this->mime; }
[ "protected", "function", "getImageMime", "(", "$", "tmp_name", ")", "{", "$", "this", "->", "mime", "=", "@", "$", "this", "->", "acceptedMimes", "[", "exif_imagetype", "(", "$", "tmp_name", ")", "]", ";", "if", "(", "!", "$", "this", "->", "mime", "...
Gets the real image mime type. @param $tmp_name string The upload tmp directory @return null|string
[ "Gets", "the", "real", "image", "mime", "type", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L297-L305
train
samayo/bulletproof
src/bulletproof.php
Image.getName
public function getName() { if (!$this->name) { $this->name = uniqid('', true).'_'.str_shuffle(implode(range('e', 'q'))); } return $this->name; }
php
public function getName() { if (!$this->name) { $this->name = uniqid('', true).'_'.str_shuffle(implode(range('e', 'q'))); } return $this->name; }
[ "public", "function", "getName", "(", ")", "{", "if", "(", "!", "$", "this", "->", "name", ")", "{", "$", "this", "->", "name", "=", "uniqid", "(", "''", ",", "true", ")", ".", "'_'", ".", "str_shuffle", "(", "implode", "(", "range", "(", "'e'", ...
Returns the image name. @return string
[ "Returns", "the", "image", "name", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L322-L329
train
samayo/bulletproof
src/bulletproof.php
Image.setName
public function setName($isNameProvided = null) { if ($isNameProvided) { $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); } return $this; }
php
public function setName($isNameProvided = null) { if ($isNameProvided) { $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); } return $this; }
[ "public", "function", "setName", "(", "$", "isNameProvided", "=", "null", ")", "{", "if", "(", "$", "isNameProvided", ")", "{", "$", "this", "->", "name", "=", "filter_var", "(", "$", "isNameProvided", ",", "FILTER_SANITIZE_STRING", ")", ";", "}", "return"...
Provide image name if not provided. @param null $isNameProvided @return $this
[ "Provide", "image", "name", "if", "not", "provided", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L338-L345
train
samayo/bulletproof
src/bulletproof.php
Image.getWidth
public function getWidth() { if ($this->width != null) { return $this->width; } list($width) = getimagesize($this->_files['tmp_name']); return $width; }
php
public function getWidth() { if ($this->width != null) { return $this->width; } list($width) = getimagesize($this->_files['tmp_name']); return $width; }
[ "public", "function", "getWidth", "(", ")", "{", "if", "(", "$", "this", "->", "width", "!=", "null", ")", "{", "return", "$", "this", "->", "width", ";", "}", "list", "(", "$", "width", ")", "=", "getimagesize", "(", "$", "this", "->", "_files", ...
Returns the image width. @return int
[ "Returns", "the", "image", "width", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L352-L361
train
samayo/bulletproof
src/bulletproof.php
Image.getHeight
public function getHeight() { if ($this->height != null) { return $this->height; } list(, $height) = getimagesize($this->_files['tmp_name']); return $height; }
php
public function getHeight() { if ($this->height != null) { return $this->height; } list(, $height) = getimagesize($this->_files['tmp_name']); return $height; }
[ "public", "function", "getHeight", "(", ")", "{", "if", "(", "$", "this", "->", "height", "!=", "null", ")", "{", "return", "$", "this", "->", "height", ";", "}", "list", "(", ",", "$", "height", ")", "=", "getimagesize", "(", "$", "this", "->", ...
Returns the image height in pixels. @return int
[ "Returns", "the", "image", "height", "in", "pixels", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L368-L377
train
samayo/bulletproof
src/bulletproof.php
Image.setLocation
public function setLocation($dir = 'bulletproof', $permission = 0666) { $isDirectoryValid = $this->isDirectoryValid($dir); if (!$isDirectoryValid) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_04'], $dir); return false; } $create = !is_dir($dir) ? @mkdir('' . $dir, (int) $permission, true) : true; if (!$create) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_05'], $dir); return false; } $this->location = $dir; return $this; }
php
public function setLocation($dir = 'bulletproof', $permission = 0666) { $isDirectoryValid = $this->isDirectoryValid($dir); if (!$isDirectoryValid) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_04'], $dir); return false; } $create = !is_dir($dir) ? @mkdir('' . $dir, (int) $permission, true) : true; if (!$create) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_05'], $dir); return false; } $this->location = $dir; return $this; }
[ "public", "function", "setLocation", "(", "$", "dir", "=", "'bulletproof'", ",", "$", "permission", "=", "0666", ")", "{", "$", "isDirectoryValid", "=", "$", "this", "->", "isDirectoryValid", "(", "$", "dir", ")", ";", "if", "(", "!", "$", "isDirectoryVa...
Creates a location for upload storage. @param $dir string the folder name to create @param int $permission chmod permission @return $this
[ "Creates", "a", "location", "for", "upload", "storage", "." ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L413-L432
train
samayo/bulletproof
src/bulletproof.php
Image.contraintsValidator
protected function contraintsValidator() { /* check image for valid mime types and return mime */ $this->getImageMime($this->_files['tmp_name']); /* validate image mime type */ if (!in_array($this->mime, $this->mimeTypes)) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_06'], implode(', ', $this->mimeTypes)); return false; } /* get image sizes */ list($minSize, $maxSize) = $this->size; /* check image size based on the settings */ if ($this->_files['size'] < $minSize || $this->_files['size'] > $maxSize) { $min = $minSize.' bytes ('.intval($minSize / 1000).' kb)'; $max = $maxSize.' bytes ('.intval($maxSize / 1000).' kb)'; $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_07'], $min, $max); return false; } /* check image dimension */ list($maxWidth, $maxHeight) = $this->dimensions; $this->width = $this->getWidth(); $this->height = $this->getHeight(); if ($this->height > $maxHeight || $this->width > $maxWidth) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_08'], $maxHeight, $maxWidth); return false; } return true; }
php
protected function contraintsValidator() { /* check image for valid mime types and return mime */ $this->getImageMime($this->_files['tmp_name']); /* validate image mime type */ if (!in_array($this->mime, $this->mimeTypes)) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_06'], implode(', ', $this->mimeTypes)); return false; } /* get image sizes */ list($minSize, $maxSize) = $this->size; /* check image size based on the settings */ if ($this->_files['size'] < $minSize || $this->_files['size'] > $maxSize) { $min = $minSize.' bytes ('.intval($minSize / 1000).' kb)'; $max = $maxSize.' bytes ('.intval($maxSize / 1000).' kb)'; $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_07'], $min, $max); return false; } /* check image dimension */ list($maxWidth, $maxHeight) = $this->dimensions; $this->width = $this->getWidth(); $this->height = $this->getHeight(); if ($this->height > $maxHeight || $this->width > $maxWidth) { $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_08'], $maxHeight, $maxWidth); return false; } return true; }
[ "protected", "function", "contraintsValidator", "(", ")", "{", "/* check image for valid mime types and return mime */", "$", "this", "->", "getImageMime", "(", "$", "this", "->", "_files", "[", "'tmp_name'", "]", ")", ";", "/* validate image mime type */", "if", "(", ...
Validate image size, dimension or mimetypes @return boolean
[ "Validate", "image", "size", "dimension", "or", "mimetypes" ]
c7fefd19a25c68b70c6209b7ccc685be07a9b898
https://github.com/samayo/bulletproof/blob/c7fefd19a25c68b70c6209b7ccc685be07a9b898/src/bulletproof.php#L439-L471
train
florianv/exchanger
src/Service/Registry.php
Registry.getServices
public static function getServices(): array { return [ 'central_bank_of_czech_republic' => CentralBankOfCzechRepublic::class, 'central_bank_of_republic_turkey' => CentralBankOfRepublicTurkey::class, 'cryptonator' => Cryptonator::class, 'currency_converter' => CurrencyConverter::class, 'currency_data_feed' => CurrencyDataFeed::class, 'currency_layer' => CurrencyLayer::class, 'european_central_bank' => EuropeanCentralBank::class, 'exchange_rates_api' => ExchangeRatesApi::class, 'fixer' => Fixer::class, 'forge' => Forge::class, 'national_bank_of_romania' => NationalBankOfRomania::class, 'open_exchange_rates' => OpenExchangeRates::class, 'array' => PhpArray::class, 'russian_central_bank' => RussianCentralBank::class, 'webservicex' => WebserviceX::class, 'xignite' => Xignite::class, 'national_bank_of_ukraine' => NationalBankOfUkraine::class, ]; }
php
public static function getServices(): array { return [ 'central_bank_of_czech_republic' => CentralBankOfCzechRepublic::class, 'central_bank_of_republic_turkey' => CentralBankOfRepublicTurkey::class, 'cryptonator' => Cryptonator::class, 'currency_converter' => CurrencyConverter::class, 'currency_data_feed' => CurrencyDataFeed::class, 'currency_layer' => CurrencyLayer::class, 'european_central_bank' => EuropeanCentralBank::class, 'exchange_rates_api' => ExchangeRatesApi::class, 'fixer' => Fixer::class, 'forge' => Forge::class, 'national_bank_of_romania' => NationalBankOfRomania::class, 'open_exchange_rates' => OpenExchangeRates::class, 'array' => PhpArray::class, 'russian_central_bank' => RussianCentralBank::class, 'webservicex' => WebserviceX::class, 'xignite' => Xignite::class, 'national_bank_of_ukraine' => NationalBankOfUkraine::class, ]; }
[ "public", "static", "function", "getServices", "(", ")", ":", "array", "{", "return", "[", "'central_bank_of_czech_republic'", "=>", "CentralBankOfCzechRepublic", "::", "class", ",", "'central_bank_of_republic_turkey'", "=>", "CentralBankOfRepublicTurkey", "::", "class", ...
Returns a map of all supports services. @return array
[ "Returns", "a", "map", "of", "all", "supports", "services", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/Registry.php#L28-L49
train
florianv/exchanger
src/CurrencyPair.php
CurrencyPair.createFromString
public static function createFromString(string $string): CurrencyPairContract { $matches = []; if (!preg_match('#^([A-Z0-9]{3,})\/([A-Z0-9]{3,})$#', $string, $matches)) { throw new \InvalidArgumentException('The currency pair must be in the form "EUR/USD".'); } $parts = explode('/', $string); return new self($parts[0], $parts[1]); }
php
public static function createFromString(string $string): CurrencyPairContract { $matches = []; if (!preg_match('#^([A-Z0-9]{3,})\/([A-Z0-9]{3,})$#', $string, $matches)) { throw new \InvalidArgumentException('The currency pair must be in the form "EUR/USD".'); } $parts = explode('/', $string); return new self($parts[0], $parts[1]); }
[ "public", "static", "function", "createFromString", "(", "string", "$", "string", ")", ":", "CurrencyPairContract", "{", "$", "matches", "=", "[", "]", ";", "if", "(", "!", "preg_match", "(", "'#^([A-Z0-9]{3,})\\/([A-Z0-9]{3,})$#'", ",", "$", "string", ",", "$...
Creates a currency pair from a string. @param string $string A string in the form EUR/USD @throws \InvalidArgumentException @return CurrencyPairContract
[ "Creates", "a", "currency", "pair", "from", "a", "string", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/CurrencyPair.php#L60-L70
train
florianv/exchanger
src/Service/CurrencyConverter.php
CurrencyConverter.fetchOnlineRate
private function fetchOnlineRate($url, ExchangeRateQuery $exchangeRateQuery): ExchangeRate { $currencyPair = $exchangeRateQuery->getCurrencyPair(); $response = $this->getResponse($url); if (200 !== $response->getStatusCode()) { throw new Exception("Unexpected response status {$response->getReasonPhrase()}, $url"); } $responsePayload = StringUtil::jsonToArray($response->getBody()->__toString()); $keyAsCurrencyPair = $this->stringifyCurrencyPair($currencyPair); if (empty($responsePayload['results'][$keyAsCurrencyPair]['val'])) { throw new Exception("Unexpected response body {$response->getReasonPhrase()}"); } if ($responsePayload['results'][$keyAsCurrencyPair]['fr'] !== $currencyPair->getBaseCurrency()) { throw new Exception("Unexpected base currency {$responsePayload['results'][$keyAsCurrencyPair]['fr']}"); } if ($responsePayload['results'][$keyAsCurrencyPair]['to'] !== $currencyPair->getQuoteCurrency()) { throw new Exception("Unexpected quote currency {$responsePayload['results'][$keyAsCurrencyPair]['to']}"); } if ($exchangeRateQuery instanceof HistoricalExchangeRateQuery) { $dateStringified = $responsePayload['date']; $date = new \DateTime($dateStringified); $rate = $responsePayload['results'][$keyAsCurrencyPair]['val'][$dateStringified]; } else { $date = new \DateTime('now'); $rate = $responsePayload['results'][$keyAsCurrencyPair]['val']; } return $this->createRate($currencyPair, (float) $rate, $date); }
php
private function fetchOnlineRate($url, ExchangeRateQuery $exchangeRateQuery): ExchangeRate { $currencyPair = $exchangeRateQuery->getCurrencyPair(); $response = $this->getResponse($url); if (200 !== $response->getStatusCode()) { throw new Exception("Unexpected response status {$response->getReasonPhrase()}, $url"); } $responsePayload = StringUtil::jsonToArray($response->getBody()->__toString()); $keyAsCurrencyPair = $this->stringifyCurrencyPair($currencyPair); if (empty($responsePayload['results'][$keyAsCurrencyPair]['val'])) { throw new Exception("Unexpected response body {$response->getReasonPhrase()}"); } if ($responsePayload['results'][$keyAsCurrencyPair]['fr'] !== $currencyPair->getBaseCurrency()) { throw new Exception("Unexpected base currency {$responsePayload['results'][$keyAsCurrencyPair]['fr']}"); } if ($responsePayload['results'][$keyAsCurrencyPair]['to'] !== $currencyPair->getQuoteCurrency()) { throw new Exception("Unexpected quote currency {$responsePayload['results'][$keyAsCurrencyPair]['to']}"); } if ($exchangeRateQuery instanceof HistoricalExchangeRateQuery) { $dateStringified = $responsePayload['date']; $date = new \DateTime($dateStringified); $rate = $responsePayload['results'][$keyAsCurrencyPair]['val'][$dateStringified]; } else { $date = new \DateTime('now'); $rate = $responsePayload['results'][$keyAsCurrencyPair]['val']; } return $this->createRate($currencyPair, (float) $rate, $date); }
[ "private", "function", "fetchOnlineRate", "(", "$", "url", ",", "ExchangeRateQuery", "$", "exchangeRateQuery", ")", ":", "ExchangeRate", "{", "$", "currencyPair", "=", "$", "exchangeRateQuery", "->", "getCurrencyPair", "(", ")", ";", "$", "response", "=", "$", ...
Fetch online rate. @param string $url @param ExchangeRateQuery $exchangeRateQuery @return ExchangeRate @throws Exception
[ "Fetch", "online", "rate", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/CurrencyConverter.php#L148-L184
train
florianv/exchanger
src/Service/CentralBankOfRepublicTurkey.php
CentralBankOfRepublicTurkey.buildUrl
private function buildUrl(DateTimeInterface $requestedDate = null): string { if (null === $requestedDate) { $fileName = 'today'; } else { $yearMonth = $requestedDate->format('Ym'); $dayMonthYear = $requestedDate->format('dmY'); $fileName = "$yearMonth/$dayMonthYear"; } return self::BASE_URL.$fileName.self::FILE_EXTENSION; }
php
private function buildUrl(DateTimeInterface $requestedDate = null): string { if (null === $requestedDate) { $fileName = 'today'; } else { $yearMonth = $requestedDate->format('Ym'); $dayMonthYear = $requestedDate->format('dmY'); $fileName = "$yearMonth/$dayMonthYear"; } return self::BASE_URL.$fileName.self::FILE_EXTENSION; }
[ "private", "function", "buildUrl", "(", "DateTimeInterface", "$", "requestedDate", "=", "null", ")", ":", "string", "{", "if", "(", "null", "===", "$", "requestedDate", ")", "{", "$", "fileName", "=", "'today'", ";", "}", "else", "{", "$", "yearMonth", "...
Builds the url. @param DateTimeInterface|null $requestedDate @return string
[ "Builds", "the", "url", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/CentralBankOfRepublicTurkey.php#L97-L108
train
florianv/exchanger
src/StringUtil.php
StringUtil.xmlToElement
public static function xmlToElement(string $string): \SimpleXMLElement { $disableEntities = libxml_disable_entity_loader(true); $internalErrors = libxml_use_internal_errors(true); try { // Allow XML to be retrieved even if there is no response body $xml = new \SimpleXMLElement($string ?: '<root />', LIBXML_NONET); libxml_disable_entity_loader($disableEntities); libxml_use_internal_errors($internalErrors); } catch (\Exception $e) { libxml_disable_entity_loader($disableEntities); libxml_use_internal_errors($internalErrors); throw new \RuntimeException('Unable to parse XML data: '.$e->getMessage()); } return $xml; }
php
public static function xmlToElement(string $string): \SimpleXMLElement { $disableEntities = libxml_disable_entity_loader(true); $internalErrors = libxml_use_internal_errors(true); try { // Allow XML to be retrieved even if there is no response body $xml = new \SimpleXMLElement($string ?: '<root />', LIBXML_NONET); libxml_disable_entity_loader($disableEntities); libxml_use_internal_errors($internalErrors); } catch (\Exception $e) { libxml_disable_entity_loader($disableEntities); libxml_use_internal_errors($internalErrors); throw new \RuntimeException('Unable to parse XML data: '.$e->getMessage()); } return $xml; }
[ "public", "static", "function", "xmlToElement", "(", "string", "$", "string", ")", ":", "\\", "SimpleXMLElement", "{", "$", "disableEntities", "=", "libxml_disable_entity_loader", "(", "true", ")", ";", "$", "internalErrors", "=", "libxml_use_internal_errors", "(", ...
Transforms an XML string to an element. @param string $string @throws \RuntimeException @return \SimpleXMLElement
[ "Transforms", "an", "XML", "string", "to", "an", "element", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/StringUtil.php#L32-L51
train
florianv/exchanger
src/StringUtil.php
StringUtil.jsonToArray
public static function jsonToArray(string $string): array { static $jsonErrors = [ JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found', JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded', ]; $data = json_decode($string, true); if (JSON_ERROR_NONE !== json_last_error()) { $last = json_last_error(); throw new \RuntimeException( 'Unable to parse JSON data: ' .(isset($jsonErrors[$last]) ? $jsonErrors[$last] : 'Unknown error') ); } return $data; }
php
public static function jsonToArray(string $string): array { static $jsonErrors = [ JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found', JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded', ]; $data = json_decode($string, true); if (JSON_ERROR_NONE !== json_last_error()) { $last = json_last_error(); throw new \RuntimeException( 'Unable to parse JSON data: ' .(isset($jsonErrors[$last]) ? $jsonErrors[$last] : 'Unknown error') ); } return $data; }
[ "public", "static", "function", "jsonToArray", "(", "string", "$", "string", ")", ":", "array", "{", "static", "$", "jsonErrors", "=", "[", "JSON_ERROR_DEPTH", "=>", "'JSON_ERROR_DEPTH - Maximum stack depth exceeded'", ",", "JSON_ERROR_STATE_MISMATCH", "=>", "'JSON_ERRO...
Transforms a JSON string to an array. @param string $string @throws \RuntimeException @return array
[ "Transforms", "a", "JSON", "string", "to", "an", "array", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/StringUtil.php#L62-L84
train
florianv/exchanger
src/Service/Cryptonator.php
Cryptonator.getExchangeRate
public function getExchangeRate(ExchangeRateQuery $exchangeQuery): ExchangeRateContract { $currencyPair = $exchangeQuery->getCurrencyPair(); $response = $this->request( sprintf( self::LATEST_URL, strtolower($currencyPair->getBaseCurrency()), strtolower($currencyPair->getQuoteCurrency()) ) ); $data = StringUtil::jsonToArray($response); if (!$data['success']) { $message = !empty($data['error']) ? $data['error'] : 'Unknown error'; throw new Exception($message); } $date = (new \DateTime())->setTimestamp($data['timestamp']); return $this->createRate($currencyPair, (float) ($data['ticker']['price']), $date); }
php
public function getExchangeRate(ExchangeRateQuery $exchangeQuery): ExchangeRateContract { $currencyPair = $exchangeQuery->getCurrencyPair(); $response = $this->request( sprintf( self::LATEST_URL, strtolower($currencyPair->getBaseCurrency()), strtolower($currencyPair->getQuoteCurrency()) ) ); $data = StringUtil::jsonToArray($response); if (!$data['success']) { $message = !empty($data['error']) ? $data['error'] : 'Unknown error'; throw new Exception($message); } $date = (new \DateTime())->setTimestamp($data['timestamp']); return $this->createRate($currencyPair, (float) ($data['ticker']['price']), $date); }
[ "public", "function", "getExchangeRate", "(", "ExchangeRateQuery", "$", "exchangeQuery", ")", ":", "ExchangeRateContract", "{", "$", "currencyPair", "=", "$", "exchangeQuery", "->", "getCurrencyPair", "(", ")", ";", "$", "response", "=", "$", "this", "->", "requ...
Gets the exchange rate. @param ExchangeRateQuery $exchangeQuery @return ExchangeRateContract @throws Exception
[ "Gets", "the", "exchange", "rate", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/Cryptonator.php#L40-L63
train
florianv/exchanger
src/Service/Cryptonator.php
Cryptonator.supportQuery
public function supportQuery(ExchangeRateQuery $exchangeQuery): bool { $currencyPair = $exchangeQuery->getCurrencyPair(); return !$exchangeQuery instanceof HistoricalExchangeRateQuery && in_array($currencyPair->getBaseCurrency(), $this->getSupportedCodes()) && in_array($currencyPair->getQuoteCurrency(), $this->getSupportedCodes()); }
php
public function supportQuery(ExchangeRateQuery $exchangeQuery): bool { $currencyPair = $exchangeQuery->getCurrencyPair(); return !$exchangeQuery instanceof HistoricalExchangeRateQuery && in_array($currencyPair->getBaseCurrency(), $this->getSupportedCodes()) && in_array($currencyPair->getQuoteCurrency(), $this->getSupportedCodes()); }
[ "public", "function", "supportQuery", "(", "ExchangeRateQuery", "$", "exchangeQuery", ")", ":", "bool", "{", "$", "currencyPair", "=", "$", "exchangeQuery", "->", "getCurrencyPair", "(", ")", ";", "return", "!", "$", "exchangeQuery", "instanceof", "HistoricalExcha...
Tells if the service supports the exchange rate query. @param ExchangeRateQuery $exchangeQuery @return bool
[ "Tells", "if", "the", "service", "supports", "the", "exchange", "rate", "query", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/Cryptonator.php#L72-L79
train
florianv/exchanger
src/Service/PhpArray.php
PhpArray.validateRates
private function validateRates(array $rates) { foreach ($rates as $rate) { if (!is_scalar($rate)) { throw new \InvalidArgumentException(sprintf( 'Rates passed to the PhpArray service must be scalars, "%s" given.', gettype($rate) )); } } }
php
private function validateRates(array $rates) { foreach ($rates as $rate) { if (!is_scalar($rate)) { throw new \InvalidArgumentException(sprintf( 'Rates passed to the PhpArray service must be scalars, "%s" given.', gettype($rate) )); } } }
[ "private", "function", "validateRates", "(", "array", "$", "rates", ")", "{", "foreach", "(", "$", "rates", "as", "$", "rate", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "rate", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "("...
Validate the rates array. @param array $rates @throws \InvalidArgumentException
[ "Validate", "the", "rates", "array", "." ]
d0802d4a1134bb6dca30326516aa5864b0413dbc
https://github.com/florianv/exchanger/blob/d0802d4a1134bb6dca30326516aa5864b0413dbc/src/Service/PhpArray.php#L130-L140
train
blockchain/api-v1-client-php
src/V2/Receive/Receive.php
Receive.generate
public function generate($key, $xpub, $callback, $gap_limit = null) { $p = compact('key', 'xpub', 'callback'); if(!is_null($gap_limit)) $p['gap_limit'] = $gap_limit; $q = http_build_query($p); curl_setopt($this->ch, CURLOPT_POST, false); curl_setopt($this->ch, CURLOPT_URL, static::URL.'?'.$q); if (($resp = curl_exec($this->ch)) === false) { throw new HttpError(curl_error($this->ch)); } if (($data = json_decode($resp, true)) === NULL) { throw new Error("Unable to decode JSON response from Blockchain: $resp"); } $info = curl_getinfo($this->ch); if ($info['http_code'] == 200) { return new ReceiveResponse($data['address'], $data['index'], $data['callback']); } throw new Error(implode(', ', $data)); }
php
public function generate($key, $xpub, $callback, $gap_limit = null) { $p = compact('key', 'xpub', 'callback'); if(!is_null($gap_limit)) $p['gap_limit'] = $gap_limit; $q = http_build_query($p); curl_setopt($this->ch, CURLOPT_POST, false); curl_setopt($this->ch, CURLOPT_URL, static::URL.'?'.$q); if (($resp = curl_exec($this->ch)) === false) { throw new HttpError(curl_error($this->ch)); } if (($data = json_decode($resp, true)) === NULL) { throw new Error("Unable to decode JSON response from Blockchain: $resp"); } $info = curl_getinfo($this->ch); if ($info['http_code'] == 200) { return new ReceiveResponse($data['address'], $data['index'], $data['callback']); } throw new Error(implode(', ', $data)); }
[ "public", "function", "generate", "(", "$", "key", ",", "$", "xpub", ",", "$", "callback", ",", "$", "gap_limit", "=", "null", ")", "{", "$", "p", "=", "compact", "(", "'key'", ",", "'xpub'", ",", "'callback'", ")", ";", "if", "(", "!", "is_null", ...
Generates a receive adddress. @param string $key The API key. @param string $xpub The public key. @param string $callback The callback URL. @param int $gap_limit How many unused addresses are allowed. @return \Blockchain\V2\Receive\ReceiveResponse @throws \Blockchain\Exception\Error @throws \Blockchain\Exception\HttpError
[ "Generates", "a", "receive", "adddress", "." ]
be194230ed4dd97d5ae84bcf67a4c90f930566b5
https://github.com/blockchain/api-v1-client-php/blob/be194230ed4dd97d5ae84bcf67a4c90f930566b5/src/V2/Receive/Receive.php#L49-L74
train
blockchain/api-v1-client-php
src/V2/Receive/Receive.php
Receive.callbackLogs
public function callbackLogs($key, $callback) { $p = compact('key', 'callback'); $q = http_build_query($p); curl_setopt($this->ch, CURLOPT_POST, false); curl_setopt($this->ch, CURLOPT_URL, static::URL.'/callback_log?'.$q); if (($resp = curl_exec($this->ch)) === false) { throw new HttpError(curl_error($this->ch)); } if (($data = json_decode($resp, true)) === NULL) { throw new Error("Unable to decode JSON response from Blockchain: $resp"); } $info = curl_getinfo($this->ch); if ($info['http_code'] == 200) { return array_map([$this, 'createCallbackLogEntry'], (array) $data); } throw new Error(implode(', ', $data)); }
php
public function callbackLogs($key, $callback) { $p = compact('key', 'callback'); $q = http_build_query($p); curl_setopt($this->ch, CURLOPT_POST, false); curl_setopt($this->ch, CURLOPT_URL, static::URL.'/callback_log?'.$q); if (($resp = curl_exec($this->ch)) === false) { throw new HttpError(curl_error($this->ch)); } if (($data = json_decode($resp, true)) === NULL) { throw new Error("Unable to decode JSON response from Blockchain: $resp"); } $info = curl_getinfo($this->ch); if ($info['http_code'] == 200) { return array_map([$this, 'createCallbackLogEntry'], (array) $data); } throw new Error(implode(', ', $data)); }
[ "public", "function", "callbackLogs", "(", "$", "key", ",", "$", "callback", ")", "{", "$", "p", "=", "compact", "(", "'key'", ",", "'callback'", ")", ";", "$", "q", "=", "http_build_query", "(", "$", "p", ")", ";", "curl_setopt", "(", "$", "this", ...
Gets the callback logs. @param string $key The API key. @param string $callback The callback URL. @return \Blockchain\V2\Receive\CallbackLogEntry[] @throws \Blochchain\Exception\Error @throws \Blockchain\Exception\HttpError
[ "Gets", "the", "callback", "logs", "." ]
be194230ed4dd97d5ae84bcf67a4c90f930566b5
https://github.com/blockchain/api-v1-client-php/blob/be194230ed4dd97d5ae84bcf67a4c90f930566b5/src/V2/Receive/Receive.php#L120-L143
train
pantheon-systems/example-drops-8-composer
scripts/composer/ScriptHandler.php
ScriptHandler.prepareForPantheon
public static function prepareForPantheon() { // Get rid of any .git directories that Composer may have added. // n.b. Ideally, there are none of these, as removing them may // impair Composer's ability to update them later. However, leaving // them in place prevents us from pushing to Pantheon. $dirsToDelete = []; $finder = new Finder(); foreach ( $finder ->directories() ->in(getcwd()) ->ignoreDotFiles(false) ->ignoreVCS(false) ->depth('> 0') ->name('.git') as $dir) { $dirsToDelete[] = $dir; } $fs = new Filesystem(); $fs->remove($dirsToDelete); // Fix up .gitignore: remove everything above the "::: cut :::" line $gitignoreFile = getcwd() . '/.gitignore'; $gitignoreContents = file_get_contents($gitignoreFile); $gitignoreContents = preg_replace('/.*::: cut :::*/s', '', $gitignoreContents); file_put_contents($gitignoreFile, $gitignoreContents); }
php
public static function prepareForPantheon() { // Get rid of any .git directories that Composer may have added. // n.b. Ideally, there are none of these, as removing them may // impair Composer's ability to update them later. However, leaving // them in place prevents us from pushing to Pantheon. $dirsToDelete = []; $finder = new Finder(); foreach ( $finder ->directories() ->in(getcwd()) ->ignoreDotFiles(false) ->ignoreVCS(false) ->depth('> 0') ->name('.git') as $dir) { $dirsToDelete[] = $dir; } $fs = new Filesystem(); $fs->remove($dirsToDelete); // Fix up .gitignore: remove everything above the "::: cut :::" line $gitignoreFile = getcwd() . '/.gitignore'; $gitignoreContents = file_get_contents($gitignoreFile); $gitignoreContents = preg_replace('/.*::: cut :::*/s', '', $gitignoreContents); file_put_contents($gitignoreFile, $gitignoreContents); }
[ "public", "static", "function", "prepareForPantheon", "(", ")", "{", "// Get rid of any .git directories that Composer may have added.", "// n.b. Ideally, there are none of these, as removing them may", "// impair Composer's ability to update them later. However, leaving", "// them in place prev...
is not used in the GitHub PR workflow.
[ "is", "not", "used", "in", "the", "GitHub", "PR", "workflow", "." ]
a0a8468f164b703e92864631a39eb518ebfb1a22
https://github.com/pantheon-systems/example-drops-8-composer/blob/a0a8468f164b703e92864631a39eb518ebfb1a22/scripts/composer/ScriptHandler.php#L55-L82
train
jamesiarmes/php-ews
src/Client.php
Client.initializeSoapClient
protected function initializeSoapClient() { $this->soap = new SoapClient( dirname(__FILE__) . '/assets/services.wsdl', array( 'user' => $this->username, 'password' => $this->password, 'location' => 'https://' . $this->server . '/EWS/Exchange.asmx', 'classmap' => $this->classMap(), 'curlopts' => $this->curl_options, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, ) ); return $this->soap; }
php
protected function initializeSoapClient() { $this->soap = new SoapClient( dirname(__FILE__) . '/assets/services.wsdl', array( 'user' => $this->username, 'password' => $this->password, 'location' => 'https://' . $this->server . '/EWS/Exchange.asmx', 'classmap' => $this->classMap(), 'curlopts' => $this->curl_options, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, ) ); return $this->soap; }
[ "protected", "function", "initializeSoapClient", "(", ")", "{", "$", "this", "->", "soap", "=", "new", "SoapClient", "(", "dirname", "(", "__FILE__", ")", ".", "'/assets/services.wsdl'", ",", "array", "(", "'user'", "=>", "$", "this", "->", "username", ",", ...
Initializes the SoapClient object to make a request @return \jamesiarmes\PhpNtlm\SoapClient
[ "Initializes", "the", "SoapClient", "object", "to", "make", "a", "request" ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Client.php#L1605-L1620
train
jamesiarmes/php-ews
src/Client.php
Client.makeRequest
protected function makeRequest($operation, $request) { $this->getClient()->__setSoapHeaders($this->soapHeaders()); $response = $this->soap->{$operation}($request); return $this->processResponse($response); }
php
protected function makeRequest($operation, $request) { $this->getClient()->__setSoapHeaders($this->soapHeaders()); $response = $this->soap->{$operation}($request); return $this->processResponse($response); }
[ "protected", "function", "makeRequest", "(", "$", "operation", ",", "$", "request", ")", "{", "$", "this", "->", "getClient", "(", ")", "->", "__setSoapHeaders", "(", "$", "this", "->", "soapHeaders", "(", ")", ")", ";", "$", "response", "=", "$", "thi...
Makes the SOAP call for a request. @param string $operation The operation to be called. @param \jamesiarmes\PhpEws\Request $request The request object for the operation. @return \jamesiarmes\PhpEws\Response The response object for the operation. @suppress PhanTypeMismatchReturn
[ "Makes", "the", "SOAP", "call", "for", "a", "request", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Client.php#L1648-L1654
train
jamesiarmes/php-ews
src/Client.php
Client.processResponse
protected function processResponse($response) { // If the soap call failed then we need to throw an exception. $code = $this->soap->getResponseCode(); if ($code != 200) { throw new \Exception( "SOAP client returned status of $code.", $code ); } return $response; }
php
protected function processResponse($response) { // If the soap call failed then we need to throw an exception. $code = $this->soap->getResponseCode(); if ($code != 200) { throw new \Exception( "SOAP client returned status of $code.", $code ); } return $response; }
[ "protected", "function", "processResponse", "(", "$", "response", ")", "{", "// If the soap call failed then we need to throw an exception.", "$", "code", "=", "$", "this", "->", "soap", "->", "getResponseCode", "(", ")", ";", "if", "(", "$", "code", "!=", "200", ...
Process a response to verify that it succeeded and take the appropriate action @throws \Exception @param \stdClass $response @return \stdClass
[ "Process", "a", "response", "to", "verify", "that", "it", "succeeded", "and", "take", "the", "appropriate", "action" ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Client.php#L1665-L1677
train
jamesiarmes/php-ews
src/Client.php
Client.soapHeaders
protected function soapHeaders() { // If the headers have already been built, no need to do so again. if (!empty($this->headers)) { return $this->headers; } $this->headers = array(); // Set the schema version. $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'RequestServerVersion Version="' . $this->version . '"' ); // If impersonation was set then add it to the headers. if (!empty($this->impersonation)) { $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'ExchangeImpersonation', $this->impersonation ); } if (!empty($this->timezone)) { $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'TimeZoneContext', array( 'TimeZoneDefinition' => array( 'Id' => $this->timezone, ) ) ); } return $this->headers; }
php
protected function soapHeaders() { // If the headers have already been built, no need to do so again. if (!empty($this->headers)) { return $this->headers; } $this->headers = array(); // Set the schema version. $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'RequestServerVersion Version="' . $this->version . '"' ); // If impersonation was set then add it to the headers. if (!empty($this->impersonation)) { $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'ExchangeImpersonation', $this->impersonation ); } if (!empty($this->timezone)) { $this->headers[] = new \SoapHeader( 'http://schemas.microsoft.com/exchange/services/2006/types', 'TimeZoneContext', array( 'TimeZoneDefinition' => array( 'Id' => $this->timezone, ) ) ); } return $this->headers; }
[ "protected", "function", "soapHeaders", "(", ")", "{", "// If the headers have already been built, no need to do so again.", "if", "(", "!", "empty", "(", "$", "this", "->", "headers", ")", ")", "{", "return", "$", "this", "->", "headers", ";", "}", "$", "this",...
Builds the soap headers to be included with the request. @return \SoapHeader[]
[ "Builds", "the", "soap", "headers", "to", "be", "included", "with", "the", "request", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Client.php#L1684-L1721
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.discover
public function discover() { $result = $this->tryTLD(); if ($result === false) { $result = $this->trySubdomain(); } if ($result === false) { $result = $this->trySubdomainUnauthenticatedGet(); } if ($result === false) { $result = $this->trySRVRecord(); } if ($result === false) { throw new \RuntimeException('Autodiscovery failed.'); } return $result; }
php
public function discover() { $result = $this->tryTLD(); if ($result === false) { $result = $this->trySubdomain(); } if ($result === false) { $result = $this->trySubdomainUnauthenticatedGet(); } if ($result === false) { $result = $this->trySRVRecord(); } if ($result === false) { throw new \RuntimeException('Autodiscovery failed.'); } return $result; }
[ "public", "function", "discover", "(", ")", "{", "$", "result", "=", "$", "this", "->", "tryTLD", "(", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "$", "result", "=", "$", "this", "->", "trySubdomain", "(", ")", ";", "}", "if", ...
Execute the full discovery chain of events in the correct sequence until a valid response is received, or all methods have failed. @return integer One of the AUTODISCOVERED_VIA_* constants. @throws \RuntimeException When all autodiscovery methods fail.
[ "Execute", "the", "full", "discovery", "chain", "of", "events", "in", "the", "correct", "sequence", "until", "a", "valid", "response", "is", "received", "or", "all", "methods", "have", "failed", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L253-L274
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.newEWS
public function newEWS() { // Discovery not yet attempted. if ($this->discovered === null) { $this->discover(); } // Discovery not successful. if ($this->discovered === false) { return false; } $server = false; $version = null; // Pick out the host from the EXPR (Exchange RPC over HTTP). foreach ($this->discovered['Account']['Protocol'] as $protocol) { if (($protocol['Type'] == 'EXCH' || $protocol['Type'] == 'EXPR') && isset($protocol['ServerVersion'])) { if ($version === null) { $sv = $this->parseServerVersion($protocol['ServerVersion']); if ($sv !== false) { $version = $sv; } } } if ($protocol['Type'] == 'EXPR' && isset($protocol['Server'])) { $server = $protocol['Server']; } } if ($server) { if ($version === null) { // EWS class default. $version = Client::VERSION_2007; } return new Client( $server, (!empty($this->username) ? $this->username : $this->email), $this->password, $version ); } return false; }
php
public function newEWS() { // Discovery not yet attempted. if ($this->discovered === null) { $this->discover(); } // Discovery not successful. if ($this->discovered === false) { return false; } $server = false; $version = null; // Pick out the host from the EXPR (Exchange RPC over HTTP). foreach ($this->discovered['Account']['Protocol'] as $protocol) { if (($protocol['Type'] == 'EXCH' || $protocol['Type'] == 'EXPR') && isset($protocol['ServerVersion'])) { if ($version === null) { $sv = $this->parseServerVersion($protocol['ServerVersion']); if ($sv !== false) { $version = $sv; } } } if ($protocol['Type'] == 'EXPR' && isset($protocol['Server'])) { $server = $protocol['Server']; } } if ($server) { if ($version === null) { // EWS class default. $version = Client::VERSION_2007; } return new Client( $server, (!empty($this->username) ? $this->username : $this->email), $this->password, $version ); } return false; }
[ "public", "function", "newEWS", "(", ")", "{", "// Discovery not yet attempted.", "if", "(", "$", "this", "->", "discovered", "===", "null", ")", "{", "$", "this", "->", "discover", "(", ")", ";", "}", "// Discovery not successful.", "if", "(", "$", "this", ...
Method to return a new Client object, auto-configured with the proper hostname. @return mixed Client object on success, FALSE on failure.
[ "Method", "to", "return", "a", "new", "Client", "object", "auto", "-", "configured", "with", "the", "proper", "hostname", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L355-L401
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.tryTLD
public function tryTLD() { $url = 'https://' . $this->tld . self::AUTODISCOVER_PATH; return ($this->tryViaUrl($url) ? self::AUTODISCOVERED_VIA_TLD : false); }
php
public function tryTLD() { $url = 'https://' . $this->tld . self::AUTODISCOVER_PATH; return ($this->tryViaUrl($url) ? self::AUTODISCOVERED_VIA_TLD : false); }
[ "public", "function", "tryTLD", "(", ")", "{", "$", "url", "=", "'https://'", ".", "$", "this", "->", "tld", ".", "self", "::", "AUTODISCOVER_PATH", ";", "return", "(", "$", "this", "->", "tryViaUrl", "(", "$", "url", ")", "?", "self", "::", "AUTODIS...
Perform an NTLM authenticated HTTPS POST to the top-level domain of the email address. @return integer|boolean One of the AUTODISCOVERED_VIA_* constants or false on failure.
[ "Perform", "an", "NTLM", "authenticated", "HTTPS", "POST", "to", "the", "top", "-", "level", "domain", "of", "the", "email", "address", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L426-L430
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.trySubdomain
public function trySubdomain() { $url = 'https://autodiscover.' . $this->tld . self::AUTODISCOVER_PATH; return ($this->tryViaUrl($url) ? self::AUTODISCOVERED_VIA_SUBDOMAIN : false); }
php
public function trySubdomain() { $url = 'https://autodiscover.' . $this->tld . self::AUTODISCOVER_PATH; return ($this->tryViaUrl($url) ? self::AUTODISCOVERED_VIA_SUBDOMAIN : false); }
[ "public", "function", "trySubdomain", "(", ")", "{", "$", "url", "=", "'https://autodiscover.'", ".", "$", "this", "->", "tld", ".", "self", "::", "AUTODISCOVER_PATH", ";", "return", "(", "$", "this", "->", "tryViaUrl", "(", "$", "url", ")", "?", "self",...
Perform an NTLM authenticated HTTPS POST to the 'autodiscover' subdomain of the email address' TLD. @return integer|boolean One of the AUTODISCOVERED_VIA_* constants or false on failure.
[ "Perform", "an", "NTLM", "authenticated", "HTTPS", "POST", "to", "the", "autodiscover", "subdomain", "of", "the", "email", "address", "TLD", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L439-L445
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.trySubdomainUnauthenticatedGet
public function trySubdomainUnauthenticatedGet() { $this->reset(); $url = 'http://autodiscover.' . $this->tld . self::AUTODISCOVER_PATH; $ch = curl_init(); $opts = array( CURLOPT_URL => $url, CURLOPT_HTTPGET => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 4, CURLOPT_CONNECTTIMEOUT => $this->connection_timeout, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'readHeaders'), CURLOPT_HTTP200ALIASES => array(301, 302), CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 ); curl_setopt_array($ch, $opts); $this->last_response = curl_exec($ch); $this->last_info = curl_getinfo($ch); $this->last_curl_errno = curl_errno($ch); $this->last_curl_error = curl_error($ch); if ($this->last_info['http_code'] == 302 || $this->last_info['http_code'] == 301) { if ($this->tryViaUrl($this->last_response_headers['location'])) { return self::AUTODISCOVERED_VIA_UNAUTHENTICATED_GET; } } return false; }
php
public function trySubdomainUnauthenticatedGet() { $this->reset(); $url = 'http://autodiscover.' . $this->tld . self::AUTODISCOVER_PATH; $ch = curl_init(); $opts = array( CURLOPT_URL => $url, CURLOPT_HTTPGET => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 4, CURLOPT_CONNECTTIMEOUT => $this->connection_timeout, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'readHeaders'), CURLOPT_HTTP200ALIASES => array(301, 302), CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 ); curl_setopt_array($ch, $opts); $this->last_response = curl_exec($ch); $this->last_info = curl_getinfo($ch); $this->last_curl_errno = curl_errno($ch); $this->last_curl_error = curl_error($ch); if ($this->last_info['http_code'] == 302 || $this->last_info['http_code'] == 301) { if ($this->tryViaUrl($this->last_response_headers['location'])) { return self::AUTODISCOVERED_VIA_UNAUTHENTICATED_GET; } } return false; }
[ "public", "function", "trySubdomainUnauthenticatedGet", "(", ")", "{", "$", "this", "->", "reset", "(", ")", ";", "$", "url", "=", "'http://autodiscover.'", ".", "$", "this", "->", "tld", ".", "self", "::", "AUTODISCOVER_PATH", ";", "$", "ch", "=", "curl_i...
Perform an unauthenticated HTTP GET in an attempt to get redirected via 302 to the correct location to perform the HTTPS POST. @return integer|boolean One of the AUTODISCOVERED_VIA_* constants or false on failure.
[ "Perform", "an", "unauthenticated", "HTTP", "GET", "in", "an", "attempt", "to", "get", "redirected", "via", "302", "to", "the", "correct", "location", "to", "perform", "the", "HTTPS", "POST", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L454-L485
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.trySRVRecord
public function trySRVRecord() { $srvhost = '_autodiscover._tcp.' . $this->tld; $lookup = dns_get_record($srvhost, DNS_SRV); if (sizeof($lookup) > 0) { $host = $lookup[0]['target']; $url = 'https://' . $host . self::AUTODISCOVER_PATH; if ($this->tryViaUrl($url)) { return self::AUTODISCOVERED_VIA_SRV_RECORD; } } return false; }
php
public function trySRVRecord() { $srvhost = '_autodiscover._tcp.' . $this->tld; $lookup = dns_get_record($srvhost, DNS_SRV); if (sizeof($lookup) > 0) { $host = $lookup[0]['target']; $url = 'https://' . $host . self::AUTODISCOVER_PATH; if ($this->tryViaUrl($url)) { return self::AUTODISCOVERED_VIA_SRV_RECORD; } } return false; }
[ "public", "function", "trySRVRecord", "(", ")", "{", "$", "srvhost", "=", "'_autodiscover._tcp.'", ".", "$", "this", "->", "tld", ";", "$", "lookup", "=", "dns_get_record", "(", "$", "srvhost", ",", "DNS_SRV", ")", ";", "if", "(", "sizeof", "(", "$", "...
Attempt to retrieve the autodiscover host from an SRV DNS record. @link http://support.microsoft.com/kb/940881 @return integer|boolean The value of self::AUTODISCOVERED_VIA_SRV_RECORD or false.
[ "Attempt", "to", "retrieve", "the", "autodiscover", "host", "from", "an", "SRV", "DNS", "record", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L495-L508
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.setCAInfo
public function setCAInfo($path) { if (file_exists($path) && is_file($path)) { $this->cainfo = $path; } return $this; }
php
public function setCAInfo($path) { if (file_exists($path) && is_file($path)) { $this->cainfo = $path; } return $this; }
[ "public", "function", "setCAInfo", "(", "$", "path", ")", "{", "if", "(", "file_exists", "(", "$", "path", ")", "&&", "is_file", "(", "$", "path", ")", ")", "{", "$", "this", "->", "cainfo", "=", "$", "path", ";", "}", "return", "$", "this", ";",...
Set the path to the file to be used by CURLOPT_CAINFO. @param string $path Path to a certificate file such as cacert.pem @return self
[ "Set", "the", "path", "to", "the", "file", "to", "be", "used", "by", "CURLOPT_CAINFO", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L517-L524
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.doNTLMPost
public function doNTLMPost($url, $timeout = 6) { $this->reset(); $ch = curl_init(); $opts = array( CURLOPT_URL => $url, CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $this->getAutoDiscoverRequest(), CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $this->username . ':' . $this->password, CURLOPT_TIMEOUT => $timeout, CURLOPT_CONNECTTIMEOUT => $this->connection_timeout, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'readHeaders'), CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, ); // Set the appropriate content-type. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8')); if (!empty($this->cainfo)) { $opts[CURLOPT_CAINFO] = $this->cainfo; } if (!empty($this->capath)) { $opts[CURLOPT_CAPATH] = $this->capath; } if ($this->skip_ssl_verification) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } curl_setopt_array($ch, $opts); $this->last_response = curl_exec($ch); $this->last_info = curl_getinfo($ch); $this->last_curl_errno = curl_errno($ch); $this->last_curl_error = curl_error($ch); if ($this->last_curl_errno != CURLE_OK) { return false; } $discovered = $this->parseAutodiscoverResponse(); return $discovered; }
php
public function doNTLMPost($url, $timeout = 6) { $this->reset(); $ch = curl_init(); $opts = array( CURLOPT_URL => $url, CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $this->getAutoDiscoverRequest(), CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $this->username . ':' . $this->password, CURLOPT_TIMEOUT => $timeout, CURLOPT_CONNECTTIMEOUT => $this->connection_timeout, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'readHeaders'), CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, ); // Set the appropriate content-type. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8')); if (!empty($this->cainfo)) { $opts[CURLOPT_CAINFO] = $this->cainfo; } if (!empty($this->capath)) { $opts[CURLOPT_CAPATH] = $this->capath; } if ($this->skip_ssl_verification) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } curl_setopt_array($ch, $opts); $this->last_response = curl_exec($ch); $this->last_info = curl_getinfo($ch); $this->last_curl_errno = curl_errno($ch); $this->last_curl_error = curl_error($ch); if ($this->last_curl_errno != CURLE_OK) { return false; } $discovered = $this->parseAutodiscoverResponse(); return $discovered; }
[ "public", "function", "doNTLMPost", "(", "$", "url", ",", "$", "timeout", "=", "6", ")", "{", "$", "this", "->", "reset", "(", ")", ";", "$", "ch", "=", "curl_init", "(", ")", ";", "$", "opts", "=", "array", "(", "CURLOPT_URL", "=>", "$", "url", ...
Perform the NTLM authenticated post against one of the chosen endpoints. @param string $url URL to try posting to. @param integer $timeout Number of seconds before the request should timeout. @return boolean
[ "Perform", "the", "NTLM", "authenticated", "post", "against", "one", "of", "the", "chosen", "endpoints", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L566-L616
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.parseAutodiscoverResponse
protected function parseAutodiscoverResponse() { // Content-type isn't trustworthy, unfortunately. Shame on Microsoft. if (substr($this->last_response, 0, 5) !== '<?xml') { return false; } $response = $this->responseToArray($this->last_response); if (isset($response['Error'])) { $this->error = $response['Error']; return false; } // Check the account action for redirect. switch ($response['Account']['Action']) { case 'redirectUrl': $this->redirect = array( 'redirectUrl' => $response['Account']['RedirectUrl'] ); return false; case 'redirectAddr': $this->redirect = array( 'redirectAddr' => $response['Account']['RedirectAddr'] ); return false; case 'settings': default: $this->discovered = $response; return true; } }
php
protected function parseAutodiscoverResponse() { // Content-type isn't trustworthy, unfortunately. Shame on Microsoft. if (substr($this->last_response, 0, 5) !== '<?xml') { return false; } $response = $this->responseToArray($this->last_response); if (isset($response['Error'])) { $this->error = $response['Error']; return false; } // Check the account action for redirect. switch ($response['Account']['Action']) { case 'redirectUrl': $this->redirect = array( 'redirectUrl' => $response['Account']['RedirectUrl'] ); return false; case 'redirectAddr': $this->redirect = array( 'redirectAddr' => $response['Account']['RedirectAddr'] ); return false; case 'settings': default: $this->discovered = $response; return true; } }
[ "protected", "function", "parseAutodiscoverResponse", "(", ")", "{", "// Content-type isn't trustworthy, unfortunately. Shame on Microsoft.", "if", "(", "substr", "(", "$", "this", "->", "last_response", ",", "0", ",", "5", ")", "!==", "'<?xml'", ")", "{", "return", ...
Parse the Autoresponse Payload, particularly to determine if an additional request is necessary. @return boolean|array FALSE if response isn't XML or parsed response array.
[ "Parse", "the", "Autoresponse", "Payload", "particularly", "to", "determine", "if", "an", "additional", "request", "is", "necessary", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L625-L656
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.setTLD
protected function setTLD() { $pos = strpos($this->email, '@'); if ($pos !== false) { $this->tld = trim(substr($this->email, $pos + 1)); return true; } return false; }
php
protected function setTLD() { $pos = strpos($this->email, '@'); if ($pos !== false) { $this->tld = trim(substr($this->email, $pos + 1)); return true; } return false; }
[ "protected", "function", "setTLD", "(", ")", "{", "$", "pos", "=", "strpos", "(", "$", "this", "->", "email", ",", "'@'", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "$", "this", "->", "tld", "=", "trim", "(", "substr", "(", "$",...
Set the top-level domain to be used with autodiscover attempts based on the provided email address. @return boolean
[ "Set", "the", "top", "-", "level", "domain", "to", "be", "used", "with", "autodiscover", "attempts", "based", "on", "the", "provided", "email", "address", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L664-L673
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.reset
public function reset() { $this->last_response_headers = array(); $this->last_info = array(); $this->last_curl_errno = 0; $this->last_curl_error = ''; return $this; }
php
public function reset() { $this->last_response_headers = array(); $this->last_info = array(); $this->last_curl_errno = 0; $this->last_curl_error = ''; return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "last_response_headers", "=", "array", "(", ")", ";", "$", "this", "->", "last_info", "=", "array", "(", ")", ";", "$", "this", "->", "last_curl_errno", "=", "0", ";", "$", "this", "->"...
Reset the response-related structures. Called before making a new request. @return self
[ "Reset", "the", "response", "-", "related", "structures", ".", "Called", "before", "making", "a", "new", "request", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L681-L689
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.getAutodiscoverRequest
public function getAutodiscoverRequest() { if (!empty($this->requestxml)) { return $this->requestxml; } $xml = new \XMLWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->startDocument('1.0', 'UTF-8'); $xml->startElementNS( null, 'Autodiscover', 'http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006' ); $xml->startElement('Request'); $xml->writeElement('EMailAddress', $this->email); $xml->writeElement( 'AcceptableResponseSchema', 'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a' ); $xml->endElement(); $xml->endElement(); $this->requestxml = $xml->outputMemory(); return $this->requestxml; }
php
public function getAutodiscoverRequest() { if (!empty($this->requestxml)) { return $this->requestxml; } $xml = new \XMLWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->startDocument('1.0', 'UTF-8'); $xml->startElementNS( null, 'Autodiscover', 'http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006' ); $xml->startElement('Request'); $xml->writeElement('EMailAddress', $this->email); $xml->writeElement( 'AcceptableResponseSchema', 'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a' ); $xml->endElement(); $xml->endElement(); $this->requestxml = $xml->outputMemory(); return $this->requestxml; }
[ "public", "function", "getAutodiscoverRequest", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "requestxml", ")", ")", "{", "return", "$", "this", "->", "requestxml", ";", "}", "$", "xml", "=", "new", "\\", "XMLWriter", "(", ")", ";"...
Return the generated Autodiscover XML request body. @return string @suppress PhanTypeMismatchArgumentInternal
[ "Return", "the", "generated", "Autodiscover", "XML", "request", "body", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L698-L725
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.readHeaders
public function readHeaders($_ch, $str) { $pos = strpos($str, ':'); if ($pos !== false) { $key = strtolower(substr($str, 0, $pos)); $val = trim(substr($str, $pos + 1)); $this->last_response_headers[$key] = $val; } return strlen($str); }
php
public function readHeaders($_ch, $str) { $pos = strpos($str, ':'); if ($pos !== false) { $key = strtolower(substr($str, 0, $pos)); $val = trim(substr($str, $pos + 1)); $this->last_response_headers[$key] = $val; } return strlen($str); }
[ "public", "function", "readHeaders", "(", "$", "_ch", ",", "$", "str", ")", "{", "$", "pos", "=", "strpos", "(", "$", "str", ",", "':'", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "$", "key", "=", "strtolower", "(", "substr", "(...
Utility function to pick headers off of the incoming cURL response. Used with CURLOPT_HEADERFUNCTION. @param resource $_ch cURL handle. @param string $str Header string to read. @return integer Bytes read. @todo Determine if we can remove $_ch here. @SuppressWarnings(PHPMD.UnusedFormalParameter)
[ "Utility", "function", "to", "pick", "headers", "off", "of", "the", "incoming", "cURL", "response", ".", "Used", "with", "CURLOPT_HEADERFUNCTION", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L741-L751
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.responseToArray
public function responseToArray($xml) { $doc = new \DOMDocument(); $doc->loadXML($xml); $out = $this->nodeToArray($doc->documentElement); return $out['Response']; }
php
public function responseToArray($xml) { $doc = new \DOMDocument(); $doc->loadXML($xml); $out = $this->nodeToArray($doc->documentElement); return $out['Response']; }
[ "public", "function", "responseToArray", "(", "$", "xml", ")", "{", "$", "doc", "=", "new", "\\", "DOMDocument", "(", ")", ";", "$", "doc", "->", "loadXML", "(", "$", "xml", ")", ";", "$", "out", "=", "$", "this", "->", "nodeToArray", "(", "$", "...
Utility function to parse XML payloads from the response into easier to manage associative arrays. @param string $xml XML to parse. @return array
[ "Utility", "function", "to", "parse", "XML", "payloads", "from", "the", "response", "into", "easier", "to", "manage", "associative", "arrays", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L761-L768
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.nodeToArray
protected function nodeToArray($node) { $output = array(); switch ($node->nodeType) { case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: $output = trim($node->textContent); break; case XML_ELEMENT_NODE: for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) { $child = $node->childNodes->item($i); $value = $this->nodeToArray($child); if (isset($child->tagName)) { $tag = $child->tagName; if (!isset($output[$tag])) { $output[$tag] = array(); } $output[$tag][] = $value; } elseif ($value || $value === '0') { $output = (string) $value; } } // Edge case of a node containing a text node, which also has // attributes. this way we'll retain text and attributes for // this node. if (is_string($output) && $node->attributes->length) { $output = array('@text' => $output); } if (is_array($output)) { if ($node->attributes->length) { $attributes = array(); foreach ($node->attributes as $attrName => $attrNode) { $attributes[$attrName] = (string) $attrNode->value; } $output['@attributes'] = $attributes; } foreach ($output as $tag => $value) { if (is_array($value) && count($value) == 1 && $tag != '@attributes') { $output[$tag] = $value[0]; } } } break; } return $output; }
php
protected function nodeToArray($node) { $output = array(); switch ($node->nodeType) { case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: $output = trim($node->textContent); break; case XML_ELEMENT_NODE: for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) { $child = $node->childNodes->item($i); $value = $this->nodeToArray($child); if (isset($child->tagName)) { $tag = $child->tagName; if (!isset($output[$tag])) { $output[$tag] = array(); } $output[$tag][] = $value; } elseif ($value || $value === '0') { $output = (string) $value; } } // Edge case of a node containing a text node, which also has // attributes. this way we'll retain text and attributes for // this node. if (is_string($output) && $node->attributes->length) { $output = array('@text' => $output); } if (is_array($output)) { if ($node->attributes->length) { $attributes = array(); foreach ($node->attributes as $attrName => $attrNode) { $attributes[$attrName] = (string) $attrNode->value; } $output['@attributes'] = $attributes; } foreach ($output as $tag => $value) { if (is_array($value) && count($value) == 1 && $tag != '@attributes') { $output[$tag] = $value[0]; } } } break; } return $output; }
[ "protected", "function", "nodeToArray", "(", "$", "node", ")", "{", "$", "output", "=", "array", "(", ")", ";", "switch", "(", "$", "node", "->", "nodeType", ")", "{", "case", "XML_CDATA_SECTION_NODE", ":", "case", "XML_TEXT_NODE", ":", "$", "output", "=...
Recursive method for parsing DOM nodes. @param \DOMElement $node DOMNode object. @return mixed @link https://github.com/gaarf/XML-string-to-PHP-array @suppress PhanTypeMismatchArgument, PhanUndeclaredProperty
[ "Recursive", "method", "for", "parsing", "DOM", "nodes", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L781-L829
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.parseVersion2010
protected function parseVersion2010($minorversion) { switch ($minorversion) { case 0: return Client::VERSION_2010; case 1: return Client::VERSION_2010_SP1; case 2: return Client::VERSION_2010_SP2; default: return Client::VERSION_2010; } }
php
protected function parseVersion2010($minorversion) { switch ($minorversion) { case 0: return Client::VERSION_2010; case 1: return Client::VERSION_2010_SP1; case 2: return Client::VERSION_2010_SP2; default: return Client::VERSION_2010; } }
[ "protected", "function", "parseVersion2010", "(", "$", "minorversion", ")", "{", "switch", "(", "$", "minorversion", ")", "{", "case", "0", ":", "return", "Client", "::", "VERSION_2010", ";", "case", "1", ":", "return", "Client", "::", "VERSION_2010_SP1", ";...
Parses the version of an Exchange 2010 server. @param integer $minorversion Minor server version. @return string Server version.
[ "Parses", "the", "version", "of", "an", "Exchange", "2010", "server", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L859-L871
train
jamesiarmes/php-ews
src/Autodiscover.php
Autodiscover.tryViaUrl
protected function tryViaUrl($url, $timeout = 6) { $result = $this->doNTLMPost($url, $timeout); return ($result ? true : false); }
php
protected function tryViaUrl($url, $timeout = 6) { $result = $this->doNTLMPost($url, $timeout); return ($result ? true : false); }
[ "protected", "function", "tryViaUrl", "(", "$", "url", ",", "$", "timeout", "=", "6", ")", "{", "$", "result", "=", "$", "this", "->", "doNTLMPost", "(", "$", "url", ",", "$", "timeout", ")", ";", "return", "(", "$", "result", "?", "true", ":", "...
Attempts an autodiscover via a URL. @param string $url Url to attempt an autodiscover. @param integer $timeout Number of seconds before the request should timeout. @return boolean
[ "Attempts", "an", "autodiscover", "via", "a", "URL", "." ]
eaad3c8d3c40721e2acf0732c1f398829e772c3c
https://github.com/jamesiarmes/php-ews/blob/eaad3c8d3c40721e2acf0732c1f398829e772c3c/src/Autodiscover.php#L906-L910
train