Ejemplo n.º 1
0
 /**
  * Clear the whole storage
  *
  * @return null
  */
 public function clear()
 {
     foreach (glob(\Kalibri::app()->getLocation() . 'Data/cache/*') as $file) {
         if (is_file($file)) {
             unlink($file);
             // delete file
         }
     }
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     if (!$this->tableName) {
         $this->tableName = strtolower(str_replace(array(\Kalibri::app()->getNamespace() . '\\App\\Model\\', 'Kalibri\\Model\\'), '', get_class($this)));
     }
     $this->keyField = $this->keyField ?: $this->tableName . '_id';
     $this->_cache = \Kalibri::cache();
     // Register model
     \Kalibri::model($this->tableName, $this);
 }
Ejemplo n.º 3
0
 public function load($configName = null, $configLocation = null)
 {
     $configName = $configName ?: self::MAIN_CONFIG_NAME;
     $configLocation = $configLocation ?: \Kalibri::app()->getLocation() . 'App/Config/';
     $configPath = $configLocation . $configName . '.php';
     if (file_exists($configPath)) {
         $this->_data = array_merge($this->_data, include $configPath);
         (K_COMPILE_BASE || K_COMPILE_ROUTES) && \Kalibri::compiler()->skip($configPath);
         return $this;
     }
     throw new \Kalibri\Exception("Config '{$configName}' not found");
 }
Ejemplo n.º 4
0
 public function __construct(array $data = null)
 {
     if (!$this->_modelName) {
         $this->_modelName = strtolower(str_replace([\Kalibri::app()->getNamespace() . '\\App\\Model\\Entity\\', 'Kalibri\\Model\\Entity\\'], '', get_class($this)));
     }
     if (!$this->_primaryName) {
         $this->_primaryName = Text::underscoreToCamel(\Kalibri::model($this->_modelName)->getKeyFieldName());
     }
     if ($data !== null) {
         $this->initData($data);
     }
 }
Ejemplo n.º 5
0
 /**
  * Get all marks. Allmost the same as Kalibri\Benchmark::get(TRUE)
  * but point will not autocomplete
  *
  * @param bool @stopAll
  *
  * @return array
  */
 public function getMarks($stopAll = false)
 {
     if ($stopAll) {
         $total = array('time' => 0, 'memory' => 0, 'marks' => 0, 'peak_memory' => 0, 'includes' => array());
         if (function_exists('memory_get_peak_usage')) {
             $total['peak_memory'] = memory_get_peak_usage(false);
         }
         if (function_exists('get_included_files')) {
             $total['includes'] = get_included_files();
             $basePath = substr(\Kalibri::app()->getLocation(), 0, -strlen(\Kalibri::app()->getNamespace()) - 2);
             $includesCount = count($total['includes']);
             for ($i = 0; $i < $includesCount; $i++) {
                 $total['includes'][$i] = str_replace($basePath, '', $total['includes'][$i]);
             }
         }
         foreach ($this->_marks as $name => $mark) {
             if (!$mark['stop']) {
                 $mark = $this->stop($name);
             }
             $total['time'] += $mark['execution'];
             $total['memory'] += $mark['memory_used'];
         }
         $total['marks'] = count($this->_marks);
         $this->_marks[self::RESULTS_MARK] = $total;
     }
     return $this->_marks;
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     $this->_appName = \Kalibri::app()->getNamespace();
 }
Ejemplo n.º 7
0
 public function checkProjectBase()
 {
     $map = \Kalibri::config()->get('route.map-project');
     if ($map) {
         foreach ($map as $way => $name) {
             if ($way == $this->_segments[0]) {
                 // Remove first segment that contains map key
                 array_shift($this->_segments);
                 return $name;
             }
         }
     }
     return \Kalibri::app()->getNamespace();
 }
Ejemplo n.º 8
0
 /**
  * Get view file name location
  *
  * @param string $name View name
  *
  * @return string
  */
 public function getLocation($name = null, $path = null)
 {
     $appLocation = \Kalibri::app()->getLocation() . '/App';
     if ($name === null) {
         $name = $this->_name;
     }
     //var_dump( $this->viewsDir );
     // Search in location if specified
     if ($path !== null) {
         // Add trailing slash at the end
         if ($path !== '' && $path[\strlen($path) - 1] !== '/') {
             $path .= '/';
         }
         return $path . $this->viewsDir . '/' . $name . '.php';
     }
     // Search in application path
     if (\file_exists($appLocation . $this->viewsDir . '/' . $name . '.php')) {
         return $appLocation . $this->viewsDir . '/' . $name . '.php';
     }
     // Try to find template in base kalibri templates
     if (\file_exists(K_ROOT . self::DIR_FALLBACK_VIEWS . '/' . $name . '.php')) {
         return K_ROOT . self::DIR_FALLBACK_VIEWS . '/' . $name . '.php';
     }
     return null;
 }
Ejemplo n.º 9
0
 public function load($shortName = null)
 {
     $shortName = $shortName ?: $this->_currentLang;
     if (isset($this->_isLoaded[$shortName])) {
         return true;
     }
     $appLocation = \Kalibri::app()->getLocation();
     $locations = array(K_ROOT . 'Kalibri/Data/Locale/' . $shortName . '/', $appLocation . 'Locale/' . $shortName . '/');
     if (!isset($this->_messages[$shortName])) {
         $this->_messages[$shortName] = array();
     }
     foreach ($locations as $location) {
         if (is_dir($location)) {
             foreach (scandir($location) as $fileName) {
                 if (!is_dir($location . $fileName)) {
                     $this->_messages[$shortName] = array_merge($this->_messages[$shortName], include $location . $fileName);
                 }
             }
         }
     }
     $this->_isLoaded[$shortName] = true;
 }
Ejemplo n.º 10
0
<?php

session_start();
define('PAGE_START', microtime(true));
define('K_APP_FOLDER', str_replace('\\', '/', realpath('..')) . '/');
require_once '../../Kalibri/_init.php';
$appMode = strpos($_SERVER['HTTP_HOST'], '.dev') === false ? null : 'dev';
Kalibri::app(new \Kalibri\Application(K_APP_FOLDER, $appMode))->run();