Beispiel #1
0
 /** Create a new literal object
  *
  * PHP values of type bool, int or float, will automatically be converted
  * to the corresponding datatype and PHP sub-class.
  *
  * If a registered datatype is given, then the registered subclass of EasyRdf_Literal
  * will instantiated.
  *
  * Note that literals are not required to have a language or datatype.
  * Literals cannot have both a language and a datatype.
  *
  * @param  mixed  $value     The value of the literal or an associative array
  * @param  string $lang      The natural language of the literal or null (e.g. 'en')
  * @param  string $datatype  The datatype of the literal or null (e.g. 'xsd:integer')
  * @return object EasyRdf_Literal (or subclass of EasyRdf_Literal)
  */
 public static function create($value, $lang = null, $datatype = null)
 {
     if (EasyRdf_Utils::isAssociativeArray($value)) {
         if (isset($value['xml:lang'])) {
             $lang = $value['xml:lang'];
         } else {
             if (isset($value['lang'])) {
                 $lang = $value['lang'];
             }
         }
         if (isset($value['datatype'])) {
             $datatype = $value['datatype'];
         }
         $value = isset($value['value']) ? $value['value'] : null;
     }
     if ($datatype == null) {
         if ($lang == null) {
             // Automatic datatype selection
             $datatype = self::getDatatypeForValue($value);
         }
     } else {
         // Expand shortened URIs (qnames)
         $datatype = EasyRdf_Namespace::expand($datatype);
     }
     // Work out what class to use for this datatype
     if (isset(self::$_datatypeMap[$datatype])) {
         $class = self::$_datatypeMap[$datatype];
     } else {
         $class = 'EasyRdf_Literal';
     }
     return new $class($value, $lang, $datatype);
 }
 public function testIsAssocIntPreppend()
 {
     $arr = array('foo' => 'bar');
     array_unshift($arr, 'rat');
     $this->assertFalse(EasyRdf_Utils::isAssociativeArray($arr));
 }