/** * Uses the configuration from the application and returns the LooEntityManager. * * @return LooEntityManager */ public function getEntityManager() { if (empty(static::$entityManager)) { $config = Setup::createAnnotationMetadataConfiguration(Settings::getEntityPaths(), Settings::isDevMode()); $connection = Settings::getDbConnection(); static::$entityManager = LooEntityManager::create($connection, $config); } return static::$entityManager; }
/** * Creates an url with the base url and the given parameters * * @param string $controller * @param string $action * @param array $data * @return string */ public static function url($controller = '', $action = '', array $data = []) { $url = Settings::getBaseUrl(); if ($controller) { $url .= $controller; } if ($action) { $url .= '/' . $action; } if (!empty($data)) { $url .= '?' . http_build_query($data); } return $url; }
/** * Run the application. If there is an exception thrown send an 500. * * @param Request $request */ public function run(Request $request) { try { $this->handleRequest($request); } catch (Exception $e) { $logger = $this->masterFactory->getDebugFactory()->getErrorLogger(); $logger->error($e->getMessage() . PHP_EOL . $e->getTraceAsString()); header(sprintf('Status: %s', Response::getMessageForCode(500))); if (Settings::isDevMode()) { echo $e->getMessage() . PHP_EOL; echo '<pre>'; echo $e->getTraceAsString(); echo '</pre>'; } } }
/** * @param string $channel \Debug\LoggerChannel * @param int $level \Debug\LoggerLevel * * @return Logger */ protected function getLogger($level = LoggerLevel::DEBUG, $channel = LoggerChannel::MAIN) { $logger = new Logger($channel); $logger->pushHandler($this->getStreamHandler(Settings::getLogPath() . $channel . '.log', $level)); return $logger; }
/** * @param string $layout * @return string * @throws FieldNotSetException */ protected function getLayoutFile($layout) { if (!isset(Settings::getLayouts()[$layout])) { throw new FieldNotSetException($layout . ' is not set'); } return Settings::getBasePath() . Settings::getLayouts()[$layout]; }
?> <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="Orcs"> <meta name="author" content="Daniel Weiss"> <link rel="shortcut icon" href="<?php echo Settings::getPublicUrl(); ?> favicon.ico" /> <title><?php echo isset($this->title) ? $this->title : Settings::getAppName(); ?> </title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> </head> <body> <div class="container"> <?php echo $this->renderContent(); ?> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<?php use Loo\Core\MasterFactory; use Loo\Data\Settings; define('ROOT', __DIR__); include_once 'vendor/autoload.php'; $factory = new MasterFactory(); Settings::setConfig($factory->getDataFactory()->getConfig()); Settings::setErrorHandling(); Settings::setPhpSettings();
/** * @dataProvider urlDataProvider * @param string $controller * @param string $action * @param array $data * @param string $expected */ public function testUrl($controller, $action, $data, $expected) { Settings::setConfig(new Store(['base_url' => 'http://foo.local/'])); $this->assertEquals($expected, Helper::url($controller, $action, $data)); }