Ejemplo n.º 1
0
 /**
  * Constructor
  */
 public function __construct($rootPath, $configPath)
 {
     if (!self::$instance) {
         self::$instance = $this;
         if (file_exists($configPath)) {
             $this->options = parse_ini_file($configPath, true);
         } else {
             throw new Exception('Config file not found.');
         }
         if (!empty($this->options['Application']) && !empty($this->options['Application']['bootstrap'])) {
             $bootsPath = str_replace('[APP_PATH]', APP_PATH, $this->options['Application']['bootstrap']);
             if (file_exists($bootsPath)) {
                 require_once $bootsPath;
             } else {
                 echo 'Bootstrap not found. ' . $bootsPath;
             }
         }
         if (is_dir($rootPath)) {
             self::$root = $rootPath;
         } else {
             throw new Exception('Root dir not found.');
         }
         K_Request::init();
     } else {
         return self::instance;
     }
 }
Ejemplo n.º 2
0
 /**
  * Call an action
  * @param <type> $routerInfo
  */
 public static function callAction($routerInfo = array())
 {
     $routerInfo['disableLayout'] = isset($routerInfo['disableLayout']) ? $routerInfo['disableLayout'] : true;
     $routerInfo['breakOnRender'] = false;
     $routerInfo['caller'] = 1;
     // 0 - call from internet request, 1 - call local
     K_Capture::start();
     K_Application::get()->executeRequest($routerInfo, true);
     // execute router with autoRender attribute
     return K_Capture::end();
 }
Ejemplo n.º 3
0
 /**
 * Run & capture html + cache
 * @param Array $routerInfo - array( 'controller'=>'...', 'action'=>'...', 'module'=>'...', 'disableLayout'=true, ['params'=>array()] )
 * @param Array $cacheArray - array( 'manager'=>$cacheManagerObject, 'id'=>'cacheID', ['tags'=>array()], ['lifetime'=>(int)60])
 * @param bool $fastDrawCacheData - false - disabled, true - enabled, put content to output buffer & NOT RETURN RESULT HTML (return true on OK), works only if you use cache
 * @example
 		$this->call->html( 
 			array(
 				'module'=>'admin',
 				'controller'=>'index',
 				'action'=>'index',
 				'params'=>array(
 					'id'=>22
 				)
 			),
 			array(
 				'manager' => K_Registry::get('cacheManager')->getCache('unlim'),
 				'id'=>'admin_index_index_22_cache_id',
 				'tags'=>array(
 					'cache-by-call',
 					'id-22',
 					'admin-index-index-22'
 				),
 				'lifetime'=>120
 			),
 			true // on false you can use result HTML, and draw its manually (ONLY IF YOU USE CACHE)
 		);
 */
 public function html($routerInfo = array(), $cacheArray = null, $fastDrawCacheData = false)
 {
     // load from cache
     if (isset($cacheArray) && !empty($cacheArray) && is_array($cacheArray)) {
         if ($cacheArray['manager']->test($cacheArray['id'])) {
             return $cacheArray['manager']->loadRender($cacheArray['id'], $fastDrawCacheData);
         }
     }
     $routerInfo['disableLayout'] = isset($routerInfo['disableLayout']) ? $routerInfo['disableLayout'] : true;
     $routerInfo['breakOnRender'] = false;
     $routerInfo['caller'] = 1;
     // 0 - call from internet request, 1 - call local
     K_Capture::start();
     K_Application::get()->executeRequest($routerInfo, true, false);
     // execute router with autoRender attribute
     $html = K_Capture::end();
     // save to cache
     if (isset($cacheArray) && !empty($cacheArray) && is_array($cacheArray)) {
         $cacheArray['manager']->saveRender($cacheArray['id'], $html, isset($cacheArray['tags']) && is_array($cacheArray['tags']) ? $cacheArray['tags'] : array(), isset($cacheArray['lifetime']) ? (int) $cacheArray['lifetime'] : 0);
     }
     return $html;
 }
Ejemplo n.º 4
0
 public function _render()
 {
     if ($this->_options['disableRender']) {
         if ($this->_options['breakOnRender']) {
             die or exit;
         }
         return;
     }
     if ($this->_options['breakOnRender']) {
         $headers = K_Application::get()->getHeaders();
         if (is_array($headers) && count($headers)) {
             foreach ($headers as $header) {
                 header($header, true);
                 // @TODO may be error TRUE/FALSE on replace
             }
         }
     }
     if (!empty($this->_options['ajaxOutput'])) {
         echo $this->_options['ajaxOutput'];
         die or exit;
     }
     if (is_array($this->_options['helpers']) && count($this->_options['helpers'])) {
         $viewHelper = K_ViewHelper::get();
         foreach ($this->_options['helpers'] as $helper) {
             $viewHelper->loadHelper($this, $helper);
         }
     }
     if (!$this->_options['disableLayout']) {
         $this->_loadLayout();
     } else {
         $this->context();
     }
     if ($this->_options['breakOnRender']) {
         K_Debug::get()->printAll();
         die or exit;
         // ;)
     }
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     K_Debug::get()->enable(false);
     $this->application = K_Application::get();
     K_Registry::write('bootstrap', $this);
 }
Ejemplo n.º 6
0
<?php

defined('ROOT_PATH') || define('ROOT_PATH', realpath(dirname(__FILE__) . '/..'));
require_once realpath(dirname(__FILE__) . '/all_config.php');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(ROOT_PATH), realpath(K_PATH), realpath(ROOT_PATH . '/library'), get_include_path())));
/** Zend_Application */
require_once K_PATH . '/application2.php';
// Create application, bootstrap, and run
$application = new K_Application(ROOT_PATH, ROOT_PATH . '/configs/system/application.ini');
$application->addHeader('Content-type: text/html; charset=utf-8');
try {
    $application->bootstrap()->run();
} catch (Exception $e) {
    echo 'Exception: ' . $e->getMessage();
}