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