Valinor/docs/mkdocs.yml

91 lines
2.3 KiB
YAML
Raw Normal View History

# yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json
site_name: Valinor
2022-06-12 16:30:13 +02:00
site_url: https://valinor.cuyz.io/
repo_url: https://github.com/CuyZ/Valinor
repo_name: CuyZ/Valinor
edit_uri: edit/master/docs/pages/
docs_dir: pages
extra:
2022-06-12 16:30:13 +02:00
meta:
title: Valinor • PHP object mapper with strong type support
description: PHP library that helps to map any input into a strongly-typed value object structure.
image: img/valinor-banner.png
social:
- icon: fontawesome/brands/github
link: https://github.com/CuyZ
- icon: fontawesome/solid/globe
link: https://cuyz.io
version:
provider: mike
extra_css:
- stylesheets/extra.css
plugins:
2022-06-28 16:15:29 +02:00
- mike:
canonical_version: latest/
theme:
name: material
2022-06-10 18:57:14 +02:00
custom_dir: overrides
favicon: img/valinor-icon.svg
logo: img/valinor-icon.svg
features:
- navigation.sections
- navigation.top
- navigation.indexes
- content.code.annotate
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
primary: teal
accent: teal
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: teal
accent: teal
toggle:
icon: material/brightness-4
name: Switch to light mode
markdown_extensions:
- meta
2022-06-28 16:15:48 +02:00
- toc:
permalink: true
- pymdownx.highlight:
anchor_linenums: true
extend_pygments_lang:
- name: php
lang: php
options:
startinline: true
- pymdownx.inlinehilite
- pymdownx.snippets:
auto_append:
- docs/includes/links.md
- pymdownx.superfences
- admonition
nav:
- Introduction: index.md
- Getting Started: getting-started.md
- Credits: credits.md
2022-06-10 18:57:14 +02:00
- Changelog: changelog.md
- Usage:
- Validation: validation.md
- Message customization: message-customization.md
- Source: source.md
- Mapping:
feat!: make mapper more strict and allow flexible mode The mapper is now more type-sensitive and will fail in the following situations: - When a value does not match exactly the awaited scalar type, for instance a string `"42"` given to a node that awaits an integer. - When unnecessary array keys are present, for instance mapping an array `['foo' => …, 'bar' => …, 'baz' => …]` to an object that needs only `foo` and `bar`. - When permissive types like `mixed` or `object` are encountered. These limitations can be bypassed by enabling the flexible mode: ```php (new \CuyZ\Valinor\MapperBuilder()) ->flexible() ->mapper(); ->map('array{foo: int, bar: bool}', [ 'foo' => '42', // Will be cast from `string` to `int` 'bar' => 'true', // Will be cast from `string` to `bool` 'baz' => '…', // Will be ignored ]); ``` When using this library for a provider application — for instance an API endpoint that can be called with a JSON payload — it is recommended to use the strict mode. This ensures that the consumers of the API provide the exact awaited data structure, and prevents unknown values to be passed. When using this library as a consumer of an external source, it can make sense to enable the flexible mode. This allows for instance to convert string numeric values to integers or to ignore data that is present in the source but not needed in the application. --- All these changes led to a new check that runs on all registered object constructors. If a collision is found between several constructors that have the same signature (the same parameter names), an exception will be thrown. ```php final class SomeClass { public static function constructorA(string $foo, string $bar): self { // … } public static function constructorB(string $foo, string $bar): self { // … } } (new \CuyZ\Valinor\MapperBuilder()) ->registerConstructor( SomeClass::constructorA(...), SomeClass::constructorB(...), ) ->mapper(); ->map(SomeClass::class, [ 'foo' => 'foo', 'bar' => 'bar', ]); // Exception: A collision was detected […] ```
2022-06-23 10:30:36 +02:00
- Type strictness: mapping/type-strictness.md
- Construction strategy: mapping/construction-strategy.md
- Inferring interfaces: mapping/inferring-interfaces.md
- Handled types: mapping/handled-types.md
- Other:
- Performance & caching: other/performance-and-cache.md
- Dealing with dates: other/dealing-with-dates.md
- Static analysis: other/static-analysis.md