當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Slim::environment方法代碼示例

本文整理匯總了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());
         }
     }
 }
開發者ID:nogo,項目名稱:api,代碼行數:23,代碼來源:ResourceController.php

示例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 {
開發者ID:daskleinesys,項目名稱:atton,代碼行數:31,代碼來源:index.php

示例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;
 }
開發者ID:dannykopping,項目名稱:spore,代碼行數:28,代碼來源:Serializer.php

示例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
開發者ID:rohanabraham,項目名稱:lxHive,代碼行數:31,代碼來源:index.php


注:本文中的Slim\Slim::environment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。