定制 michaldudek/knit-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

michaldudek/knit-bundle

最新稳定版本:0.3.0

Composer 安装命令:

composer require michaldudek/knit-bundle

包简介

Knit integration with Symfony3.

README 文档

README

Knit ties your PHP objects with your database of choice in a simple way. Read more about Knit in its repository.

This is a Symfony3 Bundle that integrates Knit with the framework.

Build Status SensioLabsInsight

Installation

Require the bundle:

$ composer require michaldudek/knit-bundle

Enable the bundle in your Kernel:

<?php

// ...

    public function registerBundles()
    {
        $bundles = [
            // ...

            new Knit\Bundle\KnitBundle(),
        ];
        // ...
    }

Configuration

Add knit section to your config.yml.

There are three available settings and all of them are just names of services you want injected to the main Knit\Knit class (those will serve as defaults for all repositories).

knit:
    # required, default store
    store: [store.service_name]

    # optional, default data mapper, "knit.data_mapper.array_serializer" by default
    data_mapper: [data_mapper.service_name]

    # optional, event dispatcher used, "event_dispatcher" by default
    event_dispatcher: [event_dispatcher.service_name]

Configuring a Store

As you can see, for Knit, a store is nothing more than a dependency that needs to be injected. This gives you power to configure your stores in any way you want.

For convenience, KnitBundle registers two dependencies for the two stores it implements so far: knit.store.doctrine_dbal.criteria_parser and knit.store.mongodb.criteria_parser. It also registers two parameters for easier resolution of store classes: %knit.store.doctrine_dbal.class% and %knit.store.mongodb.class%.

Using these two aspects you can easily configure your data stores and register them in the container:

services:

    mysql_store:
        class: %knit.store.doctrine_dbal.class%
        arguments:
            - driver: pdo_mysql
              user: %db.username%
              password: %db.password%
              host: %db.host%
              dbname: %db.database%
            - @knit.store.doctrine_dbal.criteria_parser
            - @logger

    # or

    mongodb_store:
        class: %knit.store.mongodb.class%
        arguments:
            - hostname: %mongo.host%
              database: %mongo.database%
              username: %mongo.username%
              password: %mongo.password
            - @knit.store.mongodb.criteria_parser
            - @logger

where all the connection parameters you have to register yourself, obviously.

Then in config.yml you can just specify:

knit:
    store: mysql_store    # or mongodb_store

Repositories

By convention, all repositories should be registered as services. You are going to inject them into other services or controllers anyway, so for clarity KnitBundle doesn't automagically creates them.

An example definition of a repository is like this:

user.repository:
    parent: knit.repository
    arguments: [MyApp\User, "users"]

where 1st argument is the managed object class name and second a collection name. Additional arguments are also allowed - see Knit documentation for details on what they are.

License

MIT, see LICENSE.md.

Copyright (c) 2015 Michał Pałys-Dudek

统计信息

  • 总下载量: 47
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固