\LazyJsonMapper\PropertyPropertyDefinition

Describes the behavior of a LazyJsonMapper property.

NOTE: The class validates all parameters, but provides public properties to avoid needless function calls. It's therefore your responsibility to never assign any bad values to the public properties after this object's creation!

Summary

Methods
Properties
Constants
__construct()
getStrictClassPath()
equals()
asString()
__toString()
$arrayDepth
$propType
$isObjectType
BASIC_TYPES
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

BASIC_TYPES

BASIC_TYPES

List of valid basic PHP types.

NOTE: We don't include array, object or null. Because we handle arrays separately (via $arrayDepth), and objects via $isObjectType, and we never want to explicitly cast anything to NULL. We also avoid PHP's alternative names for some types, favoring their shortest names.

Properties

$arrayDepth

$arrayDepth : integer

Array-depth until we reach the typed values.

Examples:

  • 0 = Property directly refers to an instance of "type".
  • 1 = Property is an array of ["type","type"].
  • 2 = Property is an array of arrays of [["type","type"],["type"]].
  • and so on...

Type

integer

$propType

$propType : string|null

Assigned value-type for the property.

In case of basic PHP types, it is a string value such as int.

It uses NULL to represent mixed or "" (mixed shorthand) to make it easy & fast to check for untyped properties via a === null comparison.

In case of classes, this is the normalized NameSpace\Class path, but WITHOUT any initial leading \ ("look from the global namespace") backslash. That's PHP's preferred notation for class paths in all of its various "get name" functions. However, that's very unsafe for actual object creation, since PHP would first try resolving to a relative object. Therefore, use getStrictClassPath() for actual creation and for all strict comparisons where any kind of namespace resolution will be involved, in functions such as is_a() or is_subclass_of(), etc!

Type

string|null

$isObjectType

$isObjectType : boolean

Whether the type is a class object or a built-in type.

Tip: If this value is TRUE then you can always trust $propType to be a string representing the normalized NameSpace\Class path to the target class.

Type

boolean

Methods

__construct()

__construct(string|null  $definitionStr = null, string|null  $baseNamespace = '') 

Constructor.

Parameters

string|null $definitionStr

A PHPdoc-style string describing the property, or NULL to create a default "untyped" property. Note that if the type is set to the exact keyword LazyJsonMapper, we will select the core class path without you needing to write the full, global \LazyJsonMapper\LazyJsonMapper path yourself. This shortcut also works with "array of" LazyJsonMapper[][] syntax.

string|null $baseNamespace

Namespace to use for resolving relative class paths. It CANNOT start or end with a backslash. (Use __NAMESPACE__ format). If no namespace is provided, all classes are assumed to be relative to the global namespace (\).

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException

If the provided definition is invalid.

getStrictClassPath()

getStrictClassPath() : string|null

Get the strict, global path to the target class.

Always use this function when creating objects or in any other way using the "property type" class path as argument for PHP's class checking functions. The strict path that it provides ensures that PHP will find the global path instead of resolving to a local object.

Returns

string|null —

Strict path if this is an object, otherwise NULL.

equals()

equals(\LazyJsonMapper\Property\PropertyDefinition  $otherObject) : boolean

Check if all values of this property match another property object.

Parameters

\LazyJsonMapper\Property\PropertyDefinition $otherObject

The object to compare with.

Returns

boolean —

TRUE if all property values are identical, otherwise FALSE.

asString()

asString() : string

Get the property definition as its string representation.

The string perfectly represents the property definition, and can therefore even be used when constructing other object instances.

Returns

string

__toString()

__toString() : string

Get the property definition as its string representation.

Returns

string