In this third part of a five-part series on the data mapper design pattern, I start developing a basic user mapper class. This class allows you to map user domain objects to their associated database table in a fairly easy way.
– The Data Mapper design pattern is a powerful and elegant solution that permits developers to isolate domain objects from the underlying persistence storage mechanism of an application. Its implementation, at least at a basic level, is a pretty straightforward process that can be tackled with minor …
Archive for the ‘Tutorials’ Category
Building the Data Mapper Classes for the Data Mapper Design Pattern
Creating a Static Web Form Helper with Restrictive Constructors
Welcome to the final installment of a series that shows you how to use restrictive constructors in PHP 5. With a decent variety of code samples, this series recreates for you a few common scenarios where the implementation of both protected and private constructors can greatly improve the behavior of different classes in the context of a given application.
– And now that you’ve been properly introduced to the subject of this series, its time to briefly recapitulate the topics that were covered in the last tutorial. In that part of the series I built a basic MySQL abstraction class, which used a private constructor in conjunction with a static method c…
Getting More Info on Reflected Properties with the Reflection API
In this fifth part of the series you will learn a couple of additional methods included with the PHP reflection API. The first one will allow you to check the existence of a specified class property, and the second one will permit you to retrieve all of the static properties defined by that class at once.
– Frankly speaking, the powerful reflection library that comes included with PHP 5 is one of those features that you, as a web developer, cant live without once youve discovered its real functionality. While is fair to say that in the old days of PHP 4, the language already provided some native functi…
Implementing the Iterator SPL Interface
In this second part of a series, I make the MySQLi_ResultWrapper class a full implementer of the Iterator SPL interface. Implementing the rest of the methods declared by the interface is a straightforward process that allows us to traverse MySQL result sets by using a plain foreach construct.
– As you may know, the Standard PHP Library (commonly know as SPL) provides developers with a powerful set of native classes and interfaces that can be used for easily tackling problems that come up in everyday programming, such as autoloading resources on request, traversing recursively directories…
Building a Data Access Layer for the Data Mapper Design Pattern
In this second part of a five-part series I go one step further in the implementation of the Data Mapper design pattern in PHP 5. Specifically, I build a simple MySQL abstraction class which performs a few common tasks. These include connecting to the database server and running hard-coded queries, fetching database rows and so forth.
– Put in a simple way, the Data Mapper design pattern is an elegant solution that allows developers to keep all of the domain objects handled by an application separate from the underlying persistence layer. This characteristic is commonly known as persistence ignorance. As with many other patterns…
Building a Singleton Database with Restrictive Constructors in PHP 5
In this third installment of a four-part series, I show you that a private constructor can be truly helpful when strictly implementing the Singleton design pattern. In this case, the pattern will be applied within a class that behaves like a simple MySQL abstraction layer, but the same concept can be extended to other classes.
– At first sight, declaring a constructor method protected or private in PHP 5 seems to be a rather irrelevant and even boring topic. The process doesnt differ too much from specifying one of those levels of restriction for a regular class method. However, this first impression may be misleading.
…
Working with Reflected Properties with the Reflection API
In this fourth part of a seven-part series, I demonstrate how to use the PHP reflection API to retrieve useful information about the properties declared by a specific class. Reflection allows you to do more with properties of a class than determine their visibility or learn the values assigned to them, but that’s what we’ll be covering here.
– In case youre not aware of it, among the many enhancements and helpful features that were added to PHP 5, theres one that has been unfairly overlooked by many developers. This might be because at first glance it doesn’t seem to be as useful as the others. Yes, as this articles title suggests, Im t…
The Iterator, Countable and ArrayAccess SPL Interfaces
In this first part of a short series, I’m going to introduce you to using the Iterator, Countable and ArrayAccess interfaces that come with the Standard PHP Library. You’ll see how to implement some of the methods declared by the Iterator interface within a class that manipulates MySQL result sets via an intuitive API.
– For many PHP developers eager to apply the object-oriented paradigm in a more thorough and consistent manner, the release of PHP 5 brought a number of handy features that allowed them to achieve this goal in a truly painless fashion. This isnt breaking news, of course, but the inclusion of member …
Implementing the Data Mapper Design Pattern in PHP 5
In this first part of a five-part series, I introduce you to implementing the Data Mapper design pattern in PHP 5. This pattern attempts to solve the issue of the strong coupling that often exists between the domain objects present in an application and the underlying persistence mechanism. This benefit comes at a cost, since data mappers add a new layer of complexity. Living with this minor trade-off is quite worthwhile, though, as you’ll see.
– Since the web is in constant evolution and merges a variety of technologies and languages, developing web applications (specially mid-sized and large-scale ones) has become a challenging process. Indeed, applications require extensive planning, modeling and testing, before reaching a stable depl…
Defining an Abstract Class with Restrictive Constructors in PHP 5
In this second part of a four-part series, I rebuild the example application developed in the previous tutorial. As you’ll recall, it used a protected constructor to prevent the instantiation of the base array iterator class. In this case, a better result will be achieved by declaring the iterator abstract; still, the example demonstrates a simple utilization of a restrictive constructor in a concrete situation.
– Unquestionably, the introduction of a more robust object model in PHP 5 has provided developers with additional features that allow them to build efficient and thorough object-oriented applications without the need to appeal to the ugly programming hacks used frequently in the bad old days of PHP …
















































Recent Comments