本文整理汇总了PHP中Builder::generateBase方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::generateBase方法的具体用法?PHP Builder::generateBase怎么用?PHP Builder::generateBase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder::generateBase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
OrmTest::assertTrue("Creating test database {$dbname}.", true);
} catch (Exception $e) {
throw new OrmTestException('Unable to create test database. Probably missing proper config.php or a permissions issue. (' . $e->getMessage() . ')');
}
try {
Db::execute("CREATE TABLE `{$dbname}`.`user` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) NOT NULL,\n `email` varchar(255) NOT NULL,\n `active` tinyint(4) NOT NULL,\n `created_at` datetime NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
Db::execute("CREATE TABLE `{$dbname}`.`phone_number` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `number` varchar(255) NOT NULL,\n `type` varchar(255) NOT NULL,\n `location` varchar(255),\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
Db::execute("CREATE TABLE `{$dbname}`.`post` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `user_id` int(11) NOT NULL,\n `title` varchar(255) NOT NULL,\n `body` text NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
Db::execute("CREATE TABLE `{$dbname}`.`post_meta` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `post_id` int(11) NOT NULL,\n `key` varchar(255) NOT NULL,\n `val` varchar(255) NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
Db::execute("CREATE TABLE `{$dbname}`.`orphan` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) NOT NULL,\n `age` varchar(255) NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
OrmTest::assertTrue("Creating test database tables.", true);
} catch (Exception $e) {
throw new OrmTestException('Unable to create test tables. Probably a permissions issue. (' . $e->getMessage() . ')');
}
try {
Builder::generateBase(null, $dbname);
OrmTest::assertTrue("Checking for generated base classes in ./{$dbname}/base.php.", file_exists("./{$dbname}/base.php"));
require "./{$dbname}/base.php";
OrmTest::assertTrue('Checking for generated base classes in php scope.', class_exists('UserBase'));
} catch (Exception $e) {
Db::query("drop database {$dbname}");
exec("read -p 'Press enter to delete the test directory named: {$dbname} OR CTRL+C TO ABORT'; rm -rf {$dbname}");
throw new OrmTestException('Unable to generate model! (' . $e->getMessage() . ')');
}
try {
foreach (array('Jason', 'Jim', 'Jerri', 'Al') as $name) {
$user = new User(array('name' => $name, 'email' => "{$name}@not_a_domain.com", 'created_at' => new PlainSql('NOW()'), 'active' => 1));
$user->save();
}
OrmTest::assertTrue('Testing save() on new object.', is_numeric($user->getId()));
$user->setName("{$name} Johnson")->save();
示例2: array
#!/usr/bin/php
<?php
if (in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
Generate DumbledORM models.
Usage:
<?php
echo $argv[0];
?>
<option>
<option>
-h, -?, --help, -help Print this help message
-p, --prefix <prefix> Prefix generated classes
-d, --dir <directory> Output directory for the model instead of the default ./model
<?php
} else {
$params = array('p:' => 'prefix:', 'd:' => 'dir:');
$opt = getopt(implode('', array_keys($params)), $params);
require 'config.php';
require 'dumbledorm.php';
Builder::generateBase($opt['p'], $opt['d'] ? $opt['d'] : 'model');
}