コード例 #1
0
ファイル: Response.php プロジェクト: hostbox/api-payu
 private function assign(array $data)
 {
     $errors = array();
     foreach ($data as $propertyName => $value) {
         $pr = new ClassType($this);
         if (trim($value) == '') {
             $value = NULL;
         }
         $propertyName = Strings::underdashToCamel($propertyName);
         if ($pr->hasProperty($propertyName)) {
             $property = $pr->getProperty($propertyName);
             if ($property->getAnnotation('var') == 'DateTime' && $value !== NULL) {
                 $value = new DateTime($value);
             }
             $this->{$propertyName} = $value;
         } else {
             $errors[] = $propertyName;
         }
     }
 }
コード例 #2
0
ファイル: Request.php プロジェクト: hostbox/api-payu
 /**
  * @param Config $config
  * @throws LogicException
  * @return array
  */
 public function getDataToArray(Config $config)
 {
     $this->setPosId($config->getPosId());
     if ($this instanceof NewPaymentRequest) {
         $this->setPosAuthKey($config->getPosAuthKey());
     }
     $reflection = new ClassType($this);
     $parameters = array();
     $errors = array();
     foreach ($reflection->getProperties() as $property) {
         if ($property->hasAnnotation('var') && $property->getAnnotation('var') == 'bool') {
             $getterPrefix = 'is';
         } else {
             $getterPrefix = 'get';
         }
         $propertyGetter = $getterPrefix . ucfirst($property->getName());
         $value = $this->{$propertyGetter}();
         if ($value !== NULL) {
             $parameters[Strings::camelToUnderdash($property->getName())] = $value;
         }
         if ($property->hasAnnotation('required') && $value === NULL) {
             $errors[] = $property->getName();
         }
     }
     if (count($errors) > 0) {
         throw new LogicException('Empty required properties: ' . implode(', ', $errors));
     }
     $parameters['sig'] = $this->getSig($config->getKey1());
     return $parameters;
 }