Example #1
0
File: Tab.php Project: fnu/php-orm
 /**
  * 生成源代码
  *
  * @return string  Model的源代码
  */
 public function toModelCode()
 {
     $code = "<?php\n\n";
     $code .= $this->toNamespace();
     $code .= "use " . \G\Conf::get('orm.model.use') . ";\n";
     $code .= "\n";
     $code .= "/**\n";
     $code .= " * 数据模型\n";
     $code .= " * {$this->getTableComment()}\n";
     $code .= " * Table: {$this->getTableName()}\n";
     $code .= " */\n";
     $code .= "class {$this->getBaseModelName()} extends " . \G\Conf::get('orm.model.extend') . "\n";
     $code .= "{\n";
     $code .= $this->toAttributes();
     $code .= "\n";
     $code .= $this->toMethod();
     $code .= "}\n";
     return $code;
 }
Example #2
0
 public function toExtends()
 {
     $extends = $this->getClassExtends();
     if (\G\Conf::get('orm.model.extend')) {
         array_unshift($extends, \G\Conf::get('orm.model.extend'));
     }
     return empty($extends) ? '' : ' extends ' . implode(', ', $extends);
 }
Example #3
0
#!/usr/bin/env php
<?php 
/**
 *  路径分隔符
 */
define('DS', DIRECTORY_SEPARATOR);
/**
 * 应用的根目录
 */
define('APPLICATION_PATH', realpath('.'));
include APPLICATION_PATH . '/library/G/Loader.php';
\G\Loader::getInstance();
\G\Conf::getInstance();
$db = \G\Db::getInstance();
foreach ($db->getTables() as $tab) {
    $tabObj = new \G\Tab($tab);
    var_dump($tabObj->getModelFilePath());
    /*
     * 创建输出的目录
     */
    if (!file_exists(dirname($tabObj->getModelFilePath()))) {
        mkdir(dirname($tabObj->getModelFilePath()), 0777, true);
    }
    file_put_contents($tabObj->getModelFilePath(), $tabObj->toModelCode());
}