Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionBrowseMainController extends DiffusionBrowseController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
// Figure out if we're browsing a directory, a file, or a search result
|
|
|
|
// list. Then delegate to the appropriate controller.
|
|
|
|
|
2014-02-01 20:48:28 +01:00
|
|
|
$grep = $request->getStr('grep');
|
|
|
|
$find = $request->getStr('find');
|
|
|
|
if (strlen($grep) || strlen($find)) {
|
Decouple some aspects of request routing and construction
Summary:
Ref T5702. This is a forward-looking change which provides some very broad API improvements but does not implement them. In particular:
- Controllers no longer require `$request` to construct. This is mostly for T5702, directly, but simplifies things in general. Instead, we call `setRequest()` before using a controller. Only a small number of sites activate controllers, so this is less code overall, and more consistent with most constructors not having any parameters or effects.
- `$request` now offers `getURIData($key, ...)`. This is an alternate way of accessing `$data` which is currently only available on `willProcessRequest(array $data)`. Almost all controllers which implement this method do so in order to read one or two things out of the URI data. Instead, let them just read this data directly when processing the request.
- Introduce `handleRequest(AphrontRequest $request)` and deprecate (very softly) `processRequest()`. The majority of `processRequest()` calls begin `$request = $this->getRequest()`, which is avoided with the more practical signature.
- Provide `getViewer()` on `$request`, and a convenience `getViewer()` on `$controller`. This fixes `$viewer = $request->getUser();` into `$viewer = $request->getViewer();`, and converts the `$request + $viewer` two-liner into a single `$this->getViewer()`.
Test Plan:
- Browsed around in general.
- Hit special controllers (redirect, 404).
- Hit AuditList controller (uses new style).
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5702
Differential Revision: https://secure.phabricator.com/D10698
2014-10-17 14:01:40 +02:00
|
|
|
$controller = new DiffusionBrowseSearchController();
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
} else {
|
|
|
|
$results = DiffusionBrowseResultSet::newFromConduit(
|
|
|
|
$this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.browsequery',
|
|
|
|
array(
|
|
|
|
'path' => $drequest->getPath(),
|
2014-05-13 22:51:45 +02:00
|
|
|
'commit' => $drequest->getStableCommit(),
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
)));
|
|
|
|
$reason = $results->getReasonForEmptyResultSet();
|
|
|
|
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
|
|
|
|
|
|
|
|
if ($is_file) {
|
|
|
|
$controller = new DiffusionBrowseFileController($request);
|
|
|
|
} else {
|
|
|
|
$controller = new DiffusionBrowseDirectoryController($request);
|
|
|
|
$controller->setBrowseQueryResults($results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$controller->setDiffusionRequest($drequest);
|
|
|
|
$controller->setCurrentApplication($this->getCurrentApplication());
|
|
|
|
return $this->delegateToController($controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|