Home > Article > Backend Development > PHP library collection
Time 2015-09-08 14:13:00 Linux China
Original text http://linux.cn /article-6158-rss.html
ThemesPHPHTML
It’s an exciting time to be a PHP developer. There are tons of useful libraries distributed every day that are easy to discover and use on Github. Below are 24 of the coolest libraries I've ever come across. Is your favorite library not on this list? Then share it in the comments!
1. Dispatch – micro-framework
Dispatch is a small PHP framework. It doesn't give you a complete MVC setup, but you can define URL rules and methods to better organize your application. This is perfect for APIs, simple sites or prototypes.
You can match specific types of HTTP requests and paths, render views or do more. If you combine Dispatch with other frameworks, you can have a very powerful and lightweight program!
2. Klein – Lightning-fast routing for PHP
Klein is another lightweight routing library for PHP5.3+. Although it has a somewhat more verbose syntax than Dispatch, it is quite fast. Here's an example:
You can also customize to specify the HTTP method and use regular expressions for the path.
This is great for small projects, but when you use a library like this for a large application, you have to follow the rules because your code can become unmaintainable very quickly. So you'd better go with a fully mature framework like Laravel or CodeIgniter.
3. Ham – Routing library with cache
Ham is also a lightweight routing framework, but it uses caching to achieve even faster speeds. It does this by caching anything I/O related into XCache/APC. Here's an example:
This library requires you to have at least one of XCache and APC installed, which may mean that it may not work on hosts provided by most hosting providers. But if you have a host with one of them installed, or you have control over your web server, you should try this fastest framework.
4. Assetic - Resource Management
Assetic is a PHP resource management framework for merging and reducing CSS/JS resources. Below are examples.
Combining resources in this way is a good idea as it speeds up the site. Not only the total download volume is reduced, but also a large number of unnecessary HTTP requests are eliminated (these are the two things that most affect page load time)
5. ImageWorkshop – Image processing with layers
ImageWorkshop is a tool that allows you to control An open source library for layered images. With it you can resize, crop, create thumbnails, watermark or do more. Here's an example:
ImageWorkshop was developed to simplify some of the most common cases of working with images in PHP, if you need something more powerful you should take a look at Imagine library!
6. Snappy - Snapshot/PDF library
Snappy is a PHP5 library that can generate snapshots, URLs, HTML, and PDFs. It relies on the wkhtmltopdf binary (available on Linux, Windows and OSX). You can use them like this:
Be aware that your hosting provider may not allow calling external binaries.
7. Idiorm - lightweight ORM library
Idiorm is my favorite one that I have used in the tutorials on this website before. It is a lightweight ORM library, a PHP5 query builder built on PDO. With it, you can forget how to write boring SQL:
Idiorm has a sister library called Paris, which is an Active based on Idiorm Record implementation.
8. Underscore – PHP’s tool belt
Underscore is an interface to the original Underscore.js – Tool belt for Javascript applications. The PHP version does not disappoint and supports almost all native features. Here are some examples:
This library also supports chain syntax, which makes it even more powerful.
9. Requests - Simple HTTP Requests
Requests is a library that simplifies HTTP requests. If you're like me and can almost never remember the various parameters passed to Curl, then this is for you:
With this library you can send HEAD, GET, POST, PUT, DELTE With PATCH HTTP requests, you can add files and parameters via arrays and have access to all corresponding data.
10. Buzz – Simple HTTP request library
Buzz 是另一个完成HTTP请求的库。下面是一个例子:
因为它缺乏文档,所以你不得不阅读源码来获知它支持的所有参数。
11. Goutte – Web抓取库
Goutte 是一个抓取网站和提取数据的库。它提供了一个优雅的API,这使得从远程页面上选择特定元素变得简单。
12. Carbon – DateTime 库
Carbon 是 DateTime API 的一个简单扩展。
13. Ubench – 微型基准库
Ubench 是一个用于评测PHP代码的微型库,可监控(代码)执行时间和内存使用率。下面是范例:
(仅)在开发时运行这些校验是一个好主意。
14. Validation – 输入验证引擎
Validation 声称是PHP库里最强大的验证引擎。但是,它能名副其实吗?看下面:
你可以通过这个库验证你的表单或其他用户提交的数据。除此之外,它内置了很多校验,抛出异常和定制错误信息。
15. Filterus – 过滤库
Filterus 是另一个过滤库,但它不仅仅可以验证,也可以过滤匹配预设模式的输出。下面是一个例子:
Filterus有很多内建模式,支持链式用法,甚至可以用独立的验证规则去验证数组元素。
16. Faker – 假数据生成器
Faker 是一个为你生成假数据的PHP库。当你需要填充一个测试数据库,或为你的web应用生成测试数据时,它能派上用场。它也非常容易使用:
只要你继续访问对象属性,它将继续返回随机生成的数据。
17. Mustache.php – 优雅模板库
Mustache是一款流行的模板语言,实际已经在各种编程语言中得到实现。使用它,你可以在客户端或服务段重用模板。 正如你猜得那样, Mustache.php 是使用PHP实现的。
建议看一下官方网站 Mustache docs 查看更多高级的例子。
18. Gaufrette – 文件系统抽象层
Gaufrette 是一个PHP5库,提供了一个文件系统的抽象层。它使得以相同方式操控本地文件,FTP服务器,亚马逊 S3或更多操作变为可能。它允许你开发程序时,不用了解未来你将怎么访问你的文件。
也有缓存和内存适配器,并且随后将会增加更多适配器。
19. Omnipay – 支付处理库
Omnipay 是一个PHP支付处理库。它有一个清晰一致的API,并且支持数十个网关。使用这个库,你仅仅需要学习一个API和处理各种各样的支付处理器。下面是一个例子:
使用相同一致的API,可以很容易地支持多种支付处理器,或在需要时进行切换。
20. Upload – 处理文件上传
Upload 是一个简化文件上传和验证的库。上传表单时,这个库会校验文件类型和尺寸。
它将减少不少乏味的代码。
21. HTMLPurifier – HTML XSS 防护
HTMLPurifier 是一个HTML过滤库,通过强大的白名单和聚集分析,保护你代码远离XSS攻击。它也确保输出标记符合标准。 (源码 在github 上)
如果你的网站允许用户提交 HTML 代码,不修改就展示代码的话,那这时候就是用这个库的时候了。
22. ColorJizz-PHP – 颜色操控库
ColorJizz 是一个简单的库,借助它你可以转换不同的颜色格式,并且做简单的颜色运算
它已经支持并且可以操控所有主流颜色格式了
23. PHP Geo – 地理位置定位库
phpgeo 是一个简单的库,用于计算地理坐标之间高精度距离。例如:
它将在使用地理位置数据的app里出色工作。你可以试译 HTML5 Location API,雅虎的API(或两者都用,我们在 weather web app tutorial 中这样做了),来获取坐标。
24. ShellWrap – 优美的命令行包装器
借助 ShellWrap 库,你可以在PHP代码里使用强大的 Linux/Unix 命令行工具。
当命令行里发生异常时,这个库抛出异常,所以你可以及时对之做出反应。它也可以通过管道让你一个命令的输出作为另一个命令的输入,来实现更强的灵活性。
以上就介绍了PHP库收集,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。