Lean Mapper extension for Nette
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
Makefile
composer.json
license.md
readme.md

readme.md

LeanMapper-extension

Build Status

Lean Mapper extension for Nette.

Become a Patron!

Installation

Download a latest package or use Composer:

composer require janpecha/leanmapper-extension

Extension requires:

  • PHP 5.3 or later
  • Nette 2.2 or later
  • LeanMapper 2.2 or later

Usage

extensions:
	leanmapper: JP\LeanMapperExtension\LeanMapperExtension


leanmapper:
	# database connection
	username: ...
	password: ...
	database: ...

Configuration

Database connection

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

Entities

leanmapper:
	entityFactory: LeanMapper\DefaultEntityFactory
	entities:
		table: EntityClass

		table:
			entity: EntityClass
			repository: RepositoryClass # repository is auto-registred in DI container
			primaryKey: table_primary_key

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

Mapper

leanmapper:
	mapper: JP\LeanMapperExtension\Mapper
	defaultEntityNamespace: 'Model\Entity'

Support for addons

<?php
use Nette\DI\CompilerExtension;
use JP\LeanMapperExtension\IEntityProvider;

class FooExtension extends CompilerExtension implements IEntityProvider
{
	// from IEntityProvider
	function getEntityMappings()
	{
		return array(
			array(
				'table' => 'foo_articles',
				'primaryKey' => 'id',
				'entity' => 'Foo\Model\Article',
				'repository' => 'Foo\Model\ArticleRepository', # repository is auto-registred in DI container, see option 'registerRepository'
				'registerRepository' => TRUE, // optional
			),
			// ...
		);
	}
}
?>

Mapper (for experts)

<?php
$mapper = JP\LeanMapperExtension\Mapper($defaultEntityNamespace = NULL);

// register entity
$mapper->register($tableName, $entity = NULL, $repository = NULL, $primaryKey = NULL);
?>

License: New BSD License
Author: Jan Pecha, http://janpecha.iunas.cz/