TAILIEUCHUNG - PHP Objects, Patterns, and Practice- P6

PHP Objects, Patterns, and Practice- P6: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods. | CHAPTER 12 ENTERPRISE PATTERNS When you need to put your system through its paces you can use test mode to switch in a fake registry. This can serve up stubs objects that fake a real environment for testing purposes or mocks similar objects that also analyze calls made to them and assess them for correctness . Registry testMode mockreg Registry instance You can read more about mock and stub objects in Chapter 18 Testing with PHPUnit. Registry Scope and PHP The term scope is often used to describe the visibility of an object or value in the context of code structures. The lifetime of a variable can also be measured over time. There are three levels of scope you might consider in this sense. The standard is the period covered by an HTTP request. PHP also provides built-in support for session variables. These are serialized and saved to the file system or the database at the end of a request and then restored at the start of the next. A session ID stored in a cookie or passed around in query strings is used to keep track of the session owner. Because of this you can think of some variables having session scope. You can take advantage of this by storing some objects between requests saving a trip to the database. Clearly you need to be careful that you don t end up with multiple versions ofthe same object so you may need to consider a locking strategy when you check an object that also exists in a database into a session. In other languages notably Java and Perl running on the ModPerl Apache module there is the concept of application scope. Variables that occupy this space are available across all instances of the application. This is fairly alien to PHP but in larger applications it is very useful to have access to an applicationwide space for accessing configuration variables. You can build a registry class that emulates application scope though you must be aware of some pretty considerable caveats. Figure 12-3 shows a possible structure for Registry classes that .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.