Source for file Util.php

Documentation is available at Util.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.  * Utilクラスです。
  20.  *
  21.  * @package teeple
  22.  */
  23. class Teeple_Util {
  24.     
  25.     /**
  26.      * iniファイルを読込みます。
  27.      *
  28.      * @param string $configfile iniファイルのパス
  29.      * @return array 
  30.      */
  31.     public static function readIniFile($configfile{
  32.         
  33.         if(file_exists($configfile)) {
  34.             $this->log->info("Filterの設定ファイルが存在しません。($configfile)");
  35.             return NULL;
  36.         }
  37.         
  38.         $config parse_ini_file($configfiletrue);
  39.         if (is_array($config)) {
  40.             $this->log->error("Filterの設定ファイルに誤りがあります。($configfile)");
  41.             return NULL;
  42.         }
  43.         if (CONFIG_CODE != INTERNAL_CODE{
  44.             mb_convert_variables(INTERNAL_CODECONFIG_CODE$config);
  45.         }
  46.         
  47.         return $config;
  48.     }
  49.     
  50.     /**
  51.      * ハイフン区切りでCapitalizeされたクラス名を取得します。
  52.      *
  53.      * @param string $name クラス名
  54.      * @return string 
  55.      */
  56.     public static function capitalizedClassName($name{
  57.         
  58.         $pathList explode("_"$name);
  59.         $ucPathList array_map('ucfirst'$pathList);
  60.         return join("_"$ucPathList);
  61.     }
  62.  
  63.     /**
  64.      * 値が空白かどうかをチェックします。
  65.      *
  66.      * @param mixed $value 
  67.      * @param boolean $trim 
  68.      * @return boolean 
  69.      */
  70.     public static function isBlank($value$trim TRUE{
  71.         
  72.         if (is_array($value)) {
  73.             return (count($value== 0);
  74.         }
  75.         if ($trim{
  76.             $value trim($value);
  77.         }
  78.         return ($value === NULL || $value === "");
  79.     }
  80.     
  81.     /**
  82.      * エラーメッセージにパラメータを埋め込んで返します。
  83.      *
  84.      * @param string $msg 
  85.      * @param array $param 
  86.      * @return string 
  87.      */
  88.     public static function formatErrorMessage($msg&$param{
  89.         
  90.         foreach($param as $i => $arg{
  91.             $msg str_replace("{".$i."}"$arg$msg);
  92.         }
  93.         return $msg;
  94.     }
  95.     
  96.     /**
  97.      * クラスファイルをincludeします。
  98.      *
  99.      * @param string $name 
  100.      * @return boolean 
  101.      */
  102.     public static function includeClassFile($name{
  103.         
  104.         $pathList explode('_'$name);
  105.         $path "";
  106.         for($i=0$i<count($pathList)$i++{
  107.             if ($i != count($pathList1{
  108.                 $path .= strtolower($pathList[$i]);
  109.                 $path .= '/';
  110.             else {
  111.                 $path .= $pathList[$i];
  112.             }
  113.         }
  114.         $path .= ".php";
  115.         $result @include_once $path;
  116.         if ($result !== FALSE{
  117.             return TRUE;
  118.         }
  119.         
  120.         $path implode('/'$pathList.".php";
  121.         $result @include_once $path;
  122.         
  123.         return $result === FALSE FALSE TRUE;
  124.     }
  125.     
  126.     /**
  127.      * オブジェクトまたは配列から指定された名前のプロパティを取り出します。
  128.      *
  129.      * @param mixed $obj 
  130.      * @param string $fieldName 
  131.      * @return mixed 
  132.      */
  133.     public static function getProperty($obj$fieldName{
  134.         
  135.         if (is_object($obj)) {
  136.             return $obj->$fieldName;
  137.         }
  138.         if (is_array($obj)) {
  139.             return isset($obj[$fieldName]$obj[$fieldNameNULL;
  140.         }
  141.         return $obj;
  142.     }
  143.     
  144.     /**
  145.      * オブジェクトまたは配列に指定された名前のプロパティをセットします。
  146.      *
  147.      * @param mixed $obj 
  148.      * @param string $fieldName 
  149.      * @param mixed $value 
  150.      */
  151.     public static function setProperty(&$obj$fieldName$value{
  152.         
  153.         if (is_object($obj)) {
  154.             $obj->$fieldName $value;
  155.         }
  156.         if (is_array($obj)) {
  157.             $obj[$fieldName$value;
  158.         }
  159.         return;
  160.     }
  161.     
  162.     /**
  163.      * オブジェクトまたは配列にセットされているプロパティの名前をすべて取得します。
  164.      *
  165.      * @param mixed $obj 
  166.      * @return array 
  167.      */
  168.     public static function getPropertyNames($obj{
  169.         
  170.         if (is_object($obj)) {
  171.             return array_keys(get_object_vars($obj));
  172.         }
  173.         if (is_array($obj)) {
  174.             return array_keys($obj);
  175.         }
  176.         return array();
  177.     }
  178.  
  179. }
  180. ?>

Documentation generated on Mon, 26 Apr 2010 09:00:03 +0900 by phpDocumentor 1.4.3