Example #1
0
 public function model(string $name, $id = null)
 {
     $className = $this->loadClass(__FUNCTION__, $name);
     \Model::$auto_prefix_models = 'App\\model\\';
     # this line is unnecessary I think
     return \Model::factory($name);
     /*
             if (is_null($id) === true) {
                 return \Model::factory($name);
             } else {
                 if ($id == 0) {
                     return \Model::factory($name)->create();
                 } else {
                     return \Model::factory($name)->find_one($id);
                 }
             }*/
 }
 public function register(Application $app)
 {
     $app['paris.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         $config = isset($app['idiorm.config']) ? $app['idiorm.config'] : null;
         \ORM::configure($config);
         if (isset($app['paris.model.prefix'])) {
             \Model::$auto_prefix_models = $app['paris.model.prefix'];
         }
     });
     $app['paris'] = $app->share(function ($app) {
         $app['paris.initializer']();
         return new ParisService();
     });
     $app['paris.db'] = $app->share(function ($app) {
         $app['paris.initializer']();
         return \ORM::get_db();
     });
 }
Example #3
0
<?php

# this is a good spot to use lucid::$stage to change your connection settings.
# The initial db config is setup to use a sqlite database, but this is almost
# certainly unsuitable for a production environment where you should be using
# an ACID compliant database. Try out Postgresql or Mysql!
use Lucid\Lucid;
\Model::$auto_prefix_models = 'App\\model\\';
\ORM::configure('caching', true);
\ORM::configure('caching_auto_clear', true);
\ORM::configure('logging', true);
\ORM::configure('logger', function ($logString, $queryTime) {
    lucid::$app->logger()->info($logString . ' in ' . $queryTime);
});
switch (lucid::$app->config()->string('stage')) {
    case 'development':
    case 'qa':
    case 'production':
        \ORM::configure('sqlite:' . __DIR__ . '/../database/development.sqlite');
        break;
}
Example #4
0
<?php

/**
 * Unamed - a WordPress replacement
 *
 * @category CMS
 * @package  Unamed
 * @author   Shane Logsdon <*****@*****.**>
 * @license  MIT http://mit.edu/
 * @link     http://bitbucket.org/slogsdon/unamed
 */
ORM::configure('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME);
ORM::configure('username', DB_USER);
ORM::configure('password', DB_PASS);
ORM::configure('logging', DB_LOGGING);
Model::$auto_prefix_models = '\\Unamed\\Models\\';
Example #5
0
}
/**
 * When you want to load ORM to read and write database
 *
 * @example
 *
 * $app->loadOrm();
 * Model::factory('User')->find_one(1);
 *
 */
$app->inject('loadOrm', function () use($app) {
    $config = $app->database;
    ORM::configure(buildDsn($config));
    ORM::configure('username', $config['username']);
    ORM::configure('password', $config['password']);
    Model::$auto_prefix_models = '\\Model\\';
});
/**
 * The pdo service for global use
 */
$app->share('pdo', function () use($app) {
    $config = $app->database;
    return new PDO(buildDsn($config), $config['username'], $config['password'], $config['options']);
});
return $app;
/**
 * build Dsn string
 *
 * @param array $config
 * @return string
 */
Example #6
0
// Only invoked if mode is "api"
$app->configureMode('api', function () use($app) {
    $app->config(array('view' => new api\View\JsonApiView(), 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'debug' => false));
});
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('base' => $app->request->getScriptName(), 'log.enable' => true, 'log.level' => \Slim\Log::WARN, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('base' => dirname($app->request->getScriptName()) . '/www', 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'debug' => true));
});
// Init database
try {
    if (!empty($config['db']['username'])) {
        \Model::$auto_prefix_models = '\\' . $config['db']['prefix'] . '\\';
        \ORM::configure($config['db']['dsn']);
        \ORM::configure('username', $config['db']['username']);
        \ORM::configure('password', $config['db']['password']);
        ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
    }
} catch (\PDOException $e) {
    $app->getLog()->error($e->getMessage());
}
// load configuration
try {
    $app->config($config);
    $themeconfigcontroller = new \api\Controller\ConfigController();
    $themeconfig = (array) $app->config('theme');
} catch (\PDOException $e) {
    $app->getLog()->error($e->getMessage());
Example #7
0
<?php

define('SERVER_ROOT', dirname(dirname(dirname(__FILE__))));
define('APP_ROOT', SERVER_ROOT . '/app');
define('GENERATOR_ROOT', SERVER_ROOT . '/generator');
define('CONIFG_ROOT', APP_ROOT . '/config/');
# autoload
require SERVER_ROOT . '/vendor/autoload.php';
/** @var \Core\Application $config */
$config = \Core\Application::getInstance();
#region DB
if ($database = $config->get('database')) {
    $host = $database['host'];
    $db = $database['db'];
    $username = $database['username'];
    $password = $database['password'];
    \ORM::configure("mysql:host={$host};dbname={$db};charset=utf8");
    \ORM::configure('username', $username);
    if ($password) {
        \ORM::configure('password', $password);
    }
    \ORM::configure('caching', true);
    \ORM::configure('caching_auto_clear', true);
    \ORM::configure('default_charset', "utf-8");
}
\Model::$auto_prefix_models = '\\Component\\Data\\Model\\';
#endregion
require APP_PATH . '/vendor/autoload.php';
// load configuration
$dotenv = new \Dotenv\Dotenv(APP_PATH);
$dotenv->load();
$dotenv->required(['APP_DEBUG']);
// define the app
$app = new \SlimController\Slim();
// configure application
$app->config(['templates.path' => APP_PATH . '/app/views', 'controller.class_prefix' => '\\app\\controllers', 'controller.class_suffix' => 'Controller', 'controller.method_suffix' => 'Action', 'view' => new \Slim\Views\Twig(), 'log.enabled' => true, 'log.level' => \Slim\Log::DEBUG, 'log.writer' => new \Slim\Logger\DateTimeFileWriter(['path' => APP_PATH . '/storage/logs'])]);
// configure models
require_once APP_PATH . '/vendor/j4mie/idiorm/idiorm.php';
require_once APP_PATH . '/vendor/j4mie/paris/paris.php';
ORM::configure('mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_NAME'));
ORM::configure('username', getenv('DB_USERNAME'));
ORM::configure('password', getenv('DB_PASSWORD'));
Model::$auto_prefix_models = '\\app\\models\\';
// configure views
$app->view()->parserOptions = ['debug' => true, 'cache' => APP_PATH . '/storage/twig'];
$app->view()->parserExtensions = [new \Slim\Views\TwigExtension(), new \src\twig\TwigExtension()];
// environment depending settings
if (getenv('APP_DEBUG') == 'true') {
    // configure logging
    $app->config('debug', true);
    // configure request logging
    $app->hook('slim.after.router', function () use($app) {
        $request = $app->request;
        $response = $app->response;
        $app->log->debug(sprintf('Request path: %s - Response status: %d', $request->getPathInfo(), $response->getStatus()));
    });
    // configure error reporting
    $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
Example #9
0
 function setModelDir($dir, $namespace = "\\Abode\\models\\custom")
 {
     $this->config->set("models.dir", $dir);
     $this->config->set("models.ns", $namespace);
     \Model::$auto_prefix_models = $namespace . "\\";
 }