Example #1
0
 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;
         }
     }
 }
Example #2
0
 /**
  * @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;
 }