/** * Iniciamos la sesión * @return nothing */ public static final function init() { // Configuramos... self::$configuration = get_config(str_replace('Framework\\', '', get_called_class())); // Obtenemos una instancia de LDB para utilizar... self::$db = LittleDB::get_instance(); if (!isset($_SESSION) or session_id() == '') { session_start(); } // Iniciamos datos predeterminados para la sesión if (!isset($_SESSION['hash'])) { if (isset($_COOKIE[self::$configuration['cookie_name']])) { $_SESSION['hash'] = $_COOKIE[self::$configuration['cookie_name']]; $_SESSION['use_cookies'] = true; } else { $_SESSION['hash'] = null; $_SESSION['use_cookies'] = false; } $_SESSION['ip'] = ip2long($_SERVER['REMOTE_ADDR']); } $_SESSION['datetime'] = time(); if ($_SESSION['hash'] !== null) { self::set_id(); } Context::add('is_logged', array('Framework\\Session', 'is_session')); }
/** * Recursive implementation of export * * @param mixed $value The value to export * @param integer $indentation The indentation level of the 2nd+ line * @param SebastianBergmann\Exporter\Context $processed Contains all objects and arrays that have previously been rendered * @return string * @see SebastianBergmann\Exporter\Exporter::export */ protected function recursiveExport(&$value, $indentation, $processed = NULL) { if ($value === NULL) { return 'null'; } if ($value === TRUE) { return 'true'; } if ($value === FALSE) { return 'false'; } if (is_float($value) && floatval(intval($value)) === $value) { return "{$value}.0"; } if (is_resource($value)) { return sprintf('resource(%d) of type (%s)', $value, get_resource_type($value)); } if (is_string($value)) { // Match for most non printable chars somewhat taking multibyte chars into account if (preg_match('/[^\\x09-\\x0d\\x20-\\xff]/', $value)) { return 'Binary String: 0x' . bin2hex($value); } return "'" . str_replace(array("\r\n", "\n\r", "\r"), array("\n", "\n", "\n"), $value) . "'"; } $whitespace = str_repeat(' ', 4 * $indentation); if (!$processed) { $processed = new Context(); } if (is_array($value)) { if (($key = $processed->contains($value)) !== FALSE) { return 'Array &' . $key; } $key = $processed->add($value); $values = ''; if (count($value) > 0) { foreach ($value as $k => $v) { $values .= sprintf('%s %s => %s' . "\n", $whitespace, $this->recursiveExport($k, $indentation), $this->recursiveExport($value[$k], $indentation + 1, $processed)); } $values = "\n" . $values . $whitespace; } return sprintf('Array &%s (%s)', $key, $values); } if (is_object($value)) { $class = get_class($value); if ($hash = $processed->contains($value)) { return sprintf('%s Object &%s', $class, $hash); } $hash = $processed->add($value); $values = ''; $array = $this->toArray($value); if (count($array) > 0) { foreach ($array as $k => $v) { $values .= sprintf('%s %s => %s' . "\n", $whitespace, $this->recursiveExport($k, $indentation), $this->recursiveExport($v, $indentation + 1, $processed)); } $values = "\n" . $values . $whitespace; } return sprintf('%s Object &%s (%s)', $class, $hash, $values); } return var_export($value, TRUE); }
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); }
public function testLog() { $context = new Context('dialog'); $context->add('div', array('class' => 'dialog')); $context->add('context', 'title'); $context->add('context', 'body'); $context->select('title')->add('div', array('class' => 'title')); $context->select('title')->add('content'); $body = $context->select('body'); $body->add('div', array('class' => 'body')); $body->add('content'); $content = array('title' => 'My title', 'body' => 'My first contextual view'); Context::clearLog(); $context->render($content); $actual = implode("\n", Context::getLog()); $expected = <<<END [Render] Rendering dialog#dialog [Selector] Selector dialog applies [Decorator] Rendering decorator Context with name body [Context] Creating context body with id body [Render] Rendering body#body [Selector] Selector body applies [Decorator] Rendering decorator Content with name content [Decorator] Rendering decorator HtmlTag with name div [Decorator] Rendering decorator Context with name title [Context] Creating context title with id title [Render] Rendering title#title [Selector] Selector title applies [Decorator] Rendering decorator Content with name content [Decorator] Rendering decorator HtmlTag with name div [Decorator] Rendering decorator HtmlTag with name div END; // Normalize line endings $expected = str_replace("\r\n", "\n", $expected); $actual = str_replace("\r\n", "\n", $actual); $this->assertEquals($expected, $actual); }
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); }