Validates a directory according to the spec

@param array  $result
@param string $spec

@return bool
1002
public function validateDirectory($result, $spec)
    {
        $spec  = explode('|', $spec);
        $valid = false;

        foreach ($spec as $s) {
            if (isset($result[$s]) && $result[$s]) {
                $valid = true;
                break;
            }
        }

        return $valid;
    }
650932
protected function formatSuccess($result)
    {
        switch ($this->outputMode) {
            case self::MODE_SINGLE:
                $result->data = array_values($this->data)[0];
                break;

            case self::MODE_MULTIPLE:
                $result->data = array_values($this->data);
                break;

            case self::MODE_OTHER:
                // do nothing for this output mode
                break;

            default:
                throw new HTTPException('Error generating output.  Cannot match output mode with data set.', 500, [
                    'code' => '894684684646846816161'
                ]);
        }

        // process included records if there's valid entries only
        if ($this->data && $this->included) {
            $result->included = array_flatten($this->included);
        }
    }
53251
private function parseJson($result)
    {
        $json = json_decode($result, true);
        if (empty($json) || !empty($json['errcode'])) {
            $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
            $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容！';
            return false;
        }
        return $json;
    }
366315
public function checkDirectory($dir, $validationSpec)
    {
        $exists    = file_exists($dir);
        $writable  = $exists && is_writable($dir);
        $missing   = !$exists;
        $creatable = $missing && is_writable(dirname($dir));

        $return = array(
            'exists'    => $exists,
            'writable'  => $writable,
            'missing'   => $missing,
            'creatable' => $creatable
        );

        $return['valid'] = $this->validateDirectory($return, $validationSpec);

        return $return;
    }
590299
public function assertCommandResult($result) {
        $exitCode = $this->getExitCode();

        // Escape % as the callback will pass this value to sprintf() if the assertion fails, and
        // sprintf might complain about too few arguments as the output might contain stuff like %s
        // or %d.
        $output = str_replace('%', '%%', $this->getOutput());

        if ($result === 'fail') {
            $callback = 'notEq';
            $errorMessage = sprintf(
                'Invalid exit code, did not expect 0. Command output: %s',
                $output
            );
        } else {
            $callback = 'eq';
            $errorMessage = sprintf(
                'Expected exit code 0, got %d. Command output: %s',
                $exitCode,
                $output
            );
        }

        Assertion::$callback(0, $exitCode, $errorMessage);
    }
363015
private static function SortByNavIndex(array &$result)
    {
        $sorted = array();
        foreach ($result as $bundle=>$modules)
        {
            ksort($modules);
            $sorted[$bundle] = $modules;
        }
        return $sorted;
    }
775223
public function is_error($result = null)
    {
        if ($result !== null) {
            return $result === false ? $this->db_error_msg : null;
        }

        return $this->db_error ? $this->db_error_msg : null;
    }
486095
public function setSessionValidationResult(ValidationResult $result, $combineWithExisting = false)
    {
        // Combine with existing result
        if ($combineWithExisting) {
            $existingResult = $this->getSessionValidationResult();
            if ($existingResult) {
                if ($result) {
                    $existingResult->combineAnd($result);
                } else {
                    $result = $existingResult;
                }
            }
        }

        // Serialise
        $resultData = $result ? serialize($result) : null;
        $this->getSession()->set("FormInfo.{$this->FormName()}.result", $resultData);
        return $this;
    }
460359
public function validate(&$failed = null)
    {
        $result = $this->getRepository()->getSpace()->validateEntities($failed);
        return !$failed->contains($this);
    }
518653
public function folder_validate($folder, &$char = null)
    {
        if (parent::folder_validate($folder, $char)) {
            $vendor = $this->get_vendor();
            $regexp = '\\x00-\\x1F\\x7F%*';

            if ($vendor == 'cyrus') {
                // List based on testing Kolab's Cyrus-IMAP 2.5
                $regexp .= '!`@(){}|\\?<;"';
            }

            if (!preg_match("/[$regexp]/", $folder, $m)) {
                return true;
            }

            $char = $m[0];
        }

        return false;
    }
47980
private function matchesPath($result, array $acceptor)
    {
        return !($result instanceof ResultInterface)
            ? false
            : $acceptor['expected'] == $result->search($acceptor['argument']);
    }
265780
protected function finishAddOrderCheckout(array $result)
    {
        if (!empty($result['order']['order_id'])) {

            $vars = array(
                '@num' => $result['order']['order_id'],
                '@name' => $result['order']['customer_name'],
                '@status' => $this->order->getStatusName($result['order']['status'])
            );

            $message = $this->text('Order #@num has been created for user @name. Order status: @status', $vars);
            $this->redirect("admin/sale/order/{$result['order']['order_id']}", $message, 'success');
        }
    }
10287
private function validate(Specification $spec)
    {
        if ($spec instanceof Not || $spec instanceof AndX || $spec instanceof OrX) {
            throw new \InvalidArgumentException('Algolia does not allows to negate a group');
        }
    }
590530
protected function processResult($result)
    {
        $output = Helper::objectToArray($result);

        if (! is_array($output)) {
            throw new Error\Api($output);
        }

        if (isset($output['result'])) {
            return $output;
        }

        if (
            isset($output['request']) &&
            $output['request']['result'] != 1 &&
            $output['request']['result'] !== 'TRUE') {
            throw new Error\Api($output['request']['errorId'] . ' - ' . $output['request']['errorMessage']);
        }

        return $output;
    }
179781
private function getErrorMessage(array $result)
    {
        $errorMessage = '';
        if (isset($result['errors'][0]['property']) && isset($result['errors'][0]['message'])) {
            $errorMessage = $result['errors'][0]['property'] . ': ' . $result['errors'][0]['message'];
        }
        return $errorMessage;
    }
845620
protected function finalize($result) {
        $this->eagerLoad = [];
        $this->criteria->reset();
        $this->scope = null;
        return $result;
    }
217979
protected function prepareAccessTokenResponse(array $result)
    {
        if ($this->getAccessTokenResourceOwnerId() !== null) {
            $result['resource_owner_id'] = $this->getValueByKey(
                $result,
                $this->getAccessTokenResourceOwnerId()
            );
        }
        return $result;
    }