public function __construct($collection, $fieldName) { $this->_collectionId = $collection->getUniqueId(); $this->_fieldName = $fieldName; $this->_fieldString = $this->_collectionId . '.`' . $this->_fieldName . '`'; $this->_fieldUniqueId = kanon::getUniqueId('modelField:' . $this->_collectionId . '.' . $this->_fieldName); }
protected function _saveFile($tmpName, $name) { $ext = '.dat'; if ($dotpos = strrpos($name, ".")) { $ext = strtolower(substr($name, $dotpos)); } $fileName = false; if (!is_file($tmpName)) { return false; } //var_dump($this->_options); //var_dump($this->getControlSet()->getOptions()); ///echo kanon::getBasePath().' '; //echo $this->_getPath().' '; $path = realpath(kanon::getBasePath() . '/' . $this->_getPath()); if ($pk = $this->getItemPrimaryKey()) { $fileName = $path . '/' . $this->_filesPrefix . $pk . $ext; } else { return false; } if ($fileName == '') { $fileName = $this->_tempnam($path, $this->_filesPrefix, $ext); } if ($fileName) { //echo $fileName; //exit; if (copy($tmpName, $fileName)) { return basename($fileName); } } return false; }
public function getUniqueId() { if ($this->_uniqueId === null) { $this->_uniqueId = kanon::getUniqueId(); } return $this->_uniqueId; }
protected function _load() { if ($this->_isLoaded) { return; } static $types = array('model', 'modelProperty', 'controller', 'controlSet', 'control'); $modulePath = kanon::getBasePath() . '/modules/' . $this->_name; if (is_file($modulePath . '/module.php') && is_php($modulePath . '/module.php')) { include $modulePath . '/module.php'; $this->_autoload = $autoload; foreach ($this->_autoload as $class => $filename) { $classFilename = $modulePath . '/' . $filename; if (is_file($classFilename) && is_php($classFilename)) { require_once $classFilename; $type = ''; $r = new ReflectionClass($class); foreach ($types as $checkType) { if ($r->isSubclassOf($checkType)) { $type = $checkType; } } $this->_classes[$type][$class] = $filename; } } } $this->_isLoaded = true; }
public function __construct($argument, $function) { $this->_argument = $argument; $this->_function = $function; $this->_as = kanon::getUniqueId(); //'sql' }
public function index() { $storage = kanon::getStorage('icons'); echo 'Path: ' . $storage->getPath('favicon.ico') . '<br />'; echo 'Url: ' . $storage->getUrl('favicon.ico') . '<br />'; $storage = kanon::getStorage('images'); echo 'Path: ' . $storage->getPath('test.jpg') . '<br />'; echo 'Url: ' . $storage->getUrl('test.jpg') . '<br />'; }
public static function run($applicationClass) { $app = self::getInstance($applicationClass); $app->setBasePath(kanon::getBasePath()); $baseUrl = kanon::getBaseUri(); //echo $baseUrl; $app->setBaseUri($baseUrl); $app->run(); }
public function getUri() { if ($this->_uri !== null) { return $this->_uri; } $baseUrl = 'http://' . request::getServerName() . ''; //$baseUrl. return $this->_options['url']; return kanon::getBaseUri() . '/' . $this->_options['url']; }
public function getTable($tableName) { // Compatibility with zenMysql2 ORM $storage = kanon::getModelStorage(); foreach ($storage->getRegistry()->modelSettings as $modelName => $settings) { if ($settings['table'] == $tableName) { return kanon::getCollection($modelName); } } return false; }
public function __construct($trace = null) { $requestUri = request::getUri(); $requestUri = reset(explode('?', $requestUri)); $this->_filename = basename($requestUri); if ($trace === null) { $trace = debug_backtrace(); } $file = $trace[0]['file']; $this->_basePath = dirname($file); $this->_baseUrl = kanon::getBaseUri(); //$this->_rel = dirname(substr($requestUri, strlen($this->_baseUrl))); $this->_rel = dirname(substr($requestUri, strlen($this->_baseUrl))); }
function __autoload($name) { if (!kanon::autoload($name)) { plugins::autoload($name); } }
public function show($parameters) { foreach ($parameters as $k => $v) { ${$k} = $v; } $this->start('_content'); if (!is_file($this->_filename)) { throw new Exception($this->_filename . " not found"); } $view =& $this; include kanon::getThemedViewFilename($this->_filename); $this->_content = ''; $this->end(); if ($this->_layout !== null) { $this->_filename = dirname($this->_filename) . '/' . $this->_layout; $this->_layout = null; $parameters = $this->_layoutParameters; $this->_layoutParameters = null; $this->show($parameters); } else { echo $this->get('_content'); } }
public static function getBasePath() { if (self::$_basePath === null) { $trace = debug_backtrace(); //var_dump($trace); $last = end($trace); $file = $last['file']; //[1] self::$_basePath = dirname($file); } return self::$_basePath; }
protected $_fields = array('topicId' => 'help_topic_id', 'keywordId' => 'help_keyword_id'); protected $_foreignKeys = array('topicId' => array('helpTopic', 'id'), 'keywordId' => array('helpKeyword', 'id')); } class helpKeyword extends model { protected $_fields = array('id' => 'help_keyword_id', 'name' => 'name'); } class groupImage extends model { protected $_fields = array('id' => 'id', 'groupId' => 'group_id', 'filename' => 'filename', 'createdAt' => 'created_at'); protected $_foreignKeys = array('groupId' => array('group', 'id')); } /*$storage = kanon::getModelStorage() ->connect('mysql:host=localhost;port=3307;dbname=db', 'root', 'password') ;*/ $storage = kanon::getModelStorage()->connect('sqlite:' . dirname(__FILE__) . '/test.sqlite', 'root', ''); $storage->registerCollection('helpCategory', 'help_category'); $storage->registerCollection('helpTopic', 'help_topic'); $storage->registerCollection('helpRelation', 'help_relation'); $storage->registerCollection('helpKeyword', 'help_keyword'); //$storage->getConnection(); /*echo '<pre>'; storageRegistry::dump(); echo '</pre>';*/ $categories = helpCategory::getCollection(); //echo 'start foreach'."\r\n"; //echo $categories->select()->getSql(); foreach ($categories->select() as $category) { } //var_dump($categories->getStorage()->getConnection()->errorInfo()); //echo 'finish foreach'."\r\n";
<?php /** * $Id$ */ require_once '../../kanon-framework.php'; class helloWorld extends controller { public function index() { echo 'Hello world!'; } /** !Route GET $firstName/$lastName */ public function hello($firstName, $lastName) { echo 'Hello ' . $firstName . ' ' . $lastName . '!'; } } kanon::run('helloWorld');
/** * Run controller - select methods and run them */ public function run($methodToRun = null) { $time = microtime(true); kanon::setFinalController($this); $methodFound = false; $class = get_class($this); if (strlen($this->_relativeUri) > 1) { // longer than "/" if ($this->getCurrentUrl() != $this->getCanonicalUrl()) { //echo $this->getCurrentUrl().'<br >'; //echo $this->getCanonicalUrl().'<br >'; // TODO FIX INCORRECT REDIRECTS (resulted in loops) //$this->movedPermanently($this->getCanonicalUrl()); } } if ($action = $this->_relativeUri->getBasePath()) { $this->_action = $action; if (strpos($action, '.') !== false) { $this->_type = end(explode('.', $action)); $action = substr($action, 0, strlen($action) - strlen($this->_type) - 1); // cut .html, .js etc } else { $this->_type = ''; } } profiler::getInstance()->addSql("run() before onConstruct()", $time); $this->onConstruct(); if ($action == 'assets' && $this->_useAssets) { $this->assets(); return; } if ($methodToRun !== null) { if (method_exists($this, $methodToRun)) { $this->_call($methodToRun, $action, $this->_getArgs($methodToRun)); //call_user_func_array(array($this, $methodToRun), $this->_getArgs($methodToRun)); } return; } else { if (extension_loaded('eAccelerator')) { throw new Exception('eAccelerator strips phpdoc blocks. Turn it off.'); } else { if (list($actions, $methodName, $pathArgs) = $this->_getRouteMethod($this->_relativeUri, '!RouteInit')) { $this->_makeChildUri($actions); $methodFound = true; if (method_exists($this, $methodName)) { $this->_call($methodName, $action, $this->_getArgs($methodName, $pathArgs)); //call_user_func_array(array($this, $methodName), $this->_getArgs($methodName, $pathArgs)); } } if (list($actions, $methodName, $pathArgs) = $this->_getRouteMethod($this->_relativeUri, '!Route')) { $this->_makeChildUri($actions); $methodFound = true; if (method_exists($this, $methodName)) { if ($this->getHttpMethod() == 'GET') { $this->_header(); } $this->_call($methodName, $action, $this->_getArgs($methodName, $pathArgs)); //call_user_func_array(array($this, $methodName), $this->_getArgs($methodName, $pathArgs)); if ($this->getHttpMethod() == 'GET') { $this->_footer(); } return; } } } if (!$methodFound) { if ($action) { $uc = ucfirst($action); $this->_makeChildUri(array($this->_action)); $initFunction = 'init' . $uc; if ($controller = kanon::getActionController(get_class($this), $action)) { $this->runController($controller); return; } if (method_exists($this, $initFunction)) { $methodFound = true; $time = microtime(true); call_user_func_array(array($this, $initFunction), $this->_getArgs($initFunction)); profiler::getInstance()->addSql("method " . $initFunction, $time); } $actionFunction = 'action' . $uc; if (method_exists($this, $actionFunction)) { $methodFound = true; call_user_func_array(array($this, $actionFunction), $this->_getArgs($actionFunction)); } $showFunction = 'show' . $uc; if (method_exists($this, $showFunction)) { $methodFound = true; $this->_header(); $time = microtime(true); call_user_func_array(array($this, $showFunction), $this->_getArgs($showFunction)); profiler::getInstance()->addSql("method " . $showFunction, $time); $this->_footer(); } if (!$methodFound) { return $this->_action($action); } } else { if (method_exists($this, 'customIndex')) { $this->customIndex(); } else { //$this->_initIndex(); if (method_exists($this, '_initIndex')) { call_user_func_array(array($this, '_initIndex'), $this->_getArgs('_initIndex')); $methodFound = true; } if (method_exists($this, 'index')) { $time = microtime(true); $this->_header(); profiler::getInstance()->addSql("method _header", $time); $time = microtime(true); call_user_func_array(array($this, 'index'), $this->_getArgs('index')); profiler::getInstance()->addSql("method index", $time); $this->_footer(); $methodFound = true; } if (!$methodFound) { return $this->_action(''); } //$this->index(); } } } } }
/** * Formats a file path. * * @param string $file An absolute file path * @param integer $line The line number * @param string $format The output format (txt or html) * @param string $text Use this text for the link rather than the file path * * @return string */ protected static function formatFile($file, $line, $format = 'html', $text = null) { if (null === $text) { $text = $file; } $linkFormat = 'rcp:%f'; //?%l?0-0//C:\workspace\ if ('html' === $format && $file && $line && $linkFormat) { $localFilename = str_replace(kanon::getBasePath(), '', $file); $text = $localFilename; $link = strtr($linkFormat, array('%f' => $localFilename, '%l' => $line)); //$link = 'data:link/php;base64,'.base64_encode($localFilename); $text = sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $link, $text); } return $text; }