PayPal\Common\ReflectionUtil::getPropertyClass PHP Method

getPropertyClass() public static method

If the class is null, it returns null. If the property is not found, it returns null.
public static getPropertyClass ( $class, $propertyName ) : null | string
$class
$propertyName
return null | string
    public static function getPropertyClass($class, $propertyName)
    {
        if ($class == get_class(new PayPalModel())) {
            // Make it generic if PayPalModel is used for generating this
            return get_class(new PayPalModel());
        }
        // If the class doesn't exist, or the method doesn't exist, return null.
        if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
            return null;
        }
        if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
            $param = $annotations['return'];
        }
        if (isset($param)) {
            $anno = preg_split("/[\\s\\[\\]]+/", $param);
            return $anno[0];
        } else {
            throw new PayPalConfigurationException("Getter function for '{$propertyName}' in '{$class}' class should have a proper return type.");
        }
    }

Usage Example

Beispiel #1
0
 public function fromArray($arr)
 {
     foreach ($arr as $k => $v) {
         if (is_array($v)) {
             $clazz = ReflectionUtil::getPropertyClass(get_class($this), $k);
             if (ArrayUtil::isAssocArray($v)) {
                 $o = new $clazz();
                 $o->fromArray($v);
                 $setterFunc = "set" . ucfirst($k);
                 $this->{$setterFunc}($o);
             } else {
                 $setterFunc = "set" . ucfirst($k);
                 $arr = array();
                 foreach ($v as $nk => $nv) {
                     if (is_array($nv)) {
                         $o = new $clazz();
                         $o->fromArray($nv);
                         $arr[$nk] = $o;
                     } else {
                         $arr[$nk] = $nv;
                     }
                 }
                 $this->{$setterFunc}($arr);
                 //TODO: Cleaning up any current values in this case. Should be doing this allways
             }
         } else {
             $this->{$k} = $v;
         }
     }
 }
All Usage Examples Of PayPal\Common\ReflectionUtil::getPropertyClass