Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatible with slim v3 #346

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Xhgui/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace XHGui;

use Slim\Slim;
use Slim\Slim as App;

abstract class AbstractController
{
Expand All @@ -17,11 +17,11 @@ abstract class AbstractController
protected $_template = null;

/**
* @var Slim
* @var App
*/
protected $app;

public function __construct(Slim $app)
public function __construct(App $app)
{
$this->app = $app;
}
Expand Down
15 changes: 7 additions & 8 deletions src/Xhgui/Controller/CustomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace XHGui\Controller;

use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Slim as App;
use XHGui\AbstractController;
use XHGui\Searcher\SearcherInterface;

class CustomController extends AbstractController
{
Expand All @@ -13,7 +15,7 @@ class CustomController extends AbstractController
*/
protected $searcher;

public function __construct(Slim $app, SearcherInterface $searcher)
public function __construct(App $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand All @@ -24,9 +26,8 @@ public function get()
$this->_template = 'custom/create.twig';
}

public function help()
public function help(Request $request)
{
$request = $this->app->request();
if ($request->get('id')) {
$res = $this->searcher->get($request->get('id'));
} else {
Expand All @@ -38,10 +39,8 @@ public function help()
]);
}

public function query()
public function query(Request $request, Response $response)
{
$request = $this->app->request();
$response = $this->app->response();
$response['Content-Type'] = 'application/json';

$query = json_decode($request->post('query'), true);
Expand Down
10 changes: 4 additions & 6 deletions src/Xhgui/Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use Exception;
use InvalidArgumentException;
use Slim\Http\Request;
use Slim\Slim;
use Slim\Http\Response;
use XHGui\Saver\SaverInterface;
use XHGui\AbstractController;
use Slim\Slim as App;

class ImportController extends AbstractController
{
Expand All @@ -19,18 +20,15 @@ class ImportController extends AbstractController
/** @var string */
private $token;

public function __construct(Slim $app, SaverInterface $saver, $token)
public function __construct(App $app, SaverInterface $saver, $token)
{
parent::__construct($app);
$this->saver = $saver;
$this->token = $token;
}

public function import()
public function import(Request $request, Response $response)
{
$request = $this->app->request();
$response = $this->app->response();

try {
$this->runImport($request);
$result = ['ok' => true, 'size' => $request->getContentLength()];
Expand Down
9 changes: 4 additions & 5 deletions src/Xhgui/Controller/MetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace XHGui\Controller;

use Slim\Slim;
use Slim\Http\Response;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;
use Slim\Slim as App;

class MetricsController extends AbstractController
{
Expand All @@ -13,16 +14,14 @@ class MetricsController extends AbstractController
*/
protected $searcher;

public function __construct(Slim $app, SearcherInterface $searcher)
public function __construct(App $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
}

public function metrics()
public function metrics(Response $response)
{
$response = $this->app->response();

$stats = $this->searcher->stats();

$body = "# HELP xhgui_profiles_total Number of profiles collected.\n";
Expand Down
45 changes: 15 additions & 30 deletions src/Xhgui/Controller/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace XHGui\Controller;

use Exception;
use Slim\Slim;
use Slim\Http\Request;
use Slim\Http\Response;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;
use Slim\Slim as App;

class RunController extends AbstractController
{
Expand All @@ -19,23 +21,20 @@ class RunController extends AbstractController
*/
private $searcher;

public function __construct(Slim $app, SearcherInterface $searcher)
public function __construct(App $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
}

public function index()
public function index(Request $request, Response $response)
{
$response = $this->app->response();
// The list changes whenever new profiles are recorded.
// Generally avoid caching, but allow re-use in browser's bfcache
// and by cache proxies for concurrent requests.
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=0');

$request = $this->app->request();

$search = [];
$keys = ['date_start', 'date_end', 'url'];
foreach ($keys as $key) {
Expand Down Expand Up @@ -83,9 +82,8 @@ public function index()
]);
}

public function view()
public function view(Request $request, Response $response)
{
$response = $this->app->response();
// Permalink views to a specific run are meant to be public and immutable.
// But limit the cache to only a short period of time (enough to allow
// handling of abuse or other stampedes). This way we don't have to
Expand All @@ -95,7 +93,6 @@ public function view()
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=60, must-revalidate');

$request = $this->app->request();
$detailCount = $this->app->config('detail.count');
$result = $this->searcher->get($request->get('id'));

Expand Down Expand Up @@ -149,9 +146,8 @@ protected function getFilters()
return $filters;
}

public function deleteForm()
public function deleteForm(Request $request)
{
$request = $this->app->request();
$id = $request->get('id');
if (!is_string($id) || !strlen($id)) {
throw new Exception('The "id" parameter is required.');
Expand All @@ -167,9 +163,8 @@ public function deleteForm()
]);
}

public function deleteSubmit()
public function deleteSubmit(Request $request)
{
$request = $this->app->request();
$id = $request->post('id');
// Don't call profilers->delete() unless $id is set,
// otherwise it will turn the null into a MongoId and return "Sucessful".
Expand Down Expand Up @@ -202,9 +197,8 @@ public function deleteAllSubmit()
$this->app->redirect($this->app->urlFor('home'));
}

public function url()
public function url(Request $request)
{
$request = $this->app->request();
$pagination = [
'sort' => $request->get('sort'),
'direction' => $request->get('direction'),
Expand Down Expand Up @@ -256,10 +250,8 @@ public function url()
]);
}

public function compare()
public function compare(Request $request)
{
$request = $this->app->request();

$baseRun = $headRun = $candidates = $comparison = null;
$paging = [];

Expand Down Expand Up @@ -312,9 +304,8 @@ public function compare()
]);
}

public function symbol()
public function symbol(Request $request)
{
$request = $this->app->request();
$id = $request->get('id');
$symbol = $request->get('symbol');

Expand All @@ -333,9 +324,8 @@ public function symbol()
]);
}

public function symbolShort()
public function symbolShort(Request $request)
{
$request = $this->app->request();
$id = $request->get('id');
$threshold = $request->get('threshold');
$symbol = $request->get('symbol');
Expand All @@ -356,9 +346,8 @@ public function symbolShort()
]);
}

public function callgraph()
public function callgraph(Request $request)
{
$request = $this->app->request();
$profile = $this->searcher->get($request->get('id'));

$this->_template = 'runs/callgraph.twig';
Expand All @@ -368,10 +357,8 @@ public function callgraph()
]);
}

public function callgraphData()
public function callgraphData(Request $request, Response $response)
{
$request = $this->app->request();
$response = $this->app->response();
$profile = $this->searcher->get($request->get('id'));
$metric = $request->get('metric') ?: 'wt';
$threshold = (float)$request->get('threshold') ?: 0.01;
Expand All @@ -382,10 +369,8 @@ public function callgraphData()
return $response->body(json_encode($callgraph));
}

public function callgraphDataDot()
public function callgraphDataDot(Request $request, Response $response)
{
$request = $this->app->request();
$response = $this->app->response();
$profile = $this->searcher->get($request->get('id'));
$metric = $request->get('metric') ?: 'wt';
$threshold = (float)$request->get('threshold') ?: 0.01;
Expand Down
8 changes: 4 additions & 4 deletions src/Xhgui/Controller/WatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace XHGui\Controller;

use Slim\Slim;
use Slim\Http\Request;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;
use Slim\Slim as App;

class WatchController extends AbstractController
{
Expand All @@ -13,7 +14,7 @@ class WatchController extends AbstractController
*/
protected $searcher;

public function __construct(Slim $app, SearcherInterface $searcher)
public function __construct(App $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand All @@ -27,10 +28,9 @@ public function get()
$this->set(['watched' => $watched]);
}

public function post()
public function post(Request $request)
{
$saved = false;
$request = $this->app->request();
foreach ((array)$request->post('watch') as $data) {
$saved = true;
$this->searcher->saveWatch($data);
Expand Down
10 changes: 5 additions & 5 deletions src/Xhgui/Controller/WaterfallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace XHGui\Controller;

use Slim\Slim;
use Slim\Http\Request;
use Slim\Http\Response;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;
use XHGui\Profile;
use Slim\Slim as App;

class WaterfallController extends AbstractController
{
Expand All @@ -14,7 +16,7 @@ class WaterfallController extends AbstractController
*/
protected $searcher;

public function __construct(Slim $app, SearcherInterface $searcher)
public function __construct(App $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down Expand Up @@ -53,10 +55,8 @@ public function index()
]);
}

public function query()
public function query(Request $request, Response $response)
{
$request = $this->app->request();
$response = $this->app->response();
$search = [];
$keys = ['remote_addr', 'request_start', 'request_end'];
foreach ($keys as $key) {
Expand Down
4 changes: 2 additions & 2 deletions src/Xhgui/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Pimple\Container;
use RuntimeException;
use Slim\Middleware\SessionCookie;
use Slim\Slim;
use Slim\Slim as App;
use Slim\Views\Twig;
use XHGui\Db\PdoRepository;
use XHGui\Middleware\RenderMiddleware;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected function _slimApp()
date_default_timezone_set($c['config']['timezone']);
}

$app = new Slim($c['config']);
$app = new App($c['config']);

// Enable cookie based sessions
$app->add(new SessionCookie([
Expand Down
Loading