Home arrow PHP arrow Page 3 - Verifying Float Values with the Strategy Design Pattern

Adding a strategy class for checking float numbers - PHP

In this third part of a series on validating incoming data with the strategy design pattern, I create a brand new strategy class that can check whether or not a supplied input value is a float number. The addition of this class extends the capabilities of the sample validation program that I’m building in this series.

TABLE OF CONTENTS:
  1. Verifying Float Values with the Strategy Design Pattern
  2. Review: the sample classes developed so far
  3. Adding a strategy class for checking float numbers
  4. Using the FloatValidator class as a standalone component
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
April 21, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In reality, building a strategy class that can validate float numbers is nearly identical to creating one that checks integers, which we already did in the previous segment. Nonetheless, the best way to prove the truth of my claim is by means of some functional code, so below I included the definition of this brand new strategy class. It looks like this:

(FloatValidator.php)

 

<?php

class FloatValidator extends AbstractValidator

{

    protected $_filter = FILTER_VALIDATE_FLOAT; 

    protected $_errorMessage = 'Please enter a float value.';

}

There you have it. As you can see, building a refined class that validates float numbers is reduced (again) to overriding the already familiar “$_filter” and “$_errorMessage” properties defined by the parent abstract validation class. Of course, “FloatValidator” is as flexible as its partner “IntegerValidator,” so it can be used in conjunction with other classes or in an isolated fashion.

The latter option deserves at least a quick look. So in the last section of this tutorial I’m going to set up a basic script that will show how to use the previous “FloatValidator” class in an independent manner.

Now, don’t waste more time; read the lines come.



 
 
>>> 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: