2017 © Pedro Peláez
 

library leanmapper-extension

LeanMapper extension for Nette DI

image

janpecha/leanmapper-extension

LeanMapper extension for Nette DI

  • Wednesday, February 7, 2018
  • by janpecha
  • Repository
  • 3 Watchers
  • 3 Stars
  • 1,192 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 3 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

LeanMapper-extension

Build Status Downloads this Month Latest Stable Version License, (*1)

Lean Mapper extension for Nette., (*2)

Donate, (*3)

Installation

Download a latest package or use Composer:, (*4)

composer require janpecha/leanmapper-extension

Extension requires: * PHP 7.2 or later * Nette 3.0 or later * LeanMapper 4.0 or later, (*5)

Usage

``` neon extensions: leanmapper: JP\LeanMapperExtension\LeanMapperExtension, (*6)

leanmapper: # database connection username: ... password: ... database: ..., (*7)



Configuration ------------- ### Database connection ``` neon leanmapper: # required username: ... password: ... database: ... # optional connection: LeanMapper\Connection host: localhost driver: mysqli lazy: true profiler: ... # on|off or NULL => enabled in debug mode, disabled in production mode charset: utf8mb

Entities

``` neon leanmapper: entityFactory: LeanMapper\DefaultEntityFactory entityMapping: table: EntityClass, (*8)

    table:
        entity: EntityClass
        repository: RepositoryClass # only mapping, you need manually register repository to DI
        primaryKey: table_primary_key

    articles:
        entity: App\Model\Article
        primaryKey: article_id


### Mapper ``` neon leanmapper: mapper: true # bool defaultEntityNamespace: 'Model\Entity' nameMapping: camelcase # default | camelcase | underscore prefix: null

Support for addons

``` php use Nette\DI\CompilerExtension; use JP\LeanMapperExtension\IEntityProvider;, (*9)

class FooExtension extends CompilerExtension implements IEntityProvider { // from IEntityProvider function getEntityMappings() { return array( array( 'table' => 'foo_articles', 'primaryKey' => 'id', 'entity' => Foo\Model\Article::class, 'repository' => Foo\Model\ArticleRepository::class, # only mapping, you need manually register repository to DI ), // ... ); } }, (*10)


STI mapping ``` php use Nette\DI\CompilerExtension; use JP\LeanMapperExtension\IStiMappingProvider; class FooExtension extends CompilerExtension implements IStiMappingProvider { function getStiMappings() { return [ Model\Entity\Client::class => [ // base entity // type => target entity 'company' => Model\Entity\ClientCompany::class, ], // ... ]; } function getStiTypeFields() { return [ Model\Entity\Client::class => 'clientType', ]; } }

Row mapping, (*11)

``` php use Nette\DI\CompilerExtension; use JP\LeanMapperExtension\IRowMappingProvider;, (*12)

class FooExtension extends CompilerExtension implements IRowMappingProvider { function getRowFieldMappings() { return [ \Model\Entity\OrderItem::class => [ 'currency' => [ 'fromDbValue' => [static::class, 'currencyFromDb'], 'toDbValue' => [static::class, 'currencyToDb'], ] ], // ... ]; }, (*13)

function getRowMultiValueMappings()
{
    return [
        \Model\Entity\OrderItem::class => [
            'price' => [
                'fromDbValue' => [static::class, 'priceFromDb'],
                'toDbValue' => [static::class, 'priceToDb'],
            ],
        ],
    ];
}


static function currencyFromDb($value)
{
    return strtoupper($value);
}


static function currencyToDb($value)
{
    return strtolower($value);
}


static function priceFromDb(array $values)
{
    return [$values['price'], $values['currency']];
}


static function priceToDb($value)
{
    return [
        'price' => $value[0],
    ];
}

} ```, (*14)


License: New BSD License
Author: Jan Pecha, http://janpecha.iunas.cz/, (*15)

The Versions

07/02 2018

dev-master

9999999-dev

LeanMapper extension for Nette DI

  Sources   Download

BSD-3-Clause BSD-3

The Requires

 

The Development Requires

29/04 2017

v0.9.2

0.9.2.0

LeanMapper extension for Nette DI

  Sources   Download

BSD-3

The Requires

 

The Development Requires

21/11 2015

v0.9.1

0.9.1.0

LeanMapper extension for Nette 2.2

  Sources   Download

BSD-3

The Requires

 

The Development Requires

14/09 2014

v0.9.0

0.9.0.0

LeanMapper extension for Nette 2.2

  Sources   Download

BSD-3

The Requires

 

The Development Requires