瀏覽代碼

Whoops. Missed some docs and cleanup :)

Justin Hileman 11 年之前
父節點
當前提交
1fe5b0dfc2
共有 2 個文件被更改,包括 27 次插入9 次删除
  1. 5 4
      src/Mustache/Compiler.php
  2. 22 5
      src/Mustache/Context.php

+ 5 - 4
src/Mustache/Compiler.php

@@ -334,10 +334,11 @@ class Mustache_Compiler
      * @param string $otag  Current Mustache opening tag
      * @param string $ctag  Current Mustache closing tag
      * @param int    $level
+     * @param bool   $arg   (default: false)
      *
      * @return string Generated section PHP source code
      */
-    private function section($nodes, $id, $start, $end, $otag, $ctag, $level, $arg=false)
+    private function section($nodes, $id, $start, $end, $otag, $ctag, $level, $arg = false)
     {
         $filters = '';
 
@@ -354,7 +355,7 @@ class Mustache_Compiler
             $delims = '';
         }
 
-        $key    = ucfirst(md5($delims."\n".$source));
+        $key = ucfirst(md5($delims."\n".$source));
 
         if (!isset($this->sections[$key])) {
             $this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $delims, $this->walk($nodes, 2));
@@ -363,8 +364,8 @@ class Mustache_Compiler
         if ($arg === true) {
             return $key;
         } else {
-            $method   = $this->getFindMethod($id);
-            $id = var_export($id, true);
+            $method = $this->getFindMethod($id);
+            $id     = var_export($id, true);
 
             return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key);
         }

+ 22 - 5
src/Mustache/Context.php

@@ -14,8 +14,8 @@
  */
 class Mustache_Context
 {
-    private $stack = array();
-    private $block_stack = array();
+    private $stack      = array();
+    private $blockStack = array();
 
     /**
      * Mustache rendering Context constructor.
@@ -39,9 +39,14 @@ class Mustache_Context
         array_push($this->stack, $value);
     }
 
+    /**
+     * Push a new Context frame onto the block context stack.
+     *
+     * @param  mixed $value Object or array to use for block context
+     */
     public function pushBlockContext($value)
     {
-        array_push($this->block_stack, $value);
+        array_push($this->blockStack, $value);
     }
 
     /**
@@ -54,9 +59,14 @@ class Mustache_Context
         return array_pop($this->stack);
     }
 
+    /**
+     * Pop the last block Context frame from the stack.
+     *
+     * @return mixed Last block Context frame (object or array)
+     */
     public function popBlockContext()
     {
-        return array_pop($this->block_stack);
+        return array_pop($this->blockStack);
     }
 
     /**
@@ -131,9 +141,16 @@ class Mustache_Context
         return $value;
     }
 
+    /**
+     * Find an argument in the block context stack.
+     *
+     * @param string $id
+     *
+     * @return mixed Variable value, or '' if not found.
+     */
     public function findInBlock($id)
     {
-        foreach ($this->block_stack as $context) {
+        foreach ($this->blockStack as $context) {
             if (array_key_exists($id, $context)) {
                 return $context[$id];
             }