phpcr/src/PHPCR/PropertyType.php

Show: PublicProtectedPrivateinherited
Table of Contents
This file is part of the PHPCR API and was originally ported from the Java JCR API to PHP by Karsten Dambekalns for the FLOW3 project.

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.

License
Apache Software License 2.0  
Link
http://phpcr.github.com/  

\PHPCR\PropertyType

Package: Default
The property types supported by the JCR standard.
  • 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

>VConstant  UNDEFINED = 0
This constant can be used within a property definition 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 Property#getType and it cannot be assigned as the type when creating a new property.

>VConstant  STRING = 1
The STRING property type is used to store strings.
>VConstant  BINARY = 2
BINARY properties are used to store binary data.
>VConstant  LONG = 3
The LONG property type is used to store integers.
>VConstant  DOUBLE = 4
The DOUBLE property type is used to store floating point numbers.
>VConstant  DATE = 5
The DATE property type is used to store time and date information.
>VConstant  BOOLEAN = 6
The BOOLEAN property type is used to store boolean values.
>VConstant  NAME = 7
A NAME is a pairing of a namespace and a local name.

When read, the namespace is mapped to the current prefix.

>VConstant  PATH = 8
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.

>VConstant  REFERENCE = 9
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 the removal of its target node.

>VConstant  WEAKREFERENCE = 10
A WEAKREFERENCE property stores the identifier of a referenceable node (one having type mix:referenceable).

A WEAKREFERENCE property does not enforce referential integrity.

>VConstant  URI = 11
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.
>VConstant  DECIMAL = 12
The DECIMAL property type is used to store precise decimal numbers.
>VConstant  TYPENAME_UNDEFINED = 'undefined'
String constant for type name as used in serialization.
>VConstant  TYPENAME_STRING = 'String'
String constant for type name as used in serialization.
>VConstant  TYPENAME_BINARY = 'Binary'
String constant for type name as used in serialization.
>VConstant  TYPENAME_LONG = 'Long'
String constant for type name as used in serialization.
>VConstant  TYPENAME_DOUBLE = 'Double'
String constant for type name as used in serialization.
>VConstant  TYPENAME_DATE = 'Date'
String constant for type name as used in serialization.
>VConstant  TYPENAME_BOOLEAN = 'Boolean'
String constant for type name as used in serialization.
>VConstant  TYPENAME_NAME = 'Name'
String constant for type name as used in serialization.
>VConstant  TYPENAME_PATH = 'Path'
String constant for type name as used in serialization.
>VConstant  TYPENAME_REFERENCE = 'Reference'
String constant for type name as used in serialization.
>VConstant  TYPENAME_WEAKREFERENCE = 'WeakReference'
String constant for type name as used in serialization.
>VConstant  TYPENAME_URI = 'URI'
String constant for type name as used in serialization.
>VConstant  TYPENAME_DECIMAL = 'Decimal'
String constant for type name as used in serialization.

Methods

methodprivate__construct() : void

Make instantiation impossible.

..

methodpublicconvertType(mixed $value, int $type, int $srctype = self::UNDEFINED) : mixed
static

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)
STRINGxUtf-8 encodedcast to intcast to floatSYYYY-MM-DDThh:Mm:ss.sssTZD'' is false, else trueif valid name, nameif valid path, as namecheck valid uuidRFC 3986string
BINARYUtf-8xConverted to string and then interpreted as above
LONGcast to stringString, then Utf-8xcast to floatUnix Time0 false else trueValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptioncast to string
DOUBLEcast to stringString, then Utf-8cast to intxUnix Time0.0 is false, else trueValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptioncast to string
DATESYYYY-MM-DDThh:
Mm:ss.sssTZD
String, then Utf-8Unix timestampUnix timestampx trueValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionUnix timestamp
BOOLEANcast to stringString, then Utf-80/10.0/1.0ValueFormatExceptionx'0'/'1' ValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatException
NAMEQualified formString, then Utf-8ValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionxnoop (relative path)ValueFormatException„./“ and qualified name. % encode illegal charactersValueFormatException
PATHStandard formString, then Utf-8ValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionif relative path lenght 1 noop / otherwise ValueFormatExceptionxValueFormatException„./“ if not starting with /. % encode illegal charactersValueFormatException
REFERENCEnoopString, then Utf-8ValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionxValueFormatExceptionValueFormatException
URInoopString, then Utf-8ValueFormatExceptionValueFormatExceptionValueFormatException ValueFormatExceptionsingle name: decode %, remove ./ else ValueFormatExceptionDecode %, remove leading ./ . if not star w. name, / or ./ then ValueFormatExceptionValueFormatExceptionxValueFormatException
DECIMALnoopUtf-8 encodedcast to intcast to floatUnix Time0 false else trueValueFormatExceptionValueFormatExceptionValueFormatExceptionValueFormatExceptionx

Parameters
NameTypeDescription
$valuemixed

The value or value array to check and convert

$typeint

Target type to convert into. One of the type constants in PropertyType

$srctypeint

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)

Returns
TypeDescription
mixedthe value casted into the proper format (throws an exception if conversion is not possible)
Throws
ExceptionDescription
\PHPCR\ValueFormatExceptionis thrown if the specified value cannot be converted to the specified type
\PHPCR\RepositoryExceptionif the specified Node is not referenceable, the current Session is no longer active, or another error occurs.
\InvalidArgumentExceptionif 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.
Details
See
\PHPCR\http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4%20Property%20Type%20Conversion  
methodpublicdetermineType(mixed $value, boolean $weak = false) : int
static

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

Parameters
NameTypeDescription
$valuemixed

The variable we need to know the type of

$weakboolean

When a Node is given as $value this can be given as true to create a WEAKREFERENCE.

Returns
TypeDescription
intOne of the type constants
Throws
ExceptionDescription
\PHPCR\ValueFormatExceptionif the type can not be determined
Details
Api
 
methodpublicnameFromValue(integer $type) : string
static

Returns the name of the specified type, as used in serialization.

Parameters
NameTypeDescription
$typeinteger

type the property type

Returns
TypeDescription
stringname of the specified type
Throws
ExceptionDescription
\InvalidArgumentExceptionif the given type is unknown.
Details
Api
 
methodpublicvalueFromName(string $name) : int
static

Returns the numeric constant value of the type with the specified name.

This method is case-insensitive

Parameters
NameTypeDescription
$namestring

The name of the property type

Returns
TypeDescription
intThe numeric constant value
Throws
ExceptionDescription
\InvalidArgumentExceptionif the given name is unknown.
Details
Api
 
Documentation was generated by phpDocumentor 2.0.0a12.