chai / framework
此包已被弃用,不再维护。未建议替代包。
最新版本(v0.0.1)的此包没有可用的许可信息。
Chai是一个有用的工具框架
v0.0.1
2013-07-10 14:50 UTC
Requires
- php: >=5.3.0
- illuminate/database: 4.0.*
- illuminate/filesystem: 4.0.*
- symfony/console: 2.3.*
Requires (Dev)
- mockery/mockery: 0.8.0
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2020-01-19 16:55:02 UTC
README
Chai是一个用于辅助PHP应用程序开发的工具集合。它旨在易于使用,并且不依赖于任何框架。它利用其他框架和库的组件,以避免重新发明轮子。
要求
- PHP 5.3或更高版本
- Composer
组件
迁移
迁移允许您对数据库进行“版本控制”。您可以创建表、更新表或执行其他操作。大多数迁移系统都有一个向上和向下方法。向上方法执行所需操作,如创建或更新表。向下方法执行相反操作,允许您多次运行迁移而不会出现任何问题。此外,Chai还有一个更新方法,在迁移已被应用的情况下运行。
入门
要开始使用迁移,您需要创建一个控制台脚本(bin/console
)。
<?php
//use Symfony\Component\Console\Application;
use Chai\Console\Application;
use Chai\Migrations\Migrations;
$migrations = new Migrations();
$migrations->setMigrationsDirectory(__DIR__.'/../app/database/migrations');
$migrations->setDatabaseParameters(array(
'host' => '',
'port' => '',
'username' => '',
'password' => '',
'database' => '',
));
$app = new Application('Description', '0.1.0');
$app->register($migrations);
$app->run();
然后运行bin/console migration:init
,这将创建migrations表。
创建迁移
您可以使用控制台应用程序创建迁移。
bin/console migration:create <name>
迁移名称必须全部小写,使用下划线(_
)作为分隔符,且不能以数字开头。
有效的迁移名称
- create_user_table
- update_post_table
- add_index_to_metadata_table
- test_migration_2
无效的迁移名称
- CreateTable
- Add Post Table
- 1test_migration
所有迁移都以前置时间戳作为前缀。这是为了保持迁移的唯一性,并了解它们应该按何种顺序运行。
基本迁移看起来像
<?php
use Chai\Migrations\BaseMigration;
class TestMigration extends BaseMigration
{
public function up()
{
// Do something here
}
public function down()
{
// Do the opposite here
}
public function update()
{
// Do something only if the
// migration has already been ran
}
}
运行迁移
bin/console migration:up [name]
bin/console migration:down [name]
状态
bin/console migration:status