2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group aphront
|
|
|
|
*/
|
|
|
|
abstract class AphrontApplicationConfiguration {
|
|
|
|
|
|
|
|
private $request;
|
|
|
|
private $host;
|
|
|
|
private $path;
|
2011-02-02 22:48:52 +01:00
|
|
|
private $console;
|
2011-01-16 22:51:39 +01:00
|
|
|
|
|
|
|
abstract public function getApplicationName();
|
|
|
|
abstract public function getURIMap();
|
|
|
|
abstract public function buildRequest();
|
2011-01-30 01:16:09 +01:00
|
|
|
abstract public function build404Controller();
|
2011-01-16 22:51:39 +01:00
|
|
|
|
|
|
|
final public function setRequest(AphrontRequest $request) {
|
|
|
|
$this->request = $request;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getRequest() {
|
|
|
|
return $this->request;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:48:52 +01:00
|
|
|
final public function getConsole() {
|
|
|
|
return $this->console;
|
|
|
|
}
|
2011-02-05 20:45:13 +01:00
|
|
|
|
|
|
|
final public function setConsole($console) {
|
|
|
|
$this->console = $console;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
final public function buildController() {
|
|
|
|
$map = $this->getURIMap();
|
|
|
|
$mapper = new AphrontURIMapper($map);
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$path = $request->getPath();
|
|
|
|
list($controller_class, $uri_data) = $mapper->mapPath($path);
|
|
|
|
|
2011-01-30 01:16:09 +01:00
|
|
|
if (!$controller_class) {
|
|
|
|
return $this->build404Controller();
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
PhutilSymbolLoader::loadClass($controller_class);
|
|
|
|
$controller = newv($controller_class, array($request));
|
|
|
|
|
|
|
|
return array($controller, $uri_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function setHost($host) {
|
|
|
|
$this->host = $host;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getHost() {
|
|
|
|
return $this->host;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function setPath($path) {
|
|
|
|
$this->path = $path;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getPath() {
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:48:52 +01:00
|
|
|
final public function willBuildRequest() {
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|