Apache Zeta Components Manual :: File Source for json.php

Source for file json.php

Documentation is available at json.php

  1. <?php
  2. /**
  3.  * File containing the ezcMvcJsonViewHandler class
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  23.  * @version //autogentag//
  24.  * @filesource
  25.  * @package MvcTools
  26.  */
  27.  
  28. /**
  29.  * The view handler that renders result objects as JSON.
  30.  *
  31.  * @package MvcTools
  32.  * @version //autogentag//
  33.  * @mainclass
  34.  */
  35. class ezcMvcJsonViewHandler implements ezcMvcViewHandler
  36. {
  37.     /**
  38.      * Contains the zone name
  39.      *
  40.      * @var string 
  41.      */
  42.     protected $zoneName;
  43.  
  44.     /**
  45.      * Contains the result after process() has been called.
  46.      *
  47.      * @var mixed 
  48.      */
  49.     protected $result;
  50.  
  51.     /**
  52.      * Contains the variables that will be available in the template.
  53.      *
  54.      * @var array(mixed) 
  55.      */
  56.     protected $variables = array();
  57.  
  58.     /**
  59.      * Creates a new view handler, where $zoneName is the name of the block and
  60.      * $templateLocation the location of a view template.
  61.      *
  62.      * @param string $zoneName 
  63.      * @param string $templateLocation 
  64.      */
  65.     public function __construct$zoneName$templateLocation null )
  66.     {
  67.         $this->zoneName = $zoneName;
  68.     }
  69.  
  70.     /**
  71.      * Adds a variable to the template, which can then be used for rendering
  72.      * the view.
  73.      *
  74.      * @param string $name 
  75.      * @param mixed $value 
  76.      */
  77.     public function send$name$value )
  78.     {
  79.         $this->variables[$name$value;
  80.     }
  81.  
  82.     /**
  83.      * Processes the template with the variables added by the send() method.
  84.      * The result of this action should be retrievable through the getResult() method.
  85.      *
  86.      * The $last parameter is set if the view handler is the last one in the
  87.      * list of zones for a specific view. Only in that case is json_encode()
  88.      * used to generate JSON output.
  89.      *
  90.      * @param bool $last 
  91.      */
  92.     public function process$last )
  93.     {
  94.         $this->result = $this->variables;
  95.         if $last )
  96.         {
  97.             $this->result = json_encode$this->result );
  98.         }
  99.     }
  100.  
  101.     /**
  102.      * Returns the value of the property $name.
  103.      *
  104.      * @throws ezcBasePropertyNotFoundException if the property does not exist.
  105.      * @param string $name 
  106.      * @ignore
  107.      */
  108.     public function __get$name )
  109.     {
  110.         return $this->variables[$name];
  111.     }
  112.  
  113.     /**
  114.      * Returns true if the property $name is set, otherwise false.
  115.      *
  116.      * @param string $name 
  117.      * @return bool 
  118.      * @ignore
  119.      */
  120.     public function __isset$name )
  121.     {
  122.         return array_key_exists$name$this->variables );
  123.     }
  124.  
  125.     /**
  126.      * Returns the name of the template, as set in the constructor.
  127.      *
  128.      * @return string 
  129.      */
  130.     public function getName()
  131.     {
  132.         return $this->zoneName;
  133.     }
  134.  
  135.     /**
  136.      * Returns the result of the process() method.
  137.      *
  138.      * @return mixed 
  139.      */
  140.     public function getResult()
  141.     {
  142.         return $this->result;
  143.     }
  144. }
  145. ?>
Documentation generated by phpDocumentor 1.4.3