Jeedom Core

utils
in package

Utility functions for Jeedom core system

Provides helper methods for object conversion, JSON manipulation, encryption/decryption and asynchronous execution

Tags
see
config

For system configuration

see
cron

For async execution

Table of Contents

Properties

$jeedom_encryption  : string|null|false
$properties  : array<string, array<string|int, ReflectionProperty>>

Methods

a2o()  : void
Populates object properties from array data
attrChanged()  : bool
Checks if attributes have changed between old and new values
decrypt()  : false|string|null
Decrypts ciphertext using AES-256-CBC
encrypt()  : string|null
Encrypts plaintext using AES-256-CBC
executeAsync()  : void
This function allows asynchronous execution of any class function.
getEncryptionPassword()  : false|string|null
Gets encryption password from configuration
getJsonAttr()  : array<string|int, mixed>|bool|mixed|string
Gets JSON attribute value(s)
o2a()  : array<string|int, array<string, mixed>>|array<string, mixed>
Converts object(s) to array representation
processJsonObject()  : void
Processes JSON objects for class synchronization
setJsonAttr()  : array<string|int, mixed>|bool|mixed
Sets JSON attribute value(s)

Properties

$jeedom_encryption

private static string|null|false $jeedom_encryption = \null

Encryption key

$properties

private static array<string, array<string|int, ReflectionProperty>> $properties = array()

Cached reflection properties by class

Methods

a2o()

Populates object properties from array data

public static a2o(object &$_object, iterable<string, mixed> $_data) : void
Parameters
$_object : object

Object to populate

$_data : iterable<string, mixed>

Source data

attrChanged()

Checks if attributes have changed between old and new values

public static attrChanged(bool $_changed, array<string|int, mixed>|mixed $_old, array<string|int, mixed>|mixed $_new) : bool
Parameters
$_changed : bool

Current change status

$_old : array<string|int, mixed>|mixed

Previous value

$_new : array<string|int, mixed>|mixed

New value

Return values
bool

True if values are different

decrypt()

Decrypts ciphertext using AES-256-CBC

public static decrypt(string $ciphertext[, string|null $password = null ]) : false|string|null
Parameters
$ciphertext : string

Encrypted text

$password : string|null = null

Custom password (uses system key if null)

Tags
throws
Exception

On decryption failure

see
self::getEncryptionPassword()

For default key

Return values
false|string|null

Decrypted text

encrypt()

Encrypts plaintext using AES-256-CBC

public static encrypt(string $plaintext[, string|null $password = null ]) : string|null
Parameters
$plaintext : string

Text to encrypt

$password : string|null = null

Custom password (uses system key if null)

Tags
throws
Exception

On encryption failure

see
self::getEncryptionPassword()

For default key

Return values
string|null

Encrypted text prefixed with 'crypt:'

executeAsync()

This function allows asynchronous execution of any class function.

public static executeAsync(string $class, string $method[, array<string|int, mixed>|null $options = null ][, string $datetime = 'now' ]) : void

A cron will be created to execute it immediately (by default) or at the given datetime. To pass arguments to your function, you should pass an array of values in $options

Parameters
$class : string

A class name

$method : string

The method name

$options : array<string|int, mixed>|null = null

An array of options that will be passed to the cron

$datetime : string = 'now'

Any English textual datetime description that can be parsed by strtotime()

Tags
throws
InvalidArgumentException

if $class::$method does not exist

getEncryptionPassword()

Gets encryption password from configuration

public static getEncryptionPassword() : false|string|null
Tags
throws
Exception

If key file cannot be read

see
config::genKey()

For key generation

Return values
false|string|null

Encryption key

getJsonAttr()

Gets JSON attribute value(s)

public static getJsonAttr(mixed &$_attr[, array<string|int, string>|string $_key = '' ][, mixed $_default = '' ]) : array<string|int, mixed>|bool|mixed|string
Parameters
$_attr : mixed

Source attributes

$_key : array<string|int, string>|string = ''

Key(s) to retrieve

$_default : mixed = ''

Default value if not found

Return values
array<string|int, mixed>|bool|mixed|string

Attribute value(s)

o2a()

Converts object(s) to array representation

public static o2a(array<string|int, object>|object|mixed $_object[, bool $_noToArray = false ]) : array<string|int, array<string, mixed>>|array<string, mixed>
Parameters
$_object : array<string|int, object>|object|mixed

Object(s) to convert

$_noToArray : bool = false

Skip toArray() method if true

Tags
throws
ReflectionException
used-by
eqLogic::deadCmdGeneric()

Object-To-Array conversion

Return values
array<string|int, array<string, mixed>>|array<string, mixed>

Array representation

processJsonObject()

Processes JSON objects for class synchronization

public static processJsonObject(string $_class, array<string|int, array<string, mixed>>|string $_ajaxList[, array<string|int, mixed>|null $_dbList = null ][, bool $_remove = true ]) : void
Parameters
$_class : string

Target class name

$_ajaxList : array<string|int, array<string, mixed>>|string

New objects data

$_dbList : array<string|int, mixed>|null = null

Existing objects

$_remove : bool = true

Remove missing objects

Tags
throws
Exception

On invalid input

setJsonAttr()

Sets JSON attribute value(s)

public static setJsonAttr(array<string, mixed>|string|mixed $_attr, array<string, mixed>|string|int $_key[, mixed|null $_value = null ]) : array<string|int, mixed>|bool|mixed
Parameters
$_attr : array<string, mixed>|string|mixed

Current attributes

$_key : array<string, mixed>|string|int

Key to set or array of key/values

$_value : mixed|null = null

Value to set if key is string

Return values
array<string|int, mixed>|bool|mixed

Updated attributes


        
On this page

Search results