Example #1
0
File: App.php Project: arzynik/cana
 public function displayPage($page = null)
 {
     if (is_null($page)) {
         $page = $this->pages();
         $page = isset($page[0]) ? $page[0] : '';
         switch ($page) {
             case '':
                 $pageName = Cana::config()->defaults->page;
                 break;
             default:
                 $pageName = implode('/', $this->pages());
                 break;
         }
     } else {
         $pageName = $page;
     }
     if (getenv('DEBUG')) {
         error_log('>> DISPLAYING PAGE: ' . $pageName);
     }
     try {
         parent::displayPage($pageName == 'error' ? 'home' : $pageName);
     } catch (Exception $e) {
         $this->exception($e);
     }
     return $this;
 }
Example #2
0
 public function testRouterNotHomeFolder()
 {
     $_REQUEST['__url'] = 'nothomefolder';
     $this->ob();
     Cana::app()->buildPages();
     Cana::app()->displayPage();
     $check = $this->ob(false);
     $this->assertEquals('NOTHOME-FOLDER', $check);
 }
Example #3
0
 public function objectMap($a, $b = null)
 {
     // create a new object if not caching
     if (Cana::config()->cache->object === false) {
         $obj = new $a($b);
     } else {
         if (is_string($a)) {
             $t = new $a();
         }
         // NOCACHE: if the first param is an object, and you gave us the id, use the id you gave us
         if (is_object($a) && (is_string($b) || is_int($b))) {
             $obj = $this->_objectMap[get_class($a)][$b] = $a;
             // CACHED: if the first param is an object, the second is an id, and we have it cached
         } elseif (is_object($a) && (is_string($b) || is_int($b)) && $this->_objectMap[get_class($a)][$a->{$b}]) {
             $obj = $this->_objectMap[get_class($a)][$a->{$b}];
             // CACHED: if the first param is an object, and we have it cached
         } elseif (is_object($a) && method_exists($a, 'idVar') && $this->_objectMap[get_class($a)][$a->{$a->idVar()}]) {
             $obj = $this->_objectMap[get_class($a)][$a->{$a->idVar()}];
             // NOCACHE: if the first param is an object with no other info, store it. these come from Cana_Table typicaly
         } elseif (is_object($a) && method_exists($a, 'idVar')) {
             $obj = $this->_objectMap[get_class($a)][$a->{$a->idVar()}] = $a;
             // CACHED: if the first param is the type of object, and the second one is the id
         } elseif (is_string($a) && (is_string($b) || is_int($b)) && $this->_objectMap[$a][$b]) {
             $obj = $this->_objectMap[$a][$b];
             // CACHED: if the first param is the type of object, and the second one is the object and we didnt know that we already had it
         } elseif (is_string($a) && is_object($b) && method_exists($t, 'idVar') && $this->_objectMap[$a][$b->{$t->idVar()}]) {
             $obj = $this->_objectMap[$a][$b->{$t->idVar()}];
             // NOCACHE: we dont have it, so make it and store it
         } elseif ($a) {
             $obj = new $a($b);
             if (!$this->_objectMap[get_class($obj)][$obj->{$obj->idVar()}]) {
                 $this->_objectMap[get_class($obj)][$obj->{$obj->idVar()}] = $obj;
             }
             // NOCACHE: you didnt give us anything to work with
         } else {
             $obj = new Cana_Model();
         }
     }
     // return an object of some type
     $t = null;
     return $obj;
 }
Example #4
0
 public static function gitVersion()
 {
     $v = shell_exec('cd ' . Cana::config()->dirs->root . ' && git rev-parse HEAD');
     return trim($v);
 }
Example #5
0
<?php

/**
 * HTTP entry point
 *
 * @author	Devin Smith (www.devin-smith.com)
 * @date	2009.09.18
 *
 * This uses a caffeine engine base so we can reuse it in the future
 * reguardless of what it is.
 *
 */
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', true);
require_once './app.php';
Cana::app()->displayPage();
Example #6
0
 public static function q($query, $args = null, $db = null)
 {
     $db = $db ? $db : Cana::db();
     $res = $db->query($query, $args);
     $classname = get_called_class();
     while ($row = $res->fetch()) {
         $items[] = new $classname($row);
     }
     //$res->closeCursor();
     return new Cana_Iterator($items);
 }
Example #7
0
File: app.php Project: arzynik/cana
        $fileName = $GLOBALS['config']['dirs']['library'] . $path . '/' . $class . '.php';
        if (file_exists($fileName)) {
            require_once $fileName;
            if (!$ignoreAlias && strpos($className, $prefix) !== 0 && !class_exists($className)) {
                class_alias((strpos($prefix, '/') ? '' : $prefix . '_') . $className, $className);
            }
            return;
        }
    }
    if (!getenv('PHPUNIT')) {
        throw new Cana_Exception_MissingLibrary('The file ' . $GLOBALS['config']['dirs']['library'] . $className . '.php' . ' does not exist');
        exit;
    }
});
// no reason to pass __url
if (!$_REQUEST['__url']) {
    $request = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
    $dir = dirname($_SERVER['SCRIPT_NAME']);
    $base = substr($dir, -1) == '/' ? $dir : $dir . '/';
    $url = preg_replace('/^' . str_replace('/', '\\/', '' . $dir) . '/', '', $request);
    $url = substr($url, 0, 1) == '/' ? $url : '/' . $url;
    $_REQUEST['__url'] = substr($url, 1);
}
if (getenv('TRAVIS')) {
    $configFile = $GLOBALS['config']['dirs']['config'] . 'config.travis.xml';
} elseif (file_exists($GLOBALS['config']['dirs']['config'] . 'config.xml')) {
    $configFile = $GLOBALS['config']['dirs']['config'] . 'config.xml';
}
// init (construct) the static Caffeine application and display the page requested
Cana::init(['app' => 'App_App', 'config' => (new Cana_Config($configFile))->merge($GLOBALS['config'])]);
Example #8
0
 public static function app($app = null)
 {
     if (is_null($app)) {
         return self::$_app;
     } else {
         self::$_app = $app;
     }
 }
Example #9
0
 public static function save($object, $options = array())
 {
     $objectType = get_class($object);
     Cana::config()->cache->object = false;
     $current = new $objectType($object->{$object->idVar()});
     Cana::config()->cache->object = true;
     $oldVals = array();
     $newVals = array();
     foreach ($current->properties() as $var => $val) {
         if (isset($object->{$var})) {
             if ($object->{$var} != $current->{$var}) {
                 $oldVals[$var] = $current->{$var};
                 $newVals[$var] = $object->{$var};
             }
         }
     }
     if (isset($options['custom'])) {
         foreach ($options['custom'] as $key => $customOption) {
             $oldVals[$key] = $customOption['old'];
             $newVals[$key] = $customOption['new'];
         }
     }
     $time = isset($options['timestamp']) ? $options['timestamp'] : date('Y-m-d H:i:s');
     // set
     $set = Cana_Table::fromTable(isset($options['set']['table']) ? $options['set']['table'] : $object->table() . '_change_set', isset($options['set']['id']) ? $options['set']['id'] : $object->idVar() . '_change_set', $object->db());
     $set->strip();
     $set->timestamp = $time;
     if (isset($options['author_id'])) {
         $authorVar = $options['author_id'];
     } elseif (c::admin()->id_admin) {
         $authorVar = 'id_admin';
     } elseif (c::user()->id_user) {
         $authorVar = 'id_user';
     } elseif (isset($options['id_admin'])) {
         $authorVar = 'id_admin';
     }
     if ($authorVar) {
         if (isset($options['author'])) {
             $author = $options['author'];
         } elseif (c::admin()->id_admin) {
             $author = c::admin()->id_admin;
         } elseif (c::user()->id_user) {
             $author = c::user()->id_user;
             // there is some case where the change is made by a cron task
         } elseif (isset($options['id_admin'])) {
             $author = $options['id_admin'];
         }
         if ($author) {
             $set->{$authorVar} = $author;
         }
     }
     $set->{$object->idVar()} = $object->{$object->idVar()};
     // changes. only save set if theres at least one change
     if (count($oldVals)) {
         $set->save();
         foreach ($oldVals as $field => $oldVal) {
             $change = Cana_Table::fromTable(isset($options['change']['table']) ? $options['change']['table'] : $object->table() . '_change', isset($options['change']['id']) ? $options['change']['id'] : $object->{$object->idVar()} . '_change', $object->db());
             $change->strip();
             $change->{$set->idVar()} = $set->{$set->idVar()};
             $change->field = $field;
             $change->new_value = $newVals[$field];
             $change->old_value = $oldVals[$field];
             $change->save();
         }
     }
     return $set;
 }