示例#1
0
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author: Thomas Urban
 */
namespace de\toxa\txf;

// always disable notices
error_reporting(error_reporting() & ~E_NOTICE);
include_once dirname(__FILE__) . '/classes/txf.php';
if (!txf::hasCurrent()) {
    txf::setContextMode(txf::CTXMODE_REWRITTEN);
    txf::select(new txf());
    view::init();
}
示例#2
0
文件: run.php 项目: cepharum/txf
 *
 * Requests may be redirected here either by using rewrite capabilities of web
 * server or using requests including this script such as
 *
 *    <your-site>/run.php/appname/script.php
 *
 * which is then processing request for script "script.php" of application
 * "appname".
 *
 * @author Thomas Urban
 *
 */
try {
    include 'rewritten.php';
    // get application actually requested
    $application = txf::getContext()->application;
    // get script of application actually requested
    $script = path::glue($application->pathname, $application->script);
    // change to that folder for supporting homogenic use of relative pathnames
    chdir(dirname($script));
    // include selected script
    include_once $script;
    // due to disabled shutdown handler we are required to call related handler manually
    view::current()->onShutdown();
} catch (http_exception $e) {
    header($e->getResponse());
    view::variable('exception', $e);
    view::addBodyClass('exception');
    view::addBodyClass('http-exception');
    $data = variable_space::create('reason', $e);
    try {
示例#3
0
 /**
  * Compiles URL addressing selected script of current application.
  *
  * @param string $scriptName pathname of script relative to application folder
  * @param array $parameters set of parameters to pass in query
  * @param mixed $selector first of multiple optional selectors to include
  * @return string URL of addressed script including optional parameters
  */
 public function scriptURL($scriptName, $parameters = array(), $selector = null)
 {
     if (!is_array($parameters)) {
         throw new \InvalidArgumentException('parameters must be array');
     }
     if (substr($scriptName, -4) == '.php') {
         $scriptName = substr($scriptName, 0, -4);
     }
     $selectors = func_get_args();
     $selectors = array_slice($selectors, 2);
     if (count($selectors) == 1 && is_array($selectors[0])) {
         $selectors = array_shift($selectors);
     }
     $selectors = implode('/', array_map(function ($selector) {
         return rawurlencode($selector);
     }, $selectors));
     switch (txf::getContextMode()) {
         case txf::CTXMODE_NORMAL:
         default:
             $url = path::glue($this->url, $scriptName, $selectors);
             break;
         case txf::CTXMODE_REWRITTEN:
             $proxy = $this->usedProxy === true ? '' : $this->usedProxy;
             if ($this->gotNameFromEnvironment) {
                 $url = path::glue($this->context->url, $proxy, $scriptName, $selectors);
             } else {
                 $url = path::glue($this->context->url, $proxy, $this->name, $scriptName, $selectors);
             }
             break;
     }
     return $url . (count($parameters) ? '?' . http_build_query($parameters) : '');
 }
示例#4
0
文件: session.php 项目: cepharum/txf
 public static final function getScopeParameter(&$domain, &$path)
 {
     // process focus selection
     $focus = config::get('session.focus', 'application');
     switch ($focus) {
         case 'domain':
             // valid for whole current domain
             $domain = $_SERVER['HTTP_HOST'];
             $path = '/';
             break;
         case 'txf':
             // valid for all applications in current installation, only
             $domain = $_SERVER['HTTP_HOST'];
             $path = '/' . txf::getContext()->prefixPathname;
             break;
         case 'application':
             // valid for current application, only
             $domain = $_SERVER['HTTP_HOST'];
             $path = '/' . application::current()->prefixPathname;
             break;
         default:
             // option is explicitly providing domain and path to focus
             if (strpos($focus, '%') !== false) {
                 $focus = strtr($focus, array('%H' => $_SERVER['HTTP_HOST'], '%T' => '/' . txf::getContext()->prefixPathname, '%A' => '/' . application::current()->prefixPathname));
             }
             $temp = explode('/', $focus);
             $domain = array_shift($temp);
             $path = '/' . implode('/', $temp);
     }
 }
示例#5
0
文件: user.php 项目: cepharum/txf
 /**
  * Iterates over given or configured list of user database providers invoking
  * provided callback on every provider until first callback is returning
  * properly without throwing exception.
  *
  * @param callable $callback callback to invoke per iterated user database provider
  * @param array|string $explicitSource set of provider names to iterate or name of first provider in a sequence to test
  * @return mixed|null result return from callback, null if all callbacks threw exception
  * @throws \RuntimeException on missing valid set of providers to iterate
  * @throws unauthorized_exception if callback is throwing in other case than "user isn't found"
  * @throws \InvalidArgumentException on missing callback
  */
 public static final function findProvider($callback, $explicitSource = null)
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException('invalid callback on finding user provider');
     }
     // get list of sources to look up for requested user
     if (is_array($explicitSource)) {
         $sources = $explicitSource;
     } else {
         $sources = func_get_args();
         array_shift($sources);
     }
     if (!count($sources)) {
         $sources = config::getList('user.sources.enabled');
     }
     if (!count($sources)) {
         throw new \RuntimeException('missing/invalid user sources configuration');
     }
     // traverse list of sources ...
     foreach ($sources as $source) {
         if (trim($source) !== '' && ctype_alnum($source)) {
             // read its configuration
             $definition = config::get('user.sources.setup.' . $source);
             if (is_array($definition)) {
                 // read name of class for managing user source from configuration
                 $class = array_key_exists('class', $definition) ? data::isKeyword($definition['class']) : null;
                 if (!$class) {
                     $class = data::isKeyword($definition['type'] . '_user');
                 }
                 if (txf::import($class)) {
                     try {
                         // create instance of managing class
                         $factory = new \ReflectionClass($class);
                         $user = $factory->newInstance();
                         if ($user instanceof self) {
                             $user->configure($definition);
                             return call_user_func($callback, $user);
                         }
                     } catch (unauthorized_exception $e) {
                         if (!$e->isUserNotFound()) {
                             throw $e;
                         }
                     } catch (\Exception $e) {
                         log::warning('failed to search user source: ' . $e);
                     }
                 }
             }
         }
     }
     return null;
 }
示例#6
0
文件: view.php 项目: cepharum/txf
 /**
  * Adds message to be flashed on next rendered page.
  *
  * @param string $message message to flash
  * @param string $context context/kind of message, e.g. notice, error, alert
  */
 public static function flash($message, $context = 'notice')
 {
     $session =& txf::session(session::SCOPE_GLOBAL);
     $session['view']['flashes'][$context][] = $message;
 }
示例#7
0
文件: context.php 项目: cepharum/txf
 /**
  * Retrieves part of request URI selecting current application and script.
  *
  * The fetched request URI is provided as array of pathname elements, that is
  * pathname might be derived by joining returned elements with '/'.
  *
  * @note Fetched request URI might include further selectors to be processed
  *       by requested script, e.g.
  *
  *       myapp/myscript/par1-of-script/par2-of-script
  *
  * @param string $detectedProxy name of detected proxy script
  * @return array sequence of filenames contained in requested URI for selecting script
  */
 public function getRequestedScriptUri(&$detectedProxy)
 {
     switch (txf::getContextMode()) {
         case txf::CTXMODE_REWRITTEN:
             assert('$_SERVER[REDIRECT_URL] || $_SERVER[PATH_INFO] || $_SERVER[REQUEST_URI]');
             // get originally requested script (e.g. prior to rewrite)
             if (trim($_SERVER['REQUEST_URI']) !== '') {
                 // use of lighttpd's rewriting detected
                 $query = strtok($_SERVER['REQUEST_URI'], '?');
                 // mark rewrite mode by not selecting any valid used proxy
                 $detectedProxy = true;
             } else {
                 if (trim($_SERVER['REDIRECT_URL']) !== '') {
                     // use of mod_rewrite detected
                     $query = $_SERVER['REDIRECT_URL'];
                     // mark rewrite mode by not selecting any valid used proxy
                     $detectedProxy = true;
                 } else {
                     // request for proxy script (run.php) detected
                     $query = $_SERVER['PATH_INFO'];
                     // remember proxy script used this time, if any
                     $detectedProxy = $this->scriptPathname;
                 }
             }
             // derive list of application and script selectors
             return path::stripCommonPrefix(explode('/', $query), $this->prefixPathname);
             // txf::CTXMODE_NORMAL
         // txf::CTXMODE_NORMAL
         default:
             // expect application and script selectors being part of requested
             // script pathname
             return preg_split('#/+#', $this->applicationScriptPathname);
     }
 }
示例#8
0
文件: captcha.php 项目: cepharum/txf
 public function __construct()
 {
     $this->session =& txf::session();
 }
示例#9
0
文件: stateful.php 项目: cepharum/txf
 public function __construct()
 {
     $this->set =& txf::session(session::SCOPE_CLASS + session::SCOPE_SCRIPT, 'input_source_stateful');
 }