本文整理汇总了PHP中Silex\Application::json方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::json方法的具体用法?PHP Application::json怎么用?PHP Application::json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app['multifetch.methods'] = array('POST');
$app['multifetch.url'] = 'multi';
$app['multifetch.parallel'] = false;
$app['multifetch.headers'] = true;
$app['multifetch.builder'] = function () use($app) {
$controllers = $app['controllers_factory'];
$renderer = function ($url) use($app) {
return $app['fragment.renderer.inline']->render($url, $app['request']);
};
$multifetcher = new Multifetcher();
$options = array('parallel' => (bool) $app['multifetch.parallel'], 'headers' => (bool) $app['multifetch.headers']);
if (in_array('GET', $app['multifetch.methods'])) {
$controllers->get('/', function (Application $app) use($multifetcher, $renderer, $options) {
$responses = $multifetcher->fetch($app['request']->query->all(), $renderer, $options);
return $app->json($responses);
});
}
if (in_array('POST', $app['multifetch.methods'])) {
$controllers->post('/', function (Application $app) use($multifetcher, $renderer, $options) {
$responses = $multifetcher->fetch($app['request']->request->all(), $renderer, $options);
return $app->json($responses);
})->before(function (Request $request) {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
$data = json_decode($request->getContent(), true);
$request->request->replace(is_array($data) ? $data : array());
}
});
}
$app['controllers']->mount($app['multifetch.url'], $controllers);
};
}
示例2: connect
public function connect(SilexApplication $app)
{
$app['controller.setup'] = $this;
$controllers = $app['controllers_factory'];
$controllers->get('/', function (Application $app) {
return $app->redirectPath('install_root');
})->bind('setup');
$controllers->get('/installer/', 'controller.setup:rootInstaller')->bind('install_root');
$controllers->get('/upgrade-instructions/', 'controller.setup:displayUpgradeInstructions')->bind('setup_upgrade_instructions');
$controllers->get('/installer/step2/', 'controller.setup:getInstallForm')->bind('install_step2');
$controllers->post('/installer/install/', 'controller.setup:doInstall')->bind('install_do_install');
$controllers->get('/connection_test/mysql/', function (Application $app, Request $request) {
$dbHelper = new DatabaseHelper($app, $request);
return $app->json($dbHelper->checkConnection());
});
$controllers->get('/test/path/', function (Application $app, Request $request) {
$pathHelper = new PathHelper($app, $request);
return $app->json($pathHelper->checkPath());
});
$controllers->get('/test/url/', function (Application $app, Request $request) {
$pathHelper = new PathHelper($app, $request);
return $app->json($pathHelper->checkUrl());
});
return $controllers;
}
示例3: connect
public function connect(Application $app)
{
$controller = $this->controller;
$targetRepository = $this->repository;
$controller->get("/", function () use($app, $targetRepository) {
$repository = new $targetRepository($app['db']);
$results = $repository->findAll();
return $app->json($results);
});
$controller->get("/{id}", function ($id) use($app, $targetRepository) {
$repository = new $targetRepository($app['db']);
$result = $repository->find($id);
return $app->json($result);
})->assert('id', '\\d+');
$controller->post("/", function (Request $request) use($app, $targetRepository) {
$repository = new $targetRepository($app['db']);
$params = $request->request->all();
return $app->json($repository->insert($params));
});
$controller->put("/{id}", function (Request $request, $id) use($app, $targetRepository) {
$repository = new $targetRepository($app['db']);
$params = $request->request->all();
return $app->json($repository->update($id, $params));
})->assert('id', '\\d+');
$controller->delete("/{id}", function ($id) use($app, $targetRepository) {
$repository = new $targetRepository($app['db']);
return $app->json($repository->delete($id));
})->assert('id', '\\d+');
return $controller;
}
示例4: connect
/**
* Returns routes to connect to the given application.
*
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->post('/', function (Request $request) use($app) {
$create = $app['produtoTagService']->create($request);
return $app->json($create);
});
$controllers->get('/', function () use($app) {
$categorias = $app['produtoTagService']->read();
$data = $app['produtoCategoriaSerializer']->serializeAll($categorias);
return $app->json($data);
});
$controllers->get('/{id}', function ($id) use($app) {
$categoria = $app['produtoTagService']->read($id);
$data = $app['produtoTagSerializer']->serialize($categoria);
return $app->json($data);
});
$controllers->put('/', function (Request $request) use($app) {
return $app->json($app['produtoTagService']->update($request));
});
$controllers->delete('/{id}', function ($id) use($app) {
return $app->json($app['produtoTagService']->delete($id));
});
return $controllers;
}
示例5: connect
public function connect(Application $app)
{
$controllers = new ControllerCollection();
$supervisor = new API();
$servers = (include __DIR__ . '/../../config.php');
foreach (array_keys($servers) as $server_id) {
$servers[$server_id]['id'] = $server_id;
}
$controllers->get('/list.{_format}', function ($_format) use($supervisor, $app, $servers) {
if ($_format == 'json') {
return $app->json($servers);
} else {
// use a closure to avoid leaking any vars into the template that we don't explicitly want
return call_user_func(function () use($app) {
$url_root = $app['url_generator']->generate('home');
ob_start();
ob_implicit_flush(false);
include __DIR__ . '/../../views/supervisorui.html.php';
return ob_get_clean();
});
}
})->bind('server_list')->value('_format', 'html');
$controllers->get('/details/{server_id}', function ($server_id) use($supervisor, $app, $servers) {
$server_ip = $servers[$server_id]['ip'];
$details = array_merge(array('version' => $supervisor->getSupervisorVersion('127.0.0.1'), 'pid' => $supervisor->getPID('127.0.0.1')), $supervisor->getState('127.0.0.1'), $servers[$server_id]);
return $app->json($details);
});
return $controllers;
}
示例6: connect
/**
* Returns employee routes to connect to the given application.
*
* @param Application $_app An Application instance
* @return ControllerCollection $controllers A ControllerCollection instance
*/
public function connect(Application $_app)
{
$_app->register(new EmployeeServiceProvider());
$controllers = $_app['controllers_factory'];
// Route for CREATING one employee record
$controllers->post('/', function () use($_app) {
return $_app->json($_app['employeeService.create']);
});
// Route for READING a list of employee records
$controllers->get('/', function () use($_app) {
return $_app->json($_app['employeeService.read']);
});
// Route for READING one employee record
$controllers->get('/{id}/', function () use($_app) {
return $_app->json($_app['employeeService.readOne']);
});
// Route for UPDATING one employee record
$controllers->put('/{id}/', function () use($_app) {
return $_app->json($_app['employeeService.update']);
});
// Route for DELETING one employee record
$controllers->delete('/{id}/', function () use($_app) {
return $_app->json($_app['employeeService.delete']);
});
return $controllers;
}
示例7: deleteAction
public function deleteAction(Request $request, Application $app)
{
$order = $request->attributes->get('order');
if (!$order) {
return $app->json('Not Found', 404);
}
$app['repository.order']->delete($order);
return $app->json('No Content', 204);
}
示例8: deleteAction
public function deleteAction(Request $request, Application $app)
{
$artist = $request->attributes->get('artist');
if (!$artist) {
return $app->json('Not Found', 404);
}
$app['repository.artist']->delete($artist);
return $app->json('No Content', 204);
}
示例9: Put
public function Put(Application $app, Request $request)
{
$validity = $app['phpdraft.LoginUserValidator']->IsUserProfileUpdateValid($request);
if (!$validity->success) {
return $app->json($validity, Response::HTTP_BAD_REQUEST);
}
$response = $app['phpdraft.LoginUserService']->UpdateUserProfile($request);
return $app->json($response, $response->responseType());
}
示例10: setupErrorHandlers
/**
* Setup error handlers
*/
protected function setupErrorHandlers()
{
$this->app->error(function (\Exception $e, $code) {
$data = array('status' => $code);
if ($this->app['config']('app.debug', false)) {
$data['error'] = $e->getMessage();
}
return $this->app->json($data, $code);
});
}
示例11: connect
public function connect(Application $app)
{
$routes = $app['controllers_factory'];
$db = $this->repo;
$routes->get('/', function () use($app) {
return 'Hello World';
});
$routes->get('obras/all/concluidas', function () use($app, $db) {
$obras = $db->getAllObrasConcluidas();
return $app->json($obras);
});
$routes->get('obras/{uf}/all', function ($uf) use($app, $db) {
$obras = $db->getAllObrasByEstado($uf);
return $app->json($obras);
});
$routes->get('obras/id/{idn_empreendimento}', function ($idn_empreendimento) use($app, $db) {
$obra = $db->getObra($idn_empreendimento);
return $app->json($obra);
});
$routes->get('obras/{uf}/estatisticas', function ($uf) use($app, $db) {
$data = array();
$data['vermelho'] = $db->getQtObrasNaoIniciadasByEstado($uf);
$data['amarelo'] = $db->getQtObrasEmConstrucaoByEstado($uf);
$data['verde'] = $db->getQtObrasConcluidasByEstado($uf);
return $app->json($data);
});
/*
function getCoordenadasDD($obras) {
foreach ($obras as $key => $obra) {
//latitude
$obras[$key]['val_lat'] = str_replace('"','',$obras[$key]['val_lat']);
$obras[$key]['val_lat'] = substr($obras[$key]['val_lat'],0,-1);
$arr = array();
$result = preg_match('/^(\d\d?).(\d\d?).(\d\d?(?:[.,]\d+)?).$/u', $obras[$key]['val_lat'], $arr);
//convervento coordenadas de dms para dd
$obras[$key]['val_lat'] = '-';
$obras[$key]['val_lat'] .= ($arr[1] + ($arr[2]/60) + ($arr[3]/3600));
//longitude
$obras[$key]['val_long'] = str_replace('"','',$obras[$key]['val_long']);
$obras[$key]['val_long'] = substr($obras[$key]['val_long'],0,-1);
$arr2 = array();
$result = preg_match('/^(\d\d?).(\d\d?).(\d\d?(?:[.,]\d+)?).$/u', $obras[$key]['val_long'], $arr2);
//convervento coordenadas de dms para dd
$obras[$key]['val_long'] = '-';
$obras[$key]['val_long'] .= ($arr2[1] + ($arr2[2]/60) + ($arr2[3]/3600));
}
return $obras;
}
*/
return $routes;
}
示例12: Upload
public function Upload(Application $app, Request $request)
{
$sport = $request->get('sport');
$file = $request->files->get('file');
$validity = $app['phpdraft.ProPlayerValidator']->IsUploadSportValid($sport, $file);
if (!$validity->success) {
return $app->json($validity, $validity->responseType());
}
$response = $app['phpdraft.ProPlayerService']->Upload($sport, $file);
return $app->json($response, $response->responseType());
}
示例13: connect
/**
* {@inheritdoc}
*/
public function connect(Application $app)
{
// creates a new controller based on the default route
$controllers = $app['controllers_factory'];
$controllers->get('/products', function (Application $app) {
return $app->json([]);
});
$controllers->get('/product/{productId}', function (Application $app, $productId) {
return $app->json([]);
});
return $controllers;
}
示例14: GetPositions
public function GetPositions(Application $app, Request $request)
{
$draft_sport = $request->get('draft_sport');
$validity = $app['phpdraft.DepthChartPositionValidator']->IsDraftSportValid($draft_sport);
if (!$validity->success) {
return $app->json($validity, Response::HTTP_BAD_REQUEST);
}
$response = $app['phpdraft.ResponseFactory'](true, array());
$response->positions = array();
$response->positions = $app['phpdraft.DraftDataRepository']->GetPositions($draft_sport);
return $app->json($response);
}
示例15: Delete
public function Delete(Application $app, Request $request)
{
$user_id = $request->get('user_id');
$user = $app['phpdraft.LoginUserRepository']->LoadById($user_id);
if ($app['phpdraft.LoginUserService']->CurrentUserIsAdmin($user)) {
$response = new PhpDraftResponse(false, array());
$response->errors[] = "Unable to delete user - user is admin.";
return $app->json($response, $response->responseType());
}
$response = $app['phpdraft.LoginUserService']->DeleteUser($user);
return $app->json($response, $response->responseType());
}