PHP Classes
Icontem

File: phon/PHONEvaluator.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  PHON  >  phon/PHONEvaluator.php  
File: phon/PHONEvaluator.php
Role: Class source
Content type: text/plain
Description: File for the PHONEvaluator class
Class: PHON
Unserialize values exported with var_export
 

Contents

Class file image Download
<?php
/**
 * File for the PHONEvaluator class.
 * @package PHON
 */

require_once 'PHONValidator.php';

/**
 * Singleton class that safely evaluates PHON data into PHP values.
 * @package PHON
 */
final class PHONEvaluator {
    
/**
     * Singleton instance.
     * @var PHONEvaluator
     */
    
private static $instance;
    
    
/**
     * Singleton access.
     * @return PHONEvaluator Singleton instance.
     */
    
public static function getInstance() {
        if (!
self::$instance) {
            
self::$instance = new PHONEvaluator();
        }
        return 
self::$instance;
    }
    
    
/**
     * A reference to the validator singleton.
     * @var PHONValidator
     */
    
private $validator;
    
    
/**
     * Constructor.
     */
    
private function __construct() {
        
$this->validator PHONValidator::getInstance();
    }
    
    
/**
     * Evaluates the provided PHON data.
     * @param string $phon The PHON data.
     * @return mixed The PHP values represented by the PHON data.
     */
    
public function evaluate($phon) {
        if (!
$this->validator->isSecure($phon)) {
            require_once 
'InvalidPHON.php';
            
throw new InvalidPHON('PHON data found to be unsecure and evaluation was halted'$phon);
        }
        
$data null;
        if (@eval(
"\$data = $phon;") === false) {
            require_once 
'InvalidPHON.php';
            
throw new InvalidPHON('PHON evaluation halted due to invalid data format'$phon);
        }
        return 
$data;
    }
}

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products