/**
  * Constructor
  * @param $name string the unique name of the property within a meta-data schema (can be a property URI)
  * @param $assocTypes array an array of integers that define the application entities that can
  *  be described with this property.
  * @param $allowedTypes mixed must be a scalar or an array with the supported types, default: METADATA_PROPERTY_TYPE_STRING
  * @param $translated boolean whether the property may have various language versions, default: false
  * @param $cardinality integer must be on of the supported cardinalities, default: METADATA_PROPERTY_CARDINALITY_ONE
  * @param $displayName string
  * @param $validationMessage string A string that can be displayed in case a user tries to set an invalid value for this property.
  * @param $mandatory boolean Is this a mandatory property within the schema?
  */
 function MetadataProperty($name, $assocTypes = array(), $allowedTypes = METADATA_PROPERTY_TYPE_STRING, $translated = false, $cardinality = METADATA_PROPERTY_CARDINALITY_ONE, $displayName = null, $validationMessage = null, $mandatory = false)
 {
     // Validate name and assoc type array
     assert(is_string($name));
     assert(is_array($assocTypes));
     // A single type will be transformed to an
     // array of types so that we can handle them
     // uniformly.
     if (is_scalar($allowedTypes) || count($allowedTypes) == 1) {
         $allowedTypes = array($allowedTypes);
     }
     // Validate types
     $canonicalizedTypes = array();
     foreach ($allowedTypes as $allowedType) {
         if (is_array($allowedType)) {
             // We expect an array with a single entry
             // of the form "type => additional parameter".
             assert(count($allowedType) == 1);
             // Reset the array, just in case...
             reset($allowedType);
             // Extract the type and the additional parameter
             $allowedTypeId = key($allowedType);
             $allowedTypeParam = current($allowedType);
         } else {
             // No additional parameter has been set.
             $allowedTypeId = $allowedType;
             $allowedTypeParam = null;
         }
         // Validate type
         assert(in_array($allowedTypeId, MetadataProperty::getSupportedTypes()));
         // Transform the type array in a
         // structure that is easy to handle
         // in for loops.
         $canonicalizedTypes[$allowedTypeId][] = $allowedTypeParam;
         // Validate additional type parameter.
         switch ($allowedTypeId) {
             case METADATA_PROPERTY_TYPE_COMPOSITE:
                 // Validate the assoc id of the composite.
                 assert(is_integer($allowedTypeParam));
                 // Properties that allow composite types cannot be translated.
                 assert(!$translated);
                 break;
             case METADATA_PROPERTY_TYPE_VOCABULARY:
                 // Validate the symbolic name of the vocabulary.
                 assert(is_string($allowedTypeParam));
                 break;
             default:
                 // No other types support an additional parameter
                 assert(is_null($allowedTypeParam));
         }
     }
     // Validate translation and cardinality
     assert(is_bool($translated));
     assert(in_array($cardinality, MetadataProperty::getSupportedCardinalities()));
     // Default display name
     if (is_null($displayName)) {
         $displayName = 'metadata.property.displayName.' . $name;
     }
     assert(is_string($displayName));
     // Default validation message
     if (is_null($validationMessage)) {
         $validationMessage = 'metadata.property.validationMessage.' . $name;
     }
     assert(is_string($validationMessage));
     // Initialize the class
     $this->_name = (string) $name;
     $this->_assocTypes =& $assocTypes;
     $this->_allowedTypes =& $canonicalizedTypes;
     $this->_translated = (bool) $translated;
     $this->_cardinality = (int) $cardinality;
     $this->_displayName = (string) $displayName;
     $this->_validationMessage = (string) $validationMessage;
     $this->_mandatory = (bool) $mandatory;
 }
Esempio n. 2
0
 /**
  * Constructor
  * @param $name string the unique name of the property within a meta-data schema (can be a property URI)
  * @param $assocTypes array an array of integers that define the application entities that can
  *  be described with this property.
  * @param $types mixed must be a scalar or an array with the supported types, default: METADATA_PROPERTY_TYPE_STRING
  * @param $translated boolean whether the property may have various language versions, default: false
  * @param $cardinality integer must be on of the supported cardinalities, default: METADATA_PROPERTY_CARDINALITY_ONE
  * @param $compositeType integer an association type, mandatory if $type is METADATA_PROPERTY_TYPE_COMPOSITE
  */
 function MetadataProperty($name, $assocTypes = array(), $types = METADATA_PROPERTY_TYPE_STRING, $translated = false, $cardinality = METADATA_PROPERTY_CARDINALITY_ONE, $displayName = null)
 {
     // Validate name and assoc type array
     assert(is_string($name));
     assert(is_array($assocTypes));
     // A single type (scalar or composite) will be
     // transformed to an array of types so that we
     // can treat them uniformly.
     if (is_scalar($types) || count($types) == 1) {
         $types = array($types);
     }
     // Validate types
     foreach ($types as $type) {
         if (is_array($type)) {
             // Validate composite types
             assert(count($type) == 1 && isset($type[METADATA_PROPERTY_TYPE_COMPOSITE]) && is_integer($type[METADATA_PROPERTY_TYPE_COMPOSITE]));
             // Properties that allow composite types cannot be translated
             assert(!$translated);
         } else {
             // Validate all other types
             assert($type != METADATA_PROPERTY_TYPE_COMPOSITE && in_array($type, MetadataProperty::getSupportedTypes()));
         }
     }
     // Validate translation and cardinality
     assert(is_bool($translated));
     assert(in_array($cardinality, MetadataProperty::getSupportedCardinalities()));
     // Default display name
     if (is_null($displayName)) {
         $displayName = 'metadata.property.displayName.' . $name;
     }
     assert(is_string($displayName));
     // Initialize the class
     $this->_name = (string) $name;
     $this->_assocTypes =& $assocTypes;
     $this->_types =& $types;
     $this->_translated = (bool) $translated;
     $this->_cardinality = (int) $cardinality;
     $this->_displayName = (string) $displayName;
 }