guiyumin 发布的文章

If you look at https://cli.vuejs.org/guide/cli-service.html it tells you that after installing @vue/cli-service ( which may be part of the standard CLI installation ) then vue-cli-service is available in npm scripts, but that if you want to access it directly then you need to use ./node_modules/.bin/vue-cli-service This worked for me, and I guess you could add ./node_modules/.bin to your $PATH if you were so inclined.

- 阅读剩余部分 -

Title: How to verify json web token (jwt) signature by using PHP native functions?

class Jsonwebtoken()
{
   public static function verify(string $token)
    {
        /**应该学习firebase jwt lib,做大量错误处理 */
        $tokenParts = explode('.', $token);
        list($headb64, $bodyb64, $cryptob64) = $tokenParts;

        /** both work */
        $pubKey = openssl_get_publickey('file://'.__DIR__.'/jwtRS256.key.pub');
        // $pubKey = file_get_contents(__DIR__.'/jwtRS256.key.pub');

        $signature = self::urlsafeB64Decode($cryptob64); // from Google Firebase JWT lib

        $isVerified = openssl_verify("$headb64.$bodyb64", $signature, $pubKey, OPENSSL_ALGO_SHA256);

        return $isVerified === 1; // openssl_verify return value is int
    }

    /**
     * Decode a string with URL-safe Base64.
     *
     * @param string $input A Base64 encoded string
     *
     * @return string A decoded string
     */
    public static function urlsafeB64Decode(string $input)
    {
        $remainder = strlen($input) % 4;
        if ($remainder) {
            $padlen = 4 - $remainder;
            $input .= str_repeat('=', $padlen);
        }
        return base64_decode(strtr($input, '-_', '+/'));
    }
}

- 阅读剩余部分 -

<?php
$my_array = array("Dog","Cat","Horse");

list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
// I have several animals, a Dog, a Cat and a Horse.
?>

这个函数有点意思, 和ES6里面的 ...Array有点像。
补充
这个函数的问题是,如果左边的$my_array比如只有2个元素,也就是是说count($my_array) ===2,这种情况就会导致报错,因为数组越界了。所以应该增加一定的校验和错误处理。

$model->save()的时候,如果不符合rules,会导致保存失败,但不抛出异常,所以这个时候,就需要看一下是不是rules设置的问题,所以可以这样做:

$model->save(false)

这样做,就是绕过了rules里对数据的validation,首先保证了,你对数据库的CRUD是成功的,代码是OK的,然后再看,是否是数据的问题。

Statements That Cannot Be Rolled Back

Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines.

You should design your transactions not to include such statements. If you issue a statement early in a transaction that cannot be rolled back, and then another statement later fails, the full effect of the transaction cannot be rolled back in such cases by issuing a ROLLBACK statement.

这个是摘自MySQL文档,8.0和5.7都是同样的文档。但据说PostgreSQL没有这样的问题,还没测试。