当前位置: 首页>>代码示例>>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;未经允许,请勿转载。