-
Posted: March 31st, 2010, 7:00am MDT
In this penultimate part of the series on the data mapper design pattern, I demonstrate how to provide the UserMapper class we've previously created with the ability to delete users from its associated MySQL table.
- Superbly described in Martin Fowler's book Patterns of Enterprise Application Architecture, Data Mapper is a powerful database access pattern aimed at keeping domain objects isolated from the underlying storage mechanism (in most cases a relational database). This permits developers to build multi...
-
Posted: March 30th, 2010, 7:00am MDT
In this third part of a seven-part series on the Iterator, Countable and ArrayAccess SPL interfaces, I give the MySQLi_ResultWrapper class developed in the previous part the capability of counting the number of rows contained in a given result set. I'll do that by implementing the count() method declared by the Countable interface. Doing this will make it possible to use an instance of the class to traverse data sets and count records as if they were plain PHP arrays, which is quite appealing to client code that works with the classs API.
- As you possibly know, the Standard PHP Library (also know simply by its acronym, SPL) is comprised of a powerful set of functions, classes and interfaces that permit developers to address problems that occur frequently during the development of web programs. Ranging from autoloading classes on deman...
-
Posted: March 29th, 2010, 7:00am MDT
In this sixth part of a seven-part series, I explain how to use the power of reflection to find out if a class has been defined abstract and final, and if it implements a specified interface. Performing all of these tasks is a straightforward process, so you shouldnt have major problems using these reflection methods within your own PHP applications.
- When it comes to highlighting the most remarkable features incorporated into PHP 5 a few years ago, undoubtedly its enhanced object model, along with the support for native exceptions and interfaces, are the first things that come to mind. However, as you may have heard, the language also comes wi...
-
Posted: March 25th, 2010, 7:00am MDT
If you're writing a program that involves computation, you're going to come face to face with some basic programming concepts. This article, the first of a five-part series, will explain scalars, one of the basic ideas of programming in Perl. It is excerpted from chapter two of the book Beginning Perl, written by James Lee (Apress; ISBN: 159059391X).
- The essence of programming is computation we want the computer to do some work with the input (the data we give it). Very rarely do we write programs that tell us something we already know. Even more rarely do we write programs that do nothing interesting with our data at all. So, if were going to w...
-
Posted: March 24th, 2010, 7:00am MDT
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 ...
-
Posted: March 23rd, 2010, 7:00am MDT
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...
-
Posted: March 22nd, 2010, 7:00am MDT
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...
-
Posted: March 18th, 2010, 7:00am MDT
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...
-
Posted: March 17th, 2010, 7:00am MDT
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...
-
Posted: March 16th, 2010, 7:00am MDT
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.
...
-
Posted: March 15th, 2010, 9:58pm MDT
As the iPad nears its shipping date, iPad developers are flocking to the Objective-C platform and Apple's SDK 3.2
- Using the same development platform as the iPhone, the iPad has caused a marked surge in use of the iPad development software and emulators almost as strong as the market is picking up the actual iPad units.
The iPad itself sold well over 155,000 units in just over three days. Developer's interes...
-
Posted: March 15th, 2010, 7:00am MDT
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...
-
Posted: March 11th, 2010, 7:00am MST
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 ...
-
Posted: March 10th, 2010, 7:00am MST
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...
-
Posted: March 9th, 2010, 7:00am MST
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 ...
-
Posted: March 8th, 2010, 7:00am MST
This third part of a seven-part series explores the methods of the PHP Reflection API. You will learn how to take advantage of their functionality to retrieve useful information about the methods defined by a reflected class.
- One of today's most powerful approaches for retrieving information about the internal structure of classes and interfaces in PHP 5 is via the language's native reflection API. What's more, not only does this API comes packaged with a huge variety of methods that let developers perform all sorts of ...
-
Posted: March 4th, 2010, 7:00am MST
What exactly is a restrictive constructor, and why would you want to use one? If you're a PHP programmer who uses such design patterns as Singleton and Factory, this series of articles on restrictive constructors will give you another tool to use in your applications.
- As you'll probably know, with the release of PHP 5 quite some time ago, the language was provided with the ability to specify the visibility of properties and methods in classes, something that had already been implemented in more mature programming languages such as Java and C++.
In a pretty str...
-
Posted: March 3rd, 2010, 7:00am MST
In this second part of a series, I explore some handy methods of the PHP Reflection API. They allow you to retrieve miscellaneous information about a class, including its name and containing file, as well as its starting and ending lines.
- Overlooked by many developers, the Reflection API that comes with PHP 5 is a powerful reverse-engineering extension of the language that permits developers to analyze, inspect and retrieve valuable information about selected classes and interfaces by means of a set of convenient methods.
So, if y...
-
Posted: March 2nd, 2010, 7:00am MST
In this first part of a series, we'll begin exploring some of the methods included with the Reflection API bundled with PHP 5. The interface allows developers to collect relevant information about a reflected class, including its name, its declared constants and properties, in a extremely straightforward way.
- Even though PHP is intrinsically a weakly-typed language, as it doesnt internally impose any constraints on the types of values that can be held by a given variable (with the exception of type hinting and type casting), its introspective capabilities are quite impressive indeed. Native old functio...
-
Posted: March 1st, 2010, 7:00am MST
Welcome to the final part of a ten-part series that shows you how to use the Swift Mailer library to build email applications. This final part of the series will explain how to use the batchsend() method, and how to specify the Return-path MIME header within emails.
- Frankly speaking, building a full-featured email application with PHP has always been a challenging task, even for seasoned developers. The process often demands that developers deal directly with the internals of both the SMTP and POP3 protocols, and it's worse if the application must provide su...