opensrs\Mail::getCommand PHP Method

getCommand() public method

public getCommand ( $dataObject, $fields = null, $required = false )
    public function getCommand($dataObject, $fields = null, $required = false)
    {
        $command = '';
        if (is_null($fields)) {
            if (isset($dataObject->attributes)) {
                if (isset($this->requiredFields['attributes'])) {
                    $command .= $this->getCommand($dataObject->attributes, $this->requiredFields['attributes'], true);
                }
                if (isset($this->optionalFields['attributes'])) {
                    $command .= $this->getCommand($dataObject->attributes, $this->optionalFields['attributes'], false);
                }
            }
        } else {
            // check required fields
            if (!empty($fields)) {
                foreach ($fields as $i => $field) {
                    if (is_array($field)) {
                        if (!isset($dataObject->{$i})) {
                            if ($required) {
                                Exception::notDefined($i);
                            }
                        }
                        $command .= $this->getCommand($dataObject->{$i}, $field, $required);
                    } else {
                        if (!isset($dataObject->{$field}) || $dataObject->{$field} == '') {
                            if ($required) {
                                Exception::notDefined($field);
                            }
                        } else {
                            if (is_array($dataObject->{$field})) {
                                $value = json_encode($dataObject->{$field});
                            } else {
                                $value = $dataObject->{$field};
                            }
                            $command .= " {$field}={$value}";
                        }
                    }
                }
            }
        }
        return $command;
    }