当前位置: 首页>>代码示例>>PHP>>正文


PHP Context::push方法代码示例

本文整理汇总了PHP中Context::push方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::push方法的具体用法?PHP Context::push怎么用?PHP Context::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context::push方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * @param Context $context
  *
  * @return mixed
  */
 public function render($context)
 {
     /** @var $block_context BlockContext */
     $block_context = null;
     if (isset($context->render_context[BLOCK_CONTEXT_KEY])) {
         $block_context = $context->render_context[BLOCK_CONTEXT_KEY];
     }
     $context->push();
     if ($block_context === null) {
         $context['block'] = $this;
         $result = $this->nodelist->render($context);
     } else {
         $push = $block = $block_context->pop($this->name);
         if ($block === null) {
             $block = $this;
         }
         // Create new block so we can store context without thread-safety issues.
         $block = new BlockNode($block->name, $block->nodelist);
         $block->context = $context;
         $context['block'] = $block;
         $result = $block->nodelist->render($context);
         if ($push !== null) {
             $block_context->push($this->name, $push);
         }
     }
     $context->pop();
     return $result;
 }
开发者ID:idlesign,项目名称:dja,代码行数:33,代码来源:loader_tags.php

示例2: testAddItemInInnerScope

 public function testAddItemInInnerScope()
 {
     $this->context->push();
     $this->context->set('test', 'test');
     $this->assertEquals('test', $this->context->get('test'));
     $this->context->pop();
     $this->assertEquals(null, $this->context->get('test'));
 }
开发者ID:QuentinBellus,项目名称:php-liquid,代码行数:8,代码来源:ContextTest.php

示例3: test_stack

 public function test_stack()
 {
     $context = new Context();
     $this->assertSame([], $context->to_array());
     $context->push();
     $context['one'] = 1;
     $this->assertSame(['one' => 1], $context->to_array());
     $context->push();
     $context['two'] = 2;
     $this->assertSame(['one' => 1, 'two' => 2], $context->to_array());
     $context->push();
     $context['three'] = 3;
     $this->assertSame(['one' => 1, 'two' => 2, 'three' => 3], $context->to_array());
     $context->pop();
     $this->assertSame(['one' => 1, 'two' => 2], $context->to_array());
     $context->pop();
     $this->assertSame(['one' => 1], $context->to_array());
     $context->pop();
     $this->assertSame([], $context->to_array());
 }
开发者ID:icybee,项目名称:bluetihi,代码行数:20,代码来源:ContextTest.php

示例4: test_context

 public function test_context()
 {
     $c = new Context(array('a' => 1, 'b' => 'xyzzy'));
     $this->assertEquals($c['a'], 1);
     $this->assertEquals($c->push(), array());
     $c['a'] = 2;
     $this->assertEquals($c['a'], 2);
     $this->assertEquals($c->get('a'), 2);
     $this->assertEquals($c->pop(), array('a' => 2));
     $this->assertEquals($c['a'], 1);
     $this->assertEquals($c->get('foo', 42), 42);
 }
开发者ID:idlesign,项目名称:dja,代码行数:12,代码来源:context.php

示例5: testContainsTellsYouIfAGivenContextIsInTheCurrentStack

 public function testContainsTellsYouIfAGivenContextIsInTheCurrentStack()
 {
     $context = new Context();
     $context->push('foo');
     $context->push('bar');
     $context->push('baz');
     $this->assertTrue($context->contains('foo'));
     $this->assertTrue($context->contains('bar'));
     $this->assertTrue($context->contains('baz'));
     $popped = $context->pop();
     $this->assertFalse($context->contains($popped));
     // TODO: remove once global state is fully deprecated (2.0)
     _elgg_services()->setValue('context', new Context());
     elgg_push_context('foo');
     elgg_push_context('bar');
     elgg_push_context('baz');
     $this->assertTrue(elgg_in_context('foo'));
     $this->assertTrue(elgg_in_context('bar'));
     $this->assertTrue(elgg_in_context('baz'));
     $popped = elgg_pop_context();
     $this->assertFalse(elgg_in_context($popped));
 }
开发者ID:sephiroth88,项目名称:Elgg,代码行数:22,代码来源:ContextTest.php

示例6: testContext

 public function testContext()
 {
     $server = $this->getMockBuilder('Deployer\\Server\\ServerInterface')->disableOriginalConstructor()->getMock();
     $env = $this->getMockBuilder('Deployer\\Server\\Environment')->disableOriginalConstructor()->getMock();
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->disableOriginalConstructor()->getMock();
     $output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->disableOriginalConstructor()->getMock();
     $context = new Context($server, $env, $input, $output);
     $this->assertInstanceOf('Deployer\\Server\\ServerInterface', $context->getServer());
     $this->assertInstanceOf('Deployer\\Server\\Environment', $context->getEnvironment());
     $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface', $context->getInput());
     $this->assertInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface', $context->getOutput());
     Context::push($context);
     $this->assertEquals($context, Context::get());
     $this->assertEquals($context, Context::pop());
 }
开发者ID:acorncom,项目名称:deployer,代码行数:15,代码来源:ContextTest.php

示例7: run

 /**
  * Run task.
  *
  * @param Context $context
  */
 public function run(Context $context)
 {
     Context::push($context);
     $env = $context->getEnvironment();
     // Save cd's working_path path.
     if ($env !== null) {
         $workingPath = $env->get('working_path', false);
     }
     // Call tasks.
     call_user_func($this->callback);
     // Restore cd's working_path path.
     if ($env !== null && isset($workingPath)) {
         $env->set('working_path', $workingPath);
     }
     Context::pop();
 }
开发者ID:acorncom,项目名称:deployer,代码行数:21,代码来源:Task.php

示例8: _mustacheStyleSection

    /**
     * Process Mustache section style
     *
     * @param Context $context current context
     * @param array   $current section node data
     *
     * @throws \RuntimeException
     * @return mixed|string
     */
    private function _mustacheStyleSection(Context $context, $current)
    {
        $sectionName = $current[Tokenizer::NAME];

        // fallback to mustache style each/with/for just if there is
        // no argument at all.
        try {
            $sectionVar = $context->get($sectionName, true);
        } catch (\InvalidArgumentException $e) {
            throw new \RuntimeException(
                $sectionName . ' is not registered as a helper'
            );
        }
        $buffer = '';
        if (is_array($sectionVar) || $sectionVar instanceof \Traversable) {
            $isList = is_array($sectionVar) &&
                (array_keys($sectionVar) === range(0, count($sectionVar) - 1));
            $index = 0;
            $lastIndex = $isList ? (count($sectionVar) - 1) : false;

            foreach ($sectionVar as $key => $d) {
                $specialVariables = array(
                    '@index' => $index,
                    '@first' => ($index === 0),
                    '@last' => ($index === $lastIndex),
                );
                if (!$isList) {
                    $specialVariables['@key'] = $key;
                }
                $context->pushSpecialVariables($specialVariables);
                $context->push($d);
                $buffer .= $this->render($context);
                $context->pop();
                $context->popSpecialVariables();
                $index++;
            }
        } elseif (is_object($sectionVar)) {
            //Act like with
            $context->push($sectionVar);
            $buffer = $this->render($context);
            $context->pop();
        } elseif ($sectionVar) {
            $buffer = $this->render($context);
        }

        return $buffer;
    }
开发者ID:nico13051995,项目名称:IntITA,代码行数:56,代码来源:Template.php

示例9: testPushDoesNotAlterCase

 public function testPushDoesNotAlterCase()
 {
     $context = new Context();
     $context->push("HELLO");
     $this->assertEquals("HELLO", $context->peek());
 }
开发者ID:ibou77,项目名称:elgg,代码行数:6,代码来源:ContextTest.php

示例10: render

 /**
  * @param Context $context
  * @return SafeString|string
  * @throws Exception|TypeError|VariableDoesNotExist
  * @throws RuntimeError
  */
 public function render($context)
 {
     if (isset($context['forloop'])) {
         $parentloop = $context['forloop'];
     } else {
         $parentloop = array();
     }
     $context->push();
     try {
         $values = $this->sequence->resolve($context, True);
     } catch (VariableDoesNotExist $e) {
         $values = array();
     }
     if ($values === null) {
         $values = array();
     } elseif (is_string($values)) {
         // We convert a string to array to make it iterable.
         $values = str_split($values);
         // TODO Check unicode handling.
     }
     if (!is_array($values) && !$values instanceof Iterator) {
         throw new RuntimeError('Noniterable "' . $values . '" is passed to for loop.');
     }
     $len_values = count($values);
     if ($len_values < 1) {
         $context->pop();
         return $this->nodelist_empty->render($context);
     }
     $nodelist = new NodeList();
     if ($this->is_reversed) {
         $values_ = $values;
         krsort($values_);
         $values = $values_;
         unset($values_);
     }
     $unpack = count($this->loopvars) > 1;
     // Create a forloop value in the context.  We'll update counters on each iteration just below.
     $loop_dict = $context['forloop'] = array('parentloop' => $parentloop);
     foreach ($values as $i => $item) {
         // Shortcuts for current loop iteration number.
         $loop_dict['counter0'] = $i;
         $loop_dict['counter'] = $i + 1;
         // Reverse counter iteration numbers.
         $loop_dict['revcounter'] = $len_values - $i;
         $loop_dict['revcounter0'] = $len_values - $i - 1;
         // Boolean values designating first and last times through loop.
         $loop_dict['first'] = $i == 0;
         $loop_dict['last'] = $i == $len_values - 1;
         $context['forloop'] = array_merge($context['forloop'], $loop_dict);
         $pop_context = False;
         if ($unpack) {
             // If there are multiple loop variables, unpack the item into them.
             $success_ = True;
             try {
                 $unpacked_vars = py_zip($this->loopvars, $item);
             } catch (TypeError $e) {
                 $success_ = False;
             }
             if ($success_) {
                 $pop_context = True;
                 $context->update($unpacked_vars);
             }
         } else {
             $context[$this->loopvars[0]] = $item;
         }
         // In TEMPLATE_DEBUG mode provide source of the node which actually raised the exception
         if (Dja::getSetting('TEMPLATE_DEBUG')) {
             foreach ($this->nodelist_loop as $node) {
                 /** @var $node Node */
                 try {
                     $nodelist[] = $node->render($context);
                 } catch (Exception $e) {
                     if (!py_hasattr($e, 'django_template_source')) {
                         $e->django_template_source = $node->source;
                     }
                     throw $e;
                 }
             }
         } else {
             foreach ($this->nodelist_loop as $node) {
                 $nodelist[] = $node->render($context);
             }
         }
         if ($pop_context) {
             /*
              * The loop variables were pushed on to the context so pop them
              * off again. This is necessary because the tag lets the length
              * of loopvars differ to the length of each set of items and we
              * don't want to leave any vars from the previous loop on the
              * context.
              */
             $context->pop();
         }
     }
//.........这里部分代码省略.........
开发者ID:idlesign,项目名称:dja,代码行数:101,代码来源:defaulttags.php

示例11: testFailToSetEmptyContext

 public function testFailToSetEmptyContext()
 {
     $context = new Context();
     $context->set("  ");
     $this->assertNull($context->peek());
     $this->assertNull($context->pop());
     $context->push("  ");
     $this->assertEquals("  ", $context->peek());
     $this->assertEquals("  ", $context->pop());
 }
开发者ID:gzachos,项目名称:elgg_ellak,代码行数:10,代码来源:ContextTest.php


注:本文中的Context::push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。