\LazyJsonMapperUtilities

Collection of shared utility functions for the library.

Summary

Methods
Properties
Constants
createStrictClassPath()
splitStrictClassPath()
createRelativeClassPath()
atomicWrite()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

createStrictClassPath()

createStrictClassPath(string  $className = '') : string|null

Create a strict, global class path.

This helper ensures that the input is a non-empty string, and then automatically prepends a leading \ if missing, so that PHP understands that the class search MUST happen only in the global namespace.

Parameters

string $className

The class name to convert.

Returns

string|null —

String if non-empty string input, otherwise NULL.

splitStrictClassPath()

splitStrictClassPath(string  $strictClassPath = '') : array

Splits a strict class-path into its namespace and class name components.

To rejoin them later, just use: 'namespace' + '\\' + 'class'.

The class path should be in get_class() aka TheClass::class format.

Parameters

string $strictClassPath

Class output of createStrictClassPath().

Returns

array —

Associative array with keys for namespace and class.

createRelativeClassPath()

createRelativeClassPath(array  $sourceComponents, array  $targetComponents) : string

Compare two class paths and generate the shortest path between them.

Parameters

array $sourceComponents

Source class as splitStrictClassPath().

array $targetComponents

Target class as splitStrictClassPath().

Returns

string —

The final path to reach from the source to the target.

atomicWrite()

atomicWrite(string  $filename, string  $data, string  $atomicSuffix = 'atomictmp') : integer|boolean

Atomic filewriter.

Safely writes new contents to a file using an atomic two-step process. If the script is killed before the write is complete, only the temporary trash file will be corrupted.

The algorithm also ensures that 100% of the bytes were written to disk.

Parameters

string $filename

Filename to write the data to.

string $data

Data to write to file.

string $atomicSuffix

Lets you optionally provide a different suffix for the temporary file.

Returns

integer|boolean —

Number of bytes written on success, otherwise FALSE.