当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::response方法代码示例

本文整理汇总了PHP中Slim\Slim::response方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::response方法的具体用法?PHP Slim::response怎么用?PHP Slim::response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Slim的用法示例。


在下文中一共展示了Slim::response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: inscription

 public function inscription(\Slim\Slim $app)
 {
     $allPostVars = $app->request->post();
     $username = $allPostVars['username'];
     $mail = $allPostVars['mail'];
     $mdp = $allPostVars['mdp'];
     try {
         $db = getDB();
         $verif = $db->prepare("SELECT username \n\t\t\t\tFROM users\n\t\t\t\tWHERE username = :username");
         $verif->bindParam(':username', $username, PDO::PARAM_INT);
         $verif->execute();
         $usernamed = $verif->fetch(PDO::FETCH_OBJ);
         $verif->closeCursor();
         if ($usernamed) {
             $answer = "Ce nom d'utilisateur est déjà pris, merci de retenter avec un nouveau.";
         } else {
             $sth = $db->prepare("INSERT INTO users \n\t\t\t\t(username, mail, mdp)\n\t\t\t\tVALUES (:username, :mail, :mdp)");
             $sth->bindParam(':username', $username, PDO::PARAM_INT);
             $sth->bindParam(':mail', $mail, PDO::PARAM_INT);
             $sth->bindParam(':mdp', $mdp, PDO::PARAM_INT);
             $sth->execute();
             $answer = array("status" => "success", "code" => 1);
         }
         $app->response->setStatus(200);
         $app->response()->headers->set('Content-Type', 'application/json');
         echo json_encode($answer);
         $db = null;
     } catch (PDOException $e) {
         $app->response()->setStatus(404);
         echo '{"error":{"text":' . $e->getMessage() . '}}';
     }
 }
开发者ID:antoninriviere,项目名称:slimrest,代码行数:32,代码来源:class-connexion.php

示例2: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     // Capture STDOUT
     ob_start();
     $options = array('REQUEST_METHOD' => strtoupper($method), 'PATH_INFO' => $path, 'SERVER_NAME' => 'local.dev');
     if ($method === 'get') {
         $options['QUERY_STRING'] = http_build_query($data);
     } elseif (is_array($data)) {
         $options['slim.input'] = http_build_query($data);
     } else {
         $options['slim.input'] = $data;
     }
     // Prepare a mock environment
     Slim\Environment::mock(array_merge($options, $optionalHeaders));
     $env = Slim\Environment::getInstance();
     $this->app->router = new NoCacheRouter($this->app->router);
     $this->app->request = new Slim\Http\Request($env);
     // Custom headers
     $this->app->request->headers = new Slim\Http\Headers($env);
     $this->app->response = new Slim\Http\Response();
     // Establish some useful references to the slim app properties
     $this->request = $this->app->request();
     $this->response = $this->app->response();
     // Execute our app
     $this->app->run();
     // Return the application output. Also available in `response->body()`
     return ob_get_clean();
 }
开发者ID:hochanh,项目名称:slim-test-helpers,代码行数:28,代码来源:WebTestClient.php

示例3: loginUser

function loginUser(\Slim\Slim $slimApp)
{
    //echo "middleware:loginUser";
    $request = $slimApp->request;
    $response = $slimApp->response();
    $response->headers->set('Content-Type', 'application/json');
    //
    $userData = json_decode($request->getBody());
    $name = $userData->userName;
    $password = $userData->password;
    $email = $userData->email;
    //
    $dbUtil = new \icraft\DBUtil();
    $DBH = $dbUtil->getConnection();
    // $sql = "SELECT * FROM `users` WHERE uName=\'saumya\' && uPassword=\'saumyaPW1\'";
    //$STH = $DBH->prepare("SELECT * FROM `users` WHERE uName='$name' && uPassword='$password'");
    $STH = $DBH->query("SELECT * FROM `users` WHERE uName='{$name}' && uPassword='{$password}'");
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    //$STH->execute();
    //var_dump($STH);
    $response->body('FAIL');
    // Default FAIL
    while ($row = $STH->fetch()) {
        /*
        echo $row['uName'] . "\n";
        echo $row['uPassword'] . "\n";
        echo $row['uEmail'] . "\n";
        */
        $n = $row['uName'];
        $p = $row['uPassword'];
        $e = $row['uEmail'];
        $responseObj = "{'status':'SUCCESS','userObj':{'name':{$n},'password':{$p},'email':{$e}}}";
        $response->body($responseObj);
    }
}
开发者ID:saumya,项目名称:slimCraft,代码行数:35,代码来源:middleWare.php

示例4:

 /**
  * constructor
  */
 final function __construct()
 {
     self::$app || (self::$app = \Slim\Slim::getInstance());
     $this->request = self::$app->request();
     $this->response = self::$app->response();
     $this->config = self::$app->config;
     $this->validator = self::$app->validator;
     $this->init();
 }
开发者ID:donghaichen,项目名称:Clover,代码行数:12,代码来源:BaseController.php

示例5: xmlOutput

 /**
  * @param IXmlExporter $exporter
  * @param int $status
  * @param string $contentType
  */
 protected function xmlOutput(IXmlExporter $exporter, $status = 200, $contentType = 'application/xml')
 {
     $this->app->expires(0);
     $this->app->contentType($contentType);
     $response = $this->app->response();
     $response->setStatus($status);
     $response->header('Content-Description', 'File Transfer');
     if ($exporter->isFile()) {
         $response->header('Content-Disposition', 'attachment; filename=' . $exporter->getFileName());
     }
     $response->body($exporter->buildXml());
 }
开发者ID:nextglory,项目名称:CacoCloud,代码行数:17,代码来源:REST.php

示例6: checkAuth

 /**
  * @param Route $route
  * @throws \Slim\Exception\Stop
  */
 private function checkAuth(Route $route)
 {
     $request = OAuth2\Request::createFromGlobals();
     $scopeRequired = [];
     if ($route->isSecure()) {
         $scopeRequired = 'admin';
     }
     if (!$this->oauth->verifyResourceRequest($request, NULL, $scopeRequired)) {
         $response = $this->oauth->getResponse();
         $this->app->response()->status($response->getStatusCode());
         $response->send();
         $this->app->stop();
     }
 }
开发者ID:alexdevid,项目名称:slim-rest,代码行数:18,代码来源:Kernel.php

示例7: __construct

 public function __construct(Slim $app, array $params = array())
 {
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     $this->params = $this->buildParams($params);
 }
开发者ID:benconnito,项目名称:kopper,代码行数:7,代码来源:Controller.php

示例8: __construct

 /**
  * Constructor
  * 
  * @param Slim $app
  */
 public function __construct(Slim $app, array $config = [])
 {
     $this->app = $app;
     $this->dic = $app->dic;
     $this->request = $app->request();
     $this->response = $app->response();
     $this->config = $config;
 }
开发者ID:chippyash,项目名称:slim-dic,代码行数:13,代码来源:AbstractController.php

示例9: __invoke

 /**
  * Call this class as a function.
  *
  * @return void
  */
 public function __invoke()
 {
     $request = MessageBridge::newOAuth2Request($this->slim->request());
     $response = new OAuth2\Response();
     $isValid = $this->server->validateAuthorizeRequest($request, $response);
     if (!$isValid) {
         MessageBridge::mapResponse($response, $this->slim->response());
         return;
     }
     $authorized = $this->slim->request()->params('authorized');
     if (empty($authorized)) {
         $this->slim->render($this->template, ['client_id' => $request->query('client_id', false)]);
         return;
     }
     //@TODO implement user_id
     $this->server->handleAuthorizeRequest($request, $response, $authorized === 'yes');
     MessageBridge::mapResponse($response, $this->slim->response());
 }
开发者ID:tularamaurya,项目名称:slim-oauth2-routes,代码行数:23,代码来源:Authorize.php

示例10: request

 public function request($method, $path, $options = array())
 {
     ob_start();
     Environment::mock(array_merge(array('PATH_INFO' => $path, 'SERVER_NAME' => 'slim-test.dev', 'REQUEST_METHOD' => $method), $options));
     $app = new Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     return ob_get_clean();
 }
开发者ID:emeka-osuagwu,项目名称:sweetemoji,代码行数:10,代码来源:RouteTest.php

示例11: request

 public function request($method, $path, $options = array())
 {
     // Capture STDOUT
     ob_start();
     // Prepare a mock environment
     Environment::mock(array_merge(array('REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'SERVER_NAME' => 'mock.matrix42.com'), $options));
     $app = new Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     // Return STDOUT
     return ob_get_clean();
 }
开发者ID:akarimgh,项目名称:matrix42-slim-api,代码行数:13,代码来源:test-route.php

示例12: handleException

 /**
  * Return HTTP status code and message to requester.
  *
  * @param Slim      $app
  * @param Exception $e
  *
  * @return mixed
  */
 private function handleException($app, Exception $e)
 {
     $status = $e->getCode();
     $statusText = \Slim\Http\Response::getMessageForCode($status);
     if ($statusText === null) {
         $status = 500;
         $statusText = 'Internal Server Error';
     }
     $app->response->setStatus($status);
     $app->response->headers->set('Content-Type', 'application/json');
     $app->response->setBody(json_encode(array('status' => $status, 'statusText' => preg_replace('/^[0-9]+ (.*)$/', '$1', $statusText), 'description' => $e->getMessage())));
     $app->response()->finalize();
     return $app->response();
 }
开发者ID:usf-it,项目名称:usf-idm-common,代码行数:22,代码来源:SlimLogMiddleware.php

示例13: register

 public function register(Slim $app)
 {
     $app->container->singleton('cache', function () {
         return new FilesystemCache('tmp/cache/db');
     });
     $app->container->singleton('connection', function () {
         $dbOptions = (require 'config/connection.config.php');
         $config = new Configuration();
         return DriverManager::getConnection($dbOptions, $config);
     });
     $app->container->singleton('log', function () {
         $logger = new Logger('echale-gas');
         $logger->pushHandler(new StreamHandler('tmp/logs/app.log', LogLevel::DEBUG));
         return $logger;
     });
     $app->container->singleton('paginator', function () use($app) {
         return new PagerfantaPaginator($app->config('defaultPageSize'));
     });
     $app->container->singleton('paginatorFactory', function () use($app) {
         return new PaginatorFactory($app->paginator);
     });
     $app->container->singleton('proxiesConfiguration', function () use($app) {
         $config = new ProxyConfiguration();
         $config->setProxiesTargetDir('tmp/cache/proxies');
         spl_autoload_register($config->getProxyAutoloader());
         return $config;
     });
     $app->urlHelper = new TwigExtension();
     $app->container->singleton('twig', function () use($app) {
         $twig = new Twig();
         $twig->parserOptions = ['charset' => 'utf-8', 'cache' => realpath('tmp/cache/twig'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true];
         $twig->parserExtensions = [$app->urlHelper, new HalRendererExtension()];
         return $twig;
     });
     $app->container->singleton('controllerEvents', function () use($app) {
         $eventManager = new EventManager();
         // Ensure rendering is performed at the end by assigning a very low priority
         $eventManager->attach('postDispatch', new RenderResourceListener($app->twig), -100);
         $eventManager->attach('renderErrors', new RenderErrorsListener($app->twig), -100);
         return $eventManager;
     });
     $app->container->singleton('controller', function () use($app) {
         $controller = new RestController($app->request(), $app->response());
         $factory = new RestControllerProxyFactory($app->proxiesConfiguration, $app->controllerEvents);
         $controller = $factory->createProxy($controller);
         $factory->addEventManagement($controller);
         return $controller;
     });
     $app->view($app->twig);
 }
开发者ID:comphppuebla,项目名称:echale-gas-api,代码行数:50,代码来源:ApplicationContainer.php

示例14: checkLimit

 public function checkLimit($package)
 {
     $thisHour = floor(time() / 60 / 60);
     if (isset($_SESSION['requestHour']) && $_SESSION['requestHour'] == $thisHour) {
         $_SESSION['requestCount']++;
     } else {
         $_SESSION['requestHour'] = $thisHour;
         $_SESSION['requestCount'] = 1;
     }
     $package = R::findOne('managepackages', ' name = ?', array($this->cleanup($package)));
     $this->app->response()->header('Api-Utilization', $_SESSION['requestCount']);
     $this->app->response()->header('Api-Limit', $package->rate);
     if ($package->rate >= $_SESSION['requestCount']) {
         return true;
     }
     return false;
 }
开发者ID:zulfajuniadi,项目名称:php-rest-server,代码行数:17,代码来源:utils.php

示例15: error

 protected function error($message, $status = 404)
 {
     $this->app->response()->setStatus($status);
     $this->app->response->setBody(json_encode(array('error' => array('message' => $message, 'status_code' => $status))));
 }
开发者ID:reideer,项目名称:inventario,代码行数:5,代码来源:Controller.php


注:本文中的Slim\Slim::response方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。