Hướng dẫn pear php standard - lê php tiêu chuẩn

Pear là viết tắt của "Kho lưu trữ ứng dụng và mở rộng PHP" và được phát âm giống như trái cây. Mục đích của lê là cung cấp:PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide: PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide:

Nội dung chính

  • Tuyên bố sứ mệnh lê
  • Các thư viện và ứng dụng có cấu trúc của mã PHP
  • Phân phối mã và bảo trì gói
  • Thư viện cộng đồng mở rộng PHP (PECL)
  • " Nó là gì?
  • »Hot Off The Press
  • Cộng đồng lê
  • Cần giúp đỡ?
  • Thư viện Pear DB trong PHP là gì?
  • Làm thế nào để tôi biết nếu PEAR PHP được cài đặt?
  • Quả lê trong xampp là gì?
  • Quả lê và PECL là gì?

  • Một thư viện có cấu trúc mã nguồn mở cho người dùng PHP
  • Một hệ thống phân phối mã và bảo trì gói
  • Một kiểu tiêu chuẩn cho mã được viết bằng PHP, được chỉ định ở đây
  • Thư viện cộng đồng mở rộng PHP (PECL), xem thêm bên dưới
  • Một trang web, danh sách gửi thư và tải xuống gương để hỗ trợ cộng đồng PHP/lê

Pear là một dự án dựa trên cộng đồng được điều chỉnh bởi các nhà phát triển của nó. Các cơ quan cai trị của Pear được chia thành nhóm lê, tập thể và một tổng thống. Hiến pháp Pear (được thông qua vào tháng 3 năm 2007) xác định các nhóm này được ghi nhận ở đây. Dự án lê được thành lập vào năm 1999 bởi Stig S. Bakken và khá nhiều người đã tham gia dự án.

Tuyên bố sứ mệnh lê

Các thư viện và ứng dụng có cấu trúc của mã PHP

Các thư viện và ứng dụng có cấu trúc của mã PHP

Phân phối mã và bảo trì góipackages". Each package is a separate project with its own development team, version number, release cycle, documentation and a defined relation to other packages (including dependencies). Packages are distributed as gzipped tar files with a description file inside, and installed on your local system using the PEAR installer.

Thư viện cộng đồng mở rộng PHP (PECL)HTTP_Post" is by default independent of "HTTP". Dependencies between packages with similar names is not forbidden, and does happen. As an example,the "DB_DataObject" package depends on the "DB" package.

" Nó là gì?

Phân phối mã và bảo trì gói

Thư viện cộng đồng mở rộng PHP (PECL)channels" also distribute packages that can be installed by the PEAR Installer, see the Channels list for more information. pear.php.net does not endorse the packages from these channels, and only provides support for packages distributed from pear.php.net.

" Nó là gì?

  • »Hot Off The Press
  • Cộng đồng lê
  • Cần giúp đỡ?

Thư viện Pear DB trong PHP là gì?

Thư viện cộng đồng mở rộng PHP (PECL)

" Nó là gì?

»Hot Off The Presspickle") is a separate project that distributes PHP extensions (compiled code written in C, such as the PDO extension). PECL extensions are also distributed as packages and can be installed using the PEAR installer with the pecl command.

Thông tin thêm và tất cả các gói PECL hiện có thể được tìm thấy trên trang chủ PECL.

" Nó là gì?

PEAR là một hệ thống khung và phân phối cho các thành phần PHP có thể tái sử dụng.

Nghe có vẻ tốt? Có lẽ bạn có thể muốn biết về việc cài đặt lê trên hệ thống của mình hoặc cài đặt các gói lê.installing PEAR on your system or installing pear packages.

Bạn có thể tìm thấy trợ giúp bằng cách sử dụng các gói lê trong hướng dẫn trực tuyến và Câu hỏi thường gặp.

Nếu bạn đã được các nhà phát triển PET khác nói với một tài khoản trang web PEAR, bạn có thể sử dụng giao diện này.

»Hot Off The Press

Có vẻ như chúng tôi không có nguồn cấp dữ liệu RSS. Thử thêm một công việc cron để tìm nạp http://blog.pear.php.net/feed/ và đặt nó vào /var/tmp/pear/rss_cache/pear-news.xml

wget --output-document=/var/tmp/pear/rss_cache/pear-news.xml http://blog.pear.php.net/feed/

Cộng đồng lê

Cần giúp đỡ?

Bạn có thể tìm thấy sự giúp đỡ và hỗ trợ trên danh sách gửi thư của chúng tôi và kênh IRC.

Các nhà phát triển của chúng tôi cũng đang sử dụng LinkedIn, OpenHub, Twitter cũng như Wiki.

Nếu bạn là một lập trình viên PHP, bạn có thể sẽ gặp Pear. PEAR là viết tắt của kho mở rộng và kho ứng dụng, một thư viện các thành phần PHP có thể tái sử dụng, được xây dựng theo cùng một tiêu chuẩn, có thể được sử dụng trong bất kỳ dự án nào.PHP Extension and Application Repository, a library of reusable PHP components, built under the same standard, that can be used in any project.

Pear được phát hành lần đầu tiên vào năm 1999, và trong một thời gian dài, người quản lý phụ thuộc chính thức thực tế cho PHP. Nhưng, hiện tại, được coi là không phản hồi, và người quản lý phụ thuộc cầm quyền hiện là nhà soạn nhạc. Vì vậy, rất quan trọng để hiểu rằng PEAR không nên được sử dụng cho các dự án mới. Nhưng, ngay cả khi nó không được chấp nhận, mọi nhà phát triển PHP phải biết cách sử dụng nó, và đây là những gì hướng dẫn này sẽ hiển thị.

 


For this tutorial, we will use:

  • Ubuntu (14.04) as Operating System.
  • Apache HTTP server (2.4.7).
  • PHP (5.5.9).
  • PEAR 1.10.1
Tip
You may skip environment preparation and jump directly to the beginning of the tutorial below.

1. Preparing the environment

1.1. Apache and PHP

Below, commands to install Apache and PHP are show:

sudo apt-get update sudo apt-get install apache2 php5
libapache2-mod-php5 sudo service apache2 restart

1.2. PEAR

There are several ways to install PEAR. Choose the one you prefer.

1.2.1. Via apt-get

Just type in the terminal:

sudo apt-get install php-pear

1.2.2. Downloading the phar

Alternatively, you can download the phar archive and install it, which is more flexible for choosing configuration:

wget http://pear.php.net/go-pear.phar php go-pear.phar

And the following menu will be shown:

 1. Installation base ($prefix)                   : /home/julen/pear  2. Temporary directory for processing           
: /tmp/pear/install  3. Temporary directory for downloads             : /tmp/pear/install  4. Binaries directory                           
: /home/julen/pear/bin  5. PHP code directory ($php_dir)                 : /home/julen/pear/share/pear  6. Documentation directory                      
: /home/julen/pear/docs  7. Data directory                                : /home/julen/pear/data  8. User-modifiable configuration files directory : /home/julen/pear/cfg  9. Public Web Files
directory                    : /home/julen/pear/www 10. System manual pages directory                 : /home/julen/pear/man 11. Tests directory                              
: /home/julen/pear/tests 12. Name of configuration file                    : /home/julen/.pearrc 1-12, 'all' or Enter to continue:

We will see some of the configurations in section 3.

2. What is PEAR?

To understand what PEAR is and why it was created, we first have to review briefly the history of PHP.

In the past, many PHP projects used to rely in monolithic frameworks. These frameworks were composed by components designed to perform specific operations. But each framework had their components programmed it’s way, that is, with their own coding style, interface declaration, etc. Every framework was reinventing the wheel for problems that were solved, but in other frameworks. And, if developers wanted to use a specific component, they were forced to use some framework, which is an overkill for most of the cases. And these components were not interoperable with other frameworks.

To solve this problem, PEAR (PHP Extension and Application Repository) was developed, a PHP component development and distribution environment. It was developed with three main objectives:

  • Promote a well structured code library.
  • Maintain a distribution and maintenance system of code packages.
  • Promote a standard coding style.

With PEAR, the developers had a repository of components that would provide solutions for many areas: encryption, databases, mathematic operations, web services, and many more. And being every component usable individually, without the need of using a huge framework for very particular solutions.

2.1. Warning: PEAR is considered deprecated

Unfortunately (for PEAR), this package manager is currently (from some years ago, actually) considered deprecated, in favour of Composer. So, PEAR should also be used to deal with legacy code.

If you are starting a project and you need a dependency manager, use Composer.

3. Configuring PEAR

We can configure PEAR in several ways. We can see every configurable option by typing the following in the terminal:

pear config-show

And we will see a lot of configurations. The default configuration is fine for most cases, but we may are interested to change them.

The most likely configuration to be changed is the PEAR directory, which by default has the /usr/share/php value. This is where the PEAR PHP components will be installed.

To change the configuration, the syntax is the following:

pear config-set  

So, for this case, we would have to type:

pear config-set php_dir /path/to/pear/dir

And the configuration will be changed.

If we change the PEAR directory, we also have to change the PHP configuration, to indicate where this directory is, to make PHP know from where it has to include the components. For that, we have to edit the /etc/php5/apache2/php.ini file, adding this path to the include_path directive, so it will remain as follows:

include_path = ".:/usr/share/php:/path/to/pear/dir"

Adding the path to the configured PEAR directory after a colon, indicating that is another directory to include.

Don’t forget to restart Apache after doing any change in PHP configuration.

4. Dealing with PEAR packages

In this section, we we will see how to install, upgrade and delete packages with PEAR, see how they are organized, and things to take into account when installing them.

4.1. Installing packages

Installing packages with PEAR is so easy. But, before installing packages, we have to know what we want to install.

The easiest way to find packages, is using the official PEAR site, and making a search in the search box. For example, if we need a component for encryption operations, we would search for encryption in the the search form. For this case, we will get the following results:

Hướng dẫn pear php standard - lê php tiêu chuẩn

6.2. Validator

One of the most repeated tasks when dealing with user input is (should be) the validation. There is also a component to perform validations of many types. It’s called Validate:

pear install Validate-0.8.5

And this is how it can be used it:

validate.php

email($email)) {     echo 'Valid email.
'; } else {     echo 'Invalid email.
'; } if ($validator->number($number, ['decimal' => ','])) {     echo 'Valid number.
'; } else {     echo 'Invalid number.
'; } if ($validator->date($date, ['format' => '%d-%m-%Y'])) {     echo 'Valid date.
'; } else {     echo 'Invalid date.
'; }

As you can see, this can be very useful to perform some specific validations, such us with emails, number formats, or dates (and more).

6.3. XML serializer

A tiring job is to parse XML files. But, yes, there’s a component to deal with this task, XML_Serializer.

Install it:

pear install XML_Serializer-0.20.2

And then use it for serialization:

xml_serializer.php

 'UTF-8',     'indent'    => '    ', ]; $serializer = new XML_Serializer($options); $data = [     'XML_Serializer' => [         'title'      
=> 'XML Serializer example',         'description' => 'This is an example of XML serialization with XMl_Serializer PEAR package.',         'link'        => 'http://pear.php.net/package/XML_Serializer',        
'attributes' 
=> [             'nested element'  => 'This a nested element.',             'another element' => 'More stuff.'         ]     ] ]; $serialized = $serializer->serialize($data);
if ($serialized) {     echo 'Serialized data:
';     echo '
';     echo htmlentities($serializer->getSerializedData());     echo '
'; } else {     echo 'An error occurred serializing the data.'; }

Of course, we can do the reverse way, with the unserializer:

xml_unserializer.php

              XML Serializer example        
This is an example of XML serialization with XMl_Serializer PEAR package.         http://pear.php.net/package/XML_Serializer                      This
a nested element.             More stuff.               "; $unserialized = $unserializer->unserialize($data); if
($unserialized) {     echo 'Unserialized data:
';     echo '
';     print_r($unserializer->getUnserializedData());     echo '
'; } else {     echo 'An error occurred unserializing.'; }

With this component, practically, XML parsing does not require any work.

7.Summary

This tutorial has shown how to use the PEAR package manager for PHP, from the installation, to the use of some of the most useful packages, seeing how they can be installed, upgraded and deleted. We have also seen how to track the dependencies using the manifest file, which is an important point, because it allows us to have all the dependencies easily available in any computer, and also upgradeable.

But the most important thing to take into account is that PEAR is not the best option as package manager for new projects, since it’s deprecated and in disuse. Instead, Composer should be used. And, PEAR, only for legacy projects that used to use it as package manager.

8. Download the source code

This was a tutorial about PEAR package manager.

Download
You can download the full source code of this example here: PHPPearTutorial