Home arrow PHP arrow Validating URLs with the Strategy Design Pattern

Validating URLs with the Strategy Design Pattern

In this penultimate part of the series, I will build a strategy class that validates URLs using the built-in PHP function “filter_var().” This process is similar to defining other strategy classes discussed in previous parts, so you shouldn’t have major difficulties understanding its underlying logic.

TABLE OF CONTENTS:
  1. Validating URLs with the Strategy Design Pattern
  2. Review: the source classes defined so far
  3. Validating URLs with the Strategy design pattern
  4. Testing the UrlValidator class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
April 27, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As a PHP developer, did you ever think that implementing the Strategy design pattern in a real-word case was a daunting task that would make you suffer  premature hair loss? Well, fear not; in this article series you'll learn how to build a customizable web application which will use a bunch of loosely-coupled strategy classes to validate different types of data, such as integer and float numbers, URLs, email addresses as so forth.

And now that I've mentioned strategy classes, it's time to review the topics covered in the last tutorial. In that installment I went through the development of a simple strategy class, which checked email addresses via the "filter_var()" PHP function that comes bundled with the language's filters extension.

Even though you've probably built a class like this hundreds of times before, the process hopefully demonstrated how easy it is to apply the model imposed by the Strategy design pattern within the context of a real-world application whose primary goal is to check incoming data through a set of isolated validation (or strategy) classes.

In its current state, this example application is capable of validating integers, float numbers and email addresses in a pretty straightforward fashion, which is good  for demonstration purposes. However, it'd be useful to extend its existing functionality even further by adding yet another strategy class to it that permits you to validate URLs. With that premise in mind, in this fifth chapter of the series I'm going to define a brand new strategy class, which will perform the aforementioned validation in a few simple steps. 

Now, it's time to continue discovering the numerous benefits of implementing the Strategy design pattern in PHP. Let's get going!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: