Coder Social home page Coder Social logo

slick's Introduction

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:

<?php

return [
    'managers' => [
       
        'default' => [
            // ...
            
            'meta'      => env('DOCTRINE_METADATA', \CImrie\Slick\Mapping\SlickDriver::class),
            'mappings'  => [
               MyCustomMappingClass::class 
            ]
            
            // ...
        ]
    ]
];

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:

<?php

use \Tests\Model\Documents\User;
use CImrie\Slick\Slick;

class CustomMapping extends \CImrie\Slick\Mapping\DocumentMapping
{
    public static function mapFor(){
        return User::class;
    }
    
    public function map(Slick $builder)
    {
        $builder->id();
        $builder->string('name');
        $builder->string('email')->unique();
        // alternatively add the unique constraint manually
        //... $builder->index()->key('email')->unique();
        
        $builder->date('joinedAt');
    }
}

slick's People

Contributors

cimrie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.