Location: PHPKode > projects > GnomePHP > peec-GnomePHP-b5a360b/gnomephp/helper/lang/LangFile.php
<?php
namespace gnomephp\helper\lang;

class LangFile{
	
	private $vars=array();
	
	
	
	/**
	 * 
	 * Loads language variables into the helper class into it's own instance.
	 * 
	 * @param string $langFile A file name, example ways: form, validation etc.
	 * @param string $lang The wanted language, eg. english, swedish or norwegian etc.
	 * @param string $ext The file extension, the default is ".yml".
	 * @throws LangFileException
	 */
	public function __construct($langFile, $lang='english', $ext='.yml'){
		
		$relPath = DIRECTORY_SEPARATOR . $lang . DIRECTORY_SEPARATOR . $langFile . $ext;
		
		$pathApp = GNOME_APP_PATH . DIRECTORY_SEPARATOR . 'language' .  $relPath;
		$pathFw = GNOME_FW_PATH . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'language' . $relPath;
		if (file_exists($pathApp)){
			$this->vars = \gnomephp\yaml\sfYaml::load(file_get_contents($pathApp));
		}elseif (file_exists($pathFw)){
			$this->vars = \gnomephp\yaml\sfYaml::load(file_get_contents($pathFw));
		}else{
			throw new LangFileException("Could not locate $langFile$ext in language directories App: $pathApp or FW: $pathFw.", LangFileException::FILE_NOT_FOUND);
		}		
	}
	
	/**
	 * Gets a array key from the language file.
	 * @param string $var
	 */
	public function get($var){
		return $this->vars[$var];
	}
	
	/**
	 * Gets all the language variables.
	 */
	public function getVars(){
		return $this->vars;
	}
	
	
	
}
Return current item: GnomePHP