idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
400
|
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 .
|
401
|
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 .
|
402
|
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 .
|
403
|
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 .
|
404
|
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 .
|
405
|
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 .
|
406
|
protected static function intervalHasTime ( DateInterval $ interval ) { 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 .
|
407
|
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 .
|
408
|
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 .
|
409
|
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 .
|
410
|
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 .
|
411
|
public function setDates ( $ start , $ end ) { $ this -> setStartDate ( $ start ) ; $ this -> setEndDate ( $ end ) ; return $ this ; }
|
Set start and end date .
|
412
|
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 .
|
413
|
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 .
|
414
|
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 .
|
415
|
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 .
|
416
|
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 .
|
417
|
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 .
|
418
|
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 .
|
419
|
public function setFilters ( array $ filters ) { $ this -> filters = $ filters ; $ this -> updateInternalState ( ) ; $ this -> handleChangedParameters ( ) ; return $ this ; }
|
Set filters stack .
|
420
|
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 .
|
421
|
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 .
|
422
|
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 .
|
423
|
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 .
|
424
|
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 .
|
425
|
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 .
|
426
|
protected function validateCurrentDate ( ) { if ( $ this -> current === null ) { $ this -> rewind ( ) ; } if ( $ this -> validationResult !== null ) { return $ this -> validationResult ; } return $ this -> validationResult = $ this -> checkFilters ( ) ; }
|
Validate current date and stop iteration when necessary .
|
427
|
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 .
|
428
|
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 .
|
429
|
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 .
|
430
|
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 .
|
431
|
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 .
|
432
|
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 .
|
433
|
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 .
|
434
|
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 .
|
435
|
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 .
|
436
|
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 .
|
437
|
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 .
|
438
|
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 ) ; } $ interval = static :: createFromDateString ( $ var ) ; return $ interval -> isEmpty ( ) ? null : $ interval ; }
|
Make a CarbonInterval instance from given variable if possible .
|
439
|
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 .
|
440
|
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 .
|
441
|
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 .
|
442
|
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
|
443
|
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 .
|
444
|
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 .
|
445
|
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 .
|
446
|
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 .
|
447
|
public function getRegionName ( ) : ? string { return $ this -> region ? ( static :: regions ( ) [ $ this -> region ] ?? $ this -> region ) : null ; }
|
Returns the region name for the current language .
|
448
|
public function getFullIsoName ( ) : string { if ( ! $ this -> isoName ) { $ this -> isoName = $ this -> getNames ( ) [ 'isoName' ] ; } return $ this -> isoName ; }
|
Returns the long ISO language name .
|
449
|
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 .
|
450
|
public function getIsoName ( ) : string { $ name = $ this -> getFullIsoName ( ) ; return trim ( strstr ( $ name , ',' , true ) ? : $ name ) ; }
|
Returns the short ISO language name .
|
451
|
public function getNativeName ( ) : string { $ name = $ this -> getFullNativeName ( ) ; return trim ( strstr ( $ name , ',' , true ) ? : $ name ) ; }
|
Get the short name of the language in this language .
|
452
|
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 .
|
453
|
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 .
|
454
|
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 .
|
455
|
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 .
|
456
|
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 .
|
457
|
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 .
|
458
|
protected function loadMessagesFromFile ( $ locale ) { if ( isset ( $ this -> messages [ $ locale ] ) ) { return true ; } return $ this -> resetMessages ( $ locale ) ; }
|
Init messages language from matching file in Lang directory .
|
459
|
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 .
|
460
|
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 .
|
461
|
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 .
|
462
|
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 .
|
463
|
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
|
464
|
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
|
465
|
public function diffInWeekdays ( $ date = null , $ absolute = true ) { return $ this -> diffInDaysFiltered ( function ( CarbonInterface $ date ) { return $ date -> isWeekday ( ) ; } , $ date , $ absolute ) ; }
|
Get the difference in weekdays
|
466
|
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
|
467
|
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 .
|
468
|
public function diffInRealMinutes ( $ date = null , $ absolute = true ) { return ( int ) ( $ this -> diffInRealSeconds ( $ date , $ absolute ) / static :: SECONDS_PER_MINUTE ) ; }
|
Get the difference in minutes using timestamps .
|
469
|
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 .
|
470
|
public function diffInMilliseconds ( $ date = null , $ absolute = true ) { return ( int ) ( $ this -> diffInMicroseconds ( $ date , $ absolute ) / static :: MICROSECONDS_PER_MILLISECOND ) ; }
|
Get the difference in milliseconds .
|
471
|
public function diffInRealSeconds ( $ date = null , $ absolute = true ) { $ date = $ this -> resolveCarbon ( $ date ) ; $ value = $ date -> getTimestamp ( ) - $ this -> getTimestamp ( ) ; return $ absolute ? abs ( $ value ) : $ value ; }
|
Get the difference in seconds using timestamps .
|
472
|
public function diffInRealMicroseconds ( $ date = null , $ absolute = true ) { $ 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 .
|
473
|
public function diffInRealMilliseconds ( $ date = null , $ absolute = true ) { return ( int ) ( $ this -> diffInRealMicroseconds ( $ date , $ absolute ) / static :: MICROSECONDS_PER_MILLISECOND ) ; }
|
Get the difference in milliseconds using timestamps .
|
474
|
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
|
475
|
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 .
|
476
|
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 .
|
477
|
public function subUnit ( $ unit , $ value = 1 , $ overflow = null ) { return $ this -> addUnit ( $ unit , - $ value , $ overflow ) ; }
|
Subtract given units to the current instance .
|
478
|
public function roundUnit ( $ unit , $ precision = 1 , $ function = 'round' ) { $ metaUnits = [ 'millennium' => [ static :: YEARS_PER_MILLENNIUM , 'year' ] , 'century' => [ static :: YEARS_PER_CENTURY , 'year' ] , 'decade' => [ static :: YEARS_PER_DECADE , 'year' ] , 'quarter' => [ static :: MONTHS_PER_QUARTER , 'month' ] , 'millisecond' => [ 1000 , 'microsecond' ] , ] ; $ normalizedUnit = static :: singularUnit ( $ unit ) ; $ ranges = array_merge ( static :: getRangesByUnit ( ) , [ '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 ) ) ; while ( $ changes [ $ unit ] >= $ delta ) { $ changes [ $ unit ] -= $ delta ; } $ fraction -= floor ( $ fraction ) ; } } [ $ value , $ minimum ] = $ arguments ; $ 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 .
|
479
|
public function roundWeek ( $ weekStartsAt = null ) { return $ this -> closest ( $ this -> copy ( ) -> floorWeek ( $ weekStartsAt ) , $ this -> copy ( ) -> ceilWeek ( $ weekStartsAt ) ) ; }
|
Round the current instance week .
|
480
|
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 .
|
481
|
public function isSameUnit ( $ unit , $ date = null ) { $ units = [ 'year' => 'Y' , 'week' => 'o-W' , 'day' => 'Y-m-d' , 'hour' => 'Y-m-d H' , 'minute' => 'Y-m-d H:i' , 'second' => 'Y-m-d H:i:s' , 'micro' => 'Y-m-d H:i:s.u' , '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 .
|
482
|
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 .
|
483
|
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 .
|
484
|
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 .
|
485
|
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 .
|
486
|
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 .
|
487
|
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 .
|
488
|
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 .
|
489
|
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 .
|
490
|
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 .
|
491
|
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 .
|
492
|
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 .
|
493
|
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' ; } $ pipeline = new $ class ( $ this ) ; if ( isset ( $ callable ) ) { return $ pipeline -> execute ( $ callable ) ; } return $ pipeline ; }
|
Actual pipeline context initializer method .
|
494
|
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 .
|
495
|
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 .
|
496
|
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 .
|
497
|
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 .
|
498
|
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 .
|
499
|
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 .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.