Example #1
0
 /**
  * 指定されたconfigで変換を実行します。
  *
  * @param mixed $obj
  * @param array $config
  */
 public function execute(&$obj, &$config)
 {
     foreach ($config as $fieldName => $fieldConfig) {
         foreach ($fieldConfig as $converterName => $attr) {
             // Converterインスタンスを作成
             $converter = $this->container->getPrototype("Teeple_Converter_" . ucfirst($converterName));
             if (!is_object($converter)) {
                 throw new Teeple_Exception("Converterのインスタンスを作成できません。({$converterName})");
             }
             // 属性をセット
             foreach ($attr as $key => $value) {
                 $converter->{$key} = $value;
             }
             // Converterを実行
             if ($fieldName == self::FIELD_ALL) {
                 $keys = Teeple_Util::getPropertyNames($obj);
             } else {
                 $keys = array($fieldName);
             }
             foreach ($keys as $key) {
                 if (!$converter->convert($obj, $key)) {
                     $this->log->info("{$converterName}は{$key}に対して実行されませんでした。");
                 }
             }
         }
     }
     return;
 }
Example #2
0
 /**
  * ContainerのSingletonインスタンスを取得します。
  *
  * @return Teeple_Container
  */
 public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new Teeple_Container();
     }
     return self::$instance;
 }
Example #3
0
 /**
  * FilterChainの最後にFilterを追加
  *
  * @param   string  $name   Filterのクラス名
  * @param   string  $alias  Filterのエイリアス名
  * @param   array   $attributes Filterの属性値
  */
 public function add($name, $alias = '', $attributes = NULL)
 {
     // エイリアス名が指定されていない場合はクラス名をセット
     if (empty($alias)) {
         $alias = $name;
     }
     // Filterの実行が既に始まっていたらエラー(実行後の追加はエラー)
     if ($this->_index > -1) {
         throw new Teeple_Exception("既にフィルターが実行されています。");
     }
     // Filterのクラス名が不正だったらエラー
     if (!preg_match("/^[0-9a-zA-Z_]+\$/", $name)) {
         throw new Teeple_Exception("フィルターのクラス名が不正です。({$name})");
     }
     // 既に同名のFilterが追加されていたら何もしない
     if (isset($this->_list[$alias]) && is_object($this->_list[$alias])) {
         $this->log->info("このFilterは既に登録されています({$name}[alias:{$alias}])");
         return;
     }
     // オブジェクトの生成に失敗していたらエラー
     $className = "Teeple_Filter_" . ucfirst($name);
     $filter = $this->container->getComponent($className);
     if (!is_object($filter)) {
         throw new Teeple_Exception("Filterオブジェクトの生成に失敗しました。({$name})");
     }
     if (is_array($attributes)) {
         $filter->setAttributes($attributes);
     }
     $this->_list[$alias] = $filter;
     $this->_position[] = $alias;
     return;
 }
Example #4
0
 /**
  * フレームワークを起動させる
  *
  * @access  public
  * @since   3.0.0
  */
 public function execute()
 {
     $this->log->debug("************** controller#execute called.");
     // デフォルトトランザクションをコンテナに登録
     $defaultTx = $this->txManager->getTransaction();
     $this->container->register('DefaultTx', $defaultTx);
     // 実行するActionを決定
     $actionName = $this->hook->makeActionName();
     if ($actionName == NULL) {
         throw new Teeple_Exception("アクションが特定できません。");
     }
     // 初期ActionをActionChainにセット
     $this->log->debug("****actionName: {$actionName}");
     try {
         $this->actionChain->add($actionName);
     } catch (Exception $e) {
         $this->log->warn($e->getMessage());
         $isContinue = $this->hook->actionClassNotFound($actionName);
         if (!$isContinue) {
             return;
         }
     }
     // FilterChainのセットアップと実行
     $this->filterChain->build();
     $this->filterChain->execute();
     //$this->filterChain->clear();
 }
Example #5
0
 /**
  * 指定されたconfigでバリデーションを実行します。
  * エラーがあった場合はエラーメッセージを組み立てて
  * Requestにメッセージを追加します。
  *
  * @param object $obj
  * @param array $config
  * @return boolean
  */
 public function execute($obj, &$config)
 {
     $result = TRUE;
     foreach ($config as $fieldConfig) {
         $fieldName = $fieldConfig['name'];
         foreach ($fieldConfig['validation'] as $validatorName => $attr) {
             // Validatorインスタンスを作成
             $validator = $this->container->getPrototype("Teeple_Validator_" . ucfirst($validatorName));
             if (!is_object($validator)) {
                 throw new Teeple_Exception("Validatorのインスタンスを作成できません。({$validatorName})");
             }
             // 属性をセット
             foreach ($attr as $key => $value) {
                 $validator->{$key} = $value;
             }
             // Validatorを実行
             if (!$validator->validate($obj, $fieldName)) {
                 $result = FALSE;
                 // エラーメッセージをセット
                 $this->setErrorMessage($validator, $validatorName, $attr, $fieldConfig);
                 break;
             }
         }
     }
     return $result;
 }
Example #6
0
 public function setUp()
 {
     $this->container = Teeple_Container::getInstance();
     $this->actionChain = $this->container->getComponent('Teeple_ActionChain');
     $this->request = $this->container->getComponent('Teeple_Request');
     $this->container->register('DefaultTx', new StdClass());
     $this->response = $this->container->getComponent('Teeple_Response');
 }
Example #7
0
 /**
  * Actionを追加する
  *
  * @param   string  $name   Actionのクラス名
  */
 public function add($name)
 {
     // Actionのクラス名をチェック
     if (!preg_match("/^[0-9a-zA-Z_]+\$/", $name)) {
         throw new Teeple_Exception("Actionクラス名が不正です。");
     }
     // Actionクラスのインスタンス化
     $className = Teeple_Util::capitalizedClassName($name);
     $action = $this->container->getPrototype($className);
     $base = 'Teeple_ActionBase';
     if (!is_object($action) || !$action instanceof $base) {
         throw new Teeple_Exception("Actionクラスの生成に失敗しました。({$className})");
     }
     array_push($this->_list, $action);
     return;
 }
Example #8
0
 /**
  * データを削除します。シートの逆順に実行します。
  * @param array $sheets
  */
 private function clearTables($sheets)
 {
     $names = array();
     foreach ($sheets as $sheet) {
         $names[] = $sheet->getTitle();
     }
     foreach (array_reverse($names) as $name) {
         $entity_name = "Entity_{$name}";
         if (!class_exists($entity_name, true)) {
             print "entity class not found. skip. {$entity_name}";
             continue;
         }
         $entity = $this->c->getEntity($entity_name);
         $entity->deleteAll();
     }
     return;
 }
Example #9
0
 /**
  * ConverterのListを生成
  *
  * @param   array   $params Convertする条件が入った配列
  * @access  private
  * @since   3.0.0
  */
 private function _buildConverterList($params)
 {
     foreach ($params as $key => $value) {
         $key = preg_replace("/\\s+/", "", $key);
         $value = preg_replace("/\\s+/", "", $value);
         if ($key == "") {
             throw new Teeple_Exception("Converterの設定が不正です。");
         }
         //
         // $key は attribute.name のパターン
         //
         $keyArray = explode(".", $key);
         if (count($keyArray) != 2) {
             throw new Teeple_Exception("Converterのキーが不正です。");
         }
         $attribute = $keyArray[0];
         // 属性の名前
         $name = $keyArray[1];
         // Converterの名前
         $className = "Converter_" . ucfirst($name);
         //
         // 既に同名のConverterが追加されていたら何もしない
         //
         if (isset($this->_list[$name]) && is_object($this->_list[$name])) {
             continue;
         }
         //
         // オブジェクトの生成に失敗していたらエラー
         //
         $converter = $this->container->getComponent($className);
         if (!is_object($converter)) {
             throw new Teeple_Exception("Converter {$className} の生成に失敗しました。");
         }
         $this->_list[$name] = $converter;
     }
 }
Example #10
0
 /**
  * @return Teeple_Session
  */
 public static function instance()
 {
     return Teeple_Container::getInstance()->getComponent(__CLASS__);
 }
Example #11
0
 public function setUp()
 {
     $this->container = Teeple_Container::getInstance();
 }
Example #12
0
 /**
  * 新しいトランザクションを取得します。
  *
  * @return Teeple_Transaction
  */
 public function getTransaction()
 {
     $tx = $this->container->getPrototype('Teeple_Transaction');
     $this->txs[] = $tx;
     return $tx;
 }
Example #13
0
    fwrite(STDERR, "Invalid Parameter.");
    exit;
}
$cmpName = $argv[1];
$param = $argv;
array_shift($param);
array_shift($param);
/*
 * Teeple設定ファイルの読込み
 */
define('BASE_DIR', dirname(dirname(__FILE__)) . "/webapp");
include_once BASE_DIR . "/config/user.inc.php";
/*
 * コンテナからComponentを取得
 */
$container = Teeple_Container::getInstance();
// デフォルトトランザクションをコンテナに登録
$txManager = $container->getComponent("Teeple_TransactionManager");
$defaultTx = $txManager->getTransaction();
$container->register('DefaultTx', $defaultTx);
// 実行するコンポーネントを取得
$component = $container->getComponent($cmpName);
if (!is_object($component)) {
    fwrite(STDERR, "No component found.");
    exit;
}
if (count($param) > 0) {
    $component->_argv = $param;
}
try {
    $component->execute();
Example #14
0
 /**
  * Migrationを実行します。
  * 
  */
 public function execute()
 {
     $config = $this->dataSource->getDataSourceConfig();
     foreach ($config as $name => $dsn) {
         print "** start migration for {$name}. \n";
         $conn = $this->dataSource->getConnection($name);
         $this->pdo = $conn->getDB();
         // DBのmigratoin番号を取得
         $remote_num = $this->getRemoteNum();
         print "remote: {$remote_num}\n";
         // ローカルのmigration番号を取得
         $local = new Teeple_Migration_Local(dirname(BASE_DIR) . "/migration/" . $name);
         $local_num = $local->getMaxNum();
         print "local: {$local_num}\n";
         while ($remote_num < $local_num) {
             $remote_num++;
             print "apply {$remote_num}..";
             $ddl = $local->getContent($remote_num);
             $ddllist = explode(';', $ddl);
             try {
                 foreach ($ddllist as $q) {
                     $q = trim($q);
                     if (strlen($q)) {
                         $stmt = $this->pdo->prepare($q);
                         $stmt->execute();
                     }
                 }
             } catch (Exception $e) {
                 print "fail.\n";
                 print $e->getMessage();
                 return;
             }
             $this->pdo->beginTransaction();
             $stmt = $this->pdo->prepare("UPDATE " . self::TABLE_NAME . " SET version = {$remote_num}");
             $stmt->execute();
             $this->pdo->commit();
             print "success.\n";
         }
         print "** finish migration for {$name}. \n";
     }
     // --entityがセットされていたらEntityも更新する
     if (isset($this->_argv) && in_array('--entity', $this->_argv)) {
         print "\n*** update entity class.\n";
         $entityGenerator = Teeple_Container::getInstance()->getComponent('Teeple_EntityGenerator');
         $entityGenerator->_argv = array('--force');
         $entityGenerator->execute();
     }
 }