Removed ModelAccessValidator in favor of Forward Compatilibity Issues

- Model Access Validator causes unnecessary issues in existing integrations.
- Causes merchant to break integration if configured incorrectly.
This commit is contained in:
Jay Patel
2015-10-06 18:54:40 -05:00
parent a37b880e96
commit e1e70c0ebd
7 changed files with 1 additions and 158 deletions

View File

@@ -122,7 +122,6 @@ class PayPalModel
*/
public function __set($key, $value)
{
ModelAccessorValidator::validate($this, $this->convertToCamelCase($key));
if (!is_array($value) && $value === null) {
$this->__unset($key);
} else {
@@ -249,13 +248,7 @@ class PayPalModel
private function assignValue($key, $value)
{
// If we find the getter setter, use that, otherwise use magic method.
if (ModelAccessorValidator::validate($this, $this->convertToCamelCase($key))) {
$setter = "set" . $this->convertToCamelCase($key);
$this->$setter($value);
} else {
$this->__set($key, $value);
}
$this->__set($key, $value);
}
/**

View File

@@ -1,53 +0,0 @@
<?php
namespace PayPal\Validation;
use PayPal\Common\PayPalModel;
use PayPal\Core\PayPalConfigManager;
use PayPal\Core\PayPalLoggingManager;
/**
* Class ModelAccessorValidator
*
* @package PayPal\Validation
*/
class ModelAccessorValidator
{
/**
* Helper method for validating if the class contains accessor methods (getter and setter) for a given attribute
*
* @param PayPalModel $class An object of PayPalModel
* @param string $attributeName Attribute name
* @return bool
*/
public static function validate(PayPalModel $class, $attributeName)
{
$mode = PayPalConfigManager::getInstance()->get('validation.level');
if (!empty($mode) && $mode != 'disabled') {
//Check if $attributeName is string
if (gettype($attributeName) !== 'string') {
return false;
}
//If the mode is disabled, bypass the validation
foreach (array('set' . $attributeName, 'get' . $attributeName) as $methodName) {
if (get_class($class) == get_class(new PayPalModel())) {
// Silently return false on cases where you are using PayPalModel instance directly
return false;
}
//Check if both getter and setter exists for given attribute
elseif (!method_exists($class, $methodName)) {
//Delegate the error based on the choice
$className = is_object($class) ? get_class($class) : (string)$class;
$errorMessage = "It seems that $className:$methodName is a new field added to the API response. If not, create an issue at https://github.com/paypal/PayPal-PHP-SDK/issues";
PayPalLoggingManager::getInstance(__CLASS__)->debug($errorMessage);
if ($mode == 'strict') {
trigger_error($errorMessage, E_USER_NOTICE);
}
return false;
}
}
return true;
}
return false;
}
}