{"id":25423229,"url":"https://github.com/janpecha/leanmapper-extension","last_synced_at":"2025-10-31T14:30:32.380Z","repository":{"id":20218117,"uuid":"23489788","full_name":"janpecha/leanmapper-extension","owner":"janpecha","description":"Lean Mapper extension for Nette","archived":false,"fork":false,"pushed_at":"2024-06-27T06:43:03.000Z","size":81,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T00:22:09.866Z","etag":null,"topics":["leanmapper","leanmapper-extension","nette","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janpecha.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.janpecha.cz/donate/"}},"created_at":"2014-08-30T10:49:39.000Z","updated_at":"2023-08-19T13:41:24.000Z","dependencies_parsed_at":"2024-06-27T08:05:06.050Z","dependency_job_id":null,"html_url":"https://github.com/janpecha/leanmapper-extension","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"208714a23dadcd3c125c47477de5deb9db66abb9"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janpecha%2Fleanmapper-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janpecha%2Fleanmapper-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janpecha%2Fleanmapper-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janpecha%2Fleanmapper-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janpecha","download_url":"https://codeload.github.com/janpecha/leanmapper-extension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239144553,"owners_count":19589236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leanmapper","leanmapper-extension","nette","php"],"created_at":"2025-02-16T22:26:50.245Z","updated_at":"2025-10-31T14:30:32.348Z","avatar_url":"https://github.com/janpecha.png","language":"PHP","funding_links":["https://www.janpecha.cz/donate/"],"categories":[],"sub_categories":[],"readme":"LeanMapper-extension\n====================\n\n[![Build Status](https://github.com/janpecha/leanmapper-extension/workflows/Build/badge.svg)](https://github.com/janpecha/leanmapper-extension/actions)\n[![Downloads this Month](https://img.shields.io/packagist/dm/janpecha/leanmapper-extension.svg)](https://packagist.org/packages/janpecha/leanmapper-extension)\n[![Latest Stable Version](https://poser.pugx.org/janpecha/leanmapper-extension/v/stable)](https://github.com/janpecha/leanmapper-extension/releases)\n[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/janpecha/leanmapper-extension/blob/master/license.md)\n\n[Lean Mapper](http://leanmapper.com/) extension for [Nette](https://nette.org).\n\n\u003ca href=\"https://www.janpecha.cz/donate/\"\u003e\u003cimg src=\"https://buymecoffee.intm.org/img/donate-banner.v1.svg\" alt=\"Donate\" height=\"100\"\u003e\u003c/a\u003e\n\n\nInstallation\n------------\n\n[Download a latest package](https://github.com/janpecha/leanmapper-extension/releases) or use [Composer](http://getcomposer.org/):\n\n```\ncomposer require janpecha/leanmapper-extension\n```\n\nExtension requires:\n* PHP 7.2 or later\n* Nette 3.0 or later\n* LeanMapper 4.0 or later\n\n\nUsage\n-----\n\n``` neon\nextensions:\n\tleanmapper: JP\\LeanMapperExtension\\LeanMapperExtension\n\n\nleanmapper:\n\t# database connection\n\tusername: ...\n\tpassword: ...\n\tdatabase: ...\n```\n\n\nConfiguration\n-------------\n\n### Database connection\n\n``` neon\nleanmapper:\n\t# required\n\tusername: ...\n\tpassword: ...\n\tdatabase: ...\n\n\t# optional\n\tconnection: LeanMapper\\Connection\n\thost: localhost\n\tdriver: mysqli\n\tlazy: true\n\tprofiler: ...    # on|off or NULL =\u003e enabled in debug mode, disabled in production mode\n\tcharset: utf8mb\n```\n\n\n### Entities\n\n``` neon\nleanmapper:\n\tentityFactory: LeanMapper\\DefaultEntityFactory\n\tentityMapping:\n\t\ttable: EntityClass\n\n\t\ttable:\n\t\t\tentity: EntityClass\n\t\t\trepository: RepositoryClass # only mapping, you need manually register repository to DI\n\t\t\tprimaryKey: table_primary_key\n\n\t\tarticles:\n\t\t\tentity: App\\Model\\Article\n\t\t\tprimaryKey: article_id\n```\n\n\n### Mapper\n\n``` neon\nleanmapper:\n\tmapper: true # bool\n\tdefaultEntityNamespace: 'Model\\Entity'\n\tnameMapping: camelcase # default | camelcase | underscore\n\tprefix: null\n```\n\n\nSupport for addons\n------------------\n\n``` php\nuse Nette\\DI\\CompilerExtension;\nuse JP\\LeanMapperExtension\\IEntityProvider;\n\nclass FooExtension extends CompilerExtension implements IEntityProvider\n{\n\t// from IEntityProvider\n\tfunction getEntityMappings()\n\t{\n\t\treturn array(\n\t\t\tarray(\n\t\t\t\t'table' =\u003e 'foo_articles',\n\t\t\t\t'primaryKey' =\u003e 'id',\n\t\t\t\t'entity' =\u003e Foo\\Model\\Article::class,\n\t\t\t\t'repository' =\u003e Foo\\Model\\ArticleRepository::class, # only mapping, you need manually register repository to DI\n\t\t\t),\n\t\t\t// ...\n\t\t);\n\t}\n}\n```\n\nSTI mapping\n\n``` php\nuse Nette\\DI\\CompilerExtension;\nuse JP\\LeanMapperExtension\\IStiMappingProvider;\n\nclass FooExtension extends CompilerExtension implements IStiMappingProvider\n{\n\tfunction getStiMappings()\n\t{\n\t\treturn [\n\t\t\tModel\\Entity\\Client::class =\u003e [ // base entity\n\t\t\t\t// type =\u003e target entity\n\t\t\t\t'company' =\u003e Model\\Entity\\ClientCompany::class,\n\t\t\t],\n\t\t\t// ...\n\t\t];\n\t}\n\n\n\tfunction getStiTypeFields()\n\t{\n\t\treturn [\n\t\t\tModel\\Entity\\Client::class =\u003e 'clientType',\n\t\t];\n\t}\n}\n```\n\nRow mapping\n\n``` php\nuse Nette\\DI\\CompilerExtension;\nuse JP\\LeanMapperExtension\\IRowMappingProvider;\n\nclass FooExtension extends CompilerExtension implements IRowMappingProvider\n{\n\tfunction getRowFieldMappings()\n\t{\n\t\treturn [\n\t\t\t\\Model\\Entity\\OrderItem::class =\u003e [\n\t\t\t\t'currency' =\u003e [\n\t\t\t\t\t'fromDbValue' =\u003e [static::class, 'currencyFromDb'],\n\t\t\t\t\t'toDbValue' =\u003e [static::class, 'currencyToDb'],\n\t\t\t\t]\n\t\t\t],\n\t\t\t// ...\n\t\t];\n\t}\n\n\n\tfunction getRowMultiValueMappings()\n\t{\n\t\treturn [\n\t\t\t\\Model\\Entity\\OrderItem::class =\u003e [\n\t\t\t\t'price' =\u003e [\n\t\t\t\t\t'fromDbValue' =\u003e [static::class, 'priceFromDb'],\n\t\t\t\t\t'toDbValue' =\u003e [static::class, 'priceToDb'],\n\t\t\t\t],\n\t\t\t],\n\t\t];\n\t}\n\n\n\tstatic function currencyFromDb($value)\n\t{\n\t\treturn strtoupper($value);\n\t}\n\n\n\tstatic function currencyToDb($value)\n\t{\n\t\treturn strtolower($value);\n\t}\n\n\n\tstatic function priceFromDb(array $values)\n\t{\n\t\treturn [$values['price'], $values['currency']];\n\t}\n\n\n\tstatic function priceToDb($value)\n\t{\n\t\treturn [\n\t\t\t'price' =\u003e $value[0],\n\t\t];\n\t}\n}\n```\n\n------------------------------\n\nLicense: [New BSD License](license.md)\n\u003cbr\u003eAuthor: Jan Pecha, http://janpecha.iunas.cz/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanpecha%2Fleanmapper-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanpecha%2Fleanmapper-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanpecha%2Fleanmapper-extension/lists"}