@param array $data

@return mixed
@throws Exception
168417
protected function transform($data)
    {
        if (!$data instanceof GetSchema\Schema) {
            throw new Exception('Data is not a Schema.');
        }

        $createExpr = $this->getCreateQueryFromSchema($data);
        $indices = $createExpr->getIndices();
        $columns = $createExpr->getColumns();

        $returnData = [];

        /* @var  $column Query\ColumnExpression */
        foreach ($columns as $column) {
            $row                      = self::$tplData;
            $columnType               = $column->getColumnType();
            $dataType                 = $columnType->getDataType();

            $key = $this->getKeyTypeFromColumn($column, $indices);
            $default = $this->getDefaultValueFromColumnType($columnType);

            $row[self::KEY_FIELD]     = $row[0] = $column->getColumnName();
            $row[self::KEY_TYPE]      = $row[1] = $columnType->getSqlType();
            $row[self::KEY_COLLATION] = $row[2] = $dataType->getCollation() !== '' ? $dataType->getCollation() : null;
            $row[self::KEY_NULL]      = $row[3] = $columnType->isNullable() ? 'YES' : 'NO';
            $row[self::KEY_KEY]       = $row[4] = $key;
            $row[self::KEY_DEFAULT]   = $row[5] = $default;

            $returnData[] = $row;
        }

        return $returnData;
    }
1356294
protected function encode($name, $data)
    {
        if (is_string($data)) {
            return $data;
        }

        $data = json_encode($data);

        if (json_last_error()) {
            throw new Exception(
                "Erro json encode [ {$name} ] - " . $this->lastJsonErrorMessage(json_last_error()), 500
            );
        }

        return $data;
    }
853284
protected function getTemplate($name, array $data)
    {
        $template = App::instance()->template($name);

        if (!$template->exists()) {
            throw new Exception("The template '{$name}' does not exist.");
        }

        return $template->render($data);
    }
1226439
public function to_xml($data){
        if(!is_array($data) || count($data) <= 0) throw new \Exception('xml data exception!');
        $xml = "<xml>";
        foreach ($data as $key=>$val){
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        return $xml;
    }
521915
public function createPermission(array $data = [])
    {
        $model = new Permission($this->db);
        $model->data($data);
        try{
            $res = $model->savePermission();
            return $res;
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
1187522
protected function fieldSet(array $data)
    {
        if (!$this->tableSchema['field']) {
            throw new Exception('请在' . get_class($this) . '构造函数中调用父类的构造函数');
        }
        return \wf\db\QueryBuilder::buildSqlSet($data, $this->tableSchema['field'], $this->lockedFields);
    }
1112880
protected function UserGroupCreate(array $data)
    {
        $return = [];
        if (empty($data['STRING_ID'])) {
            throw new Exception('You must set group STRING_ID');
        }
        if ($this->UserGetGroupIdByCode($data['STRING_ID'])) {
            throw new Exception('Group with STRING_ID ' . $data['STRING_ID'] . ' already exists');
        }
        $ib = new CGroup();
        $id = $ib->Add(array_merge(['ACTIVE' => 'Y'], $data));
        if ($id) {
            $return[] = "Add {$data['STRING_ID']} users group";
        } else {
            throw new Exception("Can't create {$data['STRING_ID']} users group");
        }

        return $return;
    }
1017963
public static function fromArray(array $data)
	{
		return new self(
			!empty($data['code'])    ? $data['code']    : null,
			!empty($data['message']) ? $data['message'] : null,
			!empty($data['data'])    ? $data['data']    : null
		);
	}
1345266
private function apiServerSendData(array $data)
    {
        if ($this->transferException) {
            $curl = new Curl();
            $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 2);
            $curl->setOpt(CURLOPT_TIMEOUT, 2);
            $curl->post(Url::ensureHttp(rtrim($this->api, '/')).'/create', [
                'error_json' => Json::encode($data),
            ]);
            
            $this->lastTransferCall = $curl;
            
            return $curl->isSuccess();
        }
        
        return null;
    }
339716
public function createPayRequest($data)
    {
        if (empty($data['return_url']) && empty($data['cancel_url'])) {
            throw new \Exception('Return & Cancel URL should be specified');
        }

        $this->setPayRequestDetails($data);

        return $this->doPayPalRequest('Pay');
    }
1160645
public function fromDbTableRow(DoplioDbTable $data) {

        $data = $data->toArray();

        if (!is_array($data)) {
            throw new \Exception('Object must be either an array or a DoplioDbTable');
        }

        return $this->fromArray($data);
    }
992891
public function decode($data)
    {
        $data["data"] = $this->decrypt($data["data"], $this->config["secret"]);

        if (hash_hmac(
            "sha256",
            $data["data"],
            $this->config["secret"]
        ) == $data["token"]) {
            return unserialize($data["data"]);
        } else {
            throw new \Exception('Failed to verify payload');
        }
    }
941082
protected function extractSingleItemData(array $data) {
        if ($this->singleResponseKey && !array_key_exists($this->singleResponseKey, $data)) {
            throw new Exception('Invalid response, missing field ' . $this->singleResponseKey);
        }

        return ($this->singleResponseKey) ? $data[$this->singleResponseKey] : $data;
    }
812051
public function offsetGet($offset)
    {
        $data = $this->getQueryResult($offset);
        if (null == $data) {
            throw new Exception('Data row by key "' . $offset . '" not exists');
        }
        return $data;
    }
127311
public static function check(array $data = null)
    {
        if ($data === null) {
            return self::$defaults;
        }
        foreach (self::$defaults as $section => $default) {
            if (array_key_exists($section, $data)) {
                $value = $data[$section];
                if (is_array($default)) {
                    if (!is_array($value)) {
                        throw new InvalidSection($section, 'must be an array');
                    }
                    if (array_values($value) !== $value) {
                        throw new InvalidSection($section, 'must be a numeric array');
                    }
                } elseif (is_array($value)) {
                    throw new InvalidSection($section, 'must be a string');
                }
            } else {
                if (in_array($section, self::$required)) {
                    throw new InvalidSection($section, 'is required, but not specified');
                }
                $data[$section] = $default;
            }
        }
        if (!in_array($data['version'], [3, '3'], true)) {
            throw new UnsupportedVersion($data['version']);
        }
        if (count(array_diff_key($data['sourcesContent'], $data['sources'])) > 0) {
            throw new InvalidSection('sourcesContent', 'does not correspond to sources');
        }
        return $data;
    }
1019268
public function createFromArray(array $data)
    {
        $headers = json_encode(
            Arr::path($this->emailConfig, 'defaults.headers', [])
        );

        if (isset($data['sender_localpart'])) {
            if (! Arr::path($this->emailConfig, 'defaults.sender.domain')) {
                throw new \Exception('defaults.sender.domain not set in email config');
            }

            $data['sender_email'] = (
                Arr::remove($data, 'sender_localpart') . '@' .
                Arr::path($this->emailConfig, 'defaults.sender.domain')
            );
        }

        $defaults = [
            'headers'      => $headers,
            'sender_email' => Arr::path($this->emailConfig, 'defaults.sender.email'),
            'sender_name'  => Arr::path($this->emailConfig, 'defaults.sender.name'),
        ];

        $email = $this->emailMapper->getPrototype();

        $email = $email->exchangeArray(
            array_merge($defaults, $data)
        );

        $email = $this->emailMapper->persist($email);

        return $email;
    }
1223559
public function update(array $data)
    {
        // validate email address
        if (!empty($data['email_address']) &&
                !filter_var($data['email_address'], FILTER_VALIDATE_EMAIL)) {
            throw new Exception(
                'Invalid value for field email_address'
            );
        }
        $project_id = empty($data['project_id']) ? 0 : $data['project_id'];
        $permissions = empty($data['permissions']) ? null :
                                                (array) $data['permissions'];
        unset($data['project_id'], $data['permissions']);
        $save = false;
        if (!empty($data)) {
            $save = parent::update($data);
        }
        // add permission to project
        if ($project_id) {
            $permission = \TeamWorkPm\Factory::build('project/people');
            try {
                $add = $permission->add($project_id, $data['id']);
            } catch (Exception $e) {
                $add = $e->getMessage() == 'User is already on project';
            }
            $save = $save && $add;
            if ($add && $permissions) {
                $permissions['person_id']  = $data['id'];
                $permissions['project_id'] = $project_id;
                $save = $permission->update($permissions);
            }
        }
        return $save;
    }