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

Source for file recode.php

Documentation is available at recode.php

  1. <?php
  2. /**
  3.  * File containing the ezcMvcRecodeResponseFilter 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.  * Response filter that converts the encoding of the body.
  30.  *
  31.  * @package MvcTools
  32.  * @version //autogentag//
  33.  * @mainclass
  34.  */
  35. class ezcMvcRecodeResponseFilter implements ezcMvcResponseFilter
  36. {
  37.     /**
  38.      * Contains the from (internal) encoding
  39.      * @var string 
  40.      */
  41.     private $fromEncoding 'utf-8';
  42.  
  43.     /**
  44.      * Contains the to (external) encoding
  45.      * @var string 
  46.      */
  47.     private $toEncoding 'utf-8';
  48.  
  49.     /**
  50.      * This function re-codes the response body from charset $fromEncoding to charset $toEncoding.
  51.      *
  52.      * @param ezcMvcResponse $response 
  53.      */
  54.     public function filterResponseezcMvcResponse $response )
  55.     {
  56.         $test @iconv$this->fromEncoding$this->fromEncoding$response->body );
  57.         if $test !== $response->body )
  58.         {
  59.             throw new ezcMvcInvalidEncodingException$response->body$this->fromEncoding );
  60.         }
  61.         $res @iconv$this->fromEncoding$this->toEncoding '//IGNORE'$response->body );
  62.         $response->body $res;
  63.     }
  64.  
  65.     /**
  66.      * Should not be called with any options, as this filter doesn't support any.
  67.      *
  68.      * @throws ezcMvcFilterHasNoOptionsException if the $options array is not
  69.      *  empty.
  70.      * @param array $options 
  71.      */
  72.     public function setOptionsarray $options )
  73.     {
  74.         foreach $options as $option => $value )
  75.         {
  76.             switch $option )
  77.             {
  78.                 case 'fromEncoding':
  79.                 case 'toEncoding':
  80.                     $this->$option $value;
  81.                     break;
  82.                 default:
  83.                     throw new ezcBasePropertyNotFoundException$option );
  84.             }
  85.         }
  86.     }
  87. }
  88. ?>
Documentation generated by phpDocumentor 1.4.3