本文整理汇总了PHP中Slim\Slim::config方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::config方法的具体用法?PHP Slim::config怎么用?PHP Slim::config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: openDatabase
/**
* Open a database connection
*
* @param \Slim\Slim $app
* @return \PDO
*/
public static function openDatabase($app)
{
$dsn = $app->config('database.dsn');
$user = $app->config('database.user');
$pass = $app->config('database.pass');
return new \PDO($dsn, $user, $pass);
}
示例2: refresh
/**
* Load config into slim configuration
* @param Slim $app
*/
public function refresh(Slim $app = null)
{
if ($app != null) {
$this->app = $app;
}
$this->app->config($this->config);
}
示例3: setup
/**
* Setup the form service.
*
* @param \Slim\Slim $app The application instance.
*/
public static function setup(Slim $app)
{
$app->container->singleton('form', function () use($app) {
$prefix = $app->config('form.prefix');
return new Form($prefix ?: null);
});
}
示例4: addSettings
/**
* @param array $settings
* @return $this
*/
public function addSettings(array $settings)
{
foreach ($settings as $key => $value) {
$this->app->config($key, $value);
}
return $this;
}
示例5: run
/**
* @return $this
*/
public function run()
{
require_once __DIR__ . '/../config/propel/config.php';
//$this->config = Yaml::parse(file_get_contents(__DIR__ . '/../config/config.yml'));
$this->routes = Yaml::parse(file_get_contents(__DIR__ . '/../config/routes.yml'))['routes'];
$this->app = new \Slim\Slim();
$this->app->config(['templates.path' => __DIR__ . '/Views/']);
$this->oauth = $this->configureOAuth();
$this->instantiateRoutes()->app->run();
return $this;
}
示例6: __construct
public function __construct()
{
$slim = new Slim(['view' => new Twig()]);
$slim->config(['templates.path' => __DIR__ . '/../../view']);
$slim->view()->parserOptions = array('debug' => true, 'cache' => __DIR__ . '/../../compilation_cache');
$slim->config(['content' => ['main_menu' => $this->getMainMenu()]]);
global $config;
ORM::configure("mysql:host={$config['host']};port={$config['port']};dbname={$config['db_name']}");
ORM::configure('username', $config['db_user']);
ORM::configure('password', $config['db_password']);
ORM::configure('driver_options', [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
ORM::configure('error_mode', PDO::ERRMODE_EXCEPTION);
$this->initSlimRoute();
}
示例7: setup
/**
* Setup the template service.
*
* @param \Slim\Slim $app The application instance.
*/
public static function setup(Slim $app)
{
$debug = $app->config('debug');
$view = $app->view(new Twig());
$view->parserOptions = ['debug' => $debug, 'cache' => $app->config('view.cache_path')];
$view->setTemplatesDirectory($app->config('view.path'));
$view->parserExtensions = [new TwigExtension()];
if ($debug) {
$view->parserExtensions[] = new Twig_Extension_Debug();
}
$extensions = (array) $app->config('view.extensions');
foreach ($extensions as $ext) {
$view->parserExtensions[] = new $ext();
}
}
示例8: enable
public function enable(Slim $app)
{
$this->app = $app;
$this->config = $this->app->config('api');
$this->factory = new Factory($this->config['resources']);
// Middleware
$this->app->add(new Database());
$this->app->add(new ApiMiddleware($this->config));
// Routes
$this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get');
$this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list');
$this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put');
$this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post');
$this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete');
}
示例9: render
/**
* Override \Slim\Slim::render method on controller
*
* @param string $tpl
* @param array $data []
* @param string $suffix
* @return void
*/
protected function render($tpl, array $data = [])
{
$suffix = $this->app->config('template.suffix');
$suffix = empty($suffix) ? $this->viewSuffix : $suffix;
$tpl .= $suffix;
$this->app->render($tpl, $data);
}
示例10: configureSlim
/**
* Apply settings to the Slim application.
*
* @param \Slim\Slim $slim Application
*/
protected function configureSlim(\Slim\Slim $slim)
{
$slim->config(array('parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/'), 'es.user' => Config::getStr('ES_USER', ''), 'es.password' => Config::getStr('ES_PASSWORD', ''), 'can.edit' => Config::getBool('CAN_EDIT', false), 'can.vote' => Config::getBool('CAN_VOTE', false), 'oauth.enable' => Config::getBool('USE_OAUTH', false), 'oauth.consumer_token' => Config::getStr('OAUTH_CONSUMER_TOKEN', ''), 'oauth.secret_token' => Config::getStr('OAUTH_SECRET_TOKEN', ''), 'oauth.endpoint' => Config::getStr('OAUTH_ENDPOINT', ''), 'oauth.redir' => Config::getStr('OAUTH_REDIR', ''), 'oauth.callback' => Config::getStr('OAUTH_CALLBACK', '')));
$slim->configureMode('production', function () use($slim) {
$slim->config(array('debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')));
// Install a custom error handler
$slim->error(function (\Exception $e) use($slim) {
$errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8);
$slim->log->critical($e->getMessage(), array('exception' => $e, 'errorId' => $errorId));
$slim->view->set('errorId', $errorId);
$slim->render('error.html');
});
});
$slim->configureMode('development', function () use($slim) {
$slim->config(array('debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false));
});
}
示例11: configureSlim
/**
* Apply settings to the Slim application.
*
* @param \Slim\Slim $slim Application
*/
protected function configureSlim(\Slim\Slim $slim)
{
$slim->config(['parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/')]);
$slim->configureMode('production', function () use($slim) {
$slim->config(['debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')]);
// Install a custom error handler
$slim->error(function (\Exception $e) use($slim) {
$errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8);
$slim->log->critical($e->getMessage(), ['exception' => $e, 'errorId' => $errorId]);
$slim->view->set('errorId', $errorId);
$slim->render('error.html');
});
});
$slim->configureMode('development', function () use($slim) {
$slim->config(['debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false]);
});
}
示例12: __construct
/**
* Constructor for TodoQueue\Controller\Login
*
* @param \Slim\Slim $app Ref to slim app
*/
public function __construct(\Slim\Slim &$app)
{
$this->app = $app;
if ($renderTemplateSuffix = $app->config('controller.template_suffix')) {
$this->renderTemplateSuffix = $renderTemplateSuffix;
}
if (!is_null($paramPrefix = $app->config('controller.param_prefix'))) {
$this->paramPrefix = $paramPrefix;
$prefixLength = strlen($this->paramPrefix);
if ($prefixLength > 0 && substr($this->paramPrefix, -$prefixLength) !== '.') {
$this->paramPrefix .= '.';
}
}
if ($app->config('controller.cleanup_params')) {
$this->paramCleanup = true;
}
}
示例13: configureModes
public static function configureModes(Slim $app, array $modeConfigs)
{
foreach ($modeConfigs as $mode => $config) {
$app->configureMode($mode, function () use($app, $config) {
$app->config($config);
});
}
}
示例14: getFramework
protected function getFramework($config)
{
$app = new Slim(['view' => new Twig()]);
$app->config(['templates.path' => $config['templates.path']]);
$view = $app->view();
$view->parserOptions = $config['parserOptions'];
$view->parserExtensions = array(new TwigExtension());
return $app;
}
示例15: __construct
public function __construct(StorageInterface $storage, Slim $app)
{
$this->storage = $storage;
$this->app = $app;
$this->ignored = $app->config('api.classes.auth.ignored');
if (!is_array($this->ignored)) {
$this->ignored = array();
}
}