Example #1
0
 protected function __construct()
 {
     // require_once (WWW_PATH . '/ExtProce/debug/xhprof/xhprof_lib/utils/xhprof_lib.php');
     // require_once (WWW_PATH . '/ExtProce/debug/xhprof/xhprof_lib/utils/xhprof_runs.php');
     //  xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
     $this->enabled = true;
     self::$instance = $this;
     $this->elapse = K_Time::microtime_float();
 }
Example #2
0
 /**
  * Загружает структуру формы для типа итема 
  * 
  * 
  *    
  */
 public static function loadTypeStructure($type, $formMethodsClass = false, $formMethodsParams = array())
 {
     if ($type) {
         try {
             $typesTable = new K_Tree_Types_Model();
             $typeData = $typesTable->select()->where('`type_name`="' . $type . '"')->fetchRow();
             $unserializedFormData = unserialize($typeData['type_fields']);
             $unserializedFormData = json_decode($unserializedFormData['form_structure']);
             for ($i = 0; $i < sizeof($unserializedFormData); $i++) {
                 if ($unserializedFormData[$i]->type == 'select') {
                     if (!empty($unserializedFormData[$i]->values->method) && $formMethodsClass !== false) {
                         if (method_exists($formMethodsClass, 'f_' . $unserializedFormData[$i]->values->method)) {
                             $className = $formMethodsClass;
                             $methodName = 'f_' . $unserializedFormData[$i]->values->method;
                             $data = $className::$methodName(isset($formMethodsParams[$unserializedFormData[$i]->values->method]) ? $formMethodsParams[$unserializedFormData[$i]->values->method] : array());
                             $unserializedFormData[$i]->options = $data;
                         }
                     }
                 }
             }
             $resultData = array('form_structure' => json_encode($unserializedFormData));
             return $resultData;
         } catch (Exception $err) {
             K_Debug::get()->addError('Model K_Tree_Types_Model not found');
         }
     } else {
         K_Debug::get()->addError('Element ' . $treeId . ' was not loaded. Node required');
     }
 }
Example #3
0
 public function __construct()
 {
     K_Debug::get()->enable(false);
     $this->application = K_Application::get();
     K_Registry::write('bootstrap', $this);
 }
Example #4
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Exception_Exception::text
  * @param   object   exception object
  * @return  boolean
  */
 public static function handler(exception $e)
 {
     try {
         // устанавливаем ошибку в контроллер, что бы не рендерил представление
         K_Controller::setError();
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (isset(K_Exception::$php_errors[$code])) {
                 // Use the human-readable error name
                 $code = K_Exception::$php_errors[$code];
             }
         }
         // Create a text version of the exception
         $error = K_Exception::text($e);
         if (K_Request::isAjax() === true) {
             // Just display the text of the exception
             echo "\n{$error}\n";
             // добовляем ошибку в логгер и дебагер
             K_Log::get()->add($error);
             K_Debug::get()->add($error, $trace);
             exit(1);
         }
         echo "\n{$error}\n";
         // добовляем ошибку в логгер и дебагер
         K_Log::get()->add($error);
         K_Debug::get()->addError($error, $trace);
         exit(1);
     } catch (exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo K_Exception::text($e), "\n";
         // Exit with an error status
         exit(1);
     }
 }
Example #5
0
 /**
  * Fetch without caching & describe
  * @param K_Db_Select/String 	$sql		SQL
  * @param Int 					$count		row count (0 - default/unlimited)
  */
 public function fetchReal($sql, $count = 0, &$model = null, $calculateDuration = true)
 {
     $this->testConnection();
     $initTime = K_Time::microtime_float();
     $return = array();
     $numRows = 'N/A';
     $queryDuration = 'N/A';
     if ($result = $this->mysqli->query($this->_query($sql))) {
         $i = 0;
         if (is_object($result) && $result->num_rows > 0) {
             $numRows = $result->num_rows;
             // for debug
             while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                 if ($this->noDbRow) {
                     $return[] = $row;
                 } else {
                     $return[] = new K_Db_Row($row, $model);
                 }
                 $i++;
                 if ($count > 0 && $i >= $count) {
                     break;
                 }
             }
             $result->close();
         }
     }
     if ($calculateDuration) {
         $this->lastQueryDuration = K_Time::microtime_float() - $initTime;
         $queryDuration = $this->lastQueryDuration;
         // for debug
     }
     //echo $sql."\n";
     K_Debug::get()->addSql($sql, $numRows, $queryDuration);
     $this->noDbRow = false;
     return $return;
 }
Example #6
0
 public function putAjax($data)
 {
     K_Debug::get()->enable(false);
     $this->disableLayout = true;
     $this->rendered = true;
     die($data);
 }
Example #7
0
 protected function outRange(&$text, $fieldName, $params = array())
 {
     if (isset($params[0], $params[1]) && is_numeric($params[0]) && is_numeric($params[1])) {
         $result = $text >= $params[0] && $text <= $params[1];
         if ($result) {
             $this->setError($fieldName, 'FORM_VALIDATE_IN_RANGE', array($params[0], $params[1]));
             return false;
         }
         return true;
     }
     K_Debug::get()->addError('K_Validator :: outRange - undefined range');
     return true;
 }
Example #8
0
 protected function context()
 {
     foreach ($this->viewDirectories as $viewDir) {
         $viewDir = APP_PATH . str_replace(array('{module}', '{controller}'), array($this->_options['module'], $this->_options['controller']), $viewDir);
         if ($this->_options['view'] == strtolower("index")) {
             echo $this->_options['controller'];
             if (is_file($viewDir . '/' . $this->_options['controller'] . TEMPLATE_EXTENSION)) {
                 require $viewDir . '/' . $this->_options['controller'] . TEMPLATE_EXTENSION;
                 return;
             }
             if (is_file($viewDir . '/' . 'index' . TEMPLATE_EXTENSION)) {
                 require $viewDir . '/' . 'index' . TEMPLATE_EXTENSION;
                 return;
             }
         } else {
             if (is_file($viewDir . '/' . $this->_options['view'] . TEMPLATE_EXTENSION)) {
                 require $viewDir . '/' . $this->_options['view'] . TEMPLATE_EXTENSION;
                 return;
             }
         }
     }
     K_Debug::get()->addError('View ' . $this->_options['view'] . TEMPLATE_EXTENSION . ' no found in view directory');
 }