code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function diffForHumans(?ChronosDate $other = null, bool $absolute = false): string { return static::diffFormatter()->diffForHumans($this, $other, $absolute); }
Get the difference in a human readable format. When comparing a value in the past to default now: 5 months ago When comparing a value in the future to default now: 5 months from now When comparing a value in the past to another value: 5 months before When comparing a value in the future to another value: 5 months after @param \Cake\Chronos\ChronosDate|null $other The datetime to compare with. @param bool $absolute removes difference modifiers ago, after, etc @return string
diffForHumans
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable { if ($timezone === null) { return $this->native; } $timezone = is_string($timezone) ? new DateTimeZone($timezone) : $timezone; return new DateTimeImmutable($this->native->format('Y-m-d H:i:s.u'), $timezone); }
Returns the date as a `DateTimeImmutable` instance at midnight. @param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in @return \DateTimeImmutable
toDateTimeImmutable
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable { return $this->toDateTimeImmutable($timezone); }
Returns the date as a `DateTimeImmutable` instance at midnight. Alias of `toDateTimeImmutable()`. @param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in @return \DateTimeImmutable
toNative
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function __get(string $name): string|float|int|bool { static $formats = [ 'year' => 'Y', 'yearIso' => 'o', 'month' => 'n', 'day' => 'j', 'dayOfWeek' => 'N', 'dayOfYear' => 'z', 'weekOfYear' => 'W', 'daysInMonth' => 't', ]; switch (true) { case isset($formats[$name]): return (int)$this->format($formats[$name]); case $name === 'dayOfWeekName': return $this->format('l'); case $name === 'weekOfMonth': return (int)ceil($this->day / Chronos::DAYS_PER_WEEK); case $name === 'age': return $this->diffInYears(); case $name === 'quarter': return (int)ceil($this->month / 3); case $name === 'half': return $this->month <= 6 ? 1 : 2; default: throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)); } }
Get a part of the object @param string $name The property name to read. @return string|float|int|bool The property value. @throws \InvalidArgumentException
__get
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function __isset(string $name): bool { try { $this->__get($name); } catch (InvalidArgumentException $e) { return false; } return true; }
Check if an attribute exists on the object @param string $name The property name to check. @return bool Whether the property exists.
__isset
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function __debugInfo(): array { $properties = [ 'hasFixedNow' => Chronos::hasTestNow(), 'date' => $this->format('Y-m-d'), ]; return $properties; }
Return properties for debugging. @return array
__debugInfo
php
cakephp/chronos
src/ChronosDate.php
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
MIT
public function __construct( ChronosTime|DateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null, ) { if ($time === null) { $time = Chronos::getTestNow() ?? Chronos::now(); if ($timezone !== null) { $time = $time->setTimezone($timezone); } $this->ticks = static::parseString($time->format('H:i:s.u')); } elseif (is_string($time)) { $this->ticks = static::parseString($time); } elseif ($time instanceof ChronosTime) { $this->ticks = $time->ticks; } else { $this->ticks = static::parseString($time->format('H:i:s.u')); } }
Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u. Defaults to server time. @param \Cake\Chronos\ChronosTime|\DateTimeInterface|string|null $time Time @param \DateTimeZone|string|null $timezone The timezone to use for now
__construct
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function parse( ChronosTime|DateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null, ): static { return new static($time, $timezone); }
Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u Defaults to server time. @param \Cake\Chronos\ChronosTime|\DateTimeInterface|string $time Time @param \DateTimeZone|string|null $timezone The timezone to use for now @return static
parse
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
protected static function parseString(string $time): int { if (!preg_match('/^\s*(\d{1,2})[:.](\d{1,2})(?|[:.](\d{1,2})[.](\d+)|[:.](\d{1,2}))?\s*$/', $time, $matches)) { throw new InvalidArgumentException( sprintf('Time string `%s` is not in expected format `HH[:.]mm` or `HH[:.]mm[:.]ss.u`.', $time), ); } $hours = (int)$matches[1]; $minutes = (int)$matches[2]; $seconds = (int)($matches[3] ?? 0); $microseconds = (int)substr($matches[4] ?? '', 0, 6); if ($hours > 24 || $minutes > 59 || $seconds > 59 || $microseconds > 999_999) { throw new InvalidArgumentException(sprintf('Time string `%s` contains invalid values.', $time)); } $ticks = $hours * self::TICKS_PER_HOUR; $ticks += $minutes * self::TICKS_PER_MINUTE; $ticks += $seconds * self::TICKS_PER_SECOND; $ticks += $microseconds * self::TICKS_PER_MICROSECOND; return $ticks % self::TICKS_PER_DAY; }
@param string $time Time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u @return int
parseString
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function now(DateTimeZone|string|null $timezone = null): static { return new static(null, $timezone); }
Returns instance set to server time. @param \DateTimeZone|string|null $timezone The timezone to use for now @return static
now
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function midnight(): static { return new static('00:00:00'); }
Returns instance set to midnight. @return static
midnight
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function noon(): static { return new static('12:00:00'); }
Returns instance set to noon. @return static
noon
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function endOfDay(bool $microseconds = false): static { if ($microseconds) { return new static('23:59:59.999999'); } return new static('23:59:59'); }
Returns instance set to end of day - either 23:59:59 or 23:59:59.999999 if `$microseconds` is true @param bool $microseconds Whether to set microseconds or not @return static
endOfDay
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function setMicroseconds(int $microseconds): static { $baseTicks = $this->ticks - $this->ticks % self::TICKS_PER_SECOND; $newTicks = static::mod($baseTicks + $microseconds * self::TICKS_PER_MICROSECOND, self::TICKS_PER_DAY); $clone = clone $this; $clone->ticks = $newTicks; return $clone; }
Sets clock microseconds. @param int $microseconds Clock microseconds @return static
setMicroseconds
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function setSeconds(int $seconds): static { $baseTicks = $this->ticks - ($this->ticks % self::TICKS_PER_MINUTE - $this->ticks % self::TICKS_PER_SECOND); $newTicks = static::mod($baseTicks + $seconds * self::TICKS_PER_SECOND, self::TICKS_PER_DAY); $clone = clone $this; $clone->ticks = $newTicks; return $clone; }
Set clock seconds. @param int $seconds Clock seconds @return static
setSeconds
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function setMinutes(int $minutes): static { $baseTicks = $this->ticks - ($this->ticks % self::TICKS_PER_HOUR - $this->ticks % self::TICKS_PER_MINUTE); $newTicks = static::mod($baseTicks + $minutes * self::TICKS_PER_MINUTE, self::TICKS_PER_DAY); $clone = clone $this; $clone->ticks = $newTicks; return $clone; }
Set clock minutes. @param int $minutes Clock minutes @return static
setMinutes
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function setHours(int $hours): static { $baseTicks = $this->ticks - ($this->ticks - $this->ticks % self::TICKS_PER_HOUR); $newTicks = static::mod($baseTicks + $hours * self::TICKS_PER_HOUR, self::TICKS_PER_DAY); $clone = clone $this; $clone->ticks = $newTicks; return $clone; }
Set clock hours. @param int $hours Clock hours @return static
setHours
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function setTime(int $hours = 0, int $minutes = 0, int $seconds = 0, int $microseconds = 0): static { $ticks = $hours * self::TICKS_PER_HOUR + $minutes * self::TICKS_PER_MINUTE + $seconds * self::TICKS_PER_SECOND + $microseconds * self::TICKS_PER_MICROSECOND; $ticks = static::mod($ticks, self::TICKS_PER_DAY); $clone = clone $this; $clone->ticks = $ticks; return $clone; }
Sets clock time. @param int $hours Clock hours @param int $minutes Clock minutes @param int $seconds Clock seconds @param int $microseconds Clock microseconds @return static
setTime
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
protected static function mod(int $a, int $b): int { if ($a < 0) { return $a % $b + $b; } return $a % $b; }
@param int $a Left side @param int $a Right side @return int
mod
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function format(string $format): string { return $this->toDateTimeImmutable()->format($format); }
Formats string using the same syntax as `DateTimeImmutable::format()`. As this uses DateTimeImmutable::format() to format the string, non-time formatters will still be interpreted. Be sure to escape those characters first. @param string $format Format string @return string
format
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function resetToStringFormat(): void { static::setToStringFormat(static::DEFAULT_TO_STRING_FORMAT); }
Reset the format used to the default when converting to a string @return void
resetToStringFormat
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public static function setToStringFormat(string $format): void { static::$toStringFormat = $format; }
Set the default format used when converting to a string @param string $format The format to use in future __toString() calls. @return void
setToStringFormat
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function __toString(): string { return $this->format(static::$toStringFormat); }
Format the instance as a string using the set format @return string
__toString
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function equals(ChronosTime $target): bool { return $this->ticks === $target->ticks; }
Returns whether time is equal to target time. @param \Cake\Chronos\ChronosTime $target Target time @return bool
equals
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function greaterThan(ChronosTime $target): bool { return $this->ticks > $target->ticks; }
Returns whether time is greater than target time. @param \Cake\Chronos\ChronosTime $target Target time @return bool
greaterThan
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function greaterThanOrEquals(ChronosTime $target): bool { return $this->ticks >= $target->ticks; }
Returns whether time is greater than or equal to target time. @param \Cake\Chronos\ChronosTime $target Target time @return bool
greaterThanOrEquals
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function lessThan(ChronosTime $target): bool { return $this->ticks < $target->ticks; }
Returns whether time is less than target time. @param \Cake\Chronos\ChronosTime $target Target time @return bool
lessThan
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function lessThanOrEquals(ChronosTime $target): bool { return $this->ticks <= $target->ticks; }
Returns whether time is less than or equal to target time. @param \Cake\Chronos\ChronosTime $target Target time @return bool
lessThanOrEquals
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function between(ChronosTime $start, ChronosTime $end, bool $equals = true): bool { if ($start->greaterThan($end)) { [$start, $end] = [$end, $start]; } if ($equals) { return $this->greaterThanOrEquals($start) && $this->lessThanOrEquals($end); } return $this->greaterThan($start) && $this->lessThan($end); }
Returns whether time is between time range. @param \Cake\Chronos\ChronosTime $start Start of target range @param \Cake\Chronos\ChronosTime $end End of target range @param bool $equals Whether to include the beginning and end of range @return bool
between
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable { $timezone = is_string($timezone) ? new DateTimeZone($timezone) : $timezone; return (new DateTimeImmutable(timezone: $timezone))->setTime( $this->getHours(), $this->getMinutes(), $this->getSeconds(), $this->getMicroseconds(), ); }
Returns an `DateTimeImmutable` instance set to this clock time. @param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in @return \DateTimeImmutable
toDateTimeImmutable
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable { return $this->toDateTimeImmutable($timezone); }
Returns an `DateTimeImmutable` instance set to this clock time. Alias of `toDateTimeImmutable()`. @param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in @return \DateTimeImmutable
toNative
php
cakephp/chronos
src/ChronosTime.php
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
MIT
public function __construct(DateTimeZone|string|null $timezone = null) { $this->timezone = $timezone; }
Constructor. @param \DateTimeZone|string|null $timezone The timezone
__construct
php
cakephp/chronos
src/ClockFactory.php
https://github.com/cakephp/chronos/blob/master/src/ClockFactory.php
MIT
public function now(): DateTimeImmutable { return Chronos::now($this->timezone); }
Returns the current time object. @return \Cake\Chronos\Chronos The current time
now
php
cakephp/chronos
src/ClockFactory.php
https://github.com/cakephp/chronos/blob/master/src/ClockFactory.php
MIT
public function __construct(?Translator $translate = null) { $this->translate = $translate ?: new Translator(); }
Constructor. @param \Cake\Chronos\Translator|null $translate The text translator object.
__construct
php
cakephp/chronos
src/DifferenceFormatter.php
https://github.com/cakephp/chronos/blob/master/src/DifferenceFormatter.php
MIT
public static function resetToStringFormat(): void { static::setToStringFormat(static::DEFAULT_TO_STRING_FORMAT); }
Resets the __toString() format to ``DEFAULT_TO_STRING_FORMAT``. @return void
resetToStringFormat
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public static function setToStringFormat(string $format): void { static::$toStringFormat = $format; }
Sets the __toString() format. @param string $format See ``format()`` for accepted specifiers. @return void
setToStringFormat
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function __toString(): string { return $this->format(static::$toStringFormat); }
Returns a formatted string specified by ``setToStringFormat()`` or the default ``DEFAULT_TO_STRING_FORMAT`` format. @return string
__toString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toDateString(): string { return $this->format('Y-m-d'); }
Format the instance as date @return string
toDateString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toFormattedDateString(): string { return $this->format('M j, Y'); }
Format the instance as a readable date @return string
toFormattedDateString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toTimeString(): string { return $this->format('H:i:s'); }
Format the instance as time @return string
toTimeString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toDateTimeString(): string { return $this->format('Y-m-d H:i:s'); }
Format the instance as date and time @return string
toDateTimeString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toDayDateTimeString(): string { return $this->format('D, M j, Y g:i A'); }
Format the instance with day, date and time @return string
toDayDateTimeString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toAtomString(): string { return $this->format(DateTime::ATOM); }
Format the instance as ATOM @return string
toAtomString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toCookieString(): string { return $this->format(DateTime::COOKIE); }
Format the instance as COOKIE @return string
toCookieString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toIso8601String(): string { return $this->format(DateTime::ATOM); }
Format the instance as ISO8601 @return string
toIso8601String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc822String(): string { return $this->format(DateTime::RFC822); }
Format the instance as RFC822 @return string @link https://tools.ietf.org/html/rfc822
toRfc822String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc850String(): string { return $this->format(DateTime::RFC850); }
Format the instance as RFC850 @return string @link https://tools.ietf.org/html/rfc850
toRfc850String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc1036String(): string { return $this->format(DateTime::RFC1036); }
Format the instance as RFC1036 @return string @link https://tools.ietf.org/html/rfc1036
toRfc1036String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc1123String(): string { return $this->format(DateTime::RFC1123); }
Format the instance as RFC1123 @return string @link https://tools.ietf.org/html/rfc1123
toRfc1123String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc2822String(): string { return $this->format(DateTime::RFC2822); }
Format the instance as RFC2822 @return string @link https://tools.ietf.org/html/rfc2822
toRfc2822String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRfc3339String(): string { return $this->format(DateTime::RFC3339); }
Format the instance as RFC3339 @return string @link https://tools.ietf.org/html/rfc3339
toRfc3339String
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toRssString(): string { return $this->format(DateTime::RSS); }
Format the instance as RSS @return string
toRssString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toW3cString(): string { return $this->format(DateTime::W3C); }
Format the instance as W3C @return string
toW3cString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toUnixString(): string { return $this->format('U'); }
Returns a UNIX timestamp. @return string UNIX timestamp
toUnixString
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toQuarter(bool $range = false): int|array { $quarter = (int)ceil((int)$this->format('m') / 3); if ($range === false) { return $quarter; } $year = $this->format('Y'); switch ($quarter) { case 1: return [$year . '-01-01', $year . '-03-31']; case 2: return [$year . '-04-01', $year . '-06-30']; case 3: return [$year . '-07-01', $year . '-09-30']; default: return [$year . '-10-01', $year . '-12-31']; } }
Returns the quarter @param bool $range Range. @return array|int 1, 2, 3, or 4 quarter of year or array if $range true
toQuarter
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function toWeek(): int { return (int)$this->format('W'); }
Returns ISO 8601 week number of year, weeks starting on Monday @return int ISO 8601 week number of year
toWeek
php
cakephp/chronos
src/FormattingTrait.php
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
MIT
public function exists(string $key): bool { return isset(static::$strings[$key]); }
Check if a translation key exists. @param string $key The key to check. @return bool Whether the key exists.
exists
php
cakephp/chronos
src/Translator.php
https://github.com/cakephp/chronos/blob/master/src/Translator.php
MIT
public function plural(string $key, int $count, array $vars = []): string { if ($count === 1) { return $this->singular($key, $vars); } return $this->singular($key . '_plural', ['count' => $count] + $vars); }
Get a plural message. @param string $key The key to use. @param int $count The number of items in the translation. @param array $vars Additional context variables. @return string The translated message or ''.
plural
php
cakephp/chronos
src/Translator.php
https://github.com/cakephp/chronos/blob/master/src/Translator.php
MIT
public function singular(string $key, array $vars = []): string { if (isset(static::$strings[$key])) { $varKeys = array_keys($vars); foreach ($varKeys as $i => $k) { $varKeys[$i] = '{' . $k . '}'; } return str_replace($varKeys, $vars, static::$strings[$key]); } return ''; }
Get a singular message. @param string $key The key to use. @param array $vars Additional context variables. @return string The translated message or ''.
singular
php
cakephp/chronos
src/Translator.php
https://github.com/cakephp/chronos/blob/master/src/Translator.php
MIT
public function deprecated(Closure $callable): void { /** @var bool $deprecation Expand type for psalm */ $deprecation = false; $previousHandler = set_error_handler( function ($code, $message, $file, $line, $context = null) use (&$previousHandler, &$deprecation): bool { if ($code == E_USER_DEPRECATED) { $deprecation = true; return true; } if ($previousHandler) { return $previousHandler($code, $message, $file, $line, $context); } return false; }, ); try { $callable(); } finally { restore_error_handler(); } $this->assertTrue($deprecation, 'Should have at least one deprecation warning'); }
Helper method for check deprecation methods @param \Closure $callable callable function that will receive asserts @return void
deprecated
php
cakephp/chronos
tests/TestCase/TestCase.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/TestCase.php
MIT
public static function inputTimeProvider() { return [ ['@' . strtotime('2015-08-19 22:24:32')], ['2015-08-19 10:00:00'], ['2015-08-19T10:00:00+05:00'], ['Monday, 15-Aug-2005 15:52:01 UTC'], ['Mon, 15 Aug 05 15:52:01 +0000'], ['Monday, 15-Aug-05 15:52:01 UTC'], ['Mon, 15 Aug 05 15:52:01 +0000'], ['Mon, 15 Aug 2005 15:52:01 +0000'], ['Mon, 15 Aug 2005 15:52:01 +0000'], ['Mon, 15 Aug 2005 15:52:01 +0000'], ['2005-08-15T15:52:01+00:00'], ['20050815'], ]; }
Data provider for constructor testing. @return array
inputTimeProvider
php
cakephp/chronos
tests/TestCase/Date/ConstructTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/Date/ConstructTest.php
MIT
public function testConstructWithLargeTimezoneChange(): void { date_default_timezone_set('Pacific/Kiritimati'); $samoaTimezone = new DateTimeZone('Pacific/Samoa'); // Pacific/Samoa -11:00 is used intead of local timezone +14:00 $c = ChronosDate::today($samoaTimezone); $samoa = new DateTimeImmutable('now', $samoaTimezone); $this->assertSame($samoa->format('Y-m-d'), $c->format('Y-m-d')); }
This tests with a large difference between local timezone and timezone provided as parameter. This is to help guarantee a date change would occur so the tests are more consistent.
testConstructWithLargeTimezoneChange
php
cakephp/chronos
tests/TestCase/Date/ConstructTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/Date/ConstructTest.php
MIT
public function testAddYearPassingArg() { $this->assertSame(1977, Chronos::createFromDate(1975)->addYears(2)->year); }
** Test non plural methods with non default args ****
testAddYearPassingArg
php
cakephp/chronos
tests/TestCase/DateTime/AddTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/AddTest.php
MIT
public function testFromNow() { $date = Chronos::now(); $date = $date->modify('-1 year') ->modify('-6 days') ->modify('-51 seconds'); $interval = Chronos::fromNow($date); $result = $interval->format('%y %m %d %H %i %s'); $this->assertSame($result, '1 0 6 00 0 51'); }
Tests the "from now" time calculation.
testFromNow
php
cakephp/chronos
tests/TestCase/DateTime/DiffTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/DiffTest.php
MIT
public function testTimestamp() { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00'); $this->assertSame('0', $date->format('U')); }
Ensures that $date->format('U') returns unchanged timestamp
testTimestamp
php
cakephp/chronos
tests/TestCase/DateTime/PhpBug72338Test.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
MIT
public function testEqualSetAndCreate() { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00'); $date1 = new Chronos('1970-01-01T02:00:00+02:00'); $this->assertSame($date->format('U'), $date1->format('U')); }
Ensures that date created from string with timezone and with same timezone set by setTimezone() is equal
testEqualSetAndCreate
php
cakephp/chronos
tests/TestCase/DateTime/PhpBug72338Test.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
MIT
public function testSecondSetTimezone() { $date = Chronos::createFromTimestamp(0)->setTimezone('+02:00')->setTimezone('Europe/Moscow'); $this->assertSame('0', $date->format('U')); }
Ensures that second call to setTimezone() dont changing timestamp
testSecondSetTimezone
php
cakephp/chronos
tests/TestCase/DateTime/PhpBug72338Test.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
MIT
public static function toQuarterProvider() { return [ ['2007-12-25', 4], ['2007-9-25', 3], ['2007-3-25', 1], ['2007-3-25', ['2007-01-01', '2007-03-31'], true], ['2007-5-25', ['2007-04-01', '2007-06-30'], true], ['2007-8-25', ['2007-07-01', '2007-09-30'], true], ['2007-12-25', ['2007-10-01', '2007-12-31'], true], ]; }
Provides values and expectations for the toQuarter method @return array
toQuarterProvider
php
cakephp/chronos
tests/TestCase/DateTime/StringsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/StringsTest.php
MIT
public static function toWeekProvider() { return [ ['2007-1-1', 1], ['2007-3-25', 12], ['2007-12-29', 52], ['2007-12-31', 1], ]; }
Provides values and expectations for the toWeek method @return array
toWeekProvider
php
cakephp/chronos
tests/TestCase/DateTime/StringsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/StringsTest.php
MIT
public function testSubYearPassingArg() { $this->assertSame(1973, Chronos::createFromDate(1975)->subYears(2)->year); }
** Test non plural methods with non default args ****
testSubYearPassingArg
php
cakephp/chronos
tests/TestCase/DateTime/SubTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/SubTest.php
MIT
public function testNowNoMutateDateTime() { $value = '2018-06-21 10:11:12'; $notNow = new Chronos($value); Chronos::setTestNow($notNow); $instance = new Chronos('-10 minutes'); $this->assertSame('10:01:12', $instance->format('H:i:s')); $instance = new Chronos('-10 minutes'); $this->assertSame('10:01:12', $instance->format('H:i:s')); }
Ensure that using test now doesn't mutate test now.
testNowNoMutateDateTime
php
cakephp/chronos
tests/TestCase/DateTime/TestingAidsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
MIT
public function testNowNoMutateDate() { $value = '2018-06-21 10:11:12'; $notNow = new Chronos($value); Chronos::setTestNow($notNow); $instance = new ChronosDate('-1 day'); $this->assertSame('2018-06-20 00:00:00', $instance->format('Y-m-d H:i:s')); $instance = new ChronosDate('-1 day'); $this->assertSame('2018-06-20 00:00:00', $instance->format('Y-m-d H:i:s')); $instance = new ChronosDate('-23 hours'); $this->assertSame('2018-06-20 00:00:00', $instance->format('Y-m-d H:i:s')); }
Ensure that using test now doesn't mutate test now.
testNowNoMutateDate
php
cakephp/chronos
tests/TestCase/DateTime/TestingAidsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
MIT
public function testParseRelativeWithTimezoneAndTestValueSet() { $notNow = Chronos::parse('2013-07-01 12:00:00', 'America/New_York'); Chronos::setTestNow($notNow); $this->assertSame('06:30:00', Chronos::parse('2013-07-01 06:30:00', 'America/Mexico_City')->toTimeString()); $this->assertSame('06:30:00', Chronos::parse('6:30', 'America/Mexico_City')->toTimeString()); $this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('2013-07-01 06:30:00')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('2013-07-01 06:30:00', 'America/Mexico_City')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('06:30')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('6:30')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('6:30', 'America/Mexico_City')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('6:30:00', 'America/Mexico_City')->toIso8601String()); $this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('06:30:00', 'America/Mexico_City')->toIso8601String()); }
Test parse() with relative values and timezones
testParseRelativeWithTimezoneAndTestValueSet
php
cakephp/chronos
tests/TestCase/DateTime/TestingAidsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
MIT
public function testSetTestNowSingular() { $c = new Chronos('2016-01-03 00:00:00', 'Europe/Copenhagen'); Chronos::setTestNow($c); $this->assertSame($c, Chronos::getTestNow()); }
Test that setting testNow() on one class sets it on all of the chronos classes.
testSetTestNowSingular
php
cakephp/chronos
tests/TestCase/DateTime/TestingAidsTest.php
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
MIT
public function __construct($environment, $debug) { parent::__construct($environment, $debug); $this->setContext(self::CONTEXT_ADMIN); }
@param string $environment @param bool $debug
__construct
php
sulu/sulu-standard
app/AdminKernel.php
https://github.com/sulu/sulu-standard/blob/master/app/AdminKernel.php
MIT
public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false) { $this->fulfilled = (bool) $fulfilled; $this->testMessage = (string) $testMessage; $this->helpHtml = (string) $helpHtml; $this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText; $this->optional = (bool) $optional; }
Constructor that initializes the requirement. @param bool $fulfilled Whether the requirement is fulfilled @param string $testMessage The message for testing the requirement @param string $helpHtml The help text formatted in HTML for resolving the problem @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
__construct
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function isFulfilled() { return $this->fulfilled; }
Returns whether the requirement is fulfilled. @return bool true if fulfilled, otherwise false
isFulfilled
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getTestMessage() { return $this->testMessage; }
Returns the message for testing the requirement. @return string The test message
getTestMessage
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getHelpText() { return $this->helpText; }
Returns the help text for resolving the problem. @return string The help text
getHelpText
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getHelpHtml() { return $this->helpHtml; }
Returns the help text formatted in HTML. @return string The HTML help
getHelpHtml
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function isOptional() { return $this->optional; }
Returns whether this is only an optional recommendation and not a mandatory requirement. @return bool true if optional, false if mandatory
isOptional
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false) { $cfgValue = ini_get($cfgName); if (is_callable($evaluation)) { if (null === $testMessage || null === $helpHtml) { throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.'); } $fulfilled = call_user_func($evaluation, $cfgValue); } else { if (null === $testMessage) { $testMessage = sprintf('%s %s be %s in php.ini', $cfgName, $optional ? 'should' : 'must', $evaluation ? 'enabled' : 'disabled' ); } if (null === $helpHtml) { $helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.', $cfgName, $evaluation ? 'on' : 'off' ); } $fulfilled = $evaluation == $cfgValue; } parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional); }
Constructor that initializes the requirement. @param string $cfgName The configuration name used for ini_get() @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. Example: You require a config to be true but PHP later removes this config and defaults it to true internally. @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) @param string|null $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
__construct
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getIterator() { return new ArrayIterator($this->requirements); }
Gets the current RequirementCollection as an Iterator. @return Traversable A Traversable interface
getIterator
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function add(Requirement $requirement) { $this->requirements[] = $requirement; }
Adds a Requirement. @param Requirement $requirement A Requirement instance
add
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null) { $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false)); }
Adds a mandatory requirement. @param bool $fulfilled Whether the requirement is fulfilled @param string $testMessage The message for testing the requirement @param string $helpHtml The help text formatted in HTML for resolving the problem @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
addRequirement
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null) { $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true)); }
Adds an optional recommendation. @param bool $fulfilled Whether the recommendation is fulfilled @param string $testMessage The message for testing the recommendation @param string $helpHtml The help text formatted in HTML for resolving the problem @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
addRecommendation
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) { $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false)); }
Adds a mandatory requirement in form of a php.ini configuration. @param string $cfgName The configuration name used for ini_get() @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. Example: You require a config to be true but PHP later removes this config and defaults it to true internally. @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
addPhpIniRequirement
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) { $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true)); }
Adds an optional recommendation in form of a php.ini configuration. @param string $cfgName The configuration name used for ini_get() @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. Example: You require a config to be true but PHP later removes this config and defaults it to true internally. @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
addPhpIniRecommendation
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function addCollection(RequirementCollection $collection) { $this->requirements = array_merge($this->requirements, $collection->all()); }
Adds a requirement collection to the current set of requirements. @param RequirementCollection $collection A RequirementCollection instance
addCollection
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function all() { return $this->requirements; }
Returns both requirements and recommendations. @return Requirement[]
all
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getRequirements() { $array = array(); foreach ($this->requirements as $req) { if (!$req->isOptional()) { $array[] = $req; } } return $array; }
Returns all mandatory requirements. @return Requirement[]
getRequirements
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getFailedRequirements() { $array = array(); foreach ($this->requirements as $req) { if (!$req->isFulfilled() && !$req->isOptional()) { $array[] = $req; } } return $array; }
Returns the mandatory requirements that were not met. @return Requirement[]
getFailedRequirements
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getRecommendations() { $array = array(); foreach ($this->requirements as $req) { if ($req->isOptional()) { $array[] = $req; } } return $array; }
Returns all optional recommendations. @return Requirement[]
getRecommendations
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getFailedRecommendations() { $array = array(); foreach ($this->requirements as $req) { if (!$req->isFulfilled() && $req->isOptional()) { $array[] = $req; } } return $array; }
Returns the recommendations that were not met. @return Requirement[]
getFailedRecommendations
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function hasPhpIniConfigIssue() { foreach ($this->requirements as $req) { if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) { return true; } } return false; }
Returns whether a php.ini configuration is not correct. @return bool php.ini configuration problem?
hasPhpIniConfigIssue
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function getPhpIniConfigPath() { return get_cfg_var('cfg_file_path'); }
Returns the PHP configuration file (php.ini) path. @return string|false php.ini file path
getPhpIniConfigPath
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
protected function getRealpathCacheSize() { $size = ini_get('realpath_cache_size'); $size = trim($size); $unit = ''; if (!ctype_digit($size)) { $unit = strtolower(substr($size, -1, 1)); $size = (int) substr($size, 0, -1); } switch ($unit) { case 'g': return $size * 1024 * 1024 * 1024; case 'm': return $size * 1024 * 1024; case 'k': return $size * 1024; default: return (int) $size; } }
Loads realpath_cache_size from php.ini and converts it to int. (e.g. 16k is converted to 16384 int) @return int
getRealpathCacheSize
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
protected function getPhpRequiredVersion() { if (!file_exists($path = __DIR__.'/../composer.lock')) { return false; } $composerLock = json_decode(file_get_contents($path), true); foreach ($composerLock['packages'] as $package) { $name = $package['name']; if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) { continue; } return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION; } return false; }
Defines PHP required version from Symfony version. @return string|false The PHP required version or false if it could not be guessed
getPhpRequiredVersion
php
sulu/sulu-standard
app/SymfonyRequirements.php
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
MIT
public function __construct($environment, $debug) { parent::__construct($environment, $debug); $this->setContext(self::CONTEXT_WEBSITE); }
@param string $environment @param bool $debug
__construct
php
sulu/sulu-standard
app/WebsiteKernel.php
https://github.com/sulu/sulu-standard/blob/master/app/WebsiteKernel.php
MIT
protected function execute(InputInterface $input, OutputInterface $output): int { $loggerHelper = $this->getHelper('logger'); assert($loggerHelper instanceof LoggerHelper); $logger = $loggerHelper->create($output); $version = $input->getArgument('version'); assert(is_string($version)); $rawGenerationDate = $input->getOption('generation-date'); assert(is_string($rawGenerationDate)); $generationDate = new DateTimeImmutable($rawGenerationDate, new DateTimeZone('UTC')); $logger->info(sprintf('Build started (%s, generated %s).', $version, $generationDate->format(DATE_ATOM))); $buildFolder = $input->getOption('output'); assert(is_string($buildFolder)); $writerCollectionFactory = new FullCollectionFactory(); $writerCollection = $writerCollectionFactory->createCollection($logger, $buildFolder); $dataCollectionFactory = new DataCollectionFactory($logger); $resources = $input->getOption('resources'); assert(is_string($resources)); $buildGenerator = new BuildGenerator( $resources, $buildFolder, $logger, $writerCollection, $dataCollectionFactory, ); if ($input->getOption('coverage') !== false) { $buildGenerator->setCollectPatternIds(true); } $createZip = true; if ($input->getOption('no-zip') !== false) { $createZip = false; } $buildGenerator->run($version, $generationDate, $createZip); $logger->info('Build done.'); return self::SUCCESS; }
@return int null or 0 if everything went fine, or an error code @throws Exception @throws AssertionFailedException @throws \InvalidArgumentException
execute
php
browscap/browscap
src/Browscap/Command/BuildCommand.php
https://github.com/browscap/browscap/blob/master/src/Browscap/Command/BuildCommand.php
MIT