Ejemplo n.º 1
0
use Chalk\HookManager;
use Chalk\Parser;
use Coast\Controller;
use Coast\Request;
use Coast\Response;
use Coast\Router;
use Coast\Url;
use Coast\UrlResolver;
use Coast\View;
$app = (new Chalk(__DIR__, $config->envs))->param('root', $app)->param('config', $config);
$app->param('em', $app->lazy('app/init/em.php'))->param('cache', $app->lazy('app/init/cache.php'))->param('swift', $app->lazy('app/init/swift.php'))->param('hook', new HookManager())->param('session', $app->config->session)->module(new Core());
$app->load('app/init/funcs.php');
File::baseDir($config->publicDataDir->dir('file'));
File::mimeTypes($app->load('app/init/mime-types.php'));
Toast\Wrapper::$chalk = $app;
Toast\Wrapper::$timezone = $app->config->timezone;
$app->param('backend', $app->lazy(function ($vars) {
    $app = $vars['app'];
    $backend = (new Backend(__DIR__, $app->config->envs))->param('chalk', $app)->param('frontend', $app->frontend)->param('session', $app->session);
    $backend->param('view', new BackendView())->param('parser', new Parser(['isTidy' => true]))->param('notify', new Notifier())->param('controller', new Controller())->param('router', new Router(['target' => $backend->controller, 'params' => ['module' => 'core']]))->param('url', new UrlResolver(['baseUrl' => new Url("{$app->config->backendBaseUrl}"), 'baseDir' => $backend->dir('public'), 'router' => $backend->router]))->param('image', $backend->load('app/init/image.php'))->param('hook', new HookManager())->param('em', $app->em)->param('cache', $app->cache)->param('swift', $app->swift)->failureHandler(function (Request $req, Response $res) {
        return $res->status(404)->html($this->view->render('error/not-found', ['req' => $req, 'res' => $res], 'core'));
    })->errorHandler(function (Request $req, Response $res, Exception $e) {
        if ($this->chalk->isDebug()) {
            throw $e;
        }
        return $res->status(500)->html($this->view->render('error/index', ['req' => $req, 'res' => $res, 'e' => $e], 'core'));
    });
    $backend->executable($backend->image);
    $backend->executable($backend->router);
    $app->param('backend', $backend);
    foreach ($app->modules() as $module) {
Ejemplo n.º 2
0
/*
 * Copyright 2015 Jack Sleight <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE.md. 
 */
use Doctrine\ORM\Configuration;
use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Proxy\Autoloader;
use Chalk\Doctrine\ORM\EntityManager as ChalkEntityManager;
use Chalk\Doctrine\NamingStrategy;
use Chalk\Listener;
\Coast\Doctrine\register_dbal_types();
if (!isset($app->config->database)) {
    throw new \Chalk\Exception('Database connection details are required');
}
$config = new Configuration();
$config->setNamingStrategy(new NamingStrategy());
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
$config->setProxyDir($app->config->dataDir->dir('proxy'));
$config->setProxyNamespace('Chalk\\Proxy');
$config->setAutoGenerateProxyClasses(false);
$config->setQueryCacheImpl($app->cache->value());
$config->setResultCacheImpl($app->cache->value());
$config->setMetadataCacheImpl($app->cache->value());
Autoloader::register($app->config->dataDir->dir('proxy'), 'Chalk\\Proxy');
$evm = new EventManager();
$evm->addEventSubscriber(new Listener());
$em = new ChalkEntityManager(EntityManager::create($app->config->database + ['driver' => 'pdo_mysql', 'charset' => 'utf8'], $config, $evm));
$em->getConnection()->exec("SET NAMES utf8");
Toast\Wrapper::$em = $em;
return $em;