spunQ_UserType Class Reference

A user-defined type, whether defined locally or imported. More...

Inheritance diagram for spunQ_UserType:

spunQ_Type spunQ_DataObject spunQ_LocalUserType

List of all members.

Public Member Functions

 __construct ($parent, $name, $documentation, $options, $className)
 Construct.
 getParent ()
 Gets its parent type.
 getOwnMembers ()
 Gets the members of this type, mapped by the member name.
 getAllMembers ()
 Gets the members of this type, mapped by the member name.
 getInjectedMembers ()
 getInjectedMembersRecursive ()
 getClassName ()
 The name of the class associated with this type.
 createInstance ()
 Creates an instance of this type using getClassName().
 inheritsFrom (spunQ_UserType $type)
 Checks if a given type is an ancestor of this one.
 check ($value, spunQ_Map $options=NULL, $throwException=true)
 Overridden to check implementation for user types.
 memberExists ($name)
 Whether a member with a given name exists in this types members.
 getReferencingMembers ()
 Returns all members in any user type referencing this one.
 getMember ($name, $throwException=true)
 Returns the member with the given name out of getOwnMembersRecursive().
 getOwnMembersRecursive ()
 Gets all members of this type, mapped by the member name.
 getName ()
 Gets the name of this type.
 getDocumentation ()
 Gets the documentation for this type.
 getOptions ()
 Gets the type options for this type.
 __call ($functionName, $arguments)
 Overloaded to provide automatic getters and setters.
 __sleep ()
 Replaces $_type with the type's name.
 _verifyMembers ($omittedMembers=array(), $throwException=true)
 Verifies that all members are valid.
 _getMember ($name)
 Gets the value of a member of this object.
 _setMember ($name, $value)
 Sets the value of a member of this object.
 _getType ($throwException=true)
 Gets the type of this object.

Static Public Member Functions

static stringDescribesUserType ($string)
 Whether a type description specifies a user type.
static getByClass ($className, $throwException=true)
 Gets the user type that is associated with a class name.
static getByName ($name, $throwException=true)
 Gets the type with a given name.
static typeExists ($name)
 Checks if a type with given name exists.
static getAll ()
 Gets all type definitions, mapped by their name.
static getCommonParent (array $types)
 Gets the common parent of all given type objects.
static getCommonType (array $objects)
 Provides the common type of given objects.
static getCommonClass (array $objects)
 Provides the common parent class of given objects.
static getAllTypesDerivingFrom ($type)
 Returns an array of known types that inherit a given one.
static getAssociatedTypes ($type, $types=NULL)
 Collects all types required to describe this type.
static _init ()
 Parses type information out of the defined source files.
static initializeDevelopmentMode ()
static generateInitialState ($files, $toInclude, $youngestFilesTimestamp)
static loadInitialState ($cache)
 Will initialize the framework using cached data.
static stringDescribesType ($string)
 Checks whether a string is a valid type descriptor.
static getByName ($string)
 Will return a Type object with given description.
static getDescription ($value)
 Returns the most appropriate textual representation of a value.
static getCommonDescription (array $values)
 Finds the most suiting string description for multiple values.
static valueByProperty ($value, $path)
 Transforms a value using a property path.
static propertyOfValue ($value, $property)
 Gets a single property of a value.

Protected Member Functions

 handleGetUntranslated ($memberName, $arguments, $functionName)
 Needed by __call().
 handleGet ($memberName, $arguments, $functionName)
 Needed by __call().
 initLocalizedMember ($memberName)
 Makes sure a localized member contains a spunQ_Map.
 handleGetFromArray ($memberName, $arguments, $functionName)
 Needed by __call().
 handleSet ($memberName, $arguments, $functionName)
 Needed by __call().
 handleAdd ($memberName, $arguments, $functionName)
 Needed by __call().
 handleRemove ($memberName, $arguments, $functionName)
 Needed by __call().

Protected Attributes

 $parent
 Its parent type.
 $ownMembers = array()
 Members of this type, mapped by the member name.
 $className
 The name of the class associated with this type.
 $ownMembersRecursive
 Cache for getOwnMembersRecursive().
 $injectedMembers = array()
 Members that have been injected by other modules.
 $injectedMembersRecursive = NULL
 $name
 The name of this type.
 $documentation
 Documentation of this type as extracted from its doc comments.
 $options
 Additional options for this member.
 $_type
 The actual type of this object.

Static Protected Attributes

static $classToType = array()
 List of all types, mapped by the associated class.
static $nameToType = array()
 List of all types, mapped by their name.
static $typeInstance = NULL
 The one instance of this class that will describe all other instances.

Static Private Member Functions

static includeFiles (&$youngestFilesTimestamp, &$toInclude)
 Assembles a list of files that need to be included.
static initTypesWithoutCache ($typeNameToFile)
 Initializes types using source files.
static parseFiles (&$typeNameToFile, &$processedFiles)
 Creates type definitions for multiple files.

Private Attributes

 $allMembers
 Cache for getAllMembers().


Detailed Description

A user-defined type, whether defined locally or imported.

Definition at line 7 of file UserType.type.php.


Constructor & Destructor Documentation

spunQ_UserType::__construct ( parent,
name,
documentation,
options,
className 
)

Construct.

Parameters:
$parent Its parent type.
$name Name of this type.
$documentation Plain-text documentation.
$options See class doc
$className The name of the class that need to be instanctiated to create an instance of this type.
Returns:
spunQ_LocalUserType

Definition at line 232 of file UserType.type.php.


Member Function Documentation

spunQ_DataObject::__call ( functionName,
arguments 
) [inherited]

Overloaded to provide automatic getters and setters.

Parameters:
$functionName The function that was called.
$arguments Array containing the arguments that were passed to the function.
Exceptions:
spunQ_BadArgumentCountError 

Definition at line 148 of file DataObject.type.php.

spunQ_DataObject::__sleep (  )  [inherited]

Replaces $_type with the type's name.

Returns:
array<string>

Reimplemented in spunQ_ArrayType, spunQ_MapType, and spunQ_SetType.

Definition at line 178 of file DataObject.type.php.

spunQ_DataObject::_getMember ( name  )  [inherited]

Gets the value of a member of this object.

Will check if the object has a getter for the member and will use that method for getting the value. Otherwise, the value of the object member is returned.

Parameters:
$name The name of the member.
Returns:
any Whatever type the member has.

Definition at line 478 of file DataObject.type.php.

spunQ_DataObject::_getType ( throwException = true  )  [inherited]

Gets the type of this object.

Returns:
spunQ_Type

Definition at line 507 of file DataObject.type.php.

static spunQ_UserType::_init (  )  [static]

Parses type information out of the defined source files.

Returns:
void

Definition at line 466 of file UserType.type.php.

spunQ_DataObject::_setMember ( name,
value 
) [inherited]

Sets the value of a member of this object.

Will check if the object has a setter for the member and will use that method for setting the value. Otherwise, the object member is set directly.

Parameters:
$name The name of the member.
$value The value to set it to.
Returns:
spunQ_DataObject $this

Definition at line 495 of file DataObject.type.php.

spunQ_DataObject::_verifyMembers ( omittedMembers = array(),
throwException = true 
) [inherited]

Verifies that all members are valid.

This function is called from various modules prior to critical actions requiring a complete object - like inserting into a database.

Parameters:
$omittedMembers Do not perform checks on these member names.
$throwException Whether an exception should be thrown if a member does not have a valid value.
Returns:
boolean
Exceptions:
spunQ_IllegalValueException 

Definition at line 458 of file DataObject.type.php.

spunQ_UserType::createInstance (  ) 

Creates an instance of this type using getClassName().

Returns:
spunQ_DataObject

Definition at line 305 of file UserType.type.php.

static spunQ_UserType::getAll (  )  [static]

Gets all type definitions, mapped by their name.

Returns:
array Mapping type names to type objects.

Definition at line 73 of file UserType.type.php.

spunQ_UserType::getAllMembers (  ) 

Gets the members of this type, mapped by the member name.

The naming was chosen to reduce confusion with the pool of the members of this type and its parent type's.

Returns:
map<string,spunQ.Type> Mapping of type names to type objects.

Definition at line 271 of file UserType.type.php.

static spunQ_UserType::getAllTypesDerivingFrom ( type  )  [static]

Returns an array of known types that inherit a given one.

Parameters:
$type The type to collect children for.
Returns:
array<spunQ_UserType>

Definition at line 146 of file UserType.type.php.

static spunQ_UserType::getAssociatedTypes ( type,
types = NULL 
) [static]

Collects all types required to describe this type.

Will put its parent type, its member's types and its parent's member's types recursively into a mapping of type name to type object. This ensures that an object of this type can be described with given type. Useful for exporting data into database/peers/etc.

Parameters:
$type The type to gather associated types for.
$types Out-parameter, which contains the return value. It will be initialized with an empty map if omitted. This allows one to call this function multiple times, collecting associated types for multiple types.
Returns:
map<string,spunQ.Type> Mapping of type names to type objects. Same as the out-parameter $types. This redundance gives a bit more flexibility on the function call. The caller can either completely ignore the parameter $types and store the result, or work with the parameter only.

Definition at line 383 of file UserType.type.php.

static spunQ_UserType::getByClass ( className,
throwException = true 
) [static]

Gets the user type that is associated with a class name.

Parameters:
$className The name of the class to get type for.
$throwException Whether the function shall throw an exception if the requested type is not found. NULL will be returned if this is false and the type is not found.
Returns:
spunQ_UserType Or NULL if no type for the given class was registered.
Exceptions:
spunQ_TypeNotFoundException 

Definition at line 29 of file UserType.type.php.

static spunQ_Type::getByName ( string  )  [static, inherited]

Will return a Type object with given description.

Parameters:
$string The string description fo the type.
Returns:
spunQ_Type

Reimplemented in spunQ_ArrayType, spunQ_MapType, spunQ_SetType, and spunQ_BuiltinType.

Definition at line 313 of file Type.type.php.

static spunQ_UserType::getByName ( name,
throwException = true 
) [static]

Gets the type with a given name.

Parameters:
$name The name of the type to retrieve
$throwException Whether the function shall throw an exception if the requested type is not found. NULL will be returned if this is false and the type is not found.
Returns:
spunQ_UserType Or NULL if no type with given name was registered.

Definition at line 49 of file UserType.type.php.

spunQ_UserType::getClassName (  ) 

The name of the class associated with this type.

Returns:
string

Definition at line 297 of file UserType.type.php.

static spunQ_UserType::getCommonClass ( array $  objects  )  [static]

Provides the common parent class of given objects.

Parameters:
$objects Array of objects.
Returns:
string Name of the class

Definition at line 119 of file UserType.type.php.

static spunQ_Type::getCommonDescription ( array $  values  )  [static, inherited]

Finds the most suiting string description for multiple values.

Parameters:
$values The values to find string description for.
Returns:
string

Definition at line 373 of file Type.type.php.

static spunQ_UserType::getCommonParent ( array $  types  )  [static]

Gets the common parent of all given type objects.

Parameters:
$types array of spunQ_UserType objects
Returns:
spunQ_UserType
Exceptions:
spunQ_InvalidArgumentError If $types is empty

Definition at line 83 of file UserType.type.php.

static spunQ_UserType::getCommonType ( array $  objects  )  [static]

Provides the common type of given objects.

Parameters:
$objects Array of spunQ_DataObjects.
Returns:
spunQ_UserType

Definition at line 105 of file UserType.type.php.

static spunQ_Type::getDescription ( value  )  [static, inherited]

Returns the most appropriate textual representation of a value.

Can be used to provide useful information about a value when debugging:

  • spunQ.DataObjects will be translated using their type names.
  • spunQ.Type will be translated using their names.
  • Normal objects will be translated to their class names.
  • arrays and maps will have their parameter types found recursively, substituting 'any' for undefined types (map<string,any>).
  • any other type is translated using gettype()
Parameters:
$value The value to describe as a string.
Returns:
string

Definition at line 343 of file Type.type.php.

spunQ_Type::getDocumentation (  )  [inherited]

Gets the documentation for this type.

Returns:
string

Definition at line 458 of file Type.type.php.

spunQ_UserType::getMember ( name,
throwException = true 
)

Returns the member with the given name out of getOwnMembersRecursive().

Parameters:
$name The name of the member to retrieve.
$throwException Whether the function shall throw an exception if no member with given name esists.
Returns:
spunQ_Member Or NULL if $throwException is false and the member with given name doesn't exist.
Exceptions:
spunQ_UndefinedMemberError 

Definition at line 425 of file UserType.type.php.

spunQ_Type::getName (  )  [inherited]

Gets the name of this type.

Returns:
string

Reimplemented in spunQ_ArrayType, spunQ_MapType, and spunQ_SetType.

Definition at line 450 of file Type.type.php.

spunQ_Type::getOptions (  )  [inherited]

Gets the type options for this type.

Returns:
map<string,array<string>>

Definition at line 466 of file Type.type.php.

spunQ_UserType::getOwnMembers (  ) 

Gets the members of this type, mapped by the member name.

The naming was chosen to reduce confusion with the pool of the members of this type and its parent type's.

Returns:
map<string,spunQ.Type> Mapping of type names to type objects.

Definition at line 260 of file UserType.type.php.

spunQ_UserType::getOwnMembersRecursive (  ) 

Gets all members of this type, mapped by the member name.

In contrast to getOwnMembers(), this function will return its own, as well as its parent's members recursively.

Returns:
map<string,spunQ.Type> Mapping of type names to type objects.

Definition at line 443 of file UserType.type.php.

spunQ_UserType::getParent (  ) 

Gets its parent type.

Returns:
spunQ.UserType

Definition at line 249 of file UserType.type.php.

spunQ_UserType::getReferencingMembers (  ) 

Returns all members in any user type referencing this one.

Returns:
array<spunQ_Member>

Definition at line 354 of file UserType.type.php.

spunQ_DataObject::handleAdd ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of function calls starting with 'add'.

Parameters:
$memberName The name of the member that is possibly being appended to. Merely the name of the function without the leading 'add', with a lower-case first letter.
$arguments Array containing the arguments that were passed to the function.
$functionName The function that was called.
Returns:
spunQ_DataObject $this
Exceptions:
spunQ_BadArgumentCountError 
spunQ_InvalidArgumentError 

Reimplemented in spunQ_StorableObject.

Definition at line 327 of file DataObject.type.php.

spunQ_DataObject::handleGet ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of function calls starting with 'get'.

Todo:
spunQ_CollectionType instead of spunQ_ArrayType(?)
Parameters:
$memberName The name of the member that was possibly requested. Merely the name of the function without the leading 'get', with a lower-case first letter.
$arguments Array containing the arguments that were passed to the function.
$functionName The name of the function that was called.
Returns:
any Whatever type the member has.

Reimplemented in spunQ_StorableObject.

Definition at line 217 of file DataObject.type.php.

spunQ_DataObject::handleGetFromArray ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of getter functions, where the member has an array type.

See also:
handleGet()
Parameters:
$memberName The name of the member that was possibly requested. Merely the name of the function without the leading 'set', with a lower-case first letter.
$arguments Array containing the arguments that were passed to the function.
$functionName The function that was called.
Returns:
array

Reimplemented in spunQ_StorableObject.

Definition at line 264 of file DataObject.type.php.

spunQ_DataObject::handleGetUntranslated ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of functions requesting all translations available for a member.

Parameters:
$memberName The name of the member that was possibly requested.
$arguments Array containing the arguments that were passed to the function.
$functionName The name of the function that was called.
Returns:
map<spunQ_Locale,any> Mapping locales to whatever type the member has. Note that not every locale needs to be present in this map.

Reimplemented in spunQ_StorableObject.

Definition at line 198 of file DataObject.type.php.

spunQ_DataObject::handleRemove ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of function calls starting with 'remove'.

Parameters:
$memberName The name of the member that is possibly being removed from. Merely the name of the function without the leading 'remove', with a lower-case first letter.
$arguments Array containing the arguments that were passed to the function.
$functionName The function that was called.
Returns:
spunQ_DataObject $this
Exceptions:
spunQ_BadArgumentCountError 
spunQ_InvalidArgumentError 

Reimplemented in spunQ_StorableObject.

Definition at line 399 of file DataObject.type.php.

spunQ_DataObject::handleSet ( memberName,
arguments,
functionName 
) [protected, inherited]

Needed by __call().

Will take care of function calls starting with 'set'.

Parameters:
$memberName The name of the member that is possibly being set. Merely the name of the function without the leading 'set', with a lower-case first letter.
$arguments Array containing the arguments that were passed to the function.
$functionName The function that was called.
Returns:
spunQ_DataObject $this

Reimplemented in spunQ_StorableObject.

Definition at line 292 of file DataObject.type.php.

static spunQ_UserType::includeFiles ( &$  youngestFilesTimestamp,
&$  toInclude 
) [static, private]

Assembles a list of files that need to be included.

Parameters:
$youngestFilesTimestamp This out parameter will contain the last modification timestamp of the most recently modified file.
$toInclude Out-parameter containing the files that need to be passed to spunQ::requireAll().
Returns:
map<string,string> Mapping of type names to file paths.

Definition at line 545 of file UserType.type.php.

spunQ_UserType::inheritsFrom ( spunQ_UserType type  ) 

Checks if a given type is an ancestor of this one.

Parameters:
$type The type to check for inheritance.
Returns:
bool

Definition at line 315 of file UserType.type.php.

spunQ_DataObject::initLocalizedMember ( memberName  )  [protected, inherited]

Makes sure a localized member contains a spunQ_Map.

Parameters:
$memberName The name of the member. This member must have the option 'localized'.
Returns:
void

Definition at line 245 of file DataObject.type.php.

static spunQ_UserType::initTypesWithoutCache ( typeNameToFile  )  [static, private]

Initializes types using source files.

Parameters:
$typeNameToFile Mapping of type names to file paths. Return value of includeFiles().
Returns:
void

Definition at line 560 of file UserType.type.php.

static spunQ_UserType::loadInitialState ( cache  )  [static]

Will initialize the framework using cached data.

Parameters:
$cache A cache array, which consists of the following entries:
Returns:
void

Definition at line 521 of file UserType.type.php.

spunQ_UserType::memberExists ( name  ) 

Whether a member with a given name exists in this types members.

Parameters:
$name The name of the member to check.
Returns:
bool

Definition at line 346 of file UserType.type.php.

static spunQ_UserType::parseFiles ( &$  typeNameToFile,
&$  processedFiles 
) [static, private]

Creates type definitions for multiple files.

This function does not deal with dependencies of the types. Any type, whose parent type has not been defined yet, will stay in the out-parameter $typeNameToFile. All others will be appended to $processedFiles.

Parameters:
$typeNameToFile Mapping of type names to file paths. Return value of includeFiles(). This is an out-parameter, entries that have been processed will be removed from this array.
$processedFiles Out-parameter containing mapping of file paths to type objects.
Returns:
void

Definition at line 591 of file UserType.type.php.

static spunQ_DataObject::propertyOfValue ( value,
property 
) [static, inherited]

Gets a single property of a value.

See also:
valueByProperty()
Parameters:
$value The value to fetch property for.
$property The property to fetch.
Returns:
any

Definition at line 74 of file DataObject.type.php.

static spunQ_Type::stringDescribesType ( string  )  [static, inherited]

Checks whether a string is a valid type descriptor.

Parameters:
$string The string to check
Returns:
boolean

Definition at line 298 of file Type.type.php.

static spunQ_UserType::stringDescribesUserType ( string  )  [static]

Whether a type description specifies a user type.

Parameters:
$string The string to check.
Returns:
bool

Definition at line 14 of file UserType.type.php.

static spunQ_UserType::typeExists ( name  )  [static]

Checks if a type with given name exists.

Parameters:
$name the name of a type
Returns:
boolean

Definition at line 65 of file UserType.type.php.

static spunQ_DataObject::valueByProperty ( value,
path 
) [static, inherited]

Transforms a value using a property path.

Some types are considered to have properties within spunQ. These properties can be referred to using property path definitions. The most simple case for properties is the user type, for which every member is considered a property. Concatenations of these paths with dots as separators are called property path. The list of all users in the primary group of a given user can be described using this method in a string: 'primaryGroup.users'.
Different types have different properties:

  • UserType: As already mentioned, every member of a user type is a property of an object of that type.
  • Map:
    • _keys: An array of the keys of the map.
    • _values: An array of the values of the map. Note that _keys and _values are guaranteed to return arrays where the index of a key matches the index of its value in the according result.
    • _key: The first entry of the _keys property. This is handy for referencing the key of single key/value pairs.
    • _value: The first entry of the _values property.
    • _count: The amount of items in the map.
  • Array:
    • _keys: The array of keys of the array. Note that the difference between arrays and maps in spunQ is that arrays are always numerically indexed! So this will always return an array containing a range of integers.
    • _values: Array of values in this array. This essentially returns the array as-is and is a NOOP.
    • _key: The first entry of the _keys property.
    • _value: The first entry of the _values property.
    • _count: The amount of items in the array.
  • String:
    • _length: The length of the string.
Parameters:
$value The value to transform
$path The property path to use for the transformation. This can either be a string as described, or an array, each entry holding a property name.
Returns:
any The described value.
Todo:
refactor

Definition at line 54 of file DataObject.type.php.


Member Data Documentation

spunQ_DataObject::$_type [protected, inherited]

The actual type of this object.

Type:
spunQ.Type

Definition at line 129 of file DataObject.type.php.

spunQ_UserType::$allMembers [private]

Cache for getAllMembers().

A mapping of member names to member objects.

Type:
map<string,spunQ.Member>

Definition at line 206 of file UserType.type.php.

spunQ_UserType::$className [protected]

The name of the class associated with this type.

Type:
string

Definition at line 190 of file UserType.type.php.

spunQ_UserType::$classToType = array() [static, protected]

List of all types, mapped by the associated class.

Type:
array

Definition at line 163 of file UserType.type.php.

spunQ_Type::$documentation [protected, inherited]

Documentation of this type as extracted from its doc comments.

Type:
string

Definition at line 434 of file Type.type.php.

spunQ_UserType::$injectedMembers = array() [protected]

Members that have been injected by other modules.

Array containing the injecting members.

Type:
array<spunQ.InjectedMember>

Definition at line 214 of file UserType.type.php.

spunQ_UserType::$injectedMembersRecursive = NULL [protected]

Type:
array<spunQ.InjectedMember>

Definition at line 220 of file UserType.type.php.

spunQ_Type::$name [protected, inherited]

The name of this type.

Type:
string

Definition at line 428 of file Type.type.php.

spunQ_UserType::$nameToType = array() [static, protected]

List of all types, mapped by their name.

Type:
array

Definition at line 169 of file UserType.type.php.

spunQ_Type::$options [protected, inherited]

Additional options for this member.

This map is extracted from the tags in the doc comment. The value is intentionally typed as array, since some options can have multiple values. A doc comment containing two author tags would result in a single entry with two values.

Type:
map<string,array<string>>

Definition at line 444 of file Type.type.php.

spunQ_UserType::$ownMembers = array() [protected]

Members of this type, mapped by the member name.

The naming ownMembers was chosen to reduce confusion with the pool of the members of this type and its parent type's.

Type:
map<string,spunQ.Member>

Definition at line 183 of file UserType.type.php.

spunQ_UserType::$ownMembersRecursive [protected]

Cache for getOwnMembersRecursive().

A mapping of member names to member objects.

Type:
map<string,spunQ.Member>

Definition at line 198 of file UserType.type.php.

spunQ_UserType::$parent [protected]

Its parent type.

Type:
spunQ.UserType

Definition at line 175 of file UserType.type.php.

spunQ_Type::$typeInstance = NULL [static, protected, inherited]

The one instance of this class that will describe all other instances.

Any type describing a type has itself a type (which is spunQ.Type). That instance describing types is stored in this static variable.

Type:
spunQ_Type

Definition at line 291 of file Type.type.php.


The documentation for this class was generated from the following file:

Generated on Fri Jul 1 11:12:44 2011 for spunQ3 by  doxygen 1.5.9