项目作者: CImrie

项目描述 :
Doctrine ODM Fluent Metadata Class Implementation. Inspired by laravel-doctrine/fluent
高级语言: PHP
项目地址: git://github.com/CImrie/slick.git
创建时间: 2016-09-24T23:11:58Z
项目社区:https://github.com/CImrie/slick

开源协议:MIT License

下载


slick

Doctrine ODM Fluent Metadata Class Implementation. Inspired by laravel-doctrine/fluent.
Integrates seamlessly with cimrie/odm.

Laravel Setup

Add CImrie\Slick\SlickServiceProvider::class to the ‘providers’ section of config/app.php.
Follow the instructions for cimrie/odm.

In config/odm.php set ‘meta’ to CImrie\Slick\Mapping\SlickDriver::class
For each manager in config/odm.php specify a 'mappings' array like so:

  1. <?php
  2. return [
  3. 'managers' => [
  4. 'default' => [
  5. // ...
  6. 'meta' => env('DOCTRINE_METADATA', \CImrie\Slick\Mapping\SlickDriver::class),
  7. 'mappings' => [
  8. MyCustomMappingClass::class
  9. ]
  10. // ...
  11. ]
  12. ]
  13. ];

Usage

To set up your mapping files, you should extend one of the following classes:

  • Normal Documents: CImrie\Slick\Mapping\DocumentMapping::class,
  • Embedded Documents: CImrie\Slick\Mapping\EmbeddedMapping::class,
  • Mapped Superclass Documents: CImrie\Slick\Mapping\MappedSuperclassMapping::class

In each of the mapping files you will need to specify a mapFor and a map(Slick $builder) method implementaton.
mapFor should simply return the class name of the document you wish to map.

map(...) should make use of the $builder variable given in order to specify its mapping.
For example:

  1. <?php
  2. use \Tests\Model\Documents\User;
  3. use CImrie\Slick\Slick;
  4. class CustomMapping extends \CImrie\Slick\Mapping\DocumentMapping
  5. {
  6. public static function mapFor(){
  7. return User::class;
  8. }
  9. public function map(Slick $builder)
  10. {
  11. $builder->id();
  12. $builder->string('name');
  13. $builder->string('email')->unique();
  14. // alternatively add the unique constraint manually
  15. //... $builder->index()->key('email')->unique();
  16. $builder->date('joinedAt');
  17. }
  18. }