repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
briannesbitt/Carbon
src/Carbon/Traits/Creator.php
Creator.make
public static function make($var) { if ($var instanceof DateTimeInterface) { return static::instance($var); } $date = null; if (is_string($var)) { $var = trim($var); $first = substr($var, 0, 1); if (is_string($var) && $first !== 'P' && $first !== 'R' && preg_match('/[a-z0-9]/i', $var)) { $date = static::parse($var); } } return $date; }
php
public static function make($var) { if ($var instanceof DateTimeInterface) { return static::instance($var); } $date = null; if (is_string($var)) { $var = trim($var); $first = substr($var, 0, 1); if (is_string($var) && $first !== 'P' && $first !== 'R' && preg_match('/[a-z0-9]/i', $var)) { $date = static::parse($var); } } return $date; }
[ "public", "static", "function", "make", "(", "$", "var", ")", "{", "if", "(", "$", "var", "instanceof", "DateTimeInterface", ")", "{", "return", "static", "::", "instance", "(", "$", "var", ")", ";", "}", "$", "date", "=", "null", ";", "if", "(", "is_string", "(", "$", "var", ")", ")", "{", "$", "var", "=", "trim", "(", "$", "var", ")", ";", "$", "first", "=", "substr", "(", "$", "var", ",", "0", ",", "1", ")", ";", "if", "(", "is_string", "(", "$", "var", ")", "&&", "$", "first", "!==", "'P'", "&&", "$", "first", "!==", "'R'", "&&", "preg_match", "(", "'/[a-z0-9]/i'", ",", "$", "var", ")", ")", "{", "$", "date", "=", "static", "::", "parse", "(", "$", "var", ")", ";", "}", "}", "return", "$", "date", ";", "}" ]
Make a Carbon instance from given variable if possible. Always return a new instance. Parse only strings and only these likely to be dates (skip intervals and recurrences). Throw an exception for invalid format, but otherwise return null. @param mixed $var @return static|CarbonInterface|null
[ "Make", "a", "Carbon", "instance", "from", "given", "variable", "if", "possible", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Creator.php#L757-L775
train
briannesbitt/Carbon
src/Carbon/Traits/Converter.php
Converter.toArray
public function toArray() { return [ 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'dayOfWeek' => $this->dayOfWeek, 'dayOfYear' => $this->dayOfYear, 'hour' => $this->hour, 'minute' => $this->minute, 'second' => $this->second, 'micro' => $this->micro, 'timestamp' => $this->timestamp, 'formatted' => $this->rawFormat(defined('static::DEFAULT_TO_STRING_FORMAT') ? static::DEFAULT_TO_STRING_FORMAT : CarbonInterface::DEFAULT_TO_STRING_FORMAT), 'timezone' => $this->timezone, ]; }
php
public function toArray() { return [ 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'dayOfWeek' => $this->dayOfWeek, 'dayOfYear' => $this->dayOfYear, 'hour' => $this->hour, 'minute' => $this->minute, 'second' => $this->second, 'micro' => $this->micro, 'timestamp' => $this->timestamp, 'formatted' => $this->rawFormat(defined('static::DEFAULT_TO_STRING_FORMAT') ? static::DEFAULT_TO_STRING_FORMAT : CarbonInterface::DEFAULT_TO_STRING_FORMAT), 'timezone' => $this->timezone, ]; }
[ "public", "function", "toArray", "(", ")", "{", "return", "[", "'year'", "=>", "$", "this", "->", "year", ",", "'month'", "=>", "$", "this", "->", "month", ",", "'day'", "=>", "$", "this", "->", "day", ",", "'dayOfWeek'", "=>", "$", "this", "->", "dayOfWeek", ",", "'dayOfYear'", "=>", "$", "this", "->", "dayOfYear", ",", "'hour'", "=>", "$", "this", "->", "hour", ",", "'minute'", "=>", "$", "this", "->", "minute", ",", "'second'", "=>", "$", "this", "->", "second", ",", "'micro'", "=>", "$", "this", "->", "micro", ",", "'timestamp'", "=>", "$", "this", "->", "timestamp", ",", "'formatted'", "=>", "$", "this", "->", "rawFormat", "(", "defined", "(", "'static::DEFAULT_TO_STRING_FORMAT'", ")", "?", "static", "::", "DEFAULT_TO_STRING_FORMAT", ":", "CarbonInterface", "::", "DEFAULT_TO_STRING_FORMAT", ")", ",", "'timezone'", "=>", "$", "this", "->", "timezone", ",", "]", ";", "}" ]
Get default array representation. @example ``` var_dump(Carbon::now()->toArray()); ``` @return array
[ "Get", "default", "array", "representation", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Converter.php#L419-L435
train
briannesbitt/Carbon
src/Carbon/CarbonTimeZone.php
CarbonTimeZone.instance
public static function instance($object = null, $objectDump = null) { $tz = $object; if ($tz instanceof static) { return $tz; } if ($tz === null) { return new static(); } if (!$tz instanceof DateTimeZone) { $tz = static::getDateTimeZoneFromName($object); } if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown or bad timezone ('.($objectDump ?: $object).')'); } return false; } return new static($tz->getName()); }
php
public static function instance($object = null, $objectDump = null) { $tz = $object; if ($tz instanceof static) { return $tz; } if ($tz === null) { return new static(); } if (!$tz instanceof DateTimeZone) { $tz = static::getDateTimeZoneFromName($object); } if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown or bad timezone ('.($objectDump ?: $object).')'); } return false; } return new static($tz->getName()); }
[ "public", "static", "function", "instance", "(", "$", "object", "=", "null", ",", "$", "objectDump", "=", "null", ")", "{", "$", "tz", "=", "$", "object", ";", "if", "(", "$", "tz", "instanceof", "static", ")", "{", "return", "$", "tz", ";", "}", "if", "(", "$", "tz", "===", "null", ")", "{", "return", "new", "static", "(", ")", ";", "}", "if", "(", "!", "$", "tz", "instanceof", "DateTimeZone", ")", "{", "$", "tz", "=", "static", "::", "getDateTimeZoneFromName", "(", "$", "object", ")", ";", "}", "if", "(", "$", "tz", "===", "false", ")", "{", "if", "(", "Carbon", "::", "isStrictModeEnabled", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Unknown or bad timezone ('", ".", "(", "$", "objectDump", "?", ":", "$", "object", ")", ".", "')'", ")", ";", "}", "return", "false", ";", "}", "return", "new", "static", "(", "$", "tz", "->", "getName", "(", ")", ")", ";", "}" ]
Create a CarbonTimeZone from mixed input. @param DateTimeZone|string|int|null $object original value to get CarbonTimeZone from it. @param DateTimeZone|string|int|null $objectDump dump of the object for error messages. @return false|static
[ "Create", "a", "CarbonTimeZone", "from", "mixed", "input", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonTimeZone.php#L52-L77
train
briannesbitt/Carbon
src/Carbon/CarbonTimeZone.php
CarbonTimeZone.getAbbreviatedName
public function getAbbreviatedName($dst = false) { $name = $this->getName(); foreach ($this->listAbbreviations() as $abbreviation => $zones) { foreach ($zones as $zone) { if ($zone['timezone_id'] === $name && $zone['dst'] == $dst) { return $abbreviation; } } } return 'unknown'; }
php
public function getAbbreviatedName($dst = false) { $name = $this->getName(); foreach ($this->listAbbreviations() as $abbreviation => $zones) { foreach ($zones as $zone) { if ($zone['timezone_id'] === $name && $zone['dst'] == $dst) { return $abbreviation; } } } return 'unknown'; }
[ "public", "function", "getAbbreviatedName", "(", "$", "dst", "=", "false", ")", "{", "$", "name", "=", "$", "this", "->", "getName", "(", ")", ";", "foreach", "(", "$", "this", "->", "listAbbreviations", "(", ")", "as", "$", "abbreviation", "=>", "$", "zones", ")", "{", "foreach", "(", "$", "zones", "as", "$", "zone", ")", "{", "if", "(", "$", "zone", "[", "'timezone_id'", "]", "===", "$", "name", "&&", "$", "zone", "[", "'dst'", "]", "==", "$", "dst", ")", "{", "return", "$", "abbreviation", ";", "}", "}", "}", "return", "'unknown'", ";", "}" ]
Returns abbreviated name of the current timezone according to DST setting. @param bool $dst @return string
[ "Returns", "abbreviated", "name", "of", "the", "current", "timezone", "according", "to", "DST", "setting", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonTimeZone.php#L86-L99
train
briannesbitt/Carbon
src/Carbon/CarbonTimeZone.php
CarbonTimeZone.toRegionTimeZone
public function toRegionTimeZone(DateTimeInterface $date = null) { $tz = $this->toRegionName($date); if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown timezone for offset '.$this->getOffset($date ?: Carbon::now($this)).' seconds.'); } return false; } return new static($tz); }
php
public function toRegionTimeZone(DateTimeInterface $date = null) { $tz = $this->toRegionName($date); if ($tz === false) { if (Carbon::isStrictModeEnabled()) { throw new InvalidArgumentException('Unknown timezone for offset '.$this->getOffset($date ?: Carbon::now($this)).' seconds.'); } return false; } return new static($tz); }
[ "public", "function", "toRegionTimeZone", "(", "DateTimeInterface", "$", "date", "=", "null", ")", "{", "$", "tz", "=", "$", "this", "->", "toRegionName", "(", "$", "date", ")", ";", "if", "(", "$", "tz", "===", "false", ")", "{", "if", "(", "Carbon", "::", "isStrictModeEnabled", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Unknown timezone for offset '", ".", "$", "this", "->", "getOffset", "(", "$", "date", "?", ":", "Carbon", "::", "now", "(", "$", "this", ")", ")", ".", "' seconds.'", ")", ";", "}", "return", "false", ";", "}", "return", "new", "static", "(", "$", "tz", ")", ";", "}" ]
Returns a new CarbonTimeZone object using the region string instead of offset string. @param DateTimeInterface|null $date @return CarbonTimeZone|false
[ "Returns", "a", "new", "CarbonTimeZone", "object", "using", "the", "region", "string", "instead", "of", "offset", "string", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonTimeZone.php#L174-L187
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.createFromIso
public static function createFromIso($iso, $options = null) { $params = static::parseIso8601($iso); $instance = static::createFromArray($params); if ($options !== null) { $instance->setOptions($options); } return $instance; }
php
public static function createFromIso($iso, $options = null) { $params = static::parseIso8601($iso); $instance = static::createFromArray($params); if ($options !== null) { $instance->setOptions($options); } return $instance; }
[ "public", "static", "function", "createFromIso", "(", "$", "iso", ",", "$", "options", "=", "null", ")", "{", "$", "params", "=", "static", "::", "parseIso8601", "(", "$", "iso", ")", ";", "$", "instance", "=", "static", "::", "createFromArray", "(", "$", "params", ")", ";", "if", "(", "$", "options", "!==", "null", ")", "{", "$", "instance", "->", "setOptions", "(", "$", "options", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create CarbonPeriod from ISO 8601 string. @param string $iso @param int|null $options @return static
[ "Create", "CarbonPeriod", "from", "ISO", "8601", "string", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L264-L275
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.intervalHasTime
protected static function intervalHasTime(DateInterval $interval) { // The array_key_exists and get_object_vars are used as a workaround to check microsecond support. // Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug: // https://bugs.php.net/bug.php?id=74852 return $interval->h || $interval->i || $interval->s || array_key_exists('f', get_object_vars($interval)) && $interval->f; }
php
protected static function intervalHasTime(DateInterval $interval) { // The array_key_exists and get_object_vars are used as a workaround to check microsecond support. // Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug: // https://bugs.php.net/bug.php?id=74852 return $interval->h || $interval->i || $interval->s || array_key_exists('f', get_object_vars($interval)) && $interval->f; }
[ "protected", "static", "function", "intervalHasTime", "(", "DateInterval", "$", "interval", ")", "{", "// The array_key_exists and get_object_vars are used as a workaround to check microsecond support.", "// Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug:", "// https://bugs.php.net/bug.php?id=74852", "return", "$", "interval", "->", "h", "||", "$", "interval", "->", "i", "||", "$", "interval", "->", "s", "||", "array_key_exists", "(", "'f'", ",", "get_object_vars", "(", "$", "interval", ")", ")", "&&", "$", "interval", "->", "f", ";", "}" ]
Return whether given interval contains non zero value of any time unit. @param \DateInterval $interval @return bool
[ "Return", "whether", "given", "interval", "contains", "non", "zero", "value", "of", "any", "time", "unit", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L284-L290
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.parseIso8601
protected static function parseIso8601($iso) { $result = []; $interval = null; $start = null; $end = null; foreach (explode('/', $iso) as $key => $part) { if ($key === 0 && preg_match('/^R([0-9]*)$/', $part, $match)) { $parsed = strlen($match[1]) ? (int) $match[1] : null; } elseif ($interval === null && $parsed = CarbonInterval::make($part)) { $interval = $part; } elseif ($start === null && $parsed = Carbon::make($part)) { $start = $part; } elseif ($end === null && $parsed = Carbon::make(static::addMissingParts($start, $part))) { $end = $part; } else { throw new InvalidArgumentException("Invalid ISO 8601 specification: $iso."); } $result[] = $parsed; } return $result; }
php
protected static function parseIso8601($iso) { $result = []; $interval = null; $start = null; $end = null; foreach (explode('/', $iso) as $key => $part) { if ($key === 0 && preg_match('/^R([0-9]*)$/', $part, $match)) { $parsed = strlen($match[1]) ? (int) $match[1] : null; } elseif ($interval === null && $parsed = CarbonInterval::make($part)) { $interval = $part; } elseif ($start === null && $parsed = Carbon::make($part)) { $start = $part; } elseif ($end === null && $parsed = Carbon::make(static::addMissingParts($start, $part))) { $end = $part; } else { throw new InvalidArgumentException("Invalid ISO 8601 specification: $iso."); } $result[] = $parsed; } return $result; }
[ "protected", "static", "function", "parseIso8601", "(", "$", "iso", ")", "{", "$", "result", "=", "[", "]", ";", "$", "interval", "=", "null", ";", "$", "start", "=", "null", ";", "$", "end", "=", "null", ";", "foreach", "(", "explode", "(", "'/'", ",", "$", "iso", ")", "as", "$", "key", "=>", "$", "part", ")", "{", "if", "(", "$", "key", "===", "0", "&&", "preg_match", "(", "'/^R([0-9]*)$/'", ",", "$", "part", ",", "$", "match", ")", ")", "{", "$", "parsed", "=", "strlen", "(", "$", "match", "[", "1", "]", ")", "?", "(", "int", ")", "$", "match", "[", "1", "]", ":", "null", ";", "}", "elseif", "(", "$", "interval", "===", "null", "&&", "$", "parsed", "=", "CarbonInterval", "::", "make", "(", "$", "part", ")", ")", "{", "$", "interval", "=", "$", "part", ";", "}", "elseif", "(", "$", "start", "===", "null", "&&", "$", "parsed", "=", "Carbon", "::", "make", "(", "$", "part", ")", ")", "{", "$", "start", "=", "$", "part", ";", "}", "elseif", "(", "$", "end", "===", "null", "&&", "$", "parsed", "=", "Carbon", "::", "make", "(", "static", "::", "addMissingParts", "(", "$", "start", ",", "$", "part", ")", ")", ")", "{", "$", "end", "=", "$", "part", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid ISO 8601 specification: $iso.\"", ")", ";", "}", "$", "result", "[", "]", "=", "$", "parsed", ";", "}", "return", "$", "result", ";", "}" ]
Parse given ISO 8601 string into an array of arguments. @param string $iso @return array
[ "Parse", "given", "ISO", "8601", "string", "into", "an", "array", "of", "arguments", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L323-L348
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.addMissingParts
protected static function addMissingParts($source, $target) { $pattern = '/'.preg_replace('/[0-9]+/', '[0-9]+', preg_quote($target, '/')).'$/'; $result = preg_replace($pattern, $target, $source, 1, $count); return $count ? $result : $target; }
php
protected static function addMissingParts($source, $target) { $pattern = '/'.preg_replace('/[0-9]+/', '[0-9]+', preg_quote($target, '/')).'$/'; $result = preg_replace($pattern, $target, $source, 1, $count); return $count ? $result : $target; }
[ "protected", "static", "function", "addMissingParts", "(", "$", "source", ",", "$", "target", ")", "{", "$", "pattern", "=", "'/'", ".", "preg_replace", "(", "'/[0-9]+/'", ",", "'[0-9]+'", ",", "preg_quote", "(", "$", "target", ",", "'/'", ")", ")", ".", "'$/'", ";", "$", "result", "=", "preg_replace", "(", "$", "pattern", ",", "$", "target", ",", "$", "source", ",", "1", ",", "$", "count", ")", ";", "return", "$", "count", "?", "$", "result", ":", "$", "target", ";", "}" ]
Add missing parts of the target date from the soure date. @param string $source @param string $target @return string
[ "Add", "missing", "parts", "of", "the", "target", "date", "from", "the", "soure", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L358-L365
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setDateClass
public function setDateClass(string $dateClass) { if (!is_a($dateClass, CarbonInterface::class, true)) { throw new InvalidArgumentException(sprintf( 'Given class does not implement %s: %s', CarbonInterface::class, $dateClass )); } $this->dateClass = $dateClass; if (is_a($dateClass, Carbon::class, true)) { $this->toggleOptions(static::IMMUTABLE, false); } elseif (is_a($dateClass, CarbonImmutable::class, true)) { $this->toggleOptions(static::IMMUTABLE, true); } return $this; }
php
public function setDateClass(string $dateClass) { if (!is_a($dateClass, CarbonInterface::class, true)) { throw new InvalidArgumentException(sprintf( 'Given class does not implement %s: %s', CarbonInterface::class, $dateClass )); } $this->dateClass = $dateClass; if (is_a($dateClass, Carbon::class, true)) { $this->toggleOptions(static::IMMUTABLE, false); } elseif (is_a($dateClass, CarbonImmutable::class, true)) { $this->toggleOptions(static::IMMUTABLE, true); } return $this; }
[ "public", "function", "setDateClass", "(", "string", "$", "dateClass", ")", "{", "if", "(", "!", "is_a", "(", "$", "dateClass", ",", "CarbonInterface", "::", "class", ",", "true", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Given class does not implement %s: %s'", ",", "CarbonInterface", "::", "class", ",", "$", "dateClass", ")", ")", ";", "}", "$", "this", "->", "dateClass", "=", "$", "dateClass", ";", "if", "(", "is_a", "(", "$", "dateClass", ",", "Carbon", "::", "class", ",", "true", ")", ")", "{", "$", "this", "->", "toggleOptions", "(", "static", "::", "IMMUTABLE", ",", "false", ")", ";", "}", "elseif", "(", "is_a", "(", "$", "dateClass", ",", "CarbonImmutable", "::", "class", ",", "true", ")", ")", "{", "$", "this", "->", "toggleOptions", "(", "static", "::", "IMMUTABLE", ",", "true", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the iteration item class. @param string $dateClass @return $this
[ "Set", "the", "iteration", "item", "class", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L533-L550
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setDateInterval
public function setDateInterval($interval) { if (!$interval = CarbonInterval::make($interval)) { throw new InvalidArgumentException('Invalid interval.'); } if ($interval->spec() === 'PT0S') { throw new InvalidArgumentException('Empty interval is not accepted.'); } $this->dateInterval = $interval; $this->isDefaultInterval = false; $this->handleChangedParameters(); return $this; }
php
public function setDateInterval($interval) { if (!$interval = CarbonInterval::make($interval)) { throw new InvalidArgumentException('Invalid interval.'); } if ($interval->spec() === 'PT0S') { throw new InvalidArgumentException('Empty interval is not accepted.'); } $this->dateInterval = $interval; $this->isDefaultInterval = false; $this->handleChangedParameters(); return $this; }
[ "public", "function", "setDateInterval", "(", "$", "interval", ")", "{", "if", "(", "!", "$", "interval", "=", "CarbonInterval", "::", "make", "(", "$", "interval", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid interval.'", ")", ";", "}", "if", "(", "$", "interval", "->", "spec", "(", ")", "===", "'PT0S'", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Empty interval is not accepted.'", ")", ";", "}", "$", "this", "->", "dateInterval", "=", "$", "interval", ";", "$", "this", "->", "isDefaultInterval", "=", "false", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Change the period date interval. @param DateInterval|string $interval @throws \InvalidArgumentException @return $this
[ "Change", "the", "period", "date", "interval", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L571-L588
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setDates
public function setDates($start, $end) { $this->setStartDate($start); $this->setEndDate($end); return $this; }
php
public function setDates($start, $end) { $this->setStartDate($start); $this->setEndDate($end); return $this; }
[ "public", "function", "setDates", "(", "$", "start", ",", "$", "end", ")", "{", "$", "this", "->", "setStartDate", "(", "$", "start", ")", ";", "$", "this", "->", "setEndDate", "(", "$", "end", ")", ";", "return", "$", "this", ";", "}" ]
Set start and end date. @param DateTime|DateTimeInterface|string $start @param DateTime|DateTimeInterface|string|null $end @return $this
[ "Set", "start", "and", "end", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L610-L616
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setOptions
public function setOptions($options) { if (!is_int($options) && !is_null($options)) { throw new InvalidArgumentException('Invalid options.'); } $this->options = $options ?: 0; $this->handleChangedParameters(); return $this; }
php
public function setOptions($options) { if (!is_int($options) && !is_null($options)) { throw new InvalidArgumentException('Invalid options.'); } $this->options = $options ?: 0; $this->handleChangedParameters(); return $this; }
[ "public", "function", "setOptions", "(", "$", "options", ")", "{", "if", "(", "!", "is_int", "(", "$", "options", ")", "&&", "!", "is_null", "(", "$", "options", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid options.'", ")", ";", "}", "$", "this", "->", "options", "=", "$", "options", "?", ":", "0", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Change the period options. @param int|null $options @throws \InvalidArgumentException @return $this
[ "Change", "the", "period", "options", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L627-L638
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.toggleOptions
public function toggleOptions($options, $state = null) { if ($state === null) { $state = ($this->options & $options) !== $options; } return $this->setOptions( $state ? $this->options | $options : $this->options & ~$options ); }
php
public function toggleOptions($options, $state = null) { if ($state === null) { $state = ($this->options & $options) !== $options; } return $this->setOptions( $state ? $this->options | $options : $this->options & ~$options ); }
[ "public", "function", "toggleOptions", "(", "$", "options", ",", "$", "state", "=", "null", ")", "{", "if", "(", "$", "state", "===", "null", ")", "{", "$", "state", "=", "(", "$", "this", "->", "options", "&", "$", "options", ")", "!==", "$", "options", ";", "}", "return", "$", "this", "->", "setOptions", "(", "$", "state", "?", "$", "this", "->", "options", "|", "$", "options", ":", "$", "this", "->", "options", "&", "~", "$", "options", ")", ";", "}" ]
Toggle given options on or off. @param int $options @param bool|null $state @throws \InvalidArgumentException @return $this
[ "Toggle", "given", "options", "on", "or", "off", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L660-L671
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.addFilter
public function addFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); $this->filters[] = $tuple; $this->handleChangedParameters(); return $this; }
php
public function addFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); $this->filters[] = $tuple; $this->handleChangedParameters(); return $this; }
[ "public", "function", "addFilter", "(", "$", "callback", ",", "$", "name", "=", "null", ")", "{", "$", "tuple", "=", "$", "this", "->", "createFilterTuple", "(", "func_get_args", "(", ")", ")", ";", "$", "this", "->", "filters", "[", "]", "=", "$", "tuple", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Add a filter to the stack. @param callable $callback @param string $name @return $this
[ "Add", "a", "filter", "to", "the", "stack", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L765-L774
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.prependFilter
public function prependFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); array_unshift($this->filters, $tuple); $this->handleChangedParameters(); return $this; }
php
public function prependFilter($callback, $name = null) { $tuple = $this->createFilterTuple(func_get_args()); array_unshift($this->filters, $tuple); $this->handleChangedParameters(); return $this; }
[ "public", "function", "prependFilter", "(", "$", "callback", ",", "$", "name", "=", "null", ")", "{", "$", "tuple", "=", "$", "this", "->", "createFilterTuple", "(", "func_get_args", "(", ")", ")", ";", "array_unshift", "(", "$", "this", "->", "filters", ",", "$", "tuple", ")", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Prepend a filter to the stack. @param callable $callback @param string $name @return $this
[ "Prepend", "a", "filter", "to", "the", "stack", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L784-L793
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.createFilterTuple
protected function createFilterTuple(array $parameters) { $method = array_shift($parameters); if (!$this->isCarbonPredicateMethod($method)) { return [$method, array_shift($parameters)]; } return [function ($date) use ($method, $parameters) { return call_user_func_array([$date, $method], $parameters); }, $method]; }
php
protected function createFilterTuple(array $parameters) { $method = array_shift($parameters); if (!$this->isCarbonPredicateMethod($method)) { return [$method, array_shift($parameters)]; } return [function ($date) use ($method, $parameters) { return call_user_func_array([$date, $method], $parameters); }, $method]; }
[ "protected", "function", "createFilterTuple", "(", "array", "$", "parameters", ")", "{", "$", "method", "=", "array_shift", "(", "$", "parameters", ")", ";", "if", "(", "!", "$", "this", "->", "isCarbonPredicateMethod", "(", "$", "method", ")", ")", "{", "return", "[", "$", "method", ",", "array_shift", "(", "$", "parameters", ")", "]", ";", "}", "return", "[", "function", "(", "$", "date", ")", "use", "(", "$", "method", ",", "$", "parameters", ")", "{", "return", "call_user_func_array", "(", "[", "$", "date", ",", "$", "method", "]", ",", "$", "parameters", ")", ";", "}", ",", "$", "method", "]", ";", "}" ]
Create a filter tuple from raw parameters. Will create an automatic filter callback for one of Carbon's is* methods. @param array $parameters @return array
[ "Create", "a", "filter", "tuple", "from", "raw", "parameters", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L804-L815
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.removeFilter
public function removeFilter($filter) { $key = is_callable($filter) ? 0 : 1; $this->filters = array_values(array_filter( $this->filters, function ($tuple) use ($key, $filter) { return $tuple[$key] !== $filter; } )); $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
php
public function removeFilter($filter) { $key = is_callable($filter) ? 0 : 1; $this->filters = array_values(array_filter( $this->filters, function ($tuple) use ($key, $filter) { return $tuple[$key] !== $filter; } )); $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
[ "public", "function", "removeFilter", "(", "$", "filter", ")", "{", "$", "key", "=", "is_callable", "(", "$", "filter", ")", "?", "0", ":", "1", ";", "$", "this", "->", "filters", "=", "array_values", "(", "array_filter", "(", "$", "this", "->", "filters", ",", "function", "(", "$", "tuple", ")", "use", "(", "$", "key", ",", "$", "filter", ")", "{", "return", "$", "tuple", "[", "$", "key", "]", "!==", "$", "filter", ";", "}", ")", ")", ";", "$", "this", "->", "updateInternalState", "(", ")", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Remove a filter by instance or name. @param callable|string $filter @return $this
[ "Remove", "a", "filter", "by", "instance", "or", "name", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L824-L840
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.hasFilter
public function hasFilter($filter) { $key = is_callable($filter) ? 0 : 1; foreach ($this->filters as $tuple) { if ($tuple[$key] === $filter) { return true; } } return false; }
php
public function hasFilter($filter) { $key = is_callable($filter) ? 0 : 1; foreach ($this->filters as $tuple) { if ($tuple[$key] === $filter) { return true; } } return false; }
[ "public", "function", "hasFilter", "(", "$", "filter", ")", "{", "$", "key", "=", "is_callable", "(", "$", "filter", ")", "?", "0", ":", "1", ";", "foreach", "(", "$", "this", "->", "filters", "as", "$", "tuple", ")", "{", "if", "(", "$", "tuple", "[", "$", "key", "]", "===", "$", "filter", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Return whether given instance or name is in the filter stack. @param callable|string $filter @return bool
[ "Return", "whether", "given", "instance", "or", "name", "is", "in", "the", "filter", "stack", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L849-L860
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setFilters
public function setFilters(array $filters) { $this->filters = $filters; $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
php
public function setFilters(array $filters) { $this->filters = $filters; $this->updateInternalState(); $this->handleChangedParameters(); return $this; }
[ "public", "function", "setFilters", "(", "array", "$", "filters", ")", "{", "$", "this", "->", "filters", "=", "$", "filters", ";", "$", "this", "->", "updateInternalState", "(", ")", ";", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set filters stack. @param array $filters @return $this
[ "Set", "filters", "stack", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L879-L888
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.resetFilters
public function resetFilters() { $this->filters = []; if ($this->endDate !== null) { $this->filters[] = [static::END_DATE_FILTER, null]; } if ($this->recurrences !== null) { $this->filters[] = [static::RECURRENCES_FILTER, null]; } $this->handleChangedParameters(); return $this; }
php
public function resetFilters() { $this->filters = []; if ($this->endDate !== null) { $this->filters[] = [static::END_DATE_FILTER, null]; } if ($this->recurrences !== null) { $this->filters[] = [static::RECURRENCES_FILTER, null]; } $this->handleChangedParameters(); return $this; }
[ "public", "function", "resetFilters", "(", ")", "{", "$", "this", "->", "filters", "=", "[", "]", ";", "if", "(", "$", "this", "->", "endDate", "!==", "null", ")", "{", "$", "this", "->", "filters", "[", "]", "=", "[", "static", "::", "END_DATE_FILTER", ",", "null", "]", ";", "}", "if", "(", "$", "this", "->", "recurrences", "!==", "null", ")", "{", "$", "this", "->", "filters", "[", "]", "=", "[", "static", "::", "RECURRENCES_FILTER", ",", "null", "]", ";", "}", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Reset filters stack. @return $this
[ "Reset", "filters", "stack", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L895-L910
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.updateInternalState
protected function updateInternalState() { if (!$this->hasFilter(static::END_DATE_FILTER)) { $this->endDate = null; } if (!$this->hasFilter(static::RECURRENCES_FILTER)) { $this->recurrences = null; } }
php
protected function updateInternalState() { if (!$this->hasFilter(static::END_DATE_FILTER)) { $this->endDate = null; } if (!$this->hasFilter(static::RECURRENCES_FILTER)) { $this->recurrences = null; } }
[ "protected", "function", "updateInternalState", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasFilter", "(", "static", "::", "END_DATE_FILTER", ")", ")", "{", "$", "this", "->", "endDate", "=", "null", ";", "}", "if", "(", "!", "$", "this", "->", "hasFilter", "(", "static", "::", "RECURRENCES_FILTER", ")", ")", "{", "$", "this", "->", "recurrences", "=", "null", ";", "}", "}" ]
Update properties after removing built-in filters. @return void
[ "Update", "properties", "after", "removing", "built", "-", "in", "filters", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L917-L926
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setStartDate
public function setStartDate($date, $inclusive = null) { if (!$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid start date.'); } $this->startDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_START_DATE, !$inclusive); } return $this; }
php
public function setStartDate($date, $inclusive = null) { if (!$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid start date.'); } $this->startDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_START_DATE, !$inclusive); } return $this; }
[ "public", "function", "setStartDate", "(", "$", "date", ",", "$", "inclusive", "=", "null", ")", "{", "if", "(", "!", "$", "date", "=", "call_user_func", "(", "[", "$", "this", "->", "dateClass", ",", "'make'", "]", ",", "$", "date", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid start date.'", ")", ";", "}", "$", "this", "->", "startDate", "=", "$", "date", ";", "if", "(", "$", "inclusive", "!==", "null", ")", "{", "$", "this", "->", "toggleOptions", "(", "static", "::", "EXCLUDE_START_DATE", ",", "!", "$", "inclusive", ")", ";", "}", "return", "$", "this", ";", "}" ]
Change the period start date. @param DateTime|DateTimeInterface|string $date @param bool|null $inclusive @throws \InvalidArgumentException @return $this
[ "Change", "the", "period", "start", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L985-L998
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.setEndDate
public function setEndDate($date, $inclusive = null) { if (!is_null($date) && !$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid end date.'); } if (!$date) { return $this->removeFilter(static::END_DATE_FILTER); } $this->endDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive); } if (!$this->hasFilter(static::END_DATE_FILTER)) { return $this->addFilter(static::END_DATE_FILTER); } $this->handleChangedParameters(); return $this; }
php
public function setEndDate($date, $inclusive = null) { if (!is_null($date) && !$date = call_user_func([$this->dateClass, 'make'], $date)) { throw new InvalidArgumentException('Invalid end date.'); } if (!$date) { return $this->removeFilter(static::END_DATE_FILTER); } $this->endDate = $date; if ($inclusive !== null) { $this->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive); } if (!$this->hasFilter(static::END_DATE_FILTER)) { return $this->addFilter(static::END_DATE_FILTER); } $this->handleChangedParameters(); return $this; }
[ "public", "function", "setEndDate", "(", "$", "date", ",", "$", "inclusive", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "date", ")", "&&", "!", "$", "date", "=", "call_user_func", "(", "[", "$", "this", "->", "dateClass", ",", "'make'", "]", ",", "$", "date", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid end date.'", ")", ";", "}", "if", "(", "!", "$", "date", ")", "{", "return", "$", "this", "->", "removeFilter", "(", "static", "::", "END_DATE_FILTER", ")", ";", "}", "$", "this", "->", "endDate", "=", "$", "date", ";", "if", "(", "$", "inclusive", "!==", "null", ")", "{", "$", "this", "->", "toggleOptions", "(", "static", "::", "EXCLUDE_END_DATE", ",", "!", "$", "inclusive", ")", ";", "}", "if", "(", "!", "$", "this", "->", "hasFilter", "(", "static", "::", "END_DATE_FILTER", ")", ")", "{", "return", "$", "this", "->", "addFilter", "(", "static", "::", "END_DATE_FILTER", ")", ";", "}", "$", "this", "->", "handleChangedParameters", "(", ")", ";", "return", "$", "this", ";", "}" ]
Change the period end date. @param DateTime|DateTimeInterface|string|null $date @param bool|null $inclusive @throws \InvalidArgumentException @return $this
[ "Change", "the", "period", "end", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1010-L1033
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.filterEndDate
protected function filterEndDate($current) { if (!$this->isEndExcluded() && $current == $this->endDate) { return true; } if ($this->dateInterval->invert ? $current > $this->endDate : $current < $this->endDate) { return true; } return static::END_ITERATION; }
php
protected function filterEndDate($current) { if (!$this->isEndExcluded() && $current == $this->endDate) { return true; } if ($this->dateInterval->invert ? $current > $this->endDate : $current < $this->endDate) { return true; } return static::END_ITERATION; }
[ "protected", "function", "filterEndDate", "(", "$", "current", ")", "{", "if", "(", "!", "$", "this", "->", "isEndExcluded", "(", ")", "&&", "$", "current", "==", "$", "this", "->", "endDate", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "dateInterval", "->", "invert", "?", "$", "current", ">", "$", "this", "->", "endDate", ":", "$", "current", "<", "$", "this", "->", "endDate", ")", "{", "return", "true", ";", "}", "return", "static", "::", "END_ITERATION", ";", "}" ]
End date filter callback. @param \Carbon\Carbon $current @return bool|string
[ "End", "date", "filter", "callback", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1042-L1053
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.handleChangedParameters
protected function handleChangedParameters() { if (($this->getOptions() & static::IMMUTABLE) && $this->dateClass === Carbon::class) { $this->setDateClass(CarbonImmutable::class); } elseif (!($this->getOptions() & static::IMMUTABLE) && $this->dateClass === CarbonImmutable::class) { $this->setDateClass(Carbon::class); } $this->validationResult = null; }
php
protected function handleChangedParameters() { if (($this->getOptions() & static::IMMUTABLE) && $this->dateClass === Carbon::class) { $this->setDateClass(CarbonImmutable::class); } elseif (!($this->getOptions() & static::IMMUTABLE) && $this->dateClass === CarbonImmutable::class) { $this->setDateClass(Carbon::class); } $this->validationResult = null; }
[ "protected", "function", "handleChangedParameters", "(", ")", "{", "if", "(", "(", "$", "this", "->", "getOptions", "(", ")", "&", "static", "::", "IMMUTABLE", ")", "&&", "$", "this", "->", "dateClass", "===", "Carbon", "::", "class", ")", "{", "$", "this", "->", "setDateClass", "(", "CarbonImmutable", "::", "class", ")", ";", "}", "elseif", "(", "!", "(", "$", "this", "->", "getOptions", "(", ")", "&", "static", "::", "IMMUTABLE", ")", "&&", "$", "this", "->", "dateClass", "===", "CarbonImmutable", "::", "class", ")", "{", "$", "this", "->", "setDateClass", "(", "Carbon", "::", "class", ")", ";", "}", "$", "this", "->", "validationResult", "=", "null", ";", "}" ]
Handle change of the parameters.
[ "Handle", "change", "of", "the", "parameters", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1068-L1077
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.validateCurrentDate
protected function validateCurrentDate() { if ($this->current === null) { $this->rewind(); } // Check after the first rewind to avoid repeating the initial validation. if ($this->validationResult !== null) { return $this->validationResult; } return $this->validationResult = $this->checkFilters(); }
php
protected function validateCurrentDate() { if ($this->current === null) { $this->rewind(); } // Check after the first rewind to avoid repeating the initial validation. if ($this->validationResult !== null) { return $this->validationResult; } return $this->validationResult = $this->checkFilters(); }
[ "protected", "function", "validateCurrentDate", "(", ")", "{", "if", "(", "$", "this", "->", "current", "===", "null", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "}", "// Check after the first rewind to avoid repeating the initial validation.", "if", "(", "$", "this", "->", "validationResult", "!==", "null", ")", "{", "return", "$", "this", "->", "validationResult", ";", "}", "return", "$", "this", "->", "validationResult", "=", "$", "this", "->", "checkFilters", "(", ")", ";", "}" ]
Validate current date and stop iteration when necessary. Returns true when current date is valid, false if it is not, or static::END_ITERATION when iteration should be stopped. @return bool|string
[ "Validate", "current", "date", "and", "stop", "iteration", "when", "necessary", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1087-L1099
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.checkFilters
protected function checkFilters() { $current = $this->prepareForReturn($this->current); foreach ($this->filters as $tuple) { $result = call_user_func( $tuple[0], $current->copy(), $this->key, $this ); if ($result === static::END_ITERATION) { return static::END_ITERATION; } if (!$result) { return false; } } return true; }
php
protected function checkFilters() { $current = $this->prepareForReturn($this->current); foreach ($this->filters as $tuple) { $result = call_user_func( $tuple[0], $current->copy(), $this->key, $this ); if ($result === static::END_ITERATION) { return static::END_ITERATION; } if (!$result) { return false; } } return true; }
[ "protected", "function", "checkFilters", "(", ")", "{", "$", "current", "=", "$", "this", "->", "prepareForReturn", "(", "$", "this", "->", "current", ")", ";", "foreach", "(", "$", "this", "->", "filters", "as", "$", "tuple", ")", "{", "$", "result", "=", "call_user_func", "(", "$", "tuple", "[", "0", "]", ",", "$", "current", "->", "copy", "(", ")", ",", "$", "this", "->", "key", ",", "$", "this", ")", ";", "if", "(", "$", "result", "===", "static", "::", "END_ITERATION", ")", "{", "return", "static", "::", "END_ITERATION", ";", "}", "if", "(", "!", "$", "result", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check whether current value and key pass all the filters. @return bool|string
[ "Check", "whether", "current", "value", "and", "key", "pass", "all", "the", "filters", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1106-L1128
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.prepareForReturn
protected function prepareForReturn(CarbonInterface $date) { $date = call_user_func([$this->dateClass, 'make'], $date); if ($this->timezone) { $date = $date->setTimezone($this->timezone); } return $date; }
php
protected function prepareForReturn(CarbonInterface $date) { $date = call_user_func([$this->dateClass, 'make'], $date); if ($this->timezone) { $date = $date->setTimezone($this->timezone); } return $date; }
[ "protected", "function", "prepareForReturn", "(", "CarbonInterface", "$", "date", ")", "{", "$", "date", "=", "call_user_func", "(", "[", "$", "this", "->", "dateClass", ",", "'make'", "]", ",", "$", "date", ")", ";", "if", "(", "$", "this", "->", "timezone", ")", "{", "$", "date", "=", "$", "date", "->", "setTimezone", "(", "$", "this", "->", "timezone", ")", ";", "}", "return", "$", "date", ";", "}" ]
Prepare given date to be returned to the external logic. @param CarbonInterface $date @return Carbon
[ "Prepare", "given", "date", "to", "be", "returned", "to", "the", "external", "logic", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1137-L1146
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.next
public function next() { if ($this->current === null) { $this->rewind(); } if ($this->validationResult !== static::END_ITERATION) { $this->key++; $this->incrementCurrentDateUntilValid(); } }
php
public function next() { if ($this->current === null) { $this->rewind(); } if ($this->validationResult !== static::END_ITERATION) { $this->key++; $this->incrementCurrentDateUntilValid(); } }
[ "public", "function", "next", "(", ")", "{", "if", "(", "$", "this", "->", "current", "===", "null", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "}", "if", "(", "$", "this", "->", "validationResult", "!==", "static", "::", "END_ITERATION", ")", "{", "$", "this", "->", "key", "++", ";", "$", "this", "->", "incrementCurrentDateUntilValid", "(", ")", ";", "}", "}" ]
Move forward to the next date. @throws \RuntimeException @return void
[ "Move", "forward", "to", "the", "next", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1189-L1200
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.rewind
public function rewind() { $this->key = 0; $this->current = call_user_func([$this->dateClass, 'make'], $this->startDate); $settings = $this->getSettings(); $locale = $this->getLocalTranslator()->getLocale(); if ($locale) { $settings['locale'] = $locale; } $this->current->settings($settings); $this->timezone = static::intervalHasTime($this->dateInterval) ? $this->current->getTimezone() : null; if ($this->timezone) { $this->current = $this->current->utc(); } $this->validationResult = null; if ($this->isStartExcluded() || $this->validateCurrentDate() === false) { $this->incrementCurrentDateUntilValid(); } }
php
public function rewind() { $this->key = 0; $this->current = call_user_func([$this->dateClass, 'make'], $this->startDate); $settings = $this->getSettings(); $locale = $this->getLocalTranslator()->getLocale(); if ($locale) { $settings['locale'] = $locale; } $this->current->settings($settings); $this->timezone = static::intervalHasTime($this->dateInterval) ? $this->current->getTimezone() : null; if ($this->timezone) { $this->current = $this->current->utc(); } $this->validationResult = null; if ($this->isStartExcluded() || $this->validateCurrentDate() === false) { $this->incrementCurrentDateUntilValid(); } }
[ "public", "function", "rewind", "(", ")", "{", "$", "this", "->", "key", "=", "0", ";", "$", "this", "->", "current", "=", "call_user_func", "(", "[", "$", "this", "->", "dateClass", ",", "'make'", "]", ",", "$", "this", "->", "startDate", ")", ";", "$", "settings", "=", "$", "this", "->", "getSettings", "(", ")", ";", "$", "locale", "=", "$", "this", "->", "getLocalTranslator", "(", ")", "->", "getLocale", "(", ")", ";", "if", "(", "$", "locale", ")", "{", "$", "settings", "[", "'locale'", "]", "=", "$", "locale", ";", "}", "$", "this", "->", "current", "->", "settings", "(", "$", "settings", ")", ";", "$", "this", "->", "timezone", "=", "static", "::", "intervalHasTime", "(", "$", "this", "->", "dateInterval", ")", "?", "$", "this", "->", "current", "->", "getTimezone", "(", ")", ":", "null", ";", "if", "(", "$", "this", "->", "timezone", ")", "{", "$", "this", "->", "current", "=", "$", "this", "->", "current", "->", "utc", "(", ")", ";", "}", "$", "this", "->", "validationResult", "=", "null", ";", "if", "(", "$", "this", "->", "isStartExcluded", "(", ")", "||", "$", "this", "->", "validateCurrentDate", "(", ")", "===", "false", ")", "{", "$", "this", "->", "incrementCurrentDateUntilValid", "(", ")", ";", "}", "}" ]
Rewind to the start date. Iterating over a date in the UTC timezone avoids bug during backward DST change. @see https://bugs.php.net/bug.php?id=72255 @see https://bugs.php.net/bug.php?id=74274 @see https://wiki.php.net/rfc/datetime_and_daylight_saving_time @throws \RuntimeException @return void
[ "Rewind", "to", "the", "start", "date", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1215-L1236
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.incrementCurrentDateUntilValid
protected function incrementCurrentDateUntilValid() { $attempts = 0; do { $this->current = $this->current->add($this->dateInterval); $this->validationResult = null; if (++$attempts > static::NEXT_MAX_ATTEMPTS) { throw new RuntimeException('Could not find next valid date.'); } } while ($this->validateCurrentDate() === false); }
php
protected function incrementCurrentDateUntilValid() { $attempts = 0; do { $this->current = $this->current->add($this->dateInterval); $this->validationResult = null; if (++$attempts > static::NEXT_MAX_ATTEMPTS) { throw new RuntimeException('Could not find next valid date.'); } } while ($this->validateCurrentDate() === false); }
[ "protected", "function", "incrementCurrentDateUntilValid", "(", ")", "{", "$", "attempts", "=", "0", ";", "do", "{", "$", "this", "->", "current", "=", "$", "this", "->", "current", "->", "add", "(", "$", "this", "->", "dateInterval", ")", ";", "$", "this", "->", "validationResult", "=", "null", ";", "if", "(", "++", "$", "attempts", ">", "static", "::", "NEXT_MAX_ATTEMPTS", ")", "{", "throw", "new", "RuntimeException", "(", "'Could not find next valid date.'", ")", ";", "}", "}", "while", "(", "$", "this", "->", "validateCurrentDate", "(", ")", "===", "false", ")", ";", "}" ]
Keep incrementing the current date until a valid date is found or the iteration is ended. @throws \RuntimeException @return void
[ "Keep", "incrementing", "the", "current", "date", "until", "a", "valid", "date", "is", "found", "or", "the", "iteration", "is", "ended", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1261-L1274
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.toIso8601String
public function toIso8601String() { $parts = []; if ($this->recurrences !== null) { $parts[] = 'R'.$this->recurrences; } $parts[] = $this->startDate->toIso8601String(); $parts[] = $this->dateInterval->spec(); if ($this->endDate !== null) { $parts[] = $this->endDate->toIso8601String(); } return implode('/', $parts); }
php
public function toIso8601String() { $parts = []; if ($this->recurrences !== null) { $parts[] = 'R'.$this->recurrences; } $parts[] = $this->startDate->toIso8601String(); $parts[] = $this->dateInterval->spec(); if ($this->endDate !== null) { $parts[] = $this->endDate->toIso8601String(); } return implode('/', $parts); }
[ "public", "function", "toIso8601String", "(", ")", "{", "$", "parts", "=", "[", "]", ";", "if", "(", "$", "this", "->", "recurrences", "!==", "null", ")", "{", "$", "parts", "[", "]", "=", "'R'", ".", "$", "this", "->", "recurrences", ";", "}", "$", "parts", "[", "]", "=", "$", "this", "->", "startDate", "->", "toIso8601String", "(", ")", ";", "$", "parts", "[", "]", "=", "$", "this", "->", "dateInterval", "->", "spec", "(", ")", ";", "if", "(", "$", "this", "->", "endDate", "!==", "null", ")", "{", "$", "parts", "[", "]", "=", "$", "this", "->", "endDate", "->", "toIso8601String", "(", ")", ";", "}", "return", "implode", "(", "'/'", ",", "$", "parts", ")", ";", "}" ]
Format the date period as ISO 8601. @return string
[ "Format", "the", "date", "period", "as", "ISO", "8601", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1281-L1298
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.toString
public function toString() { $translator = call_user_func([$this->dateClass, 'getTranslator']); $parts = []; $format = !$this->startDate->isStartOfDay() || $this->endDate && !$this->endDate->isStartOfDay() ? 'Y-m-d H:i:s' : 'Y-m-d'; if ($this->recurrences !== null) { $parts[] = $this->translate('period_recurrences', [], $this->recurrences, $translator); } $parts[] = $this->translate('period_interval', [':interval' => $this->dateInterval->forHumans([ 'join' => true, ])], null, $translator); $parts[] = $this->translate('period_start_date', [':date' => $this->startDate->rawFormat($format)], null, $translator); if ($this->endDate !== null) { $parts[] = $this->translate('period_end_date', [':date' => $this->endDate->rawFormat($format)], null, $translator); } $result = implode(' ', $parts); return mb_strtoupper(mb_substr($result, 0, 1)).mb_substr($result, 1); }
php
public function toString() { $translator = call_user_func([$this->dateClass, 'getTranslator']); $parts = []; $format = !$this->startDate->isStartOfDay() || $this->endDate && !$this->endDate->isStartOfDay() ? 'Y-m-d H:i:s' : 'Y-m-d'; if ($this->recurrences !== null) { $parts[] = $this->translate('period_recurrences', [], $this->recurrences, $translator); } $parts[] = $this->translate('period_interval', [':interval' => $this->dateInterval->forHumans([ 'join' => true, ])], null, $translator); $parts[] = $this->translate('period_start_date', [':date' => $this->startDate->rawFormat($format)], null, $translator); if ($this->endDate !== null) { $parts[] = $this->translate('period_end_date', [':date' => $this->endDate->rawFormat($format)], null, $translator); } $result = implode(' ', $parts); return mb_strtoupper(mb_substr($result, 0, 1)).mb_substr($result, 1); }
[ "public", "function", "toString", "(", ")", "{", "$", "translator", "=", "call_user_func", "(", "[", "$", "this", "->", "dateClass", ",", "'getTranslator'", "]", ")", ";", "$", "parts", "=", "[", "]", ";", "$", "format", "=", "!", "$", "this", "->", "startDate", "->", "isStartOfDay", "(", ")", "||", "$", "this", "->", "endDate", "&&", "!", "$", "this", "->", "endDate", "->", "isStartOfDay", "(", ")", "?", "'Y-m-d H:i:s'", ":", "'Y-m-d'", ";", "if", "(", "$", "this", "->", "recurrences", "!==", "null", ")", "{", "$", "parts", "[", "]", "=", "$", "this", "->", "translate", "(", "'period_recurrences'", ",", "[", "]", ",", "$", "this", "->", "recurrences", ",", "$", "translator", ")", ";", "}", "$", "parts", "[", "]", "=", "$", "this", "->", "translate", "(", "'period_interval'", ",", "[", "':interval'", "=>", "$", "this", "->", "dateInterval", "->", "forHumans", "(", "[", "'join'", "=>", "true", ",", "]", ")", "]", ",", "null", ",", "$", "translator", ")", ";", "$", "parts", "[", "]", "=", "$", "this", "->", "translate", "(", "'period_start_date'", ",", "[", "':date'", "=>", "$", "this", "->", "startDate", "->", "rawFormat", "(", "$", "format", ")", "]", ",", "null", ",", "$", "translator", ")", ";", "if", "(", "$", "this", "->", "endDate", "!==", "null", ")", "{", "$", "parts", "[", "]", "=", "$", "this", "->", "translate", "(", "'period_end_date'", ",", "[", "':date'", "=>", "$", "this", "->", "endDate", "->", "rawFormat", "(", "$", "format", ")", "]", ",", "null", ",", "$", "translator", ")", ";", "}", "$", "result", "=", "implode", "(", "' '", ",", "$", "parts", ")", ";", "return", "mb_strtoupper", "(", "mb_substr", "(", "$", "result", ",", "0", ",", "1", ")", ")", ".", "mb_substr", "(", "$", "result", ",", "1", ")", ";", "}" ]
Convert the date period into a string. @return string
[ "Convert", "the", "date", "period", "into", "a", "string", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1305-L1332
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.toArray
public function toArray() { $state = [ $this->key, $this->current ? $this->current->copy() : null, $this->validationResult, ]; $result = iterator_to_array($this); [ $this->key, $this->current, $this->validationResult ] = $state; return $result; }
php
public function toArray() { $state = [ $this->key, $this->current ? $this->current->copy() : null, $this->validationResult, ]; $result = iterator_to_array($this); [ $this->key, $this->current, $this->validationResult ] = $state; return $result; }
[ "public", "function", "toArray", "(", ")", "{", "$", "state", "=", "[", "$", "this", "->", "key", ",", "$", "this", "->", "current", "?", "$", "this", "->", "current", "->", "copy", "(", ")", ":", "null", ",", "$", "this", "->", "validationResult", ",", "]", ";", "$", "result", "=", "iterator_to_array", "(", "$", "this", ")", ";", "[", "$", "this", "->", "key", ",", "$", "this", "->", "current", ",", "$", "this", "->", "validationResult", "]", "=", "$", "state", ";", "return", "$", "result", ";", "}" ]
Convert the date period into an array without changing current iteration state. @return array
[ "Convert", "the", "date", "period", "into", "an", "array", "without", "changing", "current", "iteration", "state", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1349-L1366
train
briannesbitt/Carbon
src/Carbon/CarbonPeriod.php
CarbonPeriod.callMacro
protected function callMacro($name, $parameters) { $macro = static::$macros[$name]; if ($macro instanceof Closure) { return call_user_func_array($macro->bindTo($this, static::class), $parameters); } return call_user_func_array($macro, $parameters); }
php
protected function callMacro($name, $parameters) { $macro = static::$macros[$name]; if ($macro instanceof Closure) { return call_user_func_array($macro->bindTo($this, static::class), $parameters); } return call_user_func_array($macro, $parameters); }
[ "protected", "function", "callMacro", "(", "$", "name", ",", "$", "parameters", ")", "{", "$", "macro", "=", "static", "::", "$", "macros", "[", "$", "name", "]", ";", "if", "(", "$", "macro", "instanceof", "Closure", ")", "{", "return", "call_user_func_array", "(", "$", "macro", "->", "bindTo", "(", "$", "this", ",", "static", "::", "class", ")", ",", "$", "parameters", ")", ";", "}", "return", "call_user_func_array", "(", "$", "macro", ",", "$", "parameters", ")", ";", "}" ]
Call given macro. @param string $name @param array $parameters @return mixed
[ "Call", "given", "macro", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonPeriod.php#L1410-L1419
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.getCascadeFactors
public static function getCascadeFactors() { return static::$cascadeFactors ?: [ 'milliseconds' => [Carbon::MICROSECONDS_PER_MILLISECOND, 'microseconds'], 'seconds' => [Carbon::MILLISECONDS_PER_SECOND, 'milliseconds'], 'minutes' => [Carbon::SECONDS_PER_MINUTE, 'seconds'], 'hours' => [Carbon::MINUTES_PER_HOUR, 'minutes'], 'dayz' => [Carbon::HOURS_PER_DAY, 'hours'], 'months' => [Carbon::DAYS_PER_WEEK * Carbon::WEEKS_PER_MONTH, 'dayz'], 'years' => [Carbon::MONTHS_PER_YEAR, 'months'], ]; }
php
public static function getCascadeFactors() { return static::$cascadeFactors ?: [ 'milliseconds' => [Carbon::MICROSECONDS_PER_MILLISECOND, 'microseconds'], 'seconds' => [Carbon::MILLISECONDS_PER_SECOND, 'milliseconds'], 'minutes' => [Carbon::SECONDS_PER_MINUTE, 'seconds'], 'hours' => [Carbon::MINUTES_PER_HOUR, 'minutes'], 'dayz' => [Carbon::HOURS_PER_DAY, 'hours'], 'months' => [Carbon::DAYS_PER_WEEK * Carbon::WEEKS_PER_MONTH, 'dayz'], 'years' => [Carbon::MONTHS_PER_YEAR, 'months'], ]; }
[ "public", "static", "function", "getCascadeFactors", "(", ")", "{", "return", "static", "::", "$", "cascadeFactors", "?", ":", "[", "'milliseconds'", "=>", "[", "Carbon", "::", "MICROSECONDS_PER_MILLISECOND", ",", "'microseconds'", "]", ",", "'seconds'", "=>", "[", "Carbon", "::", "MILLISECONDS_PER_SECOND", ",", "'milliseconds'", "]", ",", "'minutes'", "=>", "[", "Carbon", "::", "SECONDS_PER_MINUTE", ",", "'seconds'", "]", ",", "'hours'", "=>", "[", "Carbon", "::", "MINUTES_PER_HOUR", ",", "'minutes'", "]", ",", "'dayz'", "=>", "[", "Carbon", "::", "HOURS_PER_DAY", ",", "'hours'", "]", ",", "'months'", "=>", "[", "Carbon", "::", "DAYS_PER_WEEK", "*", "Carbon", "::", "WEEKS_PER_MONTH", ",", "'dayz'", "]", ",", "'years'", "=>", "[", "Carbon", "::", "MONTHS_PER_YEAR", ",", "'months'", "]", ",", "]", ";", "}" ]
Mapping of units and factors for cascading. Should only be modified by changing the factors or referenced constants. @return array
[ "Mapping", "of", "units", "and", "factors", "for", "cascading", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L149-L160
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.getFactor
public static function getFactor($source, $target) { $source = self::standardizeUnit($source); $target = self::standardizeUnit($target); $factors = static::getFlipCascadeFactors(); if (isset($factors[$source])) { [$to, $factor] = $factors[$source]; if ($to === $target) { return $factor; } } return null; }
php
public static function getFactor($source, $target) { $source = self::standardizeUnit($source); $target = self::standardizeUnit($target); $factors = static::getFlipCascadeFactors(); if (isset($factors[$source])) { [$to, $factor] = $factors[$source]; if ($to === $target) { return $factor; } } return null; }
[ "public", "static", "function", "getFactor", "(", "$", "source", ",", "$", "target", ")", "{", "$", "source", "=", "self", "::", "standardizeUnit", "(", "$", "source", ")", ";", "$", "target", "=", "self", "::", "standardizeUnit", "(", "$", "target", ")", ";", "$", "factors", "=", "static", "::", "getFlipCascadeFactors", "(", ")", ";", "if", "(", "isset", "(", "$", "factors", "[", "$", "source", "]", ")", ")", "{", "[", "$", "to", ",", "$", "factor", "]", "=", "$", "factors", "[", "$", "source", "]", ";", "if", "(", "$", "to", "===", "$", "target", ")", "{", "return", "$", "factor", ";", "}", "}", "return", "null", ";", "}" ]
Returns the factor for a given source-to-target couple. @param string $source @param string $target @return int|null
[ "Returns", "the", "factor", "for", "a", "given", "source", "-", "to", "-", "target", "couple", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L254-L267
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.make
public static function make($var) { if ($var instanceof DateInterval) { return static::instance($var); } if (!is_string($var)) { return null; } $var = trim($var); if (preg_match('/^P[T0-9]/', $var)) { return new static($var); } if (preg_match('/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i', $var)) { return static::fromString($var); } /** @var static $interval */ $interval = static::createFromDateString($var); return $interval->isEmpty() ? null : $interval; }
php
public static function make($var) { if ($var instanceof DateInterval) { return static::instance($var); } if (!is_string($var)) { return null; } $var = trim($var); if (preg_match('/^P[T0-9]/', $var)) { return new static($var); } if (preg_match('/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i', $var)) { return static::fromString($var); } /** @var static $interval */ $interval = static::createFromDateString($var); return $interval->isEmpty() ? null : $interval; }
[ "public", "static", "function", "make", "(", "$", "var", ")", "{", "if", "(", "$", "var", "instanceof", "DateInterval", ")", "{", "return", "static", "::", "instance", "(", "$", "var", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "var", ")", ")", "{", "return", "null", ";", "}", "$", "var", "=", "trim", "(", "$", "var", ")", ";", "if", "(", "preg_match", "(", "'/^P[T0-9]/'", ",", "$", "var", ")", ")", "{", "return", "new", "static", "(", "$", "var", ")", ";", "}", "if", "(", "preg_match", "(", "'/^(?:\\h*\\d+(?:\\.\\d+)?\\h*[a-z]+)+$/i'", ",", "$", "var", ")", ")", "{", "return", "static", "::", "fromString", "(", "$", "var", ")", ";", "}", "/** @var static $interval */", "$", "interval", "=", "static", "::", "createFromDateString", "(", "$", "var", ")", ";", "return", "$", "interval", "->", "isEmpty", "(", ")", "?", "null", ":", "$", "interval", ";", "}" ]
Make a CarbonInterval instance from given variable if possible. Always return a new instance. Parse only strings and only these likely to be intervals (skip dates and recurrences). Throw an exception for invalid format, but otherwise return null. @param mixed $var @return static|null
[ "Make", "a", "CarbonInterval", "instance", "from", "given", "variable", "if", "possible", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L599-L623
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.createFromDateString
public static function createFromDateString($time) { $interval = parent::createFromDateString($time); if ($interval instanceof DateInterval && !($interval instanceof static)) { $interval = static::instance($interval); } return static::instance($interval); }
php
public static function createFromDateString($time) { $interval = parent::createFromDateString($time); if ($interval instanceof DateInterval && !($interval instanceof static)) { $interval = static::instance($interval); } return static::instance($interval); }
[ "public", "static", "function", "createFromDateString", "(", "$", "time", ")", "{", "$", "interval", "=", "parent", "::", "createFromDateString", "(", "$", "time", ")", ";", "if", "(", "$", "interval", "instanceof", "DateInterval", "&&", "!", "(", "$", "interval", "instanceof", "static", ")", ")", "{", "$", "interval", "=", "static", "::", "instance", "(", "$", "interval", ")", ";", "}", "return", "static", "::", "instance", "(", "$", "interval", ")", ";", "}" ]
Sets up a DateInterval from the relative parts of the string. @param string $time @return static @link http://php.net/manual/en/dateinterval.createfromdatestring.php
[ "Sets", "up", "a", "DateInterval", "from", "the", "relative", "parts", "of", "the", "string", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L634-L642
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.isEmpty
public function isEmpty() { return $this->years === 0 && $this->months === 0 && $this->dayz === 0 && !$this->days && $this->hours === 0 && $this->minutes === 0 && $this->seconds === 0 && $this->microseconds === 0; }
php
public function isEmpty() { return $this->years === 0 && $this->months === 0 && $this->dayz === 0 && !$this->days && $this->hours === 0 && $this->minutes === 0 && $this->seconds === 0 && $this->microseconds === 0; }
[ "public", "function", "isEmpty", "(", ")", "{", "return", "$", "this", "->", "years", "===", "0", "&&", "$", "this", "->", "months", "===", "0", "&&", "$", "this", "->", "dayz", "===", "0", "&&", "!", "$", "this", "->", "days", "&&", "$", "this", "->", "hours", "===", "0", "&&", "$", "this", "->", "minutes", "===", "0", "&&", "$", "this", "->", "seconds", "===", "0", "&&", "$", "this", "->", "microseconds", "===", "0", ";", "}" ]
Returns true if the interval is empty for each unit. @return bool
[ "Returns", "true", "if", "the", "interval", "is", "empty", "for", "each", "unit", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L783-L793
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.sub
public function sub($unit, $value = 1) { if (is_numeric($unit)) { $_unit = $value; $value = $unit; $unit = $_unit; unset($_unit); } return $this->add($unit, -floatval($value)); }
php
public function sub($unit, $value = 1) { if (is_numeric($unit)) { $_unit = $value; $value = $unit; $unit = $_unit; unset($_unit); } return $this->add($unit, -floatval($value)); }
[ "public", "function", "sub", "(", "$", "unit", ",", "$", "value", "=", "1", ")", "{", "if", "(", "is_numeric", "(", "$", "unit", ")", ")", "{", "$", "_unit", "=", "$", "value", ";", "$", "value", "=", "$", "unit", ";", "$", "unit", "=", "$", "_unit", ";", "unset", "(", "$", "_unit", ")", ";", "}", "return", "$", "this", "->", "add", "(", "$", "unit", ",", "-", "floatval", "(", "$", "value", ")", ")", ";", "}" ]
Subtract the passed interval to the current instance. @param string|DateInterval $unit @param int $value @return static
[ "Subtract", "the", "passed", "interval", "to", "the", "current", "instance", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L1268-L1278
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.times
public function times($factor) { if ($factor < 0) { $this->invert = $this->invert ? 0 : 1; $factor = -$factor; } $this->years = (int) round($this->years * $factor); $this->months = (int) round($this->months * $factor); $this->dayz = (int) round($this->dayz * $factor); $this->hours = (int) round($this->hours * $factor); $this->minutes = (int) round($this->minutes * $factor); $this->seconds = (int) round($this->seconds * $factor); $this->microseconds = (int) round($this->microseconds * $factor); return $this; }
php
public function times($factor) { if ($factor < 0) { $this->invert = $this->invert ? 0 : 1; $factor = -$factor; } $this->years = (int) round($this->years * $factor); $this->months = (int) round($this->months * $factor); $this->dayz = (int) round($this->dayz * $factor); $this->hours = (int) round($this->hours * $factor); $this->minutes = (int) round($this->minutes * $factor); $this->seconds = (int) round($this->seconds * $factor); $this->microseconds = (int) round($this->microseconds * $factor); return $this; }
[ "public", "function", "times", "(", "$", "factor", ")", "{", "if", "(", "$", "factor", "<", "0", ")", "{", "$", "this", "->", "invert", "=", "$", "this", "->", "invert", "?", "0", ":", "1", ";", "$", "factor", "=", "-", "$", "factor", ";", "}", "$", "this", "->", "years", "=", "(", "int", ")", "round", "(", "$", "this", "->", "years", "*", "$", "factor", ")", ";", "$", "this", "->", "months", "=", "(", "int", ")", "round", "(", "$", "this", "->", "months", "*", "$", "factor", ")", ";", "$", "this", "->", "dayz", "=", "(", "int", ")", "round", "(", "$", "this", "->", "dayz", "*", "$", "factor", ")", ";", "$", "this", "->", "hours", "=", "(", "int", ")", "round", "(", "$", "this", "->", "hours", "*", "$", "factor", ")", ";", "$", "this", "->", "minutes", "=", "(", "int", ")", "round", "(", "$", "this", "->", "minutes", "*", "$", "factor", ")", ";", "$", "this", "->", "seconds", "=", "(", "int", ")", "round", "(", "$", "this", "->", "seconds", "*", "$", "factor", ")", ";", "$", "this", "->", "microseconds", "=", "(", "int", ")", "round", "(", "$", "this", "->", "microseconds", "*", "$", "factor", ")", ";", "return", "$", "this", ";", "}" ]
Multiply current instance given number of times @param float|int $factor @return $this
[ "Multiply", "current", "instance", "given", "number", "of", "times" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L1300-L1316
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.getDateIntervalSpec
public static function getDateIntervalSpec(DateInterval $interval) { $date = array_filter([ static::PERIOD_YEARS => abs($interval->y), static::PERIOD_MONTHS => abs($interval->m), static::PERIOD_DAYS => abs($interval->d), ]); $time = array_filter([ static::PERIOD_HOURS => abs($interval->h), static::PERIOD_MINUTES => abs($interval->i), static::PERIOD_SECONDS => abs($interval->s), ]); $specString = static::PERIOD_PREFIX; foreach ($date as $key => $value) { $specString .= $value.$key; } if (count($time) > 0) { $specString .= static::PERIOD_TIME_PREFIX; foreach ($time as $key => $value) { $specString .= $value.$key; } } return $specString === static::PERIOD_PREFIX ? 'PT0S' : $specString; }
php
public static function getDateIntervalSpec(DateInterval $interval) { $date = array_filter([ static::PERIOD_YEARS => abs($interval->y), static::PERIOD_MONTHS => abs($interval->m), static::PERIOD_DAYS => abs($interval->d), ]); $time = array_filter([ static::PERIOD_HOURS => abs($interval->h), static::PERIOD_MINUTES => abs($interval->i), static::PERIOD_SECONDS => abs($interval->s), ]); $specString = static::PERIOD_PREFIX; foreach ($date as $key => $value) { $specString .= $value.$key; } if (count($time) > 0) { $specString .= static::PERIOD_TIME_PREFIX; foreach ($time as $key => $value) { $specString .= $value.$key; } } return $specString === static::PERIOD_PREFIX ? 'PT0S' : $specString; }
[ "public", "static", "function", "getDateIntervalSpec", "(", "DateInterval", "$", "interval", ")", "{", "$", "date", "=", "array_filter", "(", "[", "static", "::", "PERIOD_YEARS", "=>", "abs", "(", "$", "interval", "->", "y", ")", ",", "static", "::", "PERIOD_MONTHS", "=>", "abs", "(", "$", "interval", "->", "m", ")", ",", "static", "::", "PERIOD_DAYS", "=>", "abs", "(", "$", "interval", "->", "d", ")", ",", "]", ")", ";", "$", "time", "=", "array_filter", "(", "[", "static", "::", "PERIOD_HOURS", "=>", "abs", "(", "$", "interval", "->", "h", ")", ",", "static", "::", "PERIOD_MINUTES", "=>", "abs", "(", "$", "interval", "->", "i", ")", ",", "static", "::", "PERIOD_SECONDS", "=>", "abs", "(", "$", "interval", "->", "s", ")", ",", "]", ")", ";", "$", "specString", "=", "static", "::", "PERIOD_PREFIX", ";", "foreach", "(", "$", "date", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "specString", ".=", "$", "value", ".", "$", "key", ";", "}", "if", "(", "count", "(", "$", "time", ")", ">", "0", ")", "{", "$", "specString", ".=", "static", "::", "PERIOD_TIME_PREFIX", ";", "foreach", "(", "$", "time", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "specString", ".=", "$", "value", ".", "$", "key", ";", "}", "}", "return", "$", "specString", "===", "static", "::", "PERIOD_PREFIX", "?", "'PT0S'", ":", "$", "specString", ";", "}" ]
Get the interval_spec string of a date interval. @param DateInterval $interval @return string
[ "Get", "the", "interval_spec", "string", "of", "a", "date", "interval", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L1325-L1353
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.cascade
public function cascade() { foreach (static::getFlipCascadeFactors() as $source => [$target, $factor]) { if ($source === 'dayz' && $target === 'weeks') { continue; } $value = $this->$source; $this->$source = $modulo = ($factor + ($value % $factor)) % $factor; $this->$target += ($value - $modulo) / $factor; if ($this->$source > 0 && $this->$target < 0) { $this->$source -= $factor; $this->$target++; } } return $this->solveNegativeInterval(); }
php
public function cascade() { foreach (static::getFlipCascadeFactors() as $source => [$target, $factor]) { if ($source === 'dayz' && $target === 'weeks') { continue; } $value = $this->$source; $this->$source = $modulo = ($factor + ($value % $factor)) % $factor; $this->$target += ($value - $modulo) / $factor; if ($this->$source > 0 && $this->$target < 0) { $this->$source -= $factor; $this->$target++; } } return $this->solveNegativeInterval(); }
[ "public", "function", "cascade", "(", ")", "{", "foreach", "(", "static", "::", "getFlipCascadeFactors", "(", ")", "as", "$", "source", "=>", "[", "$", "target", ",", "$", "factor", "]", ")", "{", "if", "(", "$", "source", "===", "'dayz'", "&&", "$", "target", "===", "'weeks'", ")", "{", "continue", ";", "}", "$", "value", "=", "$", "this", "->", "$", "source", ";", "$", "this", "->", "$", "source", "=", "$", "modulo", "=", "(", "$", "factor", "+", "(", "$", "value", "%", "$", "factor", ")", ")", "%", "$", "factor", ";", "$", "this", "->", "$", "target", "+=", "(", "$", "value", "-", "$", "modulo", ")", "/", "$", "factor", ";", "if", "(", "$", "this", "->", "$", "source", ">", "0", "&&", "$", "this", "->", "$", "target", "<", "0", ")", "{", "$", "this", "->", "$", "source", "-=", "$", "factor", ";", "$", "this", "->", "$", "target", "++", ";", "}", "}", "return", "$", "this", "->", "solveNegativeInterval", "(", ")", ";", "}" ]
Convert overflowed values into bigger units. @return $this
[ "Convert", "overflowed", "values", "into", "bigger", "units", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L1406-L1423
train
briannesbitt/Carbon
src/Carbon/CarbonInterval.php
CarbonInterval.total
public function total($unit) { $realUnit = $unit = strtolower($unit); if (in_array($unit, ['days', 'weeks'])) { $realUnit = 'dayz'; } elseif (!in_array($unit, ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'dayz', 'months', 'years'])) { throw new InvalidArgumentException("Unknown unit '$unit'."); } $result = 0; $cumulativeFactor = 0; $unitFound = false; $factors = static::getFlipCascadeFactors(); foreach ($factors as $source => [$target, $factor]) { if ($source === $realUnit) { $unitFound = true; $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result += $value; $cumulativeFactor = 1; } if ($factor === false) { if ($unitFound) { break; } $result = 0; $cumulativeFactor = 0; continue; } if ($target === $realUnit) { $unitFound = true; } if ($cumulativeFactor) { $cumulativeFactor *= $factor; $result += $this->$target * $cumulativeFactor; continue; } $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result = ($result + $value) / $factor; } if (isset($target) && !$cumulativeFactor) { $result += $this->$target; } if (!$unitFound) { throw new \InvalidArgumentException("Unit $unit have no configuration to get total from other units."); } if ($unit === 'weeks') { return $result / static::getDaysPerWeek(); } return $result; }
php
public function total($unit) { $realUnit = $unit = strtolower($unit); if (in_array($unit, ['days', 'weeks'])) { $realUnit = 'dayz'; } elseif (!in_array($unit, ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'dayz', 'months', 'years'])) { throw new InvalidArgumentException("Unknown unit '$unit'."); } $result = 0; $cumulativeFactor = 0; $unitFound = false; $factors = static::getFlipCascadeFactors(); foreach ($factors as $source => [$target, $factor]) { if ($source === $realUnit) { $unitFound = true; $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result += $value; $cumulativeFactor = 1; } if ($factor === false) { if ($unitFound) { break; } $result = 0; $cumulativeFactor = 0; continue; } if ($target === $realUnit) { $unitFound = true; } if ($cumulativeFactor) { $cumulativeFactor *= $factor; $result += $this->$target * $cumulativeFactor; continue; } $value = $this->$source; if ($source === 'microseconds' && isset($factors['milliseconds'])) { $value %= Carbon::MICROSECONDS_PER_MILLISECOND; } $result = ($result + $value) / $factor; } if (isset($target) && !$cumulativeFactor) { $result += $this->$target; } if (!$unitFound) { throw new \InvalidArgumentException("Unit $unit have no configuration to get total from other units."); } if ($unit === 'weeks') { return $result / static::getDaysPerWeek(); } return $result; }
[ "public", "function", "total", "(", "$", "unit", ")", "{", "$", "realUnit", "=", "$", "unit", "=", "strtolower", "(", "$", "unit", ")", ";", "if", "(", "in_array", "(", "$", "unit", ",", "[", "'days'", ",", "'weeks'", "]", ")", ")", "{", "$", "realUnit", "=", "'dayz'", ";", "}", "elseif", "(", "!", "in_array", "(", "$", "unit", ",", "[", "'microseconds'", ",", "'milliseconds'", ",", "'seconds'", ",", "'minutes'", ",", "'hours'", ",", "'dayz'", ",", "'months'", ",", "'years'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unknown unit '$unit'.\"", ")", ";", "}", "$", "result", "=", "0", ";", "$", "cumulativeFactor", "=", "0", ";", "$", "unitFound", "=", "false", ";", "$", "factors", "=", "static", "::", "getFlipCascadeFactors", "(", ")", ";", "foreach", "(", "$", "factors", "as", "$", "source", "=>", "[", "$", "target", ",", "$", "factor", "]", ")", "{", "if", "(", "$", "source", "===", "$", "realUnit", ")", "{", "$", "unitFound", "=", "true", ";", "$", "value", "=", "$", "this", "->", "$", "source", ";", "if", "(", "$", "source", "===", "'microseconds'", "&&", "isset", "(", "$", "factors", "[", "'milliseconds'", "]", ")", ")", "{", "$", "value", "%=", "Carbon", "::", "MICROSECONDS_PER_MILLISECOND", ";", "}", "$", "result", "+=", "$", "value", ";", "$", "cumulativeFactor", "=", "1", ";", "}", "if", "(", "$", "factor", "===", "false", ")", "{", "if", "(", "$", "unitFound", ")", "{", "break", ";", "}", "$", "result", "=", "0", ";", "$", "cumulativeFactor", "=", "0", ";", "continue", ";", "}", "if", "(", "$", "target", "===", "$", "realUnit", ")", "{", "$", "unitFound", "=", "true", ";", "}", "if", "(", "$", "cumulativeFactor", ")", "{", "$", "cumulativeFactor", "*=", "$", "factor", ";", "$", "result", "+=", "$", "this", "->", "$", "target", "*", "$", "cumulativeFactor", ";", "continue", ";", "}", "$", "value", "=", "$", "this", "->", "$", "source", ";", "if", "(", "$", "source", "===", "'microseconds'", "&&", "isset", "(", "$", "factors", "[", "'milliseconds'", "]", ")", ")", "{", "$", "value", "%=", "Carbon", "::", "MICROSECONDS_PER_MILLISECOND", ";", "}", "$", "result", "=", "(", "$", "result", "+", "$", "value", ")", "/", "$", "factor", ";", "}", "if", "(", "isset", "(", "$", "target", ")", "&&", "!", "$", "cumulativeFactor", ")", "{", "$", "result", "+=", "$", "this", "->", "$", "target", ";", "}", "if", "(", "!", "$", "unitFound", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Unit $unit have no configuration to get total from other units.\"", ")", ";", "}", "if", "(", "$", "unit", "===", "'weeks'", ")", "{", "return", "$", "result", "/", "static", "::", "getDaysPerWeek", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get amount of given unit equivalent to the interval. @param string $unit @throws \InvalidArgumentException @return float
[ "Get", "amount", "of", "given", "unit", "equivalent", "to", "the", "interval", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/CarbonInterval.php#L1434-L1504
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getNames
public function getNames(): array { if (!$this->names) { $this->names = static::all()[$this->code] ?? [ 'isoName' => $this->code, 'nativeName' => $this->code, ]; } return $this->names; }
php
public function getNames(): array { if (!$this->names) { $this->names = static::all()[$this->code] ?? [ 'isoName' => $this->code, 'nativeName' => $this->code, ]; } return $this->names; }
[ "public", "function", "getNames", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "names", ")", "{", "$", "this", "->", "names", "=", "static", "::", "all", "(", ")", "[", "$", "this", "->", "code", "]", "??", "[", "'isoName'", "=>", "$", "this", "->", "code", ",", "'nativeName'", "=>", "$", "this", "->", "code", ",", "]", ";", "}", "return", "$", "this", "->", "names", ";", "}" ]
Get both isoName and nativeName as an array. @return array
[ "Get", "both", "isoName", "and", "nativeName", "as", "an", "array", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L112-L122
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getRegionName
public function getRegionName(): ?string { return $this->region ? (static::regions()[$this->region] ?? $this->region) : null; }
php
public function getRegionName(): ?string { return $this->region ? (static::regions()[$this->region] ?? $this->region) : null; }
[ "public", "function", "getRegionName", "(", ")", ":", "?", "string", "{", "return", "$", "this", "->", "region", "?", "(", "static", "::", "regions", "(", ")", "[", "$", "this", "->", "region", "]", "??", "$", "this", "->", "region", ")", ":", "null", ";", "}" ]
Returns the region name for the current language. @return string|null
[ "Returns", "the", "region", "name", "for", "the", "current", "language", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L187-L190
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getFullIsoName
public function getFullIsoName(): string { if (!$this->isoName) { $this->isoName = $this->getNames()['isoName']; } return $this->isoName; }
php
public function getFullIsoName(): string { if (!$this->isoName) { $this->isoName = $this->getNames()['isoName']; } return $this->isoName; }
[ "public", "function", "getFullIsoName", "(", ")", ":", "string", "{", "if", "(", "!", "$", "this", "->", "isoName", ")", "{", "$", "this", "->", "isoName", "=", "$", "this", "->", "getNames", "(", ")", "[", "'isoName'", "]", ";", "}", "return", "$", "this", "->", "isoName", ";", "}" ]
Returns the long ISO language name. @return string
[ "Returns", "the", "long", "ISO", "language", "name", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L197-L204
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getFullNativeName
public function getFullNativeName(): string { if (!$this->nativeName) { $this->nativeName = $this->getNames()['nativeName']; } return $this->nativeName; }
php
public function getFullNativeName(): string { if (!$this->nativeName) { $this->nativeName = $this->getNames()['nativeName']; } return $this->nativeName; }
[ "public", "function", "getFullNativeName", "(", ")", ":", "string", "{", "if", "(", "!", "$", "this", "->", "nativeName", ")", "{", "$", "this", "->", "nativeName", "=", "$", "this", "->", "getNames", "(", ")", "[", "'nativeName'", "]", ";", "}", "return", "$", "this", "->", "nativeName", ";", "}" ]
Return the full name of the language in this language. @return string
[ "Return", "the", "full", "name", "of", "the", "language", "in", "this", "language", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L223-L230
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getIsoName
public function getIsoName(): string { $name = $this->getFullIsoName(); return trim(strstr($name, ',', true) ?: $name); }
php
public function getIsoName(): string { $name = $this->getFullIsoName(); return trim(strstr($name, ',', true) ?: $name); }
[ "public", "function", "getIsoName", "(", ")", ":", "string", "{", "$", "name", "=", "$", "this", "->", "getFullIsoName", "(", ")", ";", "return", "trim", "(", "strstr", "(", "$", "name", ",", "','", ",", "true", ")", "?", ":", "$", "name", ")", ";", "}" ]
Returns the short ISO language name. @return string
[ "Returns", "the", "short", "ISO", "language", "name", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L249-L254
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getNativeName
public function getNativeName(): string { $name = $this->getFullNativeName(); return trim(strstr($name, ',', true) ?: $name); }
php
public function getNativeName(): string { $name = $this->getFullNativeName(); return trim(strstr($name, ',', true) ?: $name); }
[ "public", "function", "getNativeName", "(", ")", ":", "string", "{", "$", "name", "=", "$", "this", "->", "getFullNativeName", "(", ")", ";", "return", "trim", "(", "strstr", "(", "$", "name", ",", "','", ",", "true", ")", "?", ":", "$", "name", ")", ";", "}" ]
Get the short name of the language in this language. @return string
[ "Get", "the", "short", "name", "of", "the", "language", "in", "this", "language", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L261-L266
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getIsoDescription
public function getIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
public function getIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
[ "public", "function", "getIsoDescription", "(", ")", "{", "$", "region", "=", "$", "this", "->", "getRegionName", "(", ")", ";", "$", "variant", "=", "$", "this", "->", "getVariantName", "(", ")", ";", "return", "$", "this", "->", "getIsoName", "(", ")", ".", "(", "$", "region", "?", "' ('", ".", "$", "region", ".", "')'", ":", "''", ")", ".", "(", "$", "variant", "?", "' ('", ".", "$", "variant", ".", "')'", ":", "''", ")", ";", "}" ]
Get a string with short ISO name, region in parentheses if applicable, variant in parentheses if applicable. @return string
[ "Get", "a", "string", "with", "short", "ISO", "name", "region", "in", "parentheses", "if", "applicable", "variant", "in", "parentheses", "if", "applicable", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L273-L279
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getNativeDescription
public function getNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
public function getNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
[ "public", "function", "getNativeDescription", "(", ")", "{", "$", "region", "=", "$", "this", "->", "getRegionName", "(", ")", ";", "$", "variant", "=", "$", "this", "->", "getVariantName", "(", ")", ";", "return", "$", "this", "->", "getNativeName", "(", ")", ".", "(", "$", "region", "?", "' ('", ".", "$", "region", ".", "')'", ":", "''", ")", ".", "(", "$", "variant", "?", "' ('", ".", "$", "variant", ".", "')'", ":", "''", ")", ";", "}" ]
Get a string with short native name, region in parentheses if applicable, variant in parentheses if applicable. @return string
[ "Get", "a", "string", "with", "short", "native", "name", "region", "in", "parentheses", "if", "applicable", "variant", "in", "parentheses", "if", "applicable", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L286-L292
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getFullIsoDescription
public function getFullIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
public function getFullIsoDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullIsoName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
[ "public", "function", "getFullIsoDescription", "(", ")", "{", "$", "region", "=", "$", "this", "->", "getRegionName", "(", ")", ";", "$", "variant", "=", "$", "this", "->", "getVariantName", "(", ")", ";", "return", "$", "this", "->", "getFullIsoName", "(", ")", ".", "(", "$", "region", "?", "' ('", ".", "$", "region", ".", "')'", ":", "''", ")", ".", "(", "$", "variant", "?", "' ('", ".", "$", "variant", ".", "')'", ":", "''", ")", ";", "}" ]
Get a string with long ISO name, region in parentheses if applicable, variant in parentheses if applicable. @return string
[ "Get", "a", "string", "with", "long", "ISO", "name", "region", "in", "parentheses", "if", "applicable", "variant", "in", "parentheses", "if", "applicable", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L299-L305
train
briannesbitt/Carbon
src/Carbon/Language.php
Language.getFullNativeDescription
public function getFullNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
php
public function getFullNativeDescription() { $region = $this->getRegionName(); $variant = $this->getVariantName(); return $this->getFullNativeName().($region ? ' ('.$region.')' : '').($variant ? ' ('.$variant.')' : ''); }
[ "public", "function", "getFullNativeDescription", "(", ")", "{", "$", "region", "=", "$", "this", "->", "getRegionName", "(", ")", ";", "$", "variant", "=", "$", "this", "->", "getVariantName", "(", ")", ";", "return", "$", "this", "->", "getFullNativeName", "(", ")", ".", "(", "$", "region", "?", "' ('", ".", "$", "region", ".", "')'", ":", "''", ")", ".", "(", "$", "variant", "?", "' ('", ".", "$", "variant", ".", "')'", ":", "''", ")", ";", "}" ]
Get a string with long native name, region in parentheses if applicable, variant in parentheses if applicable. @return string
[ "Get", "a", "string", "with", "long", "native", "name", "region", "in", "parentheses", "if", "applicable", "variant", "in", "parentheses", "if", "applicable", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Language.php#L312-L318
train
briannesbitt/Carbon
src/Carbon/Translator.php
Translator.get
public static function get($locale = null) { $locale = $locale ?: 'en'; if (!isset(static::$singletons[$locale])) { static::$singletons[$locale] = new static($locale ?: 'en'); } return static::$singletons[$locale]; }
php
public static function get($locale = null) { $locale = $locale ?: 'en'; if (!isset(static::$singletons[$locale])) { static::$singletons[$locale] = new static($locale ?: 'en'); } return static::$singletons[$locale]; }
[ "public", "static", "function", "get", "(", "$", "locale", "=", "null", ")", "{", "$", "locale", "=", "$", "locale", "?", ":", "'en'", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "singletons", "[", "$", "locale", "]", ")", ")", "{", "static", "::", "$", "singletons", "[", "$", "locale", "]", "=", "new", "static", "(", "$", "locale", "?", ":", "'en'", ")", ";", "}", "return", "static", "::", "$", "singletons", "[", "$", "locale", "]", ";", "}" ]
Return a singleton instance of Translator. @param string|null $locale optional initial locale ("en" - english by default) @return static
[ "Return", "a", "singleton", "instance", "of", "Translator", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Translator.php#L55-L64
train
briannesbitt/Carbon
src/Carbon/Translator.php
Translator.removeDirectory
public function removeDirectory(string $directory) { $search = rtrim(strtr($directory, '\\', '/'), '/'); return $this->setDirectories(array_filter($this->getDirectories(), function ($item) use ($search) { return rtrim(strtr($item, '\\', '/'), '/') !== $search; })); }
php
public function removeDirectory(string $directory) { $search = rtrim(strtr($directory, '\\', '/'), '/'); return $this->setDirectories(array_filter($this->getDirectories(), function ($item) use ($search) { return rtrim(strtr($item, '\\', '/'), '/') !== $search; })); }
[ "public", "function", "removeDirectory", "(", "string", "$", "directory", ")", "{", "$", "search", "=", "rtrim", "(", "strtr", "(", "$", "directory", ",", "'\\\\'", ",", "'/'", ")", ",", "'/'", ")", ";", "return", "$", "this", "->", "setDirectories", "(", "array_filter", "(", "$", "this", "->", "getDirectories", "(", ")", ",", "function", "(", "$", "item", ")", "use", "(", "$", "search", ")", "{", "return", "rtrim", "(", "strtr", "(", "$", "item", ",", "'\\\\'", ",", "'/'", ")", ",", "'/'", ")", "!==", "$", "search", ";", "}", ")", ")", ";", "}" ]
Remove a directory from the list translation files are searched in. @param string $directory directory path @return $this
[ "Remove", "a", "directory", "from", "the", "list", "translation", "files", "are", "searched", "in", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Translator.php#L120-L127
train
briannesbitt/Carbon
src/Carbon/Translator.php
Translator.loadMessagesFromFile
protected function loadMessagesFromFile($locale) { if (isset($this->messages[$locale])) { return true; } return $this->resetMessages($locale); }
php
protected function loadMessagesFromFile($locale) { if (isset($this->messages[$locale])) { return true; } return $this->resetMessages($locale); }
[ "protected", "function", "loadMessagesFromFile", "(", "$", "locale", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "messages", "[", "$", "locale", "]", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "resetMessages", "(", "$", "locale", ")", ";", "}" ]
Init messages language from matching file in Lang directory. @param string $locale @return bool
[ "Init", "messages", "language", "from", "matching", "file", "in", "Lang", "directory", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Translator.php#L240-L247
train
briannesbitt/Carbon
src/Carbon/Translator.php
Translator.setMessages
public function setMessages($locale, $messages) { $this->loadMessagesFromFile($locale); $this->addResource('array', $messages, $locale); $this->messages[$locale] = array_merge( isset($this->messages[$locale]) ? $this->messages[$locale] : [], $messages ); return $this; }
php
public function setMessages($locale, $messages) { $this->loadMessagesFromFile($locale); $this->addResource('array', $messages, $locale); $this->messages[$locale] = array_merge( isset($this->messages[$locale]) ? $this->messages[$locale] : [], $messages ); return $this; }
[ "public", "function", "setMessages", "(", "$", "locale", ",", "$", "messages", ")", "{", "$", "this", "->", "loadMessagesFromFile", "(", "$", "locale", ")", ";", "$", "this", "->", "addResource", "(", "'array'", ",", "$", "messages", ",", "$", "locale", ")", ";", "$", "this", "->", "messages", "[", "$", "locale", "]", "=", "array_merge", "(", "isset", "(", "$", "this", "->", "messages", "[", "$", "locale", "]", ")", "?", "$", "this", "->", "messages", "[", "$", "locale", "]", ":", "[", "]", ",", "$", "messages", ")", ";", "return", "$", "this", ";", "}" ]
Set messages of a locale and take file first if present. @param string $locale @param array $messages @return $this
[ "Set", "messages", "of", "a", "locale", "and", "take", "file", "first", "if", "present", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Translator.php#L257-L267
train
briannesbitt/Carbon
src/Carbon/Translator.php
Translator.getMessages
public function getMessages($locale = null) { return $locale === null ? $this->messages : $this->messages[$locale]; }
php
public function getMessages($locale = null) { return $locale === null ? $this->messages : $this->messages[$locale]; }
[ "public", "function", "getMessages", "(", "$", "locale", "=", "null", ")", "{", "return", "$", "locale", "===", "null", "?", "$", "this", "->", "messages", ":", "$", "this", "->", "messages", "[", "$", "locale", "]", ";", "}" ]
Get messages of a locale, if none given, return all the languages. @param string|null $locale @return array
[ "Get", "messages", "of", "a", "locale", "if", "none", "given", "return", "all", "the", "languages", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Translator.php#L289-L292
train
briannesbitt/Carbon
src/Carbon/Traits/Options.php
Options.getSettings
public function getSettings() { $settings = []; $map = [ 'localStrictModeEnabled' => 'strictMode', 'localMonthsOverflow' => 'monthOverflow', 'localYearsOverflow' => 'yearOverflow', 'localHumanDiffOptions' => 'humanDiffOptions', 'localToStringFormat' => 'toStringFormat', 'localSerializer' => 'toJsonFormat', 'localMacros' => 'macros', 'localGenericMacros' => 'genericMacros', 'locale' => 'locale', 'tzName' => 'timezone', 'localFormatFunction' => 'formatFunction', ]; foreach ($map as $property => $key) { $value = $this->$property ?? null; if ($value !== null) { $settings[$key] = $value; } } return $settings; }
php
public function getSettings() { $settings = []; $map = [ 'localStrictModeEnabled' => 'strictMode', 'localMonthsOverflow' => 'monthOverflow', 'localYearsOverflow' => 'yearOverflow', 'localHumanDiffOptions' => 'humanDiffOptions', 'localToStringFormat' => 'toStringFormat', 'localSerializer' => 'toJsonFormat', 'localMacros' => 'macros', 'localGenericMacros' => 'genericMacros', 'locale' => 'locale', 'tzName' => 'timezone', 'localFormatFunction' => 'formatFunction', ]; foreach ($map as $property => $key) { $value = $this->$property ?? null; if ($value !== null) { $settings[$key] = $value; } } return $settings; }
[ "public", "function", "getSettings", "(", ")", "{", "$", "settings", "=", "[", "]", ";", "$", "map", "=", "[", "'localStrictModeEnabled'", "=>", "'strictMode'", ",", "'localMonthsOverflow'", "=>", "'monthOverflow'", ",", "'localYearsOverflow'", "=>", "'yearOverflow'", ",", "'localHumanDiffOptions'", "=>", "'humanDiffOptions'", ",", "'localToStringFormat'", "=>", "'toStringFormat'", ",", "'localSerializer'", "=>", "'toJsonFormat'", ",", "'localMacros'", "=>", "'macros'", ",", "'localGenericMacros'", "=>", "'genericMacros'", ",", "'locale'", "=>", "'locale'", ",", "'tzName'", "=>", "'timezone'", ",", "'localFormatFunction'", "=>", "'formatFunction'", ",", "]", ";", "foreach", "(", "$", "map", "as", "$", "property", "=>", "$", "key", ")", "{", "$", "value", "=", "$", "this", "->", "$", "property", "??", "null", ";", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "settings", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "settings", ";", "}" ]
Returns current local settings. @return array
[ "Returns", "current", "local", "settings", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Options.php#L381-L405
train
briannesbitt/Carbon
src/Carbon/Traits/Macro.php
Macro.genericMacro
public static function genericMacro($macro, $priority = 0) { if (!isset(static::$globalGenericMacros[$priority])) { static::$globalGenericMacros[$priority] = []; krsort(static::$globalGenericMacros, SORT_NUMERIC); } static::$globalGenericMacros[$priority][] = $macro; }
php
public static function genericMacro($macro, $priority = 0) { if (!isset(static::$globalGenericMacros[$priority])) { static::$globalGenericMacros[$priority] = []; krsort(static::$globalGenericMacros, SORT_NUMERIC); } static::$globalGenericMacros[$priority][] = $macro; }
[ "public", "static", "function", "genericMacro", "(", "$", "macro", ",", "$", "priority", "=", "0", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "globalGenericMacros", "[", "$", "priority", "]", ")", ")", "{", "static", "::", "$", "globalGenericMacros", "[", "$", "priority", "]", "=", "[", "]", ";", "krsort", "(", "static", "::", "$", "globalGenericMacros", ",", "SORT_NUMERIC", ")", ";", "}", "static", "::", "$", "globalGenericMacros", "[", "$", "priority", "]", "[", "]", "=", "$", "macro", ";", "}" ]
Register a custom macro. @param object|callable $macro @param int $priority marco with higher priority is tried first @return void
[ "Register", "a", "custom", "macro", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Macro.php#L89-L97
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInMonths
public function diffInMonths($date = null, $absolute = true) { $date = $this->resolveCarbon($date); return $this->diffInYears($date, $absolute) * static::MONTHS_PER_YEAR + (int) $this->diff($date, $absolute)->format('%r%m'); }
php
public function diffInMonths($date = null, $absolute = true) { $date = $this->resolveCarbon($date); return $this->diffInYears($date, $absolute) * static::MONTHS_PER_YEAR + (int) $this->diff($date, $absolute)->format('%r%m'); }
[ "public", "function", "diffInMonths", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "$", "date", "=", "$", "this", "->", "resolveCarbon", "(", "$", "date", ")", ";", "return", "$", "this", "->", "diffInYears", "(", "$", "date", ",", "$", "absolute", ")", "*", "static", "::", "MONTHS_PER_YEAR", "+", "(", "int", ")", "$", "this", "->", "diff", "(", "$", "date", ",", "$", "absolute", ")", "->", "format", "(", "'%r%m'", ")", ";", "}" ]
Get the difference in months @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "months" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L133-L138
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInHoursFiltered
public function diffInHoursFiltered(Closure $callback, $date = null, $absolute = true) { return $this->diffFiltered(CarbonInterval::hour(), $callback, $date, $absolute); }
php
public function diffInHoursFiltered(Closure $callback, $date = null, $absolute = true) { return $this->diffFiltered(CarbonInterval::hour(), $callback, $date, $absolute); }
[ "public", "function", "diffInHoursFiltered", "(", "Closure", "$", "callback", ",", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "$", "this", "->", "diffFiltered", "(", "CarbonInterval", "::", "hour", "(", ")", ",", "$", "callback", ",", "$", "date", ",", "$", "absolute", ")", ";", "}" ]
Get the difference in hours using a filter closure @param Closure $callback @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "hours", "using", "a", "filter", "closure" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L189-L192
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInWeekdays
public function diffInWeekdays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekday(); }, $date, $absolute); }
php
public function diffInWeekdays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekday(); }, $date, $absolute); }
[ "public", "function", "diffInWeekdays", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "$", "this", "->", "diffInDaysFiltered", "(", "function", "(", "CarbonInterface", "$", "date", ")", "{", "return", "$", "date", "->", "isWeekday", "(", ")", ";", "}", ",", "$", "date", ",", "$", "absolute", ")", ";", "}" ]
Get the difference in weekdays @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "weekdays" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L230-L235
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInWeekendDays
public function diffInWeekendDays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekend(); }, $date, $absolute); }
php
public function diffInWeekendDays($date = null, $absolute = true) { return $this->diffInDaysFiltered(function (CarbonInterface $date) { return $date->isWeekend(); }, $date, $absolute); }
[ "public", "function", "diffInWeekendDays", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "$", "this", "->", "diffInDaysFiltered", "(", "function", "(", "CarbonInterface", "$", "date", ")", "{", "return", "$", "date", "->", "isWeekend", "(", ")", ";", "}", ",", "$", "date", ",", "$", "absolute", ")", ";", "}" ]
Get the difference in weekend days using a filter @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "weekend", "days", "using", "a", "filter" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L245-L250
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInRealHours
public function diffInRealHours($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); }
php
public function diffInRealHours($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); }
[ "public", "function", "diffInRealHours", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "(", "int", ")", "(", "$", "this", "->", "diffInRealSeconds", "(", "$", "date", ",", "$", "absolute", ")", "/", "static", "::", "SECONDS_PER_MINUTE", "/", "static", "::", "MINUTES_PER_HOUR", ")", ";", "}" ]
Get the difference in hours using timestamps. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "hours", "using", "timestamps", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L273-L276
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInRealMinutes
public function diffInRealMinutes($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE); }
php
public function diffInRealMinutes($date = null, $absolute = true) { return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE); }
[ "public", "function", "diffInRealMinutes", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "(", "int", ")", "(", "$", "this", "->", "diffInRealSeconds", "(", "$", "date", ",", "$", "absolute", ")", "/", "static", "::", "SECONDS_PER_MINUTE", ")", ";", "}" ]
Get the difference in minutes using timestamps. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "minutes", "using", "timestamps", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L299-L302
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInMicroseconds
public function diffInMicroseconds($date = null, $absolute = true) { $diff = $this->diff($this->resolveCarbon($date)); $value = (int) round((((($diff->days * static::HOURS_PER_DAY) + $diff->h) * static::MINUTES_PER_HOUR + $diff->i) * static::SECONDS_PER_MINUTE + ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND); return $absolute || !$diff->invert ? $value : -$value; }
php
public function diffInMicroseconds($date = null, $absolute = true) { $diff = $this->diff($this->resolveCarbon($date)); $value = (int) round((((($diff->days * static::HOURS_PER_DAY) + $diff->h) * static::MINUTES_PER_HOUR + $diff->i) * static::SECONDS_PER_MINUTE + ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND); return $absolute || !$diff->invert ? $value : -$value; }
[ "public", "function", "diffInMicroseconds", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "$", "diff", "=", "$", "this", "->", "diff", "(", "$", "this", "->", "resolveCarbon", "(", "$", "date", ")", ")", ";", "$", "value", "=", "(", "int", ")", "round", "(", "(", "(", "(", "(", "$", "diff", "->", "days", "*", "static", "::", "HOURS_PER_DAY", ")", "+", "$", "diff", "->", "h", ")", "*", "static", "::", "MINUTES_PER_HOUR", "+", "$", "diff", "->", "i", ")", "*", "static", "::", "SECONDS_PER_MINUTE", "+", "(", "$", "diff", "->", "f", "+", "$", "diff", "->", "s", ")", ")", "*", "static", "::", "MICROSECONDS_PER_SECOND", ")", ";", "return", "$", "absolute", "||", "!", "$", "diff", "->", "invert", "?", "$", "value", ":", "-", "$", "value", ";", "}" ]
Get the difference in microseconds. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "microseconds", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L334-L343
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInMilliseconds
public function diffInMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
php
public function diffInMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
[ "public", "function", "diffInMilliseconds", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "(", "int", ")", "(", "$", "this", "->", "diffInMicroseconds", "(", "$", "date", ",", "$", "absolute", ")", "/", "static", "::", "MICROSECONDS_PER_MILLISECOND", ")", ";", "}" ]
Get the difference in milliseconds. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "milliseconds", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L353-L356
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInRealSeconds
public function diffInRealSeconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = $date->getTimestamp() - $this->getTimestamp(); return $absolute ? abs($value) : $value; }
php
public function diffInRealSeconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = $date->getTimestamp() - $this->getTimestamp(); return $absolute ? abs($value) : $value; }
[ "public", "function", "diffInRealSeconds", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "/** @var CarbonInterface $date */", "$", "date", "=", "$", "this", "->", "resolveCarbon", "(", "$", "date", ")", ";", "$", "value", "=", "$", "date", "->", "getTimestamp", "(", ")", "-", "$", "this", "->", "getTimestamp", "(", ")", ";", "return", "$", "absolute", "?", "abs", "(", "$", "value", ")", ":", "$", "value", ";", "}" ]
Get the difference in seconds using timestamps. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "seconds", "using", "timestamps", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L366-L373
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInRealMicroseconds
public function diffInRealMicroseconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = ($date->timestamp - $this->timestamp) * static::MICROSECONDS_PER_SECOND + $date->micro - $this->micro; return $absolute ? abs($value) : $value; }
php
public function diffInRealMicroseconds($date = null, $absolute = true) { /** @var CarbonInterface $date */ $date = $this->resolveCarbon($date); $value = ($date->timestamp - $this->timestamp) * static::MICROSECONDS_PER_SECOND + $date->micro - $this->micro; return $absolute ? abs($value) : $value; }
[ "public", "function", "diffInRealMicroseconds", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "/** @var CarbonInterface $date */", "$", "date", "=", "$", "this", "->", "resolveCarbon", "(", "$", "date", ")", ";", "$", "value", "=", "(", "$", "date", "->", "timestamp", "-", "$", "this", "->", "timestamp", ")", "*", "static", "::", "MICROSECONDS_PER_SECOND", "+", "$", "date", "->", "micro", "-", "$", "this", "->", "micro", ";", "return", "$", "absolute", "?", "abs", "(", "$", "value", ")", ":", "$", "value", ";", "}" ]
Get the difference in microseconds using timestamps. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "microseconds", "using", "timestamps", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L383-L391
train
briannesbitt/Carbon
src/Carbon/Traits/Difference.php
Difference.diffInRealMilliseconds
public function diffInRealMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInRealMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
php
public function diffInRealMilliseconds($date = null, $absolute = true) { return (int) ($this->diffInRealMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND); }
[ "public", "function", "diffInRealMilliseconds", "(", "$", "date", "=", "null", ",", "$", "absolute", "=", "true", ")", "{", "return", "(", "int", ")", "(", "$", "this", "->", "diffInRealMicroseconds", "(", "$", "date", ",", "$", "absolute", ")", "/", "static", "::", "MICROSECONDS_PER_MILLISECOND", ")", ";", "}" ]
Get the difference in milliseconds using timestamps. @param Carbon|\DateTimeInterface|string|null $date @param bool $absolute Get the absolute of the difference @return int
[ "Get", "the", "difference", "in", "milliseconds", "using", "timestamps", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Difference.php#L401-L404
train
briannesbitt/Carbon
src/Carbon/Traits/Boundaries.php
Boundaries.endOfSecond
public function endOfSecond() { return $this->setTime($this->hour, $this->minute, $this->second, static::MICROSECONDS_PER_SECOND - 1); }
php
public function endOfSecond() { return $this->setTime($this->hour, $this->minute, $this->second, static::MICROSECONDS_PER_SECOND - 1); }
[ "public", "function", "endOfSecond", "(", ")", "{", "return", "$", "this", "->", "setTime", "(", "$", "this", "->", "hour", ",", "$", "this", "->", "minute", ",", "$", "this", "->", "second", ",", "static", "::", "MICROSECONDS_PER_SECOND", "-", "1", ")", ";", "}" ]
Modify to end of current second, microseconds become 999999 @example ``` echo Carbon::parse('2018-07-25 12:45:16.334455') ->endOfSecond() ->format('H:i:s.u'); ``` @return static|CarbonInterface
[ "Modify", "to", "end", "of", "current", "second", "microseconds", "become", "999999" ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Boundaries.php#L397-L400
train
briannesbitt/Carbon
src/Carbon/Traits/Boundaries.php
Boundaries.startOf
public function startOf($unit, ...$params) { $ucfUnit = ucfirst(static::singularUnit($unit)); $method = "startOf$ucfUnit"; if (!method_exists($this, $method)) { throw new InvalidArgumentException("Unknown unit '$unit'"); } return $this->$method(...$params); }
php
public function startOf($unit, ...$params) { $ucfUnit = ucfirst(static::singularUnit($unit)); $method = "startOf$ucfUnit"; if (!method_exists($this, $method)) { throw new InvalidArgumentException("Unknown unit '$unit'"); } return $this->$method(...$params); }
[ "public", "function", "startOf", "(", "$", "unit", ",", "...", "$", "params", ")", "{", "$", "ucfUnit", "=", "ucfirst", "(", "static", "::", "singularUnit", "(", "$", "unit", ")", ")", ";", "$", "method", "=", "\"startOf$ucfUnit\"", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unknown unit '$unit'\"", ")", ";", "}", "return", "$", "this", "->", "$", "method", "(", "...", "$", "params", ")", ";", "}" ]
Modify to start of current given unit. @example ``` echo Carbon::parse('2018-07-25 12:45:16.334455') ->startOf('month') ->endOf('week', Carbon::FRIDAY); ``` @param string $unit @param array<int, mixed> $params @return static|CarbonInterface
[ "Modify", "to", "start", "of", "current", "given", "unit", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Boundaries.php#L417-L426
train
briannesbitt/Carbon
src/Carbon/Traits/Units.php
Units.add
public function add($unit, $value = 1, $overflow = null) { if (is_string($unit) && func_num_args() === 1) { $unit = CarbonInterval::make($unit); } if ($unit instanceof DateInterval) { return parent::add($unit); } if (is_numeric($unit)) { $tempUnit = $value; $value = $unit; $unit = $tempUnit; } return $this->addUnit($unit, $value, $overflow); }
php
public function add($unit, $value = 1, $overflow = null) { if (is_string($unit) && func_num_args() === 1) { $unit = CarbonInterval::make($unit); } if ($unit instanceof DateInterval) { return parent::add($unit); } if (is_numeric($unit)) { $tempUnit = $value; $value = $unit; $unit = $tempUnit; } return $this->addUnit($unit, $value, $overflow); }
[ "public", "function", "add", "(", "$", "unit", ",", "$", "value", "=", "1", ",", "$", "overflow", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "unit", ")", "&&", "func_num_args", "(", ")", "===", "1", ")", "{", "$", "unit", "=", "CarbonInterval", "::", "make", "(", "$", "unit", ")", ";", "}", "if", "(", "$", "unit", "instanceof", "DateInterval", ")", "{", "return", "parent", "::", "add", "(", "$", "unit", ")", ";", "}", "if", "(", "is_numeric", "(", "$", "unit", ")", ")", "{", "$", "tempUnit", "=", "$", "value", ";", "$", "value", "=", "$", "unit", ";", "$", "unit", "=", "$", "tempUnit", ";", "}", "return", "$", "this", "->", "addUnit", "(", "$", "unit", ",", "$", "value", ",", "$", "overflow", ")", ";", "}" ]
Add given units or interval to the current instance. @example $date->add('hour', 3) @example $date->add(15, 'days') @example $date->add(CarbonInterval::days(4)) @param string|DateInterval $unit @param int $value @param bool|null $overflow @return CarbonInterface
[ "Add", "given", "units", "or", "interval", "to", "the", "current", "instance", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Units.php#L157-L174
train
briannesbitt/Carbon
src/Carbon/Traits/Units.php
Units.subUnit
public function subUnit($unit, $value = 1, $overflow = null) { return $this->addUnit($unit, -$value, $overflow); }
php
public function subUnit($unit, $value = 1, $overflow = null) { return $this->addUnit($unit, -$value, $overflow); }
[ "public", "function", "subUnit", "(", "$", "unit", ",", "$", "value", "=", "1", ",", "$", "overflow", "=", "null", ")", "{", "return", "$", "this", "->", "addUnit", "(", "$", "unit", ",", "-", "$", "value", ",", "$", "overflow", ")", ";", "}" ]
Subtract given units to the current instance. @param string $unit @param int $value @param bool|null $overflow @return CarbonInterface
[ "Subtract", "given", "units", "to", "the", "current", "instance", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Units.php#L276-L279
train
briannesbitt/Carbon
src/Carbon/Traits/Rounding.php
Rounding.roundUnit
public function roundUnit($unit, $precision = 1, $function = 'round') { $metaUnits = [ // @call roundUnit 'millennium' => [static::YEARS_PER_MILLENNIUM, 'year'], // @call roundUnit 'century' => [static::YEARS_PER_CENTURY, 'year'], // @call roundUnit 'decade' => [static::YEARS_PER_DECADE, 'year'], // @call roundUnit 'quarter' => [static::MONTHS_PER_QUARTER, 'month'], // @call roundUnit 'millisecond' => [1000, 'microsecond'], ]; $normalizedUnit = static::singularUnit($unit); $ranges = array_merge(static::getRangesByUnit(), [ // @call roundUnit 'microsecond' => [0, 999999], ]); $factor = 1; if (isset($metaUnits[$normalizedUnit])) { [$factor, $normalizedUnit] = $metaUnits[$normalizedUnit]; } $precision *= $factor; if (!isset($ranges[$normalizedUnit])) { throw new InvalidArgumentException("Unknown unit '$unit' to floor"); } $found = false; $fraction = 0; $arguments = null; $factor = $this->year < 0 ? -1 : 1; $changes = []; foreach ($ranges as $unit => [$minimum, $maximum]) { if ($normalizedUnit === $unit) { $arguments = [$this->$unit, $minimum]; $fraction = $precision - floor($precision); $found = true; continue; } if ($found) { $delta = $maximum + 1 - $minimum; $factor /= $delta; $fraction *= $delta; $arguments[0] += $this->$unit * $factor; $changes[$unit] = round($minimum + ($fraction ? $fraction * call_user_func($function, ($this->$unit - $minimum) / $fraction) : 0)); // Cannot use modulo as it lose double precision while ($changes[$unit] >= $delta) { $changes[$unit] -= $delta; } $fraction -= floor($fraction); } } [$value, $minimum] = $arguments; /** @var CarbonInterface $result */ $result = $this->$normalizedUnit(floor(call_user_func($function, ($value - $minimum) / $precision) * $precision + $minimum)); foreach ($changes as $unit => $value) { $result = $result->$unit($value); } return $result; }
php
public function roundUnit($unit, $precision = 1, $function = 'round') { $metaUnits = [ // @call roundUnit 'millennium' => [static::YEARS_PER_MILLENNIUM, 'year'], // @call roundUnit 'century' => [static::YEARS_PER_CENTURY, 'year'], // @call roundUnit 'decade' => [static::YEARS_PER_DECADE, 'year'], // @call roundUnit 'quarter' => [static::MONTHS_PER_QUARTER, 'month'], // @call roundUnit 'millisecond' => [1000, 'microsecond'], ]; $normalizedUnit = static::singularUnit($unit); $ranges = array_merge(static::getRangesByUnit(), [ // @call roundUnit 'microsecond' => [0, 999999], ]); $factor = 1; if (isset($metaUnits[$normalizedUnit])) { [$factor, $normalizedUnit] = $metaUnits[$normalizedUnit]; } $precision *= $factor; if (!isset($ranges[$normalizedUnit])) { throw new InvalidArgumentException("Unknown unit '$unit' to floor"); } $found = false; $fraction = 0; $arguments = null; $factor = $this->year < 0 ? -1 : 1; $changes = []; foreach ($ranges as $unit => [$minimum, $maximum]) { if ($normalizedUnit === $unit) { $arguments = [$this->$unit, $minimum]; $fraction = $precision - floor($precision); $found = true; continue; } if ($found) { $delta = $maximum + 1 - $minimum; $factor /= $delta; $fraction *= $delta; $arguments[0] += $this->$unit * $factor; $changes[$unit] = round($minimum + ($fraction ? $fraction * call_user_func($function, ($this->$unit - $minimum) / $fraction) : 0)); // Cannot use modulo as it lose double precision while ($changes[$unit] >= $delta) { $changes[$unit] -= $delta; } $fraction -= floor($fraction); } } [$value, $minimum] = $arguments; /** @var CarbonInterface $result */ $result = $this->$normalizedUnit(floor(call_user_func($function, ($value - $minimum) / $precision) * $precision + $minimum)); foreach ($changes as $unit => $value) { $result = $result->$unit($value); } return $result; }
[ "public", "function", "roundUnit", "(", "$", "unit", ",", "$", "precision", "=", "1", ",", "$", "function", "=", "'round'", ")", "{", "$", "metaUnits", "=", "[", "// @call roundUnit", "'millennium'", "=>", "[", "static", "::", "YEARS_PER_MILLENNIUM", ",", "'year'", "]", ",", "// @call roundUnit", "'century'", "=>", "[", "static", "::", "YEARS_PER_CENTURY", ",", "'year'", "]", ",", "// @call roundUnit", "'decade'", "=>", "[", "static", "::", "YEARS_PER_DECADE", ",", "'year'", "]", ",", "// @call roundUnit", "'quarter'", "=>", "[", "static", "::", "MONTHS_PER_QUARTER", ",", "'month'", "]", ",", "// @call roundUnit", "'millisecond'", "=>", "[", "1000", ",", "'microsecond'", "]", ",", "]", ";", "$", "normalizedUnit", "=", "static", "::", "singularUnit", "(", "$", "unit", ")", ";", "$", "ranges", "=", "array_merge", "(", "static", "::", "getRangesByUnit", "(", ")", ",", "[", "// @call roundUnit", "'microsecond'", "=>", "[", "0", ",", "999999", "]", ",", "]", ")", ";", "$", "factor", "=", "1", ";", "if", "(", "isset", "(", "$", "metaUnits", "[", "$", "normalizedUnit", "]", ")", ")", "{", "[", "$", "factor", ",", "$", "normalizedUnit", "]", "=", "$", "metaUnits", "[", "$", "normalizedUnit", "]", ";", "}", "$", "precision", "*=", "$", "factor", ";", "if", "(", "!", "isset", "(", "$", "ranges", "[", "$", "normalizedUnit", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Unknown unit '$unit' to floor\"", ")", ";", "}", "$", "found", "=", "false", ";", "$", "fraction", "=", "0", ";", "$", "arguments", "=", "null", ";", "$", "factor", "=", "$", "this", "->", "year", "<", "0", "?", "-", "1", ":", "1", ";", "$", "changes", "=", "[", "]", ";", "foreach", "(", "$", "ranges", "as", "$", "unit", "=>", "[", "$", "minimum", ",", "$", "maximum", "]", ")", "{", "if", "(", "$", "normalizedUnit", "===", "$", "unit", ")", "{", "$", "arguments", "=", "[", "$", "this", "->", "$", "unit", ",", "$", "minimum", "]", ";", "$", "fraction", "=", "$", "precision", "-", "floor", "(", "$", "precision", ")", ";", "$", "found", "=", "true", ";", "continue", ";", "}", "if", "(", "$", "found", ")", "{", "$", "delta", "=", "$", "maximum", "+", "1", "-", "$", "minimum", ";", "$", "factor", "/=", "$", "delta", ";", "$", "fraction", "*=", "$", "delta", ";", "$", "arguments", "[", "0", "]", "+=", "$", "this", "->", "$", "unit", "*", "$", "factor", ";", "$", "changes", "[", "$", "unit", "]", "=", "round", "(", "$", "minimum", "+", "(", "$", "fraction", "?", "$", "fraction", "*", "call_user_func", "(", "$", "function", ",", "(", "$", "this", "->", "$", "unit", "-", "$", "minimum", ")", "/", "$", "fraction", ")", ":", "0", ")", ")", ";", "// Cannot use modulo as it lose double precision", "while", "(", "$", "changes", "[", "$", "unit", "]", ">=", "$", "delta", ")", "{", "$", "changes", "[", "$", "unit", "]", "-=", "$", "delta", ";", "}", "$", "fraction", "-=", "floor", "(", "$", "fraction", ")", ";", "}", "}", "[", "$", "value", ",", "$", "minimum", "]", "=", "$", "arguments", ";", "/** @var CarbonInterface $result */", "$", "result", "=", "$", "this", "->", "$", "normalizedUnit", "(", "floor", "(", "call_user_func", "(", "$", "function", ",", "(", "$", "value", "-", "$", "minimum", ")", "/", "$", "precision", ")", "*", "$", "precision", "+", "$", "minimum", ")", ")", ";", "foreach", "(", "$", "changes", "as", "$", "unit", "=>", "$", "value", ")", "{", "$", "result", "=", "$", "result", "->", "$", "unit", "(", "$", "value", ")", ";", "}", "return", "$", "result", ";", "}" ]
Round the current instance at the given unit with given precision if specified and the given function. @param string $unit @param float|int $precision @param string $function @return CarbonInterface
[ "Round", "the", "current", "instance", "at", "the", "given", "unit", "with", "given", "precision", "if", "specified", "and", "the", "given", "function", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Rounding.php#L37-L103
train
briannesbitt/Carbon
src/Carbon/Traits/Rounding.php
Rounding.roundWeek
public function roundWeek($weekStartsAt = null) { return $this->closest($this->copy()->floorWeek($weekStartsAt), $this->copy()->ceilWeek($weekStartsAt)); }
php
public function roundWeek($weekStartsAt = null) { return $this->closest($this->copy()->floorWeek($weekStartsAt), $this->copy()->ceilWeek($weekStartsAt)); }
[ "public", "function", "roundWeek", "(", "$", "weekStartsAt", "=", "null", ")", "{", "return", "$", "this", "->", "closest", "(", "$", "this", "->", "copy", "(", ")", "->", "floorWeek", "(", "$", "weekStartsAt", ")", ",", "$", "this", "->", "copy", "(", ")", "->", "ceilWeek", "(", "$", "weekStartsAt", ")", ")", ";", "}" ]
Round the current instance week. @param int $weekStartsAt optional start allow you to specify the day of week to use to start the week @return CarbonInterface
[ "Round", "the", "current", "instance", "week", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Rounding.php#L175-L178
train
briannesbitt/Carbon
src/Carbon/Traits/Rounding.php
Rounding.ceilWeek
public function ceilWeek($weekStartsAt = null) { if ($this->isMutable()) { $startOfWeek = $this->copy()->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $this->startOfWeek($weekStartsAt)->addWeek() : $this; } $startOfWeek = $this->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $startOfWeek->addWeek() : $this->copy(); }
php
public function ceilWeek($weekStartsAt = null) { if ($this->isMutable()) { $startOfWeek = $this->copy()->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $this->startOfWeek($weekStartsAt)->addWeek() : $this; } $startOfWeek = $this->startOfWeek($weekStartsAt); return $startOfWeek != $this ? $startOfWeek->addWeek() : $this->copy(); }
[ "public", "function", "ceilWeek", "(", "$", "weekStartsAt", "=", "null", ")", "{", "if", "(", "$", "this", "->", "isMutable", "(", ")", ")", "{", "$", "startOfWeek", "=", "$", "this", "->", "copy", "(", ")", "->", "startOfWeek", "(", "$", "weekStartsAt", ")", ";", "return", "$", "startOfWeek", "!=", "$", "this", "?", "$", "this", "->", "startOfWeek", "(", "$", "weekStartsAt", ")", "->", "addWeek", "(", ")", ":", "$", "this", ";", "}", "$", "startOfWeek", "=", "$", "this", "->", "startOfWeek", "(", "$", "weekStartsAt", ")", ";", "return", "$", "startOfWeek", "!=", "$", "this", "?", "$", "startOfWeek", "->", "addWeek", "(", ")", ":", "$", "this", "->", "copy", "(", ")", ";", "}" ]
Ceil the current instance week. @param int $weekStartsAt optional start allow you to specify the day of week to use to start the week @return CarbonInterface
[ "Ceil", "the", "current", "instance", "week", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Rounding.php#L199-L214
train
briannesbitt/Carbon
src/Carbon/Traits/Comparison.php
Comparison.isSameUnit
public function isSameUnit($unit, $date = null) { $units = [ // @call isSameUnit 'year' => 'Y', // @call isSameUnit 'week' => 'o-W', // @call isSameUnit 'day' => 'Y-m-d', // @call isSameUnit 'hour' => 'Y-m-d H', // @call isSameUnit 'minute' => 'Y-m-d H:i', // @call isSameUnit 'second' => 'Y-m-d H:i:s', // @call isSameUnit 'micro' => 'Y-m-d H:i:s.u', // @call isSameUnit 'microsecond' => 'Y-m-d H:i:s.u', ]; if (!isset($units[$unit])) { if (isset($this->$unit)) { $date = $date ? static::instance($date) : static::now($this->tz); static::expectDateTime($date); return $this->$unit === $date->$unit; } if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) { throw new InvalidArgumentException("Bad comparison unit: '$unit'"); } return false; } return $this->isSameAs($units[$unit], $date); }
php
public function isSameUnit($unit, $date = null) { $units = [ // @call isSameUnit 'year' => 'Y', // @call isSameUnit 'week' => 'o-W', // @call isSameUnit 'day' => 'Y-m-d', // @call isSameUnit 'hour' => 'Y-m-d H', // @call isSameUnit 'minute' => 'Y-m-d H:i', // @call isSameUnit 'second' => 'Y-m-d H:i:s', // @call isSameUnit 'micro' => 'Y-m-d H:i:s.u', // @call isSameUnit 'microsecond' => 'Y-m-d H:i:s.u', ]; if (!isset($units[$unit])) { if (isset($this->$unit)) { $date = $date ? static::instance($date) : static::now($this->tz); static::expectDateTime($date); return $this->$unit === $date->$unit; } if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) { throw new InvalidArgumentException("Bad comparison unit: '$unit'"); } return false; } return $this->isSameAs($units[$unit], $date); }
[ "public", "function", "isSameUnit", "(", "$", "unit", ",", "$", "date", "=", "null", ")", "{", "$", "units", "=", "[", "// @call isSameUnit", "'year'", "=>", "'Y'", ",", "// @call isSameUnit", "'week'", "=>", "'o-W'", ",", "// @call isSameUnit", "'day'", "=>", "'Y-m-d'", ",", "// @call isSameUnit", "'hour'", "=>", "'Y-m-d H'", ",", "// @call isSameUnit", "'minute'", "=>", "'Y-m-d H:i'", ",", "// @call isSameUnit", "'second'", "=>", "'Y-m-d H:i:s'", ",", "// @call isSameUnit", "'micro'", "=>", "'Y-m-d H:i:s.u'", ",", "// @call isSameUnit", "'microsecond'", "=>", "'Y-m-d H:i:s.u'", ",", "]", ";", "if", "(", "!", "isset", "(", "$", "units", "[", "$", "unit", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "$", "unit", ")", ")", "{", "$", "date", "=", "$", "date", "?", "static", "::", "instance", "(", "$", "date", ")", ":", "static", "::", "now", "(", "$", "this", "->", "tz", ")", ";", "static", "::", "expectDateTime", "(", "$", "date", ")", ";", "return", "$", "this", "->", "$", "unit", "===", "$", "date", "->", "$", "unit", ";", "}", "if", "(", "$", "this", "->", "localStrictModeEnabled", "??", "static", "::", "isStrictModeEnabled", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Bad comparison unit: '$unit'\"", ")", ";", "}", "return", "false", ";", "}", "return", "$", "this", "->", "isSameAs", "(", "$", "units", "[", "$", "unit", "]", ",", "$", "date", ")", ";", "}" ]
Determines if the instance is in the current unit given. @param string $unit singular unit string @param \Carbon\Carbon|\DateTimeInterface|null $date instance to compare with or null to use current day. @throws \InvalidArgumentException @return bool
[ "Determines", "if", "the", "instance", "is", "in", "the", "current", "unit", "given", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Comparison.php#L376-L414
train
briannesbitt/Carbon
src/Carbon/Traits/Comparison.php
Comparison.isDayOfWeek
public function isDayOfWeek($dayOfWeek) { if (is_string($dayOfWeek) && defined($constant = static::class.'::'.strtoupper($dayOfWeek))) { $dayOfWeek = constant($constant); } return $this->dayOfWeek === $dayOfWeek; }
php
public function isDayOfWeek($dayOfWeek) { if (is_string($dayOfWeek) && defined($constant = static::class.'::'.strtoupper($dayOfWeek))) { $dayOfWeek = constant($constant); } return $this->dayOfWeek === $dayOfWeek; }
[ "public", "function", "isDayOfWeek", "(", "$", "dayOfWeek", ")", "{", "if", "(", "is_string", "(", "$", "dayOfWeek", ")", "&&", "defined", "(", "$", "constant", "=", "static", "::", "class", ".", "'::'", ".", "strtoupper", "(", "$", "dayOfWeek", ")", ")", ")", "{", "$", "dayOfWeek", "=", "constant", "(", "$", "constant", ")", ";", "}", "return", "$", "this", "->", "dayOfWeek", "===", "$", "dayOfWeek", ";", "}" ]
Checks if this day is a specific day of the week. @param int $dayOfWeek @return bool
[ "Checks", "if", "this", "day", "is", "a", "specific", "day", "of", "the", "week", "." ]
3f227330a10b48e5a27b74b12d972d787d5a78b3
https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Comparison.php#L470-L477
train
nrk/predis
src/Autoloader.php
Autoloader.autoload
public function autoload($className) { if (0 === strpos($className, $this->prefix)) { $parts = explode('\\', substr($className, $this->prefixLength)); $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php'; if (is_file($filepath)) { require $filepath; } } }
php
public function autoload($className) { if (0 === strpos($className, $this->prefix)) { $parts = explode('\\', substr($className, $this->prefixLength)); $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php'; if (is_file($filepath)) { require $filepath; } } }
[ "public", "function", "autoload", "(", "$", "className", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "className", ",", "$", "this", "->", "prefix", ")", ")", "{", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "substr", "(", "$", "className", ",", "$", "this", "->", "prefixLength", ")", ")", ";", "$", "filepath", "=", "$", "this", "->", "directory", ".", "DIRECTORY_SEPARATOR", ".", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "parts", ")", ".", "'.php'", ";", "if", "(", "is_file", "(", "$", "filepath", ")", ")", "{", "require", "$", "filepath", ";", "}", "}", "}" ]
Loads a class from a file using its fully qualified name. @param string $className Fully qualified name of a class.
[ "Loads", "a", "class", "from", "a", "file", "using", "its", "fully", "qualified", "name", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Autoloader.php#L51-L61
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.isReadOperation
public function isReadOperation(CommandInterface $command) { if (isset($this->disallowed[$id = $command->getId()])) { throw new NotSupportedException( "The command '$id' is not allowed in replication mode." ); } if (isset($this->readonly[$id])) { if (true === $readonly = $this->readonly[$id]) { return true; } return call_user_func($readonly, $command); } if (($eval = $id === 'EVAL') || $id === 'EVALSHA') { $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0); if (isset($this->readonlySHA1[$sha1])) { if (true === $readonly = $this->readonlySHA1[$sha1]) { return true; } return call_user_func($readonly, $command); } } return false; }
php
public function isReadOperation(CommandInterface $command) { if (isset($this->disallowed[$id = $command->getId()])) { throw new NotSupportedException( "The command '$id' is not allowed in replication mode." ); } if (isset($this->readonly[$id])) { if (true === $readonly = $this->readonly[$id]) { return true; } return call_user_func($readonly, $command); } if (($eval = $id === 'EVAL') || $id === 'EVALSHA') { $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0); if (isset($this->readonlySHA1[$sha1])) { if (true === $readonly = $this->readonlySHA1[$sha1]) { return true; } return call_user_func($readonly, $command); } } return false; }
[ "public", "function", "isReadOperation", "(", "CommandInterface", "$", "command", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "disallowed", "[", "$", "id", "=", "$", "command", "->", "getId", "(", ")", "]", ")", ")", "{", "throw", "new", "NotSupportedException", "(", "\"The command '$id' is not allowed in replication mode.\"", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "readonly", "[", "$", "id", "]", ")", ")", "{", "if", "(", "true", "===", "$", "readonly", "=", "$", "this", "->", "readonly", "[", "$", "id", "]", ")", "{", "return", "true", ";", "}", "return", "call_user_func", "(", "$", "readonly", ",", "$", "command", ")", ";", "}", "if", "(", "(", "$", "eval", "=", "$", "id", "===", "'EVAL'", ")", "||", "$", "id", "===", "'EVALSHA'", ")", "{", "$", "sha1", "=", "$", "eval", "?", "sha1", "(", "$", "command", "->", "getArgument", "(", "0", ")", ")", ":", "$", "command", "->", "getArgument", "(", "0", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "readonlySHA1", "[", "$", "sha1", "]", ")", ")", "{", "if", "(", "true", "===", "$", "readonly", "=", "$", "this", "->", "readonlySHA1", "[", "$", "sha1", "]", ")", "{", "return", "true", ";", "}", "return", "call_user_func", "(", "$", "readonly", ",", "$", "command", ")", ";", "}", "}", "return", "false", ";", "}" ]
Returns if the specified command will perform a read-only operation on Redis or not. @param CommandInterface $command Command instance. @throws NotSupportedException @return bool
[ "Returns", "if", "the", "specified", "command", "will", "perform", "a", "read", "-", "only", "operation", "on", "Redis", "or", "not", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L48-L77
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.isSortReadOnly
protected function isSortReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); $argc = count($arguments); if ($argc > 1) { for ($i = 1; $i < $argc; ++$i) { $argument = strtoupper($arguments[$i]); if ($argument === 'STORE') { return false; } } } return true; }
php
protected function isSortReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); $argc = count($arguments); if ($argc > 1) { for ($i = 1; $i < $argc; ++$i) { $argument = strtoupper($arguments[$i]); if ($argument === 'STORE') { return false; } } } return true; }
[ "protected", "function", "isSortReadOnly", "(", "CommandInterface", "$", "command", ")", "{", "$", "arguments", "=", "$", "command", "->", "getArguments", "(", ")", ";", "$", "argc", "=", "count", "(", "$", "arguments", ")", ";", "if", "(", "$", "argc", ">", "1", ")", "{", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "$", "argc", ";", "++", "$", "i", ")", "{", "$", "argument", "=", "strtoupper", "(", "$", "arguments", "[", "$", "i", "]", ")", ";", "if", "(", "$", "argument", "===", "'STORE'", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Checks if a SORT command is a readable operation by parsing the arguments array of the specified commad instance. @param CommandInterface $command Command instance. @return bool
[ "Checks", "if", "a", "SORT", "command", "is", "a", "readable", "operation", "by", "parsing", "the", "arguments", "array", "of", "the", "specified", "commad", "instance", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L100-L115
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.isGeoradiusReadOnly
protected function isGeoradiusReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); $argc = count($arguments); $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4; if ($argc > $startIndex) { for ($i = $startIndex; $i < $argc; ++$i) { $argument = strtoupper($arguments[$i]); if ($argument === 'STORE' || $argument === 'STOREDIST') { return false; } } } return true; }
php
protected function isGeoradiusReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); $argc = count($arguments); $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4; if ($argc > $startIndex) { for ($i = $startIndex; $i < $argc; ++$i) { $argument = strtoupper($arguments[$i]); if ($argument === 'STORE' || $argument === 'STOREDIST') { return false; } } } return true; }
[ "protected", "function", "isGeoradiusReadOnly", "(", "CommandInterface", "$", "command", ")", "{", "$", "arguments", "=", "$", "command", "->", "getArguments", "(", ")", ";", "$", "argc", "=", "count", "(", "$", "arguments", ")", ";", "$", "startIndex", "=", "$", "command", "->", "getId", "(", ")", "===", "'GEORADIUS'", "?", "5", ":", "4", ";", "if", "(", "$", "argc", ">", "$", "startIndex", ")", "{", "for", "(", "$", "i", "=", "$", "startIndex", ";", "$", "i", "<", "$", "argc", ";", "++", "$", "i", ")", "{", "$", "argument", "=", "strtoupper", "(", "$", "arguments", "[", "$", "i", "]", ")", ";", "if", "(", "$", "argument", "===", "'STORE'", "||", "$", "argument", "===", "'STOREDIST'", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Checks if a GEORADIUS command is a readable operation by parsing the arguments array of the specified commad instance. @param CommandInterface $command Command instance. @return bool
[ "Checks", "if", "a", "GEORADIUS", "command", "is", "a", "readable", "operation", "by", "parsing", "the", "arguments", "array", "of", "the", "specified", "commad", "instance", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L150-L166
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.setCommandReadOnly
public function setCommandReadOnly($commandID, $readonly = true) { $commandID = strtoupper($commandID); if ($readonly) { $this->readonly[$commandID] = $readonly; } else { unset($this->readonly[$commandID]); } }
php
public function setCommandReadOnly($commandID, $readonly = true) { $commandID = strtoupper($commandID); if ($readonly) { $this->readonly[$commandID] = $readonly; } else { unset($this->readonly[$commandID]); } }
[ "public", "function", "setCommandReadOnly", "(", "$", "commandID", ",", "$", "readonly", "=", "true", ")", "{", "$", "commandID", "=", "strtoupper", "(", "$", "commandID", ")", ";", "if", "(", "$", "readonly", ")", "{", "$", "this", "->", "readonly", "[", "$", "commandID", "]", "=", "$", "readonly", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "readonly", "[", "$", "commandID", "]", ")", ";", "}", "}" ]
Marks a command as a read-only operation. When the behavior of a command can be decided only at runtime depending on its arguments, a callable object can be provided to dynamically check if the specified command performs a read or a write operation. @param string $commandID Command ID. @param mixed $readonly A boolean value or a callable object.
[ "Marks", "a", "command", "as", "a", "read", "-", "only", "operation", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L178-L187
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.setScriptReadOnly
public function setScriptReadOnly($script, $readonly = true) { $sha1 = sha1($script); if ($readonly) { $this->readonlySHA1[$sha1] = $readonly; } else { unset($this->readonlySHA1[$sha1]); } }
php
public function setScriptReadOnly($script, $readonly = true) { $sha1 = sha1($script); if ($readonly) { $this->readonlySHA1[$sha1] = $readonly; } else { unset($this->readonlySHA1[$sha1]); } }
[ "public", "function", "setScriptReadOnly", "(", "$", "script", ",", "$", "readonly", "=", "true", ")", "{", "$", "sha1", "=", "sha1", "(", "$", "script", ")", ";", "if", "(", "$", "readonly", ")", "{", "$", "this", "->", "readonlySHA1", "[", "$", "sha1", "]", "=", "$", "readonly", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "readonlySHA1", "[", "$", "sha1", "]", ")", ";", "}", "}" ]
Marks a Lua script for EVAL and EVALSHA as a read-only operation. When the behaviour of a script can be decided only at runtime depending on its arguments, a callable object can be provided to dynamically check if the passed instance of EVAL or EVALSHA performs write operations or not. @param string $script Body of the Lua script. @param mixed $readonly A boolean value or a callable object.
[ "Marks", "a", "Lua", "script", "for", "EVAL", "and", "EVALSHA", "as", "a", "read", "-", "only", "operation", ".", "When", "the", "behaviour", "of", "a", "script", "can", "be", "decided", "only", "at", "runtime", "depending", "on", "its", "arguments", "a", "callable", "object", "can", "be", "provided", "to", "dynamically", "check", "if", "the", "passed", "instance", "of", "EVAL", "or", "EVALSHA", "performs", "write", "operations", "or", "not", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L199-L208
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.getDisallowedOperations
protected function getDisallowedOperations() { return array( 'SHUTDOWN' => true, 'INFO' => true, 'DBSIZE' => true, 'LASTSAVE' => true, 'CONFIG' => true, 'MONITOR' => true, 'SLAVEOF' => true, 'SAVE' => true, 'BGSAVE' => true, 'BGREWRITEAOF' => true, 'SLOWLOG' => true, ); }
php
protected function getDisallowedOperations() { return array( 'SHUTDOWN' => true, 'INFO' => true, 'DBSIZE' => true, 'LASTSAVE' => true, 'CONFIG' => true, 'MONITOR' => true, 'SLAVEOF' => true, 'SAVE' => true, 'BGSAVE' => true, 'BGREWRITEAOF' => true, 'SLOWLOG' => true, ); }
[ "protected", "function", "getDisallowedOperations", "(", ")", "{", "return", "array", "(", "'SHUTDOWN'", "=>", "true", ",", "'INFO'", "=>", "true", ",", "'DBSIZE'", "=>", "true", ",", "'LASTSAVE'", "=>", "true", ",", "'CONFIG'", "=>", "true", ",", "'MONITOR'", "=>", "true", ",", "'SLAVEOF'", "=>", "true", ",", "'SAVE'", "=>", "true", ",", "'BGSAVE'", "=>", "true", ",", "'BGREWRITEAOF'", "=>", "true", ",", "'SLOWLOG'", "=>", "true", ",", ")", ";", "}" ]
Returns the default list of disallowed commands. @return array
[ "Returns", "the", "default", "list", "of", "disallowed", "commands", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L215-L230
train
nrk/predis
src/Replication/ReplicationStrategy.php
ReplicationStrategy.getReadOnlyOperations
protected function getReadOnlyOperations() { return array( 'EXISTS' => true, 'TYPE' => true, 'KEYS' => true, 'SCAN' => true, 'RANDOMKEY' => true, 'TTL' => true, 'GET' => true, 'MGET' => true, 'SUBSTR' => true, 'STRLEN' => true, 'GETRANGE' => true, 'GETBIT' => true, 'LLEN' => true, 'LRANGE' => true, 'LINDEX' => true, 'SCARD' => true, 'SISMEMBER' => true, 'SINTER' => true, 'SUNION' => true, 'SDIFF' => true, 'SMEMBERS' => true, 'SSCAN' => true, 'SRANDMEMBER' => true, 'ZRANGE' => true, 'ZREVRANGE' => true, 'ZRANGEBYSCORE' => true, 'ZREVRANGEBYSCORE' => true, 'ZCARD' => true, 'ZSCORE' => true, 'ZCOUNT' => true, 'ZRANK' => true, 'ZREVRANK' => true, 'ZSCAN' => true, 'ZLEXCOUNT' => true, 'ZRANGEBYLEX' => true, 'ZREVRANGEBYLEX' => true, 'HGET' => true, 'HMGET' => true, 'HEXISTS' => true, 'HLEN' => true, 'HKEYS' => true, 'HVALS' => true, 'HGETALL' => true, 'HSCAN' => true, 'HSTRLEN' => true, 'PING' => true, 'AUTH' => true, 'SELECT' => true, 'ECHO' => true, 'QUIT' => true, 'OBJECT' => true, 'BITCOUNT' => true, 'BITPOS' => true, 'TIME' => true, 'PFCOUNT' => true, 'SORT' => array($this, 'isSortReadOnly'), 'BITFIELD' => array($this, 'isBitfieldReadOnly'), 'GEOHASH' => true, 'GEOPOS' => true, 'GEODIST' => true, 'GEORADIUS' => array($this, 'isGeoradiusReadOnly'), 'GEORADIUSBYMEMBER' => array($this, 'isGeoradiusReadOnly'), ); }
php
protected function getReadOnlyOperations() { return array( 'EXISTS' => true, 'TYPE' => true, 'KEYS' => true, 'SCAN' => true, 'RANDOMKEY' => true, 'TTL' => true, 'GET' => true, 'MGET' => true, 'SUBSTR' => true, 'STRLEN' => true, 'GETRANGE' => true, 'GETBIT' => true, 'LLEN' => true, 'LRANGE' => true, 'LINDEX' => true, 'SCARD' => true, 'SISMEMBER' => true, 'SINTER' => true, 'SUNION' => true, 'SDIFF' => true, 'SMEMBERS' => true, 'SSCAN' => true, 'SRANDMEMBER' => true, 'ZRANGE' => true, 'ZREVRANGE' => true, 'ZRANGEBYSCORE' => true, 'ZREVRANGEBYSCORE' => true, 'ZCARD' => true, 'ZSCORE' => true, 'ZCOUNT' => true, 'ZRANK' => true, 'ZREVRANK' => true, 'ZSCAN' => true, 'ZLEXCOUNT' => true, 'ZRANGEBYLEX' => true, 'ZREVRANGEBYLEX' => true, 'HGET' => true, 'HMGET' => true, 'HEXISTS' => true, 'HLEN' => true, 'HKEYS' => true, 'HVALS' => true, 'HGETALL' => true, 'HSCAN' => true, 'HSTRLEN' => true, 'PING' => true, 'AUTH' => true, 'SELECT' => true, 'ECHO' => true, 'QUIT' => true, 'OBJECT' => true, 'BITCOUNT' => true, 'BITPOS' => true, 'TIME' => true, 'PFCOUNT' => true, 'SORT' => array($this, 'isSortReadOnly'), 'BITFIELD' => array($this, 'isBitfieldReadOnly'), 'GEOHASH' => true, 'GEOPOS' => true, 'GEODIST' => true, 'GEORADIUS' => array($this, 'isGeoradiusReadOnly'), 'GEORADIUSBYMEMBER' => array($this, 'isGeoradiusReadOnly'), ); }
[ "protected", "function", "getReadOnlyOperations", "(", ")", "{", "return", "array", "(", "'EXISTS'", "=>", "true", ",", "'TYPE'", "=>", "true", ",", "'KEYS'", "=>", "true", ",", "'SCAN'", "=>", "true", ",", "'RANDOMKEY'", "=>", "true", ",", "'TTL'", "=>", "true", ",", "'GET'", "=>", "true", ",", "'MGET'", "=>", "true", ",", "'SUBSTR'", "=>", "true", ",", "'STRLEN'", "=>", "true", ",", "'GETRANGE'", "=>", "true", ",", "'GETBIT'", "=>", "true", ",", "'LLEN'", "=>", "true", ",", "'LRANGE'", "=>", "true", ",", "'LINDEX'", "=>", "true", ",", "'SCARD'", "=>", "true", ",", "'SISMEMBER'", "=>", "true", ",", "'SINTER'", "=>", "true", ",", "'SUNION'", "=>", "true", ",", "'SDIFF'", "=>", "true", ",", "'SMEMBERS'", "=>", "true", ",", "'SSCAN'", "=>", "true", ",", "'SRANDMEMBER'", "=>", "true", ",", "'ZRANGE'", "=>", "true", ",", "'ZREVRANGE'", "=>", "true", ",", "'ZRANGEBYSCORE'", "=>", "true", ",", "'ZREVRANGEBYSCORE'", "=>", "true", ",", "'ZCARD'", "=>", "true", ",", "'ZSCORE'", "=>", "true", ",", "'ZCOUNT'", "=>", "true", ",", "'ZRANK'", "=>", "true", ",", "'ZREVRANK'", "=>", "true", ",", "'ZSCAN'", "=>", "true", ",", "'ZLEXCOUNT'", "=>", "true", ",", "'ZRANGEBYLEX'", "=>", "true", ",", "'ZREVRANGEBYLEX'", "=>", "true", ",", "'HGET'", "=>", "true", ",", "'HMGET'", "=>", "true", ",", "'HEXISTS'", "=>", "true", ",", "'HLEN'", "=>", "true", ",", "'HKEYS'", "=>", "true", ",", "'HVALS'", "=>", "true", ",", "'HGETALL'", "=>", "true", ",", "'HSCAN'", "=>", "true", ",", "'HSTRLEN'", "=>", "true", ",", "'PING'", "=>", "true", ",", "'AUTH'", "=>", "true", ",", "'SELECT'", "=>", "true", ",", "'ECHO'", "=>", "true", ",", "'QUIT'", "=>", "true", ",", "'OBJECT'", "=>", "true", ",", "'BITCOUNT'", "=>", "true", ",", "'BITPOS'", "=>", "true", ",", "'TIME'", "=>", "true", ",", "'PFCOUNT'", "=>", "true", ",", "'SORT'", "=>", "array", "(", "$", "this", ",", "'isSortReadOnly'", ")", ",", "'BITFIELD'", "=>", "array", "(", "$", "this", ",", "'isBitfieldReadOnly'", ")", ",", "'GEOHASH'", "=>", "true", ",", "'GEOPOS'", "=>", "true", ",", "'GEODIST'", "=>", "true", ",", "'GEORADIUS'", "=>", "array", "(", "$", "this", ",", "'isGeoradiusReadOnly'", ")", ",", "'GEORADIUSBYMEMBER'", "=>", "array", "(", "$", "this", ",", "'isGeoradiusReadOnly'", ")", ",", ")", ";", "}" ]
Returns the default list of commands performing read-only operations. @return array
[ "Returns", "the", "default", "list", "of", "commands", "performing", "read", "-", "only", "operations", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Replication/ReplicationStrategy.php#L237-L303
train
nrk/predis
src/Client.php
Client.createOptions
protected function createOptions($options) { if (is_array($options)) { return new Options($options); } if ($options instanceof OptionsInterface) { return $options; } throw new \InvalidArgumentException('Invalid type for client options.'); }
php
protected function createOptions($options) { if (is_array($options)) { return new Options($options); } if ($options instanceof OptionsInterface) { return $options; } throw new \InvalidArgumentException('Invalid type for client options.'); }
[ "protected", "function", "createOptions", "(", "$", "options", ")", "{", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "return", "new", "Options", "(", "$", "options", ")", ";", "}", "if", "(", "$", "options", "instanceof", "OptionsInterface", ")", "{", "return", "$", "options", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid type for client options.'", ")", ";", "}" ]
Creates a new instance of Predis\Configuration\Options from different types of arguments or simply returns the passed argument if it is an instance of Predis\Configuration\OptionsInterface. @param mixed $options Client options. @throws \InvalidArgumentException @return OptionsInterface
[ "Creates", "a", "new", "instance", "of", "Predis", "\\", "Configuration", "\\", "Options", "from", "different", "types", "of", "arguments", "or", "simply", "returns", "the", "passed", "argument", "if", "it", "is", "an", "instance", "of", "Predis", "\\", "Configuration", "\\", "OptionsInterface", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Client.php#L71-L82
train
nrk/predis
src/Client.php
Client.getConnectionById
public function getConnectionById($connectionID) { if (!$this->connection instanceof AggregateConnectionInterface) { throw new NotSupportedException( 'Retrieving connections by ID is supported only by aggregate connections.' ); } return $this->connection->getConnectionById($connectionID); }
php
public function getConnectionById($connectionID) { if (!$this->connection instanceof AggregateConnectionInterface) { throw new NotSupportedException( 'Retrieving connections by ID is supported only by aggregate connections.' ); } return $this->connection->getConnectionById($connectionID); }
[ "public", "function", "getConnectionById", "(", "$", "connectionID", ")", "{", "if", "(", "!", "$", "this", "->", "connection", "instanceof", "AggregateConnectionInterface", ")", "{", "throw", "new", "NotSupportedException", "(", "'Retrieving connections by ID is supported only by aggregate connections.'", ")", ";", "}", "return", "$", "this", "->", "connection", "->", "getConnectionById", "(", "$", "connectionID", ")", ";", "}" ]
Retrieves the specified connection from the aggregate connection when the client is in cluster or replication mode. @param string $connectionID Index or alias of the single connection. @throws NotSupportedException @return Connection\NodeConnectionInterface
[ "Retrieves", "the", "specified", "connection", "from", "the", "aggregate", "connection", "when", "the", "client", "is", "in", "cluster", "or", "replication", "mode", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Client.php#L265-L274
train
nrk/predis
src/Client.php
Client.createPipeline
protected function createPipeline(array $options = null, $callable = null) { if (isset($options['atomic']) && $options['atomic']) { $class = 'Predis\Pipeline\Atomic'; } elseif (isset($options['fire-and-forget']) && $options['fire-and-forget']) { $class = 'Predis\Pipeline\FireAndForget'; } else { $class = 'Predis\Pipeline\Pipeline'; } /* * @var ClientContextInterface */ $pipeline = new $class($this); if (isset($callable)) { return $pipeline->execute($callable); } return $pipeline; }
php
protected function createPipeline(array $options = null, $callable = null) { if (isset($options['atomic']) && $options['atomic']) { $class = 'Predis\Pipeline\Atomic'; } elseif (isset($options['fire-and-forget']) && $options['fire-and-forget']) { $class = 'Predis\Pipeline\FireAndForget'; } else { $class = 'Predis\Pipeline\Pipeline'; } /* * @var ClientContextInterface */ $pipeline = new $class($this); if (isset($callable)) { return $pipeline->execute($callable); } return $pipeline; }
[ "protected", "function", "createPipeline", "(", "array", "$", "options", "=", "null", ",", "$", "callable", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'atomic'", "]", ")", "&&", "$", "options", "[", "'atomic'", "]", ")", "{", "$", "class", "=", "'Predis\\Pipeline\\Atomic'", ";", "}", "elseif", "(", "isset", "(", "$", "options", "[", "'fire-and-forget'", "]", ")", "&&", "$", "options", "[", "'fire-and-forget'", "]", ")", "{", "$", "class", "=", "'Predis\\Pipeline\\FireAndForget'", ";", "}", "else", "{", "$", "class", "=", "'Predis\\Pipeline\\Pipeline'", ";", "}", "/*\n * @var ClientContextInterface\n */", "$", "pipeline", "=", "new", "$", "class", "(", "$", "this", ")", ";", "if", "(", "isset", "(", "$", "callable", ")", ")", "{", "return", "$", "pipeline", "->", "execute", "(", "$", "callable", ")", ";", "}", "return", "$", "pipeline", ";", "}" ]
Actual pipeline context initializer method. @param array $options Options for the context. @param mixed $callable Optional callable used to execute the context. @return Pipeline|array
[ "Actual", "pipeline", "context", "initializer", "method", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Client.php#L429-L449
train
nrk/predis
src/Client.php
Client.createTransaction
protected function createTransaction(array $options = null, $callable = null) { $transaction = new MultiExecTransaction($this, $options); if (isset($callable)) { return $transaction->execute($callable); } return $transaction; }
php
protected function createTransaction(array $options = null, $callable = null) { $transaction = new MultiExecTransaction($this, $options); if (isset($callable)) { return $transaction->execute($callable); } return $transaction; }
[ "protected", "function", "createTransaction", "(", "array", "$", "options", "=", "null", ",", "$", "callable", "=", "null", ")", "{", "$", "transaction", "=", "new", "MultiExecTransaction", "(", "$", "this", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "callable", ")", ")", "{", "return", "$", "transaction", "->", "execute", "(", "$", "callable", ")", ";", "}", "return", "$", "transaction", ";", "}" ]
Actual transaction context initializer method. @param array $options Options for the context. @param mixed $callable Optional callable used to execute the context. @return MultiExecTransaction|array
[ "Actual", "transaction", "context", "initializer", "method", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Client.php#L472-L481
train
nrk/predis
src/Collection/Iterator/ListKey.php
ListKey.reset
protected function reset() { $this->valid = true; $this->fetchmore = true; $this->elements = array(); $this->position = -1; $this->current = null; }
php
protected function reset() { $this->valid = true; $this->fetchmore = true; $this->elements = array(); $this->position = -1; $this->current = null; }
[ "protected", "function", "reset", "(", ")", "{", "$", "this", "->", "valid", "=", "true", ";", "$", "this", "->", "fetchmore", "=", "true", ";", "$", "this", "->", "elements", "=", "array", "(", ")", ";", "$", "this", "->", "position", "=", "-", "1", ";", "$", "this", "->", "current", "=", "null", ";", "}" ]
Resets the inner state of the iterator.
[ "Resets", "the", "inner", "state", "of", "the", "iterator", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Collection/Iterator/ListKey.php#L84-L91
train
nrk/predis
src/Collection/Iterator/ListKey.php
ListKey.executeCommand
protected function executeCommand() { return $this->client->lrange($this->key, $this->position + 1, $this->position + $this->count); }
php
protected function executeCommand() { return $this->client->lrange($this->key, $this->position + 1, $this->position + $this->count); }
[ "protected", "function", "executeCommand", "(", ")", "{", "return", "$", "this", "->", "client", "->", "lrange", "(", "$", "this", "->", "key", ",", "$", "this", "->", "position", "+", "1", ",", "$", "this", "->", "position", "+", "$", "this", "->", "count", ")", ";", "}" ]
Fetches a new set of elements from the remote collection, effectively advancing the iteration process. @return array
[ "Fetches", "a", "new", "set", "of", "elements", "from", "the", "remote", "collection", "effectively", "advancing", "the", "iteration", "process", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Collection/Iterator/ListKey.php#L99-L102
train
nrk/predis
src/Connection/PhpiredisStreamConnection.php
PhpiredisStreamConnection.createReader
private function createReader() { $reader = phpiredis_reader_create(); phpiredis_reader_set_status_handler($reader, $this->getStatusHandler()); phpiredis_reader_set_error_handler($reader, $this->getErrorHandler()); return $reader; }
php
private function createReader() { $reader = phpiredis_reader_create(); phpiredis_reader_set_status_handler($reader, $this->getStatusHandler()); phpiredis_reader_set_error_handler($reader, $this->getErrorHandler()); return $reader; }
[ "private", "function", "createReader", "(", ")", "{", "$", "reader", "=", "phpiredis_reader_create", "(", ")", ";", "phpiredis_reader_set_status_handler", "(", "$", "reader", ",", "$", "this", "->", "getStatusHandler", "(", ")", ")", ";", "phpiredis_reader_set_error_handler", "(", "$", "reader", ",", "$", "this", "->", "getErrorHandler", "(", ")", ")", ";", "return", "$", "reader", ";", "}" ]
Creates a new instance of the protocol reader resource. @return resource
[ "Creates", "a", "new", "instance", "of", "the", "protocol", "reader", "resource", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Connection/PhpiredisStreamConnection.php#L136-L144
train
nrk/predis
src/Connection/Aggregate/MasterSlaveReplication.php
MasterSlaveReplication.handleInfoResponse
private function handleInfoResponse($response) { $info = array(); foreach (preg_split('/\r?\n/', $response) as $row) { if (strpos($row, ':') === false) { continue; } list($k, $v) = explode(':', $row, 2); $info[$k] = $v; } return $info; }
php
private function handleInfoResponse($response) { $info = array(); foreach (preg_split('/\r?\n/', $response) as $row) { if (strpos($row, ':') === false) { continue; } list($k, $v) = explode(':', $row, 2); $info[$k] = $v; } return $info; }
[ "private", "function", "handleInfoResponse", "(", "$", "response", ")", "{", "$", "info", "=", "array", "(", ")", ";", "foreach", "(", "preg_split", "(", "'/\\r?\\n/'", ",", "$", "response", ")", "as", "$", "row", ")", "{", "if", "(", "strpos", "(", "$", "row", ",", "':'", ")", "===", "false", ")", "{", "continue", ";", "}", "list", "(", "$", "k", ",", "$", "v", ")", "=", "explode", "(", "':'", ",", "$", "row", ",", "2", ")", ";", "$", "info", "[", "$", "k", "]", "=", "$", "v", ";", "}", "return", "$", "info", ";", "}" ]
Handles response from INFO. @param string $response @return array
[ "Handles", "response", "from", "INFO", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Connection/Aggregate/MasterSlaveReplication.php#L325-L339
train
nrk/predis
src/Connection/Aggregate/MasterSlaveReplication.php
MasterSlaveReplication.discover
public function discover() { if (!$this->connectionFactory) { throw new ClientException('Discovery requires a connection factory'); } RETRY_FETCH: { try { if ($connection = $this->getMaster()) { $this->discoverFromMaster($connection, $this->connectionFactory); } elseif ($connection = $this->pickSlave()) { $this->discoverFromSlave($connection, $this->connectionFactory); } else { throw new ClientException('No connection available for discovery'); } } catch (ConnectionException $exception) { $this->remove($connection); goto RETRY_FETCH; } } }
php
public function discover() { if (!$this->connectionFactory) { throw new ClientException('Discovery requires a connection factory'); } RETRY_FETCH: { try { if ($connection = $this->getMaster()) { $this->discoverFromMaster($connection, $this->connectionFactory); } elseif ($connection = $this->pickSlave()) { $this->discoverFromSlave($connection, $this->connectionFactory); } else { throw new ClientException('No connection available for discovery'); } } catch (ConnectionException $exception) { $this->remove($connection); goto RETRY_FETCH; } } }
[ "public", "function", "discover", "(", ")", "{", "if", "(", "!", "$", "this", "->", "connectionFactory", ")", "{", "throw", "new", "ClientException", "(", "'Discovery requires a connection factory'", ")", ";", "}", "RETRY_FETCH", ":", "{", "try", "{", "if", "(", "$", "connection", "=", "$", "this", "->", "getMaster", "(", ")", ")", "{", "$", "this", "->", "discoverFromMaster", "(", "$", "connection", ",", "$", "this", "->", "connectionFactory", ")", ";", "}", "elseif", "(", "$", "connection", "=", "$", "this", "->", "pickSlave", "(", ")", ")", "{", "$", "this", "->", "discoverFromSlave", "(", "$", "connection", ",", "$", "this", "->", "connectionFactory", ")", ";", "}", "else", "{", "throw", "new", "ClientException", "(", "'No connection available for discovery'", ")", ";", "}", "}", "catch", "(", "ConnectionException", "$", "exception", ")", "{", "$", "this", "->", "remove", "(", "$", "connection", ")", ";", "goto", "RETRY_FETCH", ";", "}", "}", "}" ]
Fetches the replication configuration from one of the servers.
[ "Fetches", "the", "replication", "configuration", "from", "one", "of", "the", "servers", "." ]
111d100ee389d624036b46b35ed0c9ac59c71313
https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Connection/Aggregate/MasterSlaveReplication.php#L344-L364
train