Example #1
0
 public static function notFound()
 {
     self::status(404);
     $medusa = new Medusa();
     $medusa->views_path = Globals::get('base_path') . '/olimpus/system/pages';
     $medusa->load('NotFound')->draw();
 }
Example #2
0
 protected function upOrDown($subject, $action)
 {
     Config::load('migrations', true, false);
     $result = array('tables' => array(), 'queries' => array());
     list($database, $table) = explode('/', $subject);
     $database = ucwords($database, '_');
     $table = ucwords($table, '_');
     $database = $database == 'All' ? '' : $database . '_Migration';
     $table = $table == 'All' ? '' : $table . '_Seed.php';
     $migrations_path = Globals::get('base_path') . "/app/migrations";
     $seeds = File::explore("{$migrations_path}/{$database}/{$table}");
     foreach ($seeds as $seed) {
         if (is_file($seed)) {
             //getting the class with namespace from path
             $class = str_replace($migrations_path, '', $seed);
             $class = dirname($class) . '\\' . basename($class, '.php');
             $class = '\\App\\Migrations' . str_replace('/', '\\', $class);
             $seed = new $class();
             if ($action == 'up') {
                 $seed->setup();
                 $seed->up();
                 $result['queries'] = $seed->executed_queries;
             } else {
                 $drop_db = $table == '' ? true : false;
                 $seed->down($drop_db);
                 $result['queries'] = $seed->executed_queries;
             }
             $result['tables'][] = $class;
         }
     }
     return $result;
 }
Example #3
0
 public function testToSetAndGetSomeParam()
 {
     Globals::registre('foo', 'bar');
     $actual = Globals::get('foo');
     $expect = 'bar';
     $this->assertEquals($expect, $actual);
 }
Example #4
0
 /**
  *   Durante el constructor se registra el directorio
  *   base de la aplicacion, la url base completa del la
  *   aplicacion y la url solicitada, se carga el archivo 
  *   de configuracion y se registra el Error handler de 
  *   bitphp
  */
 public function __construct()
 {
     Globals::registre(['base_path' => realpath(''), 'base_url' => $this->getBaseUrl(), 'request_uri' => $this->getRequestUri(), 'app_path' => realpath('') . '/app']);
     Config::load('app');
     $errorHandler = new Error();
     $errorHandler->registre();
 }
Example #5
0
 public function __construct()
 {
     Globals::registre('base_path', realpath(''));
     if ($this->runnigInWebServer()) {
         Response::redir('/');
         exit;
     }
 }
Example #6
0
 protected function setUp()
 {
     \Bitphp\Core\Globals::registre('base_path', '/foo');
     self::$file = array();
     self::$file['params'] = ['foo' => 'abc123', 'bar' => 'zxc456', 'baz' => 'qwe789'];
     self::$file['content'] = 'Something here';
     $hash = md5(json_encode(self::$file['params']));
     self::$file['name'] = '/foo/olimpus/cache/' . $hash . '.lock';
 }
Example #7
0
 /**
  * Retorna un arreglo qué contiene las cadenas json
  * de los errores registrados
  *
  * @return array
  */
 public static function getArrayLog()
 {
     $log_file = Globals::get('base_path') . '/olimpus/log/errors.log';
     $logs = File::read($log_file);
     if (!$logs) {
         return array();
     }
     return explode("\n", $logs);
 }
Example #8
0
 /**
  *   Durante el contructor se obtiene informacion
  *   de la ruta, la ruta en si, el metodo http que
  *   se solicita
  */
 public function __construct()
 {
     parent::__construct();
     $route = Route::parse(Globals::get('request_uri'));
     Globals::registre('uri_params', $route['params']);
     $this->action = $route['action'];
     $this->method = $route['method'];
     $this->routes = array();
     $this->binded = array();
 }
Example #9
0
 /**
  *   Durante el constructor se parsea la ruta de la
  *   url solicitada para obtener el controlador, la
  *   accion y los parametros.
  */
 public function __construct()
 {
     parent::__construct();
     $route = Route::parse(Globals::get('request_uri'));
     extract($route);
     Globals::registre('uri_params', $params);
     $this->controller_namespace = '\\App\\Controllers\\';
     $this->controller_file = Globals::get('app_path') . "/controllers/{$controller}.php";
     $this->controller = $controller;
     $this->action = $action;
 }
Example #10
0
 /**
  *  Registra las funciones para el manejo de errores
  *
  */
 public function registre()
 {
     #ini_set('display_errors', 0);
     error_reporting(E_ALL);
     set_error_handler(array($this, 'globalErrorHandler'));
     register_shutdown_function(array($this, 'fatalErrorHandler'));
     set_exception_handler(array($this, 'exceptionHandler'));
     $this->errors = array();
     $this->log = new Log();
     $this->medusa = new Medusa();
     $this->medusa->views_path = Globals::get('base_path') . '/olimpus/system/pages';
 }
Example #11
0
 /**
  *   Añade un registro de error al archivo de errores
  *   en formato JSON, retorna id del error si el registro
  *   fue satisfactorioo false si este falló
  *
  *   @param int $code indica el codigo de error
  *   @param string $message mensaje de error
  *   @param string $file archivo donde se produjo el error
  *   @param int $line linea donde se produjo el error
  *   @param array $trace trasa de pila
  *   @return mixed false si no se pudo guardar el error, un string
  *                  con el identificador del error si este se guardo
  */
 protected static function record($level, $message, $context)
 {
     # id es un hash md5 formado por la fecha y un numero aleatorio
     $date = date(DATE_ISO8601);
     $identifier = md5($date . rand(0, 9999));
     $log = ['level' => $level, 'date' => $date, 'message' => $message, 'id' => $identifier, 'context' => $context];
     $log = json_encode($log) . PHP_EOL;
     $log_file = Globals::get('base_path') . '/olimpus/log/errors.log';
     if (false === File::append($log_file, $log)) {
         return false;
     }
     return $identifier;
 }
Example #12
0
 /**
  *   Obtiene la entrada (estrictamente limpia) de los parametros de la url
  *
  *   @param mixed $index NOmbre o posicion de la variable a leer
  *   @return string Valor leido o null si no existe
  */
 public static function url($index)
 {
     $parms = Globals::get('uri_params');
     if (is_numeric($index)) {
         if (!isset($parms[$index])) {
             return null;
         }
         $result = $parms[$index];
     } else {
         $index = array_search($index, $parms);
         $result = self::url($index + 1);
     }
     return $result;
 }
Example #13
0
 /**
  *   Corre el modulo especificado
  *
  *   @param string $request Ruta del modulo a correr
  */
 public static function run($request, ...$_args)
 {
     $route = Route::parse($request);
     extract($route);
     self::createEnvironment($application);
     self::registreAutoload($application);
     $controller_file = Globals::get('app_path') . "/controllers/{$controller}.php";
     if (!file_exists($controller_file)) {
         trigger_error("Error al correr '{$request}', el archivo '{$controller_file}' no existe.");
         return;
     }
     # se deja al autocargador hacer su trabajo
     $full_class = "\\App\\{$application}\\Controllers\\" . $controller;
     $controller_obj = new $full_class();
     if (!method_exists($controller_obj, $action)) {
         $message = "La clase del controlador '{$controller}' del modulo '{$request}' ";
         $message .= "no contiene el metodo '{$action}'";
         trigger_error($message);
         return;
     }
     return call_user_func_array(array($controller_obj, $action), $_args);
 }
Example #14
0
 /**
  *   verifica y carga el archivo
  *   de configuracion de la aplicacion
  *
  *   @param string $file Ruta al archivo de configuracion
  *   @param bool $merge indica si se debe mezclar los parametros para cuando se cargan varios archivos
  *   @param bool $environment indica si se debe tomar en cuenta el ambiente de desarrollo
  *   @return void
  */
 public static function load($file, $merge = false, $environment = true)
 {
     $mime = 'json';
     if ($environment) {
         $environment = Environment::info()['current'];
         $mime = "{$environment}.{$mime}";
     }
     $file = Globals::get('base_path') . "/app/config/{$file}.{$mime}";
     if (file_exists($file)) {
         $content = file_get_contents($file);
         #usa la variable global para no cargar el archivo una y otra vez
         $params = json_decode($content, true);
         if (self::$source && $merge) {
             self::$source = 'mixed';
             foreach ($params as $param => $value) {
                 self::$params[$param] = $value;
             }
             return;
         }
         self::$source = $file;
         self::$params = $params;
     }
 }
Example #15
0
 /**
  * Crea un arrglo con las rutas de archivos a remover
  * escanea por defecto /app, /public e index.php
  * manda llamar la funcion identifySkipeds para descartar
  * los archivos omitidos desde la configuracion y tambien
  * agrega al escaneo los directorios y/o archivos
  * indicados en la configuracion
  *
  * @return array
  */
 public static function scan()
 {
     $files = array();
     $base = Globals::get('base_path');
     Config::load('app');
     $dirs = [$base . '/app', $base . '/public', $base . '/index.php'];
     $configured_dirs = Config::param('trash.scan');
     if ($configured_dirs !== null && is_array($configured_dirs)) {
         $dirs = array_merge($dirs, $configured_dirs);
     }
     foreach ($dirs as $dir) {
         $files = array_merge($files, File::explore($dir));
     }
     $files = self::indentifySkipeds($files);
     foreach ($files as $file) {
         # File::explore() devuelve en la lista tambien los
         # directorios escaneados, solo se requieren los archivos
         if (is_dir($file)) {
             $index = array_search($file, $files);
             unset($files[$index]);
             continue;
         }
     }
     return $files;
 }
Example #16
0
 /**
  *  Crea la ruta absoluta al archivo de la vista
  *
  *  @param string $name Nombre de la vista
  *  @return string Ruta completa al archivo de la vista
  */
 protected function getViewPath($name)
 {
     if (!$this->views_path) {
         $this->views_path = Globals::get('app_path') . "/views";
     }
     $path = $this->views_path . "/{$name}" . $this->mime;
     return $path;
 }
Example #17
0
 /**
  *   Crea el nombre de un archivo de cache en base a un arreglo.
  *
  *   @param array $dada Parametros que se toman para general el cache
  *                  por ejemplo el nombre de una vista y los parametros
  *                  que esta recibe.
  *   @return string ruta del archivo del cache
  */
 protected static function generateName($data)
 {
     $label = json_encode($data);
     $dir = Globals::get('base_path') . '/olimpus/cache/';
     return $dir . md5($label) . '.lock';
 }