本文整理汇总了PHP中Context::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::add方法的具体用法?PHP Context::add怎么用?PHP Context::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* 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'));
}
示例2: recursiveExport
/**
* 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);
}
示例3: testPlacementPrepend
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);
}
示例4: testLog
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);
}
示例5: testTableWithIds
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' => 'peter@alps.ch'), array('id' => 17, 'name' => 'Heidi', 'email' => 'heidi@alps.ch'));
$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);
}