<?php

require_once("safeElement.php");
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Safe_Array
 *
 * @author memad
 */
class SafeArray {

    private $safeArray;

    public function __construct() {
        $this->safeArray = array();
        
        
    }
    
    public function import($ordinary_array){
        if (!empty($ordinary_array)) {
            foreach ($ordinary_array as $key => $value) {
                
                $this->safeArray[] = new $SafeElement($key, $value);
                }
            }
    }
   

    public function add($key, $value) {
        $this->safeArray[] = new SafeElement($key, $value);
    }

    public function get($key) {
        foreach ($this->safeArray as $safeElement) {
            if (strtolower($key) == strtolower($safeElement->key)) {
                return $safeElement->value;
            } elseif (strtolower($this->removeTablePart($key)) == strtolower($this->removeTablePart($safeElement->key))) {
                return $safeElement->value;
            }
        }
        return "";
    }

    private function removeTablePart($string) {
        if (strstr($string, ".")) {
            $modified_string = explode(".", $string);
            return $modified_string[1];
        } else {
            return $string;
        }
    }

}
