Ejemplo n.º 1
0
function redirect($uri = '', $method = 'location', $http_response_code = 302) {
	switch($method) {
		case 'refresh' : header("Refresh:0;url=".site_url($uri));
			break;
		default	:
			if(substr($uri, 0, 7) != 'http://') {
				$uri = site_url($uri);
			}
//@todo make this be set off with the debug switch. and if debugging is on it should show a link to the page it would have forwarded to.
	 		header("Location: " . $uri, TRUE, $http_response_code);
			break;
	}
	/* @todo you should call an app end event here.*/
	SweetFramework::end();
	//exit;
}
Ejemplo n.º 2
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.º 3
0
<?php

SweetFramework::getClass('lib', 'Config')->setAll('site', array('name' => 'Sweet-framework', 'prettyUrls' => false, 'url' => 'http://localhost/projects/sweet-framework/?', 'database' => 'default', 'theme' => 'default'));
Ejemplo n.º 4
0
	function __get($var) {
		/* 
		ORM TODO:
		- is this where i tell if  i have a m2m relation ship?
			- does it make sense for Forigen Keys to exist like this?
				- not really, if its how m2m relationships are defined.
				
			- do foreign keys always have a field in the current model?
				- yes.
				
			- if it is a forigen key do i only need to return one sweet row item?
				- yes.
			- do m2m always need to return an array?
				- yes.
			- what advantages do i have for detecting m2m relationships
				- the differnces between fk and m2m code?
			- what does the pk mean?
				- //? the pk is used so you dont get an array of all the same item.
					-if it is the same item it passes it to the sweetRow obj
				- do you need it on m2m?
					- shouldn't matter.
					?no
					?not always.
						- the comments example on the pages models proves that it can be avaible.
				- do you need it on fk?
					yes.
						//in order for a fk to point to something, that something needs a pk.
						
					// for the most part the fk is gonna be the same for each row.
						- when is it differnent?
							//if its differnt does that mean there are 2 items?
								//this shouldn't be possible correct?
							//?on m2m?
			
		- how do i handle backwards relationships?
			- how were they defined before?
			- how were they handeled before?
			
			- do they even need to be defined?
				-yes.
			
			- use cases for backwards relationships?
				- m2m relationships are backwards fk relationships. they already work.
		*/
		//)
		if(!empty($this->__pull) && ( isset($this->__pull[$var]) || in_array($var, $this->__pull)) ) {
			
			////// KEYS:
			$varL = strlen($var);
/*
			$keys = array_filter(
				array_keys((array)f_first($this->__data)),
				function($k) use($var, $varL) {
					return ($var == substr($k, 0, $varL));
				}
			);
*/
			$keys = array();
			foreach(array_keys((array)f_first($this->__data)) as $k) {
				if($var == substr($k, 0, $varL)) {
					$keys[] = $k;
				}
			}
			
			//D::log($keys, 'keys');
			
			$varL++;
			$pull = isset($this->__pull[$var]) ? $this->__pull[$var] : array();
			//!meh			
			$pullRel = $this->__model->relationships[$var];
			if(is_string($fKey = f_first(array_keys($pullRel)) )) {
				//m2m
				
				//$model = SweetFramework::getClass('model', f_first($pullRel[$fKey]));
				$model = f_first($pullRel[$fKey]);
				$model = isset($this->__model->__relationships[$model]) ? $this->__model->__relationships[$model] : ($this->__model->__relationships[$model] = SweetFramework::getClass('model', $model));
				
				$returnItems = array();
				
				if(!isset($model->pk)) {
					foreach($this->__data as $row) {
						if(!empty($row)) {
							$item = self::subRow2Item($keys, $row, $varL);
							if(!empty($item)) {
								$returnItems[] = new SweetRow($model, $item, $pull);
							}
						}
					}
				} else {
					foreach($this->__data as $row) {
						if(!empty($row)) {
							$item = self::subRow2Item($keys, $row, $varL);
							if(!empty($item)) {
								if(isset($returnItems[$item[$model->pk]])) {
									f_call(array($returnItems[$item[$model->pk]], 'pass'), array($item));
								} else {
									$returnItems[$item[$model->pk]] = new SweetRow($model, $item, $pull);
								}
							}
						}
					}
				}
				return $returnItems;
			} else {
				//$model = SweetFramework::getClass('model', f_first($pullRel));
				$model = f_first($pullRel);
				$model = isset($this->__model->__relationships[$model]) ? $this->__model->__relationships[$model] : ($this->__model->__relationships[$model] = SweetFramework::getClass('model', $model));
				if(!isset($model->pk)) {
					foreach($this->__data as $row) {
						if(!empty($row)) {
							$item = self::subRow2Item($keys, $row, $varL);
							if(!empty($item)) {
								if(isset($returnItem)) {
									$returnItem->pass($item);
								} else {
									$returnItem = new SweetRow($model, $item, $pull);
								}
							}	
						}
					}
				} else {
					foreach($this->__data as $row) {
						if(!empty($row)) {
							$item = self::subRow2Item($keys, $row, $varL);
							if(!empty($item)) {
								if(isset($returnItem) && $returnItem->{$model->pk} == $item[$model->pk]) {
									$returnItem->pass($item);
								} else {
									$returnItem = new SweetRow($model, $item, $pull);
								}
							}
						}
					}
				}
			}
			return isset($returnItem) ? $returnItem : null;		
		} else if(isset($this->__model->fields[$var])) {
			//basicly this @ is here to make sure you call any field on a SweetRow and it will just return null unless it's been set.
			return !empty($this->__data[0][$var]) ? $this->__data[0][$var] : null;
			//return @f_first($this->__data)->$var;
		}
	}
Ejemplo n.º 5
0
	public function render($fileNameThatNoOneBetterUse) {
		extract($this->data);
		include(T::$loc . '/templates/' . SweetFramework::fileLoc($fileNameThatNoOneBetterUse));
	}
Ejemplo n.º 6
0
	function helper($helper) {
		if(is_array($helper)) {
			return f_last(array_map(f_callable(array($this, 'helper')), $helper));
		}
		return SweetFramework::loadFileType('helper', $helper);
	}
Ejemplo n.º 7
0
	public static function __callStatic($varName, $values=array()) {
		return SweetFramework::getClass('lib', 'Template')->$varName;
		//f_call(array(, 'get'), $args)
	}
Ejemplo n.º 8
0
<?
SweetFramework::getClass('lib', 'Config')->setAll('Debug', array(
	'debug' => true,
	'warnings' => true,
	'logfile' => LOC . '/sweet-framework/logs/main.log',
	'growl' => array(
		'host' => 'localhost',
		'password' => ''
	)
));
Ejemplo n.º 9
0
<?php

//location of the mysql db
SweetFramework::getClass('lib', 'Config')->setAll('databases', array('default' => array('driver' => 'My_SQL', 'host' => 'localhost', 'username' => 'sweetie', 'password' => 'password', 'databaseName' => 'sweet-framework')));
Ejemplo n.º 10
0
<?php

SweetFramework::getClass('lib', 'Config')->setAll('SweetFramework', array('benchMark' => false, 'niceUrls' => false, 'app' => array('folder' => 'app', 'paths' => array('config' => 'settings', 'lib' => 'libs', 'model' => 'models', 'helper' => 'helpers', 'controller' => 'controllers'))));
Ejemplo n.º 11
0
	public static function __callStatic($name, $arguments=array()) {
		return SweetFramework::getClass('model', $name);
	}
Ejemplo n.º 12
0
<?
SweetFramework::getClass('lib', 'Config')->setAll('Session', array(
	'timeout' => 31536000,
	'hashFunction' => 'sha512',
	'cookieSecret' => 'h07rsouY43hSNpNAVvcEKDrasdfasdsdfasedefeeeasx5RjTfrthw49BC6xeGNvw2nI55z1RH',
	'cookieName' => 'sweet-hash',
	'use' => array($_SERVER['REMOTE_ADDR']),
	'sslCookies' => false,
	'tableName' => 'sessions',
	'dataTableName' => 'sessiondata'
));
Ejemplo n.º 13
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;
		};
	}
Ejemplo n.º 14
0
	/**
	 * end function. Shuts the party down.
	 * 
	 * @access public
	 * @static
	 * @return void
	 */
	static function end($exit=false) {
		SweetEvent::trigger('SweetFrameworkEnd');
		
		SweetEvent::$events = array();
		
		D::time('App', 'End');
		D::close();
		
		self::$paths = array(
			'lib' => array('/sweet-framework/libs/'),
			'model' => array(),
			'helper' => array('/sweet-framework/helpers/'),
			'controller' => array(),
			'config' => array('/sweet-framework/settings/')
		);
		self::$classes = array();
		if($exit) {
			exit;
		}
	}