当前位置: 首页>>代码示例>>PHP>>正文


PHP Q_Response::addError方法代码示例

本文整理汇总了PHP中Q_Response::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Response::addError方法的具体用法?PHP Q_Response::addError怎么用?PHP Q_Response::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Q_Response的用法示例。


在下文中一共展示了Q_Response::addError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Streams_related_validate

function Streams_related_validate()
{
    switch (Q_Request::method()) {
        case 'POST':
            $required = array('toPublisherId', 'toStreamName', 'type', 'fromPublisherId', 'fromStreamName');
            break;
        case 'DELETE':
            $required = array('toPublisherId', 'toStreamName', 'type', 'fromPublisherId', 'fromStreamName');
            break;
        case 'PUT':
            $required = array('toPublisherId', 'toStreamName', 'type', 'fromPublisherId', 'fromStreamName', 'weight');
            if (isset($_REQUEST['adjustWeights'])) {
                if (!is_numeric($_REQUEST['adjustWeights'])) {
                    Q_Response::addError(new Q_Exception_WrongValue(array('field' => 'adjustWeights', 'range' => 'a numeric value'), 'adjustWeights'));
                }
            }
            break;
        case 'GET':
            $required = array();
            break;
    }
    foreach ($required as $r) {
        if (!isset($_REQUEST[$r])) {
            Q_Response::addError(new Q_Exception_RequiredField(array('field' => $r)));
        }
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:27,代码来源:validate.php

示例2: Users_account_validate

function Users_account_validate()
{
    Q_Valid::nonce(true);
    $birthday_year = $birthday_month = $birthday_day = null;
    extract($_REQUEST);
    $field_names = array('firstName' => 'First name', 'lastName' => 'Last name', 'username' => 'Username', 'gender' => 'Your gender', 'desired_gender' => 'Gender preference', 'orientation' => 'Orientation', 'relationship_status' => 'Status', 'zipcode' => 'Zipcode');
    foreach ($field_names as $name => $label) {
        if (isset($_POST[$name]) and !$_POST[$name]) {
            Q_Response::addError(new Q_Exception_RequiredField(array('field' => $label), $name));
        }
    }
    if (isset($birthday_year)) {
        if (!checkdate($birthday_month, $birthday_day, $birthday_year)) {
            $field = 'Birthday';
            $range = 'a valid date';
            Q_Response::addError(new Q_Exception_WrongValue(compact('field', 'range'), 'birthday'));
        }
    }
    global $Q_installing;
    if (isset($username) and isset($Q_installing)) {
        try {
            Q::event('Users/validate/username', compact('username'));
        } catch (Exception $e) {
            Q_Response::addError($e);
        }
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:27,代码来源:validate.php

示例3: Streams_invite_validate

function Streams_invite_validate()
{
    if (Q_Request::method() === 'PUT') {
        return;
    }
    if (Q_Request::method() !== 'GET') {
        Q_Valid::nonce(true);
    }
    $fields = array('publisherId', 'streamName');
    if (Q_Request::method() === 'POST') {
        if (Q_Valid::requireFields($fields)) {
            return;
        }
        foreach ($fields as $f) {
            if (strlen(trim($_REQUEST[$f])) === 0) {
                Q_Response::addError(new Q_Exception("{$f} can't be empty", $f));
            }
        }
    }
    if (isset($_REQUEST['fullName'])) {
        $length_min = Q_Config::get('Streams', 'inputs', 'fullName', 'lengthMin', 5);
        $length_max = Q_Config::get('Streams', 'inputs', 'fullName', 'lengthMax', 30);
        if (strlen($_REQUEST['fullName']) < $length_min) {
            throw new Q_Exception("A user's full name can't be that short.", 'fullName');
        }
        if (strlen($_REQUEST['fullName']) > $length_max) {
            throw new Q_Exception("A user's full name can't be that long.", 'fullName');
        }
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:30,代码来源:validate.php

示例4: Users_authorize_validate

function Users_authorize_validate()
{
    Q_Request::requireFields(array('client_id', 'redirect_uri', 'state'));
    if (empty($_REQUEST['response_type']) or $_REQUEST['response_type'] !== 'token') {
        Q_Response::addError(new Q_Exception_WrongValue(array('field' => 'response_type', 'range' => '"token"'), 'response_type'));
    }
    $min_length = Q_Config::expect('Users', 'authorize', 'stateMinLength');
    if (!empty($_REQUEST['state']) and strlen($_REQUEST['state']) < $min_length) {
        Q_Response::addError(new Q_Exception_WrongValue(array('field' => 'state', 'range' => "at least {$min_length} characters"), 'state'));
    }
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:11,代码来源:validate.php

示例5: Users_authorize_validate

function Users_authorize_validate()
{
    $bad_fields = array();
    foreach (array('client_id', 'redirect_uri', 'scope', 'state') as $field) {
        if (empty($_REQUEST[$field])) {
            Q_Response::addError(new Q_Exception_RequiredField(compact('field'), $field));
            $bad_fields[$field] = true;
        }
    }
    if (empty($_REQUEST['response_type']) or $_REQUEST['response_type'] !== 'token') {
        Q_Response::addError(new Q_Exception_WrongValue(array('field' => 'response_type', 'range' => '"token"'), 'response_type'));
    }
    $min_length = Q_Config::expect('Users', 'authorize', 'stateMinLength');
    if (!empty($_REQUEST['state']) and strlen($_REQUEST['state']) < $min_length) {
        Q_Response::addError(new Q_Exception_WrongValue(array('field' => 'state', 'range' => "at least {$min_length} characters"), 'state'));
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:17,代码来源:validate.php

示例6: Streams_basic_validate

function Streams_basic_validate()
{
    Q_Valid::nonce(true);
    if (Q_Request::method() !== 'POST') {
        return;
    }
    $fields = array('firstName' => 'First name', 'lastName' => 'Last name', 'gender' => 'Gender', 'birthday_month' => 'Month', 'birthday_day' => 'Day', 'birthday_year' => 'Year');
    if (isset($_REQUEST['fullName'])) {
        $length_min = Q_Config::get('Streams', 'inputs', 'fullName', 'lengthMin', 5);
        $length_max = Q_Config::get('Streams', 'inputs', 'fullName', 'lengthMax', 30);
        if (strlen($_REQUEST['fullName']) < $length_min) {
            Q_Response::addError(new Q_Exception("Your full name can't be that short.", 'fullName'));
        }
        if (strlen($_REQUEST['fullName']) > $length_max) {
            Q_Response::addError(new Q_Exception("Your full name can't be that long.", 'fullName'));
        }
    }
    if (Q_Response::getErrors()) {
        return;
    }
    if (!empty($_REQUEST['birthday_month']) or !empty($_REQUEST['birthday_day']) or !empty($_REQUEST['birthday_year'])) {
        foreach (array('birthday_month', 'birthday_day', 'birthday_year') as $field) {
            if (empty($_REQUEST[$field]) or !trim($_REQUEST[$field])) {
                throw new Q_Exception_RequiredField(compact('field'), $field);
            }
        }
        if (!checkdate($_REQUEST['birthday_month'], $_REQUEST['birthday_day'], $_REQUEST['birthday_year'])) {
            Q_Response::addError(new Q_Exception("Not a valid date", "birthday_day"));
        }
        if ($_REQUEST['birthday_year'] > date('Y') - 13) {
            // compliance with COPPA
            Q_Response::addError(new Q_Exception("You're still a kid.", "birthday_year"));
        }
        if ($_REQUEST['birthday_year'] < date('Y') - 100) {
            Q_Response::addError(new Q_Exception("A world record? Really?", "birthday_year"));
        }
    }
    if (!empty($_REQUEST['gender'])) {
        if (!in_array($_REQUEST['gender'], array('male', 'female'))) {
            Q_Response::addError(new Q_Exception("Please enter male or female", "gender"));
        }
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:43,代码来源:validate.php

示例7: Q_errors

/**
 * The default implementation.
 */
function Q_errors($params)
{
    extract($params);
    /**
     * @var Exception $exception
     * @var boolean $startedResponse
     */
    if (!empty($exception)) {
        Q_Response::addError($exception);
    }
    $errors = Q_Response::getErrors();
    $errors_array = Q_Exception::toArray($errors);
    // Simply return the errors, if this was an AJAX request
    if ($is_ajax = Q_Request::isAjax()) {
        try {
            $errors_json = @Q::json_encode($errors_array);
        } catch (Exception $e) {
            $errors_array = array_slice($errors_array, 0, 1);
            unset($errors_array[0]['trace']);
            $errors_json = @Q::json_encode($errors_array);
        }
        $json = "{\"errors\": {$errors_json}}";
        $callback = Q_Request::callback();
        switch (strtolower($is_ajax)) {
            case 'iframe':
                if (!Q_Response::$batch) {
                    header("Content-type: text/html");
                }
                echo <<<EOT
<!doctype html><html lang=en>
<head><meta charset=utf-8><title>Q Result</title></head>
<body>
<script type="text/javascript">
window.result = function () { return {$json} };
</script>
</body>
</html>
EOT;
                break;
            case 'json':
            default:
                header("Content-type: " . ($callback ? "application/javascript" : "application/json"));
                echo $callback ? "{$callback}({$json})" : $json;
        }
        return;
    }
    // Forward internally, if it was requested
    if ($onErrors = Q_Request::special('onErrors', null)) {
        $uri1 = Q_Dispatcher::uri();
        $uri2 = Q_Uri::from($onErrors);
        $url2 = $uri2->toUrl();
        if (!isset($uri2)) {
            throw new Q_Exception_WrongValue(array('field' => 'onErrors', 'range' => 'an internal URI reachable from a URL'));
        }
        if ($uri1->toUrl() !== $url2) {
            Q_Dispatcher::forward($uri2);
            return;
            // we don't really need this, but it's here anyway
        }
    }
    $params2 = compact('errors', 'exception', 'errors_array', 'exception_array');
    if (Q::eventStack('Q/response')) {
        // Errors happened while rendering response. Just render errors view.
        return Q::view('Q/errors.php', $params2);
    }
    if (!$startedResponse) {
        try {
            // Try rendering the response, expecting it to
            // display the errors along with the rest.
            $ob = new Q_OutputBuffer();
            Q::event('Q/response', $params2);
            $ob->endFlush();
            return;
        } catch (Exception $e) {
            if (get_class($e) === 'Q_Exception_DispatcherForward') {
                throw $e;
                // if forwarding was requested, do it
                // for all other errors, continue trying other things
            }
            $output = $ob->getClean();
        }
    }
    if ($errors) {
        // Try rendering the app's errors response, if any.
        $app = Q::app();
        if (Q::canHandle("{$app}/errors/response/content")) {
            Q_Dispatcher::forward("{$app}/errors");
        } else {
            echo Q::view("Q/errors.php", compact('errors'));
        }
    }
    if (!empty($e)) {
        return Q::event('Q/exception', array('exception' => $e));
    }
}
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:98,代码来源:errors.php

示例8: requireFields

 /**
  * Convenience method to apply certain criteria to an array.
  * and call Q_Response::addError for each one.
  * @see Q_Valid::requireFields
  * @method require
  * @static
  * @param {array} $fields Array of strings or arrays naming fields that are required
  * @return {array} The resulting list of exceptions
  */
 static function requireFields($fields, $throwIfMissing = false)
 {
     $args = func_get_args();
     array_splice($args, 1, 0, array(null));
     $exceptions = call_user_func_array(array('Q_Valid', 'requireFields'), $args);
     foreach ($exceptions as $e) {
         Q_Response::addError($e);
     }
 }
开发者ID:dmitriz,项目名称:Platform,代码行数:18,代码来源:Request.php


注:本文中的Q_Response::addError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。