コード例 #1
0
ファイル: uri.php プロジェクト: huseyinduygun/flexi
 /**
  * This returns the path to the controller and the function within it
  * that have been selected. This is without any parameters and includes
  * the set root path at the beginning.
  */
 public function getPath()
 {
     $path = Flexi::getRootURI();
     if ($this->controller !== null) {
         $path .= $this->controller;
         if ($this->method !== null) {
             $path .= '/' . $this->method;
         }
     }
     return $path;
 }
コード例 #2
0
ファイル: model.php プロジェクト: huseyinduygun/flexi
 /**
  * Creates a new Model.
  * 
  * If 'dbName' is null then it will use the default database (the first one in the config file).
  * 
  * If 'dbName' is null and there is no default database, then none is picked and the 'db' field
  * will not be present in this object.
  */
 public function __construct($dbName = null)
 {
     parent::__construct();
     $flexi = Flexi::getFlexi();
     // setup the db
     if ($dbName == null) {
         $dbConfig = $flexi->getDefaultDatabase();
     } else {
         $dbConfig = $flexi->getDatabase($dbName);
     }
     if ($dbConfig == null) {
         if ($dbName != null) {
             throw new Exception('Database configuration not found, database: ' . $dbName);
         }
     } else {
         $this->load->obj('obj/database', 'db', null, $dbConfig);
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: huseyinduygun/flexi
<?php

// stop scripts from auto-exiting
define('ACCESS_OK', true);
include_once 'flexi/flexi.php';
$flexi = new Flexi();
$flexi->loadConfig('config.php');
// start the website!
try {
    $flexi->run($_SERVER['REQUEST_URI']);
    // display error message
} catch (Exception $ex) {
    ?>
		<h1 id="error_title">Error!</h1>
		<h2 id="error_message"><?php 
    echo $ex->getMessage();
    ?>
</h2>
		<div id="error_stack_Trace" style="white-space: pre"><?php 
    echo $ex->getTraceAsString();
    ?>
</div>
	<?php 
}
コード例 #4
0
ファイル: controller.php プロジェクト: huseyinduygun/flexi
 /**
  * Standard constructor. Creates a new Controller and it builds it's own Loader object.
  */
 public function __construct()
 {
     parent::__construct();
     $this->flexi = Flexi::getFlexi();
     $isInsideView = false;
 }
コード例 #5
0
ファイル: loader.php プロジェクト: huseyinduygun/flexi
 /** 
  * Creates a new Loader which is associated to work on the controller given.
  * This means that any objects it loads (through the obj method) will be
  * assigned to this given controller.
  * 
  * @param controller The controller to associate with this loader.
  */
 public function __construct($parentObj)
 {
     $this->flexi = Flexi::getFlexi();
     $this->parentObj = $parentObj;
 }
コード例 #6
0
ファイル: database.php プロジェクト: huseyinduygun/flexi
 /**
  * Generates the SQL query from the settings placed onto this database object
  * and returns it. No query is performed and the database is left unaltered.
  * 
  * This is mainly for debugging purposes and so you can get copies of the SQL
  * that your queries will make.
  * 
  * @return The SQL code to perform the query currently setup on this database object.
  */
 private function generateSQL()
 {
     $sql = '';
     $ar =& $this->activerecord;
     $isSelect = false;
     if (!isset($ar['table'])) {
         throw new Exception("No table selected in query.");
     }
     // INSERT values
     if (isset($ar['update_on'])) {
         $sql = $this->generateSQLUpdate();
     } else {
         if (isset($ar['insert'])) {
             if (count($ar['table']) > 1) {
                 throw new Exception("Multiple tables selected on insert (can only select one).");
             }
             $sql = $this->generateSQLInsert();
         } else {
             if (isset($ar['delete'])) {
                 $sql = $this->generateSQLDelete();
             } else {
                 $sql = $this->generateSQLSelect();
                 $isSelect = true;
             }
         }
     }
     $debugSaveSQL = Flexi::getFlexi()->get('database_save_sql');
     if ($debugSaveSQL) {
         $file = fopen($debugSaveSQL, 'a');
         fwrite($file, $sql . "\n");
         fclose($file);
     }
     return new DBSQLQuery($sql, $ar['table'], $isSelect);
 }
コード例 #7
0
ファイル: flexi.php プロジェクト: huseyinduygun/flexi
 /**
  * Parses the URI for this page and finds the appropriate controller to run.
  * This is the last thing that should happen in the index and should never be
  * called again.
  * 
  * This is called automatically by the index.php script.
  */
 public function run($uri)
 {
     $this->uri = $uri;
     $uriParts = $this->getURISplit();
     $name = null;
     $function = null;
     $params = array();
     foreach ($uriParts as $part) {
         if ($part !== '') {
             $part = urldecode($part);
             if ($name == null) {
                 $name = $part;
             } else {
                 if ($function == null) {
                     $function = $part;
                 } else {
                     $params[] = $part;
                 }
             }
         }
     }
     // check we have a name and it's not for this script
     if ($name == null || $rootURI . $name == $_SERVER['PHP_SELF']) {
         $name = $this->defaultController;
     }
     // ignore functions beginning with an underscore
     if (strpos($function, '_') === 0) {
         $function = null;
     }
     if ($function == null) {
         $function = $this->defaultFunction;
     }
     $controllerPath = $this->findController($name);
     if ($controllerPath === false) {
         $name = $this->defaultController;
         $controllerPath = $this->findController($name);
     }
     if ($controllerPath === false) {
         throw new Exception('Default controller not found: ' . $this->defaultController);
     } else {
         require $controllerPath;
         if (class_exists($name)) {
             Flexi::pushFlexi($this);
             $controller = new $name();
             if (!method_exists($controller, $function)) {
                 $function = $this->defaultFunction;
             }
             $frame = null;
             if ($this->frames != null) {
                 $frame = $this->frames->getFrame($name, $function);
                 $controller->__setFrame($frame);
             }
             if (!$this->tryControllerMethod($controller, $name, $function, $params)) {
                 Flexi::popFlexi();
                 throw new Exception('Default method \'' . $function . '\' not found in controller: ' . $name . '\'.');
             } else {
                 if ($frame !== null) {
                     $frame->_runToEnd();
                     Flexi::popFlexi();
                 }
             }
         } else {
             Flexi::popFlexi();
             throw new Exception('Controller loaded but class not found: ' . $name);
         }
     }
 }
コード例 #8
0
ファイル: config.php プロジェクト: huseyinduygun/flexi
<?php

if (!defined('ACCESS_OK')) {
    exit('Can\'t access scripts directly!');
}
/**
 * Config
 * 
 * Site wide settings are set in this script. It is devided into different sections
 * for each area.
 */
$flexi = Flexi::getFlexi();
/* --- --- ---
 *  Environment Settings
 * --- --- --- */
// Uncomment to have the DB save it's generated SQL in '/sql.txt'
//    $flexi->set( 'database_save_sql', 'sql.txt' );
// when missing user activation is on by default
//    $flexi->set( 'disable_user_activation_links', true );
/* --- --- ---
 *  Setup
 * --- --- --- */
// The default controller and the default method to use when none is selected or found.
$flexi->setDefaultController('home', 'index');
// The URI location of the root folder for your site. Only alter this
// if it's located within a sub-folder.
// In that case it should be '/sub-folder/'
$flexi->setRootURI("/");
/* --- --- ---
 *  Paths - to find stuff
 * --- --- --- */