code verifier用のランダム文字列を生成します。

@throws	\ErrorException	code verifierの生成に失敗した場合
@return	string	code verifier
9024
protected function generateCodeVerifier () {
		$sp		= ['-'. '/', '_',  '~'];
		$length	= random_int(43, 128);
		$stack	= [];

		for ($i = 0;$i < $length;$i++) {
			switch (random_int(1, 4)) {
				case 1:
					$stack[] = chr(random_int(0x30, 0x39));
					break;
				case 2:
					$stack[] = chr(random_int(0x41, 0x5A));
					break;
				case 3:
					$stack[] = chr(random_int(0x61, 0x7A));
					break;
				case 4:
					$stack[] = $sp[random_int(0, 3)];
					break;
			}
		}

		if (count($stack) !== $length) {
			throw new \ErrorException('code verifierの作成に失敗しました。');
		}

		return $this->codeVerifier = implode('', $stack);
	}
107248
protected function generateCode()
    {
        $answer = '';
        if ($this->type == "1") {
            $code   = md5(time());
            $code   = substr($code, rand(3, 5), $this->length);
            $code   = str_replace(['2', '0', 'o', '1', 'i'], ['Z', '9', '8', 'L', 'A'], $code);
            $code   = strtoupper($code);
            $answer = $code;
        } else {
            $operate               = ['+', '-'];
            $opindex               = rand(0, 1);
            $opnum1                = rand(0, 9);
            $opnum2                = rand(0, 9);
            list($opnum1, $opnum2) = ($opindex == 1 ? [max($opnum1, $opnum2), min($opnum1, $opnum2)] : [$opnum1, $opnum2]);
            $code                  = $opnum1 . $operate[$opindex] . $opnum2 . '=?';
            $answer                = $opindex == 1 ? ($opnum1 - $opnum2) : ($opnum1 + $opnum2);
        }
        return [$code, $answer];
    }
1346733
protected function getErrorMessage($errorCode)
    {
        if (!isset($this->errorMessageMatrix[$errorCode])) {
            $this->errorMessageMatrix[$errorCode] = 'ERROR_MSG_UNKNOWN';
        }

        // if additional information exist -> add it here
        if ($this->info) {
            if (is_string($this->info)) {
                $this->errorMessageMatrix[$errorCode] .= ' '.$this->info;
            } elseif (count($this->info) != 1 || $this->info[0] != null) {
                foreach ($this->info as $info) {
                    $info = serialize($info);
                    $this->errorMessageMatrix[$errorCode] .= ' '.$info;
                }
            }
        }

        // Return constructed error message
        return $this->errorMessageMatrix[$errorCode];
    }
19048
protected function generateVerifyCode()
	{
		if($this->minLength > $this->maxLength)
			$this->maxLength = $this->minLength;
		if($this->minLength < 3)
			$this->minLength = 3;
		if($this->maxLength > 20)
			$this->maxLength = 20;
		$length = mt_rand($this->minLength,$this->maxLength);

		$letters = 'bcdfghjklmnpqrstvwxyz';
		$vowels = 'aeiou';
		$code = '';
		for($i = 0; $i < $length; ++$i)
		{
			if($i % 2 && mt_rand(0,10) > 2 || !($i % 2) && mt_rand(0,10) > 9)
				$code.=$vowels[mt_rand(0,4)];
			else
				$code.=$letters[mt_rand(0,20)];
		}

		return $code;
	}
985494
private function generate_code()
    {
        $length = rand($this->min_length, $this->max_length);
        $numChars = strlen($this->chars);

        $str = [];
        for ($i = 0; $i < $length; $i++) {
            $str[] = substr($this->chars, rand(1, $numChars) - 1, 1);
        }
        $str = implode('', $str);

        // Mix string
        $array_mix = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
        srand(microtime(true));
        shuffle($array_mix);

        return implode('', $array_mix);
    }
755921
protected function _getCancelCode()
    {
        if (!$this->has('password') && !$this->has('id')) {
            throw new FatalErrorException(__d('user', 'Cannot generated cancel code for this user: unknown user ID.'));
        }

        if (!$this->has('password')) {
            $password = TableRegistry::get('User.Users')
                ->get($this->id, ['fields' => ['password']])
                ->get('password');
        } else {
            $password = $this->password;
        }

        return Security::hash($password, 'md5', true);
    }
1112662
public function getMessage()
    {
        switch ($this->code) {
            case self::LOAD_FAILED:
                return $this->extraDetails;
            case self::SCHEMA_VIOLATION:
                return $this->extraDetails;
            case self::FIELD_VALIDATION:
                $field = $this->extraDetails['field'];
                $error = $this->extraDetails['error'];
                $value = json_encode($this->extraDetails['value']);

                return "{$field}: {$error} ({$value})";
            case self::ROW_FIELD_VALIDATION:
                $row = $this->extraDetails['row'];
                $field = $this->extraDetails['field'];
                $error = $this->extraDetails['error'];
                $value = $this->extraDetails['value'];

                return "row {$row} {$field}: {$error} ({$value})";
            case self::ROW_VALIDATION:
                $row = $this->extraDetails['row'];
                $error = $this->extraDetails['error'];

                return "row {$row}: {$error}";
            default:
                throw new \Exception("Invalid schema validation code: {$this->code}");
        }
    }
850954
final protected function writeFileError():int
    {
        $e = JsonListener::open(FEnv::get("framework.config.core.config.file"));
        if (empty($e)) {
            throw new Server500(new \ArrayObject(
                array("explain" => "Framework Config file is empty : cannot generate this error [".$this->code."]",
                "solution" => "Set a valid Framework Config file")
            ));
        }
        if (isset($e->{"200_log"}) && is_bool($e->{"200_log"}) && $e->{"200_log"} == false) {
            return (1);
        }

        $h = (new \DateTime())->format("Y-m-d H:i:s");
        $code = 200;
        $d1 = "[";
        $d2 = "]";
        $debug = array();
        $debug['time'] = $d1.$h.$d2;
        $debug["uidie"] = $d1.ToolsExceptions::generateUidie().$d2;
        $debug['client_ip'] = $d1.ToolsExceptions::getClientIp().$d2;
        $debug['code'] = $d1.$code.$d2;
        $debug['code_title'] = $d1.HttpResponse::getPhrase(200).$d2;
        $debug['explain'] = $d1."OK".$d2;
        $debug['solution'] = $d1."OK".$d2;
        $debug['env'] = $d1.FEnv::get("framework.env").$d2;
        $debug['method'] = $d1.$_SERVER['REQUEST_METHOD'].$d2;
        $debug['uri'] = $d1.$_SERVER['REQUEST_URI'].$d2;

        $debug['referer'] = $d1.(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null).$d2;

        $strlog =  implode(" ", $debug);
        $f = new FileListener();
        $f->open(
            FEnv::get("framework.logs").strtolower(FEnv::get("framework.env")).".log",
            "a+",
            true
        );
        $f->put($strlog);
        $f->close();
        return (1);
    }
1156656
public static function fileUploadErrorText($error_code): string
    {
        switch ($error_code) {
            case UPLOAD_ERR_OK:
                return I18N::translate('File successfully uploaded');
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('The uploaded file exceeds the allowed size.');
            case UPLOAD_ERR_PARTIAL:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('The file was only partially uploaded. Please try again.');
            case UPLOAD_ERR_NO_FILE:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('No file was received. Please try again.');
            case UPLOAD_ERR_NO_TMP_DIR:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('The PHP temporary folder is missing.');
            case UPLOAD_ERR_CANT_WRITE:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('PHP failed to write to disk.');
            case UPLOAD_ERR_EXTENSION:
                // I18N: PHP internal error message - php.net/manual/en/features.file-upload.errors.php
                return I18N::translate('PHP blocked the file because of its extension.');
            default:
                return 'Error: ' . $error_code;
        }
    }
1244880
public function errorCode()
    {
        if (!$this->_stmt) {
            return false;
        }

        $error = oci_error($this->_stmt);

        if (!$error) {
            return false;
        }

        return $error['code'];
    }
1003804
protected function getError() {
		if ($this->_error === false) {
			if (is_resource($this->stmt)) {
				$this->_error = @oci_error($this->stmt);
			}
			else {
				$this->_error = @oci_error();
			}
		}

		return $this->_error;
	}
330197
public function init()
    {
        if (empty($this->rawFiles)) {
            throw new ErrorException('No file specified; make sure you are using the correct .htaccess rules.');
        }

        // Handle legacy code for minifying
        if (preg_match('%^/minify/%', $this->rawFiles)) {
            $this->rawFiles = substr($this->rawFiles, 7);
            $this->setRawParam('minify', 'true');
        }

        $this->ext = strtolower(pathinfo($this->rawFiles, PATHINFO_EXTENSION));
        $supportedExtensions = Registry::getSupportedExtensions($this->ext);
        // Suppressing errors because Exceptions thrown in the callback cause Warnings.
        $webroot = $this->webroot;
        $this->files = @array_map(function($v) use ($supportedExtensions, $webroot) {
            // Make sure all the file extensions are supported
            if (! in_array(strtolower(pathinfo($v, PATHINFO_EXTENSION)), $supportedExtensions)) {
                throw new ErrorException('All requested files need to be: ' . implode(', ', $supportedExtensions));
            }
            // Strip any parent directory slugs (../) - loop through until they are all gone
            $count = 1;
            while ($count > 0) {
                $v = preg_replace('%(/\\.\\.?|\\.\\.?/)%', '', $v, -1, $count);
                // If there is no slash prefix, add it back in
                if (substr($v, 0, 1) != '/') {
                    $v = '/' . $v;
                }
            }

            // Remove sub-folder if in the path, it shouldn't be there.
            $v = str_replace(SUB_FOLDER, '', $v);

            return $webroot . $v;
        }, explode(',', $this->rawFiles));
    }
585607
public function generateCode()
    {
        $refClass = new ReflectionClass($this->className);
        $this->finalClassesCanNotBeMocked($refClass);

        $this->methods = array();
        $this->makeAllAbstractMethodsThrowException($refClass);
        if (!$this->niceMock || $refClass->isInterface()) {
            $this->makeAllMethodsThrowException($refClass);
        }
        $this->renderRules();
        $this->renderConstructor();
        $this->renderClone();
        $this->exposeMethods();
        $this->setUpGetCallsForMethod();

        $code = $this->getNamespaceCode();
        $methods = implode("\n", $this->methods);
        $superWord = $this->getSuperWord($refClass);

        $class = "class {$this->getMockName()} $superWord \\{$this->className}";
        if ('implements' === $superWord) {
            $class .= ', ';
        } else {
            $class .= ' implements ';
        }
        $class .= '\Concise\Mock\MockInterface';

        return $code .
        "$class { public static \$_methodCalls = array(); $methods }";
    }
1267873
public function getError()
    {
        $oOut       = new \stdClass();
        $oOut->msg  = $this->sErrorMsg;
        $oOut->code = $this->sErrorCode;
        $oOut->user = $this->sErrorUser;

        return $oOut;
    }
558742
protected function validateEncoding(): string
    {
        if (function_exists('mb_check_encoding')
            && mb_check_encoding($this->value, 'UTF-8')
        ) {
            return $this->value;
        }

        return function_exists('iconv')
            ? iconv('utf-8', 'utf-8', $this->value)
            : '';
    }
183595
public function getErrorsAsString(): string
    {
        $errors = $this->getErrors();
        if (0 === $errors->count()) {
            return '';
        }
        $message = 'found ' . $errors->count() . ' errors validating '
                   . \get_class($this->dataObject);
        foreach ($errors as $error) {
            $message .= "\n\n" . $error->getPropertyPath() . ': ' . $error->getMessage();
        }

        return $message;
    }
497792
protected function generate_error($ex, $faultcode = 404) {
        $error = $ex->getMessage();

        if (!empty($ex->errorcode)) {
            // The faultCode must be an int, so we obtain a hash of the errorcode then get an integer value of the hash.
            $faultcode = base_convert(md5($ex->errorcode), 16, 10);

            // We strip the $code to 8 digits (and hope for no error code collisions).
            // Collisions should be pretty rare, and if needed the client can retrieve
            // the accurate errorcode from the last | in the exception message.
            $faultcode = substr($faultcode, 0, 8);

            // Add the debuginfo to the exception message if debuginfo must be returned.
            if (debugging() and isset($ex->debuginfo)) {
                $error .= ' | DEBUG INFO: ' . $ex->debuginfo . ' | ERRORCODE: ' . $ex->errorcode;
            } else {
                $error .= ' | ERRORCODE: ' . $ex->errorcode;
            }
        }

        $fault = array(
            'faultCode' => (int) $faultcode,
            'faultString' => $error
        );

        $encodingoptions = array(
            "encoding" => "UTF-8",
            "verbosity" => "no_white_space",
            // See MDL-54868.
            "escaping" => ["markup"]
        );

        return xmlrpc_encode_request(null, $fault, $encodingoptions);
    }