phpcr/src/PHPCR/PropertyType.php
Copyright 2008-2011 Karsten Dambekalns karsten@typo3.org
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
\PHPCR\PropertyType
- The STRING property type is used to store strings.
- BINARY properties are used to store binary data.
- The LONG property type is used to store integers.
- The DECIMAL property type is used to store precise decimal numbers.
- The DOUBLE property type is used to store floating point numbers.
- The DATE property type is used to store time and date information. See 4.2.6.1 Date in the specification.
- The BOOLEAN property type is used to store boolean values.
- A NAME is a pairing of a namespace and a local name. When read, the namespace is mapped to the current prefix. See 4.2.6.2 Name in the specification.
- A PATH property is an ordered list of path elements. A path element is a NAME with an optional index. When read, the NAMEs within the path are mapped to their current prefix. A path may be absolute or relative. See 4.2.6.3 Path in the specification.
- A REFERENCE property stores the identifier of a referenceable node (one having type mix:referenceable), which must exist within the same workspace or session as the REFERENCE property. A REFERENCE property enforces this referential integrity by preventing (in level 2 implementations) the removal of its target node. See 4.2.6.4 Reference in the specification.
- A WEAKREFERENCE property stores the identifier of a referenceable node (one having type mix:referenceable).
- A WEAKREFERENCE property does not enforce referential integrity. See 4.2.6.5 Weak Reference in the specification.
- A URI property is identical to STRING property except that it only accepts values that conform to the syntax of a URI-reference as defined in RFC 3986. See also 4.2.6.6 URI in the specification.
- UNDEFINED can be used within a property definition (see 4.7.5 Property Definitions) to specify that the property in question may be of any type. However, it cannot be the actual type of any property instance. For example it will never be returned by PropertyInterface::getType() and (in level 2 implementations) it cannot be assigned as the type when creating a new property.
PHP Note on date formatting: Since there is no formatting for milliseconds in PHP we construct the date formatting by cutting the microseconds to 3 positions. Unfortunately this might cause an inacuracy of one millisecond in the worst case.
- Api
- Author
- Sebastian Kurfürst
- Author
- Karsten Dambekalns
- Author
- David Buchmann
Constants
UNDEFINED
= 0
However, it cannot be the actual type of any property instance. For example, it will never be returned by Property#getType and it cannot be assigned as the type when creating a new property.
NAME
= 7
When read, the namespace is mapped to the current prefix.
PATH
= 8
A path element is a NAME with an optional index. When read, the NAMEs within the path are mapped to their current prefix. A path may be absolute or relative.
REFERENCE
= 9
A REFERENCE property enforces this referential integrity by preventing the removal of its target node.
WEAKREFERENCE
= 10
A WEAKREFERENCE property does not enforce referential integrity.
URI
= 11
Methods
convertType(mixed $value, int $type, int $srctype = self::UNDEFINED) : mixed
Attempt to convert $values into the proper format for $type.
This is the other remaining part of ValueFactory functionality that is still needed.
If a $srctype is specified, the conversion also checks whether the conversion is allowed according to the property type conversion of the jcr specification (link below). This might be needed because NAME and other properties have quite restricted conversion matrix but in php will be modelled as string.
Note that for converting to boolean, we follow the PHP convention of treating any non-empty string as true, not just the word "true".
Table based on JCR spec
STRING (1) | BINARY (2) | LONG (3) | DOUBLE (4) | DATE (5) | BOOLEAN (6) | NAME(7) | PATH (8) | REFERENCE (9/10) | URI (11) | DECIMAL (12) | |
STRING | x | Utf-8 encoded | cast to int | cast to float | SYYYY-MM-DDThh:Mm:ss.sssTZD | '' is false, else true | if valid name, name | if valid path, as name | check valid uuid | RFC 3986 | string |
BINARY | Utf-8 | x | Converted to string and then interpreted as above | ||||||||
LONG | cast to string | String, then Utf-8 | x | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
DOUBLE | cast to string | String, then Utf-8 | cast to int | x | Unix Time | 0.0 is false, else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
DATE | SYYYY-MM-DDThh: Mm:ss.sssTZD | String, then Utf-8 | Unix timestamp | Unix timestamp | x | true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | Unix timestamp |
BOOLEAN | cast to string | String, then Utf-8 | 0/1 | 0.0/1.0 | ValueFormatException | x | '0'/'1' | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException |
NAME | Qualified form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | noop (relative path) | ValueFormatException | „./“ and qualified name. % encode illegal characters | ValueFormatException |
PATH | Standard form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | if relative path lenght 1 noop / otherwise ValueFormatException | x | ValueFormatException | „./“ if not starting with /. % encode illegal characters | ValueFormatException |
REFERENCE | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | ValueFormatException | ValueFormatException |
URI | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | single name: decode %, remove ./ else ValueFormatException | Decode %, remove leading ./ . if not star w. name, / or ./ then ValueFormatException | ValueFormatException | x | ValueFormatException |
DECIMAL | noop | Utf-8 encoded | cast to int | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x |
Name | Type | Description |
---|---|---|
$value | mixed | The value or value array to check and convert |
$type | int | Target type to convert into. One of the type constants in PropertyType |
$srctype | int | Source type to convert from, if not specified this is automatically determined, which will miss the string based types that are not strings (DECIMAL, NAME, PATH, URI) |
Type | Description |
---|---|
mixed | the value casted into the proper format (throws an exception if conversion is not possible) |
Exception | Description |
---|---|
\PHPCR\ValueFormatException | is thrown if the specified value cannot be converted to the specified type |
\PHPCR\RepositoryException | if the specified Node is not referenceable, the current Session is no longer active, or another error occurs. |
\InvalidArgumentException | if the specified DateTime value cannot be expressed in the ISO 8601-based format defined in the JCR 2.0 specification and the implementation does not support dates incompatible with that format. |
- See
- \PHPCR\http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4%20Property%20Type%20Conversion
determineType(mixed $value, boolean $weak = false) : int
Determine PropertyType from on variable type.
This is most of the remainder of ValueFactory that is still needed.
- if the given $value is a Node object, type will be REFERENCE, unless $weak is set to true which results in WEAKREFERENCE
- if the given $value is a DateTime object, the type will be DATE.
Note that string is converted to date exactly if it matches the jcr formatting spec for dates (sYYYY-MM-DDThh:mm:ss.sssTZD) according to http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4.3%20From%20DATE%20To
Name | Type | Description |
---|---|---|
$value | mixed | The variable we need to know the type of |
$weak | boolean | When a Node is given as $value this can be given as true to create a WEAKREFERENCE. |
Type | Description |
---|---|
int | One of the type constants |
Exception | Description |
---|---|
\PHPCR\ValueFormatException | if the type can not be determined |
- Api
nameFromValue(integer $type) : string
Returns the name of the specified type, as used in serialization.
Name | Type | Description |
---|---|---|
$type | integer | type the property type |
Type | Description |
---|---|
string | name of the specified type |
Exception | Description |
---|---|
\InvalidArgumentException | if the given type is unknown. |
- Api
valueFromName(string $name) : int
Returns the numeric constant value of the type with the specified name.
This method is case-insensitive
Name | Type | Description |
---|---|---|
$name | string | The name of the property type |
Type | Description |
---|---|
int | The numeric constant value |
Exception | Description |
---|---|
\InvalidArgumentException | if the given name is unknown. |
- Api