本文整理汇总了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() . '}}';
}
}
示例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();
}
示例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);
}
}
示例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();
}
示例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());
}
示例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();
}
}
示例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);
}
示例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;
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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))));
}