Skip to content

Commit 1a931f4

Browse files
committed
DOCS
1 parent 7094f1b commit 1a931f4

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ subtler than it looks.
1919
inputs) through a fluent `Expect::` builder and a `Processor`.
2020

2121
- **PHP Version**: 8.1 - 8.5
22-
- **Package**: `nette/schema` (dep: `nette/utils`)
22+
- **Package**: `nette/schema` (dep: `nette/utils`); `master` = 2.0-dev,
23+
maintenance lives on `v1.x` branches
2324

2425
## Essential Commands
2526

@@ -36,6 +37,7 @@ composer phpstan
3637

3738
- Every file starts with `declare(strict_types=1);`; **tabs**; single quotes;
3839
`@internal` for implementation details, `@method` for `Expect`'s magic methods;
40+
deprecations use the native `#[\Deprecated]` attribute, not phpDoc;
3941
Nette Coding Standard.
4042
- Tests are Nette Tester `.phpt` named `Expect.<feature>.phpt`; `checkValidationErrors()`
4143
asserts the expected error messages of a failing `process()`.

docs/internals.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ it** — and they do so in subtly different ways:
8383

8484
This is the package's sharpest trap: a piece of control state travelling through
8585
the payload, replicated across five sites. Any new `Schema` element must reproduce
86-
the strip-and-honor dance or merging silently misbehaves. (There is a standing
87-
idea to replace it with a declarative `MergeMode::Replace`; DI carries its own
88-
parallel `PREVENT_MERGING` constant. See `docs/local/ideas/odstranit-prevent-merging.md`.)
86+
the strip-and-honor dance or merging silently misbehaves. (DI carries its own
87+
parallel `PREVENT_MERGING` constant.)
8988

9089
## One transform pipeline; `assert`/`castTo` are sugar over `transform`
9190

@@ -181,13 +180,20 @@ by validating dynamics eagerly.
181180

182181
## `Expect::from()` mapping rules
183182

184-
`Expect::from($object)` reflects **constructor parameters if `__construct`
185-
exists, otherwise properties** — a class with a constructor has its properties
186-
ignored entirely. Per item: uninitialized property / non-optional parameter →
187-
`required()`; a `null` default on a type that does not accept null → also
188-
`required()` (not "default null"); an **object** default recurses into a nested
189-
`from()`; anything else becomes `default($def)`. The type comes from
190-
`Helpers::getPropertyType` (native type, then `@var`), falling back to `mixed`.
183+
`Expect::from()` accepts an instance **or a class name** (since 2.0) and
184+
reflects **constructor parameters if `__construct` exists, otherwise
185+
properties** — a class with a constructor has its properties ignored entirely.
186+
Types come from **native declarations only** (`Nette\Utils\Type::fromReflection`,
187+
fallback `mixed`); phpDoc `@var` support was removed in 2.0. Per item:
188+
189+
- a non-nullable class-typed item recurses into `from($thatClass)` **even
190+
without a default** (beware: `class_exists` is also true for enums, which
191+
then map badly);
192+
- no default (uninitialized property / non-optional parameter) → `required()`;
193+
- an **object** default recurses into a nested `from($default)` (instance-based);
194+
- any other default — including `null` — becomes `default($def)` (the 1.x rule
195+
"null default on a non-nullable type → `required()`" is gone).
196+
191197
The result is a `Structure` with `castTo($class)` **stacked after** the
192198
constructor's built-in `castTo('object')`, so a completed value travels
193199
array → `stdClass` → instance through the cast fork above.
@@ -207,4 +213,4 @@ array → `stdClass` → instance through the cast fork above.
207213
| DI / integration hook | `Processor::onNewContext`, `createContext` |
208214
| Error message rendering | `Message::toString`, `Message::*` code constants |
209215
| Key schemas, `isKey` | `Type::normalize`/`validateItems`, `Context::isKey` |
210-
| Object-to-schema mapping | `Expect::from`, `Helpers::getPropertyType` |
216+
| Object-to-schema mapping | `Expect::from` (native types only) |

0 commit comments

Comments
 (0)