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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.weightedMean | public static function weightedMean(array $values, array $weights, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Mean is undefined for empty'
. ' set.');
}
if (count($weights) !== $n) {
throw new InvalidArgumentException('The number of weights must'
. ' equal the number of values.');
}
$total = array_sum($weights) ?: EPSILON;
$temp = 0.;
foreach ($values as $i => $value) {
$temp += $value * ($weights[$i] ?: EPSILON);
}
return $temp / $total;
} | php | public static function weightedMean(array $values, array $weights, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Mean is undefined for empty'
. ' set.');
}
if (count($weights) !== $n) {
throw new InvalidArgumentException('The number of weights must'
. ' equal the number of values.');
}
$total = array_sum($weights) ?: EPSILON;
$temp = 0.;
foreach ($values as $i => $value) {
$temp += $value * ($weights[$i] ?: EPSILON);
}
return $temp / $total;
} | [
"public",
"static",
"function",
"weightedMean",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"weights",
",",
"?",
"int",
"$",
"n",
"=",
"null",
")",
":",
"float",
"{",
"$",
"n",
"=",
"$",
"n",
"??",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Mean is undefined for empty'",
".",
"' set.'",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"weights",
")",
"!==",
"$",
"n",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The number of weights must'",
".",
"' equal the number of values.'",
")",
";",
"}",
"$",
"total",
"=",
"array_sum",
"(",
"$",
"weights",
")",
"?",
":",
"EPSILON",
";",
"$",
"temp",
"=",
"0.",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"i",
"=>",
"$",
"value",
")",
"{",
"$",
"temp",
"+=",
"$",
"value",
"*",
"(",
"$",
"weights",
"[",
"$",
"i",
"]",
"?",
":",
"EPSILON",
")",
";",
"}",
"return",
"$",
"temp",
"/",
"$",
"total",
";",
"}"
] | Compute the weighted mean of a set of values.
@param array $values
@param array $weights
@param int|null $n
@return float | [
"Compute",
"the",
"weighted",
"mean",
"of",
"a",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L49-L72 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.mode | public static function mode(array $values) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Mode is undefined for empty'
. ' set.');
}
$counts = array_count_values(array_map('strval', $values));
return (float) argmax($counts);
} | php | public static function mode(array $values) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Mode is undefined for empty'
. ' set.');
}
$counts = array_count_values(array_map('strval', $values));
return (float) argmax($counts);
} | [
"public",
"static",
"function",
"mode",
"(",
"array",
"$",
"values",
")",
":",
"float",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Mode is undefined for empty'",
".",
"' set.'",
")",
";",
"}",
"$",
"counts",
"=",
"array_count_values",
"(",
"array_map",
"(",
"'strval'",
",",
"$",
"values",
")",
")",
";",
"return",
"(",
"float",
")",
"argmax",
"(",
"$",
"counts",
")",
";",
"}"
] | Find a mode of a set of values i.e a value that appears most often in the
set.
@param array $values
@throws \InvalidArgumentException
@return float | [
"Find",
"a",
"mode",
"of",
"a",
"set",
"of",
"values",
"i",
".",
"e",
"a",
"value",
"that",
"appears",
"most",
"often",
"in",
"the",
"set",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L93-L103 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.variance | public static function variance(array $values, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Variance is undefined for an'
. ' empty set.');
}
$mean = $mean ?? self::mean($values);
$ssd = 0.;
foreach ($values as $value) {
$ssd += ($value - $mean) ** 2;
}
return $ssd / $n;
} | php | public static function variance(array $values, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Variance is undefined for an'
. ' empty set.');
}
$mean = $mean ?? self::mean($values);
$ssd = 0.;
foreach ($values as $value) {
$ssd += ($value - $mean) ** 2;
}
return $ssd / $n;
} | [
"public",
"static",
"function",
"variance",
"(",
"array",
"$",
"values",
",",
"?",
"float",
"$",
"mean",
"=",
"null",
",",
"?",
"int",
"$",
"n",
"=",
"null",
")",
":",
"float",
"{",
"$",
"n",
"=",
"$",
"n",
"??",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Variance is undefined for an'",
".",
"' empty set.'",
")",
";",
"}",
"$",
"mean",
"=",
"$",
"mean",
"??",
"self",
"::",
"mean",
"(",
"$",
"values",
")",
";",
"$",
"ssd",
"=",
"0.",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"ssd",
"+=",
"(",
"$",
"value",
"-",
"$",
"mean",
")",
"**",
"2",
";",
"}",
"return",
"$",
"ssd",
"/",
"$",
"n",
";",
"}"
] | Compute the variance of a set of values given a mean and n degrees of
freedom.
@param array $values
@param float|null $mean
@param int|null $n
@throws \InvalidArgumentException
@return float | [
"Compute",
"the",
"variance",
"of",
"a",
"set",
"of",
"values",
"given",
"a",
"mean",
"and",
"n",
"degrees",
"of",
"freedom",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L115-L133 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.median | public static function median(array $values) : float
{
$n = count($values);
if ($n < 1) {
throw new InvalidArgumentException('Median is undefined for empty'
. ' set.');
}
$mid = intdiv($n, 2);
sort($values);
if ($n % 2 === 1) {
$median = $values[$mid];
} else {
$median = self::mean([$values[$mid - 1], $values[$mid]]);
}
return $median;
} | php | public static function median(array $values) : float
{
$n = count($values);
if ($n < 1) {
throw new InvalidArgumentException('Median is undefined for empty'
. ' set.');
}
$mid = intdiv($n, 2);
sort($values);
if ($n % 2 === 1) {
$median = $values[$mid];
} else {
$median = self::mean([$values[$mid - 1], $values[$mid]]);
}
return $median;
} | [
"public",
"static",
"function",
"median",
"(",
"array",
"$",
"values",
")",
":",
"float",
"{",
"$",
"n",
"=",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Median is undefined for empty'",
".",
"' set.'",
")",
";",
"}",
"$",
"mid",
"=",
"intdiv",
"(",
"$",
"n",
",",
"2",
")",
";",
"sort",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"%",
"2",
"===",
"1",
")",
"{",
"$",
"median",
"=",
"$",
"values",
"[",
"$",
"mid",
"]",
";",
"}",
"else",
"{",
"$",
"median",
"=",
"self",
"::",
"mean",
"(",
"[",
"$",
"values",
"[",
"$",
"mid",
"-",
"1",
"]",
",",
"$",
"values",
"[",
"$",
"mid",
"]",
"]",
")",
";",
"}",
"return",
"$",
"median",
";",
"}"
] | Calculate the median of a set of values.
@param array $values
@throws \InvalidArgumentException
@return float | [
"Calculate",
"the",
"median",
"of",
"a",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L142-L162 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.percentile | public static function percentile(array $values, float $p) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Percentile is not defined for'
. ' an empty set.');
}
if ($p < 0. or $p > 100.) {
throw new InvalidArgumentException('P must be between 0 and 1,'
. " $p given.");
}
$n = count($values);
sort($values);
$x = ($p / 100) * ($n - 1) + 1;
$xHat = (int) $x;
$remainder = $x - $xHat;
$a = $values[$xHat - 1];
$b = $values[$xHat];
return $a + $remainder * ($b - $a);
} | php | public static function percentile(array $values, float $p) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Percentile is not defined for'
. ' an empty set.');
}
if ($p < 0. or $p > 100.) {
throw new InvalidArgumentException('P must be between 0 and 1,'
. " $p given.");
}
$n = count($values);
sort($values);
$x = ($p / 100) * ($n - 1) + 1;
$xHat = (int) $x;
$remainder = $x - $xHat;
$a = $values[$xHat - 1];
$b = $values[$xHat];
return $a + $remainder * ($b - $a);
} | [
"public",
"static",
"function",
"percentile",
"(",
"array",
"$",
"values",
",",
"float",
"$",
"p",
")",
":",
"float",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Percentile is not defined for'",
".",
"' an empty set.'",
")",
";",
"}",
"if",
"(",
"$",
"p",
"<",
"0.",
"or",
"$",
"p",
">",
"100.",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'P must be between 0 and 1,'",
".",
"\" $p given.\"",
")",
";",
"}",
"$",
"n",
"=",
"count",
"(",
"$",
"values",
")",
";",
"sort",
"(",
"$",
"values",
")",
";",
"$",
"x",
"=",
"(",
"$",
"p",
"/",
"100",
")",
"*",
"(",
"$",
"n",
"-",
"1",
")",
"+",
"1",
";",
"$",
"xHat",
"=",
"(",
"int",
")",
"$",
"x",
";",
"$",
"remainder",
"=",
"$",
"x",
"-",
"$",
"xHat",
";",
"$",
"a",
"=",
"$",
"values",
"[",
"$",
"xHat",
"-",
"1",
"]",
";",
"$",
"b",
"=",
"$",
"values",
"[",
"$",
"xHat",
"]",
";",
"return",
"$",
"a",
"+",
"$",
"remainder",
"*",
"(",
"$",
"b",
"-",
"$",
"a",
")",
";",
"}"
] | Calculate the pth percentile of a given set of values.
@param array $values
@param float $p
@throws \InvalidArgumentException
@return float | [
"Calculate",
"the",
"pth",
"percentile",
"of",
"a",
"given",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L172-L198 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.iqr | public static function iqr(array $values) : float
{
$n = count($values);
if ($n < 1) {
throw new InvalidArgumentException('Interquartile range is not'
. ' defined for empty set.');
}
$mid = intdiv($n, 2);
sort($values);
if ($n % 2 === 0) {
$lower = array_slice($values, 0, $mid);
$upper = array_slice($values, $mid);
} else {
$lower = array_slice($values, 0, $mid);
$upper = array_slice($values, $mid + 1);
}
return self::median($upper) - self::median($lower);
} | php | public static function iqr(array $values) : float
{
$n = count($values);
if ($n < 1) {
throw new InvalidArgumentException('Interquartile range is not'
. ' defined for empty set.');
}
$mid = intdiv($n, 2);
sort($values);
if ($n % 2 === 0) {
$lower = array_slice($values, 0, $mid);
$upper = array_slice($values, $mid);
} else {
$lower = array_slice($values, 0, $mid);
$upper = array_slice($values, $mid + 1);
}
return self::median($upper) - self::median($lower);
} | [
"public",
"static",
"function",
"iqr",
"(",
"array",
"$",
"values",
")",
":",
"float",
"{",
"$",
"n",
"=",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Interquartile range is not'",
".",
"' defined for empty set.'",
")",
";",
"}",
"$",
"mid",
"=",
"intdiv",
"(",
"$",
"n",
",",
"2",
")",
";",
"sort",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"%",
"2",
"===",
"0",
")",
"{",
"$",
"lower",
"=",
"array_slice",
"(",
"$",
"values",
",",
"0",
",",
"$",
"mid",
")",
";",
"$",
"upper",
"=",
"array_slice",
"(",
"$",
"values",
",",
"$",
"mid",
")",
";",
"}",
"else",
"{",
"$",
"lower",
"=",
"array_slice",
"(",
"$",
"values",
",",
"0",
",",
"$",
"mid",
")",
";",
"$",
"upper",
"=",
"array_slice",
"(",
"$",
"values",
",",
"$",
"mid",
"+",
"1",
")",
";",
"}",
"return",
"self",
"::",
"median",
"(",
"$",
"upper",
")",
"-",
"self",
"::",
"median",
"(",
"$",
"lower",
")",
";",
"}"
] | Compute the interquartile range of a set of values.
@param array $values
@throws \InvalidArgumentException
@return float | [
"Compute",
"the",
"interquartile",
"range",
"of",
"a",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L207-L229 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.mad | public static function mad(array $values, ?float $median = null) : float
{
$median = $median ?? self::median($values);
$deviations = [];
foreach ($values as $value) {
$deviations[] = abs($value - $median);
}
return self::median($deviations);
} | php | public static function mad(array $values, ?float $median = null) : float
{
$median = $median ?? self::median($values);
$deviations = [];
foreach ($values as $value) {
$deviations[] = abs($value - $median);
}
return self::median($deviations);
} | [
"public",
"static",
"function",
"mad",
"(",
"array",
"$",
"values",
",",
"?",
"float",
"$",
"median",
"=",
"null",
")",
":",
"float",
"{",
"$",
"median",
"=",
"$",
"median",
"??",
"self",
"::",
"median",
"(",
"$",
"values",
")",
";",
"$",
"deviations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"deviations",
"[",
"]",
"=",
"abs",
"(",
"$",
"value",
"-",
"$",
"median",
")",
";",
"}",
"return",
"self",
"::",
"median",
"(",
"$",
"deviations",
")",
";",
"}"
] | Calculate the median absolute deviation of a set of values given a median.
@param array $values
@param float|null $median
@return float | [
"Calculate",
"the",
"median",
"absolute",
"deviation",
"of",
"a",
"set",
"of",
"values",
"given",
"a",
"median",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L238-L249 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.centralMoment | public static function centralMoment(array $values, int $moment, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Central moment is undefined for'
. ' empty set.');
}
$mean = $mean ?? self::mean($values, $n);
$sigma = 0.;
foreach ($values as $value) {
$sigma += ($value - $mean) ** $moment;
}
return $sigma / $n;
} | php | public static function centralMoment(array $values, int $moment, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n < 1) {
throw new InvalidArgumentException('Central moment is undefined for'
. ' empty set.');
}
$mean = $mean ?? self::mean($values, $n);
$sigma = 0.;
foreach ($values as $value) {
$sigma += ($value - $mean) ** $moment;
}
return $sigma / $n;
} | [
"public",
"static",
"function",
"centralMoment",
"(",
"array",
"$",
"values",
",",
"int",
"$",
"moment",
",",
"?",
"float",
"$",
"mean",
"=",
"null",
",",
"?",
"int",
"$",
"n",
"=",
"null",
")",
":",
"float",
"{",
"$",
"n",
"=",
"$",
"n",
"??",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Central moment is undefined for'",
".",
"' empty set.'",
")",
";",
"}",
"$",
"mean",
"=",
"$",
"mean",
"??",
"self",
"::",
"mean",
"(",
"$",
"values",
",",
"$",
"n",
")",
";",
"$",
"sigma",
"=",
"0.",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"sigma",
"+=",
"(",
"$",
"value",
"-",
"$",
"mean",
")",
"**",
"$",
"moment",
";",
"}",
"return",
"$",
"sigma",
"/",
"$",
"n",
";",
"}"
] | Compute the n-th central moment of a set of values.
@param array $values
@param int $moment
@param float|null $mean
@param int|null $n
@throws \InvalidArgumentException
@return float | [
"Compute",
"the",
"n",
"-",
"th",
"central",
"moment",
"of",
"a",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L261-L279 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.skewness | public static function skewness(array $values, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n === 0) {
throw new InvalidArgumentException('Skewness is undefined for'
. ' empty set.');
}
$mean = $mean ?? self::mean($values, $n);
$numerator = self::centralMoment($values, 3, $mean);
$denominator = self::centralMoment($values, 2, $mean) ** 1.5;
return $numerator / ($denominator ?: EPSILON);
} | php | public static function skewness(array $values, ?float $mean = null, ?int $n = null) : float
{
$n = $n ?? count($values);
if ($n === 0) {
throw new InvalidArgumentException('Skewness is undefined for'
. ' empty set.');
}
$mean = $mean ?? self::mean($values, $n);
$numerator = self::centralMoment($values, 3, $mean);
$denominator = self::centralMoment($values, 2, $mean) ** 1.5;
return $numerator / ($denominator ?: EPSILON);
} | [
"public",
"static",
"function",
"skewness",
"(",
"array",
"$",
"values",
",",
"?",
"float",
"$",
"mean",
"=",
"null",
",",
"?",
"int",
"$",
"n",
"=",
"null",
")",
":",
"float",
"{",
"$",
"n",
"=",
"$",
"n",
"??",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"n",
"===",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Skewness is undefined for'",
".",
"' empty set.'",
")",
";",
"}",
"$",
"mean",
"=",
"$",
"mean",
"??",
"self",
"::",
"mean",
"(",
"$",
"values",
",",
"$",
"n",
")",
";",
"$",
"numerator",
"=",
"self",
"::",
"centralMoment",
"(",
"$",
"values",
",",
"3",
",",
"$",
"mean",
")",
";",
"$",
"denominator",
"=",
"self",
"::",
"centralMoment",
"(",
"$",
"values",
",",
"2",
",",
"$",
"mean",
")",
"**",
"1.5",
";",
"return",
"$",
"numerator",
"/",
"(",
"$",
"denominator",
"?",
":",
"EPSILON",
")",
";",
"}"
] | Compute the skewness of a set of values given a mean and n degrees of
freedom.
@param array $values
@param float|null $mean
@param int|null $n
@throws \InvalidArgumentException
@return float | [
"Compute",
"the",
"skewness",
"of",
"a",
"set",
"of",
"values",
"given",
"a",
"mean",
"and",
"n",
"degrees",
"of",
"freedom",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L291-L306 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.range | public static function range(array $values) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Range is undefined for empty'
. ' set.');
}
return (float) (max($values) - min($values));
} | php | public static function range(array $values) : float
{
if (empty($values)) {
throw new InvalidArgumentException('Range is undefined for empty'
. ' set.');
}
return (float) (max($values) - min($values));
} | [
"public",
"static",
"function",
"range",
"(",
"array",
"$",
"values",
")",
":",
"float",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Range is undefined for empty'",
".",
"' set.'",
")",
";",
"}",
"return",
"(",
"float",
")",
"(",
"max",
"(",
"$",
"values",
")",
"-",
"min",
"(",
"$",
"values",
")",
")",
";",
"}"
] | Return the statistical range given by the maximum minus the minimum
of a set of values.
@param array $values
@throws \InvalidArgumentException
@return float | [
"Return",
"the",
"statistical",
"range",
"given",
"by",
"the",
"maximum",
"minus",
"the",
"minimum",
"of",
"a",
"set",
"of",
"values",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L342-L350 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.meanVar | public static function meanVar(array $values) : array
{
$mean = self::mean($values);
return [$mean, self::variance($values, $mean)];
} | php | public static function meanVar(array $values) : array
{
$mean = self::mean($values);
return [$mean, self::variance($values, $mean)];
} | [
"public",
"static",
"function",
"meanVar",
"(",
"array",
"$",
"values",
")",
":",
"array",
"{",
"$",
"mean",
"=",
"self",
"::",
"mean",
"(",
"$",
"values",
")",
";",
"return",
"[",
"$",
"mean",
",",
"self",
"::",
"variance",
"(",
"$",
"values",
",",
"$",
"mean",
")",
"]",
";",
"}"
] | Compute the population mean and variance and return them in a 2-tuple.
@param array $values
@return array | [
"Compute",
"the",
"population",
"mean",
"and",
"variance",
"and",
"return",
"them",
"in",
"a",
"2",
"-",
"tuple",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L358-L363 | train |
RubixML/RubixML | src/Other/Helpers/Stats.php | Stats.medMad | public static function medMad(array $values) : array
{
$median = self::median($values);
return [$median, self::mad($values, $median)];
} | php | public static function medMad(array $values) : array
{
$median = self::median($values);
return [$median, self::mad($values, $median)];
} | [
"public",
"static",
"function",
"medMad",
"(",
"array",
"$",
"values",
")",
":",
"array",
"{",
"$",
"median",
"=",
"self",
"::",
"median",
"(",
"$",
"values",
")",
";",
"return",
"[",
"$",
"median",
",",
"self",
"::",
"mad",
"(",
"$",
"values",
",",
"$",
"median",
")",
"]",
";",
"}"
] | Compute the population median and median absolute deviation and return
them in a 2-tuple.
@param array $values
@return array | [
"Compute",
"the",
"population",
"median",
"and",
"median",
"absolute",
"deviation",
"and",
"return",
"them",
"in",
"a",
"2",
"-",
"tuple",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/Stats.php#L372-L377 | train |
RubixML/RubixML | src/NeuralNet/CostFunctions/CrossEntropy.php | CrossEntropy.compute | public function compute(Tensor $expected, Tensor $output) : float
{
return $expected->negate()->multiply($output->log())->sum()->mean();
} | php | public function compute(Tensor $expected, Tensor $output) : float
{
return $expected->negate()->multiply($output->log())->sum()->mean();
} | [
"public",
"function",
"compute",
"(",
"Tensor",
"$",
"expected",
",",
"Tensor",
"$",
"output",
")",
":",
"float",
"{",
"return",
"$",
"expected",
"->",
"negate",
"(",
")",
"->",
"multiply",
"(",
"$",
"output",
"->",
"log",
"(",
")",
")",
"->",
"sum",
"(",
")",
"->",
"mean",
"(",
")",
";",
"}"
] | Compute the matrix.
@param \Rubix\Tensor\Tensor $expected
@param \Rubix\Tensor\Tensor $output
@return float | [
"Compute",
"the",
"matrix",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/CostFunctions/CrossEntropy.php#L42-L45 | train |
RubixML/RubixML | src/Graph/CART.php | CART.search | public function search(array $sample) : ?BinaryNode
{
$current = $this->root;
while ($current) {
if ($current instanceof Decision) {
$value = $current->value();
if (is_string($value)) {
if ($sample[$current->column()] === $value) {
$current = $current->left();
} else {
$current = $current->right();
}
} else {
if ($sample[$current->column()] < $value) {
$current = $current->left();
} else {
$current = $current->right();
}
}
continue 1;
}
if ($current instanceof Leaf) {
break 1;
}
}
return $current;
} | php | public function search(array $sample) : ?BinaryNode
{
$current = $this->root;
while ($current) {
if ($current instanceof Decision) {
$value = $current->value();
if (is_string($value)) {
if ($sample[$current->column()] === $value) {
$current = $current->left();
} else {
$current = $current->right();
}
} else {
if ($sample[$current->column()] < $value) {
$current = $current->left();
} else {
$current = $current->right();
}
}
continue 1;
}
if ($current instanceof Leaf) {
break 1;
}
}
return $current;
} | [
"public",
"function",
"search",
"(",
"array",
"$",
"sample",
")",
":",
"?",
"BinaryNode",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"root",
";",
"while",
"(",
"$",
"current",
")",
"{",
"if",
"(",
"$",
"current",
"instanceof",
"Decision",
")",
"{",
"$",
"value",
"=",
"$",
"current",
"->",
"value",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"sample",
"[",
"$",
"current",
"->",
"column",
"(",
")",
"]",
"===",
"$",
"value",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"left",
"(",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"sample",
"[",
"$",
"current",
"->",
"column",
"(",
")",
"]",
"<",
"$",
"value",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"left",
"(",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"}",
"continue",
"1",
";",
"}",
"if",
"(",
"$",
"current",
"instanceof",
"Leaf",
")",
"{",
"break",
"1",
";",
"}",
"}",
"return",
"$",
"current",
";",
"}"
] | Search the tree for a leaf node.
@param array $sample
@return \Rubix\ML\Graph\Nodes\BinaryNode|null | [
"Search",
"the",
"tree",
"for",
"a",
"leaf",
"node",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/CART.php#L227-L258 | train |
RubixML/RubixML | src/Graph/CART.php | CART.featureImportances | public function featureImportances() : array
{
if (!$this->root) {
return [];
}
$importances = array_fill(0, $this->featureCount, 0.);
foreach ($this->dump() as $node) {
if ($node instanceof Decision) {
$index = $node->column();
$importances[$index] += $node->purityIncrease();
}
}
$total = array_sum($importances) ?: self::BETA;
foreach ($importances as &$importance) {
$importance /= $total;
}
arsort($importances);
return $importances;
} | php | public function featureImportances() : array
{
if (!$this->root) {
return [];
}
$importances = array_fill(0, $this->featureCount, 0.);
foreach ($this->dump() as $node) {
if ($node instanceof Decision) {
$index = $node->column();
$importances[$index] += $node->purityIncrease();
}
}
$total = array_sum($importances) ?: self::BETA;
foreach ($importances as &$importance) {
$importance /= $total;
}
arsort($importances);
return $importances;
} | [
"public",
"function",
"featureImportances",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"root",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"importances",
"=",
"array_fill",
"(",
"0",
",",
"$",
"this",
"->",
"featureCount",
",",
"0.",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dump",
"(",
")",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Decision",
")",
"{",
"$",
"index",
"=",
"$",
"node",
"->",
"column",
"(",
")",
";",
"$",
"importances",
"[",
"$",
"index",
"]",
"+=",
"$",
"node",
"->",
"purityIncrease",
"(",
")",
";",
"}",
"}",
"$",
"total",
"=",
"array_sum",
"(",
"$",
"importances",
")",
"?",
":",
"self",
"::",
"BETA",
";",
"foreach",
"(",
"$",
"importances",
"as",
"&",
"$",
"importance",
")",
"{",
"$",
"importance",
"/=",
"$",
"total",
";",
"}",
"arsort",
"(",
"$",
"importances",
")",
";",
"return",
"$",
"importances",
";",
"}"
] | Return an array indexed by feature column that contains the normalized
importance score of that feature.
@return array | [
"Return",
"an",
"array",
"indexed",
"by",
"feature",
"column",
"that",
"contains",
"the",
"normalized",
"importance",
"score",
"of",
"that",
"feature",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/CART.php#L266-L291 | train |
RubixML/RubixML | src/Graph/CART.php | CART.dump | public function dump() : Generator
{
$nodes = [];
$stack = [$this->root];
while ($stack) {
$current = array_pop($stack);
if ($current instanceof BinaryNode) {
foreach ($current->children() as $child) {
$stack[] = $child;
}
}
yield $current;
}
} | php | public function dump() : Generator
{
$nodes = [];
$stack = [$this->root];
while ($stack) {
$current = array_pop($stack);
if ($current instanceof BinaryNode) {
foreach ($current->children() as $child) {
$stack[] = $child;
}
}
yield $current;
}
} | [
"public",
"function",
"dump",
"(",
")",
":",
"Generator",
"{",
"$",
"nodes",
"=",
"[",
"]",
";",
"$",
"stack",
"=",
"[",
"$",
"this",
"->",
"root",
"]",
";",
"while",
"(",
"$",
"stack",
")",
"{",
"$",
"current",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"if",
"(",
"$",
"current",
"instanceof",
"BinaryNode",
")",
"{",
"foreach",
"(",
"$",
"current",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"stack",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"yield",
"$",
"current",
";",
"}",
"}"
] | Return a generator for all the nodes in the tree starting at the root.
@return \Generator | [
"Return",
"a",
"generator",
"for",
"all",
"the",
"nodes",
"in",
"the",
"tree",
"starting",
"at",
"the",
"root",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/CART.php#L298-L315 | train |
RubixML/RubixML | src/Graph/Nodes/Cell.php | Cell.c | protected static function c(int $n) : float
{
if ($n <= 1) {
return 1.;
}
return 2. * (log($n - 1) + M_EULER) - 2. * ($n - 1) / $n;
} | php | protected static function c(int $n) : float
{
if ($n <= 1) {
return 1.;
}
return 2. * (log($n - 1) + M_EULER) - 2. * ($n - 1) / $n;
} | [
"protected",
"static",
"function",
"c",
"(",
"int",
"$",
"n",
")",
":",
"float",
"{",
"if",
"(",
"$",
"n",
"<=",
"1",
")",
"{",
"return",
"1.",
";",
"}",
"return",
"2.",
"*",
"(",
"log",
"(",
"$",
"n",
"-",
"1",
")",
"+",
"M_EULER",
")",
"-",
"2.",
"*",
"(",
"$",
"n",
"-",
"1",
")",
"/",
"$",
"n",
";",
"}"
] | Calculate the average path length of an unsuccessful search for n nodes.
@param int $n
@return float | [
"Calculate",
"the",
"average",
"path",
"length",
"of",
"an",
"unsuccessful",
"search",
"for",
"n",
"nodes",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/Nodes/Cell.php#L46-L53 | train |
RubixML/RubixML | src/NeuralNet/Parameters/MatrixParam.php | MatrixParam.update | public function update(Tensor $step) : void
{
$this->w = $this->w()->subtract($step);
} | php | public function update(Tensor $step) : void
{
$this->w = $this->w()->subtract($step);
} | [
"public",
"function",
"update",
"(",
"Tensor",
"$",
"step",
")",
":",
"void",
"{",
"$",
"this",
"->",
"w",
"=",
"$",
"this",
"->",
"w",
"(",
")",
"->",
"subtract",
"(",
"$",
"step",
")",
";",
"}"
] | Update the parameter.
@param \Rubix\Tensor\Tensor $step | [
"Update",
"the",
"parameter",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/Parameters/MatrixParam.php#L53-L56 | train |
RubixML/RubixML | src/Regressors/RegressionTree.php | RegressionTree.train | public function train(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This estimator requires a'
. ' labeled training set.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$k = $dataset->numColumns();
$this->columns = range(0, $dataset->numColumns() - 1);
$this->maxFeatures = $this->maxFeatures ?? (int) round(sqrt($k));
$this->grow($dataset);
$this->columns = [];
} | php | public function train(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This estimator requires a'
. ' labeled training set.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$k = $dataset->numColumns();
$this->columns = range(0, $dataset->numColumns() - 1);
$this->maxFeatures = $this->maxFeatures ?? (int) round(sqrt($k));
$this->grow($dataset);
$this->columns = [];
} | [
"public",
"function",
"train",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"dataset",
"instanceof",
"Labeled",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This estimator requires a'",
".",
"' labeled training set.'",
")",
";",
"}",
"DatasetIsCompatibleWithEstimator",
"::",
"check",
"(",
"$",
"dataset",
",",
"$",
"this",
")",
";",
"$",
"k",
"=",
"$",
"dataset",
"->",
"numColumns",
"(",
")",
";",
"$",
"this",
"->",
"columns",
"=",
"range",
"(",
"0",
",",
"$",
"dataset",
"->",
"numColumns",
"(",
")",
"-",
"1",
")",
";",
"$",
"this",
"->",
"maxFeatures",
"=",
"$",
"this",
"->",
"maxFeatures",
"??",
"(",
"int",
")",
"round",
"(",
"sqrt",
"(",
"$",
"k",
")",
")",
";",
"$",
"this",
"->",
"grow",
"(",
"$",
"dataset",
")",
";",
"$",
"this",
"->",
"columns",
"=",
"[",
"]",
";",
"}"
] | Train the regression tree by learning the optimal splits in the
training set.
@param \Rubix\ML\Datasets\Dataset $dataset
@throws \InvalidArgumentException | [
"Train",
"the",
"regression",
"tree",
"by",
"learning",
"the",
"optimal",
"splits",
"in",
"the",
"training",
"set",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Regressors/RegressionTree.php#L129-L146 | train |
RubixML/RubixML | src/Regressors/RegressionTree.php | RegressionTree.predict | public function predict(Dataset $dataset) : array
{
if ($this->bare()) {
throw new RuntimeException('Estimator has not been trained.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$predictions = [];
foreach ($dataset as $sample) {
$node = $this->search($sample);
$predictions[] = $node instanceof Average
? $node->outcome()
: null;
}
return $predictions;
} | php | public function predict(Dataset $dataset) : array
{
if ($this->bare()) {
throw new RuntimeException('Estimator has not been trained.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$predictions = [];
foreach ($dataset as $sample) {
$node = $this->search($sample);
$predictions[] = $node instanceof Average
? $node->outcome()
: null;
}
return $predictions;
} | [
"public",
"function",
"predict",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"bare",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Estimator has not been trained.'",
")",
";",
"}",
"DatasetIsCompatibleWithEstimator",
"::",
"check",
"(",
"$",
"dataset",
",",
"$",
"this",
")",
";",
"$",
"predictions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dataset",
"as",
"$",
"sample",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"search",
"(",
"$",
"sample",
")",
";",
"$",
"predictions",
"[",
"]",
"=",
"$",
"node",
"instanceof",
"Average",
"?",
"$",
"node",
"->",
"outcome",
"(",
")",
":",
"null",
";",
"}",
"return",
"$",
"predictions",
";",
"}"
] | Make a prediction based on the value of a terminal node in the tree.
@param \Rubix\ML\Datasets\Dataset $dataset
@throws \RuntimeException
@return array | [
"Make",
"a",
"prediction",
"based",
"on",
"the",
"value",
"of",
"a",
"terminal",
"node",
"in",
"the",
"tree",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Regressors/RegressionTree.php#L155-L174 | train |
RubixML/RubixML | src/Regressors/RegressionTree.php | RegressionTree.split | protected function split(Labeled $dataset) : Decision
{
$bestVariance = INF;
$bestColumn = $bestValue = null;
$bestGroups = [];
shuffle($this->columns);
foreach (array_slice($this->columns, 0, $this->maxFeatures) as $column) {
$values = array_unique($dataset->column($column));
foreach ($values as $value) {
$groups = $dataset->partition($column, $value);
$variance = $this->splitImpurity($groups);
if ($variance < $bestVariance) {
$bestColumn = $column;
$bestValue = $value;
$bestGroups = $groups;
$bestVariance = $variance;
}
if ($variance <= $this->tolerance) {
break 2;
}
}
}
return new Decision($bestColumn, $bestValue, $bestGroups, $bestVariance);
} | php | protected function split(Labeled $dataset) : Decision
{
$bestVariance = INF;
$bestColumn = $bestValue = null;
$bestGroups = [];
shuffle($this->columns);
foreach (array_slice($this->columns, 0, $this->maxFeatures) as $column) {
$values = array_unique($dataset->column($column));
foreach ($values as $value) {
$groups = $dataset->partition($column, $value);
$variance = $this->splitImpurity($groups);
if ($variance < $bestVariance) {
$bestColumn = $column;
$bestValue = $value;
$bestGroups = $groups;
$bestVariance = $variance;
}
if ($variance <= $this->tolerance) {
break 2;
}
}
}
return new Decision($bestColumn, $bestValue, $bestGroups, $bestVariance);
} | [
"protected",
"function",
"split",
"(",
"Labeled",
"$",
"dataset",
")",
":",
"Decision",
"{",
"$",
"bestVariance",
"=",
"INF",
";",
"$",
"bestColumn",
"=",
"$",
"bestValue",
"=",
"null",
";",
"$",
"bestGroups",
"=",
"[",
"]",
";",
"shuffle",
"(",
"$",
"this",
"->",
"columns",
")",
";",
"foreach",
"(",
"array_slice",
"(",
"$",
"this",
"->",
"columns",
",",
"0",
",",
"$",
"this",
"->",
"maxFeatures",
")",
"as",
"$",
"column",
")",
"{",
"$",
"values",
"=",
"array_unique",
"(",
"$",
"dataset",
"->",
"column",
"(",
"$",
"column",
")",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"groups",
"=",
"$",
"dataset",
"->",
"partition",
"(",
"$",
"column",
",",
"$",
"value",
")",
";",
"$",
"variance",
"=",
"$",
"this",
"->",
"splitImpurity",
"(",
"$",
"groups",
")",
";",
"if",
"(",
"$",
"variance",
"<",
"$",
"bestVariance",
")",
"{",
"$",
"bestColumn",
"=",
"$",
"column",
";",
"$",
"bestValue",
"=",
"$",
"value",
";",
"$",
"bestGroups",
"=",
"$",
"groups",
";",
"$",
"bestVariance",
"=",
"$",
"variance",
";",
"}",
"if",
"(",
"$",
"variance",
"<=",
"$",
"this",
"->",
"tolerance",
")",
"{",
"break",
"2",
";",
"}",
"}",
"}",
"return",
"new",
"Decision",
"(",
"$",
"bestColumn",
",",
"$",
"bestValue",
",",
"$",
"bestGroups",
",",
"$",
"bestVariance",
")",
";",
"}"
] | Greedy algorithm to chose the best split for a given dataset as
determined by the variance of the split.
@param \Rubix\ML\Datasets\Labeled $dataset
@return \Rubix\ML\Graph\Nodes\Decision | [
"Greedy",
"algorithm",
"to",
"chose",
"the",
"best",
"split",
"for",
"a",
"given",
"dataset",
"as",
"determined",
"by",
"the",
"variance",
"of",
"the",
"split",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Regressors/RegressionTree.php#L183-L213 | train |
RubixML/RubixML | src/Regressors/RegressionTree.php | RegressionTree.terminate | protected function terminate(Labeled $dataset) : BinaryNode
{
[$mean, $variance] = Stats::meanVar($dataset->labels());
return new Average($mean, $variance, $dataset->numRows());
} | php | protected function terminate(Labeled $dataset) : BinaryNode
{
[$mean, $variance] = Stats::meanVar($dataset->labels());
return new Average($mean, $variance, $dataset->numRows());
} | [
"protected",
"function",
"terminate",
"(",
"Labeled",
"$",
"dataset",
")",
":",
"BinaryNode",
"{",
"[",
"$",
"mean",
",",
"$",
"variance",
"]",
"=",
"Stats",
"::",
"meanVar",
"(",
"$",
"dataset",
"->",
"labels",
"(",
")",
")",
";",
"return",
"new",
"Average",
"(",
"$",
"mean",
",",
"$",
"variance",
",",
"$",
"dataset",
"->",
"numRows",
"(",
")",
")",
";",
"}"
] | Terminate the branch with the most likely outcome.
@param \Rubix\ML\Datasets\Labeled $dataset
@return \Rubix\ML\Graph\Nodes\BinaryNode | [
"Terminate",
"the",
"branch",
"with",
"the",
"most",
"likely",
"outcome",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Regressors/RegressionTree.php#L221-L226 | train |
RubixML/RubixML | src/Regressors/RegressionTree.php | RegressionTree.splitImpurity | protected function splitImpurity(array $groups) : float
{
$n = array_sum(array_map('count', $groups));
$impurity = 0.;
foreach ($groups as $dataset) {
$k = $dataset->numRows();
if ($k < 2) {
continue 1;
}
$variance = Stats::variance($dataset->labels());
$impurity += ($k / $n) * $variance;
}
return $impurity;
} | php | protected function splitImpurity(array $groups) : float
{
$n = array_sum(array_map('count', $groups));
$impurity = 0.;
foreach ($groups as $dataset) {
$k = $dataset->numRows();
if ($k < 2) {
continue 1;
}
$variance = Stats::variance($dataset->labels());
$impurity += ($k / $n) * $variance;
}
return $impurity;
} | [
"protected",
"function",
"splitImpurity",
"(",
"array",
"$",
"groups",
")",
":",
"float",
"{",
"$",
"n",
"=",
"array_sum",
"(",
"array_map",
"(",
"'count'",
",",
"$",
"groups",
")",
")",
";",
"$",
"impurity",
"=",
"0.",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"dataset",
")",
"{",
"$",
"k",
"=",
"$",
"dataset",
"->",
"numRows",
"(",
")",
";",
"if",
"(",
"$",
"k",
"<",
"2",
")",
"{",
"continue",
"1",
";",
"}",
"$",
"variance",
"=",
"Stats",
"::",
"variance",
"(",
"$",
"dataset",
"->",
"labels",
"(",
")",
")",
";",
"$",
"impurity",
"+=",
"(",
"$",
"k",
"/",
"$",
"n",
")",
"*",
"$",
"variance",
";",
"}",
"return",
"$",
"impurity",
";",
"}"
] | Calculate the weighted variance for the split.
@param array $groups
@return float | [
"Calculate",
"the",
"weighted",
"variance",
"for",
"the",
"split",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Regressors/RegressionTree.php#L234-L253 | train |
RubixML/RubixML | src/Classifiers/RandomForest.php | RandomForest.featureImportances | public function featureImportances() : array
{
if (!$this->forest or !$this->featureCount) {
return [];
}
$importances = array_fill(0, $this->featureCount, 0.);
foreach ($this->forest as $tree) {
foreach ($tree->featureImportances() as $column => $value) {
$importances[$column] += $value;
}
}
$k = count($this->forest);
foreach ($importances as &$importance) {
$importance /= $k;
}
return $importances;
} | php | public function featureImportances() : array
{
if (!$this->forest or !$this->featureCount) {
return [];
}
$importances = array_fill(0, $this->featureCount, 0.);
foreach ($this->forest as $tree) {
foreach ($tree->featureImportances() as $column => $value) {
$importances[$column] += $value;
}
}
$k = count($this->forest);
foreach ($importances as &$importance) {
$importance /= $k;
}
return $importances;
} | [
"public",
"function",
"featureImportances",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"forest",
"or",
"!",
"$",
"this",
"->",
"featureCount",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"importances",
"=",
"array_fill",
"(",
"0",
",",
"$",
"this",
"->",
"featureCount",
",",
"0.",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"forest",
"as",
"$",
"tree",
")",
"{",
"foreach",
"(",
"$",
"tree",
"->",
"featureImportances",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"importances",
"[",
"$",
"column",
"]",
"+=",
"$",
"value",
";",
"}",
"}",
"$",
"k",
"=",
"count",
"(",
"$",
"this",
"->",
"forest",
")",
";",
"foreach",
"(",
"$",
"importances",
"as",
"&",
"$",
"importance",
")",
"{",
"$",
"importance",
"/=",
"$",
"k",
";",
"}",
"return",
"$",
"importances",
";",
"}"
] | Return the feature importances calculated during training keyed by
feature column.
@throws \RuntimeException
@return array | [
"Return",
"the",
"feature",
"importances",
"calculated",
"during",
"training",
"keyed",
"by",
"feature",
"column",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Classifiers/RandomForest.php#L258-L279 | train |
RubixML/RubixML | src/Other/Strategies/BlurryPercentile.php | BlurryPercentile.gaussian | public static function gaussian() : float
{
$r1 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
$r2 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
return sqrt(-2. * log($r1)) * cos(TWO_PI * $r2);
} | php | public static function gaussian() : float
{
$r1 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
$r2 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
return sqrt(-2. * log($r1)) * cos(TWO_PI * $r2);
} | [
"public",
"static",
"function",
"gaussian",
"(",
")",
":",
"float",
"{",
"$",
"r1",
"=",
"rand",
"(",
"0",
",",
"PHP_INT_MAX",
")",
"/",
"PHP_INT_MAX",
";",
"$",
"r2",
"=",
"rand",
"(",
"0",
",",
"PHP_INT_MAX",
")",
"/",
"PHP_INT_MAX",
";",
"return",
"sqrt",
"(",
"-",
"2.",
"*",
"log",
"(",
"$",
"r1",
")",
")",
"*",
"cos",
"(",
"TWO_PI",
"*",
"$",
"r2",
")",
";",
"}"
] | Generate a random number from a Gaussian distribution with 0 mean and
standard deviation of 1.
@return float | [
"Generate",
"a",
"random",
"number",
"from",
"a",
"Gaussian",
"distribution",
"with",
"0",
"mean",
"and",
"standard",
"deviation",
"of",
"1",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Strategies/BlurryPercentile.php#L115-L121 | train |
RubixML/RubixML | src/NeuralNet/Optimizers/Adam.php | Adam.warm | public function warm(Parameter $param) : void
{
$velocity = get_class($param->w())::zeros(...$param->w()->shape());
$g2 = clone $velocity;
$this->cache[$param->id()] = [$velocity, $g2];
} | php | public function warm(Parameter $param) : void
{
$velocity = get_class($param->w())::zeros(...$param->w()->shape());
$g2 = clone $velocity;
$this->cache[$param->id()] = [$velocity, $g2];
} | [
"public",
"function",
"warm",
"(",
"Parameter",
"$",
"param",
")",
":",
"void",
"{",
"$",
"velocity",
"=",
"get_class",
"(",
"$",
"param",
"->",
"w",
"(",
")",
")",
"::",
"zeros",
"(",
"...",
"$",
"param",
"->",
"w",
"(",
")",
"->",
"shape",
"(",
")",
")",
";",
"$",
"g2",
"=",
"clone",
"$",
"velocity",
";",
"$",
"this",
"->",
"cache",
"[",
"$",
"param",
"->",
"id",
"(",
")",
"]",
"=",
"[",
"$",
"velocity",
",",
"$",
"g2",
"]",
";",
"}"
] | Warm the cache with a parameter.
@param \Rubix\ML\NeuralNet\Parameters\Parameter $param | [
"Warm",
"the",
"cache",
"with",
"a",
"parameter",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/Optimizers/Adam.php#L103-L109 | train |
RubixML/RubixML | src/NeuralNet/Optimizers/Adam.php | Adam.step | public function step(Parameter $param, Tensor $gradient) : void
{
[$velocity, $g2] = $this->cache[$param->id()];
$velocity = $velocity->multiply($this->momentumDecay)
->add($gradient->multiply(1. - $this->momentumDecay));
$g2 = $g2->multiply($this->rmsDecay)
->add($gradient->square()->multiply(1. - $this->rmsDecay));
$this->cache[$param->id()] = [$velocity, $g2];
if ($this->t < self::WARM_UP_STEPS) {
$this->t++;
$velocity = $velocity->divide(1. - $this->momentumDecay ** $this->t);
$g2 = $g2->divide(1. - $this->rmsDecay ** $this->t);
}
$step = $velocity->multiply($this->rate)
->divide($g2->sqrt()->clipLower(EPSILON));
$param->update($step);
} | php | public function step(Parameter $param, Tensor $gradient) : void
{
[$velocity, $g2] = $this->cache[$param->id()];
$velocity = $velocity->multiply($this->momentumDecay)
->add($gradient->multiply(1. - $this->momentumDecay));
$g2 = $g2->multiply($this->rmsDecay)
->add($gradient->square()->multiply(1. - $this->rmsDecay));
$this->cache[$param->id()] = [$velocity, $g2];
if ($this->t < self::WARM_UP_STEPS) {
$this->t++;
$velocity = $velocity->divide(1. - $this->momentumDecay ** $this->t);
$g2 = $g2->divide(1. - $this->rmsDecay ** $this->t);
}
$step = $velocity->multiply($this->rate)
->divide($g2->sqrt()->clipLower(EPSILON));
$param->update($step);
} | [
"public",
"function",
"step",
"(",
"Parameter",
"$",
"param",
",",
"Tensor",
"$",
"gradient",
")",
":",
"void",
"{",
"[",
"$",
"velocity",
",",
"$",
"g2",
"]",
"=",
"$",
"this",
"->",
"cache",
"[",
"$",
"param",
"->",
"id",
"(",
")",
"]",
";",
"$",
"velocity",
"=",
"$",
"velocity",
"->",
"multiply",
"(",
"$",
"this",
"->",
"momentumDecay",
")",
"->",
"add",
"(",
"$",
"gradient",
"->",
"multiply",
"(",
"1.",
"-",
"$",
"this",
"->",
"momentumDecay",
")",
")",
";",
"$",
"g2",
"=",
"$",
"g2",
"->",
"multiply",
"(",
"$",
"this",
"->",
"rmsDecay",
")",
"->",
"add",
"(",
"$",
"gradient",
"->",
"square",
"(",
")",
"->",
"multiply",
"(",
"1.",
"-",
"$",
"this",
"->",
"rmsDecay",
")",
")",
";",
"$",
"this",
"->",
"cache",
"[",
"$",
"param",
"->",
"id",
"(",
")",
"]",
"=",
"[",
"$",
"velocity",
",",
"$",
"g2",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"t",
"<",
"self",
"::",
"WARM_UP_STEPS",
")",
"{",
"$",
"this",
"->",
"t",
"++",
";",
"$",
"velocity",
"=",
"$",
"velocity",
"->",
"divide",
"(",
"1.",
"-",
"$",
"this",
"->",
"momentumDecay",
"**",
"$",
"this",
"->",
"t",
")",
";",
"$",
"g2",
"=",
"$",
"g2",
"->",
"divide",
"(",
"1.",
"-",
"$",
"this",
"->",
"rmsDecay",
"**",
"$",
"this",
"->",
"t",
")",
";",
"}",
"$",
"step",
"=",
"$",
"velocity",
"->",
"multiply",
"(",
"$",
"this",
"->",
"rate",
")",
"->",
"divide",
"(",
"$",
"g2",
"->",
"sqrt",
"(",
")",
"->",
"clipLower",
"(",
"EPSILON",
")",
")",
";",
"$",
"param",
"->",
"update",
"(",
"$",
"step",
")",
";",
"}"
] | Calculate a gradient descent step for a given parameter.
@param \Rubix\ML\NeuralNet\Parameters\Parameter $param
@param \Rubix\Tensor\Tensor $gradient | [
"Calculate",
"a",
"gradient",
"descent",
"step",
"for",
"a",
"given",
"parameter",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/Optimizers/Adam.php#L117-L141 | train |
RubixML/RubixML | src/NeuralNet/ActivationFunctions/Softmax.php | Softmax.compute | public function compute(Matrix $z) : Matrix
{
$zHat = $z->transpose()->exp();
$total = $zHat->sum();
return $zHat->divide($total)->transpose();
} | php | public function compute(Matrix $z) : Matrix
{
$zHat = $z->transpose()->exp();
$total = $zHat->sum();
return $zHat->divide($total)->transpose();
} | [
"public",
"function",
"compute",
"(",
"Matrix",
"$",
"z",
")",
":",
"Matrix",
"{",
"$",
"zHat",
"=",
"$",
"z",
"->",
"transpose",
"(",
")",
"->",
"exp",
"(",
")",
";",
"$",
"total",
"=",
"$",
"zHat",
"->",
"sum",
"(",
")",
";",
"return",
"$",
"zHat",
"->",
"divide",
"(",
"$",
"total",
")",
"->",
"transpose",
"(",
")",
";",
"}"
] | Compute the output value.
@param \Rubix\Tensor\Matrix $z
@return \Rubix\Tensor\Matrix | [
"Compute",
"the",
"output",
"value",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/ActivationFunctions/Softmax.php#L25-L32 | train |
RubixML/RubixML | src/CrossValidation/Metrics/FBeta.php | FBeta.precision | public static function precision(int $tp, int $fp) : float
{
return $tp / (($tp + $fp) ?: EPSILON);
} | php | public static function precision(int $tp, int $fp) : float
{
return $tp / (($tp + $fp) ?: EPSILON);
} | [
"public",
"static",
"function",
"precision",
"(",
"int",
"$",
"tp",
",",
"int",
"$",
"fp",
")",
":",
"float",
"{",
"return",
"$",
"tp",
"/",
"(",
"(",
"$",
"tp",
"+",
"$",
"fp",
")",
"?",
":",
"EPSILON",
")",
";",
"}"
] | Compute the class precision.
@param int $tp
@param int $fp
@return float | [
"Compute",
"the",
"class",
"precision",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/CrossValidation/Metrics/FBeta.php#L41-L44 | train |
RubixML/RubixML | src/CrossValidation/Metrics/FBeta.php | FBeta.recall | public static function recall(int $tp, int $fn) : float
{
return $tp / (($tp + $fn) ?: EPSILON);
} | php | public static function recall(int $tp, int $fn) : float
{
return $tp / (($tp + $fn) ?: EPSILON);
} | [
"public",
"static",
"function",
"recall",
"(",
"int",
"$",
"tp",
",",
"int",
"$",
"fn",
")",
":",
"float",
"{",
"return",
"$",
"tp",
"/",
"(",
"(",
"$",
"tp",
"+",
"$",
"fn",
")",
"?",
":",
"EPSILON",
")",
";",
"}"
] | Compute the class recall.
@param int $tp
@param int $fn
@return float | [
"Compute",
"the",
"class",
"recall",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/CrossValidation/Metrics/FBeta.php#L53-L56 | train |
RubixML/RubixML | src/Persisters/Filesystem.php | Filesystem.save | public function save(Persistable $persistable) : void
{
if ($this->history and is_file($this->path)) {
$filename = $this->path . '.' . (string) time() . self::HISTORY_EXT;
if (!rename($this->path, $filename)) {
throw new RuntimeException('Failed to rename history,'
. ' file, check path and permissions.');
}
}
if (is_file($this->path) and !is_writable($this->path)) {
throw new RuntimeException("File $this->path is not writable.");
}
$data = $this->serializer->serialize($persistable);
if (!file_put_contents($this->path, $data, LOCK_EX)) {
throw new RuntimeException('Failed to save persistable to'
. ' filesystem, check path and permissions.');
}
} | php | public function save(Persistable $persistable) : void
{
if ($this->history and is_file($this->path)) {
$filename = $this->path . '.' . (string) time() . self::HISTORY_EXT;
if (!rename($this->path, $filename)) {
throw new RuntimeException('Failed to rename history,'
. ' file, check path and permissions.');
}
}
if (is_file($this->path) and !is_writable($this->path)) {
throw new RuntimeException("File $this->path is not writable.");
}
$data = $this->serializer->serialize($persistable);
if (!file_put_contents($this->path, $data, LOCK_EX)) {
throw new RuntimeException('Failed to save persistable to'
. ' filesystem, check path and permissions.');
}
} | [
"public",
"function",
"save",
"(",
"Persistable",
"$",
"persistable",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"history",
"and",
"is_file",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"path",
".",
"'.'",
".",
"(",
"string",
")",
"time",
"(",
")",
".",
"self",
"::",
"HISTORY_EXT",
";",
"if",
"(",
"!",
"rename",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Failed to rename history,'",
".",
"' file, check path and permissions.'",
")",
";",
"}",
"}",
"if",
"(",
"is_file",
"(",
"$",
"this",
"->",
"path",
")",
"and",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"File $this->path is not writable.\"",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"persistable",
")",
";",
"if",
"(",
"!",
"file_put_contents",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"data",
",",
"LOCK_EX",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Failed to save persistable to'",
".",
"' filesystem, check path and permissions.'",
")",
";",
"}",
"}"
] | Save the persitable model.
@param \Rubix\ML\Persistable $persistable
@throws \RuntimeException | [
"Save",
"the",
"persitable",
"model",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Persisters/Filesystem.php#L71-L92 | train |
RubixML/RubixML | src/Graph/ITree.php | ITree.search | public function search(array $sample) : ?Cell
{
$current = $this->root;
while ($current) {
if ($current instanceof Isolator) {
$value = $current->value();
if (is_string($value)) {
if ($sample[$current->column()] === $value) {
$current = $current->left();
} else {
$current = $current->right();
}
} else {
if ($sample[$current->column()] < $value) {
$current = $current->left();
} else {
$current = $current->right();
}
}
continue 1;
}
if ($current instanceof Cell) {
return $current;
}
}
return null;
} | php | public function search(array $sample) : ?Cell
{
$current = $this->root;
while ($current) {
if ($current instanceof Isolator) {
$value = $current->value();
if (is_string($value)) {
if ($sample[$current->column()] === $value) {
$current = $current->left();
} else {
$current = $current->right();
}
} else {
if ($sample[$current->column()] < $value) {
$current = $current->left();
} else {
$current = $current->right();
}
}
continue 1;
}
if ($current instanceof Cell) {
return $current;
}
}
return null;
} | [
"public",
"function",
"search",
"(",
"array",
"$",
"sample",
")",
":",
"?",
"Cell",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"root",
";",
"while",
"(",
"$",
"current",
")",
"{",
"if",
"(",
"$",
"current",
"instanceof",
"Isolator",
")",
"{",
"$",
"value",
"=",
"$",
"current",
"->",
"value",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"sample",
"[",
"$",
"current",
"->",
"column",
"(",
")",
"]",
"===",
"$",
"value",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"left",
"(",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"sample",
"[",
"$",
"current",
"->",
"column",
"(",
")",
"]",
"<",
"$",
"value",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"left",
"(",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"}",
"continue",
"1",
";",
"}",
"if",
"(",
"$",
"current",
"instanceof",
"Cell",
")",
"{",
"return",
"$",
"current",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Search the tree for a terminal node.
@param array $sample
@return \Rubix\ML\Graph\Nodes\Cell|null | [
"Search",
"the",
"tree",
"for",
"a",
"terminal",
"node",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/ITree.php#L165-L196 | train |
RubixML/RubixML | src/Graph/Nodes/Decision.php | Decision.purityIncrease | public function purityIncrease() : float
{
$impurity = $this->impurity;
if ($this->left instanceof Purity) {
$impurity -= $this->left->impurity()
* ($this->left->n() / $this->n);
}
if ($this->right instanceof Purity) {
$impurity -= $this->right->impurity()
* ($this->right->n() / $this->n);
}
return $impurity;
} | php | public function purityIncrease() : float
{
$impurity = $this->impurity;
if ($this->left instanceof Purity) {
$impurity -= $this->left->impurity()
* ($this->left->n() / $this->n);
}
if ($this->right instanceof Purity) {
$impurity -= $this->right->impurity()
* ($this->right->n() / $this->n);
}
return $impurity;
} | [
"public",
"function",
"purityIncrease",
"(",
")",
":",
"float",
"{",
"$",
"impurity",
"=",
"$",
"this",
"->",
"impurity",
";",
"if",
"(",
"$",
"this",
"->",
"left",
"instanceof",
"Purity",
")",
"{",
"$",
"impurity",
"-=",
"$",
"this",
"->",
"left",
"->",
"impurity",
"(",
")",
"*",
"(",
"$",
"this",
"->",
"left",
"->",
"n",
"(",
")",
"/",
"$",
"this",
"->",
"n",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"right",
"instanceof",
"Purity",
")",
"{",
"$",
"impurity",
"-=",
"$",
"this",
"->",
"right",
"->",
"impurity",
"(",
")",
"*",
"(",
"$",
"this",
"->",
"right",
"->",
"n",
"(",
")",
"/",
"$",
"this",
"->",
"n",
")",
";",
"}",
"return",
"$",
"impurity",
";",
"}"
] | Return the decrease in impurity this decision node introduces.
@return float | [
"Return",
"the",
"decrease",
"in",
"impurity",
"this",
"decision",
"node",
"introduces",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/Nodes/Decision.php#L149-L164 | train |
RubixML/RubixML | src/Classifiers/NaiveBayes.php | NaiveBayes.priors | public function priors() : array
{
$priors = [];
if (is_array($this->priors)) {
$max = logsumexp($this->priors);
foreach ($this->priors as $class => $probability) {
$priors[$class] = exp($probability - $max);
}
}
return $priors;
} | php | public function priors() : array
{
$priors = [];
if (is_array($this->priors)) {
$max = logsumexp($this->priors);
foreach ($this->priors as $class => $probability) {
$priors[$class] = exp($probability - $max);
}
}
return $priors;
} | [
"public",
"function",
"priors",
"(",
")",
":",
"array",
"{",
"$",
"priors",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"priors",
")",
")",
"{",
"$",
"max",
"=",
"logsumexp",
"(",
"$",
"this",
"->",
"priors",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"priors",
"as",
"$",
"class",
"=>",
"$",
"probability",
")",
"{",
"$",
"priors",
"[",
"$",
"class",
"]",
"=",
"exp",
"(",
"$",
"probability",
"-",
"$",
"max",
")",
";",
"}",
"}",
"return",
"$",
"priors",
";",
"}"
] | Return the class prior probabilities.
@return array | [
"Return",
"the",
"class",
"prior",
"probabilities",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Classifiers/NaiveBayes.php#L178-L191 | train |
RubixML/RubixML | src/Classifiers/NaiveBayes.php | NaiveBayes.partial | public function partial(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This Estimator requires a'
. ' Labeled training set.');
}
if (!$dataset->homogeneous() or $dataset->columnType(0) !== DataType::CATEGORICAL) {
throw new InvalidArgumentException('This estimator only works'
. ' with categorical features.');
}
if (empty($this->weights) or empty($this->counts) or empty($this->probs)) {
$this->train($dataset);
return;
}
foreach ($dataset->stratify() as $class => $stratum) {
$classCounts = $this->counts[$class];
$classProbs = $this->probs[$class];
foreach ($stratum->columns() as $column => $values) {
$columnCounts = $classCounts[$column];
$counts = array_count_values($values);
foreach ($counts as $category => $count) {
if (isset($columnCounts[$category])) {
$columnCounts[$category] += $count;
} else {
$columnCounts[$category] = $count;
}
}
$total = (array_sum($columnCounts)
+ (count($columnCounts) * $this->alpha))
?: EPSILON;
$probs = [];
foreach ($columnCounts as $category => $count) {
$probs[$category] = log(($count + $this->alpha) / $total);
}
$classCounts[$column] = $columnCounts;
$classProbs[$column] = $probs;
}
$this->counts[$class] = $classCounts;
$this->probs[$class] = $classProbs;
$this->weights[$class] += $stratum->numRows();
}
if ($this->fitPriors) {
$total = (array_sum($this->weights)
+ (count($this->weights) * $this->alpha))
?: EPSILON;
foreach ($this->weights as $class => $weight) {
$this->priors[$class] = log(($weight + $this->alpha) / $total);
}
}
} | php | public function partial(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This Estimator requires a'
. ' Labeled training set.');
}
if (!$dataset->homogeneous() or $dataset->columnType(0) !== DataType::CATEGORICAL) {
throw new InvalidArgumentException('This estimator only works'
. ' with categorical features.');
}
if (empty($this->weights) or empty($this->counts) or empty($this->probs)) {
$this->train($dataset);
return;
}
foreach ($dataset->stratify() as $class => $stratum) {
$classCounts = $this->counts[$class];
$classProbs = $this->probs[$class];
foreach ($stratum->columns() as $column => $values) {
$columnCounts = $classCounts[$column];
$counts = array_count_values($values);
foreach ($counts as $category => $count) {
if (isset($columnCounts[$category])) {
$columnCounts[$category] += $count;
} else {
$columnCounts[$category] = $count;
}
}
$total = (array_sum($columnCounts)
+ (count($columnCounts) * $this->alpha))
?: EPSILON;
$probs = [];
foreach ($columnCounts as $category => $count) {
$probs[$category] = log(($count + $this->alpha) / $total);
}
$classCounts[$column] = $columnCounts;
$classProbs[$column] = $probs;
}
$this->counts[$class] = $classCounts;
$this->probs[$class] = $classProbs;
$this->weights[$class] += $stratum->numRows();
}
if ($this->fitPriors) {
$total = (array_sum($this->weights)
+ (count($this->weights) * $this->alpha))
?: EPSILON;
foreach ($this->weights as $class => $weight) {
$this->priors[$class] = log(($weight + $this->alpha) / $total);
}
}
} | [
"public",
"function",
"partial",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"dataset",
"instanceof",
"Labeled",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This Estimator requires a'",
".",
"' Labeled training set.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dataset",
"->",
"homogeneous",
"(",
")",
"or",
"$",
"dataset",
"->",
"columnType",
"(",
"0",
")",
"!==",
"DataType",
"::",
"CATEGORICAL",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This estimator only works'",
".",
"' with categorical features.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"weights",
")",
"or",
"empty",
"(",
"$",
"this",
"->",
"counts",
")",
"or",
"empty",
"(",
"$",
"this",
"->",
"probs",
")",
")",
"{",
"$",
"this",
"->",
"train",
"(",
"$",
"dataset",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"dataset",
"->",
"stratify",
"(",
")",
"as",
"$",
"class",
"=>",
"$",
"stratum",
")",
"{",
"$",
"classCounts",
"=",
"$",
"this",
"->",
"counts",
"[",
"$",
"class",
"]",
";",
"$",
"classProbs",
"=",
"$",
"this",
"->",
"probs",
"[",
"$",
"class",
"]",
";",
"foreach",
"(",
"$",
"stratum",
"->",
"columns",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"values",
")",
"{",
"$",
"columnCounts",
"=",
"$",
"classCounts",
"[",
"$",
"column",
"]",
";",
"$",
"counts",
"=",
"array_count_values",
"(",
"$",
"values",
")",
";",
"foreach",
"(",
"$",
"counts",
"as",
"$",
"category",
"=>",
"$",
"count",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"columnCounts",
"[",
"$",
"category",
"]",
")",
")",
"{",
"$",
"columnCounts",
"[",
"$",
"category",
"]",
"+=",
"$",
"count",
";",
"}",
"else",
"{",
"$",
"columnCounts",
"[",
"$",
"category",
"]",
"=",
"$",
"count",
";",
"}",
"}",
"$",
"total",
"=",
"(",
"array_sum",
"(",
"$",
"columnCounts",
")",
"+",
"(",
"count",
"(",
"$",
"columnCounts",
")",
"*",
"$",
"this",
"->",
"alpha",
")",
")",
"?",
":",
"EPSILON",
";",
"$",
"probs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columnCounts",
"as",
"$",
"category",
"=>",
"$",
"count",
")",
"{",
"$",
"probs",
"[",
"$",
"category",
"]",
"=",
"log",
"(",
"(",
"$",
"count",
"+",
"$",
"this",
"->",
"alpha",
")",
"/",
"$",
"total",
")",
";",
"}",
"$",
"classCounts",
"[",
"$",
"column",
"]",
"=",
"$",
"columnCounts",
";",
"$",
"classProbs",
"[",
"$",
"column",
"]",
"=",
"$",
"probs",
";",
"}",
"$",
"this",
"->",
"counts",
"[",
"$",
"class",
"]",
"=",
"$",
"classCounts",
";",
"$",
"this",
"->",
"probs",
"[",
"$",
"class",
"]",
"=",
"$",
"classProbs",
";",
"$",
"this",
"->",
"weights",
"[",
"$",
"class",
"]",
"+=",
"$",
"stratum",
"->",
"numRows",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fitPriors",
")",
"{",
"$",
"total",
"=",
"(",
"array_sum",
"(",
"$",
"this",
"->",
"weights",
")",
"+",
"(",
"count",
"(",
"$",
"this",
"->",
"weights",
")",
"*",
"$",
"this",
"->",
"alpha",
")",
")",
"?",
":",
"EPSILON",
";",
"foreach",
"(",
"$",
"this",
"->",
"weights",
"as",
"$",
"class",
"=>",
"$",
"weight",
")",
"{",
"$",
"this",
"->",
"priors",
"[",
"$",
"class",
"]",
"=",
"log",
"(",
"(",
"$",
"weight",
"+",
"$",
"this",
"->",
"alpha",
")",
"/",
"$",
"total",
")",
";",
"}",
"}",
"}"
] | Compute the rolling counts and conditional probabilities.
@param \Rubix\ML\Datasets\Dataset $dataset
@throws \InvalidArgumentException | [
"Compute",
"the",
"rolling",
"counts",
"and",
"conditional",
"probabilities",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Classifiers/NaiveBayes.php#L236-L299 | train |
RubixML/RubixML | src/Classifiers/AdaBoost.php | AdaBoost.score | protected function score(Dataset $dataset) : array
{
$scores = array_fill(
0,
$dataset->numRows(),
array_fill_keys($this->classes, 0.)
);
foreach ($this->ensemble as $i => $estimator) {
$influence = $this->influences[$i];
foreach ($estimator->predict($dataset) as $j => $prediction) {
$scores[$j][$prediction] += $influence;
}
}
return $scores;
} | php | protected function score(Dataset $dataset) : array
{
$scores = array_fill(
0,
$dataset->numRows(),
array_fill_keys($this->classes, 0.)
);
foreach ($this->ensemble as $i => $estimator) {
$influence = $this->influences[$i];
foreach ($estimator->predict($dataset) as $j => $prediction) {
$scores[$j][$prediction] += $influence;
}
}
return $scores;
} | [
"protected",
"function",
"score",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"array",
"{",
"$",
"scores",
"=",
"array_fill",
"(",
"0",
",",
"$",
"dataset",
"->",
"numRows",
"(",
")",
",",
"array_fill_keys",
"(",
"$",
"this",
"->",
"classes",
",",
"0.",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"ensemble",
"as",
"$",
"i",
"=>",
"$",
"estimator",
")",
"{",
"$",
"influence",
"=",
"$",
"this",
"->",
"influences",
"[",
"$",
"i",
"]",
";",
"foreach",
"(",
"$",
"estimator",
"->",
"predict",
"(",
"$",
"dataset",
")",
"as",
"$",
"j",
"=>",
"$",
"prediction",
")",
"{",
"$",
"scores",
"[",
"$",
"j",
"]",
"[",
"$",
"prediction",
"]",
"+=",
"$",
"influence",
";",
"}",
"}",
"return",
"$",
"scores",
";",
"}"
] | Return the influence scores for each sample in the dataset.
@param \Rubix\ML\Datasets\Dataset $dataset
@throws \RuntimeException
@throws \InvalidArgumentException
@return array | [
"Return",
"the",
"influence",
"scores",
"for",
"each",
"sample",
"in",
"the",
"dataset",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Classifiers/AdaBoost.php#L387-L404 | train |
RubixML/RubixML | src/Classifiers/KNearestNeighbors.php | KNearestNeighbors.partial | public function partial(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This estimator requires a'
. ' labeled training set.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$this->classes = array_unique(array_merge($this->classes, $dataset->possibleOutcomes()));
$this->samples = array_merge($this->samples, $dataset->samples());
$this->labels = array_merge($this->labels, $dataset->labels());
} | php | public function partial(Dataset $dataset) : void
{
if (!$dataset instanceof Labeled) {
throw new InvalidArgumentException('This estimator requires a'
. ' labeled training set.');
}
DatasetIsCompatibleWithEstimator::check($dataset, $this);
$this->classes = array_unique(array_merge($this->classes, $dataset->possibleOutcomes()));
$this->samples = array_merge($this->samples, $dataset->samples());
$this->labels = array_merge($this->labels, $dataset->labels());
} | [
"public",
"function",
"partial",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"dataset",
"instanceof",
"Labeled",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This estimator requires a'",
".",
"' labeled training set.'",
")",
";",
"}",
"DatasetIsCompatibleWithEstimator",
"::",
"check",
"(",
"$",
"dataset",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"classes",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"dataset",
"->",
"possibleOutcomes",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"samples",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"samples",
",",
"$",
"dataset",
"->",
"samples",
"(",
")",
")",
";",
"$",
"this",
"->",
"labels",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"labels",
",",
"$",
"dataset",
"->",
"labels",
"(",
")",
")",
";",
"}"
] | Store the sample and outcome arrays. No other work to be done as this is
a lazy learning algorithm.
@param \Rubix\ML\Datasets\Dataset $dataset
@throws \InvalidArgumentException | [
"Store",
"the",
"sample",
"and",
"outcome",
"arrays",
".",
"No",
"other",
"work",
"to",
"be",
"done",
"as",
"this",
"is",
"a",
"lazy",
"learning",
"algorithm",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Classifiers/KNearestNeighbors.php#L153-L165 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.layers | public function layers() : Generator
{
yield $this->input;
foreach ($this->hidden as $hidden) {
yield $hidden;
}
yield $this->output;
} | php | public function layers() : Generator
{
yield $this->input;
foreach ($this->hidden as $hidden) {
yield $hidden;
}
yield $this->output;
} | [
"public",
"function",
"layers",
"(",
")",
":",
"Generator",
"{",
"yield",
"$",
"this",
"->",
"input",
";",
"foreach",
"(",
"$",
"this",
"->",
"hidden",
"as",
"$",
"hidden",
")",
"{",
"yield",
"$",
"hidden",
";",
"}",
"yield",
"$",
"this",
"->",
"output",
";",
"}"
] | Return all the layers in the network.
@return \Generator | [
"Return",
"all",
"the",
"layers",
"in",
"the",
"network",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L146-L155 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.parametric | public function parametric() : Generator
{
foreach ($this->hidden as $layer) {
if ($layer instanceof Parametric) {
yield $layer;
}
}
if ($this->output instanceof Parametric) {
yield $this->output;
}
} | php | public function parametric() : Generator
{
foreach ($this->hidden as $layer) {
if ($layer instanceof Parametric) {
yield $layer;
}
}
if ($this->output instanceof Parametric) {
yield $this->output;
}
} | [
"public",
"function",
"parametric",
"(",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"hidden",
"as",
"$",
"layer",
")",
"{",
"if",
"(",
"$",
"layer",
"instanceof",
"Parametric",
")",
"{",
"yield",
"$",
"layer",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"output",
"instanceof",
"Parametric",
")",
"{",
"yield",
"$",
"this",
"->",
"output",
";",
"}",
"}"
] | The parametric layers of the network. i.e. the layers that have weights.
@return \Generator | [
"The",
"parametric",
"layers",
"of",
"the",
"network",
".",
"i",
".",
"e",
".",
"the",
"layers",
"that",
"have",
"weights",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L162-L173 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.roundtrip | public function roundtrip(Labeled $batch) : float
{
$input = Matrix::quick($batch->samples())->transpose();
$this->feed($input);
return $this->backpropagate($batch->labels());
} | php | public function roundtrip(Labeled $batch) : float
{
$input = Matrix::quick($batch->samples())->transpose();
$this->feed($input);
return $this->backpropagate($batch->labels());
} | [
"public",
"function",
"roundtrip",
"(",
"Labeled",
"$",
"batch",
")",
":",
"float",
"{",
"$",
"input",
"=",
"Matrix",
"::",
"quick",
"(",
"$",
"batch",
"->",
"samples",
"(",
")",
")",
"->",
"transpose",
"(",
")",
";",
"$",
"this",
"->",
"feed",
"(",
"$",
"input",
")",
";",
"return",
"$",
"this",
"->",
"backpropagate",
"(",
"$",
"batch",
"->",
"labels",
"(",
")",
")",
";",
"}"
] | Do a forward and backward pass of the network in one call. Returns
the loss from the backward pass.
@param \Rubix\ML\Datasets\Labeled $batch
@return float | [
"Do",
"a",
"forward",
"and",
"backward",
"pass",
"of",
"the",
"network",
"in",
"one",
"call",
".",
"Returns",
"the",
"loss",
"from",
"the",
"backward",
"pass",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L193-L200 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.feed | public function feed(Matrix $input) : Matrix
{
$input = $this->input->forward($input);
foreach ($this->hidden as $hidden) {
$input = $hidden->forward($input);
}
return $this->output->forward($input);
} | php | public function feed(Matrix $input) : Matrix
{
$input = $this->input->forward($input);
foreach ($this->hidden as $hidden) {
$input = $hidden->forward($input);
}
return $this->output->forward($input);
} | [
"public",
"function",
"feed",
"(",
"Matrix",
"$",
"input",
")",
":",
"Matrix",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"input",
"->",
"forward",
"(",
"$",
"input",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"hidden",
"as",
"$",
"hidden",
")",
"{",
"$",
"input",
"=",
"$",
"hidden",
"->",
"forward",
"(",
"$",
"input",
")",
";",
"}",
"return",
"$",
"this",
"->",
"output",
"->",
"forward",
"(",
"$",
"input",
")",
";",
"}"
] | Feed a batch through the network and return a matrix of activations.
@param \Rubix\Tensor\Matrix $input
@return \Rubix\Tensor\Matrix | [
"Feed",
"a",
"batch",
"through",
"the",
"network",
"and",
"return",
"a",
"matrix",
"of",
"activations",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L208-L217 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.infer | public function infer(Matrix $input) : Tensor
{
$input = $this->input->infer($input);
foreach ($this->hidden as $hidden) {
$input = $hidden->infer($input);
}
return $this->output->infer($input);
} | php | public function infer(Matrix $input) : Tensor
{
$input = $this->input->infer($input);
foreach ($this->hidden as $hidden) {
$input = $hidden->infer($input);
}
return $this->output->infer($input);
} | [
"public",
"function",
"infer",
"(",
"Matrix",
"$",
"input",
")",
":",
"Tensor",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"input",
"->",
"infer",
"(",
"$",
"input",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"hidden",
"as",
"$",
"hidden",
")",
"{",
"$",
"input",
"=",
"$",
"hidden",
"->",
"infer",
"(",
"$",
"input",
")",
";",
"}",
"return",
"$",
"this",
"->",
"output",
"->",
"infer",
"(",
"$",
"input",
")",
";",
"}"
] | Run an inference pass and return the activations at the output layer.
@param \Rubix\Tensor\Matrix $input
@return \Rubix\Tensor\Matrix | [
"Run",
"an",
"inference",
"pass",
"and",
"return",
"the",
"activations",
"at",
"the",
"output",
"layer",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L225-L234 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.backpropagate | public function backpropagate(array $labels) : float
{
[$gradient, $loss] = $this->output->back($labels, $this->optimizer);
foreach ($this->backPass as $layer) {
$gradient = $layer->back($gradient, $this->optimizer);
}
return $loss;
} | php | public function backpropagate(array $labels) : float
{
[$gradient, $loss] = $this->output->back($labels, $this->optimizer);
foreach ($this->backPass as $layer) {
$gradient = $layer->back($gradient, $this->optimizer);
}
return $loss;
} | [
"public",
"function",
"backpropagate",
"(",
"array",
"$",
"labels",
")",
":",
"float",
"{",
"[",
"$",
"gradient",
",",
"$",
"loss",
"]",
"=",
"$",
"this",
"->",
"output",
"->",
"back",
"(",
"$",
"labels",
",",
"$",
"this",
"->",
"optimizer",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"backPass",
"as",
"$",
"layer",
")",
"{",
"$",
"gradient",
"=",
"$",
"layer",
"->",
"back",
"(",
"$",
"gradient",
",",
"$",
"this",
"->",
"optimizer",
")",
";",
"}",
"return",
"$",
"loss",
";",
"}"
] | Backpropagate the gradient produced by the cost function and return
the loss calculated by the output layer's cost function.
@param array $labels
@return float | [
"Backpropagate",
"the",
"gradient",
"produced",
"by",
"the",
"cost",
"function",
"and",
"return",
"the",
"loss",
"calculated",
"by",
"the",
"output",
"layer",
"s",
"cost",
"function",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L243-L252 | train |
RubixML/RubixML | src/NeuralNet/FeedForward.php | FeedForward.restore | public function restore(Snapshot $snapshot) : void
{
foreach ($snapshot as [$layer, $params]) {
if ($layer instanceof Parametric) {
$layer->restore($params);
}
}
} | php | public function restore(Snapshot $snapshot) : void
{
foreach ($snapshot as [$layer, $params]) {
if ($layer instanceof Parametric) {
$layer->restore($params);
}
}
} | [
"public",
"function",
"restore",
"(",
"Snapshot",
"$",
"snapshot",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"snapshot",
"as",
"[",
"$",
"layer",
",",
"$",
"params",
"]",
")",
"{",
"if",
"(",
"$",
"layer",
"instanceof",
"Parametric",
")",
"{",
"$",
"layer",
"->",
"restore",
"(",
"$",
"params",
")",
";",
"}",
"}",
"}"
] | Restore the network parameters from a snapshot.
@param \Rubix\ML\NeuralNet\Snapshot $snapshot | [
"Restore",
"the",
"network",
"parameters",
"from",
"a",
"snapshot",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/NeuralNet/FeedForward.php#L259-L266 | train |
RubixML/RubixML | src/Graph/KDTree.php | KDTree.search | public function search(array $sample) : ?Neighborhood
{
$current = $this->root;
while ($current) {
if ($current instanceof Coordinate) {
if ($sample[$current->column()] < $current->value()) {
$current = $current->left();
} else {
$current = $current->right();
}
continue 1;
}
if ($current instanceof Neighborhood) {
return $current;
}
}
return null;
} | php | public function search(array $sample) : ?Neighborhood
{
$current = $this->root;
while ($current) {
if ($current instanceof Coordinate) {
if ($sample[$current->column()] < $current->value()) {
$current = $current->left();
} else {
$current = $current->right();
}
continue 1;
}
if ($current instanceof Neighborhood) {
return $current;
}
}
return null;
} | [
"public",
"function",
"search",
"(",
"array",
"$",
"sample",
")",
":",
"?",
"Neighborhood",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"root",
";",
"while",
"(",
"$",
"current",
")",
"{",
"if",
"(",
"$",
"current",
"instanceof",
"Coordinate",
")",
"{",
"if",
"(",
"$",
"sample",
"[",
"$",
"current",
"->",
"column",
"(",
")",
"]",
"<",
"$",
"current",
"->",
"value",
"(",
")",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"left",
"(",
")",
";",
"}",
"else",
"{",
"$",
"current",
"=",
"$",
"current",
"->",
"right",
"(",
")",
";",
"}",
"continue",
"1",
";",
"}",
"if",
"(",
"$",
"current",
"instanceof",
"Neighborhood",
")",
"{",
"return",
"$",
"current",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Search the tree for a neighborhood and return an array of samples and
labels.
@param array $sample
@return \Rubix\ML\Graph\Nodes\Neighborhood|null | [
"Search",
"the",
"tree",
"for",
"a",
"neighborhood",
"and",
"return",
"an",
"array",
"of",
"samples",
"and",
"labels",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/KDTree.php#L157-L178 | train |
RubixML/RubixML | src/Graph/KDTree.php | KDTree.nearest | public function nearest(array $sample, int $k = 1) : array
{
if ($k < 1) {
throw new InvalidArgumentException('The number of nearest'
. " neighbors must be greater than 0, $k given.");
}
$neighborhood = $this->search($sample);
if (!$neighborhood) {
return [[], []];
}
$distances = $labels = [];
$visited = new SplObjectStorage();
$stack = [$neighborhood];
while ($stack) {
$current = array_pop($stack);
if ($visited->contains($current)) {
continue 1;
}
$visited->attach($current);
$parent = $current->parent();
if ($parent) {
$stack[] = $parent;
}
if ($current instanceof Neighborhood) {
foreach ($current->samples() as $neighbor) {
$distances[] = $this->kernel->compute($sample, $neighbor);
}
$labels = array_merge($labels, $current->labels());
array_multisort($distances, $labels);
continue 1;
}
$target = $distances[$k - 1] ?? INF;
foreach ($current->children() as $child) {
if ($visited->contains($child)) {
continue 1;
}
if ($child instanceof Box) {
foreach ($child->sides() as $side) {
$distance = $this->kernel->compute($sample, $side);
if ($distance < $target) {
$stack[] = $child;
continue 2;
}
}
}
$visited->attach($child);
}
}
$distances = array_slice($distances, 0, $k);
$labels = array_slice($labels, 0, $k);
return [$labels, $distances];
} | php | public function nearest(array $sample, int $k = 1) : array
{
if ($k < 1) {
throw new InvalidArgumentException('The number of nearest'
. " neighbors must be greater than 0, $k given.");
}
$neighborhood = $this->search($sample);
if (!$neighborhood) {
return [[], []];
}
$distances = $labels = [];
$visited = new SplObjectStorage();
$stack = [$neighborhood];
while ($stack) {
$current = array_pop($stack);
if ($visited->contains($current)) {
continue 1;
}
$visited->attach($current);
$parent = $current->parent();
if ($parent) {
$stack[] = $parent;
}
if ($current instanceof Neighborhood) {
foreach ($current->samples() as $neighbor) {
$distances[] = $this->kernel->compute($sample, $neighbor);
}
$labels = array_merge($labels, $current->labels());
array_multisort($distances, $labels);
continue 1;
}
$target = $distances[$k - 1] ?? INF;
foreach ($current->children() as $child) {
if ($visited->contains($child)) {
continue 1;
}
if ($child instanceof Box) {
foreach ($child->sides() as $side) {
$distance = $this->kernel->compute($sample, $side);
if ($distance < $target) {
$stack[] = $child;
continue 2;
}
}
}
$visited->attach($child);
}
}
$distances = array_slice($distances, 0, $k);
$labels = array_slice($labels, 0, $k);
return [$labels, $distances];
} | [
"public",
"function",
"nearest",
"(",
"array",
"$",
"sample",
",",
"int",
"$",
"k",
"=",
"1",
")",
":",
"array",
"{",
"if",
"(",
"$",
"k",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The number of nearest'",
".",
"\" neighbors must be greater than 0, $k given.\"",
")",
";",
"}",
"$",
"neighborhood",
"=",
"$",
"this",
"->",
"search",
"(",
"$",
"sample",
")",
";",
"if",
"(",
"!",
"$",
"neighborhood",
")",
"{",
"return",
"[",
"[",
"]",
",",
"[",
"]",
"]",
";",
"}",
"$",
"distances",
"=",
"$",
"labels",
"=",
"[",
"]",
";",
"$",
"visited",
"=",
"new",
"SplObjectStorage",
"(",
")",
";",
"$",
"stack",
"=",
"[",
"$",
"neighborhood",
"]",
";",
"while",
"(",
"$",
"stack",
")",
"{",
"$",
"current",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"if",
"(",
"$",
"visited",
"->",
"contains",
"(",
"$",
"current",
")",
")",
"{",
"continue",
"1",
";",
"}",
"$",
"visited",
"->",
"attach",
"(",
"$",
"current",
")",
";",
"$",
"parent",
"=",
"$",
"current",
"->",
"parent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"$",
"stack",
"[",
"]",
"=",
"$",
"parent",
";",
"}",
"if",
"(",
"$",
"current",
"instanceof",
"Neighborhood",
")",
"{",
"foreach",
"(",
"$",
"current",
"->",
"samples",
"(",
")",
"as",
"$",
"neighbor",
")",
"{",
"$",
"distances",
"[",
"]",
"=",
"$",
"this",
"->",
"kernel",
"->",
"compute",
"(",
"$",
"sample",
",",
"$",
"neighbor",
")",
";",
"}",
"$",
"labels",
"=",
"array_merge",
"(",
"$",
"labels",
",",
"$",
"current",
"->",
"labels",
"(",
")",
")",
";",
"array_multisort",
"(",
"$",
"distances",
",",
"$",
"labels",
")",
";",
"continue",
"1",
";",
"}",
"$",
"target",
"=",
"$",
"distances",
"[",
"$",
"k",
"-",
"1",
"]",
"??",
"INF",
";",
"foreach",
"(",
"$",
"current",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"visited",
"->",
"contains",
"(",
"$",
"child",
")",
")",
"{",
"continue",
"1",
";",
"}",
"if",
"(",
"$",
"child",
"instanceof",
"Box",
")",
"{",
"foreach",
"(",
"$",
"child",
"->",
"sides",
"(",
")",
"as",
"$",
"side",
")",
"{",
"$",
"distance",
"=",
"$",
"this",
"->",
"kernel",
"->",
"compute",
"(",
"$",
"sample",
",",
"$",
"side",
")",
";",
"if",
"(",
"$",
"distance",
"<",
"$",
"target",
")",
"{",
"$",
"stack",
"[",
"]",
"=",
"$",
"child",
";",
"continue",
"2",
";",
"}",
"}",
"}",
"$",
"visited",
"->",
"attach",
"(",
"$",
"child",
")",
";",
"}",
"}",
"$",
"distances",
"=",
"array_slice",
"(",
"$",
"distances",
",",
"0",
",",
"$",
"k",
")",
";",
"$",
"labels",
"=",
"array_slice",
"(",
"$",
"labels",
",",
"0",
",",
"$",
"k",
")",
";",
"return",
"[",
"$",
"labels",
",",
"$",
"distances",
"]",
";",
"}"
] | Run a k nearest neighbors search of every neighborhood and return
the labels and distances in a 2-tuple.
@param array $sample
@param int $k
@throws \InvalidArgumentException
@return array[] | [
"Run",
"a",
"k",
"nearest",
"neighbors",
"search",
"of",
"every",
"neighborhood",
"and",
"return",
"the",
"labels",
"and",
"distances",
"in",
"a",
"2",
"-",
"tuple",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/KDTree.php#L189-L262 | train |
RubixML/RubixML | src/Graph/BallTree.php | BallTree.range | public function range(array $sample, float $radius) : array
{
if ($radius <= 0.) {
throw new InvalidArgumentException('Radius must be'
. " greater than 0, $radius given.");
}
$samples = $labels = $distances = [];
$stack = [$this->root];
while ($stack) {
$current = array_pop($stack);
if (!$current instanceof BinaryNode) {
continue 1;
}
if ($current instanceof Cluster) {
foreach ($current->samples() as $i => $neighbor) {
$distance = $this->kernel->compute($sample, $neighbor);
if ($distance <= $radius) {
$samples[] = $neighbor;
$labels[] = $current->label($i);
$distances[] = $distance;
}
}
continue 1;
}
foreach ($current->children() as $child) {
if ($child instanceof Ball) {
$distance = $this->kernel->compute($sample, $child->center());
if ($distance <= ($child->radius() + $radius)) {
$stack[] = $child;
}
}
}
}
return [$samples, $labels, $distances];
} | php | public function range(array $sample, float $radius) : array
{
if ($radius <= 0.) {
throw new InvalidArgumentException('Radius must be'
. " greater than 0, $radius given.");
}
$samples = $labels = $distances = [];
$stack = [$this->root];
while ($stack) {
$current = array_pop($stack);
if (!$current instanceof BinaryNode) {
continue 1;
}
if ($current instanceof Cluster) {
foreach ($current->samples() as $i => $neighbor) {
$distance = $this->kernel->compute($sample, $neighbor);
if ($distance <= $radius) {
$samples[] = $neighbor;
$labels[] = $current->label($i);
$distances[] = $distance;
}
}
continue 1;
}
foreach ($current->children() as $child) {
if ($child instanceof Ball) {
$distance = $this->kernel->compute($sample, $child->center());
if ($distance <= ($child->radius() + $radius)) {
$stack[] = $child;
}
}
}
}
return [$samples, $labels, $distances];
} | [
"public",
"function",
"range",
"(",
"array",
"$",
"sample",
",",
"float",
"$",
"radius",
")",
":",
"array",
"{",
"if",
"(",
"$",
"radius",
"<=",
"0.",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Radius must be'",
".",
"\" greater than 0, $radius given.\"",
")",
";",
"}",
"$",
"samples",
"=",
"$",
"labels",
"=",
"$",
"distances",
"=",
"[",
"]",
";",
"$",
"stack",
"=",
"[",
"$",
"this",
"->",
"root",
"]",
";",
"while",
"(",
"$",
"stack",
")",
"{",
"$",
"current",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"if",
"(",
"!",
"$",
"current",
"instanceof",
"BinaryNode",
")",
"{",
"continue",
"1",
";",
"}",
"if",
"(",
"$",
"current",
"instanceof",
"Cluster",
")",
"{",
"foreach",
"(",
"$",
"current",
"->",
"samples",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"neighbor",
")",
"{",
"$",
"distance",
"=",
"$",
"this",
"->",
"kernel",
"->",
"compute",
"(",
"$",
"sample",
",",
"$",
"neighbor",
")",
";",
"if",
"(",
"$",
"distance",
"<=",
"$",
"radius",
")",
"{",
"$",
"samples",
"[",
"]",
"=",
"$",
"neighbor",
";",
"$",
"labels",
"[",
"]",
"=",
"$",
"current",
"->",
"label",
"(",
"$",
"i",
")",
";",
"$",
"distances",
"[",
"]",
"=",
"$",
"distance",
";",
"}",
"}",
"continue",
"1",
";",
"}",
"foreach",
"(",
"$",
"current",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"Ball",
")",
"{",
"$",
"distance",
"=",
"$",
"this",
"->",
"kernel",
"->",
"compute",
"(",
"$",
"sample",
",",
"$",
"child",
"->",
"center",
"(",
")",
")",
";",
"if",
"(",
"$",
"distance",
"<=",
"(",
"$",
"child",
"->",
"radius",
"(",
")",
"+",
"$",
"radius",
")",
")",
"{",
"$",
"stack",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"}",
"}",
"return",
"[",
"$",
"samples",
",",
"$",
"labels",
",",
"$",
"distances",
"]",
";",
"}"
] | Run a range search over every cluster within radius and return
the labels and distances in a 2-tuple.
@param array $sample
@param float $radius
@throws \InvalidArgumentException
@return array[] | [
"Run",
"a",
"range",
"search",
"over",
"every",
"cluster",
"within",
"radius",
"and",
"return",
"the",
"labels",
"and",
"distances",
"in",
"a",
"2",
"-",
"tuple",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/BallTree.php#L164-L208 | train |
RubixML/RubixML | src/Other/Helpers/DataType.php | DataType.determine | public static function determine($data) : int
{
switch (gettype($data)) {
case 'string':
return self::CATEGORICAL;
case 'double':
return self::CONTINUOUS;
case 'integer':
return self::CONTINUOUS;
case 'resource':
return self::RESOURCE;
default:
return self::OTHER;
}
} | php | public static function determine($data) : int
{
switch (gettype($data)) {
case 'string':
return self::CATEGORICAL;
case 'double':
return self::CONTINUOUS;
case 'integer':
return self::CONTINUOUS;
case 'resource':
return self::RESOURCE;
default:
return self::OTHER;
}
} | [
"public",
"static",
"function",
"determine",
"(",
"$",
"data",
")",
":",
"int",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"data",
")",
")",
"{",
"case",
"'string'",
":",
"return",
"self",
"::",
"CATEGORICAL",
";",
"case",
"'double'",
":",
"return",
"self",
"::",
"CONTINUOUS",
";",
"case",
"'integer'",
":",
"return",
"self",
"::",
"CONTINUOUS",
";",
"case",
"'resource'",
":",
"return",
"self",
"::",
"RESOURCE",
";",
"default",
":",
"return",
"self",
"::",
"OTHER",
";",
"}",
"}"
] | Return the integer encoded data type.
@param mixed $data
@return int | [
"Return",
"the",
"integer",
"encoded",
"data",
"type",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Other/Helpers/DataType.php#L32-L50 | train |
RubixML/RubixML | src/Graph/Nodes/Coordinate.php | Coordinate.split | public static function split(Labeled $dataset) : self
{
$columns = $dataset->columns();
$variances = array_map([Stats::class, 'variance'], $columns);
$column = argmax($variances);
$value = Stats::median($columns[$column]);
$groups = $dataset->partition($column, $value);
$min = $max = [];
foreach ($columns as $values) {
$min[] = min($values);
$max[] = max($values);
}
return new self($column, $value, $groups, $min, $max);
} | php | public static function split(Labeled $dataset) : self
{
$columns = $dataset->columns();
$variances = array_map([Stats::class, 'variance'], $columns);
$column = argmax($variances);
$value = Stats::median($columns[$column]);
$groups = $dataset->partition($column, $value);
$min = $max = [];
foreach ($columns as $values) {
$min[] = min($values);
$max[] = max($values);
}
return new self($column, $value, $groups, $min, $max);
} | [
"public",
"static",
"function",
"split",
"(",
"Labeled",
"$",
"dataset",
")",
":",
"self",
"{",
"$",
"columns",
"=",
"$",
"dataset",
"->",
"columns",
"(",
")",
";",
"$",
"variances",
"=",
"array_map",
"(",
"[",
"Stats",
"::",
"class",
",",
"'variance'",
"]",
",",
"$",
"columns",
")",
";",
"$",
"column",
"=",
"argmax",
"(",
"$",
"variances",
")",
";",
"$",
"value",
"=",
"Stats",
"::",
"median",
"(",
"$",
"columns",
"[",
"$",
"column",
"]",
")",
";",
"$",
"groups",
"=",
"$",
"dataset",
"->",
"partition",
"(",
"$",
"column",
",",
"$",
"value",
")",
";",
"$",
"min",
"=",
"$",
"max",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"values",
")",
"{",
"$",
"min",
"[",
"]",
"=",
"min",
"(",
"$",
"values",
")",
";",
"$",
"max",
"[",
"]",
"=",
"max",
"(",
"$",
"values",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"groups",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
] | Factory method to build a coordinate node from a labeled dataset
using the column with the highest variance as the column for the
split.
@param \Rubix\ML\Datasets\Labeled $dataset
@return self | [
"Factory",
"method",
"to",
"build",
"a",
"coordinate",
"node",
"from",
"a",
"labeled",
"dataset",
"using",
"the",
"column",
"with",
"the",
"highest",
"variance",
"as",
"the",
"column",
"for",
"the",
"split",
"."
] | 837385e2eb9f05c76c9522fc1673bdb87d11742d | https://github.com/RubixML/RubixML/blob/837385e2eb9f05c76c9522fc1673bdb87d11742d/src/Graph/Nodes/Coordinate.php#L66-L86 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.array_replace_recursive | public static function array_replace_recursive($array1, $array2)
{
if (function_exists('array_replace_recursive')) {
return array_replace_recursive($array1, $array2);
}
foreach ($array2 as $key => $value) {
if (is_array($value)) {
$array1[$key] = self::array_replace_recursive($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
return $array1;
} | php | public static function array_replace_recursive($array1, $array2)
{
if (function_exists('array_replace_recursive')) {
return array_replace_recursive($array1, $array2);
}
foreach ($array2 as $key => $value) {
if (is_array($value)) {
$array1[$key] = self::array_replace_recursive($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
return $array1;
} | [
"public",
"static",
"function",
"array_replace_recursive",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'array_replace_recursive'",
")",
")",
"{",
"return",
"array_replace_recursive",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
";",
"}",
"foreach",
"(",
"$",
"array2",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"array_replace_recursive",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"array1",
";",
"}"
] | Custom array_replace_recursive to be used if PHP < 5.3
Replaces elements from passed arrays into the first array recursively.
@param array $array1 The array in which elements are replaced
@param array $array2 The array from which elements will be extracted
@return array Returns an array, or NULL if an error occurs. | [
"Custom",
"array_replace_recursive",
"to",
"be",
"used",
"if",
"PHP",
"<",
"5",
".",
"3",
"Replaces",
"elements",
"from",
"passed",
"arrays",
"into",
"the",
"first",
"array",
"recursively",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L221-L235 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getTableLimit | public function getTableLimit($tableName)
{
if (empty($this->tableLimits[$tableName])) {
return false;
}
$limit = $this->tableLimits[$tableName];
if (!is_numeric($limit)) {
return false;
}
return $limit;
} | php | public function getTableLimit($tableName)
{
if (empty($this->tableLimits[$tableName])) {
return false;
}
$limit = $this->tableLimits[$tableName];
if (!is_numeric($limit)) {
return false;
}
return $limit;
} | [
"public",
"function",
"getTableLimit",
"(",
"$",
"tableName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"tableLimits",
"[",
"$",
"tableName",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"limit",
"=",
"$",
"this",
"->",
"tableLimits",
"[",
"$",
"tableName",
"]",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"limit",
";",
"}"
] | Returns the LIMIT for the table. Must be numeric to be returned.
@param $tableName
@return boolean | [
"Returns",
"the",
"LIMIT",
"for",
"the",
"table",
".",
"Must",
"be",
"numeric",
"to",
"be",
"returned",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L280-L292 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.connect | private function connect()
{
// Connecting with PDO.
try {
switch ($this->dbType) {
case 'sqlite':
$this->dbHandler = @new PDO("sqlite:".$this->dbName, null, null, $this->pdoSettings);
break;
case 'mysql':
case 'pgsql':
case 'dblib':
$this->dbHandler = @new PDO(
$this->dsn,
$this->user,
$this->pass,
$this->pdoSettings
);
// Execute init commands once connected
foreach ($this->dumpSettings['init_commands'] as $stmt) {
$this->dbHandler->exec($stmt);
}
// Store server version
$this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
break;
default:
throw new Exception("Unsupported database type (".$this->dbType.")");
}
} catch (PDOException $e) {
throw new Exception(
"Connection to ".$this->dbType." failed with message: ".
$e->getMessage()
);
}
if (is_null($this->dbHandler)) {
throw new Exception("Connection to ".$this->dbType."failed");
}
$this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
$this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler, $this->dumpSettings);
} | php | private function connect()
{
// Connecting with PDO.
try {
switch ($this->dbType) {
case 'sqlite':
$this->dbHandler = @new PDO("sqlite:".$this->dbName, null, null, $this->pdoSettings);
break;
case 'mysql':
case 'pgsql':
case 'dblib':
$this->dbHandler = @new PDO(
$this->dsn,
$this->user,
$this->pass,
$this->pdoSettings
);
// Execute init commands once connected
foreach ($this->dumpSettings['init_commands'] as $stmt) {
$this->dbHandler->exec($stmt);
}
// Store server version
$this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
break;
default:
throw new Exception("Unsupported database type (".$this->dbType.")");
}
} catch (PDOException $e) {
throw new Exception(
"Connection to ".$this->dbType." failed with message: ".
$e->getMessage()
);
}
if (is_null($this->dbHandler)) {
throw new Exception("Connection to ".$this->dbType."failed");
}
$this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
$this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler, $this->dumpSettings);
} | [
"private",
"function",
"connect",
"(",
")",
"{",
"// Connecting with PDO.",
"try",
"{",
"switch",
"(",
"$",
"this",
"->",
"dbType",
")",
"{",
"case",
"'sqlite'",
":",
"$",
"this",
"->",
"dbHandler",
"=",
"@",
"new",
"PDO",
"(",
"\"sqlite:\"",
".",
"$",
"this",
"->",
"dbName",
",",
"null",
",",
"null",
",",
"$",
"this",
"->",
"pdoSettings",
")",
";",
"break",
";",
"case",
"'mysql'",
":",
"case",
"'pgsql'",
":",
"case",
"'dblib'",
":",
"$",
"this",
"->",
"dbHandler",
"=",
"@",
"new",
"PDO",
"(",
"$",
"this",
"->",
"dsn",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"pass",
",",
"$",
"this",
"->",
"pdoSettings",
")",
";",
"// Execute init commands once connected",
"foreach",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'init_commands'",
"]",
"as",
"$",
"stmt",
")",
"{",
"$",
"this",
"->",
"dbHandler",
"->",
"exec",
"(",
"$",
"stmt",
")",
";",
"}",
"// Store server version",
"$",
"this",
"->",
"version",
"=",
"$",
"this",
"->",
"dbHandler",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_SERVER_VERSION",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"\"Unsupported database type (\"",
".",
"$",
"this",
"->",
"dbType",
".",
"\")\"",
")",
";",
"}",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Connection to \"",
".",
"$",
"this",
"->",
"dbType",
".",
"\" failed with message: \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dbHandler",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Connection to \"",
".",
"$",
"this",
"->",
"dbType",
".",
"\"failed\"",
")",
";",
"}",
"$",
"this",
"->",
"dbHandler",
"->",
"setAttribute",
"(",
"PDO",
"::",
"ATTR_ORACLE_NULLS",
",",
"PDO",
"::",
"NULL_NATURAL",
")",
";",
"$",
"this",
"->",
"typeAdapter",
"=",
"TypeAdapterFactory",
"::",
"create",
"(",
"$",
"this",
"->",
"dbType",
",",
"$",
"this",
"->",
"dbHandler",
",",
"$",
"this",
"->",
"dumpSettings",
")",
";",
"}"
] | Connect with PDO.
@return null | [
"Connect",
"with",
"PDO",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L345-L385 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.start | public function start($filename = '')
{
// Output file can be redefined here
if (!empty($filename)) {
$this->fileName = $filename;
}
// Connect to database
$this->connect();
// Create output file
$this->compressManager->open($this->fileName);
// Write some basic info to output file
$this->compressManager->write($this->getDumpFileHeader());
// Store server settings and use sanner defaults to dump
$this->compressManager->write(
$this->typeAdapter->backup_parameters()
);
if ($this->dumpSettings['databases']) {
$this->compressManager->write(
$this->typeAdapter->getDatabaseHeader($this->dbName)
);
if ($this->dumpSettings['add-drop-database']) {
$this->compressManager->write(
$this->typeAdapter->add_drop_database($this->dbName)
);
}
}
// Get table, view, trigger, procedures and events structures from
// database.
$this->getDatabaseStructureTables();
$this->getDatabaseStructureViews();
$this->getDatabaseStructureTriggers();
$this->getDatabaseStructureProcedures();
$this->getDatabaseStructureEvents();
if ($this->dumpSettings['databases']) {
$this->compressManager->write(
$this->typeAdapter->databases($this->dbName)
);
}
// If there still are some tables/views in include-tables array,
// that means that some tables or views weren't found.
// Give proper error and exit.
// This check will be removed once include-tables supports regexps.
if (0 < count($this->dumpSettings['include-tables'])) {
$name = implode(",", $this->dumpSettings['include-tables']);
throw new Exception("Table (".$name.") not found in database");
}
$this->exportTables();
$this->exportTriggers();
$this->exportViews();
$this->exportProcedures();
$this->exportEvents();
// Restore saved parameters.
$this->compressManager->write(
$this->typeAdapter->restore_parameters()
);
// Write some stats to output file.
$this->compressManager->write($this->getDumpFileFooter());
// Close output file.
$this->compressManager->close();
return;
} | php | public function start($filename = '')
{
// Output file can be redefined here
if (!empty($filename)) {
$this->fileName = $filename;
}
// Connect to database
$this->connect();
// Create output file
$this->compressManager->open($this->fileName);
// Write some basic info to output file
$this->compressManager->write($this->getDumpFileHeader());
// Store server settings and use sanner defaults to dump
$this->compressManager->write(
$this->typeAdapter->backup_parameters()
);
if ($this->dumpSettings['databases']) {
$this->compressManager->write(
$this->typeAdapter->getDatabaseHeader($this->dbName)
);
if ($this->dumpSettings['add-drop-database']) {
$this->compressManager->write(
$this->typeAdapter->add_drop_database($this->dbName)
);
}
}
// Get table, view, trigger, procedures and events structures from
// database.
$this->getDatabaseStructureTables();
$this->getDatabaseStructureViews();
$this->getDatabaseStructureTriggers();
$this->getDatabaseStructureProcedures();
$this->getDatabaseStructureEvents();
if ($this->dumpSettings['databases']) {
$this->compressManager->write(
$this->typeAdapter->databases($this->dbName)
);
}
// If there still are some tables/views in include-tables array,
// that means that some tables or views weren't found.
// Give proper error and exit.
// This check will be removed once include-tables supports regexps.
if (0 < count($this->dumpSettings['include-tables'])) {
$name = implode(",", $this->dumpSettings['include-tables']);
throw new Exception("Table (".$name.") not found in database");
}
$this->exportTables();
$this->exportTriggers();
$this->exportViews();
$this->exportProcedures();
$this->exportEvents();
// Restore saved parameters.
$this->compressManager->write(
$this->typeAdapter->restore_parameters()
);
// Write some stats to output file.
$this->compressManager->write($this->getDumpFileFooter());
// Close output file.
$this->compressManager->close();
return;
} | [
"public",
"function",
"start",
"(",
"$",
"filename",
"=",
"''",
")",
"{",
"// Output file can be redefined here",
"if",
"(",
"!",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"this",
"->",
"fileName",
"=",
"$",
"filename",
";",
"}",
"// Connect to database",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"// Create output file",
"$",
"this",
"->",
"compressManager",
"->",
"open",
"(",
"$",
"this",
"->",
"fileName",
")",
";",
"// Write some basic info to output file",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"getDumpFileHeader",
"(",
")",
")",
";",
"// Store server settings and use sanner defaults to dump",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"backup_parameters",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'databases'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"getDatabaseHeader",
"(",
"$",
"this",
"->",
"dbName",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'add-drop-database'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"add_drop_database",
"(",
"$",
"this",
"->",
"dbName",
")",
")",
";",
"}",
"}",
"// Get table, view, trigger, procedures and events structures from",
"// database.",
"$",
"this",
"->",
"getDatabaseStructureTables",
"(",
")",
";",
"$",
"this",
"->",
"getDatabaseStructureViews",
"(",
")",
";",
"$",
"this",
"->",
"getDatabaseStructureTriggers",
"(",
")",
";",
"$",
"this",
"->",
"getDatabaseStructureProcedures",
"(",
")",
";",
"$",
"this",
"->",
"getDatabaseStructureEvents",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'databases'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"databases",
"(",
"$",
"this",
"->",
"dbName",
")",
")",
";",
"}",
"// If there still are some tables/views in include-tables array,",
"// that means that some tables or views weren't found.",
"// Give proper error and exit.",
"// This check will be removed once include-tables supports regexps.",
"if",
"(",
"0",
"<",
"count",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'include-tables'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"this",
"->",
"dumpSettings",
"[",
"'include-tables'",
"]",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Table (\"",
".",
"$",
"name",
".",
"\") not found in database\"",
")",
";",
"}",
"$",
"this",
"->",
"exportTables",
"(",
")",
";",
"$",
"this",
"->",
"exportTriggers",
"(",
")",
";",
"$",
"this",
"->",
"exportViews",
"(",
")",
";",
"$",
"this",
"->",
"exportProcedures",
"(",
")",
";",
"$",
"this",
"->",
"exportEvents",
"(",
")",
";",
"// Restore saved parameters.",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"restore_parameters",
"(",
")",
")",
";",
"// Write some stats to output file.",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"getDumpFileFooter",
"(",
")",
")",
";",
"// Close output file.",
"$",
"this",
"->",
"compressManager",
"->",
"close",
"(",
")",
";",
"return",
";",
"}"
] | Primary function, triggers dumping.
@param string $filename Name of file to write sql dump to
@return null
@throws \Exception | [
"Primary",
"function",
"triggers",
"dumping",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L394-L465 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getDumpFileHeader | private function getDumpFileHeader()
{
$header = '';
if (!$this->dumpSettings['skip-comments']) {
// Some info about software, source and time
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php".PHP_EOL.
"--".PHP_EOL.
"-- Host: {$this->host}\tDatabase: {$this->dbName}".PHP_EOL.
"-- ------------------------------------------------------".PHP_EOL;
if (!empty($this->version)) {
$header .= "-- Server version \t".$this->version.PHP_EOL;
}
if (!$this->dumpSettings['skip-dump-date']) {
$header .= "-- Date: ".date('r').PHP_EOL.PHP_EOL;
}
}
return $header;
} | php | private function getDumpFileHeader()
{
$header = '';
if (!$this->dumpSettings['skip-comments']) {
// Some info about software, source and time
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php".PHP_EOL.
"--".PHP_EOL.
"-- Host: {$this->host}\tDatabase: {$this->dbName}".PHP_EOL.
"-- ------------------------------------------------------".PHP_EOL;
if (!empty($this->version)) {
$header .= "-- Server version \t".$this->version.PHP_EOL;
}
if (!$this->dumpSettings['skip-dump-date']) {
$header .= "-- Date: ".date('r').PHP_EOL.PHP_EOL;
}
}
return $header;
} | [
"private",
"function",
"getDumpFileHeader",
"(",
")",
"{",
"$",
"header",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"// Some info about software, source and time",
"$",
"header",
"=",
"\"-- mysqldump-php https://github.com/ifsnop/mysqldump-php\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- Host: {$this->host}\\tDatabase: {$this->dbName}\"",
".",
"PHP_EOL",
".",
"\"-- ------------------------------------------------------\"",
".",
"PHP_EOL",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"version",
")",
")",
"{",
"$",
"header",
".=",
"\"-- Server version \\t\"",
".",
"$",
"this",
"->",
"version",
".",
"PHP_EOL",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-dump-date'",
"]",
")",
"{",
"$",
"header",
".=",
"\"-- Date: \"",
".",
"date",
"(",
"'r'",
")",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"}",
"return",
"$",
"header",
";",
"}"
] | Returns header for dump file.
@return string | [
"Returns",
"header",
"for",
"dump",
"file",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L472-L491 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getDumpFileFooter | private function getDumpFileFooter()
{
$footer = '';
if (!$this->dumpSettings['skip-comments']) {
$footer .= '-- Dump completed';
if (!$this->dumpSettings['skip-dump-date']) {
$footer .= ' on: '.date('r');
}
$footer .= PHP_EOL;
}
return $footer;
} | php | private function getDumpFileFooter()
{
$footer = '';
if (!$this->dumpSettings['skip-comments']) {
$footer .= '-- Dump completed';
if (!$this->dumpSettings['skip-dump-date']) {
$footer .= ' on: '.date('r');
}
$footer .= PHP_EOL;
}
return $footer;
} | [
"private",
"function",
"getDumpFileFooter",
"(",
")",
"{",
"$",
"footer",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"footer",
".=",
"'-- Dump completed'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-dump-date'",
"]",
")",
"{",
"$",
"footer",
".=",
"' on: '",
".",
"date",
"(",
"'r'",
")",
";",
"}",
"$",
"footer",
".=",
"PHP_EOL",
";",
"}",
"return",
"$",
"footer",
";",
"}"
] | Returns footer for dump file.
@return string | [
"Returns",
"footer",
"for",
"dump",
"file",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L498-L510 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.exportTables | private function exportTables()
{
// Exporting tables one by one
foreach ($this->tables as $table) {
if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->getTableStructure($table);
if (false === $this->dumpSettings['no-data']) { // don't break compatibility with old trigger
$this->listValues($table);
} elseif (true === $this->dumpSettings['no-data']
|| $this->matches($table, $this->dumpSettings['no-data'])) {
continue;
} else {
$this->listValues($table);
}
}
} | php | private function exportTables()
{
// Exporting tables one by one
foreach ($this->tables as $table) {
if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->getTableStructure($table);
if (false === $this->dumpSettings['no-data']) { // don't break compatibility with old trigger
$this->listValues($table);
} elseif (true === $this->dumpSettings['no-data']
|| $this->matches($table, $this->dumpSettings['no-data'])) {
continue;
} else {
$this->listValues($table);
}
}
} | [
"private",
"function",
"exportTables",
"(",
")",
"{",
"// Exporting tables one by one",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matches",
"(",
"$",
"table",
",",
"$",
"this",
"->",
"dumpSettings",
"[",
"'exclude-tables'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"getTableStructure",
"(",
"$",
"table",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-data'",
"]",
")",
"{",
"// don't break compatibility with old trigger",
"$",
"this",
"->",
"listValues",
"(",
"$",
"table",
")",
";",
"}",
"elseif",
"(",
"true",
"===",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-data'",
"]",
"||",
"$",
"this",
"->",
"matches",
"(",
"$",
"table",
",",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-data'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"listValues",
"(",
"$",
"table",
")",
";",
"}",
"}",
"}"
] | Exports all the tables selected from database
@return null | [
"Exports",
"all",
"the",
"tables",
"selected",
"from",
"database"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L650-L667 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.exportViews | private function exportViews()
{
if (false === $this->dumpSettings['no-create-info']) {
// Exporting views one by one
foreach ($this->views as $view) {
if ($this->matches($view, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->tableColumnTypes[$view] = $this->getTableColumnTypes($view);
$this->getViewStructureTable($view);
}
foreach ($this->views as $view) {
if ($this->matches($view, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->getViewStructureView($view);
}
}
} | php | private function exportViews()
{
if (false === $this->dumpSettings['no-create-info']) {
// Exporting views one by one
foreach ($this->views as $view) {
if ($this->matches($view, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->tableColumnTypes[$view] = $this->getTableColumnTypes($view);
$this->getViewStructureTable($view);
}
foreach ($this->views as $view) {
if ($this->matches($view, $this->dumpSettings['exclude-tables'])) {
continue;
}
$this->getViewStructureView($view);
}
}
} | [
"private",
"function",
"exportViews",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-create-info'",
"]",
")",
"{",
"// Exporting views one by one",
"foreach",
"(",
"$",
"this",
"->",
"views",
"as",
"$",
"view",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matches",
"(",
"$",
"view",
",",
"$",
"this",
"->",
"dumpSettings",
"[",
"'exclude-tables'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"view",
"]",
"=",
"$",
"this",
"->",
"getTableColumnTypes",
"(",
"$",
"view",
")",
";",
"$",
"this",
"->",
"getViewStructureTable",
"(",
"$",
"view",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"views",
"as",
"$",
"view",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matches",
"(",
"$",
"view",
",",
"$",
"this",
"->",
"dumpSettings",
"[",
"'exclude-tables'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"getViewStructureView",
"(",
"$",
"view",
")",
";",
"}",
"}",
"}"
] | Exports all the views found in database
@return null | [
"Exports",
"all",
"the",
"views",
"found",
"in",
"database"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L674-L692 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getTableStructure | private function getTableStructure($tableName)
{
if (!$this->dumpSettings['no-create-info']) {
$ret = '';
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Table structure for table `$tableName`".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
}
$stmt = $this->typeAdapter->show_create_table($tableName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write($ret);
if ($this->dumpSettings['add-drop-table']) {
$this->compressManager->write(
$this->typeAdapter->drop_table($tableName)
);
}
$this->compressManager->write(
$this->typeAdapter->create_table($r)
);
break;
}
}
$this->tableColumnTypes[$tableName] = $this->getTableColumnTypes($tableName);
return;
} | php | private function getTableStructure($tableName)
{
if (!$this->dumpSettings['no-create-info']) {
$ret = '';
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Table structure for table `$tableName`".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
}
$stmt = $this->typeAdapter->show_create_table($tableName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write($ret);
if ($this->dumpSettings['add-drop-table']) {
$this->compressManager->write(
$this->typeAdapter->drop_table($tableName)
);
}
$this->compressManager->write(
$this->typeAdapter->create_table($r)
);
break;
}
}
$this->tableColumnTypes[$tableName] = $this->getTableColumnTypes($tableName);
return;
} | [
"private",
"function",
"getTableStructure",
"(",
"$",
"tableName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-create-info'",
"]",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"ret",
"=",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- Table structure for table `$tableName`\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_create_table",
"(",
"$",
"tableName",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
"as",
"$",
"r",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"ret",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'add-drop-table'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"drop_table",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"create_table",
"(",
"$",
"r",
")",
")",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"tableName",
"]",
"=",
"$",
"this",
"->",
"getTableColumnTypes",
"(",
"$",
"tableName",
")",
";",
"return",
";",
"}"
] | Table structure extractor
@todo move specific mysql code to typeAdapter
@param string $tableName Name of table to export
@return null | [
"Table",
"structure",
"extractor"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L740-L765 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getTableColumnTypes | private function getTableColumnTypes($tableName)
{
$columnTypes = array();
$columns = $this->dbHandler->query(
$this->typeAdapter->show_columns($tableName)
);
$columns->setFetchMode(PDO::FETCH_ASSOC);
foreach ($columns as $key => $col) {
$types = $this->typeAdapter->parseColumnType($col);
$columnTypes[$col['Field']] = array(
'is_numeric'=> $types['is_numeric'],
'is_blob' => $types['is_blob'],
'type' => $types['type'],
'type_sql' => $col['Type'],
'is_virtual' => $types['is_virtual']
);
}
return $columnTypes;
} | php | private function getTableColumnTypes($tableName)
{
$columnTypes = array();
$columns = $this->dbHandler->query(
$this->typeAdapter->show_columns($tableName)
);
$columns->setFetchMode(PDO::FETCH_ASSOC);
foreach ($columns as $key => $col) {
$types = $this->typeAdapter->parseColumnType($col);
$columnTypes[$col['Field']] = array(
'is_numeric'=> $types['is_numeric'],
'is_blob' => $types['is_blob'],
'type' => $types['type'],
'type_sql' => $col['Type'],
'is_virtual' => $types['is_virtual']
);
}
return $columnTypes;
} | [
"private",
"function",
"getTableColumnTypes",
"(",
"$",
"tableName",
")",
"{",
"$",
"columnTypes",
"=",
"array",
"(",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_columns",
"(",
"$",
"tableName",
")",
")",
";",
"$",
"columns",
"->",
"setFetchMode",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"col",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"parseColumnType",
"(",
"$",
"col",
")",
";",
"$",
"columnTypes",
"[",
"$",
"col",
"[",
"'Field'",
"]",
"]",
"=",
"array",
"(",
"'is_numeric'",
"=>",
"$",
"types",
"[",
"'is_numeric'",
"]",
",",
"'is_blob'",
"=>",
"$",
"types",
"[",
"'is_blob'",
"]",
",",
"'type'",
"=>",
"$",
"types",
"[",
"'type'",
"]",
",",
"'type_sql'",
"=>",
"$",
"col",
"[",
"'Type'",
"]",
",",
"'is_virtual'",
"=>",
"$",
"types",
"[",
"'is_virtual'",
"]",
")",
";",
"}",
"return",
"$",
"columnTypes",
";",
"}"
] | Store column types to create data dumps and for Stand-In tables
@param string $tableName Name of table to export
@return array type column types detailed | [
"Store",
"column",
"types",
"to",
"create",
"data",
"dumps",
"and",
"for",
"Stand",
"-",
"In",
"tables"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L774-L794 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.createStandInTable | public function createStandInTable($viewName)
{
$ret = array();
foreach ($this->tableColumnTypes[$viewName] as $k => $v) {
$ret[] = "`${k}` ${v['type_sql']}";
}
$ret = implode(PHP_EOL.",", $ret);
$ret = "CREATE TABLE IF NOT EXISTS `$viewName` (".
PHP_EOL.$ret.PHP_EOL.");".PHP_EOL;
return $ret;
} | php | public function createStandInTable($viewName)
{
$ret = array();
foreach ($this->tableColumnTypes[$viewName] as $k => $v) {
$ret[] = "`${k}` ${v['type_sql']}";
}
$ret = implode(PHP_EOL.",", $ret);
$ret = "CREATE TABLE IF NOT EXISTS `$viewName` (".
PHP_EOL.$ret.PHP_EOL.");".PHP_EOL;
return $ret;
} | [
"public",
"function",
"createStandInTable",
"(",
"$",
"viewName",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"viewName",
"]",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"\"`${k}` ${v['type_sql']}\"",
";",
"}",
"$",
"ret",
"=",
"implode",
"(",
"PHP_EOL",
".",
"\",\"",
",",
"$",
"ret",
")",
";",
"$",
"ret",
"=",
"\"CREATE TABLE IF NOT EXISTS `$viewName` (\"",
".",
"PHP_EOL",
".",
"$",
"ret",
".",
"PHP_EOL",
".",
"\");\"",
".",
"PHP_EOL",
";",
"return",
"$",
"ret",
";",
"}"
] | Write a create table statement for the table Stand-In, show create
table would return a create algorithm when used on a view
@param string $viewName Name of view to export
@return string create statement | [
"Write",
"a",
"create",
"table",
"statement",
"for",
"the",
"table",
"Stand",
"-",
"In",
"show",
"create",
"table",
"would",
"return",
"a",
"create",
"algorithm",
"when",
"used",
"on",
"a",
"view"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L835-L847 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getViewStructureView | private function getViewStructureView($viewName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- View structure for view `${viewName}`".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_view($viewName);
// create views, to resolve dependencies
// replacing tables with views
foreach ($this->dbHandler->query($stmt) as $r) {
// because we must replace table with view, we should delete it
$this->compressManager->write(
$this->typeAdapter->drop_view($viewName)
);
$this->compressManager->write(
$this->typeAdapter->create_view($r)
);
break;
}
} | php | private function getViewStructureView($viewName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- View structure for view `${viewName}`".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_view($viewName);
// create views, to resolve dependencies
// replacing tables with views
foreach ($this->dbHandler->query($stmt) as $r) {
// because we must replace table with view, we should delete it
$this->compressManager->write(
$this->typeAdapter->drop_view($viewName)
);
$this->compressManager->write(
$this->typeAdapter->create_view($r)
);
break;
}
} | [
"private",
"function",
"getViewStructureView",
"(",
"$",
"viewName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"ret",
"=",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- View structure for view `${viewName}`\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"ret",
")",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_create_view",
"(",
"$",
"viewName",
")",
";",
"// create views, to resolve dependencies",
"// replacing tables with views",
"foreach",
"(",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
"as",
"$",
"r",
")",
"{",
"// because we must replace table with view, we should delete it",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"drop_view",
"(",
"$",
"viewName",
")",
")",
";",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"create_view",
"(",
"$",
"r",
")",
")",
";",
"break",
";",
"}",
"}"
] | View structure extractor, create view
@todo move mysql specific code to typeAdapter
@param string $viewName Name of view to export
@return null | [
"View",
"structure",
"extractor",
"create",
"view"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L856-L878 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getTriggerStructure | private function getTriggerStructure($triggerName)
{
$stmt = $this->typeAdapter->show_create_trigger($triggerName);
foreach ($this->dbHandler->query($stmt) as $r) {
if ($this->dumpSettings['add-drop-trigger']) {
$this->compressManager->write(
$this->typeAdapter->add_drop_trigger($triggerName)
);
}
$this->compressManager->write(
$this->typeAdapter->create_trigger($r)
);
return;
}
} | php | private function getTriggerStructure($triggerName)
{
$stmt = $this->typeAdapter->show_create_trigger($triggerName);
foreach ($this->dbHandler->query($stmt) as $r) {
if ($this->dumpSettings['add-drop-trigger']) {
$this->compressManager->write(
$this->typeAdapter->add_drop_trigger($triggerName)
);
}
$this->compressManager->write(
$this->typeAdapter->create_trigger($r)
);
return;
}
} | [
"private",
"function",
"getTriggerStructure",
"(",
"$",
"triggerName",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_create_trigger",
"(",
"$",
"triggerName",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'add-drop-trigger'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"add_drop_trigger",
"(",
"$",
"triggerName",
")",
")",
";",
"}",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"create_trigger",
"(",
"$",
"r",
")",
")",
";",
"return",
";",
"}",
"}"
] | Trigger structure extractor
@param string $triggerName Name of trigger to export
@return null | [
"Trigger",
"structure",
"extractor"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L886-L900 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getProcedureStructure | private function getProcedureStructure($procedureName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Dumping routines for database '".$this->dbName."'".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_procedure($procedureName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write(
$this->typeAdapter->create_procedure($r)
);
return;
}
} | php | private function getProcedureStructure($procedureName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Dumping routines for database '".$this->dbName."'".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_procedure($procedureName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write(
$this->typeAdapter->create_procedure($r)
);
return;
}
} | [
"private",
"function",
"getProcedureStructure",
"(",
"$",
"procedureName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"ret",
"=",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- Dumping routines for database '\"",
".",
"$",
"this",
"->",
"dbName",
".",
"\"'\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"ret",
")",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_create_procedure",
"(",
"$",
"procedureName",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
"as",
"$",
"r",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"create_procedure",
"(",
"$",
"r",
")",
")",
";",
"return",
";",
"}",
"}"
] | Procedure structure extractor
@param string $procedureName Name of procedure to export
@return null | [
"Procedure",
"structure",
"extractor"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L908-L923 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getEventStructure | private function getEventStructure($eventName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Dumping events for database '".$this->dbName."'".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_event($eventName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write(
$this->typeAdapter->create_event($r)
);
return;
}
} | php | private function getEventStructure($eventName)
{
if (!$this->dumpSettings['skip-comments']) {
$ret = "--".PHP_EOL.
"-- Dumping events for database '".$this->dbName."'".PHP_EOL.
"--".PHP_EOL.PHP_EOL;
$this->compressManager->write($ret);
}
$stmt = $this->typeAdapter->show_create_event($eventName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write(
$this->typeAdapter->create_event($r)
);
return;
}
} | [
"private",
"function",
"getEventStructure",
"(",
"$",
"eventName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"ret",
"=",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- Dumping events for database '\"",
".",
"$",
"this",
"->",
"dbName",
".",
"\"'\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"ret",
")",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"typeAdapter",
"->",
"show_create_event",
"(",
"$",
"eventName",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
"as",
"$",
"r",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"create_event",
"(",
"$",
"r",
")",
")",
";",
"return",
";",
"}",
"}"
] | Event structure extractor
@param string $eventName Name of event to export
@return null | [
"Event",
"structure",
"extractor"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L931-L946 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.prepareColumnValues | private function prepareColumnValues($tableName, $row)
{
$ret = array();
$columnTypes = $this->tableColumnTypes[$tableName];
foreach ($row as $colName => $colValue) {
$colValue = $this->hookTransformColumnValue($tableName, $colName, $colValue, $row);
$ret[] = $this->escape($colValue, $columnTypes[$colName]);
}
return $ret;
} | php | private function prepareColumnValues($tableName, $row)
{
$ret = array();
$columnTypes = $this->tableColumnTypes[$tableName];
foreach ($row as $colName => $colValue) {
$colValue = $this->hookTransformColumnValue($tableName, $colName, $colValue, $row);
$ret[] = $this->escape($colValue, $columnTypes[$colName]);
}
return $ret;
} | [
"private",
"function",
"prepareColumnValues",
"(",
"$",
"tableName",
",",
"$",
"row",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"columnTypes",
"=",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"tableName",
"]",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"colName",
"=>",
"$",
"colValue",
")",
"{",
"$",
"colValue",
"=",
"$",
"this",
"->",
"hookTransformColumnValue",
"(",
"$",
"tableName",
",",
"$",
"colName",
",",
"$",
"colValue",
",",
"$",
"row",
")",
";",
"$",
"ret",
"[",
"]",
"=",
"$",
"this",
"->",
"escape",
"(",
"$",
"colValue",
",",
"$",
"columnTypes",
"[",
"$",
"colName",
"]",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Prepare values for output
@param string $tableName Name of table which contains rows
@param array $row Associative array of column names and values to be
quoted
@return array | [
"Prepare",
"values",
"for",
"output"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L957-L967 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.escape | private function escape($colValue, $colType)
{
if (is_null($colValue)) {
return "NULL";
} elseif ($this->dumpSettings['hex-blob'] && $colType['is_blob']) {
if ($colType['type'] == 'bit' || !empty($colValue)) {
return "0x${colValue}";
} else {
return "''";
}
} elseif ($colType['is_numeric']) {
return $colValue;
}
return $this->dbHandler->quote($colValue);
} | php | private function escape($colValue, $colType)
{
if (is_null($colValue)) {
return "NULL";
} elseif ($this->dumpSettings['hex-blob'] && $colType['is_blob']) {
if ($colType['type'] == 'bit' || !empty($colValue)) {
return "0x${colValue}";
} else {
return "''";
}
} elseif ($colType['is_numeric']) {
return $colValue;
}
return $this->dbHandler->quote($colValue);
} | [
"private",
"function",
"escape",
"(",
"$",
"colValue",
",",
"$",
"colType",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"colValue",
")",
")",
"{",
"return",
"\"NULL\"",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'hex-blob'",
"]",
"&&",
"$",
"colType",
"[",
"'is_blob'",
"]",
")",
"{",
"if",
"(",
"$",
"colType",
"[",
"'type'",
"]",
"==",
"'bit'",
"||",
"!",
"empty",
"(",
"$",
"colValue",
")",
")",
"{",
"return",
"\"0x${colValue}\"",
";",
"}",
"else",
"{",
"return",
"\"''\"",
";",
"}",
"}",
"elseif",
"(",
"$",
"colType",
"[",
"'is_numeric'",
"]",
")",
"{",
"return",
"$",
"colValue",
";",
"}",
"return",
"$",
"this",
"->",
"dbHandler",
"->",
"quote",
"(",
"$",
"colValue",
")",
";",
"}"
] | Escape values with quotes when needed
@param string $tableName Name of table which contains rows
@param array $row Associative array of column names and values to be quoted
@return string | [
"Escape",
"values",
"with",
"quotes",
"when",
"needed"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L977-L992 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.hookTransformColumnValue | protected function hookTransformColumnValue($tableName, $colName, $colValue, $row)
{
if (!$this->transformColumnValueCallable) {
return $colValue;
}
return call_user_func_array($this->transformColumnValueCallable, array(
$tableName,
$colName,
$colValue,
$row
));
} | php | protected function hookTransformColumnValue($tableName, $colName, $colValue, $row)
{
if (!$this->transformColumnValueCallable) {
return $colValue;
}
return call_user_func_array($this->transformColumnValueCallable, array(
$tableName,
$colName,
$colValue,
$row
));
} | [
"protected",
"function",
"hookTransformColumnValue",
"(",
"$",
"tableName",
",",
"$",
"colName",
",",
"$",
"colValue",
",",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"transformColumnValueCallable",
")",
"{",
"return",
"$",
"colValue",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"transformColumnValueCallable",
",",
"array",
"(",
"$",
"tableName",
",",
"$",
"colName",
",",
"$",
"colValue",
",",
"$",
"row",
")",
")",
";",
"}"
] | Give extending classes an opportunity to transform column values
@param string $tableName Name of table which contains rows
@param string $colName Name of the column in question
@param string $colValue Value of the column in question
@return string | [
"Give",
"extending",
"classes",
"an",
"opportunity",
"to",
"transform",
"column",
"values"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1015-L1027 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.listValues | private function listValues($tableName)
{
$this->prepareListValues($tableName);
$onlyOnce = true;
$lineSize = 0;
// colStmt is used to form a query to obtain row values
$colStmt = $this->getColumnStmt($tableName);
// colNames is used to get the name of the columns when using complete-insert
if ($this->dumpSettings['complete-insert']) {
$colNames = $this->getColumnNames($tableName);
}
$stmt = "SELECT ".implode(",", $colStmt)." FROM `$tableName`";
// Table specific conditions override the default 'where'
$condition = $this->getTableWhere($tableName);
if ($condition) {
$stmt .= " WHERE {$condition}";
}
$limit = $this->getTableLimit($tableName);
if ($limit) {
$stmt .= " LIMIT {$limit}";
}
$resultSet = $this->dbHandler->query($stmt);
$resultSet->setFetchMode(PDO::FETCH_ASSOC);
$ignore = $this->dumpSettings['insert-ignore'] ? ' IGNORE' : '';
$count = 0;
foreach ($resultSet as $row) {
$count++;
$vals = $this->prepareColumnValues($tableName, $row);
if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
if ($this->dumpSettings['complete-insert']) {
$lineSize += $this->compressManager->write(
"INSERT$ignore INTO `$tableName` (".
implode(", ", $colNames).
") VALUES (".implode(",", $vals).")"
);
} else {
$lineSize += $this->compressManager->write(
"INSERT$ignore INTO `$tableName` VALUES (".implode(",", $vals).")"
);
}
$onlyOnce = false;
} else {
$lineSize += $this->compressManager->write(",(".implode(",", $vals).")");
}
if (($lineSize > $this->dumpSettings['net_buffer_length']) ||
!$this->dumpSettings['extended-insert']) {
$onlyOnce = true;
$lineSize = $this->compressManager->write(";".PHP_EOL);
}
}
$resultSet->closeCursor();
if (!$onlyOnce) {
$this->compressManager->write(";".PHP_EOL);
}
$this->endListValues($tableName, $count);
} | php | private function listValues($tableName)
{
$this->prepareListValues($tableName);
$onlyOnce = true;
$lineSize = 0;
// colStmt is used to form a query to obtain row values
$colStmt = $this->getColumnStmt($tableName);
// colNames is used to get the name of the columns when using complete-insert
if ($this->dumpSettings['complete-insert']) {
$colNames = $this->getColumnNames($tableName);
}
$stmt = "SELECT ".implode(",", $colStmt)." FROM `$tableName`";
// Table specific conditions override the default 'where'
$condition = $this->getTableWhere($tableName);
if ($condition) {
$stmt .= " WHERE {$condition}";
}
$limit = $this->getTableLimit($tableName);
if ($limit) {
$stmt .= " LIMIT {$limit}";
}
$resultSet = $this->dbHandler->query($stmt);
$resultSet->setFetchMode(PDO::FETCH_ASSOC);
$ignore = $this->dumpSettings['insert-ignore'] ? ' IGNORE' : '';
$count = 0;
foreach ($resultSet as $row) {
$count++;
$vals = $this->prepareColumnValues($tableName, $row);
if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
if ($this->dumpSettings['complete-insert']) {
$lineSize += $this->compressManager->write(
"INSERT$ignore INTO `$tableName` (".
implode(", ", $colNames).
") VALUES (".implode(",", $vals).")"
);
} else {
$lineSize += $this->compressManager->write(
"INSERT$ignore INTO `$tableName` VALUES (".implode(",", $vals).")"
);
}
$onlyOnce = false;
} else {
$lineSize += $this->compressManager->write(",(".implode(",", $vals).")");
}
if (($lineSize > $this->dumpSettings['net_buffer_length']) ||
!$this->dumpSettings['extended-insert']) {
$onlyOnce = true;
$lineSize = $this->compressManager->write(";".PHP_EOL);
}
}
$resultSet->closeCursor();
if (!$onlyOnce) {
$this->compressManager->write(";".PHP_EOL);
}
$this->endListValues($tableName, $count);
} | [
"private",
"function",
"listValues",
"(",
"$",
"tableName",
")",
"{",
"$",
"this",
"->",
"prepareListValues",
"(",
"$",
"tableName",
")",
";",
"$",
"onlyOnce",
"=",
"true",
";",
"$",
"lineSize",
"=",
"0",
";",
"// colStmt is used to form a query to obtain row values",
"$",
"colStmt",
"=",
"$",
"this",
"->",
"getColumnStmt",
"(",
"$",
"tableName",
")",
";",
"// colNames is used to get the name of the columns when using complete-insert",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'complete-insert'",
"]",
")",
"{",
"$",
"colNames",
"=",
"$",
"this",
"->",
"getColumnNames",
"(",
"$",
"tableName",
")",
";",
"}",
"$",
"stmt",
"=",
"\"SELECT \"",
".",
"implode",
"(",
"\",\"",
",",
"$",
"colStmt",
")",
".",
"\" FROM `$tableName`\"",
";",
"// Table specific conditions override the default 'where'",
"$",
"condition",
"=",
"$",
"this",
"->",
"getTableWhere",
"(",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"condition",
")",
"{",
"$",
"stmt",
".=",
"\" WHERE {$condition}\"",
";",
"}",
"$",
"limit",
"=",
"$",
"this",
"->",
"getTableLimit",
"(",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"stmt",
".=",
"\" LIMIT {$limit}\"",
";",
"}",
"$",
"resultSet",
"=",
"$",
"this",
"->",
"dbHandler",
"->",
"query",
"(",
"$",
"stmt",
")",
";",
"$",
"resultSet",
"->",
"setFetchMode",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"ignore",
"=",
"$",
"this",
"->",
"dumpSettings",
"[",
"'insert-ignore'",
"]",
"?",
"' IGNORE'",
":",
"''",
";",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"resultSet",
"as",
"$",
"row",
")",
"{",
"$",
"count",
"++",
";",
"$",
"vals",
"=",
"$",
"this",
"->",
"prepareColumnValues",
"(",
"$",
"tableName",
",",
"$",
"row",
")",
";",
"if",
"(",
"$",
"onlyOnce",
"||",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'extended-insert'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'complete-insert'",
"]",
")",
"{",
"$",
"lineSize",
"+=",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\"INSERT$ignore INTO `$tableName` (\"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"colNames",
")",
".",
"\") VALUES (\"",
".",
"implode",
"(",
"\",\"",
",",
"$",
"vals",
")",
".",
"\")\"",
")",
";",
"}",
"else",
"{",
"$",
"lineSize",
"+=",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\"INSERT$ignore INTO `$tableName` VALUES (\"",
".",
"implode",
"(",
"\",\"",
",",
"$",
"vals",
")",
".",
"\")\"",
")",
";",
"}",
"$",
"onlyOnce",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"lineSize",
"+=",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\",(\"",
".",
"implode",
"(",
"\",\"",
",",
"$",
"vals",
")",
".",
"\")\"",
")",
";",
"}",
"if",
"(",
"(",
"$",
"lineSize",
">",
"$",
"this",
"->",
"dumpSettings",
"[",
"'net_buffer_length'",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'extended-insert'",
"]",
")",
"{",
"$",
"onlyOnce",
"=",
"true",
";",
"$",
"lineSize",
"=",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\";\"",
".",
"PHP_EOL",
")",
";",
"}",
"}",
"$",
"resultSet",
"->",
"closeCursor",
"(",
")",
";",
"if",
"(",
"!",
"$",
"onlyOnce",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\";\"",
".",
"PHP_EOL",
")",
";",
"}",
"$",
"this",
"->",
"endListValues",
"(",
"$",
"tableName",
",",
"$",
"count",
")",
";",
"}"
] | Table rows extractor
@param string $tableName Name of table to export
@return null | [
"Table",
"rows",
"extractor"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1036-L1103 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.prepareListValues | public function prepareListValues($tableName)
{
if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"--".PHP_EOL.
"-- Dumping data for table `$tableName`".PHP_EOL.
"--".PHP_EOL.PHP_EOL
);
}
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
$this->dbHandler->exec($this->typeAdapter->start_transaction());
}
if ($this->dumpSettings['lock-tables']) {
$this->typeAdapter->lock_table($tableName);
}
if ($this->dumpSettings['add-locks']) {
$this->compressManager->write(
$this->typeAdapter->start_add_lock_table($tableName)
);
}
if ($this->dumpSettings['disable-keys']) {
$this->compressManager->write(
$this->typeAdapter->start_add_disable_keys($tableName)
);
}
// Disable autocommit for faster reload
if ($this->dumpSettings['no-autocommit']) {
$this->compressManager->write(
$this->typeAdapter->start_disable_autocommit()
);
}
return;
} | php | public function prepareListValues($tableName)
{
if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"--".PHP_EOL.
"-- Dumping data for table `$tableName`".PHP_EOL.
"--".PHP_EOL.PHP_EOL
);
}
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
$this->dbHandler->exec($this->typeAdapter->start_transaction());
}
if ($this->dumpSettings['lock-tables']) {
$this->typeAdapter->lock_table($tableName);
}
if ($this->dumpSettings['add-locks']) {
$this->compressManager->write(
$this->typeAdapter->start_add_lock_table($tableName)
);
}
if ($this->dumpSettings['disable-keys']) {
$this->compressManager->write(
$this->typeAdapter->start_add_disable_keys($tableName)
);
}
// Disable autocommit for faster reload
if ($this->dumpSettings['no-autocommit']) {
$this->compressManager->write(
$this->typeAdapter->start_disable_autocommit()
);
}
return;
} | [
"public",
"function",
"prepareListValues",
"(",
"$",
"tableName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\"--\"",
".",
"PHP_EOL",
".",
"\"-- Dumping data for table `$tableName`\"",
".",
"PHP_EOL",
".",
"\"--\"",
".",
"PHP_EOL",
".",
"PHP_EOL",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'single-transaction'",
"]",
")",
"{",
"$",
"this",
"->",
"dbHandler",
"->",
"exec",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"setup_transaction",
"(",
")",
")",
";",
"$",
"this",
"->",
"dbHandler",
"->",
"exec",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"start_transaction",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'lock-tables'",
"]",
")",
"{",
"$",
"this",
"->",
"typeAdapter",
"->",
"lock_table",
"(",
"$",
"tableName",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'add-locks'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"start_add_lock_table",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'disable-keys'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"start_add_disable_keys",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"// Disable autocommit for faster reload",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-autocommit'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"start_disable_autocommit",
"(",
")",
")",
";",
"}",
"return",
";",
"}"
] | Table rows extractor, append information prior to dump
@param string $tableName Name of table to export
@return null | [
"Table",
"rows",
"extractor",
"append",
"information",
"prior",
"to",
"dump"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1112-L1151 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.endListValues | public function endListValues($tableName, $count = 0)
{
if ($this->dumpSettings['disable-keys']) {
$this->compressManager->write(
$this->typeAdapter->end_add_disable_keys($tableName)
);
}
if ($this->dumpSettings['add-locks']) {
$this->compressManager->write(
$this->typeAdapter->end_add_lock_table($tableName)
);
}
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->commit_transaction());
}
if ($this->dumpSettings['lock-tables']) {
$this->typeAdapter->unlock_table($tableName);
}
// Commit to enable autocommit
if ($this->dumpSettings['no-autocommit']) {
$this->compressManager->write(
$this->typeAdapter->end_disable_autocommit()
);
}
$this->compressManager->write(PHP_EOL);
if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"-- Dumped table `".$tableName."` with $count row(s)".PHP_EOL.
'--'.PHP_EOL.PHP_EOL
);
}
return;
} | php | public function endListValues($tableName, $count = 0)
{
if ($this->dumpSettings['disable-keys']) {
$this->compressManager->write(
$this->typeAdapter->end_add_disable_keys($tableName)
);
}
if ($this->dumpSettings['add-locks']) {
$this->compressManager->write(
$this->typeAdapter->end_add_lock_table($tableName)
);
}
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->commit_transaction());
}
if ($this->dumpSettings['lock-tables']) {
$this->typeAdapter->unlock_table($tableName);
}
// Commit to enable autocommit
if ($this->dumpSettings['no-autocommit']) {
$this->compressManager->write(
$this->typeAdapter->end_disable_autocommit()
);
}
$this->compressManager->write(PHP_EOL);
if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"-- Dumped table `".$tableName."` with $count row(s)".PHP_EOL.
'--'.PHP_EOL.PHP_EOL
);
}
return;
} | [
"public",
"function",
"endListValues",
"(",
"$",
"tableName",
",",
"$",
"count",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'disable-keys'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"end_add_disable_keys",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'add-locks'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"end_add_lock_table",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'single-transaction'",
"]",
")",
"{",
"$",
"this",
"->",
"dbHandler",
"->",
"exec",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"commit_transaction",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'lock-tables'",
"]",
")",
"{",
"$",
"this",
"->",
"typeAdapter",
"->",
"unlock_table",
"(",
"$",
"tableName",
")",
";",
"}",
"// Commit to enable autocommit",
"if",
"(",
"$",
"this",
"->",
"dumpSettings",
"[",
"'no-autocommit'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"$",
"this",
"->",
"typeAdapter",
"->",
"end_disable_autocommit",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"PHP_EOL",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"dumpSettings",
"[",
"'skip-comments'",
"]",
")",
"{",
"$",
"this",
"->",
"compressManager",
"->",
"write",
"(",
"\"-- Dumped table `\"",
".",
"$",
"tableName",
".",
"\"` with $count row(s)\"",
".",
"PHP_EOL",
".",
"'--'",
".",
"PHP_EOL",
".",
"PHP_EOL",
")",
";",
"}",
"return",
";",
"}"
] | Table rows extractor, close locks and commits after dump
@param string $tableName Name of table to export.
@param integer $count Number of rows inserted.
@return void | [
"Table",
"rows",
"extractor",
"close",
"locks",
"and",
"commits",
"after",
"dump"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1161-L1200 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getColumnStmt | public function getColumnStmt($tableName)
{
$colStmt = array();
foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
$colStmt[] = "LPAD(HEX(`${colName}`),2,'0') AS `${colName}`";
} elseif ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
} elseif ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colStmt[] = "`${colName}`";
}
}
return $colStmt;
} | php | public function getColumnStmt($tableName)
{
$colStmt = array();
foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
$colStmt[] = "LPAD(HEX(`${colName}`),2,'0') AS `${colName}`";
} elseif ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
} elseif ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colStmt[] = "`${colName}`";
}
}
return $colStmt;
} | [
"public",
"function",
"getColumnStmt",
"(",
"$",
"tableName",
")",
"{",
"$",
"colStmt",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"tableName",
"]",
"as",
"$",
"colName",
"=>",
"$",
"colType",
")",
"{",
"if",
"(",
"$",
"colType",
"[",
"'type'",
"]",
"==",
"'bit'",
"&&",
"$",
"this",
"->",
"dumpSettings",
"[",
"'hex-blob'",
"]",
")",
"{",
"$",
"colStmt",
"[",
"]",
"=",
"\"LPAD(HEX(`${colName}`),2,'0') AS `${colName}`\"",
";",
"}",
"elseif",
"(",
"$",
"colType",
"[",
"'is_blob'",
"]",
"&&",
"$",
"this",
"->",
"dumpSettings",
"[",
"'hex-blob'",
"]",
")",
"{",
"$",
"colStmt",
"[",
"]",
"=",
"\"HEX(`${colName}`) AS `${colName}`\"",
";",
"}",
"elseif",
"(",
"$",
"colType",
"[",
"'is_virtual'",
"]",
")",
"{",
"$",
"this",
"->",
"dumpSettings",
"[",
"'complete-insert'",
"]",
"=",
"true",
";",
"continue",
";",
"}",
"else",
"{",
"$",
"colStmt",
"[",
"]",
"=",
"\"`${colName}`\"",
";",
"}",
"}",
"return",
"$",
"colStmt",
";",
"}"
] | Build SQL List of all columns on current table which will be used for selecting
@param string $tableName Name of table to get columns
@return array SQL sentence with columns for select | [
"Build",
"SQL",
"List",
"of",
"all",
"columns",
"on",
"current",
"table",
"which",
"will",
"be",
"used",
"for",
"selecting"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1209-L1226 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | Mysqldump.getColumnNames | public function getColumnNames($tableName)
{
$colNames = array();
foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colNames[] = "`${colName}`";
}
}
return $colNames;
} | php | public function getColumnNames($tableName)
{
$colNames = array();
foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colNames[] = "`${colName}`";
}
}
return $colNames;
} | [
"public",
"function",
"getColumnNames",
"(",
"$",
"tableName",
")",
"{",
"$",
"colNames",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tableColumnTypes",
"[",
"$",
"tableName",
"]",
"as",
"$",
"colName",
"=>",
"$",
"colType",
")",
"{",
"if",
"(",
"$",
"colType",
"[",
"'is_virtual'",
"]",
")",
"{",
"$",
"this",
"->",
"dumpSettings",
"[",
"'complete-insert'",
"]",
"=",
"true",
";",
"continue",
";",
"}",
"else",
"{",
"$",
"colNames",
"[",
"]",
"=",
"\"`${colName}`\"",
";",
"}",
"}",
"return",
"$",
"colNames",
";",
"}"
] | Build SQL List of all columns on current table which will be used for inserting
@param string $tableName Name of table to get columns
@return array columns for sql sentence for insert | [
"Build",
"SQL",
"List",
"of",
"all",
"columns",
"on",
"current",
"table",
"which",
"will",
"be",
"used",
"for",
"inserting"
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L1235-L1247 | train |
ifsnop/mysqldump-php | src/Ifsnop/Mysqldump/Mysqldump.php | TypeAdapterMysql.parseColumnType | public function parseColumnType($colType)
{
$colInfo = array();
$colParts = explode(" ", $colType['Type']);
if ($fparen = strpos($colParts[0], "(")) {
$colInfo['type'] = substr($colParts[0], 0, $fparen);
$colInfo['length'] = str_replace(")", "", substr($colParts[0], $fparen + 1));
$colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : null;
} else {
$colInfo['type'] = $colParts[0];
}
$colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
$colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
// for virtual columns that are of type 'Extra', column type
// could by "STORED GENERATED" or "VIRTUAL GENERATED"
// MySQL reference: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
$colInfo['is_virtual'] = strpos($colType['Extra'], "VIRTUAL GENERATED") !== false || strpos($colType['Extra'], "STORED GENERATED") !== false;
return $colInfo;
} | php | public function parseColumnType($colType)
{
$colInfo = array();
$colParts = explode(" ", $colType['Type']);
if ($fparen = strpos($colParts[0], "(")) {
$colInfo['type'] = substr($colParts[0], 0, $fparen);
$colInfo['length'] = str_replace(")", "", substr($colParts[0], $fparen + 1));
$colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : null;
} else {
$colInfo['type'] = $colParts[0];
}
$colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
$colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
// for virtual columns that are of type 'Extra', column type
// could by "STORED GENERATED" or "VIRTUAL GENERATED"
// MySQL reference: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
$colInfo['is_virtual'] = strpos($colType['Extra'], "VIRTUAL GENERATED") !== false || strpos($colType['Extra'], "STORED GENERATED") !== false;
return $colInfo;
} | [
"public",
"function",
"parseColumnType",
"(",
"$",
"colType",
")",
"{",
"$",
"colInfo",
"=",
"array",
"(",
")",
";",
"$",
"colParts",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"colType",
"[",
"'Type'",
"]",
")",
";",
"if",
"(",
"$",
"fparen",
"=",
"strpos",
"(",
"$",
"colParts",
"[",
"0",
"]",
",",
"\"(\"",
")",
")",
"{",
"$",
"colInfo",
"[",
"'type'",
"]",
"=",
"substr",
"(",
"$",
"colParts",
"[",
"0",
"]",
",",
"0",
",",
"$",
"fparen",
")",
";",
"$",
"colInfo",
"[",
"'length'",
"]",
"=",
"str_replace",
"(",
"\")\"",
",",
"\"\"",
",",
"substr",
"(",
"$",
"colParts",
"[",
"0",
"]",
",",
"$",
"fparen",
"+",
"1",
")",
")",
";",
"$",
"colInfo",
"[",
"'attributes'",
"]",
"=",
"isset",
"(",
"$",
"colParts",
"[",
"1",
"]",
")",
"?",
"$",
"colParts",
"[",
"1",
"]",
":",
"null",
";",
"}",
"else",
"{",
"$",
"colInfo",
"[",
"'type'",
"]",
"=",
"$",
"colParts",
"[",
"0",
"]",
";",
"}",
"$",
"colInfo",
"[",
"'is_numeric'",
"]",
"=",
"in_array",
"(",
"$",
"colInfo",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"mysqlTypes",
"[",
"'numerical'",
"]",
")",
";",
"$",
"colInfo",
"[",
"'is_blob'",
"]",
"=",
"in_array",
"(",
"$",
"colInfo",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"mysqlTypes",
"[",
"'blob'",
"]",
")",
";",
"// for virtual columns that are of type 'Extra', column type",
"// could by \"STORED GENERATED\" or \"VIRTUAL GENERATED\"",
"// MySQL reference: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html",
"$",
"colInfo",
"[",
"'is_virtual'",
"]",
"=",
"strpos",
"(",
"$",
"colType",
"[",
"'Extra'",
"]",
",",
"\"VIRTUAL GENERATED\"",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"colType",
"[",
"'Extra'",
"]",
",",
"\"STORED GENERATED\"",
")",
"!==",
"false",
";",
"return",
"$",
"colInfo",
";",
"}"
] | Decode column metadata and fill info structure.
type, is_numeric and is_blob will always be available.
@param array $colType Array returned from "SHOW COLUMNS FROM tableName"
@return array | [
"Decode",
"column",
"metadata",
"and",
"fill",
"info",
"structure",
".",
"type",
"is_numeric",
"and",
"is_blob",
"will",
"always",
"be",
"available",
"."
] | aaaecaef045686e9f8d2e4925be267994a5d8a72 | https://github.com/ifsnop/mysqldump-php/blob/aaaecaef045686e9f8d2e4925be267994a5d8a72/src/Ifsnop/Mysqldump/Mysqldump.php#L2056-L2076 | train |
fideloper/TrustedProxy | src/TrustProxies.php | TrustProxies.setTrustedProxyIpAddresses | protected function setTrustedProxyIpAddresses(Request $request)
{
$trustedIps = $this->proxies ?: $this->config->get('trustedproxy.proxies');
// Trust any IP address that calls us
// `**` for backwards compatibility, but is deprecated
if ($trustedIps === '*' || $trustedIps === '**') {
return $this->setTrustedProxyIpAddressesToTheCallingIp($request);
}
// Support IPs addresses separated by comma
$trustedIps = is_string($trustedIps) ? array_map('trim', explode(',', $trustedIps)) : $trustedIps;
// Only trust specific IP addresses
if (is_array($trustedIps)) {
return $this->setTrustedProxyIpAddressesToSpecificIps($request, $trustedIps);
}
} | php | protected function setTrustedProxyIpAddresses(Request $request)
{
$trustedIps = $this->proxies ?: $this->config->get('trustedproxy.proxies');
// Trust any IP address that calls us
// `**` for backwards compatibility, but is deprecated
if ($trustedIps === '*' || $trustedIps === '**') {
return $this->setTrustedProxyIpAddressesToTheCallingIp($request);
}
// Support IPs addresses separated by comma
$trustedIps = is_string($trustedIps) ? array_map('trim', explode(',', $trustedIps)) : $trustedIps;
// Only trust specific IP addresses
if (is_array($trustedIps)) {
return $this->setTrustedProxyIpAddressesToSpecificIps($request, $trustedIps);
}
} | [
"protected",
"function",
"setTrustedProxyIpAddresses",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"trustedIps",
"=",
"$",
"this",
"->",
"proxies",
"?",
":",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'trustedproxy.proxies'",
")",
";",
"// Trust any IP address that calls us",
"// `**` for backwards compatibility, but is deprecated",
"if",
"(",
"$",
"trustedIps",
"===",
"'*'",
"||",
"$",
"trustedIps",
"===",
"'**'",
")",
"{",
"return",
"$",
"this",
"->",
"setTrustedProxyIpAddressesToTheCallingIp",
"(",
"$",
"request",
")",
";",
"}",
"// Support IPs addresses separated by comma",
"$",
"trustedIps",
"=",
"is_string",
"(",
"$",
"trustedIps",
")",
"?",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"trustedIps",
")",
")",
":",
"$",
"trustedIps",
";",
"// Only trust specific IP addresses",
"if",
"(",
"is_array",
"(",
"$",
"trustedIps",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setTrustedProxyIpAddressesToSpecificIps",
"(",
"$",
"request",
",",
"$",
"trustedIps",
")",
";",
"}",
"}"
] | Sets the trusted proxies on the request to the value of trustedproxy.proxies
@param \Illuminate\Http\Request $request | [
"Sets",
"the",
"trusted",
"proxies",
"on",
"the",
"request",
"to",
"the",
"value",
"of",
"trustedproxy",
".",
"proxies"
] | 2585e8ef63b11115df22f1af94d7be5e9445ec96 | https://github.com/fideloper/TrustedProxy/blob/2585e8ef63b11115df22f1af94d7be5e9445ec96/src/TrustProxies.php#L65-L82 | train |
fideloper/TrustedProxy | src/TrustProxies.php | TrustProxies.setTrustedProxyIpAddressesToTheCallingIp | private function setTrustedProxyIpAddressesToTheCallingIp(Request $request)
{
$request->setTrustedProxies([$request->server->get('REMOTE_ADDR')], $this->getTrustedHeaderNames());
} | php | private function setTrustedProxyIpAddressesToTheCallingIp(Request $request)
{
$request->setTrustedProxies([$request->server->get('REMOTE_ADDR')], $this->getTrustedHeaderNames());
} | [
"private",
"function",
"setTrustedProxyIpAddressesToTheCallingIp",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"request",
"->",
"setTrustedProxies",
"(",
"[",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
"]",
",",
"$",
"this",
"->",
"getTrustedHeaderNames",
"(",
")",
")",
";",
"}"
] | Set the trusted proxy to be the IP address calling this servers
@param \Illuminate\Http\Request $request | [
"Set",
"the",
"trusted",
"proxy",
"to",
"be",
"the",
"IP",
"address",
"calling",
"this",
"servers"
] | 2585e8ef63b11115df22f1af94d7be5e9445ec96 | https://github.com/fideloper/TrustedProxy/blob/2585e8ef63b11115df22f1af94d7be5e9445ec96/src/TrustProxies.php#L100-L103 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.setSchema | public function setSchema($schema)
{
$this->schema = $schema;
$sessionVars = [
'CURRENT_SCHEMA' => $schema,
];
return $this->setSessionVars($sessionVars);
} | php | public function setSchema($schema)
{
$this->schema = $schema;
$sessionVars = [
'CURRENT_SCHEMA' => $schema,
];
return $this->setSessionVars($sessionVars);
} | [
"public",
"function",
"setSchema",
"(",
"$",
"schema",
")",
"{",
"$",
"this",
"->",
"schema",
"=",
"$",
"schema",
";",
"$",
"sessionVars",
"=",
"[",
"'CURRENT_SCHEMA'",
"=>",
"$",
"schema",
",",
"]",
";",
"return",
"$",
"this",
"->",
"setSessionVars",
"(",
"$",
"sessionVars",
")",
";",
"}"
] | Set current schema.
@param string $schema
@return $this | [
"Set",
"current",
"schema",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L71-L79 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.setSessionVars | public function setSessionVars(array $sessionVars)
{
$vars = [];
foreach ($sessionVars as $option => $value) {
if (strtoupper($option) == 'CURRENT_SCHEMA' || strtoupper($option) == 'EDITION') {
$vars[] = "$option = $value";
} else {
$vars[] = "$option = '$value'";
}
}
if ($vars) {
$sql = 'ALTER SESSION SET ' . implode(' ', $vars);
$this->statement($sql);
}
return $this;
} | php | public function setSessionVars(array $sessionVars)
{
$vars = [];
foreach ($sessionVars as $option => $value) {
if (strtoupper($option) == 'CURRENT_SCHEMA' || strtoupper($option) == 'EDITION') {
$vars[] = "$option = $value";
} else {
$vars[] = "$option = '$value'";
}
}
if ($vars) {
$sql = 'ALTER SESSION SET ' . implode(' ', $vars);
$this->statement($sql);
}
return $this;
} | [
"public",
"function",
"setSessionVars",
"(",
"array",
"$",
"sessionVars",
")",
"{",
"$",
"vars",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sessionVars",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strtoupper",
"(",
"$",
"option",
")",
"==",
"'CURRENT_SCHEMA'",
"||",
"strtoupper",
"(",
"$",
"option",
")",
"==",
"'EDITION'",
")",
"{",
"$",
"vars",
"[",
"]",
"=",
"\"$option = $value\"",
";",
"}",
"else",
"{",
"$",
"vars",
"[",
"]",
"=",
"\"$option = '$value'\"",
";",
"}",
"}",
"if",
"(",
"$",
"vars",
")",
"{",
"$",
"sql",
"=",
"'ALTER SESSION SET '",
".",
"implode",
"(",
"' '",
",",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"statement",
"(",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Update oracle session variables.
@param array $sessionVars
@return $this | [
"Update",
"oracle",
"session",
"variables",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L87-L104 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.getDoctrineConnection | public function getDoctrineConnection()
{
if (is_null($this->doctrineConnection)) {
$data = ['pdo' => $this->getPdo(), 'user' => $this->getConfig('username')];
$this->doctrineConnection = new DoctrineConnection(
$data,
$this->getDoctrineDriver()
);
}
return $this->doctrineConnection;
} | php | public function getDoctrineConnection()
{
if (is_null($this->doctrineConnection)) {
$data = ['pdo' => $this->getPdo(), 'user' => $this->getConfig('username')];
$this->doctrineConnection = new DoctrineConnection(
$data,
$this->getDoctrineDriver()
);
}
return $this->doctrineConnection;
} | [
"public",
"function",
"getDoctrineConnection",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"doctrineConnection",
")",
")",
"{",
"$",
"data",
"=",
"[",
"'pdo'",
"=>",
"$",
"this",
"->",
"getPdo",
"(",
")",
",",
"'user'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
"'username'",
")",
"]",
";",
"$",
"this",
"->",
"doctrineConnection",
"=",
"new",
"DoctrineConnection",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getDoctrineDriver",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"doctrineConnection",
";",
"}"
] | Get doctrine connection.
@return \Doctrine\DBAL\Connection | [
"Get",
"doctrine",
"connection",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L198-L209 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.createSqlFromProcedure | public function createSqlFromProcedure($procedureName, array $bindings, $cursor = false)
{
$paramsString = implode(',', array_map(function ($param) {
return ':' . $param;
}, array_keys($bindings)));
$prefix = count($bindings) ? ',' : '';
$cursor = $cursor ? $prefix . $cursor : null;
return sprintf('begin %s(%s%s); end;', $procedureName, $paramsString, $cursor);
} | php | public function createSqlFromProcedure($procedureName, array $bindings, $cursor = false)
{
$paramsString = implode(',', array_map(function ($param) {
return ':' . $param;
}, array_keys($bindings)));
$prefix = count($bindings) ? ',' : '';
$cursor = $cursor ? $prefix . $cursor : null;
return sprintf('begin %s(%s%s); end;', $procedureName, $paramsString, $cursor);
} | [
"public",
"function",
"createSqlFromProcedure",
"(",
"$",
"procedureName",
",",
"array",
"$",
"bindings",
",",
"$",
"cursor",
"=",
"false",
")",
"{",
"$",
"paramsString",
"=",
"implode",
"(",
"','",
",",
"array_map",
"(",
"function",
"(",
"$",
"param",
")",
"{",
"return",
"':'",
".",
"$",
"param",
";",
"}",
",",
"array_keys",
"(",
"$",
"bindings",
")",
")",
")",
";",
"$",
"prefix",
"=",
"count",
"(",
"$",
"bindings",
")",
"?",
"','",
":",
"''",
";",
"$",
"cursor",
"=",
"$",
"cursor",
"?",
"$",
"prefix",
".",
"$",
"cursor",
":",
"null",
";",
"return",
"sprintf",
"(",
"'begin %s(%s%s); end;'",
",",
"$",
"procedureName",
",",
"$",
"paramsString",
",",
"$",
"cursor",
")",
";",
"}"
] | Creates sql command to run a procedure with bindings.
@param string $procedureName
@param array $bindings
@param string|bool $cursor
@return string | [
"Creates",
"sql",
"command",
"to",
"run",
"a",
"procedure",
"with",
"bindings",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L303-L313 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.createStatementFromProcedure | public function createStatementFromProcedure($procedureName, array $bindings, $cursorName = false)
{
$sql = $this->createSqlFromProcedure($procedureName, $bindings, $cursorName);
return $this->getPdo()->prepare($sql);
} | php | public function createStatementFromProcedure($procedureName, array $bindings, $cursorName = false)
{
$sql = $this->createSqlFromProcedure($procedureName, $bindings, $cursorName);
return $this->getPdo()->prepare($sql);
} | [
"public",
"function",
"createStatementFromProcedure",
"(",
"$",
"procedureName",
",",
"array",
"$",
"bindings",
",",
"$",
"cursorName",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"createSqlFromProcedure",
"(",
"$",
"procedureName",
",",
"$",
"bindings",
",",
"$",
"cursorName",
")",
";",
"return",
"$",
"this",
"->",
"getPdo",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"}"
] | Creates statement from procedure.
@param string $procedureName
@param array $bindings
@param string|bool $cursorName
@return PDOStatement | [
"Creates",
"statement",
"from",
"procedure",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L323-L328 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.createStatementFromFunction | public function createStatementFromFunction($functionName, array $bindings)
{
$bindings = $bindings ? ':' . implode(', :', array_keys($bindings)) : '';
$sql = sprintf('begin :result := %s(%s); end;', $functionName, $bindings);
return $this->getPdo()->prepare($sql);
} | php | public function createStatementFromFunction($functionName, array $bindings)
{
$bindings = $bindings ? ':' . implode(', :', array_keys($bindings)) : '';
$sql = sprintf('begin :result := %s(%s); end;', $functionName, $bindings);
return $this->getPdo()->prepare($sql);
} | [
"public",
"function",
"createStatementFromFunction",
"(",
"$",
"functionName",
",",
"array",
"$",
"bindings",
")",
"{",
"$",
"bindings",
"=",
"$",
"bindings",
"?",
"':'",
".",
"implode",
"(",
"', :'",
",",
"array_keys",
"(",
"$",
"bindings",
")",
")",
":",
"''",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"'begin :result := %s(%s); end;'",
",",
"$",
"functionName",
",",
"$",
"bindings",
")",
";",
"return",
"$",
"this",
"->",
"getPdo",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"}"
] | Create statement from function.
@param string $functionName
@param array $bindings
@return PDOStatement | [
"Create",
"statement",
"from",
"function",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L337-L344 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.addBindingsToStatement | public function addBindingsToStatement(PDOStatement $stmt, array $bindings)
{
foreach ($bindings as $key => &$binding) {
$value = &$binding;
$type = PDO::PARAM_STR;
$length = -1;
if (is_array($binding)) {
$value = &$binding['value'];
$type = array_key_exists('type', $binding) ? $binding['type'] : PDO::PARAM_STR;
$length = array_key_exists('length', $binding) ? $binding['length'] : -1;
}
$stmt->bindParam(':' . $key, $value, $type, $length);
}
return $stmt;
} | php | public function addBindingsToStatement(PDOStatement $stmt, array $bindings)
{
foreach ($bindings as $key => &$binding) {
$value = &$binding;
$type = PDO::PARAM_STR;
$length = -1;
if (is_array($binding)) {
$value = &$binding['value'];
$type = array_key_exists('type', $binding) ? $binding['type'] : PDO::PARAM_STR;
$length = array_key_exists('length', $binding) ? $binding['length'] : -1;
}
$stmt->bindParam(':' . $key, $value, $type, $length);
}
return $stmt;
} | [
"public",
"function",
"addBindingsToStatement",
"(",
"PDOStatement",
"$",
"stmt",
",",
"array",
"$",
"bindings",
")",
"{",
"foreach",
"(",
"$",
"bindings",
"as",
"$",
"key",
"=>",
"&",
"$",
"binding",
")",
"{",
"$",
"value",
"=",
"&",
"$",
"binding",
";",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_STR",
";",
"$",
"length",
"=",
"-",
"1",
";",
"if",
"(",
"is_array",
"(",
"$",
"binding",
")",
")",
"{",
"$",
"value",
"=",
"&",
"$",
"binding",
"[",
"'value'",
"]",
";",
"$",
"type",
"=",
"array_key_exists",
"(",
"'type'",
",",
"$",
"binding",
")",
"?",
"$",
"binding",
"[",
"'type'",
"]",
":",
"PDO",
"::",
"PARAM_STR",
";",
"$",
"length",
"=",
"array_key_exists",
"(",
"'length'",
",",
"$",
"binding",
")",
"?",
"$",
"binding",
"[",
"'length'",
"]",
":",
"-",
"1",
";",
"}",
"$",
"stmt",
"->",
"bindParam",
"(",
"':'",
".",
"$",
"key",
",",
"$",
"value",
",",
"$",
"type",
",",
"$",
"length",
")",
";",
"}",
"return",
"$",
"stmt",
";",
"}"
] | Add bindings to statement.
@param array $bindings
@param PDOStatement $stmt
@return PDOStatement | [
"Add",
"bindings",
"to",
"statement",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L430-L447 | train |
yajra/laravel-oci8 | src/Oci8/Oci8Connection.php | Oci8Connection.causedByLostConnection | protected function causedByLostConnection(Throwable $e)
{
if (parent::causedByLostConnection($e)) {
return true;
}
$lostConnectionErrors = [
'ORA-03113', //End-of-file on communication channel
'ORA-03114', //Not Connected to Oracle
'ORA-03135', //Connection lost contact
'ORA-12170', //Connect timeout occurred
'ORA-12537', //Connection closed
'ORA-27146', //Post/wait initialization failed
'ORA-25408', //Can not safely replay call
'ORA-56600', //Illegal Call
];
$additionalErrors = null;
$options = isset($this->config['options']) ? $this->config['options'] : [];
if (array_key_exists(static::RECONNECT_ERRORS, $options)) {
$additionalErrors = $this->config['options'][static::RECONNECT_ERRORS];
}
if (is_array($additionalErrors)) {
$lostConnectionErrors = array_merge($lostConnectionErrors,
$this->config['options'][static::RECONNECT_ERRORS]);
}
return Str::contains($e->getMessage(), $lostConnectionErrors);
} | php | protected function causedByLostConnection(Throwable $e)
{
if (parent::causedByLostConnection($e)) {
return true;
}
$lostConnectionErrors = [
'ORA-03113', //End-of-file on communication channel
'ORA-03114', //Not Connected to Oracle
'ORA-03135', //Connection lost contact
'ORA-12170', //Connect timeout occurred
'ORA-12537', //Connection closed
'ORA-27146', //Post/wait initialization failed
'ORA-25408', //Can not safely replay call
'ORA-56600', //Illegal Call
];
$additionalErrors = null;
$options = isset($this->config['options']) ? $this->config['options'] : [];
if (array_key_exists(static::RECONNECT_ERRORS, $options)) {
$additionalErrors = $this->config['options'][static::RECONNECT_ERRORS];
}
if (is_array($additionalErrors)) {
$lostConnectionErrors = array_merge($lostConnectionErrors,
$this->config['options'][static::RECONNECT_ERRORS]);
}
return Str::contains($e->getMessage(), $lostConnectionErrors);
} | [
"protected",
"function",
"causedByLostConnection",
"(",
"Throwable",
"$",
"e",
")",
"{",
"if",
"(",
"parent",
"::",
"causedByLostConnection",
"(",
"$",
"e",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"lostConnectionErrors",
"=",
"[",
"'ORA-03113'",
",",
"//End-of-file on communication channel",
"'ORA-03114'",
",",
"//Not Connected to Oracle",
"'ORA-03135'",
",",
"//Connection lost contact",
"'ORA-12170'",
",",
"//Connect timeout occurred",
"'ORA-12537'",
",",
"//Connection closed",
"'ORA-27146'",
",",
"//Post/wait initialization failed",
"'ORA-25408'",
",",
"//Can not safely replay call",
"'ORA-56600'",
",",
"//Illegal Call",
"]",
";",
"$",
"additionalErrors",
"=",
"null",
";",
"$",
"options",
"=",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"static",
"::",
"RECONNECT_ERRORS",
",",
"$",
"options",
")",
")",
"{",
"$",
"additionalErrors",
"=",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
"[",
"static",
"::",
"RECONNECT_ERRORS",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"additionalErrors",
")",
")",
"{",
"$",
"lostConnectionErrors",
"=",
"array_merge",
"(",
"$",
"lostConnectionErrors",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
"[",
"static",
"::",
"RECONNECT_ERRORS",
"]",
")",
";",
"}",
"return",
"Str",
"::",
"contains",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"lostConnectionErrors",
")",
";",
"}"
] | Determine if the given exception was caused by a lost connection.
@param \Exception $e
@return bool | [
"Determine",
"if",
"the",
"given",
"exception",
"was",
"caused",
"by",
"a",
"lost",
"connection",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8Connection.php#L455-L485 | train |
yajra/laravel-oci8 | src/Oci8/Eloquent/OracleEloquent.php | OracleEloquent.extractBinaries | protected function extractBinaries(&$attributes)
{
// If attributes contains binary field
// extract binary fields to new array
$binaries = [];
if ($this->checkBinary($attributes) && $this->getConnection() instanceof Oci8Connection) {
foreach ($attributes as $key => $value) {
if (in_array($key, $this->binaries)) {
$binaries[$key] = $value;
unset($attributes[$key]);
}
}
}
return $this->binaryFields = $binaries;
} | php | protected function extractBinaries(&$attributes)
{
// If attributes contains binary field
// extract binary fields to new array
$binaries = [];
if ($this->checkBinary($attributes) && $this->getConnection() instanceof Oci8Connection) {
foreach ($attributes as $key => $value) {
if (in_array($key, $this->binaries)) {
$binaries[$key] = $value;
unset($attributes[$key]);
}
}
}
return $this->binaryFields = $binaries;
} | [
"protected",
"function",
"extractBinaries",
"(",
"&",
"$",
"attributes",
")",
"{",
"// If attributes contains binary field",
"// extract binary fields to new array",
"$",
"binaries",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"checkBinary",
"(",
"$",
"attributes",
")",
"&&",
"$",
"this",
"->",
"getConnection",
"(",
")",
"instanceof",
"Oci8Connection",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"binaries",
")",
")",
"{",
"$",
"binaries",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"binaryFields",
"=",
"$",
"binaries",
";",
"}"
] | Extract binary fields from given attributes.
@param array $attributes
@return array | [
"Extract",
"binary",
"fields",
"from",
"given",
"attributes",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Eloquent/OracleEloquent.php#L104-L119 | train |
yajra/laravel-oci8 | src/Oci8/Eloquent/OracleEloquent.php | OracleEloquent.checkBinary | protected function checkBinary(array $attributes)
{
foreach ($attributes as $key => $value) {
// if attribute is in binary field list
if (in_array($key, $this->binaries)) {
return true;
}
}
return false;
} | php | protected function checkBinary(array $attributes)
{
foreach ($attributes as $key => $value) {
// if attribute is in binary field list
if (in_array($key, $this->binaries)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"checkBinary",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// if attribute is in binary field list",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"binaries",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if attributes contains binary field.
@param array $attributes
@return bool | [
"Check",
"if",
"attributes",
"contains",
"binary",
"field",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Eloquent/OracleEloquent.php#L127-L137 | train |
yajra/laravel-oci8 | src/Oci8/Schema/Sequence.php | Sequence.create | public function create($name, $start = 1, $nocache = false, $min = 1, $max = false, $increment = 1)
{
if (! $name) {
return false;
}
if ($this->connection->getConfig('prefix_schema')) {
$name = $this->connection->getConfig('prefix_schema') . '.' . $name;
}
$nocache = $nocache ? 'nocache' : '';
$max = $max ? " maxvalue {$max}" : '';
$sequence_stmt = "create sequence {$name} minvalue {$min} {$max} start with {$start} increment by {$increment} {$nocache}";
return $this->connection->statement($sequence_stmt);
} | php | public function create($name, $start = 1, $nocache = false, $min = 1, $max = false, $increment = 1)
{
if (! $name) {
return false;
}
if ($this->connection->getConfig('prefix_schema')) {
$name = $this->connection->getConfig('prefix_schema') . '.' . $name;
}
$nocache = $nocache ? 'nocache' : '';
$max = $max ? " maxvalue {$max}" : '';
$sequence_stmt = "create sequence {$name} minvalue {$min} {$max} start with {$start} increment by {$increment} {$nocache}";
return $this->connection->statement($sequence_stmt);
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"start",
"=",
"1",
",",
"$",
"nocache",
"=",
"false",
",",
"$",
"min",
"=",
"1",
",",
"$",
"max",
"=",
"false",
",",
"$",
"increment",
"=",
"1",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getConfig",
"(",
"'prefix_schema'",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"connection",
"->",
"getConfig",
"(",
"'prefix_schema'",
")",
".",
"'.'",
".",
"$",
"name",
";",
"}",
"$",
"nocache",
"=",
"$",
"nocache",
"?",
"'nocache'",
":",
"''",
";",
"$",
"max",
"=",
"$",
"max",
"?",
"\" maxvalue {$max}\"",
":",
"''",
";",
"$",
"sequence_stmt",
"=",
"\"create sequence {$name} minvalue {$min} {$max} start with {$start} increment by {$increment} {$nocache}\"",
";",
"return",
"$",
"this",
"->",
"connection",
"->",
"statement",
"(",
"$",
"sequence_stmt",
")",
";",
"}"
] | function to create oracle sequence.
@param string $name
@param int $start
@param bool $nocache
@return bool | [
"function",
"to",
"create",
"oracle",
"sequence",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Sequence.php#L30-L47 | train |
yajra/laravel-oci8 | src/Oci8/Schema/Sequence.php | Sequence.drop | public function drop($name)
{
// check if a valid name and sequence exists
if (! $name || ! $this->exists($name)) {
return false;
}
return $this->connection->statement("
declare
e exception;
pragma exception_init(e,-02289);
begin
execute immediate 'drop sequence {$name}';
exception
when e then
null;
end;");
} | php | public function drop($name)
{
// check if a valid name and sequence exists
if (! $name || ! $this->exists($name)) {
return false;
}
return $this->connection->statement("
declare
e exception;
pragma exception_init(e,-02289);
begin
execute immediate 'drop sequence {$name}';
exception
when e then
null;
end;");
} | [
"public",
"function",
"drop",
"(",
"$",
"name",
")",
"{",
"// check if a valid name and sequence exists",
"if",
"(",
"!",
"$",
"name",
"||",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
"->",
"statement",
"(",
"\"\n declare\n e exception;\n pragma exception_init(e,-02289);\n begin\n execute immediate 'drop sequence {$name}';\n exception\n when e then\n null;\n end;\"",
")",
";",
"}"
] | function to safely drop sequence db object.
@param string $name
@return bool | [
"function",
"to",
"safely",
"drop",
"sequence",
"db",
"object",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Sequence.php#L55-L72 | train |
yajra/laravel-oci8 | src/Oci8/Schema/Sequence.php | Sequence.lastInsertId | public function lastInsertId($name)
{
// check if a valid name and sequence exists
if (! $name || ! $this->exists($name)) {
return 0;
}
return $this->connection->selectOne("select {$name}.currval as id from dual")->id;
} | php | public function lastInsertId($name)
{
// check if a valid name and sequence exists
if (! $name || ! $this->exists($name)) {
return 0;
}
return $this->connection->selectOne("select {$name}.currval as id from dual")->id;
} | [
"public",
"function",
"lastInsertId",
"(",
"$",
"name",
")",
"{",
"// check if a valid name and sequence exists",
"if",
"(",
"!",
"$",
"name",
"||",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
"->",
"selectOne",
"(",
"\"select {$name}.currval as id from dual\"",
")",
"->",
"id",
";",
"}"
] | function to get oracle sequence last inserted id.
@param string $name
@return int | [
"function",
"to",
"get",
"oracle",
"sequence",
"last",
"inserted",
"id",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Sequence.php#L123-L131 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleBuilder.php | OracleBuilder.table | public function table($table, Closure $callback)
{
$blueprint = $this->createBlueprint($table);
$callback($blueprint);
foreach ($blueprint->getCommands() as $command) {
if ($command->get('name') == 'drop') {
$this->helper->dropAutoIncrementObjects($table);
}
}
$this->build($blueprint);
$this->comment->setComments($blueprint);
} | php | public function table($table, Closure $callback)
{
$blueprint = $this->createBlueprint($table);
$callback($blueprint);
foreach ($blueprint->getCommands() as $command) {
if ($command->get('name') == 'drop') {
$this->helper->dropAutoIncrementObjects($table);
}
}
$this->build($blueprint);
$this->comment->setComments($blueprint);
} | [
"public",
"function",
"table",
"(",
"$",
"table",
",",
"Closure",
"$",
"callback",
")",
"{",
"$",
"blueprint",
"=",
"$",
"this",
"->",
"createBlueprint",
"(",
"$",
"table",
")",
";",
"$",
"callback",
"(",
"$",
"blueprint",
")",
";",
"foreach",
"(",
"$",
"blueprint",
"->",
"getCommands",
"(",
")",
"as",
"$",
"command",
")",
"{",
"if",
"(",
"$",
"command",
"->",
"get",
"(",
"'name'",
")",
"==",
"'drop'",
")",
"{",
"$",
"this",
"->",
"helper",
"->",
"dropAutoIncrementObjects",
"(",
"$",
"table",
")",
";",
"}",
"}",
"$",
"this",
"->",
"build",
"(",
"$",
"blueprint",
")",
";",
"$",
"this",
"->",
"comment",
"->",
"setComments",
"(",
"$",
"blueprint",
")",
";",
"}"
] | Changes an existing table on the schema.
@param string $table
@param Closure $callback
@return \Illuminate\Database\Schema\Blueprint | [
"Changes",
"an",
"existing",
"table",
"on",
"the",
"schema",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleBuilder.php#L75-L90 | train |
yajra/laravel-oci8 | src/Oci8/Schema/Comment.php | Comment.setComments | public function setComments(OracleBlueprint $blueprint)
{
$this->commentTable($blueprint);
$this->fluentComments($blueprint);
$this->commentColumns($blueprint);
} | php | public function setComments(OracleBlueprint $blueprint)
{
$this->commentTable($blueprint);
$this->fluentComments($blueprint);
$this->commentColumns($blueprint);
} | [
"public",
"function",
"setComments",
"(",
"OracleBlueprint",
"$",
"blueprint",
")",
"{",
"$",
"this",
"->",
"commentTable",
"(",
"$",
"blueprint",
")",
";",
"$",
"this",
"->",
"fluentComments",
"(",
"$",
"blueprint",
")",
";",
"$",
"this",
"->",
"commentColumns",
"(",
"$",
"blueprint",
")",
";",
"}"
] | Set table and column comments.
@param \Yajra\Oci8\Schema\OracleBlueprint $blueprint | [
"Set",
"table",
"and",
"column",
"comments",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Comment.php#L31-L38 | train |
yajra/laravel-oci8 | src/Oci8/Schema/Comment.php | Comment.commentColumn | private function commentColumn($table, $column, $comment)
{
$table = $this->wrapValue($table);
$table = $this->connection->getTablePrefix() . $table;
$column = $this->wrapValue($column);
$this->connection->statement("comment on column {$table}.{$column} is '{$comment}'");
} | php | private function commentColumn($table, $column, $comment)
{
$table = $this->wrapValue($table);
$table = $this->connection->getTablePrefix() . $table;
$column = $this->wrapValue($column);
$this->connection->statement("comment on column {$table}.{$column} is '{$comment}'");
} | [
"private",
"function",
"commentColumn",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"comment",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"wrapValue",
"(",
"$",
"table",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"connection",
"->",
"getTablePrefix",
"(",
")",
".",
"$",
"table",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"wrapValue",
"(",
"$",
"column",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"statement",
"(",
"\"comment on column {$table}.{$column} is '{$comment}'\"",
")",
";",
"}"
] | Run the comment on column statement.
@param string $table
@param string $column
@param string $comment | [
"Run",
"the",
"comment",
"on",
"column",
"statement",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Comment.php#L88-L95 | train |
yajra/laravel-oci8 | src/Oci8/Query/OracleBuilder.php | OracleBuilder.updateLob | public function updateLob(array $values, array $binaries, $sequence = 'id')
{
$bindings = array_values(array_merge($values, $this->getBindings()));
/** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */
$grammar = $this->grammar;
$sql = $grammar->compileUpdateLob($this, $values, $binaries, $sequence);
$values = $this->cleanBindings($bindings);
$binaries = $this->cleanBindings($binaries);
/** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */
$processor = $this->processor;
return $processor->saveLob($this, $sql, $values, $binaries);
} | php | public function updateLob(array $values, array $binaries, $sequence = 'id')
{
$bindings = array_values(array_merge($values, $this->getBindings()));
/** @var \Yajra\Oci8\Query\Grammars\OracleGrammar $grammar */
$grammar = $this->grammar;
$sql = $grammar->compileUpdateLob($this, $values, $binaries, $sequence);
$values = $this->cleanBindings($bindings);
$binaries = $this->cleanBindings($binaries);
/** @var \Yajra\Oci8\Query\Processors\OracleProcessor $processor */
$processor = $this->processor;
return $processor->saveLob($this, $sql, $values, $binaries);
} | [
"public",
"function",
"updateLob",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"binaries",
",",
"$",
"sequence",
"=",
"'id'",
")",
"{",
"$",
"bindings",
"=",
"array_values",
"(",
"array_merge",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"getBindings",
"(",
")",
")",
")",
";",
"/** @var \\Yajra\\Oci8\\Query\\Grammars\\OracleGrammar $grammar */",
"$",
"grammar",
"=",
"$",
"this",
"->",
"grammar",
";",
"$",
"sql",
"=",
"$",
"grammar",
"->",
"compileUpdateLob",
"(",
"$",
"this",
",",
"$",
"values",
",",
"$",
"binaries",
",",
"$",
"sequence",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"cleanBindings",
"(",
"$",
"bindings",
")",
";",
"$",
"binaries",
"=",
"$",
"this",
"->",
"cleanBindings",
"(",
"$",
"binaries",
")",
";",
"/** @var \\Yajra\\Oci8\\Query\\Processors\\OracleProcessor $processor */",
"$",
"processor",
"=",
"$",
"this",
"->",
"processor",
";",
"return",
"$",
"processor",
"->",
"saveLob",
"(",
"$",
"this",
",",
"$",
"sql",
",",
"$",
"values",
",",
"$",
"binaries",
")",
";",
"}"
] | Update a new record with blob field.
@param array $values
@param array $binaries
@param string $sequence
@return bool | [
"Update",
"a",
"new",
"record",
"with",
"blob",
"field",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/OracleBuilder.php#L41-L56 | train |
yajra/laravel-oci8 | src/Oci8/Query/OracleBuilder.php | OracleBuilder.whereIn | public function whereIn($column, $values, $boolean = 'and', $not = false)
{
$type = $not ? 'NotIn' : 'In';
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
if (is_array($values) && count($values) > 1000) {
$chunks = array_chunk($values, 1000);
return $this->where(function ($query) use ($column, $chunks, $type, $not) {
foreach ($chunks as $ch) {
$sqlClause = $not ? 'where' . $type : 'orWhere' . $type;
$query->{$sqlClause}($column, $ch);
}
}, null, null, $boolean);
}
return parent::whereIn($column, $values, $boolean, $not);
} | php | public function whereIn($column, $values, $boolean = 'and', $not = false)
{
$type = $not ? 'NotIn' : 'In';
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
if (is_array($values) && count($values) > 1000) {
$chunks = array_chunk($values, 1000);
return $this->where(function ($query) use ($column, $chunks, $type, $not) {
foreach ($chunks as $ch) {
$sqlClause = $not ? 'where' . $type : 'orWhere' . $type;
$query->{$sqlClause}($column, $ch);
}
}, null, null, $boolean);
}
return parent::whereIn($column, $values, $boolean, $not);
} | [
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"boolean",
"=",
"'and'",
",",
"$",
"not",
"=",
"false",
")",
"{",
"$",
"type",
"=",
"$",
"not",
"?",
"'NotIn'",
":",
"'In'",
";",
"if",
"(",
"$",
"values",
"instanceof",
"Arrayable",
")",
"{",
"$",
"values",
"=",
"$",
"values",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
"&&",
"count",
"(",
"$",
"values",
")",
">",
"1000",
")",
"{",
"$",
"chunks",
"=",
"array_chunk",
"(",
"$",
"values",
",",
"1000",
")",
";",
"return",
"$",
"this",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"column",
",",
"$",
"chunks",
",",
"$",
"type",
",",
"$",
"not",
")",
"{",
"foreach",
"(",
"$",
"chunks",
"as",
"$",
"ch",
")",
"{",
"$",
"sqlClause",
"=",
"$",
"not",
"?",
"'where'",
".",
"$",
"type",
":",
"'orWhere'",
".",
"$",
"type",
";",
"$",
"query",
"->",
"{",
"$",
"sqlClause",
"}",
"(",
"$",
"column",
",",
"$",
"ch",
")",
";",
"}",
"}",
",",
"null",
",",
"null",
",",
"$",
"boolean",
")",
";",
"}",
"return",
"parent",
"::",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"boolean",
",",
"$",
"not",
")",
";",
"}"
] | Add a "where in" clause to the query.
Split one WHERE IN clause into multiple clauses each
with up to 1000 expressions to avoid ORA-01795.
@param string $column
@param mixed $values
@param string $boolean
@param bool $not
@return \Illuminate\Database\Query\Builder|\Yajra\Oci8\Query\OracleBuilder | [
"Add",
"a",
"where",
"in",
"clause",
"to",
"the",
"query",
".",
"Split",
"one",
"WHERE",
"IN",
"clause",
"into",
"multiple",
"clauses",
"each",
"with",
"up",
"to",
"1000",
"expressions",
"to",
"avoid",
"ORA",
"-",
"01795",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/OracleBuilder.php#L69-L89 | train |
yajra/laravel-oci8 | src/Oci8/Query/Grammars/OracleGrammar.php | OracleGrammar.compileInsertLob | public function compileInsertLob(Builder $query, $values, $binaries, $sequence = 'id')
{
if (empty($sequence)) {
$sequence = 'id';
}
$table = $this->wrapTable($query->from);
if (! is_array(reset($values))) {
$values = [$values];
}
if (! is_array(reset($binaries))) {
$binaries = [$binaries];
}
$columns = $this->columnize(array_keys(reset($values)));
$binaryColumns = $this->columnize(array_keys(reset($binaries)));
$columns .= (empty($columns) ? '' : ', ') . $binaryColumns;
$parameters = $this->parameterize(reset($values));
$binaryParameters = $this->parameterize(reset($binaries));
$value = array_fill(0, count($values), "$parameters");
$binaryValue = array_fill(0, count($binaries), str_replace('?', 'EMPTY_BLOB()', $binaryParameters));
$value = array_merge($value, $binaryValue);
$parameters = implode(', ', array_filter($value));
return "insert into $table ($columns) values ($parameters) returning " . $binaryColumns . ', ' . $this->wrap($sequence) . ' into ' . $binaryParameters . ', ?';
} | php | public function compileInsertLob(Builder $query, $values, $binaries, $sequence = 'id')
{
if (empty($sequence)) {
$sequence = 'id';
}
$table = $this->wrapTable($query->from);
if (! is_array(reset($values))) {
$values = [$values];
}
if (! is_array(reset($binaries))) {
$binaries = [$binaries];
}
$columns = $this->columnize(array_keys(reset($values)));
$binaryColumns = $this->columnize(array_keys(reset($binaries)));
$columns .= (empty($columns) ? '' : ', ') . $binaryColumns;
$parameters = $this->parameterize(reset($values));
$binaryParameters = $this->parameterize(reset($binaries));
$value = array_fill(0, count($values), "$parameters");
$binaryValue = array_fill(0, count($binaries), str_replace('?', 'EMPTY_BLOB()', $binaryParameters));
$value = array_merge($value, $binaryValue);
$parameters = implode(', ', array_filter($value));
return "insert into $table ($columns) values ($parameters) returning " . $binaryColumns . ', ' . $this->wrap($sequence) . ' into ' . $binaryParameters . ', ?';
} | [
"public",
"function",
"compileInsertLob",
"(",
"Builder",
"$",
"query",
",",
"$",
"values",
",",
"$",
"binaries",
",",
"$",
"sequence",
"=",
"'id'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sequence",
")",
")",
"{",
"$",
"sequence",
"=",
"'id'",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"wrapTable",
"(",
"$",
"query",
"->",
"from",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"reset",
"(",
"$",
"values",
")",
")",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"values",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"reset",
"(",
"$",
"binaries",
")",
")",
")",
"{",
"$",
"binaries",
"=",
"[",
"$",
"binaries",
"]",
";",
"}",
"$",
"columns",
"=",
"$",
"this",
"->",
"columnize",
"(",
"array_keys",
"(",
"reset",
"(",
"$",
"values",
")",
")",
")",
";",
"$",
"binaryColumns",
"=",
"$",
"this",
"->",
"columnize",
"(",
"array_keys",
"(",
"reset",
"(",
"$",
"binaries",
")",
")",
")",
";",
"$",
"columns",
".=",
"(",
"empty",
"(",
"$",
"columns",
")",
"?",
"''",
":",
"', '",
")",
".",
"$",
"binaryColumns",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"parameterize",
"(",
"reset",
"(",
"$",
"values",
")",
")",
";",
"$",
"binaryParameters",
"=",
"$",
"this",
"->",
"parameterize",
"(",
"reset",
"(",
"$",
"binaries",
")",
")",
";",
"$",
"value",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"values",
")",
",",
"\"$parameters\"",
")",
";",
"$",
"binaryValue",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"binaries",
")",
",",
"str_replace",
"(",
"'?'",
",",
"'EMPTY_BLOB()'",
",",
"$",
"binaryParameters",
")",
")",
";",
"$",
"value",
"=",
"array_merge",
"(",
"$",
"value",
",",
"$",
"binaryValue",
")",
";",
"$",
"parameters",
"=",
"implode",
"(",
"', '",
",",
"array_filter",
"(",
"$",
"value",
")",
")",
";",
"return",
"\"insert into $table ($columns) values ($parameters) returning \"",
".",
"$",
"binaryColumns",
".",
"', '",
".",
"$",
"this",
"->",
"wrap",
"(",
"$",
"sequence",
")",
".",
"' into '",
".",
"$",
"binaryParameters",
".",
"', ?'",
";",
"}"
] | Compile an insert with blob field statement into SQL.
@param \Illuminate\Database\Query\Builder $query
@param array $values
@param array $binaries
@param string $sequence
@return string | [
"Compile",
"an",
"insert",
"with",
"blob",
"field",
"statement",
"into",
"SQL",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/Grammars/OracleGrammar.php#L315-L345 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleAutoIncrementHelper.php | OracleAutoIncrementHelper.createAutoIncrementObjects | public function createAutoIncrementObjects(Blueprint $blueprint, $table)
{
$column = $this->getQualifiedAutoIncrementColumn($blueprint);
// return if no qualified AI column
if (is_null($column)) {
return;
}
$col = $column->name;
$start = isset($column->start) ? $column->start : 1;
// get table prefix
$prefix = $this->connection->getTablePrefix();
// create sequence for auto increment
$sequenceName = $this->createObjectName($prefix, $table, $col, 'seq');
$this->sequence->create($sequenceName, $start, $column->nocache);
// create trigger for auto increment work around
$triggerName = $this->createObjectName($prefix, $table, $col, 'trg');
$this->trigger->autoIncrement($prefix . $table, $col, $triggerName, $sequenceName);
} | php | public function createAutoIncrementObjects(Blueprint $blueprint, $table)
{
$column = $this->getQualifiedAutoIncrementColumn($blueprint);
// return if no qualified AI column
if (is_null($column)) {
return;
}
$col = $column->name;
$start = isset($column->start) ? $column->start : 1;
// get table prefix
$prefix = $this->connection->getTablePrefix();
// create sequence for auto increment
$sequenceName = $this->createObjectName($prefix, $table, $col, 'seq');
$this->sequence->create($sequenceName, $start, $column->nocache);
// create trigger for auto increment work around
$triggerName = $this->createObjectName($prefix, $table, $col, 'trg');
$this->trigger->autoIncrement($prefix . $table, $col, $triggerName, $sequenceName);
} | [
"public",
"function",
"createAutoIncrementObjects",
"(",
"Blueprint",
"$",
"blueprint",
",",
"$",
"table",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getQualifiedAutoIncrementColumn",
"(",
"$",
"blueprint",
")",
";",
"// return if no qualified AI column",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"return",
";",
"}",
"$",
"col",
"=",
"$",
"column",
"->",
"name",
";",
"$",
"start",
"=",
"isset",
"(",
"$",
"column",
"->",
"start",
")",
"?",
"$",
"column",
"->",
"start",
":",
"1",
";",
"// get table prefix",
"$",
"prefix",
"=",
"$",
"this",
"->",
"connection",
"->",
"getTablePrefix",
"(",
")",
";",
"// create sequence for auto increment",
"$",
"sequenceName",
"=",
"$",
"this",
"->",
"createObjectName",
"(",
"$",
"prefix",
",",
"$",
"table",
",",
"$",
"col",
",",
"'seq'",
")",
";",
"$",
"this",
"->",
"sequence",
"->",
"create",
"(",
"$",
"sequenceName",
",",
"$",
"start",
",",
"$",
"column",
"->",
"nocache",
")",
";",
"// create trigger for auto increment work around",
"$",
"triggerName",
"=",
"$",
"this",
"->",
"createObjectName",
"(",
"$",
"prefix",
",",
"$",
"table",
",",
"$",
"col",
",",
"'trg'",
")",
";",
"$",
"this",
"->",
"trigger",
"->",
"autoIncrement",
"(",
"$",
"prefix",
".",
"$",
"table",
",",
"$",
"col",
",",
"$",
"triggerName",
",",
"$",
"sequenceName",
")",
";",
"}"
] | create sequence and trigger for autoIncrement support.
@param Blueprint $blueprint
@param string $table
@return null | [
"create",
"sequence",
"and",
"trigger",
"for",
"autoIncrement",
"support",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleAutoIncrementHelper.php#L42-L64 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleAutoIncrementHelper.php | OracleAutoIncrementHelper.getQualifiedAutoIncrementColumn | public function getQualifiedAutoIncrementColumn(Blueprint $blueprint)
{
$columns = $blueprint->getColumns();
// search for primary key / autoIncrement column
foreach ($columns as $column) {
// if column is autoIncrement set the primary col name
if ($column->autoIncrement) {
return $column;
}
}
} | php | public function getQualifiedAutoIncrementColumn(Blueprint $blueprint)
{
$columns = $blueprint->getColumns();
// search for primary key / autoIncrement column
foreach ($columns as $column) {
// if column is autoIncrement set the primary col name
if ($column->autoIncrement) {
return $column;
}
}
} | [
"public",
"function",
"getQualifiedAutoIncrementColumn",
"(",
"Blueprint",
"$",
"blueprint",
")",
"{",
"$",
"columns",
"=",
"$",
"blueprint",
"->",
"getColumns",
"(",
")",
";",
"// search for primary key / autoIncrement column",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"// if column is autoIncrement set the primary col name",
"if",
"(",
"$",
"column",
"->",
"autoIncrement",
")",
"{",
"return",
"$",
"column",
";",
"}",
"}",
"}"
] | Get qualified autoincrement column.
@param Blueprint $blueprint
@return \Illuminate\Support\Fluent|null | [
"Get",
"qualified",
"autoincrement",
"column",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleAutoIncrementHelper.php#L72-L83 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleAutoIncrementHelper.php | OracleAutoIncrementHelper.createObjectName | private function createObjectName($prefix, $table, $col, $type)
{
// max object name length is 30 chars
return substr($prefix . $table . '_' . $col . '_' . $type, 0, 30);
} | php | private function createObjectName($prefix, $table, $col, $type)
{
// max object name length is 30 chars
return substr($prefix . $table . '_' . $col . '_' . $type, 0, 30);
} | [
"private",
"function",
"createObjectName",
"(",
"$",
"prefix",
",",
"$",
"table",
",",
"$",
"col",
",",
"$",
"type",
")",
"{",
"// max object name length is 30 chars",
"return",
"substr",
"(",
"$",
"prefix",
".",
"$",
"table",
".",
"'_'",
".",
"$",
"col",
".",
"'_'",
".",
"$",
"type",
",",
"0",
",",
"30",
")",
";",
"}"
] | Create an object name that limits to 30 chars.
@param string $prefix
@param string $table
@param string $col
@param string $type
@return string | [
"Create",
"an",
"object",
"name",
"that",
"limits",
"to",
"30",
"chars",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleAutoIncrementHelper.php#L94-L98 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleAutoIncrementHelper.php | OracleAutoIncrementHelper.dropAutoIncrementObjects | public function dropAutoIncrementObjects($table)
{
// drop sequence and trigger object
$prefix = $this->connection->getTablePrefix();
// get the actual primary column name from table
$col = $this->getPrimaryKey($prefix . $table);
// if primary key col is set, drop auto increment objects
if (isset($col) && ! empty($col)) {
// drop sequence for auto increment
$sequenceName = $this->createObjectName($prefix, $table, $col, 'seq');
$this->sequence->drop($sequenceName);
// drop trigger for auto increment work around
$triggerName = $this->createObjectName($prefix, $table, $col, 'trg');
$this->trigger->drop($triggerName);
}
} | php | public function dropAutoIncrementObjects($table)
{
// drop sequence and trigger object
$prefix = $this->connection->getTablePrefix();
// get the actual primary column name from table
$col = $this->getPrimaryKey($prefix . $table);
// if primary key col is set, drop auto increment objects
if (isset($col) && ! empty($col)) {
// drop sequence for auto increment
$sequenceName = $this->createObjectName($prefix, $table, $col, 'seq');
$this->sequence->drop($sequenceName);
// drop trigger for auto increment work around
$triggerName = $this->createObjectName($prefix, $table, $col, 'trg');
$this->trigger->drop($triggerName);
}
} | [
"public",
"function",
"dropAutoIncrementObjects",
"(",
"$",
"table",
")",
"{",
"// drop sequence and trigger object",
"$",
"prefix",
"=",
"$",
"this",
"->",
"connection",
"->",
"getTablePrefix",
"(",
")",
";",
"// get the actual primary column name from table",
"$",
"col",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
"$",
"prefix",
".",
"$",
"table",
")",
";",
"// if primary key col is set, drop auto increment objects",
"if",
"(",
"isset",
"(",
"$",
"col",
")",
"&&",
"!",
"empty",
"(",
"$",
"col",
")",
")",
"{",
"// drop sequence for auto increment",
"$",
"sequenceName",
"=",
"$",
"this",
"->",
"createObjectName",
"(",
"$",
"prefix",
",",
"$",
"table",
",",
"$",
"col",
",",
"'seq'",
")",
";",
"$",
"this",
"->",
"sequence",
"->",
"drop",
"(",
"$",
"sequenceName",
")",
";",
"// drop trigger for auto increment work around",
"$",
"triggerName",
"=",
"$",
"this",
"->",
"createObjectName",
"(",
"$",
"prefix",
",",
"$",
"table",
",",
"$",
"col",
",",
"'trg'",
")",
";",
"$",
"this",
"->",
"trigger",
"->",
"drop",
"(",
"$",
"triggerName",
")",
";",
"}",
"}"
] | Drop sequence and triggers if exists, autoincrement objects.
@param string $table
@return null | [
"Drop",
"sequence",
"and",
"triggers",
"if",
"exists",
"autoincrement",
"objects",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleAutoIncrementHelper.php#L106-L122 | train |
yajra/laravel-oci8 | src/Oci8/Schema/OracleAutoIncrementHelper.php | OracleAutoIncrementHelper.getPrimaryKey | public function getPrimaryKey($table)
{
if (! $table) {
return '';
}
$sql = "SELECT cols.column_name
FROM all_constraints cons, all_cons_columns cols
WHERE upper(cols.table_name) = upper('{$table}')
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cols.position = 1
AND cons.owner = (select user from dual)
ORDER BY cols.table_name, cols.position";
$data = $this->connection->selectOne($sql);
if ($data) {
return $data->column_name;
}
return '';
} | php | public function getPrimaryKey($table)
{
if (! $table) {
return '';
}
$sql = "SELECT cols.column_name
FROM all_constraints cons, all_cons_columns cols
WHERE upper(cols.table_name) = upper('{$table}')
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cols.position = 1
AND cons.owner = (select user from dual)
ORDER BY cols.table_name, cols.position";
$data = $this->connection->selectOne($sql);
if ($data) {
return $data->column_name;
}
return '';
} | [
"public",
"function",
"getPrimaryKey",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sql",
"=",
"\"SELECT cols.column_name\n FROM all_constraints cons, all_cons_columns cols\n WHERE upper(cols.table_name) = upper('{$table}')\n AND cons.constraint_type = 'P'\n AND cons.constraint_name = cols.constraint_name\n AND cons.owner = cols.owner\n AND cols.position = 1\n AND cons.owner = (select user from dual)\n ORDER BY cols.table_name, cols.position\"",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"connection",
"->",
"selectOne",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"return",
"$",
"data",
"->",
"column_name",
";",
"}",
"return",
"''",
";",
"}"
] | Get table's primary key.
@param string $table
@return string | [
"Get",
"table",
"s",
"primary",
"key",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/OracleAutoIncrementHelper.php#L130-L152 | train |
yajra/laravel-oci8 | src/Oci8/Oci8ServiceProvider.php | Oci8ServiceProvider.boot | public function boot()
{
$this->publishes([
__DIR__ . '/../config/oracle.php' => config_path('oracle.php'),
], 'oracle');
Auth::provider('oracle', function ($app, array $config) {
return new OracleUserProvider($app['hash'], $config['model']);
});
} | php | public function boot()
{
$this->publishes([
__DIR__ . '/../config/oracle.php' => config_path('oracle.php'),
], 'oracle');
Auth::provider('oracle', function ($app, array $config) {
return new OracleUserProvider($app['hash'], $config['model']);
});
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../config/oracle.php'",
"=>",
"config_path",
"(",
"'oracle.php'",
")",
",",
"]",
",",
"'oracle'",
")",
";",
"Auth",
"::",
"provider",
"(",
"'oracle'",
",",
"function",
"(",
"$",
"app",
",",
"array",
"$",
"config",
")",
"{",
"return",
"new",
"OracleUserProvider",
"(",
"$",
"app",
"[",
"'hash'",
"]",
",",
"$",
"config",
"[",
"'model'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Boot Oci8 Provider. | [
"Boot",
"Oci8",
"Provider",
"."
] | 0318976c23e06f20212f57ac162b4ec8af963c6c | https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Oci8ServiceProvider.php#L23-L32 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.