예제 #1
0
파일: Runner.php 프로젝트: nishimura/laiz
 public static function prepare($obj, array $config)
 {
     $container = Container::getInstance();
     $request = $container->create('laiz.action.Request');
     $request->setRequestsByConfigs($config);
     Util::setPropertiesByRequest($request, $obj);
     Builder::initObject($obj, $config);
     return $obj;
 }
예제 #2
0
 /**
  * Start MVC controller.
  *
  * @access public
  */
 public function execute()
 {
     // create container with configure
     $container = Container::getInstance();
     // setup autoload
     BasicLoader::walk($container->getComponents('laiz.autoloader.Register'));
     // create request object
     $req = $container->get('laiz.action.Request');
     // run action
     // view is action component and run in action runner
     $actionName = $req->initActionName()->getActionName();
     $actionRunner = $container->create('laiz.action.Runner');
     $actionRunner->run($actionName);
 }
예제 #3
0
파일: Object.php 프로젝트: nishimura/laiz
 /**
  * クラス名と関数名から引数のオブジェクトを生成して返却
  *
  * @param string $className
  * @param ReflectionMethod
  * @return Object[]
  * @access private
  */
 public static function getMethodParamObjectsByReflection($className, ReflectionMethod $method)
 {
     $params = array();
     $paramRefs = $method->getParameters();
     $container = Container::getInstance();
     foreach ($paramRefs as $paramRef) {
         try {
             $obj = $paramRef->getClass();
             if (!is_object($obj)) {
                 if (!$paramRef->isArray()) {
                     continue;
                 }
                 $name = $paramRef->getName();
                 $objs = $container->getComponents(Inflector::classify($name));
                 // if (count($objs) > 0)
                 $params[] = $objs;
                 continue;
             }
             $name = $obj->getName();
         } catch (ReflectionException $e) {
             $tmp = explode(' ', $e->getMessage(), 3);
             // "Class $name does not exist"からクラス名を取得
             $name = $tmp[1];
         }
         if (is_object($component = $container->get($name))) {
             $params[] = $component;
         } elseif ($component = $container->create($name)) {
             $params[] = $component;
         } else {
             trigger_error("Failed to create object [{$name}] by type hinting.", E_USER_WARNING);
         }
     }
     return $params;
 }
예제 #4
0
파일: Flexy.php 프로젝트: nishimura/laiz
 /**
  * value属性の設定
  *
  * @param HTML_Template_Flexy_Element $emenet $this->_elementsのひとつ
  * @param mixed $var inputやtextareaは文字列、selectの場合は配列
  * @access private
  */
 function _setTagValue($element, $var)
 {
     switch ($element->tag) {
         case 'input':
             if (isset($element->attributes['type'], $element->attributes['name']) && $element->attributes['type'] == 'checkbox' && preg_match('/\\[\\]$/', $element->attributes['name'])) {
                 // チェックボックスの配列
                 $element->setValue((array) $var);
             } elseif (method_exists($element, 'setValue')) {
                 $element->setValue($var);
             }
             break;
         case 'select':
             if (!is_array($var)) {
                 // selectの設定は配列でなければならない
                 break;
             }
             $options = array();
             if (!array_key_exists($this->FLEXY_FORM_SELECTED, $var)) {
                 // 初期値が指定されていない場合
                 $request = Container::getInstance()->getComponent('laiz.action.Request');
                 $selected = $request->get($element->attributes['name']);
                 $selectedKey = null;
                 foreach ($var as $sKey => $sValue) {
                     $options[$sKey] = $sValue;
                     if ($selected == $sValue) {
                         // リクエスト変数からデフォルト値の設定
                         $selectedKey = $sKey;
                     }
                 }
                 $element->setOptions($options);
                 $element->setValue($selectedKey);
             } else {
                 // 初期値が指定されている場合
                 foreach ($var as $sKey => $sValue) {
                     if ($sKey != $this->FLEXY_FORM_SELECTED) {
                         $options[$sKey] = $sValue;
                     }
                 }
                 $element->setOptions($options);
                 $element->setValue($var[$this->FLEXY_FORM_SELECTED]);
             }
             break;
         case 'textarea':
             if (method_exists($element, 'setValue')) {
                 $element->setValue($var);
             }
             break;
         default:
             break;
     }
 }