本文整理汇总了PHP中Slim\App::put方法的典型用法代码示例。如果您正苦于以下问题:PHP App::put方法的具体用法?PHP App::put怎么用?PHP App::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\App
的用法示例。
在下文中一共展示了App::put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPutRoute
public function testPutRoute()
{
$path = '/foo';
$callable = function ($req, $res) {
// Do something
};
$app = new App();
$route = $app->put($path, $callable);
$this->assertInstanceOf('\\Slim\\Route', $route);
$this->assertAttributeContains('PUT', 'methods', $route);
}
示例2: setRoute
/**
* @param string $method
* @param string $route
* @param object $routerClass
* @param string $callback
* @param Secured $secured
* @throws \Exception
*/
private function setRoute($method, $route, $routerClass, $callback, $secured)
{
$method = strtoupper($method);
$easyRoute = new Route($route, $routerClass, $callback, $secured, $this);
if ($method === 'GET') {
$this->app->get($route, array($easyRoute, 'call'));
} elseif ($method === 'PUT') {
$this->app->put($route, array($easyRoute, 'call'));
} elseif ($method === 'POST') {
$this->app->post($route, array($easyRoute, 'call'));
} elseif ($method === 'DELETE') {
$this->app->delete($route, array($easyRoute, 'call'));
} else {
throw new \Exception('Unsupported HTTP method ' . $method);
}
}
示例3: function
$container['auth'] = function ($container) {
return new BB8\Emoji\Auth($container);
};
//Initialize the slim app
$app = new App($container);
//Add middleware at app level
$app->add('BB8\\Emoji\\Middleware:init');
//Index page
$app->get('/', 'BB8\\Emoji\\Controllers\\UserController:index');
//Create new user
$app->post('/signup', 'BB8\\Emoji\\Controllers\\UserController:create');
//Login Route
$app->post('/auth/login', 'BB8\\Emoji\\Controllers\\UserController:login');
//Logout Route
$app->get('/auth/logout', 'BB8\\Emoji\\Controllers\\UserController:logout')->add('BB8\\Emoji\\Middleware:authorize');
//List all emojis Route
$app->get('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:index');
//Gets an emoji
$app->get('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:show');
//Adds a new Emoji
$app->post('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:create')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji
$app->put('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:update')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji Keyword
$app->put('/emojis/{id}/{kId}', 'BB8\\Emoji\\Controllers\\EmojiController:updateKey')->add('BB8\\Emoji\\Middleware:authorize');
//Partially Updates an Emoji
$app->patch('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:update')->add('BB8\\Emoji\\Middleware:authorize');
//Deletes an Emoji
$app->delete('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:destroy')->add('BB8\\Emoji\\Middleware:authorize');
//Load and run the application
$app->run();
示例4: Exception
$user = User::register($params['username'], $params['name'], $params['password']);
if ($user == null) {
throw new Exception("Invalid username or password!");
}
return ResultWrapper::getResult($user, $response);
} catch (Exception $e) {
return ResultWrapper::getError($e->getMessage(), $response);
}
});
$app->put('/update-password', function (Request $request, Response $response) {
try {
$params = $request->getQueryParams();
$token = $request->getHeader('token');
$result = User::updatePassword($token, $params['oldPassword'], $params['newPassword']);
if ($result == null) {
throw new Exception("Wrong password!");
}
return ResultWrapper::getResult($result, $response);
} catch (Exception $e) {
return ResultWrapper::getError($e->getMessage(), $response);
}
});
$app->get('/promo/{page}', function (Request $request, Response $response, $page) {
try {
return ResultWrapper::getResult(Promo::get($page), $response);
} catch (Exception $e) {
return ResultWrapper::getError($e->getMessage(), $response);
}
});
$app->get('/promo/{category}/{page}', function (Request $request, Response $response, $category, $page) {
try {
示例5: bootStrap
/**
* Add a repository to your Slim App
* @param App $app
* @param Repository $repository
* @return App the given app for chaining
*/
public function bootStrap(App $app, Repository $repository)
{
$baseUrl = '/' . self::parseRepoName($repository->getEntityClass()->getShortName());
/**
* Get the whole collection.
*/
$app->get($baseUrl, function (Request $request, Response $response) use($repository) {
return $response->write(self::output($repository->findAll()))->withHeader('Content-Type', 'application/json');
});
/**
* Delete the whole collection.
*/
$app->delete($baseUrl, function (Request $request, Response $response) use($repository) {
$repository->deleteAll();
});
/**
* Add a new entity to the collection.
*/
$app->post($baseUrl, function (Request $request, Response $response) use($repository) {
$body = self::getBody($request->getBody(), $repository->getEntityClass(), $response);
if ($body instanceof Response) {
return $body;
} else {
// Store the entity
$repository->insert($body);
return $response->withStatus(Status::CREATED)->withHeader('Content-Type', 'application/json')->write(self::output($body));
}
});
if ($this->showCheckPage) {
/**
* Display the repository check page.
*/
$app->get($baseUrl . '/check', function (Request $request, Response $response) use($repository) {
$repository->checkDatabase();
});
}
$entityUrl = $baseUrl . '/{id}';
/**
* Get a single entity.
*/
$app->get($entityUrl, function (Request $request, Response $response, $args) use($repository) {
$entity = $repository->get($args['id']);
if ($entity) {
return $response->write(self::output($entity))->withHeader('Content-Type', 'application/json');
}
return $response->withStatus(Status::NOT_FOUND);
});
/**
* Delete a single entity
*/
$app->delete($entityUrl, function (Request $request, Response $response, $args) use($repository) {
$repository->delete($args['id']);
});
/**
* Replace a single entity
*/
$app->put($entityUrl, function (Request $request, Response $response, $args) use($repository) {
$body = self::getBody($request->getBody(), $repository->getEntityClass(), $response);
if ($body instanceof Response) {
return $body;
} else {
// Store the entity
$repository->getIdProperty()->setValue($body, $args['id']);
$repository->update($body);
return $response->withHeader('Content-Type', 'application/json')->write(self::output($body));
}
});
return $app;
}