Source for file ConverterManager.php

Documentation is available at ConverterManager.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * フォームセットの値の変換処理を実行します。
  20.  * 
  21.  * <pre>
  22.  * ■configの仕様:
  23.  *   array(
  24.  *       'フィールド名' => array(
  25.  *           'Converter名' => array(
  26.  *               '設定1' => '設定値1',
  27.  *               '設定2' => '設定値2',
  28.  *               ....
  29.  *           ),
  30.  *       ),
  31.  *       ....
  32.  *   )
  33.  * </pre>
  34.  *
  35.  * @package teeple
  36.  */
  37. {
  38.     
  39.     const FIELD_ALL '__all';
  40.     
  41.     /**
  42.      * @var Logger 
  43.      */
  44.     protected $log;
  45.     
  46.     /**
  47.      * @var Teeple_Container 
  48.      */
  49.     private $container;
  50.     public function setComponent_container($c{
  51.         $this->container $c;
  52.     }
  53.     
  54.     /**
  55.      * コンストラクタ
  56.      *
  57.      */
  58.     public function __construct({
  59.         $this->log = LoggerManager::getLogger(get_class($this));
  60.     }
  61.  
  62.     /**
  63.      * 指定されたconfigで変換を実行します。
  64.      *
  65.      * @param mixed $obj 
  66.      * @param array $config 
  67.      */
  68.     public function execute(&$obj&$config{
  69.         
  70.         foreach($config as $fieldName => $fieldConfig{
  71.             foreach($fieldConfig as $converterName => $attr{
  72.                 // Converterインスタンスを作成
  73.                 $converter $this->container->getPrototype("Teeple_Converter_"ucfirst($converterName));
  74.                 if (is_object($converter)) {
  75.                     throw new Teeple_Exception("Converterのインスタンスを作成できません。($converterName)");
  76.                 }
  77.                 // 属性をセット
  78.                 foreach($attr as $key => $value{
  79.                     $converter->$key $value;
  80.                 }
  81.                 // Converterを実行
  82.                 if ($fieldName == self::FIELD_ALL{
  83.                     $keys Teeple_Util::getPropertyNames($obj);
  84.                 else {
  85.                     $keys array($fieldName);
  86.                 }
  87.                 foreach ($keys as $key{
  88.                     if ($converter->convert($obj$key)) {
  89.                         $this->log->info("{$converterName}は{$key}に対して実行されませんでした。");
  90.                     }
  91.                 }
  92.             }
  93.         }
  94.         return;
  95.     }
  96.     
  97. }
  98. ?>

Documentation generated on Mon, 26 Apr 2010 08:59:39 +0900 by phpDocumentor 1.4.3