Jetsong 发布的文章

掩码控制权限

<< : 左移运算符,num << 1,相当于num乘以2

: 右移运算符,num >> 1,相当于num除以2

: 无符号右移,忽略符号位,空位都以0补齐

异或(^ ): 一句话,相异为真 返回 boolean

与(&): 只有两位都为 1 则为真 ,0001 & 0101 也就是 0001

或(|): 只要两位有一位 为真则为真, 0001 | 0100,也就是0101

非(~): 对自身取反。

增 1<<0 2的0次方 0001
删 1<<1 2的1次方 0010
改 1<<2 2的2次方 0100
查 1<<3 2的3次方 1000

添加权限时: current | permissions
删除权限时: current &= ~permissions
验证是否有权限时 (current & permissions)>0

1.composer create-project composer/satis
2.vi satis.json
{

    "name": "composer/jetsong",
    "homepage": "http://satis.jetsong.top",
    "repositories": [{
            "type": "vcs",
            "url": "http://gitlab.sdjian.com:31001/php-base-server/facade/comment-like-base.git"
    }],
    "require": {
            "facade/comment-like-base": "*"
    },
    "require-dependencies": true,
    "archive": {
            "directory": "dist",
            "format": "tar",
            "prefix-url": "http://satis.jetsong.top",
            "skip-dev": true
    },
    "config": {
            "secure-http": false
    }

}
3.php bin/satis build satis.json public/
4.开启服务
server {

listen       31005;
server_name  127.0.0.1;

access_log  /data/logs/nginx/satis.access.log  main;
error_log /data/logs/nginx/satis.error.log;
root   /data/composer/satis/public;

location / {
    index  index.html index.php;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}

location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi.conf;
}

}
5.使用仓库
{

"repositories":[
    {
        "type":"composer",

"url": "http://satis.jetsong.top"

    }
],

"require": {

    "facade/comment-like-base": "*"
},
"config":{
    "secure-http": false
}

}

How do I install untrusted packages safely? Is it safe to run Composer as superuser or root?#

Certain Composer commands, including exec, install, and update allow third party code to execute on your system. This is from its "plugins" and "scripts" features. Plugins and scripts have full access to the user account which runs Composer. For this reason, it is strongly advised to avoid running Composer as super-user/root.

You can disable plugins and scripts during package installation or updates with the following syntax so only Composer's code, and no third party code, will execute:

composer install --no-plugins --no-scripts ...
composer update --no-plugins --no-scripts ...
The exec command will always run third party code as the user which runs composer.

In some cases, like in CI systems or such where you want to install untrusted dependencies, the safest way to do it is to run the above command.

反射是指在PHP运行状态中,扩展分析PHP程序,导出或者提取出关于类、属性、方法、参数等的详细信息,包括注释。这种动态获取信息以及动态调用对象方法的功能,被称为反射API。

//获取对象的属性列表
$reflect = new ReflectionObject($stu);
$props = $reflect->getProperties();
foreach ($props as $key_p => $value_p) {

var_dump($value_p->getName());

}
//获取对象的方法列表
$method = $reflect->getMethods();
foreach ($method as $key_m => $value_m) {

var_dump($value_m->getName());

}
1、反射可以用于文档、文件生成。可以用它对文件里的类进行扫描,逐个生成描述文档;
2、既然反射可以探知类的内部结构,那么可以用它做hook实现插件功能;
3、可以用于做动态代理,在未知或者不确定类名的情况下,动态生成和实例化一些类和执行方法;
4、对于多次继承的类,我们可以通过多次反射探索到基类的结构,或者采用递归的形式反射,实现实例化所有继承类,这即是PHP依赖注入的原理。

优点
1、支持反射的语言提供了一些在低级语言中难以实现的运行时特性。
2、可以在一定程度上避免硬编码,提供灵活性和通用性,解耦。
3、可以作为一个第一类对象发现并修改源代码的结构(如代码块、类、方法、协议等)。
4、可以在运行时像对待源代码语句一样计算符号语法的字符串(类似JavaScript的eval()函数),进而可将跟class或function匹配的字符串转换成class或function的调用或引用。
5、可以创建一个新的语言字节码解释器来给编程结构一个新的意义或用途。
劣势
1、此技术的学习成本高。面向反射的编程需要较多的高级知识,包括框架、关系映射和对象交互,以利用更通用的代码执行。
2、同样因为反射的概念和语法都比较抽象,过多地滥用反射技术会使得代码难以被其他人读懂,不利于合作与交流。
3、由于将部分信息检查工作从编译期推迟到了运行期,此举在提高了代码灵活性的同时,牺牲了一点点运行效率。
4、通过深入学习反射的特性和技巧,它的劣势可以尽量避免,但这需要许多时间和经验的积累。

in_array 是通过遍历数组来进行判断的 时间复杂度是O(n),当数组很庞大时非常耗时
优化:
1.将数组key,val转换 array_flip,使用 isset来判断 时间复杂度是O(1)
2.将数组转换为字符串用 strpos来判断