Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成余下翻译 #4

Open
wants to merge 7 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<h1 class="site-title"><a href="/php-the-right-way">PHP之道</a></h1>
</hgroup>
翻译:<a href="http://wulijun.github.com" target="_blank">wulijun</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.weibo.com/wulijun01234" target="_blank">关注我的微博</a>
| 补充翻译: <a href="http://horsley.github.com" target="_blank">horsley</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://weibo.com/horsley" target="_blank">关注我的微博</a>
</header>
{{ content }}
<footer class="site-footer" id="site-footer">
Expand Down
20 changes: 8 additions & 12 deletions _posts/01-06-01-Vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ isChild: true

## Vagrant {#vagrant_title}

Running your application on different environments in development and production can lead to strange bugs
popping up when you go live. It's also tricky to keep different development environments up to date with the same
version for all libraries used when working with a team of developers.
在不同的开发环境和生产环境中运行你的应用可能导致一些奇怪的错误在运行时产生。并且让一个团队的开发者的不同的开发环境
保持所有代码库更新到同一个版本也是一个棘手的事情。

If you are developing on Windows and deploying to Linux (or anything non-Windows) or are developing in a team, you
should consider using a virtual machine. This sounds tricky, but using [Vagrant][vagrant] you can set up a simple
virtual machine with only a few steps. These base boxes can then be set up manually, or you can use "provisioning"
software such as [Puppet][puppet] or [Chef][chef] to do this for you. Provisioning the base box is a great way to
ensure that multiple boxes are set up in an identical fashion and removes the need for you to maintain complicated
"set up" command lists. You can also "destroy" your base box and recreate it without many manual steps, making it
easy to create a "fresh" installation.
如果你在Windows上面进行开发并且最终部署在Linux(或其他非Windows平台),又或者你在一个团队中开发,你应该考虑使用一
个虚拟机。听起来很麻烦,但使用 [Vagrant][vagrant] 你可以使用少量步骤简单地建立一个虚拟机。这些基础的系统可以被手工
配置,或者可以使用配置工具例如 [Puppet][puppet] 或者 [Chef][chef] 来为你做这个事情。配置基础系统是一个好方法来确保
多个系统被设置成同一种规范,并且省掉你维护复杂的配置命令列表的工作。你也可以销毁你的基础系统然后使用少数手工步骤来
重建它,让它很容易可以创建一个干净的安装环境。

Vagrant creates shared folders used to share your code between your host and your virtual machine, meaning you can
create and edit your files on your host machine and then run the code inside your virtual machine.
Vagrant 创建共享的文件夹来在你的机器和虚拟机之鉴共享代码,意味着你可以在自己的机器上创建并编辑文件然后在虚拟机中运行。

[vagrant]: http://vagrantup.com/
[puppet]: http://www.puppetlabs.com/
Expand Down
28 changes: 13 additions & 15 deletions _posts/04-03-01-PEAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ isChild: true

另外一个常用的包管理器就是很多PHP开发者喜欢的[PEAR][1],它的运行方式和Composer有些类似,但是也有一些区别.

PEAR requires each package to have a specific structure, which means that the author of the package must prepare it
for usage with PEAR. Using a project which was not prepared to work with PEAR is not possible.
PEAR 要求每个代码包包含一个特定的结构,意味着包的作者必须为了用于PEAR做准备,想在项目中使用没有为PEAR准备
过的代码包是不可能的。

PEAR installs packages globally, which means after installing them once they are available to all projects on that
server. This can be good if many projects rely on the same package with the same version but might lead to problems
if version conflicts between two projects arise.
PEAR 会在全局范围安装代码包,意味着包被安装一次之后,该服务器上面的所有项目都可以使用,如果很多个项目依赖
的是同一个代码包的同一版本这可能会是个好事,但对于使用冲突版本的两个项目可能会引起问题。

### How to install PEAR
### 如何安装 PEAR

You can install PEAR by downloading the phar installer and executing it. The PEAR documentation has detailed
[install instructions][2] for every operating system.
你可以通过下载 phar 安装包并执行它来安装 PEAR。PEAR 的文档包含详细的
[安装指引][2] 适用于各种操作系统。

If you are using Linux, you can also have a look at your distribution package manager. Debian and Ubuntu for example
have a apt ``php-pear`` package.
如果你在使用 Linux, 你也可以查看你的发行版包管理器,如 Debian 和 Ubuntu 就有一个 apt ``php-pear`` 包.

### How to install a package
### 如何安装代码包

If the package is listed on the [PEAR packages list][3], you can install it by specifying the official name:
如果包是位于 [PEAR 代码包列表][3] 上面的, 你可以通过指定官方名称来安装它:

pear install foo

If the package is hosted on another channel, you need to `discover` the channel first and also specify it when
installing. See the [Using channel docs][4] for more information on this topic.
如果包是托管在其他频道的,你需要先 `discover` (发掘)频道然后再指定安装哪个包 。
关于本话题详见 [使用频道的文档][4] 以获取更多信息。

* [Learn about PEAR][1]
* [学习 PEAR][1]

[1]: http://pear.php.net/
[2]: http://pear.php.net/manual/en/installation.getting.php
Expand Down
16 changes: 8 additions & 8 deletions _posts/07-03-01-Password-Hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
isChild: true
---

## Password Hashing {#password_hashing_title}
## 密码哈希 {#password_hashing}

Eventually everyone builds a PHP application that relies on user login. Usernames and passwords are stored in a database and later used to authenticate users upon login.
最终每个人都会需要创建一个依赖用户登录的 PHP 应用。 用户名和密码被存放在数据库以便在后面用户登录的时候用来验证。

It is important that you properly [_hash_][3] passwords before storing them. Password hashing is an irreversible, one way function performed against the users password. This produces a fix length string that can not be feasibly reversed. This means you can compare a hash against another to determine if they both came from the same source string, but you can not determine the original string. If passwords are not hashed and your database is accessed by an unauthorized third-party, all user accounts are now compromised. Some users may (unfortunately) use the same password for other services. Therefore, it is important to take security seriously.
重要的是你应该适当地在存储之前 [_哈希_][3] 密码。 密码哈希是一个不可逆的、单向的函数作用于用户的密码之上。这会产生一个固定长度的字符串让你不可能逆转,意味着你可以比较两个哈希来判断他们是否来自于同一个源字符串,但你不能得到原来的字符串是什么。如果密码没有哈希过并且你的数据库被未授权的第三方访问到,所有用户的账户都会受到影响。有些用户可能(不幸的)在其他服务上使用相同的密码,因此,安全问题需要慎重考虑。

**Hashing passwords with `password_hash`**
**使用 `password_hash` 来哈希密码**

In PHP 5.5 `password_hash` will be introduced. At this time it is using BCrypt, the strongest algorithm currently supported by PHP. It will be updated in the future to support more algorithms as needed though. The `password_compat` library was created to provide forward compatibility for PHP >= 5.3.7.
PHP 5.5 `password_hash` 将会被推出。这次它将使用 BCrypt,这是 PHP 当前支持的最强的算法。这将会根据未来的需要更新来支持更多的算法。`password_compat` 库被创建用于提供 PHP >= 5.3.7 的向前兼容。

Below we hash a string, we then check the hash against a new string. Because our two source strings are different ('secret-password' vs. 'bad-password') this login will fail.
下面我们会哈希一个字符串,然后和另一个新的字符串的哈希作比较。因为我们两个源字符串是不一样的('secret-password' 'bad-password') 这个验证不会通过。

{% highlight php %}
<?php
Expand All @@ -29,9 +29,9 @@ if (password_verify('bad-password', $passwordHash)) {



* [Learn about `password_hash`] [1]
* [学习关于 `password_hash`] [1]
* [`password_compat` for PHP >= 5.3.7 && < 5.5] [2]
* [Learn about hashing in regards to cryptography] [3]
* [学习密码学里面的哈希] [3]
* [PHP `password_hash` RFC] [4]

[1]: http://us2.php.net/manual/en/function.password-hash.php
Expand Down
89 changes: 41 additions & 48 deletions _posts/09-05-01-Building your Application.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,66 @@
isChild: true
---

## Building and Deploying your Application {#build_title}
## 构建及部署你的应用 {#build_title}

If you find yourself doing manual database schema changes or running your tests manually before updating your files
(manually), think twice! With every additional manual task needed to deploy a new version of your app, the chances for
potentially fatal mistakes increase. Whether you're dealing with a simple update, a comprehensive build process or
even a continuous integration strategy, [build automation](http://en.wikipedia.org/wiki/Build_automation) is your
friend.
如果你还在做手工的数据库模式修改或者在更新文件之前(也是手动的)手动进行测试工作,请三思而后行。
伴随每一个额外的手工任务你都需要部署一个你应用的新版本,发生潜在致命错误的机会增加了。
无论你是在处理一个简单的更新、一个复杂的构建过程甚至是使用一个持续集成的策略,
[自动构建](http://en.wikipedia.org/wiki/Build_automation) 都会成为你的朋友。

Among the tasks you might want to automate are:
其中你可能想要自动完成的任务包括:

* Dependency management
* Compilation, minification of your assets
* Running tests
* Creation of documentation
* Packaging
* Deployment
* 依赖管理
* 编译,压缩你的资源文件
* 进行测试
* 文档生成
* 封装打包
* 部署


### Build Automation Tools
### 自动构建工具

Build tools can be described as a collection of scripts that handle common tasks of software deployment. The build
tool is not a part of your software, it acts on your software from 'outside'.
构建工具可以被描述为用于处理软件部署中的常用任务一系列的脚本。构建工具不是你软件的一部分,它在你的软件的外面起作用。

There are many open source tools available to help you with build automation, some are written in PHP others aren't.
This shouldn't hold you back from using them, if they're better suited for the specific job. Here are a few examples:
用很多的开源工具可以用来帮你完成自动构建的工作,有一些是用PHP写的有一些不是。
这不会影响你的使用,如果他们更适合特定任务的话,下面有一些例子:

[Phing](http://www.phing.info/) is the easiest way to get started with automated deployment in the PHP world. With
Phing you can control your packaging, deployment or testing process from within a simple XML build file. Phing (which
is based on [Apache Ant](http://ant.apache.org/)) provides a rich set of tasks usually needed to install or update a
web app and can be extended with additional custom tasks, written in PHP.
[Phing](http://www.phing.info/) 是PHP世界里面最简单的工具可以让你上手使用自动部署。使用 Phing 你可以通过一个简单的
XML构建配置文件控制你的打包、部署或者测试过程。Phing (基于 [Apache Ant](http://ant.apache.org/)) 提供一系列丰富的
任务供你安装或升级一个Web应用,并且可以通过添加额外的自定义任务扩展其功能,通过PHP编写。

[Capistrano](https://github.com/capistrano/capistrano/wiki) is a system for *intermediate-to-advanced programmers* to
execute commands in a structured, repeatable way on one or more remote machines. It is pre-configured for deploying
Ruby on Rails applications, however people are **successfully deploying PHP systems** with it. Successful use of
Capistrano depends on a working knowledge of Ruby and Rake.
[Capistrano](https://github.com/capistrano/capistrano/wiki) 是一个可供 *中高级程序员* 以一种结构化、可复用的方式
在一台或多台远程机器上执行命令的系统。它被预先配置来部署 Ruby on Rails 应用,但人们成功地 **用它来部署PHP系统**
顺利使用 Capistrano 以来一些 Ruby and Rake 的工作知识.

Dave Gardner's blog post [PHP Deployment with Capistrano](http://www.davegardner.me.uk/blog/2012/02/13/php-deployment-with-capistrano/)
is a good starting point for PHP developers interested in Capistrano.
Dave Gardner 的博客文章 [使用 Capistrano 进行PHP 部署](http://www.davegardner.me.uk/blog/2012/02/13/php-deployment-with-capistrano/)
对于对Capistrano感兴趣的PHP开发者来说是一个好的开始点。

[Chef](http://www.opscode.com/chef/) is more than a deployment framework, it is a very powerful Ruby based system
integration framework that doesn't just deploy your app but can build your whole server environment or virtual boxes.
[Chef](http://www.opscode.com/chef/) 不只是一个部署框架,它是一个非常强大的基于 Ruby 的集成框架系统,它不仅
能部署你的应用还能构建你的整个服务器环境或者虚拟主机。

Chef resources for PHP developers:
PHP 开发者的 Chef资源:

* [Three part blog series about deploying a LAMP application with Chef, Vagrant, and EC2](http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/)
* [Chef Cookbook which installs and configures PHP 5.3 and the PEAR package management system](https://github.com/opscode-cookbooks/php)
* [三部分博客系列:关于使用 Chef, Vagrant, EC2 部署一个LAMP应用](http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/)
* [Chef 参考书: 安装配置 PHP 5.3 PEAR 包管理器](https://github.com/opscode-cookbooks/php)

Further reading:
扩展阅读:

* [Automate your project with Apache Ant](http://net.tutsplus.com/tutorials/other/automate-your-projects-with-apache-ant/)
* [Maven](http://maven.apache.org/), a build framework based on Ant and [how to use it with PHP](http://www.php-maven.org/)
* [使用 Apache Ant 自动化你的项目](http://net.tutsplus.com/tutorials/other/automate-your-projects-with-apache-ant/)
* [Maven](http://maven.apache.org/), 一个基于 Ant 的构建框架 和 [如何与 PHP 协同工作](http://www.php-maven.org/)

### Continuous Integration
### 持续集成

> Continuous Integration is a software development practice where members of a team integrate their work frequently,
> usually each person integrates at least daily — leading to multiple integrations per day. Many teams find that this
> approach leads to significantly reduced integration problems and allows a team to develop cohesive software more
> rapidly.
> 持续集成是一种软件开发实践当一个团队里面的成员频繁地集成他们的工作时,通常每个人每天一次到多次集成。
> 许多团队发现这个方法可以显著减少集成问题并且允许一个团队开发拼合应用更加快捷。

*-- Martin Fowler*

There are different ways to implement continuous integration for PHP. Recently [Travis CI](https://travis-ci.org/) has
done a great job of making continuous integration a reality even for small projects. Travis CI is a hosted continuous
integration service for the open source community. It is integrated with GitHub and offers first class support for many
languages including PHP.
在 PHP 中有很多不同方法实现持续集成,最近 [Travis CI](https://travis-ci.org/) 完成了一项伟大的任务使得持续集成变得现实
甚至在一些小项目里边。Travis CI 是一个托管的持续集成服务被用于开源社区。它被集成到 GitHub 并且对许多语言提供一等的支持
其中包括PHP。

Further reading:
扩展阅读:

* [Continuous Integration with Jenkins](http://jenkins-ci.org/)
* [Continuous Integration with Teamcity](http://www.jetbrains.com/teamcity/)
* [使用 Jenkins 持续集成](http://jenkins-ci.org/)
* [使用 Teamcity 持续集成](http://www.jetbrains.com/teamcity/)
23 changes: 15 additions & 8 deletions _posts/12-01-01-Community.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# 社区

The PHP community is as diverse as it is large, and it's members are ready and willing to support new PHP programmers. You should consider joining your local PHP user group (PUG) or attending larger PHP conferences to learn more about the best practices shown here. You can also hang out on IRC in the #phpc channel on irc.freenode.com and follow the [@phpc][phpc-twitter] twitter account. Get out there, meet new developers, learn new topics and, above all, make new friends. Also there is a large Google+ Community for PHP Programmers where 9,000+ PHP Programmers are available to discuss about problem and solving others problem by each other. You can also join there on Google+ community for [PHP Programmer][php-programmers-gplus]
PHP 社区大而多,并且其中的成员都准备好并且愿意支持新的 PHP 开发者。你应该考虑加入你本地的 PHP 用户组 (PUG)
或出席大型的 PHP 会议来学习更多这里展示的最佳实践。你也可以加入 IRC 频道#phpc 在 irc.freenode.com 上
闲逛或者关注 [@phpc][phpc-twitter] 的推特账户。 走出去,结识新的开发者,学习新的主题,结交新的朋友。
同样的还有一个很大的 Google+ 社区有超过9000个PHP程序员讨论问题和互相解决其他人的问题,你也可以加入
[PHP 程序员G+社区][php-programmers-gplus]

[Read the Official PHP Events Calendar][php-calendar]
[阅读PHP官方的事件日历][php-calendar]

## PHP User Groups
## PHP 用户组

If you live in a larger city, odds are there's a PHP user group nearby. Although there's not yet an official list of PUGs, you can easily find your local PUG by searching on [Google][google] or [Meetup.com][meetup]. If you live in a smaller town, there may not be a local PUG; if that's the case, start one!
如果你生活在一个大城市,可能你附近就有一个 PHP 用户组。 虽然他们可能还不是官方名单上面的 PUG,
你也可以通过在 [Google][google] 或者 [Meetup.com][meetup] 上搜索轻易地找到你当地的PUG
如果你生活在一个较小的城市,可能当地还没有PUG,没关系,发起一个吧!

[Read about User Groups on the PHP Wiki][php-wiki]
[PHP 百科上面阅读用户组的相关信息][php-wiki]

## PHP Conferences
## PHP 会议

The PHP community also hosts larger regional and national conferences in many countries around the world. Well-known members of the PHP community usually speak at these larger events, so it's a great opportunity to learn directly from industry leaders.
PHP社区也会在世界上许多国家举办一些大型的区域性的或者国际的会议,知名的PHP社区成员通常会在大型活动中演讲,
所以这是个直接从工业领袖中学习的好机会。

[Find a PHP Conference][php-conf]
[查找PHP会议][php-conf]

[php-calendar]: http://www.php.net/cal.php
[google]: https://www.google.com/search?q=php+user+group+near+me
Expand Down