fureszpeter / laratools
一些Laravel之外的实用库,如Eloquent、Migartion、Config
dev-master
2015-04-02 09:08 UTC
Requires
- php: >=5.5
- davedevelopment/phpmig: *
- illuminate/config: 5.1.*@dev
- illuminate/database: *
- illuminate/filesystem: 5.1.*@dev
- pimple/pimple: 1.*
- symfony/finder: 2.7.*@dev
- vlucas/phpdotenv: ~1.1@dev
Requires (Dev)
- phpunit/phpunit: ~4.7@dev
This package is not auto-updated.
Last update: 2024-09-14 16:31:14 UTC
README
#laratools
如果你使用phpmig,需要在你的项目根目录或PROJECT_ROOT/config目录中创建一个phpmig.php
##phpmig
这个包依赖于phpmig,因此你可以在vendor/bin/phpmig或vendor/davedevelopment/phpmig/bin/phpmig中找到CLI命令
示例
use Phpmig\ConfigDTO;
$configAsterisk = new ConfigDTO("mysql", "127.0.0.1", "dbname", "username", "password");
$container = new Phpmig\Container(__DIR__ . "/../migrations");
$container->setDatabaseConnection("db", $configAsterisk);
$container->setEloquentCapsule("capsule", $configAsterisk);
$container->setAdapter($container["db"]);
return $container;
并在迁移文件中
class InitSchema extends Migration
{
const DB_KEY_NAME = "capsule";
/* @var \Illuminate\Database\Schema\Builder $schema */
protected $schema;
public function init()
{
$this->schema = $this->get(self::DB_KEY_NAME)->schema();
}
/**
* Do the migration
*/
public function up()
{
$this->schema->create("states", function ($table) {
/* @var Blueprint $table */
$table->increments("id");
$table->char("code", 2);
$table->string("name", 64);
});
}
}
##配置
你可以在PROJECT_ROOT中的.env文件中定义你的环境
示例 .env文件
ENVIRONMENT=local
如果环境被定义并且我们在对象创建期间使用它
配置文件格式
return [
"driver" => "mysql"
];
读取配置文件,不包含.env文件
$config = new Config\Config(new \Symfony\Component\Finder\Finder(), __DIR__ . "/../config/development/");
echo $config->get("test.driver");
读取配置文件,包含.env文件
$config = new Config\Config(new \Symfony\Component\Finder\Finder(), __DIR__ . "/../");
echo $config->get("test.driver");