public static function InjectModelDataDriver(EntityModel $model)
 {
     $entityModelClassName = get_class($model);
     $dataDriver = self::CreateDataDriver($entityModelClassName);
     if (!$dataDriver instanceof InMemoryDataDriver) {
         $entityClassName = preg_replace('/Model$/', '', $entityModelClassName);
         SurogateDataDriver::SetRealDataDriver(new MySQLDataDriver());
         $qdp = Project::GetQDP();
         EntityBuilder::BuildEntity($entityClassName, $dataDriver, null, true, false);
         $model->truncate();
     }
     EntityModel::InjectDataDriver($model, $dataDriver);
 }
Esempio n. 2
0
<?php

require_once __DIR__ . '/../common.php';
define('BASE_ENTITY_PATH', BUILDER_ENTITY_PATH . '/base/');
define('MY_ENTITY_PATH', BUILDER_ENTITY_PATH . '/');
$db_master = pdo_factory($db->slave, null);
$eb = new EntityBuilder($db_master, $db->slave);
$eb->create();
class EntityBuilder
{
    private $pdo;
    private $db_info;
    function __construct($pdo = null, $db_info = null)
    {
        $this->pdo = $pdo;
        $this->db_info = $db_info;
    }
    function __destruct()
    {
        $this->pdo = null;
    }
    public function create()
    {
        $tableNameArray = $this->_getTables();
        if (!empty($tableNameArray)) {
            $cols = $this->_getColumnStructure($tableNameArray);
            // entityのbaseディレクトリ内のファイルを削除
            if (file_exists(BASE_ENTITY_PATH)) {
                $this->clearDirectory(BASE_ENTITY_PATH);
            } else {
                if (!mkdir(BASE_ENTITY_PATH, 0764, true)) {
 /**
  * Lee la tablas existentes y genera un archivo yml
  * con el esquema de la base de datos.
  *
  * Este método solo funciona con BDs mysql
  *
  * El archivo generado tiene el nombre de la base de datos
  *
  * @return boolean TRUE si se construyo con éxito
  */
 public function buildSchema()
 {
     $arrayTablas = array();
     $dblink = mysql_connect($this->host, $this->user, $this->password);
     mysql_select_db($this->database, $dblink);
     $query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='" . $this->database . "'";
     $result = mysql_query($query, $dblink);
     while ($row = mysql_fetch_array($result)) {
         $entity = new EntityBuilder($row['TABLE_NAME']);
         $arrayTabla = $entity->getSchema();
         $arrayTablas[$row['TABLE_NAME']] = $arrayTabla[$row['TABLE_NAME']];
     }
     unset($entity);
     $yml = "# ESQUEMA DE LA BD " . $this->database . "\n\n";
     $yml .= sfYaml::dump($arrayTablas, 2);
     $archivo = new Archivo($this->database . ".yml");
     $ok = $archivo->write($yml);
     unset($archivo);
     return $ok;
 }
Esempio n. 4
0
 /**
  * Crear los archivos de clases para el modelo de datos
  * 
  * @param type $entityName
  * @param type $prefijo
  * @return array
  */
 static function appCreateEntity($entityName, $prefijo = '')
 {
     self::getConection();
     $entityBuilder = new EntityBuilder(self::$conectionDB, $entityName, $prefijo);
     $entityFile = ucfirst(str_replace($prefijo, "", $entityName));
     $model = $entityBuilder->GetModel();
     $fileModel = "../../entities/models/{$entityFile}Entity.class.php";
     $method = $entityBuilder->GetMethod();
     $fileMethod = "../../entities/methods/{$entityFile}.class.php";
     $okModel = self::createArchive($fileModel, $model);
     $okMethod = self::createArchive($fileMethod, $method);
     $result = array();
     $okModel ? array_push($result, "Ok, {$fileModel} created") : array_push($result, "ERROR creating {$fileModel}");
     $okMethod ? array_push($result, "Ok, {$fileMethod} created") : array_push($result, "ERROR creating {$fileMethod}");
     return $result;
 }
Esempio n. 5
0
 /**
  * 通过表的实体类,获取表的概要描述,包括:表名、主键、自增字段、字段、默认值
  * 应该根据不同的数据库类型创建对应的TableSchema类:$dbType = $this->getDriver(false)->getDbType();
  * 这里只用到MySQL数据库,暂时不做对应多数据库类型
  * @return \tfc\db\TableSchema
  */
 public function getTableSchema()
 {
     if ($this->_tableSchema === null) {
         $entityBuilder = EntityBuilder::getInstance($this->getDbProxy());
         $this->_tableSchema = $entityBuilder->getTableSchema($this->getTableName());
     }
     return $this->_tableSchema;
 }