Esempio n. 1
0
 /**
 		Provides a common set of logic filters for adding new items to the
 		dictionary. This prevents invalid items from being added, such as objects
 		that do not inherit from RTObject. The reason that object that do not
 		inherit from RTObject are forbidden its that there is no way to assure a
 		valid string representation can be derived from such objects. For example,
 		there is no programatic way to convert an instance of stdClass to a string.
 		Sure we would iterate over the properties and values of an object, but let's
 		say you have a custom class that only uses private properties. We could
 		alsos test for the ability of an object to be converted to a string, but by
 		enforcing this requirement, that's already done.
 */
 protected function _setObject_forKey($anObject, $aKey)
 {
     if (is_object($anObject) && is_a($anObject, "RTObject") == NO) {
         throw new InvalidArgumentException("Objects added to an RTDictionary must inherit from RTObject.");
     }
     if (is_null($aKey) == YES) {
         throw new InvalidArgumentException("Keys in an RTDictionary cannot be null");
     } else {
         if (is_object($aKey) && is_a($aKey, "RTObject")) {
             $aKey = $aKey->description();
         }
     }
     if (is_array($anObject)) {
         if (RTPHPArrayIsRTDictionary($anObject)) {
             $anObject = RTDictionary::dictionaryWithPHPArray($anObject);
         } else {
             $anObject = RTArray::arrayWithArray($anObject);
         }
     } else {
         if (is_string($anObject)) {
             $anObject = RTString::stringWithString($anObject);
         }
     }
     $this->_data[$aKey] = $anObject;
 }
Esempio n. 2
0
 /**
 		A utility method that provides standardized filtering of incomming objects.
 		Basically, it makes sure that any object added to the array is an instance
 		of RTObject. An 'object' in this context literally means it passes the
 		is_object() function.
 		\param $anObject The object to add to the array
 		\param $anIndex The index at which the object should be inserted
 		\throws InvalidArgumentException if the object passes is_object() but is not
 		an instance of RTObject.
 */
 protected function _insertObject_atIndex($anObject, $anIndex)
 {
     if (is_object($anObject) && is_a($anObject, "RTObject") == NO) {
         throw new InvalidArgumentException("RTArray can only contain primitives and objects that inherit from " . "RTObject. Found object of class '" . get_class($anObject) . "'");
     }
     if (is_array($anObject)) {
         if (RTPHPArrayIsRTDictionary($anObject)) {
             $anObject = RTDictionary::dictionaryWithPHPArray($anObject);
         } else {
             $anObject = RTArray::arrayWithArray($anObject);
         }
     } else {
         if (is_string($anObject)) {
             $anObject = RTString::stringWithString($anObject);
         }
     }
     $this->_data[$anIndex] = $anObject;
 }
Esempio n. 3
0
 public function testRTPHPArrayIsRTDictionary()
 {
     $this->assertTrue(RTPHPArrayIsRTDictionary(array("one" => "42")));
     $this->assertFalse(RTPHPArrayIsRTDictionary(array(42)));
 }