Composer 是一个 PHP 依赖管理程序。可以按照下面的步骤以全局方式安装到 Linux 系统。
- 第一步:下载 composer.phar
1 | cd /tmp |
- 第二步:移动到全局目录
1 | mv composer.phar /usr/local/bin/composer |
现在能够以全局方式在命令行中执行 composer
Composer 是一个 PHP 依赖管理程序。可以按照下面的步骤以全局方式安装到 Linux 系统。
1 | cd /tmp |
1 | mv composer.phar /usr/local/bin/composer |
现在能够以全局方式在命令行中执行 composer
标题写成常规,非规范,是由于只要没有语法错误,如何写代码本身就是编码者的一个喜好而已,但是好的习惯有助于提高可读性,减少错误,尤其提高团队合作的效率。
下面内容搜集了业内顶级开发者的习惯,来源见底部附录。
所有 javascript 文件根据依赖关系,按序放置在 <body>
结束标签前。
原因:
tab
(A .. Z, a .. z)
,10个数字(0 .. 9)
,下划线(_)
。不要使用 $ (dollar sign)
或 \ (backslash)
1 | var MESSAGE_TYPE_BROADCAST = 0, // 全局变量 |
var
应该是 Function
第一行语句变量名遵守驼峰(camelCase)规则
1 | var currentEntry, // currently selected table entry |
立即执行的方法使用小括号封装
1 | var collection = (function () { |
1 | if (condition) { |
1 | for (initialization; condition; update) { |
1 | while (condition) { |
1 | do { |
Unlike the other compound statements, the do statement always ends with a ; (semicolon).
1 |
|
每一组必须有结束代码:break, return, or throw
1 |
|
不要使用
不要使用
不要使用
Javascript编程风格
Code Conventions for the JavaScript Programming Language
Google JavaScript Style Guide
RootController
1 | class UserController extends RootController // 类后缀为 Controller |
1 | public function loginAction () {...} // Action 后缀为 Action |
1 | high-school -> highSchoolAction |
RootModel
1 | class UserModel entends RootModel //类后缀为 Model |
1 | public function calculateScore () {...} |
1 | views/<Controller>/<action>.tpl.php |
Controller
,首字母大写action
,首字母小写引用 xdebug 的文档:Communication Set-up
当远程调试时,xdebug 充当着客户端的角色,而 IDE 像是服务器,它会侦听调试端口,就是默认的9000,等待 xdebug 建立远程调试的连接。如下图所求:
当使用匿名IP时,是通过配置 xdebug.remote_connect_back,工作流程像下图所求:
当有了侦听端口的机制,那他们是如何配合起来工作的呢?
HTTP Debug Sessions
Xdebug 是依靠 cookies 来跟踪来自浏览器的请求. 工作流程是这样:
XDEBUG_SESSION_START=name
, 当有请求参数时会忽略 XDEBUG_SESSION
cookies 的值。XDEBUG_SESSION
当xdebug检测到 XDEBUG_SESSION_START
或 XDEBUG_SESSION
时,会尝试连接调用的客户端
当xdebug检测到 XDEBUG_SESSION_STOP
时,会终止调试。
首先安装 xdebug 模块
1 | sudo pecl install xdebug |
配置 php.ini
:
1 | [xdebug] |
更多配置参数请查看:XDebug 参数列表
如何知道配置成功了?
通过 phpinfo()
,如何看到启动的模块中包含 xdebug 信息,且配置如上面所示,则表示成功了。
这里使用 phpstrom。
配置 phpstorm 的侦听端口:
启动侦听端口
(可选)安装浏览器插件,设置idekey
如果你使用不同的IDE调试,每个IDE的key是不一样的,你可以通过安装浏览器插件,让它配置key并插入cookies,比如chrome插件xdebug helper
如何知道IDE配置成功了?
通过 terminal,执行 sudo lsof -n -i4TCP:9001 | grep LISTEN
,如果看到IDE在侦听该端口,则表示成功了。
设置断点,然后浏览器打开要调试的url。
1 | sudo lsof -n -i4TCP:$PORT | grep LISTEN |
lsof is a command meaning “list open files”, which is used in many Unix-like systems to report a list of all open files and the processes that opened them.
1 | sudo vi /etc/hosts |
注意 ::1
的写法:
如果地址中出现连续的0,则可以用“::”号来压缩(称为零压缩),进一步简化IP v6地址表示。例如,地址FE80:0:0:0:2AA:FF:FE9A:4CA2 可以压缩成FE80::2AA:FF:FE9A:4CA2;FF02:0:0:0:0:0:0:2 可以压缩成 FF02::2。零压缩只能用于压缩冒号十六进制地址中一个连续的16位块,不能压缩部分16位信息块,例如,不能将FF02:30:0:0:0:0:0:5 表示成 FF02:3::5。用 :: 表示0位的数量用(8-n)×16公式来计算,其中n为地址中的16位块的数量。例如,在地址FF02::2中,被压缩了96=(8-2)×16个0。零压缩只能在给定地址中使用一次,否则,就无法确定每个双冒号 (::)实例所表示的 0位数量。
特殊地址。IP v6中有两个特殊地址:
- 未指定地址(0:0:0:0:0:0:0:0 或::):仅用于指出某个地址不存在,它等价于 IP v4 未指定地址0.0.0.0。未指定地址通常作为源地址来验证暂定地址的惟一性,但不会用作目的地址。
- 环回地址(0:0:0:0:0:0:0:1或::1):用来标识环回接口,允许节点自发自收,它等价于IP v4环回地址 127.0.0.1。
1 | find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs wc -l |
1 | find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l |
1 | ps aux|grep "Application Name" |
1 | top -o cpu |
1 | top -o rsize |
chrome/browser/extensions/event_names.h
添加
1 | namespace event_names { |
chrome/browser/extensions/event_names.cc
添加
1 | namespace event_names { |
chrome\common\extensions\api\wintrust.json
添加
1 | [{ |
content\public\browser\notification_types.h
添加
1 | enum NotificationType { |
chrome/browser/extensions/browser_event_router.cc
添加绑定
1 | BrowserEventRouter::BrowserEventRouter(Profile* profile) |
实现回调
1 | void BrowserEventRouter::Observe(int type, |
在某个合适和需要的位置以下列的代码触发 NOTIFICATION_LOGIN_BY_CERT_COMPLETE
事件
1 | + std::string detail("false"); |
在扩展的 manifest
里首先声明对 wintrust
命名空间的权限
1 | "permissions": [ |
绑定事件回调函数
1 | chrome.wintrust.onLoginByCertComplete.addListener(function(success){ |
新建描述文件
创建 chrome\common\extensions\api\wintrust.json
添加接口描述代码:
1 | [ |
添加新文件到 GYP
打开 src\chrome\common\extensions\api\api.gyp
, 添加:
1 | ... |
添加新文件到 grd
打开 src\chrome\common\extensions_api_resources.grd
,添加
1 | <?xml version="1.0" encoding="UTF-8"?> |
新建头文件和实现文件
创建 src\chrome\browser\extensions\api\wintrust\wintrust_api.h
和 src\chrome\browser\extensions\api\wintrust\wintrust_api.cc
添加新文件到 GYP
打开 src\chrome\chrome_browser_extensions.gypi
, 添加:
1 | 'sources': [ |
实现 wintrust_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include "chrome/browser/extensions/extension_function.h"
namespace extensions {
class WintrustVersionDirectoryFunction : public SyncExtensionFunction {
public:
WintrustVersionDirectoryFunction();
virtual bool RunImpl() OVERRIDE;
protected:
virtual ~WintrustVersionDirectoryFunction(){};
private:
DECLARE_EXTENSION_FUNCTION("wintrust.versionDirectory", WINTRUST_VERSIONDIRECTORY);
};
}
wintrust_api.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "chrome/browser/extensions/api/wintrust/wintrust_api.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "chrome/browser/profiles/profile.h"
namespace extensions{
WintrustVersionDirectoryFunction::WintrustVersionDirectoryFunction(){}
bool WintrustVersionDirectoryFunction::RunImpl() {
base::FilePath path;
PathService::Get(base::DIR_MODULE, &path);
scoped_ptr<base::StringValue> value (base::Value::CreateStringValue(path.value().c_str()));
SetResult(value.release());
return true;
}
}
执行 python build\gyp_chromium
src\chrome\browser\extensions\extension_function_histogram_value.h
添加下面代码, 转换示例: Example: "tabs.create" -> TABS_CREATE
1 | enum HistogramValue { |
src\chrome\browser\extensions\extension_function_registry.cc
添加下面代码
1 | // 赢达信客户端接口 |
定义该接口可用于的扩展程序类型:
打开 src\chrome\common\extensions\api\_permission_features.json
添加下面代码, extension_types
定义了哪些类型的扩展可以使用新接口。
1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
定义权限的键名,该常量也显示到 manifest permission
中
打开 src\chrome\common\extensions\permissions\api_permission.h
,添加
1 | enum ID { |
实现该键名
打开 src\chrome\common\extensions\permissions\chrome_api_permissions.cc
,添加
1 | std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions() |
创建扩展 manifest
文件
1 | { |
创建扩展 manifest
文件
1 | chrome.wintrust.versionDirectory(function(path){ |