diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8e67b3e..9222422 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,115 +1,125 @@ array( + 'AphrontApplicationConfiguration' => 'aphront/applicationconfiguration', + 'AphrontController' => 'aphront/controller', + 'AphrontDefaultApplicationConfiguration' => 'aphront/default/configuration', + 'AphrontDefaultApplicationController' => 'aphront/default/controller', + 'AphrontRequest' => 'aphront/request', + 'AphrontResponse' => 'aphront/response', + 'AphrontURIMapper' => 'aphront/mapper', + 'AphrontWebpageResponse' => 'aphront/response/webpage', 'CommandException' => 'future/exec', 'ConduitClient' => 'conduit/client', 'ConduitClientException' => 'conduit/client', 'ConduitFuture' => 'conduit/client', 'ExecFuture' => 'future/exec', 'FileFinder' => 'filesystem/filefinder', 'FileList' => 'filesystem/filelist', 'Filesystem' => 'filesystem', 'FilesystemException' => 'filesystem', 'Future' => 'future', 'FutureIterator' => 'future', 'HTTPFuture' => 'future/http', 'PhutilConsoleFormatter' => 'console', 'PhutilInteractiveEditor' => 'console/editor', 'PhutilLibraryMapRegistry' => 'autoload', 'PhutilMarkupEngine' => 'markup/engine', 'PhutilRemarkupBlockStorage' => 'markup/engine/remarkup/blockstorage', 'PhutilRemarkupEngine' => 'markup/engine/remarkup', 'PhutilRemarkupEngineBlockRule' => 'markup/engine/remarkup/blockrule/base', 'PhutilRemarkupEngineRemarkupCodeBlockRule' => 'markup/engine/remarkup/blockrule/remarkupcode', 'PhutilRemarkupEngineRemarkupCounterExampleBlockRule' => 'markup/engine/remarkup/blockrule/remarkupcounterexample', 'PhutilRemarkupEngineRemarkupDefaultBlockRule' => 'markup/engine/remarkup/blockrule/remarkupdefault', 'PhutilRemarkupEngineRemarkupHeaderBlockRule' => 'markup/engine/remarkup/blockrule/remarkupheader', 'PhutilRemarkupEngineRemarkupInlineBlockRule' => 'markup/engine/remarkup/blockrule/remarkupinline', 'PhutilRemarkupEngineRemarkupListBlockRule' => 'markup/engine/remarkup/blockrule/remarkuplist', 'PhutilRemarkupRule' => 'markup/engine/remarkup/markuprule/base', 'PhutilRemarkupRuleBold' => 'markup/engine/remarkup/markuprule/bold', 'PhutilRemarkupRuleEscapeHTML' => 'markup/engine/remarkup/markuprule/escapehtml', 'PhutilRemarkupRuleEscapeRemarkup' => 'markup/engine/remarkup/markuprule/escaperemarkup', 'PhutilRemarkupRuleHyperlink' => 'markup/engine/remarkup/markuprule/hyperlink', 'PhutilRemarkupRuleItalic' => 'markup/engine/remarkup/markuprule/italics', 'PhutilRemarkupRuleLinebreaks' => 'markup/engine/remarkup/markuprule/linebreaks', 'PhutilRemarkupRuleMonospace' => 'markup/engine/remarkup/markuprule/monospace', 'QsprintfQueryParameterException' => 'xsprintf/qsprintf', 'TempFile' => 'filesystem/tempfile', ), 'function' => array( 'Futures' => 'future', '_qsprintf_check_scalar_type' => 'xsprintf/qsprintf', '_qsprintf_check_type' => 'xsprintf/qsprintf', 'array_select_keys' => 'utils', 'coalesce' => 'utils', 'csprintf' => 'xsprintf/csprintf', 'exec_manual' => 'future/exec', 'execx' => 'future/exec', 'id' => 'utils', 'idx' => 'utils', 'ipull' => 'utils', 'jsprintf' => 'xsprintf/jsprintf', 'mgroup' => 'utils', 'mpull' => 'utils', 'msort' => 'utils', 'mysql_escape_array_of_strings_for_in_clause' => 'xsprintf/qsprintf', 'mysql_escape_column_name' => 'xsprintf/qsprintf', 'mysql_escape_multiline_comment' => 'xsprintf/qsprintf', 'newv' => 'utils', 'nonempty' => 'utils', 'phutil_autoload_class' => 'autoload', 'phutil_autoload_function' => 'autoload', 'phutil_console_confirm' => 'console', 'phutil_console_format' => 'console', 'phutil_console_prompt' => 'console', 'phutil_console_wrap' => 'console', 'phutil_escape_html' => 'markup', 'phutil_find_class_descendants' => 'autoload', 'phutil_find_classes_declared_in_module' => 'autoload', 'phutil_get_library_name_for_root' => 'moduleutils', 'phutil_get_library_root' => 'moduleutils', 'phutil_get_library_root_for_path' => 'moduleutils', 'phutil_register_library_map' => 'autoload', 'phutil_render_tag' => 'markup', 'qsprintf' => 'xsprintf/qsprintf', 'vcsprintf' => 'xsprintf/csprintf', 'vjsprintf' => 'xsprintf/jsprintf', 'vqsprintf' => 'xsprintf/qsprintf', 'xsprintf' => 'xsprintf', 'xsprintf_command' => 'xsprintf/csprintf', 'xsprintf_javascript' => 'xsprintf/jsprintf', 'xsprintf_query' => 'xsprintf/qsprintf', ), 'requires_class' => array( + 'AphrontDefaultApplicationConfiguration' => 'AphrontApplicationConfiguration', + 'AphrontDefaultApplicationController' => 'AphrontController', 'ConduitFuture' => 'HTTPFuture', 'ExecFuture' => 'Future', 'HTTPFuture' => 'Future', 'PhutilRemarkupEngine' => 'PhutilMarkupEngine', 'PhutilRemarkupEngineRemarkupCodeBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupCounterExampleBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupDefaultBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupHeaderBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupInlineBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupListBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupRuleBold' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleEscapeHTML' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleEscapeRemarkup' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleHyperlink' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleItalic' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleLinebreaks' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleMonospace' => 'PhutilRemarkupRule', ), 'requires_interface' => array( ), )); diff --git a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php new file mode 100644 index 0000000..4eb76dc --- /dev/null +++ b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php @@ -0,0 +1,69 @@ +request = $request; + return $this; + } + + final public function getRequest() { + return $this->request; + } + + final public function buildController() { + $map = $this->getURIMap(); + $mapper = new AphrontURIMapper($map); + $request = $this->getRequest(); + $path = $request->getPath(); + list($controller_class, $uri_data) = $mapper->mapPath(); + + phutil_autoload_class($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; + } + +} diff --git a/src/aphront/applicationconfiguration/__init__.php b/src/aphront/applicationconfiguration/__init__.php new file mode 100644 index 0000000..ea1eeb3 --- /dev/null +++ b/src/aphront/applicationconfiguration/__init__.php @@ -0,0 +1,14 @@ +request = $request; + } + + final public function getRequest() { + return $this->request; + } + +} diff --git a/src/aphront/controller/__init__.php b/src/aphront/controller/__init__.php new file mode 100644 index 0000000..aab2bf1 --- /dev/null +++ b/src/aphront/controller/__init__.php @@ -0,0 +1,10 @@ + 'AphrontDefaultApplicationController', + ); + } + + public function buildRequest() { + $request = new AphrontRequest($this->getHost(), $this->getPath()); + $request->setRequestData($_GET + $_POST); + return $request; + } + +} diff --git a/src/aphront/default/configuration/__init__.php b/src/aphront/default/configuration/__init__.php new file mode 100644 index 0000000..2c9eddd --- /dev/null +++ b/src/aphront/default/configuration/__init__.php @@ -0,0 +1,13 @@ +getRequest(); + + $path = phutil_escape_html($request->getPath()); + $host = phutil_escape_html($request->getHost()); + + $response = new AphrontWebpageResponse(); + $response->setContent(<< + + Aphront Default Application + + +

Welcome to Aphront

+

Things appear to be working properly.

+

Request Information

+ + + + + + + +
Host{$host}
Path{$path}
+ + + +EOPAGE + ); + + return $response; + } + +} diff --git a/src/aphront/default/controller/__init__.php b/src/aphront/default/controller/__init__.php new file mode 100644 index 0000000..a2ed24a --- /dev/null +++ b/src/aphront/default/controller/__init__.php @@ -0,0 +1,14 @@ +map = $map; + } + + final public function mapPath($path) { + $map = $this->map; + foreach ($map as $rule => $value) { + list($controller, $data) = $this->tryRule($rule, $value, $path); + if ($controller) { + foreach ($data as $k => $v) { + if (is_numeric($k)) { + unset($data[$k]); + } + } + return array($controller, $data); + } + } + + return array(null, null); + } + + final private function tryRule($rule, $value, $path) { + $match = null; + if (!preg_match('#^'.$rule.'#', $path, $match)) { + return array(null, null); + } + + if (!is_array($value)) { + return array($value, $match); + } + + $path = substr($path, strlen($match[0])); + foreach ($value as $srule => $sval) { + list($controller, $data) = $this->tryRule($srule, $sval, $path); + if ($controller) { + return array($controller, $data + $match); + } + } + + return array(null, null); + } +} diff --git a/src/aphront/mapper/__init__.php b/src/aphront/mapper/__init__.php new file mode 100644 index 0000000..46dee32 --- /dev/null +++ b/src/aphront/mapper/__init__.php @@ -0,0 +1,10 @@ +host = $host; + $this->path = $path; + } + + final public function setRequestData(array $request_data) { + $this->requestData = $request_data; + return $this; + } + + final public function getPath() { + return $this->path; + } + + final public function getHost() { + return $this->host; + } + + final public function getInt($name, $default = null) { + if (isset($this->requestData[$name])) { + return (int)$this->requestData[$name]; + } else { + return $default; + } + } + + final public function getStr($name, $default = null) { + if (isset($this->requestData[$name])) { + return (string)$this->requestData[$name]; + } else { + return $default; + } + } + + final public function getArr($name, $default = null) { + if (isset($this->requestData[$name]) && is_array($this->requestData[$name])) { + return $this->requestData[$name]; + } else { + return $default; + } + } + + final public function getExists($name) { + return array_key_exists($name, $this->requestData); + } + + final public function isAjax() { + return $this->getExists(self::TYPE_AJAX); + } + +} diff --git a/src/aphront/request/__init__.php b/src/aphront/request/__init__.php new file mode 100644 index 0000000..3b8c8f9 --- /dev/null +++ b/src/aphront/request/__init__.php @@ -0,0 +1,10 @@ +content = $content; + return $this; + } + + public function buildResponseString() { + return $this->content; + } + +} diff --git a/src/aphront/response/webpage/__init__.php b/src/aphront/response/webpage/__init__.php new file mode 100644 index 0000000..f65f1fa --- /dev/null +++ b/src/aphront/response/webpage/__init__.php @@ -0,0 +1,10 @@ +setHost($host); +$application->setPath($path); +$request = $application->buildRequest(); +$application->setRequest($request); +list($controller, $uri_data) = $application->buildController(); +$controller->willProcessRequest($uri_data); +$response = $controller->processRequest(); + +echo $response->buildResponseString(); + +function setup_aphront_basics() { + @include_once 'libphutil/src/__phutil_library_init__.php'; + if (!@constant('__LIBPHUTIL__')) { + echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ". + "include the parent directory of libphutil/.\n"; + exit(1); + } + + if (!ini_get('date.timezone')) { + date_default_timezone_set('America/Los_Angeles'); + } + + + phutil_load_library(dirname(__FILE__).'/../src/'); +}