view classes/loader.php @ 47:886f43b26ee2 extractapp

move/remove develop folder
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 17 Mar 2015 10:54:13 +0100
parents
children 97c1e5102a22
line wrap: on
line source

<?php

class Loader {
	private $controller;
	private $action;
	private $urlvalues;
	private $postdata = 0;

	//store the URL values on object creation
	public function __construct($urlvalues, $postdata) {
		$this->urlvalues = $urlvalues;
		$this->postdata = $postdata;
		if ($this->urlvalues['controller'] == "") {
			$this->controller = "extractapp";
			// TODO: develope home page for the whole service.
			// change $this->controller to home after developed extract app.
			// $this->controller = "home";
			
		} else {
			$this->controller = $this->urlvalues['controller'];
		}

		if ($this->urlvalues['action'] == "") {
			$this->action = "taggingtext";
			// $this->action = "index";
		} else {
			$this->action = $this->urlvalues['action'];
		}

	}
	
	//establish the requested controller as an object
	public function CreateController() {
		//does the class exist?
		if (class_exists($this->controller)) {
			$parents = class_parents($this->controller);
			//does the class extend the controller class?
			if (in_array("BaseController",$parents)) {
				//does the class contain the requested method?
				if (method_exists($this->controller,$this->action)) {
					return new $this->controller($this->action,$this->urlvalues,$this->postdata);
				} else {
					//bad method error
					return new Error("badUrl",$this->urlvalues);
				}
			} else {
				//bad controller error
				return new Error("badUrl",$this->urlvalues);
			}
		} else {
			//bad controller error
			return new Error("badUrl",$this->urlvalues);
		}
	}
}

?>