Example #1
0
 public function component($name)
 {
     $base = NULL;
     $context = $this->c;
     $base = $context->get_context_class();
     if (array_key_exists($name, $this->_components)) {
         return $this->_components[$name];
     }
     if (!class_exists($name)) {
         if (!self::load_file_by_classname($name)) {
             throw new DF_Web_Component_LoaderException("Component class does not exist: {$name}");
         }
     }
     $component = new $name();
     if (!$component instanceof DF_Web_Component) {
         throw new DF_Web_Component_LoaderException("Class {$name} does not implement DF_Web_Component");
     }
     if ($config = $component->config()) {
         $config = $context->resolve_config_placeholders($config);
         $component->set_config($config);
     }
     $configname = self::config_name($name, $base);
     $config = $this->c->config()->find_by_id($configname);
     if ($config == NULL) {
         $config = array();
     }
     $component->config($config);
     $component->initialize($context);
     $this->_components[$name] = $component;
     return $component;
 }
Example #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';
Example #3
0
<?php

define('DEFAULT_DATA_DIR', DF_Web::path_to('data'));
class DF_Web_Model_DataDir extends DF_Web_Model
{
    private $_cache = NULL;
    protected $config = array('dataDir' => DEFAULT_DATA_DIR);
    public function getDataDir()
    {
        return $this->config['dataDir'];
    }
    public function getFileContent($name)
    {
        $dir = $this->getDataDir();
        $content = file_get_contents($dir . $name);
        return $content;
    }
    public function putFileContent($name, $content)
    {
        $dir = $this->getDataDir();
        file_put_contents($dir . $file, $content);
    }
}
Example #4
0
<?php

define('DEFAULT_CACHE_DIR', DF_Web::path_to('cache'));
class DF_Web_Model_Cache extends DF_Web_Model
{
    private $_cache = NULL;
    protected $config = array('cache_class' => 'DF_Web_Cache_Lite', 'cache_config' => array('lifeTime' => 300, 'cacheDir' => DEFAULT_CACHE_DIR));
    public function get_cache()
    {
        return $this->_cache;
    }
    public function initialize($c)
    {
        $class = $this->config['cache_class'];
        $config = $this->config['cache_config'];
        $file = preg_replace('|_|', '/', $class);
        require_once "{$file}.php";
        $this->_cache = new $class($config);
    }
}
Example #5
0
 /**
  * Called after configuration is set.
  * 
  * @param DF_Web $c
  */
 public function initialize($c)
 {
     $c->register_action_class(DF_Web_Action_REST);
 }