/** * * @param string $className * @param object $resultObj * @return object returns the passed object if successful * @throws Braintree_Exception_ValidationsFailed */ public static function returnObjectOrThrowException($className, $resultObj) { $resultObjName = Braintree_Util::cleanClassName($className); if ($resultObj->success) { return $resultObj->{$resultObjName}; } else { throw new Braintree_Exception_ValidationsFailed(); } }
private function _mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn) { if (count($objsToReturn) != count($propertyNames)) { $propertyNames = array(); foreach ($objsToReturn as $obj) { array_push($propertyNames, Braintree_Util::cleanClassName(get_class($obj))); } } return array_combine($propertyNames, $objsToReturn); }
/** * @ignore * @param string $classToReturn name of class to instantiate */ public function __construct($objToReturn = null) { if (!empty($objToReturn)) { // get a lowercase direct name for the property $property = Braintree_Util::cleanClassName(get_class($objToReturn)); // save the name for indirect access $this->_returnObjectName = $property; // create the property! $this->{$property} = $objToReturn; } }
/** * @ignore * @param string $classToReturn name of class to instantiate */ public function __construct($objToReturn = null, $propertyName = null) { $this->_attributes = array(); if (!empty($objToReturn)) { if (empty($propertyName)) { $propertyName = Braintree_Util::cleanClassName(get_class($objToReturn)); } // save the name for indirect access $this->_returnObjectName = $propertyName; // create the property! $this->{$propertyName} = $objToReturn; } }
function testCleanClassName() { $cn = Braintree_Util::cleanClassName('Braintree_Transaction'); $this->assertEquals('transaction', $cn); }