Documentation

CRM_Utils_AutoClean
in package

Class CRM_Utils_AutoClean

Automatically cleanup state when the object handle is released. This is useful for unordered cleanup when a function has many different exit scenarios (eg multiple returns, exceptions).

Table of Contents

Properties

$args  : mixed
$callback  : mixed
$isDone  : bool
Have we run this cleanup method yet?

Methods

__destruct()  : mixed
__sleep()  : mixed
Prohibit (de)serialization of CRM_Utils_AutoClean.
__wakeup()  : mixed
Prohibit (de)serialization of CRM_Utils_AutoClean.
cleanup()  : void
Explicitly apply the cleanup.
swap()  : CRM_Utils_AutoClean
Temporarily swap values using callback functions, and cleanup when the current context shuts down.
swapLocale()  : CRM_Utils_AutoClean|null
Temporarily set the active locale. Cleanup locale when the autoclean handle disappears.
swapSettings()  : CRM_Utils_AutoClean
Temporarily override the values for system settings.
with()  : CRM_Utils_AutoClean
Call a cleanup function when the current context shuts down.

Properties

$isDone

Have we run this cleanup method yet?

protected bool $isDone = \FALSE

Methods

__sleep()

Prohibit (de)serialization of CRM_Utils_AutoClean.

public __sleep() : mixed

The generic nature of AutoClean makes it a potential target for escalating serialization vulnerabilities, and there's no good reason for serializing it.

__wakeup()

Prohibit (de)serialization of CRM_Utils_AutoClean.

public __wakeup() : mixed

The generic nature of AutoClean makes it a potential target for escalating serialization vulnerabilities, and there's no good reason for deserializing it.

cleanup()

Explicitly apply the cleanup.

public cleanup() : void

Use this if you want to do the cleanup work immediately.

swap()

Temporarily swap values using callback functions, and cleanup when the current context shuts down.

public static swap(mixed $getter, mixed $setter, mixed $tmpValue) : CRM_Utils_AutoClean
function doStuff() {
  $ac = CRM_Utils_AutoClean::swap('My::get', 'My::set', 'tmpValue');
  ...
}
Parameters
$getter : mixed

Function to lookup current value.

$setter : mixed

Function to set new value.

$tmpValue : mixed

The value to temporarily use.

Tags
see
Resolver
Return values
CRM_Utils_AutoClean

swapLocale()

Temporarily set the active locale. Cleanup locale when the autoclean handle disappears.

public static swapLocale(string|null $newLocale) : CRM_Utils_AutoClean|null
Parameters
$newLocale : string|null

Ex: 'fr_CA'

Return values
CRM_Utils_AutoClean|null

swapSettings()

Temporarily override the values for system settings.

public static swapSettings(array<string|int, mixed> $newSettings) : CRM_Utils_AutoClean

Note: This was written for use with unit-tests. Give a hard think before using it at runtime.

Parameters
$newSettings : array<string|int, mixed>

List of new settings (key-value pairs).

Return values
CRM_Utils_AutoClean

with()

Call a cleanup function when the current context shuts down.

public static with(mixed $callback) : CRM_Utils_AutoClean
function doStuff() {
  $ac = CRM_Utils_AutoClean::with(function(){
    MyCleanup::doIt();
  });
  ...
}
Parameters
$callback : mixed
Return values
CRM_Utils_AutoClean

        
On this page

Search results