示例#1
0
 protected function getValue(&$field, &$options, array $parameters)
 {
     static $camelize = ['pending_file_attachments' => true, 'date_format' => true, 'send_welcome_email' => true, 'receive_daily_reports' => true, 'welcome_email_message' => true, 'auto_give_project_access' => true, 'open_id' => true, 'user_language' => true, 'pending_file_ref' => true, 'new_company' => true], $yes_no_boolean = ['welcome_email_message', 'send_welcome_email', 'receive_daily_reports', 'notes', 'auto_give_project_access'], $preserve = ['address_one' => true, 'address_two' => true];
     $value = isset($parameters[$field]) ? $parameters[$field] : null;
     if (!is_array($options)) {
         $options = ['required' => $options, 'attributes' => []];
     }
     $isNull = null === $value;
     //verficando campos requeridos
     if ($this->method == 'POST' && $options['required']) {
         if ($isNull) {
             throw new \TeamWorkPm\Exception('Required field ' . $field);
         }
     }
     //verficando campos que debe cumplir ciertos valores
     if (!$isNull && isset($options['validate']) && !in_array($value, $options['validate'])) {
         throw new \TeamWorkPm\Exception('Invalid value for field ' . $field);
     }
     // @todo Ojo la gente de team work no mainten constante el formato name-other
     if (isset($camelize[$field])) {
         if ($field === 'open_id') {
             $field = 'openID';
         } else {
             $field = Str::camel($field);
         }
     } elseif (!isset($preserve[$field])) {
         if ($field === 'company_id') {
             if ($this->action === 'projects') {
                 $field = Str::camel($field);
             } elseif ($this->action == 'people') {
                 $field = Str::dash($field);
             }
         } else {
             $field = Str::dash($field);
         }
     }
     return $value;
 }
示例#2
0
 protected static function camelizeObject($source)
 {
     $destination = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
     foreach ($source as $key => $value) {
         if (ctype_upper($key)) {
             $key = strtolower($key);
         }
         $key = Str::camel($key);
         $destination->{$key} = is_scalar($value) ? $value : self::camelizeObject($value);
     }
     return $destination;
 }
示例#3
0
 /**
  * Convierte un objecto SimpleXMLElement a stdClass
  *
  * @param SimpleXMLElement $source
  * @param bool $isArray
  * @return stdClass
  */
 private static function toStdClass(SimpleXMLElement $source, $isArray = false)
 {
     $destination = $isArray ? [] : new stdClass();
     foreach ($source as $key => $value) {
         $key = Str::camel($key);
         $attrs = $value->attributes();
         if (!empty($attrs->type)) {
             $type = (string) $attrs->type;
             switch ($type) {
                 case 'integer':
                     $destination->{$key} = (int) $value;
                     break;
                 case 'boolean':
                     $value = (string) $value;
                     $destination->{$key} = (bool) $value === 'true';
                     break;
                 case 'array':
                     if (is_array($destination)) {
                         $destination[$key] = self::toStdClass($value, true);
                     } else {
                         $destination->{$key} = self::toStdClass($value, true);
                     }
                     break;
                 default:
                     $destination->{$key} = (string) $value;
                     break;
             }
         } else {
             $children = $value->children();
             if (!empty($children)) {
                 if ($isArray) {
                     $i = count($destination);
                     $destination[$i] = self::toStdClass($value);
                 } else {
                     $destination->{$key} = self::toStdClass($value);
                 }
             } else {
                 $destination->{$key} = (string) $value;
             }
         }
     }
     return $destination;
 }