Exemple #1
0
 private static function runPreparer($obj, $methodName)
 {
     $ref = new ReflectionObject($obj);
     $refMethod = $ref->getMethod($methodName);
     $comment = $refMethod->getDocComment();
     if ($comment && preg_match_all('/@preparer +([a-zA-Z0-9_]+) +([a-zA-Z0-9_]+)/', $comment, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $line) {
             $className = $line[1];
             $propName = $line[2];
             $iniFile = str_replace('_', '/', $className);
             $parser = new Ini_Simple();
             $configs = $parser->parseIniFile("{$iniFile}.ini", true);
             $preparer = Builder::build($className);
             if (!$preparer instanceof Preparer) {
                 trigger_error($className . ' is not implemented laiz.action.Preparer.');
                 continue;
             }
             self::prepare($preparer, (array) $configs);
             $setter = function ($val) use($obj, $propName) {
                 $obj->{$propName} = $val;
             };
             $ret = $preparer->prepare($setter);
             if ($ret) {
                 return $ret;
             }
         }
         return null;
     } else {
         return null;
     }
 }
Exemple #2
0
 /**
  * コンポーネントの作成
  *
  * @param string $componentName
  * @param string $registerName
  * @return Object
  */
 public function create($componentName, $registerName = '')
 {
     $componentName = str_replace('.', '\\', $componentName);
     if (strlen($registerName) > 0) {
         $registerName = str_replace('.', '\\', $registerName);
     } else {
         $registerName = $componentName;
     }
     // コンポーネントが既に存在する場合はここでリターン
     if (is_object($this->get($registerName))) {
         return $this->get($registerName);
     }
     $obj = Object::build($componentName);
     if ($obj instanceof Singleton) {
         $this->register($obj, $registerName);
     }
     return $obj;
 }