本文整理汇总了PHP中Slim\Slim::environment方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::environment方法的具体用法?PHP Slim::environment怎么用?PHP Slim::environment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::environment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putAction
/**
* [PUT] /$resource/$id
* @param string $resource
* @param int $id
* @return type
*/
public function putAction($resource, $id)
{
$modelClass = $this->factory->with($resource);
$model = $modelClass->find($id);
if (is_null($model)) {
$this->render(['error' => 'Not found'], 404);
} else {
$env = $this->app->environment();
if (empty($env['slim.input'])) {
$this->render(['error' => 'Data not valid'], 400);
} else {
$model->fill($env['slim.input']);
$model->save();
$this->render($model->toArray());
}
}
}
示例2: Slim
// LOADING FRAMEWORKS
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Tools' . DIRECTORY_SEPARATOR . 'Autoloader.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'defines' . DIRECTORY_SEPARATOR . 'defines.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'defines' . DIRECTORY_SEPARATOR . 'gamevars.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'defines' . DIRECTORY_SEPARATOR . 'configuration.php';
// INIT ERROR-HANDLING && LOGGING
global $log4php_config;
\Logger::configure($log4php_config);
$logger = \Logger::getLogger('index.php');
// INIT SLIM APP
$app = new Slim(array('debug' => $debug, 'view' => new Twig()));
$view = $app->view();
$view->parserExtensions = array(new \Twig_Extension_Debug());
$view->parserOptions = array('debug' => $debug);
$env = $app->environment();
$env['basepath'] = __DIR__;
// DEFINE SLIM-ERROR HANDLING
$app->error(function (\Exception $e) use($app, $logger) {
$logger->error($e->getMessage());
$data = array();
HeaderViewHelper::parseCurrentUser($data);
$app->render('error.twig', $data);
});
$app->notFound(function () use($app) {
$data = array();
HeaderViewHelper::parseCurrentUser($data);
$app->render('404.twig', $data);
});
// INIT DB-CONNECTION
try {
示例3: getSerializedData
/**
* Serialize the data based on the provided "Accept" header if it exists,
* otherwise revert to the predefined default content-type
*
* @param \Slim\Slim $app
* @param $data
*
* @return array|mixed
*/
public static function getSerializedData(Slim $app, $data)
{
self::$contentTypes = $app->config("serializers");
$env = $app->environment();
$acceptableContentTypes = explode(";", $env["ACCEPT"]);
$contentType = "";
if (count($acceptableContentTypes) > 1 || empty($acceptableContentTypes)) {
$contentType = $app->config("content-type");
} else {
$contentType = $acceptableContentTypes[0];
}
// don't allow */* as the content-type, rather favour the default content-type
if ($contentType == "*/*") {
$contentType = $app->config("content-type");
}
$app->contentType($contentType);
$data = self::serialize($app, $data, $contentType);
return $data;
}
示例4: function
Resource::error($code, $e->getMessage());
});
// Database layer setup
$app->hook('slim.before', function () use($app) {
$app->container->singleton('mongo', function () use($app) {
$client = new Client($app->config('database')['host_uri']);
$client->map([$app->config('database')['db_name'] => '\\API\\Collection']);
$client->useDatabase($app->config('database')['db_name']);
return $client;
});
});
// CORS compatibility layer (Internet Explorer)
$app->hook('slim.before.router', function () use($app) {
if ($app->request->isPost() && $app->request->get('method')) {
$method = $app->request->get('method');
$app->environment()['REQUEST_METHOD'] = strtoupper($method);
mb_parse_str($app->request->getBody(), $postData);
$parameters = new Set($postData);
if ($parameters->has('content')) {
$content = $parameters->get('content');
$app->environment()['slim.input'] = $content;
$parameters->remove('content');
} else {
// Content is the only valid body parameter...everything else are either headers or query parameters
$app->environment()['slim.input'] = '';
}
$app->request->headers->replace($parameters->all());
$app->environment()['slim.request.query_hash'] = $parameters->all();
}
});
// Parse version