Ejemplo n.º 1
0
 function loadController($controller = null)
 {
     if (isset($controller)) {
         $this->contorllerFile = $controller;
     }
     $class = SweetFramework::className($this->contorllerFile);
     if (!SweetFramework::loadFileType('controller', $class)) {
         D::error('No Controller Found');
     }
     $page = $this->loadUrl($class::$urlPattern, $this->count);
     if (is_array(f_last($page))) {
         if (is_array(f_first(f_last($page)))) {
             return $this->loadController(f_first(f_first(f_last($page))), $this->count += 1);
         }
         $page[$this->count] = f_first(f_last($page));
         //D::log($page[$part], 'page o parts');
     }
     D::log($page, 'Initing Controller…');
     $this->controller = new $class();
     //$this->controller->getLibrary('Databases/Query.php');
     /*@todo make "shortcuts" more dynamic */
     //$this->controller->template =& $this->controller->lib->Template;
     if (empty($page[$this->count])) {
         return f_callable(array($this->controller, 'index'));
     } else {
         if (method_exists($class, $page[$this->count])) {
             return f_callable(array($this->controller, $page[$this->count]));
         }
     }
     if (method_exists($class, '__DudeWheresMyCar')) {
         return f_callable(array($this->controller, '__DudeWheresMyCar'));
     }
     return function () {
         header("HTTP/1.0 404 Not Found");
         echo '<h1>404 error</h1>';
         //todo check for some sort of custom 404…
         return false;
     };
 }
Ejemplo n.º 2
0
	function model($model) {
		if(is_array($model)) {
			return f_last(array_map(f_callable(array($this, 'model')), $model));
		}
		return $this->models->{SweetFramework::className($model)} = SweetFramework::getClass('model', $model);
	}
Ejemplo n.º 3
0
	function loadController($controller=null) {
		if(isset($controller)) {
			$this->contorllerFile = $controller;
		}
		if(empty($this->contorllerFile)) {
			$this->contorllerFile = $this->lib('Config')->get('site', 'mainController');
		}
		
		$class = SweetFramework::className($this->contorllerFile);
		D::log($class, 'Controller Loaded');
		
		if(!SweetFramework::loadFileType('controller', $this->contorllerFile)) {
			D::error('No Controller Found');
		}
		if(!empty($class::$urlPattern)) {
			$page = $this->loadUrl($class::$urlPattern);
		} else {
			$page = $this->loadUrl(array());
		}
		
		D::log($this->count, 'COUNT');
		D::log($page, 'page');
		
		if(is_array(f_last($page))) {
			if(is_array( f_first(f_last($page)) )) {
				$this->request = f_first($page);
				D::log($this->request, 'Request Reduced');
				if(method_exists($class, 'enRoute')) {
					$class::enRoute();
				}
				return $this->loadController(f_first(f_first(f_last($page))) );
			}
			$page[$this->count] = f_first(f_last($page));
		}
		
		$fpage = f_first($page);
		$this->controller = new $class();
		if(empty($fpage)) {
			return f_callable(array($this->controller, D::log('index', 'Controller Function')));
		} else {
			if(method_exists($class, $fpage)) {
				return f_callable(array($this->controller, D::log($fpage, 'Controller Function')));
			}
		}
		
		//D::show($class, 'controller');
		if(method_exists($class, '__DudeWheresMyCar')) {
			return f_callable(array(
				$this->controller,
				'__DudeWheresMyCar'
			));
		}
		//@todo find a way to check for __DudeWheresMyCar functions higher up the controller tree.
		
		return function() {
			header('HTTP/1.0 404 Not Found');
			echo '<h1>404 error</h1>'; //todo check for some sort of custom 404…
			return false;
		};
	}