Exemplo n.º 1
0
    }
    public function find_actions_by_path($path)
    {
        if (!$path instanceof DF_Web_Path) {
            throw new DF_Error_InvalidArgumentException("path", $path, "DF_Web_Path");
        }
        $ret = array();
        if ($best = $this->find_path_actions_by_path($path)) {
            $actions = $best->get_actions();
            $ret = self::build_path_action($path, $actions);
        } elseif ($best = $this->find_chained_actions_by_path($path)) {
            $actions = $best->get_actions();
            $ret = self::build_chain($path, $actions);
        } else {
            #throw new Exception("No actions found by path: $path");
        }
        return $ret;
    }
    public function find_actions_by_url($url)
    {
        $url = DF_Web_URL::fromString($url);
        $path = $url->get_path();
        #$path   = new DF_Web_Path($url);
        $actions = $this->find_actions_by_path($path);
        return $actions;
    }
}
require_once 'DF/Error/InvalidArgumentException.php';
require_once 'DF/Web/Routing/ActionChain.php';
DF_Web_Routing::$LOGGER = DF_Web_Logger::logger('DF_Web_Routing');
Exemplo n.º 2
0
        $response = $this->response;
        echo $response->body;
        $response->_finalized_body = true;
    }
    private function finalize_cookies()
    {
        $response = $this->response;
        foreach ($response->cookies as $c) {
            setcookie($c['name'], $c['value'], $c['expire'], $c['path'], $c['domain'], $c['secure'], $c['httponly']);
        }
        $response->_finalized_cookies = true;
    }
    public static function path_to()
    {
        // app_root should already be suffixed with /
        $home = DF_Web_Environment::singleton()->app_root;
        if (!preg_match('#/$#', $home)) {
            $home .= "/";
        }
        $args = func_get_args();
        if ($args) {
            $home .= join('/', $args);
            if (is_dir($home)) {
                $home .= '/';
            }
        }
        return $home;
    }
}
DF_Web::$LOGGER = DF_Web_Logger::logger('DF_Web');
require_once 'DF/Util/Arrays.php';
Exemplo n.º 3
0
<?php

# index.php
$DIR_SCRIPT = dirname(__FILE__);
$DIR_ROOT = "{$DIR_SCRIPT}/..";
$DIR_LIB = "{$DIR_ROOT}/lib";
set_include_path($DIR_LIB . ':' . get_include_path());
require_once 'DF/Web/Logger.php';
DF_Web_Logger::setActiveLogger('error_log');
require_once 'DF/Scrum.php';
$environment = DF_Web_Environment::singleton();
$environment->app_root = $DIR_ROOT;
$environment->trusted_proxies = 0;
$environment->base_path = dirname($_SERVER['SCRIPT_NAME']);
if (getenv('ENVIRONMENT')) {
    $environment->environment = getenv('ENVIRONMENT');
}
$environment->debug = 1;
# for production
$environment->environment = 'production';
$environment->debug = 0;
$context = new DF_Scrum();
$context->execute();
$context->finalize();
$context = NULL;
#error_log("Memory usage: ".memory_get_peak_usage());
DF_Web_Logger::shutdown();
Exemplo n.º 4
0
    public function get_path()
    {
        return $this->path;
    }
    public function get_method()
    {
        $name = $this->name;
        $method = "handle_{$name}";
        return $method;
    }
    public function get_code_ref()
    {
        $ctrl = $this->controller_name . "";
        $method = $this->get_method();
        $ref = array($ctrl, $method);
        return $ref;
    }
    public function __toString()
    {
        $ctrl = $this->controller_name;
        $method = $this->get_method();
        $path_match = $this->get_path_match();
        $name = $this->name;
        $path = $this->path;
        $args = $this->args;
        $str = "{$ctrl}::{$method} Pathmatch: {$path_match}, Name: {$name}, Path: {$path}, Args: {$args}";
        return $str;
    }
}
DF_Web_Routing_Action::$LOGGER = DF_Web_Logger::logger('DF_Web_Routing_Action');
Exemplo n.º 5
0
     */
    protected function has_config_chained($config)
    {
        if ($config->has('chained')) {
            return true;
        }
        return false;
    }
    public function is_chained_root()
    {
        return $this->is_chained_root;
    }
    public function is_endpoint()
    {
        if ($this->get_args()) {
            return true;
        }
        return false;
    }
    public function __toString()
    {
        $parent = parent::__toString();
        $chained = $this->chained;
        $captures = $this->captures;
        $root_chained = $this->is_chained_root ? "Root chained" : "Chained";
        $str = "{$parent}, {$root_chained}: {$chained}, Captures: {$captures}";
        return $str;
    }
}
DF_Web_Routing_Action_Chained::$LOGGER = DF_Web_Logger::logger('DF_Web_Routing_Action_Chained');
Exemplo n.º 6
0
require_once 'DF/Error.php';
require_once 'DF/Error/InvalidArgumentException.php';
class DF_Web_Utils_Arguments
{
    public static $LOGGER = NULL;
    public static function flatten_arguments_list($arguments)
    {
        if (!is_array($arguments)) {
            throw new DF_Error_InvalidArgumentException('arguments', $arguments, 'array');
        }
        $str = array();
        foreach ($arguments as $arg) {
            if (NULL === $arg) {
                $str[] = "NULL";
            } elseif (gettype($arg) == 'object') {
                $str[] = get_class($arg);
            } elseif (gettype($arg) == 'string') {
                $str[] = '"' . $arg . '"';
            } elseif (gettype($arg) == 'array') {
                $str[] = 'Array';
            } else {
                $type = gettype($arg);
                self::$LOGGER->warn("Building argument list. Unknown type: {$type} - value: {$arg}");
                $str[] = '"' . $arg . '"';
            }
        }
        return join(', ', $str);
    }
}
DF_Web_Utils_Arguments::$LOGGER = DF_Web_Logger::logger('DF_Web_Utils_Arguments');
Exemplo n.º 7
0
<?php

$DIR_SCRIPT = dirname(__FILE__);
$DIR_ROOT = "{$DIR_SCRIPT}/..";
$DIR_LIB = "{$DIR_ROOT}/lib";
set_include_path("{$DIR_SCRIPT}:" . $DIR_LIB . ':' . get_include_path());
require_once 'DF/Web/Logger.php';
DF_Web_Logger::setActiveLogger('log4php');
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'DF/Web/Config.php';
require_once 'DF/Web/Environment.php';
$environment = DF_Web_Environment::singleton();
$environment->app_root = "{$dir}/..";
DF_Web_Config::$basename = "tests";
Exemplo n.º 8
0
<?php

$dir = dirname(__FILE__);
set_include_path("{$dir}/..:" . get_include_path());
require_once 'DF/Web/Logger.php';
DF_Web_Logger::setActiveLogger('error_log');
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'DF/Web.php';
$environment = DF_Web_Environment::singleton();
$environment->app_root = "{$dir}/..";
DF_Web_Config::$basename = "tests";
Exemplo n.º 9
0
<?php

require_once 'DF/Web/View/Smarty.php';
class DF_Web_View_Smarty_Doclet extends DF_Web_View_Smarty
{
    public static $LOGGER = NULL;
    protected $config = array('debugging' => false, 'debugging_ctrl' => 'NONE', 'caching' => 0, 'error' => 'error.tpl');
}
DF_Web_View_Smarty::$LOGGER = DF_Web_Logger::logger('DF_Web_View_Smarty');
Exemplo n.º 10
0
        # TODO configurable and detect changes by timestamp
        $compiled_file = File::buildPath(array($app_root, "cache", "{$basename}-compiled.php"));
        if (file_exists($compiled_file)) {
            global $config;
            require_once "{$compiled_file}";
            return $config;
        }
        $file = File::buildPath(array($app_root, "{$basename}.yaml"));
        $fileenv = File::buildPath(array($app_root, "{$basename}-{$environment}.yaml"));
        $config = array();
        if (file_exists($file)) {
            if ($env->debug) {
                self::$LOGGER->debug("Loading configuration file: {$file}");
            }
            $loader = new DF_Web_Config_Loader($file);
            $config = array_merge($config, $loader->getConfig());
        }
        if (file_exists($fileenv)) {
            if ($env->debug) {
                self::$LOGGER->log("Loading configuration file: {$fileenv}");
            }
            $loader = DF_Web_Config_Loader($fileenv);
            $config = array_merge($config, $loader->getConfig());
        }
        $struct = "<?php\n \$config = " . var_export($config, 1) . ";";
        file_put_contents($compiled_file, $struct);
        return $config;
    }
}
DF_Web_Config::$LOGGER = DF_Web_Logger::logger('DF_Web_Config');
require_once 'DF/Util/Arrays.php';
Exemplo n.º 11
0
        }
        if ($this === $action) {
            return true;
        }
        if (get_class($action) !== get_class($this)) {
            return false;
        }
        if ($this->get_controller() != $action->get_controller()) {
            return false;
        }
        if ($this->get_method() != $action->get_method()) {
            return false;
        }
        if ($this->get_arguments() != $action->get_arguments()) {
            return false;
        }
        return true;
    }
    public function toString()
    {
        $args = "";
        if ($this->arguments) {
            $args = join(', ', $this->arguments);
        }
        $ctrl = $this->controller;
        $method = $this->method;
        return "{$ctrl}->{$method}({$args})";
    }
}
DF_Web_Action_REST::$LOGGER = DF_Web_Logger::logger('DF_Web_Action_REST');