mongator/pimple

用于与Pimple/Silex框架一起使用Mongator的提供程序

v2.0.0 2014-05-21 12:52 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:11:59 UTC


README

用于使用Mongator与Pimple/Silex框架的提供程序

要求

  • PHP 5.3.x
  • Unix系统
  • fabpot/pimple
  • mongator/mongator

安装

安装Mongator/Silex的推荐方式是通过Composer。您可以在Packagist上查看包信息

{
    "require": {
        "mongator/pimple": "2.*"
    }
}

参数

  • mongator.connection.dsn (默认 'mongodb://:27017'):数据库连接字符串
  • mongator.connection.database:数据库名称
  • mongator.connection.name (默认 'default'):连接名称
  • mongator.metadata.class:元数据工厂类名称
  • mongator.logger (默认 null):日志类实例
  • mongator.cache.fields (默认 ArrayCache):用于字段缓存的mongator缓存驱动实例
  • mongator.cache.data (默认 ArrayCache):用于数据缓存的mongator缓存驱动实例
  • mongator.extensions (默认 Array()):扩展实例数组
  • mongator.models.output:类输出路径
  • mongator.classes.config (默认 Array()):配置类包含类信息
  • mongator.classes.yaml.path:包含配置类YAML定义的有效目录

注册

$app->register(new Mongator\Pimple\MondatorServiceProvider());
$app->register(new Mongator\Pimple\MongatorServiceProvider(), array(
    'mongator.metadata.class' => 'Model\Mapping\Metadata',
    'mongator.models.output' => 'src/',
    'mongator.connection.database' => 'your_db'
));

使用

use Symfony\Component\HttpFoundation\Response;

$app->post('/article', function ($id) use ($app) {
    $articleRepository = $app['mongator']->getRepository('Model\Article');
    $article = $articleRepository->findOneById($id);

    return new Response('', 201);
});

** 请记住,在使用模型之前,您必须生成它们。(您可以使用此包提供的命令。)**

命令

此包中有三个有用的命令

  • mongator:generate:处理配置类并生成类文件。
  • mongator:indexes:确保所有存储库的索引
  • mongator:fix:修复所有缺失的引用。

您需要建议的包cilex/console-service-provider来在您的Silex设置上使用控制台命令。

测试

测试在tests文件夹中。要运行它们,您需要PHPUnit。示例

$ phpunit --configuration phpunit.xml.dist

许可

MIT,请参阅LICENSE