Example #1
0
 public function testPlacementPrepend()
 {
     $context = new Context();
     $context->add('content', array('name' => 'one', 'placement' => 'prepend'));
     $context->add('content', array('name' => 'two'));
     $context->setContent('one', 'outer');
     $context->setContent('two', 'inner');
     $expected = 'outerinner';
     $actual = $context->render();
     $this->assertEquals($expected, $actual);
 }
Example #2
0
 /**
  * Creates a sub context of the given name
  * @param string $name the context name
  * @param string $id the id of the new context
  * @return Context The created context
  */
 public function createContext($name, $id = null)
 {
     $context = new Context($name, $id);
     $id = $context->id();
     // add selectors
     foreach ($this->_selectors as $key => $selector) {
         $parts = explode(' ', $key);
         // handle nested selectors
         $first = array_shift($parts);
         if (count($parts) > 0 && $context->applies($first)) {
             $key = implode(' ', $parts);
         }
         $context->_selectors[$key] = $selector;
     }
     // add tags and ids
     $context->_tags = $this->_tags;
     $context->_ids = $this->_ids;
     // add content
     $context->_content = $this->_content;
     $content = $this->getContent();
     if (is_array($content) && isset($content[$id])) {
         $content = $content[$id];
     }
     $context->setContent($name, $content);
     self::$_log[] = '[Context] Creating context ' . $name . ' with id ' . $id;
     return $context;
 }
 public function testTableWithIds()
 {
     $context = new Context('table');
     $context->add('table');
     $context->add('contexts', 'row');
     $context->select('row')->add('tr')->add('contexts', 'column');
     $context->select('column')->add('td')->add('content');
     $context->ids('column', 'name,email');
     $data = array(array('id' => 23, 'name' => 'Peter', 'email' => '*****@*****.**'), array('id' => 17, 'name' => 'Heidi', 'email' => '*****@*****.**'));
     $context->setContent($data);
     $expected = '<table><tr><td>Peter</td><td>peter@alps.ch</td></tr><tr><td>Heidi</td><td>heidi@alps.ch</td></tr></table>';
     $actual = $context->render();
     $this->assertEquals($expected, $actual);
 }
Example #4
0
 public function testSettingEmptyContentIfParamMatchesName()
 {
     $context = new Context('test');
     $content = array();
     $context->setContent('test', $content);
     $actual = $context->getContent('test');
     $this->assertEquals(array(), $actual);
 }
Example #5
0
$ctx = new Context($_GET, $_POST, $_SERVER);
if ($ctx->isFile()) {
    readfile('.' . $ctx->getPath());
    exit;
} else {
    if (preg_match('/\\.php$/', $ctx->getPath())) {
        include '.' . $ctx->getPath();
        exit;
    } else {
        ob_start();
        try {
            $r = $ctx->loadComponent();
        } catch (ContextException $ce) {
            if ($ce->getCode() == 404) {
                $ctx->setHTTPStatus(404, "Not found");
                $ctx->setContent($ce->getMessage());
            } else {
                $ctx->setHTTPStatus(500, "Internal error in PHP software");
                $ctx->setContent($ce->getMessage());
            }
        }
        $output = ob_get_clean();
        if (!empty($output)) {
            $ctx->appendContent($output);
        }
        if (!empty($r)) {
            $ctx->appendContent($r);
        }
    }
}
$ctx->flushHeaders();