Пример #1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $app = App::instance()->debug(true);
     $db = $app->service(Database::class);
     $basePath = $app->get('basePath');
     $schemas = ['schema' => $basePath . 'app/schema/1-schema.sql', 'init' => $basePath . 'app/schema/2-init-data.sql', 'dummy' => $basePath . 'app/schema/3-dummy-data.sql'];
     if ($filter = $input->getArgument('schema')) {
         $schemaToImport = [];
         foreach ($filter as $key) {
             if (isset($schemas[$key])) {
                 $schemaToImport[] = $schemas[$key];
             }
         }
     } else {
         $schemaToImport = $schemas;
     }
     foreach ($schemaToImport as $schema) {
         $db->import($schema);
         if ($db->pdo()->errorCode() != '00000') {
             break;
         }
         $output->writeln("    - <fg=green>'{$schema}'</> imported", OutputInterface::VERBOSITY_VERBOSE);
     }
     $error = $db->pdo()->errorInfo();
     if ($error[0] === '00000') {
         $count = count($schemaToImport);
         $output->writeln("  <fg=yellow>{$count} schema imported</>");
     } else {
         $output->writeln("<error>\n({$error['1']}){$error['2']}\n</error>");
     }
 }
Пример #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $db = App::instance()->service(Database::class);
     $db->create();
     $error = $db->pdo()->errorInfo();
     if ($error[0] === '00000') {
         $output->writeln("  <fg=yellow>Database created</>");
     } else {
         $output->writeln("<error>\n({$error['1']}){$error['2']}\n</error>");
     }
 }
Пример #3
0
 protected function seed($table, $callback)
 {
     $tables = is_array($table) ? $table : explode(',', $table);
     $args = [];
     $app = App::instance();
     foreach ($tables as $table) {
         $args[] = $app->service(BatchInsert::class, [$table]);
     }
     $this->tableCounter += count($tables);
     $this->recordInserted += (int) call_user_func_array($callback, $args);
     return $this;
 }
Пример #4
0
 public function __construct()
 {
     $this->app = App::instance();
     if (!$this->templatePath) {
         $this->templatePath = $this->app->get('templatePath');
     }
     if (!$this->viewPath) {
         $fullClass = get_called_class();
         $pos = strrpos($fullClass, '\\');
         $nsp = false === $pos ? '/' : substr($fullClass, 0, $pos);
         $this->viewPath = Helper::fixSlashes(dirname(dirname(__DIR__)) . '/' . $nsp . '/view/');
     }
 }
Пример #5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     // fill table list here
     $tables = ['user'];
     if ($filter = $input->getArgument('table')) {
         $tableToClear = [];
         foreach (explode(',', $filter) as $table) {
             if ($found = array_search($table, $tables)) {
                 $tableToClear[] = $table;
             }
         }
     } else {
         $tableToClear = $tables;
     }
     $db = App::instance()->service(Database::class);
     $sql = '';
     foreach ($tableToClear as $table) {
         $sql .= "delete from {$table};";
     }
     $db->exec($sql);
     $count = count($tableToClear);
     $output->writeln("  <fg=yellow>{$count} table(s) cleared</>");
 }
Пример #6
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $db = App::instance()->service(Database::class);
     $db->drop();
     $output->writeln("  <fg=yellow>Database dropped</>");
 }
Пример #7
0
<?php

use app\core\App;
require_once '../app/Config.php';
require_once '../app/AutoLoad.php';
// default controller and its action
define('DEFAULT_CONTROLLER', 'HomeController');
define('DEFAULT_ACTION', 'indexAction');
define('DEFAULT_ROUTE', 'home');
// db connection params
define('DB_DRIVER', 'MySQLiDriver');
define("DB_CONN_PARAMS", serialize(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'db' => 'snp')));
// adding routes to global Scope
$app = new App();
$app->addRoute('home', 'Home', false);
$app->addRoute('register', 'Register', false);
$app->addRoute('login', 'Login', false);
$app->addRoute('news', 'News', false);
$app->addRoute('categories', 'Category', false);
$app->addRoute('comments', 'Comment', false);
$app->addRoute('logout', 'Logout', false);
$app->run();
Пример #8
0
 /**
  * Log query if debug active
  * @param  string $sql
  * @param  array  $params
  * @param  array  $error
  */
 public function log($sql, array $params, array $error)
 {
     $app = App::instance();
     if ($app->debug()) {
         $no = -1;
         $params = array_merge($params, []);
         $this->logs[] = preg_replace_callback('/(?<qm>\\?)|(?<p>:\\w+)/', function ($match) use(&$no, $params) {
             $no++;
             if (isset($match['qm']) && isset($params[$no])) {
                 return "'" . $params[$no] . "'";
             } elseif (isset($match['p']) && isset($params[$match['p']])) {
                 return "'" . $params[$match['p']] . "'";
             } else {
                 return isset($match['qm']) ? '?' : ':' . $match['p'];
             }
         }, $sql);
         if ('00000' !== $error[0]) {
             $this->errors[] = $error;
             if (!$app->get('continueOnDBError')) {
                 $this->dumpError();
             }
         }
     }
 }
Пример #9
0
header("Cache-Control: no-transform");
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(__FILE__));
define('SERVER_NAME', $_SERVER['SERVER_NAME']);
require_once 'App/Core/App.php';
require_once 'App/Core/Autoloader.php';
$config = array('db' => array('host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'test'));
function show_error($heading, $message, $template = '')
{
    //pr($traces);
    $msg = '<b>' . $heading . ' : </b><br/>' . $message . '<br/>';
    /*$traces = debug_backtrace();
      foreach ($traces[0] as $k => $v){
          if(!is_object($v) && !is_array($v)){
              if($k == 'file' || $k == 'line'){
                  $msg .= '<b>'.$k .'</b> => '.$v.'<br/>';
             }
          }           
      }*/
    $res = array();
    $res['error'] = $msg;
    echo json_encode($res);
}
function pr($t)
{
    echo '<pre>';
    print_r($t);
}
Core\App::run($config);
Пример #10
0
<?php

use app\Model;
use app\core\App;
use app\core\Breadcrumb;
use app\core\Database;
use app\core\Loader;
// require loader
require __DIR__ . '/core/Loader.php';
$loader = new Loader();
$loader->add(dirname(__DIR__))->register();
// instantiate main class
$app = App::instance();
// register configuration from file
// it will remains in App properties
$config = $app->load(__DIR__ . '/config/config.php');
$app->register($config);
// configure services
$database = $app->load(__DIR__ . '/config/database.php');
$rules = [Database::class => ['constructParams' => [$database], 'shared' => true], Model::class => ['shared' => true]];
$service = $app->service();
foreach ($rules as $key => $value) {
    $service->addRule($key, $value);
}