示例#1
0
 /**
  * Entityを生成します。
  * 
  */
 public function execute()
 {
     // --force フラグのチェック
     if (isset($this->_argv) && in_array('--force', $this->_argv)) {
         $this->forceUpdate = TRUE;
     }
     $config = $this->dataSource->getDataSourceConfig();
     foreach ($config as $name => $dsn) {
         $this->generate($name, $this->convertDSN($dsn));
     }
 }
示例#2
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();
     }
 }
示例#3
0
 /**
  * Entityを取得するマジックメソッドです。
  *
  * @param string $name
  * @return Teeple_ActiveRecord
  */
 public function __get($name)
 {
     $this->log->debug("エンティティ {$name} を取得します。");
     if (preg_match('/^Entity_/', $name)) {
         $ref = new ReflectionClass($name);
         $ds = $ref->getStaticPropertyValue('_DATASOURCE');
         if ($ds == "") {
             $ds = DEFAULT_DATASOURCE;
         }
         $this->log->debug("データソース: {$ds}");
         if (isset($this->connection[$ds])) {
             $conn = $this->connection[$ds];
         } else {
             $conn = $this->dataSource->getConnection($ds);
             $this->connection[$ds] = $conn;
             if ($this->isstart) {
                 $conn->beginTransaction();
             }
         }
         return new $name($conn->getDB());
     }
     return NULL;
 }
示例#4
0
 /**
  * DataSourceをすべてクローズします。
  *
  */
 public function postfilter()
 {
     $this->dataSource->closeAll();
 }
示例#5
0
 /**
  * DB接続情報を設定します。
  *
  * @param array $ds DB接続情報
  */
 public static function setDataSource($ds)
 {
     self::$ds = $ds;
 }
示例#6
0
/**
 * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
 *
 * PHP versions 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @package     teeple
 * @author      Mitsutaka Sato <*****@*****.**>
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 */
include_once dirname(__FILE__) . '/teeple.inc.php';
//
// Action自動生成機能のON/OFF
//
define('USE_DEVHELPER', false);
//
//Smartyテンプレートの設定
//
Teeple_Smarty4Maple::setOptions(array("caching" => false, "cache_lifetime" => 5, "compile_check" => false, "force_compile" => true));
//
// DataSourceの設定
//
define('DEFAULT_DATASOURCE', 'default');
Teeple_DataSource::setDataSource(array('default' => array('dsn' => 'mysql:host=localhost;dbname=default;charset=utf8', 'user' => 'default', 'pass' => 'default')));