Login   Register  
PHP Classes
elePHPant
Icontem

File: phon/PHONEvaluator.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  PHON  >  phon/PHONEvaluator.php  >  Download  
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
Author: By
Last change:
Date: 6 years ago
Size: 1,377 bytes
 

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;
    }
}